akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n;
  ll a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  for(int k = 0; k < n; k++){
    if(a - k * d + (n - 1 - k) * c <= b && b <= a - k * d + (n - 1 - k) * c + (n - 1) * (d - c)){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 384
n=int(input())
h=list(map(int,input().split()))
keep=0
for i in range(0,n-1):
  i=n-i-1
  if h[i]>=h[i-1]:
    pass
  elif h[i]==h[i-1]-1:
    h[i-1]-=1
  else:
    keep=1
    break
print(["Yes","No"][keep])

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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000003
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<bool>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
    ll n, m, k, res = 0;
    cin>>n;
    vl div(n + 1, 0);
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j * i <= n; j++) 
            div[i * j]++; 
    }
    for(ll i=1;i<=n;i++)
        res += i*div[i];
    cout<<res;

}

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

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


Measured memory_bytes: 81320
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N; 
  	cin>>N;
	queue<pair<char,string>> q;
	q.push({'a',"a"});
  
	char mx; 
  	string pre;
	while(!q.empty()){
		tie(mx,pre)= q.front(); 
      	q.pop();
		if (pre.size() >= N) 
          	break;
		for (char c='a'; c<=mx+1; ++c) 
          	q.push({max(mx, c), pre + c});
	}
  
	cout<< pre <<endl;
	while(!q.empty()){ 
      	cout<< q.front().second <<endl; 
      	q.pop(); 
   	}
  
  return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,i,j,n,a,b,c,d;
    cin>>a>>b>>c>>d;
    int f=0;
    while(a>0&&c>0)
    {
        if(f==0)
        {
            c-=b;
            f=1;
        }
        else
        {
            a-=d;
            f=0;
        }
    }
    if(a<=0)
        cout<<"No\n";
    else
        cout<<"Yes\n";

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<math.h>



using namespace std;

main()
{
	int n,w;
	cin>>n>>w;
	
	int i,j;
	int weight[n],cost[n];
	
	for(i=0;i<n;i++)
	{
		cin>>weight[i]>>cost[i];
	}
	
	long long dp[n][w+1];
	
	for(j=0;j<w+1;j++)
	{
		if(j < weight[0])
			dp[0][j] = 0;
		else
			dp[0][j] = cost[0];
	}
	
	for(i=1;i<n;i++)
	{
		for(j=0;j<w+1;j++)
		{
			if(j-weight[i]>=0)
			dp[i][j] = max(cost[i] + dp[i-1][j - weight[i]]  ,  dp[i-1][j]);
			else
			dp[i][j] = dp[i-1][j];
		}
	}
	
	cout<<dp[n-1][w];
	
	
	
}



Measured memory_bytes: 78336
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
using namespace std;
bool edg[101][101]; int n,k,m;
int main()
{
	scanf("%d%d",&n,&k); m=n*(n-1)/2;
	m-=k;
	if(m<n-1)
	{
		printf("-1"); return 0;
	}
	printf("%d\n",m); m-=n-1; for(int i=2;i<=n;i++)	edg[i][1]=1;
	for(int i=2;i<=n&&m;i++)	for(int j=i+1;j<=n&&m;j++)
		edg[i][j]=1,m--;
	for(int i=1;i<=n;i++)	for(int j=1;j<=n;j++)
		if(edg[i][j])	printf("%d %d\n",i,j);
	return 0;
}

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

int main()
{
	int N,H,W;
	int A,B;
	int ans=0;
	
	cin >> N >> H >> W;
	for(int i=0;i<N;i++)
	{
		cin >> A >> B;
		if(A>=H && B>=W)ans++;
	}
	
	cout << ans << endl;
	return 0;
}

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

#define MAX 2000001
#define VMAX 10000

