akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    string s; cin >> s;
    cout << ((s[2] == s[3] && s[4] == s[5])? "Yes":"No") << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long n, a,b;
		n = s.nextInt();
		a = s.nextInt();
		b = s.nextInt();
		System.out.println(Math.min(n*a,b));
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll x, y; cin >> x >> y;

    ll ans = 1LL << 60;
    if (y >= x) ans = min(ans, y - x);
    if (y >= -x) ans = min(ans, y + x + 1);
    if (-y >= x) ans = min(ans, -y - x + 1);
    if (-y >= -x) ans = min(ans, -y + x + 2);

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i)
const int maxn=3005,mod=1e9+7;
int n,m,dp[maxn][maxn][2];
int main(){
	scanf("%d%d",&m,&n);
	dp[0][0][1]=1;
	REP(i,1,m)dp[0][i][0]=1;
	REP(i,1,n)
		REP(j,0,m)
			REP(k,0,1){
				if(j)(dp[i][j][k|(j==1)]+=dp[i-1][j][k])%=mod;
				if(j<m)(dp[i][j][k|(j==0)]+=dp[i-1][j+1][k])%=mod;
				if(j<m)(dp[i][j][k]+=dp[i-1][j][k])%=mod;
				if(j)(dp[i][j][k]+=dp[i-1][j-1][k])%=mod;
			}
	int ans=0;
	REP(i,0,m)(ans+=dp[n][i][1])%=mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	while(cin>>n,n){
		vector<vint> vv;
		initvv(vv,n,5);
		rep(i,n){
			rep(j,4){
				cin>>vv[i][j];
			}
			vv[i][4]=(vv[i][1]+vv[i][3])*4+vv[i][2]*9;
		}
		vint tt(4);
		rep(i,4){
			cin>>tt[i];
		}
		// tt[4]=(tt[1]+tt[3])*4+tt[2]*9;
		int ans=0;
		vint v;
		rep(i,n){
			bool f=true;
			rep(j,4){
				if(vv[i][j+1]>tt[j]) f=false;
			}
			if(f){
				ans++;
				v.PB(vv[i][0]);
			}
		}
		if(ans==0) cout<<"NA\n";
		else rep(i,v.size()) cout<<v[i]<<endl;

	}
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#ifdef JLOCAL
#include "stress.h"
#endif
using namespace std;

#define rep(i, z, n) for (int i = (z); i < int(n); ++i)
#define repr(i, n, z) for (int i = int(n) - 1; i >= (z); --i)
#define shl(n) (1 << (n))
#define hbit(n, i) (((n) >> (i)) & 1)

#define STRESS 0
using lint = long long;

vector<int> g[111111];
vector<int> db;
vector<int> dw;

void dfs(int v, int p, int d, vector<int>& vd) {
    vd[v] = d;
    for (int i : g[v]) {
        if (i == p) {
            continue;
        }
        dfs(i, v, d + 1, vd);
    }
}

void solve(istream& cin, ostream& cout) {
    int n;
    cin >> n;
    rep(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    db.resize(n);
    dfs(0, -1, 0, db);
    dw.resize(n);
    dfs(n - 1, -1, 0, dw);
    int cb = 0;
    int cw = 0;
    rep(i, 0, n) {
        if (db[i] <= dw[i]) {
            cb++;
        } else {
            cw++;
        }
    }

    if (cb > cw) {
        cout << "Fennec";
    } else {
        cout << "Snuke";
    }
}

int main() {
#if !defined(JLOCAL) || !STRESS
#ifdef JLOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve(cin, cout);
#else
    srand();
    for (int ti = 0; ti < 100; ti++) {
        stress::gen();
        stress::stupid();
        ifstream in("input.txt");
        ofstream out("output.txt");
        solve(in, out);
        out.flush();
        stress::check();
    }
    cout << "ok" << endl;
#endif
    return 0;
}


Measured memory_bytes: 13056
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
	typedef long long ll;
	const int maxn=100050;
	ll po[maxn];
	map<ll,ll>m;
	int main() {
		IOS
		ll i;
		for(i=1;i*i*i*i*i<=1e18;i++){
			m[i*i*i*i*i]=i;
			po[i]=i*i*i*i*i;
		}
		ll n;
		cin>>n;
		ll a,b;
		for(i=0;;i++){
			ll t1=po[i],t2,t3;
			t2=t1-n;//n=t1-t2;
			t3=abs(t2);
			if(m[t3]){//如果t3是个五次幂 
				cout<<i<<" ";
				if(t2>=0)
					cout<<m[t3];
				else
					cout<<-m[t3];
				cout<<endl;
				return 0;
			}
			t1=-po[i];
			t2=t1-n;
			t3=abs(t2);
			if(m[t3]){//如果t3是个五次幂 
				cout<<-i<<" ";
				if(t2>=0)
					cout<<m[t3];
				else
					cout<<-m[t3];
				cout<<endl;
				return 0;
			}
		}
		return 0;
	}

Measured memory_bytes: 3920
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	double a, b;
	double menseki, tubo;
	
	cin >> a >> b;
	
	menseki = a * b;
	
	tubo = menseki / 3.305785;
	
	
	cout << setprecision(6);
	cout << setiosflags(ios::fixed);

	cout << tubo << endl;
	
	return 0;
	
}

Measured memory_bytes: 1280
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int sc() {
		int a=scan.nextInt();
		return a;
	}
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int a=sc();
		int b=sc();
		int c=sc();
		int nokori=a-b;
		System.out.println(c-nokori<0?0:c-nokori);
	}
}

