akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int sum = 0;
		
        String sn = "" + n;
        
        for(String s : sn.split("")) {
          sum += Integer.parseInt(s);
        }
      
		// 出力
		System.out.println(n % sum == 0 ? "Yes" : "No");
	}
}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, MOD = map(int,input().split())
    E = [[] for _ in range(n)]
    nv_to_idx = [{} for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int,input().split())
        u -= 1; v -= 1
        nv_to_idx[u][v] = len(E[u])
        nv_to_idx[v][u] = len(E[v])
        E[u].append(v)
        E[v].append(u)

    # tree DP
    dp = [1] * n
    stack = [(0, -1)]
    while stack:
        v, p = stack.pop()
        if v >= 0:
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            dp[p] = dp[p] * (dp[~v] + 1) % MOD

    # rerooting
    def rerooting(v, p):
        # p-rooted -> dp[p] を v-rooted に modify
        if p != -1:
            idx = nv_to_idx[p][v]
            dp[p] = cum_left[p][idx] * cum_right[p][idx + 1] % MOD

        # monoid に対する cumulative sum を計算
        if cum_left[v] is None:
            k = len(E[v])
            left = [1] * (k + 1)
            right = [1] * (k + 1)
            for i in range(k):
                left[i + 1] = left[i] * (dp[E[v][i]] + 1) % MOD
            for i in range(k - 1, -1, -1):
                right[i] = right[i + 1] * (dp[E[v][i]] + 1) % MOD
            cum_left[v] = left
            cum_right[v] = right

        # dp[v] を v-rooted に modify
        dp[v] = cum_left[v][-1]

    ans = [None] * n
    stack = [(0, -1)]
    cum_left = [None] * n
    cum_right = [None] * n
    while stack:
        v, p = stack.pop()
        if v >= 0:
            rerooting(v, p)
            ans[v] = dp[v]
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            rerooting(p, ~v)

    print(*ans, sep = '\n')
resolve()

