akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using vi = std::vector<int>;
using vvi = std::vector<vi>;

int N;
vvi edges;
vi sign;

bool isBipartite(int, int);

int main()
{
	scanf("%d", &N);
	sign.resize(N, -1);
	edges.resize(N, vi(N));
	for (auto&& e: edges)
		for (auto&& f: e)
		{
			char tmp;
			scanf(" %c", &tmp);
			if (tmp == '1') f = 1;
		}
	if (!isBipartite(0, 0))
	{
		puts("-1");
		return 0;
	}
	for (auto& e: edges)
		for (auto& f: e)
			if (f == 0)
				f = 1 << 29;
	for (int i{}; i < N; i++)
		edges[i][i] = 0;
	for (int mid{}; mid < N; mid++)
		for (int from{}; from < N; from++)
			for (int to{}; to < N; to++)
				edges[from][to] = std::min(edges[from][to], edges[from][mid] + edges[mid][to]);
	
	int max{};
	for (auto& e: edges)
		for (auto& f: e)
			max = std::max(max, f);
	printf("%d\n", max + 1);

	return 0;
}

bool isBipartite(int index, int one_zero)
{
	if (sign[index] >= 0) return one_zero == sign[index];
	sign[index] = one_zero;
	for (int i{}; i < N; i++)
		if (edges[index][i] && !isBipartite(i, 1 - one_zero))
			return false;
	return true;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

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

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

ll n,x;
ll l[110];

int main(){
    cin >> n >> x;
    ll ans = 0,mem = 0;
    ++ans;
    for(int i = 0; i < n; i++){
        cin >> l[i];
        mem += l[i];
        if(mem <= x)    ++ans;
    }

    cout << ans << endl;


    
}

Measured memory_bytes: 256
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

N = n1()
a = nn()

ans = 0
for i in range(N):
    if i % 2 == 0 and a[i] % 2 == 1:
        ans += 1

print(ans)


Measured memory_bytes: 77052
S = str(input())
X=[]
ans = 0

for s in S:
    X.append(int(s))

for n in range(1,len(X)):
    if X[n-1] == X[n]:
        ans += 1
        if X[n] == 1:
            X[n] = 0
        else:
            X[n] = 1

print(ans)

Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 4000000000000000000
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

int main(){
  ll sp[300][300];
  int n;
  ll ans=0;
  
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>sp[i][j];
    }
  }
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      bool flg=true;
      if(i==j)continue;
      for(int k=0;k<n;k++){
        if(k==i||k==j)continue;
        if(sp[i][j]>sp[i][k]+sp[j][k]){
          cout<<-1<<endl;
          return 0;
        }
        if(sp[i][j]==sp[i][k]+sp[j][k]){
          flg=false;
          break;
        }
      }
      if(flg)ans+=sp[i][j];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define all(n) (n).begin(),(n).end()
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0);
ll dp[25][2100000],n;
bool ok[25][25];
const ll mod = 1000000007;

int main(){
	cin>>n;
	int all = 1<<n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>ok[i][j];
		}
	}
	for(int j=0;j<n;j++) if(ok[0][j]) dp[0][1<<j]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<all;j++){
			if(dp[i][j]){
				for(int k=0;k<n;k++){
					if( ok[i+1][k] && !(j&(1<<k)) ){
						dp[i+1][j|(1<<k)] = (dp[i+1][j|(1<<k)] + dp[i][j]) % mod; 
					}
				}
			}
		}
	}
	cout<<dp[n-1][all-1]<<'\n';
}


Measured memory_bytes: 167104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) int __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

struct UnionFind{
    int n;
    vi p,r;
    UnionFind(int N):n(N){
        p.resize(n);
    	iota(all(p),0);
        r.resize(n);
        fill(all(r),0);
    }
    void unite(int a, int b){
        int c=root(a),d=root(b); 
        if(c!=d) {
            if(r[c]<r[d]){
                p[c]=d;
            }else{
                p[d]=c;
                if(r[c]==r[d])r[c]++;
            }
        }
    }
    int root(int a){return p[a]=(p[a]==a?a:root(p[a]));}
    bool same(int a, int b){return root(a)==root(b);}
};

