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

using ll = long long;
using K = long double;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())
#define ALL(a) (a).begin(), (a).end()

char mex(string s) {
	map<char,int> mp;
	for (auto& c : s) mp[c] = 1;
	for (char c = 'a'; c <= 'z'; ++c) {
		if (!mp[c]) return c;
	}
	return -1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << '\n';
		return 0;
	}
	
	if (SIZE(s) < 26) {
		cout << (s + mex(s)) << '\n';
		return 0;
	}
	
	char mx = 0;
	
	for (int i = SIZE(s)-1; i >= 0; --i) {
		if (s[i] < mx) {
			for (int j = 0; j < i; ++j) cout << s[j];
			for (int j = i+1; j < SIZE(s); ++j) if (s[j] > s[i]) mx = min(mx, s[j]);
			cout << mx << '\n';
			return 0;
		} else {
			mx = s[i];
		}
	}
	
	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2>
using Dict = std::unordered_map<T1,T2>;




int main(void) {
    int N;
    std::cin >> N;
    std::cout << -(N%1000-1000)%1000 << std::endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vector<pair<int, int>> v(n);
  rep(i, n) 
    v[i] = {a[i]+b[i], i};
  sort(v.rbegin(), v.rend());
  ll res[2] = {};
  rep(i, n) {
    int idx = v[i].second;
    if (i%2)
      res[1] += b[idx];
    else
      res[0] += a[idx];
  }
  cout << res[0]-res[1] << endl;
  return 0;
}

Measured memory_bytes: 1792
/* Bubble Sort */
#include <stdio.h>

int main()
{
    int N, i, j, cnt = 0, temp;
    int A[100];

    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%d", &A[i]);
    }
    for(i=0; i<N; i++){
        for(j=N-1; j>i; j--){
            if(A[j] < A[j-1]){
                temp = A[j];
                A[j] = A[j-1];
                A[j-1] = temp;
                cnt++;
            }
        }
    }

    for(i=0; i<N; i++){
        if(i>0){ printf(" "); }
        printf("%d", A[i]);
    }
    printf("\n%d\n", cnt);
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    string S;
    cin >> N >> S;
    vector<vector<ll>> pos(10, vector<ll>());
    rep(i, N) {
        pos[S[i] - '0'].emplace_back(i);
    }
    ll ans = 0;
    rep(i, 10) {
        pos[i].push_back(INF);
    }
    rep(i, 1000) {
        string s = to_string(i);
        while (s.size() < 3) {
            s = '0' + s;
        }
        ll last = -INF;
        ll ok = true;
        rep(j, 3) {
            ll d = s[j] - '0';
            ll idx = *lower_bound(pos[d].begin(), pos[d].end(), last + 1);
            if (idx > last && idx != INF) {
                last = idx;
            } else {
                ok = false;
                break;
            }
        }
        if (ok) ans++;
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    // ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

using i64 = long long;
using u64 = unsigned long long;

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

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    if(s[len-1] == 's') s += "es";
    else s += "s";
    cout << s << endl;
}


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

int main(){
    ll N, A, B; cin >> N >> A >> B;

    if((B-A) % 2 == 0){
        cout << (B - A) / 2 << endl;
        return 0;
    }
    cout << min((A - 1 + B) / 2, (N - B + 1 + N - A) / 2)  << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    public Program()
    {
        int N = int.Parse(Console.ReadLine());
        string[] inputs = Console.ReadLine().Split();
        int T = int.Parse(inputs[0]);
        int A = int.Parse(inputs[1]);
        int[] hs = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int result = 0;
        double min = int.MaxValue;
        foreach(int i in Enumerable.Range(0, N))
        {
            Double a = Math.Abs(A - (T - 0.006 * hs[i]));
            if(min > a)
            {
                min = a;
                result = i;
            }
        }
        Console.WriteLine(result + 1);
    }
    static void Main(string[] args)
    {
        var p = new Program();
    }
}


Measured memory_bytes: 13396
N=int(input())

