akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 60
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll dp[MAXN][MAXN],c[MAXN][MAXN]; 
int n;
int main(){
	SF("%d",&n);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=i;j++){
			if(j==0)
				c[i][j]=1;
			else
				c[i][j]=(c[i-1][j-1]+c[i-1][j])%MOD;
		}
	dp[1][n]=1;
	dp[1][n-1]=1;
	for(int i=1;i<n;i++)
		for(int j=-i;j<=i;j++){
			for(int sum=max(1,abs(j));sum<=n-i;sum++){
				if((sum+j)%2)
					continue;
				for(int pos=0;pos<=sum;pos++){
					int t=sum-pos;
					int val=(j+pos-t)/2;
					if(val<-n||val>n)
						continue;
					dp[i+sum][val+n]+=dp[i][j+n]*c[i+sum][sum]%MOD*c[sum][pos]%MOD;
					dp[i+sum][val+n]%=MOD;
				}
			}
		}
	PF("%lld\n",dp[n][n]);
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , m , vis[N] , dis[N];
vector<pii> g[N];

void dfs(int c) {
  vis[c] = true;
  for(auto e : g[c]) {
    int t = e.fi;
    if(vis[t]) {
      if(dis[t] != dis[c] + e.se) {
        puts("No");
        exit(0);
      }
    } else {
      dis[t] = dis[c] + e.se;
      dfs(t);
    }
  }
}

int main(){
  scanf("%d%d",&n,&m);
  rep(i,0,m) {
    int l , r , d;
    scanf("%d%d%d",&l,&r,&d);
    g[l].pb(mp(r,d));
    g[r].pb(mp(l,-d));
  }
  rep(i,1,n+1) if(!vis[i])
    dfs(i);
  puts("Yes");
  return 0;
}


Measured memory_bytes: 11392
n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]

ans = [0]*(n)
ans[n-2] = csf[n-2][0] + csf[n-2][1] # go to the goal.
# print('ans', ans)
for i in range(n-3, -1, -1):
    # print('i =',i)
    ans_cur = csf[i][0] + csf[i][1] # go to the next station with 1st train. 
    for j in range(i+1, n-1):
        # print('j = ', j)
        if ans_cur < csf[j][1]: # arrive before 1st train.
            ans[i] = ans[j]
            break
        while ans_cur%csf[j][2] != 0:
            ans_cur += 1 # wait for next train.
        ans_cur += csf[j][0]
    else:
        ans[i] = ans_cur

for val in ans:
    print(val)

    





Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for (int i = (a) ; i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい


void Main(){
	ll W, H, x, y;
	cin >> W >> H >> x >> y;
	double ans;
	ans = W*H / 2.0;
	cout << ans << " ";
	if(W%2 == 0 && H%2 == 0 && x == W/2 && y == H/2) cout << 1 << endl;
	else cout << 0 << endl;





}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）
 
#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// ----- template end ---- //
 
// ------- library ------- //


// ----- library end ----- //



int main() {

  ll N, x;
  cin >> N >> x;

  priority_queue<ll, vector<ll>, greater<ll> > PQ;
  ll tmp;
  ll sum = 0;
  while (cin >> tmp){
    PQ.push(tmp);
    sum += tmp;
  }

  if (sum==x){
    cout << N << endl;
    return 0;
  }
  else if (x > sum){
    cout << N-1 << endl;
    return 0;
  }

  //あとはお菓子が足りない場合なので、小さい方から貪欲

  ll ans = 0;
  while (x>=0){
    x -= PQ.top();
    PQ.pop();
    if (x>=0){ //お菓子を渡せたということだから+1
      ++ans;
    }
  }

  cout << ans << endl;

  

// -- main() end -- //
}


 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n;
int a, b, c;
string s[MN];
string ans;

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

    cin >> n;
    cin >> a >> b >> c;
    F0R(i, n) cin >> s[i];
    F0R(i, n){
        if(s[i] == "AB"){
            if(a==0&&b==0){
                cout << "No\n";
                return 0;
            }
            if(a==0){
                ans.pb('A');
                ++a; --b;
            } else if(b == 0){
                ans.pb('B');
                ++b; --a;
            } else{
                if(i == n-1){
                    ans.pb('A');
                    ++a; --b;
                } else{
                    if(s[i+1] == "AC"){
                        ans.pb('A');
                        ++a; --b;
                    } else{
                        ans.pb('B');
                        ++b; --a;
                    }
                }
            }
        } else if(s[i] == "AC"){
            if(a==0&&c==0){
                cout << "No\n";
                return 0;
            }
            if(a==0){
                ans.pb('A');
                ++a; --c;
            } else if(c == 0){
                ans.pb('C');
                ++c; --a;
            } else{
                if(i == n-1){
                    ans.pb('A');
                    ++a; --c;
                } else{
                    if(s[i+1] == "AB"){
                        ans.pb('A');
                        ++a; --c;
                    } else{
                        ans.pb('C');
                        ++c; --a;
                    }
                }
            }
        } else{
            if(b==0&&c==0){
                cout << "No\n";
                return 0;
            }
            if(b==0){
                ans.pb('B');
                ++b; --c;
            } else if(c==0){
                ans.pb('C');
                ++c; --b;
            } else{
                if(i == n-1){
                    ans.pb('B');
                    ++b; --c;
                } else{
                    if(s[i+1] == "AB"){
                        ans.pb('B');
                        ++b; --c;
                    } else{
                        ans.pb('C');
                        ++c; --b;
                    }
                }
            }
        }
    }
    cout << "Yes\n";
    F0R(i, n) cout << ans[i] << "\n";
    
    return 0;
}


