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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}


ll f[100000];
ll g[100000];
ll x[100000];
int v[100000];
ll c;

int n;
ll ma;
int main(){
  cin >> n>>c;
  ll sum = 0;
  REP(i,n){
    cin >> x[i] >> v[i];
    sum += v[i];
    f[i] = sum - x[i];
    ma = max(ma,f[i]);
    g[i] = max(g[max(i-1,0ll)],f[i]-x[i]);
    //cout << g[i] << " " << f[i] << " " << ma<< endl;
  }
  sum = 0;
  for(int i = n-1;i>0;i--){
    sum += v[i];
    ma = max(ma,sum+g[i-1]-(c-x[i]));
    //cout << g[i-1] <<" " << ma << endl;
  }
  sum = 0;
  g[0] = 0;
  for(int i = n-1;i>=0;i--){
    sum += v[i];
    f[i] = sum - (c-x[i]);
    ma = max(ma,f[i]);
    g[i] = max(g[(i+1)%n],f[i]-(c-x[i]));
  }
  sum = 0;
  REP(i,n-1){
    sum += v[i];
    ma = max(ma,sum+g[i+1]-x[i]);
  }
  cout << ma << endl;
}

/*
ll dp[100001][2];
int x[100001];
int v[100001];
ll c;
dp[i]=iを通ったときの最大値
dp[i] = max(dp[i],dp[k]+x[i]-abs(v[i]-v[k]))
      = max(dp[i],dp[i-1]-abs(v[i]-v[i-1]),dp[i+1]-abs(v[i]-v[i+1]))
ll ma = 0;

int inde = 0;
int n;
int main (){
  cin >> n >> c;
  FOR(i,1,n+1){
    cin >> x[i]>> v[i];
    dp[i][0] = dp[i-1][0] + v[i] - abs(x[i]-x[i-1]);
    cout << dp[i][0] << endl;
    if(dp[0][0] < dp[i][0]-x[i]){
      dp[0][0] = dp[i][0]-x[i];
      inde = i;
    }
  }
  x[n] = c;
  dp[0][1] = dp[0][0];
  cout << dp[0][1] << "aaaa"<<endl;
  for(int i = n;i>inde;i--){
    dp[i][1] = dp[(i+1)%(n+1)][1] + v[i] - abs(x[i]-x[(i+1)%(n+1)]);
    cout << dp[i][1] << endl;
  }
  REP(i,n+1){
    ma = max(ma,dp[i][0]);
    ma = max(ma,dp[i][1]);
  }
  cout << ma << endl;
}
*/


Measured memory_bytes: 2944
import collections
 
s = collections.deque(list(input()))
q = int(input())
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1)
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))

Measured memory_bytes: 9180
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, x, y;
	cin >> n >> x >> y;

	x--;
	y--;

	VI result(n - 1, 0);
	REP(i, n - 1) {
		RANGE(j, i + 1, n) {
			int ix = abs(x - i);
			int jy = abs(y - j);
			int d = min(ix + jy + 1, j - i);
			// cout << "i = " << i << "; j = " << j
			//	 << "; min(ix + jy + 1, j - i) = " << d << endl;
			result[d - 1]++;
		}
	}
	REP(i, n - 1) { cout << result[i] << endl; }
	return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
e = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = list(map(int, input().split()))
    e[a].append(b)
    e[b].append(a)

res = 0
for cur in range(1, N+1):
    isObser = True
    for u in e[cur]:
        if H[u-1] >= H[cur-1]:
            isObser = False
    res += int(isObser)
print(res)