def divisor(x):
    div=[]
    for i in range(1,int(x**(1/2))+1):
        if x%i==0:
            div.append(i)
            if i!=x//i:
                div.append(x//i)
    return sorted(div)

def factorization(n):
    arr=[]
    temp=n
    for i in range(2,int(n**(1/2))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp//=i
            arr.append([i,cnt])
        
    if temp!=1:
        arr.append([temp,1])

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

zt=[1]
ans=0
while N>1:
    for i in divisor(N):
        if i not in zt:  
            if len(factorization(i))==1:
                z=i
                zt.append(z)
                break
    if z==0:
        break
    N=N//z
    ans+=1
    z=0

print(ans)

Measured memory_bytes: 9488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		if(str.indexOf("a")!=-1 && str.indexOf("b")!=-1 && str.indexOf("c")!=-1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

#define rep(i,n)  for(int i = 0; i < (int)(n); i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string N; std::cin >> N;
  ll s = 0;
  rep(i,sz(N)) {
    int n = N[i] - '0';
    s += n;
  }
  if ( s % 9 == 0 ) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}



Measured memory_bytes: 3772
#include<iostream>

using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

int check(llong P) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        llong s = 0;
        while (s + T[i] <= P) {
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n) {right = mid;}
        else {left = mid;}
    }
    return right;
}

int main(int argc, char const *argv[]){
    cin >> n >> k;
    for (int i = 0; i < n; i++) {cin >> T[i];}
    llong ans = solve();
    cout << ans << endl;
    
    return 0;
}


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


/* Raiyan Noory Rady,CSE'17,RUET
Email:raiyannooryrady@gmail.com
Smile->Desire->Unity->Effort->Struggle->Success->Again smile :)
*/

#define ll long long int
#define pf push_front
#define mod  1000000007
#define inf  1000000000000000000
#define pi  acos(-1.0)
#define maxn  1000009
#define sorted(s)  sort(s.begin(),s.end())
#define sortarr(a) sort(a,a+n)
#define slc(n) scanf("%I64d", &n)
#define sl(n)  scanf("%lld", &n)
#define sf(n)  scanf("%lf", &n)
#define si(n)  scanf("%d", &n)
#define sch(n)  scanf(" %c", &n)
#define ss(n)  scanf("%s", n)
#define prf printf
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define forl(n) for(i=0;i<n;i++)
/*STL library functions

sort(first_iterator, last_iterator) – To sort the given vector.

reverse(first_iterator, last_iterator) – To reverse a vector.

*max_element (first_iterator, last_iterator) – To find the maximum element of a vector.

*min_element (first_iterator, last_iterator) – To find the minimum element of a vector.

accumulate(first_iterator, last_iterator, initial value of sum) – Does the summation of vector elements

count(first_iterator, last_iterator,x) – To count the occurrences of x in vector.

find(first_iterator, last_iterator, x) – Points to last address of vector ((name_of_vector).end())
 if element is not present in vector.

binary_search(first_iterator, last_iterator, x) – Tests whether x exists in sorted vector or not.

lower_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last)
which has a value not less than ‘x’.

upper_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last)
 which has a value greater than ‘x’.

arr.erase(position to be deleted) – This erases selected element in vector and shifts and resizes the vector elements accordingly.

arr.erase(unique(arr.begin(),arr.end()),arr.end()) – This erases the duplicate occurrences in sorted vector in a single line.

distance(first_iterator,desired_position) – It returns the distance of desired position from the first iterator.
This function is very useful while finding the index.

next_permutation(first_iterator, last_iterator) – This modified the vector to its next permutation.

prev_permutation(first_iterator, last_iterator) – This modified the vector to its previous permutation.
*/

using namespace std;
ll c[100005];

int main()
{

   ll n,k,q,i,x;
   cin>>n>>k>>q;
   for(i=1;i<=q;i++)
   {
       cin>>x;
       c[x]++;

   }
   for(i=1;i<=n;i++)
   {
       ll ans= k-(q-c[i]);
       if(ans<=0)
        cout<<"No"<<endl;
       else
        cout<<"Yes"<<endl;
      // cout<<c[i]<<" "<<ans<<endl;
   }


    return 0;
}






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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(long long &a, long long b) { if (a > b) a = b; }

int main(){
  ll i, j;
  vector<ll> a(4);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  vector<bool> n(4);
  for(i = 0; i < 4; i++){
    switch(a[i]){
      case 1: n[0] = true;
        break;
        case 4: n[1] = true;
        break;
      case 7: n[2] = true;
        break;
        case 9: n[3] = true;
        break;
    }
  }
  if(n[0] && n[1] && n[2] && n[3])
  cout << "YES" << endl;
  else 
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

string s;
bool vis[30];

int main()
{
    cin >> s;
    int n=s.size();
    if (n<26)
    {
        rep(i,0,n-1) vis[s[i]-'a']=1;
        rep(i,0,26)
        {
            if (!vis[i])
            {
                cout << s;putchar('a'+i);
                break;
            }
        }
    }
    else
    {
        per(i,n-1,0)
        {
            int p=-1,ch=s[i]-'a';
            rep(j,0,25)
                if ((vis[j]) && (ch<j)) {p=j;break;}
            if (p!=-1)
            {
                rep(j,0,i-1) putchar(s[j]);
                putchar('a'+p);return 0;
            }
            vis[ch]=1;
        }
        puts("-1");
    }
    return 0;
}

    

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      int D = input.nextInt();
      int T = input.nextInt();
      int S = input.nextInt();

      int ans = S * T;
      if(ans < D) {
         System.out.println("No");
      }  else if(ans > D | ans == D) {
         System.out.println("Yes");
      }
      input.close();

   }
   
}


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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}
int h,w,d;
//0から始める場合と1から始める場合
ll cost[90100] = {0};
map<int,pii> mp;
int q;