Measured memory_bytes: 6928
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    for (int i = 1; i <= 5; ++i) {
        int x;
        cin >> x;
        if (!x) {
            cout << i << endl;
        }
    }    

    return 0;
}


Measured memory_bytes: 3608
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
	string s;	
	long long k, j = 0;
	cin >> s;	
	int l = s.length();	
	for (int i = 0; i < l; i++)
	{ 
		if (s[i] != '1') break;	
		j++;
	}
	cin >> k;
	if (k <= j) printf("1\n");	
	else printf("%c\n", s[j]);
	return 0;
}

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

using namespace std;

int main()
{
	string s;
	int X, Y, ans = 0, x_init;
	vector<int> x, y;
	cin >> s;
	cin >> X >> Y;

	int state = -1;
	int count = 0;
	for (int i = 0; i < s.size();i++) {
		if (s[i] == 'F') {
			if (state == -1 || state == 0 || state == 2) { 
				count++; 
			}
			else if (state == 1) {
				state = 0;
				count++;
			}
			else {
				state = 2;
				count++;
			}
		}
		else if(s[i] == 'T')
		{
			if (state == -1) {
				x_init = count;
				count = 0;
				state = 3;
			}
			else if (state == 0) {
				x.push_back(count);
				count = 0;
				state = 3;
			}
			else if (state == 1) {
				state = 3;
			}
			else if (state == 2) {
				y.push_back(count);
				count = 0;
				state = 1;
			}
			else {
				state = 1;
			}
		}
	}

	if (state == -1) x_init = count;
	if (state == 0)  x.push_back(count);
	if (state == 2)  y.push_back(count);

	/*
	cout << x_init << endl << endl;
	for (int i = 0; i < x.size(); i++) {
		cout << x[i] << ' ';
	}
	cout << endl;
	for (int i = 0; i < y.size(); i++) {
		cout << y[i] << ' ';
	}
	cout << endl << endl;
	*/
	vector<vector<bool>> x_dp = vector<vector<bool>>(4001, vector<bool>(16001, false));
	vector<vector<bool>> y_dp = vector<vector<bool>>(4001, vector<bool>(16001, false));
	
	x_dp[0][x_init+8000] = true;////////////////////////////
	for (int i = 1; i <= x.size(); i++) {
		for (int j = 0; j < 16001; j++) {
			if (j + x[i - 1] < 16001 && j - x[i - 1] >= 0) x_dp[i][j] = x_dp[i - 1][j + x[i-1]] || x_dp[i - 1][j - x[i-1]];
			else if(j + x[i - 1] >= 16001 && j - x[i - 1] >= 0) x_dp[i][j] = x_dp[i - 1][j - x[i - 1]];
			else if(j + x[i - 1] < 16001 && j - x[i - 1] < 0) x_dp[i][j] = x_dp[i - 1][j + x[i - 1]];
			//if (x_dp[i][j])cout << 'x: ' << i << ',' << j << endl;
		}
	}

	y_dp[0][8000] = true;
	for (int i = 1; i <= y.size(); i++) {
		for (int j = 0; j < 16001; j++) {
			if (j + y[i - 1] < 16001 && j - y[i - 1] >= 0) y_dp[i][j] = y_dp[i - 1][j + y[i-1]] || y_dp[i - 1][j - y[i-1]];
			else if (j + y[i - 1] >= 16001 && j - y[i - 1] >= 0) y_dp[i][j] = y_dp[i - 1][j - y[i - 1]];
			else if (j + y[i - 1] < 16001 && j - y[i - 1] < 0) y_dp[i][j] = y_dp[i - 1][j + y[i - 1]];
			//if (y_dp[i][j])cout << 'y: ' << i << ',' << j << endl;
		}
	}

	if (x_dp[x.size()][X + 8000] && y_dp[y.size()][Y + 8000]) cout << "Yes"; 
	else cout << "No";

	//cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){

    int n,k;
    string s = "";

    cin >> n >> k;
    cin >> s;

    if(s[k-1] == 'A'){
        s[k-1] = 'a';
    }
    if(s[k-1] == 'B'){
        s[k-1] = 'b';
    }
    if(s[k-1] == 'C'){
        s[k-1] = 'c';
    }

    cout << s << endl;


}

Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
            if(N==1){
 			System.out.println("Hello World");
 			
        }else{
        int A = sc.nextInt();
        int B = sc.nextInt(); 

			System.out.println(A+B);
    }
}
}