struct Kruskal{
    using Edge=pair<int,pair<int,int>>;
    vector<Edge> edge;
	int n;
	Kruskal(){}
	Kruskal(int N):n(N){ }
	Edge rem;
    void add(int C,int S,int T){
		edge.eb(C,mp(S,T));
	}
    void remove(int C,int S,int T){
		rem=mp(C,mp(S,T));
	}
	pair<int,vector<Edge>> calcMST(){
		int ans=0;
		vector<Edge> ret;

		UnionFind uf(n);		
		for(auto e:edge){
			if( !uf.same(e.sc.fs, e.sc.sc) and e!=rem ){
				ret.pb(e);
				ans+=e.fs;
				uf.unite(e.sc.fs, e.sc.sc);
				if(ret.size()==n-1){
					break;
				}
			}
		}
		return mp(ans,ret);
	}
	

};

int main(){
	int n,m;
	while(cin>>n>>m){
		Kruskal kr(n);
		rep(i,m){
			dcl(s,d,c);
			kr.add(c,s-1,d-1);
		}
		
		using Edge=pair<int,pair<int,int>>;
		sort(all(kr.edge),[](Edge a,Edge b){return a.fs<b.fs;});

		auto mst=kr.calcMST();
		int cost=mst.fs;
		int ans=0,anscost=0;

		for(auto e:mst.sc){
			kr.remove(e.fs, e.sc.fs, e.sc.sc);
			int cur=kr.calcMST().fs;
			if(cur != cost || cur==-1){
				ans++;
				anscost+=e.fs;
			}
		}
		cout<<ans<<" "<<anscost<<endl;
	}
	return 0;
}



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

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

typedef long long ll;
typedef long double ld;
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
const int N=2e5+5;
int mod=100000000;
/*int k1, k2;
ll dp[10][10][100][100];
ll solve(int n1, int n2, int last1, int last2)
{
    if(n1==0&&n2==0)
        return 1;
    if(dp[last1][last2][n1][n2]!=-1)
        return dp[last1][last2][n1][n2];

    ll &ans=dp[last1][last2][n1][n2];
    ans=0;
    if(last1<k1&&n1)
    {
        ans=(ans+solve(n1-1,n2,last1+1,0))%mod;

    }
    if(last2<k2&&n2)
    {
         ans=(ans+solve(n1,n2-1,0,last2+1))%mod;
    }
    // cout<<n1<<" "<<n2<<" "<<last1<<" "<<last2<<" "<<ans<<endl;
    return ans;

}*/
    ll n,arr[N], co[N], ans=0;

int main()
{
    FIO
    int k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];
        sort(arr,arr+n);
        ll ans=1e9;

        for(int i=n-1;i>=k-1;i--)
        {
        //    cout<<arr[i]<<" "<<arr[i-k+1]<<" \n";

            ans=min(ans,arr[i]-arr[i-k+1]);
        }
        cout<<ans;
return 0;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

/*---------------------------------------------------------------------------------------------------*/

void solve()
{
 int n,k;
 cin >> n >> k;
 int a[n+1];
 fp(i,1,n)
    cin >> a[i];
 fp(i,k+1,n)
 {
     if(a[i]>a[i-k])
        cout << "Yes\n";
     else
        cout << "No\n";
 }
  return;
} 

