akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

using namespace std;

int inf = 1e8;

int minimum_steiner_tree(const vector<int>& T, const vector<vector<int> > &g) {
  const int n = g.size();
  const int numT = T.size();
  if (numT <= 1) return 0;

  vector<vector<int> > d(g); // all-pair shortest
  for (int k = 0; k < n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        d[i][j] = min( d[i][j], d[i][k] + d[k][j] );

  int OPT[(1 << numT)][n];
  for (int S = 0; S < (1 << numT); ++S)
    for (int x = 0; x < n; ++x)
      OPT[S][x] = inf;

  for (int p = 0; p < numT; ++p) // trivial case
    for (int q = 0; q < n; ++q)
      OPT[1 << p][q] = d[T[p]][q];

  for (int S = 1; S < (1 << numT); ++S) { // DP step
    if (!(S & (S-1))) continue;
    for (int p = 0; p < n; ++p)
      for (int E = 0; E < S; ++E)
        if ((E | S) == S)
          OPT[S][p] = min( OPT[S][p], OPT[E][p] + OPT[S-E][p] );
    for (int p = 0; p < n; ++p)
      for (int q = 0; q < n; ++q)
        OPT[S][p] = min( OPT[S][p], OPT[S][q] + d[p][q] );
  }
  int ans = inf;
  for (int S = 0; S < (1 << numT); ++S)
    for (int q = 0; q < n; ++q)
      ans = min(ans, OPT[S][q] + OPT[((1 << numT)-1)-S][q]);

  return ans;
}

int main(){
  while(true){
    vector<int> v;
    int h = getInt();
    int w = getInt();

    if(h + w == 0) break;

    REP(i,h) REP(j,w){
      if(getInt() == 1){
	v.push_back(i * w + j);
      }
    }

    vector<vector<int> > g(h * w, vector<int>(h * w, inf));
    
    REP(i,h) REP(j,w){
      g[i * w + j][i * w + j] = 0;
      if(i != h - 1){
	g[i * w + j][(i + 1) * w + j] = g[(i + 1) * w + j][i * w + j] = 1;
      }
      if(j != w - 1){
	g[i * w + j][i * w + j + 1] = g[i * w + j + 1][i * w + j] = 1;
      }
    }

    int ans = w * h - (minimum_steiner_tree(v, g) + 1);

    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
int main()
{
	int m,n,si,er,i,po,xusi;
	while(~scanf("%d",&n))
	{
		er = 0;
		si = 0;
		for(i = 0;i<n;i++)
		{
			scanf("%d",&m);
			if(m%2==0)
				er++;
			if(m%4==0)
				si++;
		}
		er = er - si;
		if(si>=n/2)
		{
		  cout<<"Yes"<<endl;
		  continue;
		}
		po = n - er - si;
		if(po>si)
		{
		cout<<"No"<<endl;
		}
		else{
		cout<<"Yes"<<endl;
		}
		
	
	}
  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define readvec(vec)    \
  for (auto& e : vec) { \
    cin >> e;           \
  }
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n;
  cin >> n;
  vecint a(n, 0);
  for (auto& e : a) cin >> e;
  ll ans = 0;
  ll sum = 0;
  REP(i, n) {
    if (a[i] != 0) {
      sum += a[i];
    }
    if (a[i] == 0 || i == n - 1) {
      ans += sum / 2;
      sum = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
//#include <string>
//#include <set>
#define ll long long
using namespace std;

int main() 
{
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n), min_cost(n, 1 << 30);
    for(ll i = 0; i < n; i++) {
        cin >> h.at(i);
    }

    min_cost.at(0) = 0;
    for(ll i = 1; i < n; i++) {
        for(ll j = 1; j <= k; j++) {
            if(i - j >= 0) {
                min_cost.at(i) = min(min_cost.at(i), min_cost.at(i - j) + abs(h.at(i) - h.at(i - j)));
            }
        }
    }

    cout << min_cost.at(n - 1) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;

int n,ans;
int a[10][10], use[10], perm[10], pos[10];

void dfs(int d, int r){
  if(d==n){
    ans = r; return;
  }

  for(int i=0;i<n;i++){
    if(!use[i]){
      use[i] = 1;

      perm[d] = i; pos[d] = 0;
      for(int j=0;j<d;j++){
	pos[d] = max(pos[d], pos[j] + a[i][perm[j]]);
      }
      if(pos[d]<ans)dfs(d+1,pos[d]);

      use[i] = 0;
    }
  } 
}

int main(){
  while(cin >> n,n){
    for(int i=0;i<n;i++)for(int j=0;j<n;j++){
	cin >> a[i][j];
	if(j<i)a[i][j] = a[j][i] = max(a[i][j],a[j][i]);
      }

    memset(use,0,sizeof(use));
    ans = 1e9;
    dfs(0,0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[200000];
int cnt[100];

int main()
{
  int i,n,mi,ma,tmp;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  mi=2000000000;
  ma=0;
  for (i=0;i<n;i++)
  {
    if (a[i]<mi) mi=a[i];
    if (a[i]>ma) ma=a[i];
  }
  if (ma-mi>=2)
  {
    printf("No\n");
    return 0;
  }
  memset(cnt,0,sizeof(cnt));
  for (i=0;i<n;i++)
    cnt[a[i]-mi]++;
  if (cnt[1]==0)
  {
    if ((mi+mi<=n)||(mi==n-1))
    {
      printf("Yes\n");
    }
    else
    {
      printf("No\n");
    }
  }
  else
  {
    if (cnt[1]==1)
      printf("No\n");
    else
    {
      tmp=ma-cnt[0];
      if ((tmp>0)&&(tmp+tmp<=cnt[1]))
        printf("Yes\n");
      else printf("No\n");
    }
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>

using namespace std;

int n,m;
string s,t;

int gcd(int a, int b)
{
  if (b == 0) return a;
  return gcd(b, a%b);
}

int main()
{
  cin >> n >> m >> s >> t;
  int64_t d = gcd(n, m);
  int64_t lcm = 1LL * n * m / d;

  unordered_map<int64_t, char> char_map;
  for (int i = 0; i < n; i++) {
    char_map[i*lcm/n+1] = s[i];
  }

  for (int i = 0; i < m; i++) {
    if (char_map.find(i*lcm/m+1) != char_map.end()) {
      if (char_map[i*lcm/m+1] != t[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  cout << lcm << endl;

  return 0;
}


Measured memory_bytes: 4260
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s; cin >> s;
  if(s=="ABC") puts("ARC");
  else puts("ABC");
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdint.h>
#include <iterator>

using namespace std;

int main()
{
  int N;
  std::cin >> N;

  vector<uint32_t> X;
  X.reserve(N);
  
  for (int n=0; n<N; ++n) {
    uint32_t x;
    cin >> x;
    X.push_back(x);
  }

  vector<uint32_t> X_sorted;
  X_sorted.reserve(N);

  copy(X.begin(), X.end(), back_inserter(X_sorted));

  sort(X_sorted.begin(), X_sorted.end());

  for (auto& x : X) {
    auto low = lower_bound(X_sorted.begin(), X_sorted.end(), x);
    int ii = (low-X_sorted.begin());
    cout << ( (ii < (N-1)/2.) ? X_sorted[N/2] : X_sorted[N/2-1] ) << endl;
  }
       
  return 0;
}


Measured memory_bytes: 3712
import numpy as np
x = list(input())
x = [int(y) for y in x]
x = np.array(x)
A = [i % 2 for i in range(len(x))]
A = np.array(A)
B = [(i+1) % 2 for i in range(len(x))]
B = np.array(B)
dA = np.sum((x - A)**2)
dB = np.sum((x - B)**2)
print(min(dA,dB))

Measured memory_bytes: 21572
def main():
    n = int(input())
    xym, xyM, x_ym, x_yM = 10**9, -10**9, 10**9, -10**9
    for _ in range(n):
        x, y = map(int, input().split())
        xy, x_y = x+y, x-y
        xym, xyM, x_ym, x_yM = min(xym, xy), max(xyM, xy), min(x_ym, x_y), max(x_yM, x_y)
    print(max(xyM-xym, x_yM-x_ym))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9148
#include<iostream>
using namespace std;
int mt[16][16][16][16];
int dp[16][16];
int i,j,k,l,m,n,o,a,b,c,d,cnt,X,Y;
void init(){
  for(int i=0;i<16;i++){
    for(int j=0;j<16;j++){
      dp[i][j]=0;
      for(int k=0;k<16;k++){
	for(int l=0;l<16;l++){ 
	  mt[i][j][k][l]=0;
	}
      }
    } 
  }
}
int main(){
  int n;
  cin>>n;
  for(int data=0;data<n;data++){
    init();
    cin>>X>>Y>>m;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>d;
      mt[a][b][c][d]=1;
      mt[c][d][a][b]=1;
    }
    dp[0][0]=1;
    for(int i=1;i<=X;i++){
      if(mt[i][0][i-1][0]==1){
	dp[i][0]=0;
      }else{
	dp[i][0]=dp[i-1][0];
      }
    }

    for(int i=1;i<=Y;i++){

      if(mt[0][i][0][i-1]){
	dp[0][i]=0;
      }else{
	dp[0][i]=dp[0][i-1];
      }

      for(int j=1;j<=X;j++){
	if(mt[j][i][j-1][i]==0){
	  dp[j][i]+=dp[j-1][i];
	}
	if(mt[j][i][j][i-1]==0){
	  dp[j][i]+=dp[j][i-1];
	}
      }
    }
    if(dp[X][Y]==0){
      cout<<"Miserable Hokusai!"<<endl;
    }else{
      cout<<dp[X][Y]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1416
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  ll A, B;
  cin >> A >> B;
  if (1 <= A && A <= 9 && 1 <= B && B <= 9) cout << A*B << endl;
  else cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k, ans = 0;
    cin >> n >> k;
    while(n) {
        ans++;
        n /= k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

def g(num_in):
    num = num_in
    cnt = 0
    if num == 0:
        return 0

    while True:
        base = popcount(num)
        if num%base == 0:
            cnt += 1
            break
        else:
            num = num%base
            cnt += 1
    return cnt


n = int(input())
s = input()

st = 0
for c in s:
    if c == "1":
        st += 1

if st > 1:

    mod_p1 = [0 for i in range(n)]
    mod_n1 = [0 for i in range(n)]
    base1 = 1
    base2 = 1
    for i in range(n):
        t1 = base1%(st+1)
        t2 = base2%(st-1)

        mod_p1[-i-1] = t1
        mod_n1[-i-1] = t2

        base1 *= 2
        base2 *= 2

        base1%=(st+1)
        base2%=(st-1)

    p1 = 0
    n1 = 0
    for i in range(n):
        if s[i] == "1":
            p1 += mod_p1[i]
            n1 += mod_n1[i]

    for i in range(n):
        if s[i] == "0":
            base = p1
            base += mod_p1[i]
            base %= st+1
            print(1+g(base))

        else:
            base = n1
            base -= mod_n1[i]
            base %= st-1
            print(1+g(base))

else:
    mod_p1 = [0 for i in range(n)]
    base1 = 1
    for i in range(n):
        t1 = base1 % (st + 1)

        mod_p1[-i - 1] = t1

        base1 *= 2

        base1 %= (st + 1)

    p1 = 0
    for i in range(n):
        if s[i] == "1":
            p1 += mod_p1[i]

    for i in range(n):
        if s[i] == "0":
            base = p1
            base += mod_p1[i]
            base %= st + 1
            print(1 + g(base))

        else:
            print(0)

Measured memory_bytes: 95580
#include <bits/stdc++.h>
 
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fo(i, a, b, k) for(int i = a; i <= b; i += k)
#define _fo(i, a, b, k) for(int i = a; i >= b; i -= k)
#define foa(i, a) for (auto &i : a)
#define fod(i, a) for(int i = 1; i*i <= a; i++)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  
#define log2i(x) (31-__builtin_clz(x))
#define log2ll(x) (63-__builtin_clzll(x)) 
#define msz(x) __builtin_popcount(x) 
#define mszll(x) __builtin_popcountll(x) 
#define fom(i, a, b) for(int i = a; i < (1<<b); i++)
#define ifon(i, mask) if(mask&(1<<i))
#define ss(i, mask) while(i=(i-mask)&mask)
#define ifss(i, mask) if(i > (mask^i)) 

typedef int64_t ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 1e5+1;
const int MOD = 1e9+7;
const ll INF = INT_MAX;
const ll _INF = INT_MIN;

vi h;

bool solve() {
	int s = sz(h);
	
	if(s == 1) return true;
	fo(i, 0, s-2, 1)
		if(h[i]-h[i+1] > 1) return false;
		
	if(s == 2) return true;
	fo(i, 1, s-2, 1) 
		if(h[i] < h[i-1] && h[i+1] < h[i]) return false;
		
	return true;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, temp = 0;
	
	cin >> n;
	fo(i, 1, n, 1) {
		int val;
		cin >> val;
		if(val != temp) {
			h.pb(val);
			temp = val;	
		} 
	}
	
	if(solve())	cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 892
#include <bits/stdc++.h> 

using namespace std;

int main() {
  string S;

  cin>>S;

  int win = 0, lose = 0;

  for(int i=0; i<S.length(); i++) {
    if(S[i]=='o') {
      win++;
    } else {
      lose++;
    }
  }

  int left;
  left = 15 - S.length();

  if(win+left>=8) {
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h1, m1, h2, m2, k = 0;
	int wakeMin, sleepMin = 0;
	int ans;
	
	scanf("%d", &h1);
	scanf("%d", &m1);
	scanf("%d", &h2);
	scanf("%d", &m2);
	scanf("%d", &k);
	//printf("%d %d %d %d %d %d", h1, m1, h2, m2, k);
	
	wakeMin = 60*h1 + m1;
	sleepMin = 60*h2 + m2;
	
	//printf("%d %d\n", wakeMin, sleepMin);
	ans = (sleepMin - wakeMin) - k;
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
int n, m, s, nxt;
LL a[N << 1], ans;
void mark(int s, int t){
	a[s] ++;
	a[t+1] -= t - s + 2;
	a[t+2] += t - s + 1;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	cin >> s;
	-- s;
	for(int i = 1; i < n; ++ i){
		cin >> nxt;
		-- nxt;
		if(nxt == s);
		else if(nxt > s) mark(s+2, nxt);
		else mark(s+2, nxt+m);
		ans += (nxt - s + m) % m;
		s = nxt;
	}
	for(int i = 1; i < 2*m; ++ i) a[i] += a[i-1];
	for(int i = 1; i < 2*m; ++ i) a[i] += a[i-1];
	for(int i = 0; i < m; ++ i) a[i] += a[i+m];
	cout << ans - *max_element(a, a+m) << endl;
}


Measured memory_bytes: 1792
n,k = map(int,input().split())
mod = 7+10**9

a = [0]*(k+1)

for i in reversed(range(1,k+1)):
    a[i] += pow(k//i, n, mod)
    for j in range(2,k//i+1):
        a[i] -= a[i*j]

ans = 0
for i in range(1,k+1):
    ans += (i*a[i]) % mod

print(ans % mod)

Measured memory_bytes: 74404
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;
ll a[3];
int main(){
	string s;
	cin>>s;
	ll n=s.size();
	for(ll i=0; i<s.size(); i++){
		if(s[i]=='a') a[0]++;
		else if(s[i]=='b') a[1]++;
		else a[2]++;
	}
	sort(a,a+3);
	if(a[0]==0 && a[1]==0 && a[2]==1) cout<<"YES";
	else if(a[0]==0 && a[1]==1 && a[2]==1) cout<<"YES";
	else if(s.size()%3==0){
		if(a[0]==s.size()/3 && a[1]==s.size()/3 && a[2]==s.size()/3) cout<<"YES"<<endl;
		else cout<<"NO";
	}
	else {
		if(a[0]==n/3 && a[1]==(n/3)+1 && a[2]==(n/3)+1){
			cout<<"YES";
		}
		else if(a[0]==n/3 && a[1]==(n/3) && a[2]==(n/3)+1){
			cout<<"YES";
		}
		else cout<<"NO";
	}

}

Measured memory_bytes: 3700
#include <bits/stdc++.h>

using namespace std;

int arr[10];

int n,m,q,ans;
int a[55],b[55],c[55],d[55];

int sc()
{
	int ans=0;
	for(int i=0;i<q;i++)
		if(arr[b[i]]-arr[a[i]]==c[i]) ans+=d[i];
	return ans;
}

void go(int x)
{
	if(x==n) {ans=max(ans,sc()); return;}
	for(int i=arr[x-1];i<=m;i++)
	{
		arr[x]=i;
		go(x+1);
	}
}

int main()
{
	cin >> n >> m >> q;
	for(int i=0;i<q;i++)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	arr[0]=1;
	go(1);
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;
    cout << K * ll(pow((K-1),N-1)) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int antena[5], k;
    for (int i = 0; i < 5; i++)
    {
        cin >> antena[i];
    }

    cin >> k;

    bool flag = true;

    for (int i = 0; i < 5; i++)
    {
        for (int j = i + 1; j < 5; j++)
        {
            if (antena[j] - antena[i] > k)
            {
                flag = false;
                break;
            }
        }
    }

    if (flag)
        cout << "Yay!";
    else
        cout << ":(";
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,k,ans=9e18;
    cin>>n>>k;
    vector<ll>a(n),b(n),x,y;
    for(int i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
        x.push_back(a[i]);
        y.push_back(b[i]);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    for(int x1=0; x1<n; x1++)
    {
        for(int x2=x1+1; x2<n; x2++)
        {
            for(int y1=0; y1<n; y1++)
            {
                for(int y2=y1+1; y2<n; y2++)
                {
                    ll cnt=0;
                    ll lx=x[x1],rx=x[x2];
                    ll ly=y[y1],ry=y[y2];
                    for(int i=0; i<n; i++)
                    {
                        if(a[i]>=lx && a[i]<=rx && b[i]>=ly && b[i]<=ry)
                            cnt++;
                    }
                    if(cnt>=k){
                        ans=min(ans,(rx-lx)*(ry-ly));
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3548
#include<iostream>
#include<cstdio>

using namespace std;

void Q1() {

	double r;
	double PI = 3.141592653589;
	cin >> r;

	printf("%lf %lf\n", PI*r*r, 2 * r*PI);

}

void Q2() {
	int a, b;
	char op;

	while (true)
	{
		cin >> a >> op >> b;
		if (op == '?') { break; }
		else if (op == '+') {
			cout << a + b << endl;
		}
		else if (op == '-') {
			cout << a - b << endl;
		}
		else if (op == '*') {
			cout << a * b << endl;
		}
		else if (op == '/'){
			cout << a / b << endl;
		}
	}
	
}

int main() {
	Q2();

	return 0;
}

Measured memory_bytes: 1160
import collections
N=int(input())
S=list(input())
ans=collections.Counter(S)

for n in range(N-1):
  S=list(input())
  count_S=collections.Counter(S)
  for k in ans.keys():
    if k in count_S.keys():
      if ans[k]>count_S[k]:
        ans[k]=count_S[k]
    else:
      ans[k]=0
A=[chr(i) for i in range(97,97+26)]
anslist=[]
for l in A:
  if l in ans.keys():
    for n in range(ans[l]):
      anslist.append(l)
print(''.join(anslist))


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var s = br.readLine();

      System.out.println(s.contains("AB") || s.contains("BA") ? "Yes" : "No");
    }
  }
}


Measured memory_bytes: 32748
#include <iostream>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
map<string,int> dp;
int direction[]={1,-1,4,-4};
//分别代表右移、左移、下移、上移
void bfs()
{
    queue<string> que;
    que.push("01234567");
    dp["01234567"]=0;
    while(!que.empty()){
        string now=que.front();
        que.pop();
        //p是字符串中0的位置
        int p=0;
        for(int i=0;i<8;i++){
            if(now[i]=='0'){
                p=i;
                break;
            }
        }
        for(int i=0;i<4;i++){
            int n=p+direction[i];
            if(n>=0&&n<8&&!(p==3&&i==0)&&!(p==4&&i==1)){
                //右上角不能向右移、左下角不能向左移
                string next=now;
                swap(next[p],next[n]);
                if(dp.find(next)==dp.end()){
                    //用find函数来定位数据出现位置，它返回的一个迭代器，
                    //当数据出现时，它返回数据所在位置的迭代器，
                    //如果map中没有要查找的数据，它返回的迭代器等于end函数返回的迭代器
                     dp[next]=dp[now]+1;
                    que.push(next);
                }
            }
        }
    }
}
int main()
{
    bfs();
    string s;
    while(getline(cin,s)){
       s.erase(remove(s.begin(),s.end(),' '),s.end());
       cout<<dp[s]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5240
#include<bits/stdc++.h>
using namespace std;
int j=2;
vector<int>v[10005];
int a[10005],b[10005],c[10005],sum[10005],vis[10005];

void dfs(int x)
{
    b[x]=1;
    int len=v[x].size();
    for(int i=0;i<len;i++)
    {
        if(b[v[x][i]])
            continue;
        c[v[x][i]]=a[j];
        j++;
        dfs(v[x][i]);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    int maxx=0;
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        vis[x]++;
        vis[y]++;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int t=1;
    int va=vis[t];
    for(int i=2;i<=n;i++)
    {
        if(vis[i]>va)
        {
            t=i;
            va=vis[i];
        }
    }
    int s=0;
    int su=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        su+=a[i];
        s=max(s,a[i]);
    }
    su-=s;
    sort(a+1,a+1+n,greater<int>());
    dfs(t);
    c[t]=a[1];
    printf("%d\n",su);
    printf("%d",c[1]);
    for(int i=2;i<=n;i++)
    {
        printf(" %d",c[i]);
    }
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    std::cin >> S;

    ll ans   = 0;
    ll W_cnt = 0;
    REP(i, S.size()) {
        if(S[i] == 'W') {
            ans += i - W_cnt;
            W_cnt++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 720
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int sum = 0;
    int q = scan.nextInt();
    int[][] a = new int[q][4];
    for (int i=0;i<q;i++){
      for (int j=0;j<4;j++){
        a[i][j] = scan.nextInt();
      }
    }
    int [] d = new int[n];
    ArrayList<Integer> empty = new ArrayList<Integer>();
    ArrayList<Integer> dd = all(n,m,d,0,1,a,q,empty);

    for (int i=0;i<dd.size();i++){
      if (sum < dd.get(i)){
        sum = dd.get(i);
      }
    }
    System.out.println(sum);
  }

  public static int check(int[][] a, int[] b, int q){
    int sum = 0;
    for (int i=0;i<q;i++){
      int what = b[a[i][1]-1] - b[a[i][0]-1];
      if (what == a[i][2]){
        sum += a[i][3];
      }
    }
    return sum;
  }

  public static ArrayList<Integer> all(int n, int m, int[] a, int current, int k,int[][] gg,int q,ArrayList<Integer> s){
    if (current == n){
      int ww = check(gg,a,q);
      s.add(ww);
      return s;
    }

    for (int i=k;i<=m;i++){
      a[current] = i;
      all(n,m,a,current+1,i,gg,q,s);
      a[current] = 0;
    }

    return s;
  }
}


Measured memory_bytes: 40388
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vector<string> s(n);
    REP(i,n){
        cin>>s.at(i);
        sort(s.at(i).begin(),s.at(i).end());
    }

    sort(s.begin(),s.end());

    i64 sum =0;
    i64 k = 0;
    REP(i,n){
        if( i == 0 || s.at(i-1) != s.at(i) ){
            k = 1;
        } else {
            k += 1;
        }
        if( i == n-1 || s.at(i) != s.at(i+1) ){
            sum += k*(k-1) / 2;
        }
    }


    cout<<sum<<endl;
    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    r = N % 1000
    ans = 0
    if r % 1000 != 0:
        ans = 1000 - r
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9224
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

int w, n;

struct bar {
	int a, b;
};

vector <bar> v;
int order[35];

int main() {
	scanf("%d", &w);
	scanf("%d", &n);
	
	for (int i=0; i<n; i++) {
		bar r;
		scanf("%d, %d", &r.a, &r.b);
		v.push_back(r);
	}
	
	for (int i=1; i<=w; i++) {
		int s = i;
		for (int j=0; j<n; j++) {
			if (v[j].a==s) s = v[j].b;
			else if (v[j].b==s) s = v[j].a;
		}
		order[s] = i;
	}
	
	for (int i=1; i<=w; i++) cout << order[i] << endl;
	
	return 0;
}

Measured memory_bytes: 1224
n=int(input())
arr=[int(i) for i in input().split()]
ans=1
if 0 in arr:
    print(0)
else:
    for i in arr:
        ans=ans*i
        boo=True
        if ans>1000000000000000000:
            print(-1)
            boo=False
            break
    if boo:
        print(ans)


Measured memory_bytes: 21784
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        int s, e;

        cin >> s >> e;
        if (s <= 5) {
            if (s < e) {
                while (s != e) 
                    printf("%d ", s++);
                printf("%d\n", e);
            }
            else {
                while (s != e)
                    printf("%d ", s--);
                printf("%d\n", e);
            }
        }
        else if (s < e) {
            while (s < e) 
                printf("%d ", s++);
            printf("%d\n", e);
        }
        else if (e < s) {
            while (s != 5) {
                printf("%d ", s);
                s = (s + 1) - ((s + 1) / 10) * 5;
            }

            if (e == 5) 
                printf("5\n");
            else {
                printf("5 ");

                s--;
                while (s != e && s != 0)
                    printf("%d ", s--);
                if (s == e)
                    printf("%d\n", e);
                else if (e == 0) {
                    printf("0\n");
                    break;
                }
                else {
                    while (s != e)
                        printf("%d ", s++);
                    printf("%d\n", e);
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1148
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, y;
	cin >> n >> y;
	y /= 1000;

	rep(i, n+1){
		rep(j, n+1){
			if(i+j > n || i*10+j*5 > y) break;
			ll k = n-i-j;
			if(i*10+j*5+k == y){
				cosp(i); cosp(j); co(k);
				return 0;
			}
		}
	}

	cosp(-1); cosp(-1); co(-1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 80

bool dp[MAX + 1][MAX + 1][MAX * 2 * MAX + 1];

signed main(){
    int h,w;
    cin >> h >> w;
    int a[h][w], b[h][w], c[h][w];
    REP(i,h){
        REP(j,w){
            cin >> a[i][j];
        }
    }
    REP(i,h){
        REP(j,w){
            cin >> b[i][j];
            c[i][j] = abs(a[i][j] - b[i][j]);
        }
    }
    dp[0][0][c[0][0]] = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k <= MAX * 2 * MAX; k++){
                if(i - 1 >= 0){
                    dp[i][j][k + c[i][j]] |= dp[i - 1][j][k];
                    dp[i][j][abs(k - c[i][j])] |= dp[i - 1][j][k];
                }
                if(j - 1 >= 0){
                    dp[i][j][k + c[i][j]] |= dp[i][j - 1][k];
                    dp[i][j][abs(k - c[i][j])] |= dp[i][j - 1][k];
                }
            }
        }
    }
    for(int i = 0; i <= MAX * 2 * MAX; i++){
        if(dp[h - 1][w - 1][i]){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 82176
# -*- coding: utf-8 -*-
import sys 
from heapq import heappush, heappop
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

V,E = map(int, readline().split())
edges = [[] for _ in range(V+1)]

INF = 10**31

for _ in range(E):
    x,y,t = map(int, readline().split())
    edges[x].append((t,y))
    edges[y].append((t,x))
    

def dijkstra(q,dist,prev):
    while q:
        cost, v_from = heappop(q)
        if dist[v_from] < cost:
            continue
        for _cost,v_to in edges[v_from]:
            newcost = cost+_cost
            if newcost < dist[v_to]:
                prev[v_to] = v_from
                dist[v_to] = newcost #最短経路用
                heappush(q,(newcost,v_to))

pp = []
for i in range(1,V+1): 
    for j in range(i+1,V+1):
        dist = [INF]*(V+1) #最短距離用
        dist[i] = 0 #最短経路用
        prev=[None]*(V+1) 
        q = [(0,i)]
        dijkstra(q,dist,prev)
        p = [j]
        while prev[p[-1]]!=None:
            x,y = p[-1],prev[p[-1]]
            if x > y:
                x,y = y,x
            pp.append((x,y))
            p.append(prev[p[-1]])

print(E - len(set(pp)))

Measured memory_bytes: 86640
#include <bits/stdc++.h> 
#include <string.h>
using namespace std;  
int main()
{
	string s,s1,x;
	cin>>s;
	cin>>s1;
	x=s1.erase(s1.length()-1);
	if(x==s){
		cout<<"Yes";
	}
	else
	cout<<"No";
    return 0;  
}  

Measured memory_bytes: 3592
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, ma, mb = LI()
src = []
a_max, b_max = 1, 1
for _ in range(n):
    a, b, c = LI()
    src.append((a, b, c))
    a_max += a
    b_max += b

dp = [[[INF] * b_max for _ in range(a_max)] for _ in range(n + 1)]
dp[0][0][0] = 0


for i in range(n):
    ai, bi, ci = src[i]
    for a in range(a_max - ai):
        for b in range(b_max - bi):
            if dp[i][a][b] == INF:
                continue
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)


ans = INF
c = 1
while True:
    a, b = c * ma, c * mb
    if a >= a_max or b >= b_max:
        break
    ans = min(ans, dp[n][a][b])
    c += 1

print(ans if ans != INF else -1)


Measured memory_bytes: 25168
#include<bits/stdc++.h>
using namespace std;

 int main(){
   int N;
   cin>>N;
   vector<char>A(N);
   
   for(int i=0;i<N;i++){
     cin>>A.at(i);
   }
   
   vector<int> sum(4);
   
   for(int i=0;i<N;i++){
     if(A.at(i)=='P'){
       sum.at(0)++;
     }
     else if(A.at(i)=='W'){
       sum.at(1)++;
     }
else if(A.at(i)=='G'){
  sum.at(2)++;
}
     else if(A.at(i)=='Y'){
sum.at(3)++;
     }
   }
   
   int ans=0;
   
   for(int j=0;j<4;j++){
   
   if(sum.at(j)>0){
     ans++;
   }
   }
   
   if(ans==3){
     cout<<"Three"<<endl;
   }
   else{
     cout<<"Four"<<endl;
   }
 }

Measured memory_bytes: 256
#include <iostream>#include <iostream>
using namespace std;


int main(){
    string S, T, U;
    int Snum,Tnum;

    cin >> S >> T;
    cin >> Snum >> Tnum;
    cin >> U;

    if (U==S){
        Snum--;
    }
    else
    {
        Tnum--;
    }
    cout <<Snum << " " << Tnum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int main()
{
    string str,str2;
    int m,h;
    while(getline(cin,str))
    {

        if(!str.compare("-")) break;
        cin>>m;
        while(m--)
        {
            cin>>h;
            getchar();
            for (int i=h; i<str.length(); i++)
            {
                str2+=str[i];
            }
            for(int i=0; i<h; i++)
            {
                str2+=str[i];
            }
            str.clear();
            str=str2;
            str2.clear();
        }
        cout<<str<<endl;
        str.clear();
    }
    return 0;
}





Measured memory_bytes: 3224
n = int(input())
#a,b = map(int, input().split())
w = list(map(int, input().split()))

s1=0
s2=sum(w)
diff = [0]*(n-1)

for i in range(n-1):
  s1+=w[i]
  s2-=w[i]
  diff[i]=abs(s1-s2)

ret=min(diff)


print(ret)

Measured memory_bytes: 3064
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
a = rl()
b = rl()
cnt = 0
for i in range(n):
  ai = a[i]
  bi = b[i]
  if bi > ai:
    cnt += ai
    bi -= ai
    ai1 = a[i+1]
    if bi > ai1:
      cnt += ai1
      a[i+1] = 0
    else:
      a[i+1] -= bi
      cnt += bi
  else:
    cnt += bi
print(cnt)





Measured memory_bytes: 26016
#include    <stdio.h>

int main(void)
{
  int i, x;
  
  i = 1;
  while (1) {
    scanf("%d", &x);
    if (x == 0) break;
    printf("Case %d: %d\n", i, x);
    i++;
  }
  
  return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;

//二分探査
ll INF = 10e9;
ll N, A, B;
vector<ll > vec;

bool check(ll mid){

    //基本的に全員に一様に与えられるダメージ
    ll basic = mid * B;
    //cout << basic << endl;
    //mid人に与えられる追加ダメージ
    ll add = A - B;

    vector<ll > t_vec = vec;

    //撃破できた人数
    ll cn = 0;
    for(ll i = 0; i < N; i++){
        t_vec[i] -= basic;
        if(t_vec[i] <= 0){
            cn++;
            continue;
        }
        //残りの追加ダメージ数が何回必要か
        ll tmp = t_vec[i] / add;
        if(t_vec[i] % add > 0){
            tmp++;
        } 
        //追加ダメージを与えられるか与えられないならfalseを返す
        if(tmp > mid){
            return false;
        }
        //残り追加ダメージ回数を更新
        mid -= tmp;
        //体力を更新
        t_vec[i] -= add * tmp;
        //体力を0似できた人の数を更新
        cn++;
    }

    if(cn == N){
        return true;
    }

    return false;
}

int main(){

    cin >> N >> A >> B;

    for(ll i = 0; i < N; i++){
        ll t = 0;
        cin >> t;
        vec.push_back(t);
    }

    sort(vec.rbegin(), vec.rend());

    //当てはまる中で最小の境界を見つける
    //INFが大きすぎるとオーバーフローの危険性あり
    ll ng = -1; ll ok = INF;

    while(ng + 1 < ok){
        ll mid = (ng + ok) / 2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }

    cout << ok << endl;


}

Measured memory_bytes: 1908
#include<bits/stdc++.h>                                                                                                                
using namespace std;
int p;
int main(){
    int n;
    cin >> n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        cin >> p;
        if(p != i) ++cnt;
    }   
    if(cnt > 2) cout << "NO" << '\n';
    else cout << "YES" << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
const int V = 100001;
int v[N], w[N], n, t;
long long dp[N][V];
long long calc(int idx, int val) {
	if (idx >= n) {
		if (val == 0)
			return 0;
		return 1e18;
	}
	auto &ret = dp[idx][val];
	if (ret != -1)
		return ret;
	ret = min(calc(idx + 1, val - v[idx]) + w[idx], calc(idx + 1, val));
	return ret;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> t;
	long long val = 0;
	for (int i = 0; i < n; ++i) {
		cin >> w[i] >> v[i];
		val += v[i];
	}
	memset(dp, -1, sizeof(dp));
	for (int i = val; i >= 0; --i) {
		long long wt = calc(0, i);
		if (wt <= t) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 79232
stack = []
for x in input().split():
	if x=="+":
		stack.append(str(int(stack.pop()) + int(stack.pop())))
	elif x=="-":
		stack.append(str(- int(stack.pop()) + int(stack.pop())))
	elif x=="*":
		stack.append(str(int(stack.pop()) * int(stack.pop())))
	else:
		stack.append(x)
print(stack.pop())



Measured memory_bytes: 5600
t, x, y = 0, 0, 0
for i in range(int(input())):
	next_t, next_x, next_y = map(int, input().split())
	diff = abs(x - next_x) + abs(y - next_y)
	if diff > (next_t - t) or (diff - (next_t - t)) % 2 == 1:
		print("No")
		exit(0)
	t, x, y = next_t, next_x, next_y
print("Yes")

Measured memory_bytes: 47336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);


    int d,t,s;
    cin >> d >> t >> s;

    if (d <= t * s)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
        
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define V vector
#define P pair
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
 
int main()
{
    sts(s);
    ins(x);ins(y);
    V<int>cntx,cnty;
    int sumx=0,sumy=0;
    bool ansx=false,ansy=false;
    int oldf=0,cnt=0;
    s.PB('T');
    rep(i,s.size()){
        if(s.at(i)=='T'){
            int plus=i-oldf-1;
            if(cnt==0){
                cntx.PB(i);
            }else if(cnt%2){
                cnty.PB(plus);
            }else{
                cntx.PB(plus);
            }
            oldf=i;
            cnt++;
        }
        
    }
    bool dpx[8000][16010],dpy[8000][16010];
    rep(i,8000){
        rep(j,16010){
            dpx[i][j]=false;
            dpy[i][j]=false;
        }
    }
    dpx[0][8000]=true;dpy[0][8000]=true;
    For(i,1,cntx.size()+1){
    	rep(j,16001){
    		if(dpx[i-1][j])dpx[i][j+cntx.at(i-1)]=true;
    		if(dpx[i-1][j]&&i!=1)dpx[i][j-cntx.at(i-1)]=true;
    	}
    }
    
    For(i,1,cnty.size()+1){
    	rep(j,16001){
    		if(dpy[i-1][j])dpy[i][j+cnty.at(i-1)]=true;
    		if(dpy[i-1][j])dpy[i][j-cnty.at(i-1)]=true;
    	}
    }
    Yes(dpx[cntx.size()][x+8000]&&dpy[cnty.size()][y+8000]);
    return 0;
}


Measured memory_bytes: 250496
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    /////////
    int ans = 0;
    for(int i=0;i<1000;++i){
        int a = i/100;
        int c = i%10;
        int b = (i/10)%10;
        int count = 0;
        for(int j=0;j<n;++j){
            if(s[j]==('0'+a)) {
                a=b;b=c;count+=1;
            }
            if(count ==3)break;
            
        }
        if(count==3) ans += 1;
    }
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

const int MAX_N = 1e5 + 5;

int arr [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  string s;
  int K;
  cin >> s >> K;

  int n = s.size();
  for (int i = 0; i < n; i++) {
    arr[i] = s[i] - 'a';
  }

  for (int i = 0; i < n; i++) {
    if (arr[i] != 0 && K >= 26 - arr[i]) {
      K -= 26 - arr[i];
      arr[i] = 0;
    }
  }

  arr[n - 1] += K;
  arr[n - 1] %= 26;

  for (int i = 0; i < n; i++) {
    cout << (char) ('a' + arr[i]);
  }
  cout << endl;
}


Measured memory_bytes: 4124