Measured memory_bytes: 23380
class UnionFindVerSize():
    def __init__(self, N):
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self._parent = [n for n in range(0, N+1)]
        # グループのサイズ（個数）
        self._size = [1] * (N + 1)

    def find_root(self, x):
        """ xの木の根(xがどのグループか)を求める """
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x]) # 縮約
        return self._parent[x]

    def unite(self, x, y):
        """ xとyの属するグループを併合する """
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        """ xが属するグループのサイズ（個数）を返す """
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        """ グループ数を計算して返す """
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans
    
N, K, L = map(int, input().split())
p, q, r, s = [], [], [], []
uf1 = UnionFindVerSize(N)
uf2 = UnionFindVerSize(N)

for _ in range(K):
    tmp = list(map(int, input().split()))
    uf1.unite(tmp[0], tmp[1])
for _ in range(L):
    tmp = list(map(int, input().split()))
    uf2.unite(tmp[0], tmp[1])
    
d = {}
for i in range(1, N+1):
    k = uf1.find_root(i)
    l = uf2.find_root(i)
    d[(k, l)] = d.get((k, l), 0) + 1
    
ans = []
for i in range(1, N+1):
    ans.append(d[(uf1.find_root(i), uf2.find_root(i))])
print(*ans)

Measured memory_bytes: 55968
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    const R: usize = 3;

    let L = read!(usize);

    let N;
    let mut es = vec![];

    if L < R {
        N = 2;
        for i in 0..L {
            es.push((1, 2, i));
        }
    } else {
        let mut h = 0;
        let mut p = 1;
        while p * R <= L {
            p *= R;
            h += 1;
        }
        N = h + 1;

        let mut q = p;
        for i in 1..N {
            q /= R;

            for k in 0..R {
                es.push((i, i + 1, k * q));
            }
        }

        // s 未満の経路は生成済み
        let mut s = p;

        // j に到達すると長さ p 以下の経路が列挙される
        let mut j = 1;

        // debug!((p, s, j));

        while s < L {
            let t = L - s;

            while j <= 1 || p > t {
                p /= R;
                h -= 1;
                j += 1;
            }

            // debug!((p, s, t, j));

            // t + p 未満の経路が生成される
            es.push((1, j, s));

            s += p;
        }
    }

    let M = es.len();

    if N > 20 {
        panic!("too many vertices");
    }

    if M > 60 {
        panic!("too many edges");
    }

    println!("{} {}", N, M);
    for (u, v, w) in es {
        println!("{} {} {}", u, v, w);
    }
}


Measured memory_bytes: 4352
# coding:utf-8

import sys
import heapq
import itertools
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def dijkstra(start: int, size: int, graph: dict) -> list:
    costs = [INF] * size
    costs[start] = 0
    visited = set()
    hp = []
    heapq.heappush(hp, (0, start))
    while hp:
        hc, hv = heapq.heappop(hp)
        if hv in visited:
            continue
        for to, move_cost in graph[hv]:
            if hc + move_cost >= costs[to]:
                continue
            costs[to] = hc + move_cost
            heapq.heappush(hp, (costs[to], to))
        visited.add(hv)

    return costs


n, m, r = LI()
R = LI_()

G = defaultdict(list)
for i in range(m):
    a, b, c = LI()
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))

C = {}
for ri in R:

    C[ri] = dijkstra(ri, n, G)

