akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int main()
{
  int *A;
  int i, n, q, a, len=0;
  fscanf(stdin, "%d", &n);
  A = (int*)malloc(sizeof(int)*n);
  bzero(A, sizeof(int)*n);
  for (i=0; i<n; i++) {
    fscanf(stdin, "%d", &q);
    switch (q) {
    case 0:
      fscanf(stdin, "%d", &a);
      A[len++]=a;
      break;
    case 1:
      fscanf(stdin, "%d", &a);
      printf("%d\n", A[a]);
      break;
    case 2:
      len--;
    }
  }
  return 0;
}



Measured memory_bytes: 2584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << ((c + b - 1) / b <= (a + d - 1) / d ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;

int main() {
  string S, T="";
  cin >> S;
  for (char c:S) {
    if (c=='B') {
      if (T.size()==0) {continue;}
      else {T.erase(T.size()-1);}
    }
    else {T.push_back(c);}
  }
  cout << T << endl;
}

Measured memory_bytes: 3576
n = int(input())
hl = list(map(int, input().split()))

ans = 0
cnt = 0
prev_h = 0
for h in hl:
    if h > prev_h:
        ans = max(ans,cnt)
        cnt = 0
    else:
        cnt += 1
    prev_h = h

ans = max(ans,cnt)
print(ans)

Measured memory_bytes: 85548
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll n,i,j,t,m=0,T,ans=0,r,k,p=0,q,x,y,l;
         cin>>n>>x>>t;
         if(n%x==0)
            cout<<n/x*t<<endl;
         else cout<<(n/x+1)*t<<endl;
}













Measured memory_bytes: 3620
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		List<Integer>[] x = new ArrayList[4];
		for(int i = 0; i < 4; i++)
			x[i] = new ArrayList<>();
		int w1 = sc.nextInt();
		x[0].add(sc.nextInt());
		for(int i = 1; i < N; i++)
			x[sc.nextInt()-w1].add(sc.nextInt());
		for(int i = 0; i < 4; i++)
			Collections.sort(x[i], Collections.reverseOrder());
		int[][] S = new int[4][N+1];
		for(int i = 0; i < 4; i++) {
			for(int j = 1; j <= x[i].size(); j++) {
				S[i][j] = S[i][j-1];
				S[i][j] += x[i].get(j-1);
			}
		}		
		int ans = 0;
		for(int i = 0; i <= x[0].size(); i++)
			for(int j = 0; j <= x[1].size(); j++)
				for(int k = 0; k <= x[2].size(); k++)
					for(int l = 0; l <= x[3].size(); l++)
						if((long)(i+j+k+l)*w1+j+k*2+l*3 <= W)
							ans = Math.max(ans, S[0][i]+S[1][j]+S[2][k]+S[3][l]);
		System.out.println(ans);
	}

}


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

int main(void) {
	int h, w, i;
	scanf("%d%d", &h, &w);
	if (!h && !w) {
		return 0;
	}
	char frame[w + 1], rect[w + 1];
	memset(frame, '#', w);
	memset(rect, '.', w);
	rect[0] = rect[w - 1] = '#';
	frame[w] = rect[w] = 0;
	puts(frame);
	for (i = 1; i < h - 1; i++) {
		puts(rect);
	}
	puts(frame);
	puts("");
	return main();
}

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

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

    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '.') cnt2++;
    }

    int ans = cnt2;
    for (int i = 0; i < N; i++) {
        if (S[i] == '#') cnt1++;
        else cnt2--;
        ans = min(ans, cnt1 + cnt2);
    }
    cout << ans << endl;
}

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

bool cmp(int a,int b){
        return a>b;
}


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

    //Insert code
  	
    ll n,a,b,aa=0,bb=0,cc=0;
    cin>>n>>a>>b;
    for (int i=0;i<n;i++){
    	int tmp;
      	cin>>tmp;
      	if (tmp<=a) aa++;
      	else if (tmp>=(b+1)) cc++;
      	else bb++;
    }
  	cout<<min(aa,min(bb,cc));
  
    //End code


    cerr << "\nTime elapsed: " << 1000*clock() / CLOCKS_PER_SEC << "ms\n";
    
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    A[i] = A[i] - (i + 1)

