akhauriyash/Code-Regression huggingface dataset:
// Marcin Knapik
#include<bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< pair<int, int> , null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
#define losuj_real(a, b) uniform_real_distribution<long double>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second
 
template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }
  
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll N = 1e6+7;
const ll T = 1<<20;
const ll BIG_INF = 1e18 + 7;

ll n, m, k, q;
	
ll dp[N];

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

    cin >> n >> k;

    vi tab(n);
    cin >> tab;

    for(int i = 1; i <= k; i++)
    	for(auto&u:tab)
    		if(i - u >= 0 && !dp[i-u])
    			dp[i] = 1;
    
    cout << (dp[k] ? "First\n" : "Second\n");
}

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

int main() {
	vector<pair<int, int> > pairs;
	string s = "ABCDE";

	bool ok = true;
	
	while (ok) {
		int max_v = 0, max_n = 0;

		for (int i = 0; i < 5; ++i) {
			int val1, val2;
			cin >> val1 >> val2;

			if (val1 == 0 && val2 == 0) {
				ok = false;
				break;
			}

			int all = val1 + val2;

			if (all > max_v) {
				max_v = all;
				max_n = i;
			}
		}

		if(ok != false) pairs.push_back(make_pair(max_n, max_v));
	}

	for (int i = 0; i < pairs.size(); ++i) {
		cout << s[pairs[i].first] << " " << pairs[i].second << endl;
	}

}



Measured memory_bytes: 3216
import sys
from collections import defaultdict
sys.setrecursionlimit(2*10**6)
class UF():
    def __init__(self, num):
        self.par = [-1]*num
        self.size = [1]*num
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
                self.size[rx] += self.size[ry] 
            elif self.par[rx] > self.par[ry]:
                self.par[rx] = ry
                self.size[ry] += self.size[rx]
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
                self.size[rx] += self.size[ry]
        return



N = int(input())

XY = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
X, Y = list(map(list, zip(*XY)))
G = UF(N)
checked = [False]*N

Xc = defaultdict(list)
Yc = defaultdict(list)
for i in range(N):
    Xc[X[i]].append(i)
    Yc[Y[i]].append(i)

for v in Xc.values():
    if len(v) == 1:
        continue
    vx = v[0]
    for x in v[1:]:
        G.union(vx, x)

for v in Yc.values():
    if len(v) == 1:
        continue
    vy = v[0]
    for y in v[1:]:
        G.union(vy, y)

ans = -N

Zx = defaultdict(set)
Zy = defaultdict(set)
for i in range(N):
    ri = G.find(i)
    Zx[ri].add(X[i])
    Zy[ri].add(Y[i])

for i in range(N):
    ri = G.find(i)
    if checked[ri] == True:
        continue
    checked[ri] = True
    ans += len(Zx[ri])*len(Zy[ri])
print(ans)

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> ret(N);
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      int dist = j - i;
      dist = min(dist, abs(i - X) + abs(j - Y) + 1);
      dist = min(dist, abs(i - Y) + abs(j - X) + 1);
      ret[dist - 1]++;
    }
  }
  for (int i = 0; i < N - 1; i++) cout << ret[i] << endl;
}

Measured memory_bytes: 256
import math
y, k, d = map(int, input().split())
if y >= 0:
    x = y
else:
    x = -y
i = math.floor(x / d)
if i >= k:
    p = x - k * d
elif i == x / d:
    if i + k == 2 * int((i + k) / 2):
        p = 0
    else:
        p = d
else:
    if (2 * i + 1) * d == 2 * x:
        p = x - i * d
    else:
        if i + k == 2 * int((i + k) / 2):
            p = x - i * d
        else:
            p = (i + 1) * d - x
print(int(p))

Measured memory_bytes: 9128
#include <iostream>
#include <math.h>
#include <algorithm>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)
#define INF 1000000000000001

using namespace std;

int main()
{
    ll n, num_people[5], ans = 0;
    ll min_num = INF;
    cin >> n;
    REP(i,5){
        cin >> num_people[i];
        if(num_people[i] < min_num) min_num = num_people[i];
    }
    if(n % min_num == 0){
        ans = 5 + (n / min_num - 1);
    }else{
        ans = 5 + (n / min_num);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N;
  char S[102],T[102];
  scanf("%d\n",&N);
  scanf("%s %s",S,T);
  for(int i=0;i<N;i++){
    printf("%c",S[i]);
    printf("%c",T[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1660
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String line = sc.nextLine();
			Scanner s = new Scanner(line);
			int[] a = new int[5];
			for (int i=0 ; i<5 ; i++){
			a[i] = s.nextInt(); }
			Arrays.sort(a);
			printReverse(a);
		}
	}
	static void printReverse(int[] a) {
		for (int i = a.length - 1; i >= 0; i--) {
			System.out.print(a[i]);
			if (i == 0)
				break;
			System.out.print(" ");
		}
		System.out.println();
	}
}

Measured memory_bytes: 17376
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, K, Q): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let A: Vec<usize> = (0..Q)
        .map(|_| {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.trim().parse().unwrap()
        })
        .collect();

    let mut s = vec![0; N + 1];
    for &a in &A { s[a] += 1; }
    let ans = (1..(N + 1)).map(|i|
        if K + s[i] > Q { "Yes"} else { "No" }
    )
    .collect::<Vec<_>>()
    .join("\n");

    println!("{}", ans);
}


