akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const int INF=1e9;

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

  int N;
  cin>>N;
  int M=3*N;
  vector<int> A(M);
  rep(i,M) cin>>A[i];

  rep(i,M) A[i]--;
  vector<vector<int>> dp(N,vector<int> (N,-INF));
  dp[A[0]][A[1]]=0;
  dp[A[1]][A[0]]=0;
  int all=0;

  vector<int> mva(N,-INF);
  mva[A[0]]=0;
  mva[A[1]]=0;
  for(int k=1;k<N;k++){
    int now=3*k-1;
    if(A[now]==A[now+1]&&A[now+1]==A[now+2]){
      all++;
      continue;
    }

    vector<int> nexmva=mva;
    if(A[now]==A[now+2]) swap(A[now+1],A[now+2]);
    if(A[now+1]==A[now+2]) swap(A[now],A[now+2]);

    if(A[now]==A[now+1]){
      int tar=A[now];
      int val=dp[A[now+2]][A[now+2]];
      vector<int> pp=dp[tar];
      for(int j=0;j<N;j++){
        int V=pp[j];
        if(V!=-INF){
            chmax(dp[j][A[now+2]],V+1);
            chmax(dp[A[now+2]][j],V+1);
            chmax(nexmva[j],V+1);
            chmax(nexmva[A[now+2]],V+1);
        }
      }
      if(val!=-INF){
        chmax(dp[tar][tar],val+1);
        chmax(nexmva[tar],val+1);
      }
    }else{
      for(int l=0;l<=2;l++){
          int V=dp[A[now+l]][A[now+l]];
          if(V==-INF) continue;
          int fir=now+(l+1)%3;
          int sec=now+(l+2)%3;
          chmax(dp[A[fir]][A[sec]],V+1);
          chmax(dp[A[sec]][A[fir]],V+1);
          chmax(nexmva[A[fir]],V+1);
          chmax(nexmva[A[sec]],V+1);  
      }
    }

    for(int j=now;j<=now+2;j++){
        for(int m=0;m<N;m++){
            chmax(dp[A[j]][m],mva[m]);
            chmax(dp[m][A[j]],mva[m]);
            chmax(nexmva[A[j]],mva[m]);
        }
    }

    int ma=*max_element(all(mva));
    for(int j=now;j<=now+2;j++) for(int m=now;m<j;m++){
        chmax(dp[A[j]][A[m]],ma);
        chmax(dp[A[m]][A[j]],ma);
        chmax(nexmva[A[j]],ma);
        chmax(nexmva[A[m]],ma);
    }
    mva=nexmva;
  }

  int ans=0;
  for(int i=0;i<N;i++) for(int j=0;j<N;j++){
    if(dp[i][j]==-INF) continue;
    int last=0;
    if(i==j&&i==A.back()) last=1;
    chmax(ans,dp[i][j]+last);
  }
  ans+=all;
  cout<<ans<<endl;

  return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  vector<int> start(26, -1);
  vector<int> goal(26, -1);
  for (int i = 0; i < S.size(); i++) {
    int a = S[i] - 'a';
    int b = T[i] - 'a';

    if (start[a] != -1 || goal[b] != -1) {
      // すでに変換方法が書かれていた場合
      if (start[a] != b || goal[b] != a) {
        // 一対一対応になっていない
        cout << "No" << endl;
        return 0;
      }
    } else {
      start[a] = b;
      goal[b] = a;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(B / A < C)
    cout << B / A << endl;
  else
    cout << C << endl;
}

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

int main() {
  string s; cin >> s;
  char c[4] = {'A', 'G', 'C', 'T'};
  int ans = 0, tmp = 0;
  for(int i = 0; i < s.size(); i++) {
    bool match = false;
    for(int j = 0; j < 4; j++) {
      if(s[i] == c[j]) match = true;
    }
    if(match) tmp++;
    else {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }
  ans = max(ans, tmp);
  cout << ans << endl;
  return 0;
}


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

int	main()
{
	int	N;
	unordered_map<int, int>	cnt_map;
	cin >> N;
	int	a;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		for (int j = -1; j < 2; ++j) {
			if (cnt_map.count(a + j))
				++cnt_map[a + j];
			else
				cnt_map[a + j] = 1;
		}
	}
	int	max_cnt = 0;
	int	cnt;
	for (auto pr : cnt_map) {
		cnt = pr.second;
		if (max_cnt < cnt)
			max_cnt = cnt;
	}
	cout << max_cnt << endl;
}


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

using namespace std;
using ll=long long;

int main()
{
    int n;cin >>n;
    string s;cin >>s;
    string num[1000];
    for(int i=0;i<1000;i++){
        ostringstream ss;
        ss << i;
        num[i]=ss.str();
        string a="00",b="0";
        if(i<10){
            swap(a,num[i]);
            num[i]+=a;
        }
        else if(i<100){
            swap(b,num[i]);
            num[i]+=b;
        }
    }
    ll ans=0;
    for(int i=0;i<1000;i++){
        bool flg=true;int t=0;
        for(int k=0;k<3;k++){
            bool w=true;
            for(int j=t;j<n;j++){
                if(num[i][k]==s[j]&&w){
                    t=j+1;
                    w=false;
                }
            }
            if(w)flg=false;
        }
        if(flg)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
def cost_for_next_a(c):
    return 123 - ord(c)

s = input()
K = int(input())

new_s = ""


# for i in range(len(s)):
#     if cost_for_next_a(s[i]) <= K:
#         new_s += "a"
#         K -= cost_for_next_a(s[i])
#     elif i != len(s) - 1:
#         new_s += s[i]
#     else:
#         new_s += chr(ord(s[i]) + K)

for i in range(len(s)):
    if i == len(s) - 1:
        if cost_for_next_a(s[i]) <= K:
            new_s += chr(97 + (K - cost_for_next_a(s[i])) % 26)
        else:
            new_s += chr(ord(s[i]) + K)
    elif s[i] == 'a':
        new_s += 'a'
    elif cost_for_next_a(s[i]) <= K:
        new_s += "a"
        K -= cost_for_next_a(s[i])
    else:
        new_s += s[i]

print(new_s)


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

using namespace std;

int main(){
    char S[4];
    cin >> S;
    int temp = 0;
    for (int i = 0; S[i]; ++i) {
        if(S[i] == '+'){
            temp++;
        } else{
            temp--;
        }
    }
    cout << temp;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int H,W,n,m,i,j,k;
	char a[100][100];
	scanf("%d %d",&H,&W);
	m=W+2;
	for(i=0;i<H;i++)
	{
		scanf("%s",&a[i]);
	}
	for(k=0;k<m;k++)
	{
		printf("#");
	}
	printf("\n");
	for(i=0;i<H;i++)
	{
		printf("#");
		for(j=0;j<W;j++)
		{
			printf("%c",a[i][j]);
		}
		printf("#\n");
	}
	for(k=0;k<m;k++)
	{
		printf("#");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    double a[n];
    rep(i, n) cin >> a[i];
    double S = 0.0;
    rep(i, n) S+= 1.0 / a[i];
    cout <<setprecision(10) <<  1.0 / S << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int Q = 2e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,a,b,ans,v[N];
vector<vector<int> > g(N);

int fp(int x, int p) {

    if(!p) return 1;

    int res = fp(x,p/2);

    return (((1LL*res*res)%mod)*(p&1 ? x : 1))%mod;

}

int inv(int x) {

    return fp(x,mod-2);

}

int dfs(int node) {

    v[node] = 1;

    int d = inv(fp(2,n-1));

    int cur = 1;

    int cnt = 0;

    for(auto ch:g[node]) {

        if(!v[ch]) {

            int ret = dfs(ch);
            cnt += ret;
            cur = (cur+fp(2,ret)-1)%mod;

        }


    }

    cur = (cur + fp(2, n-cnt-1) - 1) % mod;

    ans = (ans+(inv(2)*(1+(-((1LL*cur*d)%mod)+mod)%mod))%mod)%mod;

    return cnt+1;

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    for (int i = 0; i < n-1; ++i) {
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }

    dfs(1);

    cout << ans << '\n';

    return 0;
}

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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    rep(i, M) cin >> A.at(i);

    int leftCount = 0;
    int rightCount = 0;
    rep(i, M) {
        if (A.at(i) < X) {
            leftCount++;
        } else {
            rightCount++;
        }
    }

    int ans = min(leftCount, rightCount);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int t[800100];
void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v]=(new_val);
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v]=max(t[2*v],t[2*v+1]);
    }
    return;
}
int sum(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return max(sum(v*2, tl, tm, l, min(r, tm)), sum(v*2+1, tm+1, tr, max(l, tm+1), r));
}
void dfs(int i,int j,vector<int> tree[],int a[],int ans[],int ul)
{
	int tem=sum(1,0,ul,a[i],a[i]);
	int u=sum(1,0,ul,0,a[i]-1)+1;
	update(1,0,ul,a[i],u);
	ans[i]=sum(1,0,ul,0,ul);
	FOR(k,0,tree[i].size())
	{
		if(tree[i][k]!=j)
		dfs(tree[i][k],i,tree,a,ans,ul);
	}
	update(1,0,ul,a[i],tem);
	return;
}
bool che(pair<ll,int> a,pair<ll,int> b)
{return a.second<b.second;}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		pair<ll,int> a[n];
		FOR(i,0,n){cin>>a[i].first;a[i].second=i;}
		sort(a,a+n);
		ll j=1,p=a[0].first,ul;
		FOR(i,0,n)
		{
			if(a[i].first==p)
			a[i].first=j;
			else
			{
				j++;
				p=a[i].first;
				a[i].first=j;
			}
		}
		sort(a,a+n,che);
		ul=j+5;
		int u,v;
		vector<int> tree[n];
		FOR(i,1,n)
		{
			cin>>u>>v;
			tree[u-1].pb(v-1);
			tree[v-1].pb(u-1);
		}
		int ans[n];
		int b[n];
		FOR(i,0,n)
		b[i]=a[i].first;
		dfs(0,-1,tree,b,ans,ul);
		FOR(i,0,n)
		{
			cout<<ans[i]<<'\n';
		}
	}
	return 0;
}


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

typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) {return m / gcd(n, m) * n;}

int main(void) {
	ll h, r;
	cin >> h >> r;
	if (h + r == 0)
		cout << 0 << endl;
	else if (h >= 0)
		cout << 1 << endl;
	else
		cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;


int main(){
  int i,j;
  ll n,d,a;
  cin>>n>>d>>a;
  vector<P> v;
  VI w;
  for(i=0;i<n;i++){
    ll x,h;
    cin>>x>>h;
    v.pb(P(x,h));
  }
  for(i=0;i<n;i++){
    w.pb(v[i].fi+2*d);
  }
  for(i=0;i<n;i++) v.pb(P(w[i],INF));
  sort(v.begin(),v.end());
  
  VI q(n);
  int ind=0;
  ll b=0;
  ll ans=0;
  for(i=0;i<2*n;i++){
    //cout<<v[i].fi<<" "<<v[i].se<<endl;
    //cout<<b<<endl;
    if(v[i].se==INF){
      b-=q[ind];
      ind++;
      //cout<<1<<" "<<i<<" "<<b<<endl;
    }
    else {
      if(v[i].se-b>=0){
        ans+=(v[i].se-b+a-1)/a;
        q[i-ind]=a*((v[i].se-b+a-1)/a);
        b+=q[i-ind]; 
        //cout<<2<<" "<<i<<" "<<b<<endl;
        //cout<<i-ind<<" "<<q[i-ind]<<endl;
      }
    }
  }
  //for(i=0;i<3;i++) cout<<q[i]<<endl;
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 13676
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}




int main(void) {
  ll N;
  cin >> N;
  ll v[22], c[22];
  ll i;
  
  for(i=0; i<N; i++) cin >> v[i];
  for(i=0; i<N; i++) cin >> c[i];
  
  ll ans=0;
  for(i=0; i<N; i++) {
    if(v[i]-c[i]>0) ans+=v[i]-c[i];
  }
  
  pt(ans);
}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

int main(int argc, char **argv) {
    i64 n, k;
    cin >> n >> k;

    cout << (n==k ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>
using namespace std;

//long long a[100000];
//long long b[100000];

using namespace std;
 

bool used[100000];
//int cost[100000][100000];
vector <pair <int, int> > edges[100000];
int main(){
    int V;
    int E;
    cin >> V >> E;
    
    for(int i = 0; i < V; i++){
        used[i] = false;
    }
    for(int i = 0; i < E; i++){
        int s;
        int t;
        int w;
        cin >> s  >> t >> w;
        edges[s].push_back(make_pair(t, w));
        edges[t].push_back(make_pair(s, w));
    }

    priority_queue <pair <int, int> > pq_cost_t;

    int ans = 0;
    pq_cost_t.push(make_pair(0, 0));
    while(!pq_cost_t.empty()){
        auto cur = pq_cost_t.top();
        pq_cost_t.pop();
        if(used[cur.second]){
            continue;
        }
        ans -= cur.first;
        used[cur.second] = true;
        for(int i = 0; i < edges[cur.second].size(); i++){
            int w = edges[cur.second][i].second;
            int t = edges[cur.second][i].first;
            pq_cost_t.push(make_pair(-w, t));
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9968
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e5+1;

int32_t main()
{
	c_p_p();
	int n;
	cin>>n;
	int A[n],sum=0;
	rep(i,0,n)cin>>A[i];
	sort(A,A+n,greater<int>());
	int ans=0,e=0,cnt=0,rem=n-1;
	vi V;
	rep(i,0,n)
	{
		
		if(rem<=e)break;
		ans+=A[i];
		//deb(ans);
		V.pb(A[i+1]);
		--rem;
		++e;
	}
	for(auto it:V)
	{
		if(rem==0)break;
		ans+=it;
		
		rem--;
		
	}
	cout<<ans;


	return 0;
}
	

Measured memory_bytes: 5856
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(S: str):
    N = len(S)
    # 0:文字列の総数 1:Aの数  2:ABの数 3:ABCの数
    ## dp[i][j] = i文字目まで見たときに状態jの数
    ## answer: dp[N][3]

    dp = [[0]*4 for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in (0,1,2,3):
            if S[i] == "?":
                dp[i+1][j] += dp[i][j]*3
            else:
                dp[i+1][j] += dp[i][j]

            dp[i+1][j]%=MOD
            
        ## カウント進める場合
        if S[i] == "A" or S[i] == "?":
            dp[i+1][1] += dp[i][0]
            dp[i+1][1] %= MOD
        
        if S[i] == "B" or S[i] == "?":
            dp[i+1][2] += dp[i][1]
            dp[i+1][2] %= MOD

        if S[i] == "C" or S[i] == "?":
            dp[i+1][3] += dp[i][2]
            dp[i+1][3] %= MOD

    print(dp[N][3]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27692
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
 
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
 
const ll big=998244353;
int exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    
    int n;cin >> n;
    vector<ll> a(n),t(n);
    rep(i,n)cin >> t[i] >> a[i];
    rep2(i,1,n){
        if(t[i-1]<=t[i]&&a[i-1]<=a[i])continue;
        ll tt=t[i];
        t[i]*=max((t[i-1]+t[i]-1)/t[i],(a[i-1]+a[i]-1)/a[i]);
        a[i]*=max((t[i-1]+tt-1)/tt,(a[i-1]+a[i]-1)/a[i]);
    }
    cout << t[n-1]+a[n-1] << endl;
}

Measured memory_bytes: 256
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)


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

int main()
{
    long long int k,x,i,a,b,ans;
    cin>>k>>x;
    a = k - 1;
    ans = (a*2)+1;
    b = x - a;
    for(i=1;i<=ans;i++)
    {
        cout<<b<<endl;
        b++;
    }

    return 0;
}


Measured memory_bytes: 256
class Node
  attr_accessor :parent, :rank
  
  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFindTree
  def initialize(n)
    @nodes = (0..n).to_a.map { |i| Node.new(i) }
  end
  
  def find(x)
    return x if @nodes[x].parent == x
    
    return @nodes[x].parent = find(@nodes[x].parent)
  end
  
  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b
    
    if @nodes[a].rank < @nodes[b].rank
      @nodes[a].parent = b
    else
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end
  
  def same?(a, b)
    find(a) == find(b)
  end
  
  def parents
    @nodes.map(&:parent)
  end
end

n,m=gets.chomp.split.map(&:to_i)
tree = UnionFindTree.new(n+3)
visited = Array.new(n+1,false)
m.times do
  x,y,z=gets.chomp.split.map(&:to_i)
  tree.unite(x,y)
end

h = Hash.new(0)
1.upto(n) do |i|
  h[tree.find(i)] += 1
end
puts h.size


Measured memory_bytes: 17276
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
namespace MCF{
	const int MAXN=120;
	const int MAXM=2100;
	int to[MAXM];
	int next[MAXM];
	int first[MAXN];
	int c[MAXM];
	long long w[MAXM];
	long long pot[MAXN];
	int rev[MAXM];
	long long ijk[MAXN];
	int v[MAXN];
	long long toc;
	int tof;
	int n;
	int m;
	void init(int _n){
		n=_n;for(int i=0;i<n;i++)first[i]=-1;
	}
	void ae(int a,int b,int cap,int wei){
		next[m]=first[a];to[m]=b;first[a]=m;c[m]=cap;w[m]=wei;m++;
		next[m]=first[b];to[m]=a;first[b]=m;c[m]=0;w[m]=-wei;m++;
	}
	int solve(int s,int t,int flo){
		toc=tof=0;
		for(int i=0;i<n;i++)pot[i]=0;
		while(tof<flo){
			for(int i=0;i<n;i++)ijk[i]=9999999999999LL;
			for(int i=0;i<n;i++)v[i]=0;
			priority_queue<pair<long long,int> > Q;
			ijk[s]=0;
			Q.push(make_pair(0,s));
			while(Q.size()){
				long long cost=-Q.top().first;
				int at=Q.top().second;
				Q.pop();
				if(v[at])continue;
				v[at]=1;
				for(int i=first[at];~i;i=next[i]){
					int x=to[i];
					if(v[x]||ijk[x]<=ijk[at]+w[i]-pot[x]+pot[at])continue;
					if(c[i]==0)continue;
					ijk[x]=ijk[at]+w[i]-pot[x]+pot[at];
					rev[x]=i;
					Q.push(make_pair(-ijk[x],x));
				}
			}
			int flow=flo-tof;
			if(!v[t])return 0;
			int at=t;
			while(at!=s){
				flow=min(flow,c[rev[at]]);
				at=to[rev[at]^1];
			}
			at=t;
			tof+=flow;
			toc+=flow*(ijk[t]-pot[s]+pot[t]);
			at=t;
			while(at!=s){
				c[rev[at]]-=flow;
				c[rev[at]^1]+=flow;
				at=to[rev[at]^1];
			}
			for(int i=0;i<n;i++)pot[i]+=ijk[i];
		}
		return 1;
	}
}
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	MCF::init(a);
	for(int i=0;i<b;i++){
		int p,q,r,s;scanf("%d%d%d%d",&p,&q,&r,&s);
		MCF::ae(p,q,r,s);
	}
	int res=MCF::solve(0,a-1,c);
	if(!res)printf("-1\n");
	else printf("%lld\n",MCF::toc);
}

Measured memory_bytes: 1092
#include <stdio.h>

#define TRUE i
#define FALSE 0

int solve(int,int);
int A[2000];
int n;

int solve(int i, int m){
  int res;
  
  if(m==0) return TRUE;
  if(i>=n) return FALSE;

  res = solve(i+1,m) || solve(i+1,m-A[i]);

  return res;
}

int main(){
  int m,q,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

Measured memory_bytes: 580
H,W,K = map(int,input().split())

amari = [1,1,2,3,5,8,13,21]

lis = [0] * W

lis[0] += 1

for j in range(H):

    nlis = [0] * W

    for i in range(W):

        if i > 0:

            if i == 1:
                nlis[i-1] += lis[i] * amari[W-2]

            else:
                nlis[i-1] += lis[i] * amari[i-1] * amari[W-1-i]

        nlis[i] += lis[i] * amari[i] * amari[W-1-i]

        if i < W-1:

            if i == W-2:
                nlis[i+1] += lis[i] * amari[W-2]

            else:
                nlis[i+1] += lis[i] * amari[i] * amari[W-i-2]

    for i in range(W):

        lis[i] = nlis[i] % (10 ** 9+ 7)

print (lis[K-1] % (10**9 + 7))


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

int main(){
  int n, ans=0;
  cin >> n ;
  for(int i=1;i<=n;i++){
    if((to_string(i)).size()%2==1)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3708
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll x, y; 
  cin >> x >> y;
  if(x < y) swap(x, y);
  ll tt = x-y;

  if(tt%2) cout << "IMPOSSIBLE" ;
  else cout << y +  tt/2 << endl;
  return 0;
} //good night.

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int N; cin >> N;
  string s1, s2; cin >> s1 >> s2;
  vector<bool> p;
  rep(i,N){
    if (s1[i]==s2[i]) p.push_back(0);
    else {
      p.push_back(1);
      i++;
    }
  }

  ll ans = 3;
  if (p[0]) ans *= 2;
  ll MOD = 1000000007;
  for (int i=1;i<p.size();i++){
    if (p[i-1]==1 && p[i]==0) continue;
    else if (p[i-1]==1 && p[i]==1) (ans *= 3) %= MOD;
    else (ans *= 2) %= MOD;
  }
  cout << ans << endl;
  




  // cout << fixed << setprecision(10);
  
  return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';

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

int main() {
    int N;
    int ansa[20005], ansb[20005];
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p; --p;
        ansa[p] = p * N + 1;
        ansb[p] = (N - p - 1) * N + i + 1;
    }

    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << ansa[i];
    }
    cout << endl;

    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << ansb[i];
    }
    cout << endl;
    return (0);
}

Measured memory_bytes: 768
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
l.sort()
if n%2==0:
  m=n//2
  sum1=0
  sum2=0
  for j in range(m):
    sum1 += l[j]
    sum2 += l[n-1-j]
  max=2*sum2-2*sum1-l[m]+l[m-1]
  print(max)
else:
  if n==3:
    max1=l[2]+l[1]-2*l[0]
    max2=2*l[2]-l[1]-l[0]
    if  (max1>max2):
      print(max1)
    else:
      print(max2)
  else:
    m=(n-1)//2
    sum1=0
    sum2=0
    for j in range(m+1):
      sum1 += l[j]
      sum2 += l[n-1-j]
    max1=2*sum2-l[m]-l[m+1]-2*sum1+2*l[m]
    max2=2*sum2-2*l[m]-2*sum1+l[m]+l[m-1]
    if  (max1>max2):
      print(max1)
    else:
      print(max2)

Measured memory_bytes: 7512
#include<cstdio>
int K,A[100010];
long long f(long long x){
	for(int i=0;i<K;i++)x=x/A[i]*A[i];
	return x;
}
int main(){
	scanf("%d",&K);
	for(int i=0;i<K;i++)scanf("%d",A+i);
	long long left=0,right=1ll<<60,mid;
	while(right-left>1){
		mid=left+right>>1;
		if(f(mid)<2)left=mid;
		else right=mid;
	}
	long long l=right;
	left=0,right=1ll<<60;
	while(right-left>1){
		mid=left+right>>1;
		if(f(mid)<=2)left=mid;
		else right=mid;
	}
	if(l<=left)printf("%lld %lld\n",l,left);
	else puts("-1");
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	char s[20];
	cin>>n>>s>>k;
	char ch=s[k-1];
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i] != ch) cout<<'*';
		else cout<<s[i];
	}
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll n; cin >> n;
	vector<ll> a(5);
	for( auto &k : a ) cin >> k;
	ll m = *( min_element( a.begin(), a.end() ) );
	if( m >= n ){
		cout << '5' << endl;
	} else {
		cout << 4 + (n+(m-1))/m << endl;
	}
	return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
int main()
{
  ll a,b,N;
  cin>>a>>b;
  if(b==100)N=1000*a+b;
  else if(b<=9)N=10*a+b;
  else N=100*a+b;
  bool T=false;
  ll c=1;
  while(c*c<=N){
    if(c*c==N)T=true;
    c++;
  }
  if(T)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
	int k;
	string s;
	cin >> k;
	cin >> s;
	
	if(s.length() > k){
		string n = "";
		for(int i = 0; i < k; ++i){
			n += s[i];
		}
		n += "...";
		cout << n;
	}else{
		cout << s;
	}
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define R register
#define rep(i,a,b) for(R signed i=a ; i<=b ; ++i)
#define dwn(i,a,b) for(R signed i=a ; i>=b ; --i)
#define go(i,u) for(R signed i=head[u] ; i ; i=a[i].next)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;

inline int read() {
	int res=0,f=1;char ch;
	while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
	do {
		res=res*10+ch-'0';
	} while(isdigit(ch=getchar()));
	return res*f;
}

const int N=2005;

struct Edge {
	int next,to;
}a[N<<1];

int head[N],size;

inline void add(int u,int v) {
	a[++size].next=head[u],a[size].to=v,head[u]=size;
}

inline void insert(int u,int v) {
	add(u,v),add(v,u);
}

bool ok[N];

int n,dp[N],num[N],sum[N];

void dfs(int u,int fa) {
	num[u]=ok[u],sum[u]=0;
	int maxx=0,id=0;
	go(i,u) {
		int v=a[i].to;
		if(v!=fa) {
			dfs(v,u);
			num[u]+=num[v];
			sum[u]+=sum[v]+num[v];
			if(sum[v]+num[v]>maxx) maxx=sum[v]+num[v],id=v;
		}
	}
	if(!id) dp[u]=0;
	else if(sum[u]-maxx>=maxx) dp[u]=sum[u]/2;
	else dp[u]=sum[u]-maxx+min(dp[id],(2*maxx-sum[u])/2);
}

int main() {
	n=read();
	rep(i,1,n) scanf("%1d",&ok[i]);
	rep(i,2,n) insert(read(),read());
	int ans=0x3fffffff;
	rep(i,1,n) {
		dfs(i,0);
		if(sum[i]&1) continue ;
		if(dp[i]==sum[i]/2) ans=min(ans,dp[i]);
	}
	printf("%d",ans!=0x3fffffff?ans:-1);
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		
		int [][]p = new int [k][2];
		int r = 1;
		int l = k+1;
		int r0 = k+2;
		int l0 = 2* k +1;
		int cnt = 0;
		for(int i = k ; i >= 1 ;i--) {
			if(cnt % 2 == 0) {
				p[k-i][0] = r;
				p[k-i][1] = l;
				r++;
				l--;
			}
			else {
				p[k-i][0] = r0;
				p[k-i][1] = l0;
				r0++;
				l0--;
			}
			cnt++;
		}
		for(int i = 0 ;i < k ;i++) {
			System.out.println(p[i][0]+" "+p[i][1]);
		}

	}

}


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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n, p;
    string s;
    cin >> n >> p >> s;

    ll ans = 0;
    if(p == 2 || p == 5){
        rep(i, n){
            if((s[i] - '0')  % p == 0){
                ans += i+1;
            }
        }
    }else{
        ll ten = 1;
        vector<ll> v(p, 0);
        v[0] = 1;
        ll cnt = 0;
        for (int i = n-1; i >= 0; --i) {
            cnt = (cnt + (s[i] - '0') * ten % p) % p;
            ten = ten * 10 % p;
            ans += v[cnt];
            v[cnt] ++;
        }   
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 110

bool solve(){
  int h,w;
  char c[SIZE][SIZE];
  string s;
  bool f[26] = {};
  
  scanf("%d%d",&h,&w);

  if(h == 0) return false;

  for(int i=0;i<h;i++){
    scanf("%s",c[i]);

    for(int j=0;j<w;j++){
      if(c[i][j]!='.' && f[c[i][j]-'A'] == false){
        f[c[i][j]-'A'] = true;
        s += c[i][j];
      }
    }
  }

  sort(s.begin(),s.end());
  
  do{
    char copy_c[SIZE][SIZE];
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        copy_c[i][j] = c[i][j];
      }
    }

    bool check = true;

    for(int p=0;p<s.size();p++){
      int min_h = INF, max_h = -1 ,min_w = INF,max_w = -1;
      
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(copy_c[i][j] == s[p]){
            min_h = min(min_h, i);
            max_h = max(max_h, i);
            min_w = min(min_w, j);
            max_w = max(max_w, j);
          }
        }
      }

      for(int i=min_h;i<=max_h;i++){
        for(int j=min_w;j<=max_w;j++){
          if(copy_c[i][j] != s[p] && copy_c[i][j] != '#')
            check = false;
          copy_c[i][j] = '#';
        }
      }
      
    }

    if(check){
      puts("SAFE");
      return true;
    }
    
  }while(next_permutation(s.begin(),s.end()));
  
  puts("SUSPICIOUS");
  return true;

}

