akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<vector>

using namespace std;

typedef long long ll;

int count(int n, int d){
	int ret = 0, temp = d;
	while(temp <= n){
		ret += n / temp;
		temp *= d;
	}
	return ret;
}

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

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

	int n, ans = 0;
	cin >> n;
	bool prime[n + 5];
	vector<int> p;
	memset(prime, true, sizeof(prime));
	for(int i = 2 ; i * i <= n ; i++){
		if(prime[i]){
			for(int j = i * i ; j <= n ; j += i){
				prime[j] = false;
			}
		}
	}
	for(int i = 2 ; i <= n ; i++){
		if(prime[i]){
			p.push_back(count(n, i));
		}
	}
	for(int i = 0 ; i < (int)p.size() ; i++){
		if(p[i] >= 74){
			++ans;
		}
	}
	for(int i = 0 ; i < (int)p.size() ; i++){
		for(int j = i + 1 ; j < (int)p.size() ; j++){
			if(p[i] >= 24 && p[j] >= 2) ++ans;
			if(p[i] >= 2 && p[j] >= 24) ++ans;
			if(p[i] >= 14 && p[j] >= 4) ++ans;
			if(p[i] >= 4 && p[j] >= 14) ++ans;
		}
	}
	for(int i = 0 ; i < (int)p.size() ; i++){
		for(int j = i + 1 ; j < (int)p.size() ; j++){
			for(int k = j + 1 ; k < (int)p.size() ; k++){
				if(p[i] >= 4 && p[j] >= 4 && p[k] >= 2) ++ans;
				if(p[i] >= 4 && p[j] >= 2 && p[k] >= 4) ++ans;
				if(p[i] >= 2 && p[j] >= 4 && p[k] >= 4) ++ans;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


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

bool eq(char a,char b){
    return b == '#';
}

int main(){
    int h,w;
    char a[52][52];
    char b[52][52];

    cin >> h >> w;

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

    for(int i = 0;i < h+2;++i){
        a[i][0] = 48;
        a[i][w+1] =48;
    }

    for(int i = 0;i < w+2;++i){
        a[0][i] = 48;
        a[h+1][i] = 48;
    }

    for(int i = 1;i < h + 1;++i){
        for(int j = 1;j < w + 1;++j){
            if(a[i][j] == '#')  {b[i][j] = '#';cout << b[i][j]; continue;}
            
            b[i][j] = 48+eq(a[i][j],a[i-1][j-1])+eq(a[i][j],a[i-1][j])+eq(a[i][j],a[i-1][j+1])+eq(a[i][j],a[i][j-1])+eq(a[i][j],a[i][j+1])+eq(a[i][j],a[i+1][j-1])+eq(a[i][j],a[i+1][j])+eq(a[i][j],a[i+1][j+1]);
            cout <<b[i][j];
        }
        cout << endl;
    }
        
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const int limit = 200010;
ll a[limit];
ll csum[limit];

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n) csum[i+1] += csum[i] + a[i];

	ll ans = 1LL << 60;

	rep(i,2,n-1){
		// [1, i]
		const ll sa = csum[i];
		const int apos = lower_bound(csum,csum + i, (sa + 1) /2) - csum;


		//[i+1,n]
		const ll sb = csum[n] - csum[i];
		const int bpos = lower_bound(csum + i + 1,csum + n - 1, (sb + 1) /2 + csum[i]) - csum;

		for(auto &aidx:{apos,apos-1}){
			for(auto &bidx:{bpos,bpos-1}){
				const int anum = aidx;
				const int bnum = i - aidx;
				const int cnum = bidx - i;
				const int dnum = n - bidx;
				//cerr << aidx << " " << i << " " << bidx << endl;
				if(min({anum,bnum,cnum,dnum}) == 0) continue;				
				const auto res = minmax({csum[aidx],csum[i] - csum[aidx],csum[bidx] - csum[i], csum[n] - csum[bidx]});
				chmin(ans,res.second - res.first);
			}
		}
	}

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

Measured memory_bytes: 3328
#include<stdio.h>
int main()
{
    int n, k, i, d, j, m;
    scanf("%d %d",&n,&k);
    int a[n+1];
    for(i=0;i<n+1;i++)
    {
        a[i]= 0;
    }
    for(i=0;i<k;i++)
    {
        scanf("%d",&d);
        for(j=0;j<d;j++)
        {
            scanf("%d",&m);
            a[m]=1;
        }
    }
    int c =0 ;
    for(i=1;i<n+1;i++)
    {
        if(a[i]==0)
        {
            c++;
        }
    }
    printf("%d",c);
    return 0;
}

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

int main() {
	
	int n, m; cin >> n >> m;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vector<int> maxh(n, -1);
	vector<int> tmp(n, -10000000);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		a--;
		b--;
		maxh[a] = max(maxh[a], h[b]);
		maxh[b] = max(maxh[b], h[a]);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (maxh[i] < h[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if ((b-1) % (a-1) == 0)
        cout << (b-1) / (a-1);
    else
        cout << (b-1) / (a-1) + 1;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ref(i,x,y)for(int i=x;i<=y;++i)
using namespace std;
typedef long long LL;
const int mod=998244353;
int n;
char a[300010];	
#define R(a) (a=='R'?1:(a=='G'?2:3))
int mul(int a,int b){return (LL)a*b%mod;}
int main(){
	scanf("%d",&n);
	scanf("%s",a+1);
	int id=0,idct=0,id2=0,   idct2=0,ans=1;
	ref(i,1,n*3){
		int c=R(a[i]);
		if(idct==0&&(c==id||c==id2)||id==0){
			if(id==0)id=c;else if(c==id2)swap(id,id2);
			idct++;
		}else
		if(c==id&&idct>0)idct++;
		else{
			if(id2==0)id2=c,idct2=1,ans=mul(ans,idct),idct--;
			else if(id2==c)idct2++,ans=mul(ans,idct),idct--;
			else{
				ans=mul(ans,idct2);
				idct2--;
				if(idct2==0)id2=0;
			}
		}
		if(id2==0&&idct==0)id=0;
	}
	ref(i,1,n)ans=mul(ans,i);
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    int N, K;
    cin >> N >> K;
    vector<int>vec(N);
    for(int i = 0; i < N; i++)cin >> vec[i];
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int ans = 0;
    for(int i = 0; i < K; i++)ans += vec[i];
    cout << ans << endl;


    return 0;
}

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

int yoc(int n){
  if (n%2==1){
    return 0;
  }
  return yoc(n/2)+1;
}
int main(){
  int N;
  cin >> N;
  int a[N];
  int ans;
  for (int i=0;i<N;i++){
    cin >> a[i];
    ans=i==0?yoc(a[i]):min(ans,yoc(a[i]));
  }
  cout << ans << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, K;
bool check(vector<ll>& A, ll len) {
  ll cnt = 0;
  for (ll i = 0; i < N; ++i) {
    ll a = A.at(i);
    cnt += (a - 1) / len;
    // ll temp = 0;
    // ll p = 1;
    // ll temp_len = len;
    // while (a > temp_len) {
    //   temp_len *= 2;
    //   temp += p;
    //   p *= 2;
    // }
    // cnt += temp;
  }
  // cout << "cnt" << cnt << "\n";
  if (cnt <= K) {
    return true;
  }
  else {
    return false;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  ll l = 0, r = pow(10, 9) + 1;
  while (l + 1 != r) {
    ll m = (l + r) / 2;
    if (check(A, m)) {
      r = m;
    }
    else {
      l = m;
    }
  }
  cout << r << "\n";
}


Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)

int main()
{
    fast;
    ll n,k,x,y;
    cin>>n>>k>>x>>y;
    ll mn=min(n,k);
    long long ans=0;
    ans+=mn*x;
    n-=k;
    if(n>0)ans+=n*y;
    cout<<ans<<endl;
}



Measured memory_bytes: 3616
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    k = ii()
    done = [0 for i in range(k + 10)]
    tmp = 0
    cnt = 0
    while True:
        cnt += 1
        tmp *= 10
        tmp += 7
        tmp %= k
        if done[tmp]:
            print(-1)
            exit()
        if tmp == 0:
            print(cnt)
            exit()
        done[tmp] = 1


main()


Measured memory_bytes: 17668
#include<bits/stdc++.h>
int n,d1,d2,color[606][606],N;
void paint(int d){
	int b=0;
	while(!(d&3))d>>=2,++b;
	if(d&1){
		for(int i=0;i<N;++i)
		for(int j=0;j<N;++j)
		if(((i>>b)+(j>>b))&1)color[i][j]=1;
	}else{
		for(int i=0;i<N;++i)
		for(int j=0;j<N;++j)
		if((i>>b)&1)color[i][j]=1;
	}
}
int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	N=n<<1;
	paint(d1),paint(d2);
	int NN=n*n;
	for(int i=0;i<N;++i)
	for(int j=0;j<N;++j)
	if(!color[i][j]){
		printf("%d %d\n",i,j);
		if(!--NN)return 0;
	}
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n, m;
  while(cin >> n >> m, n != 0 && m != 0) {
    vt<int> sum_h(n + 1, 0), sum_w(m + 1, 0);
    rep(i, 0, n) {
      int h;
      cin >> h;
      sum_h[i + 1] += sum_h[i] + h;
    }
    rep(i, 0, m) {
      int w;
      cin >> w;
      sum_w[i + 1] += sum_w[i] + w;
    }

    map<int, i64> cnt_h, cnt_w;
    rep(i, 0, n + 1) {
      rep(j, i + 1, n + 1) {
        cnt_h[sum_h[j] - sum_h[i]]++;
      }
    }
    rep(i, 0, m + 1) {
      rep(j, i + 1, m + 1) {
        cnt_w[sum_w[j] - sum_w[i]]++;
      }
    }

    i64 ans = 0;
    for(auto &it : cnt_h) {
      if(cnt_w.count(it.first)) ans += it.second * cnt_w[it.first];
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 38868
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
ll mo=1000000007;
int main() 
{ 
	ll t1=1;
	//cin>>t1;
	while(t1)
	{
		ll n;
		cin>>n;
		ll arr1[n];
		unordered_map<ll,ll> umap;
		for(ll i=0;i<n;i++){cin>>arr1[i];umap[arr1[i]]++;}
        sort(arr1,arr1+n);
		
		ll seive[1000001];
		for(ll i=0;i<1000001;i++)seive[i]=0;	
		
		ll c=0;
		for(ll i=0;i<n;i++)
		{
           if(seive[arr1[i]]==0)
           {
           	 if(umap[arr1[i]]==1)
           	 c++;
           	 for(ll j=1;arr1[i]*j<1000001;j++)
           	 {
           	 	seive[arr1[i]*j]=1;
           	 }
           }
		}
		cout<<c<<endl;
		t1--;
    }
    return 0; 
}

Measured memory_bytes: 20740
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	string p("keyence");

	int front_idx = 0;
	for (; front_idx < min(S.size(), p.size()); front_idx++)
	{
		if (S[front_idx] != p[front_idx])
		{
			break;
		}
	}

	int left_cnt = p.size() - front_idx;
	int back_idx = S.size() - left_cnt;
	for (; back_idx < S.size(); back_idx++, front_idx++)
	{
		if (S[back_idx] != p[front_idx])
		{
			cout << "NO";
			return 0;
		}
	}

	cout << "YES";

	return 0;
}


Measured memory_bytes: 256
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, gcd
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    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
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n = input()
yes = False
for i in n:
    if i == "7":
        yes = True
        break
if yes:
    print("Yes")
else:
    print("No")

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

using namespace std;

int main() {
    string S;
    int N, Q;
    int count[100001] = {0};
    int cur_count = 0;

    cin >> N >> Q;
    cin >> S;

    for (int i = 0; i < N-1; i++) {
        if (S[i] == 'A' && S[i+1] == 'C' ){
            cur_count++;
        }
        count[i+1] = cur_count;
    }

    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;

        cout << count[r-1] - count[l-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 1408
X = int(input())

import math

# n年後のお金
def calcX(n):
  X = 100
  for i in range(n):
    X = math.floor(X * 1.01)
  return X

year = 0
while True:
  if X > calcX(year):
    year += 1
  else:
    print(year)
    break

Measured memory_bytes: 9112
#include<bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace std;
#define ll long long
#define i1 int128_t
#define vi vector<long long>
#define st set<long long>
#define uset unordered_set<long long>
#define si set<long long>:: iterator
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(long long i=a; i<b; i++)
#define fs(i,a,s) for(long long i=a; s[i]!='\0'; i++)
#define endl "\n"

int main(){

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif

	ll n;
	cin>>n;

	if(n%1000)
		cout<<1000-n%1000;
	else
		cout<<0;
	 // fclose(stdin);
	 // fclose(stdout);
}


Measured memory_bytes: 3616
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

  int main() {
    debug();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int p,q,count=0;
    bool flag=false;
    for (int i = 0; i <n; ++i)
    {
    	cin>>p>>q;
    	if(p==q){
    		count++;
    	}else{
    		if(count>=3){
    			flag=true;
    		}
    		count=0;
    	}
    }
    
    if(count>=3){
    	flag=true;
    }
   
   if(flag){
   	  cout<<"Yes"<<endl;
   }else{
   	  cout<<"No"<<endl;
   }

    return 0;
  }

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin>>N;
    vector<int> A(N);
    REP(i,N) cin>>A[i];
    sort(ALL(A));
    cout<<abs(A[0] - A[N-1])<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    string s,t;
    cin>>s>>t;
    bool ans=true;
    rep(i,s.size()){
        if(s.at(i)!=t.at(i)) ans=false;
    }
    if(ans) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vint a(n), b(n);
    rep(i, n) cin >> a[i];

    int k = 0;
    for (int i = 1; i < n; i++)
    {
        k ^= a[i];
    }
    b[0] = k;
    for (int i = 1; i < n; i++)
    {
        k ^= a[i - 1];
        k ^= a[i];
        b[i] = k;
    }
    view(b);

    return 0;
}

Measured memory_bytes: 4756
from collections import deque

def is_not_empty(A):
    for x in A:
        if x: return True
    return False

N = int(input())
A = [deque([int(i) - 1 for i in input().split()]) for _ in range(N)]

ans = 0
yesterday = set(range(N))
while is_not_empty(A):
    today = set()
    for my in yesterday:
        if not A[my]: continue
        if my in today: continue
        enemy = A[my][0]
        if my == A[enemy][0] and enemy not in today:
            today.add(A[my].popleft())
            today.add(A[enemy].popleft())

    if not today:
        ans = -1
        break

    ans += 1
    yesterday = today

print(ans)

Measured memory_bytes: 35948
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double

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

  if (s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


  return 0;
}


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


N = int(input())

A = inpl()

flag = True
for a in A:
    if a % 2 == 1:
        pass
    elif a % 3 == 0 or a % 5 == 0:
        pass
    else:
        flag = False

print("APPROVED" if flag else "DENIED")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k;cin>>n>>k;
    vector<ll>v(n);
    for(int i=0;i<n;++i){
        cin>>v[i];
    }
    if(k==1){
        //print the minimum dist from 0
        ll minm=INT_MAX;
        for(int i=0;i<n;++i){
            minm=min(abs(v[i]),minm);
        }
        return cout<<minm,0;
    }
    vector<int>dis;
    for(int i=0;i<int(v.size());++i){
        dis.emplace_back(v[i+1]-v[i]);
    }
    partial_sum(all(dis),dis.begin());
    ll minm=LLONG_MAX;
    for(int i=0;i+k-1<int(dis.size());++i){
        ll init=0;
        if(i!=0)init=dis[i-1];
        minm=min({minm,dis[i+k-2]-init+abs(v[i]),dis[i+k-2]-init+abs(v[i+k-1])});
       // D(minm);
    }
    cout<<minm;

    
}

Measured memory_bytes: 4680
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;

    vector<pair<int,int>> ab(n);
    for(int i = 0; i < n; i++){
        pair<int,int> tmp;
        cin >> tmp.second >> tmp.first;
        ab[i] = tmp;
    }

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

    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += ab[i].second;
        if(ab[i].first < sum){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  ll ans = 0;
  ll maxi = -1e18;
  REP(i, n) {
    if (maxi <= a[i]) {
      maxi = a[i];
      continue;
    }
    ans += maxi - a[i];
  }
  cout << ans << endl;
}

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

int main() {
    uint N; cin >> N;
    vector<int> d(N, 0);

    int recover = 0;
    for (auto &x: d) cin >> x;
    for (uint i=0; i<N; i++) {
        for (uint j=(i+1); j<N; j++) {
            recover += d[i] * d[j];
        }
    }
    cout << recover << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read


n, *ab = map(int, read().split())
ans = [0]*(n-1)
edges = [[]for _ in range(n)]
used = [0]*n

for i, a, b in zip(range(n-1), *[iter(ab)] * 2):
    edges[a-1].append([b-1, i])

for node in range(n):
    unable = used[node]
    color = 1

    for to, id in edges[node]:
        if color == unable:
            color += 1
        ans[id] = str(color)
        used[to] = color
        color += 1

print(max(used))
print('\n'.join(ans))

Measured memory_bytes: 44120
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する

int cal1(vector<int> v){
    int N = v.size();
    map<int,int> dp;
    dp[v[0]]++;
    int ret = 1;
    rep(i,1,N){
        if(dp.find(v[i] - 1) == dp.end()){
            dp[v[i]]++;
        }else{
            dp[v[i]] = dp[v[i] - 1] + 1;
        }
        ret = max(ret,dp[v[i]]);
    }
    ret = N - ret;
    return ret;
}
//int cal2(vector<int> v){
//    int N = v.size();
//    int cur = N;
//    int ret = 0;
//    for(int i = N-1; i >= 0; i--){
//        if(v[i] == cur){
//            cur--;
//            ret++;
//        }
//    }
//    ret = N - ret;
//    return ret;
//}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> v(N);
    rep(i,0,N) cin >> v[i];

//    int ans = min(cal1(v),cal2(v));
    int ans = cal1(v);
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 11768
k = int(input())
pool = [i for i in range(1,10)]
i = 0
while len(pool) < k:
    n = int(str(pool[i]) + str(pool[i])[-1])
    if n%10 == 0:
        pool += [n, n+1]
    elif n%10 == 9:
        pool += [n-1, n]
    else:
        pool += [n-1, n, n+1]
    i += 1
print(pool[k-1])

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

dic = {}
for val in a:
    if not(val in dic.keys()):
        dic[val] = 1
    else:
        dic[val] += 1

sum = 0
for val in dic.keys():
    sum += dic[val]*(dic[val]-1)//2

for k in range(n):
    print(sum - dic[a[k]]*(dic[a[k]]-1)//2 + (dic[a[k]]-1)*(dic[a[k]]-2)//2)


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

ll N, num;
vector<ll> res, c, deg;
vector<vector<bool>> T;
vector<bool> visited;

void dfs_visit(ll s) {
  res[s] = c[num];
  visited[s] = true;
  num++;
  for (ll u = 0; u < N; u++) {
    if (!T[s][u] || visited[u] == true) {
      continue;
    } else {
      visited[u] = true;
      dfs_visit(u);
    }
  }
  return;
}
void solve() {
  if (N == 1) {
    cout << 0 << "\n";
    cout << c[0] << '\n';
    return;
  }
  ll score = 0, index, tmp = 0;
  sort(c.rbegin(), c.rend());
  for (ll i = 1; i < N; i++) {
    score += c[i];
  }
  for (int i = 0; i < N; i++) {
    if (tmp < deg[i]) {
      tmp = deg[i];
      index = i;
    }
  }
  num = 0;
  dfs_visit(index);
  cout << score << '\n';
  for (ll i = 0; i < N; i++) {
    cout << res[i] << " ";
  }
  cout << "\n";
  return;
}

int main() {
  cin >> N;
  T.resize(N, vector<bool>(N, false));
  visited.resize(N, false);
  c.resize(N);
  deg.resize(N, 0);
  res.resize(N, 0);
  for (ll i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    T[a][b] = true;
    T[b][a] = true;
  }
  for (int i = 0; i < N; i++) {
    cin >> c[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 13440
import math
i = int(input())

#入力の個数が2個なら2数の最大公約数を求め1から最大公約数までの数で約数を求める
if i == 2:
    a,b = map(int,input().split())
    num = math.gcd(a,b)
    for i in range(1,num + 1):
        if a % i == 0 and b % i == 0:
            print(i)

#入力の個数が3個なら2数の最大公約数を調べ最大公約数と3個目の最大公約数を調べ1から最大公約数までの数で約数を求める
else:
    a,b,c = map(int,input().split())
    num = math.gcd(a,b)
    num = math.gcd(num,c)
    for i in range(1,num + 1):
        if a % i == 0 and b % i == 0 and c % i ==0:
            print(i)


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

using namespace std;

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << ((b >= a) ? "unsafe" : "safe");
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <limits>
#include <iomanip>

#define rep(i, n) for(int i = 0, end = (int)(n); i < end; i++)

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------
const static int N = 100005;
vector<int> R[N];

int n;
vector<int> dist;

void dfs(int v, int d=0, int p = -1) {
    dist[v] = d;
    for(int i : R[v]) {
        if (i == p) continue;
        dfs(i, d+1, v);
    }
}

vector<int> calcDist(int index) {
    dist = vector<int>(n);
    dfs(index);
    return dist;
}

int main() {
    int a, b;
    cin >> n >> a >> b;
    --a; --b;
    rep(i, n - 1) {
        int t, s;
        cin >> t >> s;
        --t; --s;
        R[t].push_back(s);
        R[s].push_back(t);
    }

    vector<int> distA = calcDist(a);
    vector<int> distB = calcDist(b);

    int d_max = 0;
    rep(i, n) {
        if (distA[i] < distB[i]) {
            d_max = max(d_max, distB[i]);
        }
    }
    cout << d_max - 1 << endl;
    return 0;
}


Measured memory_bytes: 10744
# -*- coding:utf-8 -*-
import math
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    cumulative = [0]
    ans = 0
    for tmp in range(len(a)):
        cumulative.append(cumulative[-1]+a[tmp])
    else:
        factor = list(set(cumulative))
    dic = { tmp: 0 for tmp in factor }
    for tmp in cumulative:
        dic[tmp] += 1
    for tmp in factor:
        if dic[tmp] > 1:
            ans += math.factorial(dic[tmp])/(math.factorial(dic[tmp]-2)*2)
    else:
        print(int(ans))

Measured memory_bytes: 46040
h, w = gets.chomp.split.map(&:to_i)
sa = []
h.times do
  sa.push(gets.chomp.chars)
end

grid_r = [-1, 0, 1]
grid_c = [-1, 0, 1]
sa.each_with_index do |row, row_index|
  row.each_with_index do |value, col_index|
    next if value == "#"
    num = 0
    grid_r.each do |i|
      next if row_index + i < 0 or row_index + i >= h
      grid_c.each do |j|
        next if col_index + j < 0 or col_index + j >= w
        num += 1 if sa[row_index + i][col_index + j] == "#"
      end
    end
    sa[row_index][col_index] = num.to_s
  end
end

sa.each do |row|
  puts row.join
end


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
using P = std::pair<int, int>;
using namespace std;

struct team_data {
    int team_num = -1;
    int solved_num = 0;
    int sum_time = 0;    // minute
    //vector<int> solved_time;
    vector<int> penalty;
};

int main() {
    int M, T, P, R;
    while(cin >> M >> T >> P >> R, M) {
        vector<team_data> v(T);
        for(int i=0; i<v.size(); ++i) {
            v[i].team_num = i+1;
            v[i].penalty.resize(P);
        }
        for(int i=0; i<R; ++i) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            if(j != 0) {
                v[t-1].penalty[p-1] += 20;
            } else {
                v[t-1].sum_time += m;
                v[t-1].solved_num += 1;
                v[t-1].sum_time += v[t-1].penalty[p-1];
            }
        }
        vector<vector<team_data>> v2(P+1);
        for(auto& x : v) {
            v2[x.solved_num].push_back(x);
        }
        for(auto& x : v2) {
            sort(x.begin(), x.end(), [](team_data const& t1, team_data const& t2) {
                    return t1.team_num > t2.team_num;
                    });
            stable_sort(x.begin(), x.end(), [](team_data const& t1, team_data const& t2) {
                    return t1.sum_time < t2.sum_time;
                    });
        }
        vector<team_data> ret;
        for(int i=v2.size()-1; i>=0; --i) {
            for(auto& x2 : v2[i]) {
                ret.push_back(x2);
            }
        }
        for(int i=0; i<ret.size(); ++i) {
            if(i != 0) {
                if(ret[i-1].solved_num == ret[i].solved_num) {
                    if(ret[i-1].sum_time == ret[i].sum_time) cout << '=';
                    else cout << ',';
                } else {
                    cout << ',';
                }
            }
            cout << ret[i].team_num;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);

    rep(i,n){
        cin >> a.at(i);
        cin >> b.at(i);
        cin >> c.at(i);
    }
    
    vector<vector<ll>> dp(n, vector<ll>(3));

    rep(i,n){
        if(i == 0){
            dp[0][0] = a.at(0);
            dp[0][1] = b.at(0);
            dp[0][2] = c.at(0);
            continue;
        }

        //aを選ぶ
        chmax(dp[i][0], dp[i-1][1] + a.at(i));
        chmax(dp[i][0], dp[i-1][2] + a.at(i));
        //bを選ぶ
        chmax(dp[i][1], dp[i-1][0] + b.at(i));
        chmax(dp[i][1], dp[i-1][2] + b.at(i));
        //cを選ぶ
        chmax(dp[i][2], dp[i-1][0] + c.at(i));
        chmax(dp[i][2], dp[i-1][1] + c.at(i));
    }

    
    ll ans = 0;
    rep(i,3){
        if(ans < dp[n-1][i]){
            ans = dp[n-1][i];
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 8064
total = int(input())
tall = list(map(int, input().split()))
dif = 0
for i in range(total - 1):
    if tall[i] > tall[i+1]:
        var = tall[i] - tall[i+1]
        tall[i+1] += var
        dif += var
    else:
        pass
print(dif)


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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, 3) {
    if(s[i] == '1') cnt++;
  }
  cout << cnt << endl;
}

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

int main()
{
	int k, x;
	cin >> k >> x;
	
	if (500*k >= x)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

bool is_square(int n) {
  int k = max(0, (int)sqrt(n) - 2);
  while (k * k < n) ++k;
  return k * k == n;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, D;
  while (cin >> N >> D) {
    vec<int, 2> X = make_v(N, D, 0);
    for (int i = 0; i < N; i++) {
      for (int k = 0; k < D; k++) cin >> X[i][k];
    }
    int res = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        int sum = 0;
        for (int k = 0; k < D; k++) {
          int d = X[i][k] - X[j][k];
          sum += d * d;
        }
        if (is_square(sum)) ++res;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();

        int total = l * n + n * (n - 1) / 2;
        if (l >= 0) {
            System.out.println(total - l);
        } else {
            if (Math.abs(l) < n) {
                System.out.println(total);
            } else {
                System.out.println(total - (l + n - 1));
            }
        }
    }
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, ans=0;

	cin >> N;
	vector<ll> A(N);
	rep(i,N) cin >> A[i];

	sort(all(A));

	if( N%2 ){
		int mid = N/2;
		rep(i,N){
			if( i > mid + 1 )     ans += 2*A[i];
			else if( i == mid+1 ) ans += A[i];
			else if( i == mid )   ans += max(A[i+1]-A[i], A[i]-A[i-1]);
			else if( i == mid-1 ) ans -= A[i];
			else if( i <  mid-1 ) ans -= 2*A[i];
		}
	}else{
		int mid = N/2;
		rep(i,N){
			if( i > mid )         ans += 2*A[i];
			else if( i == mid )   ans += A[i];
			else if( i == mid-1 ) ans -= A[i];
			else if( i <  mid-1 ) ans -= 2*A[i];
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a+b;
  ans = max(ans, a-b);
  ans = max(ans, a*b);
  cout << ans << endl;
  return 0;
}

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

int main() {

int n,m;
cin >> n;
string s[n];
set<string> list;
for(int i=0;i<n;i++){
cin >>s[i];
list.insert(s[i]);
}
cin >> m;
string t[m];

for(int i=0;i<m;i++){
cin >>t[i];
list.insert(t[i]);
}
int maxi=0;
for(string temp:list){
int count=0;
for(string stemp:s){
if(temp.compare(stemp)==0){count++;
}
}
for(string stemp:t){
if(temp.compare(stemp)==0){count--;

}
}
maxi=max(maxi,count);


}
cout << maxi;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const DIGITS: usize = 40;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let X: usize = sc.get();
    let M: usize = sc.get();
    let mut doubling = vec![vec![0; M]; DIGITS+1];
    let mut sum = vec![vec![0; M]; DIGITS+1];
    for i in 0..M {
        doubling[0][i] = i * i % M;
        sum[0][i] = i * i % M;
    }
    for k in 0..DIGITS {
        for i in 0..M {
            doubling[k+1][i] = doubling[k][doubling[k][i]];
            sum[k+1][i] = sum[k][i] + sum[k][doubling[k][i]];
        }
    }
    let mut ans = 0;
    let mut cur = X;
    for k in 0..DIGITS {
        if (N>>k) & 1 != 0 {
            ans += sum[k][cur];
            cur = doubling[k][cur];
        }
    }
    ans += X;
    ans -= cur;
    println!("{}", ans);
}


Measured memory_bytes: 66136
#include <stdio.h>

int main(){




for( ; ; ){

int h, w, i, j;

scanf("%d%d", &h, &w);


if(h == 0 & w == 0){return 0;}

for(i = 0; i < h; i++){

for(j = 0; j < w; j++)
{printf("#");}

printf("\n");

}
printf("\n");

}

}

Measured memory_bytes: 1712
h, w, k = map(int, input().split())
c = [ list(input()) for _ in range(h)]
ans = 0
for p_h in range(2**h):
    for p_w in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (p_h >> i) & 1==0 and (p_w >> j) & 1==0:
                    if c[i][j] == '#':
                        black += 1
        if black == k:
            ans += 1
print(ans)

Measured memory_bytes: 9052
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}

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


int main(){
  char c; cin >> c;
  if(c=='A') cout << 'T';
  else if(c=='T') cout << 'A';
  else if(c=='G') cout << 'C';
  else cout << 'G' ;
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	ll a, b, c; cin >> a >> b >> c;
	ll k; cin >> k;
	ll m = max({ a, b, c });
	ll w = m << k;
	cout << w - m + a + b + c << endl;
	return 0;
}

Measured memory_bytes: 256
fn solve(aa: Vec<u64>) -> Vec<u64> {
    let n = aa.len();

    let mut bb = Vec::new();
    for (i, a) in aa.iter().enumerate() {
        bb.push(a * 1000000 + i as u64 + 1);
    }

    bb.sort();

    let mut cc = Vec::new();
    for b in bb {
        cc.push(b % 1000000);
    }

    cc
}

#[test]
fn test() {
    assert_eq!(solve(vec![1, 2, 3, 4, 5]), vec![1, 2, 3, 4, 5]);
    assert_eq!(
        solve(vec![8, 2, 7, 3, 4, 5, 6, 1]),
        vec![8, 2, 4, 5, 6, 7, 3, 1]
    );
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let _n = parse_line!(usize);
    let aa = parse_vec!(u64);

    println!(
        "{}",
        solve(aa)
            .iter()
            .map(|i| i.to_string())
            .collect::<Vec<String>>()
            .join(" ")
    );
}


Measured memory_bytes: 12908