Measured memory_bytes: 8828
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const ll MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }

struct ModCombination {
    vector<unsigned int> F;
    ModCombination(unsigned int n) : F(n+1, 1){
        for(unsigned int i=1; i <= n; i++){
            F[i] = 1LL * F[i-1] * i % MOD;
        }
    }
    unsigned int operator()(unsigned int a, unsigned int b){
        if(b > a) return 0;
        return 1LL * F[a] * mod_pow(F[b], MOD-2, MOD) % MOD * mod_pow(F[a-b], MOD-2, MOD) % MOD;
    }
};

int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    ModCombination mc(H+W);
    int ans = 0;
    for(int i=B+1; i<=W; i++){
        ans += ((int64_t)mc(H-A+i-2, i-1) * mc(W-i+A-1, A-1)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
v = list(map(int, input().split()))

odev = [{}, {}]

for i in range(N):
  odev[i%2][v[i]] = odev[i%2].get(v[i],0) + 1

for i in range(2):
  odev[i] = sorted(odev[i].items(), key=lambda x: x[1], reverse=True)

sameChr = odev[0][0][0] == odev[1][0][0]
odev = [list(map(lambda x: x[1], odev[0])), list(map(lambda x: x[1], odev[1]))]

if(sameChr):
  if(len(odev[0]) > 1 and len(odev[1]) > 1):
    print(N - max(odev[0][1] + odev[1][0], odev[0][0] + odev[1][1]))
  elif(len(odev[0]) == 1 and len(odev[1]) == 1):
    print(N // 2)
  elif(len(odev[0]) == 1):
    print(N - odev[0][0] + odev[1][1])
  else:
    print(N - odev[0][1] + odev[1][0])
else:
  print(N - odev[0][0] - odev[1][0])

Measured memory_bytes: 19292
n, m = map(int, input().split())
E = [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]

V = [[] for _ in range(n)]
for a, b in E:
    V[a].append(b)
    V[b].append(a)

def dfs(a, b, f):
    if vis[f] == 1: return
    vis[f] = 1
    for t in V[f]:
        if f==a and t == b: continue
        dfs(a, b, t)

ans = 0
for a, b in E:
    vis = [0]*n
    dfs(a, b, a)
    if vis[b] == 0: ans += 1
print(ans)


Measured memory_bytes: 9172
function main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var cnt = 0;
    if(b==100) b++;
    console.log(Math.pow(100,a)*b);
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include<stdio.h>
#include<stdlib.h>
main()
{
        int i, h, *a;
        scanf("%d", &h);
        a = (int*)malloc(sizeof(int) * h);
        for (i = 0; i < h; i++) {
                scanf("%d", &a[i]);
        }
        for (i = 0; i < h; i++) {
                printf("node %d: key = %d, ", i + 1, a[i]);
                if (i) {
                        printf("parent key = %d, ", a[(i + 1) / 2 - 1]);
                }
                if ((i + 1) * 2 <= h) {
                        printf("left key = %d, ", a[(i + 1) * 2 - 1]);
                }
                if ((i + 1) * 2 + 1 <= h) {
            printf("right key = %d, ", a[(i + 1) * 2]);
        }
                putchar('\n');
        }
        free(a);
}

Measured memory_bytes: 1776
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    b=100;
    for(i=1; ; i++){
        b=b+b/100;
        if(b>=a){
            cout<<i;
            return 0;
        }
    }
    return 0;
}
//1000000000000000000

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


//template<class T>
//inline bool chmax(T &a, T b) {
//    if (a < b) {
//        a = b;
//        return true;
//    }
//    return false;
//}

ll inf = 10000000;
ll mod = 1000000007;

int main() {
    int A, P;
    cin >> A >> P;
    cout << (3 * A + P) / 2 << endl;
}


Measured memory_bytes: 256
import sys

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

def main():
    dp = [0, 1]
    for d in n:
        d = int(d)
        dp[0], dp[1] = min(dp[0]+d, dp[1]+10-d), min(dp[0]+d+1, dp[1]+10-d-1)

    return dp[0]

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 5492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    deque<ll> d;
    rep(i, n)
    {
        d.push_back(a[i]);
    }
    ll ans = 0;
    vector<P> x;
    while (d.size() > 1)
    {
        ll a = d.front();
        ll b = d.back();
        d.pop_front();
        d.pop_back();
        if (d.size())
        {
            if (d.front() > 0)
            {
                d.push_front(a - b);
                x.push_back(P(a, b));
            }
            else
            {
                d.push_back(b - a);
                x.push_back(P(b, a));
            }
        }
        else
        {
            ans = b - a;
            x.push_back(P(b, a));
        }
    }
    cout << ans << endl;
    rep(i, n - 1)
    {
        cout << x[i].first << " " << x[i].second << endl;
    }
}

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

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

  vector<int> vec(N);

  for (int i = 0; i < N; i++) cin >> vec.at(i);

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

  int count = 0;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      for (int k = j + 1; k < N; k++){
        if (vec.at(i) != vec.at(j) && vec.at(j) != vec.at(k) && vec.at(k) != vec.at(i) && abs(vec.at(j) - vec.at(i) < vec.at(k) && vec.at(i) + vec.at(j) > vec.at(k)) ){
          count += 1;
        }
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 3628
s = str(input())
t = str(input())

mn = 10000
for i in range(len(s)-len(t)+1):
    s_ = s[i:i+len(t)]
    ne = 0
    for j in range(len(t)):
        if s_[j] != t[j]:
            ne += 1
    if ne < mn:
        mn = ne

print(mn)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mincost(vector<ll> v,ll n)
{
  ll dp[100001];
  dp[0] = 0;
  dp[1] = abs(v[1] - v[0]);
  for(ll i=2;i<n;i++)
  {
    dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]),dp[i-2] + abs(v[i] - v[i-2]));
  }
  return dp[n-1];
}
int main()
{
  vector<ll> v;
  ll n,t;
  cin>>n;
  for(ll i=0;i<n;i++)
  {
    cin>>t;
    v.push_back(t);
  }
  cout<<mincost(v,n);

  return 0;
}

