akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(void)
{
    int n, cnt = 0;
    string s;
    cin >> n >> s;
    rep(i,1000){
        int c[3] = {i/100, (i/10)%10, i%10};
        int e = 0;
        rep(i,n){
            if(c[e]+'0' == s[i]) e++;
        }
        if(e == 3) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
def gauss_jordan(bs):
    rank = 0
    pivot_cols = []
    for col in reversed(range(61)):
        pivot = -1
        for i,row in enumerate(bs[rank:]):
            if row&(1<<col):
                pivot = rank+i
                break
        if pivot < 0: continue
        pivot_cols.append(col)
        bs[pivot],bs[rank] = bs[rank],bs[pivot]
        for i,row in enumerate(bs):
            if i != rank and row&(1<<col):
                bs[i] ^= bs[rank]
        rank += 1
    return bs

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    bs = []
    for a,s in zip(A[::-1],S[::-1]):
        x = a
        for b in bs:
            x = min(x, x^b)
        if x:
            if s=='0':
                bs.append(x)
                bs = gauss_jordan(bs)
            else:
                return 1
    return 0

T = int(input())
for _ in range(T):
    print(solve())

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


#define ll                      long long
#define pii                     pair<int, int>
#define pli                     pair<ll, int>
#define pil                     pair<int, ll>
#define pll                     pair<ll, ll>
#define vi                      vector<int>
#define vll                     vector<ll>
#define vb                      vector<bool>
#define vd                      vector<double>
#define vs                      vector<string>
#define ff                      first
#define ss                      second
#define pb                      push_back
#define eb                      emplace_back
#define ppb                     pop_back
#define pf                      push_front
#define ppf                     pop_front
#define vpii                    vector<pii>
#define vpll                    vector<pll>
#define umap                    unordered_map
#define all(x)                  x.begin(),x.end()
#define clr(a,b)                memset(a,b,sizeof a)
#define fr(i, n)                for(ll i=0; i<n;++i)
#define fr1(i, n)               for(ll i=1; i<=n; ++i)
#define rfr(i, n)                for(ll i=n-1; i>=0; --i)
#define precise(x)              cout<<fixed<<setprecision(x)
#define wh                        while
#define mp                        make_pair
#define le                        length()



ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll lcm(ll a,ll b) 
{ return (a*b)/__gcd(a,b); }

ll power(ll x,ll y,ll p) 
{ ll res=1; x=x%p;
    while(y>0) 
    { if (y&1) res=(res*x)%p; 
      y=y>>1; x=(x*x)%p; } 
    return res; } 
    
bool inside(ll x,ll y,ll n,ll m)
{
    return(x>=0&&x<n&&y>=0&&y<=m);
}   


/*void dfs(int s)
{
        if(vis[s])return;
        
        vis[s]=true;
        nodes++;
        for(auto u:g[s])
        {
            if(!vis[u])
            {
                dfs(u);    
            }        
        }
}*/

void solve()
{    
	ll n;
	cin>>n;
	vector<ll> a(4,0);
	fr(i,n)
	{
		string t;
		cin>>t;
		
		if(t=="AC")
		{
			a[0]++;
		}
		else if(t=="WA")a[1]++;
		else if(t=="TLE")a[2]++;
		else a[3]++;
	}
	
	fr(i,4)
	{
		if(i==0)
		{
			cout<<"AC x "<<a[i]<<endl;
		}
		else if(i==1)
		{
			cout<<"WA x "<<a[1]<<endl;
		}
		else if(i==2)
		{
			cout<<"TLE x "<<a[2]<<endl;
		}
		else
		{
			cout<<"RE x "<<a[3]<<endl;
		}
	}
}

int main()
{
//    int t;
//    cin>>t;
//    wh(t--)
    {
        solve();
    }
    return 0;
}


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

int main()
{
    int n, m, order, a[1000];

    while( cin >> n >> m )
    {
        if( n == 0 && m == 0 )
            break;

        for( int i = 0; i < n; i++ )
            cin >> a[i];

        int j = 0, sum = 0;
        for( int i = 0; i < m; i++ )
        {
            cin >> order;
            if( j < n - 1 )
            {
                j += order;
                
                sum++;

                if( j >= n - 1 );
                else
                {
                    j += a[j];
                    if( j < 0 )
                        j = 0;
                }
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;

const int N=1e5+20;

int n,k,a[N],dp[N];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=2;i<=n;i++)
	{
		dp[i]=INT_MAX;
		for(int j=1;j<=k and i-j>0;j++)
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	}
	printf("%d\n",dp[n]);
}

Measured memory_bytes: 4576
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << "Draw";
        return 0;
    }
    if(a > b && b!=1){
        cout << "Alice";
        return 0;
    }else if(b > a && a !=1){
        cout << "Bob";
        return 0;
    }else if(a ==1){
        cout << "Alice";
        return 0;
    }
    cout << "Bob";
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int left,right;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'A'){
            left = i;
            break;
        }
    }

    for(int i=s.size()-1;i>=0;i--){
        if(s[i] == 'Z'){
            right = i;
            break;
        }
    }

    cout << right - left + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]

