akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n){ int ret = 1; for(int i = 1; i < n + 1; ++i) { ret = ret * i; } return ret; }

/* 最大公約数 */
template <typename T>T gcd(T x, T y){ return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>T lcm_n(vector<T> &numbers) { T l; l = numbers[0]; for(int i = 1; i < numbers.size(); ++i) { l = lcm(l, numbers[i]); } return l; }

/*
 * DP向け
 */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*
 * グラフ
 */
class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;
 
    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }
 
    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }
 
        int res = 0;
 
        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }
 
        return dp[v] = res;
    }
};

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

  vector<int> ans(N,0);

  for(int i = 0; i < N-1; ++i){
    int tmp;
    cin >> tmp;
    --tmp;
    ++ans[tmp];
  }

  for(auto v : ans){
    cout << v << endl;
  }

  return 0;
}


Measured memory_bytes: 4048
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

int n;
int main() {
	map<int, int>m;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		auto it = m.find(a);
		if (it != m.end()) {
			m[a]++;
		}
		else {
			m[a]=1;
		}
	}
	int ans = 0;
	for (auto it = m.begin(); it != m.end(); it++) {
		//cout << it->first << " " << it->second << endl;
		if ((it->first) <= (it->second)) {
			ans += it->second - it->first;
		}
		else {
			ans += it->second;
		}
	}
	cout << ans << endl;
	//system("pause");
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int i,j,k,n,w;
    cin>>n>>w;
    long long int a[n],b[n],dp[n+1][w+1];
    for(i=0;i<n;i++)
        cin>>a[i]>>b[i];
    for(i=0;i<=n;i++){
        for(j=0;j<=w;j++){
            if(i==0||j==0)
                dp[i][j]=0;
            else if(a[i-1]>j)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],b[i-1]+dp[i-1][j-a[i-1]]);
        }
    }
    cout<<dp[n][w];
    return 0;
}

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

using namespace std;

const int MOD=1e9+7;

long long mem[1005][1005],mem2[1005][1005];
long long nck[1005][1005];
long long fac[1005],invfac[1005];
int n,a,b,c,d;

int mul(long long a,long long b)
{
	a%=MOD; b%=MOD;
	return (1LL*a*b)%MOD;
}

long long poww(long long x,int y)
{
	if(y==0) return 1;
	if(y&1) return mul(poww(x,y-1),x);
	return poww(mul(x,x),y/2);
}

int ways(int n,int m)
{
	if(n==0) return 1;
	if(mem2[n][m]!=-1) return mem2[n][m];
	return mem2[n][m]=mul(nck[n*m][m],ways(n-1,m));
}

int main()
{
	cin >> n >> a >> b >> c >> d;
	fac[0]=1;
	for(int i=1;i<=n;i++) {fac[i]=mul(fac[i-1],i); invfac[i]=poww(fac[i],MOD-2);}
	for(int i=0;i<=n;i++)
	{
		nck[i][0]=1;
		for(int j=1;j<=i;j++)
			nck[i][j]=(nck[i-1][j]+nck[i-1][j-1])%MOD;
	}
	memset(mem2,-1,sizeof mem2);
	mem[b+1][0]=1;
	for(int i=b;i>=a;i--)
	{
		for(int j=n;j>=0;j--)
		{
			//mem[i][j] -> mem[cur][rem];
			mem[i][j]=mem[i+1][j];
			for(int k=c;j-i*k>=0&&k<=d;k++)
			{
				//cout << i << " " << j << " " << k << " : " << mem[i+1][j-i*k] <<" " << nck[j][i*k] << " " << ways(k,i) << endl;
				mem[i][j]+=mul(mul(mul(mem[i+1][j-i*k],nck[j][i*k]),ways(k,i)),invfac[k]);
				mem[i][j]%=MOD;
			}
		}
	}
	cout << mem[a][n] << endl;
}

Measured memory_bytes: 23168
#include<bits/stdc++.h>
using namespace std;
long long n,m,s,t,x,y,z,g,top,head,tail,top1,top2,top3,min1,i,j,ans,ans2,
		  o=1000000000,zz[2100000+10],zz2[2100000+10],zz3[2100000+10],
		  to[2100000+10],nex[2100000+10],fir[2100000+10],fei[2100000+10],
		  liu[2100000+10],d[40000000+10],book[2100000+10],vis[2100000+10];
