akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int niz[100005];
long long rj[100005];

int main () {
	
	int n,k;
	cin>>n>>k;
	for(int i=0; i<n; i++){
		cin>>niz[i];
	}	
	rj[0]=0;
	for(int i=1; i<n; i++){
		rj[i]=100000000000;
	}
	for(int i=1; i<n; i++){
		for(int j=i-1; j>=max(0,i-k); j--){
		//	cout<<i<<" "<<j<<endl;
		//	cout<<rj[i]<<" "<<rj[j]<<endl;
		//	cout<<niz[i]<<" "<<niz[j]<<endl;
			if(rj[j]+max(niz[i],niz[j])-min(niz[i],niz[j])<rj[i]){
				rj[i]=rj[j]+max(niz[i],niz[j])-min(niz[i],niz[j]);
			}
		}
	}
	/*for(int i=0; i<n; i++){
		cout<<rj[i];
	}*/
	cout<<rj[n-1];
//  |                           |                  	
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
  }


Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    x,y = [],[]
    root = [[] for _ in range(N)]
    go = [True for _ in range(N)]
    for i in range(N):
        _x,_y = map(int,input().split())
        x.append((_x,i))
        y.append((_y,i))
        
    x.sort()
    y.sort()
    
    for i in range(N-1):
        dx = x[i+1][0] - x[i][0]
        dy = y[i+1][0] - y[i][0]
        root[x[i][1]].append((dx,x[i+1][1]))
        root[x[i+1][1]].append((dx,x[i][1]))
        root[y[i][1]].append((dy,y[i+1][1]))
        root[y[i+1][1]].append((dy,y[i][1]))
    
    ans = 0    
    queue = root[0]
    heapq.heapify(queue)
    go[0] = False
    while queue:
        cost,following = heapq.heappop(queue)
        if not go[following]:
            continue
        go[following] = False
        for e in root[following]:
            if go[e[1]]:
                heapq.heappush(queue,e)
        ans += cost
        
    print(ans)
    
if __name__ == "__main__":
    main()

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

void solve() 
{
    int r,g,b,n;cin>>r>>g>>b>>n;
    int ans=0;
    REP(i,n+1)REP(j,n+1){
        if((n-r*i-g*j)%b==0&&(n-r*i-g*j)/b>=0)ans++;
    }cout<<ans<<endl;
}

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

Measured memory_bytes: 256
S = input()
count_1 = 0
count_2 = 0
for i,s in enumerate(S):
    if i % 2 == 0 and s == '0':
        count_1 += 1
    elif i % 2 != 0 and s == '1':
        count_1 += 1
for i,s in enumerate(S):
    if i % 2 == 0 and s == '1':
        count_2 += 1
    elif i % 2 != 0 and s == '0':
        count_2 += 1
print(min(count_1,count_2))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
using P = pair<int,int>;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
const int INF = 1e9;

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  int a, b, gx, gy;
  cin >> a >> b >> gx >> gy;
  a--; b--; gx--; gy--;
  string s[h];
  rep(i,h) cin >> s[i];
  vector<vector<int>> d(h,vector<int>(w,INF));
  d[a][b] = 0;
  queue<P> que;
  que.push(P(a,b));
  while(!que.empty()) {
    P p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    rep(dir,4) {
      for(int step = 1; step <= k; step++) {
        int nx = x + step*dx[dir], ny = y + step*dy[dir];
        if(nx < 0 or ny < 0 or nx >= h or ny >= w or s[nx][ny] == '@' or d[nx][ny] < d[x][y] + 1) break;
        else {
          if(d[nx][ny] > d[x][y] + 1) {
            d[nx][ny] = d[x][y] + 1;
            que.push(P(nx,ny));
          }
        }
      }
    }
  }
  cout << (d[gx][gy] == INF ? -1 : d[gx][gy]) << endl;
  return 0;
}


Measured memory_bytes: 12136
K, A, B = map(int, input().split())
if A + 1 >= B:
  print(K + 1)
  exit(0)
if K >= A:
  print(B + (K - A - 1) // 2 * (B - A) + (K - A - 1) % 2)
else:
  print(K + 1)

Measured memory_bytes: 38256
#include<stdio.h>

int main(){
  int n,i,j,x,y,z;
  int A[120][120]={0};

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&x);
    scanf("%d",&y);
    if(y!=0){
      for(j=0;j<y;j++){
	scanf("%d",&z);
	A[x][z]=1;
      }
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<n;j++){
      printf("%d ",A[i][j]);
    }
    printf("%d\n",A[i][n]);
  }
  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;
using namespace boost;
using namespace adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

