akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    int total=0,change=0,gh=0,h=0,gj=0,j=0,g=0,i=0,coin=0;
    while(1){
        scanf("%d",&total);
        if(total==0)break;
        change=1000-total;
        gh=change/500;
        change=change%500;
        h=change/100;
        change=change%100;
        gj=change/50;
        change=change%50;
        j=change/10;
        change=change%10;
        g=change/5;
        change=change%5;
        i=change;
        coin=gh+h+gj+j+g+i;
        printf("%d\n",coin);
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int a,b,c,d,e; cin >> a >> b >> c >> d >> e;
	if(!a) cout << 1;
	if(!b) cout << 2;
	if(!c) cout << 3;
	if(!d) cout << 4;
	if(!e) cout << 5;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3608
def func():
    tvs = []
    for i in range(num):
        tvs.append((-1, -1))
    for i in range(len(bans)):
        now = bans[i][0]
        can = bans[i][2]
        tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]
        for j, tv in enumerate(tvs):
            if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
                del tvs[j]
                tvs.append((bans[i][1], can))
                break
        else:
            return False
    return True


n, C = map(int, input().split())

bans = []
for i in range(n):
    bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])

for num in range(1, 1024):
    if func():
        print(num)
        break


Measured memory_bytes: 18984
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;

int main(void){
    ll result = 0;
    
    ll N, M;
    cin >> N >> M;
    
    vector<ll> count(M, 0);
    rep(i, N){
        int K;
        cin >> K;
        
        rep(i, K){
            ll x;
            cin >> x;
            
            count[x-1] ++;
        }
    }
    
    rep(i, M){
        if(count[i] == N){
            result ++;
        }
    }
    cout << result << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    set<pair<int, int>> red;
    vector<pair<int, int>> blue(n);
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a >> b;
        pair<int, int> p=make_pair(a,b);
        red.insert(p);
    }
    for(int i=0; i<n; i++){
        int c,d;
        cin >> c >> d;
        pair<int, int> p=make_pair(c,d);
        blue.at(i)=p;
    }
    sort(blue.begin(), blue.end());
    int ans=0;
    for(int i=0; i<n; i++){
        int a,b;
        a=blue.at(i).first;
        b=blue.at(i).second;
        bool possible=false;
        int pair_c, pair_d=0;
        for(auto p:red){
            int c,d;
            c=p.first;
            d=p.second;
            //cout << "c" << c << "d" << d << " ";
            if(c<a && d<b){
                possible = true;
                if(d >= pair_d){
                    pair_d=d;
                    pair_c=c;
                }
            }
        }
        if(possible){
            ans++;
            pair<int,int> q=make_pair(pair_c, pair_d);
            red.erase(q);
            //cout << "blue" << a << b << "red" << pair_c << pair_d << endl;
        }
        for(auto p:red){
            //cout << p.first << p.second << " ";
        }
        //cout << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cmath>
#define NUM 1000000
using namespace std;
int main(){
  int n, prime[NUM+1], p[NUM+1], count, sum;
  prime[1]=0;
  for(int i=2; i<NUM+1; i++){
    prime[i] = 1;
    p[i-2]=0;
  }
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
      	  prime[i*j]=0;
      }
  }
  count=0;
  for(int i=2; i<=NUM; i++){
    if(prime[i] == 1){
      p[count] = i;
      count++;
    }
  }
  while(cin >> n){
    if(n == 0) return 0;
    sum=0;
    for(int i=0; i<n; i++){
      sum+=p[i];
    }
    cout << sum << endl; 
  }  
}

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

typedef long long ll;

ll N, S;
vector<ll> A;
vector<vector<ll>> Dp;
const ll MOD = 998244353;
const ll HALF = MOD / 2 + 1;

int main() {
  cin >> N >> S;
  A.resize(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
  }
  Dp.resize(N + 1);
  for (auto &dp : Dp) dp.resize(S + 1);
  ll init = 1;
  for (ll i = 0; i < N; ++i) (init *= 2) %= MOD;
  Dp[0][0] = init;
  for (ll i = 0; i < N; ++i) {
    Dp[i + 1] = Dp[i];
    for (ll s = 0; s <= S - A[i]; ++s) {
      (Dp[i + 1][s + A[i]] += Dp[i][s] * HALF % MOD) %= MOD;
    }
  }
  cout << Dp[N][S] << endl;
  return 0;
}


Measured memory_bytes: 74108
#include <stdio.h>
#include <math.h>

int main()
{
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    printf("%f\n", sqrt(pow((x2-x1), 2) + pow((y2-y1), 2)));
    return 0;
}


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

