akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> using LPQ = priority_queue<T, vector<T>, greater<T>>;
template<typename C> void dijkstra(int s, vector<vector<pair<int, C>>> const & g, vector<C> & d) {
	LPQ<pair<C, int>> q;
	d[s] = 0;
	q.emplace(d[s], s);
	while(! q.empty()) {
		C   c = q.top().FI;
		int v = q.top().SE;
		q.pop();
		if(d[v] != c) { continue; }
		for(auto & e : g[v]) {
			int ev = e.FI;
			C   ec = e.SE;
			if(setmin(d[ev], d[v] + ec)) { q.emplace(d[ev], ev); }
		}
	}
}

int main() {
	IN(int, n, m, s);
	const int M = 50 * n;
	const int V = n * (M + 1);
	auto id = [&](int i, int j) { return (M + 1) * i + j; };
	vector<vector<pair<int, LL>>> g(V);
	inc(i, m) {
		IN(int, x, y, a, b);
		x--; y--;
		incII(j, a, M) {
			g[id(x, j)].EB(id(y, j - a), b);
			g[id(y, j)].EB(id(x, j - a), b);
		}
	}
	inc(i, n) {
		IN(int, c, d);
		inc(j, M) {
			g[id(i, j)].EB(id(i, min(j + c, M)), d);
		}
	}
	
	const LL INF = 1e18;
	vector<LL> d(V, INF);
	dijkstra<LL>(id(0, min(s, M)), g, d);
	incID(i, 1, n) {
		LL ans = INF;
		incII(j, 0, M) { setmin(ans, d[id(i, j)]); }
		OUT(ans);
	}
}


Measured memory_bytes: 23804
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int L = Integer.parseInt(sc.next());
		String s[] = new String[N];
		for (int i = 0; i < N; i++) {
	        s[i] = sc.next();
		}
		String result = "";
        Arrays.sort(s, (s1, s2) -> s1.compareTo(s2));
		for (int i = 0; i < N; i++) {
			result += s[i];
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 40512
from operator import itemgetter

N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
# 降順ソート

qs = [list(map(int, input().split())) for _ in range(M)]
qs.sort(key=itemgetter(1), reverse=True)
# Cj降順ソート

qi = 0
cnt = 0
ans = 0
for aa in a:
    while cnt < N and qi < M and qs[qi][1] > aa:
        t = min(qs[qi][0], N - cnt)
        cnt += t
        ans += qs[qi][1] * t
        qi += 1
    if cnt == N:
        break
    ans += aa
    cnt += 1
    if cnt == N:
        break
print(ans)


Measured memory_bytes: 33016
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
 
public class Main {	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		String s = br.readLine();		
		long k = Integer.parseInt(br.readLine());	
		int cnt = 1;
		long sum = 0;
		char c = s.charAt(0);
		boolean allSame = true;
		for (int i = 1; i < s.length(); i++) {
			if (c != s.charAt(i)) {
				sum += cnt/2;
				cnt = 1;
				c = s.charAt(i);
				allSame = false;
			}else
				cnt++;
		}
		if (allSame) {
			bw.write((k * s.length()) / 2 + "\n");
			bw.flush();
			return;
		}
		sum += cnt/2;
		if (s.charAt(0)!=s.charAt(s.length()-1)) {
			bw.write(sum*k + "\n");
			bw.flush();
			return;
		}
		s += s;
		cnt = 1;
		long sum2 = 0;
		c = s.charAt(0);
		for (int i = 1; i < s.length(); i++) {
			if (c != s.charAt(i)) {
				sum2 += cnt/2;
				cnt = 1;
				c = s.charAt(i);
			}else
				cnt++;
		}
		sum2 += cnt/2;
		bw.write(sum + (sum2-sum)*(k-1) + "\n");
		bw.flush();
		bw.close();
		br.close();
	}
}

Measured memory_bytes: 22996
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;



ll dp[51][51][2501];

int main() {
	int n;
	cin >> n;
	int a; cin >> a;
	vector<int>x(n);
	FOR(i,0, n) {
		cin >> x[i];
	}
	
	int X =max(*max_element(all(x)),a);
	rep(j, n+1)rep(k, n+1)rep(s, n*X+1) {
		if (j == 0 && k == 0 && s == 0) {
			dp[j][k][s] = 1;
		}
		else if (j >= 1 && s < x[j-1]) {
			dp[j][k][s] = dp[j - 1][k][s];
		}
		else if (j >= 1 && k >= 1 && s >= x[j-1]) {
			dp[j][k][s] = dp[j - 1][k][s] +
				dp[j - 1][k - 1][s - x[j-1]];
		}
		else {
			dp[j][k][s] = 0;
		}
	}
	ll count = 0;
	FOR(i,1, n+1) {
		count += dp[n][i][i*a];
	}
	cout << count << endl;
}


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