Measured memory_bytes: 92816
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s; cin>>s;
	for (int i = 0; i<(int)s.size(); ++i) if (s[i] == '9') s[i] = '1'; else s[i] = '9';
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 110;
char s[N];
int main(){
	ll k, l = 0;
	cin >> s >> k;
	ll len = strlen(s);
	while(l < len && s[l] == '1') l ++;
	if(l+1 <= k) printf("%c\n",s[l]);
	else printf("1\n");
	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll H, W;
    cin >> H >> W;
    string S[H];
    REP(i, H) cin >> S[i];
    ll L[H][W], R[H][W], D[H][W], U[H][W];
    REP(i, H)
    {
        REP(j, W) 
        {
            L[i][j] = 0;
            R[i][j] = 0;
            D[i][j] = 0;
            U[i][j] = 0;
        }
    }

    REP(i, H)
    {
        REP(j, W)
        {
            if (S[i][j] == '#')
            {
                L[i][j] = 0;
                D[i][j] = 0;
            }
            else
            {
                if (j == 0) L[i][j] = 1;
                else L[i][j] = L[i][j - 1] + 1;
                if (i == 0) D[i][j] = 1;
                else D[i][j] = D[i - 1][j] + 1;
            }
        }
    }

    for (int i = H - 1; i >= 0; --i)
    {
        for (int j = W - 1; j >= 0; --j)
        {
            if (S[i][j] == '#')
            {
                R[i][j] = 0;
                U[i][j] = 0;
            }
            else
            {
                if (j == W - 1) R[i][j] = 1;
                else R[i][j] = R[i][j + 1] + 1;
                if (i == H - 1) U[i][j] = 1;
                else U[i][j] = U[i + 1][j] + 1; 
            }
        }
    }

    ll ans = 0;
    REP(i, H) REP(j, W) ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3);

    cout << ans << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL N;
    cin >> N;

    LL t = 2;
    LL n = N;
    LL res = 0;
    while(t * t <= N && n > 1) {
        int c = 0;
        while(n % t == 0) {
            ++c;
            n /= t;
        }
        ++t;
        if(c > 0) {
            int tt = 1;
            while(c >= tt) {
                ++res;
                c -= tt;
                ++tt;
            }
        }
    }

    if(n != 1) {
        ++res;
    }
    cout << res << endl;
    return 0;
}


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

using i64 = int64_t;

using Graph = vector<vector<int>>;

constexpr int INF = 1e9;

void dfs(int u, vector<int> &min_dist, const Graph &tree){
    for(auto to: tree[u]){
        if(min_dist[to] < INF)continue;
        min_dist[to] = min_dist[u] + 1;
        dfs(to, min_dist, tree);
    }
    return;
}