int main(void)
{
	unsigned short *A, *B;
	
	int C[VMAX+1];
	int n, i, j;
	scanf("%d",&n);
	
	A = malloc(sizeof(short)*n+1);
	B = malloc(sizeof(short)*n+1);
	
	for(i=0;i<=VMAX;i++) C[i] = 0;
	
	for(i=0;i<n;i++) {
		scanf("%hu",&A[i+1]);
		C[A[i+1]]++;
	}
	
	for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];
	
	for(j=1;j<=n;j++) {
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for(i=1;i<=n;i++) {
		if(i>1) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 9572
#include <iostream>

using namespace std;

int n,a[100010];

int main()
{
	//freopen("input.txt","r",stdin);
	cin >> n;
	for (int i=1;i<=n;++i)
		cin >> a[i];
	int st=1,co=0;
	while (st<=n)
	{
		int up=0;
		while (st<n)
		{
			if (a[st]==a[st+1]) st++;
			else
			{
				if (!up and a[st+1]>a[st]) up=1;
				else if (!up) up=-1;
				if (up==1 and a[st+1]<a[st]) break;
				if (up==-1 and a[st+1]>a[st]) break;
				st++;
			}
		}
		co++;
		st++;
	}
	cout << co;
}

Measured memory_bytes: 640
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<String> s = nextStrArray();
      int A = Integer.parseInt(s.get(0));
      int B = Integer.parseInt(s.get(2));
      if(s.get(1).equals("+")){
        myout(A + B);
      }else{
        myout(A - B);
      }
	}
	//Method addition frame start


  
	//Method addition frame end
}


Measured memory_bytes: 32792
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	int n, k;
	cin >> n >> k;
	vector<pair<int, int> > v(n);
	long long ans = 0;
	for (int i = 0; i < n; i++)
		cin >> v[i].second >> v[i].first;
	sort(v.begin(), v.end(), greater<pair<int, int> > ());
	map<int, int> cnt;
	vector<pair<int, int> > taken;
	for (int i = 0; i < k; i++) {
		ans += v[i].first;
		cnt[v[i].second]++;
		taken.push_back({v[i].first, v[i].second});
	}
	int cursz = cnt.size();
	ans += 1LL * cursz * cursz;
	map<int, bool> vis;
	vector<int> arr;
	for (int i = k; i < n; i++) {
		if (cnt[v[i].second] == 0 && !vis[v[i].second]) {
			vis[v[i].second] = true;
			arr.push_back(v[i].first);
		}
	}
	int na = arr.size();
	int ptr = k - 1;
	long long mx = ans;
	for (int i = 0; i < na; i++) {
		while (ptr >= 0) {
			if (cnt[taken[ptr].second] > 1) {
				ans += arr[i];
				ans -= taken[ptr].first;
				ans -= 1LL * cursz * cursz;
				cursz++;
				ans += 1LL * cursz * cursz;
				mx = max(ans, mx);
				ptr--;
				break;
			}
			ptr--;
		}
	}
	cout << mx;
	return 0;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int K = 38;
const int N = K*(K-1)+1;

vi ans[N];

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

    forn(r,K) ans[N-1].pb(r);
    forn(i,N-1) ans[i].pb(i/(K-1));


    int n = K;
    forn(start,K-1) {
        for (int d = 0; d < K-1; d++) {
            for (int q = 0, r = start; q < K-1; q++, r = (r+d)%(K-1)) {
                ans[q*(K-1)+r].pb(n);
            }
            ans[(K-1)*(K-1) + d].pb(n);
            n++;
        }
    }