Measured memory_bytes: 2676
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str,com;
	int n,a,b;
	cin>>str>>n;
	for(int i=0;i<n;++i){
		cin>>com>>a>>b;
		switch(com[2]){
			case 'p':
				cin>>com;
				str=str.substr(0,a)+com+str.substr(b+1);
				break;
			case 'v':
				com=str.substr(a,b-a+1);
				str=str.substr(0,a)+string(com.rbegin(),com.rend())+str.substr(b+1);
				break;
			case 'i':
				cout<<str.substr(a,b-a+1)<<endl;
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
H,N = map(int,input().split())
AB  = [list(map(int,input().split())) for i in range(N)]
inf = float("inf")
maxA = max(AB)[0]
dp = [inf]*(maxA+H)
dp[0]=0

for i in range(N):
  a,b = map(int,AB[i])
  for j in range(H+maxA):
    if j-a>=0:
      dp[j] = min(dp[j-a] + b, dp[j])
#print(dp)
print(min(dp[H:]))
    

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll N;
  scanf("%lld", &N);

  mll m;

  for (ll x = 1; x <= 100; x++) {
    for (ll y = x; y <= 100; y++) {
      for (ll z = y; z <= 100; z++) {
        ll v = x * x + y * y + z * z + x * y + y * z + z * x;

        if (x == y && y == z) {
          m[v] += 1;
        } else if (x == y || y == z) {
          m[v] += 3;
        } else {
          m[v] += 6;
        }
      }
    }
  }

  for (ll i = 1; i <= N; i++) {
    cout << m[i] << endl;
  }
}


Measured memory_bytes: 5068
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
LL M;
LL dp[5145][5145];

void ADD(LL &v, LL t) {
  v += t;
  while (v >= M) v -= M;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N >> M;
  int p = (N+1)/2;
  dp[0][0] = 1;
  // 1..p-1
  reps(i, 1, p) {
    rep(j, N) {
      LL coeff = 1;
      for (int nj=j; nj<N; nj+=i) {
        dp[i][nj] += coeff * dp[i-1][j];
        dp[i][nj] %= M;
        coeff++;
      }
    }
  }
  rep(j, N) {
    LL coeff = 1;
    for (int nj=j; nj<N; nj+=p) {
      dp[p][nj] += coeff * dp[p-1][j];
      dp[p][nj] %= M;
      if (N%2 == 0) coeff++;
    }
  }

  LL ans = 0;
  rep(j, N) ADD(ans, dp[p][j]);
  cout << ans << endl;
}


Measured memory_bytes: 102656
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {-1, 0};
int dy[] = {0, -1};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int board[2][110], dp[2][110];
signed main() {
    int N; cin >> N;
    rep(i,0,2) rep(j,0,N) cin >> board[i][j];

    rep(i,0,2) rep(j,0,N) {
        int cost = 0;
        rep(k,0,2) {
            int x = i + dx[k], y = j + dy[k];
            if(x < 0 || x >= 2 || y < 0 || y >= N) continue;
            chmax(cost, dp[x][y]);
        }
        dp[i][j] = cost + board[i][j];
    }

    cout << dp[1][N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		int dishNum = scan.nextInt();
		int manzoku = 0;

		int[] a = new int[dishNum];
		int[] b = new int[dishNum];
		int[] c = new int[dishNum];

		for(int i=0;i<dishNum;i++) {
			a[i] = scan.nextInt();
		}
		for(int i=0;i<dishNum;i++) {
			b[i] = scan.nextInt();
		}
		for(int i=0;i<dishNum-1;i++) {
			c[i] = scan.nextInt();
		}

		for(int i=0;i<dishNum;i++) {
			manzoku += b[a[i]-1];
			if(i != 0) {
				if(a[i-1]+1==a[i]) {
					manzoku += c[a[i]-2];
				}
			}
		}
		System.out.println(manzoku);
	}

}


Measured memory_bytes: 21584
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int l=s.size();
  string ans;
  for(int i=0; i<l; i++){
    if(s.at(i)=='0') ans+= '0';
    else if(s.at(i)=='1') ans+= '1';
    else if(s.at(i)=='B' && ans.size()!=0) ans.erase(ans.begin()+ans.size()-1);
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
def input():
    return sys.stdin.readline()[:-1]
n, m = map(int, input().split())
cyc = [0 for _ in range(n)]
num = [10**30 for _ in range(n)]
adj = [[] for _ in range(n)]
used = [False for _ in range(m)]
for i in range(m):
    u, v, s = map(int, input().split())
    adj[u-1].append([v-1, s, i])
    adj[v-1].append([u-1, s, i])

revised_count = 0 #奇数ループで調整したかどうか
revised = False
novo = -1
vera = -10**30

def dfs(x):
    global revised_count, novo, vera, revised
    for v, s, e in adj[x]:
        #print(x, v, s, e)
        if used[e]:
            #print("hoge0")
            continue
        elif num[v] > 10**20:
            cyc[v] = cyc[x]+1
            num[v] = s-num[x]
            used[e] = True
            dfs(v)
        elif num[v]+num[x] == s:
            used[e] = True
            continue
        elif (cyc[v]-cyc[x])%2 == 1:
            print(0)
            #print("hoge1")
            sys.exit()
        elif revised:
            print(0)
            #print(num)
            #print("hoge2")
            sys.exit()
        elif (s-num[x]+num[v])%2 == 1:
            print(0)
            #print("hoge3")
            #print(s, num[x], num[v])
            sys.exit()
        else:
            novo = v
            vera = (s-num[x]+num[v])//2
            #revised = True
            revised_count += 1
            used[e] = True
    return

num[0] = 0
dfs(0)

if revised_count > 0:
    #print("revised")
    #revised = False
    #revesed_2 = True
    cyc = [0 for _ in range(n)]
    num = [10**30 for _ in range(n)]
    num[novo] = vera
    cyc[novo] = 0
    used = [False for _ in range(m)]
    revised = True
    revised_count = 0
    dfs(novo)
    for i in range(n):
        if num[i] < 0:
            print(0)
            sys.exit()
    print(1)
else:
    even = min([num[i] for i in range(n) if cyc[i]%2 == 0])
    odd = min([num[i] for i in range(n) if cyc[i]%2 == 1])
    print(max(0, even+odd-1))

Measured memory_bytes: 144232
H, W = map(int, input().split())
a1, a2, a3, a4 = [], [], [], []

for h in range(1, H):
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a1.append(D)
A1 = min(a1)

for h in range(1, H):
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a2.append(D)
A2 = min(a2)

H, W = W, H

for h in range(1, H):
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a3.append(D)
A3 = min(a3)

for h in range(1, H):
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a4.append(D)
A4 = min(a4)

print(int(min(A1, A2, A3, A4)))


Measured memory_bytes: 18896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int range_min = 0;
    range_min += (H2 - H1) * 60;
    if (M2 - M1 >= 0){
        range_min += M2 - M1;
    } else{
        range_min -= 60;
        range_min += M2 + 60 - M1;
    }
    range_min -= K;

    cout << range_min << endl;

    return 0;
}


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

int main(void){
    char x;
    cin>>x;
    if(isupper(x))cout<<'A'<<endl;
    else cout<<'a'<<endl;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ll A, B, N; cin >> N >> A >> B;
    ll C = B - A;
    if(C & 1){
        //Aが1に行ってから1ラウンド -> 合流
        ll res_A = 0;
        res_A = (A-1) + 1;
        res_A += (C-1) / 2;
        //BがNに行ってから1ラウンド -> 合流
        ll res_B;
        res_B = (N-B) + 1;
        res_B += (C-1) / 2;
        cout << min(res_A, res_B) << endl;
    }
    else{
        cout << (B-A)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll n; cin >> n;
  vll a(50, n/50);
  rep(i, 50) a[i]+=i;
  int rest = n%50;
  rep(i,rest) {
    a[i]+=50;
    rep(j,50) {
      if (j==i)continue;
      a[j]--;
    }
  }
  cout << 50 << endl;
  rep(i, 50) {
    printf("%lld%c", a[i], i==49?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 3692
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
lr_list = []

for i in range(m):
    lr_list.append(list(map(int, input().split())))

l = 1
r = n

for item in lr_list:
    l = max(l, item[0])
    r = min(r, item[1])

print(max(0, r - l + 1))


Measured memory_bytes: 60120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,num;
vector<ll> vec;
int main()
{
  cin>>n;
  while(n>0)
  {
      num=n%26;
      vec.push_back(num);
      if(n%26==0)
      {
          n=n/26-1;
      }
      else
        n=n/26;

  }
  for(int i=vec.size()-1;i>=0;i--)
  {
      if(vec[i]==0)
      {
          cout<<"z";
      }
      else
      cout<<char(vec[i]+96);
  }
  cout<<endl;
}


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


// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>  ordered_set;
#define ll long long
 
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl
 
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
ld dp[3005][3005];

#define INF 1000000000000000000
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(11);
    long double pi= 3.14159265358979323846;
    ll n;
    cin>>n;
    ld ar[n];
    rep(i,n)
    {
        cin>>ar[i+1];
    }
    dp[1][1]=ar[1];
    dp[1][0]=1-ar[1];
    for(ll i=2;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1-ar[i]);
        for(ll j=1;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j-1]*ar[i]+dp[i-1][j]*(1-ar[i]);
        }
    }
    ld ans=0;
    for(ll i=(n)/2+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout<<ans;
    return 0;
}

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

const int INF = 1000000000;

struct Edge {
    int from, to, cap, flow, index;
    Edge(int from, int to, int cap, int flow, int index) :
    from(from), to(to), cap(cap), flow(flow), index(index) {}
};

struct Dinic {
    int N;
    vector < vector < Edge > > G;
    vector < Edge * > dad;
    vector < int > Q;

    Dinic(int N) : N(N), G(N), dad(N), Q(N) {}

    void AddEdge(int from, int to, int cap) {
        G[from].push_back(Edge(from, to, cap, 0, G[to].size()));
        if (from == to) G[from].back().index++;
        G[to].push_back(Edge(to, from, cap, 0, G[from].size() - 1));
    }

    long long BlockingFlow(int s, int t) {
        fill(dad.begin(), dad.end(), (Edge *) NULL);
        dad[s] = &G[0][0] - 1;

        int head = 0, tail = 0;
        Q[tail++] = s;

        while(head < tail){
            int x = Q[head++];
            for (int i = 0; i < G[x].size(); i++){
                Edge &e = G[x][i];
                if(!dad[e.to] && e.cap - e.flow > 0){
                    dad[e.to] = &G[x][i];
                    Q[tail++] = e.to;
                }
            }
        }
        if (!dad[t]) return 0;

        long long totflow = 0;
        for (int i = 0; i < G[t].size(); i++){
            Edge *start = &G[G[t][i].to][G[t][i].index];
            int amt = INF;
            for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]){
                if (!e) { amt = 0; break; }
                amt = min(amt, e->cap - e->flow);
            }
            if (amt == 0) continue;
            for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]) {
                e->flow += amt;
                G[e->to][e->index].flow -= amt;
            }
            totflow += amt;
        }
        return totflow;
    }

    long long GetMaxFlow(int s, int t) {
        long long totflow = 0;
        while (long long flow = BlockingFlow(s, t)) totflow += flow;
        return totflow;
    }
};