Measured memory_bytes: 21972
import java.util.*;

public class Main{
        public static void main(String[] args){

        int n;
        int x,y,dx,dy;
        int xmax,ymax;
        int d,dmax;

        Scanner kbd=new Scanner(System.in);

        n=kbd.nextInt();
        x=0;
        y=0;
        d=0;

        for(int i=0; i<n; i++){
        dmax=0;
        xmax=0;
        ymax=0;
        while(true){
           dx=kbd.nextInt();
           dy=kbd.nextInt();
           x+=dx;
           y+=dy;
           d=x*x+y*y;
           if(dmax<d){
              dmax=d;
              xmax=x;
              ymax=y;
           } else if(dmax==d){
                if(x>xmax){
                xmax=x;
                ymax=y;
                }
           }
           if(dx==0 && dy==0){
                System.out.println(xmax+" "+ymax);
                break;
                }
           }
        }

        }
}

Measured memory_bytes: 26088
import java.util.*;

public class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        String T = sc.next();

        for ( int i = 0; i < S.length(); i++ ) {
            S = S.substring( S.length() - 1 ) + S.substring( 0, S.length() - 1 );
            //System.out.println( S );
            if( S.equals( T ) )
            {
                System.out.print( "Yes" );
                return;
            }
        }
        System.out.print( "No" );

        sc.close();
    }
}

Measured memory_bytes: 23252
x = input()
stack = []
for xx in x:
    if xx == "T":
        if len(stack) > 0:
            if stack[-1] == "S":
                stack.pop()
            else:
                stack.append(xx)
        else:
            stack.append(xx)
    else:
        stack.append(xx)

print(len(stack))



Measured memory_bytes: 10548
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	ll n;
	cin >> n;
	if (n % 2 == 0) cout << n << endl;
	else cout << 2 * n << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int n;
char s[maxn];
ll ans = 0;
const ll p = 1e9 + 7;
template <class T> void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
ll pw(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % p;
    a = a * a % p, b >>= 1;
  }
  return ret;
}
int main() {
  cin >> s + 1, n = strlen(s + 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1') {
      ans = (ans + pw(2, cnt) * pw(3, n - i)) % p, cnt++;
    }
  }
  ans = (ans + pw(2, cnt)) % p;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    int r,c,r1,c1;
    scanf("%d %d",&r,&c);
    int rc[r+1][c+1];
    for(r1=0;r1<=r;r1++){
        for(c1=0;c1<=c;c1++){
            rc[r1][c1]=0;
        }
    }
    for(r1=0;r1<=r-1;r1++){
        for(c1=0;c1<=c-1;c1++){
                scanf("%d",&rc[r1][c1]);
        }
    }
    for(r1=0;r1<=r-1;r1++){
        for(c1=0;c1<=c-1;c1++){
            rc[r1][c]=rc[r1][c]+rc[r1][c1];
        }
    }
    for(c1=0;c1<=c+1;c1++){
        for(r1=0;r1<=r-1;r1++){
            rc[r][c1]=rc[r][c1]+rc[r1][c1];
        }
    }
    for(r1=0;r1<=r;r1++){
        for(c1=0;c1<=c;c1++){
            printf("%d",rc[r1][c1]);
            if(c1<c)printf(" ");
        }
        printf("\n");
    }
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b;cin >> a >> b;
    cout << max({a+b, a+a-1, b+b-1}) << endl;
    return 0;
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

vector<long long> arr;