#define int int64_t
#define MAX_N 105
#define MAX_W 100005

#define INF LONG_LONG_MAX/2

using namespace std;

int N,W;

pair<int,int> input[MAX_N];
int dp[MAX_N][MAX_W];

//v ist wieviel noch platz ist
int f(int index, int v) {
    if(index == N+1)return 0;
    if(v <= 0)return 0;

    if(dp[index][v] != -1) return dp[index][v]; 

    dp[index][v] = f(index+1, v);

    if(v-input[index].first >= 0)  
        dp[index][v] = max(dp[index][v],input[index].second + f(index+1, v - input[index].first));

    return dp[index][v];
}

signed main() {
    scanf("%lld %lld", &N, &W);

    int w,v;
    for(int i = 1; i<=N; i++) {
        scanf("%lld %lld", &w, &v);
        input[i] = make_pair(w,v);
    }

    for(int y = 0; y<=N+1; y++) {
        for(int x= 0; x<=W+1; x++){
            dp[y][x] = -1;
        }
    }

    printf("%lld\n", f(1, W));
}

Measured memory_bytes: 80128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define int ll

//ICPC Ranking  AOJ

#define MAX 60
int tt[55];
int pena[55][15];
int point[55];
bool done[MAX];

signed main(){
  int M,T,P,R;
  while(cin>>M>>T>>P>>R&&!(M==0&&T==0&&P==0&&R==0)){
    for(int i=0; i<=55; i++){
      for(int j=0; j<=15; j++){
        pena[i][j]=0;
      }
      tt[i]=0;
      point[i]=0;
      done[i]=false;
    }
    
    for(int i=0; i<R; i++){
      int m,t,p,j;
      cin>>m>>t>>p>>j;
      if(j){
        pena[t][p]++;
      }else{
        tt[t]+=m;
        tt[t]+=pena[t][p]*20;
        point[t]++;
      }
    }
    
    PR pre;
    for(int i=1; i<=T; i++){
      int m=0,t=0;
      int nowt=0;
      for(int j=1; j<=T; j++){
        if(done[j]) continue;
        if(point[j]>m){
          nowt=j;
          m=point[j];
          t=tt[j];
        }else if(point[j]==m){
          if(tt[j]<=t){
            nowt=j;
            m=point[j];
            t=tt[j];
          }
        }
      }
      
      done[nowt]=true;
      if(i==1) cout<<nowt;
      else{
        if(pre.first==m&&pre.second==t){
          cout<<'='<<nowt;
        }else{
          cout<<','<<nowt;
        }
      }
      
      pre.first=m; pre.second=t;
    }
    cout<<en
  }
  RE
}



Measured memory_bytes: 3108
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int is_prime[400001];
  REP1(i, 400000) is_prime[i] = true;
  is_prime[1] = false;
  for (int i = 2; i * i <= 400000; ++i) {
    if (is_prime[i]) {
      for (int j = 2; i * j <= 400000; ++j) is_prime[i * j] = false;
    }
  }
  int sum[400001];
  sum[0] = 0;
  REP(i, 400000) sum[i + 1] = sum[i] + is_prime[i + 1];
  int n;
  while (cin >> n && n) {
    cout << sum[2 * n] - sum[n] << endl;
  }
  return 0;
}


Measured memory_bytes: 6196
#include <bits/stdc++.h>
using namespace std;
#define endl            "\n"
#define ll                long long
#define all(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define clr(v, d)        memset(v, d, sizeof(v))
#define rep(i, v)        for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define vi                vector <int>
#define vl                vector <ll>
#define ii                pair <ll,ll>
#define vii                vector <ii>
const double PI = 2 * acos(0.0);
void run() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
}
const ll M = 3 * 1e3, mod = 1e9 + 7;
int n;
ll dp[M + 5][M + 5][2];
vi v;
ll sol(int i, int j, bool turn) {
	if (i > j)
		return 0;
	ll &ret=dp[i][j][turn];
	if(~ret)return ret;
	if (turn) {
		return ret=max(sol(i + 1, j, !turn) + v[i], sol(i, j - 1, !turn) + v[j]);
	} else {
		return ret=min(sol(i + 1, j, !turn) - v[i], sol(i, j - 1, !turn) - v[j]);
	}
}
int main() {
	run();
	cin >> n;
	v.resize(n);
	lp(i,n)
		cin >> v[i];
	clr(dp, -1);
	cout << sol(0, n - 1, 1);
}


