akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_origin = A[:]

if sum(A) < sum(B):
    print(-1)
    exit()

diff = [[i, a - b] for i, a, b in zip(range(N), A, B)]

order = sorted([[i, x] for i, x in diff if x > 0], key=lambda d: d[1])
C = []

charge = order.pop()
for i in range(N):
    while A[i] - B[i] < 0:
        if charge[1] > B[i] - A[i]:
            A[charge[0]] -= (B[i] - A[i])
            charge[1] -= (B[i] - A[i])
            A[i] = B[i]
        else:
            A[charge[0]] = B[charge[0]]
            A[i] += charge[1]
            charge = order.pop()

ans = 0
for a, ao in zip(A, A_origin):
    if a != ao:
        ans += 1

print(ans)


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

int main()
{
    int r;
    cin >> r;
    cout << 2*r * 3.141592 << endl;
    return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

int main() {
  string s;
  cin >> s;
  for (auto e : s) {
    if (e == '9') {
      puts("Yes");
      return 0;
    }
  }

  puts("No");

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[1000];
	for(int i=1;i<=2*n;i++)
	{
		cin>>a[i];
	} 
	sort(a+1,a+2*n+1);
	int s=0;
	for(int i=1;i<=2*n-1;i+=2)
	{
		s+=min(a[i],a[i+1]);
	}
	cout<<s<<endl;
 	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
	string firstStr = "First";
	string secondStr = "Second";
	
	string S;
	cin >> S;

	if (S[0] != S[S.size() - 1]) {
		cout << (S.size() % 2 ? firstStr : secondStr) << endl;
	} else {
		cout << (S.size() % 2 ? secondStr : firstStr) << endl;
	}

    return 0;
}


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

int main(){
    int q,x;
    string command;

    list<int> v;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> command;
        if(command == "insert"){
            cin >> x;
            v.push_front(x);
        }else if(command == "deleteFirst"){
            v.pop_front();
        }else if(command == "deleteLast"){
            v.pop_back();
        }else if(command == "delete"){
            cin >> x;
            for (list<int>::iterator it = v.begin(); it != v.end() ; it++) {
                if(*it == x){
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i = 0;
    for(auto itr = v.begin(); itr != v.end(); ++itr) {
        if ( i ++) cout << " ";
        cout << *itr;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 34256
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len([d for d in dist[i] if d > K / 2]))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [(1 if min(d1, d2) > (K-1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, sum(adist))

print(ans)


Measured memory_bytes: 87000
# -*- coding: utf-8 -*-

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))


a,b = input_multiple_number()

if a%2 == 1 and b%2 == 1:
    print("Odd")
else:
    print("Even")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define mod 1e9 +7;
typedef long long ll;
typedef vector<ll> vll;
const double phi = (1 + sqrt(5)) / 2;
const double phi_ = (1 - sqrt(5)) / 2;
ll fib(ll n){
    double res = pow(phi, n+1) - pow(phi_, n+1);
    return res / sqrt(5);
}
ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}
ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}
string to_bin_string(ll n){
    stringstream ss;
    ss << bitset<8>(n); //任意の桁数<m>
    string s = ss.str();
    return s;
}
int main()
{
    ll a, b, ans;
    cin >> a >> b;
    ll ma = max(a,b), mi = min(a, b);
    if(ma == 1)ans = 1;
    else if(mi == 1)ans = ma - 2;
    else ans = (mi - 2)*(ma - 2);
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    h = [int(i) for i in ipt().split()]
    ans = 0
    f = True
    mih = min(h)
    for i,hi in enumerate(h):
        if hi == mih:
            f = False
        elif f:
            ans += max(0,hi-h[i+1])
        else:
            ans += max(0,hi-h[i-1])
    print(ans+mih)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll w, h;
	cin >> w >> h;
	ll x, y;
	cin >> x >> y;

	double a = double(w*h) / 2;
	
	int ans = 0;
	if (2*x == w && 2*y == h) ans = 1;

	printf("%.10f %d\n", a, ans);

	return 0;
}


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

int main(){

  int n,x;
  cin>>n>>x;
   vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >>vec.at(i);}

  sort(vec.begin(), vec.end());
  int count=0;
  for(int i=0;i<n;i++){
    if(i==n-1 && vec[n-1] < x)break;
    if(vec[i] <=x ){
  count++;
    x = x-vec[i];
    
  
  }else
  {
   
    break;}
  }
   cout<< count <<endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007


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

    // solution comes here

    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) {
        cin >> A[i];
        A[i] = A[i] - i-1;
    }

    sortup(A);

    ll b = A[N>>1];/*
    if(N%2) b = A[N/2];
    else b = (A[N/2]+A[(N+1)/2]) / 2;
    */

    ll ans=0;
    rep(i, N) ans += abs(A[i] - b);
    cout << ans << nl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<cassert>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int not_prime[1000001];

vector<ll> factorize(ll n){
    vector<ll> ret;
    ll i = 2;
    while(n != 1 && i <= 1000000){
        if(not_prime[i]){
            i++;
            continue;
        }
        ll j = i;
        while(j <= 1000000){
            not_prime[j] = 1;
            j += i;
        }

        while(n % i == 0){
            n /= i;
            ret.push_back(i);
        }

        i++;
    }
    if(n != 1LL){
        ret.push_back(n);
    }
    return ret;
}

int main() {
    ll n, p;
    cin >> n >> p;

    vector<ll> facts = factorize(p);

    ll ans = 1LL;
    map<ll, ll> count;
    for(ll f: facts) ++count[f];
    for(auto itr=count.begin();itr!=count.end();++itr) {
        if((itr->second)/ n)ans *= pow(itr->first, ((itr->second)/ n));
    }

    cout << ans << endl;
}


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

int main()
{
	int n,l[1000],r[1000];
	cin>>n;
	int v=0;
	for(int i=0;i<n;i++){
		cin>>l[i]>>r[i];
		v+=r[i]-l[i]+1;
	}
	
	cout<<v<<endl;
	
	return 0;
}


Measured memory_bytes: 256
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;



signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);

  string s;
  cin >> s;
  if (s == "ARC")
    cout << "ABC";
  else
    cout << "ARC";
  
  
}


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