ans = INF
for root in itertools.permutations(R):
    tmp = 0
    for i in range(r - 1):
        tmp += C[root[i]][root[i + 1]]
    ans = min(ans, tmp)

print(ans)


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

const int maxn = 1e5+5;
struct cityies{
    int p, y;
}city[maxn];

struct num{
    int id1, id2;
}id[maxn];
struct city2{
    int ord, y;
    bool operator < (const city2 &rhs) const{
        return y < rhs.y;
    }
};
vector<city2> v[maxn];
int p10[9], n, m;
void print(num x){
    for(int i = 5; i>=0;i--){
        putchar(x.id1/p10[i]+'0');
        x.id1 %= p10[i];
    }
    for(int i = 5; i>=0;i--){
        putchar(x.id2/p10[i]+'0');
        x.id2 %= p10[i];
    }
    puts("");
}
signed main(){
    p10[0] = 1;
    for(int i = 1; i <= 7; i++) p10[i] = p10[i-1]*10;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; i++){
        scanf("%d%d", &city[i].p, &city[i].y);
        v[city[i].p].push_back((city2){i, city[i].y});
    }
    for(int i = 1; i <= n; i++){
        sort(v[i].begin(), v[i].end());
        for(int j = 0; j < v[i].size(); j++){
            id[v[i][j].ord].id1 = i;
            id[v[i][j].ord].id2 = j+1;
        }
    }
    for(int i = 1; i <= m; i++){
        print(id[i]);
    }
    return 0;
}

Measured memory_bytes: 8576
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> ka(n, 0);
	for (int i = 0; i < (n*n - n) / 2; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if (c > d) {
			ka[a-1] += 3;
		}
		else if (c == d) {
			ka[a-1]++;
			ka[b-1]++;
		}
		else {
			ka[b-1] += 3;
		}
	}
	for (int i = 0; i < n; i++) {
		int jun = 1;
		for (int j = 0; j < n; j++) {
			if (ka[j] > ka[i]) {
				jun++;
			}
		}
		cout << jun << endl;
	}
}



Measured memory_bytes: 3124
#include <stdio.h>

char *
to_relationship(int a, int b)
{
	if (a == b) return "a == b";
	else if (a < b) return "a < b";
	else if (a > b) return "a > b";
	return "";
}

int
main()
{
	int a, b;
	scanf("%d %d", &a, &b);

	char *relation = to_relationship(a, b);
	printf("%s\n", relation);

	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc049_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> c(H, vector<char>(W, 0));
  rep(i, H) {
    rep(j, W) { cin >> c[i][j]; }
  }

  rep(i, 2 * H) {
    rep(j, W) { cout << c[i/2][j]; }
    cout << endl;
  }
}

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

#define N 200001

int main(void)
{
	int i,length,count=0;
	char str_s[N],str_t[N];

	scanf("%s",str_s);
	scanf("%s",str_t);

	length = strlen(str_s);

	for(i=0;i<length;i++){
		if(str_s[i]!=str_t[i]){
			count++;
		}
	}

	printf("%d\n",count);

	return 0;
}


Measured memory_bytes: 2120
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	long value;
	long stock;
} S_SHOP;

int cmpAscVal(const void * n1, const void * n2)
{
	if (((S_SHOP *)n1)->value > ((S_SHOP *)n2)->value)
	{
		return 1;
	}
	else if (((S_SHOP *)n1)->value < ((S_SHOP *)n2)->value)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  long n,m;
  scanf("%ld %ld", &n, &m);
  S_SHOP shops[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &shops[i].value, &shops[i].stock);
  }

  qsort(shops, n, sizeof(S_SHOP), cmpAscVal);

  long need = m;
  long spend = 0;
  for (long i = 0; i < n; i++) {
    if (shops[i].stock < need) {
      spend += shops[i].value*shops[i].stock;
      need -= shops[i].stock;
    } else {
      spend += shops[i].value*need;
      break;
    }
  }

  printf("%ld\n", spend);

  return 0;
}

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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N){
    cin >> a[i];
  }
  vector<int> color(9);//color[7]までは赤色までの各色の有無
  rep(i,N){
    if(a[i] <= 399) color[0] = 1;
    if(a[i] >= 400 && a[i] <= 799) color[1] = 1;
    if(a[i] >= 800 && a[i] <= 1199) color[2] = 1;
    if(a[i] >= 1200 && a[i] <= 1599) color[3] = 1;
    if(a[i] >= 1600 && a[i] <= 1999) color[4] = 1;
    if(a[i] >= 2000 && a[i] <= 2399) color[5] = 1;
    if(a[i] >= 2400 && a[i] <= 2799) color[6] = 1;
    if(a[i] >= 2800 && a[i] <= 3199) color[7] = 1;
    if(a[i] >= 3200) color[8]++;//任意の色の数
  }

  int mi = 0;
  int ma = 0;
  int c = 0;//赤までの色数
  rep(i,8){
    if(color[i]) c++;
  }
  if(c == 0 && color[8] != 0) mi = 1;
  else mi = c;
  
  ma = c + color[8];
  cout << mi << " " << ma << endl;
 }


