akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
using namespace std;
int table[400 + 2][400 + 2] = {};
int main()
{
	int N;
	while (cin >> N && N != 0)
	{
		map<int,pair<int, int> > tableMap;
		int w = 1;
		int h = 1;
		int n = 0,d;
		int min_x = 200;
		int max_x = 200;

		int min_y = 200;
		int max_y = 200;
		table[200][200] = 0;
		tableMap[0]=  make_pair(200, 200);
		for (int i = 1; i < N;i++)
		{
			cin >> n >> d;
			int x = tableMap[n].second;
			int y = tableMap[n].first;
			int nx = x;
			int ny = y;

			if (d == 0)
			{
				nx = x - 1;
				if (nx < min_x)
				{
					min_x = nx;
					w++;
				}
			}
			else if (d == 1)
			{
				ny = y + 1;
				if (ny > max_y)
				{
					max_y = ny;
					h++;
				}
			}
			else if (d == 2)
			{
				nx = x + 1;
				if (nx > max_x)
				{
					max_x = nx;
					w++;
				}
			}
			else if (d == 3)
			{
				ny = y - 1;
				if (ny < min_y)
				{
					min_y = ny;
					h++;
				}
			}
			tableMap[i] = make_pair(ny, nx);
		}

		cout << w <<" "<<  h << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
<?php

$s = rtrim(fgets(STDIN));
echo toUpper($s) . PHP_EOL;

function toUpper($str) {
    $diff = ord('a') - ord('A');
    $n = strlen($str);
    for ($i = 0; $i < $n; $i++) {
        if ($str[$i] < 'a' || $str[$i] > 'z') {
            continue;
        }
        $str[$i] = chr(ord($str[$i]) - $diff);
    }

    return $str;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int s, w;
    cin >> s >> w;
    if(w>=s) cout << "unsafe" << '\n';
    else cout << "safe" << '\n';

    return 0;
}


Measured memory_bytes: 3608
N=int(input())
digit=len(str(N))
first=int(str(N)[0])
last=N%10
mid=(N-first*10**(digit-1)-last)//10
table=[[0 for i in range(0,10)]for j in range(0,10)]

if digit==1:
    print(N)
else:
    for i in range(1,10):
        for j in range(1,10):
            if i!=j:
                table[i][j]=(10**(digit-1)-10)//90
            else:
                table[i][j]=(10**(digit-1)-10)//90+1
    for i in range(1,10):
        for j in range(1,10):
            if i<first:
                table[i][j]+=10**(digit-2)
            elif i==first:
                if last>=j:
                    table[i][j]+=mid+1
                else:
                    table[i][j]+=mid
            else:
                table[i][j]+=0

    sum=0
    for i in range(0,10):
        for j in range(0,10):
            if i!=j:
                sum+=table[i][j]*table[j][i]

    subsum=0
    for i in range(0,10):
        subsum+=table[i][i]*(table[i][i]-1)+table[i][i]
    print(sum+subsum)

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

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool same(int x, int y) { return root(x) == root(y); }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }

    int size(int x) { return -par[root(x)]; }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.merge(a, b);
    }

    int ans = 0;
    rep(i, n) ans = max(ans, uf.size(i));

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


Measured memory_bytes: 3952
open System

[<EntryPoint>]
let main argv =
  let a = Console.ReadLine() |> int in
  let b = Console.ReadLine() |> int in
  let c = Console.ReadLine() |> int in
  let x = Console.ReadLine() |> int in
  
  seq {
    for i in [0..a] do
      for j in [0..b] do
        for k in [0..c] do
          yield i * 500 + j * 100 + k * 50
  }
  |> Seq.sumBy (fun y -> if y = x then 1 else 0)
  |> Console.WriteLine
  0


Measured memory_bytes: 15440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;
const int maxn = (int)1e5+7;

//浮点型运算
const db eps = 1e-6;
bool eq(const db &a, db const &b) { return fabs(a - b) < eps; }
bool ls(const db &a, db const &b) { return a + eps < b; }
bool le(const db &a, db const &b) { return eq(a, b) || ls(a, b); }

ll l[100];

void Init() {
}

