fork(1) download
  1. #include <bits/stdc++.h>
  2. #define fast() \
  3.   ios_base::sync_with_stdio(0); \
  4.   cin.tie(NULL); \
  5.   cout.tie(NULL);
  6. void file()
  7. {
  8. #if CPH || ONLINE_JUDGE
  9. // freopen("IN.txt", "r", stdin);
  10. // freopen("OUT.txt", "w", stdout);
  11. #else
  12. freopen("input.txt", "r", stdin);
  13. freopen("output.txt", "w", stdout);
  14. #endif
  15. }
  16. using namespace std;
  17. #define _CRT_SECURE_NO_WARNINGS
  18. #define ll long long
  19. #define ld long double
  20. #define dd double
  21. #define endl "\n"
  22. #define F first
  23. #define S second
  24. #define all(v) v.begin(), v.end()
  25. #define input for(ll i=0;i<n;i++) {cin>>arr[i];}
  26. #define input2 for(ll i=0;i<n;i++) {cin>>arr2[i];}
  27. #define output for(int i=1;i<=n;i++){cout<<arr[i]<<" ";}
  28. #define output_ans for(int i=1;i<=n;i++){cout<<ans[i]<<" ";}
  29. #define for0 for(ll i=0 ; i<n; i++)
  30. #define forj for(ll j=0 ; j<n; j++)
  31. #define fors for(ll i=0 ; i<s.size(); i++)
  32. #define for1 for(ll i=1 ; i<=n; i++)
  33. #define ww while
  34.  
  35. bool prime(ll n)
  36. {
  37. if (n == 0 || n == 1)
  38. return 0;
  39. if (n == 2 || n == 3)
  40. return 1;
  41. if (n % 2 == 0 || n % 3 == 0)
  42. return 0;
  43. for (ll i = 5; i * i <= n; i += 6)
  44. if (n % i == 0 || n % (i + 2) == 0)
  45. return 0;
  46. return 1;
  47. }
  48. bool compare(pair < ll , ll > p1,pair < ll , ll > p2) {
  49. return (p1.first - p1.second) > (p2.first - p2.second);
  50. }
  51. ll gcd(ll a, ll b) {
  52. while (b != 0)
  53. {
  54. ll a1 = a;
  55. a = b;
  56. b = a1 % b;
  57. }
  58. return a;
  59. }
  60. void solve()
  61. {
  62. string s; cin>>s;
  63. ll com=0, curl=0,squar=0,bract=0;
  64. fors{
  65. if(s[i]=='('){
  66. bract++;
  67. }
  68. else if(s[i]==')'){bract--;}
  69. else if(s[i]=='<'){com++;}
  70. else if(s[i]=='>'){com--;}
  71. else if(s[i]=='{'){curl++;}
  72. else if(s[i]=='}'){curl--;}
  73. else if(s[i]=='['){squar++;}
  74. else if(s[i]==']'){squar--;}
  75. }
  76. ll ans=(abs(bract)+abs(com)+abs(curl)+abs(squar))/2;
  77. if(com+bract+squar+curl==0){cout<<ans<<endl;}
  78. else {cout<<"Impossible\n";}
  79.  
  80. }
  81. int main()
  82. {
  83. fast();
  84. file();
  85. int TC = 1;
  86. // cin >> TC;
  87. while (TC--)
  88. {
  89. solve();
  90. }
  91. return 0;
  92. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
0