akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def main():

    graph = [[] for _ in range(51)]
    for start in range(51):
        for cost in range(1,51):
            if start%cost == 0:
                graph[0].append((cost, start))
    for end in range(1, 51):
        for cost in range(end+1, 51):
            start = end + cost
            while start <= 50:
                graph[end].append((cost, start))
                start += cost

    use = 0
    for l in reversed(range(1, 52)):
        for a, b in zip(A, B):
            ok = False
            q = [b]
            checked = [False]*51
            checked[b] = True
            while q:
                qq = []
                for p in q:
                    if p == a:
                        ok = True
                        break
                    for cost, np in graph[p]:
                        if not checked[np] and (cost < l or use&(1<<cost)):
                            checked[np] = True
                            qq.append(np)
                if ok: break
                q = qq
            if not ok:
                if l == 51:
                    return -1
                use |= (1<<l)
                break
    return use

if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define N 19

int a[1<<N],s[1<<N][2],ans[N];
int n;

int main()
{
	scanf("%d",&n);
	for (int i=0;i<(1<<n);i++) scanf("%d",&a[i]),s[i][0]=a[i];
	for (int k=0;k<n;k++) {
		for (int j=0;j<(1<<n);j++)
			if (!(j>>k&1))
			{
				int t=j|(1<<k);
				for (int i=0;i<2;i++)
				{
					if (s[j][i]>s[t][0]) s[t][1]=s[t][0],s[t][0]=s[j][i];
					else if (s[j][i]>s[t][1]) s[t][1]=s[j][i];
				}
			}
	}
	for (int i=1;i<(1<<n);i++)
	{
		ans[i]=max(ans[i-1],s[i][0]+s[i][1]);
		printf("%d\n",ans[i]);
	}
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC125().SolveB(new ConsoleInput(Console.In, ' '));
        }
    }

    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; }
    }
  class ABC125
  {
    public void SolveB(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var V = cin.ReadIntArray(n);
            var C = cin.ReadIntArray(n);
            int sum = 0;
            for (int i = 0; i < n; i++)
            {
                if (V[i] > C[i]) sum += V[i] - C[i];
            }
            WriteLine(sum);
            ReadLine();
        }
  }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  int P[100000], Y[100000];
  vector<int> yd[100001];
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }
  for(int i = 1; N >= i; i++) {
    sort(yd[i].begin(), yd[i].end());
  }
  for(int i = 0; M > i; i++) {
    cout << setw(6) << setfill('0') << P[i];
    int b = lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) -
            yd[P[i]].begin() + 1;
    cout << setw(6) << setfill('0') << b << endl;
  }
}

Measured memory_bytes: 7808
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd


X, Y = map(int, input().split())

a = 2*X - Y / 2
b = Y / 2 - X

if Y % 2 != 0:
    print("No")
elif a >= 0 and b >= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27084
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll gcd(ll a,ll b)
{
    while(a^=b^=a^=b%=a);
    return b;
}
ll a[110];
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
        scanf("%lld",&a[i]);
    ll ans=a[1];
    for(i=2; i<=n; i++)
        ans=ans/gcd(ans,a[i])*a[i];
   printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
//**************************
//*** author  :  Alex Hu **
//************************

//  _______        __________         ________        __
//  \      \   ____\______   \ ____  /  _____/  _____/  |_
//  /   |   \ /  _ \|       _// __ \/   \  ____/ __ \   __\
// /    |    (  <_> )    |   \  ___/\    \_\  \  ___/|  |
// \____|__  /\____/|____|_  /\___  >\______  /\___  >__|
//         \/              \/     \/        \/     \/

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define fi first
#define se second
#define sqr(a) ((a)*(a))

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

const ll mod=1e9+7;
const ll INF=0x3f3f3f3f3f3f3f3f;

#define int long long

int k,a,b; 

