akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

import "strings"

func main() {
	for {
		var H, W int
		var line string
		fmt.Scan(&H, &W)
		if H == 0 {
			break
		}
		for i := 0; i < H; i++ {
			if i%2 != 0 {
				if W%2 != 0 {
					line = strings.Repeat(".#", W/2) + "."
				} else {
					line = strings.Repeat(".#", W/2)
				}
			} else {
				if W%2 != 0 {
					line = strings.Repeat("#.", W/2) + "#"
				} else {
					line = strings.Repeat("#.", W/2)
				}
			}
			fmt.Println(line)
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define f first
#define s second

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout);
	string a, b;
	cin >> a >> b;
	pair<int, pi> dp[a.size() + 1][b.size()+ 1];
	for(int i = 0; i <= a.size(); i++){
		for(int j = 0; j <= b.size(); j++){
			dp[i][j] = {-1, {0, 0}};
		}
	}
	dp[0][0] = {0, {0, 0}};
	for(int i = 0; i < a.size(); i++){
		for(int j = 0; j < b.size(); j++){
			if(a[i] == b[j]){
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], mp(dp[i][j].f + 1, mp(i, j)));
			}
			dp[i + 1][j] = max(dp[i + 1][j], mp(dp[i][j].f, mp(i, j)));
			dp[i][j + 1] = max(dp[i][j + 1], mp(dp[i][j].f, mp(i, j)));
		}
	}
	pair<int, pi> ans = mp(0, mp(0, 0));
	for(int i = 0; i <= a.size(); i++){
		for(int j = 0; j <= b.size(); j++){
			ans = max(ans, mp(dp[i][j].f, mp(i, j)));
		}
	}
	pi cur = ans.s;
	string answer = "";
	while(!(cur.f == 0 || cur.s == 0)){
		int i = cur.f;
		int j = cur.s;
		pi prev = dp[i][j].s;
		if(prev == mp(i - 1, j - 1)){
			answer += a[i - 1];
		}
		cur = prev;
	}
	reverse(all(answer));
	cout << answer << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 105856
