akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		int[] num = new int[Dice.SURFACE];

		for(int i = 0; i < input.length; i++){
			num[i] = Integer.parseInt(input[i]);
		}

		Dice dice = new Dice(num);
		char[] ope = br.readLine().toCharArray();

		for(int i = 0; i < ope.length; i++){

			if(ope[i] == 'N'){
				dice.moveN();
			}else if(ope[i] == 'E'){
				dice.moveE();
			}else if(ope[i] == 'W'){
				dice.moveW();
			}else if(ope[i] == 'S'){
				dice.moveS();
			}

		}

		System.out.println(dice.getNum(1));

	}
}

class Dice{

	static final int SURFACE = 6;
	private int[] num = new int[SURFACE];

	public Dice(int[] set){

		for(int i = 0; i < SURFACE; i++){
			num[i] = set[i];
		}

	}

	public int getNum(int rabel){

		return num[rabel - 1];

	}

	public int getRabel(int n){

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

			if(n == num[i]){
				return i + 1;
			}

		}

		return -1;

	}

	public void moveE(){

		int temp = num[0];
		num[0] = num[3];
		num[3] = num[5];
		num[5] = num[2];
		num[2] = temp;

	}

	public void moveN(){

		int temp = num[0];
		num[0] = num[1];
		num[1] = num[5];
		num[5] = num[4];
		num[4] = temp;

	}

	public void moveS(){

		int temp = num[0];
		num[0] = num[4];
		num[4] = num[5];
		num[5] = num[1];
		num[1] = temp;

	}

	public void moveW(){

		int temp = num[0];
		num[0] = num[2];
		num[2] = num[5];
		num[5] = num[3];
		num[3] = temp;

	}

}

Measured memory_bytes: 24248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl;
#define all(v) v.begin(), v.end()


int main() {
  int N, K;
  cin >> N >> K;
  int A[N+1]; ll ans = 0;
  A[0] = 0;
  rep1(i,N) {
    cin >> A[i];
    A[i] += A[i-1];
    A[i]--;
    A[i] %= K;
  }
  map<int, int> m;
  rep(i,min(K, N+1)) {
    m[A[i]]++;
  }
  rep(i,N) {
    m[A[i]]--;
    ans += m[A[i]];
    if (i+K<=N)
      m[A[i+K]]++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 13748
import sys
from collections import *
from heapq import *
from fractions import gcd
import itertools
import math

sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, input().split(' ')))
def In(): return int(input())
def InS(): return input()

N = In()
pos = []
for i in range(N):
    pos.append(InMap())

Res = 0
for v in itertools.permutations(pos, N):
    tmp = 0
    for i in range(N - 1):
        tmp += math.sqrt((v[i][0] - v[i+1][0])**2 + (v[i][1] - v[i+1][1])**2)
    Res += tmp
print(Res / float(math.factorial(N)))
exit()


Measured memory_bytes: 5460
import itertools
S = input()
ans = 0
s = itertools.groupby(S)
b=0
for key,group in s:
  if key=="<":
    a = len(list(group))
    ans += ((b+b+a)*(a+1))/2
    b = a
  elif key==">":
    a = len(list(group))
    if b<=a:
      ans +=(b+abs(b-a)+0)*(a+1)/2-b
      b=0
    else:
      ans +=((a-1)*(a))/2
      b=0
    #print(ans)
print(int(ans))
#print(len(list(s)))

Measured memory_bytes: 78792
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

