akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

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

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


int main(){
	ll x,k,d;
	cin >> x >> k >> d;
	
	if(abs(x)/d >= k){
		cout << min(abs(x-k*d), abs(x+k*d)) << endl;
		return 0;
	}
	if(abs(x)/d == k-1){
		cout << min(abs(x-k*d), abs(x+k*d)) << endl;
		return 0;
	}
	ll tmp=abs(x)/d;
	if((k-tmp)%2==0){
		cout << min(abs(x-tmp*d),abs(x+tmp*d))<< endl;
		return 0;
	}else{
		cout << min(abs(x-(tmp+1)*d), abs(x+(tmp+1)*d))<< endl;
		return 0;
	}
}

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

long long a[200010];
long long dp[200010];
long long presum[200010];
int n;
int main() 
{
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	presum[1] = a[1];
	for (int i = 3; i <= n; i += 2)
		presum[i] = presum[i - 2] + a[i];
	for (int i = 2; i <= n; i++)
	{
		if (i & 1)
			dp[i] = max(dp[i - 2] + a[i], dp[i - 1]);
		else
			dp[i] = max(dp[i - 2] + a[i], presum[i - 1]);

	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 8452
//import java.io.File;
import java.util.Scanner;

public class Main{
  public static void main(String[] args) throws Exception {
    //Scanner scan = new Scanner(new File("in.txt"));
    Scanner scan = new Scanner(System.in);

    char[][] list = new char[][] {
      {'.',',','!','?',' '},
      {'a','b','c'},
      {'d','e','f'},
      {'g','h','i'},
      {'j','k','l'},
      {'m','n','o'},
      {'p','q','r','s'},
      {'t','u','v'},
      {'w','x','y','z'}
    };

    int input1 = scan.nextInt();

    for(int cases = 0; cases < input1; cases++) {
      char[] numbers = scan.next().toCharArray();
      StringBuilder sb = new StringBuilder();
      for(int ite = 0; ite < numbers.length; ite++) {
        int count = -1;
        int num = numbers[ite]-'1';

        while(numbers[ite] != '0' && ite < numbers.length-1) {
          ite++;
          count++;
        }

        if(count != -1) sb.append(list[num][count%list[num].length]);
      }
      System.out.println(sb.toString());
    }
  }
}

Measured memory_bytes: 29372
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,S=1<<16,inf=2e9;
int v[N],cnt[16],dp[S];
inline int dfs(ri s){
	if(dp[s]!=-1) return dp[s];
	if(__builtin_popcount(s)==1) return inf;
	ri i,j,p,t,res=inf;
	for(i=1;i<16;++i)
		if(s&1<<i)
			for(j=i+1;j<16;++j)
				if(s&1<<j){
					p=i^j;
					t=s^1<<i^1<<j^1<<p;
				//	printf("next %d %d\n",__builtin_popcount(s),__builtin_popcount(t));
					if(t&1<<p)
						res=min(res,dfs(t)+1);
					else
						res=min(res,dfs(t)+2);
				}
//	printf("dp %d %d\n",s,res);
	return dp[s]=res;
}
int main(){
	ri n,i,x,y,c,ans;
	gi(n);
	for(i=1;i^n;++i) gi(x),gi(y),gi(c),v[x]^=c,v[y]^=c; 
	for(i=0;i<n;++i) ++cnt[v[i]];
	c=0;ans=0;
	for(i=1;i<16;++i)
		ans+=cnt[i]>>1,
		c|=(cnt[i]&1)<<i;
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
//	printf("c = %d\n",c);
	printf("%d\n",ans+dfs(c));
	return 0;
}

Measured memory_bytes: 2944
n = int(input())
b = list(map(int,input().split()))
c = 0
t = []
for i in range(n):
        if i + 1 < b[i]:
                print(-1)
                c = 1
                break

if c == 0:
        while b != []:
                s = []
                for  i in range(len(b)):
                        if i + 1 == b[i]:
                                s.append(b[i])
                t.insert(0,max(s))
                b.pop(max(s)-1)
        for i in range(len(t)):
                print(t[i])

Measured memory_bytes: 3064
#include <stdio.h>
 
int main(){
    int sum = 0;
    char ch;
 
    while(true)
    {
        while((ch = getchar()) != '\n'){
            sum += ch - '0';
        }
        if(sum == 0)
            break;
        else{
            printf("%d\n",sum);
            sum = 0;
        }
    }
}


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

vector <int> weight(101),value(101);

const long long inf=1e11+5;

int main() {
	int n, w ,sum=0;
	cin>>n>>w;
	for(int i=0;i<n;i++) {
		cin>>weight[i]>>value[i];
		sum+=value[i];
	}
	vector<long long > dp(sum+1, inf);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for (int current=sum-value[i];current>=0; --current){
			dp[current+ value[i]]= min(dp[current+value[i]],dp[current]+weight[i]);
		}
	}


	for(int i=sum;i>=0;--i){
		if(dp[i]<=w) {
			cout<<i;
			break;
		}
	}

	
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
vector<string> yesno={"No", "Yes"};
//----------------------------------------------------------------
#define bis(i, j)        i & (1<<j)

int main(void) {
  int n;
  cin >> n;
  vec col(8);
  int kami=0;
  rep(i,n){
    int tmp;
    cin >> tmp;
    if(tmp>3199){
      kami++;
    } else {
      col[tmp/400]++;
    }
  }
  int ans=0;
  rep(i,8){
    if(col[i]>0) ans++;
  }

  prt2((ans ? ans : 1), ans+kami);
}


Measured memory_bytes: 256
n = int(input())

array = [0] * 100

for i in range(1,n+1):
    array[int(str(i)[0])*10+int(str(i)[-1])] += 1


ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += array[i*10+j] * array[j*10+i]

print(ans)

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


int main()
{
    string n;
    cin >> n;
    
    for (int i = 0; i < 3; i++) {
        if (n[i] == '1') {
            n.replace(i, 1, "9");
        }else{
            n.replace(i, 1, "1");
        }
    }
    cout << n << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*input
15
123 119
129 120
132 112
126 109
118 103
115 109
102 100
130 120
105 105
132 115
104 102
107 107
127 116
121 104
121 115
8
8 234
9 244
10 226
11 227
12 240
13 237
14 206
15 227
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=3e5+5;
const ll maxlg=__lg(maxn)+2;
pii arr[maxn];
int dp[513][100005];
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,q;
    cin>>n;
    REP1(i,n) cin>>arr[i].f>>arr[i].s;
    REP1(i,min((1<<9)-1,n)){
        REP(j,100005){
            dp[i][j]=dp[i/2][j];
            if(j>=arr[i].s) MXTO(dp[i][j],dp[i/2][j-arr[i].s]+arr[i].f);
        }
    }
    cin>>q;
    while(q--){
        int x,w;
        cin>>x>>w;
        vector<pii> v;
        int rt;
        while(x){
            if(x<(1<<9)){
                rt=x;
                break;
            }
            v.pb(arr[x]);
            x/=2;
        }
        ll ans=0;
        REP(i,(1<<(sz(v)))){
            int s1=0,s2=0;
            REP(j,sz(v)){
                if(i&(1<<j)){
                    s1+=v[j].f;
                    s2+=v[j].s;
                }
            }  
            if(s2<=w){
                MXTO(ans,dp[rt][w-s2]+s1);
            }
        }
        cout<<ans<<'\n';
        
    }
}


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

int N;
vector<pair<pair<int, int>, int> > v;

int main(){
    cin >> N;

    int x, y, h;
    int xt, yt, ht;
    for(int i = 0; i < N; i++){
        cin >> x;
        cin >> y;
        cin >> h;
        v.push_back(make_pair(make_pair(x, y), h));
        if(h!=0){
            xt = x;
            yt = y;
            ht = h;
        }
    }

    int H;
    bool flag = true;
    for(int i = 0; i <= 100 && flag; i++){
        for(int j = 0; j <= 100 && flag; j++){
            H = abs(i - xt) + abs(j - yt) + ht;
            for(int k = 0; k < N && flag; k++){
                h = max(H - abs(i - v[k].first.first) - 
                    abs(j - v[k].first.second), 0); 
                if(h == v[k].second){
                    if((k == N - 1) && (H > 0)){
                        flag = false;
                        x = i;
                        y = j;
                    }
                }else{
                    break;
                }
            }
        }
    }

    cout << x << " " << y << " " << H << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
  int n,a[111111],c[111111]={},ans=0;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  for(int i=0;i<n;i++){
    c[a[i]]++;
    c[a[i]+1]++;
    c[a[i]+2]++;
  }
  for(int i=0;i<=a[n-1];i++)
    ans=max(ans,c[i]);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1024
#define min(a,b) ((a)<(b)?(a):(b))
int x[10000][2];

int compare(const void* p1, const void *p2){return ((int*)p2)[1]-((int*)p1)[1];}

int guard(int n,int m){
  int i,s=0;
  memset(x,0,sizeof(x));
  for(i=0;i<n;i++)scanf("%d%d",x[i],x[i]+1);
  qsort(x,n,sizeof(x[0]),compare);
  for(i=0;i<n;i++){
    int t=min(m,x[i][0]);
    m-=t;x[i][0]-=t;
    if(!m)break;
  }
  for(;i<n;i++)s+=x[i][0]*x[i][1];
  return s;
}

int main(){
  int n,m;
  while(1){
    scanf("%d%d",&n,&m);
    if(!n&&!m)return 0;
    printf("%d\n",guard(n,m));
  }
}

Measured memory_bytes: 804
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    int N;
    cin >> N;
    vector<int> d(N);
    REP(i, N) cin >> d[i];
    int sum = 0;
    REP(i, N) REP(j, N) if (i < j) sum += d[i] * d[j];

    cout << sum << endl;


}

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

const int MOD = (int)1e9 + 7;

int modPow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>=1;
    }
    return res;
}