p.sort(key=lambda x: x[0])
ans=0
for i in p:
    if i[1] >= m:
        ans += i[0] * m
    else:
        ans += i[0] * i[1]
    m -= i[1]

    if m <= 0:
        break
print(ans)

Measured memory_bytes: 29020
import sys

input = sys.stdin.readline


def main():
    H = int(input())
    W = int(input())
    N = int(input())

    q, r, = divmod(N, max(H, W))
    ans = q
    ans += 1 if r > 0 else 0

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

using P = pair<int, int>;
using LL = long long;

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const int MOD = 1000000007;
const int INF = 1000000000;

int main() {
  IN(N); IN(M);

  vector<int> v[100001];
  REP(i, N) {
    IN(a); IN(b);
    v[a].push_back(b);
  }
  priority_queue<int> q;
  int ans = 0;
  for (int i = M-1; i >= 0; --i) {
    // M日目から初日に向かって探索していく
    // i日目にできる仕事はv[M-i]まで
    // M-1日目にできる仕事はv[1]のみ
    for (const auto& e : v[M-i])
      q.push(e);

    if (q.empty())
      continue;
    int p = q.top(); q.pop();
    ans += p;
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int64_t C(int64_t n, int64_t k) {
	int64_t ret = 1;
	for(int64_t i = 1; i <= k; ++i) {
		ret *= (n + 1 - i);
		ret /= i;
	}
	return ret;
}

int main() {
	string s; cin >> s;
	int sn = s.size();
	int k; cin >> k;
	int64_t ans[sn + 1][k + 1][2] = {};
	ans[0][k][0] = 1;
	for(int i = 1; i <= sn; ++i) {
		int c = s[i - 1] - '0';
		for(int x = 0; x <= k; ++x) {
			ans[i][x][1] += ans[i - 1][x][1];
			if(c == 0) {
				ans[i][x][0] += ans[i - 1][x][0];
			} else {
				ans[i][x][1] += ans[i - 1][x][0];
			}
			for(int j = 1; j <= 9; ++j) {
				if(x + 1 <= k) ans[i][x][1] += ans[i - 1][x + 1][1];
				if(j < c) {
					if(x + 1 <= k) ans[i][x][1] += ans[i - 1][x + 1][0];
				} else if(j == c) {
					if(x + 1 <= k) ans[i][x][0] += ans[i - 1][x + 1][0];
				}
			}
		}
	}
	// for(int i = 0; i <= sn; ++i) {
	// 	for(int j = 0; j <= k; ++j) {
	// 		for(int y = 0; y < 2; ++y) {
	// 			cerr << ans[i][j][y] << '\n';
	// 		}
	// 	}
	// }
	cout << ans[sn][0][0] + ans[sn][0][1] << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e7+100;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    int i,j;
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a<b){
            cout<<"No"<<endl;
            continue;
        }
//        if(a%b>c){
//            cout<<"No"<<endl;
//            continue;
//        }
        if(d-b<0){
            cout<<"No"<<endl;
            continue;
        }
        if(c>=b){
            cout<<"Yes"<<endl;
            continue;
        }
        ll g=gcd(b,d);
        a=a%b;
        ll k=(b-a)/g;
        if((b-a)%g==0) k--;
        if(a+k*g>c){
            cout<<"No"<<endl;
            continue;
        }
        else cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(pair<string,pair<int,int>> a,pair<string,pair<int,int>> b){
	if(a.first!=b.first)
		return a.first<b.first;
	else
		return a.second.second>b.second.second;
}
int main(){
	int n;
	cin>>n;
	pair<string,pair<int,int>> pa[n];
	for(int i=0;i<n;i++)
		cin>>pa[i].first>>pa[i].second.second,pa[i].second.first=i+1;
	sort(pa,pa+n,cmp);
	for(int i=0;i<n;i++)
		cout<<pa[i].second.first<<endl;
	return 0;
}

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

signed main() {
    double L;
    cin >> L;
    auto h = [&](double x, double y, double z) { return x * y * z; };
    auto g = [&](double x, double y) {
        double l = 0.0, r = L - x - y;
        for (int i = 0; i < 100; i++) {
            double ml = (2.0 * l + r) / 3.0, mr = (l + 2.0 * r) / 3.0;
            if (h(x, y, ml) > h(x, y, mr))
                r = mr;
            else
                l = ml;
        }
        return h(x, y, (l + r) / 2);
    };
    auto f = [&](double x) {
        double l = 0.0, r = L - x;
        for (int i = 0; i < 100; i++) {
            double ml = (2.0 * l + r) / 3.0, mr = (l + 2.0 * r) / 3.0;
            if (g(x, ml) > g(x, mr))
                r = mr;
            else
                l = ml;
        }
        return g(x, (l + r) / 2);
    };
    double l = 0.0, r = L;
    for (int i = 0; i < 100; i++){
        double ml = (2.0 * l + r) / 3.0, mr = (l + 2.0 * r) / 3.0;
        if (f(ml) > f(mr))
            r = mr;
        else
            l = ml;
    }
    printf("%.10lf\n", f((l + r) / 2));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
int main()
{IOS;
	int n,k;cin>>n>>k;
	cout<<n+1-k<<endl;
}

Measured memory_bytes: 256
card = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]

A, B = map(int, input().split())
alice = -1
bob = -1
for i in range(13):
    if card[i] == A:
        alice = i
    if card[i] == B:
        bob = i

if alice > bob:
    print('Alice')
elif bob > alice:
    print('Bob')
else:
    print('Draw')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#define mod 1000000007

using namespace std;

int main(void){
	int n;

	cin >> n;

	vector<int> a(n+1);

	for (int i = 1; i < n + 1; i++){
		cin >> a[i];
	}

	int num = 0;

	if (a[1] == 1){
		int t = a[1];
		a[1] = a[2];
		a[2] = t;
		num++;
	}

	for (int i = 2; i < n + 1; i++){
		if (a[i] == i && a[i-1] == i - 1){
			int t = a[i];
			a[i] = a[i-1];
			a[i-1] = t;
			num++;			
		}
	}

	for (int i = 2; i < n + 1; i++){

		if (a[i] == i){
			int t = a[i];
			a[i] = a[i-1];
			a[i-1] = t;
			num++;
		}
	}


	cout << num << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct point{
    int v, w;
    vector<ll> dp; 
    int um;
};

int main() {
    int n ;cin >> n;
    vector<bool> ans(1000001,true);
    vector<bool> kita(1000001,false);
    rep(i,n){
        int s; cin >> s;
        int k = 2;
        if (!kita[s]){
            while (s * k < 1000001){
                ans[s*k] = false;
                k++;
            }
        }
        else {
            ans[s] = false;
        }
        kita[s] = true;
    }
    int an = 0;
    rep(i,1000001){
        if (ans[i] && kita[i]) an++;
    }
    cout << an << endl;
}

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

int main(){
    int k;
    string s,dot=".";
    cin >> k >> s;
    if(s.size()<=k) cout << s << endl;
    else{
        int size = s.size();
        s = s.substr(0,k);
        s = s+"...";
        cout << s << endl;
    }
}

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

typedef long long ll;

int main() {
    int n; cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++) cin >> a[i];

    map <ll, ll> m;
    ll ans = 0;

    for(int i = 0; i < n; i++) m[i - a[i]]++;
    for(int i = 0; i < n; i++) ans += 1ll * m[i + a[i]];
    
    cout << 1ll * ans;
}

Measured memory_bytes: 27792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int ipow(int x, int y)
{
	int z = 1;
	for (int i = 0; i < y; i++) {
		z *= x;
	}

	return z;
}

int next(int* ar, int deg, int value)
{
	int num = 0;
	for (int i = 0; i < deg; i++) {
		ar[i] = value % 2;
		if (value % 2)num++;
		value /= 2;
	}

	return num;
}


int main()
{
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> test(n);
	int* ar = new int[n];
	int count = ipow(2, n);
	int honest;
	pair<int, int> tmp;
	bool contra = false;
	int max = 0;

	for (int i = 0; i < n; i++) {
		int tests;
		cin >> tests;
		for (int j = 0; j < tests; j++) {
			cin >> tmp.first >> tmp.second;
			test[i].emplace_back(tmp);
		}
	}

	//for (int i = 0; i < n; i++) {
	//	for (pair<int, int> p : test[i]) {
	//		printf("[%d,%d] ", p.first, p.second);
	//	}
	//	printf("\n");
	//}

	for (int i = 0; i < count; i++) {
		honest = next(ar, n, i);
		contra = false;
		for (int j = 0; j < n; j++) {
			if (ar[j] == 0)continue;
			for (pair<int, int> p : test[j]) {
				if (ar[p.first - 1] != p.second) {
					//printf("cthrow(%d,%d)\n", p.first, p.second);
					contra = true;
					break;
				}
			}
			if (contra) {
				break;
			}
		}
		if (!contra) {
			max = honest > max ? honest : max;
		}
	}

	printf("%d", max);

	return 0;
}



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

using namespace std;

#define ll long long

int main()
{
	int N;
	cin >> N;
	vector < ll > A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

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

	int minusCount = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] < 0) {
			minusCount++;
      A[i] *= -1;
		}
	}

	if (minusCount % 2 == 0) {
		cout << accumulate(A.begin(), A.end(), (ll)0) << endl;
		return 0;
	}

	ll zeroDiff = LLONG_MAX;
	for (int i = 0; i < N; i++) {
		if (A[i] < zeroDiff) {
			zeroDiff = A[i];
		}
	}

	cout << accumulate(A.begin(), A.end(), (ll)0) - zeroDiff * 2 << endl;

	return 0;
}


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