Measured memory_bytes: 141568
N, K = map(int, input().split())
mod = 10**9 + 7

cnt = 0
for k in range(K, N+2):
    mn = k*(k-1)//2
    mx = N*(N+1)//2 - (N-k)*(N-k+1)//2
    cnt += mx-mn+1
    cnt %= mod

print(cnt)


Measured memory_bytes: 9128
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

ll bpow(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n & 1) res *= a;
        a *= a;
        res %= MOD;
        a %= MOD;
        n >>= 1;
    }
    return res;
}

ll MAX = 1e6+10;

ll inv(ll x)
{
    return bpow(x, MOD-2) % MOD;
}

ll combi(ll n, ll r) // O(min(r, n-r))
{
    r = min(r, n-r);
    ll res = 1;
    ll u = 1, d = 1;
    for(ll i = 1; i <= r; i++)
    {
        u *= (n-i+1);
        u %= MOD;
        d *= i;
        d %= MOD;
    }
    return (u * inv(d) % MOD) % MOD;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    
    ll X, Y; cin >> X >> Y;
    if((X+Y) % 3 != 0)
    {
        cout << 0 << endl;
        return 0;
    }
    ll n = (2*Y-X)/3, m = (2*X-Y)/3;
    if(n < 0 || m < 0)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ans = combi(n+m, n);
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	
	int n; cin >> n;
	if(n==0) cout << 1;
	else if(n==1) cout << 0;
	
	return 0;
}

Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

static int like2017[100001] = { 0 };

static int isP(int x)
{
	int i;
	int result = 1;

	if (x == 2){
		result = 1;
	}
	else if (x % 2 == 0){
		result = 0;
	}
	else{
		for (i = 3; i*i <= x; i += 2){
			if (x%i == 0){
				result = 0;
				break;
			}
		}
	}
	return result;
}

int main(void)
{
	int q;
	int i;

	for (i = 3; i < 100001; i += 2){
		like2017[i - 1] = like2017[i - 2];
		like2017[i] = like2017[i - 1];
		if (isP(i) && isP((i + 1) / 2)){
			like2017[i] += 1;
		}
	}

	scanf("%d", &q);
	while (q-- > 0){
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", like2017[r] - like2017[l - 1]);
	}

	return 0;
}


Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntSplit(len int) ([]int, map[int]int) {
	buf := make([]byte, 0) //ここのサイズは何でもよさそう
	sc.Buffer(buf, 1000000009)

	mp := make(map[int]int)
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " ") {
		tmp, err := strconv.Atoi(v)
		if err == nil {
			arr[i] = tmp
			mp[tmp]++
		}
	}
	return arr, mp
}

func main() {
	var n int
	fmt.Scan(&n)
	sl, mp := scanIntSplit(n)

	var sum int
	for _, v := range mp {
		sum += v * (v - 1) / 2
	}

	for k := 0; k < n; k++ {
		ans := sum
		if mp[sl[k]] > 1 {
			a := mp[sl[k]] * (mp[sl[k]] - 1) / 2
			b := (mp[sl[k]] - 1) * (mp[sl[k]] - 2) / 2
			ans = sum - (a - b)
		}

		fmt.Println(ans)
	}
}


Measured memory_bytes: 21508
N = int(input())
power = 1
A = 10**9 + 7

  #yをxで割った時の商をa、余りをbとすると、y=ax+b
  #ここにiを掛けると、y=(ax+b)i
  #y=aix+bi、となるので第１項は余りが０になる
  #なので、毎回割って、その余りにのみ注目すれば良い

for i in range(1, N+1):
  power = power * i % A

print(power)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

  int n, m; cin >> n >> m;
  vector< int > g[n];
  for(int i=1; i<=m; i++) {
    int u, v, w; cin >> u >> v >> w;
    u--, v--;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }

  int vis[n]; fill(vis, vis+n, 0);

  function<void(int)> dfs =
    [&](int u) {
      vis[u] = 1;
      for(int v: g[u]) {
        if( vis[v] != 0 ) continue;
        dfs(v);
      }
    };

  int ans = 0;
  for(int i=0; i<n; i++) if( vis[i] == 0 ) {
    ans++;
    dfs(i);
  }
  cout << ans << nl;

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


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