int main(){
  scanf("%d %d %d",&h,&w,&d);
  REP(i,h)REP(j,w){
    int a;
    scanf("%d",&a);
    mp[a] = pii(i,j);
  }
  FOR(i,1,d+1)for(int j = i+d; j <h*w+1;j+=d){
    int p_i = mp[j-d].first;
    int p_j = mp[j-d].second;
    int n_i = mp[j].first;
    int n_j = mp[j].second;
    cost[j] = cost[j-d] + abs(p_i-n_i) + abs(p_j-n_j);
  }
  scanf("%d",&q);
  REP(i,q){
    int s,g;
    scanf("%d %d",&s,&g);
    printf("%lld\n",cost[g]-cost[s]);
  }
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int cnt[2] = {};
	vector<pii> arr;
	while(n--) {
		string s;
		cin >> s;
		
		int a = 0 , b = 0;
		for(char c : s)
			if(c == '(') {
				a++;
			}
			else {
				if(a == 0)
					b++;
				else
					a--;
			}
		
		if(a == 0 && b == 0)	continue;
		if(a == 0)
			cnt[1] += b;
		else if(b == 0)
			cnt[0] += a;
		else 
			arr.push_back({a,b});
	}
	sort(arr.begin(),arr.end(),[=](pii a,pii b)->bool
		{return (a.first > a.second && b.first > b.second) ? a.second < b.second : a.first - a.second > b.first - b.second;});
	for(pii now : arr) {
		cnt[0] -= now.second;
		if(cnt[0] < 0) {
			cout << "No" << endl;
			return 0;
		}
		cnt[0] += now.first;
	}
	if(cnt[0] == cnt[1])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

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

int h, w;
char g[1000][1000];
vector<vector<int>> dist(1000, vector<int>(1000, INF));
queue<P> que;

void bfs(){
  while(!que.empty()){
    P cque = que.front();
    int y = cque.first;
    int x = cque.second;
    que.pop();
    rep(i,4){
      int ny = y + dy[i];
      int nx = x + dx[i];
      if(ny < 0 || ny >= h || nx < 0 || nx >= w ) continue;
      if(g[ny][nx] == '#') continue;
      if(dist[ny][nx] <= dist[y][x]+1) continue;
      dist[ny][nx] = dist[y][x]+1;
      que.push(make_pair(ny,nx));
    }
  }
}

int main(){
  cin >> h >> w;
  rep(i,h)rep(j,w){
    cin >> g[i][j];
    if(g[i][j] == '#'){
      que.push(make_pair(i, j));
      dist[i][j] = 0;
    }
  }
  bfs();
  int ans = -1;
  rep(i,h)rep(j,w)
    ans = max(ans, dist[i][j]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13328
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True


mo=998244353

ans=0
n,s=LI()
a=LI()

def dyn(n,A,a):
    dp=[[0]*(A+1) for i in range(n+1)]
    for i in range(n):
        x=a[i]
        dp[i+1]=dp[i][:]
        dp[i+1][x]+=1+i
        for j in range(x,A+1):
            dp[i+1][j]+=dp[i][j-x]
            dp[i+1][j]%=mo
    return dp

dp=dyn(n,3000,a)

for i in dp:
    ans+=i[s]
    ans%=mo

print(ans)

Measured memory_bytes: 169432
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
int H,W;
vector<vector<char>> S(1000,vector<char>(1000));
vector<vector<int>> cost(1000,vector<int>(1000));
deque <P> que;
int INF = 10000000;

int main() {

    cin >> H >> W;
    int i,j;
    int Ch,Cw,Dh,Dw;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;

    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cin >> S.at(i).at(j);
        }
    }

    vector<int> dx = {-1,0,1,0};
    vector<int> dy = {0,1,0,-1};
    vector<int> magic_dx = {-2,-1,0,1,2};
    vector<int> magic_dy = {-2,-1,0,1,2};

    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cost.at(i).at(j) = INF;
        }
    }
    
    P s = make_pair(Cw-1,Ch-1);
    que.push_front(s);
    cost.at(Ch-1).at(Cw-1) = 0;

    while(!que.empty()){
        //新しい座標の取り出し
        P q = que.front();
        que.pop_front();

        //それがゴールだったら終わり
        if(q.first == Dw-1 && q.second == Dh-1){
            break;
        }

        //4方向試す
        for(i=0;i<4;i++){
            int nx,ny;
            nx = q.first + dx.at(i);
            ny = q.second + dy.at(i);
            //移動できるならキューに新たな座標を追加
            if(0 <= nx && nx < W && 0 <= ny && ny < H && S.at(ny).at(nx) == '.'){
                if(cost.at(ny).at(nx) > cost.at(q.second).at(q.first)){
                    P n = make_pair(nx,ny);
                    que.push_front(n);
                    cost.at(ny).at(nx) = cost.at(q.second).at(q.first);
                }
            }
        }

        //魔法
        for(i=0;i<5;i++){
            for(j=0;j<5;j++){
                int nx,ny;
                nx = q.first + magic_dx.at(i);
                ny = q.second + magic_dy.at(j);
                //移動できるならキューに新たな座標を追加
                if(0 <= nx && nx < W && 0 <= ny && ny < H && S.at(ny).at(nx) == '.'){
                    if(cost.at(ny).at(nx) > cost.at(q.second).at(q.first) + 1){
                        P n = make_pair(nx,ny);
                        que.push_back(n);
                        cost.at(ny).at(nx) = cost.at(q.second).at(q.first) + 1;
                    }
                }
            }
        }
    }
    if(cost.at(Dh-1).at(Dw-1) == INF){
        cout << -1 << endl;
    }else{
        cout << cost.at(Dh-1).at(Dw-1) << endl;
    }

}

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

