akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;

int main() {
    cin >> n;
    vector<pii> edges;
    vector<vector<int>> g(n);
    rep(i, n-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        edges.emplace_back(a, b);
    }

    int k = -1;
    map<pii, int> color;
    vector<int> cs(n, 0);

    vector<bool> visited(n, 0);
    queue<int> q;
    visited[0] = true;
    q.push(0);
    while (q.size()) {
        int u = q.front(); q.pop();
        int t = g[u].size();
        chmax(k, t);
        int c = 1;
        for (const auto &v: g[u]) {
            if (visited[v]) continue;
            if (c == cs[u]) c++;
            visited[v] = true;
            cs[v] = color[make_pair(u, v)] = color[make_pair(v, u)] = c++;
            q.emplace(v);
        }
    }

    cout << k << endl;
    for (const auto &e: edges) cout << color[e] << endl;
}


Measured memory_bytes: 22396
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
bool cmp( pair < string , pair < int , int > > X , pair < string , pair < int , int > > Y ){
	if(X.ff == Y.ff){
		return X.ss.ff > Y.ss.ff ;
	}
	else
		return X.ff < Y.ff ;
}
void solve(){
	int n ;
	cin >> n ;
	vector < pair < string , pair < int ,int >  > > v(n) ;
	for( int i = 0 ; i < n ; i++) cin >> v[i].ff >> v[i].ss.ff , v[i].ss.ss = i+1;
	sort(st(v),cmp);
	for( int i = 0 ; i < n ; i++ ){
		cout << v[i].ss.ss << "\n";
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


ll gcdfun(ll a, ll b) {
	if (a < b)swap(a, b);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main()
{
	int N;
	cin >> N;
	vector<ll>A(N), l, r;
	REP(i, N)cin >> A[i];
	l = A, r = A;
	REP(i, N - 1) {
		l[i + 1] = gcdfun(l[i + 1], l[i]);
		r[N - 2 - i] = gcdfun(r[N - 2 - i], r[N - 1 - i]);
	}

	ll res = 1;
	REP(i, N) {
		ll tmp =
			i == 0 ? r[i + 1] :
			i == N - 1 ? l[i - 1] :
			gcdfun(l[i - 1], r[i + 1]);
		res = max(res, tmp);
	}
	cout << res << endl;

	return 0;
}


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

using namespace std;
using ll = long long;

const long long INF = 1LL << 60;
const int MOD = 1000000007;

double dp[3001][3001] = {};

int main() {
    #ifdef MYLOCAL
        ifstream in("input.txt");
        cin.rdbuf(in.rdbuf());
    #endif

    int n;
    cin >> n;

    vector<double> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
    }

    dp[0][0] = 1.0;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i + 1][j + 1] += dp[i][j] * p[i];
            dp[i + 1][j] += dp[i][j] * (1 - p[i]);
        }
    }
    double res = 0.0;
    for (int j = (n+1)/2; j <= n; ++j) {
        res += dp[n][j];
    }

    cout << fixed << setprecision(10) << res << endl;

    return 0;
}

Measured memory_bytes: 68992
#include<stdio.h>

int main(void)
{
	int i,j,n;
	long A[200000],Max,min;
	
	scanf("%d",&n);
	for(i=0;i<=n-1;i++)
	{
		scanf("%ld",&A[i]);
	}
	Max=-2000000000;
	min=A[0];
	for(i=1;i<=n-1;i++)
	{
		if(Max<A[i]-min)
		{
			Max=A[i]-min;
		}
		if(min>A[i])
		{
			min=A[i];
		}
	}
	printf("%ld\n",Max);
	return 0;
}