int main ()
{
    int n;
    scanf("%d", &n);
    l[0] = 2;
    l[1] = 1;
    rep(i, 2, n + 1)
        l[i] = l[i-1] + l[i-2];
    printf("%lld\n", l[n]);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 201000;
vector<int> E[N],in[N];
namespace Graph{
	const int inf = 1e9;
	vector<pair<int,int> > ans;
	int n,tot,t,head[N],b[N],vis[N],cur[N];
	struct edge{int v,nxt,f;}e[N*4];
	void init(int m){
		n=m;t=2*n+1;tot=1;
		ans.resize(n);
	}
	void add(int x,int y,int z){
		e[++tot]={y,head[x],z};
		head[x]=tot;
		e[++tot]={x,head[y],0};
		head[y]=tot;
	}
	bool bfs(){
		memset(b,0,sizeof(b));b[0]=1;
		queue<int> q;q.push(0);
		while(!q.empty()){
			int u=q.front();q.pop();
			for(int i=head[u];i;i=e[i].nxt)
				if(e[i].f&&!b[e[i].v]){
					b[e[i].v]=b[u]+1;
					q.push(e[i].v);
				}
		}
		return b[t];
	}
	int dfs(int x,int flow){
		if(!flow||x==t) return flow;
		int f=flow,tmp;
		for(int &i=cur[x];i;i=e[i].nxt)
			if(b[e[i].v]==b[x]+1&&(tmp=dfs(e[i].v,min(e[i].f,f)))){
				f-=tmp;e[i].f-=tmp;e[i^1].f+=tmp;
				if(!f) break;
			}
		return flow-f;
	}
	int Dinic(){
		int ans=0;
		while(bfs()){
			memcpy(cur,head,sizeof(cur));
			ans+=dfs(0,inf);
		}
		return ans;
	}
	void solve(int x){
		vis[x]=1;
		for(int p:in[x])
			for(int i=head[p+n];i;i=e[i].nxt)
				if(e[i].f&&e[i].v!=t){
					if(vis[e[i].v]) continue;
					ans[p]=make_pair(x,e[i].v);
					solve(e[i].v);
				}
	}
	void print(){
		for(int i=1;i<n;i++) if(!ans[i].first){puts("-1");return;}
		for(int i=1;i<n;i++) printf("%d %d\n",ans[i].first,ans[i].second);
	}
}
int n;
int main(){
	read(n);
	Graph::init(n);
	for(int i=1;i<n;i++){
		int k;read(k);
		while(k--){
			int x;read(x);
			E[i].push_back(x);
			in[x].push_back(i);
		}
	}
	for(int i=2;i<=n;i++){
		for(int x:in[i]) Graph::add(i,x+n,1);
		Graph::add(0,i,1);
	}
	for(int i=1;i<n;i++) Graph::add(i+n,Graph::t,1);
	if(Graph::Dinic()<n-1){puts("-1");return 0;}
	Graph::solve(1);
	Graph::print();
	return 0;
}


Measured memory_bytes: 33476
/*
    By Prabal Aggarwal
*/
#include <bits/stdc++.h>
#define fastIo                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define ll long long
#define MOD 1000000007
const int N = 1000005;
ll dp[N][2][2];
int main()
{
    fastIo;

    ll n;
    cin >> n;

    vector<pair<ll,ll>>v(n);
    ll x,y;

    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        v[i] = {x,y};
    }

    ll mx = INT_MIN,mn = INT_MAX;
    ll mx2 = INT_MIN,mn2 = INT_MAX;

    for(ll i=0;i<n;i++)
    {
        mx = max(mx,v[i].first+v[i].second);
        mn = min(mn,v[i].first+v[i].second);
        mx2 = max(mx2,v[i].first-v[i].second);
        mn2 = min(mn2,v[i].first-v[i].second);
        
    }

    cout<<max(mx-mn,mx2-mn2);



    return 0;
}

Measured memory_bytes: 6356
Q = int(input())
querys = [[int(x) for x in input().split()] for _ in range(Q)]
def execute_query(lst,op):
    if len(op)==2 and op[0]==0:
        lst.append(op[1])
        return lst
    if len(op)==2 and op[0]==1:
        print(lst[op[1]])
        return lst
    else:
        return lst[:-1]
       
lst=[] 
for q in querys:
    lst=execute_query(lst,q)


Measured memory_bytes: 34068
R, G, B, N = map(int, input().split())
"""
3000以下なので全探索を考える。
まず，全探索できるものは全探索から考える必要がある。
オーダーを計算し，いけそうならそれで行くべき。今回は固定を順にしていくので間に合う
そこから探索する範囲を絞り込んで
"""