Measured memory_bytes: 129584
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
//#include <array>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <stack>
//#include <queue>
#include <numeric>
using ll = long long;
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N; i++)
	{
		cin >> B[i];
	}
	for (int i = 0; i < N; i++)
	{
		cin >> C[i];
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	auto it_C_lb = C.begin();
	vector<ll> dp(N);
	for (int i = 0; i < N; i++)
	{
		it_C_lb = lower_bound(it_C_lb, C.end(), B[i] + 1);
		dp[i] = C.end() - it_C_lb;
	}
	for (int i = N - 1; i >= 1; i--)
	{
		dp[i - 1] += dp[i];
	}
	ll ans = 0;
	auto it_B_lb = B.begin();
	for (int i = 0; i < N; i++)
	{
		it_B_lb = lower_bound(it_B_lb, B.end(), A[i] + 1);
		ans += dp[(int)(it_B_lb - B.begin())];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int no_of_stones, no_of_steps;
    cin >> no_of_stones >> no_of_steps;

    vector <int> height(no_of_stones + 1, 0);
    for(int i = 1; i <= no_of_stones; i++)
        cin >> height[i];

    const int oo = 1e9;
    vector <int> minimum_cost(no_of_stones + 1, oo);
    minimum_cost[1] = 0;

    for(int i = 2; i <= no_of_stones; i++)
    {
        for(int j = i - 1; j >= max(1, i - no_of_steps); j--)
        {
            minimum_cost[i] = min(minimum_cost[i], minimum_cost[j] + abs(height[i] - height[j]));
        }
    }

    cout << minimum_cost[no_of_stones];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M; cin >> N >> M;
  vector<int> v (N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
    v[i]--;
  }
  vector<vector<int>> adj (N, vector<int> ());
  for(int i = 0; i < M; i++){
    int a, b; cin >> a >> b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  vector<int> components (N, -1);
  int c = -1;
  for(int i = 0; i < N; i++){
    if(components[i] == -1){
      c++;
      queue<int> q;
      q.push(i);
      while(!q.empty()){
        int curr = q.front(); q.pop();
        if(components[curr] != -1) continue;
        components[curr] = c;
        for(int j = 0; j < adj[curr].size(); j++){
          q.push(adj[curr][j]);
        }
      }
    }
  }
  int res = 0;
  for(int i = 0; i < N; i++){
    if(components[i] == components[v[i]]){
      res++;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll A, B, V, W, T;
	cin >> A >> V;
	cin >> B >> W;
	cin >> T;
	ll D = abs(A - B);
	ll S = V - W;
	string ans = "NO";
	if (S * T >= D)
		ans = "YES";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
    }
    let s_bytes = s.as_bytes();
    let mut ans = 0;
    let mut cnt = 0;
    for &b in s_bytes {
        if b == b'R' {
            cnt += 1;
            ans = ans.max(cnt);
        } else {
            cnt = 0;
        }
    }
    println!("{}", ans);
}


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

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

  if (N%10==N/10%10 && N%10==N/100%10 ) {
    cout << "Yes" << endl;
  }
 
  else if (N/10%10==N/100%10 && N/10%10==N/1000 ) {
    cout << "Yes" << endl;
     }
  else {
    cout << "No" << endl;
     }
      
}



Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <cassert>

using namespace std;

typedef unsigned int MEMTYPE;

class mybitset {
  MEMTYPE *mem;
  int size;
  bool ismemfree;
public:
  int bitlen(){
    return sizeof(MEMTYPE) * 8;
  }
  mybitset(){
    ismemfree = true;
  }
  void setsize(int size){
    this->size = size;
    mem = new MEMTYPE[size / bitlen() + 1];
    ismemfree = false;
  }
  ~mybitset(){
    if (!ismemfree){
      delete [] mem;
    }
  }
  bool get(int pos){
    MEMTYPE bit = 1 << (pos % bitlen());
    return (mem[pos / bitlen()] & bit) != 0;
  };
  void set(int pos){
    MEMTYPE bit = 1 << (pos % bitlen());
    mem[pos / bitlen()] |= bit;
  };
  void reset(int pos){
    MEMTYPE bit = ~(1 << (pos % bitlen()));
    mem[pos / bitlen()] &= bit;
  }
};

class primer {
  mybitset isprime;
  int max;
public:
  bool getPrime(int number);
  primer(int max);
};

bool primer::getPrime(int number){
  assert(max > number);
  //if (max > number){
    return isprime.get(number);
  //}
  //assert(max * max > number);
  //for(int i = 0; i < max ; i++){
  //  if (isprime.get(i)){
  //    if (number % i == 0){
  //      return false;
  //    }
  //  }
  //}
  return true;
}
primer::primer(int max){
  this->max = max;
  isprime.setsize(max + 1);
  //??¨??????????????????????????§?´???°?????????????????????
  isprime.reset(0);
  isprime.reset(1);
  for(int i = 2; i < max; i++){
    isprime.set(i);
  }
  for(int i = 2; i < sqrt(max); i++){
    if(isprime.get(i)){
      for(int j = 2; i * j < max; j++){
        isprime.reset(i * j);
      }
    }
  }
}


int main(int argc, char const *argv[]) {
  int count;
  cin >> count;
  int prime_count = 0;
  primer p = primer(100000000);
  for (int i = 0; i < count; i++) {
    int number;
    cin >> number;
    if (p.getPrime(number)){
      prime_count++;
    }
  }
  cout << prime_count << endl;
  return 0;
}

/* test code
int main(int argc, char const *argv[]) {
  int count;
  cin >> count;
  int prime_count = 0;
  primer p = primer(20);
  mybitset b;
  b.setsize(100);
  cout << "b.bitlen() = " << b.bitlen() << endl;
  for(int i = 0; i < 20; i++){
    b.set(i);
    if(!b.get(i)){
      cout << "set error "<< i << endl;
    }
  }
  for(int i = 0; i < 20; i++){
    b.reset(i);
    if(b.get(i)){
      cout << "reset error"<< i << endl;
    }
  }
  for(int i = 20; i >= 0; i--){
    b.set(i);
    if(!b.get(i)){
      cout << "set error" << i << endl;
    }
  }
  for (int i = 0; i < count; i++) {
    int number;
    cin >> number;
    if (p.getPrime(number)){
      prime_count++;
    }
  }
  cout << prime_count << endl;
  return 0;
}
*/

Measured memory_bytes: 14896
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
char ch[555555];
int main()
{
    scanf("%s",ch);
    int len=strlen(ch);
    if(ch[0]==ch[len-1])
    {
        if((len-2)%2==0)
        {
            printf("First\n");
        }
        else
        {
            printf("Second\n");
        }
    }
    else
    {
        if((len-2)%2==0)
        {
            printf("Second\n");
        }
        else
        {
            printf("First\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1E5;
int n, s;
int x[N];
LL p[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> s;
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> p[i];
    LL ans = 0;
    int l = 0, r = n - 1;
    int lst = -1;
    while ((x[l] < s) != (x[r] < s)) {
        if (p[l] >= p[r]) {
            if (lst != -1)
                ans += abs(lst - x[r]);
            lst = x[r];
            p[l] += p[r--];
        } else {
            if (lst != -1)
                ans += abs(lst - x[l]);
            lst = x[l];
            p[r] += p[l++];
        }
    }
    if (x[l] > s) {
        if (lst != -1)
            ans += x[r] - lst;
        ans += x[r] - s;
    } else {
        if (lst != -1)
            ans += lst - x[l];
        ans += s - x[l];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> dp(22,vector<long long>((1 << 21),-1));
vector<vector<long long>> x(22,vector<long long>(22));
long long n;

long long ans(long long curr , long long val){
    if(val == 0){
        return 1;
    }
    if(dp[curr][val] != -1){
        return dp[curr][val];
    }
    long long ret = 0;
    for(int i = 0 ; i < n ; i += 1){
        if(val & (1 << i) && x[curr][i] == 1){
            ret += ans(curr + 1 , val - (1 << i));
        }
    }
    dp[curr][val] = ret;
    dp[curr][val] %= 1000000007;
    return ret;
}

int main()
{
    cin >> n;
    for(int i = 0 ; i < n ; i += 1){
        for(int j = 0 ; j < n ; j += 1){
            cin >> x[i][j];
        }
    }
    long long val = (1 << n)-1;
    cout << ans(0,val)%1000000007;
}

Measured memory_bytes: 377216
#include <stdio.h>

int main()
{
	bool board[8][8]{};
	for (int i{}; i < 8; i++)
	{
		for (int j{}; j < 8; j++)
		{
			if (i % 2 == 0 && j % 2) continue;
			board[i][j] = true;
		}
	}
	int q;
	scanf("%d", &q);
	for (int i{}; i < q; i++)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		a--; b--; c--; d--;
		int count{};
		for (int row{ a }; row <= c; row++)
			for (int col{ b }; col <= d; col++)
				count += board[row][col];
		printf("%d\n", count);
	}
	return 0;
}


Measured memory_bytes: 2748
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 100010
#define MO 1000000007
#define LL long long
int x[MAXN],n,m;
bool vis[MAXN];
void task1()
{
	static int dp[100010][3];
	dp[0][0]=1;
	for(int i=1;i<=m;i++)
		vis[x[i]]=1;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0];
		dp[i][1]=(dp[i-1][0]+dp[i-1][1])%MO;
		dp[i][2]=((dp[i-1][0]+dp[i-1][1])%MO+(dp[i-1][1]+dp[i-1][2])%MO)%MO;
		if(!vis[i-1])
		{
			dp[i][0]=(dp[i][0]+dp[i-1][2])%MO;
			dp[i][1]=(dp[i][1]+dp[i-1][2])%MO;
			dp[i][2]=(dp[i][2]+dp[i-1][2])%MO;
		}
	}
	printf("%d\n",dp[n][2]);
}
struct node
{
	LL a[3][3];
}A,C,a,b,c,tmp;
void Mul(node &ret,node X,node Y)
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			tmp.a[i][j]=0;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				tmp.a[i][j]=(tmp.a[i][j]+X.a[i][k]*Y.a[k][j]%MO)%MO;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			ret.a[i][j]=tmp.a[i][j];
}
void Pow(int X)
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			c.a[i][j]=C.a[i][j];
	while(X)
	{
		if(X&1) Mul(a,a,c);
		Mul(c,c,c);
		X>>=1;
	}
}
int f[3],g[3];
int main()
{
//	freopen("placing.in","r",stdin);
//	freopen("placing.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&x[i]);
	memset(A.a,0,sizeof A.a);
	memset(C.a,0,sizeof C.a);
	A.a[0][0]=A.a[1][1]=A.a[2][2]=A.a[1][2]=A.a[0][2]=1;
	A.a[0][1]=2;
	C.a[0][2]=C.a[1][0]=C.a[1][1]=C.a[1][2]=C.a[2][0]=C.a[2][2]=1;
	C.a[0][0]=C.a[0][1]=2;
	f[0]=1;
	x[++m]=n;
	for(int l=1,pos=0;l<=m;l++)
	{
		int k=x[l]-pos-1;
		memset(b.a,0,sizeof b.a);
		memset(a.a,0,sizeof a.a);
		for(int i=0;i<3;i++)
			a.a[i][i]=1;
		if(k) Pow(k);
		Mul(b,a,A);
		for(int i=0;i<3;i++)
		{
			g[i]=0;
			for(int j=0;j<3;j++)
				g[i]=(g[i]+f[j]*b.a[j][i]%MO)%MO;
		}
		for(int i=0;i<3;i++)
			f[i]=g[i];
		pos=x[l];
	}
	printf("%d\n",f[2]);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    ll x,y;cin>>x>>y;
    ll ans=0;
    for(ll i=x;i<=y;i*=2){
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(input())
t = list(input())
ss = [s,t]
n = len(s)
res = [[],[]]
for i in range(2):
    d = defaultdict(int)
    cnt = 1
    for j,x in enumerate(ss[i]):
        if d[x] == 0:
            d[x] = cnt
            cnt += 1
        res[i].append(d[x])
print('Yes' if res[0] == res[1] else 'No')

Measured memory_bytes: 103044
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>
 
using namespace std;
 
typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;
 
vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}
 
//#define DEBUG
 
ll A, B, M, N, D, K, L, Q, W, H, T, X, Y, S;
 
int main()
{
    string str;cin >> str;
    if (str[0] == '9' || str[1] == '9') {
        cout << "Yes" << endl;
    } else
        cout << "No" << endl;
 
    return 0;
}

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



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

    int s[n];
    for(int i=0;i<n;i++){
        cin >> s[i];
    }

    int q;
    cin >> q;


    vector< pair<int,bool> > t(q);
    for(int i=0;i<q;i++){
        int c;
        cin >> c;

        t[i] = make_pair(c,true);
    }


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



    int ans = 0;


    for(int i=0;i<n;i++){
        int x = s[i];
        int f = 0;
        int e = q-1;

        while(f<=e&&f>=0){
            int c = (f+e)/2;
            if(x==t[c].first&&t[c].second){
                t[c].second = false;
                ans++;
                break;
            }else if(t[c].first<x){
                f = c+1;
            }else{
                e = c-1;
            }
        }
    }

    cout << ans << endl;
}


/*if(x==t[j].first&&t[j].second){
                t[j].second = false;
                ans++;
                break;
            }*/


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

using namespace std;

#define int long long

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    if (n > m) swap(n, m);
    if (m == 1) {
        cout << 1;
        exit(0);
    }
    if (n == 1) {
        cout << m - 2;
        exit(0);
    }
    cout << n * m - 2 * (n + m) + 4 << '\n';
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int selectionSort(int A[], int N) {
  int swap = 0;
  for (int i = 0; i < N - 1; i++) {
    int min = i;
    int flag = 0;
    for (int j = i + 1; j < N; j++) {
      if (A[j] < A[min]) {
        min = j;
        flag = 1;
      }
    }
    if (flag) {
      int tmp = A[i];
      A[i] = A[min];
      A[min] = tmp;
      swap++;
    }
  }
  return swap;
}

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

int main(void) {
  int N;
  scanf("%d", &N);
  int A[N];
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  int swap = selectionSort(A, N);
  printArr(A, N);
  printf("%d\n", swap);

  return 0;
}


Measured memory_bytes: 2060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, R;
  cin >> N >> R;

  ll ans = R;
  if (N < 10) {
    ans = R + 100 * (10 - N);
  }

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


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
	int n; cin >> n;
  vector<double> a(n);
  vector<double> b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));
  if(n%2==1){
    ll ans=b[n/2]-a[n/2]+1;
    cout << ans << endl;
    return 0;
  }
  double left=(a[n/2-1]+a[n/2])/2;
  double right=(b[n/2-1]+b[n/2])/2;
  ll ans=(right-left)*2+1;
  cout << ans << endl;
	
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N, N2;
int xs[1<<20];
int solve(int i){
  if(i >= N2) return xs[i];
  int l = solve(i*2), r = solve(i*2+1);
  return (r==l?r: max(r,l) - min(r,l));
}

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

  cin >> N;
  N2 = 1 << N;
  REP(i,N2) cin >> xs[N2+i];

  cout << solve(1) << endl;

  return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, char> pic;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}


