akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline
R,C,k=map(int,input().split())
A=[[0]*C for i in range(R)]
for i in range(k):
  r,c,v=map(int,input().split())
  A[r-1][c-1]=v
dp0=[[0]*(C+1) for i in range(R+1)]
dp1=[[0]*(C+1) for i in range(R+1)]
dp2=[[0]*(C+1) for i in range(R+1)]
dp3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    V=A[i-1][j-1]
    dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
    dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1])
    dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1])
    dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))

Measured memory_bytes: 432088
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j;
    string s,ss,x="";
    cin>>n>>s>>ss;
    for(i=0;i<s.size();i++)
    {
        x+=s[i];
        x+=ss[i];
    }
    cout<<x<<endl;
    ///kaj shes ha ha
}


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

#define N 202222


int n;
char s[N];

int dp[N];
int sta[N], top = 0;

struct opr {
	int o;
	int top, v;
};

vector <opr> op;
long long ans;
int main() {
	scanf("%s", s);
	n = (int)strlen(s);
	int pos = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') {
			++pos;
			sta[++top] = pos;
			dp[pos] = 0;
			op.push_back({0, sta[top], dp[pos]});
		}
		else if (s[i] == ')') {
			++pos;
			if (top) {
				ans += (dp[pos] = dp[sta[top] - 1] + 1);
				op.push_back({1, sta[top], dp[pos]});
				top--;
			}
			else {
				dp[pos] = 0;
				op.push_back({-1, -1, -1});
			}
		}
		else {
			opr cur = op.back(); op.pop_back();
			pos--;
			switch (cur.o) {
				case -1: break;
				case 0:
					top--;
					break;
				case 1:
					ans -= cur.v;
					sta[++top] = cur.top;
				break;
			}
		}
		printf("%lld\n", ans);
	}
}



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

char a[55][55], b[55][55];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n, m; cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }

    for (int i = 0; i < n - m + 1; i++) {
        for (int j = 0; j < n - m + 1; j++) {

            bool failed = false;
            for (int y = i; y < i + m; y++) {
                for (int x = j; x < j + m; x++) {
                    if (a[y][x] != b[y - i][x - j]) {
                        failed = true;
                        break;
                    }
                }
                if (failed) break;
            }
            if (!failed) {
                cout << "Yes\n";
                return 0;
            }

        }
    }

    cout << "No\n";

    return 0;
}


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

res = 0
for h_flags in range(1 << h):
    for w_flags in range(1 << w):
        black_cnt = 0

        for i in range(h):
            if (h_flags >> i) & 1 == 0:
                continue

            for j in range(w):
                if (w_flags >> j) & 1 == 0:
                    continue

                black_cnt += cells[i][j] == '#'

        if black_cnt == k:
            res += 1

print(res)


Measured memory_bytes: 9196
from collections import deque

N, Q = map(int, input().split())
edge = [[] for i in range(N)]
ops = []
ans = [0] * N

for _ in range(N-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
for _ in range(Q):
    ops.append(tuple(map(int, input().split())))

for op in ops:
    node = op[0]-1
    pnt = op[1]
    ans[node] += pnt

stack = deque()
stack.append((0, -1))

while stack:
    st = stack.pop()
    node, parent = st[0], st[1]
    children = edge[node]
    for child in children:
        if child == parent:
            continue
        ans[child] += ans[node]
        stack.append((child, node))

print(*ans)

Measured memory_bytes: 86392
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long inf = 1ll << 61;
const long long mod = 1000000007;
struct edge {int to, cost;};
typedef pair<int, int> P;
vector<edge>G[100006];
int u[200006], v[200006], d[200006];
int d1[100006], d2[100006], dp1[100006], dp2[100006];
void dijk(int s,int V,int *d,int *dp) {
	fill(d, d + V, inf);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>>Q;
	Q.push(P(0, s));
	dp[s] = 1;
	while (Q.size()) {
		P p = Q.top();
		Q.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		rep(i, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				dp[e.to] = dp[v];
				dp[e.to] %= mod;
				Q.push(P(d[e.to], e.to));
			}
			else if(d[e.to]==d[v]+e.cost){
				dp[e.to] += dp[v];
				dp[e.to] %= mod;
			}
		}
	}
}