/*
 * Code be weshen zyk :'(
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define F first
#define S second

using ll = long long;
using ii = pair<int, int>;
using db = long double;

#ifdef ONLINE_JUDGE
#define cerr if(0)cerr
#endif

template<class C> void amin(C &a4, C b4) {
	a4 = min(a4, b4);
}
template<class C> void amax(C &a4, C b4) {
	a4 = max(a4, b4);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
	os << "[";
	for (auto vv : V)
		os << vv << ",";
	return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}

const int N = 1e3 + 5;
int dp[N][N];
int n, m;
char grid[N][N];
int solve(int x, int y) {
	if(x >= n || y >= m || grid[x][y] == '#')
		return 0;
	if(x==n-1&&y==m-1)
		return 1;
	int &ret = dp[x][y];
	if (~ret)
		return ret;
	ret = solve(x,y+1) + solve(x+1,y);
	if(ret >= 1000000007)
		ret -= 1000000007;
	return ret;
}
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	cin >> n >> m;

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> grid[i][j];
	memset(dp,-1,sizeof dp);
	cout << solve(0,0) << '\n';
	return 0;
}


Measured memory_bytes: 5248
import sys
n = int(input())
a_ls = []
for i in range(2):
    a = [int(i) for i in sys.stdin.readline().split()]
    a_ls.append(a)

memo_ls = [[0 for j in range(n)] for i in range(2)]
memo_ls[0][0] = a_ls[0][0]
for i in range(2):
    for j in range(n):
        if i == j == 0:
            continue
        memo_ls[i][j] = max(memo_ls[i-1][j], memo_ls[i][max(0, j-1)]) + a_ls[i][j]
print(memo_ls[-1][-1])

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

int n;
const int maxn = 2e5 + 5;
int a[maxn];

int dp[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    int ans = 0;
    for(int i = 1;i <= n;i++){
        if(dp[a[i] - 1] == -1){
            dp[a[i]] = 1;
        }else{
            dp[a[i]] = dp[a[i] - 1] + 1;
        }
        ans = max(ans, dp[a[i]]);
    }
    cout << n - ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/ 
 
int sc1() {int x; scanf("%d", &x); return x;}
 
long long sc2() {long long x; scanf("%lld", &x); return x;}
 
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
 
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}
 
int mx=1e9;
int arr[100000000];
 
int solve() {
 

 	int h,w,n;
 	cin>>h>>w>>n;
 	h=max(h,w);
 	int aa=n/h;
 	if(n%h) aa++;
 	cout<<aa<<endl;
	return 0;
}
 
 
 
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




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

int main(){
    int64_t N,K;
    cin >> N >> K;
    int64_t x = N%K;
    cout << min(x,K-x) << endl;
}   

Measured memory_bytes: 256
R,G,B,N = map(int, input().split())
rgb = [R,G,B]
rgb.sort(reverse = True)
#print(rgb)
ans = 0
for r in range(N//rgb[0]+1):
    n1 = N - rgb[0]*r
    for g in range(n1//rgb[1]+1):
        if (n1 - rgb[1]*g)%rgb[2] == 0:
            #print(r,g,n2//rgb[2])
            ans += 1

print(ans)

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

int main()
{
  double max = 0, min = 1000000000;
  double d = 0;
  while(scanf("%lf", &d) != EOF)
  {
    max = max < d ? d : max;
    min = min > d ? d : min;
  }
  printf("%lf\n", max - min);
  return 0;
}

Measured memory_bytes: 1076
#include<bits/stdc++.h>
using namespace std;
int a,b;

int main()
{
	scanf("%d %d",&a,&b);
	if(a%3==0||b%3==0||(a+b)%3==0)
	{
		printf("Possible\n");
	}
	else
	{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

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

    vector<long long> dp(N,LLONG_MAX);
    dp[0] = 0;

    for ( int i = 0; i < N; i++ ) {
        if ( i+1 < N ) { dp[i+1] = min( dp[i+1], dp[i] + abs(H[i]-H[i+1]) ); }
        if ( i+2 < N ) { dp[i+2] = min( dp[i+2], dp[i] + abs(H[i]-H[i+2]) ); }
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
import sys
from bisect import bisect_right as br
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = []
for _ in range(M):
  k, x = map(int, input().split())
  b.append((x, k))
b.sort()
l = 0
res = 0
while len(b):
  x, k = b.pop()
  i = br(a, x)
  if l >= i: break
  if i - l > k:
    i = l + k
  res += x * (i - l)
  l = i
print(res + sum(a[l: ]))

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    int x, n;
    cin >> x >> n;
    vi p(n);
    rep(i, n) cin >> p[i];

    sort(rng(p));
    rep(i, 1000) {
        if (!binary_search(rng(p), x - i)) {
            prt(x - i);
            return 0;
        };
        if (!binary_search(rng(p), x + i)) {
            prt(x + i);
            return 0;
        };
    }

    return 0;
}


Measured memory_bytes: 3624
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    x=list(map(int,input().split()))
    ans=INF
    zero=bisect_left(x,0)
    for i in range(K+1):
        if zero<i or N-zero<K-i:
            continue
        if i==K:
            tmp=abs(x[zero-i])
        elif i==0:
            tmp=x[zero+K-i-1]
        else:
            tmp=min(abs(x[zero-i])*2+x[zero+K-i-1],abs(x[zero-i])+x[zero+K-i-1]*2)
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int N;
ll si,ti;
 
bool check(ll p,ll n){
  if(p<0)p*=-1;
  if(p%(1LL<<n)==0)return true;
  else return false;
}
 
int solve(){
  ll p=si;
  int res=0;
  while(p!=ti){
    res++;
    for(int i=30;i>=0;i--){
      ll d=(1LL<<i);
      if(!check(p,i))continue;
      if(p+d>ti)continue;
      p=p+d;
      break;
    }
  }
  return res;
}
 
int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>si>>ti;
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<cmath>
#include<vector>
#define buff 10001

using namespace std;

int main(void){

  int size,cumsum=0;
  cin>>size;
  size=size;
  vector<int> vec(size);
  vector<int> res(size);
  vector<int> cstore(buff);
  for(int i=0;i<size;i++){
    cin>>vec.at(i);
    cstore.at(vec.at(i))++;
  }
  for(int i=0;i<buff;i++){
    cumsum+=cstore.at(i);
    cstore.at(i)=cumsum;
  }
  for(int i=size-1;i>=0;i--){
    res.at(--cstore.at(vec.at(i)))=vec.at(i);
  }
  for(int i=0;i<size-1;i++) cout<<res.at(i)<<" ";
  cout<<res.at(size-1)<<endl;
  return 0;
}



Measured memory_bytes: 18328
#include <algorithm>
#include <stdio.h>

int main() {
	int N, n[300300], i; long long t;
	for (scanf("%d", &N), i = 0; i < 3*N; i++)
		scanf("%d", &n[i]);
	for (std::sort(n, n+3*N), t = 0, i = 3*N-2; i >= N; i -= 2)
		t += n[i];
	printf("%lld", t);
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
string s;
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	cin>>s;
	int len=s.length();
	int l;
	int r;	
	rep(i,0,len)
	{
		if(s[i]=='A')
		{
			l=i;
			break;
		}
	}
	rep(i,0,len)
	{
		if(s[i]=='Z')
		{
			r=i;
		}
	}
	cout<<r-l+1<<endl;
	
	
    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();} 
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') 
{*p = *p * 10 + ch - '0';}}}

Measured memory_bytes: 888
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    int tem = n % x!= 0;
    cout << t * (n / x + tem) << endl;
    return 0;
}

Measured memory_bytes: 3136
import copy

def Bubble_Sort(n,cards):

	for i in range(n):
		for j in range(n-1,i,-1):
			if int(cards[j][1]) < int(cards[j-1][1]):
				cards[j],cards[j-1] = cards[j-1],cards[j]

def Selection_Sort(n,cards):

	for i in range(n):
		mini = i
		for j in range(i,n):
			if int(cards[j][1]) < int(cards[mini][1]):
				mini = j
		cards[i],cards[mini] = cards[mini],cards[i]

def Print_cards(n,cards):

	for i in range(n-1):
		print(f"{cards[i][0]}{cards[i][1]} ",end='')
	print(f"{cards[n-1][0]}{cards[n-1][1]}")


def isStable(n,original,sorted):

	for i in range(n):
		for j in range(i+1,n):
			for a in range(n):
				for b in range(a+1,n):
					if int(original[i][1]) == int(original[j][1]) and original[i] == sorted[b] and original[j] == sorted[a]:
						return False

	return True

def test():

	n = int(input())
	cards_original = input().split()
	cards_for_Bubble = copy.deepcopy(cards_original)
	cards_for_Selection = copy.deepcopy(cards_original)

	Bubble_Sort(n,cards_for_Bubble)
	Print_cards(n,cards_for_Bubble)
	if isStable(n,cards_original,cards_for_Bubble) == True:
		print("Stable")
	else:
		print("Not stable")

	Selection_Sort(n,cards_for_Selection)
	Print_cards(n,cards_for_Selection)
	if isStable(n,cards_original,cards_for_Selection) == True:
		print("Stable")
	else:
		print("Not stable")

if __name__ == "__main__":
	test()




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

int main() {
	char input[5];
	int ans = 0;
	scanf("%s", input);

	for (int i = 0; i < 4; i++) {
		if (input[i] == '+')ans++;
		else ans--;
	}

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


	return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
using namespace std;

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

int bubbleSort(vector<int> &A,int N){
    int count = 0; 
    bool end = false;
    while(!end){
        end = true;
        RFOR(i,N-1,0){
            if(A[i] < A[i-1]){
                swap(A[i],A[i-1]);
                end = false;
                count++;
            }
        }
    }
    return count;
}

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

    vector<int> A(N);
    FOR(i,0,N) cin>>A[i];

    int ans = bubbleSort(A,N);

    cout<<A[0];
    FOR(i,1,N) cout<<" "<<A[i];

    cout<<"\n";
    put(ans);
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int S, W;
	cin >> S >> W;
	if(S<=W) cout << "unsafe" << endl;
	else cout << "safe" << endl;

	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int h,n;
	cin >> h >> n;
	vi a(n),b(n);
	rep(i,n) cin >> a[i] >> b[i];
	
	int dp[20010];
	rep(i,10000+h) dp[i] = INF;
	for(int i = 10000+h; i >= 0; i--){
		for(int j = 0; j < n; j++){
			if(i+a[j] >= 10000+h){
				dp[i] = min(dp[i],b[j]);
			}else{
				dp[i] = min(dp[i],dp[i+a[j]]+b[j]);
			}
			
		}
	}
	int ans = 1e9;
	for(int i = 0; i <= 10000; i++) ans = min(ans,dp[i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
N=int(input())
A1=list(map(int, input().split()))
A2=list(map(int, input().split()))

B1=[None]*N
B2=[None]*N
c1=0
c2=0
for i in range(N):
    c1+=A1[i]
    c2+=A2[N-i-1]
    B1[i]=c1
    B2[N-i-1]=c2

m=0
for i in range(N):
    x=B1[i]+B2[i]
    if m<x:
        m=x
print(m)


Measured memory_bytes: 3064
N = int(input())
W = list(map(int, input().split()))
S = [0 for i in range(N+1)]
for i in range(N):
  S[i+1] = S[i] + W[i]
  
ans = 999999999
for t in range(1,N+1):
  if ans > abs(S[N]-S[t] - S[t]):
    ans = abs(S[N]-S[t] - S[t])
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

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

const ll mod = 1000000007;

unordered_map<ll, int> primeFactorize(ll a) {
  ll i = 2;
  unordered_map<ll, int> factor;
  while (i * i <= a) {
    if (a % i == 0) {
      factor[i]++;
      a /= i;
    }
    else i++;
  }
  factor[a]++;
  return factor;
}

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  unordered_set<ll> primeFound;
  bool isPairwiseCoprime = true;
  for (int i = 0; i < n; i++) {
    auto primeFactor = primeFactorize(a[i]);
    for (auto &x: primeFactor) {
      if (x.first == 1) continue;
      else if (primeFound.find(x.first) != primeFound.end()) {
        isPairwiseCoprime = false;
        break;
      }
      else primeFound.insert(x.first);
    }
    if (!isPairwiseCoprime) break;
  }

  if (isPairwiseCoprime) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll gcdAll = a[0];
  for (int i = 1; i < n; i++) gcdAll = gcd(gcdAll, a[i]);

  if (gcdAll == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;

  return 0;
}


Measured memory_bytes: 11124
#include<stdio.h>

int main(){
  int D;
  scanf("%d", &D);
  if(D == 22){
    printf("Christmas Eve Eve Eve\n");
  } else if(D == 23){
    printf("Christmas Eve Eve\n");
  } else if(D == 24){
    printf("Christmas Eve\n");
  } else {
    printf("Christmas\n");
  }
  
  return 0;
}
    

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

vector<p> g[100005];
int ans[100005];

void dfs(int cur, int par, int c) {
    ans[cur] = c;
    for (int i = 0; i < g[cur].size(); i++) {
        int nx = g[cur][i].first;
        ll cost = g[cur][i].second;
        if (nx == par) continue;
        if (cost & 1) {
            dfs(nx, cur, 1 - c);
        } else {
            dfs(nx, cur, c);
        }
    }
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        ans[i] = -1;
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        g[u].push_back(p(v, w));
        g[v].push_back(p(u, w));
    }
    dfs(0, -1, 1);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 9984
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

long long powmod(long long x, long long y){
	long long a = 1;
	x %= MOD;
	while(y){
		if(y & 1){
			a = a * x % MOD;
		}
		x = x * x % MOD;
		y >>= 1;
	}
	return a;
}

vector<LL> fact;

LL cmb(int n, int k){
	return fact[n] * powmod(fact[n - k] * fact[k], MOD - 2) % MOD;
}

int n;
VV(int) G;
vector<int> szs;
vector<LL> dess;
vector<LL> ans;

void dfs1(int u, int p){
	G[u].erase(remove(ALL(G[u]), p), G[u].end());
	LL ret = 1;
	int sz = 0;
	for(int v : G[u]){
		dfs1(v, u);
		sz += szs[v];
		ret = cmb(sz, szs[v]) * dess[v] % MOD * ret % MOD;
	}
	szs[u] = sz + 1;
	dess[u] = ret;
}

void dfs2(int u, LL a){
	ans[u] = a = cmb(n - 1, n - szs[u]) * dess[u] % MOD * a % MOD;

	for(int v : G[u]){
		LL b = a * powmod(cmb(n - 1, szs[v]) * dess[v], MOD - 2) % MOD;
		dfs2(v, b);
	}
}

void mainmain(){
	scanf("%d", &n);
	fact.resize(n + 5);
	fact[0] = 1;
	for(int i = 1; i < n + 5; ++i){
		fact[i] = fact[i - 1] * i % MOD;
	}
	G.resize(n);
	for(int i = 0; i < n - 1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	szs.resize(n);
	dess.resize(n);
	ans.resize(n);
	dfs1(0, -1);
	dfs2(0, 1);
	for(LL x : ans){ printf("%lld\n", x); }
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int a,b,c;
bool solve(){
  return a<=c&&c<=b; 
}
int main(){
  cin>>a>>b>>c;
  if(solve()) prin("Yes");
  else prin("No");
  return 0;
}


Measured memory_bytes: 256
// I have to work harder than anyone else to make it! I’ll never catch up otherwise… 

// ICPC next year.

#include<bits/stdc++.h>
using namespace std;

#define P pair<int,int>
#define P pair<int,int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define str std::string 
#define pb push_back 
#define ll long long
#define pq(x) std::priority_queue<x> 
#define ultapq(x) priority_queue<x,vector<x>,greater<x>> 
#define show_pq(x) for(int i = 0; i < n; i++){cout<<yes.top(); yes.pop();} 
#define itrt(yo) for(auto x:yo){std::cout<<x<<nl;} 
#define vec(x) std::vector<x> 
#define nl '\n' 
#define DRI(X) ll (X); scanf("%lld", &X)
#define DRII(X, Y) ll X, Y; scanf("%lld%lld", &X, &Y)
#define DRIII(X, Y, Z) ll X, Y, Z; scanf("%lld%lld%lld", &X, &Y, &Z)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define F first
#define S second
#define ALL(x) x.begin(),x.end() 
#define BN(x) x.begin()
#define ED(x) x.end()
#define MAP_traverse(it,x)  for(auto it = BN(x); it!= ED(x); it++)
#define PI 3.14159265358979323846264338327950L
const unsigned int M = 1000000007;



int main()
{
	IOS;
	int n,k;
	cin>>n>>k;
	int a[n];
	for (int i = 0; i <n; i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);

	int ans=0;
	for (int i = 0; i < k; i++)
	{
		//cout<<"ank";
		ans+=a[i];
	}
	cout<<ans;
	
	
	
	
	
	
}

Measured memory_bytes: 3644
#pragma region Library

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

using ll = long long int; // int_fast64_t;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
using vi = vt<int>;
using vvi = vvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;

constexpr int INF = 1 << 30;  // 1073741824 2倍すると-2147483648
constexpr ll INFL = 1l << 62; // 4611686018427387904 2倍すると-0.9*10^18
constexpr int dx4[] = {0, 1, 0, -1};
constexpr int dy4[] = {1, 0, -1, 0};
constexpr int dx8[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy8[] = {0, -1, 0, 1, -1, -1, 1, 1};
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define RANGE(i, a, b) for (int i = (a); i <= (b); i++)
#define RANGER(i, a, b) for (int i = (b); i >= (a); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) RFOR(i, 0, (n))

#pragma endregion

int main() {
  double t, x;
  cin >> t >> x;
  cout << t / x << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

#+++++

def main():
	n, m = map(int, input().split())
	s=input()
	s=s[::-1]
	#arch=[len(s)+100]*len(s)
	
	pos=0
	ret=[]
	while pos < len(s)-1:
		for mi in range(m,0,-1):
			if pos+mi >= len(s):
				pass
			elif s[pos+mi]=='0':
				pos += mi
				ret.append(mi)
				#print(pos)
				break
			else:
				pass
		else:
			return -1
	
	r=ret[::-1]
	print(*r)
	
'''
def main2():
	n, m = map(int, input().split())
	s = input()
	
	tt=[-1]*len(s)
	t_parent=[-1]*len(s)
	rs=s[::-1]
	open_list=[0]
	max_dist = 0
　	while True#len(open_list) > 0:
		st, parent, count = open_list.pop()
		for i in range(m, 0, -1):
			aa = st + i
			if aa > n+1:
				pass
			
			#gmマス
			if rs[aa] == 1:
				continue
			
			#アクセス済み
			if tt[aa] > 0:
				break
				
			tt[aa] = count+1
			t_parent[aa] = st
			open_list.append(aa, st, count+1)
			
	print(1)
'''
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 50416
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    string S;
    cin >> S;
    if(S == "Sunny"){
      cout << "Cloudy" << endl;
    }else if(S == "Cloudy"){
      cout << "Rainy" << endl;
    }else{
      cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
m, d = map(int, input().split())
ans = 0
for mm in range(1, m + 1):
    for dd in range(1, d + 1):
        d1 = dd % 10
        d10 = dd // 10
        if d1 >= 2 and d10 >= 2 and d1 * d10 == mm:
            ans += 1
print(ans)


Measured memory_bytes: 2940
package main

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

const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1

var sc = bufio.NewScanner(os.Stdin)

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sort(str string) string {
	n := len(str)
	res := []rune(str)
	for i := 0; i < n; i++ {
		min := i
		for j := i + 1; j < n; j++ {
			if res[j] < res[min] {
				min = j
			}
		}
		res[i], res[min] = res[min], res[i]
	}
	return string(res)
}

func combination(n, r int) int {
	result := 1
	for i := n; i > (n - r); i-- {
		result *= i
	}
	for i := 2; i <= r; i++ {
		result /= i
	}
	return result
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	sorted := make(map[string]int, n)
	for i := 0; i < n; i++ {
		s := nextStr()
		s = sort(s)
		if _, ok := sorted[s]; ok {
			sorted[s]++
		} else {
			sorted[s] = 1
		}
	}

	count := 0
	for _, v := range sorted {
		count += combination(v, 2)
	}
	fmt.Printf("%d\n", count)
}


Measured memory_bytes: 7552
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    let xs: Vec<i64> = sc.vec(n);
    let mut x = xs[0];
    let mut cost = 0;
    for i in 1..n {
        cost += min!((xs[i] - x) * a, b);
        x = xs[i];
    }
    put!(cost);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 11768
#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>;
const ll INF = 1000000000;

int main(){
    int h,n;
    scanf("%d %d",&h,&n);
    vector<int> dp(h+1,INF);
    dp[0] = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        rep(j,h) {//体力をj減らすことのできる最小コスト
            int nj = min(j+a,h);
            dp[nj] = min(dp[nj], dp[j]+b);
        }
    }
    cout << dp[h] << endl;

}

Measured memory_bytes: 256
from collections import deque
S = input()
Q = int(input())
info = []
for _ in range(Q):
    info.append(input().split())
# print(info)
rev = 1
ans = deque(list(S))
for i in range(Q):
    if info[i][0] == '1':
        rev *= -1
    else:
        if rev == 1:
            if info[i][1] == '1':
                ans.appendleft(info[i][2])
            else:
                ans.append(info[i][2])
        else:
            if info[i][1] == '1':
                ans.append(info[i][2])
            else:
                ans.appendleft(info[i][2])

if rev == -1:
    ans.reverse()

# print(ans)
print(''.join(ans))

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

typedef pair<int,int> PAIR;
const int INF=100000000;
 
int main(){
	int n,y;
	cin>>n>>y;

	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= n; j++){
				if(i*10000+j*5000+(n-i-j)*1000==y&&n-i-j>=0){
					cout<<i<<' '<<j<<' '<<(n-i-j)<<endl;
					return 0;
				}
		}
	}

	cout<<-1<<' '<<-1<<' '<<-1<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		long r[]=new long[n];
		r[0]=a[0];
		long cnt1=0;
		if(r[0]>=0) {
			cnt1+=Math.abs(-1-r[0]);
			r[0]=-1;
		}
		for(int i=1;i<n;i++) {
			r[i]=r[i-1]+a[i];
			if(i%2==1&&r[i]<=0) {
				cnt1+=Math.abs(1-r[i]);
				r[i]=1;
			}
			if(i%2==0&&r[i]>=0) {
				cnt1+=Math.abs(-1-r[i]);
				r[i]=-1;
			}
		}
		r=new long[n];
		r[0]=a[0];
		long cnt2=0;
		if(r[0]<=0) {
			cnt2+=Math.abs(1-r[0]);
			r[0]=1;
		}
		for(int i=1;i<n;i++) {
			r[i]=r[i-1]+a[i];
			if(i%2==1&&r[i]>=0) {
				cnt2+=Math.abs(-1-r[i]);
				r[i]=-1;
			}
			if(i%2==0&&r[i]<=0) {
				cnt2+=Math.abs(1-r[i]);
				r[i]=1;
			}
		}
		System.out.println(Math.min(cnt1, cnt2));
	}
}

Measured memory_bytes: 52144
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1200

int main() {
	char str[N],buf[2];
	char *p;
	int sum;
	while (1) {
		scanf("%s",str);
		if (str[0] == '0')break;
		sum = 0;
		p = str;
		while (*p) {
			sum += atoi(strncpy(buf,p++,1));
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 556
import java.util.*;

public class Main {

	/**
	 * @param args
	 */


	static boolean[] matrix = new boolean[1000000];  //素数がfalse
	static{
		for (int i = 2; i <= 999999; i++) {
			if (matrix[i])
				continue;
			for (int j = 2; i*j <= 999999; j++) {
				matrix[i*j] = true;
			}
		}
	}

	private static int solve(int n) {
		int cnt = 0;

		for (int i = 2; i <= n; i++) {
			if (!matrix[i])
				cnt++;
		}

		return cnt;
	}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		while(scan.hasNext()){
			System.out.println(solve(scan.nextInt()));
		}
	}

}