int H, W;
const int maxn = 105;

char s[maxn][maxn];

int main(){
    cin >> H >> W;
    for(int i = 1;i <= H;i++){
        scanf("%s", s[i] + 1);
    }  
    Dinic dinic(500);
    for(int i = 1;i <= H;i++){
        for(int j = 1;j <= W;j++){
            if(s[i][j] == 'S'){
                dinic.AddEdge(0, i, INF);
                dinic.AddEdge(0, j + H, INF);
            }else if(s[i][j] == 'T'){
                dinic.AddEdge(i, H + W + 1, INF);
                dinic.AddEdge(j + H, H + W + 1, INF);
            }else if(s[i][j] == 'o'){
                dinic.AddEdge(i, j + H, 1);
            }
        }
    }
    int maxflow = dinic.GetMaxFlow(0, H + W + 1);
    if(maxflow >= INF){
        cout << -1 << endl;
    }else{
        cout << maxflow << endl;
    }     
    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
int main(){
	int a,b,c;
	for(c=0;c<3000;c++){
		scanf("%d %d",&a,&b);
		if(a==0&&b==0){
			break;
		}
		else if(a<=b){
			printf("%d %d\n",a,b);
		}
		else{
			printf("%d %d\n",b,a);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int n,k;
    cin >> n >> k;
    vector<ll> h(n,0);
    rep(i,n)cin >> h[i];
    vector<ll> dp(n,LONG_LONG_MAX);
    dp[0] = 0;
    for(int i = 0;i<= n;i++){
        for(int j = 1; j <= k;j++){
            chmin(dp[i+j],dp[i] + abs(h[i]-h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 1792
//Volume5-0516
import java.util.ArrayDeque;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

    	ArrayDeque<Integer> q = new ArrayDeque<Integer>();

        Scanner sc = new Scanner(System.in);

        while(true){

        	int n = sc.nextInt();
        	int k = sc.nextInt();

        	if(n==0&&k==0){break;}

        	int sum = 0,
        		max;

        	q.clear();

        	int tmp;
        	for(int i=0;i<k;i++,n--){
        		q.add(tmp = sc.nextInt());
        		sum += tmp;
        	}
        	max=sum;
        	while(n-- > 0){
        		q.add(tmp = sc.nextInt());
        		sum = sum - q.poll() + tmp;
        		if(sum>max){max = sum;}
        	}
        	System.out.println(max);
        }
    }
}

Measured memory_bytes: 63068
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static PriorityQueue<Edge> pq=new PriorityQueue<>();
	static int n, m, count;
	static int[] par;
	

	static class Edge implements Comparable<Edge>{
		int u, v, cost;
		Edge(int u, int v, int cost){
			this.u=u;
			this.v=v;
			this.cost=cost;
		}
		public int compareTo(Edge e) {
			return this.cost-e.cost;
		}
	}

	static void init(int N) {//初期化
		for(int i=0; i<N; i++) {
			par[i]=i;
		}
	}

	static int root(int x) {//親を求める
		if(par[x]==x) {
			return x;
		}
		return par[x]=root(par[x]);
	}

	static boolean same(int x, int y) {//判定(同グループかどうか)
		return (root(x)==root(y));
	}

	static void unite(int x, int y) {//まとめる
		par[root(x)]=root(y);
	}

	static int kraskal() {
		init(n);
		int res=0;
		for(int i=0; i<count; i++) {
			Edge e=pq.poll();
			if(!same(e.u, e.v)) {
				unite(e.u, e.v);
				res+=e.cost;
			}
		}
		return res;
	}


	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
				n=sc.nextInt();
				par=new int[n];
				count=0;
				for(int i=0; i<n; i++) {
					for(int j=0; j<n; j++) {
						int a=sc.nextInt();
						if(j<=i) continue;
						if(a==-1) a=100000000;
						count++;
						pq.add(new Edge(i, j, a));
					}
				}
				System.out.println(kraskal());
				pq.clear();

		}
	}
}


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

int find(int x, vector<int> &root){
    if (x == root[x]) return x;
    root[x] = find(root[x], root);
    return root[x];
}

bool check(int x, int y, vector<int> &root){
    return find(x, root) == find(y, root);
}

void unions(int x, int y, vector<int> &root, vector<int> &size){
    x = find(x, root);
    y = find(y, root);
    if (size[x] >= size[y]) root[y] = x;
    else root[x] = y;
    if (size[x] == size[y]) size[x]++;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> root(n+1);
    for (int i = 0; i<=n; i++) root[i] = i;
    vector<int> size(n+1);
    for (int i = 0; i<=n; i++) size[i] = 0;
    int x, y, z;
    for (int i = 0; i<m; i++){
        cin >> x >> y >> z;
        if (!check(x,y,root)) unions(x,y,root,size);
    }
    int cnt = 0;
    vector<bool> tmp(n+1);
    for (int i=0; i<=n; i++) tmp[i] = true;
    for (int i=1; i<=n; i++){
        if (tmp[find(i,root)]){
            tmp[find(i,root)] = false;
            cnt++;
        }
    }
    cout << cnt << endl;
}




Measured memory_bytes: 1024
open Printf
open Scanf

let solve n =
  let rec loop i mn =
    if i * i > n then mn
    else if n mod i = 0 then loop (i + 1) @@ min mn (i + n / i - 2)
    else loop (i + 1) mn in
  loop 1 n

let () =
  scanf "%d " solve |> printf "%d\n"


Measured memory_bytes: 3824
let bin_search x ary =
  let rec doit l r =
    if l >= r then false
    else begin
      let m = (l + r) / 2 in
      if x = ary.(m) then true
      else if x < ary.(m) then doit l m
      else doit (m + 1) r
    end
  in
  doit 0 (Array.length ary)

let () =
  let _ = read_int () in
  let s = Array.of_list (List.map int_of_string (Str.split (Str.regexp_string " ") (read_line ()))) in
  let _ = read_int () in
  let t = List.map int_of_string (Str.split (Str.regexp_string " ") (read_line ())) in
  let c = List.fold_left (fun cnt e -> if bin_search e s then (cnt + 1) else cnt) 0 t in
  Printf.printf "%d\n" c

Measured memory_bytes: 16248
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] s = new int[w];
		for (int i = 0; i < w; i++) {
			s[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String line = sc.next();
			String[] ss = line.split(",");
			int a = Integer.parseInt(ss[0]);
			int b = Integer.parseInt(ss[1]);
			int c = s[a - 1];
			s[a - 1] = s[b - 1];
			s[b - 1] = c;
		}
		for (int i = 0; i < w; i++) {
			System.out.println(s[i]);
		}
	}
}

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

int main() {
  int N ; 
  cin >> N ; 
  map<string , int> memo ; 
  string S ; 
  
  for(int i = 0; i<N ; i++){
    cin >> S ; 
    memo[S] += 1 ; 
  }

  int maxv = 0 ; 
  for(const auto& x : memo){ //memo の長さに勝手に合わせてくれるx
    int v = x.second ; 
    if(v > maxv) maxv = v ; 
  }
  
  for(auto it = memo.begin() ; it !=memo.end() ; it++){ //it は memo の最初から最後まで
    if (it->second == maxv) { // memoのsecondが maxと一緒なら
		cout << it->first << endl;
    }
  }
}

Measured memory_bytes: 19268
#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>;
ll MOD=1000000007;

int main(){
  int n; cin>>n;
  vector<ll>V(n);
  rep(i,n){
    cin>>V[i];
    if (V[i]==0){
      cout << 0;
      return 0;
    }
  }
  int64_t ans = V[0];
  for(int i=1;i<n;i++){
    if (V[i]>(1000000000000000000/ans)){
      ans = -1;
      break;
    }
    else ans *= V[i];
  }
  cout << ans;
}

Measured memory_bytes: 4044
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int m1, d1, m2, d2; cin >> m1 >> d1 >> m2 >> d2;

	cout << (m1 != m2) << endl;

	return 0;
}

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

