akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] r = new int[9];
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = a / 400;
            if (a < 3200) {
                r[b]++;
            } else {
                r[8]++;
            }
        }
        int c = 0;
        for (int i = 0; i <= 7; i++) {
            if (r[i] > 0) {
                c++;
            }
        }
        if (c > 0) {
            System.out.println("" + c + " " + (c + r[8]));
        } else {
            System.out.println("" + 1 + " " + (c + r[8]));
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,m;

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

	ll X = (n - m) * 100 + m * 1900;

	REP(i,m) {
		X *= 2;
	}
	cout << X << endl;

	return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())

if h == 1 or w == 1:
    print(1)

elif h%2 == 0 or w%2 == 0:
    if h%2 == 0:
        result = (h//2) * w
        print(result)
    else:
        result = (w//2) * h
        print(result)
else:
    result = (h//2) * (w//2) + (h - h//2) * (w - w//2)
    print(result)

Measured memory_bytes: 3064
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

template <typename T>
T Max(T x, T y) {return x > y ? x : y;}

template <typename T>
T Min(T x, T y) {return x < y ? x : y;}

#define LL long long

const LL mod = 1000000007;

LL k, inv, ans;
LL sum[2005];
int n;
int a[2005];

int main() {
    inv = (mod + 1) / 2;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i ++)
        scanf("%d", &a[i]);
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= n; j ++) {
            if(i == j) continue;
            if(a[j] < a[i]) sum[i] ++;
        }
    for(int i = 1; i <= n; i ++) {
        LL cnt = 0;
        for(int j = i + 1; j <= n; j ++)
            if(a[j] < a[i])
                cnt ++;
        ans = (ans + (cnt * k % mod)) % mod;
    }
    for(int i = 1; i <= n; i ++)
        ans = (ans + (k - 1) * k % mod * sum[i] % mod * inv % mod) % mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import Counter
# from numba import njit

# input = stdin.readline

# @njit
def solve(n,a):
  d = Counter(a)
  res = 0
  for k,v in d.items():
    if k <= v:
      res += v-k
    else:
      res += v
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 22456
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next()); 
    int B = A % 10;
    if(B==3){
      System.out.println("bon");
    }else if(B==0 || B==1 || B==6 || B==8){
      System.out.println("pon");
    }else{
      System.out.println("hon");
    }
  }
}



Measured memory_bytes: 35536
sx, sy, tx, ty = gets.chomp.split.map(&:to_i)
print "U"*(ty-sy).abs+"R"*(tx-sx).abs
print "U"+"L"*((tx-sx).abs+1)+"D"*((ty-sy).abs+1)+"R"
print "R"*(tx-sx).abs+"U"*(ty-sy).abs
print "R"+"D"*((ty-sy).abs+1)+"L"*((tx-sx).abs+1)+"U"
puts

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

int main() {
    int n; cin >> n;
    int h[n + 1];
    for (int i = 0; i < n; i++) cin >> h[i];

    int dp[n + 1];
    dp[0] = 0, dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)

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

int main(){
	int N ;
	cin >> N;
	int A[N];
	for(int i = 0; i < N; i++) cin >> A[i];
	int n = N;
	int a = 0;
	while(n == N){
		n = 0;
		for(int i = 0; i < N; i++){
			if(A[i] % 2 == 0) {
			n++;
			A[i] = A[i] / 2;
			}
		}
		if(n == N) a++;
	}
	cout << a << endl;
}
	


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    string s, t;
    cin >> s >> t;
    if(s.size() != (t.size())-1)
    	cout << "No";
    else{
    	ll c = 0;
    	// cout << "ye";
    	for(int i = 0; i < s.size(); ++i){
    		if(s[i] != t[i]){
    			++c;
    			cout << "No";
    			break;
    		}
    	}
    	if(c == 0)
    		cout << "Yes";
    } 
    return 0;
}

Measured memory_bytes: 3648
import bisect
h,w,m=map(int,input().split())
hl=[0]*h
wl=[0]*w
s=[]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    hl[a]+=1
    wl[b]+=1
    s.append([a,b])
mh=max(hl)
mw=max(wl)
hh=[]
ww=[]
for i in range(h):
    if hl[i]==mh:
        hh.append(i)
for i in range(w):
    if wl[i]==mw:
        ww.append(i)
f=0
for a,b in s:
    hi=bisect.bisect_left(hh,a)
    wi=bisect.bisect_left(ww,b)
    if hi!=len(hh) and hh[hi]==a and wi!=len(ww) and ww[wi]==b:
        f+=1
