akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 99999999;

int main(void) {

  int e, t;
  vector<int> y2, z3;
  for (t = 0; t*t <= 1000000; t++) y2.push_back(t*t);
  for (t = 0; t*t*t <= 1000000; t++) z3.push_back(t*t*t);

  while (cin >> e, e) {
    int m = INF;
    for (int i = 0; i < y2.size(); i++) {
      for (int j = 0; j < z3.size(); j++) {
        if (y2[i]+z3[j] <= e) {
          m = min(m, (e-y2[i]-z3[j])+i+j);
        }
      }
    }
    cout << m << endl;
  }

  return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll n,p[110][11],ans=-1e10,c,kari;
bool f[110][11];

int main(){
  cin>>n;
  fr(i,n) fr(j,10) cin>>f[i][j];
  fr(i,n) fr(j,11) cin>>p[i][j];
  fr(i,1<<10){
    if(i==0) continue;
    kari=0;
    fr(j,n){
      c=0;
      fr(k,10) if((i>>k)&f[j][k]) c++;
      kari+=p[j][c];
    }
    ans=max(ans,kari);
  }
  cout<<ans<<endl;
}

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

using namespace std;
const int N = 2e5 + 10;
int p[N], a[N], n;

bool isval(int x) {
    for (int i = 0; i <= 2 * n; i++) a[i] = (p[i] >= x);
    if (a[n] == a[n-1] || a[n] == a[n+1]) return a[n];
    int l = n-1, r = n+1;
    while (a[l] != a[l-1]) l--;
    while (a[r] != a[r+1]) r++;
    l++, r--;
    if ((r - l + 1) % 2) return a[l-1];
    if (n <= (r+l)/2) return a[l-1];
    else return a[r+1];

}
int main()
{
    cin >> n;
    for (int i = 1; i < 2 * n; i++) cin >> p[i];
    p[0] = p[1], p[2*n] = p[2*n - 1];
    int dw = 1, up = 2 * n - 1;
    while (up - dw > 1) {
        int mid = (up + dw)>>1;
        if (isval(mid)) dw = mid;
        else up = mid;
    }
    cout << dw << "\n";
}


Measured memory_bytes: 1920
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }
        int[] Xclone = X.clone();
        Arrays.sort(Xclone);
        int front = Xclone[N/2-1];
        int back = Xclone[N/2];
        for (int i : X) {
            if (i <= front) {
                System.out.println(back);
            } else if (back <= i) {
                System.out.println(front);
            }
        }
    }    
}


Measured memory_bytes: 65524
import collections

N, K = map(int, input().split())
A = list(map(int, input().split()))

A = collections.Counter(A)
A = A.most_common()

M = len(A) # 数の種類
ans = 0

for i in range(len(A)-1, -1, -1):
    if M <= K:
        print(ans)
        break
    else:
        M -= 1
        ans += A[i][1]
else:
    print(ans)




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