int main(){
  int t;

  scanf("%d",&t);
  
  while(t--) solve();
  
  return 0;
}

Measured memory_bytes: 3172
K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_range=min(K,S)
cnt=0
for x in range(max_range+1):
    for y in range(min(max_range,max(0,S-x-max_range)),min(max_range,S-x)+1):
        z= S-x-y
        if 0 > z:
            break
        if z <= max_range:
            cnt+=1
print(cnt)


Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov
//export PATH=:~/.local/bin

vvll comb(ll n) {
    vvll v(n + 1,vll(n + 1, 0));
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < v.size(); j++) {
        for (int k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}

int main(){
    ll n;
    cin >> n;
    if(n%2==0){
        ll m=comb(n)[n][2]-n/2;
        cout << m << endl;
        repi(i,1,n+1){
            repi(j,i+1,n+1){
                if(i+j!=n+1){
                    cout << i <<" "<< j << endl;
                }
            }
        }
    }else{
        ll m=comb(n)[n][2]-n/2;
        cout << m << endl;
        repi(i,1,n){
            repi(j,i+1,n+1){
                if(i+j!=n){
                    cout << i <<" "<< j << endl;
                }
            }
        }
    }
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;


int main() {
	char input[100];
	int counter = 0;
	cin >> input;
	if (input[0] == input[1] || input[1] == input[2] || input[2] == input[3]) {
		counter++;
	}
	if (counter == 0) {
		cout << "Good" << endl;
	}
	else if (counter != 0) {
		cout << "Bad" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
    ll x; cin >> x;

    ll ans = 0;
    while(x >= 500){
        ans += 1000;
        x -= 500;
    }
    while(x >= 5){
        ans += 5;
        x -= 5;
    }
    print(ans);
}

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

using namespace std;

#define INF 210000000
#define int long long

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

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

signed main() {
		string a,b,c;
		cin >> a >> b >> c;
		cout << a[0] << b[0] << c[0] << endl;
}



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

using namespace std;

int main(){

    long long int a,b,c,k; cin >> a >> b >> c >> k;

    if(a>=k){ cout << k << endl; return 0;}
    if(a+b>=k){
        cout << a << endl;
        return 0;
    }
    cout << a + (k-a-b)*-1 << endl;
    return 0;
}

Measured memory_bytes: 3632
n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    inputs = list(map(int,input().split()))
    c.append(inputs[0])
    a.append(inputs[1:])

ans=100000000000000
for i in range(2**n):
    id_str=str(bin(i))[2:]
    plus=['0']*(n-len(id_str))
    plus_str=''
    for j in range(len(plus)):
        plus_str+=plus[j]
    id = plus_str+id_str
    m_sum=[0]*m
    c_sum=0
    for j in range(n):
        if id[j]=='1':
            for k in range(m):
                m_sum[k]+=a[j][k]
            c_sum+=c[j]
    if min(m_sum)>=x:
        if c_sum<ans:
            ans=c_sum

if ans==100000000000000:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    int n,m,i;
    cin>>n>>m;
    ll x,y;
    vector<pair<ll,ll> >a;
    for(i=0;i<n;i++)
        {cin>>x;
        a.pb({x,1});
        }
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        a.pb({y,x});
    }
    sort(a.rbegin(),a.rend());
    ll ans=0;
    int j=0,p=0;
    while(p<n){
        if(a[j].ss)
        {
            ans+=a[j].ff;
            p++;
            a[j].ss--;
            //cout<<a[j].ff<<e;
        }
        else
            j++;
    }
    cout<<ans<<e;
}



Measured memory_bytes: 6512
#include <bits/stdc++.h>
    using namespace std;
    #define FOR(i,n) for(int i=0;i<n;i++)
    #define why(n,x) int n;while(cin >>n,n!=x)
    #define iFOR(i,x,n)for(int i=x;i<n;i++)
    #define unless(flg) if ( !(flg) )
    #define read cin<<
    #define echo cout<<
    #define fin <<'\n'
    #define __ <<" "<<
    #define ___ <<" "
    #define bash push_back
    #define ALL(x) x.begin(),x.end()
    #define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
    #define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
    #define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
    #define int long long
    #define abs Abs
    typedef long long ll;
    typedef pair < int , int > pii;
    typedef vector < int > vit;
    typedef map < string , int > mstit;
    typedef vector < pii > vpi ;
    typedef greater < pii > gpi;
    typedef priority_queue < pii , vpi , gpi > dijk ;
    const int INF = 0x3f3f3f3f;
    const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
    const int SMOD = 1000000007;
    const int NMOD = 1000000009;
    int dx[]={1,0,-1,0,1,1,-1,-1};
    int dy[]={0,-1,0,1,-1,1,-1,1};
    ll Abs(ll x){return (x<0 ? -x : x);}
    bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
    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; }
    int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
    int gcd(int a,int b){return b?gcd(b,a%b):a;}
    struct xyz{
    xyz(){
    cin.tie(0), ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    };
    }xyzzy;
     
     
    signed main(){
    int a,b,c;
     
    cin >>a >> b >> c;
    cout <<(a*b)/2 fin;
    return 0;
    }
     