int modInv(int a, int mod){
    return modPow(a, mod - 2, mod) % mod;
}

int nCr(int n, int r){
    if(r == 0) return 1;

    int res = 1;
    for(int i = 1; i <= r; i++){
        res = res * (n - i + 1) % MOD * modInv(i, MOD) % MOD;
    }
    return res;
}


signed main() {
    int n,a,b;
    cin >> n >> a >> b;

    int ans = modPow(2,n,MOD) - nCr(n,a) - nCr(n,b) - 1;
    cout << (ans % MOD + MOD) % MOD << endl;
}


Measured memory_bytes: 256
#!/env/usr/python3
N, X = map(int, input().split())
n = 1
n_list = [n]
p = 1
p_list = [p]

for i in range(N):
	n = 2*n + 3
	n_list.append(n)

def p_func(L, X):
	p = 0
	if L == 0 and X == 1:
		p = 1
	elif L >= 1 and X == 1:
		p = 0
	elif X <= n_list[L-1]+1:
		p = p_func(L-1, X-1)
	elif X == n_list[L-1]+2:
		p = p_func(L-1, n_list[L-1]) + 1
	elif X <= 2 * n_list[L-1] + 2:
		p = p_func(L-1, X-n_list[L-1]-2) + p_func(L, n_list[L]-n_list[L-1]-2) + 1
	elif X == 2 * n_list[L-1] + 3:
		p = 2 * p_func(L-1, n_list[L-1]) + 1
	return p