signed main()
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5216
def divisors(n, sort=False):
    """
    nの約数をO(√n)で列挙する
    """
    d = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            d.append(i)
            if i != n // i:
                d.append(n//i)
    if sort:
        d.sort()
    return d


N = int(input())

cnt = 0
for i in range(1, N + 1, 2):
    if len(divisors(i)) == 8:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second

//CHECK FOR N = 1 OR OTHER DUMB TESTS 

using namespace std;

int main() {
	//ifstream cin("tst.in");
	//ofstream out("tst.out");
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	ll a, b;
	cin >> a >> b;
	int cnt = 0;
	while (a <= b) {
		cnt++;
		a *= 2LL;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
e = [0]*(N+1)
for i in range(2,N+1):
    cur = i
    for j in range(2,i+1):
        while cur%j==0:
            e[j] += 1
            cur //=j
def num(m):
    return len(list(filter(lambda x:x>=m-1,e)))
print(num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)//2)

Measured memory_bytes: 3064
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))

S = sum(A)
ans_candidate = []
for i in range(1, int(S ** 0.5) + 1):
    if S % i == 0:
        ans_candidate.append(i)
        ans_candidate.append(S // i)


ans = 1
for z in ans_candidate:
    modZ_down = sorted([a % z for a in A])
    modZ_up = sorted([z - mzd for mzd in modZ_down], reverse=True)

    modZ_down = list(accumulate(modZ_down))
    modZ_up = list(accumulate(modZ_up[::-1]))[::-1]

    for i in range(N - 1):
        if (modZ_down[i] == modZ_up[i + 1]) and (modZ_down[i] <= K):
            ans = max(ans, z)

print(ans)


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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;
  if (n % 1000 == 0) {
    cout << 0 << endl;
  } else {
    cout << (1000 - n % 1000) << endl;
  }

  return 0;
}


Measured memory_bytes: 3592
N=int(input())
S=list(input())

r=g=b=0
c=0

for i in range(N):
    if S[i]=="R":
        r+=1
    elif S[i]=="G":
        g+=1
    else:
        b+=1

for i in range(N-2):
    for j in range(i+1,N-1):
        k=2*j-i
        if k>N-1:
            break
        if S[i]!=S[j] and S[k]!=S[j] and S[i]!=S[k]:
            c+=1

print(r*g*b-c)

Measured memory_bytes: 9240
n=int(input())
rec=list(map(int,input().split()))
s=[0,abs(rec[1]-rec[0])]
for i in range(2,n):
        total2=abs(rec[i]-rec[i-2])+s[i-2]
        total1=abs(rec[i]-rec[i-1])+s[i-1]
        s.append(min(total2,total1))
print(s[-1])

Measured memory_bytes: 20476
import sys
readline = sys.stdin.readline
N, T = map(int, readline().split())
AB = [list(map(int, readline().split())) for _ in range(N)]
AB.sort()
A, B = map(list, zip(*AB))
dp = [0]*(T + max(A) + 2)
L = len(dp)
for i in range(N):
    dp2 = dp[:]
    a, b = A[i], B[i]
    for t in range(L):
        if T + a > t >= a:
            dp2[t] = max(dp2[t], dp[t-a] + b)
    dp = dp2[:]
print(max(dp))

Measured memory_bytes: 51804
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;

int n;
char s[1000005];
struct node1
{
	int a,b;
}x[1000005];
int cnt=0,c=0;
struct node2
{
	int a,b;
}y[1000005];
int st[1000005],top=0;
int sum=0,flag=0;

bool cmp1(node1 n,node1 m){return n.a+n.b>m.a+m.b;}
bool cmp2(node2 n,node2 m){return n.a<m.a;}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int now=0;
		top=0;
		scanf("%s",s);
		int len=strlen(s);
		for(int j=0;j<len;j++)
		{
			if(s[j]==')'&&!top) now++;
			else if(s[j]=='(') top++;
			else top--;
		}
		int s,t;
		if(now!=0) s=now,t=top-now;
		else s=0,t=top;
		if(t<0) x[++cnt].a=s,x[cnt].b=t;
		else y[++c].a=s,y[c].b=t;
	}
	sort(x+1,x+cnt+1,cmp1),sort(y+1,y+c+1,cmp2);
	for(int i=1;i<=c;i++)
	{
		if(sum<y[i].a) flag=1;
		sum+=y[i].b;
	}
	for(int i=1;i<=cnt;i++)
	{
		if(sum<x[i].a) flag=1;
		sum+=x[i].b;
	}
	if(flag||sum) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 11316
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	private static int cnt = 0;
	private static int n;
	private static int[] a;

	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		shellSort(a, n);

		// output3
		System.out.println(cnt);

		// output4-
		for (int i = 0; i < a.length; i++) {
			System.out.println(a[i]);
		}
	}

	private static void insertionSort(int[] a, int n, int g) {
		for (int i = g; i < n; i++) {
			int v = a[i];
			int j = i - g;
			while (j >= 0 && a[j] > v) {
				a[j + g] = a[j];
				j = j - g;
				cnt++;
			}
			a[j + g] = v;
		}
	}

	private static void shellSort(int[] a, int n) {
		List<Integer> g = new ArrayList<>();
		int x = 0;
		boolean flag = true;
		while (flag) {
			x = 3 * x + 1;
			if (x > n) break;
			g.add(x);
		}
		Collections.reverse(g);
		int m = g.size();

		// output1
		System.out.println(m);

		// output2
		for (int i = 0; i < g.size(); i++) {
			if (i != 0) System.out.print(" ");
			System.out.print(g.get(i));
		}
		System.out.print("\n");

		for (int i = 0; i < m; i++) {
			insertionSort(a, n, g.get(i));
		}
	}
}

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

int N;