void solv() {
	
	int n;
	cin >> n;
	ll a[22];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	ll dp[40010];
	memset(dp, -1, sizeof(dp));
	dp[0] = 1;
	for (size_t i = 0; i < n; i++)
	{
		for (int j = 40000; j >= 0; j--)
		{
			if (j + a[i] <= 40000 && dp[j] != -1) {
				dp[j + a[i]] = 1;
			}
		}
	}

	int q;
	cin >> q;
	for (size_t i = 0; i < q; i++)
	{
		int v;
		cin >> v;
		if (dp[v] == 1) {
			cout << "yes" << endl;
		}
		else cout << "no" << endl;
	}
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 3392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


ll par[1000000];
ll Rank[1000000];

void init(ll n){
    rep(i,1,n){
        par[i]=i;
        Rank[i]=0;
    }
}

ll find(ll x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}

void unite(ll x,ll y){
    x=par[x];
    y=par[y];
    if(x==y)return ;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(Rank[x]==Rank[y]){
            Rank[x]++;
        }
    }
    
}

bool same(ll x,ll y){
    return find(x)==find(y);
}


struct edge{ ll u,v,cost; };
bool comp(edge e1,edge e2){
    return e1.cost<e2.cost;
}
edge es[1000000];   //0~(E-1)
ll V,E;
ll kruskal(){
    sort(es,es+E,comp);
    init(V);
    ll res=0;
    rep(i,0,E-1){
        edge e=es[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res+=e.cost;
        }
    }
    return res;
}