long long rx[1005],ry[1005],rc[1005],bx[1005],by[1005],bc[1005],a,b,c,e;
int lj(long long u,long long v,long long w,long long f){
	//cout<<u<<" "<<v<<" "<<w<<" "<<f<<endl;
	top++;
	to[top]=v;
	liu[top]=w;
	fei[top]=f;
	nex[top]=fir[u];
	fir[u]=top;
	return 0;
}
int lj2(long long u,long long v,long long w,long long f){
	lj(u,v,w,f);
	lj(v,u,0,-f);
	return 0;
}
int main(){
/*
	scanf("%lld%lld%lld%lld",&n,&m,&s,&t);
	for(i=1;i<=m;i++){
		scanf("%lld%lld%lld%lld",&x,&y,&z,&g);
		lj(x,y,z,g);
		lj(y,x,0,-g);
	}*/
	scanf("%lld",&n);
	s=(n<<1)+1;
	t=s+1;
	a=t+1;
	b=a+1;
	c=b+1;
	e=c+1;
	for(i=1;i<=n;i++)
		scanf("%lld%lld%lld",&rx[i],&ry[i],&rc[i]);
	for(i=1;i<=n;i++)
		scanf("%lld%lld%lld",&bx[i],&by[i],&bc[i]);
	for(i=1;i<=n;i++){
		lj2(i,a,rc[i],rx[i]+ry[i]);
		lj2(i,b,rc[i],rx[i]-ry[i]);
		lj2(i,c,rc[i],-rx[i]+ry[i]);
		lj2(i,e,rc[i],-rx[i]-ry[i]);
	}
	for(i=1;i<=n;i++){
		lj2(a,i+n,bc[i],-bx[i]-by[i]);
		lj2(b,i+n,bc[i],-bx[i]+by[i]);
		lj2(c,i+n,bc[i],bx[i]-by[i]);
		lj2(e,i+n,bc[i],bx[i]+by[i]);
	}
	for(i=1;i<=n;i++)
		lj2(s,i,rc[i],0);
	for(i=1;i<=n;i++)
		lj2(i+n,t,bc[i],0);
	n=e;
	o*=o;
	while(1)
	{
		head=1;tail=1;
		d[1]=s;
		
		for(i=1;i<=n;i++)
			vis[i]=-o;
		vis[s]=0;
		book[s]=1;
		while(head<=tail){
			top2=d[head];
			top1=fir[top2];
			while(top1!=0){
				if(vis[top2]+fei[top1]>vis[to[top1]]&&liu[top1]!=0){
					vis[to[top1]]=vis[top2]+fei[top1];
					zz[to[top1]]=top2;
					zz2[to[top1]]=liu[top1];
					zz3[to[top1]]=top1;
					if(book[to[top1]]==0)
					{
						tail++;
						d[tail]=to[top1];
						book[to[top1]]=1;
					}
				}
				top1=nex[top1];
			}
			head++;
			book[top2]=0;
		}
		if(vis[t]<0)
			break;
		top1=t;
		min1=o;
		while(top1!=s){
			min1=min(min1,zz2[top1]);
			top1=zz[top1];
		}
		top1=t;
		ans+=min1;
		ans2+=min1*vis[t];
		while(top1!=s){
			top2=zz3[top1];
			if(top2%2==1)
				top3=top2+1;
			else
				top3=top2-1;
			top1=zz[top1];
			liu[top2]-=min1;
			liu[top3]+=min1;
		}
	}
	cout<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 20736
#include<stdio.h>
void printDiff(int,int);
int main(void)
{
  int a,b;
  scanf("%d%d",&a,&b);
  printDiff(a,b);
  return 0;
}
void printDiff(int a,int b)
{
  if(a<b) printf("a < b");
  if(a>b) printf("a > b");
  if(a==b) printf("a == b");
  printf("\n");
}



Measured memory_bytes: 2072
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 998244353
#define mp make_pair
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (ll)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()

using namespace std;

vector<vector<int> > val,a;

int n;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    a.resize(n,vector<int> (3));
    f(i,0,n)
    {
        vector<int> v(4,-1);
        val.pb(v);
    }
    f(i,0,n)
    {
        f(j,0,3)
            cin>>a[i][j];
    }
    cout<<dp(0,3);
}