int main() {
    cin >> N;
    vector<long long> S(N);
    cin >> S[0];
    for (int i = 1; i < N; i++) {
        int a; cin >> a;
        S[i] = S[i - 1] + a;
    }
    long long ans = 1e18;
    for (int i = 0; i < N - 1; i++) {
        ans = min(ans, abs(S[N - 1] - 2 * S[i]));
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.next();
            for (int i = s.length() / 2 - 1; i > 0; i--) {
                if (s.substring(0, i).equals(s.substring(i, i * 2))) {
                    out.println(i * 2);
                    return;
                }
            }
        }

    }

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

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

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

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

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

        private static boolean isPrintableChar(int c) {
            return c >= 33 && c <= 126;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();

            int b = readByte();
            while (!isPrintableChar(b))
                b = readByte();

            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }

            return sb.toString();
        }

    }
}



Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    int ans = 1;
    while (ans <= N) ans *= 2;
    ans /= 2;

    cout << ans << endl;
}



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

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, K;
int A[5050];
bool dp[5050][5050];

bool isNecessary(int x) {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = true;
    for (int i = 0; i < N; ++i) {
        rep(k, K + 1) {
            dp[i + 1][k] = dp[i][k];
            if (i != x && k - A[i] >= 0) {
                dp[i + 1][k] |= dp[i][k - A[i]];
            }
        }
    }
    for (int r = max(0ll, K - A[x]); r < K; ++r) {
        if (dp[N][r])return true;
    }
    return false;
}

signed main() {
    cin >> N >> K;
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    int notNecessary = -1;
    int neccessary = N;
    while (neccessary - notNecessary > 1) {
        int m = (notNecessary + neccessary) / 2;
        if (isNecessary(m))neccessary = m;
        else notNecessary = m;
    }
    cout << notNecessary + 1 << endl;
}


Measured memory_bytes: 25344
N=int(input())
t=list(map(int,input().split()))
v=list(map(int,input().split()))

bound = [0 for _ in range(N+1)]

for i in range(N-1):
    bound[i+1]=min(v[i],v[i+1],bound[i]+t[i])
for i in range(N-1,0,-1):
    bound[i]=min(bound[i],bound[i+1]+t[i],v[i],v[i-1])


sum=0
for i in range(N):
    if (bound[i]+bound[i+1]+t[i])/2>v[i]:
        sum+=(bound[i]+v[i])*(v[i]-bound[i])/2
        sum+=(bound[i+1]+v[i])*(v[i]-bound[i+1])/2
        sum+=v[i]*(t[i]-2*v[i]+bound[i]+bound[i+1])
    else:
        sum+=(bound[i+1]-bound[i]+t[i])*0.5*(bound[i+1]+3*bound[i]+t[i])*0.5*0.5
        sum+=(t[i]+bound[i]-bound[i+1])*0.5*(bound[i]+3*bound[i+1]+t[i])*0.5*0.5

print(sum)




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

using namespace std;