Measured memory_bytes: 13000
open Printf
open Scanf

let id x = x

let n, k = scanf "%d %d" (fun n k -> n, k)

let vs = Array.init n (fun i -> scanf " %d" id)

let () =
    Array.sort (fun x y -> y - x) vs;
    let r = ref 0 in
    for i = 0 to k - 1 do
        r := !r + vs.(i)
    done;
    printf "%d\n" !r

    

Measured memory_bytes: 384
open Printf open Scanf
open Array

let () =
  Scanf.scanf " %d %d %d" @@ fun a b k ->
    let a,b = min a b,max a b in
    init a (fun i -> a-i)
    |> fold_left (fun c v ->
      if a mod v = 0 && b mod v = 0 then
        let c = c+1 in
        if c=k then (
          print_int v; exit 0
        ) else c
      else c
    ) 0
    |> ignore

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

int w, h, ans;
int field[20][20];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

void curling(int n, int x, int y) {
    if (n >= ans) {
        return;
    }
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i],
            ny = y + dy[i];
        if (nx < 0 || w <= nx || ny < 0 || h <= ny || field[ny][nx] == 1) {
            continue;
        }
        while (true) {
            if (field[ny][nx] == 3) {
                ans = n;
                return;
            }
            nx += dx[i];
            ny += dy[i];
            if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                break;
            }
            if (field[ny][nx] == 1) {
                field[ny][nx] = 0;
                curling(n + 1, nx - dx[i], ny - dy[i]);
                field[ny][nx] = 1;
                break;
            }
        }
    }
}

