akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int MAXN = 505;
int n, c;
int d[MAXN][MAXN], a[MAXN][MAXN];

int freq[3][MAXN];

ll score(int idx, int dest) {
    ll res = 0LL;
    for (int cc = 1; cc <= c; ++cc) {
        res += 1LL * freq[idx][cc] * d[cc][dest];
    }

    return res;
}

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

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

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf(" %d", &a[i][j]);
            ++freq[(i + j) % 3][a[i][j]];
        }
    }

    ll best = 1e18;

    for (int c1 = 1; c1 <= c; ++c1) {
        ll cur_first = score(0, c1);
        if (cur_first > best) continue;
        for (int c2 = 1; c2 <= c; ++c2) {
            if (c1 == c2) continue;

            ll cur_second = cur_first + score(1, c2);
            if (cur_second > best) continue;

            for (int c3 = 1; c3 <= c; ++c3) {
                if (c1 == c3 or c2 == c3) continue;
                best = min(best, cur_second + score(2, c3));
            }
        }
    }

    printf("%lld\n", best);

    return 0;
}


Measured memory_bytes: 1280
s = input()
flag = 1

if s.find("AA") != -1:
  flag = 0
if s.find("KA") != -1:
  flag = 0
if s.find("IA") != -1:
  flag = 0

if s.replace("A","") != "KIHBR":
  flag = 0
  
if flag == 1:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 38384
// Tazoe

#include <iostream>
using namespace std;

int main()
{
	// 入力
	int t1, t2, t3, t4;
	cin >> t1;
	cin >> t2;
	cin >> t3;
	cin >> t4;

	// 演算
	int t = t1+t2+t3+t4;
	int x = t/60;
	int y = t%60;

	// 出力
	cout << x << '\n';
	cout << y << '\n';

	return 0;
}