#print(A)

A = sorted(A)

if N%2 == 1:
    b = A[(N-1)//2]
else:
    b = A[N//2] + A[N//2-1]
    b = b // 2

ans = 0
for i in A:
    ans += abs(i - b)

print(ans)

Measured memory_bytes: 26020
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
goukei = 0

for i in range (n):
    if b[i]>=a[i]:
        b[i] = b[i]-a[i]
        if b[i]>=a[i+1]:
            goukei += a[i]+a[i+1]
            a[i+1]=0
        else:
            goukei += a[i]+b[i]
            a[i+1]=a[i+1]-b[i]

    else:
        goukei += b[i]
print(goukei)


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int ans = 0;
  
  for (int i=0; i<N-2; i++) {
    if (S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    int out = (a[2]-a[1])/2+(a[2]-a[0])/2;
    a[0] += ((a[2]-a[0])/2)*2;
    a[1] += ((a[2]-a[1])/2)*2;
    cerr << a[0] << "\t" << a[1] << "\t" << a[2] << endl;
    if(a[0]==a[1] && a[1]==a[2]){
        //do nothing
    }else if(a[0]%2==a[1]%2){
        out++;
    }else{
        out += 2;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
 
int main() {
  
  int N,X,Y;
  cin >> N >> X >> Y;

  vector<vector<int>> G(N+1,vector<int>(0)),D(N+1,vector<int>(N+1,MOD));
  for(int i = 1;i < N;i++) {
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }

  G[X].push_back(Y);
  G[Y].push_back(X);

  vector<int> dis(N);
  for(int i = 1;i < N;i++) {
    D[i][i] = 0;
    vector<bool> seen(N+1,false);
    queue<int> Q;
    Q.push(i);
    while(!Q.empty()) {
      int q = Q.front();
      Q.pop();
      seen[q] = true;
      for(int nv:G[q]) {
        D[i][nv] = min(D[i][nv],D[i][q]+1);
        if(!seen[nv]) Q.push(nv);
      }
    }

    for(int j = 1;j <= N;j++) {
      if(j > i) dis[D[i][j]]++;
    }
  }

  for(int i = 1;i <= N-1;i++) cout << dis[i] << endl;
  
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
const int mod = 1000000007;
ll y(ll x,ll i){return ((ll)(x/pow(2,i-1))-(ll)(x/pow(2,i)));}
ll n,m,ans=0,s=0;
priority_queue<ll> a;
int main(){
  cin >> n >> m;
  for (size_t i = 0; i < n; i++) {
    ll temp;
    cin >> temp;
    s += temp;
    a.push(temp);
  }
  for (size_t i = 0; i < m; i++) {
    ll temp=a.top();
    ans += temp - (temp/2);
    a.pop();
    a.push(temp/2);
  }
  cout << s-ans << endl;
}


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

int H, W;
char G[502][502];

int main() {
    scanf("%d %d", &H, &W);

    for(int i = 0; i < H; i++) {
        scanf("\n");
        for(int j = 0; j < W; j++) {
            scanf("%c", &G[i][j]);
        }
    }

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(0 < i && i < H - 1 && 0 < j && j < W - 1 && (j == 1 || i % 2 || G[i][j] == '#')) printf("#");
            else printf(".");
        }
        printf("\n");
    }
    printf("\n");
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(0 < i && i < H - 1 && 0 < j && j < W - 1 && G[i][j] != '#' && (j == 1 || i % 2)) printf(".");
            else printf("#");
        }
        printf("\n");
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>



using namespace std;





int main() {
	int n;
	cin >> n;
	int s = 0, i;
	int x;
	for (i = 1; i <= n; i++) {
		scanf("%d", &x);
		while ( !(x & 1) ) {
			x >>= 1;
			s++;
		}
	}
	cout << s << endl;
	 
} 








Measured memory_bytes: 256
import math
pi=3.14159265358979

x = 0
y = 0
theta = math.radians(90)

while True:
    a, b = map(float, raw_input().split(','))
    if a==0 and b==0: break
    x += a * math.cos(theta)
    y += a * math.sin(theta)
    theta += math.radians(-b)

print int(x)
print int(y)

Measured memory_bytes: 4436
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A), b(B);
	int min_a = 1e5 + 5, min_b = 1e5 + 5, ans;
	for (int i = 0; i < A; i++) {
		cin >> a.at(i);
		if (a.at(i) < min_a) min_a = a.at(i);
	}
	for (int i = 0; i < B; i++) {
		cin >> b.at(i);
		if (b.at(i) < min_b) min_b = b.at(i);
	}
 	ans = min_a + min_b;
	for (int i = 0; i < M; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		int tmp = a.at(x - 1) + b.at(y - 1) - z;
		if (tmp < ans) ans = tmp;
	}
  
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;


int ans[60];
int found;

int main(){
	
	for(int i=6;found<=60;i+=5){
		bool b=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)b=false;
		}
		if(b){
			ans[found]=i;
			found++;
		}
	}
	
	int n;cin>>n;
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
	
	return 0;
}


Measured memory_bytes: 256
s=gets.chop.chars.reverse
dp=[[0]*26]
s.map{|c|
	*x=dp[-1]
	x[c.ord-97]=x.min+1
	dp<<x
}
($><<i=(97+dp[-1].index(dp[-1].min)).chr;(s.pop;dp.pop)while s[0]&&s[-1]!=i;s.pop;dp.pop)while s[0]

Measured memory_bytes: 74424
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	odd := 0.0
	for i := 1; i <= n; i++ {
		if i%2 == 1 {
			odd++
		}
	}
	fmt.Println(odd / float64(n))
}

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

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);