Measured memory_bytes: 19760
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int max = X*4;
        int min = X*2;

        System.out.println(Y%2 == 0 && min<=Y && Y<=max ? "Yes" : "No");
    }
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;
ll N;

void count(ll res, ll use, ll &cnt) {
    if (res > N) return ;
    if (use == 0b111) cnt++;

    count(res * 10 + 3, use | 0b001, cnt);
    count(res * 10 + 5, use | 0b010, cnt);
    count(res * 10 + 7, use | 0b100, cnt);
}
int main()
{
    cin >> N;

    ll ans = 0;
    count(0, 0, ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}


ll f[1000009];


int main()
{
speed

ll n,k;
cin>>n>>k;
ll a[n];
rep(i,0,n) cin>>a[i];
ll l=1;
ll r=1e10;
ll ans=1e10;
while(l<=r)
{
	ll m=(l+r)/2;
	ll c=0;
	rep(i,0,n)
	{
		if(a[i]%m==0) c+=(a[i]/m-1);
		else c+=(a[i]/m);
	}
	if(c<=k)
	{
		ans=min(ans,m);
		r=m-1;
	}
	else
	{
		l=m+1;
	}
	
}
cout<<ans<<endl;



}



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

bool grid[80][80][6400];
int z[80][80];

int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> z[i][j];
    int x;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &x), z[i][j] = abs(z[i][j] - x);
    grid[0][0][z[0][0]] = true;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (i + 1 < h){
                for (int k = 0; k < 6400; k++){
                    if (!grid[i][j][k]) continue;
                    if (k + z[i + 1][j] < 6400) grid[i + 1][j][k + z[i + 1][j]] = true;
                    if (abs(k - z[i + 1][j]) < 6400) grid[i + 1][j][abs(k - z[i + 1][j])] = true;
                }
            }
            if (j + 1 < w){
                for (int k = 0; k < 6400; k++){
                    if (!grid[i][j][k]) continue;
                    if (k + z[i][j + 1] < 6400) grid[i][j + 1][k + z[i][j + 1]] = true;
                    if (abs(k - z[i][j + 1]) < 6400) grid[i][j + 1][abs(k - z[i][j + 1])] = true;
                }
            }
        }
    }
    for (int i = 0; i < 6400; i++){
        if (grid[h - 1][w - 1][i]){
            printf("%d\n", i);
            return 0;
        }
    }
}

Measured memory_bytes: 40192
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)
#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll oo=1e15;
int n,a[100005],b[100005],c[100005];
char A='a',B='b',C='c';
map<pair<int,char>,ll>calc;
ll vacation(int day,char last){
    if(day==n+1) return 0;
    if(calc[{day,last}])
        return calc[{day,last}];
    ll maxi=0;
    if(last!=A)
        maxi=max(maxi,a[day]+vacation(day+1,A));
    if(last!=B)
        maxi=max(maxi,b[day]+vacation(day+1,B));
    if(last!=C)
        maxi=max(maxi,c[day]+vacation(day+1,C));
    calc[{day,last}]=maxi;
    return maxi;
}
int main()
{
    scanf("%d",&n);
    f(i,1,n+1)
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    cout<<vacation(1,'Z')<<'\n';
    return 0;
}


Measured memory_bytes: 29568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;