int main() {
    
    int length[3];
    int a,b,c;
    int n;
    
    cin >> n;
    while(cin >> length[0] >> length[1] >> length[2]) {
        sort(length,length + 3,greater<int>());
        a = length[2] * length[2];
        b = length[1] * length[1];
        c = length[0] * length[0];
        
        if(a + b == c)cout << "YES" << endl;
        else cout<< "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;

  map<string, int> mp;

  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    mp[s]++;
  }

  int mx = 0;

  for(auto p : mp)  mx = max(mx, p.second);
  for(auto p : mp){
    if(p.second != mx)  continue;
    cout << p.first << endl;
  } 

  return 0;

}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	int n,m; cin>>n>>m;
	string s; cin>>s;
	int now = n;
	vector<int> ans;
	while(1){
		int to{now};
		for(int i=1; i<=m; i++){
			if(s.at(now-i)=='0'){
				to = now-i;
				if(to==0) break;
			}
		}
		ans.push_back(now-to);
		if(to == now) {
			cout << -1 << endl;
			return 0;
		}
		if(to == 0) break;
		now = to;
	}
	for(auto it=ans.rbegin(); it!=ans.rend(); it++) cout << *it << (it!=ans.rend()-1?' ':'\n');
	cout << flush;
	
}



Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	char s[h][w];
	REP(i, h){
		REP(j, w){
			cin >> s[i][j];
		}
	}
	REP(i, h){
		REP(j, w){
			if (s[i][j] == '#'){
				if (s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.' && s[i][j+1] == '.'){
					cout << "No" << "\n";
					return 0;
				}
			}
		}
	}
	cout << "Yes" << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <deque>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    string s; cin >> s;
    deque<char> deq;
    for(int i = 0; i < s.size(); i++) deq.push_back(s[i]);
    int q; cin >> q;
    int reverse_cnt = 0;
    while(q--)
    {
        int t; cin >> t;
        if(t == 1)
        {
            reverse_cnt++;
        }
        else
        {
            int f; char c; cin >> f >> c;
            if(f == 1)
            {
                if (reverse_cnt % 2 == 0)
                {
                    deq.push_front(c);
                }
                else
                {
                    deq.push_back(c);
                }
            }
            else
            {
                if(reverse_cnt % 2 == 0)
                {
                    deq.push_back(c);
                }
                else
                {
                    deq.push_front(c);
                }
            }
            
        }
    }
    if(reverse_cnt % 2 != 0)
    {
        reverse(deq.begin(), deq.end());
    }
    string ans = "";
    for(int i = 0; i < deq.size(); i++) ans += deq[i];
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 1368
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i,n){
        long long x,  y;
        cin >> x >> y;
        //cout << x << y << endl;
        long double diff = sqrt((x * x) + (y * y));
        //cout << diff << endl;
        if(diff <= d) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin>>n;

    map<ll,ll> mp;

    for(int i=0;i<n;i++)
    {
        cin>>x;
        mp[x]++;
        sum+=x;
    }

    cin>>q;

    for(int i=0;i<q;i++)
    {
        cin>>x>>y;

        f = y-x;
        c = mp[x];
        sum = sum + (c*f);

        mp[y]+= mp[x];
        mp[x]=0;
        cout<<sum<<endl;
    }




}


