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

int main() {
  int N, C, M = 1e5;
  cin >> N >> C;
  vector<vector<int>> V(C, vector<int>(M));
  while (N--) {
    int s, t, c;
    cin >> s >> t >> c;
    s--, c--;
    V.at(c).at(s)++;
    if (t < M) V.at(c).at(t)--;
  }
  for (int i = 0; i < C; i++) {
    for (int j = 1; j < M; j++) {
      V.at(i).at(j) += V.at(i).at(j - 1);
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = 0; j < C; j++) {
      if (V.at(j).at(i) == 2) V.at(j).at(i) = 1;
      sum += V.at(j).at(i);
    }
    ans = max(ans, sum);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 15408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    string s;
    cin >> s;
    int cnt =0;
    int r=s.size();
    int l=0;
    int dif = 0;
    while(s[l] !='A') {
        l++;
    }
    while(s[r] !='Z') {
        r--;
    }
    dif = r-l+1;

    cout << dif << "\n";
}

Measured memory_bytes: 640
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	while (true) {
		int n = -1;
		cin >> n;
		if (n <= 0) break;
		vector<int> p(n), r(n + 1);
		for (int i = 0; i < n; ++i) {
			cin >> p[i];
			r[p[i]] = i;
		}
		set<int> s;
		s.insert(-2);
		s.insert(-1);
		s.insert(n);
		s.insert(n + 1);
		LL ans = 0;
		for (int i = n; i > 0; --i) {
			auto c = s.lower_bound(r[i]);
			auto b = c, d = c;
			--b, ++d;
			auto a = b;
			--a;
			int aa = *a;
			int bb = *b;
			int cc = *c;
			int dd = *d;
			s.insert(r[i]);
			if (bb >= 0) {
				LL ls = max(0, aa + 1);
				LL le = bb;
				LL rs = r[i];
				LL re = min(n - 1, cc - 1);
				LL cnt = (le - ls + 1) * (re - rs + 1);
				ans += i * cnt;
			}
			if (cc < n) {
				LL ls = max(0, bb + 1);
				LL le = r[i];
				LL rs = cc;
				LL re = min(n - 1, dd - 1);
				LL cnt = (le - ls + 1) * (re - rs + 1);
				ans += i * cnt;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 5760
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

int parent(int i){ return i/2; }
int left(int i){ return 2*i; }
int right(int i){ return (2*i)+1; }

void maxHeapify(int i){
  int l, r, largest, tmp;
  l = left(i);
  r = right(i);
  if( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  
  if( r <= H && A[r] > A[largest] ) largest = r;

  if( largest != i ){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if( H < 1 ) return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  int tmp;
  if( key < A[i] ) return;
  A[i] = key;
  while( i > 1 && A[i/2] < A[i] ){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i / 2;
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H,key);
}

int main(){
  int key;
  char c[10];

  while( 1 ){
    scanf("%s",c);
    if( c[0] == 'e' && c[1] == 'n' ) break;
    if( c[0] == 'i' ){
      scanf("%d",&key);
      insert(key);
    }
    else printf("%d\n",extract());
  }
  return 0;
}



Measured memory_bytes: 5636
#include <stdio.h>

int main(void)
{
  char s[200002];
  char t[200002];
  int i,ans = 0;
  scanf("%s",s);
  scanf("%s",t);
  for(i=0; s[i] != '\0'; i++)
  {
    if(s[i] != t[i]) ans++;
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 2512
#include<cstdio>
#define maxn 100005
using namespace std;
int n,a[maxn];
inline char nc(){
	static char buf[100000],*L=buf,*R=buf;
	return L==R&&(R=(L=buf)+fread(buf,1,100000,stdin),L==R)?EOF:*L++;
}
inline int read(){
	int ret=0,f=1;char ch=nc();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=nc();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=nc();
	return ret*f;
}
inline bool check1(){
	bool flg=1;
	for (int i=1;i<=n;i++) if (a[i]) flg=0;
	return flg;
}
inline bool check2(){
	if (n%3) return 0;
	int num=0,lst=0;
	for (int i=1;i<=n;i++)
	if (a[i]){
		if (!lst) lst=a[i],num=1;
		else if (lst==a[i]) num++;else return 0;
		
	}
	if (num==(n/3)*2) return 1; 
	return 0;
}
inline bool check3(){
	if (n%3) return 0;
	int x,y,z,nx=0,ny=0,nz=0;
	for (int i=1;i<=n;i++){
		if (!nx){x=a[i];nx++;continue;}
		if (x==a[i]){nx++;continue;}
		if (!ny){y=a[i];ny++;continue;}
		if (y==a[i]){ny++;continue;}
		if (!nz){z=a[i];nz++;continue;}
		if (z==a[i]){nz++;continue;}
		return 0;
	}
	if (nx==n/3&&ny==n/3&&nz==n/3&&(x^y^z)==0) return 1;
	return 0;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	if (check1()){printf("Yes");return 0;}
	if (check2()){printf("Yes");return 0;}
	if (check3()){printf("Yes");return 0;}
	printf("No");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int n;
char s[110];

int main()
{
    scanf("%d",&n);
    scanf("%s",s);

    if(n%2)
    {
        printf("No\n");
        return 0;
    }
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[i+n/2])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

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

int main(){
	int n;
	cin >> n;
	int max = 2;
	vector<int> v1(n), v2(n);
	for(int i = 0; i < n; i++){
		cin >> v1[i];
	}
	for(int i = 0; i < n; i++){
		cin >> v2[i];
	}
	for(int i = 0; i < n; i++){
		int tmp = 0;
		for(int j = 0; j <= i; j++){
			tmp += v1[j];
		}
		for(int j = i; j < n; j++){
			tmp += v2[j];
		}
		if(tmp > max) max = tmp;
	}
	cout << max;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

class UnionFind{
public:
	vector<int> par;
	//0-indexed
	UnionFind(int n){init(n);}
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		else par[x] = y;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N,M;
	cin >> N >> M;
	vector<int> Lang[M+1];
	FOR(i,1,N+1){
		int K,L;
		cin >> K;
		FOR(j,0,K){
			cin >> L;
			Lang[L].push_back(i);
		}
	}
	UnionFind uf(N+1);
	FOR(i,1,M+1){
		FOR(j,1,Lang[i].size()){
			uf.unite(Lang[i][0],Lang[i][j]);
		}
	}
	set<int> ans;
	FOR(i,1,N+1)ans.insert(uf.root(i));
	if(ans.size()==1){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 4608
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=[LI() for _ in range(n)]
  l.sort(reverse=True)

  q=[]
  i=1
  ans=0
  while True:
    while True:
      if len(l)>0:
        if l[-1][0]<=i:
          a,b=l.pop()
          heapq.heappush(q,-b)
        else:
          break
      else:
        break
    if len(q)>0:
      c=heapq.heappop(q)
      ans-=c
    i+=1

    if i>m:
      break

  return ans

# main()
print(main())


Measured memory_bytes: 23844
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//



     signed main(){
  int d;
  clock_t st=clock();
  cin>>d;
    clock_t ed=clock();

  int c[26];
  for(int i=0;i<26;i++)cin>>c[i];
  int t[d],s[d][26],x[26]={};
    vector<int>v[26];
    for(int i=0;i<26;i++)v[i].push_back(-1);

  for(int i=0;i<d;i++)for(int j=0;j<26;j++)cin>>s[i][j];
   // cerr<<'i';
  for(int i=0;i<d;i++){
      for(int j=0;j<26;j++)x[j]+=c[j];
      int k=0;
      for(int j=1;j<26;j++)if(x[k]+s[i][k]<x[j]+s[i][j])k=j;
      t[i]=k;
      x[k]=0;
      v[k].push_back(i);
  }
  for(int i=0;i<26;i++)v[i].push_back(d);
//for(int i=0;i<d;i++)cout<<t[i]+1<<endl;
  // cerr<<double(clock()-st)/CLOCKS_PER_SEC<<endl;
while(double(clock()-st)/CLOCKS_PER_SEC<1.96){
    int p=rand()%d;
    auto q=find(v[t[p]].begin(),v[t[p]].end(),p);
    q++;
  // int m=(p+(*q))/2;
   int m=p+rand()%((*q)-p);
//cerr<<m<<' '<<p<<endl;
   if(m==p)continue;
   auto r1=find(v[t[m]].begin(),v[t[m]].end(),m);
   auto r0=r1-1,r2=r1+1;
   if((m-p)*((*q)-m)*c[t[p]]+s[m][t[p]]>(m-(*r0))*((*r2)-m)*c[t[m]]+s[m][t[m]]){
 
    v[t[p]].insert(q,m);
    v[t[m]].erase(r1);
    t[m]=t[p];
   }




}
     for(int i=0;i<d;i++)cout<<t[i]+1<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 3752
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a,b=MI()
print(a*b)

Measured memory_bytes: 9484
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q,x,n,d;
    list<int>l;
    scanf("%d",&q);
    list<int>::iterator it;
     list<int>::iterator it2;
    it=l.end();
    for(int i=0;i<q;i++)
    {
        scanf("%d",&n);
        if(n==0)
        {
           scanf("%d",&x);
           l.insert(it,x);
            it--;
        }
        else if(n==1)
        {
            scanf("%d",&d);
            if(d>0)
            {
                for(int k=0;k<d;k++)
                {
                    it++;
                }
            }
            if(d<0)
            {
                for(int k=0;k<((-1)*d);k++)
                {
                    it--;
                }
            }
        }
        else if(n==2)
        {
            it2=it;
            it2++;
            l.erase(it);
            it=it2;
        }
    }
    for( it=l.begin();it!=l.end();it++)
    {
        cout<<*it<<endl;
    }
    return 0;
}



Measured memory_bytes: 18696
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n, x; cin >> n >> x;
    int mi = INF;
    rep(i,n){
        int a; cin >> a;
        x -= a;
        mi = min(mi,a);
    }
    cout << n + x / mi << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//木の連結成分の個数は頂点数ー辺の数

signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll x,k,d; cin >> x >> k >> d;
    ll y=x/(2*d)+(k/2);
    //cout << y << endl;
    ll ans=1e18;
    if(y<0) y=0;
    if(y>k) y=k;
    for(ll i=y-2;i<=y+2;i++){
        if(i<0||k<i) continue;
        ll j=(k-2LL*i);
        ll res=x+j*d;
        res=labs(res);
        chmin(ans,res);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int64_t a,b,c,d,e;
  string f,g,h,i,j;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
#define ll long long int
#define w(t) int t;cin>>t; while(t--)
#define mp make_pair
#define fi first
#define se second
#define fr(n) for(int i=0;i<n;i++)
#define um unordered_map
#define pqm priority_queue <int, vector<int>, greater<int> >
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    int t=a;
    a=b;
    b=t;
    t=a;
    a=c;
    c=t;
    cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,k=map(int, readline().rstrip().split())
    pp=list(map(int, readline().rstrip().split()))
    pp.sort()
    ans=0
    for i in range(k):
        ans+=pp[i]
    print(ans)
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int x, n;
    cin >> x >> n;

    vector<int> p(n);

    rep(i, n){
        cin >> p[i];
    }

    int ans;
    int diff = INT_MAX;

    for(int i = 0; i <= 101; i++){
        bool exist = false;

        rep(j, n){
            if(i == p[j]){
                exist = true;
                break;
            }
        }

        if(!exist){

            //cerr << i << " " << abs(i - x) << " " << diff << endl;
            if(abs(i - x) < diff){
                ans = i;
                diff = abs(i - x);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int s = Integer.parseInt(sc.next());
    int w = Integer.parseInt(sc.next());
    pw.println(
      s <= w ? "unsafe" : "safe"
    );
  }
}


Measured memory_bytes: 35732
n, y = gets.chomp.split.map(&:to_i)

(0..n).each do |i|
  (0..n-i).each do |j|
    k = n-i-j
    if y == 10000 * i + 5000 * j + 1000 * k
      puts sprintf('%d %d %d', i, j, k)
      exit
    end
  end
end
puts sprintf('%d %d %d', -1, -1, -1)


Measured memory_bytes: 3836
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        int[][] a = new int[n][m];
        int[][] b = new int[m][l];
        long[][] c = new long[n][l];
        for(int i=0; i<n; i++) {
        		for(int j=0; j<m; j++) {
        			a[i][j] = sc.nextInt();
        		}
        }
        for(int i=0; i<m; i++) {
    			for(int j=0; j<l; j++) {
    				b[i][j] = sc.nextInt();
    			}
        }
        for(int i=0; i<n; i++) {
        		for(int k=0; k<l; k++) {
        			for(int j=0; j<m; j++) {
        				c[i][k] += a[i][j]*b[j][k];
        			}
        		}
        }
        for(int i=0; i<n; i++) {
        		for(int k=0; k<l; k++) {
        			if(k==l-1) {
        				System.out.println(c[i][k]);
        			} else {
        				System.out.print(c[i][k] + " ");
        			}
        		}
        }
    }
}



Measured memory_bytes: 54600
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        k: usize,
        v: [i32; n],
    }
    let mut dp = vec![vec![vec![0; n + 1]; n + 1]; k + 1];
    let max = std::cmp::max;
    for i in 1..(k + 1) {
        for l in 0..n {
            for r in l..n {
                let mut s = dp[i - 1][l][r];
                s = max(dp[i - 1][l + 1][r] + v[l], s);
                if r > 0 {
                    s = max(dp[i - 1][l][r - 1] + v[r], s);
                }
                if i > 1 {
                    s = max(dp[i - 2][l + 1][r], s);
                    if r > 0 {
                        s = max(dp[i - 2][l][r - 1], s);
                    }
                }
                dp[i][l][r] = s;
            }
        }
    }
    println!("{}", dp[k][0][n - 1]);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve()
{
  int n;
  cin >> n;
  int x=(n+999)/1000;
  cout << (x*1000)-n << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


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

int main() {
    int N; cin >> N;
    string s; cin >> s;
    vector<int> S(N); for (int i = 0; i < N; i++) S[i] = s[i] - '0';
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                int mode = 0;
                for (int l = 0; l < N; l++) {
                    if (mode == 0 && S[l] == i) {
                        mode++;
                    } else if (mode == 1 && S[l] == j) {
                        mode++;
                    } else if (mode == 2 && S[l] == k) {
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int p = 0;
	int w = 0;
	int g = 0;
	int y = 0;

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

		

		if (s == 'P') {
			++p;
		}
		else if (s == 'W') {
			++w;
		}
		else if (s == 'G') {
			++g;
		}
		else if (s == 'Y') {
			++y;
		}
	}
	if (p > 0 && w > 0 && g > 0 && y > 0) {
		cout << "Four" << endl;
	}
	else if (p > 0 && w > 0 && g > 0 && y == 0) {
		cout << "Three" << endl;
	}
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  int N;cin>>N;
  vector<pair<ll,int>> D(N);
  repeat(i,N){
    cin >> D[i].first;
    D[i].second = i+1;
  }
  sort(D.begin(),D.end());
  vll n(N,1);
  vector<vint> g(N);
  vector<Pii> edges;
  bool isok = true;
  for(int i=N-1;i>0;i--){
    debug(i);
    ll S = D[i].first+2*n[i]-N;
    int j = lower_bound(D.begin(),D.end(),pair<ll,int>(S,0))-D.begin();
    if(j>=i || D[j].first != S){
      isok = false;
      break;
    }
    edges.push_back({D[i].second,D[j].second});
    n[j]+=n[i];
    g[j].push_back(i);
  }
  queue<pair<ll,int>> Q;
  Q.push({0,0});
  ll S=0;
  while(!Q.empty()){
    Pii p = Q.front();
    Q.pop();
    S+=p.first;
    for(int u:g[p.second]){
      Q.push({p.first+1,u});
    }
  }
  isok &= S==D[0].first;
  if(!isok){
    cout <<-1<<endl;
    return 0;
  }
  repeat(i,edges.size()){
    cout << edges[i].first<<" "<<edges[i].second<<endl;
  }
  return 0;
}


Measured memory_bytes: 9972
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i+1;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

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


typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
    /* Credits: Thomas Draper */
    if ((first == last) || (first == k) || (last == k))
        return false;
    Iterator itr1 = first;
    Iterator itr2 = last;
    ++itr1;
    if (last == itr1)
        return false;
    itr1 = last;
    --itr1;
    itr1 = k;
    --itr2;
    while (first != itr1)
    {
        if (*--itr1 < *itr2)
        {
            Iterator j = k;
            while (!(*itr1 < *j)) ++j;
            iter_swap(itr1,j);
            ++itr1;
            ++j;
            itr2 = k;
            rotate(itr1,j,last);
            while (last != j)
            {
                ++j;
                ++itr2;
            }
            rotate(k,itr2,last);
            return true;
        }
    }
    rotate(first,k,last);
    return false;
}

int main() {
    double R;
    cin >> R;
    double pi =3.14159265358979;
    double ans = pi * 2 * R;
    printf("%lf",ans);


}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll MOD = 1e9 + 7;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char prev = s[0];
    int difs = 0;
    rep(i, n-1) if (s[i+1] != prev) difs++, prev = s[i+1];
    if (difs%2==0) {
        if (difs > 2*k) cout << n - (difs - 2*k) - 1 << endl;
        else cout << n - 1 << endl;
    } else {
        if (difs > 2*k) cout << n - (difs - 2*k) - 1 << endl;
        else cout << n - 1 << endl;
    }
}

Measured memory_bytes: 512
import itertools
ln = itertools.product(range(1,100),repeat = 3)
#print(ln)
line = [0 for i in range(10000)]
#print(len(line))
for i in ln:
    x,y,z = i
    n = x**2 +y**2 + z**2 +x*y + y*z + z*x
    if n <=10000:
        line[n-1]+=1
N = int(input())
for i in range(N):
    print(line[i])
        

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll H,W;
    cin >> H >> W;
    cin >> n;
    vector<ll> a(n);
    for(auto &x:a)cin >> x;
    ll ret[H][W];
    ll now = 1;
    ll cnt = 0,t=0;
    for(i=0;i<H;i++){
        if(i%2==0){
            for(j=0;j<W;j++){
                ret[i][j]=now;
                cnt++;
                if(cnt==a[t]){
                    t++;cnt=0;now++;
                }
            }
        }else{
            for(j=W-1;j>=0;j--){
                ret[i][j] = now;
                cnt++;
                if(cnt==a[t]){
                    t++;cnt=0;now++;
                }
            }
        }
    }
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cout << ret[i][j]<< " ";
        }
        cout << endl;
    }
    return 0;
}

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

	int n, k, mod, mx;
	int cnt[3][2001][2001];

int TT(int t, int y1, int x1, int y2, int x2 ){
	if( y1 > y2 || x1 > x2) return 0;
	return cnt[t][y2][x2] - cnt[t][y1-1][x2] - cnt[t][y2][x1-1] + cnt[t][y1-1][x1-1];
}

int main() {
	cin >> n >> k;

	mod = 2*k;
	for(int i = 0; i < n; i++) {
		int x, y, s;
		char t;

		cin >> x >> y >> t;

		s = (t == 'W') ? 0 : 1;
		
		cnt[s][y%mod+1][x%mod+1]++;
	}

	for(int t = 0; t < 2; t++) {
		for(int i = 1; i <= mod; i++) 
			for(int j = 1; j <= mod; j++) 
				cnt[t][i][j] += cnt[t][i-1][j]+cnt[t][i][j-1]-cnt[t][i-1][j-1];
	}

	for(int i = 0; i < k; i++) {
		for(int j = 0; j < k; j++) {
			int y1 = k-i, x1 = k-j, y2 = 2*k-i, x2 = 2*k-j;

			int s = 0;
			s += TT(0, 1, 1, y1, x1); 
			s += TT(1, y1+1, 1, y2, x1);
			s += TT(1, 1, x1+1, y1, x2);
			s += TT(0, y1+1, x1+1, y2, x2);
			s += TT(0, y2+1, 1, mod, x1);
			s += TT(0, 1, x2+1, y1, mod);
			s += TT(1, y2+1, x1+1, mod, x2);
			s += TT(1, y1+1, x2+1, y2, mod);
			s += TT(0, y2+1, x2+1, mod, mod);
			mx = max(mx, s);

			s = 0;
			s += TT(1, 1, 1, y1, x1);
			s += TT(0, y1+1, 1, y2, x1);
			s += TT(0, 1, x1+1, y1, x2);
			s += TT(1, y1+1, x1+1, y2, x2);
			s += TT(1, y2+1, 1, mod, x1);
			s += TT(1, 1, x2+1, y1, mod);
			s += TT(0, y2+1, x1+1, mod, x2);
			s += TT(0, y1+1, x2+1, y2, mod);
			s += TT(1 ,y2+1, x2+1 ,mod, mod);	
			mx = max(mx, s);
		}
	}
	cout << mx << endl;
	return 0;
}


Measured memory_bytes: 33024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int[] ia = readNums();
		int n = ia[0];
		int x = ia[1];
		int mn = _intMax;
		int s = 0;
		for (int i = 0; i < n; i++) {
			int m = readNum();
			s += m;
			mn = min(mn, m);
		}
		int ans = n;
		x -= s;
		ans += x / mn;
		pln(ans);
	}

	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 21204
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	list := make(map[int]int)
	for i := 0; i < N; i++ {
		A := nextInt()
		if _, exist := list[A]; exist {
			fmt.Println("NO")
			return
		} else {
			list[A] = A
		}
	}
	fmt.Println("YES")
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 50048
#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int a, b;
	const int v1 = 200, v2 = 300;
	char name[200];
	for (; ~fscanf(stdin, "%s %d%d", &name, &a, &b); fprintf(stdout, "%s %d %d\n", name, a + b, a*v1 + b*v2)) getchar();
	return 0;
}

Measured memory_bytes: 600
import copy
N=int(input())
lst=list(map(int,input().split()))
lst2=copy.copy(lst)
for i in range(1,N+1):
  lst2[i-1]-=i
lst2=sorted(lst2)
b=lst2[N//2]
ans=0
for i in range(N):
  ans+=abs(lst[i]-(b+i+1))
print(ans)

Measured memory_bytes: 27220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const long long INF=1e9+5;
const string alp="abcdefghijklmnopqrstuvwxyg"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYG";
typedef long long ll;

int main() {
  ll N;
  cin>>N;
  ll a[N];
  set<ll> S;
  rep(i,N){
    cin>>a[i];
    S.insert(a[i]);
  }
  cout<<S.size()<<endl;
}

Measured memory_bytes: 3628
var
	N,Q,ccc,i,k:Longint;
	D,DM,M,ans:int64;
	S:String;
begin
	readln(N);
	readln(S);
	readln(Q);
	for ccc:=1 to Q do begin
		read(k);
		D:=0;DM:=0;M:=0;ans:=0;
		for i:=1 to N do begin
			if i>k then begin
				if S[i-k]='D' then begin
					dec(DM,M);
					dec(D);
				end else if S[i-k]='M' then begin
					dec(M);
				end;
			end;
			if S[i]='D' then begin
				inc(D);
			end else if S[i]='M' then begin
				inc(DM,D);
				inc(M);
			end else if S[i]='C' then begin
				inc(ans,DM);
			end;
		end;
		writeln(ans);
	end;
end.


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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ll long long
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
//#define end "\n"
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=998244353;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;


ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}

ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}

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

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}

const long sz=1e5+10;

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}


int main()
{
    fast;
    ll t;
   // cin>>t;
    t=1;
    while(t--){
        ll n,d;
        cin>>n>>d;
        cout<<ceil(1.0*n/(2*d+1));
    }
    return 0;
}


Measured memory_bytes: 256
[sx, sy, tx, ty] = [ int(i) for i in raw_input().split()]

X = tx - sx
Y = ty - sy

res = ''
for i in xrange(X):
	res += 'R'
for i in xrange(Y):
	res += 'U'
for i in xrange(X):
	res += 'L'
for i in xrange(Y):
	res += 'D'

res += 'D'
for i in xrange(X+1):
	res += 'R'
for i in xrange(Y+1):
	res += 'U'
res += 'L'

res += 'U'
for i in xrange(X+1):
	res += 'L'
for i in xrange(Y+1):
	res += 'D'
res += 'R'

print res

Measured memory_bytes: 2692
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
int main(void){
    int a;
    cin>>a;
    int ans;
    int max=0;
    if(a==1){
        cout<<"1"<<endl;
        return 0;
    }
    for(int i=1;i<=a;i++){
        int c=i;
        int count=0;
        while(1){
            if(c%2==0){
                c/=2;
                count++;
            }else{
                break;
            }
            if(max<=count){
                max=count;
                ans=i;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;


int main() {
    int A,B,C;
    cin >> A >> B >> C;
    vector<int> divisors;
    reps(i,C) {
      if (C % i == 0) divisors.push_back(i);
    }
    int r=0;
    for (int i=0; i < divisors.size(); i++) {
        if (A <= divisors[i] && B >= divisors[i]) r++;
    }
    cout << r << endl;
}


Measured memory_bytes: 3172
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 200200
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,Q,ans;char s[MAX];
char ch[2],A[MAX],B[MAX];
bool vis[MAX];
int chk(int x)
{
	for(int i=1;i<=Q;++i)
		if(s[x]==A[i])
		{
			x+=(B[i]=='L')?-1:1;
			if(x<1)return 0;
			if(x>n)return 1;
		}
	return 2;
}
int main()
{
	n=read();Q=read();scanf("%s",s+1);
	for(int i=1;i<=Q;++i)scanf("%s",ch),A[i]=ch[0],scanf("%s",ch),B[i]=ch[0];
	{
		int l=1,r=n,ret=0;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(chk(mid)==0)l=mid+1,ret=mid;
			else r=mid-1;
		}
		for(int i=1;i<=ret;++i)vis[i]=true;
	}
	{
		int l=1,r=n,ret=n+1;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(chk(mid)==1)r=mid-1,ret=mid;
			else l=mid+1;
		}
		for(int i=ret;i<=n;++i)vis[i]=true;
	}
	for(int i=1;i<=n;++i)ans+=!vis[i];
	printf("%d\n",ans);
	return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define Lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin();

int lbidx(vector<int> x, int y) {
  return lower_bound(x.begin(), x.end(), y) - x.begin();
};

int upidx(vector<int> x, int y) {
  return upper_bound(x.begin(), x.end(), y) - x.begin();
};

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);

  rep(i, 0, N) {
    cin >> A[i];
  }
  rep(i, 0, N) {
    cin >> B[i];
  }

  int ans = 0;
  int T = 1;
  rep(k, 0, 30) {
    int mod = 2 * T;
    vector<int> Amod(N);
    vector<int> Bmod(N);
    rep(i, 0, N) {
      Amod[i] = A[i] % mod;
      Bmod[i] = B[i] % mod;
    }
    sort(All(Amod));

    ll counter = 0;
    rep(i, 0, N) {
      int bi = Bmod[i];
      // int l1 = lbidx(Amod, T - bi);
      // int r1 = lbidx(Amod, 2 * T - bi);
      // int l2 = lbidx(Amod, 3 * T - bi);
      // int r2 = lbidx(Amod, 4 * T - bi);
      int l1 = Lbidx(Amod, T - bi);
      int r1 = Lbidx(Amod, 2 * T - bi);
      int l2 = Lbidx(Amod, 3 * T - bi);
      int r2 = Lbidx(Amod, 4 * T - bi);
      // auto l1 = lower_bound(Amod.begin(), Amod.end(), T - bi);
      // auto r1 = lower_bound(Amod.begin(), Amod.end(), 2 * T - bi);
      // auto l2 = lower_bound(Amod.begin(), Amod.end(), 3 * T - bi);
      // auto r2 = lower_bound(Amod.begin(), Amod.end(), 4 * T - bi);
      counter += (r1 - l1) + (r2 - l2);
    }
    if (counter % 2 == 1) ans += T;
    T *= 2;
  }

  cout << ans << endl;
};


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

int main(void) {
	int N;
	cin >> N;
	vector <int> ans(N+1);
	for (int i = 1; i <= N; i++) {
		int A;
		cin >> A;
		ans.at(A) = i;
	}

	for (int i = 1; i <= N; i++) {
		cout << ans.at(i);
		if (i < N) cout << " ";
		else cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1152
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())



class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


def main():
	n,m=map(int,input().split())
	uf=WeightedUnionFind(n)
	
	for i in range(m):
		l,r,d=map(int,input().split())
		if uf.same(l,r):
			if d!=uf.diff(l,r):
				print("No")
				exit(0)
		else:
			uf.union(l,r,d)
	print("Yes")
	
if __name__ == '__main__':
	main()

Measured memory_bytes: 11428
#include <iostream>

using namespace std;

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

  int n, d;
  cin >> n >> d;
  int ans = 0;
  for (int i = 0; i < n; i += 2 * d + 1) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
const int M = 1e3;
char mmp[M][M] , s[M][M];
int h , w , k , step[M][M] , dr[4][2] = {1 , 0 , -1 , 0 , 0 , 1 , 0 , -1};
struct TnT {
    int x , y , step , flag;
};
bool vis[M][M];
void bfs(TnT sta) {
    memset(step , 0 , sizeof(step));
    step[sta.x][sta.y] = 1;
    memset(vis , false , sizeof(vis));
    vis[sta.x][sta.y] = true;
    queue<TnT>q;
    q.push(sta);
    while(!q.empty()) {
        TnT gg = q.front();
        q.pop();
        for(int i = 0 ; i < 4 ; i++) {
            TnT gl = gg;
            gl.x += dr[i][0];
            gl.y += dr[i][1];
            if(gl.x >= 0 && gl.x < h && gl.y >= 0 && gl.y < w && mmp[gl.x][gl.y] != '#' && !vis[gl.x][gl.y]) {
                gl.step++;
                step[gl.x][gl.y] = gl.step;
                vis[gl.x][gl.y] = true;
                q.push(gl);
            }
        }
    }
}
int main() {
    scanf("%d%d%d" , &h , &w , &k);
    for(int i = 0 ; i < h ; i++) {
        scanf("%s" , mmp[i]);
    }
    TnT sta;
    for(int i = 0 ; i < h ; i++) {
        for(int j = 0 ; j < w ; j++) {
            if(mmp[i][j] == 'S') {
                sta.x = i , sta.y = j;
                break;
            }
        }
    }
    sta.step = 0 , sta.flag = k;
    bfs(sta);
    int ans = 1000000000;
    for(int i = 0 ; i < h ; i++) {
        for(int j = 0 ; j < w ; j++) {
            if(step[i][j] != 0) {
                if(i == 0 || i == h - 1 || j == 0 || j == w - 1) {
                    int gg = step[i][j];
                    if(gg % k == 0) {
                        ans = min(ans , gg / k);
                    }
                    else {
                        ans = min(ans , gg / k + 1);
                    }
                }
                else {
                    int gg = step[i][j] , gl = 0;
                    if(gg % k == 0) {
                        gl = gg / k;
                    }
                    else {
                        gl = gg / k + 1;
                    }
                    gg = i;
                    if(gg % k == 0) {
                        ans = min(ans , gl + gg / k);
                    }
                    else {
                        ans = min(ans , gl + gg / k + 1);
                    }
                    gg = j;
                    if(gg % k == 0) {
                        ans = min(ans , gl + gg / k);
                    }
                    else {
                        ans = min(ans , gl + gg / k + 1);
                    }
                    gg = h - 1 - i;
                    if(gg % k == 0) {
                        ans = min(ans , gl + gg / k);
                    }
                    else {
                        ans = min(ans , gl + gg / k + 1);
                    }
                    gg = w - 1 - j;
                    if(gg % k == 0) {
                        ans = min(ans , gl + gg / k);
                    }
                    else {
                        ans = min(ans , gl + gg / k + 1);
                    }
                }
            }
        }
    }
    printf("%d\n" , ans);
    return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> A(N);
  
  for( int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  int dai = A.at(0), shou = A.at(0);
  
  for ( int i = 1; i < N; i++){
    if ( dai < A.at(i) ){
      dai = A.at(i);
    }
    if ( A.at(i) < shou ){
      shou = A.at(i);
    }
  }
  
  cout << dai - shou << endl;
  
}


Measured memory_bytes: 256
//b.c B-Time Limit Exceeded
#include<stdio.h>

int main(void){
    int n,time;
    scanf("%d %d",&n,&time);
    int c[n],t[n];
    for(int i=0;i<n;++i){
        scanf("%d %d",&c[i],&t[i]);
    }

    int min = -1;
    for(int i=0;i<n;++i){
        if(time>=t[i] && (min>c[i] || min == -1) ){
            min = c[i];
        }
    }

    if(min == -1){
        printf("TLE\n");
    }else{
        printf("%d\n",min);
    }
    return 0;
}

Measured memory_bytes: 128
def main():
    cities, roads = map(int, input().split())
    count = [0] * cities
    for _ in range(roads):
        begin, end = map(int, input().split())
        count[begin - 1] += 1
        count[end - 1] += 1
    for i in range(cities):
        print(count[i])


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940