akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>	
#include <time.h>
#include <vector>
#include <stdio.h>
#include <memory.h>
#include <string>
#include <string.h>
#include <map>
#include <algorithm>
#include <queue>
#include <set>
#include <time.h>
#include <assert.h>
#include <sstream>
//#include <unordered_map>
#include <bitset>
#include <utility>
#include <iomanip>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <math.h>
#include <cmath>
#include <complex>
using namespace std;
typedef long long ll;
typedef complex<double> point;

const int N = 1e5 + 10;
int n, m, a[N], vis[N], p[N];
vector<int>adj[N];
multiset<int>ms[N];
set<pair<int, int> >st;
int find(int x) {
	if(x == p[x])
		return x;
	return p[x] = find(p[x]);
}

int main() {

	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		p[i] = i;
	}
	for(int i = 0; i < m; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
		u = find(u);
		v = find(v);
		p[u] = v;
	}
	for(int i = 0; i < n; ++i) {
		int u = find(i);
		ms[u].insert(a[i]);
	}
	for(int i = 0; i < n; ++i) {
		int u = find(i);
		st.insert({-int(ms[u].size()),u});
	}
	int u = -1;
	if(st.size()) {
		u = st.begin()->second;
		st.erase(st.begin());
	}
	ll ans = 0;
	while(u != -1 && st.size() >= 1 && ms[u].size()) {
		int v = st.begin()->second;
		st.erase(st.begin());
		ans += *ms[u].begin();
		ans += *ms[v].begin();
		ms[u].erase(ms[u].begin());
		ms[v].erase(ms[v].begin());
		for(auto it = ms[v].begin(); it != ms[v].end(); ++it)
			ms[u].insert(*it);
		++m;
	}
	if(m == n - 1)
		printf("%lld\n", ans);
	else
		puts("Impossible");


	return 0;
}

Measured memory_bytes: 15872
N,T=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
ans=0
for i in range(1,N):
    if t[i]-t[i-1] < T:
        ans+=t[i]-t[i-1]
    else:
        ans+=T
else:
    ans+=T
print(ans)

Measured memory_bytes: 25300
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
#a = A.count(m1)
for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)

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

using namespace std;

int main(){
    int n;
    cin>>n;
    long long s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
        if(i){
            s[i]+=s[i-1];
        }
    }
    int i=0,j=2;
    while(j<n-2){
        if(abs(s[j+1]-s[1]-(s[n-1]-s[j+1]))<abs(s[j]-s[1]-(s[n-1]-s[j]))){
            j++;            
        }
        else{
            break;
        }
    }
    // cout<<i<<" "<<j<<endl;
    long long ans=max(s[i],max(s[1]-s[i],max(s[j]-s[1],s[n-1]-s[j])))-min(s[i],min(s[1]-s[i],min(s[j]-s[1],s[n-1]-s[j])));
    for(int l=2;l<n-2;l++){
        while(i<l-1){
            if(abs(s[i]-(s[l]-s[i]))>abs(s[i+1]-(s[l]-s[i+1]))){
                i++;
            }
            else{
                break;
            }
        }
        while(j<n-2){
            if(abs(s[j]-s[l]-(s[n-1]-s[j]))>abs(s[j+1]-s[l]-(s[n-1]-s[j+1]))){
                j++;
            }
            else{
                break;
            }
        }
        ans=min(ans,max(s[i],max(s[l]-s[i],max(s[j]-s[l],s[n-1]-s[j])))-min(s[i],min(s[l]-s[i],min(s[j]-s[l],s[n-1]-s[j]))));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, M;
    cin >> N >> M;
    int sum = 0;
    vector<int> A(M);
    REP (i, M) cin >> A[i], sum += A[i];
    cout << (N - sum >= 0 ? N - sum : -1) << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<char>>;
using P =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;}
const ll mod=1000000007;

int f(int ab,vector<int>& l){
    int left=-1;
    int right=l.size();
    while(right-left>1){
        int mid=left+(right-left)/2;
        if(l[mid]>=ab)right=mid;
        else left=mid;
    }
    return right;
}