Measured memory_bytes: 256
### constant

MAX_INT = 1 << 30

### subroutines

def min_cover(k, bits)
  return 0 if bits == 0
  return MAX_INT if k >= $x

  mc = min_cover(k + 1, bits)

  bits0 = bits & ~$masks[k]
  if (bits != bits0)
    mc0 = 1 + min_cover(k + 1, bits0)
    mc = mc0 if mc > mc0
  end

  mc
end

### main

loop do
  $x, $y = gets.split.map(&:to_i)
  break if $x == 0 && $y == 0

  $nbrs = $x.times.map{[]}
  $masks = $x.times.map{|k| 1 << k}

  $y.times do
    ai, bi = gets.split.map(&:to_i)
    $masks[ai] |= 1 << bi
    $masks[bi] |= 1 << ai
  end
  #p $masks

  puts min_cover(0, (1 << $x) - 1)
end

Measured memory_bytes: 6120
import bisect
N, Q = map(int, input().split())
S = input()
numlist = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        numlist.append(i)

l = [0 for i in range(Q)]
r = [0 for i in range(Q)]
for i in range(Q):
    ll, rr = map(int, input().split())
    l[i], r[i] = ll-1, rr-1

for i in range(Q):
    hajime = bisect.bisect_left(numlist, l[i])
    owari = bisect.bisect_right(numlist,r[i]-1)
    print(owari - hajime)

Measured memory_bytes: 15500
H, W = map(int, input().split())

data = [[-W]*W for i in range(H)]

for i in range(H):
    s = input()
    x = -(2*W)
    for j in range(W):
        if s[j] == '#':
            x = 0
        data[i][j] = x
        x += 1
    x = -(2*W)
    for j in range(W):
        if data[i][W-j-1] == 0:
            x = 0
        elif data[i][W-j-1] < 0:
            data[i][W-j-1] = x
        else:
            if x > 0:
                x = min(x, data[i][W-j-1])
            else:
                x = data[i][W-j-1]
            data[i][W-j-1] = x
        x += 1


for w in range(W):
    x = -(2*H)
    for h in range(H):
        if data[h][w] == 0:
            x = 0
        elif data[h][w] > 0:
            if x > 0:
                x = min(x, data[h][w])
            else:
                x = data[h][w]
            data[h][w] = x
        else:
            data[h][w] = x
        x += 1
    x = -(2*H)
    for h in range(H):
        if data[H-h-1][w] == 0:
            x = 0
        elif data[H-h-1][w] > 0:
            if x > 0:
                x = min(x, data[H-h-1][w])
            else:
                x = data[H-h-1][w]
            data[H-h-1][w] = x
        else:
            data[H-h-1][w] = x
        x += 1

ans = 0
for d in data:
    ans = max(ans, max(d))
print(ans)


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