Measured memory_bytes: 256
#include<stdio.h>                                                 
                                                                  
int main(void){                                                   
   int N,M,x,y;                                                   
   scanf("%d %d",&N,&M);                                          
   x = N*(N-1);                                                   
   y = M*(M-1);                                                   
   printf("%d",(x+y)/2);                                          
   return 0;                                                      
} 

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		int ans[10] = {0};
		for(int i = 0;i < n;i++){
			int k;
			cin >> k;
			ans[k]++;
		}
		for(int i = 0;i < 10;i++){
			for(int j = 0;j < ans[i];j++) cout << '*';
			if(ans[i] == 0) cout << '-';
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
res = []
for i in range(1, int(n**0.5)+1):
    if n%i == 0:
        res.append([i, int(n/i)])
ans = 10**9+1
for i in range(len(res)):
    tmp = max(len(str(res[i][0])), len(str(res[i][1])))
    if ans > tmp:
        ans = tmp
print(ans)

Measured memory_bytes: 39280
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast int fvariable = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
ll n,m;
vector<vector<ll>>vc(ms);
vector<ll>val(ms);
void solve()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
    }
    for(int i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        vc[a].pb(b);
        vc[b].pb(a);
    }
    for(int i=1;i<=n;i++)
    {
        bool flag=1;
        for(auto it:vc[i])
        {
            if(val[i]<=val[it])
                {flag=0;break;}
        }
        ans+=flag;
    }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 12968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CReplacingInteger solver = new CReplacingInteger();
        solver.solve(1, in, out);
        out.close();
    }

    static class CReplacingInteger {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long k = in.nextLong();
            long ret = n % k;
            if (ret != 0) {
                if (Math.abs(ret - k) < ret) ret = Math.abs(ret - k);
            }
            out.println(ret);
        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            byte b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21460
#include <stdio.h>

int powy(int a,int b){
	int ans=1;
	for(int i=0;i<b;i++){
		ans=ans*a;
	}

	return ans;
}

int main(void){
	int n;
	scanf("%d",&n);
	int count=0;
	for(int i=0;i<8;i++){
		if(powy(2,i)<=n&&n<powy(2,i+1)) count=i;
	}
	printf("%d", powy(2,count));
	return 0;
} 

Measured memory_bytes: 128