print(p_func(N, X))


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

int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		for (int j = 2; j <= sqrt(a); j++){
			if (a % j == 0){
				cnt++;
				break;
			}
		}
				
	}

	cout << n-cnt << endl;
}



Measured memory_bytes: 3132
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */

    for (i = 0; i <= VMAX; i++) C[i]=0;
    for(i = 0; i < n; i++){
        scanf("%hu", &A[i+1]);
        C[A[i + 1]]++;
    }
    for(i = 1; i <= VMAX; i++){
        C[i] = C[i] + C[i-1];
    }
    for(j = n; j > 0; j--){
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
    for(i = 1; i <= n; i++){
        if(i > 1) printf(" ");
        printf("%d",B[i]);
    }
    printf("\n");
     
  return 0;
}



Measured memory_bytes: 9560
#!/usr/bin/env python3
n, m = map(int, input().split())
s = input()
ans = []
cur = n
while cur:
    for d in range(1, min(cur + 1, m + 1))[::-1]:
        if s[cur - d] == '0':
            ans.append(d)
            cur -= d
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep=' ')


Measured memory_bytes: 6372
/*
            AtCoder010-AGC-D

    Let's consider some cases:

    1) If the array has odd number of even integers, the player whose turn is now
can win by performing the operation on one of the even integers(thus, GCD won't change the parities)

    2) If 1) doesn't happen and there are at least two odd numbers, the player whose turn will come next will win,
since no matter what the player whose turn is now will do, the other player can undo it.

    3) If 1) and 2) don't happen and we have at least an one, the player whose turn will come next will win, because the sum of
the possible drops is even and the player currently at turn won't have any remaining move.

    If none of the cases above happen, we have only 1 odd integer and (n-1) even integers, so we need to perform the operation
on the odd integer, and we will solve the game recursively for the next player.

    Since the GCD will be at least 2, the complexity will therefore be O(n log valmax).

*/
#include<bits/stdc++.h>
using namespace std;
int n, v[100002];
int winn(int turn)
{
    int odd = 0, even = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(v[i] % 2 == 0)
            ++even;
        else
            if(v[i] == 1)
                ++odd;
    }
    if(even % 2 == 1)
        return turn;
    if(even < n - 1)
        return 3 - turn;
    if(odd)
        return 3 - turn;
    for(int i = 1; i <= n; ++i)
        if(v[i] % 2 == 1)
            --v[i];
    int cmm = v[1];
    for(int i = 1; i <= n; ++i)
        cmm = __gcd(cmm, v[i]);
    for(int i = 1; i <= n; ++i)
        v[i] /= cmm;
    return winn(3 - turn);
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    int tu = winn(1);
    if(tu == 1)
        cout << "First";
    else
        cout << "Second";
    return 0;
}


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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define FORR(i,a,b) for (int i = a; i <= b; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

int t;
ll a, b, c, d;

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

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> t;
	while (t--) {
		cin >> a >> b >> c >> d;

		if (a < b || d < b) {
			cout << "No" << endl;
			continue;
		}

		ll g = gcd(b, d);
		a = (c / g) * g + a % g;
		while (a <= c) a += g;

		if (a < b) cout << "No" << endl;
		else cout << "Yes" << endl;
	}

	return 0;
}

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