if len(hh)*len(ww)>f:
    print(mh+mw)
else:
    print(mh+mw-1)

Measured memory_bytes: 168528
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
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;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int main() {
	int N, M, R;
	scanf("%d %d %d", &N, &M, &R);

	int r[8];
	for (int i = 0; i < R; i++) {
		scanf("%d", &r[i]);
	}
	int mm[200][200];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			mm[i][j] = INT_MAX/10 * (i != j);
		}
	}
	for (int i = 0; i < M; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		mm[a-1][b-1] = c;
		mm[b-1][a-1] = c;
	}

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0 ; j < N; j++) {
				if (mm[i][j] > mm[i][k] + mm[k][j]) {
					mm[i][j] = mm[i][k] + mm[k][j];
				}
			}
		}
	}

	int min = INT_MAX/10;
	sort(r, r+R);
	do {
		int sum = 0;
		for (int i = 1; i < R; i++) {
			sum += mm[r[i-1]-1][r[i]-1];
		}
		chmin<int>(min,sum);
	} while (next_permutation(r, r+R));
	printf("%d\n", min);
	return 0;
}


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

int main() {
  // 入力
  int a, b, c;
  cin >> a >> b >> c;

  int ans;
  if (a == b) {
    ans = c;
  } else if (a == c) {
    ans = b;
  } else {
    ans = a;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(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 PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[2][100], dp[2][101];

int main() {
	cin >> n;
	inc(i, 2) {
	inc(j, n) {
		cin >> a[i][j];
	}
	}
	
	dp[0][0] = 0;
	inc1(j, n) {
		dp[0][j] = dp[0][j - 1] + a[0][j - 1];
		dp[1][j] = max(dp[1][j - 1], dp[0][j]) + a[1][j - 1];
	}
	
	cout << dp[1][n] << endl;
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
taro = 0
hanako = 0
for i in range(n):
    t,h = input().split()
    if t>h:
        taro += 3
    elif t==h:
        taro += 1
        hanako += 1
    else:
        hanako += 3
print(taro,hanako)


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

int main()
{
	int k; cin >> k;
	
	vector<int> vec(32);        
	vec = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	cout << vec[k-1] << endl;
	
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
//#define TEST

struct stx{
    int s, t, x;
    bool operator < (const stx& o) const{
        if (x == o.x)
            return s < o.s;
        return x < o.x;
    }
};

const int INF = 1e9+10;

int main(int argc, char** argv) {
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\stdout", "w", stdout);
    }

    int N, Q;
    cin >> N >> Q;
    vector<stx> v(N);
    FOR(i, N) {
        cin >> v[i].s >> v[i].t >> v[i].x;
        v[i].s -= v[i].x;
        v[i].t -= v[i].x;
    }
    sort(v.begin(), v.end());
    set<pii> D;
    FOR(i, Q) {
        int di;
        cin >> di;
        D.insert(make_pair(di, i));
    }

    vector<int> sol(Q, -1);
    FOR(i, N){
        if (D.empty()) break;
        auto it = D.lower_bound(make_pair(v[i].s,-1));
        while(it != D.end() && it->first < v[i].t){
            sol[it->second] = v[i].x;
            it = D.erase(it);
        }
    }
    FOR(i, Q)
        cout << sol[i] << '\n';

    //if (argc == 2 && atoi(argv[1]) == 123456789) cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


Measured memory_bytes: 14336
n = int(input())

L = [int(i) for i in input().split()]

Answer = int(0)
for i in range(n-2):
     if L[i]<L[i+1] and L[i+1]<L[i+2]:
             Answer = Answer + 1
     if L[i+2]<L[i+1] and L[i+1]<L[i]:
             Answer = Answer + 1
print(Answer)


Measured memory_bytes: 3060
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
	return c - '0';
}

	return -1;
}

int main() {
	char A, B, C, D;
	cin >> A >> B >> C >> D;

	int a = ctoi(A);
	int b = ctoi(B);
	int c = ctoi(C);
	int d = ctoi(D);


	for (int i=0; i<=1; i++) {
		for (int j=0; j<=1; j++) {
			for (int k=0; k<=1; k++) {
				string ans = "";
				int result = a;
				ans += A;

				if (i) {
					result += b;
					ans += '+';
				} else {
					result -= b;
					ans += '-';
				}
				ans += B;

				if (j) {
					result += c;
					ans += '+';
				} else {
					result -= c;
					ans += '-';
				}
				ans += C;

				if (k) {
					result += d;
					ans += '+';
				} else {
					result -= d;
					ans += '-';
				}
				ans += D;

				if (result == 7) {
					ans += "=7";
					cout << ans << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.Exception
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    var allcut = 0L
    for (i in 0 until n) {
        allcut += a[i] - 1
    }
    if (allcut <= k) {
        println(1)
        return
    }
    var l = 1
    var r = 1000000005
    while (r - l > 1) {
        val mid = (l + r) / 2
        var num = 0L
        for (i in 0 until n) {
            num += (a[i] + mid - 1) / mid - 1
        }
        if (num <= k) {
            r = mid
        } else {
            l = mid
        }
    }
    println(r)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 59016
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <array>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define uinf 0x3f3f3f3f3f3f3f3f
#define CLEAR(a) a = decltype(a)()
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define pii pair<int ,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define pi 2*acos(0.0)
#define INFILE() freopen("in.txt","r",stdin)
#define OUTFILE() freopen("out.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FIN std::ifstream cin("D:\input.txt")

vector<int> A;
int N;
int siz;

int d(vector<int> nums) {
	nums.push_back(-1000000);
	for (auto a : A) {
		nums.back() = a;
		int num = 0;
		if (siz == nums.size()) {
			REP(i, nums.size()) num += nums[i] * pow(10, i);
		}
		else {
			num = d(nums);
		}
		if (N <= num) return num;
	}
	return -1;
}

signed main(void) {
	cin >> N;
	siz = (int)log10(N)+1;

	int K; cin >> K;
	bitset<10> D;
	REP(i, K) {
		int a; cin >> a;
		D[a] = true;
	}
	REP(i, 10) if (not D[i]) A.push_back(i);

	int res = d(vector<int>());
	if (res >= 0) {
		cout << res << endl;
		return 0;
	}

	if (A[0] == 0) {
		cout << A[1];
	}
	else cout << A[0];

	REP(i, siz) cout << A[0];
	cout << endl;

	return 0;
}


Measured memory_bytes: 888
def main():
    from builtins import int,str,map,list,dict,float,print,len,sorted,max,min
    from itertools import accumulate, permutations, combinations
    from collections import deque, defaultdict, Counter
    from operator import itemgetter
    from bisect import bisect_left, bisect_right, bisect
    from heapq import heappop, heappush
    from fractions import gcd
    import sys, re, math, copy

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))
    sys.setrecursionlimit(10 ** 6)  # 再帰上限を10＊＊6に

    D = input_number()
    ans = 'Christmas'
    r = 25 - D
    for i in range(r):
        ans+=' Eve'
    print(ans)

def resolve():
    main()

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 64876
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), m = s.nextInt();
		Map<Integer,String> ac = new TreeMap<>();
		Map<Integer,String> wa = new TreeMap<>();
		Map<String, Integer> waMap = new HashMap<String, Integer>();
		int wrong = 0, accepted = 0;
		for(int i=0;i<m;i++) {
			int num = s.nextInt();
			String val = s.next();
			if (val.equals("AC")) {
				if (!ac.containsKey(num)) {
					accepted++;
					ac.put(num, val);
				}
			}else {
				if (waMap.containsKey(num+"WA")) {
					waMap.put(num+"WA", waMap.get(num+"WA") + 1);
				}else {
					waMap.put(num+"WA", 1);
				}
				if (!ac.containsKey(num)) {
					wrong++;
				}
				if (!wa.containsKey(num)) {
					wa.put(num, val);
				}
			}
		}
		for(Integer x : wa.keySet()) {
			if (!ac.containsKey(x)) {
				wrong -= waMap.get(x+"WA");
			}
		}
		System.out.println(accepted+" "+wrong);
	}
}


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

int main() {


int a,b,c,x,d=0;
cin>>a>>b>>c>>x;
int i,j,k;

for( i=0;i<=a;i++)
{
    for( j=0;j<=b;j++)
    {
        
        for( k=0;k<=c;k++)
        {
            if((500*i+100*j+50*k)==x)
                d++;
            
        }
        
        
        
        
        
    }
    
    
 
   }





cout<<d;








	return 0;
}

Measured memory_bytes: 256
import math

def distance(p,x,y):
    ans = 0
    for i in range(len(x)):
        ans += (abs(x[i]-y[i])**p)
    return pow(ans,1/p)

def chebyshev(x,y):
    return max(abs(x[i]-y[i]) for i in range(len(x)))

N = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

print(distance(1,x,y))
print(distance(2,x,y))
print(distance(3,x,y))
print(chebyshev(x,y))    


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

using namespace std;
int main(){
double a,b,c,d,e;
cin>>a;
b=a*2;
c=a*a;
d=b*3.14159265358979323846;
e=c*3.14159265358979323846;
printf("%6f",e);
cout<<" ";
printf("%6f",d);
cout<<endl;
return 0;
}

Measured memory_bytes: 1280
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

const K: usize = 26;

#[derive(Debug)]
struct Input {
    d: usize,
    c: Vec<i64>,
    s: Vec<Vec<i64>>,
}

fn get_input<'a>(it: &mut impl Iterator<Item = &'a str>) -> Input {
    parse!(it, d: usize, c: [i64; K]);
    let mut s = vec![];
    for _ in 0..d {
        parse!(it, sl: [i64; K]);
        s.push(sl);
    }
    Input { d, c, s }
}

fn calc_score(input: &Input, t: &[usize]) -> i64 {
    let mut score = 0;
    let mut last = vec![0; K];
    for i in 0..t.len() {
        score += input.s[i][t[i]];
        last[t[i]] = i + 1;
        for j in 0..K {
            score -= input.c[j] * ((i + 1 - last[j]) as i64);
        }
    }
    score
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let input = get_input(&mut it);
    debug!("{:?}", input); // DEBUG
    parse!(it, t: [u1; input.d]);
    for i in 0..t.len() {
        println!("{}", calc_score(&input, &t[..(i + 1)]));
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

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

    string s;
    cin >> s;

    int n = s.length();
    int sum = 0;

    for(int i = 0; i < n; i++)
    {
        sum += (s[i] - '0');
    }

    if(sum % 9 == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    
    return 0;
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s;
  cin>>t;
  int a=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      for(int j=0;j<i;j++){
        if(s[j]==t[i] || s[j]==s[i]){
          a=1;
          break;
        }
      }
      for(int j=i+1;j<s.size();j++){
        if(s[j]==t[i]){
          s[j]=s[i];
        }
        else if(s[j]==s[i]){
          s[j]=t[i];
        }
      }
      s[i]=t[i];
    }
    if(a==1) break;
  }
  if(a==1) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

vector<vector<int>> data(100010);
ll dp[100010][3];
bool kati(ll i,ll j){
    if((i+1)%3==j){
        return true;
    }
    return false;
}
ll Max(ll a,ll b,ll c){
    if(a>b && a>c){
        return a;
    }
    if(b>a && b>c){
        return b;
    }
    return c;
}

int main(){
    ll n,k,r[3];cin>>n>>k>>r[0]>>r[1]>>r[2];
    string t;
    cin>>t;
    int xx;
    rep(i,0,n-1){
        if(t[i]=='r'){
            xx=0;
        }else if(t[i]=='s'){
            xx=1;
        }else{
            xx=2;
        }
        data[i%k].pb(xx);
    }
    ll sum=0;
    
    rep(i,0,k-1){
        rep(j,0,data[i].size()-1){
            if(j==0){
                dp[j][(data[i][0]+2)%3]=r[(data[i][0]+2)%3];
                dp[j][(data[i][0]+1)%3]=0;
                dp[j][(data[i][0])%3]=0;
            }else{
                rep(l,0,2){
                    dp[j][l]=max(dp[j-1][(l+1)%3],dp[j-1][(l+2)%3]);
                    if(kati(l,data[i][j])){
                        dp[j][l]+=r[l];
                    }
                }
            }
            /*
            rep(l,0,2){
                cout<<dp[j][l]<<' ';
            }
            cout<<endl;*/
        }
        sum+=Max(dp[data[i].size()-1][0],dp[data[i].size()-1][1],dp[data[i].size()-1][2]);
        //cout<<dp[data[i].size()-1][0]<<dp[data[i].size()-1][1]<<dp[data[i].size()-1][2]<<endl;
    }
    cout<<sum<<endl;
    
    return 0;
}



Measured memory_bytes: 5624
n =int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[n-1])

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

signed main(){
  int a,b,c,d=0;
  cin>>a>>b>>c;
  if(a != b )
    d++;
  if(b != c)
    d++;
  if(c != a)
    d++;
  if(d == 2)
    cout<<"Yes\n";
  else 
    cout<<"No\n";
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;

int main(void){
    for(int i=0;i<3;i++){
        char n;cin>>n;
        if(n=='1')cout<<'9';
        else cout<<'1';
    }
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 256
a = input().split()
W = int(a[0])
H = int(a[1])
x = int(a[2])
y = int(a[3])
if (x == W/2 and y != H/2) or (x != W/2 and y == H/2) or (x != W/2 and y != H/2):
  print(H*W/2,0)
else:
  print(H*W/2,1)

Measured memory_bytes: 38256
#include<iostream>

using namespace std;

int main(){
    char yosou[3];
    char tenki[3];
    int ans = 0;


    cin>>yosou;
    cin>>tenki;

    for(int i = 0; i < 3; i++){
        if(yosou[i] == tenki[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
mgr = [4, 1, 4, 1, 2, 1, 2, 1]

while True:
    try:
        p = list(map(int, input().split(' ')))
        v = []
        for i in range(8):
            q = mgr[i:] + mgr[:i]
            sum_v = sum(p) - sum(p[j]-q[j] if p[j]-q[j] >= 0 else 0 for j in range(8))
            v.append(sum_v)
        if v.count(max(v)) > 1:
            mv = max(v)
            ans = []
            for i in range(8):
                if v[i] == mv:
                    ans.append(int("".join(map(str, mgr[i:] + mgr[:i]))))
            print(" ".join(list(str(min(ans)))))
        else:
            i = v.index(max(v))
            print(" ".join(map(str, mgr[i:] + mgr[:i])))
    except:
        break

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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto &(i) : (vec))


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
inline
int numb(int a, int b, int c, int n, int k, Vint &Data){
  Vint A(4, 0), B(4, -1);
  REP(i, n){
    A.at(k & 3) += Data.at(i);
    B.at(k & 3)++;
    k >>= 2;
  }
  if(B.at(0) == -1 || B.at(1) == -1 || B.at(2) == -1) return INFi;
  int cost_merge = 10 * (B.at(0) + B.at(1) + B.at(2));
  return abs(a - A.at(0)) + abs(b - A.at(1)) + abs(c - A.at(2)) + cost_merge;
}

int main(void){
  int n, a, b, c; cin >> n >> a >> b >> c;
  Vint L(n); vREP(ele, L) cin >> ele;
  // cout << "L :"; vREP(ele, L) cout << ele << " "; cout << "\n";
  int res = INFi;
  REP(i, 1 << (2 * n)) chmin(res, numb(a, b, c, n, i, L));
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
    int n, a, i = 1;
    scanf("%d%d", &n, &a);
    while(pow(a,i) <= n)
    {
        i++;
    }
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 888
N,Q = map(int,input().strip().split())
P = [i for i in range(N)]
def root(x):
    path_to_root = []
    while P[x] != x:
        path_to_root.append(x)
        x = P[x]
    for node in path_to_root:
        P[node] = x # パス圧縮
    return x
def is_same_set(x,y):
    return root(x) == root(y)
def unite(x,y):
    P[root(x)] = root(y)
for i in range(Q):
    q,x,y = map(int,input().strip().split())
    if q == 0:
        unite(x,y)
    if q == 1:
        print(int(is_same_set(x,y)))



Measured memory_bytes: 5976
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define all(v) v.begin(),v.end()

int32_t main() {
	int n;
	cin>>n;
	int a[n],dp[n]={0};
	for(int i=0;i<n;i++) cin>>a[i];
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
	    dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
k = int(input())
S = input()
n = len(S)
mod = 10**9+7

facs = [1] * (n+k)
# invs = [1] * (n+k)
nfac = 1
for i in range(1, n+k):
    nfac = nfac * i % mod
    facs[i] = nfac
    # invs[i] = pow(facs[i], mod-2, mod)
invn1 = pow(facs[n-1], mod-2, mod)

ans = 0
for i in range(k+1):
    left = facs[i+n-1] * pow(facs[i], mod-2, mod) * invn1 % mod
    left = left * pow(25, i, mod) % mod
    ans += left * pow(26, k-i, mod) % mod
    ans %= mod
print(ans)


Measured memory_bytes: 91364
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int r = sc.nextInt();
        int d = sc.nextInt();
        int x2000 = sc.nextInt();

        for (int i = 0; i<10; i++){
            int cu = (x2000*r) - d;
            System.out.println(cu);
            x2000 = cu;
        }
    }
}

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

int main() {
  string a, b;
  cin >> a >> b;
  if(a.size() > b.size()) {
    cout << "GREATER" << endl;
    return 0;
  } else if(a.size() < b.size()) {
    cout << "LESS" << endl;
    return 0;
  }
  int n = a.size();
  for (int i=0; i<n; i++) {
    if(a.at(i) > b.at(i)) {
      cout << "GREATER" << endl;
      return 0;
    } else if(a.at(i) < b.at(i)) {
      cout << "LESS" << endl;
      return 0;
    }
  }
  cout << "EQUAL" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}


Measured memory_bytes: 2728
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 505;

char a[MAXN][MAXN];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) scanf("%s", a[i]);

  bool bad = true;
  int c = 0;
  REP(j, n) {
    int cb = 0;
    REP(i, n)
      if (a[i][j] == '#') cb++;
    
    if (cb > 0) bad = false;
    if (cb < n) c++;
  }

  if (bad) {
    puts("-1");
    return 0;
  }
  
  int ans = 1e9;
  REP(i, n) {
    int cw = 0;
    REP(j, n)
      if (a[i][j] == '.') cw++;
    int cb = 0;
    REP(j, n)
      if (a[j][i] == '#') cb++;

    ans = min(ans, cw + (cb == 0) + c);
  }

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


Measured memory_bytes: 512
import sys
def main():
  input=sys.stdin.readline
  N, K = map(int, input().split())
  wd = [tuple(map(int, input().split())) for i in range(N)]
  wd.sort()
  d = 0
  dp = [0]*N
  l = 0
  r = wd[0][0] + wd[0][1]*K
  while(r - l > 1):
    tmp = (l+r)//2
    num = 0
    for w, d in wd:
      if w <= tmp:
          num += ((tmp - w) // d) + 1
    if num >= K:
      r = tmp
    else:
      l = tmp
  print(r)
main()

Measured memory_bytes: 18112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cerr<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

int main(){
    int n,m;cin >> n >> m;
    vector<vi> vec(100001+10);
    rep(i,n){
        int a,b;cin >> a >> b;
        vec[a].push_back(b);
    }
    ll ans = 0;
    priority_queue<int> q;
    for(int i=1;i<=m;++i){
        for(int j=0;j<vec[i].size();++j){
            q.push(vec[i][j]);
        }
        if(q.empty()) continue;
        ans += q.top();q.pop();
        //cerr << "i = " << i << " ans = " << ans << "\n";
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
def abs(c): 
    if c > 0: 
        return c 
    else: 
        return -c

    n = int(input())
n = int(input())
a = [int(i) for i in input().split()]
h = len(a)
a.sort()
t = a[h-1]
s = a[0]
center = t/2
interval = abs(center-s)

for i in range(1,h-1):
    if abs(center-a[i]) < interval:
        s = a[i]
        interval = abs(center-a[i])
        
print(t,end="")
print(" ",end="")
print(s)


Measured memory_bytes: 14052
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 12

int N,D;
int table[10][SIZE];


int main(){

	scanf("%d %d",&N,&D);

	for(int i = 0; i < N; i++){
		for(int k = 0; k < D; k++){

			scanf("%d",&table[i][k]);
		}
	}

	int ans = 0;
	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){

			int sum = 0;

			for(int a = 0; a < D; a++){

				sum += (table[i][a]-table[k][a])*(table[i][a]-table[k][a]);
			}

			int tmp = sqrt(sum);

			if(tmp*tmp == sum){

				ans++;
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
      
int main(void){
      
int i,x,y,n;
  
for(i=1;i<=3000;i++){
scanf("%d %d",&x,&y);
if(x==0&&y==0){
break;
}
if(x>y){
n=x;
x=y;
y=n;
}
printf("%d %d\n",x,y);
}
  
return 0;
}


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

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

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

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

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

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

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

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

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

void debug_out() { cerr << endl; }

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

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

const int N = 2e5 + 5;
int a[N];
void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int c1 = 0, c2 = 0;
	fr(i, 0, n - 2){
		if(s[i] == 'W') c1++;
	}
	int ans = 1e18;
	for(int i = n - 1; i >= 0; i--){
		ans = min(ans, c1 + c2);
		if(i == 0) break;
		if(s[i] == 'E') c2++;
		if(s[i - 1] == 'W') c1--;
	}
	cout << ans;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<cstdio>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
const int N=200005;
int n,m,h,w;
int fa[N];
vector<tuple<int,int,int> >G;
bool isc[N];
int getf(int v)
{
	if(v==fa[v]) return v;
	fa[v]=getf(fa[v]);
	return fa[v];
}
int merge(int u,int v)
{
	int f1=getf(u),f2=getf(v);
	if(f1!=f2)
	{
		if(isc[f1]&&isc[f2]) return -1;
		else
		{
			fa[f2]=f1;
			isc[f1]|=isc[f2];
			return 1;
		}
	}
	else if(!isc[f1])
	{
		isc[f1]=true;
		return 0;
	}
	else return -1;
}
int main()
{
	scanf("%d%d%d",&n,&h,&w);
	for(int i=1;i<=n;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		v+=h;
		G.push_back(make_tuple(u,v,w));
	}
	sort(G.begin(),G.end(),[=](const tuple<int,int,int>&x,const tuple<int,int,int>&y){return get<2>(x)>get<2>(y);});
	m=h+w;
	for(int i=1;i<=m;i++)
		fa[i]=i,isc[i]=false;
	long long ans=0;
	for(auto [u,v,w]:G)
		if(merge(u,v)!=-1) ans+=w;
	printf("%lld",ans);
	return 0;
}

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

using namespace std;
//解説写経
int dp[50][500][500];
int a[50]; int b[50]; int c[50];
const int inf = 1e9;

int main(){
int n,ma, mb; cin >> n >> ma >> mb;
  
  for(int i = 0; i < 50; i++){
    for(int j = 0; j < 500; j++){
      for(int k = 0; k < 500; k++){ 
         dp[i][j][k] = inf;
      }}}
 
  for(int i = 0; i < n ; i++){ cin >> a[i] >> b[i] >> c[i];}
  
  dp[0][0][0] = 0; 
  
  for(int i = 0; i < n; i++){
    // dp[i][][]からdp[i+1][][]への配るdpを考える
    for(int j = 0; j < 500; j++){
      for(int k = 0; k < 500; k++){
        if( dp[i][j][k] == inf){ continue;}
        
        dp[i+1][j][k] = min( dp[i+1][j][k], dp[i][j][k]);
        if( j+a[i] < 500 && k+b[i] < 500){
        dp[i+1][j+a[i]][k+b[i]] = min( dp[i+1][j+a[i]][k+b[i]]  , dp[i][j][k] + c[i]);}
        
      }}}
  
     int ans = inf;
     int c = 1;
    while( ma*c <= 500 && mb*c <= 500){
      ans = min( ans, dp[n][ma*c][mb*c]); c++;}
  
  if( ans == inf){ ans = -1;}
    
    cout << ans << endl; return 0;}
                
       
        
    
  

Measured memory_bytes: 49024
using System;
public class Hello
{
    public static void Main()
    {
        var line = System.Console.ReadLine().Split(' ');
        long A = long.Parse(line[0]);
        long V = long.Parse(line[1]);
        line = System.Console.ReadLine().Split(' ');
        long B = long.Parse(line[0]);
        long W = long.Parse(line[1]);
        long T = long.Parse(System.Console.ReadLine());
        long D = T * V - T * W;
        long d = Math.Abs(A - B);
        if (D >= d)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }

    }
}


Measured memory_bytes: 27396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

int main() {
    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    
    vector<int> a(n), b(n);
    rep(i, n) {
        a[i] = (i + 1) * n;
        b[i] = (n - i) * n;
    }
    
    rep3(i, 1, n) {
        p[i]--;
        a[p[i]] += i;
    }
    
    outa(a, n);
    outa(b, n);
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N+1);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int cnt = 1;
  int ans = 0;
  
  for(int j=0; j<N; j++){
    if(vec.at(j) == vec.at(j+1)){
      cnt++;
    }
    else{
      ans++;
      if(cnt %2 == 0){
        ans--;
      }
      cnt = 1;
    }
  }
  cout << ans << endl; 
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int ans,n,a[100001],m; 
int main()
{
	cin>>n>>m;
	ans=2147483647;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a,a+n+1);
	for(int i=1;i<=n-m+1;i++)
	{
		ans=min(ans,a[i+m-1]-a[i]);
	}
	cout<<ans;
}
 

Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

if N % 10 in [2,4,5,7,9]:
    print("hon")
elif N % 10 in [0, 1, 6, 8]:
    print("pon")
elif N % 10  == 3:
    print("bon")

Measured memory_bytes: 61660
N = int(input())
hight_list = [int(item) for item in input().split()]


dp = [0 for i in range(N+1)]

dp[1] = abs(hight_list[1] - hight_list[0])

for i in range(2, N):
    jump1 = abs(hight_list[i] - hight_list[i-1])
    jump2 = abs(hight_list[i] - hight_list[i-2])

    dp[i] = min(dp[i-1] + jump1, dp[i-2] + jump2)


print(dp[N-1])

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

#define C getchar()

inline int read()
{
    int x=0;
    char ch;
    bool flag=true;
    for(;ch>'9'||ch<'0';ch=C)
    if(ch=='-')
    flag=false;
    for(;ch>='0'&&ch<='9';ch=C)
    x=(x<<3)+(x<<1)+(ch^48);
    return flag?x:-x;
}

int n;
long long ans=9999999999;

void intt()
{
    n=read();
}

void work()
{
    for(int i=1;i<=n/2;i++)
    {
        long long anss=0;
        int j=i;
        int k=n-i;
        while(j||k)
        {
            anss+=k%10+j%10;
            j/=10;
            k/=10;
        }
        ans=min(ans,anss);
    }
    printf("%lld\n",ans);
}

int main()
{
    intt();
    work();
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (A, B) = readInts()
  println(
    when {
      A <= 5 -> 0
      A <= 12 -> B / 2
      else -> B
    }
  )
}

fun readString() = readLine()!!
fun readStrings() = readString().split(' ')
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 38048
using System;

public class Test
{
	static public void Main( )
	{
		int n = int.Parse( Console.ReadLine() );
		int i = 1;
		
		do {
			int x = i;
			if( 0 == x%3 ) {
				Console.Write( " {0}", i );
			} else {
				do {
					if( 3 == x%10 ) {
						Console.Write( " {0}", i );
						break;
					} else {
						x /= 10;
					}
				} while( 0 != x );
			}
		} while( ++i <= n );
		
		Console.WriteLine( );
	}
}

Measured memory_bytes: 5764
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        
        int result_1 = a * b;
        int result_2 = c * d;
        
        if (result_1 > result_2) {
            System.out.println(result_1);
        } else {
            System.out.println(result_2);
        }
        scan.close();
    }
}

Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int N=s.length();
  vector<ll> dp(N+1);
  dp[1]=1;
  if(s[0]==s[1]){
    dp[2]=1;
  }else{
    dp[2]=2;
  }
  FOR(i,3,N+1){
    if(s[i-1]!=s[i-2]){
      dp[i]=dp[i-1]+1;
    }else{
      dp[i]=dp[i-3]+2;
    }
  }
  cout<<dp[N]<<endl;
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
int w[105],v[105];
int w1[105],w2[105],w3[105],w4[105];
int x1,x2,x3,x4;
int cnt1=1,cnt2=1,cnt3=1,cnt4=1;
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n,W;
	cin>>n>>W;
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&w[i],&v[i]);
		if(w[i]==w[0])  w1[cnt1++]=v[i];
		if(w[i]==w[0]+1)w2[cnt2++]=v[i];
		if(w[i]==w[0]+2)w3[cnt3++]=v[i];
		if(w[i]==w[0]+3)w4[cnt4++]=v[i];
	}
	sort(w1+1,w1+cnt1,cmp);
	sort(w2+1,w2+cnt2,cmp);
	sort(w3+1,w3+cnt3,cmp);
	sort(w4+1,w4+cnt4,cmp);
	for(int i=2;i<cnt1;i++) w1[i]+=w1[i-1];
	for(int i=2;i<cnt2;i++) w2[i]+=w2[i-1];
	for(int i=2;i<cnt3;i++) w3[i]+=w3[i-1];
	for(int i=2;i<cnt4;i++) w4[i]+=w4[i-1];
	x1=w[0],x2=x1+1,x3=x2+1,x4=x3+1;
	int ma=-1;
	for(int i1=0;i1<=cnt1;i1++)
	{
		for(int i2=0;i2<=cnt2;i2++)
		{
			for(int i3=0;i3<=cnt3;i3++)
			{
				for(int i4=0;i4<=cnt4;i4++)
				{
					if(1ll*i1*x1+1ll*i2*x2+1ll*i3*x3+1ll*i4*x4>1ll*W) continue;
					ma=max(w1[i1]+w2[i2]+w3[i3]+w4[i4],ma);
				}
			}
		}
	}
	cout<<ma;
}

Measured memory_bytes: 256