using namespace std;

const int maxn = 100010;

struct seg {
    int l, r, op;
    seg move() {
        seg ret;
        if (op != -1) ret.op = op^1;
        else ret.op = -1;
        if (op == 3) ret.op = 3;
        ret.l = l-1;
        ret.r = r+1;
        return ret;
    }
    int contain(int x) {
        if (op == -1) return 0;
        return x >= l && x <= r && ((op==3)||(x&1)==op);
    }
    seg(int v=0) {l=r=v; op=v&1;}
} full, dp[maxn];

struct Edge {
    int v, x;
} E[maxn<<1];

int l[maxn], e = 0;
int p[maxn], n, K;

inline void insert(int u, int v) {
    E[e].v = v; E[e].x = l[u]; l[u] = e++;
    E[e].v = u; E[e].x = l[v]; l[v] = e++;
}

seg operator*(const seg &x, const seg &y) {
    seg ret;
    if (x.op == -1 || y.op == -1) {
        ret.op = -1;
        return ret;
    }
    if (x.op == 3 && y.op != 3) {
        ret.op = y.op;
    } else if (x.op != 3 && y.op == 3) {
        ret.op = x.op;
    } else if (x.op != y.op) {
        ret.op = -1;
        return ret;
    } else ret.op = x.op;
    ret.l = max(x.l, y.l);
    ret.r = min(x.r, y.r);
    if (ret.l > ret.r) ret.op = -1;
    return ret;
}