int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    rep(i,n)cin>>l[i];
    sort(l.begin(),l.end());
    int ans=0;
    rep(b,n)rep(a,b){
        int ab=l[a]+l[b];
        //int r=lower_bound(l.begin(),l.end(),ab)-l.begin();
        int r=f(ab,l);
        int u=b+1;
        ans+=max(0,r-u);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3632
#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;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;
typedef vector <ld> vld;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef set <ld> sld;
typedef set <ll> sll;
typedef set <pll> spll;
typedef char ch;
typedef string str;
typedef tree <int, null_type, greater<int>, rb_tree_tag,
tree_order_statistics_node_update> super_set;
#define DIM 10006
#define MODULO 1000
#define INF 10000000007
#define epc 0.000000001
#define pi  3.14159265358979323846
#define e   2.71828182845904523536
#define gr  1.61803398874989484820
ll n;
bool good(ll a) {
    ll c = 0;
    ll b[7];
    while (a > 0) {
        c++;
        b[c] = a%10;
        a /= 10;
    }
    for (int i = 2; i <= c; i++) {
        if (b[i] != b[i-1])
            return false;
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cout << "ops" << endl;

    cin >> n;
    while (!good(n))
        n++;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long gcd(long long a,long long b){
    long long r = a % b;
    while(r > 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
long long lcm(long long a,long long b){return a*b/gcd(a,b);}
int main(){
    long long a, b;
    scanf("%lld%lld",&a,&b);
    printf("%lld\n",lcm(a, b));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
using ll = long long ;

const double pi=3.14159265358979323846;

int min(int a, int b){
    if(a<b) return a ;
    else return b ;
}

int max(int a, int b){
    return (a<=b) ? a : b  ;
}

int main() {

    string n ; 
    cin >> n   ;
    char last = n[n.size()-1] ;
    //cout << last << endl ;
    if(last=='2' || last=='4' || last=='5' || last=='7' ||last=='9')
     cout << "hon" << endl ;
    else if(last=='0' || last=='1' || last=='6' || last=='8')
     cout << "pon" << endl ;
    else 
     cout << "bon" << endl ;

    
  return 0 ;
}

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

long mem[3001][3001];

long rec(int a[], int n, int i, int j, int ch)
{
  if(i==j)
    return ch?-a[i]:a[i];
  if(mem[i][j]!=1e9+5)
    return mem[i][j];
  long ans=0;
  long ans1=rec(a,n,i+1,j,!ch);
  long ans2=rec(a,n,i,j-1,!ch);
  if(ch==0) 
    ans=max(ans1+a[i],ans2+a[j]);
  else
    ans=min(ans1-a[i],ans2-a[j]);
  mem[i][j]=ans;
  return ans;
}

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<=3000;i++)
  {
  	for(int j=0;j<=3000;j++)
  		mem[i][j]=1e9+5;
  }
  cout<<rec(a,n,0,n-1,0)<<endl;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;
string s,t;
vector<ll> pos[30];
ll cnt[30];
int main()
{
  IOS
  cin>>s>>t;
  ll i;
  
  for(i=0;i<30;i++)
  	pos[i].clear();
  ll l=s.length();
  for(i=0;i<l;i++)
  	{
  		cnt[s[i]-'a']=1;
  		pos[s[i]-'a'].pb(i);
  	}
  ll l1=t.length();
  for(i=0;i<l1;i++)
  	if(!cnt[t[i]-'a'])
  	{
  		cout<<-1;
  		return 0;
  	}
  ll prev=-1;
  ll sum=0;
  for(i=0;i<l1;i++)
  {
  	 ll ub=upper_bound(all(pos[t[i]-'a']),prev)-pos[t[i]-'a'].begin();
  	 if(ub==pos[t[i]-'a'].size())
  	 {
  	 	sum+=l;
  	 	prev=-1;
  	 	ll ub=upper_bound(all(pos[t[i]-'a']),prev)-pos[t[i]-'a'].begin();
  	 	prev=pos[t[i]-'a'][ub];
  	 }
  	 else
  	 	prev=pos[t[i]-'a'][ub];
  }
  sum+=prev+1;
  cout<<sum;
  return 0;
}                   

Measured memory_bytes: 1736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int M, K;
        public long MOD = 1000000007;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                M = line[0];
                K = line[1];
            }

            if (M == 0)
            {
                if (K == 0) Console.WriteLine("0 0");
                else Console.WriteLine("-1");
                return;
            }

            if (M == 1)
            {
                if (K == 0) Console.WriteLine("0 0 1 1");
                else Console.WriteLine("-1");
                return;
            }

            // M >= 2
            long M2 = 1;
            for (int i = 0; i < M; i++)
            {
                M2 *= 2;
            }
            List<long> ret = new List<long>();
            if (K >= M2)
            {
                Console.WriteLine("-1");
            }
            else
            {
               
                ret.Add(K);
                for (long i = 0; i < M2; i++)
                {
                    if (i != K) ret.Add(i);
                }
                ret.Add(K);
                for (long i = M2 - 1; i >= 0; i--)
                {
                    if (i != K) ret.Add(i);
                }
            }

            Console.WriteLine(string.Join(" ", ret));
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 32472
import sys
from collections import defaultdict

def push_vertex(vtx: int,queue: list, weights: dict, done: dict):
    queue.extend(weights[vtx])
    done[vtx] = True
    [queue.remove(x) for x in queue[:] if done[x[0]]]
    del weights[vtx]
    queue.sort(key=lambda x: x[1], reverse=True)
    return


def main():
    n = int(input())
    weights = defaultdict(list)
    for i in range(n):
        for idx, weight in enumerate(input().split()):
            if weight != '-1':
                weights[i+1].append((idx+1, int(weight)))
    done = {}
    for i in weights.keys():
        done[i] = False
    mst_weights = 0
    queue = []
    vtx = [*weights][0]
    push_vertex(vtx, queue, weights, done)

    while len(weights) != 0:
        new_vtx, new_vtx_weight = queue.pop()
        mst_weights += new_vtx_weight
        #print(f"connect to {new_vtx} ,weight={new_vtx_weight}")
        push_vertex(new_vtx, queue, weights, done)

    print(mst_weights)
    return

main()


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

int N, a[100000], b[100000], c[100000], dp[3][100000];

int main()
{
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d %d %d", a + i, b + i, c + i);
    }
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for (int i = 0; i < N; i++)
    {
        dp[0][i] = a[i] + max(dp[1][i-1],dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1],dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[1][i-1],dp[0][i-1]);
    }
    printf("%d\n", max(dp[0][N-1], max(dp[1][N-1], dp[2][N-1])));
    return 0;
}


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

#define S 1000
int dp[S+1][S+1];

void debug_dp(int ts, int ss) {
  rep1 (i, ss) {
    rep1 (j, ts) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
}

int main() {
  string t, s;
  cin >> t >> s;
  rep (i, t.size()+1) dp[0][i] = 1;

  rep1 (i, s.size()) {
    rep1 (j, t.size()) {
      if (s[i-1] == t[j-1]) {
        dp[i][j] = dp[i-1][j-1] + dp[i][j-1];
      } else {
        dp[i][j] = dp[i][j-1];
      }
      dp[i][j] %= 1000000007;
    }
  }
  // debug_dp(t.size(), s.size());

  cout << dp[s.size()][t.size()] << endl;
}



Measured memory_bytes: 7048
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vector<ll> v(n);
  REP(i,n) cin>>v[i];
  vector<ll> s(n+1);
  partial_sum(ALL(v), begin(s)+1);
  map<ll,ll> m;
  REP(i,n+1) {
    ++m[s[i]];
  }
  ll sum = 0;
  for (auto p : m) {
    ll a,b;
    tie(a,b) = p;
    sum += b*(b-1)/2;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 15872
//============================================================================
// Name        : filename.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : test program
//============================================================================

/*
D - Triangles

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 400 点

問題文
高橋君は、互いに区別出来る N 本の棒を持っています。i 本目の棒の長さは L_i です。
高橋君は、これらのうち 3 本の棒を使って三角形を作ろうとしています。このとき、棒の長さを a, b, c として、以下の条件がすべて成り立たなければなりません。

・a < b + c
・b < c + a
・c < a + b

作れる三角形は何種類あるでしょうか。ただし、2 つの三角形は、そのうち一方にのみ使われている棒が存在するときに異なるとします。

制約

・入力は全て整数
・3 ≤ N ≤ 2 × 10^3
・1 <= L_i <= 10^3

 */

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using ll = long long;
using ull = unsigned long long;

#define REP(i, m, n) for (ll i = (m); i < (ll)(n); ++(i))
#define REPM(i, m, n) for (ll i = (m); i <= (ll)(n); ++(i))
#define REPR(i, m, n) for (ll i = (m); i >= (ll)(n); --(i))
#define REPD(i, m, n, d) for (ll i = (m); i < (ll)(n); i += (d))
#define REPMD(i, m, n, d) for (ll i = (m); i <= (ll)(n); i += (d))
#define ALL(x) begin(x), end(x)

/**
 * エントリポイント．
 * @return 0.
 */
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n;
    cin >> n;
    vector<ll> l(n);
    REP(i, 0, n)
    {
        cin >> l[i];
    }
    sort(ALL(l));
    ll count = 0;
    REP(i, 0, n - 1)
    {
        ll l1 = l[i]; // 短い方
        REP(j, i + 1, n)
        {
            ll l2 = l[j];         // 長い方
            ll min = l2 - l1 + 1; // これ以上じゃないといけない
            ll max = l2 + l1 - 1; // これ以下じゃないといけない
            auto left = lower_bound(ALL(l), min);
            auto right = upper_bound(ALL(l), max);
            ll span = distance(left, right); //  right - left;
            if (min <= l1 && l1 <= max)
            {
                span--;
            }
            if (min <= l2 && l2 <= max)
            {
                span--;
            }
            // cerr << l1 << " " << l2 << " " << max << " " << min << " " << span << endl;
            count += span;
        }
    }
    cout << count / 3 << endl; // 3つ分重複してカウントされるので割る
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))

from collections import deque

exv = list()

for a in p:
    exv.append((1+a)/2)

sm = 0
mx = 0

q = deque()

for a in range(N):
    sm += exv[a]
    q.appendleft(exv[a])
    if len(q) > K:
        sm -= q.pop()
    if len(q) == K:
        mx = max(mx,sm)

print('{:.12f}'.format(mx))

Measured memory_bytes: 24808
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
	vector<char> v;
	string s;

	cin >> s;

	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == '0') {
			v.push_back('0');
		}
		else if (s[i] == '1') {
			v.push_back('1');
		}
		else {
			if (v.size() == 0)continue;
			v.pop_back();
		}
	}

	for (vector<char>::iterator it = v.begin();it != v.end();it++) {
		cout << *it;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
A, B, AB = [], [], []
for i in range(n):
    ai, bi = map(int, input().split())
    A.append(ai)
    B.append(bi)
    AB.append((ai + bi, i))
AB.sort(reverse=True)


ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += A[AB[i][1]]
    else:
        ans -= B[AB[i][1]]
print(ans)


Measured memory_bytes: 66264
#include <bits/stdc++.h>
using namespace std;
int n;
long long h[100005];
long long dp[100005];

long long solve(int i){
	if(i >= n-1) return 0;
	if(dp[i] != -1) return dp[i];

	dp[i] = 1e17;
	if(i+1 <= n-1)
		dp[i] = min(dp[i], abs(h[i] - h[i+1]) + solve(i+1));
	if(i+2 <= n-1)
		dp[i] = min(dp[i], abs(h[i] - h[i+2]) + solve(i+2));

	return dp[i];
}

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld", &h[i]);


	memset(dp, -1, sizeof dp);
	cout<<solve(0)<<endl;


	return 0;
}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }


  int main(){
    string S;
    cin >> S;
    S.insert(4, " ");
    print(S);
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define S second
#define F first

using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
const int maxn = 1000;
int seq[maxn];
int32_t main() {
    int n;
    cin >> n;
    int sum =0;
    int minv =1e9;

    for (int i = 1;i <= n;i++){
        cin >> seq[i];
        sum += seq[i];
        if (seq[i] % 10) minv =min(minv,seq[i]);
    }
    if (sum % 10 == 0) sum -= minv;
    if (minv == 1e9) cout << 0 << endl;
    else cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans,t=1;
	cin>>n;
	while (n)
	{
		if (n%10==1) ans=9*t+ans;
		else if (n%10==9) ans=t+ans;
		else ans=n*t+ans;
		t*=10;
		n/=10;
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int s1 = Integer.parseInt(s.substring(0, 2));
        int s2 = Integer.parseInt(s.substring(2));
        if ((s1 == 0 || s1 > 12) && (s2 == 0 || s2 > 12)) {
            System.out.println("NA");
        } else if (s1 == 0 || s1 > 12) {
            System.out.println("YYMM");
        } else if (s2 == 0 || s2 > 12) {
            System.out.println("MMYY");
        } else {
            System.out.println("AMBIGUOUS");
        }
    }
}

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

int main() {

	int N, sum = 0, a = 0;
	cin >> N;
	vector<int> h(N), max(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		max[i] = h[i];
	}

	sort(max.begin(), max.end());
	int MAX = max[max.size() - 1];

	for (int i = 0; i < MAX; i++) {
		for (int j = 0; j < N; j++) {
			if (h[j] > i) {
				a++;
				if (j == 0) {
					if (i >= h[j + 1] && a > 0) {
						sum++;
						a = 0;
					}
				}
				else if (j == N - 1) {
					if (a > 0) {
						sum++;
						a = 0;
					}
				}
				else {
					if (i >= h[j + 1] && a > 0) {
						sum++;
						a = 0;
					}
				}
			}
			else a = 0;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
from operator import itemgetter
N = int(input())
AB = [(0,0)]*N

for i in range(N):
    a, b = map(int,input().split())
    AB[i] = (a,b)

AB.sort(key=itemgetter(1,0))

t = 0
flag = True

for a,b in AB:
    t += a
    if b < t:
        flag=False
print("Yes") if flag else print("No")

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

from math import gcd

k = int(readline())
cnt = 0
gcd_ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd_ans = gcd(i, j)
        for l in range(1, k + 1):
            memo = gcd(l, gcd_ans)
            cnt += memo
print(cnt)


Measured memory_bytes: 67572
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

N = int(input())
A = [int(i) for i in input().split()]

cur = 1
for a in A:
	if cur == a:
		cur += 1
b = N-cur+1
if b == N:
	print(-1)
else:
	print(b)


Measured memory_bytes: 26612
import java.util.Scanner;

class Task{
    String name;
    int time;
}

public class Main {

    static final int len = 100005;
    static Task[] num = new Task[len];

    static int head = 0;
    static int tail = 0;

    // ??????????????????????????????
    public static void enqueue(Task task){
        num[tail] = task;
        tail = (tail+1) % len;
    }

    // ??????????????????????????????
    public static Task dequeue(){
        Task temp = num[head];
        head = (head+1) % len;
        return temp;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        for (int i=0; i<n; i++){
            Task temp = new Task();
            temp.name = sc.next();
            temp.time = sc.nextInt();
            enqueue(temp);
        }

        tail = n;

        int sum = 0;

        //????????????????????¶????????¬??????????????????
        while (head != tail){
            Task temp = dequeue();
            if (temp.time <= q){
                sum += temp.time;
                System.out.println(temp.name + " " + sum);
            }
            else {
                temp.time -= q;
                enqueue(temp);
                sum += q;
            }
        }
    }

}

Measured memory_bytes: 75172
n,x = gets.split.map(&:to_i)
 
arr = gets.split.map(&:to_i)
arr<<x
 
min = arr.min
 
 
 
arr = arr.map{|i| i-=min}
 

 
i = 0
max = arr.max
 
n.times{
    
    maxkouho = arr[i].gcd(arr[i+1])
 
    max = [maxkouho,max].min
    
    
   i+=1 
}
 
p max


Measured memory_bytes: 11780
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
	int x;
	while(~scanf("%d",&x))
	{
		int sum = 0;
		for(int i=1;sum <= x;i++)
		{
			if(sum == x)
			{
				printf("%d\n",i);
				break;
			}
			else if(sum + i < x)
			sum += i;
			else 
			{
				printf("%d\n",i);
				break;
			}
			
		}
	}
	return 0;
}

Measured memory_bytes: 128
def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a


def acinput():
    return list(map(int, input().split(" ")))
def lcm(x, y):
    return x*y //gcd(x, y)

a, b, c, d = acinput()
l = lcm(c, d)
CD = b//l-(a-1)//l
nC = b//c-(a-1)//c
nD = b//d-(a-1)//d

res = b-a+1-(nC+nD-CD)
print(int(res))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        string S;
        cin >> N >> S;
        // string SS(S);
        // ll ans = 0;
        // rep(i, 0, N-1) {
        //         if (S[i] == '#' and S[i+1] == '.') {
        //                 ++ans;
        //                 S[i+1] = '#';
        //         }
        // }

        // ll ans2 = 0;
        // rep(i, 0, N-1) {
        //         if (SS[i] == '#' and SS[i+1] == '.') {
        //                 ++ans;
        //                 SS[i] = '.';
        //                 ++ans2;
        //         }
        // }

        // cout << min(ans, ans2) << endl;

        ll wc, bc;
        wc = bc = 0;
        rep(i, 0, N) {
                if (S[i] == '#') ++bc;
                else ++wc;
        }

        ll wl, bl;
        wl = bl = 0;

        ll ans = bl + wc;
        rep(i, 0, N) {
                if (S[i] == '#') {
                        ++bl;
                        --bc;
                } else {
                        ++wl;
                        --wc;
                }
                ll sm = bl + wc;
                chmin(ans, sm);
        }

        cout << ans << endl;
}


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

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char> > c(h, vector<char>(w));
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}
	int ans = 0;
	rep(mark_i, (1 << h)) {
		rep(mark_j, (1 << w)) {
			int black = 0;
			rep(i, h) {
				rep(j, w) {
					if (((mark_i >> i) & 1) == 0 && ((mark_j >> j) & 1) == 0 && c[i][j] == '#') black++;
				}
			}
			if (black == k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll parent[1000009],sz[1000009];
void fill(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        parent[i]=i;
        sz[i]=1;
    }
}
ll find_parent(ll q)
{
    if(q==parent[q])
        return q;
    return parent[q]=find_parent(parent[q]);
}
void union_sets(ll a,ll b)
{
    a=find_parent(a);
    b=find_parent(b);
    if(a!=b)
    {
        if(sz[a]<sz[b])
            swap(a,b);
        parent[b]=a;
        sz[a]+=sz[b];
    }
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    fill(n);
    ll x,y;
    for(ll i=0;i<m;i++)
    {
        cin>>x>>y;
        union_sets(x,y);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans=max(ans,sz[i]);
    }
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

Measured memory_bytes: 6792
#include <iostream>
#include <cmath>
#define lowbit(x)  x&(-x)
#define ll long long
using namespace std;
const int MAX = 2e5+10;
ll a[MAX], sum[MAX];

int main(){
	int n;
	cin>>n;
	for(int i = 1; i <= n; i ++){
		cin>>a[i];
		sum[i] = sum[i-1]+a[i];
	}
	ll Min = 1LL*50000000000000000;
	//cout << Min << endl;
	for(int i = 1; i < n; i ++){
		ll cnt = sum[n]-2LL*sum[i];
		if(Min > abs(cnt))Min = abs(cnt);
	}
	cout << Min << endl;
}

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

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

	string f, e;
	cout << 0 << endl;
	cin >> f;
	if( f == "Vacant" ) return 0;
	cout << N - 1 << endl;
	cin >> e;
	if( e == "Vacant" ) return 0;
	int l = 0;
	int r = N - 1;
	while( r - l > 1 ) {
		int m = (l + r) / 2;
		string now;
		cout << m << endl;
		cin >> now;
		if( now == "Vacant" ) return 0;
		int s = r - m;
		if( s % 2 == 0 && now != e || s % 2 && now == e ) {
			l = m;
			f = now;
		}
		else {
			r = m;
			e = now;
		}
	}
}


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll par[1000000],Rank[1000000];
ll N;
// 要素Nで初期化
void init(){
  rep(i,N){
    par[i]=i;
    Rank[i]=0;
  }
}
ll root(ll x){
  return par[x]==x ? x : par[x]=root(par[x]);
}
bool same(ll x,ll y){
  return root(x)==root(y);
}
void unite(ll x,ll y){
  x=root(x);y=root(y);
  if(x==y)return;
  if(Rank[x]<Rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(Rank[x]==Rank[y])Rank[x]++;
  }
}

int main(){
  ll ans=0;
  ll M;cin>>N>>M;
  init();
  vector<ll> p(N);
  rep(i,N){
    cin>>p[i];
  }
  ll x,y;
  rep(i,M){
    cin>>x>>y;
    unite((x-1),(y-1));
  }
  rep(i,N){
    ans+=same(i,p[i]-1);
  }
  cout<<ans<<endl; 
  return 0;
}

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

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

	int n = s.size();

	if ((n + (s[0] == s[n - 1])) % 2) cout << "First" << endl;
	else cout << "Second" << endl;

	return 0;
}


Measured memory_bytes: 512
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll a,b,c,d;
    std::cin >> a>>b>>c>>d;
    
    bool ok = true;
    while(true){
        if(ok){
            c -= b;
            if(c<=0){
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }else{
            a -= d;
            if(a<=0){
                std::cout << "No" << std::endl;
               return 0;
            }
        }
        ok = !ok;
        // std::cout << a<<" "<<c << std::endl;
    }
}



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

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

using ll = long long;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string s,t;
  cin>>s>>t;
  int l = s.size();
  bool can=true;
  for(int i = 0; i < l; i++) {
    if(s[i]!=t[i]) can= false;
  }
  if(can) cout<<"Yes"<<endl;
  if(!can)cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>

#define MAX 1001

void normalize(double *x, double *y){
	double z;
	z = sqrt((*x)*(*x)+(*y)*(*y));
	*x /= z;
	*y /= z;
}

int main(void){
	double x[MAX];
	double y[MAX];
	double vx,vy;
	int q;
	
	x[0] = y[0] = 0;
	x[1] = 1; y[1] = 0;
	for (int i=2; i<MAX; i++){
		vx = -y[i-1]; vy = x[i-1];
		normalize(&vx,&vy);
		x[i] = x[i-1] + vx;
		y[i] = y[i-1] + vy;
//		printf ("%d:(%f, %f)\n", i, x[i], y[i]);
	}
	
	while (scanf("%d",&q), q!=-1){
		printf("%.2f\n%.2f\n",x[q],y[q]);
	}
	return 0;
}

Measured memory_bytes: 1084
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c;
    d = abs(b-a);
    e = abs(c-a);
    if(e>d)
    {
        cout<< "A"<<endl;
    }
    else if(d>e)
        cout<< "B"<<endl;
    else
        cout<< "A"<<endl;

    return 0;

}


Measured memory_bytes: 256
H, N = map(int, input().split())
magics = []
for _ in range(N):
  a, b = map(int, input().split())
  magics.append([a, b])
max_a = max(a for a, _ in magics)
dp = [0]*(H+max_a)
for i in range(1, H+max_a):
  dp[i] = min(dp[i-a]+b for a, b in magics)
print(min(dp[H:]))

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int red=0,blue=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='0'){
          red++;
      }
      else{
        blue++;  
      }
    }
    int ka=min(red,blue);
    cout<<ka*2<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  for(int i = 0; i * 4 <= N; i++){
    int res = N - i * 4;
    if(res % 7 == 0){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    int last = s.size() - 1;
    while(true)
    {
        if( s[last] == 'r' && s[last-1] == 'e' && s[last-2] == 'm' && s[last-3] == 'a' && s[last-4] == 'e' && s[last-5] == 'r' && s[last-6] == 'd')
        {
            last -= 7;
            continue;
        }
        if( s[last] == 'r' && s[last-1] == 'e' && s[last-2] == 's' && s[last-3] == 'a' && s[last-4] == 'r' && s[last-5] == 'e' )
        {
            last -= 6;
            continue;
        }
        if( ( s[last] == 'm' && s[last-1] == 'a' && s[last-2] == 'e' && s[last-3] == 'r' && s[last-4] == 'd' )
                || ( s[last] == 'e' && s[last-1] == 's' && s[last-2] == 'a' && s[last-3] == 'r' && s[last-4] == 'e' ) )
        {
            last -= 5;
            continue;
        }
        else if(last == -1)
        {
            cout << "YES" << endl;
            return 0;
        }
        cout << "NO" << endl;
        return 0;
    }

}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  int i, n;
  scanf("%d", &n);
  i = (n/100)*100 + (n/100)*10 + n/100;
  
  if( n <= i ){
	printf("%d", i);
  }else {
	printf("%d", i + 111);
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

 

using namespace std;

 

int main()
{
   int a, b, temp, i;
   for(i=1; i<=3000; i++)
   {
      cin >> a >> b;
      
      if(a== 0 && b== 0)
      break;
      
      if(a > b)
      {
        temp = a;
        a = b;
        b = temp;
     
    }
    
    
 

   cout << a << " " << b << endl;
}

}


Measured memory_bytes: 3004
#include<iostream>
#include <math.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    int i;
    int j;
    char center;
    if (s.length() == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (s.length() % 2 == 0) {
        i = s.length() / 2 - 1;
        j = i + 1;
        center = s[i];
        
    } else {
        i = s.length() / 2 - 1;
        j = s.length() / 2 + 1;
        center = s[i + 1];
    }
    while (i >= 0 && j < s.length() && center == s[i] && s[i] == s[j]) {
        --i;
        ++j;
    }
    cout << j << endl;
    return 0;
}

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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if(a > b) cout << b;
    else cout << a;
    cout << " ";
    if(a + b - n > 0) cout << a + b - n;
    else cout << 0;
    cout << endl; 
    return 0;
}

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

int main(int argc, char const* argv[])
{
    int                          N, tmp;
    std::unordered_map<int, int> d;
    std::cin >> N;
    while (std::cin >> tmp) {
        d.emplace(tmp, 0);
    }
    std::cout << (d.size()) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int N,K;
  int ret;

  cin >> N >> K;
  if(10<=N) ret=K;
  else ret=K+100*(10-N);

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      
		int ans = a % 1000;
        
          
        if (ans != 0) {
        	ans = 1000 - ans;
        }
		
		// 出力
		System.out.println(ans);
	}
}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string X;
    cin >> X;
    int popcount = 0;
    for (int i=0;i<N;i++){
        if (X[i] == '1') popcount++;
    }
    int plus = popcount + 1;
    int minus = popcount - 1;
    vector<int> pow2plus(200005);
    vector<int> pow2minus(200005);
    pow2plus[0] = 1;
    pow2minus[0] = 1;
    for (int i=0;i<=200000;i++){
        pow2plus[i+1] = pow2plus[i]*2;
        pow2plus[i+1] %= plus;
        if (minus != 0){
            pow2minus[i+1] = pow2minus[i]*2;
            pow2minus[i+1] %= minus;
        }
    }
    int Xplus = 0, Xminus = 0;
    for (int i=0;i<N;i++){
        if (X[i]=='1'){
            Xplus += pow2plus[N-i-1];
            Xplus %= plus;
            if (minus != 0){
                Xminus += pow2minus[N-i-1];
                Xminus %= minus;
            }        
        }
    }
    vector<int> ans(N);
    for (int i=0;i<N;i++){
        if (X[i]=='1') {
            //minusで計算する
            if (minus == 0) ans[i] = 0;
            else {
                int next = Xminus - pow2minus[N-i-1];
                if (next < 0) next += minus;
                ans[i]++;
                while (next > 0){
                    int pop = 0;
                    for (int bit=0;bit<=30;bit++){
                        if ((next>>bit)&1) pop++;
                    }
                    next %= pop;
                    ans[i]++;
                }        
            }
        }else{
            //plusで計算する
            int next = Xplus + pow2plus[N-i-1];
            next %= plus;
            ans[i]++;
            while (next > 0){
                int pop = 0;
                for (int bit=0;bit<=30;bit++){
                    if ((next>>bit)&1) pop++;
                }
                next %= pop;
                ans[i]++;
            }
        }
    }
    for (int i=0;i<N;i++){
        cout << ans[i] << "\n";
    }
}

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

