akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N,M; cin >> N >> M;
    string S(N,'a');
    REP(i,M){
        int s,c; cin >> s >> c;
        s--;
        if(S[s]=='a') S[s] = c+'0';
        else if(S[s]!=c+'0'){
            cout << -1 << endl;
            return 0;
        }
    }
    if(N>1 && S[0]=='0'){
        cout << -1 << endl;
        return 0;
    }

    if(N==1){
        if(S[0]=='a') S[0] = '0';
        cout << S << endl;
    }
    else if(N==2){
        if(S[0]=='a') S[0] = '1';
        if(S[1]=='a') S[1] = '0';
        cout << S << endl;
    }
    else{
        if(S[0]=='a') S[0] = '1';
        if(S[1]=='a') S[1] = '0';
        if(S[2]=='a') S[2] = '0';
        cout << S << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 100006
#define ll long long int 
using namespace std; 
struct node{
	int v,m;
}a[101];
ll f[M];
ll min(ll a,ll b)
{
	if(a>b)return b;
	return a;
}
int max(int a,int b)
{
	if(a>b)return a;
	return b;
}
int main()
{
	int n,m;
	int sum=0,mx=0;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i].m>>a[i].v;
		sum+=a[i].v;
	}
	for(int i=1;i<=sum;++i)f[i]=1000000000000;
	for(int i=1;i<=n;++i)
	for(int j=sum;j>=a[i].v;--j){
	f[j]=min(f[j],f[j-a[i].v]+a[i].m);
	if(f[j]<=m)mx=max(mx,j);
}
	cout<<mx;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    set <int> s;
    int a=nxt(),b=nxt(),c=nxt();
    s.insert(a);s.insert(b);s.insert(c);
    cout<<s.size()<<endl;

    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<algorithm>