using namespace std;

int n;
vector<long long int> v;

#define MOD 998244353
#define MAX 200002
#define MAXX 1000001
long long int cn[MAXX];
long long int pw[MAXX];
long long int com[MAXX];

long long int ppow(long long int i,long long int j){
	long long int res=1;
	while(j){
		if(j&1LL){
			res*=i;
			if(res>=MOD)res%=MOD;
		}
		j>>=1LL;
		i*=i;
		i%=MOD;
	}
	return res;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		v.push_back(a);
	}
	for(int i=0;i<v.size();i++){
		cn[v[i]]+=v[i];
		pw[v[i]]+=v[i]*v[i];
		pw[v[i]]%=MOD;
		cn[v[i]]%=MOD;
	}
	for(int i=1;i<MAXX;i++){
		for(int j=i*2;j<MAXX;j+=i){
			cn[i]+=cn[j];
			pw[i]+=pw[j];
			cn[i]%=MOD;
			pw[i]%=MOD;
		}
	}
	long long int ans=0;
	for(int i=MAXX-1;i>=1;i--){
		com[i]=((cn[i]*cn[i])%MOD)-pw[i];
		com[i]+=MOD;
		com[i]%=MOD;
		for(int j=i*2;j<MAXX;j+=i){
			com[i]+=MOD-com[j];
			com[i]%=MOD;
		}
		com[i]%=MOD;
		com[i]+=MOD;
		com[i]%=MOD;
		ans+=com[i]*ppow(i,MOD-2);
		ans%=MOD;
	}
	ans*=ppow(2,MOD-2);
	ans%=MOD;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 25328
def main():
    S = input()
    flag = True
    for idx in range(len(S)//2):
        if S[idx] != S[-idx-1]:
            flag = False
    N = len(S)
    for idx in range((N+1)//4):
        if S[idx] != S[(N-1)//2 - 1 - idx]:
            flag = False
        if S[idx + (N - 1)// 2 + 1] != S[N - 1 - idx]:
            flag = False

    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;
	int table[101][101] = {0};
	for(int i=0 ; i < n*(n-1)/2 ; i++ ){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--, b--;
		int s1, s2;
		if( c > d ){ 
			s1 = 3;
			s2 = 0;
		}else if( c == d ){
			s1 = s2 = 1;
		}else{
			s1 = 0;
			s2 = 3;
		}
		table[a][b] = s1;
		table[b][a] = s2;
	}
	vector<P> v;
	int score[101] = {0};
	for(int i=0 ; i < n ; i++ ){
		for(int j=0 ; j < n ; j++ ){
			if( i == j ) continue;
			score[i] += table[i][j];
		}
		v.push_back( P(-score[i],i) );
	}
	sort( v.begin() , v.end() );
	int rank[101] = {0};
	rank[ v[0].second ] = 1;
	for(int i=1 ; i < v.size() ; i++ ){
		rank[ v[i].second ] = ( v[i].first == v[i-1].first )? rank[ v[i-1].second ] : i+1;
	}
	for(int i=0 ; i < n ; i++ ){
		cout << rank[i] << endl;
	}
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 0;
        int next = 10;
        for(int i = 1; i <= N; i++){
            count++;
            if(i == next - 1){
                i = next * 10 - 1;
                next *= 100;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

	string S;
	cin >>S;
	
	string an = "Yes";
	for (int i = 0; i < S.size(); i++) {
		if (i % 2 == 0 && S.at(i) == 'L') {
			an = "No";
		}
		if (i % 2 == 1 && S.at(i) == 'R') {
			an = "No";
		}

	}
	
	
	
	cout << an<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  long long l,r,i,j,ans = 2020;vector<long long> d;cin >> l >> r;
  for(i=l;i<=min(l+2018,r);i++) d.push_back(i%2019);
  for(i=0;i<d.size()-1;i++){
    for(j=i+1;j<d.size();j++) ans = min(ans,(d[i]*d[j])%2019);
  }
  cout << ans << endl;
}

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

int main() {
	int n;
  	cin>>n;
  	set<string> s;
  	while(n--){
  	    string t;cin>>t;
  	    s.insert(t);
  	}
  	cout<<s.size();
	return 0;
}

Measured memory_bytes: 19224
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
	class Program
	{

		static void Main(string[] args)
		{
			var K = int.Parse(Console.ReadLine());
			var S = Console.ReadLine();

			if(K >= S.Length)
			{
				Console.WriteLine(S);
			}
			else
			{
				var answer = S.Substring(0, K);
				answer += "...";
				Console.WriteLine(answer);
			}
		}
	}
}

Measured memory_bytes: 27532
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int main() {
    while (1) {
        int n = 0;
        int s[1000] = {0};
        int total = 0;
        double ave = 0;
        double a = 0;
        
        cin >> n;
        if (n == 0) {
            return 0;
        }
        for (int i = 0; i < n; i++) {
            cin >> s[i];
            total += s[i];
        }
        
        ave = (double)total / n;
        for (int i = 0; i < n; i++) {
            a += (s[i] - ave) * (s[i] - ave);
        }
        a /= n;
        a = sqrt(a);
        
        printf("%.8f\n", a);
    }
}




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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int INF = 1000*1000*1000;
const int N = 100;
const int W = 10000;
int n, m;
int dp[N+1][W+1];
int v[N+1], w[N+1];

int main() {
  int i, j;
  memset(dp, 0, sizeof(dp));
  scanf("%d%d ", &n, &m);
  for (i=1; i<=n; i++) scanf("%d%d ", v+i, w+i);
  for (i=1; i<=n; i++)
    for (j=0; j<=m; j++)
      if (j-w[i]<0)
        dp[i][j] = dp[i-1][j];
      else
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);

  printf("%d\n", dp[n][m]);

  return 0;
}

Measured memory_bytes: 5144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		//入力表示
		String S =scanner.next();
		String T =scanner.next();
		
		//個数表示
		int A = scanner.nextInt();
		int B = scanner.nextInt() ; 
		
		//減らしたい文字の入力表示
		String U =scanner.next();
		
		//Uの選んだ数字が１つ減る
		 if(S.equals(U)) {
			 A--; 
		 }
		 else {
			 B--; 
		 }
		 System.out.println(A+" " +B);
		 
		scanner.close();
	}
}

Measured memory_bytes: 23764
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, V):
    V.sort(reverse=True)
    from fractions import Fraction
    while len(V) > 1:
        a = V.pop()
        b = V.pop()
        V.append(Fraction(a+b, 2))
    return float(V[0])