count = 0
for r in range(N//R+1):
    rest = N - r*R
    for g in range(rest//G+1):
        n_b = (rest - g*G)
        if n_b % B == 0 and n_b >= 0:
            count += 1
print(count)

Measured memory_bytes: 9216
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	}
}

Measured memory_bytes: 49084
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		// 計算
		String result = "NO";
		if(a*b*c == 5*5*7) result = "YES";
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25188
use proconio::input;
use std::cmp::{max, min};

const MAX_L: usize = 100_000;
const BASE_SIZE: usize = 1 << 10;

fn main() {
    input! {
        n: usize,
        vw: [(usize, usize); n],
        q: usize,
        vl: [(usize, usize); q],
    }
    let dp = make_base(&vw);
    for vlq in vl {
        println!("{}", calc(&vw, vlq.0 - 1, vlq.1, &dp));
    }
}

fn make_base(vw: &Vec<(usize, usize)>) -> Vec<Vec<usize>> {
    let mut dp = Vec::<Vec<usize>>::new();

    dp.push(
        (0..=MAX_L)
        .map(|i| if i < vw[0].1 { 0 } else { vw[0].0 })
        .collect()
    );

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L)
            .map(|i| {
                let w = vw[c].1;
                let v = if i < w { 0 } else { dp[p][i - w] + vw[c].0 };
                max(dp[p][i], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    vw: &Vec<(usize, usize)>,
    u: usize, 
    l: usize,
    dp: &Vec<Vec<usize>>
) -> usize {
    if u < dp.len() {
        dp[u][l]
    } else {
        let p  = (u - 1) / 2;
        let w = vw[u].1;
        let pv1 = calc(vw, p, l, dp);
        let pv2 = if l < w { 0 } else { calc(vw, p, l - w, dp) + vw[u].0 };
        max(pv1, pv2)
    }
}


Measured memory_bytes: 814836
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int month, day;
    cin >> month >> day;
    int ans = 0;
    for(int i=1;i<=month;i++){
        for(int j=1;j<=day;j++){
            if(((j%10)*(j/10)==i)&&(j%10>1)&&(j/10>1)){
                ans ++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
def insertionSort(A,N):
    for i in range(1,N):
        v = A[i]
        j=i-1
        while(j>=0 and A[j] > v):
            A[j+1] = A[j]
            j-=1
        A[j+1]=v
        print(*A)

if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    print(*A)
    insertionSort(A,N)

Measured memory_bytes: 5980
#include <cstdio>

using namespace std;
typedef long long llong;

#define MAX
const llong mod = 1000000000 + 7;

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

  printf("%d", N % 2 == 0 ? N / 2 : N / 2 + 1);

  return 0;
}

Measured memory_bytes: 1708
from collections import Counter

S = input()
K = int(input())

chars = sorted(list(Counter(S).keys()))

## 辞書列で一番若い文字を見つけ、そこから多くてK文字の文字列をリストに入れる
idx_pre_char = 0
solver = []
while len(solver) < K:
  for i in range(len(S)):
    if S[i] == chars[idx_pre_char]:
      if i <= len(S) - K:
        for j in range(K):
          solver.append(S[i:i+j+1])
      else:
        for j in range(len(S)-i):
          solver.append(S[i:i+j+1])
  solver = list(set(solver))
  idx_pre_char += 1


solver.sort()
print(solver[K-1])



Measured memory_bytes: 4596
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 27 16:15:21 2019

@author: yuta
"""

def coin(a,b,c,x):
    count = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                d = 500 * i + 100 * j + 50 * k
                if d == x:
                    count += 1
    print(count)

a = int(input())
b = int(input())
c = int(input())
x = int(input())

coin(a,b,c,x)                

Measured memory_bytes: 3064
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#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>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<vector<ll>> mat(H+2, vector<ll>(W+2, 0));
    rep(i, H) {
        string s;
        cin >> s;
        rep(j, W) {
            if (s[j] == '#') {
                for(int k = -1; k <= 1; k++) {
                    for(int l = -1; l <= 1; l++) {
                        if(k == 0 & l == 0) mat[i+1][j+1] = -100;
                        else mat[i+1+k][j+1+l] += 1;
                    }
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            if (mat[i+1][j+1] < 0) {
                cout << '#' ;
            } else {
                cout << mat[i+1][j+1];
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main()
{
  int x;cin>>x;
  for(int k=1;k<=360;++k)
  {
    if((k*x)%360==0)
    {
      cout<<k<<endl;
      break;
    }
  }
  return 0;
}
  

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,d,p,q,co=0;
    cin>>n>>d;
    for(int i=1; i<=n; i++)
    {
        cin>>p>>q;

       
        if(p*p+q*q<=d*d)
           {
             co++;

           }
    }
    cout<<co<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;



void solve()
{
    int n,x,sm=0,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        ans+=sm*x;
        ans%=mod;
        sm+=x;
        if(sm>=mod)
            sm%=mod;
    }
    cout<<ans;
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t;
 t=1;
 for(int i=1;i<=t;i++)
 {
   solve();
 }


}

Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#include<algorithm>
#include<memory.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N = 500 + 5, M = 1e9 + 7;
int n, c;
int a[N], b[N],p[N][N];
ll pp(int n, int p) {
	if (!p)return 1;
	ll ret = pp(n, p / 2) % M;
	if (p & 1)return ((ret*ret)%M*n)%M;
	return (ret*ret) % M;
}
ll dp[N][N];
int calc(int idx, int rem) {
	if (idx == n && !rem)return 1;
	if (idx == n)return 0;
	ll &ret = dp[idx][rem];
	if (ret != -1)return ret;
	ret = 0;
	for (int i = 0;i <= rem;i++) {
		ll sm = (p[b[idx]][i] - p[a[idx] - 1][i] + M)%M;
		ret = (ret + sm*calc(idx + 1, rem - i)%M)%M;
	}
	return ret;
}
int main() {
		//freopen("in.txt", "r", stdin);
		scanf("%d%d", &n, &c);
		for (int i = 0;i < n;i++)scanf("%d", &a[i]);
		for (int i = 0;i < n;i++)scanf("%d", &b[i]);
		for (int i = 0;i <= c;i++)
			for (int j = 1;j <= 400;j++)
				p[j][i] = (p[j - 1][i] + pp(j, i))%M;
		memset(dp, -1, sizeof dp);
		cout << calc(0, c);
	
}


Measured memory_bytes: 3072
/*input
1000000000000000000
7450580596923828125
1490116119384765625
298023223876953125
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll unsigned long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,q=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;
		
		cin>>n;
		

		ll ten[19];
		ll fifty[19];
		ten[0]=1;
		fifty[0]=1;
		ll five[30];
		five[0] = 1;
		for (int i = 1; i < 28; ++i)
		{
			five[i] = five[i-1]*5;
			count += (n/five[i])-((n/five[i])%2);
			// watch(five[i]);
		}
		// for (int i = 1; i < 19; ++i)
		// {
		// 	ten[i] = ten[i-1]*10;
		// 	fifty[i] = fifty[i-1]*50;
		// 	watch(fifty[i]);
		// }

		if(n%2!=0)
		{
			cout << 0 << endl;
			continue;
		}
		// for (int i = 1; i > 0; --i)
		// {
		// 	count+= n/ten[i];
			
		// }
		// for (int i = 10; i >0; --i)
		// {
		// 	count	+= n/fifty[i];
		// }
		cout << count/2 << endl;
		
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(" ");
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        string[] p = Console.ReadLine().Split(" ");
        int[] P = new int[N];
        for(var i=0;i<N; i++)
        {
            P[i] = int.Parse(p[i]);
        }

        Array.Sort(P);

        int sum = 0;
        for(var i = 0; i<K;i++)
        {
            sum += P[i];
        }

        Console.WriteLine(sum);
    }
}




Measured memory_bytes: 27744
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i,N)
  {
    cin >> H[i];
  }
  bool ans = true;
  for(int i=N-1;i>0;i--)
  {
    if(H[i]<H[i-1])
    {
      H[i-1] -= 1;
      if(H[i]<H[i-1])
      {
        ans = false;
      }
    }
  }
  if(ans == true)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  return 0;
}


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

const int nm = 1e5;
int n, x[nm];
long long a, b, rv = 0;

int main() {
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n - 1; i++)
		rv += min((x[i + 1] - x[i]) * a, b);
	cout << rv << endl;
}


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

#define M_PI 3.14159265358979323846

using namespace std;

//typedef
//-------------------------#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}
inline int readInt()
{
    int x;
    scanf("%d", &x);
    return x;
}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const int INF = 2147483647;

ll N;
int cnt = 0;
set<ll> st;
void dfs(ll s)
{
    if (s > N)
        return;

    st.insert(s);
    dfs(s * 10 + 5);
    dfs(s * 10 + 7);
    dfs(s * 10 + 3);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    cin >> N;

    dfs(7);
    dfs(5);
    dfs(3);

    for (auto e : st)
    {
        int is7 = false, is5 = false, is3 = false;

        ll t = e;
        while (t)
        {
            if (t % 10 == 7)
                is7 = true;
            if (t % 10 == 5)
            {
                is5 = true;
            }
            if (t % 10 == 3)
            {
                is3 = true;
            }
            t /= 10;
        }

        if (is7 && is5 && is3)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
#include <assert.h>
using namespace std;

const unsigned long long MOD = (unsigned long long)(1e9 + 7);
const unsigned long long BASE = (unsigned long long)(998244353);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

int main()
{
    int n;
    cin >> n;
    unsigned long long ret = 0;
    FROM_S(a, 1, n)
    {
        int b = int((n - 1) / a);
        ret += (unsigned long long)b;
    }
    cout << ret << endl;
    return 0;
}

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

int main()
{
	unsigned int a, b, n,ret,total,tmp;
	cin >> n >> a >> b;
	ret = 0;
	for (int i = 1; i <= n; i++) {
		total = 0;
		tmp = i;
		while (tmp > 0) {
			total += tmp % 10;
			tmp = (tmp - tmp % 10) / 10;
		}
		if (total >= a && total <= b) {
			ret+=i;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
# easy!
n,t = map(int,input().split())
l = [ list(map(int,input().split(" "))) for i in range(n)]

l = sorted(l) # 2次リストのindex'0'でソートされる

for j in range(n):
    if l[j][1] <= t:
        print(l[j][0])
        break
else:
    print('TLE')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a ;
  int a_c = 0 ;
  int s ;
  cin >> a ;
  a_c = a ;
  if (( a % 10 ) != 0) { s = s + 1
;} ;//1の位
   if (( a % 10 ) != 0) { a_c = a - 1
;} ;
   if (( a_c % 100 ) != 0) { s = s + 1
;} ;
  if (a >= 100) { s = s + 1
;} ;    
	cout << s << endl ;            
}

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

typedef long long ll;
ll n, s, a, d[6005]={1}, M=998244353;
int main() {
	cin >> n >> s;
	while(n--) {
		cin >> a;
		for(ll i=s; i>=0; i--) {
			(d[i+a] += d[i]) %= M;
			(d[i] *= 2) %= M;
		}
	}
	cout << d[s];
	return 0;
}

Measured memory_bytes: 3668
//
//  main.cpp
//  B
//
//  Created by 曾憲揚 on 2020/8/21.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

#include <iostream>
using namespace std;
int table[20], pre[20], prenonzer[20];

long long cal(int n){
    int cycs = (n+14)/15-1, mod = (n+14)%15 + 1;
    return pre[15]*cycs+ 1LL*(cycs-1)*cycs/2 * 15 * prenonzer[15]+
           pre[mod] + 1LL*15*cycs*(prenonzer[mod]);
}

int main(int argc, const char * argv[]) {
    for(int i=1; i<=15; i++){
        table[i] = (i%3==0 || i%5==0)? 0: i;
        prenonzer[i] = prenonzer[i-1] + bool(table[i]);
        pre[i] = pre[i-1] + table[i];
    }
    
    int n; cin>>n;
    cout<< cal(n) << '\n';
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int p[maxn];
int getf(int v)
{
  return p[v] == v ? v : p[v] = getf(p[v]);
}
int main()
{
  int n , m ;
  scanf("%d%d",&n,&m);
  for(int i = 1 ; i <= n ; i++) p[i] = i; 
  for(int i = 0 ; i < m ; i++)
  {
    int u , v , w;scanf("%d%d%d",&u,&v,&w);
    int dx = getf(u);
    int dy = getf(v);
    if(p[dx] != p[dy])
    {
      p[dx] = dy;
    }
  }
  int ans = 0;
  for(int i = 1 ; i <= n ; i++)
  {
    if(p[i] == i) ans ++;
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int a, b;
    cin >> a >> b;
    ppp((a+b-3)/(a-1));
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    vector<i64> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    using P = pair<i64, i64>;
    vector<P> seq;

    auto printSeq = [&]() {
        REP(i, N - 1) {
            cout << seq[i].first << " " << seq[i].second << endl;
        }
    };

    for (i64 i = 1; i <= N - 2; i++) {
        if (A[i] >= 0) {
            seq.emplace_back(A[0], A[i]);
            A[0] -= A[i];
        } else {
            seq.emplace_back(A[N - 1], A[i]);
            A[N - 1] -= A[i];
        }
    }

    seq.emplace_back(A[N - 1], A[0]);
    A[N - 1] -= A[0];
    assert(seq.size() == N - 1);
    cout << A[N - 1] << endl;
    printSeq();

    return 0;
}


Measured memory_bytes: 6132
#6
#入力
N=int(input())

#処理
import math as m
t=0
for i in range(m.ceil(N/4),m.floor(N*3/4)+1):
    #print(i)
    if 4*i==N:
        continue
    for j in range(m.ceil(N*i/(4*i-N)),m.floor(2*N*i/(4*i-N))+1):
        #print(j)
        if 4*i*j-N*i-N*j==0:
            continue
        k=int((N*i*j)/(4*i*j-N*i-N*j))
        #print(k)
        if 4*i*j*k==N*(i*j+i*k+j*k):
            h=i
            n=j
            t=1
            break
    if t==1:
        break

print(h,n,k)

Measured memory_bytes: 3064
use std::collections::BinaryHeap;

fn main(){
  let nrl: Vec<usize> = read_vec();
  let n = nrl[0];
  let r = nrl[1];
  let l = nrl[2];

  let mut ptm: usize = 0;
  let mut pid: usize = 1;
  let mut cpt: Vec<isize> = vec![0;n+1];
  let mut ttm: Vec<usize> = vec![0;n+1];

  let mut hp: BinaryHeap<(isize, isize)> = BinaryHeap::new();

  for i in 1 .. n+1 {
    hp.push((0, -1 * (i as isize)));
  }

  for _ in 0 .. r {
    let dtx: Vec<isize> = read_vec();
    let d = dtx[0] as usize;
    let t = dtx[1] as usize;
    let x = dtx[2];

    ttm[pid] += t - ptm;

    cpt[d] += x;
    hp.push((cpt[d], -1 * (d as isize)));

    let mut mp = *hp.peek().unwrap();

    loop {
      if cpt[(mp.1 * -1) as usize] == mp.0 { break; }
      hp.pop();
      mp = *hp.peek().unwrap();
    }
    
    ptm = t;
    pid = (mp.1 * -1) as usize;
  }

  ttm[pid] += l - ptm;

  let mut mid: usize = 1;
  let mut mt: usize = ttm[1];

  for i in 2 .. n+1 {
    if mt < ttm[i] {
      mt = ttm[i];
      mid = i;
    }
  }

  println!("{}", mid);
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 23788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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字くらい使った方がいいかも
*/

int main(void){
    int N; cin >> N;
    int a;
    vector<ll> accum(N+1, 0);

    for(int i=1; i<=N; i++){
        cin >> a;
        accum[i] = accum[i-1]+a;
    }

    ll ans = (1LL<<60);
    for(int i=1; i<=N-1; i++){
        ll tmp = abs(2*accum[i]-accum[N]);
        ans = min(ans, tmp);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(int, N, K);
    vector<int> a(N);
    read(a);

    // const int p = find(all(a), 1) - begin(a);

    int l = 0;
    int r = K;
    int ans = 1;
    while (r < N) {
        ++ans;
        l += K - 1;
        r += K - 1;
        dump(l, r);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 640
#include <stdlib.h>
#include <string.h>
#include<math.h>
#include <stdio.h>
void shift(char* p, long m, int n)
{
	int r;
	while (m > 0)
	{
		r = m % n;			//求余
		if (r < 10)
		{
			*p = r + 48;    //小余10的数转换成字符后赋给P所指向的元素
		}
		else
		{
			*p = r + 55;	//10-15转化为“A~F”后赋给P所指向的元素
		}
		m = m / n;
		p++; 				//指针后移

	}
	*p = '/0';
}
int main(void)
{
	int x;
	long y;
	char a[32] = {'\0'};		//存放结果的数组

		scanf("%ld %d", &y,&x);

		printf("\n");
		
		shift(a, y, x);
		printf("%d", strlen(a)-1);
	


	
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
    public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
         if(a < b){
             System.out.println("a < b");
           }else if(b < a){
            System.out.println("a > b");
            }else if(b == a){
             System.out.println("a == b");
            }
    }
}

Measured memory_bytes: 26064
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn u64() -> u64 {
    read()
}

fn vec_u64(n: usize) -> Vec<u64> {
    let mut vec = Vec::new();
    for _ in 0..n {
        vec.push(u64())
    }
    vec
}

fn main() {
    let mut abc = vec_u64(3);
    abc.sort();

    if abc[2] % 2 == 0 {
        println!("0");
    } else {
        println!("{}", abc[0] * abc[1]);
    }
}


Measured memory_bytes: 2108
#include <stdio.h>
main(){
  int a[4],b[4],i,c[4];
  while(scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) !=EOF){
    int h=0,v=0;
  c[0]=11;
  c[1]=11;
  c[2]=11;
  c[3]=11;
    for(i=0;i<4;i++){
      if(a[i]==b[i]){
	h++;
	c[i]=a[i];
      }
    }
    for(i=0;i<4;i++){
      if((a[i]==b[0]||a[i]==b[1]||a[i]==b[2]||a[i]==b[3])&&a[i]!=c[i]) v++;
    }
    printf("%d %d\n",h,v);
  }

  return 0; 
}

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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << ' ' << x << ' ' << y << endl;
}


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

using namespace std;
#define ll long long
#define pb push_back

int main()
{
	int n, x, d;
	cin >> n >> d >> x;
	int arr[n];
	for(int i=0; i<n; i++) cin >> arr[i];
	int cnt=0;
	for(int i=1; i<=d; i++) {
		for(int j=0; j<n; j++) {
			if(i%arr[j]==1 || arr[j]==1) cnt++;
		}
	}
	cout << cnt + x << endl;
	return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here! sakuraihaaho
    int b = 0,c;
    string x;
    while(true){ 
        cin>>x;
        if(x.at(0) == '0')break;
        for(int i = 0;i<x.size();i++)
        b += x.at(i) -'0';
        cout<<b<<endl;
        b = 0;
    }
 //  cout<<endl;
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,w; cin>>n>>w;
  vvll vs(4);
  ll base=-1;
  rep(i,n){
    ll w,v; cin>>w>>v;
    ll d;
    if(base==-1) d=0, base=w;
    else d=w-base;
    
    vs[d].push_back(v);
  }
  vvll s(4);
  rep(i,4){
    sort(vs[i].rbegin(),vs[i].rend());
    ll len=vs[i].size();
    s[i].resize(len+1);
    rep(j,len) s[i][j+1]=s[i][j]+vs[i][j];
  }
  
  ll ans=0;
  rep(i,s[0].size()){
    rep(j,s[1].size()){
      rep(k,s[2].size()){
        ll sumv=s[0][i]+s[1][j]+s[2][k];
        ll sumw=base*i+(base+1)*j+(base+2)*k;
        
        if(sumw>w) continue;
        
        ll idx=(w-sumw)/(base+3);
        if(idx>=s[3].size()) idx=s[3].size()-1;
        sumv+=s[3][idx];
        chmax(ans,sumv);
      }
    }
  }
  cout<<ans<<endl;
}

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

ll ans=0,total=0;
int n;
vector<ll> a,b;
vector<P> t;

int main(){
  cin>>n;
  a.resize(n);
  b.resize(n);
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    total+=a[i];
  }
  
  if(a==b){
    cout<<0<<endl;
    return 0;
  }
  
  ll p=0;

  for(int i=0;i<n;i++){
    if(a[i]<=b[i]){
      b[i]-=a[i];
      a[i]=0;
      p+=b[i];
    }else{
      ll x=a[i]-b[i]+1;
      ll y=b[i];
      t.push_back( P(x,y) );
    }
  }

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

  ll mini=(1LL<<60);
  for(int i=0;i<(int)t.size();i++){
    if(t[i].first > p){
      total-=t[i].second;
      mini=0;
      continue;
    }
    mini=min(mini, t[i].second);
  }
  
  cout<<total-mini<<endl;
  
  return 0;
}


Measured memory_bytes: 896
A = [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]
N = int(input())

print(A[N-1])


Measured memory_bytes: 2940
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int student[150];
	for (int i = 0; i < n; i++) {
		cin >> student[i];
	}
	for (int i = 2; i <= m; i++) {
		for (int j = 0; j < n-1; j++) {
			if (student[j] % i > student[j + 1] % i) {
				swap(student[j], student[j + 1]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << student[i] << endl;
	}
}


Measured memory_bytes: 3112
#include<iostream>

using namespace std;

const int MAX = 260;

char data[MAX][MAX];
int num[4][MAX][MAX];
int in;

int solve(){
  for(int i = 1; i <= in; i++){
    for(int j = 1; j <= in; j++){
      if(data[i][j] == '1'){
	num[0][i][j] = num[0][i-1][j]+1;
	num[1][i][j] = num[1][i][j-1]+1;
	num[2][i][j] = num[2][i-1][j-1]+1;
	num[3][i][j] = num[3][i-1][j+1]+1;
      }
    }
  }
  int m = 0;
  for(int i = 0; i < 4; i++)
    for(int j = 1; j <= in; j++)
      for(int k = 1; k <= in; k++) m = max(m,num[i][j][k]);
  return m;
}

void init(){
  for(int i = 0; i < MAX; i++){
    fill(num[0][i],num[0][i]+MAX,0);
    fill(num[1][i],num[1][i]+MAX,0);
    fill(num[2][i],num[2][i]+MAX,0);
    fill(num[3][i],num[3][i]+MAX,0);
  }
}
int main(){

  while(cin >> in && in){
    init();
    for(int i = 1; i <= in; i++){
      for(int j = 1; j <= in; j++){
	cin >> data[i][j];
	num[0][i][j] = num[1][i][j] = num[2][i][j] = num[3][i][j] = 0;
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

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

using ll = long long;

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

    vector<ll> a(3 * N);
    for (int i = 0; i < 3 * N; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll sum = 0;
    for (int i = 0; i < N; i++) {
        sum += a[2 * i + 1];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest9
{
    class Program
    {
        public class Sub
        {
            static public int func(int num)
            {
                num += 1;// 0,1を無くすため
                int ret = 0;

                bool[] num_array = new bool[num];   //すべてfalse

                num_array[0] = true;
                num_array[1] = true;

                for (int act = 2; act < num; act++)
                {
                    if (num_array[act] == false)
                    {
                        int tmp = act * 2;
                        while (tmp < num)
                        {
                            num_array[tmp] = true;
                            tmp += act;
                        }
                    }
                }

                for (int i = 0; i < num; i++)
                {
                    if (num_array[i] == false)
                    {
                        ret++;
                    }
                }

                return ret;
            }
        }

        static void Main(string[] args)
        {
            while (true)
            {
                var line_origin = Console.ReadLine();

                if (string.IsNullOrEmpty(line_origin))
                {
                    break;
                }

                int num = int.Parse(line_origin);

                //素数の個数を探す　エラトステネスのふるい
                int ans = Sub.func(num);
                Console.WriteLine(ans.ToString());
            }
        }
    }
}

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

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int k = t.size();
	bool ok = false;
	int start = 0;
	rep(i, n - k + 1) {
		string tmp = s.substr(i, k);
		bool elf = true;
		rep(j, tmp.size()) {
			if (tmp[j] != '?') {
				if (tmp[j] != t[j]) elf = false;
			}
		}
		if (elf) {
			ok = true;
			start = i;
		}
	}
	if (!ok) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	else {
		for (int i = start; i < start + k; ++i) {
			s[i] = t[i - start];
		}
	}
	rep(i, n) {
		if (s[i] == '?') s[i] = 'a';
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#define INF 1000000000

using namespace std;

const int N = 200000;

int main() {
  int n, r[N];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &r[i]);

  int mi = r[0], ans = -INF;
  for (int i = 1; i < n; i++) {
    ans = max(ans, r[i] - mi);
    mi = min(mi, r[i]);
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 3380
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A[] = new int[3];
		for (int i=0;i<3;i++) {
			A[i]= sc.nextInt();
		}
		Arrays.parallelSort(A);
		System.out.println(A[0]+A[1]);
	}
}

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

int main(){
    int N = 5;
    vector<int> T(N);
    for(int i=0; i<N; i++) cin >> T[i];
    sort(T.begin(), T.end());
    int ans = 1e9;
    do{
        int tmp = 0;
        for(int i=0; i<N-1; i++){
            tmp += ceil(1.0*T[i]/10)*10;
        }
        tmp += T[N-1];
        ans = min(ans, tmp);
    }while(next_permutation(T.begin(), T.end()));

    cout << ans << endl;
}

Measured memory_bytes: 256