static const int mod = 1e9 + 7;
using namespace std;

int main(){
  string s;
  int dp[100000+3][13] = {0};
  cin >> s;
  int n = s.length();
  int A[n];
  for (int i = 0; i < n; i++) {
    if (s[i] == '?') {
      A[i] = -1;
    } else {
      A[i] = int(s[i] - '0');
    }
  }

  dp[0][0] = 1;
  long long mul = 1;
  for (int i = 0; i < n; i++) {//digit from the top
    for (int j = 0; j < 10; j++) {//0~9 for each digit
      if (A[n-i-1] != -1 && A[n-i-1] != j) { continue; }
      for (int k = 0; k < 13; k++) {//residual when divided by 13
        /*
        Point 1: 桁ごとに分割できる
          ??2??5 = (100000 * ?) + (10000 * ?) + (1000 * 2) + (100 * ?) + (10 * ?) + (1 * 5)

        Point 2: 桁を13で割ったあまりに落とし込める
          100000%13 = 4
          10000%13 = 3
          1000%13 = 12
          100%13 = 9
          10%13 = 10
          1%13 = 1
          なので、
          ??2??5を13で割ったときのあまりを考える際は
          ??2??5 = (4 * ?) + (3 * ?) + (12 * 2) + (9 * ?) + (10 * ?) + (1 * 5)
          のようにさらに単純化できる
        */
        //1桁目から数えてi桁目時点であまりkになる場合の数は、i桁目のあまりkの数に
        dp[i+1][(j*mul + k)%13] += dp[i][k];
        dp[i+1][(j*mul + k)%13] %= mod;
      }
    }
    mul *= 10;
    mul %= 13;
  }
  cout << dp[n][5] << endl;
  return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <set>
using namespace std;
int main() {
  set<string> x;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    x.insert(s);
  }
  cout << x.size() << endl;
  return 0;
}


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

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

    string strA = "";
    string strB = "";
    for (int i = 0; i < b; i++) strA += to_string(a);
    for (int i = 0; i < a; i++) strB += to_string(b);

    if (strA > strB) cout << strB << endl;
    else cout << strA << endl;
    return 0;
}

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

typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl; 
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main() 
{
 
int k ; cin >> k ;
string s ; cin >> s;
if(s.length() > k ){
s.erase(s.begin()+k, s.end());
s.append("...");
cout << s << endl ; 
}else cout << s << endl;



return 0;
   
}

Measured memory_bytes: 3624
local n=io.read("n","l")
local s={}
for i=1,2 do
    s[i]={io.read():byte(1,n)}