signed main() {
	int n, m, s, t; cin >> n >> m >> s >> t;
	s--; t--;
	rep(i, m) {
		cin >> u[i] >> v[i] >> d[i];
		u[i]--; v[i]--;
		G[u[i]].push_back({ v[i],d[i] });
		G[v[i]].push_back({ u[i],d[i] });
	}
	dijk(s, n, d1, dp1);
	dijk(t, n, d2, dp2);
	int ans = dp1[t] * dp2[s] % mod;
	int mind = d1[t];
	rep(i, n) {
		if (d1[i] + d2[i] == mind&&d1[i] == d2[i]) {
			ans -= dp1[i] * dp2[i] % mod*dp1[i]%mod*dp2[i]%mod;
			ans = (ans + mod) % mod;
		}
	}
	rep(i, m) {
		if (d1[u[i]] > d1[v[i]])swap(u[i], v[i]);
		if (d1[u[i]] + d[i] + d2[v[i]] == mind) {
			if (d1[u[i]] -d[i]< d2[v[i]] && d2[v[i]] < d1[v[i]]) {
				ans -= dp1[u[i]] * dp2[v[i]] % mod*dp1[u[i]] % mod*dp2[v[i]] % mod;
				ans = (ans + mod) % mod;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
vector<int> G[MAXN];

int d[MAXN];
int qx[MAXN];

void dfs(int cur, int par, int cost) {
  cost += qx[cur];
  d[cur] = cost;

  for (int next: G[cur]) {
    if (next != par) dfs(next, cur, cost);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  memset(qx, 0, sizeof(qx));
  memset(d, 0, sizeof(d));
  for (int i = 0; i < q; ++i) {
    int p, x;
    cin >> p >> x;
    p--;
    qx[p] += x;
  }
  dfs(0, -1, 0);
  for (int i = 0; i < n; ++i) {
    cout << d[i];
    if (i == n - 1) puts("");
    else cout << " ";
  }
  return 0;
}


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

using namespace std;

#define PI 3.14159265
#define int long long
#define pb push_back
#define mp make_pair
#define smax(x , y) x = max(x , y)
#define smin(x , y) x = min(x , y)

const int maxn = 1e5+10;

main(){
	int n; cin >> n;
	if(n % 10 == 9 or n / 10 == 9) return cout << "Yes" << endl , 0;
	return cout << "No" << endl , 0;
}  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    N = N % 10
    if N == 3:
        print('bon')
    elif N in [2, 4, 5, 7, 9]:
        print('hon')
    else:
        print('pon')


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10716
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int memo[310000];

int main(){
	int N;
	cin >> N;
	priority_queue<long long int> que;
	priority_queue<long long int, vector<long long int>, greater<long long int>> que2;
	vector<long long int> a(3 * N);
	for(int i = 0; i < 3 * N; i++){
		cin >> a[i];
	}
	long long int S = 0;
	for(int i = 0; i < N; i++){
		S += a[i];
		que2.push(a[i]);
	}
	memo[N - 1] = S;
	for(int i = N; i < 2 * N; i++){
		S += a[i];
		que2.push(a[i]);
		S -= que2.top();
		que2.pop();
		memo[i] = S;
	}
	S = 0;
	for(int i = 3 * N - 1; i >= 2 * N; i--){
		S += a[i];
		que.push(a[i]);
	}
	long long int ans = memo[2 * N - 1] - S;
	for(int i = 2 * N - 1; i >= N; i--){
		S += a[i];
		que.push(a[i]);
		S -= que.top();
		que.pop();
		ans = max(ans, memo[i - 1] - S);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5748
N = int(input())
x=[]
u=[]
for i in range(0,N):
    a=[j for j in input().split()]
    x.append(float(a[0]))
    u.append(a[1])

s=0
for i in range(0,N):
    if u[i]=="BTC":
        s+=380000*x[i]
    else:
        s+=x[i]
print(s)
    

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
    cnt+=min(a[i],b[i])
    b[i]=max(0,b[i]-a[i])
    x=a[i+1]
    a[i+1]=max(0,a[i+1]-b[i])
    cnt+=(x-a[i+1])
print(cnt)


Measured memory_bytes: 18624
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int first = in.nextInt();
        if(first == 1){
            System.out.println("Hello World");
        }
        else{
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
        }
    }
}

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

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var n = h[0];
		var p = read();
		var uf = new UF(n + 1);
		foreach (var r in new int[h[1]].Select(_ => read())) uf.Unite(r[0], r[1]);
		Console.WriteLine(p.Select((x, i) => uf.AreUnited(x, i + 1)).Count(x => x));
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
}


Measured memory_bytes: 29368
#include<iostream>

using namespace std;

int a[20];
int n,m,q;
int sum=0;

bool dfs(int sum_, int idx){
    //cout << sum_ << " " << idx << endl;
    if(sum_ == m) return true;
    else if(idx == n) return false;
    else if(dfs(sum_+a[idx],idx+1)||dfs(sum_,idx+1)) return true;
    return false;

}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> m;
        if(dfs(0,0)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>

using namespace std;



int main(int argc, char *argv[]) {
	int c[9];

	for (int i = 0; i < 9; i++)
		cin >> c[i];

	int da1 = c[1] - c[0];
	int da2 = c[4] - c[3];
	int da3 = c[7] - c[6];
	int db1 = c[2] - c[1];
	int db2 = c[5] - c[4];
	int db3 = c[8] - c[7];
	int dc1 = c[3] - c[0];
	int dc2 = c[4] - c[1];
	int dc3 = c[5] - c[2];
	int dd1 = c[6] - c[3];
	int dd2 = c[7] - c[4];
	int dd3 = c[8] - c[5];

	if (da1 == da2 && da1 == da3 && db1 == db2 && db2 == db3 && dc1 == dc2 && dc2 == dc3 && dd1 == dd2 && dd2 == dd3) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,k;
  string s;
  cin>>n>>k;
  cin>>s;
  vector<ll>v;
  if(s[0]=='0')v.push_back(0);
  v.push_back(1);
  for(ll i=1;i<n;i++){
    if(s[i-1]==s[i])v[v.size()-1]++;
    else v.push_back(1);
  }
  if(s[n-1]=='0')v.push_back(0);
  ll ans=0;
  for(ll i=0;i<(ll)v.size()&&i<k*2+1;i++){
    ans+=v[i];
  }
  ll tmp=ans;
  for(ll j=k*2+1;j<(ll)v.size();j+=2){
    tmp+=v[j]+v[j+1]-v[j-(k*2+1)]-v[j-k*2];
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1528
// ------------------------------------
// Date:2018/ 2/25
// Problem:AOJ DPL Coin Changing Problem 1_a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int N;
int M;
int dp[50505];
int c[20];


int main()
{
  scanf("%d %d", &N, &M);
  memset(dp, 50000, sizeof(dp));
  REP(mi, M) {
    scanf("%d", &c[mi]);
  }
  sort(c, c + M);
  
  dp[0] = 0;
  REP(ni, N) {
    REP(mi, M) {
      // 多すぎる時
      if (ni + c[mi] > N) break;
      // 硬貨を選ばない時と選ぶ時
      dp[ni + c[mi]] = min(dp[ni] + 1,
                         dp[ni + c[mi]]);
    }
  }
  printf("%d\n", dp[N]);
  return 0;
}



Measured memory_bytes: 3492
def wall(d, x, y, z):
    if z == 0: return x < 4 and d[y * 2][x] == '1'
    if z == 1: return y < 4 and d[y * 2 + 1][x] == '1'
    if z == 2: return x > 0 and d[y * 2][x - 1] == '1'
    if z == 3: return y > 0 and d[y * 2 - 1][x] == '1'
def move(x, y, z):
    if z == 0: return (x + 1, y, 'R')
    if z == 1: return (x, y + 1, 'D')
    if z == 2: return (x - 1, y, 'L')
    if z == 3: return (x, y - 1, 'U')
d = []
p = ""
x = y = z = 0
for i in range(9):
    d.append(raw_input())
while x != 0 or y != 0 or z < 2:
    z = (z + 3) % 4
    while not wall(d, x, y, z):
        z = (z + 1) % 4
    (x, y, c) = move(x, y, z)
    p += c
print p

Measured memory_bytes: 4260
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int ketawa(int a) {
	if (a < 10)return a;
	else return a % 10 + ketawa(a / 10);
}

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;

int main()
{
	int n; cin >> n;
	vector<int> h(n), dp(n);
	rep(i, n) cin >> h[i];
	dp[0] = 0; dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
	}
	cout << dp[n-1] << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Stack;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		for(;;){
			int N = sc.nextInt();
			if(N==0)break;
			Stack<Integer> stack=new Stack<Integer>();
			rec(N,stack);
		}
	}
	static void rec(int n,Stack<Integer>stack){
		if(n==0){
			boolean first =true;
			for(Integer i:stack){
				if(first){
					System.out.print(i);
				} else{
					System.out.print(" "+i);
				}
				first=false;
				
			}
			System.out.println();
			return;
		}
		int init = n;
		if(stack.size()>0){
			init = stack.peek();
		}
		
		for(int i = init;i>0;i--){
			if(n-i<0)continue;
			stack.add(i);
			rec(n-i,stack);
			stack.pop();
		}
	}
}

Measured memory_bytes: 46612
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

ll H, W;



int main(int argc, char* argv[])
{
  std::cin >> H >> W;
  std::string str(W, 'a');
  std::vector< std::string > vs(H, str); 

  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {  
      std::cin >> vs[y][x];
    }
  }

  for (ll y = 0; y < H; y++) {
    std::cout << vs[y] << std::endl << vs[y] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
a=[[(H//3)*W,((H-1)//3+1)*W],[H*(W//3),((W-1)//3+1)*H],
[(H//3)*W,(H-H//3)*(W//2),(H-H//3)*(W-W//2)],
[(W//3)*H,(W-W//3)*(H//2),(W-W//3)*(H-H//2)],
[((H-1)//3+1)*W,(H-((H-1)//3+1))*(W//2),(H-((H-1)//3+1))*(W-W//2)],
[((W-1)//3+1)*H,(W-((W-1)//3+1))*(H//2),(W-((W-1)//3+1))*(H-H//2)]]
print(min([max(e)-min(e) for e in a]))

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> to(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to.at(a).push_back(b);
    to.at(b).push_back(a);
  }
  vector<int> d0(n, n), d1(n, n);
  d0.at(0) = 0;
  d1.at(n - 1) = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int x : to.at(v)) {
      if (d0.at(x) < n) continue;
      d0.at(x) = d0.at(v) + 1;
      q.push(x);
    }
  }
  q.push(n - 1);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int x : to.at(v)) {
      if (d1.at(x) < n) continue;
      d1.at(x) = d1.at(v) + 1;
      q.push(x);
    }
  }
  int black = 0;
  for (int i = 0; i < n; i++) {
    if (d0.at(i) <= d1.at(i)) {
      black++;
    }
  }
  if (black > n - black) {
    puts("Fennec");
  } else {
    puts("Snuke");
  }
}


Measured memory_bytes: 6528
use std::io::*;
use std::str::FromStr;
   
fn read<T: FromStr>() -> T {
	let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
	let n: usize = read();
	let mut a: Vec<usize> = Vec::new();
	let mut b: Vec<usize> = Vec::new();
	let mut c: Vec<usize> = Vec::new();
	for i in 0..n{
		a.push(read());
	}
	for i in 0..n{
		b.push(read());
	}
	for i in 0..n-1{
		c.push(read());
	}

	let mut sum = b.iter().fold(0, |sum, &b| sum + b);
    for i in 0..n-1 {
        if a[i] + 1 == a[i + 1] {
            sum += c[a[i] - 1];
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  int L=A+B;
  int R=C+D;
  
  if(L > R){
  cout << " Left " << endl;
  }
  
  else if(L == R){
  cout << " Balanced " << endl;
  }
  
  else{
    cout << " Right " << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
using namespace std;
int n,m,a,b,k;
char s[200002];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(re int i=1;i<=n;++i)if(s[i]!='?')putchar(s[i]);else putchar('D');
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

ll c[100010];

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a;
    ll ans = 0;
    rep(i, n){
        ll tmp;
        cin >> tmp;
        if(tmp <= 100000){
            c[tmp]++;
            a.emplace_back(tmp);
        }else{
            ans++;
        }
    }
    repr(i, 1, 100001){
        if(c[i] >= i){
            ans += c[i]-i;
        }else{
            ans += c[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

  int64_t N;
  cin >> N;
  vector<int64_t> L(N);
  if (N <3) {
    cout << 0; 
    return 0; 
  }
  for (int64_t i = 0; i < N; i++) {
    cin >> L.at(i);
  }

  sort(L.begin(), L.end());

  int64_t cnt = 0;
  for (int64_t i = 0; i < N; i++) {
    for (int64_t j = i + 1; j < N; j++) {
      if (L.at(i) == L.at(j)) {
        continue;
      }
      for (int64_t k = j + 1; k < N; k++) {
        if (L.at(i) == L.at(k) or L.at(j) == L.at(k)) {
          continue;
        }
        if (L.at(i) + L.at(j) > L.at(k) and L.at(j) + L.at(k) > L.at(i) and
            L.at(k) + L.at(i) > L.at(j)) {
              cnt++; 
        }
      }
    }
  }
  cout << cnt; 

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define INF (1e9)
using namespace std;
struct data{int y,x;};
int n;
data stmp[16];
bool can[16][16];
string mp[16];
char RGB[3]={'R','G','B'};

void Min(int &a,int b){a=min(a,b);}
int Idx(int y,int x){return y*4+x;}

int getBit(int sta,data a,data b,char ch){
  int res=0;
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++){
      if(a.x<=j&&j<=b.x&&a.y<=i&&i<=b.y)res|=(mp[i][j]==ch)<<Idx(i,j);
      else res|=(sta&(1<<Idx(i,j)));
    }
  return res;
}


typedef pair<int,int> P;
int DP(){
  vector<int>D(1<<16,INF);
  queue<int> Q;
  Q.push(0);
  D[0]=0;
  while(!Q.empty()){
    int bit=Q.front();Q.pop();
    if(bit==(1<<16)-1)break;
    for(int i=0;i<3;i++)
      for(int a=0;a<16;a++)
	for(int b=0;b<16;b++)
	  if(can[a][b]){
	    data yx=(data){a/4,a%4};
	    data YX=(data){b/4,b%4};
	    int nbit=getBit(bit,yx,YX,RGB[i]);
	    if(D[nbit]==INF)Q.push(nbit),D[nbit]=D[bit]+1;
	  }

  }
  return D[(1<<16)-1];
}

void mk_can(){
  for(int i=0;i<n;i++){
    int w=stmp[i].x,h=stmp[i].y;
    for(int y=-3;y<4;y++)
      for(int x=-3;x<4;x++){
	int a=max(0,y),b=max(0,x);
	int Y=min(3,y+h-1);
	int X=min(3,x+w-1);
	if(a>Y||b>X)continue;
	can[Idx(a,b)][Idx(Y,X)]=1;
      }
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>stmp[i].y>>stmp[i].x;
  for(int i=0;i<4;i++)cin>>mp[i];
  mk_can();
  cout<<DP()<<endl;
  return 0;
}

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

#define ll long long

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    int temp;

    if(b <= a){
        temp = a;
        a = b;
        b = temp;
    }
    if(c <= b){
        temp = b;
        b = c;
        c = temp;
    }
    if(b <= a){
        temp = a;
        a = b;
        b = temp;
    }

    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 3064
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
    long long nPk_modp(long long n, long long k, long long p);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

    ll h1,m1,h2,m2,k;

    cin >> h1 >> m1 >> h2 >> m2 >> k;

    ll st,en;
    st = 60 * h1 + m1;
    en = 60 * h2 + m2;

    en -= k;

    ll ans = en - st;

    cout << ans << endl;

    return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

long long Combi::nPk_modp(long long n, long long k, long long p)
{
  ll ans = 1;
  for(long long i = k; i <= n; i++)
  {
    ans = (ans * i) % p;
  }

  return ans;
};


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

using namespace std;

const int NMAX = 100000 + 5;
int cnt[NMAX] = {};

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

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        cnt[a]++;
        cnt[a + 1]++;
        cnt[a + 2]++;
        ans = max({ans, cnt[a], cnt[a + 1], cnt[a + 2]});
    }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);


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

  int n, y;
  cin >> n >> y;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n-i; j++) {
      int k = n - i - j;
      if (10000 * i + 5000 * j + 1000 * k == y) {
        printf("%d %d %d\n", i, j, k);
        return 0;
      }
    }
  }

  printf("-1 -1 -1\n");

  return 0;
}


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

int main(void) {
    int N;cin>>N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin>>A[i];
    int cnt = 0;
    while (true) {
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 1) {
                cout << cnt << endl;
                return 0;
            }
            A[i] /= 2;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include<cmath>

using namespace std;

void Solution()
{
    int n;
    
    cin>>n;
    
    while(n--)
    {
        double xa, ya, ra;
        double xb, yb, rb;
        double d;
        
        cin>>xa>>ya>>ra>>xb>>yb>>rb;
        
        d = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); // distance of o1 and o2
        
        if (d > ra + rb)
        {
            cout << "0" << endl;
        }
        else if (d >= abs(ra - rb)) // && ra + rb >= d
        {
            cout << "1" << endl;
        }
        else if (ra > rb) // d < ra - rb
        {
            cout << "2" << endl;
        }
        else
        {
            cout << "-2" << endl;
        }
    }
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1232
#include<iostream>
using namespace std;
string s;
int g(string s);
int f(string s)
{
	int ans=0,pre=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='+')
		{
			ans+=g(s.substr(pre,i-pre));
			pre=i+1;
		}
	}
	return ans;
}
int g(string s)
{
	int ans=1;
	for(int i=0;i<s.size();i++)ans*=s[i]=='*'?1:s[i]-'0';
	return ans;
}
main()
{
	cin>>s;
	int M=f(s+"+");
	int L=s[0]-'0';
	for(int i=1;i<s.size();i++)
	{
		if(s[i]=='+')L+=s[i+1]-'0';
		else if(s[i]=='*')L*=s[i+1]-'0';
	}
	int a;cin>>a;
	cout<<(a==M?a==L?"U":"M":a==L?"L":"I")<<endl;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L; cin>>L;
    int n = 1;
    while(L>=(1<<n)) n++;
    int extra = L-(1<<(n-1));
    int m = 2*(n-1)+__builtin_popcount(extra);
    cout<<n<<" "<<m<<endl;
    rep(i,n-1){
        int j=i+1;
        cout<<j<<" "<<j+1<<" 0\n";
        cout<<j<<" "<<j+1<<" "<<(1<<i)<<"\n";
    }
    int now = 1<<(n-1);
    int idx=0;
    while(extra){
        if (extra&1){
            cout<<(idx+1)<<" "<<n<<" "<<now<<"\n";
            now += 1<<idx;
        }
        idx++;
        extra>>=1;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int MAX = 100001;

class TaskD {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n;
		cin >> n;
		vector<int> values(n), weight(n);
		for(int i = 0; i < n; i++){
			cin >> values[i] >> weight[i];
		}
		int limit = min(1<<9,n);
		vector<vector<int>> dp(limit, vector<int>(MAX, 0));
		for(int i = 0; i < MAX ; i++){
			dp[0][i] = i >= weight[0] ? values[0] : 0;
		}
		for(int u = 1; u < limit; u++){
			int p = (u-1)/2;
			for(int w = 0; w < MAX; w++){
				dp[u][w] = dp[p][w];
				if(w - weight[u] >= 0){
					dp[u][w] = max(dp[u][w], dp[p][w - weight[u]] + values[u]);
				}
			}
		}
			
		int q;
		cin >> q;
		while(q--){
			int u, maxWeight;
			cin >> u >> maxWeight;
			vector<int> nodes;
			while(u-1 >= limit){
				nodes.push_back(u-1);
				u/=2;
			}
			int ans = 0;
			int sz = nodes.size();
			for(int mask = 0; mask < (1<<sz); mask++){
				int w= 0, v = 0;
				for(int i = 0; i < sz; i++){
					if(mask & (1<<i)){
						w += weight[nodes[i]];
						v += values[nodes[i]];
					}
				}
				if(w <= maxWeight){
					ans = max(ans, dp[u-1][maxWeight - w] + v);
				}
			}
			cout << ans << endl;
		}
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 206544
#include <stdio.h>
int main(){
	long int N;
	scanf("%ld", &N);
	long int A[N + 2];
	for(long int i = 1; i <= N; i++){
		scanf("%ld", &A[i]);
	}
	long int  sum = 0;
	for(long int i = 2; i <= N; i++){
		if(A[i-1] > A[i]){
			sum += A[i - 1] - A[i];
			A[i] = A[i - 1];
		}
	}
	printf("%ld", sum);
	return 0;
}

Measured memory_bytes: 3284
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 10010;

int n, m;
vector <pair <int, ll>> e[N];
ll dis[N] = {};
int cnt[N] = {};
bool inque[N] = {};

void spfa(int s)
{
    queue <int> q;
    for(int i = 1; i <= n; ++ i) dis[i] = LLONG_MAX;
    dis[s] = 0;
    q.push(s);
    inque[s] = true;
    cnt[s] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        inque[u] = false;
        for (auto v : e[u])
        {
            if (dis[v.first] > dis[u] + v.second)
            {
                dis[v.first] = dis[u] + v.second;
                if (!inque[v.first])
                {
                    ++ cnt[v.first];
                    if (cnt[v.first] > 2 * n)
                    {
                        //printf("vf = %d\n", v.first);
                        return;
                    }
                    q.push(v.first);
                    inque[v.first] = true;
                }
            }
        }
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0, u, v; i < m; ++ i)
    {
        ll c;
        scanf("%d%d%lld", &u, &v, &c);
        e[u].push_back({v, -c});
    }
    spfa(1);
//    if (dis[n] == LLONG_MAX)
//    {
//        assert(0 == 1);
//    }
    if (cnt[n] > n)
    {
        printf("inf\n");
    }
    else printf("%lld\n", -dis[n]);
    return 0;
}


Measured memory_bytes: 512
N = int(input())
A = [int(i) for i in input().split()]
A.append(0) # dummy


before = A[0]
raising = False
buy = []
sell = []
for i in range(1, len(A)):
  v = A[i]
  if before < v:
    if not raising:
      buy.append(i - 1)
      raising = True
  if v < before:
    if raising:
      sell.append(i - 1)
    raising = False
  before = v

m = 1000
k = 0
for i in range(N):
  v = A[i]
  if i in buy:
    k = m // v
    m = m - k * v
  if i in sell:
    m += k * v
    k = 0
print(m)

Measured memory_bytes: 8952
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String n = fs.next();
		int k = fs.nextInt();
		int len = n.length();
		
		long dp[][][] = new long[len+1][k+1][2]; //最後は未満フラグ（1なら未満）
		dp[0][0][0] = 1;
		for(int i=1;i<=len;i++) {
			int now = n.charAt(i-1)-'0';
			if(now == 0) {
				for(int j=0;j<=k;j++) {
					//0を選ぶ場合
					//未満じゃない-未満じゃない
					dp[i][j][0] += dp[i-1][j][0];
					//未満->未満
					dp[i][j][1] += dp[i-1][j][1];
					if(j+1>k)continue;
					//0以外を選ぶ場合
					//未満->未満
					dp[i][j+1][1] += dp[i-1][j][1] * 9;
				}
			}
			else {
				for(int j=0;j<=k;j++) {
					//0を選ぶ場合
					//未満じゃない-未満
					dp[i][j][1] += dp[i-1][j][0];
					//未満->未満
					dp[i][j][1] += dp[i-1][j][1];
					
					if(j+1>k)continue;
					//0以外を選ぶ場合
					//未満じゃない->未満じゃない
					dp[i][j+1][0] += dp[i-1][j][0];
					//未満じゃない→未満
					dp[i][j+1][1] += dp[i-1][j][0] * (now-1);//0以外の好きな数
					//未満->未満
					dp[i][j+1][1] += dp[i-1][j][1] * 9;
				}
			}
			
			
		}
		long ans = dp[len][k][0] + dp[len][k][1];
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define int long long
using namespace std ;

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

    bool a = false , b = false ;
    string s ;
    cin >> s ;
    for(int i = 0 ; i < 3; ++i)
    {
    	if(s[i] == 'A')
    		a =true; 
    	else 
    		b = true ; 

    }
    if(a && b)
    	cout << "Yes" ;
    else
    	cout << "No" ; 	                                   
}    


















Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    ull a,b,x;
    cin>>a>>b>>x;
    ull ans=b/x-a/x;
    if(a%x==0)ans++;
    cout<<ans;
}


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

ll gcd(int a, int b)
{
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
    int K; cin >>K;
    ll ans=0;
    for (int a=1;a<K+1;a++)
        for (int b=1;b<K+1;b++)
            for (int c=1;c<K+1;c++)
                ans+=gcd(gcd(a,b),c);
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 3624
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void) {

	int A = 0, B = 0, C = 0;
	cin >> A >> B >> C;
	string res;

	if ((A == 5 || A == 7) && (B == 5 || B == 7) && (C == 5 || C == 7) && (A + B + C == 17)) {
		res = "YES";
	}
	else {
		res = "NO";
	}

		cout << res << endl;

	return 0;




}

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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;

  std::vector<int> x(N), y(N);
  rep(i, N) {
    std::cin >> x[i] >> y[i];
  }

  double sum = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = i + 1; j < N; ++j) {
      double dx = (double) (x[i] - x[j]);
      double dy = (double) (y[i] - y[j]);
      sum += std::sqrt(dx * dx + dy * dy);
    }
  }

  std::cout << std::fixed << std::setprecision(10);
  std::cout << sum * 2 / N << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)

template <typename T>
class Seg_Tree{
public: // 0-index
  vector<T> dat;
  T initial,M;
  int n;
  T unite(T a,T b){//
    T c;
    c.first = max(a.first,b.first);
    c.second = min(a.second,b.second);
    return c;
  }
  Seg_Tree(int n0_=1,T initial_=1,T M_=1){
    initsize(n0_,initial_,M_);
  }
  void initsize(int n0,T initial_,T M_){
    M = M_;
    initial = initial_;
    int k=1;
    while(1){
      if(n0<=k){
        n=k;
        dat.resize(2*n-1);
        for(int i=0;i<2*n-1;i++)dat[i]=initial;
        break;
      }
      k*=2;
    }
  }
 
  //i banme wo x nisuru
  void update(int i,T x){
    i += n-1;
    dat[i] = x;
    while(i>0){
      i = (i-1) / 2;
      dat[i] = unite(dat[i*2+1],dat[i*2+2]);
    }
  }
 
  //[a,b)
  T query0(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return initial;
    if(a<=l && r<=b)return dat[k];
    else{
      T vl = query0(a,b,k*2+1,l,(l+r)/2);
      T vr = query0(a,b,k*2+2,(l+r)/2,r);
      return unite(vl,vr);
    }
  }
 
  //return [a,b)
  T query(int a,int b){
    return query0(a,b,0,0,n);
  }
  T ex(int i){
    T x = query(0,i);
    T y = query(i+1,n);
    return unite(x,y);
  }
};

ll len(pair<ll,ll> x){
  return max(0LL,x.second-x.first+1LL);
}

int main(){ 

  ll N,ans=0;
  cin >> N;
  vector< pair<ll,ll> > LR(N);
  FOR(i,0,N)cin>>LR[i].first>>LR[i].second;

  sort(LR.begin(), LR.end());

  vector<ll> fun_big(N+1,0),fun_end(N+1,0);

  ll l = 0,r=1e9+7;
  FOR(i,0,N){
    ans = max(ans,LR[i].second-LR[i].first+1);
    l = max(l,LR[i].first);
    r = min(r,LR[i].second);
    if( r-l+1 <= 0 )continue;
    fun_big[i+1] = r-l+1;
  }

  l = 0,r=1e9+7;
  FORR(i,0,N){
    l = max(l,LR[i].first);
    r = min(r,LR[i].second);
    if( r-l+1 <= 0 )continue;
    fun_end[N-i] = r-l+1;
  }

  FOR(i,1,N){
    ans = max( ans , fun_big[i] + fun_end[N-i]);
  }

  Seg_Tree< pair<ll,ll> > sg(N,make_pair(0,1000000009),make_pair(1,1));

  FOR(i,0,N){
    sg.update(i,LR[i]);
  }

  FOR(i,0,N){
    ans = max(ans,len(LR[i])+len(sg.ex(i)));
  }


  cout << ans << endl;

}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string S;cin >> S;
    int ct = 0;
    bool ok = false;
    if(S == "SSS")cout << 0 << endl;
    if(S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR")cout << 1 << endl;
    if(S == "RRS" || S == "SRR")cout << 2 << endl; 
    if(S == "RRR")cout << 3 << endl;
}

Measured memory_bytes: 3616
import java.util.*;  

public class Main {	
    public static Long gcd(Long x,Long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
    public static Long lcm(Long x,Long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    }
    public static Long df(Long x){                                                              
        if(x==0) return x+1; 
        return 5*df(x-1);
    }
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Long a = sc.nextLong();
        Long b = a-a;
        Long c = b;
        for (Long i=b;df(i+1)<=a/2;i++){c+=(a/2)/df(i+1);}
		System.out.println(c*((a+1)%2));   
	}   
}



Measured memory_bytes: 21716
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){

	int n;
	cin >> n;


	string a, b, c;
	cin >> a >> b >> c;

	int ans = 0;

	for (int i = 0; i < n; i++){

		if (a[i] == b[i] && b[i] == c[i]) continue;

		if (a[i] == b[i] || b[i] == c[i] || a[i] == c[i]){
			ans++;
		} else if (a[i] != b[i] && b[i] != c[i] && a[i] != c[i]){
			ans += 2;
		}
	} 

	cout << ans << endl;




} 


Measured memory_bytes: 256