typedef long long int ll;
const ll MOD = 1000000007;

ll A[1000010];

int main() {
    int n, D, H;
    cin >> n >> H >> D;
    ll B = 0;
    ll meow = 1;
    for (int i = 1; i <= n; i++) {
        meow = (meow * i) % MOD;
        B = (B + meow) % MOD;
    }

    A[0] = meow;
    ll sum = A[0];
    for (int i = 1; i < H; i++) {
        A[i] = sum * B % MOD;
        sum = (sum + A[i]) % MOD;
        if (i - D >= 0)
            sum = (sum - A[i - D] + MOD) % MOD;
    }
    cout << sum << "\n";
}


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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 305;

int ans[N][N];
int main() {
	int h, w, _;
	char mat[N][N];
	scanf("%d %d %d", &h, &w, &_);
	for(int i = 0; i < h; i++){
		scanf("%s", mat[i]);
	}
	int id = 1;
	for(int j = 0; j < w; j++){
		for(int i = 0; i < h; i++){
			if(mat[i][j] == '#'){
				int up = i, down = i;
				ans[i][j] = id;
				while(up > 0 && mat[up-1][j] == '.' && ans[up-1][j] == 0){
					up--;
					ans[up][j] = id;
				}
				while(down < h-1 && mat[down+1][j] == '.' && ans[down+1][j] == 0){
					down++;
					ans[down][j] = id;
				}
				for(int k = j-1; k >= 0; k--){
					int up2 = i, down2 = i;
					if(ans[i][k] != 0 || mat[i][k] != '.') break;
					while(up2 > up && mat[up2-1][k] == '.' && ans[up2-1][k] == 0){
						up2--;
					}
					while(down2 < down && mat[down2+1][k] == '.' && ans[down2+1][k] == 0){
						down2++;
					}
					if(up2 != up || down2 != down){
						break;
					}
					for(int l = up2; l <= down2; l++){
						ans[l][k] = id;
					}
				}
				for(int k = j+1; k < w; k++){
					int up2 = i, down2 = i;
					if(ans[i][k] != 0 || mat[i][k] != '.') break;
					while(up2 > up && mat[up2-1][k] == '.' && ans[up2-1][k] == 0){
						up2--;
					}
					while(down2 < down && mat[down2+1][k] == '.' && ans[down2+1][k] == 0){
						down2++;
					}
					if(up2 != up || down2 != down){
						break;
					}
					for(int l = up2; l <= down2; l++){
						ans[l][k] = id;
					}
				}
				id++;
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			assert(ans[i][j] != 0);
			printf("%d%c", ans[i][j], j == w-1 ? '\n' : ' ');
		}
	}

}


Measured memory_bytes: 1152
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>

using namespace std;

int main(int argc, const char * argv[]) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec(n);
  int a,b;
  for(int i = 0; i < n; i++){
    cin >> a >> b;
    vec[i].first = a;
    vec[i].second = b;
  }
  sort(vec.begin(), vec.end());


  int64_t buy;
  int64_t cost = 0;
  for(int i = 0; i < n; i++){
    buy = min(vec[i].second, m);
    m -= buy;
    cost += buy*vec[i].first;
    if(m == 0){
      cout << cost << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
   fast
   string s;
   cin>>s;
   if(s=="Sunny")
   {
       cout<<"Cloudy"<<endl;
   }
   if(s=="Cloudy")
   {
       cout<<"Rainy"<<endl;
   }
   if(s=="Rainy")
   {
       cout<<"Sunny"<<endl;
   }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int tax(int p, int r) {
	return p * (r + 100) / 100;
}

int main() {
	int x, y, s;
	cin >> x >> y >> s;
	if (!(x || y || s)) {
		return 0;
	}
	int m = 0;
	for (int i = 1; i < s; i++) {
		for (int j = i; j < s; j++) {
			int o = tax(i, x) + tax(j, x);
			if (o == s) {
				int n = tax(i, y) + tax(j, y);
				if (m < n) {
					m = n;
				}
			}
		}
	}
	cout << m << endl;
	return main();
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef long double td;
typedef vector<td> vd;
typedef pair<ll,ll> ii;
typedef vector<ii> vii; typedef vector<bool> vb;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = ll(a); i < (ll)(b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define show(v,n) cerr << #v << " = "; forn(i,n) cerr << v[i] << " "; cerr << endl;
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
int MAXN = 500005;


ll solve(vector <int> &v, int n, int k)
{
	ll MAXN = (ll)(1e18);
	vector <ll> dp(n,MAXN);
	dp[0]=0;
	forr(i,1,n)
	{
		forr(j,1,k+1)
		{
			if(i-j < 0) break;
			dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
		}
	}
	return dp[n-1];
}
 
int main()
{ 	
	FIN;
	#ifdef input
		freopen("test1.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector <int> v(n);
	forn(i,n) cin >> v[i];
	cout << solve(v,n,2) << endl;
    return 0;
}


Measured memory_bytes: 4512
#include <iostream>

int main()
{
	long long s, c;
	std::cin >> s >> c;
	if (s * 2 >= c)
		std::cout << c / 2 << std::endl;
	else
		std::cout << s + (c - 2 * s) / 4 << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int H, W;
  char a[101][101];
  char aa[101][101];
  char aaa[101][101];
  int i, ii, j, jj, kk;
  
  memset(a, '\0', sizeof(a));
  memset(aa, '\0', sizeof(aa));
  memset(aaa, '\0', sizeof(aaa));
  
  scanf("%d %d", &H, &W);
  getchar();
  
  for(i=0;i<H;i++){
    gets(a[i]);
  }
  
//  printf("%d %d\n",H ,W);
  
  ii = 0;
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(memcmp(&a[i][j],"#",1)==0){
        memcpy(aa[ii],a[i],W);
        ii++;
        break;
      }
    }
  }
  
  jj=0;
  for(j=0;j<W;j++){
    for(i=0;i<ii;i++){
      if(memcmp(&aa[i][j],"#",1)==0){
        for(kk=0;kk<ii;kk++){
          memcpy(&aaa[kk][jj],&aa[kk][j],1);
        }
        jj++;
       break;
      }
    }
  }
  
  for(i=0;i<ii;i++){
    printf("%s\n",&aaa[i][0]);
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ll long long
using namespace std;

void solve() {
    double PI = 3.14159265359;
    double r;
    cin >> r;
    cout << 2 * r * PI << endl;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 3256
package main

import (
	"bufio"
	"math"
	"os"
	"strconv"
	"strings"
)

var n int
var D []int
var INF=int(math.Pow(2,31))-1

//////////////////////bufio/////////////////////
var err error
var inputReader= bufio.NewReader(os.Stdin)
var outputWriter=bufio.NewWriter(os.Stdout)
func main(){
	var n,q int
	s:=reading()
	n,err=strconv.Atoi(s[0])
	q,err=strconv.Atoi(s[1])
	initRMQ(n)
	var a,b,c int
	for i := 0; i < q; i++ {
		s=reading()
		a,err=strconv.Atoi(s[0])
		b,err=strconv.Atoi(s[1])
		c,err=strconv.Atoi(s[2])
		if a==0 {
			update(b,c)
		}else {
			temp:=strconv.Itoa(findMin(b,c))
			outputWriter.WriteString(temp+"\n")
			outputWriter.Flush()
		}
	}
}
func reading()[]string{
	var input string
	input, err = inputReader.ReadString('\n')
	input = strings.Replace(input, "\n", "", -1)
	s:=strings.Split(input," ")
	return s
}

////////////////////////Range Query////////////////////////////////
func initRMQ(lenarr int){
	n = 1
	for ;n < lenarr;  {
		n *= 2
	}
	D=make([]int,2*n-1)
	for i := 0; i < 2*n-1; i++ {
		D[i]=INF
	}
}
func update(k,a int){
	k += n - 1
	D[k]=a
	for ;k > 0 ; {
		k=(k-1)/2
		D[k]=min(D[2*k+1],D[2*k+2])
	}
}
func findMin(a,b int)int {
	return query(a,b+1,0,0,n)
}
func query(a,b,k,l,r int) int {
	if r <= a || b <= l {
		return INF
	}
	if a <= l && r <= b{
		return D[k]
	}

	vl := query(a,b,2*k+1,l,(l+r)/2)
	vr := query(a,b,2*k+2,(l+r)/2,r)
	return min(vl,vr)
}
func min(a,b int) int{
	if a <= b {
		return a
	}else {
		return b
	}
}


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

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

#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;
const int maxn = 100000 + 10;

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
int a[maxn];
int b[maxn];
vector<int> A, B, G[maxn];

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    n = read<int>();
    for(int i = 1; i <= n; i++) a[0] ^= (a[i] = read<int>()), A.pb(a[i]);
    for(int i = 1; i <= n; i++) b[0] ^= (b[i] = read<int>()), B.pb(b[i]);

    A.pb(a[0]); sort(A.begin(), A.end());
    B.pb(b[0]); sort(B.begin(), B.end());

    for(int i = 0; i <= n; i++) if(A[i] != B[i]) return puts("-1"), 0; 

    static bool equ[maxn], vis[maxn];

    A.resize(unique(A.begin(), A.end()) - A.begin());

    for(int i = 1; i <= n; i++) equ[i] = (a[i] == b[i]);
    for(int i = 0; i <= n; i++) a[i] = lower_bound(A.begin(), A.end(), a[i]) - A.begin();
    for(int i = 0; i <= n; i++) b[i] = lower_bound(A.begin(), A.end(), b[i]) - A.begin();
    for(int i = 0; i <= n; i++) if(!equ[i]) G[a[i]].pb(i);

    int ans = 0;
    for(int i = 0; i <= n; i++) if(!equ[i] && !vis[i]) {
        static int q[maxn];
        int head = 0, tail = 0;

        vis[q[tail++] = i] = 1;
        while(head < tail) {
            int x = q[head++];
            for(const auto& to : G[b[x]]) 
                if(!vis[to]) vis[to] = 1, q[tail++] = to;
        }

        ans += i ? tail+1 : tail-1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 7800
#include <bits/stdc++.h> 
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using Pii = std::pair<int, int>;

int main(int argc, char *argv[])
{
    int N, A, B, C;
    std::cin >> N >> A >> B >> C;

    std::vector<int> l(N, 0);
    for (int i = 0; i < N; i++) {
        std::cin >> l[i];
    }

    const int K = 4;

    int ans = INF;
    for (int i = 0; i < std::pow(K, N); i++) {
        int cost = 0;
        std::vector<int> a(3, 0);
        std::vector<int> count(3, 0);
        for (int j = 0; j < N; j++) {
            int tmp = i;

            for (int k = 0; k < j; k++) {
                tmp /= K;
            }
            tmp %= K;

            if (tmp == 1) {
                a[0] += l[j];
                count[0]++;
            } else if (tmp == 2) {
                a[1] += l[j];
                count[1]++;
            } else if (tmp == 3) {
                a[2] += l[j];
                count[2]++;
            }
        }

        cost += std::abs(A - a[0]);
        cost += std::abs(B - a[1]);
        cost += std::abs(C - a[2]);

        if (count[0] == 0 || count[1] == 0 || count[2] == 0) {
            continue;
        }

        for (int j = 0; j < 3; j++) {
            cost += 10*(count[j]-1);
        }

        ans = std::min(ans, cost);
    }

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int d[100010]={};
    int cnt[100010];
    for(int i=2; i<=100000; i++){
        for(int j=1; j*j<=i; j++){
            if(i%j==0){
                d[i]++;
                if(j*j<i) d[i]++;
            }
        }
    }
    cnt[2]=0;
    for(int i=3; i<=100000; i++){
        cnt[i]=cnt[i-1];
        if(d[i]>=5) cnt[i]++;
    }
    int q; cin>>q;
    for(int i=0; i<q; i++){
        int n; cin>>n;
        cout<<cnt[n]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3892
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
i=0
while True:
    if i*4>n:
        print("No")
        break
    if (n-i*4)%7==0:
        print("Yes")
        break
    i+=1


Measured memory_bytes: 77412
n=int(input())
l=[[float('inf')]*n for i in range(n)]
ans=0
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=[int(s) for s in input().rstrip().split()]
    l[i][x-1]=y

for i in range(2**n):
  d=[0 for j in range(n)]
  for j in range(n):
    if i>>j & 1:
      d[j]=1
      
  flag=1
  for j in range(n):
    if d[j]==1:
      for k in range(n):
        if l[j][k]==float('inf'):
          continue
        if l[j][k]!=d[k]:
          flag=0

  if flag==1:
    ans=max(ans,sum(d))

print(ans)


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}
	ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>();
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=1; i<=n; i++) {
			if((i*(i+1))/2>=n) {
				System.out.println(i);
				break;
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 21972
#include<stdio.h>
int main(void) {
	signed long long int t, n=0, ask=0, sum = 0;
	scanf("%d",&n);
	for (t = 0; t <= n; t++) {
		sum = sum + t;
	}

	for (t = 0; t*3 <= n; t++) {
		sum = sum - t*3;
	}

	for (t = 0; t*5 <= n; t++) {
		sum = sum - t*5;
	}

	for (t = 0; t*15 <= n; t++) {
		sum = sum + t*15;
	}
	printf("%lld", sum);
	
	return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>

  /* 配列の要素を交換する */
void Swap(int x[ ], int i, int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

  /* クイックソートを行う */
void QSort(int x[ ], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
    //ShowData(x, 10);               /* 途中経過を表示 */

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

int main(){
  int n, k,i,j,tmp;
  long int result=0;
  int h[200001];
  
  scanf("%d %d", &n, &k);
  for(i=0;i<n;i++) scanf("%d", &h[i]);
  
  QSort(h, 0, n-1);
  
  for(i=0;i<n-k;i++) result += h[i];
  
  printf("%ld", result);
  
  return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int a[3], b[3];
    rep(i, 3){
        cin >> a[i] >> b[i];
    }
    vi v(4);
    rep(i, 3){
        v[a[i]-1]++;
        v[b[i]-1]++; 
    }
    int c=0, d = 0;
    rep(i, 4){
        if(v[i] % 2 == 0)c++;
        if(v[i]%2==1)d++;
        if(v[i] == 0){
            cout << "NO" << "\n";
            return 0;
        }
    }
    if(c == 2 && d == 2)cout << "YES" << "\n";
    else cout << "NO" << "\n";
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int b[n-1];
	for(int i = 0;i<n-1;i++){
		cin >> b[i];
	}
	int sum = 0;
	for(int i = 0;i<n;i++){
		if(i == 0){
			sum+=b[0];
		}else if(i == n-1){
			sum+=b[n-2];
		}else{
			if(b[i] > b[i-1])
				sum+=b[i-1];
			else
				sum+=b[i];
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

void dfs(std::vector<std::vector<size_t>>& vs, size_t k, size_t n) {
  if (n == k) {
    std::string res(n, 'a');
    for (size_t i = 0; i < n; ++i)
      for (auto j: vs[i])
        res[j] += i;

    printf("%s\n", res.c_str());
    return;
  }

  for (size_t i = 0; i < vs.size(); ++i) {
    vs[i].push_back(k);
    dfs(vs, k+1, n);
    vs[i].pop_back();
    if (vs[i].empty()) break;
  }
}

int main() {
  size_t n;
  scanf("%zu", &n);
  std::vector<std::vector<size_t>> vs(n);
  dfs(vs, 0, n);
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    int sum= 0;
    rep(i,m) {
        cin >> a[i];
        sum+= a[i];
    }
    if(sum > n) {
        cout << -1 << endl;
        } else {
            cout << n - sum << endl;
        }
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T &b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T &b) {
	a = min(a, b);
}

int main() {
	makei(N);
	makev(a, N);
	sort(rev(a));
	int tmp = a[0];
	ll ans1 = 0, ans2 = 0;
	Rep(1, N) {
		if (a[i] == tmp) {
			if (ans1 == 0) {
				ans1 = tmp;
				tmp = -1;
			}
			else {
				ans2 = tmp;
				break;
			}
		}
		else {
			tmp = a[i];
		}
	}
	say(ans1*ans2);
}


Measured memory_bytes: 640
#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 pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n;
int a[200001],b[200001];
int cnt=0;
int main(){
    cin>>n;
    rep(i,n) cin>>a[i+1];
    for(int i=n;i>0;--i){
        int flag=0;
        for(int j=i;j<=n;j+=i){
            if(b[j]!=0) ++flag;
        }
        if(a[i]%2!=flag%2){
            b[i]=1;++cnt;
        }
    }
    if(cnt){cout<<cnt<<endl;FOR(i,1,n+1)if(b[i]) cout<<i<<" ";}
    else cout<<0;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2432
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class Program
{
    static void Main(string[] args)
    {
        var abn = Console.ReadLine().Split(' ');
        var a = decimal.Parse(abn[0]);
        var b = decimal.Parse(abn[1]);
        var n = decimal.Parse(abn[2]);
        var x = b <= n ? b - 1 : n;

        var res = Math.Floor(a * x / b) - a * Math.Floor(x / b);

        Console.WriteLine(res);
    }
}


Measured memory_bytes: 18104
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	#define endl '\n'
	int k; string s; cin >> k >> s;
	if((int)s.size() > k)cout << s.substr(0, k) << "..." << endl;
	else cout << s << endl;
}


Measured memory_bytes: 3644
/*
 * Grading.cpp
 *
 *  Created on: 2014/07/31
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

#define EXIT (0)

typedef struct {
	int a_iMidtermScore;
	int a_iFinalScore;
	int a_iRetryScore;
}ScoreData;

int main(void) {

	int iMidtermScore, iFinalScore, iRetryScore;
	vector<ScoreData> vecScoreDate;
	while (1) {
		cin >> iMidtermScore >> iFinalScore >> iRetryScore;
		if ((-1 == iMidtermScore) && (-1 == iFinalScore) && (-1 == iRetryScore)) {
			break;
		}
		ScoreData Data;
		Data.a_iMidtermScore = iMidtermScore;
		Data.a_iFinalScore = iFinalScore;
		Data.a_iRetryScore = iRetryScore;
		vecScoreDate.push_back(Data);
	}

	for (unsigned int i = 0; i < vecScoreDate.size(); i++) {
		ScoreData Data = vecScoreDate.at(i);
		int iSumScore = Data.a_iMidtermScore + Data.a_iFinalScore;
		if ((Data.a_iMidtermScore == -1) || (Data.a_iFinalScore == -1)) {
			cout << "F" << endl;
		} else if (iSumScore >= 80) {
			cout << "A" << endl;
		} else if ((65 <= iSumScore) && (iSumScore < 80)) {
			cout << "B" << endl;
		} else if ((50 <= iSumScore) && (iSumScore < 65)) {
			cout << "C" << endl;
		} else if ((30 <= iSumScore) && (iSumScore < 50)) {
			if (Data.a_iRetryScore >= 50) {
				cout << "C" << endl;
			} else {
				cout << "D" << endl;
			}
		} else if (iSumScore < 30) {
			cout << "F" << endl;
		}
	}

	return EXIT;
}

Measured memory_bytes: 1208
n, q = map(int, input().split())
array = [[s for s in input().split()] for i in range(n)]
total_time = 0
while len(array) != 0:
    a = array.pop(0)
    a_t = int(a[1])
    if a_t - q <= 0:
        total_time += a_t
        a[1] = total_time
        print(a[0], a[1])
    else:
        a[1] = a_t - q
        array.append(a)
        total_time += q

Measured memory_bytes: 16592
# A - ><
S = str(input())
####
ans = [0] * (len(S)+1)
tani = []

for i,s in enumerate(S+'<'):
    if s == '<':
        if i == 0:
            tani.append(i)
        elif S[i-1] == '>':
            tani.append(i)
#print(tani)

for t in tani:
    #print('tani', t)

    i = t
    val = 0
    while True:
        if i >= len(S):
            break
        if S[i] == '>':
            break
        if ans[i+1] < val + 1:
            ans[i+1] = val + 1
        i += 1
        val += 1

    i = t
    val = 0
    while True:
        if i <= 0:
            break
        if S[i-1] == '<':
            break
        if ans[i-1] < val + 1:
            ans[i-1] = val + 1
        i -= 1
        val += 1

#print(ans)

print(sum(ans))


Measured memory_bytes: 23724
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from itertools import product

N = I()
F = [[[0]*2 for _ in range(5)] for _ in range(N)]
P = []
for i in range(N):
    temp = III()
    for j in range(5):
        for k in range(2):
            F[i][j][k] = temp[j*2+k]
for _ in range(N):
    P.append(III())

ans = -float('inf')
A = list(product([True, False],repeat=10))
for a in A:
    if a == (False,)*10:
        continue
    val = 0
    for i in range(N):
        count = 0
        for j in range(5):
            for k in range(2):
                if a[2*j+k]==True and F[i][j][k]==1:
                    count += 1
        val += P[i][count]
    if val > ans:
        ans = val

print(ans)

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

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
    int N,X;
    cin>>N>>X;

    vector<int>L;

    for(int i = 0;i<N;i++)
    {
        int inp;
        cin>>inp;
        L.push_back(inp);
    }

    vector<int>D;

    D.push_back(0);

    for(int i = 1;i<N+1;i++)
    {
        int inp = D[i-1] + L[i-1];
        D.push_back(inp);
    }

    int count = 0;

    for(int i = 0;i<N+1;i++)
    {
        if(D[i]<=X)
            count++;
    }

    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
dic = {"r": p, "s": r, "p": s}
t = list(input())
ans = 0

for i in range(len(t)):
    if i < k:
        ans += dic[t[i]]
    else:
        if not t[i-k] == t[i]:
            ans += dic[t[i]]
        else:
            t[i] = "x"
print(ans)


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

using namespace std;

int main(void){
  string num;
  
  cin >> num;
  
  if(num[0] == num[1] && num[1] == num[2]) cout << "Yes" << endl;
  else if(num[1] == num[2] && num[2] == num[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		
		if(R < 1200) {
			System.out.println("ABC");			
		} else if(R < 2800) {
			System.out.println("ARC");		
		} else {
			System.out.println("AGC");	
		}
	}
}


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

#define ll long long
#define INF 2147483647

int inp(){
    char c = getchar();
    while(c < '0' || c > '9')
        c = getchar();
    int sum = 0;
    while(c >= '0' && c <= '9'){
        sum = sum * 10 + c - '0';
        c = getchar();
    }
    return sum;
}

char s[100010];

int main(){
    int n = inp();
    int ans = 0;
    scanf("%s", s + 1);
    for(int l = 1, r; l <= n; l = r + 1){
        r = l;
        while(r < n && s[r + 1] == s[l])
            r++;
        ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N=2e5+5, mod=998244353;
int k,n,a[N];
ll mn=1e9;
vector<ll> v;
int main(){
	scanf("%d%d",&k,&n);
	for (int i = 0; i < n; ++i){
		scanf("%d",a+i);
		v.pb(a[i]);
	}
	for (int i = 0; i < n; ++i){
		v.pb(0LL+k+a[i]);
	}
	for (int i = 0; i < n; ++i){
		mn=min(mn,v[i+n-1]-v[i]);
	}
	cout<<mn<<endl;
		
}

Measured memory_bytes: 7152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
	ll money = 1000;
	for(int i=1; i<n; i++){
		if(a[i] > a[i-1]){
			ll cur = money / a[i-1];
			money += cur * (a[i]-a[i-1]);
		}
	}
	cout << money << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
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;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<ll> ans_v(2);

    for(int start_plus = 0; start_plus <= 1; start_plus++){ // 最初が+なら0, -なら1
        ll ans = 0, sum = 0;
        for(int i = 0; i < N; i++){
            sum += A[i];
            if(i % 2 == start_plus){ //sum > 0にする
                if(sum > 0) continue;
                else{
                    ans += 1 - sum;
                    sum = 1;
                }
            } 
            else if(i % 2 != start_plus){ //sum < 0にする
                if(sum < 0) continue;
                else{
                    ans += sum + 1;
                    sum = -1;
                }
            } 
        }
        ans_v[start_plus] = ans;

    } 

    cout << min(ans_v[0], ans_v[1]) << endl;
}

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

const long mod = 1000000007; 

long pmod(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * pmod(b, e - 1) % mod;
  long t = pmod(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return pmod(n, mod - 2);
}

long comb(long n, long r) {
  long prod = 1;
  for (int i = 0; i < r; ++i) {
    prod = prod * (n - i) % mod * inv(r - i) % mod;
  }
  return prod;
}

int n, a, b;
int main() {
  cin >> n >> a >> b;
  long sum = pmod(2, n);
  sum += mod - comb(n, a);
  sum += mod - comb(n, b);
  sum += mod - 1;
  cout << sum % mod << endl;
}

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

#define MOD 1000000007

int main(){
    int n; cin >> n;
    vector<int> prime(n, 0);
    for (int i=n; i>1; i--){//n!をiで回す
        //cout << "i is " << i << endl;
        int n_copy=i;
        for (int j=2; j*j<=n; j++){//iを素因数分解
            while(n_copy%j==0){
                n_copy/=j;
                //cout << "n_copy is " << n_copy << endl;
                prime.at(j-2)++;//vectorは2origin（0, 1は素数でないため）
            }
        }
        if (n_copy>1) prime.at(n_copy-2)++;
    }
    long long count=1;
    for(int i=0; i<n-1; i++){
        //cout << i+2 << ":" << prime.at(i) << endl;
        count*=prime.at(i)+1;
        count%=MOD;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 764
/**
 *    author:  tourist
 *    created: 14.12.2019 10:27:58       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  double r1, r2;
  cin >> r1 >> r2;
  cout << fixed << setprecision(17) << r1 * r2 / (r1 + r2) << '\n';
  return 0;
}


Measured memory_bytes: 256
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const [x, a, b] = input.trim().split(" ").map(Number);
  if (b - a <= 0) {
    return "delicious";
  } else if (b - a <= x) {
    return "safe";
  } else {
    return "dangerous";
  }
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int a[3][3];
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  int n;
  cin >> n;
  rep(i, n) {
    int b;
    cin >> b;
    rep(j, 3) rep(k, 3) if (a[j][k] == b) a[j][k] = -1;
  }

  bool f = false;
  rep(i, 3) {
    bool tmp = true;
    rep(j, 3) {
      if (a[i][j] != -1) tmp = false;
    }
    if (tmp) f = true;
  }

  rep(i, 3) {
    bool tmp = true;
    rep(j, 3) {
      if (a[j][i] != -1) tmp = false;
    }
    if (tmp) f = true;
  }

  bool tmp = true;
  rep(i, 3) if (a[i][i] != -1) tmp = false;
  if (tmp) f = true;

  tmp = true;
  rep(i, 3) if (a[2 - i][i] != -1) tmp = false;
  if (tmp) f = true;

  cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    for (long long b = k + 1; b <= n; b++) {
        long long m = n / b;
        ans += (b - k) * m;
        ans += max(n - (b * m + k - 1), 0LL);
        ans -= (k == 0 ? 1 : 0);
        // cout << "b=" << b << " m=" << m << " ans=" << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  char d1[4];
  char d2[7][4] = {{'S','U','N'},{'M','O','N'},{'T','U','E'},{'W','E','D'},{'T','H','U'},{'F','R','I'},{'S','A','T'}};
  int i,j,k;

  scanf("%s",d1);
  
  for(i = 0;i < 7;i++){
    for(j = 0;j < 3;j++){
      if((d2[i][j] == d1[j])&&(j == 2)){
	k = i;
	printf("%d\n",7 - k);
      }
      else if(d2[i][j] != d1[j]){
	break;	
      }
    }
  }
     
    return 0;
  }

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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N=1e5+5;
const int M=1e9+7;
void solve()
{
	int n;
	cin>>n;
	int cnt=0;
	bool flag=false;
	for(int i=0;i<n;i++)
	{
		int t1,t2;
		cin>>t1>>t2;
		if(t1==t2)
			cnt++;
		else
			cnt=0;
		if(cnt==3)
			flag=true;
	}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

signed main()
{
	FAST
	
	#ifndef ONLINE_JUDGE
	freopen("input_sublime.txt", "r", stdin);
	freopen("output_sublime.txt", "w", stdout);
	#endif
	
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
    
    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
  int n;
  int h, m, mm;
  while(cin >> n, n){
    double L=0, D=0, M=0;
    int L_cnt=0, D_cnt=0, M_cnt=0;
    for(int i = 0 ; i < n ; i++){
      scanf("%d:%d", &h, &m);
      if(h == 0) h = 24;
      if(h == 1) h = 25;
      scanf("%d", &mm);
      
      int mmm = h * 60 + m;
      
      bool flag = false;
      
      int t = mm - m;
      if(t < 0){
	mm += 60;
	t = mm - m;
      }
      if(t <= 8) flag = true;
      
      if(flag){
	if(660 <= mmm && mmm <= 899){
	  L += 100;
	  L_cnt++;
	}
	else if(1080 <= mmm && mmm <= 1259){
	  D += 100;
	  D_cnt++;
	}
	else if(1260 <= mmm && mmm <= 1559){
	  M += 100;
	  M_cnt++;
	}
      }
      else{
	if(660 <= mmm && mmm <= 899) L_cnt++;
	else if(1080 <= mmm && mmm <= 1259) D_cnt++;
	else if(1260 <= mmm && mmm <= 1559) M_cnt++;
      }
    }
    
    if(L_cnt == 0) cout << "lunch no guest" << endl;
    else cout << "lunch " << (int)L / L_cnt << endl;
    
    if(D_cnt == 0) cout << "dinner no guest" << endl;
    else cout << "dinner " << (int)D / D_cnt << endl;
    
    if(M_cnt == 0) cout << "midnight no guest" << endl;
    else cout << "midnight " << (int)M / M_cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1248
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = sc.nextInt()
    println(problem088a(n, a))
}

fun problem088a(n: Int, a: Int): String {
    return if (n % 500 <= a) "Yes" else "No"
}

Measured memory_bytes: 31404