int main() {
  string s, ans = "No"; cin >> s;
  int n_cnt = 0, w_cnt = 0, s_cnt = 0, e_cnt = 0;
  
  for (int i = 0; i < s.size(); ++i) {
    char direction = s[i];
    if (direction == 'N') ++n_cnt;
    else if (direction == 'W') ++w_cnt;
    else if (direction == 'S') ++s_cnt;
    else if (direction == 'E') ++e_cnt;
  }
  
  if (n_cnt > 0 && s_cnt > 0 && w_cnt > 0 && e_cnt > 0) ans = "Yes";
  else if (n_cnt == 0 && s_cnt == 0 && w_cnt > 0 && e_cnt > 0) ans = "Yes";
  else if (n_cnt > 0 && s_cnt > 0 && w_cnt == 0 && e_cnt == 0) ans = "Yes";
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for (int i=((int)(n));i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
typedef long long int ll;
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};

int main() {
  int N; cin >> N;
  int h[N]; rep(i,N) cin >> h[i];

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

  // cout << fixed << setprecision(10);
  
  return 0;
}

Measured memory_bytes: 3976
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<limits>
#include<stack>
//include<bits/stdc++.h>
using namespace std;
int main()
{
	bool arr[3][3] = { false };
	map<int, int>bingomap;
	int tmp;
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> tmp;
			bingomap[tmp] = i*3+j;
		}
	}
	int num; cin >> num;
	for (int i = 0; i < num; i++)
	{
		cin >> tmp;
		if (bingomap.find(tmp)!=bingomap.end())
		{
			int pos = bingomap[tmp];
			arr[pos / 3][pos % 3] = true;
		}
	}
	bool bingo = false;
	for (int i = 0; i < 3 && bingo ==false; i++)
	{
		int row = 0, col = 0;
		for (int j = 0; j < 3 && bingo == false; j++)
		{
			if (arr[i][j] == true)
				row++;

			if (arr[j][i] == true)
				col++;
		}
		if (row==3 || col==3)
			bingo = true;
	}
	if (bingo == false && ((arr[0][0] ==1 && arr[1][1] ==1 && arr[2][2] == true) || (arr[0][2] ==1 && arr[1][1] ==1 && arr[2][0] == true)))
		bingo = true;
	if (bingo)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by hikigineer on 2017/03/04.
 */
public class Main {
    static Scanner in;
    static PrintWriter out;
    static String INPUT = "";

    public static void main(String[] args) throws Exception
    {
        in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
        out = new PrintWriter(System.out);
        int N = ni();
        int T = ni();
        int[] t = new int[N + 1];
        int i;
        for(i = 0; i < N; i++)
            t[i] = ni();
        t[N] = 2000000000;
        long total = 0L;
        for(i = 0; i < N; i++)
        {
            total += t[i + 1] - t[i] < T ? t[i + 1] - t[i] : T;
        }
        out.println(total);
        out.flush();
    }

    static int ni() {
        return Integer.parseInt(in.next());
    }
}

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