bool possible(int pos){
    long long sz = arr[pos];
    for(int i = 0; i < arr.size(); ++i){
        if(i == pos) continue;
        if(arr[i] - sz > sz) return false;
        sz += arr[i];
    }
    return true;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    for(int i = 0; i < n; ++i){
        long long j;
        cin >> j;
        arr.push_back(j);
    }

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

    int left = 0;
    int right = n;

    while(right - left > 1){
        int middle = right + left >> 1;
        if(possible(middle)){
            right = middle;
        } else {
            left = middle;
        }
    }

    if(possible(left)){
        cout << n;
    } else {
        cout << n - left - 1;
    }

    return 0;
}


Measured memory_bytes: 1400
N, M = map(int,input().split())
A = list(-int(i) for i in input().split())
import heapq

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)//(-2)
    heapq.heappush(A,-a)

print(-sum(A))


Measured memory_bytes: 14252
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<tuple>
using namespace std;

int gcd(long long x, long long y)
{
    long long r;
    do {
        r = x % y;
        x = y;
        y = r;
    } while (r != 0);
    
    return x;
}

int abc109_c(){
    // 入力
    long long n,x;
    cin >> n >> x;
    vector<long long> v;
    for (int i=0; i<n; ++i) {
        int a;
        cin >> a;
        v.push_back(abs(a-x));
    }
    long long d = v[0];
    
    //処理
    for(int i=0 ; i<n ; ++i){
        d = gcd(d,v[i]);
    }
    
    //出力
    cout << d << endl;
    return 0;
}

int main() {
    abc109_c();
    return 0;
}


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

sum_a = 0
sum_ab = []
for a, b in ab:
    sum_a += a
    sum_ab.append(a + b)

sum_ab.sort(reverse=True)
for i in range(1, n, 2):
    sum_a -= sum_ab[i]
print(sum_a)

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int main() {
	string s;
	cin >> s;
	if (s[(int) s.size() - 1] == 's') s += "e";
	s += "s";
	cout << s << endl;
	return 0;
}


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

using namespace std;
using ll =long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;

const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){ cin.sync_with_stdio(0);
    ll N; cin >> N;

    vector<pll> more_open, more_close, equal;
    FOR(i, 0, N) {
        string S; cin >> S;

        ll close = 0;
        {
            ll close_open = 0;
            for (const char c : S) {
                if (c == ')') {
                    if (close_open) close_open --;
                    else close ++;
                } else {
                    assert(c == '(');
                    close_open ++;
                }
            }
        }

        ll open = 0;
        {
            ll open_close = 0;
            for (auto it = S.rbegin(); it != S.rend(); it++) {
                const char c = *it;

                if (c == '(') {
                    if (open_close) open_close--;
                    else open ++;
                } else {
                    assert(c == ')');
                    open_close ++;
                }
            }
        }

        if (open > close) {
            more_open.eb(close, open);
        } else if (open < close) {
            more_close.eb(close, open);
        } else {
            equal.eb(close, open);
        }
    }

    sort(all(more_open));
    // sort(more_close.rbegin(), more_close.rend());
    // sort(all(more_close));
    // reverse(all(more_close));
    // sort(all(more_open), [](const pll& a, const pll& b) {
    //         ll adiff = a.xx - a.yy;
    //         ll bdiff = b.xx - b.yy;
    //         return adiff < bdiff;
    //         });

    sort(all(more_close), [](const pll& a, const pll& b) {
            if (a.yy == b.yy) {
                return a.xx < b.xx;
            }
            return a.yy < b.yy;
            });
    reverse(all(more_close));

    ll total_open = 0;

    bool possible = true;

    for (auto &v : {more_open, equal, more_close}) {
        for (auto p : v) {
            ll open, close;
            tie(close, open) = p;

            total_open -= close;
            if (total_open < 0) possible = false;
            total_open += open;
        }
    }

    if (total_open != 0) {
        possible = false;
    }

    if (possible) cout << "Yes" << endl;
    else cout << "No" << endl;


    // Use all with open > close ORDERED BY close ASC (if not possible, it is impossible)
    // Reached max all_open number
    // Use all with open = close;
    // Use all with open < close ORDERED BY open DESC

} //cin.tie(0) bei schnellem Wechseln



Measured memory_bytes: 34688
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

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

    vector<ll> B(N), C(N);
    B[0] = A[0];
    for (ll i = 1; i < N; i++) {
        B[i] = gcd(B[i - 1], A[i]);
    }
    C[N - 1] = A[N - 1];
    for (ll i = N - 2; i >= 0; i--) {
        C[i] = gcd(C[i + 1], A[i]);
    }

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ll p = (i == 0 ? C[i + 1] : i == N - 1 ? B[N - 2] : gcd(B[i - 1], C[i + 1]));
        ans = max(ans, p);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2688