int aoki[100010],taka[100010];
vi ab[100010];

int main() {
	int n,u,v;
	cin >> n >> u >> v;
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		ab[a].push_back(b);
		ab[b].push_back(a);
	}

	rep(i,100010) aoki[i] = INF;
	aoki[v] = 0;
	queue<int> que;
	que.push(v);
	while(que.size()){
		int x = que.front(); que.pop();
		for(auto& y : ab[x]){
			if(aoki[x]+1 < aoki[y]){
				aoki[y] = aoki[x]+1;
				que.push(y);
			}
		}
	}

	rep(i,100010) taka[i] = INF;
	taka[u] = 0;
	int ans = aoki[u]-1;
	que.push(u);
	while(que.size()){
		int x = que.front(); que.pop();
		for(auto& y : ab[x]){
			if(taka[x]+1 < taka[y]){
				taka[y] = taka[x]+1;
				if(taka[y] < aoki[y]) que.push(y);
				ans = max(ans,aoki[y]-1);
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6656
//13
#include<iostream>
#include<string>
#include<set>

using namespace std;

int main(){
  int m;
  cin>>m;
  while(m--){
    string s;
    cin>>s;
    set<string> sset;
    for(int i=1;i<s.size();i++){
      for(int j=0;j<2;j++){
	string t(s.begin(),s.begin()+i);
	string b(s.begin()+i,s.end());
	if(j){
	  swap(t,b);
	}
	for(int k=0;k<4;k++){
	  string tt=t,bb=b;
	  if(k&1){
	    tt=string(t.rbegin(),t.rend());
	  }
	  if(k&2){
	    bb=string(b.rbegin(),b.rend());
	  }
	  sset.insert(tt+bb);
	}
      }
    }
    cout<<sset.size()<<endl;
  }
  return 0;
}

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

public class Main {
	
	public void sort(int[][] data){
		for(int i = 0; i < data.length-1; i++){
			int m = i;
			for(int j = i+1; j < data.length-1; j++){
				if( data[j][1] < data[m][1] ){
					m = j;
				}
			}
			for(int j = 0; j < 3; j++){
				int temp = data[m][j];
				data[m][j] = data[i][j];
				data[i][j] = temp;
			}
		}
	}
	public int[] nextPermutation(int[] x, int index){
		int max = index;
		boolean[] temp = new boolean[x.length];
		for(int i = index; i < x.length; i++){
			temp[x[i]-1] = true;
			if( x[i] > x[max] ){
				max = i;
			}
		}
		int key = index+1;
		if( max == index ){
			for(; index > 0; index--){
				temp[x[index-1]-1] = true;
				if( x[index] > x[index-1] ){
					break;
				}
			}
			key = index;
		} 

		for(int i = x[key-1]; i < temp.length; i++){
			if( temp[i] ){
				x[key-1] = i+1;
				temp[i] = false;
				break;
			}
		}		
		int count = 0;
		for(int i = 0; i < temp.length; i++){
			if( temp[i] ){
				x[key+count] = i+1;
				count++;
			}
		}			
		return x;
	}
			
	public  void solve() throws IOException{
		int n = nextInt();
		int[][] data = new int[n][3];		
		for(int i = 0; i < n; i++){
			data[i][0] = nextInt();
			data[i][1] = nextInt();
			data[i][2] = nextInt();			
		}
		sort(data);	
		int[] x = new int[n];
		for(int i = 0; i < x.length; i++){
			x[i] = i+1;
		}
		double min = 1000000001;
		int[] ans = new int[n];
		System.arraycopy(x, 0, ans, 0, n);
		int repeat = 400000;
		while( x[0] != n && repeat-- > 0 ){
			int[] total = new int[n];
			int high = data[x[n-1]-1][1];
			int low = high;
			for(int i = n-2; i >= 0; i--){
				int a = data[x[i]-1][1];		
				high = Math.max(high, a);
				low = Math.min(low, a);
				total[i] = high-low+Math.min(high-a, a-low);
			
			}		
			double sum = 0;
			double w = 0;
			double v = (double)2000/70;	
			int i = 0;		
			for(; i < x.length-1; i++){
				if( sum + total[i]/v > min ){
					sum = min;
					break;
				}
				int len = Math.abs(data[x[i]-1][1]-data[x[i+1]-1][1]);
				w += 20*data[x[i]-1][2];
				v = 2000/(70+w);
				sum += len/v;								
			}
			if( sum < min ){
				System.arraycopy(x, 0, ans, 0, n);
				min = sum;
			}
			i = Math.min(i, n-1);
			x = nextPermutation(x, i);			
		}
		writer.print(data[ans[0]-1][0]);
		for(int i = 1; i < n; i++){
			writer.print(" " + data[ans[i]-1][0]);
		}
		writer.println();	
		writer.flush();			
	}
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}		
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 10000
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#define ll long long
using namespace std;
int ac,wa,tle,re,n;
string s;

int main(void)
{
	cin>>n;
	while(n--)
	{
		cin>>s;
		if(s[0]=='A') ac++;
		else if(s[0]=='W') wa++;
		else if(s[0]=='T') tle++;
		else if(s[0]=='R') re++;
	}
	cout<<"AC x "<<ac<<'\n'<<"WA x "<<wa<<'\n'<<"TLE x "<<tle<<'\n'<<"RE x "<<re<<'\n';
	return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> A(N);
  for (auto &it : A)
    cin >> it;

  // 累積 GCD (左と右両方)
  vector<ll> left(N + 1, 0), right(N + 1, 0);
  for (int i = 0; i < N; ++i)
    left[i + 1] = gcd(left[i], A[i]);
  for (int i = N - 1; i >= 0; --i)
    right[i] = gcd(right[i + 1], A[i]);

  ll ans = 0;
  for (int i = 0; i < N; i++)
  {
    ll l = left[i];
    ll r = right[i + 1];
    ans = max(ans, gcd(l, r));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;
const int INF = 1e9;

int colors[210];

bool bip(vector<vector<int>> &g, int v, int color) {
    colors[v] = color;
    for (auto e: g[v]) {
        if (colors[e] == colors[v]) return false;
        if (colors[e] == 0 && !bip(g, e, -color)) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    vector<vector<int>> dist(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            char c;
            cin >> c;
            if (c == '0') {
                dist[i][j] = i == j ? 0 : INF;
            } else {
                g[i].push_back(j);
                dist[i][j] = 1;
            }
        }
    }

    if (!bip(g, 0, 1)) {
        cout << -1 << endl;
        return 0;
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ans = max(ans, dist[i][j]+1);
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
dishes=[]
mindiv=10

for i in range(5):
  dishes.append(int(input()))

for j in range(len(dishes)):
  k= dishes[j]
  if(k%10 ==0 ):
    continue
  if(k%10 <mindiv):
    mindiv= k%10
  if(k%10 <=5 ):
    k += 5
  dishes[j]= round(k,-1)
  
# print(dishes)
# print(mindiv)
print(sum(dishes)-(10-mindiv))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        for (int i = 0; i < s.length(); i++) {
            String str1 = s.substring(0, 1);
            String str2 = s.substring(1);
            s = str2 + str1;
            if (s.equals(t)) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }

}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int c=1;
	for(int i=0;i<n-1;i++)
		if(s[i]!=s[i+1]) c++;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 512
inp = input()
inlist = inp.split()

tD = int(inlist[0])
tA = int(inlist[1])
aD = int(inlist[2])
aA = int(inlist[3])

tlife = tD
alife = aD

while(True):
  alife -= tA
  if( alife <= 0):
    print("Yes")
    break
  
  tlife -= aA
  if( tlife <= 0):
    print("No")
    break

Measured memory_bytes: 9196
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long s = a*b;
    if(a>1l) s -= b*2;
    if(b>1l) s -= a*2;
    if(a>1l && b>1l) s+=4;
    System.out.println(s);
  }
}


Measured memory_bytes: 22100
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<i64>();
    let mut seq = vec![0; n];
    let mut sum = 0;
    for i in 0..n {
        seq[i] = read::<i64>();
        sum += seq[i];
    }
    let mut candidates = vec![];
    for i in 1..sum {
        if i * i > sum {
            break;
        }
        if sum % i == 0 {
            candidates.push(i);
            candidates.push(sum / i);
        }
    }
    candidates.sort();
    candidates.reverse();
    for &m in candidates.iter() {
        let mut values = seq.iter().cloned().map(|x| x % m).collect::<Vec<_>>();
        values.sort();
        let mut l = 0;
        let mut r = n - 1;
        let mut lcnt = values[l];
        let mut rcnt = (m - values[r]) % m;
        while r - l > 1 {
            if lcnt <= rcnt {
                l += 1;
                lcnt += values[l];
            } else {
                r -= 1;
                rcnt += (m - values[r]) % m;
            }
        }
        // println!("{} {} {} {}", l, r, lcnt, rcnt);
        assert!(lcnt == rcnt);
        if lcnt <= k {
            println!("{}", m);
            return;
        }
    }
}


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

int main() {
    int n;
    cin >>n;
    for (int i=1; i<=n; i++) {
        if (0==i%3)
            cout <<' ' <<i;
        else {
               int x=i;
               while (0!=x) {
                   if(3==x%10) {
                       cout <<' ' <<i;
                       break;
                   }
                   x /=10;
               }
        }
    }
    cout <<endl;
    return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		// 回数
		int n = in.nextInt();
		// answer
		long ans = 1;
		long max = 123456789123L;
		if ( n <= 100000) {
			for (int i = 1; i <= n; i++) {
				ans = ans * i;
				if (max < ans) {
					ans = ans % (1000000000+7);
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
n, m = map(int, input().split())

hyokou = list(map(int, input().split()))

s = []
ss = []

res = 0

a = [[0 for i in range(1)] for i in range(n)]

for _ in range(m):
    nnn = list(map(int, input().split()))
    a[nnn[0] - 1].append(hyokou[nnn[1] - 1])
    a[nnn[1] - 1].append(hyokou[nnn[0] - 1])

for i in range(n):
    b = max(a[i])
    if hyokou[i] > b:
        res += 1
print(res)

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

const int MAX_N = 100000;
int n;
int h[MAX_N];

int main()
{
  cin >> n;
  forn(i,n) cin >> h[i];

  bool ok = true;
  for (int i = n-2; i >= 0; i--) {
    if (h[i] > h[i+1]) h[i]--;
    ok &= h[i] <= h[i+1];
  }

  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


Measured memory_bytes: 640
N = int(input())

ans = N

for A in range(N+1):
    counter = 0
    temp = A
    while temp > 0:
        q, r = divmod(temp, 6)
        counter += r
        temp = q

    temp = N - A
    while temp > 0:
        q, r = divmod(temp, 9)
        counter += r
        temp = q

    if ans > counter:
        ans = counter

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <sstream>

using namespace std;


int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    vector<int> vs(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> vs[i];
    }
    int result = 0;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        result += (vs[i] > tmp) ? (vs[i] - tmp) : 0;
    }
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i,N) for (int i = 0; i < N; i++)
#define llong long long

int N;
vector<int> a, b;

int main() {
    cin >> N;
    a.resize(N); b.resize(N-1);
    rep(i,N-1) cin >> b[i];
    a[0] = b[0]; a[N-1] = b[N-2];
    for (int i = 1; i < N-1; i++) {
        a[i] = min(b[i], b[i-1]);
    } 
    cout << accumulate(a.begin(), a.end(), 0) << endl;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size() + 1;
  VI a(n, 0);
  int cnt = 0;
  rep(i, s.size()) {
    if(s[i] == '<')
      cnt++;
    else
      cnt = 0;
    chmax(a[i + 1], cnt);
  }

  for(int i = s.size(); i >= 1; i--) {
    if(s[i - 1] == '>')
      cnt++;
    else
      cnt = 0;
    chmax(a[i - 1], cnt);
  }
  ll ans = 0;
  rep(i, n) ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2844
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(decltype(N+k) i=k; i<N;i++)
#define rep(i,N) for(decltype(N) i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return 約数unordered_set 1 <= x <= n
auto divv = [](auto n) {
  unordered_set<decltype(n)> v;
  for(decltype(n) i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
  return v;
};

// check prime (and n>=2) or not
auto isPrime = [](auto n){
  if(n <= 1) return false;
  for(decltype(n) i = 2; i <= sqrt(n); ++i) {
      if(n % i == 0) {
          return false;
      }
  }
  return true;
};



int main() {
    ll t1,t2,a1,a2,b1,b2;
    cin>>t1>>t2;
    cin>>a1>>a2;
    cin>>b1>>b2;
    if(t1*a1+t2*a2 == t1*b1 + t2*b2){
        pr("infinity");
        return 0;
    }else if(t1*a1+t2*a2 < t1*b1 + t2*b2){
        swap(a1,b1);
        swap(a2,b2);
    }
    if(a1>b1) {
        pr(0);
        return 0;
    }
    auto y = b1 - a1;
    y*=t1;
    auto diff = t1*a1+t2*a2 - t1*b1 - t2*b2;
    if(y%diff != 0) pr(y/diff*2+1);
    else pr(y/diff*2);


}


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

int main(){
  int n,h;
  cin>>n>>h;
  vector<int> a(n),b(n);
  rep(i,n){
    int A, B;
    cin>>A>>B;
    a[i]=A; b[i]=B;
  }
  sort(a.begin(),a.end(),greater<int>());
  sort(b.begin(),b.end(),greater<int>());
  int ans=0;
  rep(i,n){
    if(a[0] < b[i]){
      h-=b[i];
      ans++;
    }
    if(h<=0) break;
  }
  if(h>0){
    ans+=h/a[0];
    if(h%a[0]!=0) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4060
/************************************/
//
//?§????????????????S???????????????????????§???h:m:s?????¢??????????????????????????????????????°??????
//
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_D&lang=jp
/************************************/

#include<stdio.h>

#define MIN 0
#define MAX 86400

int main()
{
	int S,h,m,ss;
	
	scanf("%d", &S);
	
	/* ????????¶?´? */
	if((S>=MIN) && (S<MAX))
	{
		h=S/3600;
		S-=h*3600;
		m=S/60;
		ss=S-m*60;
		
		printf("%d:%d:%d\n", h, m, ss);
	}
	else
	{
		/* ERROR */
		return -1;
	}
	
	return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7

const ll MAX = 400;

vector<int> bfs(vector<char> map, int H, int W, int start){
    vector<int> ans(H*W + 1, -1);
    if(map.at(start) == '#'){
        return ans;
    }
    ans.at(start) = 0;
    
    queue<int> que;
    que.push(start);    
    int tmp;
    while(que.size() != 0){
        tmp = que.front();
        que.pop();
        if(tmp >= W+1){
            if(map.at(tmp - W) == '.'){
                if(ans.at(tmp - W) == -1){
                    ans.at(tmp - W) = ans.at(tmp) + 1;
                    que.push(tmp - W);
                }
            }
        }
        if(tmp <= W*(H-1)){
            if(map.at(tmp + W) == '.'){
                if(ans.at(tmp + W) == -1){
                    ans.at(tmp + W) = ans.at(tmp) + 1;
                    que.push(tmp + W);
                }
            }
        }
        if(tmp % W != 1){
            if(map.at(tmp - 1) == '.'){
                if(ans.at(tmp - 1) == -1){
                    ans.at(tmp - 1) = ans.at(tmp) + 1;
                    que.push(tmp - 1);
                }
            }
        }
        if(tmp % W != 0){
            if(map.at(tmp + 1) == '.'){
                if(ans.at(tmp + 1) == -1){
                    ans.at(tmp + 1) = ans.at(tmp) + 1;
                    que.push(tmp + 1);
                }
            }
        }
    }
    return ans;
}

int max_vect(vector<int> vec){
    int ans = -1;
    for(int i = 0; i < vec.size(); i++){
        ans = max(ans,vec.at(i));
    }
    return ans;
}


int main() {
    int H,W;
    cin >> H >> W;
    vector<char> map(H*W+1);
    for(int i = 1; i < H*W+1; i++){
        cin >> map.at(i);
    }
    
    int ans = -1;
    for(int i = 1; i < H*W+1; i++){
        ans = max(ans, max_vect(bfs(map, H, W, i)));
    }
    
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    V<int> a(n,0);
    for(int i=0;i<n-1;i++){
        int d;cin>>d;
        a[d-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<"\n";
    }
}

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

using namespace std;


/// Bismilahir Rahmanir Rahim


typedef unsigned int ui;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef short int si;
typedef unsigned short int usi;
typedef double dd;
typedef pair <int, int> pii;


#define CASE false
#define TEST false
#define BUFFER true
#define TIME false
#define DEBUG true
#define SET_GEN false
#define _ << " " <<
#define __ << "\n"
#define ff first
#define ss second
#define RANGE(a, b) (rand() % (b-a+1) + a)


const double pi = acos(-1.);
const double eps = 1e-7;
const int inf = 2147483647;
const int _inf = -2147483648;
const int mod = 1e9+7;


void delay(int sec); // DEBUG


void solution(void)
{
    int n, ck;

    cin >> n >> ck;

    int *val = new int [n];
    int *weight = new int [n];

    for(int i = 0; i < n; ++i) {
        cin >> weight[i] >> val[i];
    }

    ulli **ks = new ulli* [n+1];
    for(int i = 0; i <= n; ++i) ks[i] = new ulli [ck+1];

    for(int i = 0; i <= ck; ++i) ks[0][i] = 0;


    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j <= ck; ++j) {
            if (j >= weight[i-1]) {
                ks[i][j] = max(ks[i-1][j-weight[i-1]] + val[i-1], ks[i-1][j]);
            }
            else ks[i][j] = ks[i-1][j];
        }
    }

    cout << ks[n][ck] << "\n";


    delete[] val, weight;
    for(int i = 0; i <= n; ++i) delete[] ks[i];
    delete[] ks;


    return ;
}

int main(int argc, char *arv[])
{
    #if BUFFER
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #endif

    #if SET_GEN
    srand((unsigned int) time(0));
    #endif


    unsigned short int t = 1;

    #if CASE
    int cnt = 1;
    #endif

    #if TEST
    cin >> t;
    #endif

    #if TIME
    clock_t start_time, end_time;
    double time_elapsed;
    #endif


    while(t--) {

        #if TIME
        start_time = clock();
        #endif

        #if CASE
        cout << "Case " << cnt++ << ": ";
        #endif

        solution();

        #if TIME
        end_time = clock();

        time_elapsed = (double) (end_time - start_time) / CLOCKS_PER_SEC;

        cout << "\nRuntime: " << fixed << setprecision(7) << time_elapsed << "\n";
        #endif
    }


    return 0;
}

void delay(int sec)
{
    int mili_sec = 1000 * sec;

    clock_t start_time = clock();

    while (clock() < start_time + mili_sec);

    return ;
}


Measured memory_bytes: 79488
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        string[] input = ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);

        if (A > 8 || B > 8) WriteLine(":(");
        else WriteLine("Yay!");
        ReadLine();
    }
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = 0;
	for (int i = 0; i < m; i++) {
		int x; scanf("%d", &x);
		ans += x;
	}

	ans = n - ans;
	printf("%d\n", ans < 0 ? -1 : ans);
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct topological_sort{
    vector<vector<int>> graph;
    vector<bool> done,open;
    vector<int> res;
    bool success;
    topological_sort(vector<vector<int>> &graph):graph(graph),done(graph.size()),open(graph.size()){
        success=true;
        rep(i,0,graph.size()){
            if(!dfs(i)){
                success=false;
                break;
            }
        }
        reverse(res.begin(),res.end());
    }
    bool dfs(int v){
        if(open[v]) return false;
        if(done[v]) return true;
        open[v]=true;
        done[v]=true;
        for(auto &u:graph[v]) if(!dfs(u)) return false;
        open[v]=false;
        res.push_back(v);
        return true;
    }
};

void solve(){
    int v,e;
    cin >> v >> e;
    vector<vector<int>> graph(v);
    rep(i,0,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
    }
    topological_sort ts(graph);
    rep(i,0,v) cout << ts.res[i] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 4216
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        if (a % 2 == 0) System.out.println(a * a / 4);
        else {
            int a1 = a / 2;
            int a2 = a1 + 1;
            System.out.println(a1 * a2);
        }
        inp.close();
    }
}


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

using namespace std;



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

	//freopen("input.txt", "r", stdin); // redirects standard input
	//freopen("output.txt", "w", stdout); // redirects standard output

	int n, k, i, j, d, x, ans, a, b, m;
	cin >> n >> m;
	vector<int> h(n + 1);
	for (i = 1; i <= n; i++) cin >> h[i];
	vector<vector<int>> adj(n + 1);
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	ans = 0;
	for (i = 1; i <= n; i++) {
		bool valid = true;
		for (auto p : adj[i]) {
			if (h[i] <= h[p]) valid = false;
		}
		if (valid)
			ans++;
	}

	cout << ans << "\n";




	return 0;
}

Measured memory_bytes: 8304
#include <stdio.h>

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
	int64_t N,M,K;
	std::cin >> N >> M >> K;
	std::vector<int64_t> A;
	std::vector<int64_t> B;
	int64_t s = 0;
	for (int64_t n = 0; n < N; ++n)
	{
		int64_t a;
		std::cin >> a;
		s += a;
		A.emplace_back(s);
	}
	s = 0;
	for (int64_t m = 0; m < M; ++m)
	{
		int64_t b;
		std::cin >> b;
		s += b;
		B.emplace_back(s);
	}

	

	int64_t q = std::distance(A.begin(), std::upper_bound(A.begin(), A.end(), K));
	for (int64_t m = 0; m < M; ++m)
	{
		auto t = K - B[m];
		if (t < 0) break;
		auto tt = std::upper_bound(A.begin(), A.end(), t);
		q = std::max(q, m + std::distance(A.begin(), tt) + 1);
	}

	std::cout << q << std::endl;
	return 0;
}


Measured memory_bytes: 7988
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    string s;
    std::cin >> s;
    std::cout << s.substr(0,4)<<" "<<s.substr(4,8) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  string a,b;
  cin>>a>>b;
  int x=stoi(a+b);
  string ans="No";
  rep(i,1000){
    if(i*i==x) ans="Yes";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3556
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;

void main(){
    immutable train_01 = readln.chomp.to!int;
    immutable train_02 = readln.chomp.to!int;
    immutable bus_01 = readln.chomp.to!int;
    immutable bus_02 = readln.chomp.to!int;

    immutable answer = min(train_01, train_02) + min(bus_01, bus_02);
    writeln(answer);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A;
  int F = 0;
  cin >> A;
  for(int B = 1; B<10; B++){
    for(int C = 1; C<10; C++){
      if(A == B*C){
        F = 1;
      }
    }
  }
  if(F == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256