Measured memory_bytes: 9436
#include<bits/stdc++.h>
using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // string s;
    // cin>>s;
   	// int flag=1;
    // for(int i=0;i<s.size();++i){
    // 	for(int j=i+1;j<s.size();++j){
    // 		if(s[i]==s[j]){
    // 			flag=0;
    // 			break;
    // 		}
    // 	}
    // }
    // cout<<((flag)?"yes":"no");



    // string s;
    // cin>>s;
    // set<char>c;
    // for(char k:s) c.insert(k);
    // cout<<((s.size()==c.size())?"yes":"no");
    


    // string s;
    // cin>>s;
    // map<char,int>m;
    // for(int i=0;i<s.size();++i){
    // 	if(m[s[i]]>0){
    // 		cout<<"no";
    // 		return 0;
    // 	}
    // 	++m[s[i]];
    // }
    // cout<<"yes";

    // int a,b;
    // cin>>a>>b;
    // int ans=a+b;
    // (ans>=10)?cout<<"error":cout<<ans;
    

    // int n;
    // cin>>n;
    // int a,mx=0,mi=1000;
    // for(int i=0;i<n;++i){
    // 	cin>>a;
    // 	if(mx<a) mx=a;
    // 	if(mi>a) mi=a;
    // }


    // int n;
    // cin>>n;
    // int ar[n];
    // for(int i=0;i<n;++i) cin>>ar[i];
   	// cout<<*max_element(ar,ar+n)-*min_element(ar,ar+n);
    

    // int n,m;
    // cin>>n>>m;
    // n+=2;
    // m+=2;
    // for(int i=0;i<n;++i){
    // 	for(int j=0;j<m;++j){
    // 		if(i==0 || i==n-1 || j==0 || j==m-1) cout<<"#";
    // 		else{
    // 			char c;
    // 			cin>>c;
    // 			cout<<c;
    // 		}
    // 	}
    // 	cout<<'\n';
    // }

    int x,y;
    cin>>x>>y;
    int ar[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    cout<<((ar[x]==ar[y])?"Yes":"No");
    return 0;
}


Measured memory_bytes: 3592
N, M = map(int, input().split())
req = [list(map(int, input().split())) for i in range(M)]
req.sort(key = lambda x:x[1])
last_destroyed = 0
ans = 0
for i in range(M):
    if req[i][0] >= last_destroyed :
        ans += 1
        last_destroyed = req[i][1]