int main() {
    while (true) {
        cin >> w >> h;
        if ((w | h) == 0) {
            break;
        }
        int sx, sy;
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                cin >> field[y][x];
                if (field[y][x] == 2) {
                    sx = x;
                    sy = y;
                }
            }
        }
        ans = 11;
        curling(1, sx, sy);
        if (ans > 10) {
            ans = -1;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{


int a,b;
scanf("%d %d",&a,&b);
if((a>=1 && a<=9) && (b>=1 && b<=9))
{
    if(a>b)
{
    while(a>0)
    {
        printf("%d",b);
        a--;
    }
}
else if(a<b)
{
    while(b>0)
    {
        printf("%d",a);
        b--;
    }
}
else if(a==b)
{
     while(a>0)
    {
        printf("%d",b);
        a--;
    }
}
}


return 0;
}


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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N;
int K;
priority_queue<pair<int, int>> q;
// d, t

void init()
{
	cin >> N >> K;
	rep(i, N) {
		int t = GET<int>();
		int d = GET<int>();
		q.push(MP(d, t));
	}
}

void solve()
{
	vector<int> c(N+1, 0);
	ll k = 0;
	ll res = 0;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> mi;
	rep(i, K) {
		auto x  = q.top();
		q.pop();
		res += x.first;
		if (c[x.second] == 0) {
			k++;
		}
		mi.push(x);
		c[x.second]++;
	}
	ll ma = res + k * k;
	reps(i, k+1, K+1) {
		while (c[mi.top().second] == 1) mi.pop();
		res -= mi.top().first;
		c[mi.top().second]--;
		mi.pop();
		while (!q.empty() && c[q.top().second]) {
			q.pop();
		}
		if (q.empty()) break;
		res += q.top().first;
		c[q.top().second]++;
		q.pop();
		ma = max(ma, res + i * i);
	}
	cout << ma << endl;
}



Measured memory_bytes: 5616
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=220;
    int N,M,R;
    int dist[MAXN][MAXN];
    int r[10];
    int vis[10];
    void floyed(){
        for(int k=1;k<=N;k++){
            for(int u=1;u<=N;u++){
                for(int v=1;v<=N;v++){
                    if(dist[u][v]>dist[u][k]+dist[k][v]){
                        dist[u][v]=dist[u][k]+dist[k][v];
                    }
                }
            }
        }
    }
    int ans=0x3f3f3f3f;
    void dfs(int idx,int pre,int sum){
        if(idx==R){
            ans=min(ans,sum);
            return;
        }
        for(int u=0;u<R;u++){
            if(!vis[u]){
                vis[u]=true;
                if(pre==-1)dfs(idx+1,u,0);
                else dfs(idx+1,u,sum+dist[r[pre]][r[u]]);
                vis[u]=false;
            }
        }
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N>>M>>R;
        memset(dist,0x3f,sizeof(dist));
        for(int u=0;u<R;u++)cin>>r[u];
        for(int u=0;u<M;u++){
            int a,b,c;
            cin>>a>>b>>c;
            dist[a][b]=c;
            dist[b][a]=c;
        }
        floyed();
        dfs(0,-1,0);
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#define int long long
using namespace std;
const int N=105;
const int S=1e5+1;
const int mod=1e9+7;
int dp[N][S],sum[N][S],ar[N];
signed main(){
	int n,i,j,k;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	dp[0][0]=1;
	for(i=0;i<=k;i++){
		sum[0][i]=1;
	}
	for(i=1;i<=n;i++){
		for(j=0;j<=k;j++){
			if(j-ar[i]>0){
				dp[i][j]=(sum[i-1][j]-sum[i-1][j-ar[i]-1]+mod)%mod;
			}
			else{
				dp[i][j]=sum[i-1][j];
			}
			if(j>0){
				sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
			}
			else{
				sum[i][j]=dp[i][j];
			}
		}
	}
	cout<<dp[n][k];
}

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

int main(){
  int a,p;
  cin >> a >> p;
  cout << (3*a+p)/2;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = Counter(a)

ans = 0
for i in a:
    if c[i] == 0:
        continue
    c[i] -= 1
    k = 1<<i.bit_length()
    j = k-i
    if j in c and c[j] > 0:
        ans += 1
        c[j] -= 1
print(ans)


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

public class Hello
{
    public static void Main()
    {
        var hs = new HashSet<int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < 3; i++) hs.Add(int.Parse(line[i]));
        Console.WriteLine(hs.Count());
    }
}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            int b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            int c = int.Parse(str[1]);
            int goukei = 0;
            if(b <= 3)
            {
                goukei += 100000 * (4 - b);
            }
            if (c <= 3)
            {
                goukei += 100000 * (4 - c);
            }
            if (b == 1 && c == 1)
            {
                goukei += 400000;
            }
            Console.WriteLine(goukei);
        }
    }
}


Measured memory_bytes: 13140
#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);
}

signed main()
{
	int n=read(),k=read();
	print(n-k+1);

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define f first
#define s second

int n, ans = 1e9;
string str;

int main() {
	cin >> str;
	n = str.length();
	ans = n;
	FOR(i, 0, n-2) {
		if (str[i] != str[i+1]) ans = min(ans, max(i+1, n-i-1));
	}
	cout << ans;
}


Measured memory_bytes: 512