//    map<int,int> gcnt;
//    forn(i,n) for (auto x : ans[i]) gcnt[x]++;
//    forn(i,n) forsn(j,i+1,n) {
//        map<int,int> cnt;
//        for (auto x : ans[i]) {
//            cnt[x]++;
//            assert(cnt[x] < 2);
//        }
//        for (auto x : ans[j]) cnt[x]++;
//        int inter = 0;
//        for (auto xy : cnt) if (xy.second == 2) {
//            inter++;
//        }
//        assert(inter == 1);
//    }
//    for (auto xy : gcnt) {
//        assert(xy.second == K);
//    }

    cout << N << ' ' << K << endl;
    forn(i,N) {
        for (auto x : ans[i]) cout << x+1 << ' ';
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 896
import java.util.*;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final long K = sc.nextLong();
		final long A = sc.nextLong();
		final long B = sc.nextLong();

		if (B - A <= 2) {
			System.out.println(1L + K);
		} else if (K <= A) {
			System.out.println(1L + K);
		} else {
			long ops = K - A - 1L;
			long boost = B - A;
			long units = ops / 2;
			long r = ops % 2;

			System.out.println(B + boost * units + r);
		}
		sc.close();
	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define N (1<<20)
using namespace std;
typedef long long ll;
string str;
int bit[N+1],n;
int a[N];
 
int sum(int i){
  int res=0;
  while(i>0){
    res+=bit[i];
    i-=i&-i;
  }
  return res;
}
 
void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}
 
ll solve(){
  n=str.size();
  int cnt[30]={},cnt2[30]={};
  for(int i=0;i<n;i++)cnt[str[i]-'a']++;
  int c = 0,alp=-1;
  for(int i=0;i<30;i++)if(cnt[i]%2) c++,alp = i;
  if(c >=2) return -1;

  int A=0;
  stack <int> stk[30];
  int flg = 0;
  for(int i=0;i<n;i++){
    int idx=str[i]-'a';
    if(idx == alp&& cnt[idx]/2<=cnt2[idx]&&flg == 0) {flg=1;a[i] = n/2+1;continue;}
    if(cnt[idx]/2>cnt2[idx]){
      stk[idx].push(A);
      A++;
      cnt2[idx]++;
      a[i]=A;
    }
    else {
      a[i]=n-stk[idx].top();
      stk[idx].pop();
    }
  }
  
  ll ans=0;
  for(int j=0;j<n;j++){
    ans+=j-sum(a[j]);
    add(a[j],1);
  }
  return ans;
}
 
 
int main(){
  cin>>str;
  reverse(str.begin(),str.end());
  cout <<solve()<<endl;  
  return 0;
}


Measured memory_bytes: 3716
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        root = self.find(x)
        return -self.parents[root]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = li()
uf = UnionFind(N)
for i in range(M):
    a, b = li()
    uf.union(a-1, b-1)

ans = max(uf.size(x) for x in range(N))
print(ans)

Measured memory_bytes: 74580
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



def main_sum():
    N,M,K=map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = len(A) + 1
    maxB = len(B) + 1

    add = 0
    for i in range(1,A_len+1):
        Asum[i] = A[i-1] + Asum[i-1]

    add = 0
    for i in range(1,B_len+1):
        Bsum[i] = B[i-1] + Bsum[i-1]

    ans = 0
    prev = 0
    for i in reversed(range(maxA)):
        for j in range(prev,maxB):
            if Asum[i] + Bsum[j] <= K:
                prev = j
                if ans < i + j:
                    ans = i + j
                if j == (maxB - 1):
                    print(ans)
                    exit()
            else:
                break

    print(ans)




main_sum()


Measured memory_bytes: 48400
#include<stdio.h>

int syr[10]; //??????????????§???????????\??????
int s=0; //????????????????????\??£????????????????????°???????????\??£?????????????????§???

int top() { //?????????????????????????????????
	return syr[s-1];
}
void pop() { //???????????????????????????????????????
	s--;
}
void push(int num) { //??\?????????????????????????????????????´???????????¬???????????????\????????????????????????
	if(num>0) {
		syr[s] = num;
		s++;
	}
}

int main() {
	int num;
	while(scanf("%d",&num) != EOF) {
		//scanf("%d",&num); //??????????????\???
		push(num);
		if(num==0) {
			printf("%d\n",top());
			pop();
		}
	}
	return 0;
}

Measured memory_bytes: 1704
a, b= map(int, input().split())
ans=0
if a == 1:
    ans += 300000
elif a == 2:
    ans += 200000
elif a == 3:
    ans += 100000

if b == 1:
    ans += 300000
elif b == 2:
    ans += 200000