print(ans)

Measured memory_bytes: 29440
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,pre=-1,ans=0,now=0;scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(x<=pre)now++;
		else now=0;
		pre=x,ans=max(ans,now);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll mod = 998244353;

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

    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    vector<vector<ll> > dp(n + 1, vector<ll>(s + 1, 0));

    dp[0][0] = 1;

    REP(i, n) REP(j, s + 1) {
        dp[i + 1][j] += dp[i][j] * 2;
        dp[i + 1][j] %= mod;
        if (j + a[i] <= s) {
            dp[i + 1][j + a[i]] += dp[i][j];
            dp[i + 1][j] %= mod;
        }
    }

    cout << dp[n][s] << '\n';
    return 0;
}


Measured memory_bytes: 73692
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n), B(n);
  rep(i, n) cin >> A[i] >> B[i];
  sort(all(A));
  sort(all(B));
  if(n%2) {
    cout << B[n/2]-A[n/2]+1 << endk;
  } else {
    cout << (B[n/2]+B[n/2-1])-(A[n/2]+A[n/2-1])+1 << endk;
  }
  return 0;
}


Measured memory_bytes: 6360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    string s[H];
    for(int h=0; h<H; h++){
        cin >> s[h];
    }
    
    for(int i=0; i<W+2; i++)
        cout << "#";
    cout << endl;
    
    for(int h=0; h<H; h++){
        cout << "#" << s[h] << "#" << endl;
    }
    
    for(int i=0; i<W+2; i++)
        cout << "#";
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<map>
    #include<deque>
    #include<algorithm>
    #include<string>
    using namespace std;
    #define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
    #define Rep(i,n) REP(i,0,n)
    #define rep(i,n) REP(i,1,n+1)
    typedef long long ll;
     
    int a,b,c;
    int main(){
        cin>>a>>b>>c;
        if(a==b&&b==c){
            cout<<1<<endl;
        }
        else if(a==b || b==c ||c==a){
            cout<<2<<endl;
        }
        else cout<<3<<endl;
        return 0;
    }


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

long long N, M, MIN = 1000000000;
static vector<long long> Fin;
long long Par[1000] = {}, Rank[1000] = {};
bool visited[1000] = {};
static bool Back[1000][1000] = {};
static vector<long long> To[1000];
static vector<long long> V[1000];

void DFS(long long S, long long P, long long R) {
	To[S].push_back(P);
	Rank[P] = R;
	visited[P] = true;
	for (int X : V[P]) {
		if (!visited[X]) {
			Par[X] = P;
			DFS(S, X, R + 1);
		}
	}
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		long long A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back(B);
		Back[B][A] = true;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) visited[j] = false, Par[j] = 0, Rank[j] = 1000000000;
		DFS(i, i, 0);
		long long MINX = 1000000000;
		vector<long long> ANSX = {};
		for (int X : To[i]) {
			if (Back[i][X] && Rank[X] < MINX) {
				MINX = Rank[X];
				vector<long long> ANS;
				while (X != i) {
					ANS.push_back(X);
					X = Par[X];
				}
				ANS.push_back(i);
				ANSX = ANS;
			}
		}
		if (!ANSX.empty()) {
			if (ANSX.size() < MIN) {
				MIN = ANSX.size();
				Fin = ANSX;
			}
		}
	}
	if (Fin.empty()) cout << -1 << endl;
	else {
		reverse(Fin.begin(), Fin.end());
		cout << Fin.size() << endl;
		for (int P : Fin) cout << P + 1 << endl;
	}
}

Measured memory_bytes: 9472
import sys
s = input()
res = True
if s[0] != 'A':
    res = False

cnt = 0
for i in range(2,len(s)-1):
    if s[i] == 'C':
        cnt +=1
    elif s[i].isupper():
        res = False
        
if cnt != 1:
    res = False

if s[1].isupper() or s[-1].isupper():
    res = False

if res:
    print('AC')
else:
    print('WA')



Measured memory_bytes: 3060
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                count += 1

print(count)

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

string s;