int main(){
    int n, u, v;
    cin >> n >> u >> v;
    Graph tree(n+1);
    for(int i=0;i<n-1;++i){
        int a, b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> min_dist_taka(n+1, INF);
    vector<int> min_dist_ao(n+1, INF);
    min_dist_taka[u] = 0;
    dfs(u, min_dist_taka, tree);
    min_dist_ao[v] = 0;
    dfs(v, min_dist_ao, tree);
    int ans = 0;
    for(int i=1;i<=n;++i){
        //cerr << min_dist_taka[i] << " " << min_dist_ao[i] << endl;
        if(min_dist_taka[i] < min_dist_ao[i]){
            ans = max(ans, min_dist_ao[i]);
        }
    }

    cout << ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 10368
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll n,k; cin>>n>>k;
  ll r = n%k;
  cout<<min(r,k-r);
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) ll(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 3005;

signed main(){
    fastio;
    int i,j,n,m;
    string s,t,ans;
    cin>>s>>t;
    n=sz(s); m=sz(t);
    vector<vector<int>>dp(n+1,vector<int>(m+1));
    for(i=0;i<=n;++i){
        for(j=0;j<=m;++j){
            if(!i or !j){
                dp[i][j]=0;
                continue;
            }
            if(s[i-1]==t[j-1]){
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int x=n,y=m;
    while(x and y){
        if(s[x-1]==t[y-1]){
            ans+=s[x-1];
            x--;
            y--;
        }
        else if(dp[x-1][y]>dp[x][y-1]){
            x--;
        }
        else{
            y--;
        }
    }
    reverse(all(ans));
    cout<<ans;
}

Measured memory_bytes: 35584
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        long value = 1;
        long modConst = 1000000007;
      
        for (int i = 1; i <= n; i++) {
            value *= i;
            value %= modConst;
        }
    
		// 出力
		System.out.println(value);
	}
}

Measured memory_bytes: 21716
# include<bits/stdc++.h>
# define rep(i,l,r) for(int i=l;i<=r;++i)
using namespace std;
const int N=1e5+5;
vector<int>lk[N];
int fa[N],deep[N];
int s[N];
int np[N],p1[N],p2[N];
 
void dfs(int x,int fr){
	fa[x]=fr;deep[x]=deep[fr]+1;
	for(auto y:lk[x])
	if(y!=fr)dfs(y,x);
}
 
int main(){
	int n;
	cin>>n;
	rep(i,1,n){
		int x,y;
		scanf("%d%d",&x,&y);
		lk[x].push_back(y);lk[y].push_back(x);
	}
	dfs(1,0);
	int x=1;
	rep(i,2,n)
	if(deep[i]>deep[x])x=i;
	dfs(x,0);
	int y=1;
	rep(i,2,n)
	if(deep[i]>deep[y])y=i;
	for(int i=y;i;i=fa[i])s[i]=1;
	rep(i,1,n)
	if(!s[i]&&++s[fa[i]]==1){
		puts("-1");
		exit(0);
	}
	vector<int>a;
	for(int i=y;i;i=fa[i])a.push_back(s[i]);
	int top=0;
	for(auto i:a){
		np[top+1]=top+i;
		rep(j,1,i-1)np[top+1+j]=top+j;
		top+=i;
	}
	rep(i,1,n)p1[np[i]]=i;
	top=0;
	for(auto it=a.end();--it>=a.begin();){
		int i=*it;
		np[top+1]=top+i;
		rep(j,1,i-1)np[top+1+j]=top+j;
		top+=i;
	}
	rep(i,1,n)p2[np[i]]=i;
	int i=1;
	while(p1[i]==p2[i]&&i<=n)++i;
	if(p1[i]<p2[i])
		rep(i,1,n)printf("%d ",p1[i]);
	else
		rep(i,1,n)printf("%d ",p2[i]);
}

Measured memory_bytes: 13816
#include <stdio.h>

#define MAX 100000
long T[MAX];
int n, k;

int check(long P) {
	int j, i = 0;
	long s;
	
	for (j = 0; j < k; j++) {
		s = 0;
		while( s + T[i] <= P) {
			s += T[i];
			i++;
			if (i == n) return n;
		}
	}
	return i;
}

int solve() {
	long left = 0;
	long right = 100000 * 10000;
	long mid;
	int v;

	while ( right -left > 1) {
		mid = (left + right) / 2;
		v = check(mid);
//		printf("%ld %ld %ld %d\n", left, mid, right ,v);
		if (v >= n) {
			right = mid;
		} else {
			left = mid;
		}
	}
	return  right;
}

int main(void) {
	int i;
	scanf("%d %d", &n, &k);

	for (i = 0; i < n; ++i) {
		scanf(" %ld", &T[i]);
	}
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 1376
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, K;
string s;
int ans1, ans2;

signed main(){
    int a,b;
    cin >> a >> b;
    int c = max(a, b);
    int d = min(a, b);
    cout << max(c + c - 1, c + d) << endl;


    return 0;
}

/*

*/

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if( A+B > C+D ) cout << "Left" << endl;
  else if( A+B < C+D ) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}


Measured memory_bytes: 256
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val numbers = readLine()!!.split(" ").map { it.toInt() }
    if(!isSame(numbers, validList(n))) {
        println(0)
        return
    }
    var ans = 1
    for(i in (1..(n/2))) {
        ans *= 2
        ans %= 1000000000 + 7
    }
    println(ans)
}

fun isSame(num1:List<Int>, num2:List<Int>):Boolean {
    val tmp1 = num1.sorted()
    val tmp2 = num2.sorted()
    for(i in tmp1.indices) {
        if(tmp1[i] != tmp2[i]) {
            return false
        }
    }
    return true
}

fun validList(num:Int):List<Int> {
    return if(num%2==0) {
        val tmp = (1 until num step 2).map { it }.toMutableList()
        tmp.addAll(tmp)
        tmp
    } else {
        val tmp = (2 until num step 2).map { it }.toMutableList()
        tmp.addAll(tmp)
        tmp.add(0)
        tmp
    }
}

Measured memory_bytes: 66512
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = -1000; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    ll N; cin >> N;
    bool flag = false;
    rep (i,1000){
        rep (j,1000){
            ll tmp = pow(i,5) - pow(j,5);
            if (tmp == N){
                cout << i << " " << j << endl;
                flag = true;
                break;
            }
        }
        if (flag == true){
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 4044
MOD=998244353
N,K=map(int,input().split())
LR=[]
for i in range(K):
    l,r=map(int,input().split())
    LR.append((l,r))
LR.sort(key=lambda x:x[0])

#0-indexedにする
dp=[0]*N
imos=[0]*(N+1)
dp[0]=1

for i in range(N):
    dp[i]=(dp[i]+imos[i])%MOD
    for l,r in LR:
        if i+l>=N:
            break
        imos[i+l]=(imos[i+l]+dp[i])%MOD
        R=min(i+r+1,N)
        imos[R]=(imos[R]-dp[i]+MOD)%MOD
    imos[i+1]=(imos[i]+imos[i+1])%MOD
print(dp[N-1])

Measured memory_bytes: 73304
#include<stdio.h>
int main(void){
  int a;
  scanf("%d",&a);
  int L=a/100;
  int R=a%100;
  if(1<=L && L<=12){
    if(1<=R && R<=12){
      printf("AMBIGUOUS\n");
    }else{
      printf("MMYY\n");
    }
  }else{
    if(1<=R && R<=12){
      printf("YYMM\n");
    }else{
      printf("NA\n");
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include<cmath>
#include<iostream>

using namespace std;

int main(){
  int remaind = 100;  
  int n;
  
  cin >> n;

  for(int i = 0; i < n; i++){
    remaind = (int)ceil(remaind * 1.05);
  }

  cout << remaind * 1000 << endl;
  
  return 0;
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
#define MAX_E 2011
#define MAX_V 1011
#define INF 10e16
struct edge{LL from,to,cost;};

edge es[MAX_E];

LL d[MAX_V];
LL nloop[MAX_V];
int V,E;
void find_negative_loop(){
   memset(d,0,sizeof(d));
     REP(j,V+1){
        bool update =false;
        REP(i,E){
            edge e=es[i];
            if(d[e.from]!=INF&& d[e.to]>d[e.from]+e.cost){
               d[e.to] = d[e.from] +e.cost;
               update=true;
               if(j==V)nloop[e.from]=-1;
            }
        }
        if(!update)break;
     }
     /*
     REP(i,V+1){
         if(d[i]<0){
            nloop[i]=-10e12;
         }else{
            nloop[i]=0;
         }
     }
     */
   
}

//s番目の頂点から各頂点への最短経路を求める
void shortest_path(int s){
     REP(i,V+1)d[i]=INF;
     REP(i,V+1){
         //cout<<nloop[i]<<endl;
         if(nloop[i]!=0){
            d[i]=-INF;
         }
     }
     d[s]=0;
     
     REP(j,V+1){
        bool update =false;
        REP(i,E){
            edge e=es[i];
            if(d[e.from]!=INF&& d[e.to]>d[e.from]+e.cost){
               d[e.to] = d[e.from] +e.cost;
               update=true;
            }
        }
        if(!update)break;
     }
}

int main(){
        
	cin>>V>>E;
	REP(i,E){
	    LL a,b,c;
	    cin>>a>>b>>c;
	    es[i]=edge{a,b,-c};
	}
	find_negative_loop();
	shortest_path(1);
	if(d[V]<=-INF){
           cout<<"inf"<<endl;
        }else{
           cout<<-d[V]<<endl;
        }
	return(0);
}

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

using namespace std;
using ll = long long;
#define each(i, mp) for (auto &i : mp)

int main()
{
  string s;
  cin >> s;
  map<ll, ll> mp;
  mp[0] = 1;
  reverse(s.begin(), s.end());
  ll now = 0, ten = 1;
  each(e, s)
  {
    now = (now + (e - '0') * ten) % 2019;
    ten *= 10;
    ten %= 2019;
    mp[now]++;
  }
  ll ans = 0;
  each(e, mp)
  {
    ans += e.second * (e.second - 1) / 2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3720
//
//  first.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000



int main()
{
    string S;
    cin >> S;
    for (int i=0; i<S.size(); i++) {
        cout << "x";
    }
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    int a=0;
    cin>>s;
    if(s[0]!='C')a++;
    if(s[1]!='O')a++;
    if(s[2]!='D')a++;
    if(s[3]!='E')a++;
    if(s[4]!='F')a++;
    if(s[5]!='E')a++;
    if(s[6]!='S')a++;
    if(s[7]!='T')a++;
    if(s[8]!='I')a++;
    if(s[9]!='V')a++;
    if(s[10]!='A')a++;
    if(s[11]!='L')a++;
    if(s[12]!='2')a++;
    if(s[13]!='0')a++;
    if(s[14]!='1')a++;
    if(s[15]!='6')a++;
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

cnt = 0
for i in range(1,N+1):
    d1,d2 = map(int,input().split(" "))
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    
    if cnt == 3:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 9004
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(*args):
    print(*args,file=sys.stderr)

def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
     
#input

                
def resolve():
    N,=pin()
    b=list(pin())
    
    ans=0
    for i in range(N):
        temp=0
        t=b[i]
        while(t%2==0):
            t//=2
            temp+=1
        #print(temp)
        ans+=temp
    print(ans)
        #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()

"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
5 2 4"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
631 577 243 199"""
        output = """0"""
        self.assertIO(input, output)
    
if __name__=="__main__":resolve()

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;

    //nが1の場合は例外
    if(n == 1) {
        ans = s[0] - '0';
        cout << ans << endl;
        return 0;
    }

    //00…0(0がn-1個)から11…1(1がn-1個)のbit列を全て調べる
    for(int b = 0; b < (1 << (n-1)); b++) {

        ll t = s[0] - '0';  //ansを計算するための補助変数

        //bのn-iビット目について調べる
        for(int i = 1; i <= n-1; i++) {

            //bのn-iビット目が1だったら
            if( b & (1 << (n-1-i)) ) {
                //ansにtを加えて、tにs[i]を代入する
                ans += t;
                t = s[i] - '0';
            }
            //bのn-iビット目が0だったら
            else {
                //tを10倍してs[i]を加える
                t = 10*t + (s[i] - '0');
            }

            //1ビット目まで調べ終わったら
            if(i == n-1) {
                //ansにtを加える
                ans += t;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

struct UnionFind {
    vector<int> root;
    
    UnionFind(int n) {
        root.assign(n,-1);
    }
    
    int find(int n){
        if(root[n] < 0) return n;
        else return root[n] = find(root[n]);
    }
    
    void connect(int a,int b){
        int ar = find(a);
        int br = find(b);
        if(ar == br) return;
        
        if(-root[ar] < -root[br]){
            root[br] += root[ar];
            root[ar] = br;
        }else{
            root[ar] += root[br];
            root[br] = ar;
        }
    }
    
    
};


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

    
    int N,M,K;
    cin >> N >> M >> K;
    
    UnionFind U(N);
    vi frend(N);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--,b--;
        frend[a]++;
        frend[b]++;
        U.connect(a,b);
    }
    vvi block(N);
    rep(i,K){
        int c,d;
        cin >> c >> d;
        c--,d--;
        block[c].pb(d);
        block[d].pb(c);
    }
    vi ans;
    
    rep(i,N){
        int an = 0;
        an = -U.root[U.find(i)] - frend[i] - 1;
        int aa = U.find(i);
        for (int p : block[i]) {
            if(aa == U.find(p)) an--;
        }
        ans.pb(an);
    }
    
    rep(i,N-1) cout << ans[i] << " ";
    cout << ans[N-1] << endl;
    

    return 0;
}


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

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) if((x)>(y))(x)=(y)
#define chmax(x,y) if((x)<(y))(x)=(y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a[200200];
ll res;

signed main() {
	cin >> n;
	rep(i,n) cin >> a[i];
	int l = 0, x = a[0];
	repst(i,1,n) {
		if (i!=n && (x&a[i])==0) x ^= a[i];
		else if (i!=n) {
			int t = i-l;
			while (x&a[i]) res += t, x ^= a[l], l++, t--;
			x ^= a[i];
		}
		else {
			int t = i-l;
			res += t*(t+1)/2;
		}
		//cout << i << ' ' << l << ' ' << res << ln;
	}
	cout << res << ln;
}

Measured memory_bytes: 1920
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[]=new int[n];
    int b[]= new int[n];
    int c[] =new int[n-1];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    for(int i=0;i<n;i++){
      b[i]=sc.nextInt();
    }
    for(int i=0;i<n-1;i++){
     c[i]=sc.nextInt();
    }
    int index=-100;int sum=0;
    for(int i=0;i<n;i++){
      
      if(a[i]==index+1){
        sum+=b[a[i]-1]+c[index-1];
      }
      else{
        sum+=b[a[i]-1];
      }
      index = a[i];
    }
    System.out.println(sum);
  }
}
    

Measured memory_bytes: 21844
import java.util.*;

public class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt(){
		return Integer.parseInt(s.next());
	}

	public static void main(String[]$){
		int a=gInt(),b=gInt(),c=gInt();
		System.out.println(
				a+b>=c&&a<=c
				?"YES":"NO"
				);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;
int main() {
	
	double a,b,c;
	double S,L,h;
	int C;

	cin >> a >> b >> C;

	c = sqrt(a * a + b * b - 2 * a * b * cos(C * acos(-1) / 180));
	S = a * b * 0.5 * sin(C * acos(-1) / 180);
	h = S / a * 2;
	L = a + b + c;

	printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);

	return 0;
}


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

ll calc(string s, ll total, int idx) {
    if (s.size() - 1 <= idx) {
        ll n = stoll(s, nullptr, 0);
        return total + n;
    }
    string first = s.substr(0, idx + 1);
    ll first_n = stoll(first, nullptr, 0);
    string remain = s.substr(idx + 1);
    return calc(remain, first_n + total, 0) + calc(s, total, idx + 1);
}

void solve() {
    string S;
    cin >> S;
    ll x = calc(S, 0, 0);
    cout << x << endl;
}

int main() {
    solve();
    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)

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

bool isin(int x, int y){
  bool ans;
  if(0 <= x and x < h and 0 <= y and y < w) ans = true;
  else ans = false;
  return ans;
}

int changeto(int to,vector<vector<int>> &tmpp){
  queue<pair<int,int>> q;
  int from = tmpp[0][0];
  if(from == to) return 0;

  q.push(pair<int,int>(0,0));
  tmpp[0][0] = to;
  int res = 1;

  while(not q.empty()){
    pair<int,int> p = q.front();
    q.pop();

    rep(i, dx.size()){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(isin(nx,ny) and tmpp[nx][ny] == from){
	q.push(pair<int,int>(nx, ny));
	tmpp[nx][ny] = to;
	res++;
      }
    }
  }
  return res;
}

int rec(int depth,vector<vector<int>> p){
  if(depth == 4){
    changeto(c,p);
    int res = changeto(-1,p);
    return res;
  }

  int res = 0;
  FOR(i,1,7){
    vector<vector<int>> tmpp = p;
    changeto(i,tmpp);
    res = max(res, rec(depth+1, tmpp));
  }
  return res;
}
	      
int main(void){
  while(cin >> h >> w >> c, h){
    vector<vector<int>> p(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> p[i][j];

    int res = rec(0,p);
    cout << res << endl;
  }
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  int sum = A + B + C;
  int m = max(max(A,B),C);
  int n = min(min(A,B),C);
  int o = sum - m - n;
  int kaisuu = 0;
  while(kaisuu < K){
    m *= 2;
    kaisuu++;
  }

  cout << m + n + o;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	map<LL,LL> m1;
	cin>>n;
	LL s=0;
	for(i=0;i<n;i++){
		cin>>a;
		m1[a]++;
		s+=a;
	}
	cin>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		s+=(b-a)*m1[a];
		m1[b]+=m1[a];
		m1[a]=0;
		cout<<s<<endl;
	}
}

Measured memory_bytes: 9436
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
L = []
for i in range(M):
    P, Y = map(int, input().split())
    L.append([P, Y, i])

L = sorted(L)

reset = 0
count = 0
ans = []
for i in range(M):
    if L[i][0] != reset:
        reset = L[i][0]
        count = 1
    else:
        count += 1
    
    ans.append([L[i][2], str(reset).zfill(6) + str(count).zfill(6)])

ans = sorted(ans)

for i in range(M):
    print(ans[i][1])

Measured memory_bytes: 43956
s = input()
n = len(s)
ans = 0
for bit in range(1 << (n-1)):
    f = s[0]
    for i in range(n-1):
        if bit & 1 << i:
            f += '+'
        f += s[i+1]
        
    ans += sum(map(int, f.split('+')))
    
print(ans)

Measured memory_bytes: 41452
from collections import *
N = int(input())
As = list(map(int, input().split()))

def solve(arr1, arr2):
    cnt1 = Counter(arr1)
    cnt2 = Counter(arr2)

    most1 = cnt1.most_common()
    most2 = cnt2.most_common()

    # 1文字しかないときの処理を簡単にするためにダミーのエントリを追加
    most1.append(('_', 0))
    most2.append(('_', 0))

    # (i) 最頻出文字が異なる → 単に最頻出文字を採用すればよい
    if most1[0][0] != most2[0][0]:
        return len(arr1) * 2 - most1[0][1] - most2[0][1]
    # (ii) 最頻出文字が同じ → 2通り試して良い方を採用
    else:
        ans1 = len(arr1) * 2 - most1[0][1] - most2[1][1]
        ans2 = len(arr1) * 2 - most1[1][1] - most2[0][1]
        return min(ans1, ans2)

arr1 = As[0::2]
arr2 = As[1::2]
print(solve(arr1, arr2))


Measured memory_bytes: 21944
#include "bits/stdc++.h"

using namespace std;

#define ll          long long int

static const int maxn = 1000 + 5;

struct structure
{
      ll w, s, v;
      structure(ll w = 0, ll s = 0, ll v = 0) : w(w), s(s), v(v) {}
      inline void read()
      {
            scanf("%lld %lld %lld", &w, &s, &v);
      }
      inline bool operator < (const structure &p) const
      {
            return ((p.w + p.s) > (w + s));
      }
};

int N;
structure block[maxn];

ll dp[1000+5][100000+4];
bool memoize[1000+5][100000+4];

inline ll solve(int pos, ll weight)
{
      if (pos > N) return 0;
      if (weight > 10000) return 0;
      ll &ret = dp[pos][weight];
      bool &mem = memoize[pos][weight];
      if (mem) return ret;
      mem = 1;
      ret = 0;
      if (weight <= block[pos].s)
      {
            ret = max(ret, block[pos].v + solve(pos+1, weight + block[pos].w));
      }
      ret = max(ret, solve(pos+1, weight));
      return ret;
}

int main()
{
      scanf("%d", &N);
      for (int i = 1; i <= N; i++) block[i].read();
      sort(block+1, block+N+1);
      printf("%lld", solve(1, 0));
}



Measured memory_bytes: 879104
#include<iostream> 
using namespace std; 
int main(){
    int W,H,x,y,r;
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
    if((x+r<=W)&&(y+r<=H)&&(x-r>=0)&&(y-r>=0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    }


Measured memory_bytes: 3112
import sys
n=int(input())
s=int(input())

if n==s:
  print(n+1)
  sys.exit(0)

def f(b,n):
  ret=0
  while n:
    ret+=n%b
    n//=b
  return ret

for b in range(2,int(n**0.5)+1):
#for b in range(2,n+2):
  ss=f(b,n)
  if ss==s:
    print(b)
    sys.exit(0)

#n=pb+q
for p in range(int((n-1)**0.5),0,-1):
  q=s-p
  b=(n-q)//p
  if q<0 or b<=q or b<2 or (n-q)%p!=0:
    continue
    
  #print(b,p,q)
  ss=f(b,n)
  if ss==s:
    print(b)
    sys.exit(0)
    
print(-1)

Measured memory_bytes: 40684
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define all(x) (x).begin(), (x).end
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template <class F, class T> void convert(const F &f, T &t){	stringstream ss; ss << f; ss >> t;}



int f(int a, int x){
	return (int)(a * (100+x) / 100);
}

bool solve(){
	int x, y, s;
	cin>> x>> y>> s;
	if(x==0 && y==0 && s==0) return false;

	vector<int> h(s);
	for(int i=1;i<s;++i){
		int a = 1;
		while(f(a, x) <= i) ++a;
		--a;
		if(f(a, x) == i) h[i] = a;
	}

	int ans = 0;
	for(int i=1;i<s;++i) ans = max(ans, f(h[i], y) + f(h[s-i], y));
	cout<< ans<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	while(solve());
	return 0;
}

Measured memory_bytes: 1196
# import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, a, b, c, d = list(map(int,ipti().split()))
    a -= 1
    b -= 1
    c -= 1
    d -= 1

    s = input()

    if c > d:
        s_groupby = itertools.groupby(s[b-1:d+2])
        for key, group in s_groupby:
            group_list = list(group)
            if key == "." and len(group_list) >= 3:
                break
        else:
            print('No')
            sys.exit()

    for i in range(a + 1, d):
        if s[i] == "#":
            if s[i + 1] == "#":
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 42488
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S, T; cin >> S >> T; 
	int count = 0; 
	if(S.at(0) == T.at(0)) count ++; 
	if(S.at(1) == T.at(1)) count ++; 
	if(S.at(2) == T.at(2)) count ++; 
	cout << count << endl; 
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{      
    
    public void Slove()
    {
        string command = Console.ReadLine();
        int gCount = command.Count(x => x == 'g');
        int pCount = command.Length - gCount;
        int result = (gCount - pCount) / 2;
        System.Console.WriteLine(result);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


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

#define int long long

using namespace std;

int ans[200001];
vector <int> g[200001];
int n,  k;
int u[200001];
int mx;
int d[200001];
int a[200001];

void dfs (int v) {
	u[v] = 1;
	for (auto to : g[v]) {
		if (u[to]) continue;
		dfs (to);
		ans[v] += ans[to];
		d[v] = max (d[v], d[to] + 1);
	}
	if (d[v] >= k - 1 && a[v] != 1) {       
		ans[v] ++;
		d[v] = -1;
	}
}

 main () {
    ios_base::sync_with_stdio (0);
    cin.tie (0), cout.tie (0);
	cin >> n >> k;
	for (int i = 1;i <= n;i ++) {
		int x;
		cin >> x;
		a[i] = x;
		a[1] = 1;
		if (i == 1) {
			if (x != 1) ans[1] = 1;
		}
		else g[x].push_back (i);
	}
	dfs (1);
	cout << ans[1];
	return 0;
}

Measured memory_bytes: 17536
///Good words cool more than cold water.
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();

		int b = a;
		int sum = 0;
		while(b > 0) {
			sum += b%10;
			b -= b%10;
			b /= 10;
		}
		if(a%sum == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

using namespace std ; 

const int N = 1e6 +  7 ; 

long long n , ans =-1e17 ; 
long long a[N]  ; 
long long dp[N][5] ; 


long long solve(int i , int rem ){
    if(i>=n)return 0 ; 
    if(dp[i][rem]!=-1)return dp[i][rem] ; 
    long long ret = -1e18;     
    ret = max(ret ,  a[i] +  solve(i+2 , rem) ) ; 
    for(int j = 1 ;  j<=rem ;j ++){
        ret = max(ret , a[i] + solve( i+2 + j , rem - j) ) ; 
    }
    return dp[i][rem] = ret ; 
}

int main(){
    memset(dp , -1 , sizeof dp )  ; 
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0) ;    
    //freopen("in.in" , "r" , stdin) ; 
    cin>>n ; 
    for(int i = 0 ;i <  n;i++){
        cin>>a[i] ;
    }
    if(n%2){
        ans = max(ans , solve(0 , 2) ) ; 
        ans = max(ans , solve(1 , 1)) ; 
        if(n > 2)
        ans = max(ans , solve(2 , 0)) ; 
    }
    else{
        ans = max(ans , solve(0 , 1) ) ;
        ans = max(ans , solve(1 , 0)) ; 
    }
    cout<<ans ;  
    return 0 ; 
}

Measured memory_bytes: 52088
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D, A, XH):
    XH.sort()
    X = [x for x, _ in XH]
    H = [h for _, h in XH]

    q = deque()
    ans = 0
    dmg = 0
    for i in range(N):
        while q and q[0][0] < X[i]:
            _, d = q.popleft()
            dmg -= d
        if H[i] <= dmg:
            continue
        ans += -(-(H[i] - dmg) // A)
        q.append((X[i]+2*D, (-(-(H[i] - dmg) // A))*A))
        dmg += (-(-(H[i] - dmg) // A))*A
    return ans


def main():
    N, D, A = read_int_n()
    XH = [read_int_n() for _ in range(N)]
    print(slv(N, D, A, XH))


if __name__ == '__main__':
    main()


Measured memory_bytes: 110116
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;


int main(){
    ll N;
    cin>>N;
    vl A(N);
    F0R(i,N){
        cin>>A[i];
    }
    multiset<ll> ms;
    for(auto v:A){
        if(ms.lower_bound(v)!=ms.begin()){
            ms.erase(prev(ms.lower_bound(v)));
        }
        ms.insert(v);
    }
    
    out(ms.size());
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

void solve() {
  string s;
  cin >> s;

  int start = 0;
  int end = s.size() - 1;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A'){
      start = i;
      break;
    }
  }
  for(int i = s.size() - 1; i >=0; i--){
    if(s[i] == 'Z'){
      end = i;
      break;
    }
  }
  cout << end - start + 1<< endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] a = new int[n+2];
		for(int i=0;i<m;i++) {
			a[in.nextInt()]++;
			a[in.nextInt()+1]--;
		}
		for(int i=1;i<=n;i++) {
			a[i] += a[i-1];
		}
		int ans = 0;
		for(int i=0;i<=n;i++) {
			if(a[i]==m) ans++;
		}
		System.out.println(ans);
		in.close();
	}

}


Measured memory_bytes: 64328