def main():
    N = read_int()
    V = read_int_n()
    print(slv(N, V))


if __name__ == '__main__':
    main()


Measured memory_bytes: 66796
#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int r=w, l=0, u=h, d=0;
  int x[n], y[n], a[n];
  for(int i=0; i<n; i++){
    cin >> x[i] >> y[i] >> a[i];
    if(a[i]==1 && x[i]>l)
      l=x[i];
    else if(a[i]==2 && x[i]<r)
      r=x[i];
    else if(a[i]==3 && y[i]>d)
      d=y[i];
    else if(a[i]==4 && y[i]<u)
      u=y[i];
    }
  if(u-d>0&&r-l>0)
    cout << (u-d)*(r-l);
  else
    cout << 0;
  return 0;
}

Measured memory_bytes: 3572
#include<stdio.h>
int main(){
    int x,y;
    scanf("%d%d",&x,&y);
    int i,j;
    for(i=0;i<=x;i++){
        j=x-i;
        if(2*i+4*j == y){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1636
n = int(input())
s = str(input())
slist = []
for i in range(n):
  slist.append(s[i])
slime = slist[0]
fslist = []
fslist.append(slime)
for i in range(1, n):
  if slime != slist[i]:
    fslist.append(slist[i])
    slime = slist[i]
print(len(fslist))

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;



int main() {
	string s;
	int n, k, i;
	char t;

	cin >> n;
	cin >> s;
	cin >> k;

	t = s[k - 1];

	rep(i, n) {
		if (s[i] != t)s[i] = '*';
	}

	cout << s;

	return 0;
}


Measured memory_bytes: 256
/*
 © 2020-01-31 19:54:48 crystaalroo all Rights Reserved
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for(int i = (a); i <(b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define sz(x) (int) (x).size()
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long lli;
typedef pair<int,int > ii;
#define ENDL '\n'
#define deb(x) cout << #x": " << (x) << endl;
const int INF=1e9;
const lli mod = 1e9+7;
const int N = 1E6;


int main(){
  int n;
  cin>>n;
  lli costo[3][n],dp[3][n];
  fore(i,0,n)fore(j,0,3){cin>>costo[j][i];dp[j][i]=0;}

  fore(i,0,3)dp[i][0]=costo[i][0];

  fore(i,1,n)fore(j,0,3)fore(k,0,3)if(k!=j)dp[j][i]=max(dp[k][i-1]+costo[j][i],dp[j][i]);
  lli mx = max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
  cout<<mx<<ENDL;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int A;
  int B;
  
  cin >> A;
  cin >> B;
  if((B-1)%(A-1) == 0){
    cout << (B-1)/(A-1) << endl;
  }
  else{
    cout << (B-1)/(A-1)+1 << endl;
  }  
}


Measured memory_bytes: 256
S = input()
q = int(input())
L = []
for _ in range(q):
    Op = input().split()
    l, r = int(Op[1]), int(Op[2])
    if Op[0] == 'replace':
        S = S[:l] + Op[3] + S[r+1:]
    elif Op[0] == 'reverse':
        S = S[:l] + S[l:r+1][::-1] + S[r+1:]
    elif Op[0] == 'print':
        print(S[l:r+1])


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

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
typedef long long LL;

const int maxn = 100010;

char s1[maxn], s2[maxn];
int n, m, f[maxn][26];

int main()
{
    scanf("%s", s1 + 1); n = str(s1 + 1);
    scanf("%s", s2 + 1); m = str(s2 + 1);
    REP(i, 0, 25) f[n + 1][i] = -1;
    for ( int i = n; i >= 0; -- i )
    {
        REP(j, 0, 25)
        {
            if ( s1[i] - 'a' == j ) f[i][j] = i;
            else f[i][j] = f[i + 1][j];
        }
    }
    long long ans = 0, now = 1;
    REP(i, 1, m)
    {
        if ( f[now][s2[i] - 'a'] != -1 ) { ans += f[now][s2[i] - 'a'] - now + 1; now = f[now][s2[i] - 'a'] + 1; }
        else if ( f[1][s2[i] - 'a'] != -1 ) { ans += n - now + f[1][s2[i] - 'a'] + 1; now = f[1][s2[i] - 'a'] + 1 ; }
        else { puts("-1"); return 0; }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 10624
X,N = list(map(int,input().split()))
P = list(map(int,input().split()))

out1 = 1000
out2 = 1000
for i in range(-200,200):
    if i not in P:
        if abs(X-i)<out1:
            out1=abs(X-i)
            out2=i
print(out2)


Measured memory_bytes: 61684
function Main(input) {
  var list = input.split("\n");
  var X = parseInt(list[0].split(" ")[0],10);
  var Y = parseInt(list[0].split(" ")[1],10);
  var Z = parseInt(list[0].split(" ")[2],10);
  var K = parseInt(list[0].split(" ")[3],10);
  var A = list[1].split(" ").map(s => parseInt(s, 10));
  var B = list[2].split(" ").map(s => parseInt(s, 10));
  var C = list[3].split(" ").map(s => parseInt(s, 10));
  
  var maxlist = Array(0);
  var listlen;
  var max;
  var maxnum;
  var tmp;
  
  A.sort(comp);
  B.sort(comp);
  C.sort(comp);

  maxlist.push([A[X-1]+B[Y-1]+C[Z-1], X-1, Y-1, Z-1]);
  
  for (i = 0; i < K; i++) {
    max = 0;
    listlen = maxlist.length;
    for (j=0; j<listlen; j++) {
      if (maxlist[j][0] > max) {
        max = maxlist[j][0];
        maxnum = j;
      }
    }
    
    console.log(max);
      
    nextlist(maxlist,maxnum,A,B,C);
      
    maxlist.splice(maxnum, 1);
  }
}
 
function nextlist(list, j, A, B, C) {
  var x, y, z;
  x = list[j][1];
  y = list[j][2];
  z = list[j][3];
  
  if (x>0) listadd(list,[A[x-1]+B[y]+C[z],x-1,y,z]);
  if (y>0) listadd(list,[A[x]+B[y-1]+C[z],x,y-1,z]);
  if (z>0) listadd(list,[A[x]+B[y]+C[z-1],x,y,z-1]);
}

function listadd(list, add) {
  var N = list.length;
  for (var i = 0; i < N; i++) {
    if (list[i][0] == add[0]) {
      if (list[i][1] == add[1]) {
        if (list[i][2] == add[2]) {
          if (list[i][3] == add[3]) return;
        }
      }
    }
  }
  list.push(add);
}

function comp(a, b) {
  if (a>b) return 1;
  if (b>a) return -1;
  return 0;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 24284
e_1,e_2,e_3,e_4=map(int,input().split())

if e_1!=e_2!=e_3!=e_4:
    print('no')
elif e_1==e_2==e_3==e_4:
    print('yes')
elif (e_1==e_2 and e_3==e_4) or (e_1==e_3 and e_2==e_4) or (e_1==e_4 and e_2==e_3):
    print('yes')
else:
    print('no')


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

int main(void){
	int n;
	int card[5][20];
	cin >> n;

	for(int i=0; i<4; i++){
		for(int j=0; j<13; j++){
			card[i][j] = 0;
		}
	}

	for(int i=0; i<n; i++){
		char art;
		int num;
		cin >> art >> num;

		if(art == 'S'){
			card[0][num-1] = 1;
		}else if(art == 'H'){
			card[1][num-1] = 1;
		}else if(art == 'C'){
			card[2][num-1] = 1;
		}else if(art == 'D'){
			card[3][num-1] = 1;
		}
	}

	for(int i=0; i<4; i++){
		for(int j=0; j<13; j++){
			if(card[i][j] == 0){
				if(i==0){
					printf("S %d\n", j+1);
				}else if(i==1){
					printf("H %d\n", j+1);
				}else if(i==2){
					printf("C %d\n", j+1);
				}else if(i==3){
					printf("D %d\n", j+1);
				}
			}

		}
	}


	return 0;
}

Measured memory_bytes: 1144
gosen = 5 * 10**15

S = gets.chomp
K = gets.to_i
vec = S.chars.map do |c|
  c.to_i
end

now = 0
ans = 1

(0...K).each do |v|
  unless S[v].to_i == 1
    ans = S[v].to_i
    break
  end
end
p ans.to_i

Measured memory_bytes: 1788
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	pl := make([]int, n)
	ql := make([]int, n)

	for i := 0; i < n; i++ {
		pl[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		ql[i] = nextInt()
	}
	// p,qの数値化
	p, q := 0, 0
	for j := 0; j < n; j++ {
		p += pl[j] * pow(10, n-j-1)
	}
	for j := 0; j < n; j++ {
		q += ql[j] * pow(10, n-j-1)
	}

	// 順列作成
	var tl []int = []int{1, 2, 3, 4, 5, 6, 7, 8}
	pall := permutations(tl[:n])

	// 数値リスト化
	pallnum := make([]int, len(pall))
	for i := 0; i < len(pall); i++ {
		tmp := 0
		for j := 0; j < n; j++ {
			tmp += pall[i][j] * pow(10, n-j-1)
		}
		pallnum[i] = tmp
	}

	// 順列並びかえ
	sort.Ints(pallnum)

	pidx := -1
	qidx := -1
	for i := 0; i < len(pall); i++ {
		// pidxとqidxが求まっているならば終わり
		if pidx != -1 && qidx != -1 {
			break
		}

		// p比較
		if p == pallnum[i] {
			pidx = i
		}

		// q比較
		if q == pallnum[i] {
			qidx = i
		}
	}

	fmt.Println(abs(pidx - qidx))

}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(a<b && b<c){
        puts("Yes");
        return 0;
    }

    if(a < b){
        if(c * pow(2, k) > b) puts("Yes");
        else puts("No");
        return 0;
    }

    int cnt = 0;
    while(b <= a){
        b *= 2;
        ++cnt;
    }

    if(cnt >= k){
        if(k==cnt){
            if(b < c) puts("Yes");
            else puts("No");
            return 0;
        }
        puts("No");
        return 0;
    }

    if(c * pow(2, k-cnt) > b) puts("Yes");
    else puts("No");



    return 0;
}

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

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int sum = 0; 
    while(K > 0){
        if(A > 0){
            sum++;
            A--;
            K--;
        }else if(B > 0){
            B--;
            K--;
        }else if(C > 0){
            C--;
            sum--;
            K--;
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n; cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  bool f = true;
  rep(i,n) {
    f = f && (v[0]==v[i]);
  }
  if(f) {
    cout << n/2 << endl;
    return 0;
  }
  map<int,int> mp1;
  map<int,int> mp2;
  rep(i,n) {
    if(i%2==0) {
      if(mp1.find(v[i])!=mp1.end()) {
        mp1[v[i]]++;
      } else {
        mp1[v[i]] = 1;
      }
    } else {
      if(mp2.find(v[i])!=mp2.end()) {
        mp2[v[i]]++;
      } else {
        mp2[v[i]] = 1;
      }
    }
  }
  vector<pair<int,int>> v1;
  vector<pair<int,int>> v2;
  for(auto &i : mp1) {
    v1.push_back(make_pair(i.second, i.first));
  }
  for(auto &i : mp2) {
    v2.push_back(make_pair(i.second, i.first));
  }
  sort(v1.begin(), v1.end());
  reverse(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  reverse(v2.begin(), v2.end());
  int ans = 0;
  for(auto &a : v1) {
    for(auto &b : v2) {
      if(a.second != b.second) {
        ans=max(ans, a.first+b.first);
        break;
      }
    }
  }
  cout << n-ans << endl;
  return 0;
}


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define DEBUG(debug_x) cerr <<#debug_x<<": "<<debug_x<<endl;
#define DEBUG2(debug_x, debug_y) cerr <<#debug_x<<":"<<debug_x<<" "<<#debug_y<<":"<<debug_y<<endl;
#define DEBUG3(debug_x, debug_y, debug_z) cerr <<#debug_x<<":"<<debug_x<<" "<<#debug_y<<":"<<debug_y<<" "<<#debug_z<<":"<<debug_z<<endl;
#define DEBUGVC(debug_x) cerr <<#debug_x<<": "; for(auto a:debug_x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(debug_x) cerr <<#debug_x<<":"<<endl; for(auto a:debug_x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (200005)
#define INF (1LL << 60)
const int MOD = (int)1e9;
typedef pair<int,int> Pii;
typedef pair<double,double> Pdd;
 
signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> k(M);
    vector<vector<int>> s(M);
    for(int i=0; i<M; i++){
        cin >> k[i];
        for(int j=0; j<k[i]; j++) {
            int t; cin >> t;
            t--;
            s[i].push_back(t);
        }
    }
    vector<int> p(M);
    for(int i=0; i<M; i++) cin >> p[i];

    int cnt=0;
    for(int bit=0; bit<(1<<N); bit++){
        bool f=true;
        for(int i=0; i<M; i++){
            int sum=0;
            for(int j=0; j<s[i].size(); j++){
                if(bit & (1<<s[i][j])) sum++;
            }
            if(sum%2!=p[i]){
                f=false;
                break;
            }
        }
        if(f) cnt++;
    }

    cout << cnt << endl;

}

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

#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

const ll oo=1e18;
const int MOD=1000000007;
const int INF=1000000000;
const ld EPS=0.000000001;

string s1,s2,ans="";
int dp[3005][3005];

signed main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>s1>>s2;
    for(int i=1;i<=s1.length();++i) {
        for(int j=1;j<=s2.length();++j) {
            if(s1[i-1]==s2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=s1.length(),j=s2.length();
    while(i>0&&j>0) {
        if(s1[i-1]==s2[j-1]) {
            ans=s1[i-1]+ans;
            --i;--j;
        }
        else {
            if(dp[i][j-1]>dp[i-1][j]) --j;
            else --i;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 35456
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
long long N,ans;
int main(){
    cin>>N;
    int A[N][N],B[N][N];
    rep(i,N*N){cin>>A[i/N][i%N];B[i/N][i%N]=A[i/N][i%N];}
    rep(k,N)rep(i,N)rep(j,N)B[i][j]=min(B[i][j],B[i][k]+B[k][j]);
    rep(i,N*N)if(A[i/N][i%N]!=B[i/N][i%N]){cout<<-1<<endl;return 0;}
    rep(k,N)rep(i,N)rep(j,N){
                if(i==k||k==j||i==j)continue;
                if(A[i][k]+A[k][j]==A[i][j])A[i][j]=1000000001;
    }
    rep(i,N*N)if(A[i/N][i%N]!=1000000001)ans+=A[i/N][i%N];
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 4336
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;

//#define FILE_INPUT
//#define DEBUG_MODE

int n;
int ww;
long long int memo[101][100001];
int w[100];
long long int v[100];

long long int Search(int num, int weight)
{
	if (memo[num][weight] >= 0) {
		//cout << "Load : " << num << " : " << weight << " : " << memo[num][weight] << endl;
		return memo[num][weight];
	}
	if (num == n - 1) {
		long long int max = 0;
		if (weight + w[num] <= ww) {
			max = v[num];
		}
		memo[num][weight] = max;
		//cout << num << " : " << weight << " : " << max << endl;
		return max;
	}
	long long int max = Search(num + 1, weight);
	if (weight + w[num] <= ww) {
		long long int value2 = v[num] + Search(num + 1, weight + w[num]);
		if (value2 > max) {
			max = value2;
		}
	}
	memo[num][weight] = max;
	//cout << num << " : " << weight << " : " << max << endl;
	return max;
}

int main()
{
#ifdef FILE_INPUT
	ifstream in("test3.txt");
	cin.rdbuf(in.rdbuf());
#endif	/* FILE_INPUT */  
	cin >> n >> ww;
	for (int i = 0; i < n; ++i) {
		cin >> w[i] >> v[i];
		for (int j = 0; j < 100000; ++j) {
			memo[i][j] = -1;
		}
	}

	long long int max_value = Search(0, 0);
	cout << max_value << endl;

	return 0;
}

Measured memory_bytes: 78336
N = int(input())
S = input()

if (N%2 != 0):
    print('No')
else:
    n = N//2
    for i in range(n):
        if (S[i] != S[n+i]):
            print('No')
            i = -1
            break
    if (i != -1):
        print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int x, n;
	cin >> x >> n;
	if( n==0)
	{
		cout << x << endl;
		return 0;
	}
	vector<int>v;
	int num;
	for (int i = 0; i < n; i++)
	{
		cin >> num;
		v.push_back(num);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i <= n+1; i++)
	{
		if (!binary_search(v.begin(), v.end(), x - i)) {
			cout << x - i << endl;
			break;
		}
		else if (!binary_search(v.begin(), v.end(), x + i)) {
			cout << x + i << endl;
			break;
		}
	}



	
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 

using ll = long long;

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

constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

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;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll mod){ll r=1;while(e>0){if(e&1)r=(r%mod)*(b%mod)%mod;b=(b%mod)*(b%mod)%mod;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i < v.size()-1)s<<", ";}s<<']';return s;}

int main(){

    int n;
    scanf("%d", &n);
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < n; ++i){
        cout << s[i] << t[i];
    }
    cout << endl;




    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int t[N], x[N], y[N];

    for(int i = 0; i < N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }

    int i;
    for(i = 0; i < N; i++) {
        if(x[i] + y[i] > t[i]) {
            break;
        }
        else if((x[i] + y[i]) % 2 != t[i] % 2) {
            break;
        }
    }
    
    if(i == N) { cout << "Yes"; }
    else { cout << "No"; }

    cout << endl;
    return 0;
}

Measured memory_bytes: 1408