akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main() {
	long long int a, b, c; 
	scanf("%lld%lld%lld", &a, &b, &c);
	long long int sum = b;
	if(c <= a + b + 1) sum += c;
	if(c > a + b + 1) sum += a + b + 1;
	printf("%lld", sum);
	
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N = int(input())

    A = [None]
    for _ in range(N):
        A.append(int(input()))

    pressed = [False] * (N+1)
    button = 1
    cnt = 0
    while not pressed[button]:
        pressed[button] = True
        cnt += 1
        button = A[button]
        if button == 2:
            print(cnt)
            return

    print(-1)

if __name__ == "__main__": main()


Measured memory_bytes: 8568
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <string>

using namespace std;

#define int long long

struct qqq
{
    int a, b, c, d;
    qqq(){};
    qqq(int a, int b, int c, int d): a(a), b(b), c(c), d(d){};
};

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int a, b, n;
    cin >> a >> b >> n;
    int last;
    if (n > b)
    {
        last = n / b * b - 1;
    }
    else if (n == b)
    {
        last = b - 1;
    }
    else
    {
        last = (n * a / b * b + a - 1) / a;
    }
    cout << (a * last) / b - (last / b) * a;
}

Measured memory_bytes: 3556
S = input ()
 
if S == 'SUN':
    print(7)
 
elif S == 'MON':
    print(6)
 
elif S == 'TUE':
    print(5)
 
elif S == 'WED':
    print(4)
 
elif S == 'THU':
    print(3)
 
elif S == 'FRI':
    print(2)
 
elif S == 'SAT':
    print(1)


Measured memory_bytes: 9048
N=int(input())
ad_ma=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    nums=list(map(lambda x:int(x)-1,input().split()))
    f=nums[0]
    nums=nums[2:]
    for num in nums:
        ad_ma[f][num]=1
 
  
for i in range(N):
    for j in range(N):
        if(j!=N-1):
            print(ad_ma[i][j],end=' ')
        else:
            print(ad_ma[i][j])


Measured memory_bytes: 6392
#include <bits/stdc++.h>
#define int long long int
#define ld long double
#define pb push_back
#define pf push_front
#define ft first
#define sc second
#define all(v) v.begin(), v.end()
using namespace std;
const int maxn = 3010, mod = 998244353;
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int d = 0; d < m; d++) {
        int a;
        cin >> a;
        n -= a;
    }
    if (n < 0) {
        cout << -1;
    } else {
        cout << n;
    }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    ll ansn = a[n-1];
    ll ansr = 0;
    for(ll i=0;i<n-1;++i){
        if(max(ansn - ansr, ansr) - min(ansn - ansr, ansr) > max(ansn - a[i], a[i]) - min(ansn - a[i], a[i])){
            ansr = a[i];
        }
    }
    cout<<ansn<<' '<<ansr<<endl;

    return 0;
}

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

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    
    ll x, y, z;
    x = y = z = 1;
    rep(i,n) {
        x *= 10;
        y *= 9;
        z *= 8;
        
        x %= mod;
        y %= mod;
        z %= mod;
    }
    
    ll ans = (x - y - y + z) % mod;
    
    if(ans < 0)
        ans += mod;
    
    cout << ans << endl;
    
    
    return 0;
}




Measured memory_bytes: 3620
#include <stdio.h>