#include <stdio.h>

int main(void)
{
	long long X,K,D,answer,amari;
	scanf("%lld",&X);
	scanf("%lld",&K);
	scanf("%lld",&D);
	if(X<0)X=-1*X;
	if(X/D>K)answer=X-D*K;
	else{
		amari=X%D;
		K-=X/D;
		if(K%2!=0)answer=D-amari;
		else answer=amari;
	}
	printf("%lld",answer);
	return 0;
}

Measured memory_bytes: 1736
import collections

N = int(input())

l = list()
for i in range(N):
    l.append(int(input()))

c = collections.Counter(l)

la = list(c.values())
M = len(la)
ans = 0
for i in range(M):
    if la[i] % 2 == 1:
        ans += 1

print(ans)

Measured memory_bytes: 62296
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll f(vector<ll> &v1, ll p){
  vector<ll> v;
  rep(i,0,v1.sz){
    v.pb(v1[i]);
  }
  long long index = 0;
  for(long long i = 62; i >= 0; i--){
    long long flag = 0;
    for(long long j=index;j<v.sz;j++){
      if(v[j]&(1LL<<i)){
        flag = 1;
        swap(v[index],v[j]);
        break;
      }
    }
    for(long long j=index+1;j<v.sz;j++){
      if(v[j]&(1LL<<i)){
        v[j]^=v[index];
      }
    }
    if(flag==1){
      index++;
    }
  }
  index = 0;
  for(long long i = 62;i >= 0; i--){
    if(index==v.sz)break; 
    if((v[index]&(1LL<<i))!=0&&(p&(1LL<<i))==0){
      index++;
    }
    else if((v[index]&(1LL<<i))!=0&&(p&(1LL<<i))!=0){
      p ^= v[index];
      index++;
    }
  }
  if(p==0)return 1;
  return 0;
}