int main(){
    cin>>V>>E;
    edge e;
    rep(i,0,E-1){
        cin>>e.u>>e.v>>e.cost;
        es[i]=e;
    }
    cout<<kruskal()<<endl;
    
    return 0;
}



Measured memory_bytes: 5612
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64
    }

    if n >= 1000 {
        println!("ABD");
    } else {
        println!("ABC");
    }
}

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

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

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


Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct Edge{
	int v,nxt;
}e[200010];int tot;
int first[100010];
int deg[100010];
void build(int u,int v)
{
	e[++tot]=(Edge){v,first[u]};
	first[u]=tot;
	deg[u]++;
	return ;
}
char col[100010];
bool book[100010];
int val[100010];
int n;
int dis[100010];
void dfs(int u,int lst,int& T,int& mxdis)
{
	if(book[u])return ;
	dis[u]=dis[lst]+val[u];
	if(dis[u]>=mxdis){
		mxdis=dis[u];
		T=u;
	}
	for(int i=first[u];i;i=e[i].nxt)
		if(e[i].v!=lst)
			dfs(e[i].v,u,T,mxdis);
	return ;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		build(u,v);
		build(v,u);
	}
	scanf("%s",col+1);
	queue<int>q;
	for(int i=1;i<=n;i++)
		if(col[i]=='B'&&deg[i]<=1)
			q.push(i);
	while(!q.empty())
	{
		int u=q.front();
		book[u]=true;
		q.pop();
		for(int i=first[u];i;i=e[i].nxt)
		{
			deg[e[i].v]--;
			if(deg[e[i].v]==1&&col[e[i].v]=='B')
				q.push(e[i].v);
		}
	}
	int s=0,cnt=0;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(book[i])continue;
		s=i;cnt++;
		int need=col[i]=='W';
		if(need==(deg[i]&1))val[i]=0;
		else val[i]=2,ans++;
	}
	ans+=2*(cnt-1);
	if(!cnt){
		printf("0\n");
		return 0;
	}
	if(cnt==1){
		printf("1\n");
		return 0;
	}
	int t=0,mxdis=0;
	dfs(s,0,t,mxdis);
	s=t;
	mxdis=0;
	dfs(s,0,t,mxdis);
	ans-=mxdis;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define ll unsigned long long
