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

int main(){
    //入力
    int64_t a,b,x,ans;
    cin >> a >> b >> x;
    
    ans=b/x-a/x;

    if(a%x==0){
        ans++;
    }

    //出力
    cout << ans << endl;

}

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

int main() {
  string s; cin>>s;
  string ans="YES";
  while(true){
    if(s.size()==0){break;}
    else if(s.size()<5){ans="NO";break;}
    string t= s.substr(0,5);
    if(t=="dream"|| t=="erase"){s.erase(0,5);}
    else{ans="NO";break;}
    if(t=="erase" && s[0]=='r'){s.erase(0,1);}
    if(s.substr(0,5)=="erase"){continue;}
    else if(t=="dream" && s[0]=='e' && s[1]=='r'){s.erase(0,2);}
  }
  cout<<ans;
}
      






Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

const ll MAX = 4000010;

const ll MOD = 1e9 + 7;

long long fac[MAX], finv[MAX], inv[MAX];
 
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 



int main(){
ll N,M,K; cin >> N >> M >> K;
  COMinit();
  
  ll sum = 0;
  
  for(ll i = 0; i < N ; i++){
    for(ll j = 0; j < M; j++){
      if( i == 0 || j == 0){ sum += ( N - i)*( M - j) * ( i + j ) ; sum = sum % MOD;}
      else{ sum += 2 * ( N - i) * ( M - j) * ( i + j) ; sum = sum % MOD;} 
    }}
  
  sum *= COM( N * M - 2, K - 2) ; sum = sum % MOD;
  cout << sum << endl; return 0;}
  
  

Measured memory_bytes: 93952
import java.util.Scanner;

public class Main {

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

		String s = sc.next();
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A') {
				if (s.charAt(i + 1) == 'C') {
					System.out.print("Yes");
					return;
				}
			}
		}
		System.out.print("No");
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;
ll max(ll a, ll b){return a > b ? a : b;}
ll min(ll a, ll b){return a < b ? a : b;}

int mpow(int b, int e)
{
    int ret=1;
    for(int i=0; i<e; i++)
    {
        ret=ret*b%mod;
    }
    return ret;
}

char grid[1001][1001];
ll dp[1001][1001];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    dp[0][1] = 1;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin >> grid[i][j];
            if(grid[i][j]=='.')
            {
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
    }
    cout << dp[n][m];
}
//TODO: 56
//come back to 50D, 55D


Measured memory_bytes: 9088
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	int N; cin >> N;
	vector<int> H(N);
	vector<int> ans(N, 0);
	rep(i, N) {
		cin >> H[i];
		if (i == 0)continue;
		ans[i] += (H[i - 1] >= H[i] ? ans[i - 1] + 1: 0);
	}

	sort(ans.begin(), ans.end(), greater<int>());
	cout << ans[0] << endl;

	return 0;
}


Measured memory_bytes: 3964
import java.util.Scanner;

public class Main {

	static int count = 0;
	