end

local mod=1000000007
local combination
local i
if s[1][1]==s[2][1] then
    combination=3
    i=2
else
    combination=6
    i=3
end
while i<=n do
    if s[1][i-1]~=s[2][i-1] and s[1][i]~=s[2][i] then
        combination=combination*3
        i=i+2
    elseif s[1][i-1]==s[2][i-1] and s[1][i]~=s[2][i] then
        combination=combination*2
        i=i+2
    else
        if s[1][i-1]==s[2][i-1] then
            combination=combination*2
        end
        i=i+1
    end
    combination=combination%mod
end
print(combination)

Measured memory_bytes: 2776
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int H, W;
    cin >> H >> W;

    vector<string> s(H);
    rep(i, H) cin >> s[i];
    
    rep(y, H) rep(x, W) {
        if (s[y][x] != '#') {
            continue;
        }
        bool ok =false;
        rep(i, 2) {
            int xx = x - 1 + 2 * i;
            int yy = y;
            if (0 <= xx && xx < W && 0 <= yy && yy < H) {
                if (s[yy][xx] == '#') {
                    ok = true;
                }
            }
        }
        rep(i, 2) {
            int xx = x;
            int yy = y - 1 + 2 * i;
            if (0 <= xx && xx < W && 0 <= yy && yy < H) {
                if (s[yy][xx] == '#') {
                    ok = true;
                }
            }
        }
        if (ok == false) {
            put("No");
            return 0;
        }
    }

    put("Yes");

    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	vector<int>v(N, 0);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (A[i] < A[j])v[i]++;
		}
	}
	vector<int>b(N, 0);
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < i; j++) {
			if (A[i] < A[j])b[i]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += ((K * b[i]) % MOD + (K * (K - 1) / 2) % MOD * v[i]) % MOD;
		ans %= MOD;
	}
	cout << ans;
}

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

int m;
int x[21], y[21];

int ans = 0;

void solve(int num, vector<int>& v, bitset<30> used) {
    if (num >= m) {
        //
        map<double, int> mp;
        int ret = 0;
        for (int i=0; i<m; i+=2) {
            for (int j=i+2; j<m; j+=2) {
                int a = (y[v[i]] - y[v[i+1]]) * (x[v[j]] - x[v[j+1]]);
                int b = (y[v[j]] - y[v[j+1]]) * (x[v[i]] - x[v[i+1]]);
                if (a == b) ret++;
            }
        }

        // for (int i=0; i<m; i+=2) {
        //     mp[(double)(y[i]-y[i+1])/(x[i]-x[i+1])]++;
        // }
        // int ret = 0;
        // for (auto & tmp : mp) {
        //     if (tmp.second >= 2) {
        //         ret += tmp.second * (tmp.second-1) / 2;
        //     }
        // }
        ans = max(ans, ret);
        return;
    }

    // 左橋から選ぶ
    int idx = 0;
    for (int i=0; i<m; ++i) {
        if (!used[i]) {
            v.push_back(i);
            used[i] = true;
            idx = i;
            break;
        }
    }

    for (int i=0; i<m; ++i) {
        if (!used[i]) {
            v.push_back(i);
            used[i] = true;
            solve(num+2, v, used);
            used[i] = false;
            v.pop_back();
        }
    }

    v.pop_back();
    used[idx] = false;
}

int main() {
    cin >> m;
    rep(i, m) cin >> x[i] >> y[i];

    vector<int> v;
    bitset<30> used;

    solve(0, v, used);

    cout << ans << endl;

}



Measured memory_bytes: 3160
using System;

namespace ITP1_9_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string W = Console.ReadLine();
            W = W.ToLower();
            int count = 0;

            while(true)
            {
                string[] str = Console.ReadLine().Split(' ');
                if (str[0] == "END_OF_TEXT")
                    break;

                for(int i = 0; i < str.GetLength(0); ++i)
                {
                    if (str[i].ToLower() == W)
                        count += 1;
                }
            }

            Console.WriteLine("{0}", count);
        }
    }
}