elif b == 3:
    ans += 100000

if a == 1 and b == 1:
    ans+= 400000
print(ans)

Measured memory_bytes: 40240
#include<stdio.h>

int main()
{
	int height[10], i;
	for (i = 0; i < 10; i++)
	{
		scanf("%d", &height[i]);
	}
	int n1 = 0, n2 = 0, n3 = 0, l, m, s;
	for (i = 0; i < 10; i++)
	{
		if (n1 < height[i])
		{
			n1 = height[i];
			l = i;
		}
	}
	for (i = 0; i < 10; i++)
	{
		if ((n2 < height[i]) && (i != l))
		{
			n2 = height[i];
			m = i;
		}
	}
	for (i = 0; i < 10; i++)
	{
		if ((n3 < height[i]) && (i != l) && (i != m))
		{
			n3 = height[i];
			s = i;
		}
	}
	printf("%d\n%d\n%d\n", n1, n2, n3);
	return 0;
}

Measured memory_bytes: 1028
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 
 
void solve(){
    string s;
    cin>>s;
    cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
}
 
 
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    ll Q=1;
    // cin>>Q;
    rep(_,Q){
 
        solve();
 
    }
   
 
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int func(int X,int A,int B,int C){return (A*X+B)%C;}

int main(){
	int n,a,b,c,x;
	while(1){
		cin>>n>>a>>b>>c>>x;
		if(!n && !a && !b && !c && !x)break;
		int lucky[n];
		rep(i,n)cin>>lucky[i];
		int cnt=0,place=0;
		while(cnt<=10000){
			if(x==lucky[place])place++;
			if(place>=n)break;
			x=func(x,a,b,c);
			cnt++;
		}
		if(cnt>10000)cout<<-1<<endl;
		else cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int a, b; cin>>a>>b;
    a--, b--;
    cout << (b + a - 1) / a << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
class V:
    def __init__(self, f, v = None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def __call__(self, n):
        if n is None:
            return self.v

        if self.v is None:
            self.v = n
            return self.v
        self.v = self.f(self.v, n) 

h, w = map(int, input().split())

def minmax(*args):
    return max(args) - min(args)

def sep(m, n):
    a = b = c = 0
    nn = n // 2
    ans = V(min, float("inf"))

    for i in range(1, m):
        a = i * n
        mm = (m - i) // 2
    
        # 横
        b, c = (m - i) * nn, (m - i) * (n - nn)
        ans(minmax(a, b, c))

        # 縦
        b, c = mm * n, (m - i - mm) * n
        ans(minmax(a, b, c))
    
    return ans.v

print(min(sep(h, w), sep(w, h)))

Measured memory_bytes: 9136
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main()
{
  int A,B; cin >> A >> B; bool flag = true;
  for(int i = 0; i < A + B - 1; i++){
    char c; cin >> c;
    if( i < A && c != '-'){continue;}
    else if( i == A && c == '-'){continue;}
    else if( A < i && c != '-'){continue;}
    else{ flag = false; break;}}
  if(flag){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
  return 0;}

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

int p,q,a,n,cnt;

void dfs(int depth,int sum_p,int sum_q,int nowq){
  if(p*sum_q == sum_p*q){
    cnt++;
    return;
  }

  if(depth == n) return;

  for(int i = nowq ; i*sum_q <= a ; i++){
    dfs(depth+1,i*sum_p+sum_q,i*sum_q,i);
  }
}

int main(){
  while(cin >> p >> q >> a >> n , p + q + a + n){
    cnt = 0; 
    dfs(0,0,1,1);
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

struct mint{
    static const long long MOD = 998244353;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

vector<long long> A;
array<array<array<mint, 2>, 3001>, 3001> cache;
array<array<array<bool, 2>, 3001>, 3001> flg;

mint calc(ll pos, ll rest, ll state){
    if(rest == 0){
        return static_cast<ll>(A.size()) - pos + 1;
    }
    if(pos >= A.size()){
        return 0;
    }
    if(rest < 0){ return 0; }
    if(flg.at(pos).at(rest).at(state)){
        return cache.at(pos).at(rest).at(state);
    }

    mint ret = 0;
    if(state == 0){
        ret += calc(pos + 1, rest - A.at(pos), 1) * (pos + 1);
    }else{
        ret += calc(pos + 1, rest - A.at(pos), 1);
    }
    ret += calc(pos + 1, rest, state);

    flg.at(pos).at(rest).at(state) = true;
    cache.at(pos).at(rest).at(state) = ret;
    return ret;
}

void solve(long long N, long long S){
    REP(i, N + 1){
        REP(j, 3001){
            flg.at(i).at(j).at(0) = false;
            flg.at(i).at(j).at(1) = false;
        }
    }
    cout << calc(0, S, 0) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long S;
    scanf("%lld",&S);
    A.resize(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, S);
    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(ll, d, g);
  vector<ll> p(d), c(d);
  rep(i, d) cin >> p[i] >> c[i];
  ll ans = numeric_limits<ll>::max();
  for (int s = 0; s < (1 << d); ++s) {
    ll solved = 0;
    ll score = 0;
    rep(i, d) if ((s >> i) & 1) {
      solved += p[i];
      score += p[i] * 100 * (i + 1) + c[i];
    }
    for (int i = d - 1; i >= 0 && score < g; --i) {
      if ((s >> i) & 1) continue;
      ll score_per_problem = 100 * (i + 1);
      ll problems_to_solve = ((g - score) + score_per_problem - 1) / score_per_problem;
      ll solve = min(problems_to_solve, p[i]);
      solved += solve;
      score += score_per_problem * solve;
      if (solve == p[i]) score += c[i];
    }
    ans = min(ans, solved);
  }
  out(ans);
}

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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

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

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int X; cin >> X;
    int t = X / 500;
    X -= t*500;
    cout << t * 1000 + X / 5 * 5 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


n,m=map(int,input().split())
p=[[] for _ in range(n)]

for i in range(m):
        a,b=map(int,input().split())
        p[a-1].append([b,i])

for i in range(n):
        p[i].sort()
ans=[""]*m
for i in range(n):
        for j in range(len(p[i])):
                ans[p[i][j][1]]=str(i+1).zfill(6)+str(j+1).zfill(6)

for i in range(m):
        print(ans[i])




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

int main(){
	int n;
	scanf("%d", &n);
	int dp[3] = {0};
	for(int i=0; i < n; i++) {
		int new_dp[3] = {0};
		int c[3];
		for(int j=0; j < 3; j++) scanf("%d", &c[j]);
		for(int j=0; j < 3; j++)
			for(int k=0; k < 3; k++)
				if(j != k) new_dp[k] = max(new_dp[k], dp[j] + c[k]);
		for(int j=0; j < 3; j++)
			dp[j] = new_dp[j];
	}
	printf("%d\n", max({dp[0], dp[1], dp[2]}));
}


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

int main(){
	/*input*/
	int n;	cin >> n; 
	vector<int>a(n + 2);
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	/*calculation*/
	vector<int>ans(n + 2);
	for(int i = 1; i <= n + 1; i++){
		ans[i] = ans[i - 1] + abs(a[i] - a[i - 1]);
	}
	/*output*/
	for(int i = 1; i <= n; i++){
		cout << ans[n + 1] - (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i])) + abs(a[i + 1] - a[i - 1]) << endl;
	}
	/*debug*/
	/*
	cout << endl;
	cout << "sum:" << ans[n] << endl;
	for(int i = 0; i < n + 2; i++){
		cout << "a[" << i << "]:" << a[i] << endl;
	}
	for(int i = 0; i < n + 2; i++){
		cout << "ans[" << i << "]:" << ans[i] << endl;
	}
	*/
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int n;
  cin >>n;
  int ans = 0;
  for(int i=0;i*4<=n;i++){
    for(int j=0;i*4+j*7<=n;j++){
      if(i*4+j*7 == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<queue>
#include<vector>
#define MAX 100000000
using namespace std;
typedef pair<int,int> p;
typedef pair<int,p> P;
//G@ê@à
struct edge{
	int to,cost,enem;
};
int main(){
	int n,m,l;
	while(cin>>n>>m>>l,n||m||l){
		vector<edge> tab[110];
		for(int i=0;i<m;i++){
			int a,b,d,e;
			cin>>a>>b>>d>>e;
			a--;
			b--;
			edge pre;
			pre.cost=d;
			pre.enem=e;
			pre.to=b;
			tab[a].push_back(pre);
			pre.to=a;
			tab[b].push_back(pre);
		}
		int d[110][110];
		//d[ê][à]=G;
		for(int i=0;i<n;i++)
		for(int j=0;j<=l;j++){
			d[i][j]=MAX;
		}
		d[0][l]=0;
		priority_queue<P,vector<P>,greater<P> > que;
		que.push(P(0,p(0,l)));
		while(!que.empty()){
			P now=que.top();
			que.pop();
			int nowplace=now.second.first;
			int nowenem=now.first;
			int nowmoney=now.second.second;
			if(d[nowplace][nowmoney]<nowenem)
				continue;
			if(nowplace==n-1)
			break;
			d[nowplace][nowmoney]=nowenem;
			for(int i=0;i<(int)tab[nowplace].size();i++){
				edge e=tab[nowplace][i];
				if(e.cost<=nowmoney&&d[e.to][nowmoney-e.cost]>nowenem){
					d[e.to][nowmoney-e.cost]=nowenem;
					que.push(P(nowenem,p(e.to,nowmoney-e.cost)));
				}
				if(d[e.to][nowmoney]>nowenem+e.enem){
					d[e.to][nowmoney]=nowenem+e.enem;
					que.push(P(nowenem+e.enem,p(e.to,nowmoney)));
				}
			}
		}
		int ans=MAX;
		for(int i=0;i<=l;i++)
		ans=min(ans,d[n-1][i]);
		cout<<ans<<endl;
		
		
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define LEN(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
using ll = long long;
using llu = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod(ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

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

////////////////////////// Solution starts below. //////////////////////////////



int main () {
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.precision(10);
	string s;
	cin >> s;
	if(s[LEN(s)-1] == 's')
		cout << s << "es\n";
	else
		cout << s << "s\n";

	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int cnt=0;
  string a,b="CODEFESTIVAL2016";
  cin>>a;
  for(int i=0;i<a.size();i++){
    if(a[i]!=b[i])cnt++;
  }
  cout<<cnt<<endl;
  return(0);
}


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

int main(){
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	if(a+b*5+c*10+d*50+e*100+f*500>=1000){
	printf("%d\n",1);
 } else{
	 printf("%d\n",0);
 }
}

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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  A.push_back(A[0] + K);
  int dist = 0;
  for (int i = 0; i < N; ++i) {
    dist = max(A[i + 1] - A[i], dist);
  }
  cout << K - dist << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans=0;
    if(n<=111)ans=111;
    else if(n<=222)ans=222;
    else if(n<=333)ans=333;
    else if(n<=444)ans=444;
    else if(n<=555)ans=555;
    else if(n<=666)ans=666;
    else if(n<=777)ans=777;
    else if(n<=888)ans=888;
    else if(n<=999)ans=999;
    cout<<ans<<endl;
    return 0;
}

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

const int MEMO = 10000;
char s[1001][1001];
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int bfs(int h, int w) {
  int ans = -1;
  int d[h][w];
  queue<P> que;
  // すべての点をMEMO(10000)で初期化
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) d[i][j] = MEMO;
  // 全てのスタート地点をキューに入れて0(始点)とする
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        que.push(P(i, j));
        d[i][j] = 0;
      }
    }
  // キューが空になるまでループ
  while (que.size()) {
    // キューの先頭を取り出す
    P p = que.front();
    que.pop();
    // 移動4方向をループ
    for (int i = 0; i < 4; i++) {
      // 移動した後の点を(nx, ny)とする
      int ny = p.first + dy[i], nx = p.second + dx[i];
      // 移動が可能か、最短で移動できるかを判定
      if (0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] != '#' &&
          d[ny][nx] > d[p.first][p.second] + 1) {
        // 移動できるならキューに入れ、その点の距離をpからの距離+1で確定する
        que.push(P(ny, nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }

  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (ans < d[i][j]) ans = d[i][j];

  return ans;  //終わったら終了
}

int main() {
  int h, w, ans;

  cin >> h >> w;

  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }

  //最後に最遅を調べる
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
    }
  }

  ans = bfs(h, w);

  //チェック用
  // for (int i = 0; i < h; i++) {
  //  for (int j = 0; j < w; j++) {
  //    cout << raf[i][j];
  //  }
  //  cout << endl;
  // }

  cout << ans;

  return 0;
}

Measured memory_bytes: 13328
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main() {
  int n, m, sum = 0, a[10000];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum > n) {
    cout << -1 << endl;
  } else {
    cout << n - sum << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n,a[N];
ll ans;
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]),ans+=a[i]/2;
int pre=0;
for (int i=1;i<=n;i++){
if (!a[i]) pre=0;
if (!(a[i]&1)) continue;
if (pre) ans++,pre=0;else pre=i;
}
printf("%lld\n",ans);
return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
using namespace std;

int x, y;
int a[2000][2000];
int c[2000][2000];
int MAX[2000][2002];
int T[2000];
void kaiten() {
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			c[i][j] = a[i][j];
		}
	}
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			a[y - j - 1][i] = c[i][j];
		}
	}
	swap(x, y);
}
signed main() {
	int MIN = INT_MAX;
	cin >> x >> y;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			cin >> a[i][j];
			MIN = min(MIN, a[i][j]);
		}
	}
	int ans = 1000000000;
	for (int i = 0; i < 4; i++) {
		memset(MAX, 0, sizeof(MAX));
		for (int n = x-1; n >= 0; n--) {
			for (int m = 1; m <= y; m++) {
				MAX[n][m] = max({ MAX[n + 1][m], a[n][m - 1],MAX[n][m-1]});
			}
			MAX[n][y + 1] = INT_MAX;
		}
		int S = -1, G = 1000000000;//[S,G)
		while (G - S > 1) {
			int K = (S + G) / 2;
			for (int i = 0; i < x; i++) {
				for (int j = 1; j <= y+1; j++) {
					if (MAX[i][j] > MIN + K) {
						T[i] = j - 1;
						break;
					}
				}
			}
			int l = INT_MAX, r = 0, n = INT_MAX, m = 0;
			for (int i = 0; i < x; i++) {
				for (int j = 0; j < y; j++) {
					if (T[i] > j) {
						l = min(l, a[i][j]);
						r = max(r, a[i][j]);
					}
					else {
						n = min(n, a[i][j]);
						m = max(m, a[i][j]);
					}
				}
			}
			if (max(r - l, m - n) <= K) {
				G = K;
			}
			else {
				S = K;
			}
		}
		ans = min(ans, G);
		kaiten();
	}
	cout << ans << endl;
}

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

int main() {
  // N時間駐車した時の最小の駐車料金を出力
  int N, A, B, T;
  cin >> N >> A >> B ;
  //N = 6, A = 18, B = 100;
  
  T = N * A;

  	if  (T >= B) {
      cout << B << endl;
  	}
  	else {
      cout << T <<endl;
    }
} 

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    cout << accumulate(v.begin(), v.begin() + k, 0) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner r =new Scanner(System.in);
		int w = r.nextInt();
		int h = r.nextInt();
		int x = r.nextInt();
		int y = r.nextInt();
		int z = r.nextInt();
		if(z <= x && x <= (w -z) && z <= y && y <= (h - z)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 17232
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

int N, x;
int a[(int)1e5 + 1];

void solve() {
  ll ans = 0;
  REP(i, N) {
    if (a[i] > x) {
      ans += a[i] - x;
      a[i] -= (a[i] - x);
    }
  }
  FOR(i, 1,  N) {
    if (a[i] + a[i - 1] > x) {
      int t = a[i] + a[i - 1] - x;
      ans += t;
      a[i] -= t;
    }
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> x;
  REP(i, N) {
    cin >> a[i];
  }
  solve();
  return 0;
}


Measured memory_bytes: 640
'use strict'




function Main(input) {
  input = input.trim().split('\n')

  const N = parseInt(input[0])
  const A = input[1].split(' ').map(s => parseInt(s))

  let flg = true
  A.forEach(n => {
    if(n % 2 === 0) {
      if (n % 3 !== 0) {
        if (n % 5 !== 0) {
          flg = false
          return
        }
      }
    }
  })

  if (flg) {
    console.log('APPROVED')
  } else {
    console.log('DENIED')
  }


}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=10005;
const int NN=1000000;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    str ans="No";
    while (n>0){
        if (n%10==7)ans="Yes";
        n/=10;
    }
    cout << ans << E;
    r0;
}
/*














*/


Measured memory_bytes: 3652
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+2];
        A[0] = 0;
        A[N+1] = 0;
        int sum = 0;
        int[][] diff = new int[N+1][2];
        for(int i = 1; i <= N; i++){
            A[i] = sc.nextInt();
            diff[i-1][0] = Math.abs(A[i-1] - A[i]);
            sum += diff[i-1][0];
            if(diff[i-1][0] !=0) diff[i-1][1] = A[i-1] - A[i] <0 ? -1: 1;
        }
        diff[N][0] = Math.abs(A[N]);
        sum += diff[N][0];
        if(diff[N][0] !=0) diff[N][1] = A[N] <0 ? -1: 1;
        for(int i = 1; i <= N; i++){
            if(diff[i-1][1] * diff[i][1] >-1 ) System.out.println(sum);
            else System.out.println(sum - 2*Math.min(diff[i-1][0], diff[i][0]));
        }
        sc.close();
    }

}


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