#define MAX 100000

using namespace std;


int n;
ll ha[200];
ll i,j,a,k;

ll gcd(ll a,ll b)
{
    ll r=0;
    while(b!=0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return(a);
}

int main()
{
   // freopen("in.txt","r",stdin);
    cin>>n;
    cin>>k;
    n--;
    while(n--)
    {
        cin>>a;
        ll jj,kk,aa;
        kk=k;
        aa=a;
        j=k*a;
        while(k!=0)
        {
            i=a%k;
            a=k;
            k=i;
        }
        //cout<<"gcd="<<a<<endl;

        k=kk/a;
        k=k*aa;
        //cout<<k<<endl;
    }
    cout<<k<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x=1000000000000000000,ans=1;
long long a[1000000];
int n;
int main(){
  scanf("%d", &n);
  for(int i=0;i<n;i++) {
      scanf("%lld", &a[i]);
      if(a[i]==0){
	      printf("0"); 
		  return 0;
	  }
  }      
  for(int i=0;i<n;i++){
    if(x<a[i]){ 
	   printf("-1"); 
	   return 0;
	}
    else {
      ans*=a[i];
      x /= a[i];
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 4580
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long int n,m;
vector<long int> a[100001];
long long int dp[100001]={0};
bool vis[100001]={0};
void dfs(long int x)
{
    for(long int i=0;i<a[x].size();i++)
    {
        if(vis[a[x][i]]==0)
        {
            vis[a[x][i]]=1;
            dfs(a[x][i]);
        }
        dp[x]=max(dp[x],1+dp[a[x][i]]);
    }
}
int main() {
    cin>>n>>m;
    long int b,c;
    for(long int i=0;i<m;i++)
    {
        cin>>b>>c;
        a[b].push_back(c);
    }
    for(long int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            vis[i]=1;
            dfs(i);
        }
    }
    long long int ans=0;
    for(long int i=1;i<=n;i++)
    ans=max(ans,dp[i]);
    cout<<ans;
}

Measured memory_bytes: 8576
# seishin.py
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())

M = 32
MOD = [(2 << i) for i in range(M+1)]

from bisect import bisect
def make(B, mode):
    S = [None]*M
    s = {}; get = s.get
    for b in B:
        s[b] = get(b, 0) ^ 1
    S[M-1] = sorted(b for b in s if s[b])

    for i in range(M-2, -1, -1):
        t = S[i+1]; l = len(t)
        m = MOD[i]
        mid = bisect(t, m-1)
        def gen(p, q):
            while p < mid and q < l:
                u = t[p]; v = t[q]
                if u+m == v:
                    p += 1; q += 1
                elif u+m < v:
                    yield t[p]; p += 1
                else:
                    yield t[q]-m; q += 1
            while p < mid:
                yield t[p]; p += 1
            while q < l:
                yield t[q]-m; q += 1
        *S[i], = gen(0, mid)
    if mode:
        for i in range(M):
            m = MOD[i]
            S[i] += list(map(lambda x: x+m, S[i]))
    return S
S = make(A, 0)
T = make(B, 1)

ans = 0
if 0 in S[0]:
    ans ^= 1 in T[0]
if 1 in S[0]:
    ans ^= 0 in T[0]

for i in range(1, M):
    s = S[i]; ls = len(S)
    t = T[i]; lt = len(t)
    m = MOD[i]; p = MOD[i-1]
    P = p+m; Q = 2*m

    if lt:
        c = 0
        f = lt
        while P <= t[f-1]:
            f -= 1

        u = f; v = lt
        for a in s:
            while u > 0 and P <= a + t[u-1]:
                u -= 1
            while v > 0 and Q <= a + t[v-1]:
                v -= 1
            c += (v - u)
        if c & 1:
            ans ^= 1 << i
print(ans)

Measured memory_bytes: 193308
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(d + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        last[t[i]] = i;

        for (int j = 1; j <= 26; j++)
        {
            ans -= c[j] * (i - last[j]);
        }
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    // printf("%lld\n", scoring(BestT));

    double BestScore = scoring(BestT);

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1);

    double T0 = 1e6;
    double T1 = 1;
    double TL = 1950;

    while (1)
    {
        auto end = chrono::system_clock::now(); // 計測終了時刻を保存
        auto dur = end - start;                 // 要した時間を計算
        auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();

        if (msec >= 1950)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        double score = scoring(t);

        if (exp((score - BestScore) / T) > 0.5)
        {
            BestT = t;
            BestScore = score;
        }
    }

    for (int i = 1; i <= d; i++)
    {
        printf("%d\n", BestT[i]);
    }

    // printf("%lld\n", scoring(BestT));
}


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

unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

int main()
{
    long int n,root,div,maxnumber,keep;
    cin >> n;
    root = (int)sqrt(n);
    keep = 11;

    for (int i = 1; i <= root; i++)
    {
        div = n / i;
        if (n % i == 0)
        {
            maxnumber = max(GetDigit(i),GetDigit(div));
            keep = min(keep,maxnumber);
        }
    }
    cout << keep << endl;
}   

Measured memory_bytes: 3852
#include<stdio.h>

int main(void){
  int A,B,C,D;
  scanf("%d %d %d %d\n",&A,&B,&C,&D );
  while(1){
    C -= B;
    if(C <= 0){
      printf("Yes\n" );
      break;
    }
    A -= D;
    if(A <= 0){
      printf("No\n" );
      break;
    }
  }
  return 0;
}

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

int n;
string s, t;

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

  int l = 0;
  for (int i = 0; i < s.size(); i++){
    if (s[i] == t[l]){
      l++;
    }
  }

  cout << s.size() + t.size() - l << endl;
}


Measured memory_bytes: 256
/*#include<cstdio>
#include<iostream>
#define MAX_N 100000000

using namespace std;

long long int dp[45][45];

int main(){

   while(1){
        int w,h;
        int i;
        cin>>w>>h;
        if(w==0&&h==0)break;
        for(int i=0;i<45;i++){
            for(int j=0;j<45;j++){
                dp[i][j]=0;
            }
        }
        dp[1][1]=1;
        int n;
        cin>>n;
        int x,y;
        for(i=0;i<n;i++){
            cin>>x>>y;
            dp[x][y]=-1;
        }
        for(int i=1;i<=w;i++){
            for(int j=1;j<=h;j++){
                if(i<=w&&dp[i][j]!=-1){
                    dp[i+1][j]+=dp[i][j];
                }
                if(j<=h&&dp[i][j]!=-1){
                    dp[i][j+1]+=dp[i][j];
                }
               printf("[%d] [%d] %lld\n",i,j,dp[i][j]);
            }
        }
        printf("%d\n",dp[w][h]);
    }
    return 0;
}*/

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b;
    while( cin >> a >> b , a || b ){
            int n, dp[20][20] = {0};
            dp[1][1] = 1;
            cin >> n;
            for(int i=0 ; i < n ; i++ ){
                int x,y; cin >> x >> y;
                dp[y][x] = -1;
            }
                for(int y=1 ; y <= b ; y++ ){
                        for(int x=1 ; x <= a ; x++ ){
                            if( dp[y][x] != -1 ){
                                if( y != 1 && dp[y-1][x] != -1 ){
                                    dp[y][x] += dp[y-1][x];
                            }
                            if( x != 1 && dp[y][x-1] != -1 ){
                                    dp[y][x] += dp[y][x-1];
                            }
                        }
                    }
                }
            cout<<dp[b][a]<<endl;
        }
    }