using namespace std;
int main()
{
  int K,X,i;
  cin>>K>>X;
  if(X-(K-1)>=-1000000 && X+(K-1)<=1000000)
  {
  	for(i=X-(K-1);i<=X+(K-1);i++)
  		cout<<i<<" ";
  	cout<<endl;
  }
  if(X-(K-1)<-1000000)
  {
  	for(i=-1000000;i<=X+(K-1);i++)
  		cout<<i<<" ";
  	cout<<endl;
  }
  if(X+(K-1)>1000000)
  {
  	for(i=X-(K-1);i<=1000000;i++)
  		cout<<i<<" ";
  	cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int ans = 0;
long N;
int keta;

void dfs(int limit,int n,int a,int b,int c){
  if(limit == -1) return ;
  if(n <= N){
    if(a && b && c) ans++;
  }

  dfs(limit-1,n*10+3,1,b,c);
  dfs(limit-1,n*10+5,a,1,c);
  dfs(limit-1,n*10+7,a,b,1);
}


int main(void){
  scanf("%ld",&N);
  long i = N;
  while(i > 0){
    i /= 10;
    keta++;
  }

  dfs(keta,0,0,0,0);
  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
const int mod = 1000000007;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    long long dp[n][13] ={};
    for(int i=0; i<10; i++){
        if(s[0] == '?' ){
            dp[0][i] = 1;
        }
        else if(i == (int)(s[0] - '0')){
            dp[0][i] = 1;
        }
    }
    for(int i=1; i<n; i++){
        for(int j=0; j<13; j++){
            if(s[i] == '?'){
                for(int k=0; k<13; k++){
                    int t = (k*10)%13;
                    for(int l=0; l<10; l++){
                        if(j == ((t+l)%13)) dp[i][j] += dp[i-1][k];
                    }
                }
                dp[i][j] %= mod;
            }
            else {
                int a = (int)(s[i] - '0');
                for(int k=0; k<13; k++){
                    int t = (k*10)%13;
                    if(j == (t+a)%13) dp[i][j] += dp[i-1][k];
                }
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[n-1][5] << endl;
    return 0;
}


Measured memory_bytes: 10624
#include <stdio.h>

struct person
{
	struct person *prev;
	struct person *next;
};

int main(void)
{
	int n, m;
	
	while (scanf("%d %d", &n, &m) * n != 0){
		struct person potato[10000];
		struct person *current;
		int i;
		
		for (i = 0; i < n; i++){
			potato[i].prev = potato + (i - 1 + n) % n;
			potato[i].next = potato + (i + 1) % n;
		}
		
		current = potato + n - 1;
		while (current->next != current){
			for (i = 0; i < m; i++){
				current = current->next;
			}
			current->prev->next = current->next;
			current->next->prev = current->prev;
		}
		
		printf("%d\n", current - potato + 1);
	}
	
	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

#define M 1046527

long long T[M];
//???????????\??¢??°
long long h1(long long key) { return key % M; }

long long h2(long long key) { return 1 + (key % (M - 1)); }

long long h(long long key, long long i) { return ((h1(key)) + i*h2(key)) % M; }

void insert(long long key)
{
	long long i = 0;
	while (1) {
		int j = h(key, i);
		if (!T[j]) {
			T[j] = key;
			return;
		}
		else i++;
	}
	return;
}

bool find(long long key)
{
	long long i = 0;
	while (1) {
		int j = h(key, i);
		if (T[j] == key) return 1;
		else if (!T[j]) return 0;
		else i++;
	}
}

long long getKey(char *p)
{
	long long key = 0;
	for (long long i = (strlen(p) - 1); i >= 0; i--) {
		long long x;
		switch (p[i])
		{
		case 'A':
			x = 1; break;
		case 'C':
			x = 2; break;
		case 'G':
			x = 3; break;
		case 'T':
			x = 4; break;
		default:
			break;
		}
		key += x * pow(10, i);
	}
	return key;
}

int main()
{
	int n;
	char order[10], word[15];
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%s %s", order, word);
		if (order[0] == 'i') insert(getKey(word));
		else if (find(getKey(word))) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 9396
#include<stdio.h>

int main(void) {
    //X???1L?????????????????????Y????????¬?????????Y????????¬?????????????????????Y???1L???????????????????????????JOI??¶???1??¶???????????¨???
    int x_cost_per1L, y_basic, y_upper_to_basic, y_add_per1L, amount_used;
    int x_cost, y_cost;
    
    scanf("%d %d %d %d %d", &x_cost_per1L, &y_basic, &y_upper_to_basic, &y_add_per1L, &amount_used);
    
    x_cost = x_cost_per1L * amount_used;
    y_cost = (amount_used > y_upper_to_basic) ?
                (y_basic + y_add_per1L*(amount_used - y_upper_to_basic)): y_basic;
    int cost = x_cost < y_cost ? x_cost : y_cost;
    printf("%d\n", cost);
    return 0;
}

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



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

  ll dp[50][51][2501]={0}; //dp[i][j][k]でx[0]~x[i]をj枚用いて合計がkのパターン

  dp[0][1][x[0]]=1;

  for(int i=1;i<N;i++){
    dp[i][1][x[i]]=1;
    for(int j=1;j<=i;j++){
      for(int k=0;k<2501;k++){
        if(dp[i-1][j][k]>0){
          dp[i][j][k]+=dp[i-1][j][k];
          dp[i][j+1][k+x[i]]+=dp[i-1][j][k];
        }
      }
    }
  }
  ll ans=0;
  for(int j=1;j<=50;j++){
      for(int k=0;k<2501;k++){
        if(j*A==k){
          ans+=dp[N-1][j][k];
        }
      }
  }
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 50048
mod = 1000000007

def add(a, b):
    return (a + b) % mod

def sub(a, b):
    return (a + mod - b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
    
a = []
N, M = map(int, input().split())
for i in range(M):
    a.append(int(input()))

def main():
  results = []

  flag = True

  for m in range(1, M):
      if a[m] - a[m - 1] == 1:
          flag = False
          break

  flag_end = True
  if M == 0:
      flag_end = False

  def Fib(n):
      a, b = 0, 1
      if n == 1:
          return a
      elif n == 2:
          return b
      else:
          for i in range(n-2):
              a, b = b, a + b
          return b

  if flag and flag_end:
      for m in range(M):
          if m == 0:
              results.append(Fib(a[m] + 1))
          else:
              results.append(Fib(a[m] - a[m - 1]))
      results.append(Fib(N - a[m] + 1))
      result = 1
      for i in range(len(results)):
          result = mul(result, results[i])
      print(result % mod)
  elif not flag:
      print(0)
  else:
      print(Fib(N + 2) % mod)

if __name__ == "__main__":
  main()

Measured memory_bytes: 49112
#include <bits/stdc++.h>
inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0; }
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0; }
#define For(i, l, r) for(register int i = (l); i <= (r); ++ i)
#define Fordown(i, r, l) for(register int i = (r); i >= (l); -- i)
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	puts(!((b - a) & 1) ? "Alice" : "Borys");
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll x,k,d;
  cin >> x >> k >> d;
  ll num = abs(x) / d;
  if(num > k){
    ll ans = abs(x) - k * d;
    cout << ans << endl;
  }else{
    ll ans = abs(x) % d;
    ll temp = k - num;
    if(temp & 1) cout << abs(ans - d) << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 3564
#include<iostream>
using namespace std;
int main(){
  int N,M,X; cin >> N >> M >> X;
  int a[101]={0};
  int num;
  while(cin >> num){
    a[num]=1;
  }
  int lcost=0;
  for(int i=1;i<X;i++){
    lcost += a[i];
  }
  int rcost=0;
  for(int i=X+1;i<N;i++){
    rcost += a[i];
  }
  cout << min(lcost, rcost) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    string s;
    cin >> s;
    ll lenS = s.length();
    ll ans = 0;
//    if(lenS%2 == 0){
        ll tmp = 0;
        while(true) {
          if(s.length() == 1) break;
            if (s[tmp] != s[s.length() - 1 - tmp]) {
                ans++;
            }
            tmp++;
            if (tmp == lenS / 2) break;
        }
        cout << ans << endl;
//
//    }else{
//        ll tmp = 0;
//        while(true) {
//            if (s[tmp] != s[s.length() - 1 - tmp]) {
//                ans++;
//            }
//            tmp++;
//            if(tmp == lenS/2) break;
//        }
//    }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
SUM = 0
cnt = 0
for i in range(n):
    SUM += a[i]
    if i % 2 == 0:
        cnt += max(0, 1 - SUM)
        SUM = max(1, SUM)
    else:
        cnt += max(0, 1 + SUM)
        SUM = min(-1, SUM)
ans = cnt

SUM = 0
cnt = 0
for i in range(n):
    SUM += a[i]
    if i % 2 == 0:
        cnt += max(0, 1 + SUM)
        SUM = min(-1, SUM)
    else:
        cnt += max(0, 1 - SUM)
        SUM = max(1, SUM)
ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 14644
#include <bits/stdc++.h>
using namespace std;
int x;
int d[100020];
priority_queue<pair<int, int> >q;
int main() {
	scanf("%d", &x);
	memset(d, 0x3f, sizeof d);
	for (int i = 9; i > 0; i--) {
		d[i % x] = i;
		q.push(make_pair(-d[i % x], i % x));
	}
	while (q.size()) {
		pair<int, int> u = q.top();
		q.pop();
		if (d[u.second] < -u.first) {
			continue;
		}
		for (int i = 0; i < 10; i++) {
			int np = (u.second * 10 + i) % x;
			int nd = (-u.first + i);
			if (d[np] > nd) {
				d[np] = nd;
				q.push(make_pair(-d[np], np));
			}
		}
	}
	printf("%d\n", d[0]);
	return 0;
}

Measured memory_bytes: 2804
//**************************
//*** writer  :  Alan Hu **
//************************
#include<bits/stdc++.h>

using namespace std;
     
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
     
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int Q[1010000][2],head,tail,D[810][810];
int n,m,K,sx,sy;
char p[810][810];

void Ins(int x,int y,int d)
{
	if (D[x][y]<=d || p[x][y]!='.') return;
	D[x][y]=d;
	tail++;
	Q[tail][0]=x;
	Q[tail][1]=y;	
}

int main()
{
	int x,y;
	cin>>n>>m>>K;
	rept(i,1,n+1)
	{
		scanf("%s",p[i]+1);
		rept(j,1,m+1)
		{
			if (p[i][j]=='S')
			{
				sx=i;
				sy=j;
				p[i][j]='.';
			}
			D[i][j]=1324144;
		}
	}
	Ins(sx,sy,0);
	while (head<tail)
	{
		head++;
		x=Q[head][0];
		y=Q[head][1];
		Ins(x+1,y,D[x][y]+1);
		Ins(x,y+1,D[x][y]+1);
		Ins(x-1,y,D[x][y]+1);
		Ins(x,y-1,D[x][y]+1);
	}
	int res=1e9;
	rept(i,1,n+1)
	{
		rept(j,1,m+1)
		{
			if (D[i][j]<=K)
			{
				res=min(res,1+(min(min(i-1,n-i),min(j-1,m-j))+K-1)/K);
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 8448
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s=set(map(int,input().split()))
if len(s)==2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38332
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
int main()
{
    int S, W;
    cin >> S >> W;
    if (S <= W)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
    return 0;
}

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

int main() {
  int N, A, B; cin >> N >> A >> B;
  int ans = 0;
  rep2(i, 1, N+1) {
    int sum = 0;
    int temp = i;
    string i_str = to_string(temp);
    rep(j, i_str.size()) {
      sum += temp % 10;
      temp /= 10;
    }
    if (A <= sum && sum <= B) {
      ans += i;
    }
  }
  cout << ans << endl;
}

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

int count(char *str){
  int i;
  int c = 0;
  for(i = 0; i < 3; i++){
    if(str[i] == '1'){
      c++;
    }
  }
  return c;
}

int main(){
  char strNum[3];
  cin >> strNum;
  cout << count(strNum);
}

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

int main() {
    long long x[15];
    long long r, d;
    cin >> r >> d >> x[0];

    for (int i = 0; i < 10; i++) {
        x[i + 1] = r * x[i] - d;
    }

    for (int i = 1; i <= 10; i++) {
        cout << x[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>

using namespace std;

int main(){
	int H, W;
	while (true)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
		{
			return 0;
		}
		for (int i = 0; i < H; i++)
		{		
			for (int j = 0; j < W; j++)
			{
				if ((i+j)%2 == 0)
				{
					cout << "#";
				}
				else
				{
					cout << ".";
				}				
			}
			cout <<endl;
		}
		cout <<  endl;	
		
	}
}


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

#define endl            "\n"
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<ll>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define debug1(x)       cerr<<#x<<" "<<x<<endl;
#define debug2(x,y)     cerr<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define debug3(x,y,z)   cerr<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define info(s)         cerr<<s<<" "<<endl;
#define fr(a,b,c)       for(auto a=b;b<c?a<c:a>=c;b<c?a++:a--)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define clr(x)          memset(x, 0, sizeof(x))
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define SORT(a)         sort(all(a));
#define SORTR(a)        sort(all(a),greater<ll>());
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100050
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second


template<typename T>
void output_vector(const vector<T> , bool ,bool ,int ,int );

template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v);

template<typename T>
istream& operator>>(istream &in,vector<T> &v);


void solve()
{   
    int n;cin>>n;vi v(n);cin>>v;
    ll sum=0;for(int x:v)sum^=x;
    for(int x:v)
    cout<<(x^sum)<<" ";cout<<endl;
}

int main()
{   

    FIO;
    ll test;test=1;
    // cin>>test;
    while(test--)
    solve();
    return 0;
}






template<typename T>
void output_vector(const vector<T> &v, bool debug_print=false,bool add_one = false,int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        (debug_print)?(cerr << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n')):(cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'));
}   

template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v){
    int i=0;
    for(T x:v){
        out<<x;
        (i++!=v.size())?out<<" ":out<<"\n";    
    }
    return out;
}

template<typename T>
istream& operator>>(istream &in,vector<T> &v){
    for(T &i:v)
        in>>i;
    return in;
}

Measured memory_bytes: 3956
#include<iostream>
#include<cstdio>
#include<complex>
#include<cmath>
using namespace std;
typedef complex<double> xy_t;
int main()
{
  xy_t P[110];
  int N = 0;
  double x,y;
  while(~scanf("%lf,%lf",&x,&y)){
    P[N++] = xy_t(x,y);
  }
  double sum = 0.0;
  for(int i = 0; i + 2 < N; ++i){
    xy_t a = P[0],b = P[i + 1],c = P[i + 2]; 
      sum += (conj(b - a) * (c - a)).imag();
  }
  sum /= 2;
  printf("%.6f\n",abs(sum));
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ll long long
#define f first
#define s second
const ll mx=3e5+100;
pair<ll,ll> a[mx];
int main()
{
 int x,y,z;
cin>>x>>y>>z;
cout<<(x-y)%z;
            
}
            
 

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int k = (1 + (int)Math.Sqrt(1 + 8 * N)) / 2;
		if((k * (k - 1)) / 2 != N)
		{
			Console.WriteLine("No");
			return;
		}
		Console.WriteLine("Yes");

		int[,] table = new int[k - 1, k - 1];
		int cnt = 1;
		for(int i = 0; i < k - 1; i++)
		{
			for(int j = 0; j <= i; j++)
			{
				table[i, j] = cnt;
				cnt++;
			}
		}

		var ans = new StringBuilder();
		for(int i = 0; i < k - 1; i++)
		{
			var S = new List<int>(k - 1);
			int r = i;
			int c = -1;
			while(c + 1 <= i)
			{
				c++;
				S.Add(table[r, c]);
			}
			while(r + 1 < k - 1)
			{
				r++;
				S.Add(table[r, c]);
			}
			ans.Append($"{k - 1} ");
			ans.Append(string.Join(" ", S.Select(x => x.ToString()).ToArray()));
			ans.Append("\n");
		}
		ans.Append($"{k - 1} ");
		ans.Append(string.Join(" ", Enumerable.Range(0, k - 1).Select(x => table[x, x].ToString()).ToArray()));
		ans.Append("\n");

		Console.WriteLine(k);
		Console.Write(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 23124
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

class Segment_Tree:
    __slots__ = ['ide_ele', 'size', 'num', 'seg', 'segfunc']

    def __init__(self, size, func, element):
        #####単位元######
        self.ide_ele = element
        self.size = size

        #num:n以上の最小の2のべき乗
        self.num = 2 ** (self.size - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        #####segfunc######
        self.segfunc = func

    def apply(self, apply_seq):
        #set_val
        for i in range(self.size):
            self.seg[i + self.num - 1] = apply_seq[i]    
        #built
        for i in range(self.num - 2, -1, -1) :
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
        
    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k-1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1],  self.seg[k * 2 + 2])
        
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2 
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res


n = int(input())
H = list(map(int,input().split()))
A = list(map(int,input().split()))
st = Segment_Tree(n+1,max,0)
dp = [0] * (n+1)
for i in range(n):
  hi = H[i]; ai = A[i]
  st.update(hi,st.query(0,hi+1)+ai)
print(st.query(0,n+1))


Measured memory_bytes: 114356
# 2019-11-10 20:23:41(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n = int(sys.stdin.readline().rstrip())
    if n == 1:
        print('Hello World')
        sys.exit()
    else:
        a, b = (int(x) for x in sys.stdin.read().split())
        print(a + b)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//素集合データ構造
// ref:https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
struct union_find {
    // parent[v]==w(>=0):vの親はw
    // parent[v]==k(<0):vは根&&vの属するグループの要素数は-k
    vector<long long int> parent;
    //コンストラクタ
    union_find(long long int n) {
        parent.assign(n, -1);
    }
    // vの根を求める
    //求めると同時に親を根に置き換える(木の圧縮)
    long long int root(long long int v) {
        if (parent[v] < 0) {
            return v;
        } else {
            parent[v] = root(parent[v]);
            return parent[v];
        }
    }
    // vが属するグループの要素数を求める
    long long int size(long long int v) {
        return -parent[root(v)];
    }
    // vとwを繋げる
    void unite(long long int v, long long int w) {
        v = root(v);
        w = root(w);
        if (v == w) return;
        if (parent[v] < parent[w]) swap(v, w);
        parent[w] += parent[v];
        parent[v] = w;
    }
    // vとwが同値か判定
    bool isSame(long long int v, long long int w) {
        return root(v) == root(w);
    }
};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    //[i][j]を[i*w+j]と思う
    union_find uf(h * w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            //上
            if (i != 0 && s[i][j] != s[i - 1][j]) {
                uf.unite(i * w + j, (i - 1) * w + j);
            }
            //下
            if (i != h - 1 && s[i][j] != s[i + 1][j]) {
                uf.unite(i * w + j, (i + 1) * w + j);
            }
            //左
            if (j != 0 && s[i][j] != s[i][j - 1]) {
                uf.unite(i * w + j, i * w + j - 1);
            }
            //右
            if (j != w - 1 && s[i][j] != s[i][j + 1]) {
                uf.unite(i * w + j, i * w + j + 1);
            }
        }
    }
    //各グループとそのグループが含む黒の数を管理
    unordered_map<int, int> gr_black;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                gr_black[uf.root(i * w + j)]++;
            }
        }
    }
    lint ans = 0;
    for (auto itr = gr_black.begin(); itr != gr_black.end(); itr++) {
        ans += (*itr).second * (uf.size((*itr).first) - (*itr).second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8484
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

const int MAX_N = 1<<17;        // 131072

struct SegTree {
  int n;
  int dat[MAX_N * 2 - 1];
  SegTree(int _n) {
    for (n=1; n<_n; n*=2);
    fill(dat, dat+2*n-1, 0);
  }
  void up(int a, int b) { return update(a, b, 0, 0, n); } // [a,b)ðPÂÇÁ
  void update(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) dat[k]++;
    else {
      update(a, b, k*2+1, l, (l+r)/2);
      update(a, b, k*2+2, (l+r)/2, r);
    }
  }
  int q(int a) { return query(a, 0, 0, n); } // aðÜÞæÔÌ
  int query(int a, int k, int l, int r) {
    if (r <= a || a < l) return 0;
    if (r-l == 1) return dat[k];
    return dat[k] + query(a, k*2+1, l, (l+r)/2) + query(a, k*2+2, (l+r)/2, r);
  }
};

int main() {
  int n;
  while(cin >> n) {
    SegTree sg(100001);
    REP(i,n) {
      int a, b;
      cin >> a >> b;
      //cout << a << " " << b << endl;
      sg.up(a,b+1);
      //cout << "ok" << endl;
    }
    //cout << "hoge" << endl;
    for (int i=n; i>=0; --i) {
      //cout << i << endl;
      if (sg.q(i+1) >= i) {
        cout << i << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 0
e1,e2,e3,e4=map(int,input().split())

if e1==e2 and e3==e4:
    print('yes')
elif e1==e3 and e2==e4:
    print('yes')
elif e1==e4 and e2==e3:
    print('yes')
elif e1==e2==e3==e4:
    print('yes')
else:
    print('no')


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,x,y,curr,temp,m;
    string a;
    cin >> a;
    int len = a.length();
    stack<int> s;
    int rose = 0;
    for(i=0;i<len;i++)
    {
        if(s.empty())
        {
            s.push(a[i]-'0');
        }
        else if(s.top() != (a[i]-'0'))
        {
            rose += 2;
            s.pop();
        }
        else
        {
            s.push(a[i]-'0');
        }
    }
    printf("%d\n",rose);
    return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> H(N);
    rep(i, N){
        cin >> H[i];
    }
    int now = 0;
    rep(i, N){
        if(now <= H[i]-1){
            H[i]--;
            now = H[i];
        } else if (H[i] != now) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3728
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int X, t;
    cin >> X >> t;
    cout << max(X - t, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
ans = ['0']*N
for i in range(M):
  s, c = input().split()
  if (ans[int(s)-1] != '0' and ans[int(s)-1] != c) or (N>1 and(s,c) == ('1','0')):
    ans = -1
    break
  ans[int(s)-1] = c
if ans == -1:
  print(-1)
else:
  if N>1 and ans[0]=='0':
  	ans[0]='1'
  print(int(''.join(ans)))


Measured memory_bytes: 3064
/**
  @file d.cpp
  @title D - Handstand
  @url https://atcoder.jp/contests/abc124/tasks/abc124_d
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

int main() {
  int i;

  int N, K;
  cin >> N >> K;

  string S;
  cin >> S;

  vector<int> data;
  // 先頭が 0 だったら
  if (S[0] == '0') {
    data.push_back(0);
  }

  // S[i] の数値がどこまで続くか
  for (i = 0; i < (int)S.size();) {
    int j = i;
    while (j < (int)S.size() && S[i] == S[j]) {
      j++;
    }
    data.push_back(j - i);
    i = j;
  }

  // 最後尾が 0 だったら
  if (S.back() == '0') {
    data.push_back(0);
  }

  vector<int> sums((int)data.size() + 1, 0);
  REP(i, (int)data.size()) {
    sums[i + 1] = sums[i] + data[i];
  }

  int res = 0;
  for (int left = 0; left < (int)data.size(); left += 2) {
    int right = left + K * 2 + 1;
    if (right >= (int)sums.size()) {
      right = (int)sums.size() - 1;
    }
    res = max(res, sums[right] - sums[left]);
  }

  cout << res << endl;
  return 0;
  }


Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////


int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    int n,m;cin>>n>>m;
    while(n||m){
        int a[n+1];rep(i,1,n)cin>>a[i];
        a[0]=0;rep(i,1,n)a[i]+=a[i-1];
        int b[m+1];rep(i,1,m)cin>>b[i];
        b[0]=0;rep(i,1,m)b[i]+=b[i-1];
        
        vector<int>va,vb;
        va.clear();vb.clear();
        rep(i,0,n-1){
            rep(j,i+1,n){
                va.pb(a[j]-a[i]);
            }
        }
        rep(i,0,m-1){
            rep(j,i+1,m){
                vb.pb(b[j]-b[i]);
            }
        }
        sort(va.begin(),va.end());
        sort(vb.begin(),vb.end());
        ll ans=0;
        for(auto x:va){
            ll k=upper_bound(vb.begin(),vb.end(),x)-lower_bound(vb.begin(),vb.end(),x);
            ans+=k;
        }
        cout<<ans<<endl;
        cin>>n>>m;
    }
    return 0;
}


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


int main(){
  
  int N;
  cin >> N;
  vector<char> P(0);
  vector<char> W(0);
  vector<char> G(0);
  vector<char> Y(0);
  
  for(int i = 0; i < N; i++){
	char s;
    cin >> s;
    if(s == 'P'){
      P.push_back(s);
    }
    if(s == 'W'){
      W.push_back(s);
    }
    if(s == 'G'){
      G.push_back(s);
    }
    if(s == 'Y'){
      Y.push_back(s);
    }
  }
  
  if(P.size() != 0 && W.size() != 0 && G.size() != 0 && Y.size() != 0){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 410
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,m,a[N][N],fa[N*N],size[N*N][2];
int trans(int x,int y){return (x-1)*m+y;}
int wx[4]={1,0,0,-1},wy[4]={0,1,-1,0};
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	n=read(),m=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			char c=getchar();
			while (c!='.'&&c!='#') c=getchar();
			a[i][j]=c=='.';
		}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			fa[trans(i,j)]=trans(i,j);
			size[trans(i,j)][a[i][j]]=1;
		}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			for (int k=0;k<4;k++)
			if (i+wx[k]>=1&&i+wx[k]<=n&&j+wy[k]>=1&&j+wy[k]<=m&&a[i+wx[k]][j+wy[k]]!=a[i][j])
			{
				int p=find(trans(i,j)),q=find(trans(i+wx[k],j+wy[k]));
				if (p!=q)
				{
					fa[p]=q;
					size[q][0]+=size[p][0],size[q][1]+=size[p][1];
				}
			}
	ll ans=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		if (find(trans(i,j))==trans(i,j)) ans+=1ll*size[trans(i,j)][0]*size[trans(i,j)][1];
	cout<<ans;
}

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

int main(){
  int a, b, ans;
  cin >> a >> b;
  if(a < b) ans = 0;
  else ans = 10;
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
import itertools
N=input()

r=None
for i in itertools.count(start=1,step=1):
    Q,R=divmod(N,i)
    if i>Q:
        break
    if R == 0:
        digitI = int(math.log10(i) + 1)
        digitQ = int(math.log10(Q) + 1)
        if r==None:
            r = max(digitI,digitQ)
        else:
            r=min(r,max(digitI,digitQ))
print r
        


Measured memory_bytes: 2692
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>
#include <array>
#include <fstream>
#include <deque>
#include <bitset>
#include <complex>
using namespace std;
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#define REVERSE(i,n) for(int (i) = n-1;(i) >= 0 ; --i)
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(auto(it,(c).begin());it != (c).end();)
#define cx real()
#define cy imag()
#define px first
#define py second
#define LL long long
#define int LL
#define inf  (1LL << 60)
#define mod 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
#define lower lower_bound
#define upper upper_bound
#define ZERO(c,n) memset(&c[0],0,sizeof(int)*n)
#define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << ""#a": " << a << endl;
#ifdef _DEBUG
#define debug_io fstream cin("input.txt");ofstream cout("output.txt");
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define pb(a) push_back(a)
template<class T>void scan(vector<T>& a, int n, istream& cin)
{
	T c; REP(i, n) { cin >> c; a.push_back(c); }
}
using vs = vector<string>; using vi = vector<int>; using pii = pair<int, int>;
using psi = pair<string, int>; using vvi = vector<vi>; using pss = pair<string, string>;
template<class T>bool valid(T x, T w) { return 0 <= x&&x < w; }
int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------


vi a,b,c,d;

signed main()
{
	QUICK_CIN;
	debug_input;

	int n, m;

	cin >> n >> m;

	REP(i, n) {
		int t, k;
		cin >> t >> k;
		a.push_back(t);
		b.push_back(k);
	}

	REP(i, m) {
		int t, k;
		cin >> t >> k;
		c.push_back(t);
		d.push_back(k);
	}

	REP(i, n) {
		int min_d = inf;
		int min_i = 0;
		REP(j, m) {
			int t = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (t < min_d) {
				min_d = t;
				min_i = j;
			}
		}
		cout << min_i+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
  
  cin >> n;
  
  if (n / 100 == 7) cout << "Yes";
  else {
    int nn = n % 100;

    if (nn / 10 == 7) cout << "Yes";
    else {
    	int nnn = nn % 10;

    	if (nnn == 7) cout << "Yes";
    	else cout << "No";
    }
  }
  return 0;
}


Measured memory_bytes: 3624
from itertools import groupby

R = lambda: map(int, input().split())
n, k = R()
a = list(R())
w = [0] * n

def merge(b, e):
    m = b + (e - b) // 2
    i, j = b, m
    r = k = 0
    while i < m and j < e:
        if a[i] <= a[j]:
            w[k] = a[i]
            i += 1
        else:
            r += m - i
            w[k] = a[j]
            j += 1
        k += 1
    a[e - m + i: e] = a[i: m]
    a[b: b + k] = w[:k]
    return r        
    
def mergesort(b, e):
    if e - b < 2:
        return 0
    m = b + (e - b) // 2
    return mergesort(b, m) + mergesort(m, e) + merge(b, e)


r = k * mergesort(0, n)
c = n * (n - 1) // 2
for v, g in groupby(a):
    x = sum(map(bool, g))
    c -= x * (x - 1) // 2
print((r + c * k * (k - 1) // 2) % (10**9 + 7))


Measured memory_bytes: 3192
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 3
10 1
1
15 1
2
30 2
1 2"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """12 1
100000 1
2"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """4 6
67786 3
1 3 4
3497 1
2
44908 3
2 3 4
2156 3
2 3 4
26230 1
2
86918 1
3"""
        output = """69942"""
        self.assertIO(input, output)
def resolve():
    (N,M)=(int(i) for i in input().split())
    housekis=[]
    for i in range(M):
        (a,b)=(int(i) for i in input().split())
        ability=sum([2**(int(i)-1) for i in input().split()])
        housekis.append([a,ability])
    dpt=[[1<<29 for i in range(2**N)] for j in range(M+1)]
    dpt[0][0]=0
    for i in range(M):
        for j in range(2**N):

            dpt[i+1][j]=min(dpt[i][j],dpt[i+1][j])
            dpt[i+1][j | housekis[i][1]]=min(dpt[i+1][j | housekis[i][1]],housekis[i][0]+dpt[i][j])

    if dpt[-1][-1]==1<<29:
        print(-1)
    else:
        print(dpt[-1][-1])


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 91092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

struct UnionFind
{
    vector<int> par; //par[i]:= iの親の番号
    vector<int> siz; //siz[i]:= iの属する連結成分の大きさ
    UnionFind(int N) {
        par.resize(N);
        for(int i = 0; i < N; ++i) {
            par[i] = i;
        }
        siz.resize(N,1);
    }

    int root(int x){ // xが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        return root(x) == root(y);
    }

    bool unite (int x, int y) { // xとyの木を併合
        x = root(x); y = root(y);
        if (x == y) return false;
 
        if (siz[x] < siz[y]) swap(x, y); // merge technique 小を大にくっつける
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    int size(int x) { // xの属する木の大きさを得る
        return siz[root(x)];
    }
};


int main()
{
    int n,m;
    cin >> n >> m;
    vi p(n);
    rep(i,n) cin >> p[i], p[i]--;

    UnionFind uf(n);
    rep(j,m) {
        int x,y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }
    int res = 0;
    rep(i,n) {
        if(uf.same(p[i], i)) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4548
#include <stdio.h>
int main ()
{
	int K, A, B;
	scanf ("%d", &K);
	scanf ("%d %d",&A, &B);
	for (int i = A; i <=B; i++)
	{
	 if (i % K == 0){
	 	printf ("OK\n");
	 	return 0;
		}
	}
printf ("NG");
return 0;
}

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

using namespace std;



int main(){
	string s;
	int count=0;
	while(cin>>s){
	for(int i=0;i<s.size()/2+1;i++){
		//cout<<s[i]<<"="<<s[s.size()-i-1]<<endl;
		if(i==s.size()/2)count++;
		if(s[i]!=s[s.size()-i-1])break;
	}
	}
	cout<<count<<endl;

}

Measured memory_bytes: 1184
from sys import stdin
from collections import deque, defaultdict as ddic
from itertools import combinations, permutations, product
import bisect
import heapq

rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())

n = ri()
heights = rim()
ans = 0
maximum = float('-inf')
for h in heights:
    if h >= maximum:
        ans += 1
        maximum = h

print(ans)



Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int d, t, s;
    cin >> d >> t >> s;
    int ans = (d + s - 1) / s;
    if (ans <= t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int tr[N<<2],h[N],a[N],n,ans;
void pushup(int k)
{
	tr[k]=max(tr[k<<1],tr[k<<1|1]);
}
void update(int k,int l,int r,int x,int v)
{
	if(l==r)
	{
		tr[k]=v;
		return;
	}
	int mid=l+r>>1;
	if(x<=mid) update(k<<1,l,mid,x,v);
	else update(k<<1|1,mid+1,r,x,v);
	pushup(k);
}
int query(int k,int l,int r,int a,int b)
{
	if(l==a&&r==b)
		return tr[k];
	int mid=l+r>>1;
	if(b<=mid) return query(k<<1,l,mid,a,b);
	else if(a>mid) return query(k<<1|1,mid+1,r,a,b);
	else return max(query(k<<1,l,mid,a,mid),query(k<<1|1,mid+1,r,mid+1,b));
}
main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		int mx=query(1,1,n,1,h[i])+a[i];
		ans=max(ans,mx);
		update(1,1,n,h[i],mx);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8448
N = int(input())
A = list(map(int, input().split()))
ma = [0] * (100000 + 1)

for i in range(N):
    ma[A[i]] += 1

Q = int(input())

s = sum(A)

for i in range(Q):
    b, c = map(int, input().split())
    diff = c * ma[b] - ma[b] * b
    ma[c] += ma[b]
    ma[b] = 0
    s += diff
    print(s)


Measured memory_bytes: 20808