bool visited[(int) (1e5 + 2)];
int g[(int) (1e5 + 2)];
int dfs(int curr, int c)
{
// cout << "at: " << curr << endl;
    if (curr == 2)
    {
        printf("%d\n", c-1);
        return true;
    }
    if (visited[curr])
    {
        return false;
    }

    visited[curr]  = true;
    return dfs(g[curr], c + 1);
}
int main()
{
    int n;
    cin >> n;
    for (int i=1; i <= n; i++)
    {
        cin >> g[i];
    }
    if (dfs(1, 1))
    {
        return 0;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 4208
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;
const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k, q;
//vector <i64> a;


i64 check(i64 x, i64 k, i64 n) {
    return (k + x / n);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);


    i64 a, b, c;
    cin >> a >> b >> c >> k;

    i64 res = 0;
    while (k) {
        if (a) {
            i64 x = min(a, k);
            res += x;
            a -= x;
            k -= x;
        }
        else if (b) {
            i64 x = min(b, k);
            b -= x;
            k -= x;
        }
        else {
            i64 x = min(c, k);
            c -= x;
            res -= x;
            k -= x;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3192
while True:
    t = int(input())
    if t==0:
        break
    n = (1000-t)//500+((1000-t)%500)//100+((1000-t)%100)//50+((1000-t)%50)//10+((1000-t)%10)//5+((1000-t)%5)
    print(n)



Measured memory_bytes: 5588
def dig(t):
    res = 0
    
    if t == 0:
        return 1
    
    while t > 0:
        t//=10
        res+=1

    return res

n = int(input())

f = 1000000000

for i in range(n+1):
    if i*i > n: break
    if i <= 0 or n%i > 0: continue
    
    f = min(f, max(dig(i), dig(n//i)))
    
print(f)


Measured memory_bytes: 3060