Measured memory_bytes: 0
def solve():
    MOD = 10**9 + 7

    N, M = map(int, input().split())
    Ss = list(map(int, input().split()))
    Ts = list(map(int, input().split()))

    dp = [[0]*(M+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 1
    for j in range(M+1):
        dp[0][j] = 1

    for i, S in enumerate(Ss, start=1):
        for j, T in enumerate(Ts, start=1):
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
            if S == T:
                dp[i][j] += dp[i-1][j-1]
            dp[i][j] %= MOD

    print(dp[N][M])


solve()


Measured memory_bytes: 72540
import sys
input = sys.stdin.readline
INF = 10**11
A,B,Q = map(int,input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
def binary_search(lis,x):
    ok = 0
    ng = len(lis)-1
    while ng-ok > 1:
        mid = (ok+ng)//2
        if lis[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
#print(s,t)
for _ in range(Q):
    x = int(input())
    ps = binary_search(s,x)
    pt = binary_search(t,x)
    ans = INF
    #print(ps,pt)
    for i in range(ps,ps+2):
        for j in range(pt,pt+2):
            ans = min(ans,abs(s[i]-x)+abs(s[i]-t[j]), abs(t[j]-x)+abs(t[j]-s[i]))
    print(ans)  
            


Measured memory_bytes: 82904
#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;

char s[30];
string minS[100]; // 最初の10こ
string maxS[100]; // 最後の10こ
int counter;

int dfs(char c) {
  //printf("%c\n",c);
  if (c < 'a') {
    int num = (counter + 80) % 90 + 10;
    if (counter < 10) num = counter;
    minS[num] = maxS[99 - num] = s;
    if (counter >= 99 && counter % 90 == 9) {
      sort(minS, minS + 100);
      sort(maxS, maxS + 100);
    }
    counter++;
    return 1;
  }
  int ans = 0;
  for (int i = 0; s[i] != 0; i++) {
    if (s[i] == c + 1) return ans;
    if (s[i] == c) {
      s[i] = c + 1;
      ans += dfs(c - 1);
      s[i] = c;
    }
  }
  return ans + dfs(c - 1);
}

int main() {
  while (1) {
    scanf("%s", s);
    if (s[0] == '#') break;
    counter = 0;
    printf("%d\n", dfs('y'));
    if (counter <= 10) {
      sort(minS, minS + counter);
      sort(maxS, maxS + counter);
      for (int i = 0; i < counter; i++) cout << minS[i] << "\n";
    } else if (counter <= 100) {
      sort(minS, minS + counter);
      sort(maxS + 100 - counter, maxS + 100);
      for (int i = 0; i < 5; i++) cout << minS[i] << "\n";
      for (int i = 95; i < 100; i++) cout << maxS[i] << "\n";
    } else {
      sort(minS, minS + 100);
      sort(maxS, maxS + 100);
      for (int i = 0; i < 5; i++) cout << minS[i] << "\n";
      for (int i = 95; i < 100; i++) cout << maxS[i] << "\n";
    }
  }
}



Measured memory_bytes: 3312
#include <stdio.h>
#include <string.h>

int page_length;
int dan_num;
int onedan_width;
int space_width;
char line_buffer[2000];

char buffer[100][100];
int buffer_x,buffer_y;
int buffer_pos;
int did_flush_buffer;
int did_new_line;

void buffer_init(void) {
	int i,j,length;
	buffer_x=0;
	buffer_y=0;
	buffer_pos=0;
	memset(buffer,0,sizeof(buffer));
	length=onedan_width*dan_num+space_width*(dan_num-1);
	for(i=0;i<page_length;i++) {
		for(j=0;j<length;j++) {
			buffer[i][j]='.';
		}
	}
	did_flush_buffer=1;
	did_new_line=0;
}

void flush_buffer(void) {
	int i;
	if(!did_flush_buffer) {
		for(i=0;i<page_length;i++)puts(buffer[i]);
		puts("#");
	} else {did_flush_buffer=0;return;}
	buffer_init();
}

void new_line(void) {
	if(did_new_line){did_new_line=0;return;}
	buffer_pos=0;
	buffer_y++;
	if(buffer_y>=page_length) {
		buffer_y=0;
		buffer_x++;
		if(buffer_x>=dan_num) {
			flush_buffer();
			did_flush_buffer=1;
		}
	}
}

void insert_one_char(char c) {
	did_new_line=0;
	did_flush_buffer=0;
	buffer[buffer_y]
		[(onedan_width+space_width)*buffer_x+buffer_pos]=c;
	buffer_pos++;
	if(buffer_pos>=onedan_width) {
		new_line();
		did_new_line=1;
	}
}

int main(void) {
	char* cptr;
	while(1) {
		scanf("%d",&page_length);
		if(page_length==0)break;
		scanf("%d",&dan_num);
		scanf("%d",&onedan_width);
		scanf("%d",&space_width);
		buffer_init();
		fgets(line_buffer,sizeof(line_buffer),stdin);
		while(1) {
			fgets(line_buffer,sizeof(line_buffer),stdin);
			cptr=strchr(line_buffer,'\n');
			if(cptr)*cptr=0;
			if(line_buffer[0]=='?' && line_buffer[1]==0)break;
			for(cptr=line_buffer;*cptr;cptr++)insert_one_char(*cptr);
			new_line();
		}
		flush_buffer();
		puts("?");
	}
	return 0;
}

Measured memory_bytes: 0
H,W = map(int,input().split())
A = [input() for i in range(H)]
from collections import Counter
ctr = Counter()
for row in A:
    ctr.update(row)

if H%2==0 and W%2==0:
    print('Yes' if all(v%4==0 for v in ctr.values()) else 'No')
    exit()

odd = len([1 for v in ctr.values() if v%2])
pair = len([1 for v in ctr.values() if (v//2)%2==1])
if H%2 and W%2:
    if odd != 1:
        print('No')
    else:
        print('Yes' if pair <= H//2 + W//2 else 'No')
else:
    if odd:
        print('No')
    else:
        if H%2: H,W = W,H
        assert W%2
        print('Yes' if pair <= H//2 else 'No')

Measured memory_bytes: 9432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

ll Size;
int n;
int tt[100010];
int tsp[100010];
int tlp[100010];
int trp[100010];

tuple<ll,ll,ll> conv(ll s, ll l, ll r, ll diff, ll houkou){
	if(houkou == 1){
		if(s+r-l + diff > Size){
			r = max(l, r - (s+r-l+diff-Size));
		}
		s = min(Size, s + diff);
	} else {
		// go down
		if(s - diff < 0){
			l = min(r, l + (diff-s));
		}
		s = max(0LL, s - diff);
	}
	return make_tuple(s, l, r);
}

void Build(){
	ll s=0, l=0, r=Size;
	trp[0]=Size;
	for(int i=1; i<=n; ++i){
		int diff = tt[i] - tt[i-1];
		if(i%2 == 0){
			tie(s, l, r) = conv(s, l, r, diff, 1);
		} else {
			tie(s, l, r) = conv(s, l, r, diff, -1);
		}
		tsp[i] = s;
		tlp[i] = l;
		trp[i] = r;
	}
}

int main()
{
	read(Size, n);
	for(int i=1; i<=n; ++i) read(tt[i]);
	
	Build();
	
	int q; read(q);
	for(;q--;){
		int qt, qa;
		read(qt, qa);
		int last_time = upper_bound(tt+1, tt+n+1, qt) - tt - 1;
		ll s = tsp[last_time];
		ll l = tlp[last_time];
		ll r = trp[last_time];
		tie(s, l, r) = conv(s, l, r, qt-tt[last_time], 2*(last_time%2)-1);
		if(l<=qa && qa<=r){
			printf("%lld\n", s + (qa-l));
		} else if(qa <= l){
			printf("%lld\n", s);
		} else {
			printf("%lld\n", s+r-l);
		}
	}
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std ; 
#define ll              long long int
// #define cini(x)	        scanf("%lld",&x)
// #define cins(s)	        scanf("%s",s)
#define deb(x)          cout << (x) << "  " ;
#define out(x)          cout << (x) << endl ;
#define endl            '\n'
#define pb              push_back
#define mk              make_pair
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(x,n,v)     for(ll v=x; v<n; v++)
#define loopr(n,x,v)     for(ll v=n-1; v>=x; v--)
#define mod             1000000007
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define PI              3.1415926535897932384626
#define setbits(x)      __builtin_popcount(x)
#define zrobits(x)      __builtin_ctz(x)
#define ps(x,y)         fixed << setprecision(y) << (x)
#define w(t)            int t; cin>>t; while(t--) 
#define     vi          vector<ll>
#define     vtt         vector<pair<ll,ll>> 
#define     pii         pair<ll,ll> 
#define  mapp           map<ll,ll> 
#define  sett           set<ll>
// int dp[1000][1000] ;
ll mpow(ll base, ll exp); 
// =================================
// =================================





int main(){
    fastio ;
    // w(t)
    // {
        ll a=0, b=0, c=0, d=0, e=0, p=0, q=0, r=0 ;
        ll ans=0, res=0, cnt=0, sum=0, diff=0, mul=1, val=0, k=0 ;
        // loop(0,n,i) brr[i]=0;
        // char s[100005];
        string s ;
        ll n,m ;
        cin >> n ;
        cin >> m ;
        // cin >> s ;
        ll arr[n+1];
        bool brr[m+1]; 
        loop(0,m+1,i)   brr[i]=0;
        loop(0,n,i) cin >> arr[i] ;
        sort(arr,arr+n);
        loop(1,m+1,i){
            loop(0,n,j){
                // if(i-arr[j] == 0)   brr[i]=1;
                if(i-arr[j] >= 0)   brr[i]=brr[i] || (!brr[i-arr[j]]);
            }
        }
        if(brr[m])      out("First")
        else  out("Second")
    // }
    return 0 ;
}

// g++ x.cpp -o as && ./as

Measured memory_bytes: 3716
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        String s = scan.next();
        int a = 0;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) != s.charAt(s.length() - 1 - i)){
                a++;
            }
        }
        a = a / 2;
        System.out.println(a);
    }
}

Measured memory_bytes: 23764
n=int(input())
a=list(map(int,input().split()))
ans1=0
ans2=0
flg=True
t=0
for i in range(n):
    t+=a[i]
    if flg:
        if t<=0:
            ans1+=1-t
            t=1
        flg=False
    else:
        if t>=0:
            ans1+=t+1
            t=-1
        flg=True
t=0
flg=True
for i in range(n):
    t+=a[i]
    if flg==False:
        if t<=0:
            ans2+=1-t
            t=1
        flg=True
    else:
        if t>=0:
            ans2+=t+1
            t=-1
        flg=False
print(min(ans1,ans2))

Measured memory_bytes: 85556
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r, n;
	cin >> n;
	map<int, int> m;
	m[1] = 0;
	for(int i = 2; i <= n; i++)
	{
		cin >> r;
		m[r]++;
	}
	for(int i = 1; i <= n; i++)
		cout << m[i] << "\n";
	return 0;
}

Measured memory_bytes: 12952
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;int main(){int a,b,x;cin >> a >> b >>x;if(a>x){cout<<"NO"<<endl;}else if(a+b<x){cout<<"NO"<<endl;}else{cout<<"YES"<<endl;}}
   

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int a,b,c,n,m;
    cin>>a>>b>>c;
    int ans=min(abs(a-b)+abs(b-c),min(abs(a-c)+abs(c-b),min(abs(b-c)+abs(c-a),min(abs(a-b)+abs(c-a),min(abs(c-a)+abs(a-b),abs(b-c)+abs(a-b))))));
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> A(n);
    map<int, int> M;
    rep(i, n) {
        cin >> A[i];
        ++M[A[i]];
    }

    sort(all(A));

    int maxA = A[n - 1];
    vector<bool> check_table(maxA + 1, false);
    int k;
    rep(i, n) {
        k = 2;
        while (A[i]*k <= maxA) {
            check_table[A[i]*k] = true;
            ++k;
        }
    }

    // A.erase(unique(all(A)), A.end());
    int ans = 0;
    rep(i, (int)A.size()) {
        if (! check_table[A[i]] && M[A[i]] == 1) ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13544
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

public class Program
{
    public static void Main(string[] args)
    {
        new Program().Solve(new ConsoleInput(Console.In, ' '));
    }

    public void Solve(ConsoleInput cin)
    {
        var n = cin.ReadStrArray(2);
        var s = n[0];
        var t = n[1];
        var nn = cin.ReadIntArray(2);
        var a = nn[0];
        var b = nn[1];
        var u = cin.ReadLine;

        if (s == u)
        {
            a--;
        }
        else
        {
            b--;
        }

        Write(a);
        Write(" ");
        WriteLine(b);
        ReadKey();
    }
}

public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

Measured memory_bytes: 13268
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

ll n,k,a,b; 
ll arr[100009];
ll m[100009];

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(m, 0, sizeof m);
	cin>>n;

	ll sum = 0;
	for(int i =0; i < n; i++){
		cin>>arr[i];
		m[arr[i]] += 1;
		sum += arr[i];
	}
	
	cin>>k;
	while(k--) {

		cin>>a>>b;
		ll cnt = m[a];

		sum -= (cnt * a);
		sum += (cnt * b);

		m[a] -= cnt;
		m[b] += cnt;

		cout<<sum<<endl;

	}
	return 0;
}

Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int n;
  cin >> n;
  int p[n];
  rep(i, 0, n) cin >> p[i];

  int rsl = 0;
  rep(i, 0, n - 2) {
      if(p[i] < p[i + 1] && p[i + 1] < p[i + 2]) rsl++;
      if(p[i] > p[i + 1] && p[i + 1] > p[i + 2]) rsl++;
  }
  cout << rsl << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long l = sc.nextLong();
        long r = sc.nextLong();
        long min = (n - 1) * l + r;
        long max = (n - 1) * r + l;
        long ans = max - min + 1;
        if(ans < 0){
            ans = (long)0;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23508
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int n;
	while (n = readln.chomp.to!int, n) {
		int a, b;
		foreach (i; 0..n) {
			auto x = readln.split.map!(to!int);
			if (x[0]>x[1]) {
				a += x[0]+x[1];
			} else if (x[0]<x[1]) {
				b += x[0]+x[1];
			} else {
				a += x[0];
				b += x[1];
			}
		}
		writeln(a, " ", b);
	}
}

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

namespace abc109_b
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, bool> dict = new Dictionary<string, bool>();
            int n = int.Parse(Console.ReadLine());
            string[] words = new string[100];
            bool success = true;

            words[0] = Console.ReadLine();
            dict[words[0]] = true;

            for(int i = 1; i < n; ++i)
            {
                words[i] = Console.ReadLine();

                if(dict.ContainsKey(words[i]))
                {
                    success = false; 
                }

                if(words[i][0] != words[i - 1][words[i - 1].Length - 1])
                {
                    success = false;
                }

                dict[words[i]] = true;
            }

            if(success)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13152
// Aizu Vol0 0028: Mode Value
// 2017.7.28

#include <stdio.h>

#define MAX 100

int main()
{
	short freq[MAX + 1];
	int a, max, lim;

	for (a = 1; a <= MAX; a++) freq[a] = 0;
	max = lim = 0;
	while (scanf("%d", &a) == 1) {
		if (a > lim) lim = a;
		if (++freq[a] > max) max++;
	}
	for (a = 1; a <= lim; a++) {
		if (freq[a] == max) printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int N;
int a[212345], b[212345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", a + i);
	REP(i, N) scanf("%d", b + i);

	int ans = 0;
	for (int k = 28; k >= 0; k--) {
		ll cnt = 0;
		sort(b, b + N);
		REP(i, N) cnt += lower_bound(b, b+N, (1<<(k+1)) - a[i]) - lower_bound(b, b+N, (1<<k) - a[i]);
		REP(i, N) cnt += lower_bound(b, b+N, (1<<(k+2)) - a[i]) - lower_bound(b, b+N, (1<<(k+1))+(1<<k) - a[i]);
		REP(i, N) if (a[i] >= 1<<k) a[i] -= 1<<k;
		REP(i, N) if (b[i] >= 1<<k) b[i] -= 1<<k;
		
		ans |= (cnt&1)<<k;
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int v[4252];
int reva[2521], revb[2521];

int cnta[4004][2004], cntb[4004][2004]; // [i,j] := before i, count val <= j
int dp[2002][2002];

int main(){
  scanf("%d",&n);
  REP(i,2*n){
    char buf[4];
    int x;
    scanf("%s%d",buf,&x);
    if(buf[0]=='B'){
      v[i] = x;
      reva[x] = i;
    }else{
      v[i] = -x;
      revb[x] = i;
    }
  }
  FOR(j,1,n+1)REP(i,2*n+1){
    cnta[i+1][j] = cnta[i][j] + (int)(v[i]>0 && v[i]<=j);
    cntb[i+1][j] = cntb[i][j] + (int)(v[i]<0 && v[i]>=-j);
  }
  REP(i,n+1)REP(j,n+1)dp[i][j] = 25252521;
  dp[0][0] = 0;
  REP(i,n+1)REP(j,n+1){
    if(i<n){
      int pos = reva[i+1];
      int cnt = cnta[pos][n] - cnta[pos][i] + cntb[pos][n] - cntb[pos][j];
      CHMIN(dp[i+1][j], dp[i][j] + cnt);
    }
    if(j<n){
      int pos = revb[j+1];
      int cnt = cnta[pos][n] - cnta[pos][i] + cntb[pos][n] - cntb[pos][j];
      CHMIN(dp[i][j+1], dp[i][j] + cnt);
    }
  }
  printf("%d\n",dp[n][n]);
  return 0;
}


Measured memory_bytes: 78592
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    cout << "ABC" << str << "\n";


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string>

using namespace std;

int N, E, W, S;
string str;

int main(){
	cin>>str;
	for(int i=0; i<str.size(); i++){
		if(str[i]=='N') N++;
		else if(str[i]=='E') E++;
		else if(str[i]=='W') W++;
		else 	S++;
	}
	if(N!=0 || S!=0){
		if(N==0 || S==0){
			printf("No");
			return 0;
		}
	}
	if(E!=0 || W!=0){
		if(E==0||W==0){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static ConsoleApplication.Utils;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var nt = ReadInts();
            var a = ReadInts();
            var lst = new List<int>();
            var min = int.MaxValue;
            foreach (var i in a)
            {
                if (min > i) min = i;
                lst.Add(i - min);
            }
            var res = lst.GroupBy(i => i).Max(g => g.Key).Count();
            WriteLine(res);
        }
    }

    public static class Utils
    {
        #region Extensions for IO

        public static long ReadLong()
            => ReadLine().ToLong();
        public static int ReadInt()
            => ReadLine().ToInt();

        public static IEnumerable<int> ReadInts()
            => ReadStrings().Select(int.Parse);

        public static IEnumerable<string> ReadStrings()
            => ReadLine().Split(' ');

        public static IEnumerable<string> ReadLines(int n)
        {
            foreach (var i in Enumerable.Range(0, n))
            {
                yield return ReadLine();
            }
        }

        #endregion

        #region Extensions of int

        public static bool IsOdd(this int n)
            => !n.IsEven();

        public static bool IsEven(this int n)
            => n % 2 == 0;

        public static bool CanDivideWith(this int n, int divisor)
            => n % divisor == 0;

        #endregion

        #region Extensions of string

        public static int ToInt(this string str)
            => int.Parse(str);

        public static long ToLong(this string str)
            => long.Parse(str);

        public static double ToDouble(this string str)
            => double.Parse(str);

        public static bool IsNullOrEmpty(this string str)
            => string.IsNullOrEmpty(str);

        #endregion

        public static TSource Max<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
            where TKey : IComparable
        {
            var max = source.First();
            foreach (var item in source)
            {
                if (keySelector(max).CompareTo(keySelector(item)) < 0) max = item;
            }
            return max;
        }

        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
        }

        public static IEnumerable<T> Peek<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
            return source;
        }
    }
}


Measured memory_bytes: 36128
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                        
using namespace std;
                        
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                        
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define prev prev228
#define list list228
#define complex complex228

const int N = 100 * 1000 + 228;

int n;
int a[N];

struct node
{
	int mx;
	int l, r;
	node() {
		mx = l = r = 0;
	}
};

vector< node > d;

void build(int l, int r, int v = 1) {
	d[v].l = l;
	d[v].r = r;
	if (l == r) return;
	int m = (l + r) >> 1;
	build(l, m, v << 1);
	build(m + 1, r, v << 1 | 1);
}

void init() {
	int ss = 1;
	while (ss < n) ss <<= 1;
	ss <<= 1;
	d.resize(ss + 3, node());
	build(1, n);
}

void update(int i, int x, int v = 1) {
	if (d[v].l == d[v].r) uax(d[v].mx, x);
	else {
		int m = (d[v].l + d[v].r) >> 1;
		if (i <= m) update(i, x, v << 1);
		else update(i, x, v << 1 | 1);
		d[v].mx = max(d[v << 1].mx, d[v << 1 | 1].mx);
	}
}

int get(int l, int r, int v = 1) {
	if (l > r || d[v].l > r || d[v].r < l) return 0;
	if (l <= d[v].l && d[v].r <= r) return d[v].mx;
	return max(get(l, r, v << 1), get(l, r, v << 1 | 1));
}

ghost main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	vector<int> crd;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		crd.push_back(a[i]);
	}
	sort(crd.begin(), crd.end());
	crd.erase(unique(crd.begin(), crd.end()), crd.end());
	for (int i = 1; i <= n; ++i) a[i] = lower_bound(crd.begin(), crd.end(), a[i]) - crd.begin() + 1;
	init();
	update(a[1], 1);
	int res = 1;
	for (int i = 2; i <= n; ++i) {
		int nup = get(a[i], n) + 1;
		update(a[i], nup);
		uax(res, nup);
	}
	cout << res << '\n';
	return 0;
} // kek ;
// Ого! Кажетсья это $#@!










Measured memory_bytes: 8052
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int N, M;
    cin >> N >> M;

    int rest = N - M;

    ll submitNum = pow(2, M);
    
    ll timeSum = (M * 1900 + rest * 100) * submitNum;

    p(timeSum);

    return 0;
}

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

using namespace std;

int h,w,n;

void solve(){
    int i,j;
    string str;
    cin >> h >> w >> n;
    long long ans = 0;
    if(h > w){
        ans = (n+h-1)/h;
    }
    else{
        ans = (n+w-1)/w;
    }
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
cnt=0
l=[]
for i in range(12):
    cnt+=26**i
    l.append(cnt)

n=int(input())
for i in range(12):
    if n>=l[i]:
        c=n-l[i]
        k=i+1

#print(c)

alp="abcdefghijklmnopqrstuvwxyz"
ans=""
for i in range(k):
    ans+=alp[c%26]
    c=c//26
    
print(ans[::-1])

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

#define nmax 20
#define kmax 10
#define smax 155

int C(int n, int k, int s) {
	int count = 0;
	if( k == 0 ) {
		if( s == 0 ) return 1;
		else return 0;
	}
	for(int i = 1; i <= n; i++) {
		count += C(i - 1, k - 1, s - i);
	}
	return count;
}
 
int main(void){
   // FILE* fp_in = freopen("data.txt", "r", stdin);

	while( 1 ) {
		int n, k, s;
		cin >> n >> k >> s;
		if( n == 0 && k == 0 && s == 0 ) break;
		cout << C(n,k,s) << endl;
	}


  // while(1){}
 
   return 0;
}

Measured memory_bytes: 1160
dishes = 5.times.map{gets.to_i}
amari = []

dishes.each do |i|
  i%10 == 0 ? amari.push(10) : amari.push(i%10)
end

ans = 0
last_index = amari.index(amari.min)
dishes.each.with_index do |i, index|
  if index == last_index
    ans += i
  else
    ans += ((i/10.0).ceil * 10).to_i
  end
end

puts ans


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  string s;
  int k;
  cin>>s>>k;
  int kmax=310;

  vector<int> a(s.length());
  int seg=0;
  rep_rev(j,s.length(),0){
    if(s[j]=='1') a[seg]++;
    else seg++;
  }
  seg++;

  vector<vector<vector<lint>>> dp(seg,
    vector<vector<lint>>(310,
      vector<lint>(kmax,0)
    )
  );
  dp[0][0][0]=1;
  int cmax=310;
  rep_range(i,1,seg){
    rep(c,cmax){
      rep(m,kmax){
        int dpi1cm=dp[i-1][c][m]%mod;
        if(dpi1cm==0) continue;
        rep_range(d,-c,a[i-1]+1){
          if(m+d>k) continue;
          dp[i][c+d][m+max(0,d)]+=dpi1cm;
        }
      }
    }
  }

  lint ans=0;
  rep(c,cmax)rep(m,kmax) ans+=dp[seg-1][c][m];
  return ans%mod;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 232848
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>

using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

vector<vector<ll>> dp;

combination table(2 * 100000 + 50);

signed main() {
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;
  ll p = table.C(n*m, 2);
  ll ans = 0;
  REP(i, m) {
    ll wl = n * n % mod * inverse(2) % mod * (m-i) % mod * (m-1-i) % mod;
    ans = (ans + wl) % mod;
  }
  REP(i, n) {
    ll hl = m * m % mod * inverse(2) % mod * (n-i) % mod * (n-1-i) % mod;
    ans = (ans + hl) % mod;
  }
  cout << ans * (table.C(n*m-2, k-2)) % mod << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n,k,ans =(1 << 30);cin >> n >> k;vector<int> h(n);
	rep(i, n) cin >> h[i];
	sort(h.begin(), h.end());
	rep(i, n - k + 1) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
a,b,c,d=map(int,input().split())
if a%d!=0:
    td=(a//d)+1
else:
    td=a//d
if c%b!=0:
    md=(c//b)+1
else:
    md=(c//d)
if td<md:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 61792
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <climits>
#include <algorithm>
using namespace std;
struct Node {
    Node() = default;
    Node(int h, int w) : h(h), w(w) {}
    int h = 0;
    int w = 0;
    bool operator==(const Node& rhs) {
        return h == rhs.h && w == rhs.w;
    }
};
int solve() {
	int H, W, black = 0;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; i++) {
        cin >> s[i];
        black += count(s[i].begin(), s[i].end(), '#');
    }
    Node current(0, 0), goal(H - 1, W - 1);
    vector<vector<int>> cost(H, vector<int>(W, INT_MAX));
    cost[0][0] = 1;
    int dh[4] = {1, -1, 0, 0}, dw[4] = {0, 0, 1, -1};
    queue<Node> q;
    q.push(current);
    while (!q.empty()) {
        current = q.front();
        q.pop();
        if (current == goal) return H * W - cost[current.h][current.w] - black;
        for (int i = 0; i < 4; i++) {
            int h = current.h + dh[i];
            int w = current.w + dw[i];
            if (0 <= h && h < H && 0 <= w && w < W && s[h][w] == '.' && cost[h][w] == INT_MAX) {
                q.push(Node(h, w));
                cost[h][w] = cost[current.h][current.w] + 1;
            }
        }
    }
    return -1;
}

int main() {
	cout << solve() << endl;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

toInts :: IO [Int]
toInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

solver :: String -> String
solver =
  (\x ->
     if [2, 2] == x
       then "Yes"
       else "No") .
  map length . group . sort

main :: IO ()
main = putStrLn . solver =<< getLine


Measured memory_bytes: 380
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1, n+1):
    x = a[i-1]
    for j in range(s+1):
        if dp[i-1][j]:
            dp[i][j] += dp[i-1][j] * 2
            dp[i][j] %= mod
        if j - x < 0:
            continue
        if dp[i-1][j-x]:
            dp[i][j] += dp[i-1][j-x]
            dp[i][j] %= mod
print(dp[-1][-1])


Measured memory_bytes: 145244
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

int diff(pint m, pint z) {
    return abs(m.first - z.first) + abs(m.second - z.second);
}

signed main(void) {
    int n, m; cin >> n >> m;
    vpint ab(n); vpin(ab);
    vpint cd(m); vpin(cd);

    rfor(p, ab) {
        int d = INT_MAX, pos;
        rep(i, m) {
            if(diff(p, cd[i]) < d) {
                pos = i + 1;
                d = diff(p, cd[i]);
            }
        }
        print(pos);
    }


    return 0;
}


Measured memory_bytes: 256
<?php
// Your code here!
$input = explode(" ",trim(fgets(STDIN)));
$min = $input[0];
$max = $input[1];
$count = 0;

for($i=$min;$i<=$max;$i++){//
    $judge = str_split($i);
    if($judge[0] == $judge[4] && $judge[1] == $judge[3]){
        $count++;
    }
}

echo $count;

?>













Measured memory_bytes: 3828
#include<iostream>
using namespace std;
#define INIFY 5000000

int main()
{
    int n,m;
    cin >> n >> m;
    int coin[21];
    int count[21][50001];
    for(int i=1;i<=m;i++)
    {
        cin >> coin[i];
    }
    int i,j;
    for(i=0;i<=m;i++)
       count[i][0]=0;
     for(j=1;j<=n;j++)
         count[0][j]=INIFY;
    for(i=1;i<=m;i++)
       for(j=1;j<=n;j++)
       {
           if(j-coin[i]<0)
             count[i][j]=count[i-1][j];
           else
             count[i][j]=min(1+count[i][j-coin[i]],count[i-1][j]);
       }
    cout << count[m][n] << endl;
    }


Measured memory_bytes: 7208
n = int(input())
songs = []
for _ in range(n):
    s, t = input().split()
    songs.append((s, int(t)))

x = input()
count = 0
counting = False
for i in range(n):
    if counting:
        count += songs[i][1]
    if songs[i][0] == x:
        counting = True
print(count)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
     vector<int> A(N);
     rep(i,N){
         int a;
         cin >> a;
         A[i] = --a;
     }
     vector<int> B(N),C(N-1);
     rep(i,N)cin >> B[i];
     rep(i,N-1)cin >> C[i];
     int ans = 0;
     int last = -5;
     rep(i,N){
         ans += B[A[i]];
         if(last+1==A[i])ans += C[A[i]-1];
         last = A[i];
     }
     cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, n, x;
  double ans;

  scanf("%d", &n);
  for(i=0, ans=0.0; i<n; ++i){
    scanf("%d", &x);
    ans += x;
  }
  ans /= (double)n;
  printf("%.0f\n", ans);
  return 0;
}

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

int main() {
	//input
	uintmax_t a, b, c;
	cin >> a >> b >> c;

	//calculation
	if (a + b >= c) {
		cout << "No" << endl;
		return 0;
	}

	uintmax_t ab4 = 4 * a * b;
	intmax_t cab_t = c - a - b;
	uintmax_t cab = cab_t * cab_t;


	//output
	if (ab4 < cab) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}


	return 0;
}


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

void fastInputOutput(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

ll GCD(ll a, ll b){ll gcd, g;g = __gcd(a, b);return g;}
ll LCM(ll a, ll b){ll gcd, g;g = __gcd(a, b);return (a/g)*b;}
ll PowFun(ll base, ll power){ll ans = 1;for(int i = 1; i <= power; i++){ans *= base;}return ans;}



const ll INF_LONG = 1LL<<61;
const unsigned int inf_int = 1<<31;
const ll mod = 1e9+7;
double phi = acos(-1);

void Solve()
{
    string a, b;
    cin >> a >> b;
    string p = "";
    for(int i = 0; i < b.size()-1; i++)
    {
        p += b[i];
    }
    if(a.compare(p) == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

int main()
{
    fastInputOutput();
    Solve();
    return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int A, B, C, D; scanf("%d%d%d%d", &A, &B, &C, &D);

  int ans = MIN(B, D) - MAX(A, C);
  printf("%d\n", ans > 0 ? ans : 0);
  return 0;
}


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

int main(){
  int A,B,C=0;
  string S;

  cin>>A>>B;

  for(int i=0;i<2;i++){
    if(A>=B){
      C+=A;
      A--;
    }
    else{
      C+=B;
      B--;
    }

  }

  cout<<C<<endl;
  
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = [list(input()) for _ in range(0, h)]

dx = [1, 1, 1, 0, 0, -1, -1, -1]
dy = [1, 0, -1, 1, -1, 1, 0, -1]

for i in range(0, h):
    for j in range(0, w):
        if s[i][j] != '.':
            continue

        cnt = 0
        for k in range(0, 8):
            ni = i + dy[k]
            nj = j + dx[k]

            if not (ni < 0 or h <= ni) and not (nj < 0 or w <= nj) and s[ni][nj] == '#':
                cnt += 1

        s[i][j] = str(cnt)

[print(''.join(s[ii])) for ii in range(0, h)]


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n; cin>>n;
  ll a[n];
  rep(i, n) a[i]=0;
  for(ll i=0; i<n-1; i++) {
    ll j; cin>>j;
    a[j-1]++;
  }
  for(ll i=0; i<n; i++) {
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 5212
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    num = int(input())
    data = list(map(int, input().split()))

    counnt = defaultdict(int)
    now_num = 0
    for i in range(num):
        now_num += data[i]
        counnt[now_num] += 1

    ans = 0
    sum_num = 0
    for i in range(num):
        ans += counnt[sum_num]
        sum_num += data[i]
        counnt[sum_num] -= 1

    print(ans)



if __name__ == '__main__':
    main()
    # test()


Measured memory_bytes: 111436
S = input()
if (S.count('N') > 0 and S.count('S') == 0) or (S.count('S') > 0 and S.count('N') == 0):
    print('No')
elif (S.count('E') > 0 and S.count('W') == 0) or (S.count('W') > 0 and S.count('E') == 0):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main(){
int a,b;
scanf("%d%d",&a,&b);
if(a%3==0||b%3==0||(a+b)%3==0)
	printf("Possible");
	else 
		printf("Impossible");

}

Measured memory_bytes: 128
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0];
const dy = [0,1,0,-1];
void read(T...)(auto ref T args){ 
	auto line = readln().split(); 
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
}
int sum(int n){return n * (n + 1)/ 2;}
int tax(int per,int yen) {return cast(int)(yen * (100 +per) / 100);}
void main(){
	int x,y,s;
	while(read(x,y,s),x|y|s){
		int max ;
		foreach(i;1..s){
			foreach(j;1..s){
				if (tax(x,i) + tax (x,j) == s ){
					int tax_y = tax(y,i) + tax(y,j);
					if (tax_y > max) max = tax_y;
				}	
			}
		}
		max.writeln;
	}
}

Measured memory_bytes: 2392
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int r; cin >> r;

    if(r < 1200) cout << "ABC" << endl;
    else if(r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;


}

Measured memory_bytes: 256