	static void mergeSort(int[] A, int left, int right) {
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(A, left, mid);
			mergeSort(A, mid, right);
			merge(A, left, mid, right);
		}
	}
	
	static void merge(int[] A, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		
		for (int i = 0; i < n1; i++) {
			L[i] = A[left + i];
		}

		for (int i = 0; i < n2; i++) {
			R[i] = A[mid + i];
		}
		
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		
		int i = 0, j = 0;

		for (int k = left; k < right; k++) {
			count++;
			if (L[i] <= R[j]) {
				A[k] = L[i++];
			}
			else {
				A[k] = R[j++];
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int[] S = new int[n];
		for (int i = 0; i < n; i++) {
			S[i] = scan.nextInt();
		}
		
		mergeSort(S, 0, n);

		System.out.print(S[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + S[i]);
		}
		System.out.println("\n" + count);
		
		scan.close();
	}
}

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

int main()
{
    string ans = "Yes";
    int n, h;
    cin >> n;
    vector<int> hi(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> hi[i];
    }

    for (int i = n; i >= 1; i--)
    {
        if (i == n)
        {
            continue;
        }
        else
        {
            if (hi[i] <= hi[i + 1])
            {
                continue;
            }
            else
            {
                if (hi[i] - hi[i + 1] == 1)
                {
                    hi[i] = hi[i] - 1;
                }
                else
                {
                    ans = "No";
                    break;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>

using namespace std;

int main(void){
  int n ;
  cin>>n;
  while(n--){
    vector<vector<char> > in(9,vector<char>(9));
    vector<vector<bool> > ans(9,vector<bool>(9,false));
    vector<vector<int> > usedx(9,vector<int>(9,-1));
    vector<vector<int> > usedy(9,vector<int>(9,-1));
    vector<vector<int> > usedz(9,vector<int>(9,-1));

    for(int i = 0 ; i < 9 ; i ++){
      for(int j = 0 ; j < 9 ; j ++){

	cin>>in[i][j];
	in[i][j] = in[i][j] - '1';
	
	if(usedx[i][in[i][j]] == -1){
	  usedx[i][in[i][j]] = j;
	}else{
	  ans[i][j] = true;
	  ans[i][usedx[i][in[i][j]]] = true ;
	}

	if(usedy[in[i][j]][j] == -1){
	  usedy[in[i][j]][j] = i;
	}else{
	  ans[i][j] = true;
	  ans[usedy[in[i][j]][j]][j] = true;
	}
	
	//cout<<(int)in[i][j]<<" "<<i<<" "<<j<<" "<<i/3*3+j/3<<endl;
	if(usedz[i/3*3+j/3][in[i][j]] == -1){
	  usedz[i/3*3+j/3][in[i][j]] = i*10+j;
	}else{
	  ans[i][j] = true;
	  ans[usedz[i/3*3+j/3][in[i][j]]/10][usedz[i/3*3+j/3][in[i][j]]%10] = true;
	}
      }
    }
    
    for(int i = 0 ; i < 9 ; i ++){
      for(int j = 0 ; j < 9 ; j ++){
	if(ans[i][j])cout<<"*";
	else cout<<" ";
	cout<<(int)in[i][j]+1;
      }
      cout<<endl;
    }
    if(n!=0)cout<<endl;
  }
}

Measured memory_bytes: 1220
/*
AUTHOR : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
*/

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 100050

#define ll long long
#define ld long double
#define lli long long int

#define pb emplace_back
#define INF 1000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define loop(i,n) for (lli i = 0; i < n; i++)
#define loopitr(xt,vec) for (auto xt : vec)
#define FOR(i,a,b) for (lli i = a; i < b; i+=1)
#define loop_rev(i,n) for (lli i = n-1; i >= 0; i--)
#define FOR_REV(i,a,b) for (lli i = a; i >= b; i--)
#define itr :: iterator it
#define WL(t) while(t --)

#define all(v) v.begin(),v.end()
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>
#define vi vector<lli>
#define seti set<lli>
#define pii pair<lli,lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvector(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.push_back(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvector(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";
#define printset(st) for(auto xt : st) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define endl '\n'

#define deb(x) cout<<#x<<" "<<x<<endl;

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}

bool isPrime(lli n){
if(n<=1) return false;
if(n<=3) return true;
if(n==5) return true;
if((n%2==0)||(n%3==0) || (n%5==0)) return false;
for(lli i=5;i*i<=n;i+=6)
    if((n%i==0)||(n%(i+2)==0))
        return false;
return true;
}

bool ispower2(lli n){
    return(n and (n&(n-1))==0 );
}

int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    lli n,k;
    cin>>n;
    lli a[n];
    lli dp[100005]={0};
    lli sum=0;
    loop(i,n){
        cin>>a[i];
        dp[a[i]]++;
        sum+=a[i];
    }
    lli q;
    cin>>q;
    while(q--){
        lli val1 , val2;
        cin>>val1>>val2;
        if(dp[val1]!=0){
            sum-=(val1*dp[val1]);
            sum+=(val2*dp[val1]);
            dp[val2] += dp[val1];
            dp[val1]=0;
            print(sum);
        }
        else
            print(sum);
    }
  }
return 0;
}

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

int main() {
	int n; cin >> n;
	for (int i = 1; i <= 50000; ++i) {
		if ((int)(i * 1.08) == n) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;

	return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;

void solve() {
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    cout << 'x';
  }
  cout << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n + 1), b(n);
	rep(i, n + 1) cin >> a[i];
	rep(i, n) cin >> b[i];
	ll ans = 0;
	rep(i, n) {
		if (b[i] > a[i]) {
			ans += a[i];
			if (b[i]-a[i] <= a[i + 1]) {
				ans += b[i] - a[i];
				a[i + 1] -= b[i] - a[i];
			}
			else {
				ans += a[i + 1];
				a[i + 1] = 0;
			}
		}
		else {
			ans += b[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String S = sc.next();
    	Map<Character, Integer> map = new HashMap<>();
    	for (Character c : S.toCharArray()) {
    		if (map.containsKey(c)) {
    			map.put(c, map.get(c)+1);
    		} else {
    			map.put(c, 1);
    		}
    	}
    	String ans = "Yes";
    	for (Integer count : map.values()) {
    		if (count%2 != 0) {
    			ans = "No";
    		}
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 25172
#include <stdio.h>

//挿入ソート
void insertionSort(int A[], const int N)
{
    int i, j;

    for( i = 0; i < N; ++i ){
        int tmp = A[i];
        for( j = i-1; -1 < j && tmp < A[j]; --j ){
            A[j+1] = A[j];
        }
        A[j+1] = tmp;

        //出力
        for( j = 0; j < N; ++j ){
            printf("%d", A[j]);
            if( j != N-1 ) printf(" ");
        }
        printf("\n");
    }
}

int main()
{
    int i;

    //入力
    int N;
    scanf("%d", &N);
    int A[N];
    for( i = 0; i < N; ++i )
        scanf("%d", &A[i]);

    insertionSort(A, N);

    return 0;
}

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

int main() {
		
	string s; cin >> s;

	int n = s.size() - 1;
	ll ans = 0;
	for (int bit = 0; bit < (1 << n); ++bit) {
		ll tmp = 0;
		for (int i = 0; i < n; ++i) {
			tmp *= 10;
			tmp += (int)(s[i] - '0');
			if (bit & (1 << i)) {
				ans += tmp;
				tmp = 0;
			}
		}
		tmp *= 10;
		tmp += (int)(s.back() - '0');
		ans += tmp;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int n, k;
    long double ans = 0.0;
    int x;
    int i = 1;
    int kakesan;
    bool hantei, hantei1;
    cin >> n >> k;
    do{
        hantei1 = false;
        kakesan = i;
        x = 0;
        do{
            hantei = false;
            if (kakesan < k) {
                x++;
                kakesan *= 2;
                hantei = true;
                hantei1 = true;
            }
        }while(hantei);
        ans += (pow(0.5, x) / n);
        i++;
        if (i > n)  break;
    }while(1);
    printf("%.9Lf\n", ans);
    return (0);
}

Measured memory_bytes: 384
#include<string> 
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
  string S;
  int Q;
  cin >> S;
  cin >> Q;
  int rev = 0;
  string Head; 
  string Tail;
  for (int i = 0; i < Q; i++){
    int T;
    int F;
    string C;
    cin >> T;
    if (T == 1){
      rev = 1 - rev;
    }
    if (T == 2){
      cin >> F >> C;
      if (rev){
        if (F == 1){
          Tail = Tail + C;
        }else{
          Head = C + Head;
        }
      }else{
        if (F == 1){
          Head = C + Head;
        }else{
          Tail = Tail + C;
        }
      }
    }
  }
  if (rev) {
    S = Head + S + Tail;
    reverse(S.begin(),S.end());
  }else{
    S = Head + S + Tail;
  }
  
  cout << S << endl;
}

Measured memory_bytes: 1512
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int cnt = 0;
    rep(i, A+1) {
        rep(j, B+1) {
            rep(k, C+1) {
                if (i * 500 + j * 100 + k * 50 == X) cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int 
#define NA(i,s,n) for(lli i=s; i<n; ++i)

lli nc2(lli n, lli ind, vector<lli> &rs){
    rs[ind] = (n*(n-1))/2;
    return rs[ind];
}
lli nc2(lli n){
    if(n<0) return 0;
    return (n*(n-1))/2;
}
int main(){
    lli n,tp,res=0; cin>>n;
    vector<lli> a(n+1),ct(n+1,0),rs(n+1);
    NA(i,1,n+1) cin>>a[i], ct[a[i]]++;
    NA(i,1,n+1) res+=nc2(ct[i], i, rs);
    // NA(i,1,n+1) cout<<rs[i]<<' '; cout<<'\n';
    // NA(i,1,n+1) cout<<ct[i]<<' ';
    // cout<<'\n'<<res;
    NA(i,1,n+1){
        tp = res - rs[a[i]] + nc2(ct[a[i]]-1);
        cout<<tp<<'\n';
    }
    return 0;
}


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

int main() {
  int Top, South, East, tmp, sum;
  int  n;
  char direction[6];
  while (true) {
    Top = 1;
    South = 2;
    East = 3;
    sum = 1;
    cin >> n;
    if (n==0) {
      break;
    }
    for (int i=0; i<n; i++) {
      cin >> direction;
      switch (direction[0]) {
      case 'N':
        tmp = Top;
        sum += Top = South;
        South = 7-tmp;
        break;
      case 'E':
        tmp = East;
        East = Top;
        sum += Top = 7-tmp;
        break;
      case 'W':
        tmp = Top;
        sum += Top = East;
        East = 7-tmp;
        break;
      case 'S':
        tmp = South;
        South = Top;
        sum += Top = 7-tmp;
        break;
      case 'R':
        tmp = South;
        South = East;
        East = 7-tmp;
        sum += Top;
        break;
      case 'L':
        tmp = East;
        East = South;
        South = 7-tmp;
        sum += Top;
      default:
        break;
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3080
import java.math.BigDecimal;
import java.util.*;

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

        int n = sc.nextInt();
        BigDecimal ans = new BigDecimal(1);

        BigDecimal[] a = new BigDecimal[n];
        for(int i = 0; i < n; i++){
            a[i] = new BigDecimal(sc.nextLong());
            if(a[i].equals(new BigDecimal(0))){
                System.out.println(0);
                return;
            }
        }

        for(int i = 0; i < n; i++){
            ans = ans.multiply(a[i]);
            if(ans.compareTo(new BigDecimal(1000000000000000000L)) > 0){
                System.out.println(-1);
                return;
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 65664
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

n,m=map(int,input().split())
A=list(map(int,input().split()))
dp=[inf]*(n+1)
dp[0]=0
for a in A:
    for i in range(a,n+1):
        dp[i]=min(dp[i],dp[i-a]+1)
print(dp[n])



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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
// const int inf = 1e9;
const int inf = 1e18;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

int f(int b, int n) {
    if (n < b) return n;
    return f(b, n / b) + n % b;
}

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

    int n, s;
    cin >> n >> s;

    if (n == s) {
        cout << n + 1ll << endl;
        return 0;
    }

    // b <= sqrt(n) は全探索
    for (int b = 2ll; b * b <= n; b++) {
        if (f(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }

    // b > sqrt(n)のとき
    // nはb進数で高々2桁なので、
    // n = pb+q
    // s = p+q
    // -> n-s = p(b-1)
    // ∴ bはn-sの約数+1
    int ans = inf;
    for (int d = 1ll; d * d <= n - s; d++) {
        if ((n - s) % d == 0ll) {
            int b = d + 1ll;
            if (f(b, n) == s) {
                ans = min(ans, b);
            }
            b = (n - s) / d + 1ll;
            if (f(b, n) == s) {
                ans = min(ans, b);
            }
        }
    }

    cout << (ans == inf ? -1 : ans) << endl;
}


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"atcoder"# => r#"acdr"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: chars,
    }

    let mut ans = "".to_string();
    for i in 0..s.len() {
        if i % 2 == 0 {
            ans.push_str(&s[i].to_string());
        }
    }
    ans.to_string()
}

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

int main() {
  int N, M, X;

  vector<int> c(N_MAX);
  vector<vector<int>> a(N_MAX, vector<int> N_MAX);
  const int INF = 1001001001;
  int res = INF;
  cin >> N >> M >> X;

  rep(i,N){
  	cin >> c.at(i);
    rep(j,M) cin >> a.at(i).at(j);
  }
  
  rep(tmp,1<<N){
    int sum = 0;
    vector<int> rikaido(M); 
    bitset<N_MAX> index(tmp);
    bool ok = true;

    rep(i,N){
      if(index.test(N-i-1)){
        rep(j,M) rikaido.at(j) += a.at(i).at(j);
        sum += c.at(i);
      }
    }
   
    rep(i,M){
      if(rikaido.at(i) < X){
        ok = false;
      }
    }

    if(ok){
      res = min(res, sum);
    }
  }

  if(res == INF) cout << "-1" << endl;
  else cout << res << endl;
  return 0;
}

Measured memory_bytes: 3644
def productall(a):
    N = len(a)
    if N == 0: return [1]
    A = [1] * N + a[:]
    P = 10 ** 9 + 7
    k = 12
    K = k * 8
    pa1 = (1 << k * 4 + 16) - ((1 << k * 4 + 16) % P)
    pa2 = (1 << k * 2 + 24) - ((1 << k * 2 + 24) % P)
    pa3 = (1 << k + 28) - ((1 << k + 28) % P)
    def modP(x):
        x -= ((x & m1) >> k * 4 + 16) * pa1
        x -= ((x & m2) >> k * 2 + 24) * pa2
        x -= ((x & m3) >> k + 28) * pa3
        return x
    
    c = 3
    m1 = int(("1" * (k * 4 - 16) + "0" * (k * 4 + 16)) * c, 2)
    m2 = int(("1" * (k * 6 - 24) + "0" * (k * 2 + 24)) * c, 2)
    m3 = int(("1" * (k * 7 - 28) + "0" * (k + 28)) * c, 2)
    for i in range(1, N)[::-1]:
        if i == 1 << i.bit_length() - 1:
            c *= 2
            m1 = int(("1" * (k * 4 - 16) + "0" * (k * 4 + 16)) * c, 2)
            m2 = int(("1" * (k * 6 - 24) + "0" * (k * 2 + 24)) * c, 2)
            m3 = int(("1" * (k * 7 - 28) + "0" * (k + 28)) * c, 2)
        A[i] = modP(A[2*i] * A[2*i+1])

    t = bin(A[1])[2:] + "_"
    return [int(t[-(i+1) * K - 1:-i * K - 1], 2) % P for i in range((len(t)+K-2) // K)]
def par(a):
    L = []
    while P[a] != a:
        L.append(a)
        a = P[a]
    for l in L:
        P[l] = a
    return a
def unite(a, b):
    pa = par(a)
    pb = par(b)
    if pa == pb: return
    if LEN[pa] < LEN[pb]:
        a, b, pa, pb = b, a, pb, pa
    P[pb] = pa
    if LEN[pa] == LEN[pb]: LEN[pa] += 1
    CNT[pa] += CNT[pb]
def cnt(a):
    return CNT[par(a)]

N = int(input())
P = [i for i in range(N)]
LEN = [1] * N
CNT = [1] * N
FULL = [0] * N
A = [int(a) - 1 for a in input().split()]
for i, a in enumerate(A):
    if a < 0: continue
    if par(i) != par(a):
        unite(i, a)
    else:
        FULL[i] = 1
for i in range(N):
    if FULL[i]:
        FULL[par(i)] = 1
X = []
Y = []
for i in range(N):
    if par(i) == i:
        if FULL[i] == 0:
            X.append(CNT[i])
        else:
            Y.append(CNT[i])
M = len(X)
mod = 10 ** 9 + 7
ans = (sum(X) + sum(Y) - len(Y)) * pow(N - 1, M, mod) % mod
L = productall([(a << 96) + 1 for a in X])
fa = 1
if M: ans = (ans + M * pow(N - 1, M - 1, mod)) % mod
for i, l in enumerate(L):
    if i == 0: continue
    ans = (ans - l * fa * pow(N - 1, M - i + mod - 1, mod)) % mod
    fa = fa * i % mod
print(ans)

Measured memory_bytes: 14924
#include<stdio.h>
#include<string.h>
#include<queue>
const int N=26;
int a[N][N]={0},c,b[N];
int F()
{
	int i,j,x;
	for(i=0;i<N;++i)
	{
		for(x=j=0;j<N;++j)
			x+=a[i][j]-a[j][i];
		if(x)return 0;
	}
	int v[N]={0};
	std::queue<int>q;
	q.push(c);
	while(q.size())
	{
		x=q.front(),q.pop();
		if(v[x])continue;
		v[x]=1;
		for(i=0;i<N;++i)if(a[x][i])q.push(i);
	}
	for(i=0;i<N;++i)if(b[i]&&!v[i])return 0;
	return 1;
}
int main()
{
	int n,i,j;
	char s[64];
	while(scanf("%d",&n),n)
	{
		for(i=0;i<N;b[i]=0,++i)for(j=0;j<N;++j)a[i][j]=0;
		for(i=0;i<n;++i)
			scanf("%s",s),
			a[c=s[0]-'a'][s[strlen(s)-1]-'a']++,
			b[c]++;
		puts(F()?"OK":"NG");
	}
	return 0;
}

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

bool cmp(int a, int b)
{
	return abs(a) < abs(b);
}

int main()
{
	int n, l;
	cin >> n >> l;
	int *a = new int[n];
	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		a[i] = l + i;
	}
	sort(a, a + n,cmp);
	for (int i = 1; i < n; ++i)
		sum += a[i];
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

vector<vector<int> > vec;

int main(){
  int n,m; cin >> n >> m;
  vec.resize(100010);
  rep(i,n){
    int a,b;
    cin >> a >> b;
    vec[a].push_back(b);
  }
  priority_queue<int> que;
  ll ans=0;
  for(int i=1;i<=m;i++){
    rep(j,vec[i].size()) que.push(vec[i][j]);
    if(que.size()){
      ans+=que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5632
#include <iostream>
using namespace std;
int main(){
  int n,i;
  int temp;
  double ans = 100;
  cin >> n;
  for(i = 0;i < n;i++){
    ans *= 1.05;
    temp = (int)ans;
    if((double)temp != ans){
      ans = (double)temp + 1;
    }
  }
  cout << ans << "000" << endl;
  return(0);
}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a; cin >> a;
    int s = a+ a*a+a*a*a;
    cout << s << endl;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define N 2005

vector<vi> g;
int cnt[N];
int n, x, y;

void bfs(int v) {
	int d[N];
	CL(d, -1);
	d[v] = 0;
	deque<int> q;
	q.push_back(v);

	while (sz(q)) {
		int top = q.front();
		q.pop_front();

		REP(i, sz(g[top])) {
			int u = g[top][i];
			if (d[u] == -1) {
				d[u] = d[top] + 1;
				q.push_back(u);
			}
		}
	}

	REP(i, n) {
		cnt[d[i]]++;
	}
}

int main(void) {
	scanf("%d%d%d", &n, &x, &y);
	x--, y--;
	g.resize(n);
	FOR(i, 1, n) {
		g[i - 1].pb(i);
		g[i].pb(i - 1);
	}
	g[x].pb(y);
	g[y].pb(x);

	REP(i, n) {
		bfs(i);
	}

	FOR(i, 1, n) {
		printf("%d\n", cnt[i] / 2);
	}
	//scanf("%d", &n);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;


ll n, m, x,ans=0, sum =0, MIN = LINF;

vector<vector<ll>> p(12, vector<ll>(12));
vector<ll> c(n);

vector<ll> buf;

void dfs(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
        vector<ll> skill(12);
        for(ll i = 0; i < n; ++i){
            if(buf[i]==1){
                sum += c[i];
                for(ll k = 0; k < m; ++k){
                    skill[k] += p[i][k];
                }
            }
        }
        
        bool judge = true;
        
        rep(k,m){
            if(skill[k] <x) judge = false;
        }
        
        if(judge){
            MIN = min(MIN, sum);
        }
        sum = 0;
        //cout << endl;
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            dfs(i + 1, size, range_start, range_end);
        }
    }
}


int main()
{

    cin>>n>>m>>x;
    c.resize(n);
    
    for(ll i = 0; i<n; i++){
        cin>>c[i];
      for(ll j = 0; j<m; j++){
          cin>>p[i][j];
      }
    }
    
    ll size = n;
    ll range_start = 0;
    ll range_end = 1;
    
    buf.resize(size);
    dfs(0, size, range_start, range_end);
    
    
    if(MIN ==LINF) MIN = -1;
    
    cout<<MIN<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9
#define common cout << "Case #" << w+1 << ": "  

int r,c,k;
map<pair<int,int>,int>m;
vector<vector<lli> >v,dp;

int main()
{
    fastio;
    cin >> r >> c >> k;
    for(int i=0;i<k;i++)
    {
        int x,y,z;
        cin >> x >> y >> z;
        x-=1;y-=1;
        m[{x,y}]=z;
    }
    v.resize(r);
    dp.resize(r);
    for(int i=0;i<r;i++)
    {
        v[i].resize(c);
        dp[i].resize(c);
    }
    for(int i=0;i<r;i++)
    {
        multiset<int,greater<int> >t;
        for(int j=0;j<c;j++)
        {
            if(m.find({i,j})!=m.end())
                t.insert(m[{i,j}]);
            int x=-1,y=-1,z=-1;
            if(t.size()>0)
            {
                x=*t.begin();
                t.erase(t.begin());
            }
            if(t.size()>0)
            {
                y=*t.begin();
                t.erase(t.begin());
            }
            if(t.size()>0)
            {
                z=*t.begin();
                t.erase(t.begin());
            }
            lli tot=0;
            if(x!=-1)
            {
                tot+=x;
                t.insert(x);
            }
            if(y!=-1)
            {
                tot+=y;
                t.insert(y);
            }
            if(z!=-1)
            {
                tot+=z;
                t.insert(z);
            }
            v[i][j]=tot;
        }
        break;
    }
    for(int i=0;i<c;i++)
        dp[0][i]=v[0][i];
    for(int i=1;i<r;i++)
    {
        multiset<lli,greater<lli> >t0,t1,t2,t3;
        for(int j=0;j<c;j++)
        {
            lli a=dp[i-1][j];
            t0.insert(a);
            if(m.find({i,j})!=m.end())
            {
                lli x=-1,y=-1,z=-1;
                x=*t0.begin()+m[{i,j}];
                if(t1.size()>0)
                    y=*t1.begin()+m[{i,j}];
                if(t2.size()>0)
                    z=*t2.begin()+m[{i,j}];
                t1.insert(x);
                if(y!=-1)
                    t2.insert(y);
                if(z!=-1)
                    t3.insert(z);
            }
            lli x=-1;
            if(t0.size()>0)
                x=max(x,*t0.begin());
            if(t1.size()>0)
                x=max(x,*t1.begin());
            if(t2.size()>0)
                x=max(x,*t2.begin());
            if(t3.size()>0)
                x=max(x,*t3.begin());
            if(x!=-1)
                dp[i][j]=x;
            else
                dp[i][j]=0;
        }
    }
    // for(int i=0;i<r;i++)
    // {
    //     for(int j=0;j<c;j++)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    cout << dp[r-1][c-1] << endl;
}


Measured memory_bytes: 157132
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());

		boolean  b = false;
		while(N / 10 > 0) {
			if(N % 10 == 7) {
				b = true;
				break;
			} else {
				N = N / 10;
			}
		}

		if(b || N == 7) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35660
local n = io.read("*n")
local edge = {}
local len = {}
for i = 1, n do
  edge[i] = {}
  len[i] = -1
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  edge[a][b], edge[b][a] = true, true
end
local tasks = {1}
len[1] = 0
for i = 1, n do
  local src = tasks[i]
  for dst, _u in pairs(edge[src]) do
    if len[dst] < 0 then
      len[dst] = len[src] + 1
      table.insert(tasks, dst)
    end
  end
end
local startpos = 1
for i = 2, n do
  if len[startpos] < len[i] then
    startpos = i
  end
end
tasks = {startpos}
for i = 1, n do
  len[i] = -1
end
len[startpos] = 0
for i = 1, n do
  local src = tasks[i]
  for dst, _u in pairs(edge[src]) do
    if len[dst] < 0 then
      len[dst] = len[src] + 1
      table.insert(tasks, dst)
    end
  end
end
local maxlen = 0
for i = 1, n do
  if maxlen < len[i] then maxlen = len[i] end
end
print(maxlen % 3 == 1 and "Second" or "First")


Measured memory_bytes: 30832
#include<cstdio>

using namespace std;

char win(char x){
    if (x == 'r') return 'p';
    else if (x == 's') return 'r';
    else if (x == 'p') return 's';
}

int point(char x, int r, int s, int p){
    if (x == 'r') return r;
    else if (x == 's') return s;
    else if (x == 'p') return p;
}

int main(){
    int n, k;
    int r, s, p;
    scanf("%d %d", &n, &k);
    scanf("%d %d %d", &r, &s, &p);
    char t[n+1];
    scanf("%s", t);
    int a[n];
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(i < k){
            a[i] = win(t[i]);
            ans += point(win(t[i]), r, s, p);
        }else{
            if(a[i-k] != win(t[i])){
                a[i] = win(t[i]);
                ans += point(win(t[i]), r, s, p);
            }else if(i + k < n){
                a[i] = 'o';
            }
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <limits>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using ll=long long;
using pl  = pair<ll,ll>;
using pii  = pair<int,int>;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

string S;
ll dp[2][107][4],K;

int main(){
  cin >> S >> K;
  rep(i,S.size()){
    ll C=ctoi(S[i]);
    if(i==0){
      dp[0][0][1]=1;
      dp[1][0][0]=1;
      dp[1][0][1]=C-1;
      continue;
    }
    if(C==0){
      dp[0][i][0]=dp[0][i-1][0];
      dp[0][i][1]=dp[0][i-1][1];
      dp[0][i][2]=dp[0][i-1][2];
      dp[0][i][3]=dp[0][i-1][3];
      dp[1][i][0]=dp[1][i-1][0];
      dp[1][i][1]=dp[1][i-1][0]*9+dp[1][i-1][1];
      dp[1][i][2]=dp[1][i-1][1]*9+dp[1][i-1][2];
      dp[1][i][3]=dp[1][i-1][2]*9+dp[1][i-1][3];
    }
    else{
      dp[0][i][1]=dp[0][i-1][0];
      dp[0][i][2]=dp[0][i-1][1];
      dp[0][i][3]=dp[0][i-1][2];
      dp[1][i][0]=dp[1][i-1][0];
      dp[1][i][1]=dp[1][i-1][0]*9+dp[1][i-1][1]+dp[0][i-1][0]*(C-1)+dp[0][i-1][1];
      dp[1][i][2]=dp[1][i-1][1]*9+dp[1][i-1][2]+dp[0][i-1][1]*(C-1)+dp[0][i-1][2];
      dp[1][i][3]=dp[1][i-1][2]*9+dp[1][i-1][3]+dp[0][i-1][2]*(C-1)+dp[0][i-1][3];
    }
  }
  cout << dp[0][S.size()-1][K]+dp[1][S.size()-1][K] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int N,M;
    int i;
    int A;
    int total=0;

    scanf("%d %d\n", &N, &M);

    for( i = 1; i <= M; i++ ){
        scanf("%d", &A);
        total += A;
    }

    if( N >= total ){
        printf("%d\n", N-total);
    }
    else{
        printf("-1\n");
    }

    return 0;
}


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

struct Error {
  template<class T1, class T2> Error& operator << (pair<T1,T2> p) {
    return *this << "(" << p.first << ", " << p.second << ")";
  }
  template<class T1> typename enable_if<is_scalar<T1>::value || is_same<T1,string>::value, Error&>::type operator << (T1 a) {
    cerr << boolalpha << a; 
    return *this;
  }
  template<class T1> typename enable_if<!is_scalar<T1>::value && !is_same<T1,string>::value, Error&>::type operator << (T1 a) {
    *this << "{";
    for (auto it = a.begin(); it != a.end(); it++) {
      if (it != a.begin()) 
        *this << ", ";
      *this << *it;
    }
    return *this << "}";
  }
  template<class T1, class T2, class T3> Error& operator << (tuple<T1,T2,T3> t) {
    return *this << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ")";
  }
  template<class T1, class T2, class T3, class T4> Error& operator << (tuple<T1,T2,T3,T4> t) {
    return *this << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ", " << get<3>(t) << ")";
  }
  template<class T1> Error& operator << (queue<T1> q) {
    vector<T1> v;
    while (!q.empty()) {
      v.push_back(q.front());
      q.pop();
    }
    return *this << v;
  }
  template<class T1> Error& operator << (stack<T1> s) {
    vector<T1> v;
    while (!s.empty()) {
      v.push_back(s.top());
      s.pop();
    }
    return *this << v;
  }
};

#define err Error()
#define aty(x) #x << " : " << x 

template<class T1> void dout(string name, T1 a) {
  err << name << " : " << a << "\n";
}

template<class T1, class... T2> void dout(string names, T1 a, T2... args) {
  err << names.substr(0, names.find(",")) << " : " << a << " | ";
  dout(names.substr(names.find(",") + 2), args...);
}

#ifdef LOCAL
#define debug(...) dout(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  partial_sum(b.begin(), b.end(), b.begin());
  int ans = upper_bound(b.begin(), b.end(), k) - b.begin();
  // cout << (int) (upper_bound(b.begin(), b.end(), 80) - b.begin()) << endl;
  ll sm = 0;
  for (int i = 0; i < n; ++i) {
    sm += a[i];
    debug(sm, ans, i);
    if (sm <= k) {
      ans = max(ans, i + 1 + (int)(upper_bound(b.begin(), b.end(), k - sm) - b.begin()));
    }
    else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6368
#include<stdio.h>

int main(){
int a,b,c;

scanf("%d %d %d",&a,&b,&c);
if(a < b){
	if(b < c){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}else{
	printf("No\n");
}
return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
int main() {
	int x = input(), k = 3;
	vector<int>v; v.push_back(2);
	while (v.back() < x) {
		bool b = 1;
		for (int p : v)if (k % p == 0) { b = 0; break; }
		else if (p * p > k)break;
		if (b)v.push_back(k); k += 2;
	}
	cout << v.back() << endl;
}

Measured memory_bytes: 384
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]): Unit = {

    val n: Int = readLine().toInt
    val ps: Vector[Int] = (1 to n).map(_ => readLine().toInt).toVector
    val ans = sum(ps) - max(ps) / 2
    println(ans)

  }

  def sum(v: Vector[Int]): Int =
    v.foldLeft(0)((ans, x) => ans + x)

  def max(v: Vector[Int]): Int =
    v.foldLeft(v(1))((ans, x) => ans max x)

}


Measured memory_bytes: 25292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e,A,B,C,D,E,t,n,ans;
cin >> a >> b >> c >> d >> e;
if (a%10==0) {A=a/10; a=9;n=n+1;}
else A=a/10+1;
if (b%10==0) {B=b/10; b=9;n=n+1;}
else B=b/10+1;
if (c%10==0) {C=c/10; c=9;n=n+1;}
else C=c/10+1;
if (d%10==0) {D=d/10; d=9;n=n+1;}
else D=d/10+1;
if (e%10==0) {E=e/10; e=9;n=n+1;}
else E=e/10+1;
t=min(a%10,b%10); t=min(t%10,c%10);  t=min(d%10,t%10);  t=min(e%10,t%10);
if (n==5) t=10;
ans=(A+B+C+D+E)*10-10+t;
cout << ans << endl;
}

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

class Program
{    public static void Main()
    {
        var t = Console.ReadLine().Split(' ');
        int N = int.Parse(t[0]);
        int X = int.Parse(t[1]);
        t = Console.ReadLine().Split(' ');
        int[] L = new int[N];
        for (int i = 0; i < N; i++)
            L[i] = int.Parse(t[i]);

        int p = 0, ctr = 0;
        for (int i = 0; i < N; i++)
        {
            if (p <= X)
                ctr++;
            p += L[i];
        }
        if (p <= X)
            ctr++;
        Console.WriteLine(ctr);
    }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
#define accum(x) accumulate((x).begin(), (x).end(), 0)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int mod = 1e9 + 7;

ll powmod(ll x, ll y) {
  ll res = 1;
  rep(i, 0, y) res = res * x % mod;
  return res;
}

int main() {
  int n;
  cin >> n;
  ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
  ans %= mod;
  ans = (ans + mod) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588