long long n;
vector<long long> a;

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  bool ch = 1;
  for(int i = 0; i < n; ++i)
    if(a[i] % 2 == 0) {
      if(a[i] % 3 != 0 && a[i] % 5 != 0) ch = 0;
    }
  if(ch)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
  return 0;
}

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

struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node minimum(Node x){

  while(x->l != NIL)
    x = x->l;
  return x;
}

Node search(Node u, int k){
  if(u == NIL || u->key == k)
    return u;
  else if(u->key > k)
    return search(u->l, k);
  else if(u->key < k)
    return search(u->r, k);
}

Node successor(Node x){
  Node y;

  if(x->r != NIL)
    return minimum(x->r);
  y = x->p;
  while(y != NIL && x == y->r){
    x = y;
    y = y->p;
  }
  return y;
}

void delete(Node z){
  Node y;
  Node x;
  
  if(z->l == NIL || z->r == NIL)
    y = z;
  else
    y = successor(z);
  if(y->l != NIL)
    x = y->l;
  else
    x = y->r;
  if(x != NIL)
    x->p = y->p;
  if(y->p == NIL)
    root = x;
  else if(y == y->p->l)
    y->p->l = x;
  else
    y->p->r = x;
  if(y != z)
    z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->l;
    else
      x = x->r;
  }
  z->p = y;
  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->l = z;
  else
    y->r = z;
}

void inorder(Node u){
  if(u->l != NIL)
    inorder(u->l);
  printf(" %d",u->key);
  if(u->r != NIL)
    inorder(u->r);
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->l != NIL)
    preorder(u->l);
  if(u->r != NIL)
    preorder(u->r);
}