Measured memory_bytes: 1160
def ceil(X, Y):  # 天井関数 ceil(X/Y) Y>1
    return (X + Y - 1) // Y


n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]

t, a = 1, 1
for ti, ai in ta:
    tmp = max(ceil(t, ti), ceil(a, ai))
    t, a = ti * tmp, ai * tmp
print(t + a)


Measured memory_bytes: 73856
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        a: i64, b: f64,
    }
    let q = a / 100;
    let a = a % 100;
    let b100 = (b * 100.0 + 0.5).floor() as i64;
    let add = a * b100 / 100;
    puts!("{}\n", q * b100 + add);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2792
#include<cstdio>
#include<iostream>
using namespace std;
int n, c, num[5][1005], C[1005][1005], d[1005][1005];
int calc (int x, int y, int z) {
	int sum = 0;
	for (int j = 1; j <= c; j++)
		sum += d[j][x] * num[0][j] + d[j][y] * num[1][j] + d[j][z] * num[2][j];
	return sum;
}
int main() {
	cin >> n >> c;
	for (int i = 1; i <= c; i++)
		for (int j = 1; j <= c; j++)
			cin >> d[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			cin >> C[i][j];
			num[ (i + j) % 3][C[i][j]]++;
		}
	int ans = 0x7fffffff;
	for (int i = 1; i <= c; i++)
		for (int j = 1; j <= c; j++)
			for (int k = 1; k <= c; k++) {
				if (i == j || k == j || i == k) continue;
				ans = min (ans, calc (i, j, k));
			}
	cout << ans << endl;
}