int main() {
    string s;
    cin >> s;
    vector<int> cnt(2019, 0);
    int t = 0, ten = 1;
    for (int i=s.size()-1; i>=0; i--) {
        t = (t + ten * (s[i] - '0')) % 2019;
        ten *= 10;
        ten %= 2019;
        cnt[t]++;
    }
    int ans = 0;
    for (int i=0; i<=2018; i++) {
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    ans += cnt[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	int ans = 0;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'g') ans += i % 2;
		else ans -= !(i % 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    S = sum(A)
    Q = int(input())
    for _ in range(Q):
        b, c = map(int, input().split())
        nb = C.get(b, 0)
        S += nb * (c - b)
        if b in C:
            del C[b]
        C[c] = C.get(c, 0) + nb
        print(S)
main()


Measured memory_bytes: 24008
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n = N;
		int keta;
		int sum = 0;
		int a[] = new int[9];
		for(int i = 8;i >= 0;i--) {
			a[i] = (int)Math.pow(10, i);
			keta = n/a[i];
			n = n - a[i] * keta;
			sum = sum + keta;
		}
		if(N%sum == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}

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


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int whitecnt = 0;
	for(int i=0; i<n; i++) {
		if(s[i] == 'W') {
			whitecnt++;
		}
	}
	int ans = 0;
	int val = n-whitecnt;
	for(int i=(n-1); i>=val; i--) {
		if(s[i] == 'R') {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  char d,e,f;
  d = a.at(0);
  e = b.at(0);
  f = c.at(0);
  d -= 32;
  e -= 32;
  f -= 32;
  cout << d << e << f << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";



int main()
{
    fastio
    ll t,i,j,x,f,k;
    
    cin>>k;
    if(k%7==0)
    {
        k/=7;
    }
    if(__gcd(10,k)!=1)
    {
        cout<<-1;
        return 0;
    }
    
    ll res=1;
    f=1%k;
    
    while(f)
    {
        ++res;
        f=(10*f+1)%k;
    }
    cout<<res;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long int;

int main(){
    int a,b;
    cin>>a>>b;
    if(a%2==0 || b%2==0) cout<<"Even"<<endl;
    else cout<<"Odd"<<endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long BLOCK_SZ = 555;
int freqArr[10000000];
typedef struct query { long long start, end, index; } query;
bool myComp(query a, query b);
void add(long long index, long long& curAns);
void remove(long long index, long long& curAns);

int main() {
  long long N, Q;
  scanf("%lld", &N);
  scanf("%lld", &Q);

  BLOCK_SZ = sqrt(N);
  vector<long long> arr(N);
  for(long long i = 0; i < N; i++)
    scanf("%lld", &arr[i]);

  
  vector<query> qq(Q);
  for(long long i = 0; i < Q; i++) {
    scanf("%lld%lld", &qq[i].start, &qq[i].end);
    qq[i].start--;
    qq[i].end--;
    qq[i].index = i;
  }
  sort(qq.begin(), qq.end(), myComp);

  vector<long long> queryAns(Q);
  long long curL = 0, curR = 0, curAns = 0;
  for(long long i = 0; i < Q; i++) {
    while(curL < qq[i].start) {
      remove(arr[curL], curAns);
      curL++;
    }
    while(curL > qq[i].start) {
      add(arr[curL-1], curAns);
      curL--;
    }
    while(curR <= qq[i].end) {
      add(arr[curR], curAns);
      curR++;
    }
    while(curR > qq[i].end+1) {
      remove(arr[curR-1], curAns);
      curR--;
    }
    queryAns[qq[i].index] = curAns;
  }

  for(long long i = 0; i < Q; i++)
    printf("%lld\n", queryAns[i]);
  return 0;
}

bool myComp(query a, query b) {
  if(a.start/BLOCK_SZ == b.start/BLOCK_SZ)
    return a.end < b.end;
  return a.start/BLOCK_SZ < b.start/BLOCK_SZ;
}

void add(long long index, long long& curAns) {
  freqArr[index]++;
  curAns += (freqArr[index] == 1);
}

void remove(long long index, long long& curAns) {
  freqArr[index]--;
  curAns -= (freqArr[index] == 0);
}

Measured memory_bytes: 25220
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define inRange(x, a, b) (a <= x && x <= b)

int main(){
    string l;
    while(getline(cin, l)){
        string s = "";
        for(char c : l){
            if(inRange(c, 'a', 'z'))    s += (char)(c-'a'+'A');
            if(inRange(c, 'A', 'Z'))    s += c;
        }
        int n = s.length();
        set<string> res;
        for(int i = 1; i+1 < n; i++){
            int x = i, y = i;
            while(x-1 >= 0 && y+1 < n && s[x-1]==s[y+1])    x--, y++;
            if(y != x)  res.insert(s.substr(x, y-x+1));
            if(s[i] != s[i+1])  continue;
            x = i, y = i+1;
            while(x-1 >= 0 && y+1 < n && s[x-1]==s[y+1])    x--, y++;
            if(y-x != 1)    res.insert(s.substr(x, y-x+1));
        }
        vector<string> odd, even;
        for(auto it = res.begin(); it != res.end(); it++){
            string tmp = *it;
            if(tmp.size()%2)    odd.push_back(tmp);
            else                even.push_back(tmp);
        }
        auto cp = [](string s, string t)->bool{
            return s.length() < t.length();
        };
        sort(odd.begin(), odd.end(), cp);
        sort(even.begin(), even.end(), cp);
        // cover?
        for(int i = 0; i < odd.size(); i++){
            for(int j = i+1; j < odd.size(); j++){
                int center = odd[j].size()/2;
                int ilen = odd[i].size();
                if(odd[j].substr(center-ilen/2, ilen) == odd[i]){
                    res.erase(odd[i]);
                    break;
                }
            }
        }
        // for(int i = 0; i < even.size(); i++){
        //     for(int j = i+1; j < even.size(); j++){
        //         int center = even[j].size()/2;
        //         int ilen = even[i].size();
        //         if(even[j].substr(center-ilen/2, ilen) == even[i]){
        //             res.erase(even[i]);
        //             break;
        //         }
        //     }
        // }
        if(res.begin() != res.end()){
            cout << *res.begin();
        }else{
            cout << endl;
            continue;
        }
        for(set<string>::iterator it = ++res.begin(); it != res.end(); it++)    cout << " " << *it;
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int sum = A + B;
        int multi = A * B;
        int minus = A - B;
        if (sum >= multi && sum >= minus) {
            System.out.println(sum);
        } else if (multi > sum && multi > minus) {
            System.out.println(multi);
        } else if (minus > multi && minus > sum) {
            System.out.println(minus);
        }

    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class LazySegTree{
private:
	int n;
	vector<PII> node;
public:
	LazySegTree(vector<PII> v){
		int sz = v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1, {INF, -1});
		REP(i, sz) node[i+n-1] = v[i];
		for(int i = n-2;i >= 0;i--) node[i] = min(node[2*i+1], node[2*i+2]);
	}

	void update(int k, int a){
		k += n-1;
		node[k] = {a, -1};
		while(k){
			k = (k-1)/2;
			node[k] = min(node[k*2+1], node[k*2+2]);
		}
	}

	PII query(int a, int b, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;

		if(b <= l || r <= a) return {INF, -1};
		if(a <= l && r <= b) return node[k];

		return min(query(a, b, k*2+1, l, (l+r)/2), query(a, b, k*2+2, (l+r)/2, r));
	}
};

class LazySegTree2{
private:
	int n;
	vector<int> node;
public:
	LazySegTree2(vector<int> v){
		int sz = v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1,1);
		for(int i = n-2;i >= 0;i--) node[i] = node[2*i+1]+node[2*i+2];
	}

	void update(int k, int a){
		k += n-1;
		node[k] = a;
		while(k){
			k = (k-1)/2;
			node[k] = node[k*2+1]+node[k*2+2];
		}
	}

	int query(int a, int b, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;

		if(b <= l || r <= a) return 0;
		if(a <= l && r <= b) return node[k];

		return query(a, b, k*2+1, l, (l+r)/2)+ query(a, b, k*2+2, (l+r)/2, r);
	}
};
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	int k;
	cin >> s >> k;
	vector<PII> c;
	REP(i, s.size()){
		c.push_back({s[i]-'a', i});
	}
	LazySegTree sg(c);
	LazySegTree2 sg2(vector<int>(214514, 1));
	string res = "";
	while(k > 0){
		int l = 0, r = s.size(), m;
		while(r-l > 1){
			m = (l+r)/2;
			if(sg2.query(0, m) > k)
				r = m;
			else
				l = m;
		}
		m = l;

		PII a = sg.query(0, min(m+1, (int)s.size()));
		if(a.first == INF || a.second == -1) break;
		k -= sg2.query(0, a.second);
		res = res+(char)(a.first+'a');
		sg.update(a.second, INF);
		sg2.update(a.second, 0);
		s[a.second] = -1;
	}
	cout << res;
	REP(i, s.size()){
		if(s[i] != -1)
			cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 11744
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String sp = sc.next();
        String T = sc.next();
        String ans = solve(sp,T);
        System.out.println(ans);
    }
    private static String solve(String sp, String T){
        String error = "UNRESTORABLE";
        int len1 = sp.length();
        int len2 = T.length();
        if(len1<len2) return error;
        for(int i=len1-len2; i>=0; i--){
            boolean flag = true;
            for(int j=0;j<len2;j++){
                if(sp.charAt(j+i)=='?'||T.charAt(j)==sp.charAt(j+i)) continue;
                else{
                    flag = false;
                    break;
                }
            }
            if(flag){
                StringBuilder sb = new StringBuilder();
                for(int j=0;j<i;j++){
                    if(sp.charAt(j)=='?') sb.append("a");
                    else sb.append(sp.charAt(j));
                }
                sb.append(T);
                for(int j=i+len2;j<len1;j++){
                    if(sp.charAt(j)=='?') sb.append("a");
                    else sb.append(sp.charAt(j));
                }
                return sb.toString();
            }
        }
        return error;
    }
}

Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define inf 1000000007000000007
typedef long long ll;
using namespace std;

#define N 210
int n;
struct Edge{ll to,lim,revindex;};
vector<Edge> v[N];
ll dis[N];

void Make_Edge(int from,int to,ll lim){
	v[from].push_back((Edge){to,lim,v[to].size()});
	v[to].push_back((Edge){from,0,v[from].size()-1});
}

void BFS(int start){
	lol(i,N)dis[i]=inf;
	dis[start]=0;
	queue<int> Q;
	Q.push(start);
	while(!Q.empty()){
		int x=Q.front(); Q.pop();
		lol(i,v[x].size()){
			if(dis[v[x][i].to]==inf&&v[x][i].lim>0){
				dis[v[x][i].to]=dis[x]+1;
				Q.push(v[x][i].to);
			}
		}
	}
}

int DFS(int x,int goal,ll minedge){
	if(x==goal)return minedge;
	for(int i=0;i<v[x].size();i++){
		if(dis[x]<dis[v[x][i].to]&&v[x][i].lim>0){
			int mini=DFS(v[x][i].to,goal,min(minedge,v[x][i].lim));
			if(mini>0){
				v[x][i].lim-=mini;
				v[v[x][i].to][v[x][i].revindex].lim+=mini;
				return mini;
			}
		}
	}
	return 0;
}

ll Dinic(int start,int goal){
	ll flow=0;
	while(1){
		BFS(start);
		if(dis[goal]==inf)return flow;
		flow+=DFS(start,goal,inf);
	}
}

int main(){
	int h,w;cin>>h>>w;
	n=h+w+2;
	int sx,sy,tx,ty;
	lol(i,h)lol(j,w){
		char z;cin>>z;
		if(z=='S'){Make_Edge(n-2,i,inf);Make_Edge(n-2,j+h,inf);sy=i,sx=j;}
		if(z=='T'){Make_Edge(i,n-1,inf);Make_Edge(j+h,n-1,inf);ty=i,tx=j;}
		if(z=='o'){Make_Edge(i,j+h,1);Make_Edge(j+h,i,1);}
	}
	if(sy==ty||sx==tx)cout<<"-1"<<endl;
	else cout<<Dinic(n-2,n-1)<<endl;
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
    int n;

    while(cin>>n, n) {
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            int tmp;
            cin>>tmp;
            a[i] = tmp;
        }

        sort(begin(a), end(a));

        int diff = 10000000;
        for (int i = 0; i < n-1; ++i) {
            diff = min(diff, a[i+1] - a[i]);
        }

        cout<<diff<<endl;
    }
    return 0;
}

Measured memory_bytes: 3120
import sys

n,l = input().split()
n,l = int(n), int(l)

tastes = []
bestAppleIndex = -1
bestAppleTaste = 9999999999

for i in range(0,n):

    tastes.append( l + i + 1 - 1 )

    if abs(bestAppleTaste) > abs(tastes[i]) :
        bestAppleTaste = tastes[i]
        bestAppleIndex = i

tastes[ bestAppleIndex ] = 0

print(sum(tastes))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
int n,f[N],g[N],sz[N];Vi e[N];ll res;char s[N];
void dfs1(int u, int fa){
	sz[u]=s[u]=='1';
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)
		dfs1(e[u][i],u),umax(f[u],f[e[u][i]]+1),sz[u]+=sz[e[u][i]];
}
void dfs2(int u,  int fa){
	int mx=-1e9,semx=-1e9;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)
		if(f[e[u][i]]>mx){semx=mx;mx=f[e[u][i]];}
		else if(f[e[u][i]]>semx)semx=f[e[u][i]];
		
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)
		g[e[u][i]]=max(g[u]+1,mx==f[e[u][i]]?semx+2:mx+2),dfs2(e[u][i],u);
}
int query(int *a, int n, int x){return a[n]==x?a[n-1]:a[n];}
void dfs(int u, int fa){
	static int a[N];
	int len=0;a[++len]=g[u];a[++len]=0;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)a[++len]=f[e[u][i]]+1;
	sort(a+1,a+len+1);
	if(s[u]=='1')res+=a[len-1]+1;
	else{
		int mn=1e9;
		rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa){
			if(sz[e[u][i]]&&query(a,len,f[e[u][i]]+1)>=f[e[u][i]]+1)umin(mn,f[e[u][i]]+1);
		}else if(sz[1]-sz[u]&&query(a,len,g[u])>=g[u])umin(mn,g[u]);
		if(mn<=a[len-1])res+=a[len-1]-mn+1;
	}
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa){
		int v=e[u][i];dfs(e[u][i],u);
		int x=g[v]-1,y=f[v];bool ok=0;
		if(y==min(x,y))ok|=sz[v];
		if(x==min(x,y))ok|=sz[1]-sz[v];
		res+=ok;
	}
}
int main() {
	read(n);rep(i,1,n-1){
		int u,v;read(u);read(v);e[u].pb(v);e[v].pb(u);
	}
	scanf("%s",s+1);
	dfs1(1,0);dfs2(1,0);dfs(1,0);cout<<res;
	return 0;
}


