akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
	int n, cnt = 0;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;

	REP(i, n){
		if(a[i] != b[i] && b[i] != c[i] && a[i] != c[i]) cnt += 2;
		else if (a[i] == b[i] && b[i] == c[i]) continue;
		else cnt++;
	}

	cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
int main() {
	
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int arr[4] = { 0 };

	scanf("%d %d %d", &arr[0], &arr[1], &arr[2]);

	std::sort(arr, arr + 3);

	printf("%d", -arr[0] + arr[2]);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using ll=long long;
using ld=long double;
#define inf INT_MAX  
const ll infll=1ll*inf*inf;
#define mode 998244353
#define mod 1000000007
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ub upper_bound 
#define lb lower_bound 
#define far(i,a,b) for (ll i = a; i <= b; i++)
#define rev(i,a,b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define sz(a) int((a).size())
#define ftr(c,i) for(auto i = begin(c); i != end(c); i++)
#define rtr(c,i) for(auto i = rbegin(c); i != rend(c); i++)
#define pre(c,x) ((c).find(x) != (c).end())
#define cpre(c,x) (find(all(c),x) != (c).end())
#define mll map<ll,ll>
#define vs vector<string>
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vii vector<pii >
#define vll vector<pll >
#define vvl vector<vector<ll> >
#define vvi vector< vector<int > >
#define W(t) while(t --)
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout <<(ll)(it-arr.begin()) << ')' <<  *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->ff<<' '<<it->ss << endl; cout << endl;
#define MID(i,j) ((i)+(j))/2
#define nl '\n' 
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
ll max(ll a,ll b) {return (a>b? a:b);}
ll min(ll a,ll b) {return (a>b? b:a);}
ll gcd(ll a,ll b) {return (b==0)? a:gcd(b,a%b); }
ll gcd(ll a,ll b,ll & x,ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll modinv(ll a,ll b){
	ll x,y;
	gcd(a, b, x, y);
	return (x%b + b)%b;
}
ll ceiling(ll a,ll b){ 
        if(a%b==0) return a/b;
        else return a/b+1;
}
ll bpow(ll a,ll b,ll m){
	a%=m;
	ll res=1;
	while(b>0){
		if(b&1) res=(res*a)%m;
		b>>=1;
		a=a*a%m;
	}
	return res;
}
vvl mat_mul(vvl mat1,vvl mat2,ll mod1){
        vvl res(sz(mat1),vl(sz(mat2[0]),0));
        far(i,0,sz(mat1)-1){
                far(j,0,sz(mat2[0])-1){
                        far(k,0,sz(mat1[0])-1){
                                res[i][j]=(res[i][j]+(mat1[i][k]*mat2[k][j])%mod1)%mod1;          
                        }   
        }   
        }   
        return res;
}
vvl mat_exp(vvl mat,ll p,ll mod1){ 
        vvl res(sz(mat),vl(sz(mat[0]),0));
        far(i,0,sz(mat)-1) res[i][i]=1;
        while(p>0){
                if(p&1) res=mat_mul(res,mat,mod1);   
                mat=mat_mul(mat,mat,mod1);
                p>>=1;
        }   
        return res;
}
const int N=1e6+5;
ll n,m,q,t,k,x,y,z;
map<pair<string,int>,int> rk;
int main()
{
	cin >> n;	
	string s;
	far(i,1,n){
		cin >> s >> x;
		rk[mp(s,-x)]=i;
	}
	ftr(rk,i)
	cout << i->ss << nl;
}


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

typedef long long ll;
typedef vector<ll> vll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};

template<typename DATA>
class Sparse_Segment_Tree{
  public:
    ll n_;
    unordered_map<ll, DATA> lazy2;

    const DATA init;

    Sparse_Segment_Tree(const DATA init) : init(init){
      n_=1;
      return;
    };

    ~Sparse_Segment_Tree(void){
      return;
    };

    inline ll get_hash(ll l, ll r){
      return l*2000000001 + r;
    }

    //[a,b)の範囲に対してxを作用させる
    void rangeupdate2(ll a, ll b, DATA x, ll l, ll r){
      if(a<=l && r<=b){
        chmin(lazy2[get_hash(l,r)], x);
      }else{
        if(a<(l+r)/2) rangeupdate2(a, b, x, l, (l+r)/2);
        if((l+r)/2<b) rangeupdate2(a, b, x, (l+r)/2, r);
      }
      return;
    }

    void rangeupdate2(ll a, ll b, DATA x){
      while(n_<=b) n_<<=1;
      rangeupdate2(a, b, x, 0, n_);
      return;
    }

    DATA pointquery(ll a, ll l, ll r){
      DATA tmp = init;
      if(lazy2.find(get_hash(l,r))!=lazy2.end()) tmp = lazy2[get_hash(l,r)];
      if(r-l<=1) return tmp;
      if(a<(l+r)/2) return min(tmp, pointquery(a, l, (l+r)/2));
      return min(tmp, pointquery(a, (l+r)/2, r));
    };

    DATA pointquery(ll a){
      if(a<0){
        fprintf(stderr, "Segment_Tree Search Space Error\n");
        fprintf(stderr, "Desired:\n");
        fprintf(stderr, "%lld <= %lld\n", 0, a);
        exit(0);
      }else if(n_<=a){
        return 0;
      }
      return pointquery(a, 0, n_);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, Q;
  cin >> N >> Q;

  Sparse_Segment_Tree<ll> que(0);

  ll Shift = 1000000001;

  ll S, T, X;
  REP(i,N){
    cin >> S >> T >> X;
    que.rangeupdate2(S-X+Shift, T-X+Shift, X-Shift);
  }

  ll D;
  REP(i,Q){
    cin >> D;
    ll X = que.pointquery(D+Shift)+Shift;
    if(X==Shift) X=-1;
    cout << X << "\n";
  }

  return 0;
}



Measured memory_bytes: 118096
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int N = S.size();
	vector<int> A;
	for (int i = 0; i < N; i++) {
		if (S[i] != 'x') {
			A.push_back(i);
		}
	}
	int res = 0;
	if (A.size() == 0) {
		res = 0;
	}
	else {
		int l = 0;
		int r = 0;
		if (A.size() % 2 == 0) {
			r = A[(int)A.size() / 2];
			l = A[((int)A.size() / 2) - 1];
		}
		else {
			r = l = A[(int)A.size() / 2];
		}
		while (l >= 0 || r < N) {
			if (l < 0) {
				res++;
				r++;
			}
			else if(r>=N){
				res++;
				l--;
			}
			else {

				if (S[r] == 'x' && S[l] != 'x') {
					res++;
					r++;
				}
				else if (S[r] != 'x' && S[l] == 'x') {
					res++;
					l--;
				}
				else {
					if (S[r] != S[l]) {
						res = -1;
						break;
					}
					else {
						r++;
						l--;
					}
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 1480
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int weight,value,limit;
};

Info info[100];


int main(){

	int N,W;
	scanf("%d %d",&N,&W);

	for(int i = 0; i < N; i++){
		scanf("%d %d %d",&info[i].value,&info[i].weight,&info[i].limit);
	}

	int* dp = new int[W+1];
	dp[0] = 0;
	for(int i = 1; i <= W; i++)dp[i] = -1;

	int num,mult;
	for(int i = 0; i < N; i++){
		num = info[i].limit;
		for(int k = 1; num > 0; k *= 2){
			mult = min(k,num);
			for(int w = W; w-mult*info[i].weight >= 0; w--){
				if(dp[w-mult*info[i].weight] == -1)continue;
				dp[w] = max(dp[w],dp[w-mult*info[i].weight]+mult*info[i].value);
			}
			num -= mult;
		}
	}

	int ans = 0;
	for(int i = 0; i <= W; i++)ans = max(ans,dp[i]);

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 3192
n,x=map(int, input().split())
lst=list(map(int, input().split()))
ms=lst
lst=lst*2
ans=10**15
s=0
for i in range(n):
    s=i*x
    for j in range(n):
        ms[j]=min(ms[j],lst[n+j-i])
        s+=ms[j]
    ans=min(ans,s)
print(ans)

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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
	llin(k);
	llin(a);
	llin(b);
	ll x=0;
	if(b-a>2){
		x=((k-a+1)/2)*(b-a)+a+(k-a+1)%2;
	}else{
		x=k+1;
	}
	sal(x);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);

        if (a < b && b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24108
import math
import sys

def speed(floor):
    N = 5 * floor - 5
    time = math.sqrt(N/4.9)
    return (9.8 * time)

for s in sys.stdin:
    brkSpd = float(s)

    floor = 1

    while brkSpd > speed(floor):
        floor = floor + 1

    print(floor)

Measured memory_bytes: 6824
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#include<bitset>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
struct mo{int a,b,c,d;};
signed  main(){
    int h,w;cin>>h>>w;
    int fi[1144][555];
    rep(i,0,h)rep(j,0,w)cin>>fi[i][j];
    vector<mo>v;
    rep(i,0,h){
        rep(j,0,w){
            if(fi[i][j]%2==1){
                if(j!=w-1){
                  v.push_back(mo{i,j,i,j+1});
                    fi[i][j]--;fi[i][j+1]++;
                }
                else if(i!=h-1){
                    v.push_back(mo{i,j,i+1,j});
                    fi[i][j]--;fi[i+1][j]++;
                }
            }
        }
    }
    cout<<v.size()<<endl;
    rep(i,0,v.size()){
        cout<<v[i].a+1<<" "<<v[i].b+1<<" "<<v[i].c+1<<" "<<v[i].d+1<<endl;
    }return 0;
}

Measured memory_bytes: 10092
from itertools import accumulate
N,K = map(int, input().split())
S = list(map(int, input()))

groups = list()
now = 1
cnt = 0

for s in S:
    if s == now:
        cnt += 1
    else:
        groups.append(cnt)
        now ^= 1
        cnt = 1

groups.append(cnt)

if len(groups) % 2 == 0:
    groups.append(0)

cumsum = [0] + list(accumulate(groups))

Add = 2 * K + 1

ans = 0

for i in range(0,len(groups), 2):
    left = i
    right = min(i + Add, len(groups))
    tmp = cumsum[right] - cumsum[left]

    ans = max(tmp,ans)

print(ans)


Measured memory_bytes: 9376
# ABC079C - Train Ticket
from itertools import product


def main():
    a, b, c, d = input()
    for x, y, z in product(("+", "-"), repeat=3):
        eq = a + x + b + y + c + z + d
        if eval(eq) == 7:
            print(eq + "=7")
            break


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> p(a), q(b), r(c);
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i];
    for (int i = 0; i < c; i++) cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> sum;
    for (int i = 0; i < min(a, x); i++) sum.push_back(p[i]);
    for (int i = 0; i < min(b, y); i++) sum.push_back(q[i]);
    for (int i = 0; i < c; i++) sum.push_back(r[i]);

    sort(sum.begin(), sum.end(), greater<ll>());

    ll ans = 0;
    for (int i = 0; i < x + y; i++) ans += sum[i];

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

Measured memory_bytes: 9820
#include<bits/stdc++.h>
using namespace std;
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int n=read(),k=read();
	(n+1)/2>=k?printf("YES\n"):printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main()
{
	ll n, k, q;
	cin >> n >> k >> q;
	vector<int> a(n, 0);
	rep(i, q)
	{
		ll b;
		cin >> b;
		b--;
		a[b]++;
	}
	rep(i, n)
	{
		if(q-a[i] < k)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    string s; cin >> s;
    string ans;
    ll add = 0;
    ll sub = 0;
    rep(i,n){
        if(s[i]==')'){
            if(sub > 0) sub--;
            else add++;
        }
        else sub++;
    }
    rep(i,add) ans.push_back('(');
    rep(i,n) ans.push_back(s[i]);
    add = 0;
    sub = 0;
    for(ll i=n-1; i>=0; i--){
        if(s[i]=='('){
            if(sub > 0) sub--;
            else add++;
        }
        else sub++;
    }
    rep(i,add) ans.push_back(')');
    cout << ans << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
int n[100010];
signed main(){
	int N,K;
	cin>>N>>K;
	for(int i=0;i<N;i++){
		int a,b;
		cin>>a>>b;
		n[a]+=b;
	}
	for(int i=0;i<=100000;i++){
		if(K-n[i]<=0){
			cout<<i<<endl;
			break;
		}
		else K-=n[i];

	}
	return 0;
}

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

struct data{
    int p,i;
    char s[13];
};
struct data A[105];

int main(){
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i].s>>A[i].p;
        A[i].i=i+1;
    }
    for(int i=1;i<n;i++){
        x=i;
        while(x>0 && strcmp(A[x].s,A[x-1].s)<0){
            swap(A[x],A[x-1]);
            x--;
        }
    }
    int k=0;
    for(int i=0;i<n;i++){
        if(strcmp(A[i].s,A[i+1].s)!=0){
            for(int j=k;j<=i;j++){
                x=j;
                while(x>k && A[x].p>A[x-1].p){
                    swap(A[x],A[x-1]);
                    x--;
                }
            }
            k=i+1;
        }
    }
    for(int i=0;i<n;i++) cout<<A[i].i<<endl;
}

Measured memory_bytes: 256
// AOJ 0549: A Traveler
// 2017.8.31 bal4u@uu
// 2018.2.23

#include <stdio.h>

#define M    100000
#define BigM 1000000000

int s[100003];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, m, i, p1, p2, x, ans;

	n = in(), m = in();
	s[1] = 0; for (i = 2; i <= n; i++) s[i] = s[i-1] + in();
	ans = 0, p1 = 1;
	while (m--) {
		p2 = p1 + in();
		x = s[p2] - s[p1];
		if (x >= 0) ans += x;
		else        ans -= x;
		if (ans >= BigM) ans %= M;
		p1 = p2;
	}
	printf("%d\n", ans % M);
	return 0;
}



Measured memory_bytes: 2100
mod = 10**9+7

def fact(n):
    ans = 1
    for i in range(2,n+1):
        ans *= i
        ans %= mod
    return ans
    
X,Y = list(map(int,input().split()))

# a+2b = X
# 2a+b = Y を解く
# -> a = (2Y-X)/3, b = (2X-Y)/3
# (i+1,j+2) の移動が a 回
# (i+2,j+1) の移動が b 回

a = (2*Y-X)/3
b = (2*X-Y)/3 

if (X+Y)%3 != 0 or a<0 or b<0:
    print(0)
    exit(0)

# a回とb回の移動の組み合わせは (a+b)!/a!b!
print(fact(int(a+b)) * pow(fact(int(a)),mod-2,mod) * pow(fact(int(b)),mod-2,mod) % mod)

Measured memory_bytes: 38512
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define MOD 1000000007

int main(void) {
  int N, M;
  cin >> N >> M;

  VI a(N), b(M);
  int Aappear[N*M];
  int Bappear[N*M];

  // initialize
  for (int i=0; i<N*M; i++) {
    Aappear[i] = 0;
    Bappear[i] = 0;
  }

  long long ans = 1;

  for (int i=0; i<N; i++) {
    cin >> a[i];
    if (Aappear[a[i]-1] != 0) {
      ans = 0;
    }
    Aappear[a[i]-1]++;
  }
  for (int i=0; i<M; i++) {
    cin >> b[i];
    if (Bappear[b[i]-1] != 0) {
      ans = 0;
    }
    Bappear[b[i]-1]++;
  }

  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());

  int Asmaller = 0;
  int Bsmaller = 0;

  if (ans != 0) {
    for (int i=N*M; i>0; i--) {
      if (Aappear[i-1] && Bappear[i-1]) {
        ans *= 1;
      } else if (Aappear[i-1] || Bappear[i-1]) {
        if (Aappear[i-1] == 1) {
          for (int j=Bsmaller; j<M; j++) {
            if(b[j] > i) {
              Bsmaller++;
            } else {
              break;
            }
          }
          ans *= Bsmaller;
        } else if (Bappear[i-1] == 1) {
          for (int j=Asmaller; j<N; j++) {
            if (a[j] > i) {
              Asmaller++;
            } else {
              break;
            }
          }
          ans *= Asmaller;
        }
      } else {
        for (int j=Asmaller; j<N; j++) {
          if (a[j] > i) {
            Asmaller++;
          } else {
            break;
          }
        }
        for (int k=Bsmaller; k<M; k++) {
          if (b[k] > i) {
            Bsmaller++;
          } else {
            break;
          }
        }
        long long count = Asmaller * Bsmaller;
        count -= M*N-i;

        ans *= count;
      }
      ans %= MOD;
    }
  }

  cout << ans << endl;

  return 0;

}


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

int main(void){
	int n;
	cin>>n;
	string s;
	cin>>s;
	bool flag = true;
	if(n%2==0){
		for (int i = 0; i < n/2; ++i)
		{
			if(s[i]!=s[i+n/2]){
				flag = false;
				break;
			}
		}
		if(flag)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;	
	}else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
s=input()
n=len(s)
ans=0
for i in range(2**(n-1)):
    x=[0]*(n-1)
    k=i
    for j in range(n-1):
        x[j]+=k//(2**(n-2-j))
        k-=2**(n-2-j)*(k//(2**(n-2-j)))
    a=s[0]
    for j in range(n-1):
        if x[j]==0:
            a=a+s[j+1]
        else:
            ans+=int(a)
            a=s[j+1]
    ans+=int(a)
print(ans)

Measured memory_bytes: 8884
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
T,A=get_f
H=get_f
INF=Float::INFINITY
t=array(N)
N.times do|i|
    t[i]=T-H[i]*0.006
end
min=INF
ans=-1
N.times do|i|
    val=(A-t[i]).abs
    if min>val
      min=val
      ans=i+1 
    end
end
puts ans

Measured memory_bytes: 1916
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const LL MOD = 1e9 + 7;

LL n, m;
LL mm[MaxN + 5];
int main()
{
	mm[1] = 1;
	for(LL i = 2; i <= 100000; i++)
		mm[i] = (mm[i - 1] * i) % MOD;
	while(scanf("%lld %lld", &n, &m) != EOF)
	{
		if(abs(n - m) > 1) printf("0\n");
		else
		{
			if(n != m) printf("%lld\n", (mm[n] * mm[m]) % MOD);
			else printf("%lld\n", (((mm[n] * mm[m]) % MOD) * 2) % MOD);
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string X;
    cin >> X;
    int cnt = 0;
    int cnt2 = 0;
    for(int i=0;i<X.size();i++){
        cnt2++;
        if(X[i]=='S'){
            cnt++;
        }else{
            // S→Tの場合
            if(cnt){
                cnt--;
                cnt2-=2; // SとT分を消す
            }
        }
    }
    cout << cnt2 << endl;
    return 0;
}

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

int main(){
  int n,m,x;
  cin >>n >>m >>x;
  int a[12][12];
  vector<int> c(n);
  rep(i,n){
    cin >>c[i];
    rep(j,m) cin >>a[i][j];
  }
  int ans = 1001001001;
  rep(s,1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n){
      if(s>>i&1){
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if(d[j]<x) ok = false;
    if(ok) ans = min(ans,cost);
  }
  if(ans==1001001001) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>

//using namespace std;

int main()
{
    uint32_t nn;
    std::string s;
    

    for(int i = 0; i < 3; i++){
        std::cin >> s[i];
    }

    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[0]){
        std::cout << "No" << std::endl;
        return 0;
    }
    std::cout << "Yes" << std::endl;

    return 0;
}

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

using namespace std;

int main() {
    long long a[100000], ans = 1;
    int n, j = -2;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 0) j = 0;
        if (j != 0 && a[i] > 1000000000) j = -1;
    }
    if (j == 0 || j == -1 ) {
        cout << j << endl; 
        return 0;
    }
    for (int i = 0; i < n; i++) {
        ans = ans * a[i];
        if (ans > 1000000000000000000) {
            j = -1;
            break;
        }
    }
    if (j == -1) cout << j << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4412
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var arr = new int[n];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            arr[a - 1]++;
            arr[b - 1]++;
        }
        foreach (var x in arr)
            Console.WriteLine(x);
    }
}

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

main() {
    int ans=0;
    string S; cin >> S;
    rep(i,S.size()){
        if(S[i]=='+')ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int dx[8] = { -1, -1, -1,  0,  0,  1,  1,  1 };
  int dy[8] = { -1,  0,  1, -1,  1, -1,  0,  1 };

  vector< string > map;

  string input;

  for ( int i = 0; i < 8; i++ ) {

    cin >> input;

    map.push_back( input );

  }

  while( true ) {

    bool flag = false;

    for ( int i = 0; i < 2; i++ ) {
      char my, en;
      if ( i == 0 ) {
	my = 'o';
	en = 'x';
      }else {
	my = 'x';
	en = 'o';
      }
      int cnt = 0;
      int cx, cy, dr = 0;
      for ( int y = 0; y < 8; y++ ) {
	for ( int x = 0; x < 8; x++ ) {
	  if ( map[y][x] != '.' ) continue;

	  int cc = 0;
	  int cdr = 0;
	  for ( int j = 0; j < 8; j++ ) {
	    int c = 0;
	    while( true ) {
	      int hx = x+dx[j]*(c+1);
	      int hy = y+dy[j]*(c+1);
	      if ( hx < 0 || hx >= 8 || hy < 0 || hy >= 8 ) break;
	      if ( map[hy][hx] == en ) {
		c++;
		continue;
	      }else if ( map[hy][hx] == my ) {
		cc += c;
		cdr |= ( 1 << j );
	      }
	      break;
	    }
	  }
	  if ( cc == 0 ) continue;
	  if ( cc == cnt ) {
	    if ( i == 0 ) {
	      if ( y > cy ) continue;
	      if ( y == cy && x > cx ) continue;
	    }else {
	      if ( y < cy ) continue;
	      if ( y == cy && x < cx ) continue;
	    }
	  }else if ( cc < cnt ) {
	    continue;
	  }
	  cx = x;
	  cy = y;
	  dr = cdr;
	  cnt = cc;
	}
      }

      if ( cnt > 0 ) {
	flag = true;
	map[cy][cx] = my;
	for ( int j = 0; j < 8; j++ ) {
	  if ( ( dr & ( 1 << j ) ) != 0 ) {
	    for ( int k = 1; true; k++ ) {
	      int hx = cx+dx[j]*k;
	      int hy = cy+dy[j]*k;
	      if ( map[hy][hx] == my ) break;
	      map[hy][hx] = my;
	    }
	  }
	}
      }

    }

    if ( flag == false ) break;

  }

  for ( int i = 0; i < 8; i++ ) {
    cout << map[i] << endl;
  }

  return 0;

}

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

using namespace std;

long long int dp[3002][3002][2];
int arr[3002];
int n;
long long int fun(int i,int j ,int f){
    // cout<<i<<" "<<j<<endl;
    if(i==j){
        if(f==1) return -arr[i];
        else return arr[i];
    }
    
    if(dp[i][j][f]!=-1)return dp[i][j][f];
    
    int kk;
    if(f==1){
        kk=-1;
        return dp[i][j][f]=min(kk*arr[i]+fun(i+1,j,1-f),kk*arr[j]+fun(i,j-1,1-f));
    }else{
        kk=1;
        return dp[i][j][f]=max(kk*arr[i]+fun(i+1,j,1-f),kk*arr[j]+fun(i,j-1,1-f));
    }
    
    return dp[i][j][f]=max(kk*arr[i]+fun(i+1,j,1-f),kk*arr[j]+fun(i,j-1,1-f));
    
    // if(k==0) return 0;
    
    // if(dp[k]!=-1)return dp[k];
    // int ans =0;
    
    // for(int i=0;i<n;i++){
    //     if(arr[i]<=k)ans|=(!fun(k-arr[i]));
    // }
    // // cout<<k<<" "<<ans<<endl;
    // return dp[k]=ans;
    
}

int main(){
    
    cin>>n;
    for(int i=0;i<n;i++)cin>>arr[i+1];
    
    memset(dp,-1,sizeof(dp));    

    cout<<fun(1,n,0)<<endl;
    return 0;
}

Measured memory_bytes: 141312
def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def possibility_check(n, alist):
    alist.sort()

    if n % 2:
        even = [x for x in range(2, n) if x % 2 == 0]
        comp = [0] + even + even
        comp.sort()

    else:
        odd = [x for x in range(1, n) if x % 2 == 1]
        comp = odd + odd
        comp.sort()

    if alist == comp:
        return True
    else:
        return False


def submit():
    n, alist = read_input()

    if possibility_check(n, alist):
        # ans = (2 ** (n // 2)) % (10**9 + 7)
        ans = 1
        for i in range(n // 2):
            ans *= 2
            if ans > 10**9 + 7:
                ans %= (10**9 + 7)
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    submit()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int n;
string s;

bool is_ok(int mid){
	vector<pair<string, int>> v;
	REP(i, n-mid+1){
		v.push_back(make_pair(s.substr(i, mid), i));
	}
	sort(ALL(v));
	int i=n-mid;
	bool res=false;
	while(i>0){
		auto x=v[i];
		string t=x.first;
		int u=x.second;
		while(i>=0 && v[i].first==t){
			--i;
		}
		if(i<n-1 && v[i+1].second+mid<=u){
			res=true;
			break;
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	cin>>n>>s;
	int lb=0, ub=n;
	while(ub-lb>1){
		int mid=(lb+ub)/2;
		if(is_ok(mid)){
			lb=mid;
		}
		else{
			ub=mid;
		}
	}
	cout<<lb<<'\n';
	return 0;
}


Measured memory_bytes: 6588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

  Set<String> set = new HashSet<>();
  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());

      StringBuilder buf = new StringBuilder();
      for(int i=0; i<n; i++)
        buf.append( solve(in.readLine()) ).append('\n');

      System.out.print(buf);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private int solve(String line) {

    if(!set.isEmpty()) set.clear();
    set.add(line);

    int end = line.length();
    String sF,sB,rF,rB;
    StringBuilder buf = new StringBuilder();
    for(int i=1; i<end; i++) {
      sF = line.substring(0,i);
      sB = line.substring(i, end);
      rF = buf.append(sF).reverse().toString();
      buf.setLength(0);
      rB = buf.append(sB).reverse().toString();
      buf.setLength(0);
      set.add(buf.append(sF).append(rB).toString());
      buf.setLength(0);
      set.add(buf.append(rF).append(sB).toString());
      buf.setLength(0);
      set.add(buf.append(rF).append(rB).toString());
      buf.setLength(0);
      set.add(buf.append(sB).append(sF).toString());
      buf.setLength(0);
      set.add(buf.append(sB).append(rF).toString());
      buf.setLength(0);
      set.add(buf.append(rB).append(sF).toString());
      buf.setLength(0);
      set.add(buf.append(rB).append(rF).toString());
      buf.setLength(0);
    }

    return set.size();
  }
}


Measured memory_bytes: 40080
#include <iostream>
#include <cstdlib>
using namespace std;
typedef long long int64;
inline int binary_power(int64 x,int64 n,int64 mod){
	int res=1;
	while (n){
		if (n&1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}
int main(){
	int64 m,n;
	cin >> m >> n;
	cout << binary_power(m,n,1000000007) << endl;
	return 0;
}

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

int main(){
    int f = 0, t = 0;
    
    int n;
    cin >> n;
    
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        if (a % 4 == 0) f++;
        else if (a % 2 == 0) t++;
    }
    
    n -= (t/2) * 2;
    
    if (n/2 <= f) { 
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
	int n = 0;
	int a = 0;
	int b = 0;
	scanf("%d", &n);
	scanf("%d", &a);
	scanf("%d", &b);
	if((a*n)<b){
    	printf("%d",(a*n));
    }else{
    	printf("%d",b);
    }
}

Measured memory_bytes: 128
use proconio::{input, fastout, marker::Usize1};
use std::collections::HashMap;

#[derive(Debug)]
struct UnionFind {
    parent: Vec<usize>,
    rank: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        let mut p = vec![0; n];
        for (i, v) in p.iter_mut().enumerate() {            
            *v = i;
        }
        Self {
            parent: p,
            rank: vec![0; n],
            size: vec![1; n],
        }
    }

    fn root(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            self.parent[x] = self.root(self.parent[x]);
            self.parent[x]
        }
    }

    fn unite(&mut self, a: usize, b:usize) {
        let ra = self.root(a);
        let rb = self.root(b);
        if self.rank[ra] > self.rank[rb] {
            self.parent[rb] = ra;
            self.size[ra] += self.size[rb];
        } else if self.rank[ra] < self.rank[rb] {
            self.parent[ra] = rb;
            self.size[rb] += self.size[ra];
        } else if ra != rb {
            self.parent[rb] = ra;
            self.size[ra] += self.size[rb];
            self.rank[ra] += 1;
        }
    }

    // fn size (&mut self, x: usize) -> usize {
    //     let rx = self.root(x);
    //     self.size[rx]
    // }

    // fn same(&mut self, a: usize, b: usize) -> bool {
    //     self.root(a) == self.root(b)
    // }

}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m]
    }

    let mut uf = UnionFind::new(n);
    for (a, b) in ab {
        uf.unite(a, b);
    }

    let mut map = HashMap::new();

    for i in 0..n {
        *map.entry(uf.root(i)).or_insert(0) += 1;
    }

    let ans = map.iter().map(|(_, &val)| val).max().unwrap();

    println!("{}", ans);
}


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

using namespace std;
const int N=1e6+6;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long A,B,n;
    cin>>A>>B>>n;
    ll ans=0;
    for(int i=0;i<N;i++)
    {
        ll x=(i+1)*B-1;
        if(x>n)
        {
            if(i==0) x=n;
            else break;
        }
        ans=max(ans,A*x/B-i*A);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int>height(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> height[i];
	}
	vector<int>dp(n + 1, 1e9);
	dp[1] = 0;
	dp[2] = abs(height[1] - height[2]);
	for (int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 1] + abs(height[i] - height[i - 1]), dp[i - 2] + abs(height[i - 2] - height[i]));
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    for(int i = 0 ; i < s.length() ; i++){
        s[i] = s[i]+n;
        if(s[i] > 'Z'){
            s[i] -= 26;
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

n = int(input())
a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]

def calc_idx(x, y):
    if x > y:
        x, y = y, x
    return x + y*(y-1)//2

# create graphs & calc indegree
n_game = n * (n-1) // 2
edge = [[] for i in range(n_game)]
indegree = [0] * n_game
for i in range(n):
    for j in range(1, n-1):
        g1 = calc_idx(i, a[i][j-1])
        g2 = calc_idx(i, a[i][j])
        edge[g1].append(g2)
        indegree[g2] += 1


ans = 0
cand = [[i for i in range(n_game) if indegree[i] == 0], []]
cand = deque([(i, 1) for i in range(n_game) if indegree[i] == 0])
n_ts = 0
while cand:
    u, day = cand.popleft()
    ans = max(ans, day)
    n_ts += 1
    for v in edge[u]:
        indegree[v] -= 1
        if indegree[v] == 0:
            cand.append((v, day+1))

if n_ts != n_game:
    ans = -1

print(ans)


Measured memory_bytes: 120368
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N = I()
a = LI()

x = sum(a)//N
y = x + 1

print(min(sum((i-x)**2 for i in a),sum((i-y)**2 for i in a)))


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

string S;
int Q;
deque<char> q;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> S >> Q;
    rep(i, S.size()) q.pb(S[i]);
    bool flag = true;
    while (Q--) {
        int T; cin >> T;
        if (T==1) flag = !(flag);
        else {
            int F; cin >> F;
            char C; cin >> C;
            if (F==1) {
                if (flag) q.push_front(C);
                else q.pb(C);
            }
            else {
                if (flag) q.pb(C);
                else q.push_front(C);
            }
        }
    }
    if (!(flag)) reverse(q.begin(), q.end());
    rep(i, q.size()) cout << q[i];
    cout << endl;
}

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

// Generated by 1.1.6 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()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> P(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &P[i]);
    }
    std::vector<long long> Q(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &Q[i]);
    }

    vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        A[i] = i + 1;
    }

    map<vector<long long>, long long> mp;
    do
    {
        mp[A] = mp.size();
    } while (next_permutation(A.begin(), A.end()));

    long long ans = abs(mp[P] - mp[Q]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

//割られる数：a
//余りを求めるやつ：valid
long long Modinv(long long a, long long valid = INV)
{
	long long b = valid, u = 1, v = 0;
	while (a)
	{
		if (a < b)
		{
			swap(a, b);
			swap(u, v);
		}
		long long t = a / b;
		a -= t * b;
		u -= t * v;
	}
	v %= valid;
	if (v < 0)
		v += valid;
	return v;
}
//rCnの場合
long long int Combination(long long int r, long long int n)
{
	long long int ans = 1;
	long long int div;

	for (int i = 0; i < n; i++)
	{
		ans *= r - i;
		div = i + 1;

		ans = ans % INV * Modinv(div) % INV;
	}

	return ans;
}

void execute()
{
	lint N, K;
	cin >> N >> K;

	if (N - 1 <= K)
	{
		cout << Combination(N * 2 - 1, N) << endl;
		return;
	}
	else
	{
		lint ans = 1;
		vector<lint> human_memo(K + 1);
		vector<lint> empty_memo(K + 1);
		human_memo[0] = 1;
		empty_memo[0] = 1;
		for (int i = 1; i <= K; i++)
		{
			human_memo[i] = human_memo[i - 1] * (N - i) % INV * Modinv(i) % INV;
			human_memo[i] %= INV;
			empty_memo[i] = empty_memo[i - 1] * (N + 1 - i) % INV * Modinv(i) % INV;
			empty_memo[i] %= INV;
			//cout << empty_memo[i] << " " << human_memo[i] << endl;
			//cout << Combination(N, i) << " " << Combination(N - 1, N - 1 - i) << endl;
			ans += empty_memo[i] % INV * human_memo[i] % INV;
			//ans += Combination(N, i) % INV * Combination(N - 1, N - 1 - i) % INV;
			ans %= INV;
		}
		cout << ans << endl;
		return;
	}
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int main() {
	int n, r;
	cin >> n >> r;
	
	int res;
	if (n >= 10) {
		res = r;
	}
	else {
		res = r + 100 * (10 - n);
	}

	cout << res << endl;

	return 0;
}

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int H,W,N;
    cin >> H >> W >> N;

    int bigger = max(H,W);
    cout << (N+bigger-1)/bigger << endl;


}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>

const int maxn=200000;

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

int n,a[maxn+10];
long long ans;

int main()
{
  n=read();
  for(int i=1; i<=n; ++i)
    {
      a[i]=read()-i;
    }
  std::sort(a+1,a+n+1);
  int x=a[(n+1)>>1];
  for(int i=1; i<=n; ++i)
    {
      ans+=abs(x-a[i]);
    }
  printf("%lld\n",ans);
  return 0;
}


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

int main() {
	int a,b,c;
	cin >> a >>b>>c;
	bool found = false;
	for(int i=1;i<=b;++i){
		if((i*a)%b==c) found=true;
	}
	if (found) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def dfs(g, v, i):
    if len(v) == len(g) - 1:
        return 1
    v.add(i)
    c = 0
    for u in g[i]:
        if u not in v:
            c += dfs(g, v, u)
    v.remove(i)
    return c


n, m = map(int, input().split())
tree = [list() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

print(dfs(tree, set(), 0))

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

public class Main {

	public static void main(String[] args) {
		final int N = 100;
		int[] modList = new int[N];
		for (int i = 0; i < N; i++) {
			modList[i] = 0;
			}
	
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str;
			while ((str = br.readLine()) != null) {
				int n = Integer.parseInt(str);
				modList[n-1]++;
				}
			} catch (Exception e) {
				System.out.println(e);
			}
	
		int max = 0;
		for (int i = 0; i < N; i++) {
			if (max < modList[i]) max = modList[i];
			}
		for (int i = 0; i < N; i++) {
			if ( modList[i] == max) System.out.println(i+1);
			}
	}
}



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

int main(){
  long ans=0;
  string ss;
  cin >> ss;
  long s[ss.size()];
  long ssl=stol(ss);
  for(int i=ss.size()-1;i>=0;--i){
    s[i]=ssl%10;
    ssl/=10;
  }
  
  int end=pow(2,ss.size()-1);
  
  long stk=0;
  int k;
  for(int i=0;i<end;++i){
    bitset<9> b=i;
//    cout << b << endl;
    k=0;
    for(int j=0;j<ss.size()-1;++j){
      stk+=s[k];
      if(b[j]){
        ans+=stk;
//        cout << stk << " ";
        stk=0;
      }else{
        stk*=10;
      }
      ++k;
    }
    stk+=s[ss.size()-1];
    ans+=stk;
//    cout << stk << endl;
    stk=0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int N;
LL divs[10000005];
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  LL ans = 0;
  for (int d = 1; d <= N; d++) {
    int cur = d;
    while (cur <= N) {
      divs[cur]++;
      cur += d;
    }
    ans += (LL)d * divs[d];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 81744
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,p[10],m=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i];
        m+=p[i];
    }
    sort(p,p+n);
    cout<<m-p[n-1]/2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  int n,x; cin >> n >> x;
  vector<int> l(n);
  rep(i,n) cin >> l.at(i);

  int d = 0,ans = 1;

  for(int i=0;i<n;i++){
    d+=l.at(i);
    if(d>x) break;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;cin>>S;
  vector<long long>v(26);
  for(int X=0;X<S.size();X++){
    v[S[X]-97]++;
  }
  sort(v.begin(),v.end());
  long long H=0;
  for(int X=25;X>=0;X--){
    if(v[X]>1){
      H+=v[X]*(v[X]-1)/2;
    }
    else{
      break;
    }
  }
  cout<<S.size()*(S.size()-1)/2-H+1<<endl;
}

Measured memory_bytes: 3700
n = gets.to_i
s = gets.chomp

if s.size != n || s.size < 2
  puts "No"
  exit
end

unless s.match(/\A[a-z]+\z/)
  puts "No"
  exit
end

m = s.size / 2 - 1
if s[0..m] == s[m + 1..s.size]
  puts "Yes"
else
  puts "No"
end


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

int main () {
  std::string s; std::cin >> s;
  int p = 0, g = 0, w = 0, l = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'g') {
      if (p < g) ++w, ++p;
      else ++g;
    } else {
      if (p < g) ++p;
      else ++g, ++l;
    }
  }
  std::cout << w - l << "\n";
  return 0;
}

Measured memory_bytes: 512