Measured memory_bytes: 5672
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        long minR,maxR;
        minR = (long)Math.pow(10,9)+1;
        maxR = -1;
        n = input.nextInt();
        long[] min = new long[n];
        long[] max = new long[n];
        long[] R = new long[n];
        for (int i = 0; i < n; i++){
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        }
        for (int i = n-1; i > -1; i--){
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        }
        long ans;
        ans = -(long)Math.pow(10,9)-1;
        for (int i = 0; i < n-1; i++){
            ans = Math.max(ans,max[i+1]-min[i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 107244
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

#define MAX 9

int main(void) {
	int M, D, answer = 0, i, j;
	cin >> M >> D;
	for (i = 2; i < D / 10; i++) {
		for (j = 2; j <= MAX; j++) {
			if (i * j <= M) {
				answer++;
			}
			else {
				break;
			}
		}
	}
	for (j = 2; j <= D - i * 10; j++) {
		if (i * j <= M) {
			answer++;
		}
		else {
			break;
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n;
    cin>>n;
    int arr[n+1];
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    int m;
    cin>>m;
    while(m--){
        int p,x;
        cin>>p>>x;
        int temp=sum;
        temp-=arr[p];
        temp+=x;
        cout << temp << endl;
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3660
N,*H=`dd`.split.map &:to_i
B=[0]*2**19
N.times{|i|j=k=r=H[i]
1while(r=[r,B[j]+H[N+i]].max;j&=j-1)>0
(B[k]=r;k+=k&-k)while B[k]&.<r}
p B.max

Measured memory_bytes: 57880
def readinput():
    n=int(input())
    arms=[]
    for _ in range(n):
        x,l=list(map(int,input().split()))
        arms.append([x,l])
    return n,arms

def main(n,arms):
    count=0
    i=0
    j=i+1
    while(j<n):
        l=arms[i][0]+arms[i][1]
        r=arms[j][0]-arms[j][1]
        if l<=r:
            i=j
            j=i+1
        else:
            if arms[i][1]<=arms[j][1]:
                j=j+1
                count+=1
                print('{}, {}: remove {}'.format(i,j,j))
            else:
                i=j
                j=i+1
                count+=1
                print('{}, {}: remove {}'.format(i,j,i))
    return n-count

def main2(n,arms):
    for arm in arms:
        l=arm[0]-arm[1]
        r=arm[0]+arm[1]
        arm.append(l)
        arm.append(r)
    arms.sort(key=lambda x:x[3])
    count=1
    llim=arms[0][3]
    for i in range(1,n):
        if llim<=arms[i][2]:
            count+=1
            llim=arms[i][3]
    return count

if __name__=='__main__':
    n,arms=readinput()
    ans=main2(n,arms)
    print(ans)


Measured memory_bytes: 35008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String N;
	while (!(N = br.readLine()).equals("0")) {
	    int n = Integer.parseInt(N);
	    int[][] map = new int[21][21];
	    for (int i = 0; i < n; i++) {
		String[] s = br.readLine().split(" ");
		map[Integer.parseInt(s[0])][Integer.parseInt(s[1])] = 1;

	    }
	    int m = Integer.parseInt(br.readLine());
	    int x = 10;
	    int y = 10;
	    int count = 0;
	    for (int i = 0; i < m; i++) {
		if (count != n) {
		    String[] s = br.readLine().split(" ");
		    char c = s[0].charAt(0);
		    int l = Integer.parseInt(s[1]);
		    int dx = 0;
		    int dy = 0;
		    if (c == 'N') {
			dy = 1;
		    } else if (c == 'E') {
			dx = 1;
		    } else if (c == 'S') {
			dy = -1;
		    } else if (c == 'W') {
			dx = -1;
		    }
		    for (int j = 0; j < l; j++) {
			count += map[x][y];
			map[x][y] = 0;
			x += dx;
			y += dy;
		    }
		    count += map[x][y];
		    map[x][y] = 0;
		} else {
		    br.readLine();
		}
	    }
	    if (count == n) {
		System.out.println("Yes");
	    } else {
		System.out.println("No");
	    }
	}
    }
}

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

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

    //cout << n;

    vector<long long> a;
    long long k = 0;
    for(long long i = 0; i <= n; i++){
        cin >> k;
        a.push_back(k);
    }

    vector<long long> b;
    for(long long i = 0; i < n; i++){
        cin >> k;
        b.push_back(k);
    }

    

    long long cou = 0;
    long long cou_2 = 0;
    for(long long i = 0; i < n; i++){

        if(b[i] >= (a[i] + a[i + 1])){
            cou += a[i] + a[i + 1];
            a[i + 1] = 0;
            //cout<< "ze " << cou << endl; 
        }else if(b[i] < a[i] + a[i + 1] && b[i] >= a[i]){
            cou += b[i];
            a[i + 1] -= b[i] - a[i];
            //cout << "to" << cou << endl;
        }else{
            cou += b[i];
            //cout << cou<< endl;
        }
        //cout << cou << endl;
    }

    for(long long i = n; i >= 1; i--){
        if(b[i - 1] >= (a[i] + a[i - 1])){
            cou_2 += a[i] + a[i - 1];
            a[i - 1] = 0;
            //cout<< "ze " << cou << endl; 
        }else if(b[i - 1] < a[i] + a[i - 1] && b[i - 1] >= a[i]){
            cou_2 += b[i - 1];
            a[i - 1] -= b[i - 1] - a[i];
            //cout << "to" << cou << endl;
        }else{
            cou_2 += b[i - 1];
            //cout << cou<< endl;
        }
        //cout << cou << endl;
    }

    if(cou >= cou_2){
        cout << cou << endl;
    }else{
        cout << cou_2 << endl;
    }
}

Measured memory_bytes: 2548
num = int(7)

ipt = input()
ipt = int(ipt)

res = 1
ok = False
while res < 1000000:
    if num % ipt==0:
        print(res)
        ok = True
        break
    else:
        num = num % ipt
        res = res + 1
        num = num*10 +7

if ok == False:
    print(-1)



Measured memory_bytes: 9176
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<cassert>

using namespace std;

typedef long long ll;

typedef pair<int,pair<pair<int,int>,int>> P;

int di[]={0,-1,0,1};
int dj[]={1,0,-1,0};

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

	static ll dp[3010][3010];

	for(int i=0;i<n;i++)
		dp[i][i]=a[i]*(n%2==0?-1:1);

	for(int r=2;r<=n;r++)
		for(int i=0;i+r-1<n;i++)
		{
			int j=i+r-1;
			if((n-(j-i+1))%2)
			{
				//JIRO
				dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);
			}
			else
			{
				//TARO
				dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]);
			}
		}

	cout<<dp[0][n-1]<<endl;

	return 0;
}


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

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

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