int main() {
  int x; cin >> x;
  int h = x / 500 * 1000;
  x %= 500;
  h += x / 5 * 5;
  cout << h << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int i, n, minr, nowr, maxd, nowd;
	scanf("%d", &n); /*n >= 2*/
	scanf("%d %d", &minr, &nowr);
	maxd = nowd = nowr - minr;
	for (i = 3; i <= n; i++) {
		if (nowr < minr) minr = nowr;
		scanf("%d", &nowr);
		nowd = nowr - minr;
		if (nowd > maxd) maxd = nowd;
	}
	printf("%d\n", maxd);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N;
    cin >> N;
    ll A[100000];
    for(int i=0;i<N;i++)
        cin >> A[i];
    
    ll ans = 0, p;
    for(int i=0;i<N;i++){
        p = A[i] / 2;
        ans += p;
        A[i] -= 2*p;
        if(i>0){
            p = min(A[i-1], A[i]);
            ans += p;
            A[i] -= p;
            A[i-1] -= p;
        }
        if(i<N-1){
            p = min(A[i], A[i+1]);
            ans += p;
            A[i] -= p;
            A[i+1] -= p;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/16  Problem: nagoya_19_05  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N,K;

LL ans = 0LL;

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

	cin >> N>>K;
	vector<PLL>v;
	FOR(i, 0, N) {
		LL a, b; cin >> a >> b;
		v.push_back(PLL(a, b));
	}
	SORT(v);
	FOR(i, 0, N) {
		LL val, num;
		val = v[i].first;
		num = v[i].second;
		ans += num;
		if (K <= ans) {
			cout << val << endl; return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> c(100000),d(100000);
    rep(i,100000){
        c[i].fi=0;
        c[i].se=i+1;
        d[i].fi=0;
        d[i].se=i+1;
    }
    rep(i,n/2){
        int a,b;
        cin >> a >> b;
        c[a-1].fi++;
        d[b-1].fi++;
    }
    sort(all(c));
    reverse(all(c));
    sort(all(d));
    reverse(all(d));
    if(c[0].se!=d[0].se){
        cout << n-c[0].fi-d[0].fi << endl;
        return 0;
    }
    cout << min(n-c[1].fi-d[0].fi,n-c[0].fi-d[1].fi) << endl;
}

Measured memory_bytes: 3328
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Queue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;



public class Main{
	
	static int posx;
	static int posy;
	static int type;
	static int diff;
	static int INF = Integer.MAX_VALUE;
	static int[][] d;
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt(),K=sc.nextInt();
	 
	 List<Integer> use=new ArrayList<Integer>();
	 use.add(0);use.add(1);use.add(2);use.add(3);use.add(4);use.add(5);
	 use.add(6);use.add(7);use.add(8);use.add(9);
	 
	 for(int i=0;i<K;i++) {
		 Integer temp=sc.nextInt();
		 if(use.contains(temp)) {
			 use.remove(temp);
		 }
	 }
	 
	 int strindex=0;
	 
	 int result=N;
	 while(true) {
		 boolean flag = true;
		 String str=String.valueOf(result);
		 for(int i=0;i<str.length();i++) {
			 if(!use.contains(Integer.valueOf(str.substring(i,i+1)))) {
				 flag=false;
				 break;
			 }
		 }
		 
		 if(flag) {
			 System.out.println(result);
			 break;
		 }
		 
		 result++;
		 
	 }
	 
	
	 
	 
	 
	 
 }
	


}



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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;


int main() {
    int n;
    cin >> n;

    vector<int> numbers(n);
    rep(i, n) cin >> numbers[i];

    if (numbers.front() != 0) {
        cout << -1 << endl;
        ret();
    }

    vector<int> dp(n);
    dp.back() = numbers.back();
    for (int i = n - 2; i >= 0; i--) {
        dp[i] = max(numbers[i], dp[i + 1] - 1);
    }

    rep(i, n) {
        if (numbers[i] < dp[i]) {
            cout << -1 << endl;
            ret();
        }
    }
    ll ans = 0;
    rep(i, n - 1) {
        if (dp[i] > dp[i + 1] - 1) {
            ans += dp[i];
        }
    }
    ans += numbers.back();

    cout << ans << endl;

}





Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#include<map>
#define MEM(var,val) memset(var,(val),sizeof(var))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nitro   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second

ll dp[100001][3];
ll hap[100001][3];
ll n,k;

ll rec(ll i,ll c)
{
    if(i>n)return 0;
    if(i==n)return hap[i][c];
    if(dp[i][c]!=-1)
        return dp[i][c];
        return dp[i][c]=hap[i][c]+MAX(rec(i+1,(c+1)%3),rec(i+1,(c+2)%3));

}
int main()
{

    cin>>n;
    MEM(dp,-1);
    for(int i=1;i<=n;i++)
        cin>>hap[i][0]>>hap[i][1]>>hap[i][2];
        cout<<MAX(MAX(rec(1,0),rec(1,1)),rec(1,2));

}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV 998244353
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-10;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding space */
template<class T>
struct FT{
    vector<T> d;
    FT(size_t n):d(n+1){}
    T sum(size_t i){T s{};for(++i;i>0;i-=i&-i)s+=d[i];return s;}
    T sum(size_t i,size_t j){return i?sum(j)-sum(i-1):sum(j);}
    void add(size_t i,T x){for(++i;i<d.size();i+=i&-i)d[i]+=x;}
};

FT<ll> table(1000000);

int main(){
  int n; cin >> n;
  string s; cin >> s;
  rep(i,n){
    if(s[i] == '.')  table.add(i,1);
  }
  ll ans = min(table.sum(1000000), n - table.sum(1000000));
  rep(i,n){
    ans = min(ans, i + 1 - table.sum(i) + (table.sum(i+1,1000000)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  unsigned long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	string s;
	cin>>s;
	int a,b,c,d;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	// 000
	// 001
	// 010
	// 011
	// 100
	// 101
	// 110
	// 111
	if(a-b-c-d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"; 
	}
	else if(a-b-c+d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
	}
	else if(a-b+c-d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
	}
	else if(a-b+c+d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
	}
	else if(a+b-c-d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
	}
	else if(a+b-c+d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
	}
	else if(a+b+c-d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
	}
	else if(a+b+c+d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
	}



}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

int main(){
    int N,M;
    int C;
    cin >> N >> M;
    cin >> C;
    int A;
    int B[25];
    int i,j;

    for(i=0; i<M; i++){
        cin >> B[i];
    }

    int value;
    int count=0;

    for(i=0; i<N; i++){
        value=0;
        for(j=0; j<M; j++){
            cin >> A;
            value+=A*B[j];
        }   
        if(value+C>0) count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3612
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

counter = 0
for i in range(N):
    s = C
    A = list(map(int, input().split()))
    for j in range(M):
        s += A[j] * B[j]
    if s > 0:
        counter += 1
print(counter)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back
#define mod int(1e9+7)
#define N int(2e5+100)
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define si second
using namespace std;
ll power(ll x, ll n){
   if(n==0)
      return 1ll;
   ll y=power(x,n/2);
   y=(y*y)%mod;
   if(n%2)
      return (x*y)%mod;
   return y;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	ll p[k+1],ans=0*1ll;
	for(ll g=k;g>=1;g--){
	   p[g]=power((k/g),n);
	   for(ll m=2;m*g<=k;m++){
	      p[g]-=p[m*g];
         if(p[g]<0ll)
            p[g]+=mod;
      }
      ans=(ans+(p[g]*g)%mod)%mod;
   }
   cout<<ans<<'\n';
   return 0;
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
 
 
int main(){
	fast;
	lli n, r;
	cin>>n>>r;
	lli cnt=0;
	while(n>0){
	    n/=r;
	    cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 256
from math import gcd
from collections import defaultdict
N = int(input())
MOD = 10 ** 9 + 7

zero_zero_num = 0
fishes = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero_num += 1
    elif a == 0:
        fishes[(0, -1)] += 1
    elif b == 0:
        fishes[(1, 0)] += 1
    else:
        g = gcd(a, b)
        a, b = a // g, b // g
        if (a > 0 and b > 0) or (a < 0 and b < 0):
            fishes[(abs(a), abs(b))] += 1
        else:
            a, b = (-a, -b) if a < 0 else (a, b)
            fishes[(a, b)] += 1


ans = 1
keys = list(fishes.keys())
visited = set()
for (kai, kbi) in keys:
    if kbi >= 0:
        kaj, kbj = kbi, -kai
    else:
        kaj, kbj = -kbi, kai

    if ((kai, kbi) in visited) or ((kaj, kbj) in visited):
        continue

    ans *= (1 + (pow(2, fishes[(kai, kbi)], MOD) - 1) + (pow(2, fishes[(kaj, kbj)], MOD) - 1))
    ans %= MOD
    visited.add((kai, kbi))
    visited.add((kaj, kbj))

print((ans + zero_zero_num - 1) % MOD)


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

signed main(){

	int N;
	P a[123456];
//	int s[123456];

	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + N, [](P x, P y) { return x.first+x.second > y.first+y.second; });

	int ans = 0;
	for (int i = 0; i < N; i++){
		if (i % 2 == 0) ans += a[i].first;
		else ans -= a[i].second;
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
  int M,D,d1 = 0,d10 = 0,c = 0;
  cin >> M >> D;
  for(int i = 2; i <= M; i++){
    for(int j = 2; j <= D; j++){
      d1 = j % 10;
  	  d10 = j / 10;
      if(d1 >= 2 && d10 >= 2 && i == d1 * d10){
        c++;
      }
    }
  }
  cout << c << endl;
}

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

using namespace std;

int main() {
  int x[5];
  vector<int> y;
  int s = 0;
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  for (int i = 0; i < 5; ++i) {
    s += (x[i] / 10) * 10;
    if (x[i] % 10 != 0) {
      y.push_back(x[i] % 10);
    }
  }

  if (y.size() == 0) {
    cout << s << endl;
  } else {
    sort(begin(y), end(y));
    cout << s + (y.size() - 1) * 10 + y.front() << endl;
  }
}


Measured memory_bytes: 3516
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define MN 300000
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,L,x[MN+5],t[MN+5],pre[MN+5],suf[MN+5];
priority_queue<int> q;
bool Solve(int s)
{
    while(q.size()) q.pop();
    memset(pre,0,sizeof(pre));memset(suf,0,sizeof(suf));
    int P=0,S=0;
    for(int i=1;i<=n;++i)
    {
        int a=(t[i]-1)/(2*L),b=(t[i]-1)%(2*L)+1;s-=a;
        int end1=2*(L-x[i])>=b?2:1;
        int end2=2*x[i]>=b?1:2;
        if(end1==end2)
        {
            if(end1==1) ++P,--pre[i];
            else ++suf[i];
        }
        else
        {
            if(end1==1) ++P,--pre[i],++suf[i];
            else ++P,--pre[i],q.push(i);
        }
       // cout<<i<<" "<<end1<<" "<<end2<<endl;
    }
    for(int i=0;i<=n;++i)
    {
        P+=pre[i];S+=suf[i];
       // cout<<i<<" "<<P<<" "<<S<<endl;
        while((P&&P+S>s-1)||S>s)
        {
            if(q.empty()||q.top()<=i) return false;
            int x=q.top();q.pop();//cout<<"Get"<<x<<endl;
            --P;++pre[x];++suf[x];
        }
    }
    return true;
}
int main()
{
    n=read();L=read();
    for(int i=1;i<=n;++i) x[i]=read();
    for(int i=1;i<=n;++i) t[i]=read();
  //  Solve(6);return 0;
    int l=1,r=1e9,mid,res;
    while(l<=r)
    {
        mid=l+r>>1;
        if(Solve(mid)) res=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%lld\n",1LL*res*L*2);
    return 0;
}


Measured memory_bytes: 7156
int main()
{
  long a, b, n;
  scanf("%ld %ld %ld", &a, &b, &n);
  
  long x;
  if (n < b)
    x = n;
  else
    x = b - 1;
  long ans, t1, t2, t3;
  t1 = a * x / b;
  t2 = a;
  t3 = x / b;
  ans = t1 - t2 * t3;
  printf("%ld", ans);
}

Measured memory_bytes: 1712
//https://youtu.be/LfN_fj57Dhs?t=11
#include<bits/stdc++.h>
//#define endl "\n"
using namespace std;
#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
int n,m;
vector<int> adj[100005];
int vis[100005];
int len[100005];
int dfs(int u,int cnt=0){
vis[u]=1;
for(int i=0;i<adj[u].size();i++){
        if(!vis[adj[u][i]])dfs(adj[u][i]);
    len[u]=max(len[u],len[adj[u][i]]+1);
}
}
int main(){
Me3za();
cin>>n>>m;
for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    adj[u].push_back(v);
}
for(int i=1;i<=n;i++){
      dfs(i);
}
int mx=0;
for(int i=1;i<=n;i++){
    mx=max(mx,len[i]);
}
cout<<mx<<endl;
}


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

int main()
{
    deque<long long> s;
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '0')
        {
            s.push_back(0);
        }
        else if (S[i] == '1')
        {
            s.push_back(1);
        }
        else
        {
            if (!s.empty())
                s.pop_back();
        }
    }
    while (!s.empty())
    {
        cout << s.front();
        s.pop_front();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    lli n,m;
    cin>>n>>m;

    lli count;
    lli x=(n+1)/2;
    lli y=n/2;
    lli p,q;
    p=(m+1)/2;
    q=m/2;

    lli pp,qq;
    pp=x*p;
    qq=y*q;
    count=pp+qq;

    if(n==1 || m==1) {
        count=1;
    }
    cout<<count<<endl;

    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    if (s[k-1] == 'A') s[k-1] = 'a';
    if (s[k-1] == 'B') s[k-1] = 'b';
    if (s[k-1] == 'C') s[k-1] = 'c';
    cout << s << endl;
}

Measured memory_bytes: 256
using System;
namespace ABC153D
{
    public class EmptyClass
    {
        public static void Main(string[] args)
        {
            long h = long.Parse(Console.ReadLine());
            long cnt = 0;
            long i = 0;
            while (h>0)
            {
                h /= 2;
                cnt += (long) Math.Pow(2, i);
                i++;
            }
            Console.WriteLine(cnt);
        }
    }
}


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

using namespace std;
 
int main(){
    int N, M, X, count1=0,count2=0;
    cin >> N >> M >> X;
    vector<int> vec(M);
    for(int i = 0;i<M;i++){
        cin >> vec[i];
        if(vec[i]>X)
            count1++;
        
        else
            count2++;  
    }
    cout << min(count1,count2) << endl;
}

Measured memory_bytes: 256
use std::io::{self, Write};

fn main() {
    let mut stdout = io::stdout();
    let stdin = io::stdin();
    
    let mut input = String::new();

    let (n, m): (u32, u32) = {
        stdin.read_line(&mut input).expect("failed to read line");
        
        let input: Vec<u32> = input
            .split_whitespace()
            .map(|n| n.parse::<u32>().expect("failed to parse string"))
            .collect();

        (input[0], input[1])
    };
    
    let a: Vec<u32> = {
        input.clear();
        stdin.read_line(&mut input).expect("failed to read line");

        input
            .split_whitespace()
            .map(|n| n.parse::<u32>().expect("failed to parse string"))
            .collect()
    };

    match n.checked_sub(a.iter().sum()) {
        Some(left) => println!("{}", left),
        None => println!("-1"),
    };
    stdout.flush().unwrap();
}

Measured memory_bytes: 2248
import sys
n = int(input())
ls = [int(input()) for _ in range(n)]
if 2 not in ls:
    print(-1)
    sys.exit()
i = 1
k = 0
for j in range(n):
    i = ls[i-1]
    k += 1
    if i == 2:
        print(k)
        sys.exit()
print(-1)

Measured memory_bytes: 7084
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#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)
#define sz(x) ((int)(x).size())
#define pb push_back
using ll  = long long;
using vi  = vector<int>;

signed main(){
  int n; cin >> n;
  int a,b,c;
  vi x(n),y(n),h(n);
  rep(i,n){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]){
      a = x[i]; b = y[i]; c = h[i];
    }
  }
  rep(i,101) rep(j,101){
    int H = abs(i - a) + abs(j - b) + c;
    bool f = true;
    rep(k,n){
      int tmp = abs(i - x[k]) + abs(j - y[k]) + h[k];
      if((h[k] != 0 and H != tmp) or (h[k] == 0 and H > tmp)) f = false;
    }
    if(f){
      cout << i << " " << j << " " << H << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
fn main() {
    let (a, mut b): (usize, String) = (read::<usize>(), read::<String>());
    let s1: usize = (b.pop().expect("something wrong") as u8 - b'0') as usize;
    let s0: usize = ((b.pop().expect("something wrong") as u8 - b'0') * 10) as usize;
    b.pop();
    let i: usize = (b.pop().expect("something wrong") as u8 - b'0') as usize;
    println!("{}", i * a + a * (s0 + s1) / 100);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2112
function Main(input){
  var inp = input.split('\n');
  var X = parseInt(inp[0].trim());
  var A = parseInt(inp[1].trim());
  var B = parseInt(inp[2].trim());

  var i = 0;
  var result = 0;
  while(true){
    i++;
    if( X < (A + B * i)){
      i--;
      break;
    }
  }
  console.log(X - (A + B * i));
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

struct Queue{
    int head;
    int tail;
    int Q[1000000];
    
    void init(){
        head = tail = 0;
    }
    
    bool isEmpty(){
        return head == tail;
    }
    
    bool isFull(){
        return head == (tail+1)%100;
    }
    
    void enqueue(int x){
        Q[tail] = x;
        tail++;
        tail %= 1000000;
    }
    
    int dequeue(){
        if (isEmpty()) return 0;
        int x = Q[head];
        head++;
        head %= 1000000;
        return x;
    }
};

int main(){
    int n;
    cin >> n;
    
    int q;
    cin >> q;
    
    Queue name;
    Queue time;
    name.init();
    time.init();
    
    string table[SIZE];
    int num;
    
    for (int i=0; i<n; i++){
        cin >> table[i] >> num;
        name.enqueue(i);
        time.enqueue(num);
    }
    
    int now = 0;
    int tmp1,tmp2;
    
    while(!name.isEmpty()){
        tmp1 = name.dequeue();
        tmp2 = time.dequeue();
        
        if (tmp2 <= q){
            now += tmp2;
            cout << table[tmp1] << ' ' << now << endl;
        }else {
            now += q;
            tmp2 -= q;
            name.enqueue(tmp1);
            time.enqueue(tmp2);
        }
    }
    
    return 0;
}


Measured memory_bytes: 14696
n = int(input())
l = list(map(int,input().split()))

l.append(0)
_n = int(len(l)/2)

a = 0
b = 0

l.sort(reverse=True)

for i in range(_n):
  a += l[i*2]
  b += l[i*2 + 1]

print(a-b)

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

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

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

int main(){
    int N,K; cin >> N >> K;
    ll a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=K;i<N;i++){
        if(a[i-K]<a[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 5180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,N;
  while(1){
    scanf("%d",&N);
    if(N==0)return 0;
    //mid*2,cnt
    pair<int,int> ans=make_pair(0,0);
    for(i=1;i*i<=N;++i){
      if(N%i==0){
        j=N/i;
        if(j&1){
          if(i-j/2>=1&&ans.second<=j){
            ans=pair<int,int>(i*2,j);
          }
          if(j-i*2>=1&&ans.second<=i*2){
            ans=pair<int,int>(j,i*2);
          }
        }
        swap(i,j);
        if(j&1){
          if(i-j/2>=1&&ans.second<j){
            ans=pair<int,int>(i*2,j);
          }
          if(j-i*2>=1&&ans.second<i*2){
            ans=pair<int,int>(j,i*2);
          }
        }
        swap(i,j);
      }
    }
    cout<<(ans.first-ans.second)/2+1<<" "<<ans.second<<endl;
  }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s,t;
  cin >> s >> t;
  Vi a(26),b(26);
  rep(i,0,s.size()){
    a[s[i]-'a']++;
    b[t[i]-'a']++;
  }
  sort(ALL(a));
  sort(ALL(b));
  if(a==b) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 776
import sys
import heapq
import math
input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)
for i in range(m):
    max_a = heapq.heappop(a)
    max_a /= 2
    heapq.heappush(a, max_a)
for i in range(n):
    a[i] = math.floor(-a[i])
print(sum(a))


Measured memory_bytes: 14380
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

h,w = li()
grid = [li() for _ in range(h)]

for hi in range(h):
    for wj in range(w):
        grid[hi][wj] %= 2

ans_list = []
# 奇数を左に流す
for hi in range(h):
    for wj in range(w-1):
        if grid[hi][wj] == 1:
            grid[hi][wj] = 0
            grid[hi][wj+1] = (grid[hi][wj+1]+1) % 2
            ans_list.append((hi+1, wj+1, hi+1, wj+2))




# 奇数を下に流す
for hi in range(h-1):
    if grid[hi][-1] == 1:
        grid[hi][-1] = 0
        grid[hi+1][-1] = (grid[hi+1][-1]+1) % 2
        ans_list.append((hi+1, w, hi+2, w))
        


# 結果を表示する
print(len(ans_list))
for ans in ans_list:
    print(*ans)

Measured memory_bytes: 26584