int main(){
    int N, a[100000], num[100001], i, cnt, max=0;

    scanf("%d", &N);

    for(i=0; i<100001; i++)
        num[i] = 0;

    for(i=0; i<N; i++){
        scanf("%d", &a[i]);
        num[a[i]] += 1;
    }

    for(i=1; i<100001; i++){
        cnt = 0;
        cnt += num[i-1];
        cnt += num[i];
        cnt += num[i+1];

        if(max < cnt)
            max = cnt;
    }

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

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()



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



int main() {
    ll n;
    cin >> n;
    int x = n % 10;
    string unit;
    if(x == 3){
        unit = "bon";
    } else if (x == 0||x == 1 || x == 6 || x == 8 ){
        unit ="pon";
    }else{
        unit = "hon";
    }
    cout << unit << endl;
}


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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = inputs[0];
        var m = inputs[1];
        var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        var sum = a.Sum();

        if (sum > n) Console.WriteLine("-1");
        else
        {
            var ans = n - sum;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 29164
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  ll d = 1e9+7;
  int zero = 0;
  vector<int> vec(1e5+1, 0);
  rep(i, n) {
    int x;
    cin >> x;
    vec[x]++;
  }
  int l = n - 1;
  bool ok = true;
  int cnt = 0;
  while(l > 0) {
    cnt++;
    if (vec[l] != 2) {
      ok = false;
      break;
    }
    l -= 2;
  }
  if (n%2 && vec[0] != 1) {
    ok = false;
  }
  if (ok) {
    ll ans = 1;
    rep(i, cnt) {
      ans *= 2;
      ans %= d;
    }
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
#define INF 1010101010
#define MOD 1000000007
#define LL long long

int main() {
    vector<int> abc(3);
    for (auto& e: abc) cin >> e;

    sort(abc.begin(), abc.end());
    
    cout << (abc[0]+abc[1] == abc[2] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int main(){
 
    string s;

    REP(i,3){
        cin>>s;
        s[0]-=32;
        cout<<s[0];
    
    }
    cout<<endl;
    //cout<<s<<endl;
    // stringstream is(s);
    // string t;
    // char delim=' ';
    // while(getline(is,t,delim)){
    //     cout<<t[0]<<endl;
    // }
}



Measured memory_bytes: 256
#include<iostream> //cinなど
#include<string> //文字列
#include<algorithm> //sort など
#include<math.h> //paw(冪乗など)
#include<set> // 集合
#include<map> //写像
#include<stdio.h> //printf
#include<stack>

using namespace std;
int main(){
  int x;
  cin>>x;
  if (x<1200){
    cout<<"ABC"<<endl;
  }else{
    cout<<"ARC"<<endl;
  }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=32000;
const ll MOD=1e9+7;

ll adm(ll a, ll b){
	if(a+b<MOD)return a+b;
	else return a+b-MOD;
}

ll tim(ll a, ll b){
	return (a*b)%MOD;
}

int N,K;
void input(){
	cin>>N>>K;
}

int s,t;
ll dp1[105][MAX];
ll dp2[105][MAX];
ll tmp[105];

void solve(){
	s=sqrt(N);
	if(N<s*(s+1))t=s-1;
  	else t=s;
	ll mul[MAX];
	rep1(i,s)mul[i]=(ll)N/i-N/(i+1);
 	
  	if(t==s-1){
		rep1(i,s)dp1[1][i]=1;
		rep1(i,s)dp2[1][i]=1;
		
		rep1(k,K-1){
			rep1(i,s)dp2[k+1][i]=adm(dp2[k+1][i-1], dp1[k][i]);
			dp1[k+1][s]=dp2[k+1][s];
			for(int i=s-1; i>=1; i--){
				dp1[k+1][i]=adm(dp1[k+1][i+1], tim(dp2[k][i],mul[i]));
   	    	 }
		}
		ll ans=0;
		rep1(i,t)ans=adm(ans, dp1[K][i]);
		rep1(i,s)ans=adm(ans, tim(dp2[K][i], mul[i]));
		cout<<ans<<endl;
	}
	
	else{
		rep1(i,s)dp1[1][i]=1;
		rep1(i,s)dp2[1][i]=1;
		
		rep1(k,K-1){
			rep1(i,s)dp2[k+1][i]=adm(dp2[k+1][i-1], dp1[k][i]);
			dp1[k+1][s]=adm(dp2[k+1][s], tim(mul[s],dp2[k][s]));
			for(int i=s-1; i>=1; i--){
				dp1[k+1][i]=adm(dp1[k+1][i+1], tim(dp2[k][i],mul[i]));
   	    	 }
		}
		ll ans=0;
		rep1(i,s)ans=adm(ans, dp1[K][i]);
		rep1(i,s)ans=adm(ans, tim(dp2[K][i], mul[i]));
		cout<<ans<<endl;
	}
}


int main(){
  input();
  solve();
  /*
  rep1(i,s)cout<<dp1[3][i]<<" ";
  cout<<endl;
  rep1(i,s)cout<<dp2[3][i]<<" ";
  cout<<endl;
  
  rep1(i,s)cout<<dp1[2][i]<<" ";
  cout<<endl;
  rep1(i,s)cout<<dp2[2][i]<<" ";
  cout<<endl;
  */
}

Measured memory_bytes: 51712
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

signed main()
{
  string s; cin >> s;
  string ans;
  REP(i, s.size()) {
    if (ans == "") {
      if (s[i] == 'C') ans += "C";
    } else if (ans == "C") {
      if (s[i] == 'F') {
        ans += "F";
        break;
      }
    }
  }
  print(ans == "CF" ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 256
#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 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
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[4] ={1,0,-1,0} , dy[4] ={0,1,0,-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;
    }
};


ll gcd(ll a,ll b){
    if(b ==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g =gcd(a,b);
    return a/g*b;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    ll n;
    string s[200010];
    map<string,ll> mp;
    cin>>n;
    ll m=0;
    rep(i,n){
        cin>>s[i];
        mp[s[i]]++;
        chmax(m,mp[s[i]]);
    }
    vector<string> v;
    for(auto i:mp){
        if(i.sc==m){
            v.pb(i.fi);
        }
    }
    sort(all(v));
    rep(i,(ll)v.size()){
        cout<<v[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 27120
n,m = map(int,input().split())
switch = []
for i in range(m):
    temp = list(map(int,input().split()))
    switch.append(temp)
p = list(map(int,input().split()))

ans = 0
for i in range(2**n):
    test = list(bin(i))
    test.pop(0)
    test.pop(0)
    for k in range(n-len(test)):
        test.insert(0,"0")
    temp = True
    for k in range(m):
        counter = 0
        for j in range(switch[k][0]):
            if test[switch[k][j+1]-1] == "1":
                counter += 1
        if p[k] != counter%2:
            temp = False
            break
    if temp:
        ans += 1
print(ans)

Measured memory_bytes: 3064
S = input()
first, last = int(S[:2]), int(S[2:])
yymm = (0 <= first <= 99) and (1 <= last <= 12)
mmyy = (1 <= first <= 12) and (0 <= first <= 99)
if yymm and mmyy:
    print('AMBIGUOUS')
elif yymm:
    print('YYMM')
elif mmyy:
    print('MMYY')
else:
    print('NA')


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

typedef long long ll;

const ll mod = 998244353;

ll dp[5050][5050];

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = b + 1; i <= d; i++)
        dp[a][i] = 1ll * dp[a][i - 1] * a % mod;
    for (int i = a + 1; i <= c; i++)
    {
        int ls = 0;
        for (int j = b; j <= d; j++)
        {
            dp[i][j] += 1ll * dp[i - 1][j] * j % mod;
            dp[i][j] += ls;
            ls = 1ll * ls * i % mod;
            ls += 1ll * dp[i - 1][j] * j % mod;
        }
    }
    cout << dp[c][d] % mod << endl;
    return 0;
}

Measured memory_bytes: 85764
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans=0, n=0,m,count,sum=0,ch=0;
	llint na=0, nb=0;
	bool check = false;
	vector<llint> a;
	cin >> n>>m;
	rep(i, n) {
		cin >> count;
		a.push_back(count);
		sum += count;
	}
	sort(a);
	reverse(a.begin(), a.end());
	if (sum % (4 * m) != 0)ch++;
	sum /= 4 * m;
	sum += ch;
	rep(i, m) {
	if (a.at(i) < sum) {
		cout << "No" << endl;
		break;
	}
	if (i == m - 1)cout << "Yes" << endl;
	}
	please AC;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    List<Tuple<int, int>>[] es;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        es = new List<Tuple<int, int>>[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<Tuple<int, int>>();
        }

        for (int i = 0; i < N - 1; i++)
        {
            int a = cin.nextInt() - 1;
            int b = cin.nextInt() - 1;
            int c = cin.nextInt();
            es[a].Add(Tuple.Create(b, c));
            es[b].Add(Tuple.Create(a, c));
        }

        int Q = cin.nextInt();
        int K = cin.nextInt() - 1;

        long[] dist = new long[N];
        long MAX = long.MaxValue / 4;
        for (int i = 0; i < N; i++)
        {
            dist[i] = MAX;
        }
        dist[K] = 0;
        Queue<int> q = new Queue<int>();
        q.Enqueue(K);

        while (q.Count != 0)
        {
            int now = q.Dequeue();
            foreach (var item in es[now])
            {
                int next = item.Item1;
                if (dist[next] == MAX)
                {
                    dist[next] = dist[now] + item.Item2;
                    q.Enqueue(next);
                }
            }
        }

        for (int i = 0; i < Q; i++)
        {
            int A = cin.nextInt() - 1;
            int B = cin.nextInt() - 1;
            Console.WriteLine(dist[A] + dist[B]);
        }


    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' '};

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 39064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i < n; i++)
#define ALL(n) begin(n), end(n)

string s, ans;

int main()
{
  cin >> s;
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  if(s.size() == 1) ans = "No";
  else ans = "Yes";

  cout << ans << endl;
}

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

class Main {

    public static int MODULO = 1000000007;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int W = scanner.nextInt();

        String[] grid = new String[H];

        for(int i=0; i<H; i++) {
            grid[i] = scanner.next();
        }

        int[][] memo = new int[H][W];

        for(int i=0; i<H; i++)
            Arrays.fill(memo[i], -1);

        System.out.println(findWays(0, 0, H, W, grid, memo));
    }

    private static int findWays(int rowIdx, int colIdx, int rowSize, int colSize, String[] grid, int[][] memo) {
        if(!isInRange(rowIdx, colIdx, rowSize, colSize)) {
            return 0;
        }

        if(rowIdx == rowSize - 1 && colIdx == colSize - 1) {
            return 1;
        }

        if(memo[rowIdx][colIdx] != -1) {
            return memo[rowIdx][colIdx];
        }


        int poss1 = (rowIdx + 1 < rowSize && grid[rowIdx+1].charAt(colIdx) == '.') ? findWays(rowIdx + 1, colIdx , rowSize, colSize, grid, memo) : 0;
        int poss2 = (colIdx + 1 < colSize && grid[rowIdx].charAt(colIdx+1) == '.') ? findWays(rowIdx , colIdx + 1 , rowSize, colSize, grid, memo) : 0;

        return memo[rowIdx][colIdx] = (poss1 + poss2) % MODULO;
    }

    private static boolean isInRange(int rowIdx, int colIdx, int rowSize, int colSize) {
        return (rowIdx >= 0 && rowIdx < rowSize && colIdx >= 0 && colIdx < colSize);
    }
}


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

const int maxN=1e5+1;

int n;
int dp[maxN][3];

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

        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k){
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[j]);
                }
            }
        }
    }

    int sol=0;
    for(int i=0;i<3;i++){
        sol=max(sol,dp[n][i]);
    }

    cout<<sol;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  string A,B,C;

  cin >> A >> B >> C ;

  bool ans=true;

  if(B.at(0)!=A.at(A.size()-1)) ans=false;

  if(C.at(0)!=B.at(B.size()-1)) ans=false;

  if(ans) cout << "YES" << endl;

  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin

class Queue:
    def __init__(self, process_list,quontime):
        self.process_list = process_list
        self.quontime = quontime
        self.elapsed_time = 0

    def process_done(self, process):
        process.update_leavetime_mili_seconds(process.leavetime_mili_seconds)
        print("{} {}".format(process.name,self.elapsed_time))

    def execute(self):
        while len(self.process_list) > 0:
            target_process = self.process_list.pop(0)
            if target_process.leavetime_mili_seconds <= self.quontime:
                self.elapsed_time += target_process.leavetime_mili_seconds
                self.process_done(target_process)
            else:
                self.elapsed_time += self.quontime
                target_process.update_leavetime_mili_seconds(self.quontime)
                self.process_list.append(target_process)

class Process:
    def __init__(self, arg_name,leavetime_mili_seconds):
        self.name = arg_name
        self.leavetime_mili_seconds = leavetime_mili_seconds
        # self.is_done = False

    def update_leavetime_mili_seconds(self, shori_time):
        self.leavetime_mili_seconds -= shori_time


n, q = map(int,stdin.readline().rstrip().split())
process_list = []
for i in range(n):
    input_t = stdin.readline().rstrip().split()
    process_list.append(Process(input_t[0], int(input_t[1])))
queue = Queue(process_list, q)
queue.execute()


Measured memory_bytes: 17252
tmp_str = input().split(" ")
n = int(tmp_str[0])
q = int(tmp_str[1])
queue = []
time = 0

for i in range(n):
    tmp_str = input().split(" ")
    queue.append([tmp_str[0], int(tmp_str[1])])

while queue:
    process_target = queue.pop(0)
    if process_target[1] <= q:
        time += process_target[1]
        print(process_target[0] + " " + str(time))
    else:
        time += q
        queue.append([process_target[0], process_target[1] - q])


Measured memory_bytes: 12872
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;
ll mod=1000000007;
typedef pair<int, int> P;

ll N,K;

int main()
{
    cin >> N >> K;
    ll ans=0;
    for(int b=K+1; b<=N; b++){
        if(K==0) ans--;
        ans+=N/b*(b-K);
        ans+=max(N%b-K+1, (ll)0);
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define INF 100000
using namespace std;
char x[1001][1001];
int H, W, N;
int cycle;
int tots;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
typedef pair<int, int> P;
queue<P> que; 

int count(){
    int ans = 1;
    int nl = 0; //now loop
    if(tots == H*W) return 0;
    while(que.size()){
        P p = que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int ny = p.first+dy[i];
            int nx = p.second+dx[i];
            if(ny>=0 && ny < H && nx>=0 && nx < W && x[ny][nx] == '.'){
                que.push(P(ny,nx));
                x[ny][nx]='#';
                tots++;
                if(tots==H*W) return ans;
            }
        }
        nl++; 
 //       cout << cycle <<" "<< que.size() << " " << nl << endl;
        if(nl==cycle){
            ans++;
            cycle = que.size();
            nl = 0;
 
        }
    }
    return ans;
}

int main(){
    cin >> H >> W;
    tots =0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> x[i][j];
            if(x[i][j]=='#'){
             tots++;
             que.push(P(i,j));
            }
        }
    }
    cycle = que.size();
    cout << count() << endl;
}