unsigned long long int factorial(unsigned long long int n) {
    if(n == 0) {
        return 1;
    }
    return (n * factorial(n-1)) % 1000000007;
}

int main() {
    int N, M;
    cin >> N >> M;
    if(abs(N-M) > 1) {
        cout << 0 << endl;
        return 0;
    }
    if(N-M == 0) {
        cout <<
        (((factorial(N) * factorial(M)) % 1000000007) * 2)
        % 1000000007
        << endl;
    }
    else {
        cout << (factorial(N) * factorial(M)) % 1000000007 << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
#include<iomanip>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
 
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define so(v) sort(v.begin(),v.end())
#define re(s) reverse(s.begin(),s.end())
#define lb(v,a) lower_bound(v.begin(),v.end(),a)
#define ub(v,a) upper_bound(v.begin(),v.end(),a)
#define mp1(a,b,c) piii(a,pii(b,c))
 
const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const ll mod=1e9+7;

int main(){

  int n,l[1000],ans=0;

  cin>>n;
  rep(i,2*n) cin>>l[i];
  sort(l,l+2*n);
  rep(i,2*n){
    ans+=l[i];
    i++;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define sz(x) ((int) (x).size())
#define X first
#define Y second

const int bits = 28;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    int ans = 0;
    if (n & 1) {
        for (int i = 0; i < n; ++i) {
            ans ^= a[i] ^ b[i];
        }
    }
    for (int k = bits - 1; k >= 0; --k) {
        for (int i = 0; i < n; ++i) {
            if (a[i] & (1 << (k + 1))) a[i] ^= 1 << (k + 1);
            if (b[i] & (1 << (k + 1))) b[i] ^= 1 << (k + 1);
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        int p = n - 1;
        int kek = 0;
        for (int i = 0; i < n; ++i) {
            while (p >= 0 && a[i] + b[p] >= (1 << (k + 1))) --p;
            if ((n - 1 - p) & 1) kek ^= 1;
        }
        if (kek) ans ^= 1 << (k + 1);
    }
    cout << ans << '\n';
	  
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int N,K;
vector<int> Graph[110000];
vector<int> Depth[110000];
vector<int> Deep(110000);
vector<int> Parent(110000);
vector<int> child[110000];
vector<int> cnt(110000);
int root;
void BFS() {
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(make_pair(0,root));
  Depth[0].push_back(root);
  Deep[root] = 0;
  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    for (int i = 0; i < (int)Graph[p.S].size(); i++) {
      if (Deep[Graph[p.S][i]] > p.F + 1) {
        Q.push(make_pair(p.F+1,Graph[p.S][i]));
        Deep[Graph[p.S][i]] = p.F + 1;
        Depth[p.F+1].push_back(Graph[p.S][i]);
        Parent[Graph[p.S][i]] = p.S;
        child[p.S].push_back(Graph[p.S][i]);
      }
    }
  }
}
int main() {
  cin >> N >> K;
  ll ans = (ll)K;
  for (int i = 0; i < N-1; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }
  for (int i = 0; i < N; i++) Deep[i] = 99999999;
  for (int i = 0; i < N; i++) {
    if ((int)Graph[i].size() == 1) {
      root = i;
      break;
    }
  }

  BFS();

  for (int i = 1; i < N; i++) {
    for (int j = 0; j < (int)Depth[i].size(); j++) {
      int s = Depth[i][j];
      ll l;
      if (i == 1) {
        l = K - 1 - cnt[Parent[s]];
        cnt[Parent[s]]++;
      } else {
        l = K - 2 - cnt[Parent[s]];
        cnt[Parent[s]]++;
      }
      ans *= l;
      ans %= Mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 21732
#include <stdio.h>
#define MAX 100005
#define NIL -1

struct Node {
	int p , r , l;
};

struct Node T[MAX];
int D[MAX];

void print(int u){
	int i , c;
	printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);
	
	if( T[u].p == NIL){
		printf("root, ");
	}else if(T[u].l == NIL){
			printf("leaf, ");
		}else{
			printf("internal node, ");
		}
	
	printf("[");
	
	for( i = 0, c = T[u].l; c != NIL; i++ , c = T[c].r){
		if(i)printf(", ");
		printf("%d",c);
	}
	printf("]\n");
}

int rec( int u , int p){
	D[u] = p;
	if(T[u].r != NIL) rec(T[u].r,p);
	if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void){
	int n ,i , j , d , v , c , l , r;
	scanf("%d",&n);
	for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
	
	for( i = 0; i < n; i++){
		scanf("%d %d",&v,&d);
		for( j = 0; j < d; j++){
			scanf("%d",&c);
			if( j == 0){
				T[v].l = c;
			}else {
				T[l].r = c;
			}
			l = c;
			T[c].p = v;
		}
	}
	
	for( i= 0; i < n; i++){
		if(T[i].p == NIL) r = i;
	}
	
	rec(r,0);
	for( i = 0; i < n; i++) print(i);
	
	return 0;
}



Measured memory_bytes: 6420
import sys
sin = sys.stdin.readlines()
N, M, Q = map(int, sin[0].split())

LR = [[0 for _ in range(N+2-i)] for i in range(N+2)]
for line in sin[1:M+1]:
  L, R = map(int, line.split())
  LR[L][R-L+1] += 1

for i in range(2,N+2):
  for j in range(1,N-i+2):
    LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2]
 
A = []
for line in sin[M+1:]:
  p, q = map(int, line.split())
  A.append(LR[p][q-p+1])

print("\n".join(map(str,A)))


Measured memory_bytes: 36260
using System;
using System.Linq;

class AtCoderCS {
    static void Main(string[] args) {
        int[] ABHM = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        int A = ABHM[0], B = ABHM[1], H = ABHM[2], M = ABHM[3];
        double rad = 2.0 * Math.PI * Math.Abs(H / 12.0 + M / 12.0 / 60.0 - M / 60.0);

        Console.WriteLine(Math.Sqrt(A * A + B * B - 2 * A * B * Math.Cos(rad)));
    }
}

Measured memory_bytes: 28748
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,a,b;
  std::cin>>n>>a>>b;
  ll ans=0;
  ll now,next;
  std::cin>>now;
  rep(i,1,n){
    std::cin>>next;
    if((next-now)*a>=b)ans+=b;
    else ans+=(next-now)*a;

    now=next;
  }

  std::cout<<ans;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

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

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		N = Integer.parseInt(W);


		A = new long[2][N];

		for(int k=0;k<2;k++){
			W = in.readLine();
			String[] Ws = W.split(" ");

			for (int i = 0; i < Ws.length; i++) {

				A[k][i] = Long.parseLong(Ws[i]);
			}
		}

		System.out.println(calc(0,0,0));

	}

	public static long calc(int i,int j,long sum){
		if(i==1 && j==N-1){
			return sum+A[i][j];
		}
		if(i==1){
			return calc(i,j+1,sum+A[i][j]);
		}else if(j==N-1){
			return calc(i+1,j,sum+A[i][j]);
		}else{
			return Math.max(calc(i+1,j,sum+A[i][j]), calc(i,j+1,sum+A[i][j]));
		}
	}

}


Measured memory_bytes: 22868