string solve(const string& s) {
  int n = s.size();
  int mx = 0;
  int cnt = 0;
  string last = "";
  for(const auto& p : index(s)) {
    if (p.value() == 'b') {
      ++cnt;
      if (cnt > mx) {
        mx = cnt;
        last = "";
      }
      if (cnt == mx) {
        last = max(last, s.substr(p.index()+1));
      }
    } else {
      --cnt;
    }
  }
  if (mx == 0) {
    vecint dp(n+1);
    vecint apos(n);
    int cnt_a = 0;
    int cnt_b = 0;
    for (const auto& p : index(s)) {
      if (p.value() == 'a') {
        dp[p.index()+1] = dp[p.index()];
        apos[cnt_a] = p.index();
        ++cnt_a;
      } else {
        dp[p.index()+1] = max(dp[p.index()], dp[apos[cnt_b]]+1);
        ++cnt_b;
      }
    }
    int rep = dp[n];
    string res = "";
    for (auto i : irange(0, rep)) res += "ab";
    return res;
  } else {
    return string(mx, 'b') + last;
  }
}

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int cnt = 0;
  int old = 0;
  vector<string> subs;
  for(const auto& p : index(s)) {
    if (p.value() == 'a') {
      ++cnt;
    } else {
      --cnt;
    }
    if (cnt == 0) {
      subs.push_back(s.substr(old, p.index()-old+1));
      old = p.index()+1;
    }
  }
  boost::reverse(subs);
  string res = "";
  for (const auto& sub : subs) {
    auto tmp = solve(sub);
    res = max(res, tmp + res);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
 
int main() {
 
  long long i,j,k,n,m,l,a,b,c;
  long long A[101][101] = {0};
  long long B[101][101] = {0};
  long long C[101][101] = {0};
 
  scanf("%lld %lld %lld",&n,&m,&l);
 
  for(j=0; j<n; j++) {
    for(i=0; i<m; i++) {
 
      scanf("%lld", &a);
      A[j][i] = a;
     
    }
  }
 
  for(j=0; j<m; j++){
    for(i=0;i<l;i++){
      scanf("%lld",&b);
      B[j][i] = b;
    }
  }
 
    for(i=0 ;i<n; i++) {
      for(j=0; j<l; j++){
    C[i][j] = 0;
    for(k=0;k<m; k++) {
       C[i][j] += A[i][k]*B[k][j];  
       /*    printf("%d ",C[i][j]); */
    }
    /* printf("\n"); */
      }
    }
 
 
     for(i=0; i<n; i++) {
      for(j=0; j<l; j++) {
    printf("%lld",C[i][j]);
    if(j !=l-1) {
      printf(" ");
    }
      }
      printf("\n");
      } 
 
    return 0;
 
  }


Measured memory_bytes: 2088
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	map <int, int> m;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		m[x]++;
	}
	int ans = 0;
	for (auto g : m) {
		if(g.ff != g.ss) {
			if(g.ss > g.ff)
				ans += (g.ss - g.ff);
			else
				ans += g.ss;
		}
	}
	cout << ans;
}


Measured memory_bytes: 4736
import sys
input = sys.stdin.readline

H, W = map(int, input().split())

C = []
for _ in range(10):
    C.append(list(map(int, input().split())))

A = []
for _ in range(H):
    A.append(list(map(int, input().split())))

# グラフの辞書化
graph = {}
for i in range(10):
    graph[i] = {}
    for j in range(10):
        graph[i][j] = C[j][i]
        
#print(graph)


from heapq import heappush, heappop

def dijkstra(graph, start, N):
    A = [None] * (N+1)
    queue = [(0, start)]
    while queue:
        path_len, v = heappop(queue)
        if A[v] is None: # v is unvisited
            A[v] = path_len
            for w, edge_len in graph[v].items():
                if A[w] is None:
                    heappush(queue, (path_len + edge_len, w))

    # to give same result as original, assign zero distance to unreachable vertices             
    return [0 if x is None else x for x in A]

shrtest = dijkstra(graph, 1, 10)
#print(shrtest)

ans = 0
for sub_a in A:
    for a in sub_a:
        if a == -1 or a == 1:
            continue
        else:
            ans += shrtest[a]
print(ans)


Measured memory_bytes: 40540
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c,i)
    ans+=x*(n-y)
print(ans)