int main(){
    int N; //店舗の数
    cin >> N;
    pair<pair<string,int>,int> rest[N];
    for(int i=0; i<N; i++){
        string S;
        int P;
        cin >> S >> P;
        rest[i].first = make_pair(S,-1*P);
        rest[i].second = i+1;
    }
    sort(rest,rest+N);
    for(int i=0; i<N; i++){
        cout << rest[i].second << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;

ll max2(ll a, ll b) {
    if (a > b) return a;
    else return b;
}

ll max3(ll a, ll b, ll c) {
    return max2(a, max2(b, c));
}

ll min2(ll a, ll b) {
    if (a > b) return b;
    else return a;
}

ll min3(ll a, ll b, ll c) {
    return min2(a, min2(b, c));
}


int main(void){
    ll h, w;
    cin >> h >> w;
    
    
    if ((h * w) % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    ll ans = 1e18, s1, s2, s3;
    ans = min2(h, w);
    for (int i = 1; i <= h; i++) {
        s1 = i * w;
        if (w % 2 == 0) s2 = s3 = (h - i) * (w / 2);
        else {
            s2 = (h - i) * (w / 2);
            s3 = (h - i) * (w / 2 + 1);
        }
        ll k = max3(s1, s2, s3) - min3(s1, s2, s3);
        if (k < ans) ans = k;
    }
    
    for (int i = 1; i <= w; i++) {
        s1 = i * h;
        if (h % 2 == 0) s2 = s3 = (w - i) * (h / 2);
        else {
            s2 = (w - i) * (h / 2);
            s3 = (w - i) * (h / 2 + 1);
        }
        ll k = max3(s1, s2, s3) - min3(s1, s2, s3);
        if (k < ans) ans = k;
    }
    
    cout << ans << endl;
    
}


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

int main() {

	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}	
	for (int i = 0; i < k; i++) {
		vector<int> b(n + 1, 0);
		for (int j = 0; j < n; j++) {
			int l = max(0, j - a[j]);
			int r = min(n, j + a[j] + 1);
			b[l]++;
			b[r]--;
		}
		vector<int> accum(n + 1, 0);
		for (int j = 0; j < n; j++) {
			accum[j] += b[j];
			if (0 < j) {
				accum[j] += accum[j - 1];
			}
		}
		if (accum == a) break;
		a = accum;
	}
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	int Max, Min;
	Min = 1000000;
	Max = -1000000;
	long long  Sum;
	Sum = 0;

	for (int i = 1; i <= n; i++){
		int k;
		cin >> k;
		if (k < Min) Min = k;
		if (k > Max) Max = k;
		Sum += k;

	}

	cout << Min <<" "<< Max <<" "<< Sum << endl;

	return 0;


}



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

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> p(N);
    for(int i = 0; i < N; i++) {
        cin >> p[i];
    }

    sort(p.begin(), p.end());

    int ret = 0;
    for(int i = 0; i < K; i++) {
        ret += p[i];
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3632
using System;
class aoj
{
    static void Main()
    {
        int[,] k = new int[50,11];
        for(int n = 0; n < 50; n++)
        {
            for(int m = 0; m < 11; m++)
            {
                k[n, m] = 0;
            }
        }
        int s = 0;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int b = int.Parse(a);
            int[] c = new int[10];
            int e = 0;
            int d = 0;
            while (b != 0)
            {
                for(int i = 9; i >= 0; i--)
                {
                    d = (int)Math.Pow(2, i);
                    if (b >= d)
                    {
                        b -= d;
                        c[e] = d;
                        e++;
                    }                                               
                }
            }
            int[] f = new int[e];
            int j = 0;
            for (int i = 0; i < 10; i++)
            {
                if (c[i] != 0)
                {
                    f[j] = c[i];
                    j++;
                }
            }
            Array.Sort(f);
            k[s,0] = e;
            int h = 0;
            for(int i = 1; i <= e; i++)
            {
                k[s,i] = f[h];
                h++;
            }
            s++;
        }
        for(int i = 0; i < s; i++)
        {
            for (int j = 1; j <= k[i,0]; j++)
            {
                if (j == 1)
                {
                    Console.Write(k[i,j]);
                }
                else
                {
                    Console.Write(" " + k[i,j]);
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9520
#include"bits/stdc++.h"
using namespace std;
int main(){
string s; cin >>s;
  string a,b,c,d;
  a=s.at(0);
    b=s.at(1);
    c=s.at(2);
    d=s.at(3);
      if(a==b&&a==c&&a==d){
    cout<<"No"<<endl;
  }
    else if(a==b&&c==d){cout<< "Yes"<<endl;}
 else if(a==c&&b==d){cout<<"Yes"<<endl;}
   else  if(a==d&&b==c){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;
     
      }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<queue>
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<char,char> pcc;
int v[100005],h[100005];
int main()
{
	int n,m;
	cin>>n>>m;
	mem(v);
	for(int i=1;i<=n;i++)
	cin>>h[i];
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		if(h[a]>h[b])
		{
			v[b]=1;
		}
		else if(h[a]==h[b])
		{
			v[a]=1,v[b]=1;
		}
		else
		{
			v[a]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(v[i]==0)
		ans++;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 4412
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

leftCost = 0
for place in a:
	if place > x:
		break
	else:
		leftCost += 1

rightCost = m - leftCost

if rightCost > leftCost:
	print(leftCost)
else:
	print(rightCost)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define hell 1000000007
#define int long double
#define inf (int)(100000000)

using namespace std;

void solve(){
    int a,b;
    cin>>a>>b;
    int ans=a*b;
    cout<<(long)(ans);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3748
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int D = sc.nextInt();
        int G = sc.nextInt();

        int[] p = new int[D];
        int[] c = new int[D];

        for (int i = 0; i < D; i++) {
            p[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        int ans = Integer.MAX_VALUE;
        for (int mask = 0; mask < (1 << D); mask++) {//D桁の2進数全探索
            int sum = 0, num = 0, restMax = -1;
            for (int i = 0; i < D; i++) {
                if (((mask >> i) & 1) == 1) {
                    // ビットが立っていたら全て解く
                    sum += 100 * (i + 1) * p[i] + c[i];
                    num += p[i];
                } else {
                    // ビットが立っていなかったら中途半端に解いている。
                    // 解くべき問題は一番高い点数の問題(=一番でかい0の桁)
                    restMax = i;
                }
            }

            //　全て解く問題だけでは不十分
            if (sum < G && restMax != -1) {
                // 中途半端に解くと決めた問題の一問あたりの点数
                int point = 100 * (restMax + 1);
                //　必要な問題数
                int rest = (G - sum);
                int need = (rest + (point - 1)) / point;
                if (need >= p[restMax]) {
                    // 問題数が足りない,または全解きは除く
                    continue;
                }
                num += need;
            }
            ans = Math.min(ans, num);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,k;
	cin>>n>>k;
	ll sum=(n-2)*(n-2+1)/2;
	if(sum<k){
		cout << -1;
		return 0;
	}
	sum=sum-k;
	cout << n-1+sum<<endl;
	for(int i=1;i<n;i++){
		cout << 1 << " " << i+1 <<endl;
		if(sum){
		for(int j=i+1;j<n;j++){
			if(sum){
			cout << i+1 <<  " " << j+1<<endl;
			sum--;
			}
		}
		}
	}
	return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).ok();
    let txt:Vec<_> = line.trim().split(' ').collect();
    let a:i32 = txt[0].parse().unwrap();
    let b:i32 = txt[1].parse().unwrap();

    let sum = a + b;
    let dif = a - b;
    let dot = a * b;

    let comp = [sum, dif, dot];
    let result = comp.iter().max().unwrap();

    println!("{}", result)
}


Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


const int INF = 1e9;

void solve() {
    int H, W, K; cin >> H >> W >> K;
    vector<string> S(H);
    for (int i = 0; i < H; i++) cin >> S[i];

    vector<vector<int>> choco(H, vector<int>(W)); 

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '1') choco[i][j] = 1;
        }
    }

    int ans = INF;

    for (int bit = 0; bit < 1<<(H-1); bit++) {

        vector<vector<int>> sum(H, vector<int>(W, 0));

        int tmp = 0;

        for (int i = 0; i < H-1; i++) {
            if (bit & (1<<i)) tmp++;
        }

        sum[0][0] = choco[0][0];
        bool flag = false;
        for (int i = 1; i < H; i++) {
            if (bit & (1<<(i-1))) {
                sum[i][0] = 0;
                if (choco[i][0] == 1) sum[i][0]++;
            }
            else {
                sum[i][0] = sum[i-1][0];
                if (choco[i][0] == 1) sum[i][0]++;
            }

            if (sum[i][0] > K) flag = true;
        }

        if (flag) continue;

        for (int j = 1; j < W; j++) {
            bool ok = true;

            sum[0][j] = sum[0][j-1];
            if (choco[0][j] == 1) sum[0][j]++;
            if (sum[0][j] > K) ok = false;

            for (int i = 1; i < H; i++) {
                if (bit & (1<<(i-1))) {
                    sum[i][j] = sum[i][j-1];
                    if (choco[i][j] == 1) sum[i][j]++;
                }
                else {
                    sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
                    if (choco[i][j] == 1) sum[i][j]++;
                }

                if (sum[i][j] > K) {
                    ok = false;
                    break;
                }
            }

            if (!ok) {
                tmp++;
                sum[0][j] = choco[0][j];
                for (int i = 1; i < H; i++) {
                    if (bit & (1<<(i-1))) {
                        sum[i][j] = 0;
                        if (choco[i][j] == 1) sum[i][j]++;
                    }
                    else {
                        sum[i][j] = sum[i-1][j];
                        if (choco[i][j] == 1) sum[i][j]++;
                    }

                    if (sum[i][j] > K) flag = true;
                }
            }

            if (flag) break;
        }

        if (flag) continue;

        ans = min(ans, tmp);
    }

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;


struct sushi{
  lll t;
  lll d;
};

bool comp(const sushi &a,const sushi &b){
  return a.d > b.d;
}

int main(){
  lll ii,jj,kk;
  lll n,k,tmax,tmin,tnum,snum;
  lll sum,max,bounus;
  max = 0;
  bounus = 0;
  vector<sushi> t;
  
  cin >> n >> k;

  tmax = 0;
  tmin = 1000000;
  t.resize(n);

  for(ii=0;ii<n;ii++){
    cin >> t[ii].t >> t[ii].d;
    if(t[ii].t >= tmax){
      tmax = t[ii].t;
    }
    if(t[ii].t <= tmin){
      tmin = t[ii].t;
    }
  }

  tnum = tmax - tmin + 1;

  if(k <= tnum){
    snum = k;
  }
  else{
    snum = tnum;
  }


  sort(t.begin(),t.end(),comp);

  //for(ii=0;ii<n;ii++){
  //cout << "ii:" << ii << " " << t[ii].t << " " << t[ii].d  << endl;
  //}
  sum = 0;

  set<lll> s;
  lll pos;

  map<lll,lll> m;
  sum =0;
  lll kind = 0;
  for(ii=tmin;ii<=tmax;ii++){
    m[ii] = 0;
  }
  
  for(ii=0;ii<k;ii++){
    sum += t[ii].d;
    
    m[t[ii].t] += 1;
    
    if(m[t[ii].t] == 1){
      kind += 1;
    }
  }

  bounus = pow(kind,2);
  lll curpos = k-1;
  //cout << "curpos" << curpos << endl;
  if(sum + bounus >= max){
    max = sum + bounus;
  }
  
  //cout << "max:" << max << endl;
  
  for(ii=k;ii<n;ii++){

    if(m[t[ii].t] >= 1){
      continue;
    }
    
    for(jj=curpos;jj>=0;jj--){
      if(m[t[jj].t] == 1){
	curpos = jj-1;
	continue;
      }
      else{
	//cout << "jj:" << jj << endl;
	sum -= t[jj].d;
	sum += t[ii].d;
	m[t[jj].t] -= 1;
	m[t[ii].t] += 1;
	kind += 1;
	curpos = jj-1;
	break;
      }
    }

    bounus = pow(kind,2);
    if(sum + bounus >= max){
      max = sum + bounus;
    }
    //cout << "max:" << max << endl;
  }
  
  if(sum > max){
    max =sum;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;
ll A[100005];
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,K;
	cin >> N >> K;
	rep(i,N){
		int a,b;
		cin >> a >> b;
		A[a]+=b;
	}
	ll cnt = 0;
	for(int i=0;i<=1e5;i++){
		cnt+=A[i];
		if(cnt>=K){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
import java.util.Scanner;

/*
問題文
英小文字からなる文字列 S があります。
S の長さが K 以下であれば、S をそのまま出力してください。

S の長さが K を上回っているならば、先頭 K 文字だけを切り出し、末尾に ... を付加して出力してください。

制約
K は 1 以上 100 以下の整数
S は英小文字からなる文字列
S の長さは 1 以上 100 以下

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();

        if (s.length() <= k) {
            System.out.println(s);
        } else {
            System.out.println(s.substring(0, k) + "...");
        }
    }
}

Measured memory_bytes: 38640
#include<iostream>
#include<string>

using namespace std;

int main (void) {
    string s;
    long long k;
    cin >> s >> k;
    for (auto& e : s) {
        if (e == 'a') continue;
        if (k > 'z' - e) {
            k -= ('z' - e + 1);
            e = 'a';
        }
    }
    auto lastIt = (s.end()-1);
    *lastIt = ((long long)*lastIt + k - 'a') % ('z' - 'a' + 1) + 'a';
    cout << s << endl;
}


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

int main(){
	int N;
	cin >> N;
	map<int, int> mp;
	for (int i = 0; i < N; i++){
		int a;
		cin >> a;
		mp[a]++;
	}

	int cnt = 0;
	for (auto it = mp.begin(); it != mp.end(); it++){
		cnt++;
	}

	if (cnt%2 == 0){
		cout << cnt - 1 << endl;
	} else {
		cout << cnt << endl;
	}

	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>
#include <bitset>
#include <queue>

using namespace std;
int K, N;
vector<int> A(2*10*10*10*10*10);
int tmp = 0;
int ans = 0;
int tmpMaxDist=0;
int edgeDist=0;

int main()
{
	cin >> K >> N;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		A[i] = tmp;
	}


	for (int i = 1; i < N; i++) {
		if (A[i]-A[i-1]>tmpMaxDist)
		{
			tmpMaxDist = A[i] - A[i - 1];
		}
	}

	edgeDist = (K - A[N-1]) + A[0];

	if (edgeDist> tmpMaxDist)
	{
		ans = K - edgeDist;
	}
	else
	{
		ans = K - tmpMaxDist;

	}

	cout << ans;


}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;

    ll cnt0 = 0, cnt1 = 0;
    ll cur0 = 0, cur1 = 1;
    for (int i = 0; i < s.size(); ++i) {
        if (cur0==0) {
            if (s[i]-'0'==0) {
                cnt0++;
                cur0 = 1;
                continue;
            }
            else {
                cur0=1;
                continue;
            }
        }
        else {
            if (s[i]-'0'==1) {
                cnt0++;
                cur0 = 0;
                continue;
            }
            else {
                cur0=0;
                continue;
            }
        }
    }

    for (int i = 0; i < s.size(); ++i) {
        if (cur1==0) {
            if (s[i]-'0'==0) {
                cnt1++;
                cur1 = 1;
                continue;
            }
            else {
                cur1=1;
                continue;
            }
        }
        else {
            if (s[i]-'0'==1) {
                cnt1++;
                cur1 = 0;
                continue;
            }
            else {
                cur1=0;
                continue;
            }
        }
    }

    cout << min(cnt0, cnt1) << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

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

  int H,W,A,B; cin >> H >> W >> A >> B;
  rep(h, H) {
    rep(w, W) {
      if((h < B && w < A) || (h >= B && w >= A)) {
        cout << 0;
      } else {
        cout << 1;
      }
    }
    cout << endl;
  }
}


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

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

  int n;
  cin >> n;
  vector<int> p(n);
  int max_p = 0;
  int idx = -1;
  for (size_t i = 0; i < n; ++i) {
    cin >> p[i];
    if (max_p < p[i]) {
      max_p =  p[i];
      idx = i;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (i == idx) {
      ans += p[i] / 2;
    } else {
      ans += p[i];
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Queue;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            if (n >= m) {
                out.println(0);
                return;
            }
            int[] a = in.nextIntArray(m);
            Arrays.sort(a);
            Queue<Integer> dq = new PriorityQueue<>();
            for (int i = 0; i < m - 1; i++) {
                dq.add(a[i + 1] - a[i]);
            }
            int sum = 0;
            for (int i = 0; i < m - n; i++)
                sum += dq.poll();
            out.println(sum);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

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

    }
}



Measured memory_bytes: 26328
from collections import Counter

N = int(input())
S = Counter([input() for _ in range(N)])
M = int(input())
T = Counter([input() for _ in range(M)])

ans = 0
for key, num in S.items():
  if key in T: ans = max(num-T[key],ans)
  else: ans = max(ans, num)
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
vector<string> S(N);
for (int i = 0; i < N; i++) {
    cin >> S[i];
}
int M=N;
sort(S.begin(), S.end());
for (int i = 0; i < N; i++) {
    if(S[i]==S[i+1]){
        M-=1;
    }
}
cout<<M<<endl;
}

Measured memory_bytes: 9604
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN, TT, AA;

  std::cin >> NN;
  std::cin >> TT >> AA;

  ll H[NN];
  for (size_t i = 0; i < NN; i++) {
    std::cin >> H[i];
  }

  float  rei6 = 0.006;
  float ans = 10000000.0;
  int ans_int = 0;

  for (size_t i = 0; i < NN; i++) {
    float temp = TT - rei6 * H[i] - AA;
    if (temp<0) {
      temp = -temp;
    }
    // std::cout << "temp: "<< temp<< '\n';
    if (ans > temp) {
      ans = temp;
      ans_int = i+1;
    }
  }

  std::cout << ans_int << '\n';

  return 0;
}


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

ans = 0
while max(h):
    current_hight = 0
    for i in range(len(h)):
        if not h[i]:
            if not current_hight:
                continue
            else:
                break
        elif h[i] < current_hight:
            break
        else:
            current_hight = h[i]
            h[i] -= 1
    ans += 1

print(ans)

Measured memory_bytes: 3188
#最長増加部分列問題 (LIS) 
import bisect

N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = int(input())

LIS = [seq[0]]
#print(LIS)
for i in range(len(seq)):
    if seq[i] > LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i])] = seq[i]
    #print(LIS)
#print(LIS)
print(len(LIS))


Measured memory_bytes: 10464
#include<cstdio>

int main () {
    int n, ans;
    scanf("%d", &n);
    if (n < 600) {
        ans = 8;
    } else if (n < 800) {
        ans = 7;
    } else if (n < 1000) {
        ans = 6;
    } else if (n < 1200) {
        ans = 5;
    } else if (n < 1400) {
        ans = 4;
    } else if (n < 1600) {
        ans = 3;
    } else if (n < 1800) {
        ans = 2;
    } else {
        ans = 1;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3228
#include <iostream>
#include <queue>

std::priority_queue<std::pair<int,int>,
        std::vector<std::pair<int,int>>,
                std::greater<>> pq;

int main(){
    int n;
    std::cin >> n;
    while(n--){
        int x,l;
        std::cin >> x >> l;
        pq.emplace(x + l, x - l + 1);
    }
    int last = -2100000000, count = 0;
    while(!pq.empty()){
        std::pair<int,int> front = pq.top();
        pq.pop();
#define right front.first
#define left front.second
        if(left <= last) continue;
        ++count;
        last = right;
    }
    std::cout << count;
}

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

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}

int main()
{
	int m=read(),n=read(),sum=0;
	for (int i=1;i<=n;i++) sum+=read();
	puts(sum>=m?"Yes":"No");

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
pList = list(map(int, input().split()))
#範囲内の和を求めるには累積和とういうのを使う
#事前準備
cum_sum_list = [0]*(N+1)
cum_sum = 0
pListLen = len(pList)
for i in range(pListLen):
  cum_sum += pList[i]
  cum_sum_list[i+1] = cum_sum
#範囲内の和を比べていく
max_sumK = 0
max_start = 0
max_end = 0
for i in range(N-K+1):
  start = i
  end = (i+K)
  sumK = cum_sum_list[end] - cum_sum_list[start]
  if (sumK > max_sumK):
    max_sumK = sumK
    max_start = start
    max_end = end
#最大の期待値を計算して出力
answer = 0
for num in pList[max_start:max_end]:
  answer += sum(list(range(1, (num+1))))/num
print(answer)


Measured memory_bytes: 98744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/


const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// /* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
//get<K>(tuple型の変数)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k; cin >> n >> k;
    string s; cin >> s;

    vector<int> a;
    char mode = (s[0]=='L'? 'L':'R');
    if(s[n-1] == 'L') s += 'R';
    else s += 'L';

    int ans = 0;
    int pre = 0;
    for(int i=1; i<n+1; ++i){
        if(mode == 'L' && s[i] == 'R'){
            ans += (i-pre-1);
            mode = 'R';
            pre = i;
        }
        else if(mode == 'R' && s[i] == 'L'){
            ans += (i-pre-1);
            mode = 'L';
            pre = i;
        }
    }

    cout << min(ans+2*k, n-1) << '\n';
    
    return 0;
}

Measured memory_bytes: 512
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,q,x,y,z,N=0,ans[200010];
pair <bool,LL> has[600010];
map <LL,LL> mp,into;
vector <pair <pii,LL> > v;
vector <pii> ss[600010];
vector <LL> peo;
multiset <LL> st;

int main()
{
	memset(ans,-1,sizeof(ans));
	cin>>n>>q;
	rep(i,n)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		y--;
		x-=z;
		y-=z;
		x=max(x,0LL);
		y=max(y,0LL);
		v.pb({{x,y},z});
		mp[x]=0;
		mp[y]=0;
	}
	rep(i,q)
	{
		scanf("%lld",&x);
		peo.pb(x);
		mp[x]=0;
	}
	for(map <LL,LL>::iterator it=mp.begin();it!=mp.end();it++) into[it->fi]=N++;
	rep(i,n)
	{
		v[i].fi.fi=into[v[i].fi.fi];
		v[i].fi.se=into[v[i].fi.se];
		ss[v[i].fi.fi].pb({v[i].se,1});
		ss[v[i].fi.se+1].pb({v[i].se,-1});
	}
	rep(i,q) has[into[peo[i]]]={true,i};
	rep(i,N+1)
	{
		rep(j,ss[i].size())
		{
			if(ss[i][j].se==1) st.insert(ss[i][j].fi);
			else st.erase(st.find(ss[i][j].fi));
		}
		if(has[i].fi&& !st.empty()) ans[has[i].se]=*st.begin();
	}
	rep(i,q) cout<<ans[i]<<endl;
	rt0;
}

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

int main() {
	int n, m, a[50], b[50], c[50], d[50], i, j, min[50], k[50];

	scanf("%d %d", &n, &m);
	for (i = 0;i < n;i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	for (i = 0;i < m;i++) {
		scanf("%d %d", &c[i], &d[i]);
	}
	for (i = 0;i < n;i++) {
		min[i] = 1000000000;
	}

	for (j = 0;j < n;j++) {
		for (i = 0;i < m;i++) {
			if (min[j] > abs(a[j] - c[i]) + abs(b[j] - d[i])) {
				min[j] = abs(a[j] - c[i]) + abs(b[j] - d[i]);
				k[j] = i;
			}
		}
	}

	for (i = 0;i < n;i++) {
		printf("%d\n", k[i] + 1);
	}

	return 0;

}

Measured memory_bytes: 128
@D=map[glob<>],@@=0..$'-<>=~$";map{for$x(split){$k=$j++%3;$$k[$_]+=$D[$x-1][$_]for@@}$j=++$i}<>;for$i(@@){for$j(@@){$-=$-=$i-$j&&$i-$_&&$j-$_&&$-$0[$i]-$1[$j]-$2[$_]for@@}}print$

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
double dp[3001][3001],val[3001],ans;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&val[i]);
	}
	dp[0][0]=1;
	dp[1][1]=val[1];
	dp[1][0]=1.0-val[1];
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(j==0)
			{
				dp[i][0]=dp[i-1][0]*(1.0-val[i]);
				continue;
			}
			dp[i][j]=dp[i-1][j]*(1.0-val[i])+dp[i-1][j-1]*(val[i])	;
		}
	}
	for(int i=n/2+1;i<=n;i++)
	{
		ans+=dp[n][i];
	}
	printf("%.10lf",ans);
	return 0;
} 


Measured memory_bytes: 68992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

int dp[45][405][405];

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

  int n, ma, mb;
  cin >> n >> ma >> mb;

  rep(i, n) rep(j, 405) rep(k, 405) {
    dp[i][j][k] = INF;
  }
  dp[0][0][0] = 0;
  rep(i, n) {
    int a, b, c;
    cin>>a>>b>>c;
    rep(j, 405) rep(k, 405) {
      if (j >= a && k >= b) {
        dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a][k-b] + c);
      } else {
        dp[i+1][j][k] = dp[i][j][k];
      }
    }
  }
  int res = INF;
  rep(j, 405) rep(k, 405) {
    if(j != 0 && k != 0 && j*mb == k*ma) {
      res = min(res, dp[n][j][k]);
    }
  }
  cout << (res==INF?-1:res) << endl;
}

Measured memory_bytes: 26880
def kyu(rating: int):
    if X <= 599:
        return 8
    if X <= 799:
        return 7
    if X <= 999:
        return 6
    if X <= 1199:
        return 5
    if X <= 1399:
        return 4
    if X <= 1599:
        return 3
    if X <= 1799:
        return 2
    if X <= 1999:
        return 1


X = int(input())

print(kyu(X))


Measured memory_bytes: 9168
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    ll h, w, m;
    cin >> h >> w >> m;
    vector<int> a(h, 0), b(w, 0);
    map<P, int> mp;
    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        a[x]++;
        b[y]++;
        mp[{x, y}]++;
    }
    int max_a = *max_element(all(a)), max_b = *max_element(all(b));
    int ans = max_a + max_b;
    vector<int> v1, v2;
    rep(i, h)if(max_a == a[i])v1.push_back(i);
    rep(i, w)if(max_b == b[i])v2.push_back(i);
    rep(i, v1.size()){
        rep(j, v2.size()){
            if(mp[{v1[i], v2[j]}] == 0){
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans - 1 << endl;
}   


Measured memory_bytes: 28464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#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;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
	cin >> n;
	std::vector<int> h(n);
	rep(i,n) cin >> h[i];

	int ct=0;
	int max = 0;
	rep(i,n-1){
		if(h[i] >= h[i+1]) {
			ct++;
			continue;
		}else{
			chmax(max, ct);
			ct=0;
		}
	}
  chmax(max,ct);
	cout << max << endl;


  return 0;
}


Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}
signed main(){
	ll N;
	cin>>N;
	vll A, D;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		if(A.size())
			D.pb(a-A.back());
		A.pb(a);
	}

	ll C[SIZE]={1, 1};
	for(int i=2;i<N;i++){
		C[i]=C[i-1]+mod_pow(i, MOD-2, MOD);
		C[i]%=MOD;
	}

	ll ans=0;
	for(int i=0;i<N-1;i++){
		ans+=D[i]*C[i+1];
		ans%=MOD;
	}

	for(int i=1;i<=N-1;i++){
		ans*=i;
		ans%=MOD;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2796
import java.io.IOException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        int r = 0;
        int l = 1;
        int i = 0;
        try {
            while (i != '\n') {
                while (i != 'L' && i != '\n'){ i = System.in.read(); if(i=='\n' || i == 'L'){break;} r++;}
                while (i != 'R' && i != '\n'){ i = System.in.read(); if(i=='\n' || i == 'R'){break;} l++;}
                for(int p=0;p<r-1;p++){
                    System.out.print("0 ");
                }
                int r2 = (r-1)/2;
                int l2 = (l-1)/2;
                System.out.print(r2 + (l-1-l2) + 1 + " ");
                System.out.print((r-1-r2)+l2 + 1 + " ");
                for(int p=0;p<l-1;p++){
                    System.out.print("0 ");
                }
                r=1;
                l=1;
            }
        }catch(Exception e){
            return;
        }
        System.out.println();
        return;
    }
}


Measured memory_bytes: 41512