akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

void dfs1(int i,int p,vector<vector<int>>& edges,vector<int>& l,vector<int>& u) {
    for (int j : edges[i]) if (j-p) {
        l[j] = max(l[j],l[i]-1);
        u[j] = min(u[j],u[i]+1);
        dfs1(j,i,edges,l,u);
        l[i] = max(l[i],l[j]-1);
        u[i] = min(u[i],u[j]+1);
    }
    if (l[i] > u[i]) {
        cout << "No" << endl;
        exit(0);
    }
}

void dfs2(int i,int p,vector<vector<int>>& edges,vector<int>& l) {
    for (int j : edges[i]) if (j-p) {
        dfs2(j,i,edges,l);
        if (l[i]%2 == l[j]%2) {
            cout << "No" << endl;
            exit(0);
        }
    }
}


int main() {
    int n,k;
    cin >> n;
    vector<vector<int>> edges(n);
    for (int i = 0;i < n-1;++i) {
        int u,v;
        scanf("%d%d",&u,&v);
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    vector<int> l(n,-1e7),u(n,1e7);
    cin >> k;
    for (int i = 0;i < k;++i) {
        int v,p;
        cin >> v >> p;
        v--;
        l[v] = p;
        u[v] = p;
        if (i == k-1) {
            dfs1(v,-1,edges,l,u);
            dfs1(v,-1,edges,l,u);
            dfs2(v,-1,edges,l);
        }
    }
    cout << "Yes" << endl;
    for (int i = 0;i < n;++i) cout << l[i] << "\n";
}

Measured memory_bytes: 14976
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++)
    cin >> W[i];
  int rsum = 0;
  int lsum = 0;
  for (int i = 0; i < N; i++)
    lsum += W[i];
  int mindiff = lsum;
  for (int i = 0; i < N; i++) {
    rsum += W[i];
    lsum -= W[i];
    mindiff = min({abs(rsum - lsum), mindiff});
  }
  cout << mindiff << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	static int N;
	static int[] A;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = new int[N];
		int[] cnt = new int[2];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			++cnt[A[i] % 2];
		}
		cnt[0] += cnt[1] / 2;
		cnt[1] %= 2;
		cnt[0] %= 2;
		if (cnt[1] * cnt[0] == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 33228
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
        int n, q;
        scanf("%d%d", &n, &q);
        vector<int> g(n);
        for (int i = 0; i < n; i ++) g[i] = i;
        set<int> pos;
        pos.insert(0);
        pos.insert(1);
        int ball = 0;
        while (q --) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                swap(g[a], g[b]);
                if (a == ball) ball = b;
                else if (b == ball) ball = a;
                //for (int i = 0; i < n; i++) cerr << g[i] << ' ';
                //cerr << endl;
                if (ball > 0) pos.insert(g[ball - 1]);
                if (ball < n - 1) pos.insert(g[ball + 1]);
        }
        printf("%d\n", (int) pos.size());
        return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main(){
	
	
	ll a,b,k; cin>>a>>b>>k;
	if(k <= a) cout<<a-k<<" "<<b<<"\n";
	else cout<<0<<" "<<max(0ll,b-(k-a));
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = [[] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    d = [0]*n
    d[0] = 1
    q = deque([0])
    p = [None]*n
    while q:
        x = q.popleft()
        nd = d[x]+1
        for y in v[x]:
            if not d[y]:
                d[y] = nd
                p[y] = x
                q.append(y)
    V = list(range(n))
    V.sort(key = lambda x:-d[x])
    t = [1]*n
    for x in V[:-1]:
        t[p[x]] += t[x]
    ans = n
    for x in range(n):
        tx = t[x]
        for y in v[x]:
            ty = t[y]
            if tx < ty:
                ans += pow(2,t[0]-tx,mod)-1
            else:
                ans += pow(2,ty,mod)-1
        ans %= mod
    print((n*pow(2,mod-2,mod)-ans*pow(2,(mod-2)*n%(mod-1),mod))%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 98680
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	vector<int>a(26);
	string b;
	while(cin>>b){for(int c=0;c<b.length();c++){
		if(b[c]>='a'&&b[c]<='z')a[b[c]-97]++;
		else if(b[c]>='A'&&b[c]<='Z')a[b[c]-65]++;
		}
			}
					for(int d=0;d<26;d++){
			cout<<char(d+'a')<<" : "<<a[d]<<endl;  }
}

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

using IV = std::vector<int>;
IV ToFixedIntArray(std::istream& is, int n) {
	IV ret(n);
	auto* dst = ret.data();
	while(n > 0) {
		--n;
		is >> *dst++;
	}
	return ret;
}

#include <iostream>

void DisableIOSync() {
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios::sync_with_stdio(false);
}
uint64_t CalcMinimum(
	const uint64_t Q,
	const uint64_t H,
	const uint64_t S,
	const uint64_t D,
	uint64_t Target
) {
	const auto getH = [Q, H](){
		return std::min(2*Q, H);
	};
	const auto getS = [&getH, S](){
		return std::min(2*getH(), S);
	};
	const auto getD = [&getS, D](){
		return std::min(2*getS(), D);
	};

	uint64_t res = 0;
	res += getD() * (Target / 2);
	Target &= 1;
	if(Target >= 1) {
		res += getS();
		Target -= 1;
	}
	return res;
}
int main() {
	DisableIOSync();
	const auto input = ToFixedIntArray(std::cin, 4);
	const uint64_t target = ToFixedIntArray(std::cin, 1)[0];
	std::cout << CalcMinimum(input[0], input[1], input[2], input[3], target) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 1000005
#define PB push_back
#define MP std::make_pair
#define FI first
#define SE second
typedef long long ll;
int nxt[M], head[M], to[M], id[M], deg[M], n, tot = 1;
bool used[M], dir[M];
int read() {
	char c = getchar(); int ans = 0; bool flag = 1;
	while (c < '0' || c > '9') flag &= (c != '-'), c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return flag ? ans : -ans;
}
void Write(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
}
void add(int u, int v) {
	nxt[++tot] = head[u], head[u] = tot, to[tot] = v;
	nxt[++tot] = head[v], head[v] = tot, to[tot] = u;
}
void DFS(int x) {
	for (int &i = head[x]; i; i = nxt[i])
		if (!used[i]) used[i] = used[i ^ 1] = dir[i] = true, DFS(to[i]);
}
int main() {
	n = read(); int root1 = 0, root2 = 0;
	for (int i = 1, fa; i <= n; i++)
		if ((fa = read()) == -1) root1 = i; else add(fa, i), ++deg[fa];
	for (int i = 1, fa; i <= n; i++)
		if ((fa = read()) == -1) root2 = i + n; else add(fa + n, i + n), ++deg[fa + n];
	add(root1, root2);
	for (int i = 1; i <= n; i++)
		if ((deg[i] &= 1) != (deg[i + n] &= 1)) return puts("IMPOSSIBLE"), 0;
		else if (deg[i] % 2 == 0) add(i, i + n), id[i] = tot;
	puts("POSSIBLE");
	for (int i = 1; i <= n * 2; i++) DFS(i);
	for (int i = 1; i <= n; i++, putchar(' '))
		if (deg[i] & 1) Write(0); else Write(dir[id[i]] ? 1 : -1);
	return 0;
}


Measured memory_bytes: 30152
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int64, n+1)
	b := make([]int64, n)
	for i := 0; i < n+1; i++ {
		fmt.Scanf("%d", &a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
	}
	var sum int64
	for i := n - 1; i >= 0; i-- {
		var t int64
		if a[i+1] < b[i] {
			t = a[i+1]
		} else {
			t = b[i]
		}
		sum += t
		b[i] -= t
		if a[i] < b[i] {
			t = a[i]
		} else {
			t = b[i]
		}
		sum += t
		a[i] -= t
		b[i] -= t
	}
	fmt.Println(sum)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  vll v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(all(v));
  if (v[0] == 5 && v[1] == 5 && v[2] == 7) YES();
  else NO();
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	sum := 0
	for i := 9; i <= n; i += 2 {
		d := 0
		for j := 1; j <= i; j++ {
			if i%j == 0 {
				d++
			}
		}
		if d == 8 {
			sum++
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
constexpr int MX = 22;
int a[MX][MX];
vector<ll> dp(1<<21, 0);
int n;

int main() {
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n;
    rep(i,n) {
        rep(j,n) {
            cin >> a[i][j];
        }
    }
    
    dp[(1<<n)-1] = 1;
    for(int k=n; k>=1; k--) {
        
        int comb = (1<<k)-1;
        while(comb < 1<<n) {
            for(int i=0; i<n; i++) {
                if(comb&(1<<i) and a[n-k][i]) {
                    dp[comb^(1<<i)] += dp[comb];
                    dp[comb^(1<<i)] %= mod;
                }
            }

            int x = comb & -comb; int y = comb + x;
            comb = ((comb&~y) / x >> 1) | y;
        } 
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 19416
#include <bits/stdc++.h>
using namespace std;
//cin.ignore();	// better to use 2 times getline(cin,s);
// g++ iterator.cpp -std=c++17
//cout << (A + B == C ? "YES" : "NO") << endl;
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){
   	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);}


int main(void)
{
  fast();
  int a[3][3];
  for(int i=0;i<3;i++)
  {
      for(int j=0;j<3;j++)
       {
          cin>>a[i][j];
       }
  }
  
    int n;
    cin>>n;
    while(n--)
    {
      int p;
      cin>>p;
      for(int j=0;j<3;j++)
      {
          for(int k=0;k<3;k++)
          {
              if(a[j][k]==p)
              {
                  a[j][k] = -1;
              }
          }
      }
    }
    for(int i=0;i<3;i++)
    {
        if(a[i][0]==-1 and a[i][1]==-1 and a[i][2]==-1)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    for(int i=0;i<3;i++)
    {
        if(a[0][i]==-1 and a[1][i]==-1 and a[2][i]==-1)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(a[0][0]==-1 and a[1][1]==-1 and a[2][2]==-1)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(a[2][0]==-1 and a[1][1]==-1 and a[0][2]==-1)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
     cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, k, x, y;
  cin >> n >> k >> x >> y;

  int ans = 0;
  REP(i,n){
    if(i < k ){
      ans += x;
    }else{
      ans += y;
    }
  }

  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn result<'a>(x: u64, y: u64) -> u64{
    if y > 1 { x + result(x, y-1)*10 } else {x}
}

fn main(){
    input!{
        a:usize,
        b:usize
    }
    print!("{}", (if a == b {"Yes"} else {"No"}).to_string())
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct Combination {
  vector<mint> fact, ifact;
  Combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int n,m;
  cin >> n >> m;
  map<int,int> f;
  int k = 0;
  for(int i = 2;i*i<=m; ++i){
    while(m%i==0){
      f[i]++;
      k = max(k,f[i]);
      m /= i;
    }
  }
  if(m>1) {
    f[m]++;
    k = max(k,f[m]);
  }

  Combination c(n+k);
  mint ans = 1;
  for(auto i:f){
    ans *= c(n-1+i.second,i.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
[n,w] = [int(i) for i in input().split()]
dp = [[0]*(w+1) for i in range(n)]
wv = []
for i in range(n):
    wv.append([int(j) for j in input().split()])
"""
dp[i][w] = v
i : i番目まで
w : それまでの合計
"""

for i in range(n):
    for j in range(w+1):
        if i == 0:
            dp[i][wv[i][0]] = wv[i][1]
        else:
            if j - wv[i][0] >= 0:
                dp[i][j] = max(dp[i-1][j],dp[i-1][j - wv[i][0]]+wv[i][1])
            else:
                dp[i][j] = dp[i-1][j]
print(max(dp[n-1]))
#print(dp)


Measured memory_bytes: 120044
# ARC098
def main():
    n = int(input())
    s = input()
    l, r = 0, s[1:].count("E")  # people needed to change the direction
    cnt = l + r
    for i in range(1, n):
        if s[i - 1] == "W":
            l += 1
        if s[i] == "E":
            r -= 1
        cnt = min(cnt, l + r)
    print(cnt)


if __name__ == "__main__":
    main()

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

int main()
{
	queue<pair<string, int> > G;
	string str;
	int n, m, q;

	cin >> n >> q;
	while (n--)
	{
		cin >> str >> m;
		G.push(make_pair(str, m));
	}

	int coun = 0, x;
	pair<string, int> u;

	while (!G.empty())
	{
		u = G.front();
		G.pop();
		x = min(u.second, q);
		coun += x;
		u.second -= x;
		if (u.second > 0)G.push(u);
		else
		{
			cout << u.first << " " << coun << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 6332
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{
	
	int n;cin>>n;
	int arr[n+1];

	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(i&1 && arr[i]&1){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 3632
/*
 * ITP1_7_A.cpp
 *
 *  Created on: 2016/05/21
 *      Author: suna
 */

#include <iostream>
#include <vector>

using namespace std;

//??°?????????????????±????§???????
struct MathScore
{
	int chukan_point;	//??????????¨?????????°
	int kimatu_point;	//??????????¨?????????°
	int saisi_point;	//???????¨?????????°
};

//???????????\?????¨
void inputData(vector<MathScore> *ms)
{
	MathScore input_ms;

	while(true)
	{
		cin >> input_ms.chukan_point
			>> input_ms.kimatu_point
			>> input_ms.saisi_point;

		if( (input_ms.chukan_point == -1) && (input_ms.kimatu_point == -1) && (input_ms.saisi_point == -1 ) )
		{
			break;
		}
		ms->push_back(input_ms);
	}
}

//????????????
void judgeGrade(vector<MathScore> *ms)
{
	int ABSENCE = -1;	//?¬????
	int sum_chukan_kimatu_point;		//????????¨?????????????¨?
	vector<MathScore>::iterator i;

	for(i = ms->begin(); i != ms->end(); i++)
	{
		if( (i->chukan_point == ABSENCE) || (i->kimatu_point == ABSENCE) )
		{
			cout << "F" << endl;
			continue;
		}

		//??????????¨???¨??????????¨????????¨?
		sum_chukan_kimatu_point = i->chukan_point + i->kimatu_point;

		if( sum_chukan_kimatu_point >= 80)
		{
			cout << "A" << endl;
		}
		else if( (sum_chukan_kimatu_point >= 65) && (sum_chukan_kimatu_point < 80) )
		{
			cout << "B" << endl;
		}
		else if( (sum_chukan_kimatu_point >= 50) && (sum_chukan_kimatu_point < 65) )
		{
			cout << "C" << endl;
		}
		else if( (sum_chukan_kimatu_point >= 30) && (sum_chukan_kimatu_point < 50) )
		{
			if(i->saisi_point >= 50)
			{
				cout << "C" << endl;
			}
			else
			{
				cout << "D" << endl;
			}
		}
		else if(sum_chukan_kimatu_point < 30)
		{
			cout << "F" << endl;
		}
	}
}

int main(void)
{
	//??°????????????????´???¨
	vector<MathScore> math_score;

	//???????????\???
	inputData(&math_score);

	//????????????
	judgeGrade(&math_score);
	return 0;
}

Measured memory_bytes: 1208
#include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>

using namespace std;

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};


int main(){
	int n,q;
	long long int t;
	long long int s[100000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	cin>>q;
	int ans=0;
	for(int i=0;i<q;i++){
		cin>>t;
		int SorM=0;
		int L=n;
		while(L-SorM>1){
			int mid=(L+SorM)/2;
			if(s[mid]>t){
				L=mid;
			}
			else{
				SorM=mid;
			}
		}
		if(s[SorM]==t){ans++;}
		//cout<<i<<" "<<t<<" "<<s[SorM]<<SorM<<endl;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3852
n = int(input())
t,a = map(int, input().split())
h = list(map(int,input().split()))
ans = 1
temp = t-h[0]*0.006
for i in range(n):
    loc = t-h[i]*0.006
    if abs(a-loc)<abs(a-temp):
        temp = loc
        ans = i+1
print(ans)

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    int a[n],b[n];
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    for(i=0;i<n-2;i++){
        if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	int target = 1;
	for( auto k : a ){
		if( k == target ) ++target;
	}
	if( target == 1 ) cout << -1 << endl;
	else cout << n-(target-1) << endl;
}

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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            a[i] = sc.nextInt();
        }

        long cnt = 0;
        long carry = 0;
        for (int i = 0; i < n; i++) {
            int b = sc.nextInt();
            if (a[i] <= b + carry) {
                cnt += a[i];
                a[i] -= carry;
                carry = b - Math.max(a[i], 0);
            } else {
                cnt += b + carry;
                carry = 0;
            }
//            debug(cnt, carry);
        }
        cnt += Math.min(a[n], carry);
        System.out.println(cnt);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 67024
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VS s(n);
    VI t(n);
    REP(i,n)cin>>s[i]>>t[i];
    string x;
    cin >> x;
    ll sum=0;
    int find=0;
    REP(i,n){
        if(find==1){
            sum+=t[i];
        }
        if(x==s[i]){
            find=1;
        }
    }
    cout << sum <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define ll long long
#define pi pair<int,int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int n;
double a[105],s,m;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    fort (i,n)
    {
        cin >> a[i];
        s+=a[i];
    }
    s/=n, m=s;
    fort (i,n)
        m=min(m,abs(s-a[i]));
    fort (i,n)
        if (abs(s-a[i])==m)
            rc(i-1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
const int mod = 1000000007;
struct mint {
	ll x;
	mint(ll x=0):x(x%mod){}

	bool operator>=(const mint a){
	return (x >= a.x)? 1: 0;
	}
	bool operator<(const mint a){
		return !(*this>=a);
	}
	bool operator>(const mint a){
		return (x > a.x)? 1:0;
	}
	bool operator<=(const mint a){
		return !(*this>a);
	}
	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;  //2 square
		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;
	}
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(100005);

mint f(int n, int k) {
  if (n < 0) return 0;
  // nPk = nCk * k!
  mint res = comb(n,k);
  res *= comb.fact[k];
  return res;
}

int n,k;
vector<int> v[100000+5];
//bool ok[100000+5];

 

mint dfs(int a, int p=-1){
	mint ans = 1;
	for(auto& x:v[a]){
		if(x==p) continue;
		ans *= dfs(x, a);
	}
	if(p!=-1) ans *= f(k-2,v[a].size()-1);
	else ans *= f(k,v[a].size()+1);
	return ans;
}

int main(){
	scanf("%d%d", &n, &k);
	FOR(i,1,n-1){
		int a, b; scanf("%d%d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	mint ans;
	ans = dfs(1);
	cout << ans.x;
	return 0;
}


Measured memory_bytes: 11904
n=int(input())
ant,bnt,cnt=1,1,1

for i in range(n) :
    ant=10*ant%1000000007
    bnt=9*bnt%1000000007
    cnt=8*cnt%1000000007

ans=(ant-(bnt*2-cnt))%1000000007

if ans>=0 :
    print(ans)
else :
    print(1000000007+ans) 

Measured memory_bytes: 9156
typedef struct{double x,y,k;}w;double k,t;w p[101],b;m,v[100],n,j;z(w*c,w*d){return c->k>d->k?-1:c->k<d->k;}double o(q,r,s){return p[q].x*(p[r].y-p[s].y)+p[r].x*(p[s].y-p[q].y)+p[s].x*(p[q].y-p[r].y);}main(i){for(;j=scanf("%d",&n)+~n;){for(m=i=0;i<n;i++)scanf("%lf,%lf",&p[i].x,&p[i].y),p[m].y>p[i].y?m=i:0;b=p[m];p[m]=*p;*p=b;p[100].x=b.x;p[100].y=b.y+1;for(i=1;i<n;i++)p[i].k=o(0,i,100)/hypot(p[i].x-b.x,p[i].y-b.y);qsort(p+1,n-1,sizeof(w),z);*v=0;v[1]=1;v[2]=j=2;for(i=3;i<n;i++){for(;o(v[j-1],v[j],i)<=0;j--);v[++j]=i;}printf("%d\n",n+~j);}}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()

typedef pair<int, int> P;

const int MOD = (int) 1e9 + 7;

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int d, n;
	cin >> d >> n;
	
	if (d == 0) {
		if (n == 100) {
			cout << 101 << endl;
		} else {
			cout << n << endl;
		}
	}
	if (d == 1) {
		if (n == 100) {
			cout << 10100 << endl;
		} else {
			cout << 100 * n << endl;
		}
	}
	if (d == 2) {
		if (n == 100) {
			cout << 1010000 << endl;
		} else {
			cout << 10000 * n << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, W; cin >> N >> W;
    vector<ll> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    for (int i=N-1; i>=0; --i) {
        rep(j, W+1) {
            if (j<w[i]) {
                dp[i][j] = dp[i+1][j];
            } else {
                dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]] + v[i]);
            }
        }
    }
    cout << dp[0][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()      scanf("")
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,x,a,b);
  a-=x;
  b-=x;
  if(abs(a)>abs(b))
    puts("B");
  else
    puts("A");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n;
  cin>>n;
  int64 a[n];
  rep(i,n){
    cin>>a[i];
  }
  if(n%2==0){
    rep(i,n/2){
      cout<<a[n-1-2*i]<<" ";
    }
    rep(i,n/2){
      cout<<a[2*i]<<" ";
    }
  }else{
    rep(i,(n+1)/2){
      cout<<a[n-1-2*i]<<" ";
    }
    rep1(i,(n+1)/2){
      cout<<a[2*i-1]<<" ";
    }
  }
}


Measured memory_bytes: 3712
#include<iostream>
using namespace std;
int main()
{
  char s[8][8];
  for(int i=0;i<8;i++)
    {
      string str;
      cin>>str;
      for(int j=0;j<8;j++)
	{
	  	  
	  s[i][j]=str.at(j);
	}
      
    }
  cout<<"90"<<endl;
for(int i=0;i<8;i++)
    {
      for(int j=7;j>=0;j--)
	{
	  cout<<s[j][i];
	}
      cout<<endl;
    }
 cout<<"180"<<endl;
for(int i=7;i>=0;i--)
    {
      for(int j=7;j>=0;j--)
	{
	  cout<<s[i][j];
	}
      cout<<endl;
    }
cout<<"270"<<endl;
for(int i=7;i>=0;i--)
    {
      for(int j=0;j<8;j++)
	{
	  cout<<s[j][i];
	}
      cout<<endl;
    }
  return 0;
}

Measured memory_bytes: 1184
def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return int(a / gcd(a, b)) * b

def lcml(l):
	if len(l) < 1:
		return 1
	elif len(l) == 1:
		return l[0]
	return lcm(l[0], lcml(l[1:]))

n = int(input())
print(lcml([int(x) for x in input().split()]))


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define mc map<char,ll>
#define itr ::iterator
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define fn(i,a,b) for(ll i=a;i>b;i--)
#define fne(i,a,b) for(ll i=a;i>=b;i--)
#define fm(it,m) for(it = m.begin();it != m.end();++it)
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007
#define pi 3.14159265358979323846


int main()
{  
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   IOS;
   
   int T=1;
   //cin>>T;
   f(t,0,T)
    { 
      ll n=0;
      //,i=0,j=0,k=0,flag=0;
      cin>>n;

      vi a(n),dp(n);
      
      f(i,0,n)
       cin>>a[i];

      dp[0]=0,dp[1]=abs(a[1]-a[0]);

      f(i,2,n)
       {
        dp[i] = min((dp[i-2]+abs(a[i]-a[i-2])),(dp[i-1]+abs(a[i]-a[i-1])));
       }
  
      cout<<dp[n-1]<<endl;
    }
  return 0;
}


Measured memory_bytes: 3952
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
    @a = gets.split.map(&:to_i)
  end

  def solve
    maxi = 0
    ans = 0
    a.each do |h|
      if maxi <= h
        maxi = h
      else
        ans += maxi - h
      end
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

int main(void)
{
	ll n, k; cin >> n >> k;
	vector<ll> h(n);
	each(e, h)
		cin >> e;

	ll ans = 0;
	each(e, h)
	{
		if (k <= e)
			ans++;
	}

	cout << ans;

	return 0;
}



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

int main(){
	int h[10]={};
	for(short int i=0; i<10;i++){

		cin >> h[i];
	}
	sort(h, h+10, greater<int>());
	for(short int i=0;i<3;i++){
		cout << h[i] << endl;
	}
	return 0;
}

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

long long N, Q;
static vector<long long> V[200000];
static long long COUNT[200000] = {};

void DFS(long long P, long long Q) {
	for (int NP : V[P]) {
		if (NP != Q) {
			COUNT[NP] += COUNT[P];
			DFS(NP, P);
		}
	}
}

int main() {
	cin >> N >> Q;
	for (int i = 0; i < N - 1; i++) {
		long long A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back(B);
		V[B].push_back(A);
	}
	for (int i = 0; i < Q; i++) {
		long long P, X;
		cin >> P >> X;
		P--;
		COUNT[P] += X;
	}
	DFS(0, -1);
	for (int i = 0; i < N; i++) {
		if (i != 0) cout << " ";
		cout << COUNT[i];
	}
	cout << endl;
}

Measured memory_bytes: 24320
n, k = map(int,input().split())
s = input()

press = []
temp = s[0]
cnt = 0
for string in s:
    if temp == string:
        cnt += 1
    else:
        press.append(cnt)
        temp = string
        cnt = 1
press.append(cnt)

if len(press) - 2 * k <= 0:
    print(n-1)
    exit()

ans = 2 * k
for i in press:
    ans += i - 1
print(ans)

Measured memory_bytes: 45296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque> 
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype> 
using namespace std;

int main(){
    int W, a, b;
    cin >> W >> a >> b;
    int cnt=0;
    int c=0;
    if (a+W<b) c=abs(a+W-b);
    else c=abs(b+W-a);
    if ((a<=(b+W) && (b+W)<=(a+W)) || (a<=b && b<=(a+W))) {
        cout << 0 << endl;
        return 0;
    }
    for (int i=0; i<c; i++) {
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll c[3][3];
    rp(i, 0, 3) rp(j, 0, 3) cin >> c[i][j];
    ll d[6];
    rp(i, 0, 3)
        d[i] = c[i][0] + c[i][1] + c[i][2];
    rp(i, 0, 3)
        d[i + 3] = c[0][i] + c[1][i] + c[2][i];
    set<ll> st, st2;
    rp(i, 0, 3)
    {
        st.insert(d[i] % 3);
        st2.insert(d[i + 3] % 3);
    }
    if (st.size() == 1 && st2.size() == 1)
    {
        ce("Yes");
    }
    else
    {
        ce("No");
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		List<Integer> c = new ArrayList<>();
		
		c.add(a + b);
		c.add(a - b);
		c.add(a * b);

		if(c.get(0) <= c.get(1)) {
			if(c.get(1) <= c.get(2)) {
				System.out.println(c.get(2));
				return;
			} else {
				System.out.println(c.get(1));
				return;
			}
		} else {
			if(c.get(0) <= c.get(2)) {
				System.out.println(c.get(2));
				return;
			} else {
				System.out.println(c.get(0));
				return;
			}
		}
	}
}

Measured memory_bytes: 23764
# -*- coding: utf-8 -*-

import heapq


class Tuple:
    def __init__(self, cost, y, x, dir):
        self.cost = cost
        self.y = y
        self.x = x
        self.dir = dir

    def __str__(self):
        return "y=" + str(self.y) + " : " + "x=" + str(self.x) + " : " + "dir=" + str(self.dir)

    def __cmp__(self, other):
        return self.cost - other.cost


dir_x = [1, 0, -1, 0]
dir_y = [0, 1, 0, -1]


def solve():
    X, Y = map(int, raw_input().split())
    if X == 0 and Y == 0:
        return -1

    stage = [map(int, raw_input().split()) for _ in range(Y)]
    C = map(int, raw_input().split())

    costs = [[[float("inf") for _ in xrange(4)] for _ in xrange(X)] for _ in xrange(Y)]

    costs[0][0][0] = 0
    queue = []

    heapq.heappush(queue, Tuple(0, 0, 0, 0))

    while len(queue) > 0:

        current = heapq.heappop(queue)
        if costs[current.y][current.x][current.dir] < current.cost:
            continue

        for operation in range(4):
            if operation == 0:
                # ????????? ?????£??´?????????

                next_dir = current.dir
            elif operation == 1:
                # ????????? ??????

                next_dir = (current.dir + 1) % 4
            elif operation == 2:
                # ????????? ?????¢

                next_dir = (current.dir + 2) % 4
            else:
                # ????????? ??????

                next_dir = (current.dir + 3) % 4
            # ????????? ??´????????????????????¢?????????????????????????????????????????\???????????¢??????????????????????????§???????????????

            next_x = current.x + dir_x[next_dir]
            next_y = current.y + dir_y[next_dir]
            next_cost = costs[current.y][current.x][current.dir]
            if stage[current.y][current.x] != operation:
                next_cost += C[operation]
            if 0 <= next_x < X and 0 <= next_y < Y:
                if costs[next_y][next_x][next_dir] > next_cost:
                    costs[next_y][next_x][next_dir] = next_cost
                    data = Tuple(next_cost, next_y, next_x, next_dir)
                    heapq.heappush(queue, data)

    return min(costs[Y - 1][X - 1])


if __name__ == '__main__':
    while True:
        result = solve()
        if result < 0:
            break

        print result

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

vector<pair<int,int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1; --y1; --x2; --y2;
	vector<string> grid(h);
	for (int i = 0; i < h; ++i){
		cin >> grid[i];
	}
	//do bfs from (x1, y1)
	auto valid = [&](const pair<int, int>& p){
		return p.first >= 0 && p.first < h && p.second >= 0 && p.second < w;
	};
	vector<vector<int>> dist(h, vector<int>(w, 1e9));
	vector<vector<bool>> vis(h, vector<bool>(w));
	function<void(pair<int, int>)> bfs = [&](pair<int, int> s){
		dist[s.first][s.second] = 0;
    	queue<pair<int, int>> Q;
		Q.emplace(s);
    	while (!Q.empty()) {
        	int x = Q.front().first;
        	int y = Q.front().second;
	        Q.pop();
    	    for (int i = 0; i < 4; i++) {
        	    for (int j = 1; j <= k; j++) {
            	    int xx = x + dir[i].first * j;
                	int yy = y + dir[i].second * j;
                	if (!valid({xx, yy})) continue;
	                if (grid[xx][yy] == '@' || dist[xx][yy] <= dist[x][y]) {
    	                break;
       	 	        }
    	        	if (vis[xx][yy]) {
     	  	          	continue;
                	}
                	dist[xx][yy] = dist[x][y] + 1;
                	vis[xx][yy] = 1;
                	Q.push({xx, yy});
            	}
        	}
    	}
	};
	bfs({x1, y1});
	if (dist[x2][y2] >= 1e9) dist[x2][y2] = -1;
	cout << dist[x2][y2] << '\n';
}


Measured memory_bytes: 12132
#include <iostream>

int main(){
  
  long long int N, K;
  scanf("%lld", &N);
  scanf("%lld", &K);
  
  if(K%2 == 1){
    long long int n1 = N/K;
    long long int ans = n1*n1*n1;
    std::cout << ans << std::endl;
  }
  else{ // if(K%2 == 0)
    long long int n1 = N/K;
    long long int n2 = (N+K/2)/K;
    long long int ans = n1*n1*n1 + n2*n2*n2;
    std::cout << ans << std::endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
from math import sqrt
from itertools import combinations
N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
print((N-1)*sum(map(lambda z: sqrt((z[0][0]-z[1][0])**2+(z[0][1]-z[1][1])**2), combinations(XY,2)))/len(list(combinations(XY,2)))) 


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

using namespace std;

int main() {
    long long x, k, d;
    cin >> x >> k >> d;
    if (x < 0) x = -x;
    long long temp;
    if (x % d == 0) temp = x / d;
    else temp = x / d + 1;
    if (k < temp) {
        printf("%lld\n", x - k * d);
        return 0;
    }
    k -= temp;
    x -= (temp * d);
    if (k % 2 == 0) printf("%lld\n", abs(x));
    else {
        printf("%lld\n", abs(x + d));
    }
    return 0;
}


Measured memory_bytes: 3720
N,K = map(int,input().split())

calc = (N-2) + sum([(N-i) for i in range(3,N)])

if calc < K :
    print(-1)

else :
    ans = []
    
    ans.append([1,2])
    
    for i in range(3,N+1) :
        ans.append([2,i])
    
    for i in range(3,N+1) :
        if calc <= K :
            break
        
        ans.append([1,i])
        calc -= 1
    
    for i in range(3,N) :
        if calc <= K :
            break
        
        for j in range(i+1,N+1) :
            if calc <= K :
                break
            
            ans.append([i,j])
            calc -= 1
    
    M = len(ans)
    
    print(M)
    
    for res in ans :
        print(*res)


Measured memory_bytes: 4120