Measured memory_bytes: 4608
import sys

s = sys.stdin.readline().rstrip()

flag = True
for i in range(len(s)//2):
    if s[i] != s[-i-1]:
        flag = False

if flag:
    a = s[0:(len(s)-1)//2]
    b = s[(len(s)+1)//2:]
    for i in range(len(a)//2):
        if a[i] != a[-i-1]:
            flag = False
    for j in range(len(b)//2):
        if b[j] != b[-j-1]:
            flag = False

print('Yes' if flag else 'No')


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

int main(){
    int n;
    cin >> n;
    if(n < 1200) {
        cout << "ABC" << endl;
        return 0;
    }
    else if(n < 2800) {
        cout << "ARC" << endl;
        return 0;
    }
    cout << "AGC" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;

const int MOD=1000000007;

int main(){
  int N;
  N=2000010;

  vector<ll> fac(N);
  vector<ll> inv(N);
  vector<ll> facinv(N);
  
  fac[0]=fac[1]=1;
  facinv[0]=facinv[1]=1;
  inv[1]=1;

  for(int i=2;i<N;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    facinv[i]=facinv[i-1]*inv[i]%MOD;
  }

  int K;
  cin >> K;
  string S;
  cin >> S;

  vector<ll> p26(K+1);
  p26[0]=1;
  vector<ll> p25(K+1);
  p25[0]=1;
  for(int i=1;i<=K;i++){
    p26[i]=p26[i-1]*26%MOD;
    p25[i]=p25[i-1]*25%MOD;
  }

  ll ans=0;
  for(int i=0;i<=K;i++){
    ll tmp=1;
    tmp*=p26[i]*p25[K-i]; tmp%=MOD;
    tmp*=fac[S.size()-1+K-i]; tmp%=MOD;
    tmp*=facinv[S.size()-1]; tmp%=MOD;
    tmp*=facinv[K-i]; tmp%=MOD;
    ans+=tmp; ans%=MOD;
  }

  cout << (ans+MOD)%MOD << endl;

  return 0;
}


Measured memory_bytes: 66888
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

mat memo(301, vec(301, -1)), dp(301, vec(301, -1));
ll dfs(int l, int r){
    if(l == 0 || r == 0) return 0;
    if(dp[l - 1][r - 1] != -1) return dp[l - 1][r - 1];
    return dp[l - 1][r - 1] = (min(dfs(l - 1, r), dfs(l, r - 1)) + memo[l - 1][r - 1]);
}

ll solve(string s, string t){
    //l >= r
    rep(i,H){
        int res = 0;
        rep(j, H - i) memo[i+j][j] = (res += s[i+j] == t[j]);
    }
    //l <= r
    rep(i,H){
        int res = 0;
        rep(j, H - i) memo[j][i+j] = (res += s[j] == t[i+j]);
    }
    rep(i,H) rep(j,H) dp[i][j] = -1;
    return dfs(H, H);
}

int main(){
    vector<string> block(301,"");
    cin>>H>>W;
    char c;
    rep(i,H) rep(j,W) cin>>c, block[j].push_back(c);
    ll ans = 0;
    rep(i,W - 1) ans += solve(block[i+1], block[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 1920
n = gets.chomp.to_i
array = gets.split(" ").map(&:to_i)
count = 0
move = 0
i = 0

while i + 1 < array.size do
    if array[i] >= array[i+1]
        count += 1
    else
        count = 0
    end

    if move <= count
        move = count
    end
    i += 1
end

puts move


Measured memory_bytes: 8580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

 ll n,c=0; cin>>n;
 ll a[n+1];
 for(ll i=0;i<n;i++)
 {
     cin>>a[i];
 }
 sort(a,a+n);
 for(ll i=0;i<n;i++)
 {
     for(ll j=i+1;j<n;j++)
     {
         if(a[i]!=a[j]){
         for(ll k=j+1;k<n;k++)
         {
             if(a[j]!=a[k]){
                    if(a[i]+a[j]>a[k])
                    {
                        c++;
                    }
            }

}
}
     }
     }
      

cout<<c<<endl;

}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int N,T;
	cin >> N >> T;
	int t=0;
	int pre=0;
	ll ans=0;
	cin >> t;
	for(int i=1; i<N; i++){
		cin >>t;
		if(t-pre>T){
			ans += T;
		}else{
			ans += t-pre;
		}
		pre = t;
	}

	ans += T;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

VL cand;

void dfs(string s){
    int len = s.length();
    cand.eb(stoll(s));
    if(len == 10) return;

    int last = s[len-1] - '0';

    REP(i,10){
        if(abs(last-i) >= 2) continue;
        string ns = s + to_string(i);
        dfs(ns);
    }

}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    LL K; cin >> K;
    FOR(i,1,10){
        dfs(to_string(i));
    }
    sort(cand.begin(),cand.end());

    cout << cand[K-1] << endl;
    

}


Measured memory_bytes: 2420
N, M, *XYZ = map(int, open(0).read().split())

A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    A[0].append(x + y + z)
    A[1].append(x + y - z)
    A[2].append(x - y + z)
    A[3].append(x - y - z)
    A[4].append(-x + y + z)
    A[5].append(-x + y - z)
    A[6].append(-x - y + z)
    A[7].append(-x - y - z)

cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))

print(max(cand))

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

int main(){
  int N, X;
  cin >> N >> X;
  int L[N];
  int D[N]={0};
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  
  for(int j=1; j<N+1; j++){
    D[j] = D[j-1] + L[j-1];
    if(D[j] == X){
      cout << j+1;
      return 0;
    }else if(D[j] > X){
      cout << j;
      return 0;
    }
  }
  
  if(D[N] < X){
      cout << N+1;
      return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
int m,n;
cin >> n;
map<string,int>mp;
string tmp[200];
for(int i=0;i<n;i++){
cin >> tmp[i];
mp[tmp[i]]++;
}
cin >> m;
for(int i=0;i<m;i++){
cin >> tmp[n];
mp[tmp[n]]--;
}
int max=0;
for(int i=0;i<n;i++)
if(mp[tmp[i]]>max)
max=mp[tmp[i]];
cout << max << endl;

return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();
        
        int sum = 0;
        
        if(op.equals("+")){
            sum =  a + b;
        }else if(op.equals("-")){
            sum = a - b;
        }
        
        
        System.out.println(sum);
	}
}

Measured memory_bytes: 21716