Measured memory_bytes: 42496
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <string.h>
#include <bitset>
#include <array>

using namespace std;

const int maxn=1005;

int a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a, a+n);
	int sum=0;
	for(int i=0; i<k; i++){
		sum+=a[i];
	}
	cout << sum << '\n';
	return 0;
}

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

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

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    
    ll n = S.size();
    vector<ll> T(n + 1, 0);
    ll m = 2019;
    T[n] = 0;
    ll r = 1;
    vector<ll> countMod(m, 0);
    countMod[T[n]]++;
    REP(i, n)
    {
        T[n - i - 1] = ((S[n - i - 1] - '0') * r + T[n - i]) % m;
        countMod[T[n - i - 1]]++;
        r *= 10;
        r = r % m;
    }
    ll ans = 0;
    REP(i, m) ans += countMod[i] * (countMod[i] - 1) / 2;

    cout << ans << endl;
}


Measured memory_bytes: 5224
#include <iostream>
using namespace std;
int minpath(int tab[],int k,int n)
{
	int tmp;
	int maxbreak=k-tab[n-1]+tab[0];
	for(int i=0;i<n-1;i++)
	{
		tmp=tab[i+1]-tab[i];
		if(tmp>maxbreak)maxbreak=tmp;
	}
	return k-maxbreak;
}
int main()
{
	int k,n;
	cin>>k>>n;
	int *tab;
	tab=new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>tab[i];
	}
	cout<<minpath(tab,k,n);
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int a, b, c=0;
    for (; c<3000; c++) {
        cin >> a >> b;
        if (a==0 && b==0) break;
        if (b<a) cout << b << " " << a << endl;
        else cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;

int main(){
    int n,d; cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d));
    rep(i,n)rep(k,d)cin>>x[i][k];
    int cnt=0;
    for(int i=0;i<n-1;i++){
        for(int k=i+1;k<n;k++){
            double sum=0;
            rep(t,d){
                sum +=pow(x[i][t]-x[k][t],2);
            }
            sum = sqrt(sum);
            if(sum-(int)sum == 0)cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int ar[5];
  for(int i=0;i<5;i++)
  {
    cin>>ar[i];
  }
  for(int i=0;i<5;i++)
  {
    if(ar[i]==0)
    {
      cout<<i+1<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
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); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
constexpr ll INF = 1LL<<60;

int main() {
    ll a, b, k;
    cin >> k;
    cin >> a >> b;

    FOR(i, a, b+1) {
        if(i%k==0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}


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

using namespace std;

int n, q;
string str[100100];
int lis[400100][26];
int pt[100100];
int d[400100];
int chk[400100];
int def[100100];
int mat[100100][26][26];
int p = 1;

char buf[400100];

int sz(int idx) {
	return (~idx)?d[idx]:0;
}

int cons(int len) {
	int cur = 0, i;
	d[cur]++;
	for (i=0;i<len;i++) {
		int v = buf[i]-'a';
		if (lis[cur][v]==-1) {
			lis[cur][v] = p;
			cur = p;
			p++;
		}
		else {
			cur = lis[cur][v];
		}
		d[cur]++;
	}
	chk[cur]++;
	return cur;
}

void calcmat(int idx) {
	int i, j, cur = 0;
	for (i=0;i<str[idx].size();i++) {
		int v = str[idx][i]-'a';
		for (j=0;j<26;j++) {
			if (j==v||lis[cur][j]==-1) continue;
			mat[idx][j][v] += d[lis[cur][j]];
		}
		if (chk[cur]) def[idx]++;
		cur = lis[cur][v];
	}
}

char per[30];
int main() {
	int i, j, k;

	scanf("%d",&n);
	memset(lis,-1,sizeof(lis));
	for (i=0;i<n;i++) {
		scanf("%s",buf);
		int len = strlen(buf);
		str[i].assign(buf,buf+len);
		pt[i] = cons(len);
	}
	for (i=0;i<n;i++) calcmat(i);
	scanf("%d",&q);
	for (i=0;i<q;i++) {
		int a, res = 0;
		scanf("%d%s",&a,per); --a;
		for (j=0;j<26;j++) {
			for (k=j+1;k<26;k++) {
				res += mat[a][per[j]-'a'][per[k]-'a'];
			}
		}
		printf("%d\n",res+def[a]+1);
	}

    return 0;
}


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

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

    int num = 0;
    while(true){
        bool f = true;
        for(int i=0; i<n; i++){
            if(a[i]%2 == 0){
                a[i] /= 2;
            }else{
                f = false;
                break;
            }
        }
        if(f){
            num++;
        }else{
            break;
        }
    }
    cout << num << endl;
  
    return 0;
}


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

#define ll long long
#define ld long double

#define pii pair<int, int>
#define pci pair<char, int>
#define pcc pair<char, char>

#define vi vector <int>
#define vll vector<long long>
#define vld vector<long double>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>

#define vvi vector<vi>
#define vvll vector<vll>
#define vvld vector<vld>
#define vvb vector<vb>
#define vvc vector<vc>
#define vvs vector<vs>

#define vpii vector<pii>
#define vpci vector<pci>
#define vpcc vector<pcc>

#define all(v) (v).begin(), (v).end()
#define allrev(v) (v).rbegin(), (v).rend()
#define allcomp(v) (v).begin(), (v).end(), comp
#define allrevcomp(v) (v).rbegin(), (v).rend(), comp

const int MOD = 1e9 + 7;
const ld pi = 3.1415926535897932384626433832;

#define line cout<<"\n";
#define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

void solve(int test_case){
   string a;
   cin >> a;
   if(a[2] == a[3] && a[4] == a[5])
    cout <<"Yes";
   else cout << "No";

}

int main(){
    fast
    int test = 1;
   // cin>>test;
    for(int i = 1; i <= test; i++){
        solve(i);
    }
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    int n=s.size();
    int ans=n/2;
    REP(i,n) if(s[i]=='p') ans--;
    cout << ans << endl;
}

Measured memory_bytes: 3776
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
struct data
{
	ll x , y;
	double ang;
	bool operator<(const data &a)const {return ang < a.ang;}
} a[400010];
int main()
{
	int n , i , p;
	ll sx = 0 , sy = 0 , ans = 0;
	scanf("%d" , &n);
	for (i = 1 ; i <= n ; i ++ ) scanf("%lld%lld" , &a[i].x , &a[i].y) , a[i].ang = atan2(a[i].y , a[i].x);
	sort(a + 1 , a + n + 1);
	for (p = i = 1 ; i <= n ; i ++ )
	{
		while (p < i + n && a[p].ang - a[i].ang < pi) sx += a[p].x , sy += a[p ++ ].y , ans = max(ans , sx * sx + sy * sy);
		sx -= a[i].x , sy -= a[i].y , ans = max(ans , sx * sx + sy * sy);;
		a[i + n].x = a[i].x , a[i + n].y = a[i].y , a[i + n].ang = a[i].ang + 2 * pi;
	}
	printf("%.18f\n" , sqrt(1.0 * ans));
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<limits.h>
#include<stdlib.h>

int main() {
    int N;
    scanf("%d", &N);
    int A[N];
    int eo = 1;
    int min = INT_MAX;
    int num = 0;
    for(int i=0; i<N; i++) {
        scanf("%d", &A[i]);
        if(A[i] == 0) eo = 0;
        if(A[i] < 0) eo *= -1;
        if(abs(A[i]) < min) {
            num = i;
            min = abs(A[i]);
        }
    }
    long sum = 0;
    if(eo >= 0) {
        for(int i=0; i<N; i++) {
            sum += abs(A[i]);
        }
    } else if(eo == -1) {
        for(int i=0; i<N; i++) {
            if(i==num) continue;
            sum += abs(A[i]);
        }
        sum -= abs(A[num]);
    }
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 512
N = int(input())
streak = 0

C = []

for i in range (0, N):
    A, B = map(int, input().split())
    C.append([A,B])

for i in range (0, N):
    if C[i][0] == C[i][1]:
        streak+=1
    else:
        streak = 0
    if streak > 2:
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 9192
#include <iostream>
#include <cstring>
#include <algorithm>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	};


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void insertSort(int*, int);

int main()
{
	int arr[1001];
	int size = sizeof(arr) / sizeof(arr[0]);
	int num = 0, temp = 0;
	
	scanf(" %d", &num);

	for (int i = 0; i < num; i++)
	{
		scanf(" %d", &temp);
		arr[i] = temp;
	}

	insertSort(arr, num);

	return 0;
}

void insertSort(int arr[], int _size)
{
	int i, j, key,k;

	for (i = 0; i<_size; i++) {
		key = arr[i];
		for (j = i-1; j >= 0; j--) {
			arr[j + 1] = arr[j];
			if (arr[j] < key) break;
		}

		arr[j + 1] = key;

		for (k = 0; k < _size; k++)
		{
			if(k == 0) printf("%d", arr[k]);
			else printf(" %d", arr[k]);

			if (k == _size - 1) printf("\n");
		}
	}


}


Measured memory_bytes: 2088
#include <stdio.h>
#include <math.h>
static double g_cos_pi_3, g_sin_pi_3;
static int g_flag = 1;

void koch_curve(double x1, double y1, double x2, double y2, int n) {
	double x, y, ax, ay, bx, by, cx, cy;

	if (!n) {
		if (g_flag) {
			printf("%.8lf %.8lf\n", x1, y1);
			g_flag = 0;
		}
		printf("%.8lf %.8lf\n", x2, y2);
		return;
	}
	x = (x2-x1) / 3.0;
	y = (y2-y1) / 3.0;
	ax = x1 + x;
	ay = y1 + y;
	bx = x*g_cos_pi_3 - y*g_sin_pi_3 + ax;
	by = x*g_sin_pi_3 + y*g_cos_pi_3 + ay;
	cx = x2 - x;
	cy = y2 - y;

	koch_curve(x1, y1, ax, ay, n-1);
	koch_curve(ax, ay, bx, by, n-1);
	koch_curve(bx, by, cx, cy, n-1);
	koch_curve(cx, cy, x2, y2, n-1);
}

int main(void) {
	int n;

	g_cos_pi_3 = cos(M_PI / 3.0);
	g_sin_pi_3 = sin(M_PI / 3.0);
	scanf("%d", &n);
	koch_curve(0.0, 0.0, 100.0, 0.0, n);
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int K; cin >> K;
    int x[110];
    rep(i, N) cin >> x[i];
    int ans = 0;
    rep(i, N) {
        ans += min(x[i] * 2, abs(K - x[i]) * 2);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, num, place; 
		String front, back; 
		while(true){
			String str = sc.next();
			if(str.equals("-")){
				break;
			}
			num = sc.nextInt();
			for(i=0; i<num; i++){
				place = sc.nextInt();
				back = str.substring(place);
				front = str.substring(0, place);
				str = back + front;
			}
			System.out.println(str);
		}
	}
}


Measured memory_bytes: 26424
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int k = Integer.parseInt(sc.nextLine());
      System.out.println(solve(k));
    }
  }

  public static int solve(int k) {
    int even = k / 2;
    int odd = (k + 1) / 2;
    return even * odd;
  }
}


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

int main()
{
  int A, B, C, D ;
  cin >> A >> B >> C >> D ;
  
  if(A+B>C+D){
    cout <<"Left"<<endl ;
  }
  else if(A+B == C+D){
    cout <<"Balanced"<<endl ;
  }
  else {
    cout <<"Right"<<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 n = sc.nextInt();
        Node[] arrA = new Node[n];
        for (int i = 0; i < n; i++) {
            arrA[i] = new Node(i, sc.nextInt());
        }
        Arrays.sort(arrA);
        int[] idxesA = new int[n];
        for (int i = 0; i < n; i++) {
            idxesA[arrA[i].idx] = i;
        }
        Node[] arrB = new Node[n];
        for (int i = 0; i < n; i++) {
            arrB[i] = new Node(i, sc.nextInt());
        }
        Arrays.sort(arrB);
        int[] idxesB = new int[n];
        for (int i = 0; i < n; i++) {
            idxesB[arrB[i].idx] = i;
        }
        long[] costs = new long[n];
        Arrays.fill(costs, Long.MAX_VALUE);
        PriorityQueue<Path> queue = new PriorityQueue<>();
        queue.add(new Path(0, 0));
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (costs[p.idx] <= p.value) {
                continue;
            }
            costs[p.idx] = p.value;
            if (idxesA[p.idx] != 0) {
                int next = idxesA[p.idx] - 1;
                queue.add(new Path(arrA[next].idx, p.value + Math.abs(arrA[idxesA[p.idx]].value - arrA[next].value)));
            }
            if (idxesA[p.idx] != n - 1) {
                int next = idxesA[p.idx] + 1;
                queue.add(new Path(arrA[next].idx, p.value + Math.abs(arrA[idxesA[p.idx]].value - arrA[next].value)));
            }
            if (idxesB[p.idx] != 0) {
                int next = idxesB[p.idx] - 1;
                queue.add(new Path(arrB[next].idx, p.value + Math.abs(arrB[idxesB[p.idx]].value - arrB[next].value)));
            }
            if (idxesB[p.idx] != n - 1) {
                int next = idxesB[p.idx] + 1;
                queue.add(new Path(arrB[next].idx, p.value + Math.abs(arrB[idxesB[p.idx]].value - arrB[next].value)));
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(costs[i]).append("\n");
        }
        System.out.print(sb);
    }
    
    static class Node implements Comparable<Node>{
        int idx;
        int value;
        
        public Node(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Node another) {
            return value - another.value;
        }
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        long value;
        public Path(int idx, long value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            if (value == another.value) {
                return 0;
            } else if (value < another.value) {
                return -1;
            } else {
                return 1;
            }
        }
        
        public String toString() {
            return idx + ":" + value;
        }
    }
}


Measured memory_bytes: 109772
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cassert>
#include <iomanip>
#include <complex>
    using namespace std;
    int main()
    {
    	ios_base::sync_with_stdio(0);
    	cin.tie(0);
    	//printf("nigga");
    	int G,h,j,k,o=0;
    	cin>>G>>h>>j>>k;
    	for(int i=G;i<=h;i++)
    	{
    		if(i>=j && i<=k)
    			o++;
    	}
        if(o==0)
            o=1;
    	cout<<o-1;
     
     
    	
    	return 0;
    }

Measured memory_bytes: 384
def main():
    import sys
    input = sys.stdin.readline
    
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    A = sorted(A)
    B = []
    L = bin(K)
    flag = 1
    for _ in range(max(len(L)-2,len(bin(A[-1]))-2)):
        zero = 0
        one = 0
        flag = 0
        for i in range(N):
            if A[i] > 0:
                flag = 1
            if A[i]%2 == 0:
                zero += 1
            else:
                one += 1
            A[i] = A[i]//2
        B.append([zero,one])
    B = B[::-1]
    k = pow(2,len(B)-1)
    ans = 0
    tmp = K
    for i in range(len(B)):
        zero,one = B[i]
        if zero > one and tmp >= k:
            ans += zero*k
            tmp -= k
            k //= 2
        else:
            ans += one*k
            k //= 2
    print(ans)
    
main()

Measured memory_bytes: 63960
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> p(n);
    rep(i,n){
        cin>>p[i];
        p[i]++;
    }
    ll sum=0;
    rep(i,k) sum+=p[i];
    ll mx=sum;
    rep(i,n-k){
        sum-=p[i];
        sum+=p[i+k];
        mx=max(mx,sum);
    }
    printf("%.6lf\n",(double)mx/2);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    vi a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    
    if(x == y) {
        cout << "War" << endl;
        return 0;
    }

    bool nowar = false;
    for(int i = x+1; i <= y; i++) {
        bool find = true;
        rep(j, n) {
            if(a[j] >= i) find = false;
        }
        rep(j, m) {
            if(b[j] < i) find = false;
        }
        if(find) nowar = true;
    }

    cout << (nowar ? "No War" : "War") << endl;
    
    return 0;
}

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

int main()
{
  int64_t a, b, k;
  cin >> a >> b >> k;
  if (a >= k) {
    cout << a - k << ' ' << b << endl;
  } else {
    k -= a;
    cout << 0 << ' ';
    if (b > k) {
      cout << b - k << endl;
    } else {
      cout << 0 << endl;
    }
  }
}


Measured memory_bytes: 256
import java.util.*;

// ABC 62-D
// http://abc062.contest.atcoder.jp/tasks/arc074_b

public class Main {
	
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		String s = in.next();
		System.out.println(s.indexOf("9") >= 0 ? "Yes" : "No");
	}
}

Measured memory_bytes: 21972
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

import math
def D():
    n = int(input())
    if n==1:
        print(0)
        return
    f = factorization(n)
    res = 0
    for i,j in f:
        res += math.floor(math.sqrt(2*j + 1/4) - 1/2)
    print(res)
D()

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

void solve(long long N, long long M)
{
    int ans = ((N * (N - 1)) / 2) + (M * (M - 1)) / 2;

    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define gc getchar()
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return  w*s;}
struct node{
	int to,next;
}e[1000010];
int n,X[100010],f[1010][5050],tot,h[100010],G[5050];
inline void add(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
inline void add_edge(int x,int y){add(x,y);add(y,x);}
int DFS(int now,int ffa)
{//	int fl=0;
	f[now][0]=0;
	for(int i=h[now];i;i=e[i].next)
	{
		int to=e[i].to;if(to==ffa) continue;
		int w=DFS(to,now);
		memcpy(G,f[now],sizeof(f[now]));
		memset(f[now],0x3f,sizeof(f[now]));
		for(rint j=0;j<=X[now];++j)
		{
			if(w+j<=X[now]) f[now][j+w]=min(f[now][j+w],G[j]+X[to]);
			if(j+X[to]<=X[now]) f[now][j+X[to]]=min(f[now][j+X[to]],G[j]+w);
		}
	}int ans=f[0][0];
	for(rint i=0;i<=X[now];++i) ans=min(ans,f[now][i]);
	return ans;
}
int main()
{
	n=read();memset(f,0x3f,sizeof(f));
	for(rint i=2;i<=n;++i) add_edge(read(),i);
	for(rint i=1;i<=n;++i) X[i]=read();
	if(DFS(1,0)<f[0][0]) cout<<"POSSIBLE";
	else cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 22400
#include<stdio.h>
int i(){
	return getchar()-'0';
}
int main(){
	int a,b,c,d;
	a=i();b=i();c=i();d=i();
	if(a + b + c + d == 7){printf("%d+%d+%d+%d=7\n",a,b,c,d);return 0;}
	if(a + b + c - d == 7){printf("%d+%d+%d-%d=7\n",a,b,c,d);return 0;}
	if(a + b - c + d == 7){printf("%d+%d-%d+%d=7\n",a,b,c,d);return 0;}
	if(a + b - c - d == 7){printf("%d+%d-%d-%d=7\n",a,b,c,d);return 0;}
	if(a - b + c + d == 7){printf("%d-%d+%d+%d=7\n",a,b,c,d);return 0;}
	if(a - b + c - d == 7){printf("%d-%d+%d-%d=7\n",a,b,c,d);return 0;}
	if(a - b - c + d == 7){printf("%d-%d-%d+%d=7\n",a,b,c,d);return 0;}
	if(a - b - c - d == 7){printf("%d-%d-%d-%d=7\n",a,b,c,d);return 0;}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int x, y;
  cin >> x >> y;
  if (x == y) {
    cout << "Yes" << endl;
    return 0;
  }
  set<int> a = { 1, 3, 5, 7, 8, 10, 12 };
  set<int> b = { 4, 6, 9, 10, 11 };
  if ((a.count(x) > 0 && a.count(y) > 0) || (b.count(x) > 0 && b.count(y))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

typedef long long ll;

const int kN = 1e5 + 5;

int n, m, a[kN], t[kN]; ll x[kN], d[kN], ans[kN], bas[kN];

void QPow(ll k) {
	while(k) {
		if(k & 1) {
			for(int i = 1; i <= n; ++i) t[i] = ans[bas[i]];
			for(int i = 1; i <= n; ++i) ans[i] = t[i];
		}
		for(int i = 1; i <= n; ++i) t[i] = bas[bas[i]];
		for(int i = 1; i <= n; ++i) bas[i] = t[i];
		k >>= 1;
	}
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%lld", x + i), ans[i] = i, bas[i] = i;
	ll k;
	scanf("%d%lld", &m, &k);
	for(int i = 1; i <= m; ++i) scanf("%d", a + i), std::swap(bas[a[i]], bas[a[i] + 1]);
	for(int i = 1; i <= n; ++i) d[i] = x[i] - x[i - 1];
	QPow(k);
	for(int i = 1; i <= n; ++i) t[i] = d[ans[i]];
	ll cur_ans = 0;
	for(int i = 1; i <= n; ++i) {
		cur_ans += t[i];
		printf("%lld.0\n", cur_ans);
	}
	return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>
#include <stack>
#include <utility>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define MP make_pair
const int N=5e2+10;
int main(){
    int n,m,a[N][N],now,ans;
    pi temp;
    stack<pi> s;
    char c[N];
    while(true){
        scanf("%d%d",&n,&m);
        if(n==0&&m==0)return 0;
        ans=0;
        for(int i=0;i<n;i++){
            scanf("%s",c);
            now=0;
            for(int j=0;j<m;j++){
                if(c[j]=='.')now++;
                else now=0;
                a[i][j]=now;
            }
        }
        for(int j=0;j<m;j++){
            while(!s.empty())s.pop();
            for(int i=0;i<n;i++){
                while(!s.empty()){
                    if(s.top().F>a[i][j]){
                        temp=s.top();
                        s.pop();
                        if(s.empty())ans=max(ans,temp.F*i);
                        else ans=max(ans,temp.F*(i-1-s.top().S));
                    }
                    else break;
                }
                s.push(MP(a[i][j],i));
            }
            while(!s.empty()){
                temp=s.top();
                s.pop();
                if(s.empty())ans=max(ans,temp.F*n);
                else ans=max(ans,temp.F*(n-s.top().S-1));
                
            }
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 3676
<?php
$a = explode(" ", trim(fgets(STDIN)));
$a = array_merge($a, explode(" ", trim(fgets(STDIN))));
$a = array_merge($a, explode(" ", trim(fgets(STDIN))));

$b = array_count_values($a);

if (count($b) != 4) {
    echo "NO\n";
} else {
    $c = array_count_values($b);

    if ($c[1] == 2 && $c[2] == 2) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

Measured memory_bytes: 4728
A, B, C, X, Y = map(int, input().split())
if A + B >= 2 * C:
    print(2 * C * (min(X, Y)) + min(A, 2 * C) * (X - min(X, Y)) + min(B, 2 * C) * (Y - min(X, Y)))
else:
    print(A * X + B * Y)


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

int main() {
	long long a,b,x,ans,mod=1000000007;
	cin >> a >> b >> x;
	ans=0;
	if(x>=a){
		ans+=(((1+(x-a)/(a-b)))%mod)*(a%mod);
		ans%=mod;
		x-=((1+(x-a)/(a-b))%mod)*((a-b)%mod);
	}

	ans=(ans+x)%mod;
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

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


int main(){
    cout << fixed << setprecision(12);
    ll n;
    cin >> n;
    ll out = INF;
    for(ll i = 1; i*i <= n; i++){
        if(n%i==0){
            out = min(out, i-1+(n/i)-1);
        }
    }
    cout << out << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){

    string s1,s2;
    cin>>s1>>s2;
    int l=s1.size();
    int c=0;
    for(int i=0;i<l;i++){
        if(s1.at(i)!=s2.at(i)){
            c++;
            break;
        }
    }
    if(c==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }





}


Measured memory_bytes: 3628