Measured memory_bytes: 9360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,sum;
    cin >> a >> b;
    if(a<b){
        sum = b+(b-1);
    }
    else if(a>b){
        sum = a+(a-1);
    }
    else{
        sum = a+a;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3544
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

#define yes printf("Yes\n")
#define Yes printf("YES\n")
#define no printf("No\n")
#define No printf("NO\n")

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const long long mod = 998244353;
const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";
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;
}

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n == r) return 1;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int nck[1010][1010];
void comb(int n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

int n, a, b, cnt, ans;
double v[50];
map<double, int>mp;
double ave, mi = 1e16;
signed main() {
	cin >> n >> a >> b;
	comb(n);
	rep(i, n) {
		cin >> v[i];
		++mp[v[i]];
	}
	sort(v, v + n);
	rep(i, a) {
		ave += v[n - 1 - i];
		if (mi != v[n - 1 - i]) cnt = 0;
		mi = min(mi, v[n - 1 - i]);
		++cnt;
	}
	if (v[n - a] == v[n - 1]) {
		for (int i = a; i <= b; ++i) {
			ans += nck[mp[v[n - 1]]][i];
		}
	}
	else ans = nck[mp[v[n - a]]][cnt];

	printf("%.10Lf\n", ave / a);
	printf("%lld\n", ans);
}

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

namespace Main
{
    public static class Program
    {
        public static List<int> list = new List<int>();

        static void Main(string[] arg)
        {

            var input = Console.ReadLine().ToCharArray();
            var answer = 0;

            char before = input[0];

            for(int i = 1;i<input.Count();i++)
            {
                char c = input[i];
                if(c == before)
                {
                    before = c == '1' ? '0' : '1';
                    answer++;
                }
                else
                {
                    before = c;
                }
                
            }
            

            Console.WriteLine(answer);
            Console.ReadLine();




        }
        
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();

        }
        private static double[] GetDoubleList(string line)
        {
            return line.Split(' ').Select(x => double.Parse(x)).ToArray();

        }
        private static ulong[] GetUlongList(string line)
        {
            return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
        }
        private static long[] GetLongList(string line)
        {
            return line.Split(' ').Select(x => long.Parse(x)).ToArray();
        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}


Measured memory_bytes: 11616
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
double yint(double sl, double x, double y){
    // y = sl*x+b
    return y-sl*x;
}
double herepos[20011];
double hereneg[20011];
int dists[20011];
int main ()
{
  prep();
  int n;
  cin >> n;
  for (int i=0; i<20011; i++){
    herepos[i] = 1000000000000000000;
    hereneg[i] = 1000000000000000000;
  }
  int t[n] = {0};
  int v[n] = {0};

  for (int i=0; i<n; i++){
      cin >> t[i];
  }
  for (int i=0; i<n; i++){
      cin >> v[i];
  }
  int dist = 0;
  
  herepos[0] = yint(1, 0, 0);
  for (int i=0; i<n; i++){
      hereneg[dist] = yint(-1, dist, v[i]);
      dists[dist] = i;
      dist += t[i];
      herepos[dist] = yint(1, dist, v[i]);
      dists[dist] = i;
      
  }
  hereneg[dist] = yint(-1, dist, 0);
  
  // go along decimal
  double lasth = 0;
  double curmax = 0;
  double sum = 0;

  for (int ii=0; ii<=dist*2; ii++){
     double i = ii/2.0;
     double minneg = 1000000000000000000;
 	 double minpos = 1000000000000000000;
      for (int j=0; j<=ii/2; j++){
        minpos = min(minpos, herepos[j]);
        if (herepos[j] != 1000000000000000000){
            curmax = v[dists[j]];
        }
        
      }
      for (int j=ii/2+ii%2; j<=dist; j++){
      
        minneg = min(minneg, hereneg[j]);
      }
    
      double h = min(minpos+i, min(minneg-i, curmax)); 
    //cout << h << endl;
      double ych = abs(lasth-h);
    
      sum += ych*.5/2+min(h, lasth)*.5;
      //cout << sum << endl;
      lasth = h;
      
  }
  printf("%.18lf", sum);
  return 0; 
}


Measured memory_bytes: 640
n = int(input())# your code goes here
a = input().split()
min = int(a[0])
max = int(a[0])
for i in range(n):
	if(int(a[i])<min):
		min = int(a[i])
	if(int(a[i])>max):
		max = int(a[i])
print(max-min)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<stdio.h>
#define Max 25
#define Nil -1
using namespace std;
struct Tree {
	int p, l, r;
};

Tree T[Max];
int deg[Max], dep[Max], he[Max], ch[Max];

int Findparent(int i)
{
	return T[i].p;
}

int Findsibling(int i)
{
	if (T[i].p != Nil&&T[T[i].p].r != i)
		return T[T[i].p].r;
	else if (T[i].p != Nil&&T[T[i].p].l != i)
		return T[T[i].p].l;
	else return Nil;
}

void caldep(int u, int d)
{
	if (u == Nil) return;
	dep[u] = d;
	caldep(T[u].l, d + 1);
	caldep(T[u].r, d + 1);
}

int calhe(int i)
{
	int h1 = 0, h2 = 0;
	if (T[i].l != Nil)
		h1 = calhe(T[i].l) + 1;
	if (T[i].r != Nil)
		h2 = calhe(T[i].r) + 1;
	return he[i] = (h1 > h2 ? h1 : h2);
}

int main()
{
	int n;
	int p, l, r;
	int root;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		T[i].p = Nil;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> p >> l >> r;
		T[p].l = l;
		T[p].r = r;
		T[l].p = p;
		T[r].p = p;
		if (l == Nil&&r == Nil)
		{
			deg[p] = 0;
		}

		else if (l == Nil&&r != Nil)
		{
			deg[p] = 1;
		}

		else if (l != Nil&&r == Nil)
		{
			deg[p] = 1;
		}

		else
		{
			deg[p] = 2;
		}

	}
	for (int i = 0; i < n; i++)
	{
		if (T[i].p == Nil)
		{
			ch[i] = 0;
			root = i;
		}
		else if (T[i].l == Nil&&T[i].r == Nil)
			ch[i] = 2;
		else
			ch[i] = 1;
	}
	caldep(root, 0);
	calhe(root);
	for (int i = 0; i < n; i++)
	{
		cout << "node " << i << ": parent = " << Findparent(i) << ", sibling = " << Findsibling(i) << ", degree = " << deg[i] << ", depth = " << dep[i] << ", height = " << he[i] << ", ";
		if (ch[i] == 0)
			cout << "root";
		else if (ch[i] == 1)
			cout << "internal node";
		else
			cout << "leaf";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, s;
  cin >> n >> s;
  int sqrtn = floor(sqrt(n));
  if (n == s) {
    print(n + 1);
    return 0;
  }
  FORS(i, 2, sqrtn) {
    int tmpn = n;
    int tmps = 0;
    while (tmpn >= i) {
      tmps += tmpn % i;
      tmpn /= i;
    }
    tmps += tmpn;
    //   DEBUG(tmps);
    if (tmps == s) {
      print(i);
      return 0;
    }
  }
  for (int i = sqrtn; i >= 1; i--) {
    int val = s - i;
    if (val >= 0) {
      int x = (n - val) / i;
      //  DEBUG(n);
      //  DEBUG(val);
      //   DEBUG(i);
      if ((n - val) % i == 0 && i <= x - 1 && val <= x - 1) {
        if (x != 1) {
          print(x);
          return 0;
        }
      }
    }
  }
  print("-1");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

struct stu{
  int tim, per;
};

bool compare(stu a, stu b){
  if(a.tim < b.tim){
    return true;
  }else{
    return false;
  }
}

int const nmax =1e5;
stu late[1 + nmax];

int main() {

  int n;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> late[i].tim;
    late[i].per = i;
  }
  sort(late+1, late+n+1, compare);
  for(int i = 1;i <= n;i++){
    cout << late[i].per << ' ';
  }
  return 0;
}


Measured memory_bytes: 4356
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.color = [[0] * 2 for _ in range(n)]
        for i in range(n):
            y, x = divmod(i, w)
            if s[y][x] == '#':
                self.color[i][1] = 1
            else:
                self.color[i][0] = 1

    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
        self.color[x][0] += self.color[y][0]
        self.color[x][1] += self.color[y][1]

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

    def same(self, x, y):
        return self.find(x) == self.find(y)

    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 group_count(self):
        return len(self.roots())

    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())


h, w = map(int, readline().split())
s = [readline().rstrip().decode() for _ in range(h)]
uf = UnionFind(h * w)
move = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for y, ss in enumerate(s):
    for x, sss in enumerate(ss):
        for dy, dx in move:
            xx = x + dx
            yy = y + dy
            if 0 <= xx < w and 0 <= yy < h and sss != s[yy][xx]:
                uf.union(yy * w + xx, y * w + x)
print(sum(uf.color[root][0] * uf.color[root][1] for root in uf.roots()))


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

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

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

// 最少の買う=最多の売る
// 

int n,te;
int cost[100010];

int main(){
    int i,j,k,l;
    
    cin >> n >> te;
    
    for (i=0;i<n;i++){
        scanf("%d",cost+i);
    }
    
    int low = cost[0];
    int ben = 0;
    int count = 0;
    for (i=0;i<n;i++){
        low = min(low,cost[i]);
        if (cost[i]-low > ben){
            ben = cost[i]-low;
            count = 1;
        }else if (cost[i]-low == ben){
            count ++;
        }
    }
    
    cout << count << endl;

    return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){ 
    string s=""; cin >> s;
    string ans="";
    for (int i=0;i<s.size();i++){
        char key = s[i];
        if (key=='0') ans.push_back('0');
        else if (key=='1') ans.push_back('1');
        else if (key=='B'&&ans=="") continue;
        else ans.pop_back();
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
print(input().translate(str.maketrans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')))


Measured memory_bytes: 5544