int main(void){
    int x;
    cin>>x;
    for(int i=1;i<=x;i++){
        if(i % 3 == 0){
            cout << " " << i;
        }else if(i % 10 == 3){
            cout << " " << i;
        }else if((i%100)/10==3){
            cout << " " << i;
        }else if((i%1000)/100==3){
            cout << " " << i;
        }else if((i%10000)/1000==3){
            cout << " " << i;
        }

    }
    cout << endl;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 998244353;


int main() {
    int a, b; 
    cin >> a >> b;
    cout << a*b << endl;   
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  string add_f,add_r;
  int q;cin>>q;
  bool status=true;
  rep(i,q){
    int t;cin>>t;
    if(t==1){
      status=!status;
    }
    else{
      int f;char c;cin>>f>>c;
      if(f==1&&status){
        add_f+=c;
      }
      else if(f==1&&!status){
        add_r+=c;
      }
      else if(f==2&&status){
        add_r+=c;
      }
      else{
        add_f+=c;
      }
    }
  }
  if(status){
    reverse(ALL(add_f));
    cout<<add_f+s+add_r<<endl;
  }
  else{
    reverse(ALL(s));
    reverse(ALL(add_r));
    cout<<add_r+s+add_f<<endl;
  }
  return 0;
}


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

int main(){
  int N;
  cin >>N ;
  int p[N];
  for(int i=0; i<N; i++) 
    cin >> p[i];
  //ここまで入力

  int ans = 0;
  for(int i=0; i<N-1; i++)
    //左から順に部分的に完全順列を作っていく
    if(p[i] == i+1){
      swap(p[i], p[i+1]);
      ans++;
    }
  //最後が完全順列でなければ先頭と入れ替えればよい
  if(p[N-1] == N){
    swap(p[N-1], p[0] );
    ans++;
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a,b;
    cin >> a >> b;
    cout << a*b << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h> //Ithea_Myse_Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
 
int n,gg,p[109],c[109];
int dp[10010][109];
 
int main(){
int i,j,k;
n=read(),gg=read();
for (i=1;i<=n;i++) p[i]=read(),c[i]=read();
for (i=1;i<=n;i++){
  for (k=1000;~k;k--){
    for (j=1;j<p[i];j++) dp[k+j][i]=max(dp[k+j][i-1],dp[k][i-1]+j*i*100);     
	dp[k+p[i]][i]=max(dp[k+p[i]][i-1],dp[k][i-1]+p[i]*i*100+c[i]); 
	}
  }
for (i=1;i<=1000;i++){
  if (dp[i][n]>=gg){
    return write(i);
    }
  }
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;
    ll N,M,K;
    ll A[100010],B,C,X;
    bool F=true;
    ll ans=0;
    string S,T;
    priority_queue<ll,vector<ll>,greater<ll>> Q,W;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>S>>T;
    REP(i,(signed)S.size()){
        if(S[i]!=T[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3836
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
  print(0)
  exit()
N = (X+Y)//3
# C_N_X-N
MAX = 700000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
r = COM(N, X-N)
print(r)


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

typedef pair<int, int> P;
const int INF = 10000000;
const int H_MX = 50, W_MX = 50;
char field[H_MX][W_MX];
int h, w;
int d[H_MX][W_MX];
int d_r[4] = {0, -1, 1, 0}, d_c[4] = {-1, 0, 0, 1};

int bfs() {
    queue<P> que;
    fill(d[0], d[H_MX], INF);
    que.push(P(0, 0));
    d[0][0] = 0;
    while (que.size()) {
        P p = que.front();
        que.pop();
        if (p.first == h - 1 && p.second == w - 1) break;
        for (int i = 0; i < 4; i++) {
            int nr = p.first + d_r[i], nc = p.second + d_c[i];
            if (nr >= 0 && nr < h && nc >= 0 && nc < w) {
                if (field[nr][nc] == '.' && d[nr][nc] == INF) {
                    que.push(P(nr, nc));
                    d[nr][nc] = d[p.first][p.second] + 1;
                }
            }
        }
    }

    return d[h - 1][w - 1];
}

int main() {
    cin >> h >> w;
    int white_num = 0;
    for (int r = 0; r < h; r++) {
        for (int c = 0; c < w; c++) {
            cin >> field[r][c];
            if (field[r][c] == '.') white_num++;
        }
    }
    if (bfs() == INF) cout << "-1" << endl;
    else
        cout << white_num - 2 - (bfs() - 1) << endl;

    return 0;
}

Measured memory_bytes: 3612
import sys
A, B, K = (int(x) for x in input().split())
N = min([A, B]) + 1
counter, ans = 0, 1
for x in range(1, N):
    x = N - x
    if A % x == 0 and B % x == 0:
        ans = x
        counter += 1
    if counter == K:
        print(ans)
        sys.exit()

Measured memory_bytes: 3060
S = input()
K = int(input())

d = {}
for i in range(len(S)):
    for j in range(i+1,i+K+1):
        s = S[i:j]
        if s in d.keys():
            pass
        else:
            d[s] = 0

d = sorted(d.keys())
print(d[K-1])

Measured memory_bytes: 4856
#include<stdio.h>
#include<math.h>
 
int main(){
  double ans,N;
  
  scanf("%lf \n",&N);
  
  if(fmod(N,2.0) == 0){
    ans = 0.5000000000;
    printf("%lf",ans);
  }
  else{
    ans =(N+1)/(2*N);
    printf("%lf",ans);
    
  }
  
  return 0;
  
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**5+100)

N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N
 
# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    dp[i] = res
    return res
 
ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)

Measured memory_bytes: 166800
def solve():
  ans = 0
  mod = 10**9+7
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  for i in range(N):
    for j in range(i+1,N):
      if A[i]>A[j]:
        ans += 1
  ans *= K
  A.sort()
  lis = [0]*N
  for i in range(1,N):
    if A[i]>A[i-1]:
      lis[i] = i
    else:
      lis[i] = lis[i-1]
  ans += sum(lis)*K*(K-1)//2
  ans %= mod
  return ans
print(solve())

Measured memory_bytes: 9292
#include<bits/stdc++.h>
using namespace std;
int main(){string s;
cin>>s;
int n=0;
int sum=0;
for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T'){
        n++;
    }
    else{
        sum=max(n,sum);
        n=0;
    }
}
sum=max(sum,n);
cout<<sum<<endl;

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define szof(x) ((int)x.size())
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii; 
int const INF = (int)1e9+1e3;
ll const INFL = (ll)1e18+1e6;

const int N = 1e5+5;
ll items[101][2];
ll dp[N][101];
void solve(){
	int n,w;
	cin >> n >> w;
	for(int i=1;i<=n;i++)
		cin >> items[i][0] >> items[i][1];
	for(int i=0;i<=w;i++){
		dp[i][0] = 0;
	}
	for(int i=0;i<=n;i++){
		dp[0][i] = 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			dp[j][i] = dp[j][i-1];
			if(items[i][0]<=j){
				ll val = dp[j-items[i][0]][i-1]+items[i][1];
				dp[j][i] = max(dp[j][i],val);
			}
		}
	}
	cout << dp[w][n] << endl;
}   
    
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 82448
#include<stdio.h>
int main(){
  int n ;
  scanf("%d",&n);
  if (700<=n && n<=799)
    printf("Yes");
  else if (n%10==7)
    printf ("Yes");
  else if (70<=n%100 && n%100<=79)
    printf ("Yes");
    else printf ("No");
  return 0;
  }

Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    vector<int> l(26, 0), r(26, 0);
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            l[s[i] - 'a']++;
        } else {
            r[s[i] - 'a']++;
        }
    }

    int res = 0;
    for (int i = 1; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < 26; j++) {
            if (l[j] > 0 && r[j] > 0) {
                cnt++;
            }
        }

        if (res < cnt) {
            res = cnt;
        }

        l[s[i] - 'a']++;
        r[s[i] - 'a']--;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
# ABC175
# C
# 座標XからK回正または負にD移動
# できない
x, k, d = map(int, input().split())
c = abs(x) // d
if c > k:
    print(abs(x) - d * k)
else:
    x = abs(x) - d * c
    c = k - c
    if c % 2 == 0:
        print(abs(x))
    else:
        print(abs(abs(x)-d))


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

int main() {
    int x;
    cin >> x;
    int kyu = 8;
    int s = 600;
    int rank = 0;
    while (s <= 2000){
        if (x < s) {
        cout<<kyu<<endl;
        return 0;
        }

        s+=200;
        kyu-=1;
    }

}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vector<vector<pll>> G(N);
    REP(i,0,N-1) {
        ll a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        G[a].pb({b, c});
        G[b].pb({a, c});
    }
    ll Q, K;
    cin >> Q >> K;
    --K;
    vec X(Q), Y(Q);
    REP(i,0,Q) {
        cin >> X[i] >> Y[i];
        --X[i]; --Y[i];
    }

    queue<ll> R;
    vec D(N, INF);
    R.push(K);
    D[K] = 0;
    while(!R.empty()) {
        ll v = R.front(); R.pop();
        FORR(ne,G[v]) {
            ll nv = ne.first, d = ne.second;
            if(D[nv] > D[v] + d) {
                D[nv] = MIN(D[nv],D[v]+d);
                R.push(nv);
            }
        }
    }

    REP(i,0,Q) PR(D[X[i]]+D[Y[i]]);

    return 0;
}

/*



*/

Measured memory_bytes: 13580
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main() {
    char b;
    cin >> b;
    map<char, char> mp = {
            {'A', 'T'},
            {'T', 'A'},
            {'C', 'G'},
            {'G', 'C'}
    };
    cout << mp[b] << endl;
}





Measured memory_bytes: 256
X=int(input())
ans=0
for i in range(X+1):
    if i*i<=X:
        sum=i*i
        for j in range(X):
            if i**j>X:
                break
            sum=max(sum,i**j)
    else:
        break
    ans=max(ans,sum)

print(ans)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,ans=1;
  cin >>n;
  ll h[n+1];
  for(ll i=1;i<=n;i++) cin >>h[i];
  for(ll i=2;i<=n;i++){
    ll fl=0;
    for(ll j=1;j<=i;j++){
      if(h[j]>h[i]){
        fl=1;
        break;
      }
    }
    if(fl==0) ans++;
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DB double
#define SG string
#define LL long long
#define G(A,B) G[A][B]
#define Fp(A,B,C,D) for(A=B;A<=C;A+=D)
#define Fm(A,B,C,D) for(A=B;A>=C;A-=D)
#define Clear(A) memset(A,0,sizeof(A))
using namespace std;
const LL Max=1e3+5;
const LL Mod=1e9+7;
const LL Inf=1e18;
LL N,M,X,A[Max];
inline LL Read(){
	LL X=0;char CH=getchar();bool F=0;
	while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
	while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
	return F?-X:X;
}
inline void Write(LL X){
	if(X<0)X=-X,putchar('-');
	if(X>9)Write(X/10);
	putchar(X%10+48);
}
int main(){
	LL I,J,K;
	N=Read(),M=Read(),X=Read();
	Fp(I,1,M,1){
		A[I]=Read();
	}sort(A+1,A+1+M);
	Fp(I,1,M-1,1){
		if(A[I]<X&&X<A[I+1]){
			break;
		}
	}Write(min(I,M-I));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n, x;
    int cnt=0;
    while(1){
        cin >> n >> x;
        if(n==0 && x==0) break;
        else{
            for(int i=1; i<=n-2; i++){
                for(int j=i+1; j<=n-1; j++){
                    for(int k=j+1; k<=n; k++){
                        if(i+j+k==x) cnt++;
                    }
                }
            }
            cout << cnt << endl;
            cnt=0;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <string.h>

int main(){
	int a,b,c,i,num;
	scanf("%d",&num);
	
	for(i = 0;i < num;i++){
		scanf("%d %d %d",&a,&b,&c);
		a = a * a;
		b = b * b;
		c = c * c;
		if(a == (b + c) || c == (a+b) || b == (c + a)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}	
	}
	return 0;
}

Measured memory_bytes: 580
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL A, P;
	in >> A >> P;
	out << (A * 3 + P) / 2 << std::endl;
}


Measured memory_bytes: 764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {Main instance = new Main();sc = instance.new Scanner();instance.solve();}
    private class Scanner {String[] s = new String[0];String regex = " ";int i = 0;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public String next() {try {if (i < s.length) { return s[i++];}String st = br.readLine();while ("".equals(st)) { st = br.readLine(); }s = st.split(regex, 0);i = 0;return s[i++];} catch (IOException e) { return null; }}public int nextInt(){return Integer.parseInt(next());}}        

    private void solve() {
        int N = sc.nextInt();
        int A = sc.nextInt();
        int tmp = N%500;
        if (tmp<=A){
            System.out.println("Yes");
        } else {
            System.out.println("No");            
        }        
    }
}

Measured memory_bytes: 21076
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,m; cin >> n >> m;
    vector<int> a(n),b(m),c(m);

    for(int i = 0;i < n;i ++) cin >> a.at(i);
    for(int i = 0;i < m;i ++) cin >> b.at(i) >> c.at(i);

    vector<pair<int,int> > cb(m);
    for(int i = 0;i < m;i ++){
        cb.at(i).first = c.at(i);
        cb.at(i).second = b.at(i);
    }
    sort(a.begin(),a.end());
    sort(cb.begin(),cb.end());

    int ans = 0,rest = n;

    while(rest > 0 && cb.size() > 0){
        if(a.at(a.size()-1) > cb.at(cb.size()-1).first){
            ans += a.at(a.size()-1);
            rest --;
            a.pop_back();
        }else{
            ans += cb.at(cb.size()-1).first * min(rest,cb.at(cb.size()-1).second);
            rest -= min(rest,cb.at(cb.size()-1).second);
            cb.pop_back();
        }
    }

    while(rest > 0){
        ans += a.at(a.size()-1);
        rest --;
        a.pop_back();
    }

    cout << ans << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>

#define MIN(A,B) ((A) < (B) ? (A) : (B))

int main() {
  int n, a, b, train, taxi;
  scanf("%d %d %d", &n, &a, &b);
  train = a * n;
  taxi = b;
  printf("%d\n", MIN(train, taxi));
  return 0;
}

Measured memory_bytes: 128