Measured memory_bytes: 3280
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] P = in.ii(N);

        int min = N + 1;
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int p = P[i];
            if (p < min) {
                min = p;
                ans++;
            }
        }
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 36316
#include<stdio.h>
int main(){
        int m,n;
        int value,year;
        int type,cost;
        int result;
        int i,j,k;
        int a,b;
        int max;
        double ratio;
        scanf("%d",&m);
        for(k=0;k<m;k++){
                scanf("%d",&value);
                scanf("%d",&year);
                scanf("%d",&n);
                max=0;
                for(i=0;i<n;i++){
                        scanf("%d %lf %d",&type,&ratio,&cost);
                        a=value;
                        b=0;
                        if(type==0){
                                for(j=0;j<year;j++){
                                        b=b+a*ratio;
                                        a=a-cost;
                                }
                                result=b+a;
                        }else{
                                for(j=0;j<year;j++){
                                        b=a*ratio;
                                        a=a+b-cost;
                                }
                                result=a;
                        }
                        if(result>max){
                                max=result;
                        }
                }
                printf("%d\n",max);
        }
        return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <vector>
using namespace std;
int main(){
	string s;
	cin >> s;
	int n = s.size();
	reverse( s.begin(), s.end() );
	int x = 1, tot = 0 ;
	int m = 2019;
	int ans=0;
	
	vector<int> d(n+1);
	int ten = 1;
	for( int i=-1; i<n; i++ ){
		int a=(s[i+1]-'0')*ten%m;
		d[i+1]=(d[i]+a)%m;
		ten*=10; ten%=m;
	}
	int cnt[m];
	for(int i=0;i<m;i++){
		cnt[i]=0;
	}
	for( int i=-1; i<n; i++ ){
		ans+=cnt[d[i]];
		cnt[d[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3984
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
#define MAXN 200005   //要开2倍，n=h+w-2 
#define INF 0x3f3f3f3f
#define MOD 1000000007
int h,w,a,b,n;
LL s[MAXN],inv[MAXN];

LL pow(LL a,int b)//快速幂，利用二进制 
{//若b=x+y+z,x,y,z为2^d a^b=a^x*a^y*a^z  
	LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return ans;
}

void pre()//计算阶乘和阶乘的逆元 
{
	s[0]=1,inv[0]=1;
	for(int i=1;i<=n;i++)
		s[i]=s[i-1]*i%MOD;
	inv[n]=pow(s[n],MOD-2);
	for(int i=n-1;i>0;i--)
		inv[i]=inv[i+1]*(i+1)%MOD;//求阶乘的逆元 
}
LL c(LL a,LL b)
{
	if(a<0||b<0) return 1;
	return s[a]*inv[b]%MOD*inv[a-b]%MOD; 
}
int main()
{
	//freopen("grid.in","r",stdin);
	//freopen("grid.out","w",stdout);
	scanf("%d %d %d %d",&h,&w,&a,&b);
	n=h+w-2;
	pre();
	LL ans=c(h+w-2,h-1);
	for(int i=1;i<=b;i++)
	{
		ans-=c(h-a+i-2,h-a-1)*c(a-1+w-i,a-1)%MOD;
		ans=(ans%MOD+MOD)%MOD;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3328
while True :
    try :
        n = int(input())
    except EOFError :
        break
    
    cnt = 0
    for a in range(10) :
        for b in range(10) :
            for c in range(10) :
                for d in range(10) :
                    if a + b + c + d == n :
                        cnt += 1
    print(cnt)


Measured memory_bytes: 5596
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n=int(input())
    ww=list(map(int,input().split()))
    l=ww[0]
    r=sum(ww[1:])
    if l >= r:
        print(l-r)
        return
    for i in range(1,n-1):
        w=ww[i]
        l_ = l+w
        r_ = r-w
        if l_ >= r_:
            print(min([r-l, l_-r_]))
            return
        l=l_
        r=r_
    print(r-l)

main()

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

int num[100001], memo[100001];

int dp(int n){
    if(n==0) return 0;
    if(n==1) return abs(num[0]-num[1]);
    if(memo[n]!=-1) return memo[n];
    return memo[n]=min(dp(n-1)+abs(num[n-1]-num[n]), dp(n-2)+abs(num[n-2]-num[n]));
}

int main(){
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(memo, -1, sizeof(memo));
    int n;
    cin>>n;
    for(int i=0; i<n; ++i) cin>>num[i];
    cout<<dp(n-1)<<"\n";
    return 0;
}


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


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int h[101];
    int max_v = -1;
    int cnt = 0;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        max_v = max(max_v, h[i]);
        if (h[i] >= max_v) {
            cnt++;
        }
    }
    
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>

using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
int DX[4]={1,0,-1,0};
int DY[4]={0,1,0,-1};

typedef pair<int,int> Pii;


#define SUPnl 10002

int nl;
int p[SUPnl];

int init(){REP(ni,nl){p[ni]=-1;}}

int getRoot(int a){
	while(true){
		if(p[a]==-1) return a;
		a=p[a];
	}
}

bool same(int a, int b){
	return getRoot(a)==getRoot(b);
}

void unite(int a, int b){
	a=getRoot(a);
	b=getRoot(b);
	if(a==b) return;
	p[b]=a;
}

int main(){
	int ol;
	cin>>nl>>ol;
	init();
	int ot,a,b;
	REP(oi,ol){
		cin>>ot>>a>>b;
		if(ot==0) unite(a,b);
		if(ot==1) cout<<same(a,b)<<endl;
	}
}

Measured memory_bytes: 1204
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 100005;
const ll mm = 1e+18;
void solve()
{
    map<string,int>mp;
    int n;
    cin>>n;
    rep0(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"];
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3672
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    ret = (1 + N) * N // 2
    print(ret)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import numpy as np

n, m, x = map(int, input().split())
a = []
cost = []
for _ in range(n):
    inp = input().split()
    cost.append(int(inp[0]))
    a.append(
        np.array(
            list(map(int, inp[1:]))
        )
    )

ans = -1
for i in range(2 ** n):
    total = 0
    skill = np.zeros(m)
    for j in range(n):
        if (i >> j) & 1:
            total += cost[j]
            skill += a[j]
    if (all(skill >= x)):
        if (ans == -1):
            ans = total
        else:
            ans = min(ans, total)

print(ans)

Measured memory_bytes: 27172
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }

int main() {
    // your code goes here
    ll n, W, w[105], v[105], dp[105][100005]={0};
    cin >> n >> W;
    rep(i,0,n) rep(j,0,100000) dp[i][j] = 1e17;
    dp[0][0] = 0;
    rep(i,1,n){
    	cin >> w[i] >> v[i];
    	rep(j,0,100000){
    		if(j >= v[i]) dp[i][j]=min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
    		else dp[i][j] = dp[i-1][j];
    	}
    }
    repr(j,100000,0){
    	if(dp[n][j] <= W){
    		cout << j << endl;
    		return 0;
    	}
    }
    return 0;
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 6000001;
const int mod = 1e9 + 7;
LL a[N + 20], fact[N + 20], inv[N + 20];
LL qpow(LL a, LL b, LL p = mod) {
	LL ans = 1;
	for (; b; b >>= 1) {
		if (b & 1) ans = ans * a % p;
		a = a * a % p;
	}
	return ans % p;
}
void prework() {
	fact[0] = 1;
	for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % mod;
	inv[N - 1] = qpow(fact[N - 1], mod - 2) % mod;
	for (int i = N - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
LL nCr(int n, int r) {  // calculate nCr
	if (n - r < 0 || r < 0) return 0;
	return fact[n] % mod * inv[r] % mod * inv[n - r] % mod % mod;
}
int main() {
  int k; cin >> k;
  string s; cin >> s;
  int n = s.length();
  prework();
  int S = 26;  // alphabet size
  LL ans = qpow(S, n + k);
  for (int r = 0; r < n; r++) {
    LL v = nCr(n + k, r) * qpow(S - 1, n + k - r) % mod;
    ans = (ans - v + mod * 2) % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 98148
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef long long ll;

const int MODULO = 1e9 + 7;

typedef ll mod_t;

const char SPACE = ' ', ENDL = '\n';

int ri() {
	int v;
	cin >> v;
	return v;
}

ll rll() {
	ll v;
	cin >> v;
	return v;
}

vi rvi(int n) {
	vi a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	return a;
}

vector<ll> cnt;

vi c;
vector<vi> g;
vector<ll> sz;
vector<ll> cs;

int dfs_down(int f, int p = -1) {
	ll s = 1;

	ll & ans = cnt[c[f]];
	ans++; // [f -> f]

	for (int t : g[f]) {
		if (t != p) {
			ll ts = dfs_down(t, f);

			ans += ts * s;
			s += ts;
		}
	}

	return sz[f] = s;
}

void dfs_up(int f, int p = -1) {
	int col = c[f];

	ll old_cs = cs[col];

	for (int t : g[f]) {
		if (t == p) continue;

		cs[col] = sz[t];
		dfs_up(t, f);
	}

	cs[col] = old_cs - sz[f];

	cnt[col] += sz[f] * cs[col];
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int tests =
#ifdef ONLINE_JUDGE
		1;
#else
		ri();
#endif

	/*
	graph
	tree
	dfs
	*/

	for (int t = 0; t < tests; ++t) {
		int n = ri();
		c = rvi(n);

		g.assign(n, vi(0));
		for (int i = 0; i < n - 1; ++i) {
			int f = ri() - 1;
			int t = ri() - 1;

			g[f].push_back(t);
			g[t].push_back(f);
		}

		cnt.assign(n + 1, 0);

		sz.assign(n, 0);
	
		int root = 0;
		dfs_down(root);

		cs.assign(n + 1, n);
		dfs_up(root);

		for (int c = 1; c <= n; ++c) {
			cout << cnt[c] << ENDL;
		}
	}

	return 0;
}

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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  if(s.size() != a + b + 1) {
    cout << "No" << endl;
    return 0;
  }
  else {
    if(s[a] != '-') {
      cout << "No" << endl;
      return 0;
    }
    else {
      rep(i, s.size()) {
        if(i == a) continue;
        if(!(0 <= (s[i] - '0') && (s[i] - '0') <= 9)) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<" L-B-W-- "<<x<<" --N-B\n"
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
using namespace std;
typedef long long ll;
typedef double db;
const double pai = acos(-1.0);
const double eps = 1e-8;
//const int mod=998244353;
const int mod=1e9+7;
const int inf=1e9+7;
//const ll inf=0x7f7f7f7f1234abcd;
const int maxn=1e5+10;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;x=x*x%mod;y>>=1;}return res;}
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}
inline ll lcm(ll a,ll b){return a * b / __gcd(a, b);}
int t,n,m,k;
//ll a[maxn];
inline __int128 read()
{
    __int128 x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

inline void write(__int128 x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}

int main()
{
    scanf("%d",&n);
    __int128 s=1,p;
    int f=0;
    rep(i,1,n){p=read();s*=p;if(p==0) {puts("0");return 0;}if(s>1000000000000000000) f=1;}
    if(f){puts("-1");return 0;}
    write(s);
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

const int INF = 1 << 30;

int calc_cost(vector<int>& b1, vector<int>& b2) {
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < b1.size(); i++) {
        if (b1[i] == 1) cnt1++;
    }
    for (int i = 0; i < b2.size(); i++) {
        if (b2[i] == 1) cnt2++;
    }
    if (cnt1 != cnt2) return INF;
    vector<int> idx1, idx2;
    for (int i = 0; i < b1.size(); i++) {
        if (b1[i] == 1) idx1.push_back(i);
    }
    for (int i = 0; i < b2.size(); i++) {
        if (b2[i] == 1) idx2.push_back(i);
    }
    int res = 0;
    for (int i = 0; i < idx1.size(); i++) {
        res += abs(idx1[i] - idx2[i]);
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> B(N), P(M);
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < M; i++) cin >> P[i];
    vector<int> b1, b2;
    for (int i = 0; i < M; i++) {
        if (i % 2 == 0) {
            for (int j = 0; j < P[i]; j++) {
                b1.push_back(1);
            }
        }
        else {
            for (int j = 0; j < P[i]; j++) {
                b1.push_back(0);
            }
        }
    }
    for (int i = 0; i < M; i++) {
        if (i % 2) {
            for (int j = 0; j < P[i]; j++) {
                b2.push_back(1);
            }
        }
        else {
            for (int j = 0; j < P[i]; j++) {
                b2.push_back(0);
            }
        }
    }
    int ans = INF;
    ans = min(ans, calc_cost(b1, B));
    ans = min(ans, calc_cost(b2, B));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <bitset>

using namespace std;

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

    bitset<4000010> dp;
    dp[0] = true;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        dp |= dp << a;
        sum += a;
    }

    int ret = (sum + 1) / 2;
    while (true) {
        if (dp[ret]) {
            cout << ret << endl;
            break;
        }
        ret++;
    }
    return 0;
}

Measured memory_bytes: 1792
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var R, C, K, r, c, v int
  NextInt(&R, &C, &K)
  M := make([][]int, R + 1)
  for i := range M { M[i] = make([]int, C + 1) }
  for i := 0; i < K; i++ {
    NextInt(&r, &c, &v)
    M[r][c] = v
  }
  DP := make([][][]int, R + 1)
  for i := range DP {
    DP[i] = make([][]int, C + 1)
    for j := range DP[i] { DP[i][j] = make([]int, 4) }
  }
  for r = 1; r <= R; r++ {
    for c = 1; c <= C; c++ {
      for k := 0; k < 4; k++ {
        DP[r][c][k] = MaxInt(DP[r][c - 1][k], DP[r][c][k])
        if k > 0 { DP[r][c][k] = MaxInt(DP[r][c - 1][k - 1] + M[r][c], DP[r][c][k]) }
        if k == 0 { DP[r][c][k] = MaxInt(MaxInt(DP[r - 1][c]...), DP[r][c][k]) }
        if k == 1 { DP[r][c][k] = MaxInt(MaxInt(DP[r - 1][c]...) + M[r][c], DP[r][c][k]) }
      }
    }
  }
  Write(MaxInt(DP[R][C]...))
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

Measured memory_bytes: 599912
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define rep(n) for(int i = 0;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto n:v){cout << n << "\t";}
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
using namespace std;
void solve(){
	int n,k;
	cin >> n >> k;
	vi v(n);
	for(auto &i:v){
		cin >> i ;

	}
	sort(all(v));
	int sum = 0;
	rep(k){
		sum+=v[i];
	}
	cout << sum << endl;

}


int main(){
	solve();
	// int t;
	// cin >> t;
	// while(t--){
	// 	solve();
	// }

	return 0;
}

Measured memory_bytes: 3560
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	inputs := make([]int, n)
	count := 0
	max := 0
	for i := 0; i < n; i++ {
		var input int
		fmt.Scan(&input)
		inputs[i] = input
		if i == 0 {
			continue
		}
		if inputs[i-1] >= inputs[i] {
			count++
		} else {
			count = 0
		}
		if count >= max {
			max = count
		}
	}
	fmt.Println(max)
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int n;
   cin >> n;
   vector<int> x(n);
   int a[100] = {};

   rep(i, 0, n)
   {
      cin >> x[i];
   }

   rep(i, 0, n)
   {
      rep(j, 0, 100)
      {
         a[j] += (x[i] - j) * (x[i] - j);
      }
   }

   sort(a, a + 100);

   cout << a[0] << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=3010;
char s[N][N];
int hh(int z,int n)
{
    int x,y,f,ff;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            x=i+z>n?i+z-n:i+z;
            y=j;
            f=j+z>n?j+z-n:j+z;
            ff=i;
            if(s[x][y]!=s[f][ff])
                return 0;
        }
    }
    return 1;
}
int main()
{
    int n,x,y,w,z;cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    int res=0;
    for(int i=0;i<n;i++)
        if(hh(i,n))
            res+=n;
    cout<<res;
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,t,a,b,c,d;
	cin>>t;
	while(t--){
		cin>>a>>b>>c>>d;
		if(a<b||d<b){
			cout<<"No\n";
			continue;
		}
		a%=b;
		i=__gcd(b,d);
		if((b-a)%i==0){
			j=(b-a)/i-1;
		}
		else{
			j=(b-a)/i;
		}
		if(a+j*i>c){
			cout<<"No\n";
		}
		else{
			cout<<"Yes\n";
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int expr(string& s, int& i);
int term(string& s, int& i);
int fact(string& s, int& i);
int numb(string& s, int& i);

int expr(string& s, int& i){
  int val = term(s, i);
  while(s[i]=='+'){
    i++;
    val = max(val, term(s, i));
  }
  return val;
}

int term(string& s, int& i){
  int val = fact(s, i);
  while(s[i]=='*'){
    i++;
    int x =  fact(s, i);
    if(min(x, val) == 0) val = 0;
    else if(min(x, val) == 1) val = 1;
    else val = 2;
  }
  //  cout << val << endl;
  return val;
}

int invert(string& s, int& i){
  if(isdigit(s[i])) return fact(s, i);

  while(s[i]=='-'){
    i++;
    int val2 = fact(s, i);
    if(val2==2) return 0;
    else if(val2==0) return 2;
    return 1;
  }
  return 0;
}

int fact(string& s, int& i){
  if(s[i]=='-') return invert(s, i);
  if(isdigit(s[i])) return numb(s, i);
  
  i++;
  int ret = expr(s, i);
  i++;
  return ret;
}

int numb(string& s, int& i){
  int n = s[i++] - '0';
  while(isdigit(s[i])) n = n*10 + s[i++] - '0';
  return n;
}

int main(){
  string S;
  while(cin >> S, S!="."){
    int res = 0;
    rep(i,3) rep(j,3) rep(k,3){
      string s = S;
      rep(l,s.size()){
	if(s[l]=='P') s[l] = i+'0';
	if(s[l]=='Q') s[l] = j+'0';
	if(s[l]=='R') s[l] = k+'0';
      }
      int l = 0;
      if(expr(s, l) == 2) res++;

    }
    cout << res << endl;
  }
  return 0;
}

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

const int mod = 1000000007, mod2 = 998244353, inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k;
    string s;
    cin >> n >> k >> s;
    int l = 0, r = 0, cnt = 0, ans = 0;
    while (l < s.size() && r < s.size()){
        while (r < s.size() && s[r] == '1') ++r;
        if (s[r] == '0'){
            ++cnt;
            while (r < s.size() && s[r] == '0') ++r;
        }
        while (r < s.size() && s[r] == '1') ++r;
        ans = max(ans, r - l);
        if (cnt == k){
            while (l < s.size() && s[l] == '1') ++l;
            while (l < s.size() && s[l] == '0') ++l;
            --cnt;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int x = in.nextInt();
		in.close();

		int ans = 0;
		int sum = 0;
		for (int i = 1; true; i++) {
			sum += i;
			if(x <= sum) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
#include <stdio.h>

#define N 100
#define A 1000

int main() {

	int i,j,k,n,a[A],v;

	scanf("%d",&n);

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

	for (k = 0; k < n-1; k++) {
		printf("%d ", a[k]);
	}
	printf("%d", a[k]);

	for (i = 1; i < n; i++) {
		
		printf("\n");

		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}

		for (k = 0; k < n -1; k++) {
			printf("%d ", a[k]);
		}

		printf("%d", a[k]);
	}

printf("\n");

	return 0;

}



Measured memory_bytes: 2128
#include<stdio.h>

#define MAX 10000
#define NIL -1

typedef struct{
  int p, l, r;
}Node;

Node T[MAX];
int n;

//先行順巡回
void preParse(int u){
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

//中間順巡回
void inParse(int u){
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

//後行順巡回
void postParse(int u){
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

int main(){
  int i, v, l, r, root;

  scanf("%d",&n);
  for(i = 0; i < n; i++) T[i].p = NIL;

  for(i = 0; i < n; i++){
    scanf("%d %d %d",&v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL) root = i;
  }

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    const int N = 50 + 5;
    const int inf = 1 << 28;
    int dp[N][N][N];
    fill(&dp[0][0][0], &dp[N - 1][N - 1][N - 1] + 1, inf);
    dp[a][b][c] = 0;
    for (int i = 0; i < N - 2; ++i) {
      for (int j = 0; j < N - 2; ++j) {
        for (int k = 0; k < N - 2; ++k) {
          dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + 1);
          dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], dp[i][j][k] + 1);
          dp[i][j + 1][k + 1] = min(dp[i][j + 1][k + 1], dp[i][j][k] + 1);

          dp[i + 2][j][k] = min(dp[i + 2][j][k], dp[i][j][k] + 1);
          dp[i][j + 2][k] = min(dp[i][j + 2][k], dp[i][j][k] + 1);
          dp[i][j][k + 2] = min(dp[i][j][k + 2], dp[i][j][k] + 1);
        }
      }
    }

    int mn = inf;
    for (int i = 0; i < N; ++i) {
      mn = min(mn, dp[i][i][i]);
    }
    cout << mn << endl;
  }
  
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(int argc, char *argv[])
{
  int a,b;
  while(scanf("%d %d",&a,&b) != EOF){
    if(a == 0&& b ==0)
      break;
  for(int i = 0;i < a;i++){
    for(int j = 0;j < b;j++){
      printf("#");
    }
    printf("\n");
  }
  printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N; cin >> N;
    string ans = "Yes";
    vector<string> v(N);
    for(int i=0;i<N;i++){cin >> v[i];}
    for(int i=0;i<N;i++){
        if(i == 0) continue;
        if(v[i-1][v[i-1].size()-1] != v[i][0]) {ans = "No"; break;}
        for(int j=0;j<i;j++){
            if(v[j] == v[i]) {ans = "No"; break;}
        }
    }
    cout << ans << endl;
}



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

int main() {
  int N, Q; cin >> N >> Q;
  string S; cin >> S;
  vector<vector<int>> lr(Q);
  for (int i = 0; i < Q; i++) {
    int l, r; cin >> l >> r;
    lr.at(i) = { l, r };
  }
  vector<int> a(S.size()+1, 0);
  for (int i = 1; i < S.size(); i++) {
    if (S.at(i-1) == 'A' && S.at(i) == 'C') a.at(i)++;
    a.at(i+1) = a.at(i);
  }
  for (int i = 0; i < Q; i++) {
    cout << a.at(lr.at(i).at(1)-1) - a.at(lr.at(i).at(0)-1) << endl;
  }
}

Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        vec[i]=x;
    }
    bool hantei=1;
    vector<bool> reg(n,1);
    for(int i=1;i<n;i++){
        if(vec[i]<vec[i-1]){
            while(i>=1){
                if(reg[i-1]){
                    vec[i-1] = vec[i-1]-1;
                    reg[i-1]=0;
                }else{
                    hantei=0;
                    break;
                }
                if(vec[i]<vec[i-1]){
                    hantei=0;
                    break;
                }
                i--;
                if(i==0){
                    break;
                }
                if(vec[i]>=vec[i-1]){
                    break;
                }
            }
        }
    }
    if(hantei){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	string s;
	cin>>s;
	bool f=0,g=0,h=0,k=0;
	if(s.size()>=6) f=1;
	rep(i,0,s.size()){
		if('0'<=s[i] && s[i]<='9') g=1;
		if('A'<=s[i] && s[i]<='Z') h=1;
		if('a'<=s[i] && s[i]<='z') k=1;
	}
	if(f && g && h && k) o("VALID");
	else o("INVALID");
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,k,m,p;
   cin>>n>>k;
   m = n%k;
   p = abs(m-k);
   if(m<p)
    cout<<m;
   else
    cout<<p;
   return 0;

}


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

int main(void){
  long long n;
  cin >>n;
  long long i = 0;
  long long sum = 0;
  for(i=1;i<n;i++){
    sum += i;
  }
  
  cout << sum << endl;
  
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int x;cin >> x;
	if(x < 1200){
		cout << "ABC" << endl;
	}
	else cout << "ARC" << endl;
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if(s != string(s.rbegin(), s.rend())){
    ANS("No");
    return 0;
  }
  int32 n = s.size();
  string t = s.substr(0,(n-1)/2);
  if(t != string(t.rbegin(), t.rend())){
    ANS("No");
    return 0;
  }
  t = string(s.rbegin(),s.rend()).substr(0,(n-1)/2);
  // ANS(t);
  Yes(t == string(t.rbegin(),t.rend()));
  return 0;
}

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

int main(){
	double a, b, c, d, e, f;
	double x, y;

	while (cin >> a >> b >> c >> d >> e >> f){
		x = (c*e - b*f) / (a*e - b*d);
		y = (a*f-c*d) / (a*e - b*d);
		if (x == 0){ x = 0; }
		if (y == 0){ x = 0; }
		printf("%.3f %.3f\n", x, y);
	
	}

}

Measured memory_bytes: 1236
#
# Keitai Message
#

class Cellular < Hash

  def initialize
    @buf=[]
    @key='0'
    @value=-1
    self.store('1', %w". , ! ?"+[' '])
    self.store('2', %w"a b c")
    self.store('3', %w"d e f")
    self.store('4', %w"g h i")
    self.store('5', %w"j k l")
    self.store('6', %w"m n o")
    self.store('7', %w"p q r s")
    self.store('8', %w"t u v")
    self.store('9', %w"w x y z")
  end

  def push(b)
    if b=='0'
      enter
    else
      @key=b
      @value+=1
      @value=0 if @value==self[@key].size
    end
  end

  def enter
    @buf<<self[@key][@value] if @key!='0'
    @key='0'
    @value=-1
  end

  def message
    @buf.join('')
  end

end

gets.to_i.times do

  cell = Cellular.new
  gets.chomp.chars { |c| cell.push(c) }
  puts cell.message

end

Measured memory_bytes: 6108
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    while (a[i]) {
      for (int j = i; j < n && a[j]; ++j) --a[j];
      ++ret;
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val as = List.fill(n)(sc.nextInt)
    println(sunuke(as))
  }
  def sunuke(as: List[Int]): Int =
    if (as.forall(_%2 == 0)) 1 + sunuke(as.map(_/2)) else 0
}


Measured memory_bytes: 25672
#include <iostream>

using namespace std;
typedef long long ll;

string s;
ll k;

void solve() {
  ll infinityPos = s.size() - 1;
  char firstNonOne = '0';
  for (int i=0;i<s.size();i++) {
    if (s[i] != '1') {
      infinityPos = i;
      firstNonOne = s[i];
      break;
    }
  }
  if (infinityPos <= k-1 && firstNonOne != '0') {
    cout << firstNonOne << endl;
  } else {
    cout << '1' << endl;
  }
}

int main() {
  cin >> s >> k;
  solve();
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
price_master = 0
for i in range(N+1):
    price_master += abs(A[i+1] - A[i])

for i in range(N):
    print(price_master - abs(A[i+1]-A[i]) - abs(A[i+2] - A[i+1]) + abs(A[i+2] - A[i]))


Measured memory_bytes: 13916
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String S = scan.next();
		int x = 0;
		int max = 0;
		for(int i = 0; i < N; i++) {
			if(S.substring(i, i + 1).equals("I")) {
				x++;
				if(x > max) {
					max = x;
				}
			} else if(S.substring(i, i + 1).equals("D")) {
				x--;
			}
		}
		System.out.println(max);
		scan.close();
	}

}


Measured memory_bytes: 21972
from collections import defaultdict

class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        
        S_arr = [ord(x) for x in S]
        POWER = [1] * (N + 1)
        HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
        self.S_arr = S_arr
        self.POWER = POWER
        self.HASH = HASH

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash

def main():
    N = int(input())
    S = input()
    MOD = 998244353
    rs = RollingHash(S, MOD=MOD, BASE=37)
    h, p = rs.HASH, rs.POWER

    left, right = 0, N // 2 + 1
    D = [0] * N
    while abs(right - left) > 1:
        mid = (left + right) // 2
        # hash_to_left = defaultdict(list)
        hashes = set()
        L = mid
        P = p[L]
        for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
        hashes = set()
        ok = False
        for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
        if ok:
            left = mid
        else:
            right = mid

    print(left)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4176