int main(){
  ll T;
  cin>>T;
  rep(tt,0,T){
    ll n;
    cin>>n;
    vector<ll> v;
    rep(i,0,n){
      ll a;
      cin>>a;
      v.pb(a);
    }
    string s;
    cin>>s;
    reverse(all(v));
    reverse(all(s));
    ll flag = 1;
    vector<ll> v1;
    rep(i,0,n){
      if(s[i]=='0'){
        v1.pb(v[i]);
      }
      else{
        if(f(v1,v[i])==0)flag=0;
      }
    }
    if(flag==1){
      cout << 0 << endl;
    }
    else{
      cout << 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3628
class Factorial:
    def __init__(self, n, mod):
        self.f = [1]
        self.mod = mod
        for j in range(1, n + 1):
            self.f.append(self.f[-1] * j % mod)
        self.i = [pow(self.f[-1], mod - 2, mod)]
        for j in range(n, 0, -1):
            self.i.append(self.i[-1] * j % mod)
        self.i.reverse()
    def factorial(self, j):
        return self.f[j]
    def ifactorial(self, j):
        return self.i[j]
    def comb(self, n, k):
        return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0



K = int(input())
S = list(input())
s = len(S)

N = K + s

MOD = 10 ** 9 + 7

C = Factorial(N + 10, MOD)

lst26 = [1] * (K + 2)
lst25 = [1] * (K + 2)
for i in range(K + 1):
    lst26[i + 1] = (lst26[i] * 26) % MOD
    lst25[i + 1] = (lst25[i] * 25) % MOD

ans = 0
for x in range(K + 1):
    tmp = ((C.factorial(s - 1 + K - x) * C.ifactorial(s - 1)) % MOD) * C.ifactorial(K - x)
    tmp %= MOD
    tmp = (tmp * lst26[x]) % MOD
    tmp = (tmp * lst25[K - x]) % MOD
    ans = (ans + tmp) % MOD

print (ans)    



Measured memory_bytes: 227924
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a;
  b=a/1000;
  a=a%1000;
  c=a/100;
  a=a%100;
  d=a/10;
  a=a%10;
  if(b==c || c==d ||d==a)
    cout<<"Bad"<<'\n';
  else
    cout<<"Good"<<'\n';
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;
constexpr ll MOD = 1000000007;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

#define rep(i, N) for(ll i=0; i<(N); ++i)

template<class T> inline bool chmax(T& a, T b) { if(a < b) { a = b; return 1; } else { return 0; }}
template<class T> inline bool chmin(T& a, T b) { if(a > b) { a = b; return 1; } else { return 0; }}


ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

template<typename T> inline string toString(const T &a) {
  ostringstream oss; oss << a; return oss.str();
}

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

/*
* 積が負になる数: 負数 * 正数
* 積が正になる数: 正数 * 正数 or 負数 * 負数
* 答えが0になる数: 0 * 何でも
*/

ll repeatSquaring(ll n, ll p, ll mod) {
  if(p == 0) return 1;
  if(p % 2 == 0) {
    ll t = repeatSquaring(n, p / 2, mod);
    return t * t % mod;
  } else {
    return (n * repeatSquaring(n, p - 1, mod)) % mod;
  }
}

ll comb(ll n, ll k, ll mod) {
  //分子
  ll res = 1;
  rep(i, k) res = res * (n - i) % mod;
  
  //分母（逆数にする前）
  ll bunbo = 1;
  rep(i, k) bunbo = bunbo * (k - i) % mod;
  
  res = (res * repeatSquaring(bunbo, mod - 2, mod)) % mod;
  return res;
}

int main() {
  int N, K;
  
  cin >> N >> K;
  
  COMinit();
  
  for(int i = 1; i <= K; ++i) {
    ll res = COM(K - 1, i - 1) * COM((i+1)+(N-K-(i-1))-1, N-K-(i-1)) % MOD;
    cout << res << endl;
  }
}

//1 4 4 6 7 9
/*
int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  
  //まず，正，0，負になるペアの個数を数える
  int posct = 0;
  int zeroct = 0;
  int negct = 0;
  rep(i, N) {
    if(A[i] < 0)  ++negct;
    if(A[i] == 0) ++zeroct;
    if(A[i] > 0)  ++posct;
  }
  
  //各符号の組
  int pos_pairct = (posct * posct - posct) / 2 + (negct * negct - negct) / 2;
  int neg_pairct = negct * posct;
  int zero_pairct = (zeroct * zeroct - zeroct) / 2 + (posct * zeroct + negct * zeroct);
  
  sort(A.begin(), A.end());
  
  //順番を区別していったん数えることにする
  //同じインデックス同士は掛けないが，別のインデックスで同じ数なら掛ける
  if(K <= neg_pairct) {
    //負の領域
    //負 * 正 で二分探索
    //負を全部正にして，全部ソートすれば良いのか．筆はなくて生徒みなせばよい．順番が逆になるくらいか
    // int mid = neg_pairct / 2;
    // while(true) {
    //   if(A) 
    // }
  } else if(K <= neg_pairct + zero_pairct) {
    //ゼロの領域
    cout << 0 << endl;
    return 0;
  } else {
    //正の領域
    //昇順
    
    //二分探索で解いてみる    
    int beginIndex = -1;
    rep(i, N) {
      if(A[i] > 0) beginIndex = i;
    }
    int endIndex = N - 1;
    
    int mid = (endIndex - beginIndex) / 2 + beginIndex;
    while(true) {
       
    }
    
  }
}
*/

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    cout << n * n * n << ENDL;
}

Measured memory_bytes: 256
X, N = map(int, input().split())

if N == 0:
  print(X)
  exit()

P = list(map(int, input().split()))
i = 0
while True:
  l = X - i
  r = X + i 
  if X - i not in P:
    print(X-i)
    exit()
  elif X + i not in P:
    print(X + i)
    exit()
  i += 1

Measured memory_bytes: 9188
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! all_enumerate {
  ($e:expr, $s:expr) => {
    format!("{}",$e.iter().map(|&elem| elem.to_string()).collect::<Vec<String>>().join($s))
  }
}

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

fn merge(vec: &mut Vec<i32>, left: usize, mid: usize, right: usize, cmp_n: &mut i32) {
  let n1 = mid - left;
  let n2 = right - mid;
  let mut l = Vec::with_capacity(n1 + 1);
  let mut r = Vec::with_capacity(n2 + 1);
  for i in 0..n1 {
    l.push(vec[left + i]);
  }
  for i in 0..n2 {
    r.push(vec[mid + i]);
  }
  l.push(std::i32::MAX);
  r.push(std::i32::MAX);
  let (mut i, mut j) = (0, 0);
  for k in left..right {
    *cmp_n += 1;
    if l[i] <= r[j] {
      vec[k] = l[i];
      i += 1;
    }
    else {
      vec[k] = r[j];
      j += 1;
    }
  }
}

fn merge_sort(vec: &mut Vec<i32>, left: usize, right: usize, cmp_n: &mut i32) {
  if left + 1 < right {
    let mid = (left + right) / 2;
    merge_sort(vec, left, mid, cmp_n);
    merge_sort(vec, mid, right, cmp_n);
    merge(vec, left, mid, right, cmp_n);
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let n = scan!(sc; usize);
  let mut s = scan!(sc => n; i32);
  let mut cmp_n = 0;
  merge_sort(&mut s, 0, n, &mut cmp_n);
  println!("{}", all_enumerate!(s, " "));
  println!("{}", cmp_n);
}



Measured memory_bytes: 37772
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;

signed main(){
    ll n,memo = LINF,memo_i,memo_j,memo_k;
    cin >> n;
    rep(i,1,3500){
        rep(j,1,3500){
            if(4*i*j - n*j -n*i > 0 && n*i*j % (4*i*j - n*j -n*i) == 0){
                ll x = n*i*j / (4*i*j - n*j -n*i);
                
                if(4*i*j*x == (i*x+j*x+i*j)*n && memo > max(i,max(j, x))){
                    memo = max(i,max(j, x));
                    memo_i = i;
                    memo_j = j;
                    memo_k = x;
                }
            }
        }
    }

    cout << memo_i << " " << memo_j << " " << memo_k << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

c = 0
f = False
while True:
	for i in range(n):
		if(a[i] % 2 == 0):
			a[i] /= 2
			c += 1
			f = True
	if f:
		f = False
	else:
		break

print(c)

Measured memory_bytes: 4212
def selection_sort
  @N.times do |i|
    minj = i
    i.upto (@N-1) do |j|
      minj = j  if @A[j] < @A[minj]
    end
    if @A[i] != @A[minj]
      @A[i], @A[minj] = @A[minj], @A[i]
      @count += 1
    end
  end
end



@count = 0
@N = gets.to_i
@A = gets.split(" ").map{|x| x.to_i}

selection_sort

@A.each_with_index do |x, i|
  print x
  print i == @N-1 ? "\n" : " "
end
puts @count



Measured memory_bytes: 6872
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define all(x) (x).begin(), (x).end()

int main() {
    int n, p;
    string str;
    cin >> n >> p >> str;
    deque<char> s(all(str));
    ll ans = 0;
    if(p == 2) {
        rep(i, n) {
            if((s[i]-'0')%2 == 0) {
                ans += i+1;
            }
        }
    } else if (p == 5) {
        rep(i, n) {
            if((s[i]-'0')%5 == 0) {
                ans += i+1;
            }
        }
    } else {
        map<int, int> mp;
        mp[0]++;
        int t=0, r=1;
        for(int i=n-1; i>=0; --i) {
            t=(t+(s[i]-'0')*r)%p;
            ans+=mp[t];
            mp[t]++;
            r=r*10%p;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1028
n = int(input())
a = list(map(int, input().split()))

x_2 = 0
for i in range(n):
    if i % 2:
        x_2 -= a[i]
    else:
        x_2 += a[i]

ans = [0 for _ in range(n)]
for j in range(n):
    if j == 0:
        ans[j] = x_2 // 2
    else:
        ans[j] = a[j - 1] - ans[j - 1]

print(*[a * 2 for a in ans])


Measured memory_bytes: 16968
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;




int N, M;  //N頂点M辺
vector<int> visited;
vector<vector<int>> G;
ll ans=0,kk=0;

void dfs(int now){
    visited[now] = 1;
    kk++;
    for(int next : G[now]){
        if(!visited[next]){dfs(next);}
    }
}


int main() {
    cin >> N >> M;
    G = vector<vector<int>>(N); // サイズを確保する
    visited = vector<int>(N, 0); // 全頂点を「未訪問」に初期化
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        // 頂点番号を 0-indexed とする
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i,N){
    kk=0;
    if(!visited[i])dfs(i);
    chmax(ans,kk);
    }
    cout << ans <<endl;

}


Measured memory_bytes: 21044
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 10010020030040056ll;
const int INF = 1001001001;
const double pi = acos(-1);

void MergeSort(vector<int> &a, int left, int right)
{
    if (right - left == 1)
        return;

    int mid = (right + left) / 2;
    MergeSort(a, left, mid);
    MergeSort(a, mid, right);
    int i = left;
    int j = mid;
    vector<int> tmp;
    while (true)
    {
        if (i == mid && j == right)
        {
            break;
        }
        else if (i == mid)
        {
            tmp.push_back(a.at(j));
            j++;
            continue;
        }
        else if (j == right)
        {
            tmp.push_back(a.at(i));
            i++;
            continue;
        }
        if (a[i] <= a[j])
        {
            tmp.push_back(a.at(i));
            i++;
        }
        else
        {
            tmp.push_back(a.at(j));
            j++;
        }
    }
    for (int i1 = left; i1 < right; i1++)
    {
        a.at(i1) = tmp.at(i1 - left);
    }
}

int main()
{
    int k;
    cin >> k;
    ll tmp = 7;
    for (int i = 1; i <= k + 1; i++)
    {
        if (tmp % k == 0)
        {
            cout << i << endl;
            return 0;
        }
        tmp = tmp * 10 + 7;
        tmp %= k;
    }
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3588
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

const INF=2<<32
function main()
    n::Int,k::Int=parseMap(split(readline()))
    h::Vector{Int}=parseMap(split(readline()))
    dp::Vector{Int}=fill(INF,100010)
    dp[1]=0
    for i in 1:n-1
        for j in 1:k
            if i+j>n
                break
            end
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
        end
    end
    println(dp[n])
end
main()

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

using namespace std;
int main()
{
    //freopen("output.txt","w",stdout);
    int n,x;
    cin >> n >> x;
    vector<int> arr(n);
    for(int i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    sort(arr.begin(),arr.end());
    int ss = 0;
    for(int i = 0;i < n;i++)
    {
        x -= arr[i];
        if(x < 0)
            break;
        ss++;
    }
    if(ss == n)
    {
        if(x == 0)
            cout << ss;
        else
            cout << ss-1;
    } else cout << ss;
}


Measured memory_bytes: 256
module Main where

--import Utils
import Control.Applicative

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  { [a, b] <- getInts
  ; putStrLn (unwords (map show [a * b, 2 * (a + b)]))
  }
  



Measured memory_bytes: 3656
/* ex3_4
   kohei_suzuki */

#include <stdio.h>

int main(void){
    int seki, div=9 ; //割られる整数sekiと割る整数div

    scanf("%d",&seki); //sekiを入力

    int quot; //sekiをdivで割った整数quot

    while(seki % div != 0){ //9から順に1ずつ割っていき、割り切れるまで繰り返す
        div -= 1;
        quot = seki / div;
    }

    if(quot < 10){ //割り切れてかつlが10より小さければyes
        printf("Yes\n");
    }else{ //それ以外ならno
        printf("No\n");
    }

    return 0;
}

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

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

const int INF = 1e9;
const int MAX = 1e5;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  string s;
  cin >> N >> s;

  int r = 0, b = 0;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'R') r++;
    else b++;
  }

  cout << (r > b ? "Yes" : "No") << endl;
  return 0;
}


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

int main(){
    int n; ll a, b;
    cin >> n >> a >> b;
    ll x[n];
    rep(i,n) cin >> x[i];
    ll ans = 0;
    rep(i,n-1){
        ll l = x[i+1] - x[i];
        if(l*a < b) ans += l*a;
        else ans += b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif


using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int MX = 500005;

int N, Q;
int bit[MX], A[MX], pos[MX];

void upd(int i, int v){
    for(; i <= N; i += i & -i)
        bit[i] += v;
}

int qry(int i){
    int s = 0;
    for(; i; i -= i & -i)
        s +=  bit[i];
    return s;
}

struct query{
    int l, r, i, a;
};

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
    
    cin >> N >> Q;
    rep1(i, N)
        cin >> A[i];

    vector<query> qs(Q);
    rep(i, Q){
        int l, r;
        cin >> l >> r;
        qs[i] = query{l, r, i, 0};
    }

    sort(all(qs), [](query& a, query& b){ return a.r < b.r;});

    int cur = 0;
    rep1(i, N){
        debug(A[i], i);
        if(pos[A[i]])
            upd(pos[A[i]], -1);
        debug(A[i]);
        pos[A[i]] = i;
        upd(pos[A[i]], 1);
        for(; cur < Q && qs[cur].r == i; cur++)
            qs[cur].a = qry(qs[cur].r) - qry(qs[cur].l - 1);
    }

    sort(all(qs), [](query& a, query& b){ return a.i < b.i;});

    rep(i, Q)
        cout << qs[i].a << '\n';

    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}


Measured memory_bytes: 17480
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 998244353 
#define int long long
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000005
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define PI M_PI
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}

int dp[10000005];
void solve()
{  
   for(int i=1;i<=10000000;i++)dp[i]=1;
   for(int i=2;i<=10000000;i++)
   {
       for(int j=i;j<=10000000;j+=i)
       dp[j]++;
   }
   int n,ans=0;cin>>n;
   for(int i=1;i<=n;i++)
   ans+=(i*dp[i]);
   cout<<ans;
}

signed main()
{ 
    boost
    int test=0,t;
    //cin >> t ;
    t=1;
   while(test++ <t){
	  //cout<<"Case #"<<test<<": ";
	   solve();}
  
}

Measured memory_bytes: 81756
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    cin >> s;

    int q;
    cin >> q;

    deque<char> ans;
    for (auto c : s) ans.push_back(c);

    bool r = false;
    for (int i=0; i<q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            r = !r;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            if ((!r && f==1) || (r && f==2)) {
                ans.push_front(c);
            } else {
                ans.push_back(c);
            }
        }
    }

    if(r) reverse(ans.begin(), ans.end());
  
    while(!ans.empty()) {
        putchar(ans.front());
        ans.pop_front();
    }
    cout << endl;

}


Measured memory_bytes: 960
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;

struct edge {int from, to, coin; };

int main(){
    int N, M, P; cin >> N >> M >> P;
    edge E[5001];
    for (int i = 0; i < M; i++){
        int a, b, c; cin >> a >> b >> c;
        E[i].from = a; E[i].to = b; E[i].coin = -(c - P);
    }

    const long INF = 1e10;
    long d[N+1]; fill(d, d+N+1, INF);
    d[1] = 0;
    int count = 0;
    
    while(true){
        count++;
        for (int i = 0; i < M; i++){
            edge e = E[i];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.coin){
                if (count < N) d[e.to] = d[e.from] + e.coin;
                if (count >= N) d[e.to] = -INF;
                
                
            }
        }
        if (count == N*2) break;
    }

    if (d[N] == -INF){
        cout << -1 << endl;
        return 0;
    }
    if (d[N] > 0) d[N] = 0;
    cout << -d[N] << endl;

}


Measured memory_bytes: 384
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#ls=list(map(int,input().split()))
#for i in range(m):
# for _ in range(int(input())):
#from collections import Counter
#from fractions import Fraction
n=int(input())
arr=list(map(int,input().split()))
var=arr[0]
for i in range(1,n):
    var^=arr[i]
for i in range(n):
    print(arr[i]^var,end=" ")

#ls = [list(map(int, input().split())) for i in range(n)]
#for _ in range(int(input())):


Measured memory_bytes: 31576
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

void chmax(int &a, int b) { a = max(a, b); }

int INF = 1e+16;
int n;
int a[16][16];
int score[1 << 16];
int dp[1 << 16];	//dp[used] = max-value

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) rep(j, n) cin >> a[i][j];
	
	rep(i, (1 << n)) {
		rep(j, n) {
			if ((i >> j) % 2 == 0) continue;
			for (k = j + 1; k < n; k++) {
				if ((i >> k) % 2 == 0) continue;
				score[i] += a[j][k];
			}
		}
	}
	
	rep(i, (1 << n)) dp[i] = -INF;
	dp[0] = 0;
	
	rep(i, (1 << n) - 1) {
		int uku[16], cnt = 0;
		rep(j, n) {
			if ((i >> j) % 2 == 0) {
				uku[cnt++] = j;
			}
		}
		
		rep(j, (1 << cnt)) {
			if (j == 0) continue;
			if (j % 2 == 0) continue;
			
			int beet = 0;
			rep(k, cnt) {
				if ((j >> k) % 2 == 1) {
					beet += (1 << uku[k]);
				}
			}
			chmax(dp[i + beet], dp[i] + score[beet]);
		}
	}
	cout << dp[(1 << n) - 1] << endl;
	return 0;
}

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



int main() {
    int a, b, c;
  cin>>a>>b>>c;
    cout << max(max(a, b), c) * 10 + min(min(a, b), c) + a + b + c - max(max(a, b), c) - min(min(a, b), c) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f;
double pnt=-1;
int ans1,ans2;
int main()
{
	cin>>a>>b>>c>>d>>e>>f;
	for(int i=0;i*100*a<=f;i++)
	{
		for(int j=0;j*100*b+i*100*a<=f;j++)
		{
			for(int k=0;k*c<=(i*100*a+j*100*b)/100*e&&f>=j*100*b+i*100*a+k*c;k++)
			{
				double water=i*100*a+j*100*b;
				double sugar=double(int(min((f-(water+k*c)),(water/100*e-k*c)))/d*d+k*c);
				if(water==0)continue;
				if(sugar/water>=pnt)
				{
					pnt=sugar/water;
					ans1=water+sugar;
					ans2=sugar;
				}
			}
		}
	}
	cout<<ans1<<' '<<ans2<<endl;
}

Measured memory_bytes: 256