void dfs(int u, int f) {
    dp[u] = full;
    if (p[u] != -1) dp[u] = seg(p[u]);
    for (int p = l[u]; p >= 0; p = E[p].x) {
        int v = E[p].v;
        if (v != f) {
            dfs(v, u);
            dp[u] = dp[u]*dp[v].move();
        }
    }
}

void dfs_fill(int u, int f) {
    if (u == 1) p[u] = dp[u].l;
    else if (dp[u].contain(p[f]-1)) {
        p[u] = p[f]-1;
    } else if (dp[u].contain(p[f]+1)) {
        p[u] = p[f]+1;
    }
    for (int p = l[u]; p >= 0; p = E[p].x) {
        int v = E[p].v;
        if (v != f) {
            dfs_fill(v, u);
        }
    }
}

int main() {
    memset(l, -1, sizeof(l));
    full.l = -1e6; full.r = 1e6; full.op = 3;
    memset(p, -1, sizeof(p));
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int u, v; scanf("%d%d", &u, &v);
        insert(u, v);
    }
    scanf("%d", &K);
    for (int i = 1; i <= K; i++) {
        int v, x; scanf("%d%d", &v, &x);
        p[v] = x;
    }
    dfs(1, 0);
    if (dp[1].op == -1) {
        puts("No");
    } else {
        puts("Yes");
        dfs_fill(1, 0);
        for (int i = 1; i <= n; i++) {
            printf("%d\n", p[i]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 10624
using System;
using System.Collections.Generic;
using static System.Console;
using System.IO;

internal class Program
{
    public static void Main(string[] args)
    {
        var sw = new StreamWriter(OpenStandardOutput()) {AutoFlush = false};
        SetOut(sw);

        var n = int.Parse(ReadLine());
        int count = 0;
        for (var i = 0; i < n; i++)
        {
            if (IsPrime(int.Parse(ReadLine()))) count++;
        }

        WriteLine(count);
        Out.Flush();
    }

    public static bool IsPrime(int x)
    {
        if (x <= 1) return false;
        if (x == 2) return true;
        if (x % 2 == 0) return false;

        var sqrt = Math.Sqrt(x);
        for (var i = 3; i <= sqrt; i += 2)
        {
            if (x % i == 0) return false;
        }

        return true;
    }
}


Measured memory_bytes: 15932
import math
N,D=map(int,input().split())
List=[[int(i) for i in input().split()] for j in range(N)]
c = 0
for i in range(N):
    for k in range(N):
        sum = 0
        for j in range(D):
            sum += (List[i][j]-List[k][j])**2
       
        ssum = math.sqrt(sum)
        
        if ssum - int(ssum) <0.000000001:
            c += 1
print(int((c-N)/2)) 



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int h, w; cin >> h >> w;
    string s;
    rep(i,h){
        cin >> s;
        cout << s << ln << s << ln;
    }
    return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int[] cards = Array.ConvertAll(input.Split(','), int.Parse);

                int[] memo = new int[14];
                int max = 0;

                for (int i = 0; i < 5; i++)
                {
                    memo[cards[i]]++;
                    max = Math.Max(max, memo[cards[i]]);
                }

                if (max == 4)
                {
                    sb.AppendLine("four card");
                }
                else if (max == 3)
                {
                    if (memo.Contains(2)) sb.AppendLine("full house");
                    else sb.AppendLine("three card");
                }
                else if (max == 2)
                {
                    int count = memo.Where(a => a == 2).Count();

                    if (count == 2) sb.AppendLine("two pair");
                    else sb.AppendLine("one pair");
                }
                else
                {
                    bool isStraight = false;

                    if (memo[1] > 0)
                    {
                        if (memo[10] > 0 && memo[11] > 0 && memo[12] > 0 && memo[13] > 0)
                        {
                            sb.AppendLine("straight");
                            isStraight = true;
                        }
                    }

                    if (!isStraight)
                    {
                        int index = Array.IndexOf(memo, 1);

                        if (memo[index + 1] > 0 && memo[index + 2] > 0 && memo[index + 3] > 0 && memo[index + 4] > 0)
                        {
                            sb.AppendLine("straight");
                        }
                        else sb.AppendLine("null");
                    }
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9680
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

ll fact(ll n){
    ll sum=1;
    REP(i,1,n+1) {
        sum *= i;
        sum %= mod;
    }
    return sum;
}
int main(){
    ll n,x;
    cin >> n;
    map<ll,ll> m;
    REP(i,1,n+1){
        x = i;
        for(int j=2;j*j<=x;j++){
           while(x%j == 0) {
                m[j]++;
                x /= j;
            }
        }
        if(x > 1) m[x]++;
    }
    ll ans =1;
    for(auto p:m){
        ans = (ans * (p.second + 1)) % mod;
    }
    cout << ans << endl;
    return 0;
}  


Measured memory_bytes: 256