typedef long long ll;

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i] >> h[i];
  }
  int res_x = 0;
  int res_y = 0;
  int res_h = 0;
  for (int i = 0; i <= 100; ++i) {
    for (int j = 0; j <= 100; ++j) {
      bool ok = true;
      int H;
      for (int k = 0; k < N; ++k) {
        if (h[k] > 0) {
          H = h[k] + abs(x[k] - i) + abs(y[k] - j);
          break;
        }
      }
      for (int k = 0; k < N; ++k) {
        if (max(H - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        res_x = i;
        res_y = j;
        res_h = H;
      }
    }
  }
  printf("%d %d %d\n", res_x, res_y, res_h);
}

Measured memory_bytes: 256
N = int(input())
p_list = [int(x) for x in input().split()]

p_list_sort = sorted(p_list)

j = 0
for i in range(N):
    if p_list[i] != p_list_sort[i]:
        j += 1
if j <= 2:
    print("YES")
else:
    print("NO")

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

int main() {
  string S;
  cin >> S;
 
    if (S.at(0) == 'a') {
      cout << "vowel" << endl;
  }
    else if(S.at(0) == 'e') {
      cout << "vowel" << endl;
  }
    else if(S.at(0) == 'i') {
      cout << "vowel" << endl;
  }
    else if(S.at(0) == 'o') {
      cout << "vowel" <<  endl;
  }
    else if(S.at(0) == 'u') {
      cout << "vowel" << endl;
  }
    else {
      cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n,t;
    cin>>n>>t;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    
    int ans=1;
    int now=0;
    int now_min=INF;
    rep(i,0,n){
        if(now<a[i]-now_min){
            now=a[i]-now_min;
            ans=1;
        }
        else if(now==a[i]-now_min) ans++;
        now_min=min(now_min,a[i]);
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  vector<int> a(3);
  cin >> a[0]>>a[1]>>a[2];
  int m = 10000;
  rep(i,3) if(m>=a[i]+a[(i+1)%3]) m = a[i] + a[(i+1)%3];
  cout << m << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int a,n,t;
    cin >> n >> t >> a;
    int h[n];
    REP(i,n){
        cin >> h[i];
    }
    double error_min=10000;
    int remi;
    REP(i,n){
        double error;
        error = fabs(a-(t-h[i]*0.006));
        if(error_min > error){
            remi = i;
            error_min = error;
        }
    }
    cout << remi + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar

using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

int h,w,n,x=1,y=1,r[101][101];
void input()
{
    cin>>h>>w>>n; bool add= true;
    up(i,1,n)
    {
    	int a; cin>>a;
		up(j,1,a)
		{
			r[x][y]= i;
			if (add) y++;
			else y--;
			if (y>w or y<1)
			{
				add= !add;
				x++;
				if (add) y=1; else y= w;
			}
		}
    }

    up(i,1,h)
    {
    	up(j,1,w) cout<<r[i][j]<<" ";
    	cout<<endl;
    }
}

void solve()
{

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive
    #define TASK "tmp"
   // freopen(TASK".inp","r",stdin);
   // freopen(TASK".out","w",stdout);

    input();
    solve();

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main (void) {

  char s[3];
  int ans = 0;

  cin >> s;

  for (int i = 0; i < 3; i++) {
    if (s[i] == '1')
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{ 
	char S[100];

	scanf("%s", S);

	for (int i = 0; i < sizeof(S); i++)
	{
		if ((i % 2 == 0) && S[i] == 'L')
		{
			printf("No\n");
			return 0;
		}
		if ((i % 2 == 1) && S[i] == 'R')
		{
			printf("No\n");
			return 0;
		}
		
	}

	printf("Yes\n");

	return 0;
}
	

Measured memory_bytes: 128
import java.util.*;

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

        int[] numbers = new int[100];
        int numberPlace = 0;
        String s;

        while(inp.hasNext()){
            s = inp.next();
            if (s.equals("=")){
                break;
            }
            if (s.equals("+")){
                int tempHold = numbers[numberPlace-2] + numbers[numberPlace-1];

                numbers[numberPlace-1] = 0;
                numbers[numberPlace-2] = 0;

                numberPlace -= 2;

                numbers[numberPlace] = tempHold;
            } else if (s.equals("-")){
                int tempHold = numbers[numberPlace-2] - numbers[numberPlace-1];

                numbers[numberPlace-1] = 0;
                numbers[numberPlace-2] = 0;

                numberPlace -= 2;

                numbers[numberPlace] = tempHold;
            } else if (s.equals("*")){
                int tempHold = numbers[numberPlace-2] * numbers[numberPlace-1];

                numbers[numberPlace-1] = 0;
                numbers[numberPlace-2] = 0;

                numberPlace -= 2;

                numbers[numberPlace] = tempHold;
            } else {
                numbers[numberPlace] = Integer.parseInt(s);
            }

            numberPlace++;
        }

        System.out.println(numbers[numberPlace-1]);
    }
}



Measured memory_bytes: 26248
import math
 
N, M = list(map(int, input().split()))
stairs = [0] * (N + 1)

for i in range(M):
	stairs[int(input())] = -1

# all element of stairs
for i in range(N, -1, -1):
	# last is always 1
	if i == N:
		stairs[i] = 1
	# if stair[N - 1] is not broken 
	elif i == N - 1 and stairs[i] != -1:
		stairs[i] = stairs[i + 1]
	# if stairs[i] is not broken
	elif stairs[i] != -1:
		if stairs[i + 1] != -1:
			stairs[i] += stairs[i + 1]
		if stairs[i + 2] != -1:
			stairs[i] += stairs[i + 2]
print(int(stairs[0]) % 1000000007)

Measured memory_bytes: 462708
// 5/2 解説動画を見ながら！！！

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

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

    // N = (N / 2) * 2;

    // for (long long i = 1; i <= M; i++) {
    //     // cout << i << " " << N + 1 - i << endl;
    // }

    // for (long long i = 0; i < M; i++) {
    //     int a = 2 * i + 1;
    //     int b = 2 * i + 1 + 2 * i + 1;
    //     if (b > N) b %= N;
    //     // cout << 2 * i + 1 << " " << (2 * i + 1 + 2 * i - 1) % N << endl;

    //     cout << a << " " << b << endl;
    // }

    if (N % 2 == 1) {
        // 奇数の時
        for (int i = 0; i < M; i++) {
            cout << i + 2 << " " << N - i << endl;
        }
    }
    else {
        // 偶数の時
        for (int i = 0; i < M; i++) {
            // cout << i << endl;
            // if (i < M / 2) {
            //     cout << i + 2 << " " << N - i << endl;
            // } else {
            //     cout << i + 2 << " " << N - i - 1 << endl;
            // }
            // if (i + 1 < N / 4)
            if ((double)(i + 1) / N < 0.25) {
                cout << i + 2 << " " << N - i << endl;
            } else {
                cout << i + 2 << " " << N - i - 1 << endl;
            }
        }
    }
}


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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}

void run() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		graph[u - 1].push_back(v - 1);
	}
	vector<int> dp(n), used(n);
	function<void(int)> dfs = [&](int u){
		used[u] = 1;
		for (int v : graph[u]) {
			if (!used[v]) {
				dfs(v);
			}
			dp[u] = max(dp[u], dp[v]);
		}
		dp[u]++;
	};
	for (int i = 0; i < n; i++) if (!used[i]) {
		dfs(i);
	}
	cout << *max_element(all(dp)) - 1 << "\n";
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

typedef pair<ll, ll> pll;

struct UnionFind {
	vector<ll> par, siz;
	UnionFind(ll n): par(n), siz(n, 1) {
		rep(i,n) par[i] = i;
	}
	ll find(ll x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return;
	}
	bool is_same(ll x, ll y) {
		return find(x) == find(y);
	}
	ll size(int x) {
		return siz[find(x)];
	}
};

int main() {
	ll n, m;
	cin >> n >> m;
	vector<pll> v(m);
	rep(i,m) {
		cin >> v[i].first >> v[i].second;
		v[i].first--, v[i].second--;
	}
	reverse(ALL(v));
	UnionFind uf(n);
	vector<ll> ans(m);
	ans[0] = n * (n - 1) / 2;
	rep(i,m-1) {
		ll a = v[i].first;
		ll b = v[i].second;
		if (uf.is_same(a, b)) {
			ans[i+1] = ans[i];
			continue;
		}
		ll sub = uf.size(a) * uf.size(b);
		ans[i+1] = max(0ll, ans[i] - sub);
		uf.unite(a, b);
	}
	reverse(ALL(ans));
	rep(i,m) cout << ans[i] << endl;
}

Measured memory_bytes: 7160
def main():
    S = input()
    YY = int(S[:2])
    MM = int(S[2:])

    if 1 <= YY <= 12:
        if 1 <= MM <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if 1<= MM <= 12:
            print("YYMM")
        else:
            print("NA")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
N=int(input())
A=list(map(int,input().split()))
c=0
for i in range (0,N):
    if A[i]%2==0 and A[i]%3!=0 and A[i]%5!=0:
        c=1
        break
if c==0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38384
n = int(input())
a, b = map(int,input().split())

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

q1 = 0
q2 = 0
q3 = 0

for i in range(n):
    if p[i]<=a:
        q1 += 1
    elif p[i] > b:
        q3 += 1
    else:
        q2 += 1

print(int(min(q1, q2, q3)))
        

Measured memory_bytes: 3060
#pragma GCC optmize ("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define spIO ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
typedef long double ld;
int n;
inline void solve()
{

}
int main()
{
	spIO;
	string s;
	cin >> s;
	if (s[0] != s[1] || s[1] != s[2])
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=500;

ll dp[N][N];
ll n,a[N];
ll solve(int i,int j){
	if(i>j)
		return 0LL;

	if(i==(j-1LL)){
		return a[j]-a[i-1];
	}
	if(i==j)
		return 0LL;
	ll &ans=dp[i][j];
	if(ans!=-1LL)
		return ans;
	ans=10000000000000LL;
	for (int c = i; c <=j; ++c)
	{
		ll l=solve(i,c);
		ll r=solve(c+1,j);
		ans=min(ans,l+r+a[j]-a[i-1]);
		// cout<<ans<<"\n";
	}
	return ans;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	memset(dp,-1LL,sizeof(dp));
	for (int i = 1; i <=n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		a[i]+=a[i-1];
	}
	cout<<solve(1,n)<<"\n";
}

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

int main()
{
	ll k,n,i,adj=-1;
	cin>>k>>n;
	ll arr[n];
	for(i=0;i<n;i++)
	cin>>arr[i];
	sort(arr,arr+n);
	for(i=0;i<n-1;i++)
	adj=max(adj,(ll)abs(arr[i+1]-arr[i]));
	adj=max(adj,(ll)abs(k-arr[n-1]+arr[0]));
	cout<<k-adj;
	return 0;
}


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

using namespace std;

#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 rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0) cout << b / x + 1 << endl;
    else cout << b / x - (a - 1) / x << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

void resolve(int t, int a, std::vector<int> h, std::vector<double> &results) {
    for (int x : h) {
        results.push_back(std::abs(a - (t - x * 0.006)));
    }
}

int main() {
    int N, T, A;
    std::vector<int> h;
    std::cin >> N;
    std::cin >> T >> A;
    int temp;
    for (int i = 0; i < N; i++) {
        std::cin >> temp;
        h.push_back(temp);
    }
    std::vector<double> results;
    resolve(T, A, h, results);
    int ans = 0;
    for (int i = 0; i < results.size() - 1; i++) {
        if (results[ans] > results[i + 1]) {
            ans = i + 1;
        }
    }
    ans++;
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
}
int n,m;
void input()
{
	n=read<int>(),m=read<int>();
}
int num[N],may[N];
void work()
{
	int x,y;
	For(i,1,n)num[i]=1;
	may[1]=1;
	For(i,1,m)
	{
		x=read<int>(),y=read<int>();
		--num[x],++num[y];
		if(may[x])may[y]=1;
		if(!num[x])may[x]=0;
	}
	int ans=0;
	For(i,1,n)ans+=may[i];
	write(ans,'\n');
}
int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,a,b,ans=1;
    cin>>k>>a>>b;
    if(a>=b-2){
        cout << k+1<<endl;
    }
    else{
        if(k+1<=a){
            cout << k+1<<endl;
        }
        else{
            ans+=(a-1);
            k-=(a-1);
            if(k%2==0){
                k/=2;
                ans+=(b-a)*k;
                cout <<ans<<endl;
            }
            else{
                k/=2;
                ans+=(b-a)*k+1;
                cout << ans<<endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}

vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}



signed main(){
	ll x,y; cin>>x>>y;
	ll a,b,ans;
	a = (2*y-x)/3; b = (2*x-y)/3;
	if((a+2*b!=x)||(2*a+b!=y)) return cout << 0 << endl,0;
	else{
		// cerr << "NOT CASE" << endl;
		// ans = 1;
		// for(int i = a+1; i<=a+b; i++){
		// 	ans *= i;
		// 	ans %= MOD;
		// }
		// cerr << ans << endl;
		// for(int i = 1; i<=b; i++){
		// 	// ans *= pow(i,MOD-2);
		// 	ans = ans*mpow(i,MOD-2)%MOD;
		// }
		// ans %= MOD;
		// if(ans<0) ans += MOD;
		ans = nCr(a+b,a);
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 14184
fun main(args: Array<String>) {
    val (N) = readLine()!!.split(' ').map(String::toLong)
    val t = Math.floor(N / 1.08).toLong()
    for (i in -3..3) {
        if (Math.floor((t + i) * 1.08).toLong() == N) {
            println(t+i)
            return
        }
    }
    println(":(")
}

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

using namespace std;
int a[100009][4],dp[100009][5],n,k;
int sol(int x,int y)
{
    if (x==n) return 0;
    if (dp[x][y]!=-1) return dp[x][y];
    for (int i=0;i<3;i++)
    {
        if (i==y) continue;
        dp[x][y]=max(dp[x][y],sol(x+1,i)+a[x][i]);
    }
    return dp[x][y];
}
int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for (int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    cout<<sol(0,3);
    return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    while (a >= MOD)
        a -= MOD;
    while (a < 0)
        a += MOD;
}

int main() {
    int n; cin >> n;
    
    vector<vector<int>> a(n, vector<int> (n, 0));

    for (int i = 0; i < n; i += 1)
        for (int j = 0; j < n; j += 1)
            cin >> a[i][j];

    vector<vector<int>> dp(2, vector<int> ((1 << n), 0));
    
    dp[0][0] = 1;

    for (int i = 0; i < n; i += 1) {
        int now = (i & 1);
        int then = 1 - now;
        dp[then] = vector<int> ((1 << n), 0);

        for (int mask = 0; mask < (1 << n); mask += 1) {
            if (dp[now][mask] == 0)
                continue;
            for (int who = 0; who < n; who += 1)
                if (a[i][who] and (((1 << who) & mask) == 0))
                    add(dp[then][mask + (1 << who)], dp[now][mask]);
        }
    }

    cout << dp[(n % 2)][(1 << n) - 1] << "\n";
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;

	return 0;
}


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

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

        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(a);

        int ans = 0;
        int cnt = 1;
        for (int i = 1; i < n; i++) {
            if (a[i-1] == a[i]) {
                cnt++;
            } else {
                if (cnt % 2 == 1)
                    ans++;
                cnt = 1;
            }
        }
        if (cnt % 2 == 1)
            ans++;

        System.out.println(ans);
    }
}

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

 int main() {
   int K;
   ll ans;
   cin >> K;

   queue<ll> lun;

   for (ll i = 1; i < 10; i++) lun.push(i);

   while (K > 0) {
     ll tmp = lun.front();
     K--;
     if (K == 0) ans = tmp;
     else {
       if (tmp % 10 == 0) {
         lun.push(tmp * 10);
         lun.push(tmp * 10 + 1);
       }
       else if (tmp % 10 == 9) {
         lun.push(tmp * 10 + 8);
         lun.push(tmp * 10 + 9);
       }
       else {
         lun.push(tmp * 10 + tmp % 10 - 1);
         lun.push(tmp * 10 + tmp % 10);
         lun.push(tmp * 10 + tmp % 10 + 1);
       }
       lun.pop();
      }
    }
    cout << ans << endl;
  }


Measured memory_bytes: 1792
program cutting
implicit none
real(8) w, h, x, y
integer res
real(8) s
read*, w, h, x, y
if((x.eq.w/2).and.(y.eq.h/2)) then 
res=1
else if ((x.ne.w/2).or.(y.ne.h/2)) then
res=0
end if
s=w*h
s=s/2
print*, s, res
end program

Measured memory_bytes: 256
import java.util.*;

public class Main{

    final static Scanner sc = new Scanner(System.in);
    static int res = 0;
    public static void main(String[] args) {
        System.out.println(D());
    }

    public static int D(){
        int N = Integer.parseInt(sc.next());
        String colors = sc.next();
        char [] stones = new char[N];
        for(var i =0; i< N; i++){
            stones[i] = colors.charAt(i);
        }
        int num = 0;
        for(var i : stones){
            if(i == 'R'){
                num++;
            }
        }
        int cnt = 0;
        for(var i = 0; i< num ; i++){
            if(stones[i] == 'W'){
                cnt++;
            }
        }
        return cnt;
    }

}


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

#define ll long long

const ll MOD = 1000000007;

// a^n (mod p) を繰り返し二乗法で計算する
ll nPower(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  
  // n が奇数のとき 
  if (n % 2) return (a * nPower(a, n-1, p)) %p;
  
  // n が偶数のとき
  ll t = nPower(a, n/2 , p) % p;
  return (t * t) % p;
}


ll Comb(ll n, ll r, ll p) {
  ll res = 1;
  
  for (ll i = n; i >= n - r + 1; i--) {
    res *= i;
    res %= p;
  }
  for (ll i = 1; i <= r; i++) {
    res *= nPower(i, p-2, p);
    res %= p;
  }
  return res % p;
}


int main () {
  
  ll X, Y;
  cin >> X >> Y;
  
  
  if ((2 * X - Y) % 3 == 0 && Y <= 2*X && X <= 2*Y) {
    ll a = (2*Y-X)/3, b = (2*X-Y)/3;
    cout << Comb(a+b, a, MOD) << endl;
  } else {
    cout << 0 << endl;
  }
}



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

int main(int argc, char** argv){
  string s;
  long long k;
  
  while(cin >> s >> k) {
    bool flag = false;
    
    // long long after = 5000000000000000 // 5000,0000,0000,0000
    for (int i = 0; i < k; i++) {
      if (s[i] != '1') {
	flag = true;
	cout << s[i] << endl;
	break;
      }
    }

    if (!flag) {
      cout << "1" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256