Measured memory_bytes: 29264
char s[];main(){double*q=s,b;for(;~scanf("%s",s);getchar()<14&&printf("%f\n",*q))!sscanf(s,"%lf",q+1)?b=*q--,*q=*s-47?*s-42?*s-45?*q+b:*q-b:*q*b:*q/b:*++q;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int n;
    while(sf("%d",&n)==1)
    {
        int two=0;
        for(int i=0;i<n;i++)
        {
            ll x;
            sf("%lld",&x);
            while(x%2==0)two++,x/=2;
        }
        pf("%d\n",two);
    }
    return 0;
}
 









 




























Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());

        int[] heights = new int[N];
        for (int i = 0; i < N; i++) {
            heights[i] = scanner.nextInt();
        }
        scanner.close();

        Arrays.sort(heights);

        int minDiff = Integer.MAX_VALUE;
        for (int i = 0; i <= N - K; i++) {
            int min = heights[i];
            int max = heights[i + K - 1];
            int diff = max - min;
            if (diff < minDiff) {
                minDiff = diff;
            }
        }

        System.out.println(minDiff);
    }
}


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

int main(){

    int n;
    cin >> n;

    int a[n];
    int minus_count = 0;
    for(int i=0; i<n; i++){
        int new_num;
        cin >> new_num;
        if(new_num < 0){
            minus_count ++;
            new_num = - new_num;
        }

        a[i] = new_num;
    }
    sort(a, a+n);

    long long int res = 0;

    if(minus_count % 2 == 0){

        for(int i=0; i<n; i++){
            res = res + (long long int)a[i];
        }
    }else{
        for(int i=1; i<n; i++){
            res = res + (long long int)a[i];
        }
        res = res - a[0];
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

S = input()

# 各地点の高さを求める
v = {'\\': -1, '_': 0, '/': 1}
h = 0  # 左端の高さ
H = [h]
for s in S:
    h += v[s]
    H.append(h)

# 右部分列の最大値
R = [0] * len(H)
R[-1] = -float('inf')
for i in range(len(R) - 2, -1, -1):
    R[i] = max(R[i+1], H[i+1])

A = []
i = 0
while True:
    # 左端の左斜面をスキップ
    while i < len(S) and S[i] != '\\':
        i += 1

    # 右側の縁と同じ高さまでスキップ
    while i < len(S) and (H[i] > R[i] or S[i] == '_'):
        i += 1

    if i >= len(S):
        break

    # 水たまりの面積を求める
    h = H[i]  # 左端の高さ
    a = 0     # 面積
    while i < len(S):
        a += (h - H[i]) + (H[i] - H[i+1])/2
        i += 1
        if H[i] == h: break
    A.append(int(a))

print(sum(A))
print(' '.join(map(str, [len(A)] + A)))


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

int main(){
    int i, j, num, rev, A, B, count=0;
    cin >> A >> B;
    for(i=A;i<=B;i++){
        rev = 0;
        num = i;
        for(j=0;j<5;j++){
            rev *= 10;
            rev += num % 10;
            num /= 10;
        }
        if(i == rev) count++;
    }
    cout << count << endl;
}


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

void out(vector<int> a){
		bool isFirst = true;
		for(auto &&ai: a){
			if(!isFirst) cout<<" ";
			cout<<ai;
			isFirst &= false;
		}
		cout<<endl;;	
}

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

	vector<int> prev(a), nx(a);
	prev_permutation(prev.begin(),prev.end());
	if(lexicographical_compare(prev.begin(),prev.end(),a.begin(),a.end())) out(prev);
	out(a);
	next_permutation(nx.begin(),nx.end());
	if(lexicographical_compare(a.begin(),a.end(),nx.begin(),nx.end())) out(nx);
	return 0;
}



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

int main()
{
    int n, ans = 0;
    int l, r;
    cin >> n;

    vector<int> h(n), tmp(n, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> h.at(i);
    }

    while (h != tmp)
    {
        l = -1;
        r = -1;
        for (int i = 0; i < n; i++)
        {
            if ((l < 0) and (tmp.at(i) < h.at(i)))
                l = i;

            if ((i != n - 1) and (tmp.at(i + 1) >= h.at(i + 1)) and (tmp.at(i) < h.at(i))) {
                if (r < 0)
                    r = i;
            }
            if ((r < 0) and (i == n - 1) and (tmp.at(i) < h.at(i)))
                r = i;
        }
        for (int i = l; i <= r; i++)
            tmp.at(i)++;
        
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int alpha[n][26];
    int l=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<26;j++)alpha[i][j]=0;
        string s;
        cin>>s;
        for(int j=0;j<s.size();j++){
            alpha[i][s[j]-'a']++;
        }
    }
    string ans="";
    for(int j=0;j<26;j++){
        int m=50;
        for(int i=0;i<n;i++){
            m=min(m,alpha[i][j]);
        }
        for(int i=0;i<m;i++){
            ans+=('a'+j);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int d[3601];
int h, w;
vector<vector<edge>> es;
int fld[30][30];
int cost[4];

void dijkstra(int s)
{
	fill(ALL(d), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		REP(i, es[v].size())
		{
			edge e = es[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
//i*w+j
// 3
//2 0
// 1
int dx[] = { 0, 1, 0, -1 }; int dy[] = { 1, 0, -1, 0 };
int main()
{
	while (cin >> w >> h, w)
	{
		es.clear();
		REP(i, h)REP(j, w) cin >> fld[i][j];
		REP(i, 4) cin >> cost[i];
		int goal = w*h - 1;
		es.resize(h*w*4);
		REP(i, h)REP(j, w)REP(k, 4)
		{
			int tmp = (i*w + j) + h*w*k;
			REP(l, 4)
			{
				int nx = i + dx[l]; int ny = j + dy[l];
				int next = (nx*w + ny)+h*w*l;
				if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
				if (fld[i][j] == 4) 
				{
					es[tmp].push_back(edge{ tmp, next, cost[(l - k + 4) % 4] });
				}
				else
				{
					if ((k + fld[i][j]) % 4 == l) es[tmp].push_back(edge{ tmp, next, 0 });
					else
					{
						es[tmp].push_back(edge{ tmp, next, cost[(l - k + 4) % 4] });
					}
				}
			}
		}

		dijkstra(0);

		cout << min({ d[goal], d[goal + h*w] }) << endl;
	}
	return 0;

}

Measured memory_bytes: 1520
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
  long long n;
  int ans = 0;
  cin >> n;
  if(n == 1){
    cout << ans << endl;
    return 0;
  }
  int num = sqrt(n);
  for(int i = 2; i < num; i++){
    int e = 1;
    int cnt = 0;
    while((n % (long long)pow(i,e)) == 0){
      cnt++;
      n /= pow(i,e);
      e++;
    }
    while(n % i == 0) n /= i;
    ans += cnt;
    if(n == 1) {
      cout << ans << endl;
      return 0;
    }
  }
  ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4088
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define pii pair<int,int>
#define x first
#define y second

const int N=1e5+5;
pii a[N];
int n,ans;

bool cmp(pii x,pii y){
  return x.y<y.y;
}

signed main(){
	read(n);
	for(int i=1,x,y;i<=n;i++) read(x,y),a[i]=pii(x-y,x+y);
	sort(a+1,a+1+n,cmp);
	for(int i=1,ma=INT_MIN;i<=n;i++)
		if(a[i].x>=ma) ans++,ma=a[i].y;
	write(ans);
}

Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[400000];
long long K;
int ls[200001];
int nx[200000];
int p[200000];
int res[200000];
int ress;
int main(){
  int i, j, k;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    A[i+N] = A[i];
  }
  for(i=2*N-1;i>=N;i--){
    ls[A[i]] = i;
  }
  for(i=N-1;i>=0;i--){
    nx[i] = ls[A[i]] + 1;
    while(nx[i] >= N){
      nx[i] -= N;
      p[i]++;
    }
    ls[A[i]] = i;
  }
  i = k = 0;
  for(;;){
    k += p[i];
    i = nx[i];
    if(i==0){
      break;
    }
  }
  K %= k;
  i = 0;
  while(K){
    if(K-p[i] < 0 || (K-p[i] == 0 && nx[i] > 0)){
      res[ress++] = A[i];
      i++;
      if(i==N){
        K--;
      }
      continue;
    }
    K -= p[i];
    i = nx[i];
  }
  {
    int KL2GvlyY;
    if(ress==0){
      putchar_unlocked('\n');
    }
    else{
      for(KL2GvlyY=0;KL2GvlyY<ress-1;KL2GvlyY++){
        wt_L(res[KL2GvlyY]);
        wt_L(' ');
      }
      wt_L(res[KL2GvlyY]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, A[4d5];
// ll K;
// 
// int ls[200001];
// int nx[2d5], p[2d5];
// 
// int res[2d5], ress;
// 
// {
//   int i, j, k;
//   rd(N,K,A(N));
// 
//   rep(i,N) A[i+N] = A[i];
//   for(i=2N-1;i>=N;i--) ls[A[i]] = i;
//   for(i=N-1;i>=0;i--){
//     nx[i] = ls[A[i]] + 1;
//     while(nx[i] >= N) nx[i] -= N, p[i]++;
//     ls[A[i]] = i;
//   }
// 
//   i = k = 0;
//   for(;;){
//     k += p[i];
//     i = nx[i];
//     if(i==0) break;
//   }
// 
//   K %= k;
// 
//   i = 0;
//   while(K){
//     if(K-p[i] < 0 || (K-p[i] == 0 && nx[i] > 0)){
//       res[ress++] = A[i];
//       i++;
//       if(i==N) K--;
//       continue;
//     }
// 
//     K -= p[i];
//     i = nx[i];
//   }
// 
//   wt(res(ress));
// }


Measured memory_bytes: 6144
o = input()
e = input()

ans = ''
i1 = 0
i2 = 0
for i in range(len(o) + len(e)):
    if i % 2 == 0:
        ans += o[i1]
        i1 += 1
    else:
        ans += e[i2]
        i2 += 1
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
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();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,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 main(){
  ll N,ans=0;
  cin>>N;
  vector<ll> A;
  REP(i,N){
    ll a;
    cin>>a;
    A.PB(a);
  }
  SORT(A);
  REVERSE(A);
  
  for(int i=1; i<N; ++i){
    ans+=A[i/2];
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 5364
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      c: Bytes
   }
   let mut ans = 0;
   let mut i = 0;
   let mut j = n - 1;
   loop {
      while i < n - 1 && c[i] == b'R' {
         i += 1;
      }
      while j > 0 && c[j] == b'W' {
         j -= 1;
      }
      if i < j {
         ans += 1;
         i += 1;
         j -= 1;
      } else {
         break;
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 2460
N = int(input())
robots = [list(input().split()) for _ in range(N)]
rng = sorted([[int(i[0]) - int(i[1]), int(i[0]) + int(i[1])] for i in robots], key = lambda x:x[1])

ans = 0
rng_s = -10**9
for i in rng:
    if rng_s <= i[0]:
        ans += 1
        rng_s = i[1]

print(ans)

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

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<int> g[n], cs(n), ds(n), ans(n, -1);
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
		ds[a]++;
		ds[b]++;
	}
	vector<pair<int, int>> ps(n);
	for (int i = 0; i < n; i++)
	{
		cin >> cs[i];
		ps[i] = make_pair(ds[i], i);
	}
	sort(ps.rbegin(), ps.rend());
	sort(cs.rbegin(), cs.rend());
	long res = 0;
	for (int i = 1; i < n; i++)
	{
		res += cs[i];
	}
	int sv = 0, cnt = 0;
	ans[sv] = cs[cnt++];
	queue<int> q;
	q.push(sv);
	while(!q.empty())
	{
		int v = q.front();
		q.pop();
		for (int nv : g[v])
		{
			if (ans[nv] != -1)
			{
				continue;
			}
			q.push(nv);
			ans[nv] = cs[cnt++];
		}
	}
	cout << res << endl;
	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << (i == n-1 ? '\n' : ' ');
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

ll MOD = 1e9+7;

int main(void){

    int N; cin >> N;
    ll ans=1;
    for (int i = 1; i <= N; ++i) {
        ans *= i;
        ans %= MOD;
    }

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

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

using namespace std;
int main(){
	int year,month,day; string era;
	while(cin>>year>>month>>day){
		if(year<=1868) era="pre-meiji";
		if(year==1868 && month==9 && day>=8) era="meiji";
		if(year==1868 && month>9) era="meiji";
		if(year>1868 && year<=1912) era="meiji";
		if(year==1912 && month>=7 && day>=30) era="taisho";
		if(year==1912 && month>=8) era="taisho";
		if(year>=1913 && year<=1926) era="taisho";
		if(year==1926 && month==12 && day>=25) era="showa";
		if(year>=1927 && year<=1988) era="showa";
		if(year>=1989) era="heisei";
		if(year==1989 && month==1 && day<=7) era="showa";
	
		if(era=="pre-meiji") cout << era << '\n' ;
		if(era=="meiji") cout<<era<<' '<<year-1867<<' '<<month<<' '<<day<<'\n' ;
		if(era=="taisho") cout<<era<<' '<<year-1911<<' '<<month<<' '<<day<<'\n';
		if(era=="showa") cout<<era<<' '<<year-1925<<' '<<month<<' '<<day<<'\n' ;
		if(era=="heisei") cout<<era<<' '<<year-1988<<' '<<month<<' '<<day<<'\n' ;
	};
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int N;
    cin >> N;
    vector<int> v(101);
    int tmp;
    for (int i = 0; i < N; ++i) {
        cin >> tmp;
        v.at(tmp) = 1;
    }
    int ans = 0;
    for (int j = 0; j < v.size(); ++j) {
        if(v.at(j) == 1){
            ans++;
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// int64_t GCD1(int64_t a, int64_t b)
// {
//   if (b == 0)
//     return a;
//   else
//     return GCD(b, a % b);
// }
// int64_t GCD2(int64_t c, int64_t b)
// {
//   if (b == 0)
//     return c;
//   else
//     return GCD(b, c % b);
// }
// int64_t GCD3(int64_t a, int64_t c)
// {
//   if (c == 0)
//     return a;
//   else
//     return GCD(a, c % a);
// }
// int64_t gcd(int64_t x, int64_t y) { return (x % y) ? gcd(y, x % y) : y; }
int64_t getgcd(int64_t n, int64_t m)
{
  int64_t r;
  if (n > m)
  {
    int64_t t = m;
    m = n;
    n = t;
  }
  while ((r = m % n) != 0)
  {
    m = n;
    n = r;
  }
  return n;
}

int main()
{
  int64_t k;
  cin >> k;
  int64_t gcd;
  int64_t ans;
  vector<int64_t> z(1);
  vector<int64_t> vecA(k);
  vector<int64_t> vecB(k);
  vector<int64_t> vecC(k);
  for (int i = 0; i < k; i++)
  {
    vecA.at(i) = i + 1;
    vecB.at(i) = i + 1;
    vecC.at(i) = i + 1;
  }

  for (int64_t i = 0; i < k; i++)
  {
    for (int64_t j = 0; j < k; j++)
    {
      for (int64_t l = 0; l < k; l++)
      {
        gcd = getgcd(getgcd(vecA.at(i), vecB.at(j)), vecC.at(l));
        // cout << gcd << endl;
        ans += gcd;
        // ans += d;
        // cout << vecC.at(l) << endl;
        // ans += 1;
      }
    }
    z.at(0) = ans;
  }
  cout << z.at(0) << endl;
  // cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>

#define MAXN 10000

using namespace std;

struct edge{
	int nn;
	int w;
	edge(int a, int b){nn = a; w = b;}
};

vector<edge> node[MAXN];

int maxdist[MAXN];
int visited[MAXN];

void DFS(int idx, int w){
	visited[idx] = 1;
	if(w > maxdist[idx]) maxdist[idx] = w;
	
	for(int i = 0; i < node[idx].size(); i++){
		if(visited[node[idx][i].nn]) continue;
		
		DFS(node[idx][i].nn, w + node[idx][i].w);
	}
}

int main(){
	
	int n;
	int x, y, z;
	
	scanf("%d", &n);
	
	for(int i = 0; i < n - 1; i++){
		//cin >> x >> y >> z;
scanf("%d %d %d", &x, &y, &z);
		
		node[x].push_back(edge(y,z));
		node[y].push_back(edge(x,z));
	}
	
	for(int i = 0; i < n; i++){
		if(node[i].size() != 1) continue;
		memset(visited, 0, sizeof(visited));
		DFS(i, 0);
	}
	
	for(int i = 0; i < n; i++){
//cout << maxdist[i] << endl;
printf("%d\n", maxdist[i]);
	}
	return 0;
}

Measured memory_bytes: 4316
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    S = input_raw[0]
    max_count = 0
    for i in range(len(S)):
        for j in range(i, len(S)):
            new_S = S[i:j+1]
            not_agct = False
            for news in new_S:
                if news != "A" and news != "G" and news!="C" and news !="T":
                    not_agct = True
                    break
            if not_agct == False:
                max_count = max(max_count , len(new_S))
    print max_count



if __name__ == '__main__':
    main()


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

int main()
{
    char c;
    bool flag = false;
    for (int i = 0; i < 3; i++){
        cin >> c;
        if (c == '7') flag = true;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
fn main() {
    let s: Vec<u8> = read::<String>().bytes().collect();
    let mut mod_t = vec![0];
    let mut sum = 0;
    let mut base = 1;
    let mut ma: HashMap<usize, usize> = HashMap::new();
    ma.insert(0, 1);
    for i in (0..s.len()).rev() {
        sum += base * (s[i] - b'0') as usize;
        sum %= 2019;
        mod_t.push(sum);
        match ma.get_mut(&sum) {
            Some(v) => *v += 1,
            None => {
                ma.insert(sum, 1);
            }
        }
        base *= 10;
        base %= 2019;
    }
    let mut ans = 0;
    for (_, v) in ma {
        ans += v * (v - 1) / 2;
    }
    println!("{}", ans);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, k; cin >> n >> k;
    vector<ll> x(n);
    ll ans = 1e9;
    for (ll i = 0; i < n; ++i) 
        cin >> x[i];
    for (ll i = 0; i < n - k + 1; ++i) {
        ll l = x[i], h = x[i + k - 1];
        if (l < 0 && h > 0) ans = min(ans, 2 * min(abs(l), abs(h)) + max(abs(l), abs(h)));
        else ans = min(ans, max(abs(l), abs(h)));
    }
    if (n == 1) ans = abs(x[0]);
    cout << ans << "\n";
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define se second
#define fi first
#define mp make_pair
#define pb push_back
#define ll long long
const int MAXN = (int)1e7 + 1000;
const int N = (int)1e5 + 100;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9;
ll a[N],b[N];
int main(){
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)cin >> a[i] >> b[i];
    ll ans = 0;
    for(int i = n;i >= 1;--i){
        ans += ((b[i] - (a[i] + ans) % b[i]) % b[i]);
    }
    cout << ans;
    return 0;
}


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

using namespace std;

int main(void) {
    long long X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector <long long> A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < Y; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < Z; i++) {
        cin >> C[i];
    }

    vector <long long> AB;
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            AB.push_back(A[i] + B[j]);
        }
    }

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

    vector <long long> ABC;
    for (int i = 0; i < min(K, (long long)AB.size()); i++) {
        for (int j = 0; j < Z; j++) {
            ABC.push_back(AB[i] + C[j]);
        }
    }

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

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

Measured memory_bytes: 43368
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using namespace std;


int n;
int a[100010];


llint solve(){
	llint ans1 = 0, ans2 = 0;
	llint sum = 0;
	rep(i, 0, n){
		sum += a[i];
		if(i%2 == 0 && sum <= 0){
			ans1 += 1-sum;
			sum = 1;
		}
		else if(i%2 == 1 && sum >= 0){
			ans1 += sum+1;
			sum = -1;
		}
	}
	sum = 0;
	rep(i, 0, n){
		sum += a[i];
		if(i%2 == 0 && sum >= 0){
				ans2 += sum+1;
				sum = -1;
		}
		else if(i%2 == 1 && sum <= 0){
			ans2 += 1-sum;
			sum = 1;
		}
	}
	return min(ans1, ans2);
}


signed main(){
	cin >> n;
	rep(i, 0, n) cin >> a[i];

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 640
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n,m = invr()
nums = inlt()
s = sum(nums)
print(n - s if s <= n else -1)
#print('No')
#print()



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

const ll MOD=1e9+7;

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

if(abs(N-M)>=2){
    cout<<0<<endl; return 0;
}

if(N<M) swap(N,M);

if(N==M){
    ll F=1LL;
    for(int i=N; i>=1; i--){
        F=(F*i)%MOD;
    }
    F=F*F%MOD;
    F=(F*2)%MOD;
    cout<<F<<endl; 
}
else{
    ll F=1LL;
    for(int i=M; i>=1; i--){
        F=(F*i)%MOD;
    }
    ll E=(F*N)%MOD;
    F=E*F%MOD;
    cout<<F<<endl; 
}

}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int N;//都市数
	int M;//道路
	scanf("%d %d",&N,&M);

	int a[M];
	int b[M];
	int c[N];

	for(int j=1; j<=N; j++){
		c[j] = 0;
	}

	for(int i=1; i<=M; i++){
		scanf("%d %d",&a[i],&b[i]);
		c[a[i]]++;
		c[b[i]]++;
	}

	for(int k=1; k<=N; k++){
		printf("%d\n",c[k]);
	}

	return 0;

}

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

int main() {
  int n;cin>>n;
  int ans = 0;
  int cnt;
  for (int i=1; i<=n; i+=2) {
    cnt = 0;
    for (int j=1; j<=i; j++) if (i%j == 0) cnt++;
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
whole_list = []
for b in range(4):
    whole_list.append([])
for b in range(4):
    for f in range(3):
        whole_list[b].append([])
for b in range(4):
    for f in range(3):
        for r in range(10):
            whole_list[b][f].append(0)

for _ in range(n):
    b, f, r, v = map(int, input().split())
    whole_list[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        temp_list = []
        for r in range(10):
            temp_list.append(str(whole_list[b][f][r]))
        print(" " + " ".join(temp_list))
    if b>=0 and b<=2:
        print("#"*20)




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

int dig[200010][40];

int main(){
    ll n;cin>>n;
    ll a[200010];
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum=sum^a[i];
    }
    ll an;
    rep(i,0,n){
        if(i!=0)cout<<" ";
        an=sum^a[i];
        cout<<an;
    }
    cout<<endl;
}

    









Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int const INF = 1 << 30;


int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int l = 0, r = INF;
    while(r - l > 1) {
        int mid = (l + r)/2;
        auto C = [&]() {
            int cnt = 0;
            rep(i,n) cnt += (a[i]-1)/mid;
            return cnt <= k;
        };
        if(C()) r = mid;
        else l = mid;
    }

    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3940
a,b,c,n = map(int,input().split())
ans = 0
for i in range(0,3001):
  for j in range(0,3001):
    dum1,dum2 = divmod((n-(a*i+b*j)),c)
    if dum2 == 0 and dum1 >= 0:
      ans += 1
print(ans)

Measured memory_bytes: 40940
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=2e5+5;
char s[N];int cnt[26],n,sum;ll res;
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	fp(i,1,n)res+=sum-cnt[s[i]-'a'],++cnt[s[i]-'a'],++sum;
	printf("%lld\n",res+1);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,m,a;
    cin >> n >> m;
    priority_queue<ll> q;
    for(int i=0;i<n;i++){
        cin >> a;
        q.push(a);
    }
    for(int i=0;i<m;i++){
        a = q.top();
        q.pop();
        q.push(a/2);
    }
    ll ans = 0;
    while(!q.empty()){
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n)         for(int i=0; i<(n); i++)
#define P pair<int, int>
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"

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

int main(){
    int x; cin >> x;
    if(x == 7 || x == 5 || x == 3) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
def factorize(n):
    """
    素因数はたかだか n**0.5 以下
    :return: e.g. factorize(24) -> {2: 3, 3: 1} (24 = 2**3 * 3**1)
    """
    res = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            res[i] = 0
            while temp % i ==0:
                res[i] += 1
                temp //= i

    if temp != 1:
        res[temp] = 1

    if len(res) == 0:
        res[n] = 1

    return res

def factorize_exp(n):
    """
    Return only exponents of factorization.
    :return: e.g. factorize(24) -> [3, 1] (24 = 2**3 * 3**1)
    """
    res = []
    temp = n

    if n == 1:
        # 1 は素数ではない
        return res

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            res.append(cnt)
    if temp != 1:
        res.append(1)

    if len(res) == 0:
        res.append(1)

    return res


n = int(input())
factors = factorize_exp(n)
cnt = 0

for i in factors:
    rem = i
    j = 1
    while rem >= j:
        rem -= j
        cnt += 1
        j += 1

print(cnt)

Measured memory_bytes: 9540
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    int boader = n / 2;
    if (n%2==1){
        boader += 1;
    }
    vector<int> a(n),ans(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
        if (i>=boader){
            ans[i] = a[i];
        }
    }
    for (int i=boader;i>0;i--){
        int x = 0,mul = i * 2;
        while (mul<=n){
            x += ans[mul-1];
            mul += i;
        }
        if (a[i-1]==0){
            if (x%2==0){
                ans[i-1] = 0;
            } else {
                ans[i-1] = 1;
            }
        } else {
            if (x%2==0){
                ans[i-1] = 1;
            } else {
                ans[i-1] = 0;
            }
        }
    }
    int m = 0;
    for (int i=0;i<n;i++){
        if (ans[i]==1){
            m += 1;
        }
    }
    cout << m << endl;
    for (int i=0;i<n;i++){
        if (ans[i]==1){
            cout << i+1 << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	ll N;
	cin >> N;

	vll ans;

	ll base = 1;
	for (int i = 0; i < 50; i++)
	{

		bool stand = (N % (base * (-2))) != 0;

		ans.emplace_back(ll(stand));

		N -= base * stand;

		base *= -2;


	}

	int last = 0;
	for (int i = 0; i < 50; i++)
	{
		if (ans[i] == 1)
		{
			last = i;
		}
	}

	for (int i = last; i >= 0; i--)
	{
		cout << ans[i];
	}


}





Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
#define int lld
int pw(int a,int m,int p){
    int res=1;
    while(m)m&1?res=1ll*res*a%p:0,a=1ll*a*a%p,m>>=1;
    return res;
}
const int N=20,NN=1<<18,P=998244353;

int n,nn;
int p[NN],s;
int c[NN];

void fwt(int *f,int len){
    for(int j=1;j<len;j<<=1)
        for(int i=0;i<len;i+=j<<1)
            for(int k=i,u,v;k<i+j;k++)
                u=f[k],v=f[k+j],f[k]=(u+v)%P,f[k+j]=(u-v+P)%P;
}
void ifwt(int *f,int len){
    for(int j=1;j<len;j<<=1)
        for(int i=0;i<len;i+=j<<1)
            for(int k=i,u,v;k<i+j;k++)
                u=f[k],v=f[k+j],f[k]=(u+v)%P,f[k+j]=(u-v+P)%P;
    int ilen=pw(len,P-2,P);
    FOR(i,0,len-1)f[i]=1ll*f[i]*ilen%P;
}
signed main(){
    scanf("%lld",&n);
    nn=1<<n;
    FOR(i,0,nn-1)scanf("%lld",&p[i]),s=(s+p[i])%P;
    s=pw(s,P-2,P);
    FOR(i,0,nn-1)p[i]=1ll*p[i]*s%P;
    p[0]--;
    c[0]=nn-1;
    FOR(i,1,nn-1)c[i]=P-1;
    fwt(p,nn),fwt(c,nn);
    FOR(i,0,nn-1)c[i]=1ll*c[i]*pw(p[i],P-2,P)%P;
    ifwt(c,nn);
    FOR(i,0,nn-1)printf("%lld\n",(c[i]-c[0]+P)%P);
    return 0;
}


Measured memory_bytes: 6912