int main(){
  int n,k,count = 1;
  cin >> n >> k;
  if(n > k){
    count ++;
  }
  rep(i,100){
    if(n/k <= k-1){
       break;
    }
    n /= k;
    count ++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int s[101][101];

int main() {
	int n;
	cin >> n;
	vector<int>p(n), q(n), r(n), r2(n);
	rep(i, n) {
		cin >> p[i];
		r[i] = i + 1;
	}
	rep(i, n) {
		cin >> q[i];
		r2[i] = i + 1;
	}
	int a = 0, b = 0, c = 1, d = 1;
	do {
		bool flag = true;
		rep(i, n) {
			if (p[i] != r[i])flag = false;
		}
		if (flag)a = c;
		c++;
	} while (next_permutation(r.begin(), r.end()));
	do {
		bool flag = true;
		rep(i, n) {
			if (q[i] != r2[i])flag = false;
		}
		if (flag)b = d;
		d++;
	} while (next_permutation(r2.begin(), r2.end()));
	cout << abs(a - b) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e16;
typedef long long ll;

int main(){

  int N, C; cin >> N >> C;

  ll D[C][C];
  for (int i = 0; i < C; i++){
    for (int j = 0; j < C; j++){
      cin >> D[i][j];
    }
  }
  
  ll cnt[3][C], point[3][C];
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < C; j++){
      cnt[i][j] = 0;
      point[i][j] = 0;
    }
  }
  
  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= N; j++){
      int cij; cin >> cij;
      cnt[(i + j) % 3][cij - 1]++;
    }
  }
  
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < C; j++){
      for (int k = 0; k < C; k++){
        point[i][j] += cnt[i][k] * D[k][j];
      }
    }
  }
  
  ll ans = 1e15;

  for (int i = 0; i < C; i++){
    for (int j = 0; j < C; j++){
      for (int k = 0; k < C; k++){
        if (i != j && j != k && k != i){
          ans = min(ans, point[0][i] + point[1][j] + point[2][k]);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

r = []
city = [""] * n
for i in range(n):
    s, p = map(str, input().split())
    r.append([i+1,s,p])
    city[i] = s


cs = set(city)
cs_sorted = sorted(cs)

rs = sorted(r)
for c_name in cs_sorted:
    tmp = []
    for i in range(n):
        if rs[i][1] == c_name:
            tmp.append([int(rs[i][2]), rs[i][0]])

    rest =  sorted(tmp, key=lambda x: x[0], reverse=True)
    for pp, rank in rest:
        print(rank)






Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int n ;
  cin >> n ;
  ll x ;
  cin >> x ;
  vector<ll> num(n) ;
  
  REP(i,n){
    cin >> num.at(i) ;
  }
  
  sort(ALL(num)) ;
  
  int cnt = 0 ;
  
  int i = 0 ;
  
  while(x>0){  
    if(x>=num.at(i)){
      cnt++ ;
      x -= num.at(i) ;
      i++ ;
    }
    else{
      break ;
    }
    
    if(i==n){
      if(x>0){
        cnt-- ;
      }
      break ;
    }
  
  }
  
  cout << cnt <<endl ;
  

  return 0 ;
}




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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    cout << N*(N+1)/2 << endl;
    return 0;
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if(M1 != M2) puts("1");
    else puts("0");
}

Measured memory_bytes: 256