inline void rec(ll n) {
    if (n / 26 == 0) {
        char c = 'a' + (n % 26);
        s.push_back(c);
        return ;
    }
    rec(n % 26);
    rec(n / 26 - 1);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
    ll n; cin >> n;
    n--;

    rec(n);
    reverse(s.begin(), s.end());
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<algorithm>
using namespace std;
int seq[3][100005],n,k,i,tot=0,m;
int main()
{
	scanf("%d%d",&n,&m); 
	if(n%2==0)
	{
		for(i=n/2+1;i<=n;i++)
		{
			tot++;
			seq[0][tot]=i;seq[1][tot]=i+n/2;
			seq[2][tot]=2*n-1+2*tot;
		}
		for(i=1;i<=n/2;i++)
		{
			tot++;
			seq[0][tot]=i;seq[1][tot]=i+n+n/2;
			seq[2][tot]=2*n+2*(tot-n/2);
		}
	}
	else
	{
		k=n/2;
		for(i=k+1;i<=n;i++)
		{
			tot++;
			seq[0][tot]=i;seq[1][tot]=2*n+2-2*tot;
			seq[2][tot]=3*n+1-tot;
		}
		for(i=1;i<=k;i++)
		{
			tot++;
			seq[0][tot]=i;seq[1][tot]=2*n+1-2*(tot-k-1);
			seq[2][tot]=3*n+1-tot;
		}
	}
	if(2*m-1>n)
	{
		printf("-1\n");
		return 0;
	}
	for(i=1;i<=n;i++)printf("%d %d %d\n",m-1+seq[0][i],m-1+seq[1][i],m-1+seq[2][i]);
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <functional>

typedef long long ll;


#define V vector


#include <math.h>


typedef long long ll;
using namespace std;


class Solution {
public:
    void solve(int num, std::istream& in, std::ostream& out) {
		int n, m, x; in>>n>>m>>x;

		vector<int> C(n);
		V<V<int>> pr(n);
		V<ll> sum(m);
		for (auto& vt : pr) vt.resize(m);
		int ms = 0;
		for(int i = 0;i < n;i++) {
			in >> C[i]; ms += C[i];
			for (int j = 0; j < m; j++) {
				in >> pr[i][j];
				sum[j] += pr[i][j];
			}
		}
		for (auto t : sum) {
			if (t < x) {
				out << -1; return;
			}
		}
		int M = 1 << n; M--;
		
		for (int s = M; s > 0; s = (s - 1) & M) {
			sum.assign(m, 0);
			int v = 0;
			for (int i = 0; i < n; i++) {
				if (s & (1 << i)) {
					v += C[i];
					for (int j = 0; j < m; j++) {
						sum[j] += pr[i][j];
					}
				}
			}
			if (ms > v) {
				bool ok = true;
				for (int i = 0; i < m; i++) {
					if (sum[i] < x) {
						ok = false; break;
					}
				}
				if (ok) ms = v;
			}
		}

		out << ms;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
	//int T; in >> T;
	//for(int i = 0;i < T;i++)
		//solution.solve(i+1, in, out);
	solution.solve(0, in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int n,x;
    cin>>x>>n;
    int a[n],vis[102];
    memset(vis,0,sizeof(vis));
    int i,j;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        vis[a[i]]=1;
    }
    for(i=x,j=x;;i--,j++)
    {
        if(i<=0 || vis[i]==0)
        {
            cout<<i;
            break;
        }
        if(vis[j]==0)
        {
            cout<<j;
            break;
        }
    }
}

Measured memory_bytes: 3588
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int len = s.size();

    //vector<int> digit_MOD_res(len);
    vector<int> d(len+1);

    int keta = 1;
    d[0] = 0;

    vector<int> count(2019, 0);
    count[0]++;

    for(int i=0; i<len; ++i ){
        int digit = (s[i] - '0');
        //digit_MOD_res[i] = (digit * keta) % 2019;
        //d[i+1] = (d[i] + digit_MOD_res[i]) % 2019;
        int a = (digit * keta) % 2019;
        d[i+1] = (d[i] + a) % 2019;
        keta *= 10;
        keta %= 2019;
        count[d[i+1]]++;
    }

    long long ans =0;
    for(int i=0; i<2019; ++i){
        if(count[i] > 1){
            ans += (count[i] * (count[i]-1) )/2;
        }
    }

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

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
typedef long long lol;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n, sum{0}; cin >> n;
    
    VL a(n);
    REP(i, n)
    {
        cin >> a[i];
        sum += a[i];
        sum %= MOD;
    }
    REP(i, n-1)
    {
        sum = (sum + MOD - a[i])%MOD;
        lol save = a[i]*sum%MOD;
        //cout << save << " ";
        result += save;
        result %= MOD;
    }
    

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4836
n=int(input())
num=0
num2=0
ar=list(map(int,input().split( )))
for i in range(n):
  if(ar[i]%2==0):
    num+=1
    if(ar[i]%3==0 or ar[i]%5==0):
      num2+=1
if(num==num2):
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
template<typename T, int N, T F(const T& a, const T& b)>
struct SegTree
{
public:
    SegTree()
    {
        dat = vector<T>(N * 2 - 1, 0);
    }

    void update(int i, T x)
    {
        i += N - 1;
        dat[i] = x;
        while (i > 0)
        {
            i = (i - 1) / 2;
            dat[i] = F(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = N)
    {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        else
        {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return F(vl, vr);
        }
    }

    vector<T> dat;
};

/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/











//------------------------------------------------------------------------------
ll N, A, B;
ll h[100010];
//------------------------------------------------------------------------------
bool Enough(ll n)
{
    ll need = 0;
    rep(i, 0, N)
    {
        if (((h[i] + n - 1) / n) > B)
        {
            need += (h[i] - (B * n) + (A - B - 1)) / (A - B);
        }
    }
    return need <= n;
}

void _main()
{
    cin >> N >> A >> B;
    rep(i, 0, N) cin >> h[i];

    ll l = 0;
    ll r = 1e14;
    while (r - l > 1)
    {
        ll m = (l + r) / 2;
        if (Enough(m)) r = m;
        else l = m;
    }
    cout << r << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    queue<int> in_point;
    in_point.push(a[n-1]);
    for(int i = n-2; i >= 0; i--) {
        ans += in_point.front();
        in_point.pop();
        in_point.push(a[i]);
        in_point.push(a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4840
#include <stdio.h>
int main()
{
	int N,T,c[1005],t[1005],i,count,x=0;
	scanf("%d%d",&N,&T);
	for(i=0; i<N; i++){
		scanf("%d%d",&c[i],&t[i]);
	}
	count=c[0];
	for(i=0; i<N; i++){
		if(count>=c[i]&&t[i]<=T){
			count=c[i];
			x=i;
		}
	}
	if(t[x]<=T){
		printf("%d\n",count);
	}
	else{
		printf("TLE\n");
	}
	return 0;
}


Measured memory_bytes: 128
import numpy as np
 
n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)
 
cut = np.int_(10000000000000000)
 
def cutsum(array):
    acm = np.int_(0)
    for i in array:
        if acm <= cut:
            acm += i
        else:
            acm = cut
            break
    return(acm)
 
def energy(k):
    nok = n//k
    offset = (n+k)*X
    acm = (n+k)*X + 3*cumsumx[-1] - 2*cumsumx[-k-1]
    acm += 2*cutsum(cumsumx[::-k])
    return(acm)
 
ans = (n+1)*X+2*cutsum(cumsumx)+3*cumsumx[-1]-2*cumsumx[-2]
for j in range (2,min(n//2+4,n+1)):
    tmp = energy(j)
    if tmp < ans:
        ans =tmp
 
print(ans)
 
 
 

Measured memory_bytes: 34796
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;

    int n;
    cin>>n;
    map<string, int> m;
    while(n--){
        string s;
        cin>>s;
        m[s]++;
    }
    for(string s : {"AC","WA","TLE","RE"}) cout<<s<<" x "<<m[s]<<'\n';

    return 0;
}

//cin>>x>>y;
//cout<<a<<b<<'\n';


Measured memory_bytes: 3524
/**
  *  Author: dhruv_gheewala
  *  Problem: E - Red Scarf
  *  Date:   05.09.2020
  *  Time:   16:24:53
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;
    
    #define fundri 108
    #define debug(...) 1729
#endif

#define int int64_t
typedef pair<int, int> pii;
typedef vector<int> vi;

const bool testcases = false;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(), s.end()

// if vector isn't soted then it will remove consecutive same elements
#define make_unique(vec) vec.erase(unique(all(vec)), vec.end())
#define test int TC = 1;if(testcases)cin >> TC;for(int tc = 1 ; tc <= TC ; tc++)solve(), fundri
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})
// clears stdin
#define flush(ch) cin.ignore(std::numeric_limits<std::streamsize>::max(), ch) // default, EOF

int seed; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

inline bool in_range(int a, int l, int r) {return (a >= l && a <= r);}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>bool isPrime(T n) {for(T i = 2; i * i <= n; i++)if(n % i == 0)return false; return n >= 2;}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.ff >> a.ss; return in;}

void solve();
void fast_io();

int32_t main(int32_t argc, char **argv)
{
    fast_io();
    test;
    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vi a(n);
    cin >> a;

    int whole = 0;
    for(int i = 0 ; i < n ; i++)
        whole ^= a[i];

    for(int i = 0 ; i < n ; i++)
        cout << (whole ^ a[i]) << " ";
    cout << endl;
}

void fast_io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

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

#define LL long long
#define LB long double
#define ull unsigned long long
#define x first
#define y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define Pair pair<int,int>
#define pLL pair<LL,LL>
#define pii pair<double,double>

const int INF=2e9;
const LL LINF=2e16;
const int magic=348;
const int MOD=1e9+7;
const double eps=1e-10;
const double pi=acos(-1);

struct fastio
{
	static const int S=1e7;
	char rbuf[S+48],wbuf[S+48];int rpos,wpos,len;
	fastio() {rpos=len=wpos=0;}
	inline char Getchar()
	{
		if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin);
		if (!len) return EOF;
		return rbuf[rpos++];
	}
	template <class T> inline void Get(T &x)
	{
		char ch;bool f;T res;
		while (!isdigit(ch=Getchar()) && ch!='-') {}
		if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
		while (isdigit(ch=Getchar())) res=res*10+ch-'0';
		x=(f?res:-res);
	}
	inline void getstring(char *s)
	{
		char ch;
		while ((ch=Getchar())<=32) {}
		for (;ch>32;ch=Getchar()) *s++=ch;
		*s='\0';
	}
	inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;}
	inline void Writechar(char ch)
	{
		if (wpos==S) flush();
		wbuf[wpos++]=ch;
	}
	template <class T> inline void Print(T x,char ch)
	{
		char s[20];int pt=0;
		if (x==0) s[++pt]='0';
		else
		{
			if (x<0) Writechar('-'),x=-x;
			while (x) s[++pt]='0'+x%10,x/=10;
		}
		while (pt) Writechar(s[pt--]);
		Writechar(ch);
	}
	inline void printstring(char *s)
	{
		int pt=1;
		while (s[pt]!='\0') Writechar(s[pt++]);
	}
}io;

const int MAXN=4000;

inline int add (int x) {if (x>=MOD) x-=MOD;return x;}
inline int sub (int x) {if (x<0) x+=MOD;return x;}

int n,m,k;
int dp[MAXN+48][MAXN+48],sum[MAXN+48][MAXN+48];

int main ()
{
	// freopen ("a.in","r",stdin);
	// freopen ("a.out","w",stdout);
	io.Get(n);io.Get(m);io.Get(k);
	dp[0][0]=1;int ans=0;
	for (register int i=0;i<=m;i++) sum[0][i]=1;
	for (register int i=1;i<=n+m;i++)
		for (register int j=0;j<=m;j++)
		{
			int bd=max(0,j-(k-1));
			dp[i][j]=sub(sum[i-1][j]-(bd?sum[i-1][bd-1]:0));
			sum[i][j]=(j==0?dp[i][j]:add(sum[i][j-1]+dp[i][j]));
			bool ju=false;
			if (j && j%(k-1)==m%(k-1) && (k-1)*i-j>=0 && (k-1)*i-j<=n-1 && ((k-1)*i-j)%(k-1)==(n-1)%(k-1)) ju=true;
			// if (j && j<=m-1 && j%(k-1)==(m-1)%(k-1) && (k-1)*i-j>0 && (k-1)*i-j<=n && ((k-1)*i-j)%(k-1)==n%(k-1)) ju=true;
			if (ju)
			{
				int tmp=sub(dp[i][j]-dp[i-1][j]);
				// cerr<<i<<' '<<j<<' '<<tmp<<endl;
				ans=add(ans+tmp);
			}
		}
	io.Print(ans,'\n');
	io.flush();return 0;
}

Measured memory_bytes: 130816
import sys
sys.setrecursionlimit(10**6)
N, Q = map(int, input().split())
V = [[] for _ in range(N)]
X = [0 for _ in range(N)]
def input():
    return sys.stdin.readline()[:-1]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    V[a].append(b)
    V[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    X[p] += x
# p親、n現在、s合計
def dfs(p, n):
    for i in V[n]:
        if i == p:
            continue
        X[i] += X[n] 
        dfs(n, i)
dfs(-1,0)
print(*X)
        

Measured memory_bytes: 230928
#include<iostream>

using namespace std;

int main() {
	int r, d, x;
	cin >> r >> d >> x;
	
	for (int i = 0; i < 10; i++) {
		int temp = x;
		temp = r*x - d;
		x = temp;
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N,M,X = map(int,input().split()) #整数の入力
a = list(map(int,input().split()))
#検問所の入力
b=[]
c=[]
for i in range(X+1,N): #X+1からNの範囲の整数について 
  if i in a: #ある整数が検問所の整数として存在する
    b.append(1)
for i in range(1,X): #1からX-1の範囲の整数について
  if i in a: #ある整数が検問所の整数として存在する
    c.append(1)
print(min(sum(b),sum(c)))

Measured memory_bytes: 3064
from pprint import pprint
n=int(input())
p=list(map(float,input().split()))
dp=[[0]*(n+1) for _ in range(n+1)]
dp[1][0]=1-p[0]
dp[1][1]=p[0]
for i in range(1,n):
    dp[i+1][0]=dp[i][0]*(1-p[i])
    for j in range(n):
        dp[i+1][j+1]=dp[i][j+1]*(1-p[i])+dp[i][j]*p[i]
print(sum(dp[n][(n//2+1):]))
# pprint(dp)

Measured memory_bytes: 215564
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
int main(){
    for(int i = 1; i <=5; i++) {
	int x;
	cin >> x;
	if(x == 0) cout << i << endl; 
    }
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string str;
char solve[2 * 100005];
int black_sum[2 * 100005];
int white_sum[2 * 100005];

int main()
{
	int n;
	int f = 0;
	int ans = 2 * 100005;

	cin >> n;
	cin >> str;

	for (int i = 0; i < n; i++) {
		black_sum[i + 1] = black_sum[i];
		white_sum[i + 1] = white_sum[i];

		if (str[i] == '#') {
			black_sum[i + 1]++;
		} else {
			white_sum[i + 1]++;
		}
	}

	for (int i = 0; i <= n; i++) {
		ans = min(ans, black_sum[i] + white_sum[n] - white_sum[i]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2180
N = int(input())

#INF = float('inf')

def check(A):
  th = 0 #高さの合計
  for i in range(len(A)):
    b = A[i][0]
    h = A[i][1]
    if th + b < 0:
      return False
    else:
      th += h
  return True
    

L = []
R = []
goukei = 0
for i in range(N):
  temp = str(input())
  b= 0 #最下点
  h = 0 #ゴールの位置
  for j in range(len(temp)):
    if temp[j] == "(":
      h += 1
    else:
      h -= 1
    b = min(b,h)
  if h > 0:
    L.append([b,h])
  else:
    R.append([b-h,-h])
  goukei += h

L.sort(reverse=True)
R.sort(reverse=True)
#print(L,R)

if check(L) and check(R) and goukei == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 186828