int main(){
  int n, i, x;
  char com[20];
  Node t;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      t = search(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      delete(search(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20540
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

struct tri{
  ll f,s,t;
};

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;ll K;cin >> N >> K;
  if(2*K-1>N){
    cout << -1 << endl;
    return 0;
  }

  vector<PII> v(N);
  ll b;
  int index = 0;
  b = K+2*N-1-N/2;
  if(N%2==1 && K%2==1)--b;
  repp(x,K,K+N){
    if(x&1)continue;
    v[index].first = x+b;
    v[index].second = x;
    ++index;
    --b;
  }

  b = K+2*N-1;
  repp(x,K,K+N){
    if((x&1)==0)continue;
    v[index].first = x+b;
    v[index].second = x;
    ++index;
    --b;
  }

  sort(all(v));
  ll c = K+2*N;
  queue<tri> que;
  rep(i,N){
    que.push({v[i].second,v[i].first-v[i].second,c});
    ++c;
  }
  while(!que.empty()){
    tri t = que.front();que.pop();
    cout << t.f SP t.s SP t.t << endl;
  }
  return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
ll CombinationSum(ll n)
{
	if (n <= 0) {
		return 1;
	}
	
	ll ans = 0;
	for (ll i = 0; i <= n; i ++) {
		ll sum = 1;
		for (ll j = 0; j < i; j++) {
			sum *= (n - j);
			sum /= (i - j);
		}
		ans += sum;
	}

	return ans;
}

int main()
{
	string S;
	cin >> S;

	ll ans = 0;
	ll bitMax = 1 << (S.size() - 1);
	for (ll bitPtn = 0; bitPtn < bitMax; bitPtn++) {
		ll rate = 1;
		for (ll j = S.size() - 1; 0 <= j; j--) {
			if (bitPtn & (1 << j)) {
				rate = 1;
			}
			ans += (S[j] - '0') * rate;
			rate *= 10;
		}
	}

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



Measured memory_bytes: 256
from collections import deque
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
q=int(input())
bc=[list(map(int, input().split())) for _ in range(q)]
sa=sum(a)
hako=deque([0 for _ in range(10**5+1)])
aa=Counter(a)
for i in aa:
    hako[i]=aa[i]
# print(hako)

for i in range(q):

    sa+=(bc[i][1]-bc[i][0])*hako[bc[i][0]]
    print(sa)
    hako[bc[i][1]]+=hako[bc[i][0]]
    hako[bc[i][0]]=0
    # print(hako)




# print(hako)


Measured memory_bytes: 103564
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,sum=0;
    cin>>n;
    bool b[n+1];
    memset(b, false, sizeof(b));
    int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        if(i!=1 && arr[i]==arr[i-1]+1)
            b[arr[i-1]]=true;
    }
    for(int i=0;i<n;i++)
    {
        cin>>x;
        sum+=x;
    }
    for(int i=1;i<n;i++)
    {
        cin>>x;
        if(b[i]==true)
            sum+=x;
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, C[500], S[500], F[500];
int main()
{
    cin >> N;
    for (int i = 0; i < N - 1; i++)
        cin >> C[i] >> S[i] >> F[i];
    for (int i = 0; i < N; i++)
    {
        int t = 0;
        for (int j = i; j < N - 1; j++)
        {
            if (t < S[j])
                t = S[j];
            else if (t % F[j] == 0)
                ;
            else
                t = t + F[j] - t % F[j];
            t += C[j];
        }
        cout << t << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N,K;
    cin>>N>>K;
    vector<int> x(N);
    int ans=1<<29;
    for(int i=0;i<N;i++){
            cin>>x[i];
      	if(i>=K-1){
         	ans=min(ans,(x[i]-x[i-K+1])+min(abs(x[i]),abs(x[i-K+1])));
        }
    }               
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
time = []
min = nil
min_1 = 9
5.times do
  x = gets.chomp
  min ||= x.to_i
  if x[-1].to_i != 0 && x[-1].to_i <= min_1
    min_1 = x[-1].to_i
    min = x.to_i
  end
  time << x.to_i
end
time.delete_at(time.find_index(min))
puts time.inject(min){|a,b| a+b.ceil(-1) }


Measured memory_bytes: 14332
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >>n;
    cout << n/3 << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const int MOD = 1000000007;
const int INF = 1000000000;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int h, w;
vector<vector<char> > field;
vector<vector<int> > dist;

int bfs(int sx, int sy, int gx, int gy) {
    queue<pair<int, int> > PQ;
    PQ.push(make_pair(sx, sy));

    while (! PQ.empty()) {
        int x = PQ.front().first, y = PQ.front().second;
        PQ.pop();
        // if (x == gx && y == gy) break;

        for (int i = 0; i < 4; ++i) {
            if (x + dx[i] < 0 || x + dx[i] >= h || y + dy[i] < 0 || y + dy[i] >= w) continue;
            if (field[x + dx[i]][y + dy[i]] == '#') continue;
            if (dist[x + dx[i]][y + dy[i]] > dist[x][y] + 1) {
                PQ.push(make_pair(x + dx[i], y + dy[i]));
                dist[x + dx[i]][y + dy[i]] = dist[x][y] + 1;
            }
        }
    }

    return dist[gx][gy];
}

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    cin >> h >> w;
    field.resize(h, vector<char>(w));
    dist.resize(h, vector<int>(w));
    for (int i = 0; i < h; ++i) {
        string S;
        cin >> S;
        for (int j = 0; j < w; ++j) field[i][j] = S[j];
    }

    int ans = 0;
    for (int sx = 0; sx < h; ++sx) {
        for (int sy = 0; sy < w; ++sy) {
            for (int gx = 0; gx < h; ++gx) {
                for (int gy = 0; gy < w; ++gy) {
                    // cout << sx << " " << sy << " " << gx << " " << gy << endl;
                    if (field[sx][sy] == '#' || field[gx][gy] == '#') continue;
                    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) dist[i][j] = INF;
                    dist[sx][sy] = 0;
                    ans = max(ans, bfs(sx, sy, gx, gy));
                    // cout << ans << endl;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n,p;
	while(cin>>n>>p,n+p)
	{
		int a[n];
		for (int i = 0; i < n; ++i) a[i]=0;
		int turn=0,s=p;
		while(1)
		{
			if(s>0)
			{
				++a[turn],--s;
				if(a[turn]==p) break;
				++turn;
				if(turn==n) turn=0;
			}
			else
			{
				if(a[turn]>0) s=a[turn],a[turn]=0;
				++turn;
				if(turn==n) turn=0;
			}
		}
		cout<<turn<<endl;
	}
	return 0;
}



Measured memory_bytes: 3084
# https://atcoder.jp/contests/abc095/tasks/arc096

# 値段,枚数
A, B, C, X, Y = map(int, input().split())

# C * 2 は　A + Bとなる
ans = max(X, Y) * 2 * C

ans = min(ans, A * X + B * Y)
if X > Y:
    ans = min(ans, (X - Y) * A + 2 * C * Y)

elif Y > X:
    ans = min(ans, (Y - X) * B + 2 * C * X)

print(ans)

Measured memory_bytes: 3064
x, n = map(int, input().split())
p = list(map(int, input().split()))

over = x
under = x

while True:
  if over in p and under in p:
    over +=1
    under -=1
    continue
  elif under in p:
    ans = over
    break
  else:
    ans = under
    break
    
print(ans)

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

void Main() {
  string S;
  cin >> S;
  string year;
  year = S[0];
  year += S[1];
  year += S[2];
  year += S[3];
  
  string month;
  month = S[5];
  month += S[6];
  
  string date;
  date = S[8];
  date += S[9];
  
  if (year < "2019") {
    cout << "Heisei" << endl;
  } else {
    if (month <= "04") {
      cout << "Heisei" << endl;
    } else {
      cout << "TBD" << endl;
    }
  }
}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<cmath>
#include<algorithm>

using namespace std;

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

pii operator-(const pii &l, const pii &r){
	return pii(l.first - r.first, l.second - r.second);
}

int operator/(const pii &l, const pii &r){
	return l.first * r.second - l.second * r.first;
}

int sign(pii x){ return pii(0, 0) < x ? 1 : -1; }
double atan2(pii x){ return atan2(x.second, x.first); }

const int MX = 2005;
const int MM = 1000000007;

pii D[MX];
int N, M;

int abs(int x){ return x < 0? -x : x; }

int main()
{
	scanf("%d%d", &N, &M);
	if( abs(N-M) > 1 ) return !printf("0\n");
	ll m = 1;
	for(int i = 1; i <= N; i++) m = m*i % MM;
	for(int i = 1; i <= M; i++) m = m*i % MM;
	if( N == M ) m = m*2 % MM;
	printf("%lld\n", m);
}


Measured memory_bytes: 128
while True:
    M, F, R = map(int, input().split())
    if M == -1 and F == -1 and R == -1:
        break
    if M == -1 or F == -1:
        print("F")
    elif M + F >= 80:
        print("A")
    elif M + F >= 65:
        print("B")
    elif M + F >= 50:
        print("C")
    elif M + F >= 30:
        if R >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
#include<stdio.h>
int main(){
  int a=0,b=0,c=0,i=0,j=0,k=0;
 
 scanf("%d %d %d",&a,&b,&c);

i=c;


while(i > 0){
j=c%i;
if(j == 0){
if(a <= i && i <= b){
k=k++;}}
i--;
}

printf("%d\n",k);
  return 0;
}

Measured memory_bytes: 596
N, X, M = map(int, input().split())
ans = X
loop = 1
def f(a):
    return (a * a) % M


appear = [0] * (M + 1)
tmp = f(X)
appear[X] = loop
while appear[tmp] == 0:
    loop += 1
    appear[tmp] = loop
    tmp = f(tmp)

loopstart = tmp
tmp = X
before_loop_sum = 0
before_loop_len = 0
while tmp != loopstart:
    before_loop_sum += tmp
    before_loop_len += 1
    tmp = f(tmp)

loop_sum = loopstart
loop_len = 1
tmp = f(loopstart)
while tmp != loopstart:
    loop_sum += tmp
    loop_len += 1
    tmp = f(tmp)

if N < before_loop_len:
    tmp = X
    ans = 0
    for i in range(N):
        ans += tmp
        tmp = f(tmp)
else:
    N -= before_loop_len
    ans += before_loop_sum
    n_loop = N // loop_len
    N -= loop_len * n_loop
    ans += n_loop * loop_sum
    tmp = loopstart
    for i in range(N):
        ans += tmp
        tmp = f(tmp)
print(ans- X)


Measured memory_bytes: 67392
#!/usr/bin/env python3

def main():
    S = input()

    flag1 = False
    if S[0] == 'A':
        flag1 = True
    
    flag2 = False
    cnt = 0
    for i in S[2:-1]:
        if i == 'C':
            cnt += 1
    if cnt == 1:
        flag2 = True
    
    flag3 = False
    cnt = 0
    for i in S:
        if i.isupper():
            cnt += 1
    if cnt == 2:
        flag3 = True
        

    if flag1 == flag2 == flag3 == True:
        print('AC')
    else:
        print('WA')


main()

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,t,a,b=0;
  cin >> n >> t;
  long long ans=0;
  for(int i=0; i<n; i++) {
    cin >> a;
    ans+=min(t,a-b);
    b=a;
  }
  cout << ans+t << endl;
}

Measured memory_bytes: 256
S = input().strip()
flag = 0
if S=="keyence":
    flag = 1
else:
    for i in range(len(S)-1):
        for j in range(i+1,len(S)):
            x = S[:i]+S[j:]
            if x=="keyence":
                flag = 1
                break
        if flag==1:break
if flag==1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38512
from collections import Counter

n = int(input())
ss = [input() for _ in range(n)]

c = Counter(ss)
ans = []
top = c.most_common()[0][1]
for k, v in c.most_common():
    if v < top:
        break
    ans.append(k)
ans.sort()
print(*ans, sep="\n")


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

int main() {
    int N;
    cin >> N;
    int A[N], ans = 0;
    rep(i, N) {
        cin >> A[i];
    }
    rep(i, N) {
        int idx = i;
        REP(j, i+1, N) {
            // up
            if (A[j-1] > A[j]) break;
            idx = max(idx, j);
        }
        REP(j, i+1, N) {
            // down
            if (A[j-1] < A[j]) break;
            idx = max(idx, j);
        }
        
        i = idx;
        ans++;
    }
    cout << ans << endl;
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> red(A);
  vector<int> green(B);
  vector<int> colorless(C);
  for (auto &p : red) {
    cin >> p;
  }
  for (auto &q : green) {
    cin >> q;
  }
  for (auto &r : colorless) {
    cin >> r;
  }
  sort(all(red));
  sort(all(green));
  sort(all(colorless));
  reverse(all(colorless));
  vector<int> chosen(red.begin() + (A - X), red.end());
  chosen.insert(chosen.end(), green.begin() + (B - Y), green.end());
  sort(all(chosen));
  LL sum = 0;
  for (auto &c : chosen) {
    sum += c;
  }
  for (int i = 0, j = 0; i < sz(colorless) && j < sz(chosen); i++) {
    if (colorless[i] > chosen[j]) {
      sum += (colorless[i] - chosen[j]);
      j++;
    }
  }
  cout << sum << "\n";
  return 0;
}

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

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

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

int main()
{
  ll N, X;
  cin >> N;
  vector<ll> x(N + 1);
  for (ll i = 0; i < N + 1; i++)
  {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  vector<ll> y(N);
  ll ans = 1e9 + 7;

  if (x.size() < 3)
  {
    cout << x[1] - x[0] << endl;
    return 0;
  }

  for (ll i = 0; i < N - 1; i++)
  {
    ans = min(ans, gcd(abs(x[i] - x[i + 1]), abs(x[i + 1] - x[i + 2])));
  }
  cout << ans << endl;
}


Measured memory_bytes: 4720
S = input()
N = len(S)
ans = 0
for i in range(len(S)):
  for j in range(i, len(S)):
    A = S[i:j]
    if all('ACGT'.count(c) == 1 for c in S[i:j+1]):
      ans = max(j-i+1, ans)
        
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static String S, T;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        S = sc.next();
        T = sc.next();

        System.out.println(solve() ? "Yes" : "No");
    }

    static boolean solve() {
        int[] a = new int[26];
        int[] b = new int[26];

        for (int i = 0; i < S.length(); i++) {
            a[S.charAt(i)-'a']++;
        }

        for (int i = 0; i < T.length(); i++) {
            b[T.charAt(i)-'a']++;
        }

        Arrays.sort(a);
        Arrays.sort(b);

        return Arrays.equals(a, b);
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 26364
N = gets.to_i
$adjacency_list = []
N.times{
  u, k, *v = gets.split.map &:to_i
  $adjacency_list[u] = v
}
$d = []
$f = []
$time = 1
def record_time v
  unless $d[v]
    $d[v] = $time
    $time += 1
  end
  $adjacency_list[v].each{|arr_v|
    record_time arr_v unless $d[arr_v]
  }
  unless $f[v]
    $f[v] = $time
    $time += 1
  end
end
(1..N).each{|i|
  record_time(i) unless $d[i]
}
(1..N).each{|i|
  puts "#{i} #{$d[i]} #{$f[i]}"
}

Measured memory_bytes: 8796
#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 chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int ans=0;
  rep(i,k){
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
import copy


n,m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
dict2 = {1:1, 2:10**4, 3:10**8, 4:10**12, 5:10**16, 6:10**20, 7:10**24, 8:10**28, 9:10**32}
bonus = 10**36
l = []
for i in a:
    l.append((i,dict[i],dict2[i]))

dp = [[['n',0,[]] for j in range(n+1)] for i in range(m+1)]
for i in range(m+1):
    dp[i][0][0] = "t"
for i in range(1,m+1):
    num = l[i-1][0]
    c = l[i-1][1]
    v = l[i-1][2]
    for j in range(1, n+1):
        if (j-c < 0 or dp[i][j-c][0] == 'n') and dp[i-1][j][0] == 'n':
            continue
        elif (j-c < 0 or dp[i][j-c][0] == 'n'):
            dp[i][j] = copy.copy(dp[i-1][j])
        elif dp[i-1][j][0] == 'n':
            dp[i][j][0] = 't'
            dp[i][j][1] = dp[i][j-c][1] + v + bonus
            dp[i][j][2] = copy.copy(dp[i][j-c][2])
            dp[i][j][2].append(num)
        else:
            dp[i][j][0] = 't'
            if dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus:
                dp[i][j] = copy.copy(dp[i-1][j])
            else:
                dp[i][j][1] = dp[i][j-c][1]+v+bonus
                dp[i][j][2] = copy.copy(dp[i][j-c][2])
                dp[i][j][2].append(num)
L = dp[m][n][2]
L = sorted(L, reverse=True)
ans = ''
for i in range(len(L)):
    ans += str(L[i])
print(int(ans))

Measured memory_bytes: 598792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

struct piece {
    int w, d;
    bool operator <(const piece& p) const {
        return w*d < p.w*p.d;
    }
};

int main()
{
    int n, w, d;
    while (cin >> n >> w >> d, n|w|d) {
        vector<pii> cut;
        rep(i, n){
            int p, s;
            cin >> p >> s;
            cut.pb({p, s});
        }
        vector<piece> v;
        v.pb({-1,-1});
        v.pb({w, d});
        rep(i, n){
            piece pie = v[cut[i].first]; v.erase(v.begin()+cut[i].first);
            int pos = cut[i].second%(pie.w+pie.d);
            if(pos<pie.w){ // top & bottom
                if(pos < pie.w-pos){
                    v.pb({pos, pie.d});
                    v.pb({pie.w-pos, pie.d});
                } else {
                    v.pb({pie.w-pos, pie.d});
                    v.pb({pos, pie.d});
                }
            } else { // right & left
                pos -= pie.w;
                if(pos < pie.d-pos){
                    v.pb({pie.w, pos});
                    v.pb({pie.w, pie.d-pos});
                } else {
                    v.pb({pie.w, pie.d-pos});
                    v.pb({pie.w, pos});
                }
            }
        }
        sort(ALL(v));
        REP(i, 1, v.size()){
            cout << v[i].w * v[i].d;
            if (i != v.size()-1)
                cout << " ";
            else
                cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1220
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int s,w;cin>>s>>w;
if(w>=s) cout<<"unsafe";
else cout<<"safe";


return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 100005
#define LL long long
int main()
{
	LL a,b,c;
	scanf("%lld %lld %lld",&a,&b,&c);
	if(a%2==0||b%2==0||c%2==0)
	{
		printf("0\n");
		return 0;
	}
	printf("%lld\n",min(a*b,min(a*c,b*c)));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq  priority_queue<double, std::vector<double>, std::greater<double>>

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

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


int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    while (K != 0)
    {
        K--;
        if(A > 0){
            ans++;
            A--;
        }
        else if(B > 0){
            B--;
        }
        else{
            ans--;
            C--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int x = stdIn.nextInt();
        int left = 0;
        int right = 0;

        for(int i = 0; i < m; i++){
            int a = stdIn.nextInt();
            if(a < x)
                left++;
            else
                right++;
        }
        
        if(right > left)
                System.out.println(left);
        else
            System.out.println(right);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n;
  cin>>n;
  string ans = "Three";
  rep(i,n){
  string s;
  cin>>s;
  if (s == "Y"){
    ans = "Four";
    break;
  }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    # import numpy as np
    # import math
    # import random
    input = stdin.readline

    n = int(input()[-2])
    if n in {2, 4, 5, 7, 9}:
        print('hon')
    elif n in {3}:
        print('bon')
    else:
        print('pon')


Measured memory_bytes: 9188