signed main(){
	cin>>k>>a>>b;
	if(2>=(b-a)){
		cout<<1+k<<endl;
	}else{
		int cur=1;
		int cha=a-1;
		if(cha>0)k-=cha,cur+=cha;
		cout<<cur+(k&1)+(b-a)*(k>>1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,p;
    cin>>a>>p;
    int c=a*3+p;
    cout<<c/2<<endl;
}

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

int main() {
  string S;
  cin >> S;
  if (S=="SAT") cout << 1 << endl;
  else if (S=="FRI") cout << 2 << endl;
  else if (S=="THU") cout << 3 << endl;
  else if (S=="WED") cout << 4 << endl;
  else if (S=="TUE") cout << 5 << endl;
  else if (S=="MON") cout << 6 << endl;
  else if (S=="SUN") cout << 7 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int x,y;
  cin>>x>>y;
  for(int i=0;i<=x;i++){
    if(i*2+(x-i)*4==y){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3636
def main():

    def calc(lst):
        now = lst
        while len(now) > 1:
            tmp = []
            for i in range(len(now) - 2):
                ABC = [now[i], now[i + 1], now[i + 2]]
                ABC.sort()
                tmp.append(ABC[1])
            now = tmp
        return now[0]

    N, x = map(int, input().split())
    if x == 1 or x == 2 * N - 1:
        print ('No')
        return 0
    print ('Yes')
    ans = [(1 + i) for i in range(2 * N - 1)]
    if x < N:
        tmp = N - x + 1
        for i in range((tmp + 1) // 2):
            ans[N - i - 1], ans[N - tmp + i - 1] = ans[N - tmp + i - 1], ans[N - i -1]
    else:
        tmp = x - N + 1
        for i in range((tmp + 1) // 2):
            ans[N + i - 1], ans[N + tmp - i - 1] = ans[N + tmp - i - 1], ans[N + i - 1]
    print (*ans, sep = '\n')
    # print (calc(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 15612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

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

	int K, S;
	cin >> K >> S;

	int x, y;

	long long ans = 0;
	for(x = 0; x<=K; x++){
		for(y = 0; y<=K; y++){
			int z = S - x - y;
			if(z >=0 && z <= K){
				ans++;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s,t;cin>>s>>t;
    int ans=0;
    rep(i,3){
        if(s.at(i)==t.at(i)){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3588
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	k := nextInt()

	if k%2 == 0 || k%5 == 0 {
		puts(-1)
		return
	}

	for i, ai := 1, 0; ; i++ {
		ai = ai*10 + 7
		ai %= k
		if ai == 0 {
			puts(i)
			return
		}
	}
}


Measured memory_bytes: 1800
#include <stdio.h>
#include <stdlib.h>
#define int long long

typedef struct {
	int val;
	int num;
}pair;

signed compare(const void *a, const void *b){
	pair ap = *(pair *)a, bp = *(pair *)b;
	int sub = ap.val - bp.val;
	if(sub < 0){
		return 1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return -1;
	}
}

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

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

signed main(){
	int N, M, i, j, k, l, xsum, ysum, zsum, ans = 0;
	scanf("%lld%lld", &N, &M);
	int *x = (int *)malloc(sizeof(int) * N);
	int *y = (int *)malloc(sizeof(int) * N);
	int *z = (int *)malloc(sizeof(int) * N);
	pair *w = (pair *)malloc(sizeof(pair) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld%lld", &x[i], &y[i], &z[i]);
	}
	for(j = -1; j <= 1; j += 2){
		for(k = -1; k <= 1; k += 2){
			for(l = -1; l <= 1; l += 2){
				for(i = 0; i < N; i++){
					w[i].val = j * x[i] + k * y[i] + l * z[i];
					w[i].num = i;
				}
				qsort(w, N, sizeof(pair), compare);
				xsum = 0;
				ysum = 0;
				zsum = 0;
				for(i = 0; i < M; i++){
					xsum += x[w[i].num];
					ysum += y[w[i].num];
					zsum += z[w[i].num];
				}
				ans = max(ans, ABS(xsum) + ABS(ysum) + ABS(zsum));
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        int n = Integer.parseInt(br.readLine());
        int m = Integer.parseInt(br.readLine());
        int tot = Integer.parseInt(br.readLine());
        int max = Math.max(n, m);
        int ans = tot/max;
        tot %= max;
        if(tot != 0) ans++;
        pw.println(ans);




        pw.flush();
        pw.close();
    }
}


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

int main()
{
    int a[100],count=0,n,m,sum=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
        sum+=a[i];
    }
    double x=sum/(4.00*m);
    for(int i=0;i<n;i++){
       if(a[i]>=x) count++;
    }
    count>=m?printf("Yes\n"):printf("No\n");

    return 0;
}


Measured memory_bytes: 256
// aoj-1001.c

#include <stdio.h>

int BubSort(int x[ ], int n)
{
    int i, j, temp;

    for (i = 0; i < n - 1; i++) {
        for (j = n - 1; j > i; j--) {
            if (x[j - 1] > x[j]) {  /* OÌvfÌûªå«©Á½ç */
                temp = x[j];        /* ð··é */
                x[j] = x[j - 1];
                x[j - 1]= temp;
            }
        }	
    }
}

void ShowData(int x[ ], int n) {
    int i;

    for (i = 9; i>6; i--)
        printf("%d\n", x[i]);
}

int main() {
	int i, j;
	int x[10], temp;

	// WüÍ©çæé
	for(i=0; i<10; i++) {
		scanf("%d", &x[i]);
	}

	BubSort(x, 10);
	ShowData(x, 10);
/*
	printf("%d\n", x[9]);
	printf("%d\n", x[8]);
	printf("%d", x[7]);
*/
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int total = -1;
  
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    
    int count = 0;
    
    while (A % 2 == 0) {
      count++;
      A /= 2;
    }
    
    if (count < total || total < 0) total = count;
  }
  
  cout << total << endl;
}

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

namespace attocoda
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            int d = c - (a - b);
            if (a - b < c)
                Console.WriteLine(d);
            else
                Console.WriteLine(0);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, h;
    cin >> n >> h;

    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    int amax = max_element(a.begin(), a.end()) - a.begin();

    vi largeb;
    int cnt = 0;
    rep(i, n) {
        if (a[amax] < b[i]) {
            largeb.pb(b[i]);
            cnt++;
        }
    }
    sort(largeb.rbegin(), largeb.rend());
    vll sm(cnt + 1, 0);
    rep(i, cnt) sm[i+1] = sm[i] + largeb[i];

    int ans = 0;
    if (a[amax] == b[amax]) {
        if (h <= sm[cnt]) {
            ans = lower_bound(sm.begin(), sm.end(), h) - sm.begin();
            cout << ans << endl;
        } else {
            ans += cnt;
            h -= sm[cnt];
            ans += 1;
            h -= b[amax];
            ans += (h + a[amax] - 1) / a[amax];
            cout << ans << endl;
        }
    } else {
        if (h <= sm[cnt]) {
            ans = lower_bound(sm.begin(), sm.end(), h) - sm.begin();
            cout << ans << endl;
        } else {
            ans += cnt;
            h -= sm[cnt];
            ans += (h + a[amax] - 1) / a[amax];
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 2296
n = int(input())
a =[]
b =[]
c =[]
for i in range(n):
    x1, y1, z1 = [int(i) for i in input().split()]
    a.append(x1)
    b.append(y1)
    c.append(z1)

dp = [[0 for i in range(3)] for j in range(n)]

dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

for i in range(n-1):
    dp[i + 1][0] = max(dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
    dp[i + 1][1] = max(dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
    dp[i + 1][2] = max(dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])

print(max(dp[n-1]))

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

int main(){
  int N;
  int a[110];
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> a[i];

  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; ++i){
    if (i % 2 == 0){
      Alice += a[i];
    }else{
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>


int main() {
	int N;
	scanf("%d", &N);
	long long sum=0;
	int i;
	for (i = 1; i < N + 1; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			sum = sum + i;
		}
	}
	printf("%lld", sum);
	return 0;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int a;
   cin>>a;
   cout << a+a*a+a*a*a << endl;
   return 0;
}


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

using namespace std;
typedef long long ll;

int
main()
{
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  cout << ((A % 3 == 0 || B % 3 == 0 || ((A + B) % 3 == 0)) ? "Possible"
                                                            : "Impossible")
       << endl;
  return 0;
}


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

int main(void)
{
	char moji,newm;
	while (scanf("%c", &moji) != EOF)
	{
		newm = moji;
		if ('a' <= moji && moji <= 'z') newm = moji - ('a' - 'A');
		else if ('A' <= moji && moji <= 'Z') newm= moji + ('a' - 'A');
		printf("%c", newm);
	}
	return 0;
}


Measured memory_bytes: 3148
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ps := make([]int, m)
	ss := make([]string, m)

	acm := make(map[int]bool)
	for i := 0; i < m; i++ {
		var p int
		var s string
		fmt.Scan(&p, &s)
		ps[i] = p
		ss[i] = s
		if s == "AC" {
			acm[p] = true
		}
	}

	am := make(map[int]bool)
	var ac, wa int
	for i := 0; i < m; i++ {
		p := ps[i]
		s := ss[i]
		if b, ok := am[p]; ok && b {
			continue
		}
		if s == "AC" {
			am[p] = true
			ac++
		} else {
			if b, ok := acm[p]; ok && b {
				wa++
			}
		}
	}
	fmt.Printf("%d %d\n", ac, wa)
}


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a+1),q(b+1);
    priority_queue<ll> r; r.push(0);
    ll temp;
    rep(i,a){cin >> p[i];}
    sort(all(p),greater<ll>());
    rep(i,b){cin >> q[i];}
    sort(all(q),greater<ll>());
    rep(i,c){
        cin >> temp;
        r.push(temp);
    }

    ll m,ans=0,pc=0,qc=0;
    rep(i,x+y){
        m = max(p[pc],max(q[qc],r.top()));
        ans += m;
        if(m == p[pc]){
            pc++;
            if(pc == x) pc = a;
        }
        else if(m == q[qc]){
            qc++;
            if(qc == y) qc = b;
        }
        else r.pop();
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 2936
#include <iostream>

int main() {
	int W, // Width 
		H, // Height
		x, // x position
		y, // y position
		r; // radius

	std::cin >> W >> H >> x >> y >> r;

	if (W > 0 && W <= 100 && H > 0 && H <= 100 && r > 0 && r <= 100 &&
		x >= -100 && x <= 100 && y >= -100 && y <= 100) {
		if (W - (x + r) < 0 || (x - r) < 0 || H - (y + r) < 0 || (y - r) < 0)
			std::cout << "No" << std::endl;
		else
			std::cout << "Yes" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    const ll lim = 1000000000000001ll;
    ll b = 1;
    vll vb; // 1, 26, 26^2,,,
    while(b < lim * 26ll) {
        vb.push_back(b);
        b *= 26ll;
    }
    for(ll i = 1; i < vb.size(); i++) vb[i] += vb[i - 1];
    vll l, r;
    for(ll i = 0; i < vb.size(); i++) {
        l.push_back(vb[i]);
        r.push_back(vb[i] * 26);
    }
    ll len = 0;
    for(ll i = 0; i < l.size(); i++) {
        if(l[i] <= n && n <= r[i]) {
            n -= l[i];
            len = i + 1;
            break;
        }
    }
    string ans;
    for(ll i = 0; i < len; i++) {
        ans += (n % 26) + 'a';
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;


void solve() {
	int n, s[3]; rep(i, 3)cin >> s[i]; cin >> n;
	int ans = 0;
	rep(i, 3001) {
		if (i*s[0] > n)break;
		rep(j, 3001) {
			int x = i * s[0] + j * s[1];
			if (x > n)break;
			int r = n - x;
			if (r%s[2] == 0)ans++;
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
require 'prime'

MOD = 1000000007
n = gets.to_i
f = 1
1.upto(n) do |i|
    f = f * i
end
a = Prime.prime_division(f).to_a
ans = 1
a.each do |b|
    ans *= b[1] + 1
    ans %= MOD
end
p ans

Measured memory_bytes: 3068
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, M, X, A, count = 0;
    cin >> N >> M >> X;
    REP(i, M) {
        cin >> A;
        if (A < X) count++;
    }
    cout << min(count, M - count) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
S = input()
T = input()
alpha = []
rule = {}
for i in range(len(S)):
	if S[i] in rule.keys():
		if rule[S[i]] != T[i]:
			print('No')
			sys.exit()
	elif T[i] in rule.values():
		print('No')
		sys.exit()
	else:
		rule[S[i]] = T[i]
print('Yes')

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

int main() {
  int N;
  cin >> N;
  int res = N;
  for (int i = 0; i <= N; i++) {
    int cc = 0;
    int t = i;
    while (t > 0) {
      cc += t % 6;
      t /= 6;
    }
    t = N - i;
    while (t > 0) {
      cc += t % 9;
      t /= 9;
    }
    if (res > cc) {
      res = cc;
    }
  }
  cout << res << endl;
}


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

int main() {
  int N,K,sum;
  sum=0;
  cin >> N >> K;
  vector<int> p(N);
  for (int i=0; i<N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  for (int i=0; i<K; i++) {
    sum+=p.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvin;
typedef vector<pair<ll,ll>> vpll;
typedef vector<pair<int,int>> vpin;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef queue<int> qin;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
//const int maxn =101;
//ll pr[maxn];
int main()
{
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
int n;
cin>>n;
vin A (n);
int sum=0;
F (i,0,n,1) {cin>>A[i];
  sum+=A[i];
}
sort(fall(A));
if (sum%10!=0) cout<<sum;
else {
F (i,0,n,1) {
  if ((A[i])%10!=0) {
    cout<<sum-A[i];
    exit(0);
  }
  }
cout<<0;
}
return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n; cin >> n;
  cout << (1000 - n % 1000) % 1000;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
using ll=long long;

int main(){
    double W,H,x,y;
    cin>>W>>H>>x>>y;
    double field=W*H/2;
    int check;
    if(W/2==x&&H/2==y){
        check=1;
    }else{
        check=0;
    }
    printf("%.9f %d\n",field,check);
    return 0;
}

Measured memory_bytes: 3792
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<map>
using namespace std;

int a, b, c, d, e, k;
int MAX, MIN;
int ans;

int main() {
	MIN = 1000;
	for (int i = 0; i < 5; i++) {
		cin >> a;
		if (MIN > a) {
			MIN = a;
		}
		if (MAX < a) {
			MAX = a;
		}
	}
	cin >> k;

	ans = MAX - MIN;
	if (ans <= k) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();


int main()
{
    INT x;
    cin >> x;
    INT ans = 0;
    ans += x/11*2;
    if (x%11 != 0){
        if (x%11 <= 6){
            ans++;
        }else{
            ans+=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct UnionFind {
    vector< int > data;
    
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
    
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    
    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    
    int size(int k) {
        return (-data[find(k)]);
    }
};

int main(void) {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);

    int ans = N - M;
    while(M--) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        --X; --Y;
        if(uf.find(X) == uf.find(Y)) {
            ++ans;
        } else {
            uf.unite(X, Y);
        }
    }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    rep(i, sz(S)) {
        S[i] = 'A' + (S[i] - 'A' + N) % 26;
    }
    cout << S << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
vector<pl> G[MAX_N];
bool used[MAX_N];
ll C[MAX_N];
ll sign[MAX_N];
ll l, r;

void loop(int v, ll cost, ll s) {
	// debug(v, cost, s);
	used[v] = true;
	C[v] = cost;
	sign[v] = s;
	if(sign[v] == 1) {
		l = max(l, -cost + 1);
	}
	else {
		r = min(r, cost - 1);
	}
	rep(i, 0, sz(G[v])) {
		int n = G[v][i].fst;
		ll ct = G[v][i].sec;
		if(!used[n]) loop(n, ct - cost, s * -1);
		else {
			if(sign[v] != sign[n]) {
				if(C[v] + C[n] != ct) r = -1;
			}
			else {
				// v * s1 + cost1 + v * s1 + cost2 = ct
				ll vd = (ct - C[v] - C[n]);
				if(vd % 2 != 0) r = -1;
				else {
					r = min(r, vd / 2 * sign[v]);
					l = max(l, vd / 2 * sign[v]);
				}
				// debug("omo", v, n, l, r);
			}
		}
	}
}

void solve() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b, c; cin >> a >> b >> c; a--; b--;
		G[a].pb(pl(b, c));
		G[b].pb(pl(a, c));
	}
	l = 1;
	r = linf;
	loop(0, 0, 1);
	cout << max(r - l + 1, 0ll) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 32128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
int main() {
    int N;
    cin>>N;
    vector<int>A(N);
    bool a=true;
    rep(i,N){
        cin>>A.at(i);
        if(A.at(i)%2==0){
            if(A.at(i)%3==0||A.at(i)%5==0){
            }
            else{
                a=false;
            }
        }
    }
    if(a==true){
        cout<<"APPROVED"<<endl;
    }
    else
    cout<<"DENIED"<<endl;
}


Measured memory_bytes: 3612
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main() {
    int a, b, x;
    readf("%s %s %s", &a, &b, &x);
    readln;
   
    int tot = a*a * b;
    
    double p = hypot(a, b);
    double midangle = asin(b / p) * 180 / PI;
    
    debug { writeln(p, ' ', midangle); }
    
    bool isOk(double angle) {
        double field(double b, double angle) {
            double rad = angle * PI / 180;
            double a = tan(rad) * b;
            
            return a * b / 2;
        }
        
        double lft = 0;
        if (angle < midangle) {
            double sz = field(a, angle);
            lft = tot - sz * a;
        } else {
            double sz = field(b, 90 - angle);
            lft = sz * a;
        }
        
        return lft >= x;
    }
    
    double le = 0, r = 90;
    foreach (_; 0 .. 100) {
        double m = (le + r) / 2;
        if (isOk(m)) { le = m; }
        else { r = m; }
    }
    
    writefln("%.10f", le);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	string str = in<string>();
	REP(i, str.length()) {
		for (ll j = i; j <= str.length(); ++j) {
			if (str.substr(0, i) + str.substr(j) == "keyence") {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))

kyori = [-1]*n

now = 0;kyori[now] = 0
jyunkan = 0;v = 0
for i in range(n):
    tugi = a[now] - 1
    if kyori[tugi] != -1:
        jyunkan = kyori[now] + 1
        v = tugi
        break
    kyori[tugi] = kyori[now] + 1
    if kyori[tugi] == k:
        print(tugi + 1)
        sys.exit()
    now = tugi
k -= kyori[v]
mawaru = jyunkan - kyori[v]
amari = k % mawaru

now = v;cunt = 0
for i in range(amari):
    now = a[now] - 1
    
print(now + 1)

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

int main() {
  int masu,ryokin,start;
  int left = 0;
  int right = 0;
  int point = 0;
  
  cin >> masu >> ryokin >> start;
  
  for(int i = 0; i < ryokin; i++){
    cin >> point;
    if(point > start) right++;
    else left++;
  }

  if(left >= right) cout << right;
  else cout << left;
}


Measured memory_bytes: 256
N, Z, W = parse.(split(readline(STDIN)))
a = parse.(split(readline(STDIN)))
unshift!(a, W)
N += 1

dpx, dpy = fill(-1, N), fill(-1, N)

function f(isx, pos)
    if isx
        if dpx[pos] < 0
            dpx[pos] = max(abs(a[pos] - a[N]), pos < N-1 ? maximum([f(false, p) for p in pos+1:N-1]) : typemin(Int64))
        end
        return dpx[pos]
    else
        if dpy[pos] < 0
            dpy[pos] = min(abs(a[pos] - a[N]), pos < N-1 ? minimum([f(true, p) for p in pos+1:N-1]) : typemax(Int64))
        end
        return dpy[pos]
    end
end

ans = f(true, 1)
println(ans)

Measured memory_bytes: 184884
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int mod=10000;

string decrease(string x){
	for(int i=x.size()-1;i>=0;i--){
		if(x[i]!='0'){
			x[i]--;
			if(x[i]=='0'&& i==0 &x.size()>1) 
				x=x.substr(1);
			return x;
		}else
			x[i]='9';
	}
	return x;
}

int dp[501][500][10][2][3];

int solve(string s,int m){
	int n=s.size();
	clr(dp,0);
	dp[0][0][0][0][0]=1;

	rep(i,n)rep(j,m)rep(a,10)rep(b,2)rep(c,3){
		int cur=s[i]-'0';
		rep(l,10){
			int nb=1;
			if(!b){
				if(cur<l) continue;
				if(cur==l) nb=0;
			}

			int nc=0;
			if(c==0){
				if(a>0){
					if(a==l) continue;
					if(a<l) 
						nc=1;
					else
						nc=2;
				}
			}
			if(c==1){
				if(a<=l) continue;
				nc=2;
			}
			if(c==2){
				if(a>=l) continue;
				nc=1;
			}

			int nj=(j*10+l)%m;
			
			dp[i+1][nj][l][nb][nc]=(dp[i+1][nj][l][nb][nc]+dp[i][j][a][b][c]+mod)%mod;
		}
	}
	int res=0;
	rep(a,10)rep(b,2)rep(c,3) res=(res+dp[n][0][a][b][c]+mod)%mod;
	return res;
}

int main(void){
	string a,b;
	cin >> a >> b;
	int m;
	cin >> m;

	a=decrease(a);

	int ans=(solve(b,m)-solve(a,m)+mod)%mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 59936
#include <iostream>

int main(int argc, char* argv[])
{
  int a, b, c, d;

  std::cin >> a >> b >> c >> d;

  if (a+b > c+d) {
    std::cout << "Left" << std::endl;
    return 0;
  }

  if (a+b == c+d) {
    std::cout << "Balanced" << std::endl;
    return 0;
  }

  std::cout << "Right" << std::endl;
  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a[20],b[20],c[20];
    int n,i,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++) scanf("%d",&b[i]);
    for(i=0;i<n-1;i++) scanf("%d",&c[i]);
    for(i=0;i<n;i++){
        cnt+=b[i];
        if(i!=0 && a[i-1]==a[i]-1)
            cnt+=c[a[i]-2];
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 2e5 + 500;

int n, A[N], x;

int B(int i){
	return (A[i] > x);
}

bool provjeri(){
	if(B(n - 1) == B(n))
		return B(n - 1);
	if(B(n - 1) == B(n - 2))
		return B(n - 1);
	int l = n - 1, r = n - 1;
	while(l > 0 && B(l) != B(l - 1))
		l--;
	while(r < 2 * n - 2 && B(r) != B(r + 1))
		r++;
	if(l == 0)
		return B(r);
	if(r == 2 * n - 2)
		return B(l);
	if((n - 1) - l < r - (n - 1))
		return B(l);
	return B(r);
}

int main(){
	scanf("%d", &n);
	for(int i = 0;i < 2 * n - 1;i++){
		scanf("%d", A + i);
	}
	for(int i = 20;i >= 0;i--){
		x += (1 << i);
		if(!provjeri())
			x -= (1 << i);
	}
	printf("%d\n", x + 1);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
bool godie=0;
inline int check(int *v){
	int res=v[0]<v[1]?1:-1;
	if(res<0)swap(v[0],v[2]);
	if(v[0]%3!=1)godie=1;
	if(v[0]+1!=v[1])godie=1;
	if(v[1]+1!=v[2])godie=1;
	return res*(v[0]/3+1);
}
const int maxn=100005;
int a[maxn][3],b[maxn],id[maxn],n,to[maxn],nw[maxn],cnt[10];
namespace szsz{
	int sum[maxn];
	inline void add(int x,int v){
		while(x){
			sum[x]+=v;
			x-=lowbit(x);
		}
	}
	inline int query(int x){
		int res=0;
		while(x<=n){
			res+=sum[x];x+=lowbit(x);
		}return res%2;
	}
	inline void reset(){
		memset(sum,0,sizeof(sum));
	}
}
inline int inv(int st){
	int res=0;
	szsz::reset();
	for(int i=st;i<=n;i+=2){
		res^=szsz::query(to[i]+1);
		szsz::add(to[i],1);
	}return res;
}
inline int sgn(int x){
	if(x&1)
		return -1;
	else
		return 1;
}
int main(){	read(n);
	rep(j,0,2)rep(i,1,n)read(a[i][j]);
	rep(i,1,n)b[i]=check(a[i]);
	rep(i,1,n)id[i]=i;

	rep(i,1,n){
		int p=abs(b[i]);
		if((i&1)!=(p&1))godie=1;
		to[p]=i;
		nw[i]=p*sgn(abs(i-p)>>1);
		cnt[i&1]^=(nw[i]!=b[i]);
	}
	cnt[0]^=inv(1);
	cnt[1]^=inv(2);
	if(godie){
		puts("No");
		return 0;
	}
	puts((cnt[0] == 0 && cnt[1] == 0) ? "Yes" : "No");
	return 0;
}


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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();


                int[] nums = input.Split(' ').Select(x => int.Parse(x)).ToArray();
                if (nums[1] <= nums[2] || nums[3] <= nums[0])
                {
                    Console.WriteLine("0");
                }
                else
                {
                    Console.WriteLine(Math.Min(nums[3], nums[1]) - Math.Max(nums[2], nums[0]));
                }

            return;
        }
    }
}

Measured memory_bytes: 13396
#include <cstdio>
#include <algorithm>
#include <complex>
#include <cmath>
#include <iostream>
using namespace std;

typedef complex<double> P;
double const eps=1e-8;
P ps[128];
int n;

int solve(){
    int res=1;
    for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
        P &p1=ps[i], &p2=ps[j];
        double d=abs(p1-p2);
        if(d>2) continue;
        P h=(p1-p2)/d*P(0,1)*sqrt(1-d*d/4.);
        P m=(p1+p2)/2.;
        P q1=m+h, q2=m-h;
        // cout << i << " " << j << ":";
        for(int x=0;x<2;x++){
            int t=0;
            for(int k=0;k<n;k++){
                if(abs(q1-ps[k])<=1+eps){
                    t++;
                    // cout << k << " ";
                }
            }
            // cout << endl;
            res=max(res,t);
            swap(q1,q2);
        }
    }
    return res;
}

int main(){
    while(scanf("%d",&n)!=EOF && n){
        for(int i=0;i<n;i++){
            double x,y; scanf("%lf,%lf",&x,&y);
            ps[i] = P(x,y);
        }
        printf("%d\n",solve());
    }
}

Measured memory_bytes: 1224
#include <iostream>
int main(){
    int flag = 1;
    while(flag){
        int n, x;
        long long ans = 0;
        std::cin >> n >> x;
        if(n == 0 && x == 0) break;
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                for(int k = j + 1; k <= n; k++){
                    if(i + j + k == x) ans++;
                }
            }
        }
    std::cout << ans << std::endl;
    }
}


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

#define int long long

void solve(int tt)
{
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=k;i<=b;i+=k)
    {
        if(i>=a)
        {
            cout<<"OK";
            return;
        }
    }
    cout<<"NG";
}

int32_t main()
{
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++)
        solve(i);
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n,d;
  int cnt = 0;
  cin >> n >> d;
  vector<vector<int>>vv(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> vv[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int distance = 0;
      for(int k=0;k<d;k++){
        distance += (vv[i][k]-vv[j][k])*(vv[i][k]-vv[j][k]);
      }
      bool flag = false;
      for(int k=0;k<=distance;k++){
        if(k*k == distance) flag = true;
      }
      if(flag) cnt++;
    }
  }
  cout<< cnt <<endl;
}


Measured memory_bytes: 256