int main(){
	vector<long long> inv(100000);
	vector<long long> fact(100000);
	for(int i=0;i<2;i++) inv[i] = fact[i] = 1;
	for(int i=2;i<inv.size();i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
	}
    int N;
    while(cin >> N){
        vector<int> x(N);
        for(auto& t : x) cin >> t;
        long long res = 0;
        long long c = 0;
        for(int i=1;i<N;i++){
            c += fact[N-1] * inv[i];
            c %= MOD;
            res += c * (x[i] - x[i-1]);
            res %= MOD;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 2176
import sys
sys.setrecursionlimit(10 ** 8)


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


# 愚直解
def mex(array):
    if not array:
        return 0
    set_ = set(array)
    for i in range(10000):
        if i not in set_:
            return i
"""
res = 0
for a, k in info:
    grundy = [0] * (a + 1)
    for num in range(1, a + 1):
        length = num // k
        grundy[num] = mex(grundy[num - length:num])
    res ^= grundy[-1]

if res == 0:
    print("Aoki")
else:
    print("Takahashi")
"""



# a(3n)=n, otherwise a(n)=a(floor(2n/3))
"""
def solve(n, k):
    if n % k == 0:
        return n // k
    return solve(n * (k - 1) // k, k)
"""

def solve(n, k):
    if n % k == 0:
        return n // k
    diff = (n // k) + 1
    target = n - n % k
    if (n - target) % diff == 0:
        return solve(target, k)
    n -= -((-(n - target)) // diff) * diff
    return solve(n, k)

res = 0
for a, k in info:
    res ^= solve(a, k)
if res == 0:
    print("Aoki")
else:
    print("Takahashi")

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(10) << (double)h * w / 2 << " ";
    cout << (w == x * 2 and h == y * 2 ? 1 : 0) << ln;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct node{
    int x,y;
    int len;
    node(){};
    node(int xx,int yy){x=xx;y=yy;len=x*x+y*y;}
    bool judge(node t)
    {
        if(t.len==len&&(x*t.y-y*t.x)>0&&(t.x*x+t.y*y)==0)return 1;
        else return 0;
    };
};
int main()
{
    node p1,p2,p3,p4,tt,t;
    int x,y;
    cin>>x>>y;
    p1=node(x,y);
    cin>>x>>y;
    p2=node(x,y);
    tt=node(p2.x-p1.x,p2.y-p1.y);
    for(int i=-400;i<=400;++i)
    {
        for(int j=-400;j<=400;++j)
        {
            t=node(i,j);
            t=node(t.x-p2.x,t.y-p2.y);
            if(tt.judge(t))p3=node(i,j);
            t=node(i,j);
            t=node(p1.x-t.x,p1.y-t.y);
            if(t.judge(tt))p4=node(i,j);
        }
    }
    cout<<p3.x<<" "<<p3.y<<" "<<p4.x<<" "<<p4.y<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

typedef double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

int main(){ _

	ll a,b;
	cin >> a >> b;

	ll at = min(a,b/2);
	b -= 2*at;

	at += b/4;

	cout << at << endl;

	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
mint modpow(mint a,ll n){
    mint res = 1;
    while(n > 0){
        if(n & 1) res = res * a ;
        a = a * a;
        n >>= 1;//nを２のベキに分解している
    }
    return res;
}
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}
 
int main() {
  int a, b;
  ll n;
  cin >> n >> a >> b;
  mint ans = modpow(2,n);
  ans -= 1;
  ans -= choose(n,a);
  ans -= choose(n,b);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
#include <queue>
#include<map>
#define lli long long int
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i=a;i<n;i++)
using namespace std;
int main(){
    lli a,b,c;
    cin>>a>>b>>c;
    cout<<max(0ll ,c-a+b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n=0;
	while(cin >>n){
		int x = 1,f = 0;
		for(int i=0; i<10; i++){
			if(n%2 == 1 && f == 0){cout<<x;f = 1;}
			else if(n%2 == 1 && f != 0){cout<<" "<<x;}
			x*=2;
			n = n/2;
		}
		cout<<endl;
	}
}

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

int n, a[2005], dp[2003][2003][2];
int dfs(int i, int j, int k) {
	int& ret = dp[i][j][k];
	if (ret != -1)return ret;
	if (i == n || j == n) {
		return ret = abs(a[i] - a[j]);
	}
	int mx = max(i, j) + 1;
	if (k == 0) {
		ret = -1e9;
		ret = max(ret, dfs(mx, j, 0));
		ret = max(ret, dfs(i, mx, 1));
	}
	else {
		ret = 1e9 + 5;
		ret = min(ret, dfs(i, mx, 1));
		ret = min(ret, dfs(mx, j, 0));
	}

	return ret;
}
int main() {
	scanf("%d", &n);
	n += 2;
	for (int i = 1; i <= n; i++)scanf("%d", &a[i]);
	memset(dp, -1, sizeof(dp));
	int ans = dfs(3, 2, 0);
	printf("%d", ans);
}

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

int gcd(int a, int b)
{
    int r = a % b;
    if(r == 0)
    {
        return b;
    }
    else
    {
        return gcd(b, r);
    }    
}

int gcd3(int a, int b, int c)
{
    int r1 = gcd(a, b);

    return gcd(r1, c);
}

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

    int sum = 0;
    for(int a = 1; a <= n; a++)
    {
        for(int b = 1; b <= n; b++)
        {
            for(int c = 1; c <= n; c++)
            {
                sum += gcd3(a, b, c);
            }
        }
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 3632
n;s;e;w;i;main(){
    char t[1000];
    gets(t);
    
    for(;i<strlen(t);i++){
        if(t[i]=='N')n=1;
        if(t[i]=='S')s=1;
        if(t[i]=='E')e=1;
        if(t[i]=='W')w=1;
    }
    puts(abs(n-s)+abs(w-e)?"No":"Yes");
}

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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= 3; ++i) {
        if (i != a && i != b) {
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}


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

typedef long long ll;

ll n;

int main(){
    cin >> n;
    
    if(n%2==0){
        cout << n << endl;
        return 0;
    }
    
    int res=1;
    int tmp;
    tmp=n;

    while(1){
        if(tmp%2==0 && tmp%n==0){
            res=2*n;
            break;
        }
        tmp++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
$a = str_split(trim(fgets(STDIN)));

    for($i=0;$i<=(count($a)-1);$i++){
        if(ctype_upper($a[$i])){
            echo strtolower($a[$i]);
        }elseif(ctype_lower($a[$i])){
            echo strtoupper($a[$i]);
        }else{
            echo $a[$i];
        }
    }
    echo PHP_EOL;



Measured memory_bytes: 9368
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, v, c, a = 0; cin >> n;
	int testV[30] = { 0 };
	int testC[30] = { 0 };
	for (int h = 1; h <= n; h++) {
		cin >> v; testV[h] = v;
	}
	for (int h = 1; h <= n; h++) {
		cin >> c; testC[h] = c;
	}
	for (int h = 1; h <= n; h++) {
		if ((testV[h] - testC[h]) > 0) {
			a += testV[h] - testC[h];
		}
	}
	cout << a << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int N=200005;
using namespace std;
int n,a,x[N];
int main(){
	cin>>n;
	for(int i=2;i<=n;i++)
	    cin>>a,x[a]++;
	for(int i=1;i<=n;i++)
	    cout<<x[i]<<endl;
	return 0;
}

Measured memory_bytes: 4372
#include <stdio.h>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <assert.h>
#include <string>
#include <algorithm>
#include <sstream>
#include <iostream>
using namespace std;

typedef long long ll;
const int maxl = 100010;
const int mod = 1e9 + 7;

int x, y;

int main() {
    while (scanf("%d%d", &x, &y) != EOF) {
        printf("%d\n", x + y / 2);
    }

    return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()

{

    ll n, k;
    cin >> n >> k;
    vector<ll> v(n+1);
    for(ll i = 1; i <= n; i++) cin >> v[i];
    ll ans = inf;
    for(ll i = 1; i<=n-k+1; i++)
    {

        ll x = abs(v[i]);
        ll y = abs(v[i+k-1]);
        //cout << v[i] << " " << v[i+k-1] << endl;
        if(v[i]*v[i+k-1] > 0) ans = min(ans, max(x,y));
        else
        {

            ans = min(ans, 2*x+y);
            ans = min(ans, 2*y+x);
        }
    }
    cout << ans;
}


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


int main(){
    string s;
    cin >> s;
    string x = s.substr(0, 2);
    string y = s.substr(2, 2);

    int a = stoi(x);
    int b = stoi(y);
    
    if(a>=1 && a<=12 && b>=1 && b<=12) cout << "AMBIGUOUS" << endl;
    else if(a>=1 && a<=12 && b>=0) cout << "MMYY" << endl;
    else if(a>=0 && b>=1 && b<=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}


Measured memory_bytes: 256
//#define debug

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

#define SZ(x) ((int)x.size())

const int N = (int)1e5+5;
int n, sz[N], sz_up[N], par[N];
int a[N], sum[N], cnt[N];
bool dp[N], dp2[N];
vector<int> g[N], res;

void dfs1(int u, int p) {
	dp[u] = true, par[u] = p;
	for (int &v : g[u]) {
		if (v == p) continue;
		dfs1(v, u);
		dp[u] = dp[u] && dp[v];
		sum[u] += (int)dp[v];
	}
	if (cnt[u] > 1) {
		dp[u] = false;
	}
}

void dfs2(int u, int p) {
	if (!dp2[u]) return;
	for (int &v : g[u]) {
		if (v == p) continue;
		sz_up[v] = sz_up[u] + sz[u] - sz[v];
		dp2[v] = dp2[u] && (sum[u] - (int)dp[v] == SZ(g[u]) - (p != 0) - 1);
		if (cnt[u] - int(sz[v] > 1) + int(sz_up[u] > 1) > 1) dp2[v] = false;
		dfs2(v, u);
	}
}

void dfs_sz(int u, int p) {
	sz[u] = 1, cnt[u] = 0;
	for (int &v : g[u]) {
		if (v == p) continue;
		dfs_sz(v, u);
		sz[u] += sz[v];
		cnt[u] += (sz[v] > 1);
	}
}

void dfs_ans(int u, int p, int &mx, vector<int> &re) {
	int children = SZ(g[u]) - (p != 0);
	int last = re.back(); re.pop_back();
	for (int i = 1; i < children; ++i) {
		re.push_back(++mx);
	}
	re.push_back(last), re.push_back(++mx);
	for (int &v : g[u]) {
		if (v == p || sz[v] <= 1) continue;
		dfs_ans(v, u, mx, re);
	}
}

void get_ans(int from) {
	memset(sz, 0, sizeof(sz));
	dfs_sz(from, 0);
	vector<int> re;
	re.push_back(1);
	int mx = 1;
	dfs_ans(from, 0, mx, re);
	if (!SZ(res)) {
		res = re;
	} else {
		for (int i = 0; i < n; ++i) {
			if (res[i] != re[i]) {
				if (res[i] > re[i]) {
					res = re;
				}
				return;
			}
		}
	}
}

int main() {
#ifdef debug
	clock_t tStart = clock();
#endif
	scanf("%d", &n);
	for (int i = 1, u, v; i < n; ++i) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs_sz(1, 0);
	dfs1(1, 0);
	dp2[1] = true;
	dfs2(1, 0);
	bool ok = false;
	for (int i = 1; i <= n; ++i) {
		if (i == 1 && !(SZ(g[i]) == 1 && dp[i])) continue;
		if (i > 1 && !(dp2[i] && SZ(g[i]) == 1)) continue;
		a[par[i]] = i, ok = true;
	}
	if (!ok) return puts("-1"), 0;
	for (int i = 0; i <= n; ++i) {
		if (!a[i]) continue;
		get_ans(a[i]);
	}
	for (int &v : res) {
		printf("%d ", v);
	}
	printf("\n");
#ifdef debug
	printf("Total time: %d ms\n", (int)(1000.0 * (double)(clock() - tStart) / CLOCKS_PER_SEC));
#endif
	return 0;
}

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


int main()
{
	int n, * v, c, d, sum = 0;
	cin >> n;
	v = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c;
		d = v[i] - c;
		if (d > 0) {
			sum += d;
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>


using namespace std;


void check( int val ){
	
	cout << val << endl;
}

int main( int argc , char ** argv ){
	
	int N = 0 , x = 0;
	cin >> N >> x;

	int n_size = 2*N-1;

	if(x == 1 || x == n_size){
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	vector<int> ans;
	ans.resize(n_size);


	int n_center = n_size/2;

	// cout << "n_center = " << n_center << endl;
	ans[n_center] = x;
	ans[n_center + 1] = n_size;
	ans[n_center - 1] = 1;

	int l_c = 0 , r_c = 0;

	for(int i = 2 ; i <= n_center ; i++){

		if(i + l_c == x ) l_c=1;
		if((n_size+1)-i + r_c == x) r_c=1;
		ans[n_center + i] = i + l_c;
		ans[n_center - i] = (n_size+1)-i - r_c;
	}

	for(auto _ans : ans){
		cout << _ans << endl;
	}

}



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

public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[][][]dp;
	static int[][]val;
	static long solve(int i,int j,int items)
	{
		if(i==val.length || j==val[0].length)
			return 0;
		if(dp[i][j][items]!=-1)
			return dp[i][j][items];
		long res=0;
		res=Math.max(solve(i+1,j,0),solve(i,j+1,items));
		if(val[i][j]!=0)
		{
			res=Math.max(res,(long)val[i][j]+solve(i+1,j,0));
			if(items<3)
				res=Math.max(res, (long)val[i][j]+solve(i,j+1,items+1));
			else
				res=Math.max(solve(i+1,j,0),solve(i,j+1,items));
		}
		dp[i][j][items]=res;
		return res;
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		int[]ar=split();
		int r=ar[0];
		int c=ar[1];
		int k=ar[2];
		val=new int[r][c];
		for(int i=0;i<k;i++)
		{
			ar=split();
			val[ar[0]-1][ar[1]-1]=ar[2];
		}
		dp=new long[r+1][c+1][4];
		for(int i=0;i<=r;i++)
		{
			for(int j=0;j<=c;j++)
			{
				Arrays.fill(dp[i][j], -1);
			}
		}
		System.out.println(solve(0,0,0));
	}
}


Measured memory_bytes: 687156
#include <array>
#include <iostream>
using namespace std;
 
array<array<int, 210>, 210> costs;
array<array<int, 210>, 210> times;
 
int main() {
    int n, m;
    while (cin >> n >> m, n || m) {
        for (auto& ar : costs) ar.fill(1000000);
        for (auto& ar : times) ar.fill(1000000);
        for (int i = 0; i < n; i++) {
            int a, b, c, t;
            cin >> a >> b >> c >> t;
            a--; b--;
            costs[a][b] = costs[b][a] = c;
            times[a][b] = times[b][a] = t;
        }
        for (int i = 0; i < m; i++) {
            costs[i][i] = 0;
            times[i][i] = 0;
        }
 
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < m; k++) {
                    costs[j][k] = min(costs[j][k], costs[j][i] + costs[i][k]);
                    times[j][k] = min(times[j][k], times[j][i] + times[i][k]);
                }
            }
        }
        int k;
        cin >> k;
        for (int i = 0; i < k; i++) {
            int p, q, r;
            cin >> p >> q >> r;
            p--; q--;
            if (r == 0) {
                cout << costs[p][q] << endl;
            }
            else {
                cout << times[p][q] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1500
#include <iostream>
using namespace std;
int main(){
  int x[5];
  for(int i=0;i<5;i++) cin >> x[i];

  for(int i=0;i<5;i++){
    if(x[i] == 0){
      cout << i+1 << endl;
      return 0;
    }
  }
}

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


#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<int, int> P;
typedef tuple<int, int, int> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return abs(a); }

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

int main() {
	ll n;
	cin >> n;
	//n/m >= m ならば
	//n/m = n % m とはならない
	//n >= m*m はチェック不要
	//while(i*i <= n) 不要
	//i > sqrt(n)
	//36
	//36-3 / 11 = 3
	//36-4 / 8 = 4
	//t = n - i;
	//n/i == t/i;
	//n / i = n % i

	double u = sqrt(n)+1;
	ll ut = (ll)u;
	ll sum = 0;
	for (ll i = ut; i > 0; i--) {
		auto opm = n - i;
		if (opm % i == 0) {
			auto m = opm / i;
			if (m > 0) {
				if (n / m == n % m) {
					sum += m;
				}
			}
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
const int Maxn=105;
int f[Maxn][Maxn][Maxn],g[Maxn][Maxn][Maxn],C[Maxn][Maxn];
int main(){
    int n,m,c,mod;cin>>n>>m>>c>>mod;
    for(int i=0;i<105;C[i++][0]=1)
        for(int j=1;j<=i;j++)
            C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    f[0][0][0]=1;
    auto ksm=[&](int x,int k){
        int ret=1,tmp=x;
        while(k){
            if(k&1)ret=1ll*ret*tmp%mod;
            tmp=1ll*tmp*tmp%mod;k>>=1;
        }
        return ret;
    };
    for(int k=1;k<=c;k++){
        static int base[Maxn*Maxn];
        for(int i=0,w=1;i<=n*m;i++,w=1ll*w*(c-k+1)%mod)base[i]=w;
        for(int j=0;j<=m;j++){
            int coef=ksm(k,m-j)-ksm(k-1,m-j);
            for(int i=0;i<=n;i++){
                int v=f[i][j][k-1];
                if(!v)continue;
                for(int d=0,w=1;i+d<=n;d++,w=1ll*w*coef%mod){
                    int V=v;
                    V=1ll*V*C[n-i][d]%mod;
                    V=1ll*V*base[d*j]%mod;
                    V=1ll*V*w%mod;
                    g[i+d][j][k]=(g[i+d][j][k]+V)%mod;
                }
            }
        }
        for(int i=0,w=1;i<=n*m;i++,w=1ll*w*k%mod)base[i]=w;
        for(int i=0;i<=n;i++){
            int coef=ksm(c-k+1,i)-ksm(c-k,i);
            for(int j=0;j<=m;j++){
                int v=g[i][j][k];
                if(!v)continue;
                for(int d=0,w=1;j+d<=m;d++,w=1ll*w*coef%mod){
                    int V=v;
                    V=1ll*V*C[m-j][d]%mod;
                    V=1ll*V*base[(n-i)*d]%mod;
                    V=1ll*V*w%mod;
                    f[i][j+d][k]=(f[i][j+d][k]+V)%mod;
                }
            }
        }
    }
    cout<<(f[n][m][c]+mod)%mod<<"\n";
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = mod * mod;

int main(){
	int n;
	cin >> n;
	int a[100010] = {};
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a[t]++;
	}
	ll ans=1LL;
	if (n % 2) {
		if (a[0] != 1) {
			cout << 0 << endl;
			return 0;
		}
		for (int i = 2; i <= (n - 1); i += 2) {
			ans = ans * 2LL % mod;
			if (a[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	else {
		for (int i = 1; i <= n -1; i += 2) {
			ans = ans * 2LL % mod;
			if (a[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int n, k;

int main() {
scanf("%d %d", &n, &k);
if (n >= 2 * k - 1) printf("YES\n"); else printf("NO\n");	
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int q;
  map<string,int>m;
  cin >> q;
  while(q--){
    int x, y;
    string key;
    cin >> x >> key;
    if(x){
      cout << m[key] << endl;
    }
    else{
      cin >> y;
      m[key]=y;
    }
  }
}


Measured memory_bytes: 27908
#include<iostream>
#include<list>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

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


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

int main()
{   
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    double a[n];
    double s=0;
    for(ll i=0;i<n;i++)
    {
    	cin>>a[i];
    	s += a[i];
    }
    s=s/double(n);
    ll tp = 0;
    double mn = double(abs(double(a[0])-s));
    for(ll i=0;i<n;i++)
    {
       if(double(abs(double(a[i]) - s) < mn))
       {
       	tp = i;
       mn = double(abs(double(a[i]) - s));
     }
    }
    cout<<tp<<endl;

   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	cout<<(a+b<=2*c?a*x+b*y:x>y?a<=2*c?a*(x-y)+2*c*y:2*c*x:b<=2*c?b*(y-x)+2*c*x:2*c*y)<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]


def solve():
    return N // 2 + N % 2

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

Measured memory_bytes: 3952
def BFS(K, edges, N):
  roots = [ [] for i in range(N)]
  for a, b, c in edges:
    roots[a-1] += [(b-1, c)]
    roots[b-1] += [(a-1, c)]
  dist = [-1] * N
  stack = []
  stack.append(K)
  dist[K] = 0
  while stack:
    label = stack.pop(-1)
    for i, c in roots[label]:
      if dist[i] == -1:
        dist[i] = dist[label] + c
        stack += [i]
  return dist

N = int(input())
abc = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = map(int, input().split())
xy =  [list(map(int, input().split())) for _ in range(Q)]

distance = BFS(K - 1, abc, N)
for x, y in xy:
  print(distance[x - 1] + distance[y - 1])

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

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

using namespace std;

typedef long long ll;

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

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

  if (N == 3) {
    cout << "2 5 63" << endl;
    return 0;
  }

  vector<int> vi;
  REP(i, 2, 30001) if (i % 2 == 0 || i % 3 == 0) vi.eb(i);

  random_device rd;
  mt19937 engine(rd());

  while (1) {
    shuffle(all(vi), engine);

    int sum = 0;
    int g = vi[0];
    rep(i, N) {
      sum += vi[i];
      g = __gcd(g, vi[i]);
    }

    if (g != 1) continue;

    bool flg = true;
    rep(i, N) if (__gcd(sum, vi[i]) == 1) flg = false;

    if (!flg) continue;

    rep(i, N) cout << vi[i] << ' ';
    cout << endl;
    return 0;
  }
}


Measured memory_bytes: 512
n, m, l = list(map(int, input().split()))

a = [0]*n
b = [0]*m
c = [[0 for col in range(l)] for row in range(n)]

for i in range(n):
    a[i] = list(map(int,input().split()))

for i in range(m):
    b[i] = list(map(int,input().split()))

#for i in range(n):
#    for j in range(l):
#        for k in range(m):
#            c[i][j] += a[i][k]*b[k][j]
for i in range(n):
    c[i] = [sum([a[i][k]*b[k][j] for k in range(m)]) for j in range(l)]
    print(*c[i])

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

int main(){
    int N ,M;
    cin >> N >> M;
    int a[M],b[M];
    for(int i=0;i<M;i++){
        cin >> a[i] >> b[i];
    }
    int l[N];
    for(int i=0;i<N;i++) l[i]=0;
    for(int i=0;i<M;i++){
        if(a[i] != b[i]){
            l[a[i]-1]++;
            l[b[i]-1]++;
        }
    }
    for(int i=0;i<N;i++) cout << l[i] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

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

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}

/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/
signed main(){
	char a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a == b || b == c || c == d) cout << "Bad" << endl;
	else cout << "Good" << endl;
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}

int main(){
    INT(n);
    vlint a(n); line(a);
    vlint left(n+2, 0); vlint right(n+2, 0);
    left[0] = a[0];
    rep1(i, n){
        left[i] = gcd(left[i-1], a[i]);
    }

    right[n-1] = a[n-1];
    for (int i = n-2; i >= 0; --i){
        right[i] = gcd(right[i+1], a[i]);
    }
    lint ans = 0;
    rep1(i, n-1){
        chmax(ans, gcd(left[i-1], right[i+1]));
    }
    chmax(ans, right[1]); chmax(ans, left[n-2]);
    print(ans);
}


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  VI a(n); for (int i = 0; i < n; i++) cin >> a[i];
  cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 500001
 
typedef struct Node {
    long key;
    struct Node *p, *l, *r;
} Node;
 
Node *root, *NIL;
 
 
void insert(long k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
     
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->l = z->r = NIL;
     
    while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->l;
    else x = x->r;
    }
    z->p = y;
     
    if (y == NIL) root = z;
    else if (z->key < y->key) y->l = z;
    else y->r = z;
}
 
Node* find(Node *x, long k) {
    while (x != NIL && k != x->key) {
    if (k < x->key) x = x->l;
    else x = x->r;
    }
    return x;
}
 
void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->l);
    printf(" %d", u->key);
    inorder(u->r);
}
 
void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->l);
    preorder(u->r);
}
 
void print() {
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}
 
int main() {
    long n, i, x;
    char st[20];
    scanf("%ld", &n);
    for (i = 0; i < n; i++) {
    scanf("%s", st);
    scanf("%ld", &x);
    if (st[0] == 'f') {
        if (find(root, x) != NIL) printf("yes\n");
        else printf("no\n");
    }
    else if (st[0] == 'i') insert(x);
    else if (st[0] == 'p') print();
    }
    return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
int h,w,ch[50][50],nx,ny,dx[]={0,0,1,-1},dy[]={1,-1,0,0},tot;
string dp[50];
queue<pair<int,int>> que;
int main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>dp[i];
        for(int j=0;j<w;j++){
            if(dp[i][j]=='.')tot++;
        }
    }
    que.push({0,0});
    ch[0][0]=1;
    while(!que.empty()){
        auto q=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            nx=q.F+dx[i];
            ny=q.S+dy[i];
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&dp[nx][ny]=='.'){
                if(ch[nx][ny]==0){
                    ch[nx][ny]=1+ch[q.F][q.S];
                    que.push({nx,ny});
                }
            }
        }
    }
    
    if(ch[h-1][w-1]==0)cout<<-1<<endl;
    else {
        cout<<(tot-ch[h-1][w-1])<<endl;
    }
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

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

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

func reverseString(s string) string {
	n := len(s)
	bytes := []byte(s)
	for i := 0; i < n/2; i++ {
		bytes[i], bytes[n-1-i] = bytes[n-1-i], bytes[i]
	}
	return string(bytes)
}

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

	s := next()
	n := len(s)

	cnt := make([]int, 26)
	for i := range s {
		cnt[int(s[i]-'a')]++
	}

	ans := (n*(n-1))/2 + 1
	for i := range cnt {
		ans -= (cnt[i] * (cnt[i] - 1)) / 2
	}

	puts(ans)
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;

int main()
{
    int N, total_slimes = 0;
    char pre_slime = '\0';
    std::string S;
    cin >> N >> S;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == pre_slime)
        {
            continue;
        }
        else
        {
            total_slimes++;
            pre_slime = S[i];
        }
    }
    cout << total_slimes << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
Created on Sat Aug  4 18:19:03 2018

@author: maezawa
"""

n = int(input())
a = list(map(int, input().split()))

mean_a = round(sum(a)/n)

ans = 0
for i in a:
    ans += (i-mean_a)**2

print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define answer(formula) formula ? cout << "Yes" << endl : cout << "No" << endl
#define ANSWER(formula) formula ? cout << "YES" << endl : cout << "NO" << endl

#define PI M_PI
#define INF 1050000000
#define MOD 1000000007
#define EPS (1e-10)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<string>> vvs;

constexpr int dir[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };

ll Pow(ll a, ll b, ll mod) {
	ll x = 1;
	while (b > 0) {
		if (b & 1) x = x * a;
		a = a * a;
		b = b >> 1;
	}
	return x;
}


/*<ここから>***********************************************************/


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

	answer(N % 500 <= A);


	return 0;
}


Measured memory_bytes: 256
X,N = map(int,input().split())
if N>0:
    p_set = set(map(int,input().split()))
else:
    p_set = set()

min_dist_xp = 1000
for p in reversed(range(0,102)):
    if p not in p_set:
        dist_xp = abs(X-p)
        if dist_xp<=min_dist_xp:
            min_dist_xp = dist_xp
            ans = p

print(ans)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b;
    scanf("%d %d %d", &x, &a, &b);
    if(abs(x-a)==abs(x-b))
        printf("equal");
    else if(abs(x-a)<abs(x-b))
        printf("A");
    else
        printf("B");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e5+10,mod=1e9+7;
int n,a[N],d[N],cir[N],f[N],vis[N],sum[N],foot[N],Ans=1;
void GetTree(int x)
{
	int t=0,bs=1,fl=0;
	for(vis[x]=1,x=a[x];!fl;x=a[x])
	{
		if(vis[x]) fl=1;vis[x]=1;t++;
		if(foot[x]) bs=bs*(t<foot[x]?0:(t==foot[x]?1:2))%mod,t=0;
	}
	Ans=1ll*Ans*bs%mod;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],d[a[i]]++;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		int x=i;while(!vis[x]) vis[x]=i,x=a[x];
		if(vis[x]!=i) continue;
		while(!cir[x]) cir[x]=1,x=a[x];
	}
	for(int i=1;i<=n;i++)
		if((cir[i]&&d[i]>2)||(!cir[i]&&d[i]>1)) return puts("0"),0;
	for(int i=1;i<=n;i++)
		if(d[i]==0)
		{
			int x=i,t=0;
			while(!cir[x]) t++,x=a[x];
			foot[x]=t;
		}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
		if(cir[i]&&foot[i]&&!vis[i]) GetTree(i);

	for(int i=1;i<=n;i++)
		if(!vis[i]&&cir[i])
		{
			int x=i,t=0;
			while(!vis[x]) vis[x]=1,t++,x=a[x];
			sum[t]++;
		}
	for(int w=1,u;w<=n;w++)
	{
		f[0]=1;u=sum[w];
		if(!u) continue;
		for(int i=1;i<=u;i++)
		{
			f[i]=f[i-1]*(((w&1)&&w>1)?2:1)%mod;
			if(i>1) f[i]=(f[i]+1ll*(i-1)*f[i-2]%mod*w%mod)%mod;
		}
		Ans=1ll*Ans*f[u]%mod;
	}
	cout<<Ans<<endl;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>

#include <iostream>
#include <vector>
#include <queue>


#define MAX_N 100010
#define INF   10000000100

typedef long long ll;

typedef struct _edge {
    int to;
    ll  cost;
    _edge(int t, ll c) : to(t), cost(c) {}
} edge;

std::vector< edge > tree[MAX_N];
int N, Q, K;
ll  depth[MAX_N];

void dfs(int s, int p, ll d) {
    depth[s] = d;
    std::vector<edge>::iterator itr = tree[s].begin();
    while (itr != tree[s].end()) {
        edge e = *itr;
        if (e.to != p) dfs(e.to, s, d+e.cost);
        ++itr;
    }
}

int main() {
    std::cin >> N;
    for (int i=0; i<N-1; ++i) {
        int  a, b, c;
        std::cin >> a >> b >> c;
        --a; --b;
        tree[a].push_back( edge(b, c) );
        tree[b].push_back( edge(a, c) );
    }
    std::cin >> Q >> K;
    dfs(K-1, -1, 0);
    for (int q=0; q<Q; ++q) {
        int x, y;
        std::cin >> x >> y;
        --x; --y;
        std::cout << depth[x] + depth[y] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

const ll inf = 10000000000000000;
ll n, kolr, kolw, kol2;
string s;

int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    cin >> s;
    for (ll i = 0; i < n; ++i)
        if (s[i] == 'W')
            ++kolw;
        else
            ++kolr;
    for (ll i = 0; i < kolr; ++i)
        if (s[i] == 'W')
            ++kol2;
    cout << min(kol2, kolr);
    return 0;
}


Measured memory_bytes: 3776
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
//const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int rand(int l, int r){
//    uniform_int_distribution<int> uid(l, r);
//    return uid(rng);
//}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    ll ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int f(int k,int n) {
    if(n < k) return n;
    return f(k, n / k) + n % k;
}

void solve(){
    string s;
    cin >> s;
    int ans = 0;
    fr(i, 0, sz(s)) {
        if(!(i & 1)) {
            if(s[i] == 'p') ans--;
        }
        else {
            if(s[i] == 'g') ans++;
        }
    }
    cout << ans;
}

signed main(){
    IO;
#ifdef LOCAL
    freopen("inp.txt","r", stdin);
#endif
    cout << setprecision(3) << fixed;
    //    srand(time(NULL));
    //    build();
    int t = 1;
//    cin >> t;
    fr(tt, 1, t){
//        cout << "Case #" << tt << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define print(x) cout << x << '\n';

using namespace std;

string a[100];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.in", "r", stdin);
    
    int n, i;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> a[i];
        if(i > 0){
            if(a[i][0] != a[i-1][a[i-1].length()-1]){
                cout << "No";
                return 0;
            }
        }
        for(int j = 0; j < i; j++){
            if(a[i].compare(a[j]) == 0){
                cout << "No";
                return 0;
            }
        }
        // printf("now : %d\n", a[i]);
    }

    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int m, c, a, n;
    cin >> m;
    while (m--) {
        int ans = 0;
        cin >> c >> a >> n;
        while (c > 0 && a > 0 && n > 0) {
            c--;
            a--;
            n--;
            ans++;
        }
        while (c > 1 && a > 0) {
            c -= 2;
            a--;
            ans++;
        }
        while (c > 2) {
            c -= 3;
            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >>n){
    int sum = 0;
    for(int a = 0; a<10; a++){
      for(int b = 0; b<10; b++){
	for(int c = 0; c<10; c++){
	  for(int d = 0; d<10; d++){
	    if(n == a+b+c+d){sum++;}
	  }
	}
      }
    }
    cout <<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
	int t,hour,min,sec;
	cin >> t;
	hour = t / 3600;
	min = (t - hour*3600) / 60;
	sec = (t - hour * 3600 - min * 60);
	cout << hour << ":" << min << ":" << sec << endl;
	return 0;
}


Measured memory_bytes: 3100