akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*
std::vector<bool> sieve;
std::vector<int> primes;

void eratosthenes(int maximum){
	sieve = std::vector<bool>(maximum+1);
	sieve[0]=sieve[1]=false;
	for(int i=2; i<sieve.size(); i++) sieve[i]=true;
	for(int j=4; j<sieve.size(); j+=2) sieve[j]=false;
	for(int i=3; 2*i<sieve.size(); i++){
		if(!sieve[i]) continue;
		for(int j=2*i; j<sieve.size(); j+=i) sieve[j] = false;
	}
}

void get_primes(int maximum){
	if(sieve.size() < maximum) eratosthenes(maximum);
	for(int i=2; i<sieve.size(); i++){
		if(sieve[i]) primes.push_back(i);
	}
}

std::map<long long, int> get_factors(long long x){
	std::map<long long, int> factors;
	for(int p: primes){
		if(p*p>x) break;
		while(x%p==0){
			factors[p]++;
			x /= p;
		}
	}
	if(x>1) factors[x]++;
	return factors;
}
*/

struct Prime {
	std::vector<bool> sieve;
	std::vector<int> list;

	// Keep primes up to n_max
	Prime(int n_max) {
		sieve = std::vector<bool>(n_max+1);
		sieve[0]=sieve[1]=false;
		for(int i=2; i<sieve.size(); i++) sieve[i]=true;
		for(int j=4; j<sieve.size(); j+=2) sieve[j]=false;
		for(int i=3; 2*i<sieve.size(); i++){
			if(!sieve[i]) continue;
			for(int j=2*i; j<sieve.size(); j+=i) sieve[j] = false;
		}
		for(int i=2; i<sieve.size(); i++){
			if(sieve[i]) list.push_back(i);
		}
	}

	std::map<long long, int> factors(long long x) {
		std::map<long long, int> fs;
		for(int p: list){
			if(p*p>x) break;
			while(x%p==0){
				fs[p]++;
				x /= p;
			}
		}
		if(x>1) fs[x]++;
		return fs;
	}
};


/*
int _main(){
	using namespace std;
	get_primes(10000000);
	for(int i=0; i<20; i++) cout << primes[primes.size()-1-i] << endl;
	for(auto p: get_factors(9999995)) cout << p.first << " " << p.second << endl;
	return 0;
}
*/

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;
	Prime pr(1000005);

	ll n; cin >> n;

	int ans = 0;
	for(int p: pr.list){
		if(n==1) break;
		if(n%p) continue;

		int e = 0;
		while(n%p==0){
			n/=p;
			e++;
		}

		int i=1;
		while(e-i>=0){
			e-=i;
			i++;
			ans++;
		}
	}

	if(n>1) ans++;

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3944
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define f first
#define s second

using namespace std;

typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    map<string,pair<int,ll> > m;
    vector<pair<int,string> > v;
    REP(i,n){
      string a;
      ll b,c;
      cin>>a>>b>>c;
      if(m.find(a) == m.end())
	m[a] = mp(m.size(),b*c);
      else
	m[a].s += b*c;
    }
    FOR(it,m) if(it->s.s >= (ll)1000000) v.push_back(mp(it->s.f,it->f));
    if(v.size() == 0) cout << "NA" << endl;
    else{
      sort(ALL(v));
      FOR(it,v) cout << it->s << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include<bitset>
#include <utility>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll M=1e9+7;
//const ll maxn=2e5+7;
//const int MAXN=1005;
const int MAX=2e5+5;
const int MAX_N=MAX;
//const int N=55;
const ll MOD=1000000007;
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
    freopen("1004.in","r",stdin);
    freopen("out.txt","w",stdout);
}
char a[MAX];
int nxt[MAX][26];
int dp[MAX];
int main()
{
    scanf("%s",a);
    int len=strlen(a);
    for(int i=0;i<26;i++)
        nxt[len][i]=len;
    for(int i=len-1;i>=0;i--)
        for(int j=0;j<26;j++)
            nxt[i][j]=((a[i]==(j+'a'))?i:nxt[i+1][j]);
//    printf("%d\n",nxt[len-1][25]);
    dp[len]=1;
    for(int i=len-1;i>=0;i--)
    {
        dp[i]=dp[nxt[i][0]+1]+1;
        for(int j=1;j<26;j++)
            dp[i]=min(dp[i],dp[nxt[i][j]+1]+1);
    }
//    printf("%d~\n",dp[len-1]);
    int now=0;
//    printf("%d\n",dp[now]);
    while(dp[now])
    {
        for(int i=0;i<26;i++)
            if(dp[now]==dp[nxt[now][i]+1]+1)
            {
                printf("%c",'a'+i);
                now=nxt[now][i]+1;
                break;
            }
    }
    printf("\n");

    return 0;
}


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

int n, q, c, b, temp, ans, l, r;
bool com;

int main() {
    cin >> n >> q;
    int f;
    if (n > 1) f= log2(n-1) + 2; else f = 1;
    int a[f][n];
    for (int i=0; i<n; i++) {
        for (int j=0; j<f; j++) a[j][i] = 2147483647;
    }
    for (int i=0; i<q; i++) {
        cin >> com >> b >> c;
        if (!com) {
            a[0][b] = c;
            temp = b/2;
            for (int j=1; j<f; j++) {
                a[j][temp] = min(a[j-1][temp*2], a[j-1][temp*2+1]);
                temp /=2;
            }
        }
        else {
            l=b; r=c; ans = 2147483647;
            for (int curr=0; curr < f; curr++) {
                if (l > r) break;
                if (l%2 == 1) ans=min(ans, a[curr][l]);
                if (r%2 == 0) ans=min(ans, a[curr][r]);
                if (l==r) break;
                l=(l+1)/2;
                r=(r-1)/2;
            }
            cout << ans << endl;
            ans = 2147483647;
        }
    }
}


Measured memory_bytes: 10268
#include <bits/stdc++.h>
//#include <iostream>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main() {
    int N; string S;
    cin>>N>>S;
    int ans=0;
    for (int i = 0; i < N; ++i) {
        string T=S.substr(i);
        //cout<<i<<":"<<T<<endl;
        vector<int> len(T.length());
        len[0]=T.length();
        int j=1,k=0;
        while(j<T.length()){
            while(j+k<T.length()&&T[k]==T[j+k]) ++k;
            len[j]=k;
            if(k==0){
                ++j;
                continue;
            }
            int l=1;
            while(j+l<T.length()&&l+len[l]<k){
                len[j+l]=len[l];
                ++l;
            }
            j+=l; k-=l;
        }

        for(int m=0;m<T.length();m++){
            //cout<<m<<":"<<len[m]<<endl;
            ans=max(ans,min(m,len[m]));
        }
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

const int max_n=100000;
int n;
ll a[max_n+1];

void solve(){
    ll ans=0,hu=0;
    bool flag=false;
    rep(i,n){
        if(a[i]==0) flag=true;
        else if(a[i]<0) hu++;
    }
    if(flag || hu%2==0){
        rep(i,n) ans+=abs(a[i]);
    }else{
        rep(i,n) ans+=abs(a[i]);
        priority_queue<ll,vector<ll>,greater<ll>> p;
        priority_queue<ll,vector<ll>,greater<ll>> m;
        rep(i,n){
            if(a[i]>0) p.push(a[i]);
            else m.push(abs(a[i]));
        }
        if(p.empty()) ans-=2*m.top();
        else ans-=2*min(p.top(),m.top());
    }
    cout << ans;
}

int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    solve();
}

Measured memory_bytes: 2168
# -*- coding: utf-8 -*-

import sys
import itertools
import math

N,M=[int(x) for x in input().split()]
C=[[int(x) for x in input().split()] for i in range(M)]

ps=dict()
for c,(p,y) in enumerate(C):
    if not p in ps:
        ps[p]=[]
    ps[p].append((y,c))

qs=[]
for p,cs in ps.items():
    cs.sort()
    qs += [(c,p,i) for i,(y,c) in enumerate(cs)]

qs.sort()

for c,p,i in qs:
    print("{0:0=6}{1:0=6}".format(p,i+1))


Measured memory_bytes: 57792
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s_li = list(input().rstrip())

    r_li = []
    g_li = []
    b_li = []

    for i in range(n):
        if s_li[i] == 'R':
            r_li.append(i)
        elif s_li[i] == 'G':
            g_li.append(i)
        elif s_li[i] == 'B':
            b_li.append(i)

    if (len(r_li) < 1 or len(g_li) < 1) or len(b_li) < 1:
        print(0)
    else:
        all_c = len(r_li) * len(g_li) * len(b_li)

        for i in range(n):
            for j in range(i+1,n):
                k = 2*j-i
                if k >= n:
                    continue

                if (s_li[i] != s_li[j] and s_li[j] != s_li[k]) and s_li[i] != s_li[k]:
                    all_c -= 1

        print(all_c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9336
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn lower_bound<F>(l: usize, r: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criterion(mid) {
            r = mid;
        } else {
            l = mid;
        }
    }
    l
}

fn solve() {
    let (n,q) = get!(usize, usize);
    let a = get!([isize]);
    let xs = get!(isize; q);

    let mut sums = vec![vec![0;2]; n+1];

    for i in 0..n {
        sums[i+1][i%2] = sums[i][i%2] + a[i];
        sums[i+1][(i+1)%2] = sums[i][(i+1)%2];
    }

    for x in xs {
        let crit = |l: usize| -> bool {
            (x-a[n-(l+1)/2-1]).abs() < (x-a[n-l-1]).abs()
        };
        let l = lower_bound(0, n, crit)+1;
        let res = sums[n][0]-sums[n-(l+1)/2][0]+sums[n][1]-sums[n-(l+1)/2][1] + sums[n-l][(n+1)%2];
        println!("{}", res);
    }
}


Measured memory_bytes: 16124
N, X, Y = map(int, input().split(" "))

counts = [0 for i in range(N-1)]

for i in range(N):
    for j in range(i+1, N):
        if i <= X-1 :
            if j >= Y-1:
                dis = j-i -(Y-X-1)
            elif j < Y-1:
                dis = min([j-i, (X-1)-i+1+abs(j-(Y-1))])
                
        else:
            dis = min([j-i, i-(X-1)+1+abs(j-(Y-1))])
        
        # distances[i].append(dis)
        k = dis-1
        counts[k] += 1
        
for k in range(N-1):
    print(counts[k])

Measured memory_bytes: 3444
from collections import defaultdict

n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
sorted_PY = sorted(PY)
cnt = 1
now = sorted_PY[0][0]
d = defaultdict(int)
for p, y in sorted_PY:
    if now != p:
        cnt = 1
        now = p
    d[y] = (p, cnt)
    cnt += 1

for p, y in PY:
    l, r = map(str, d[y])
    l = '0'*(6-len(l)) + l
    r = '0'*(6-len(r)) + r
    print(l+r)


Measured memory_bytes: 35236
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

class BIT{
	public:
	//[1,i]
	int n;
	vi bit;
//	int bit[MAZ_N+1];
	BIT(int size){
		n=size;
		bit=vi(n+1);
	}
	Def query(int i){//sum
		Def s=0;
		while(i>0){
			cmax(s,bit[i]);
			i-=i&-i;
		}
		return s;
	}
	void add(int i,Def x){
		while(i<=n){
			cmax(bit[i],x);
			i+=i&-i;
		}
	}
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;cin>>n;
	vvi in(2,vi(n));
	rep(i,2)rep(j,n)cin>>in[i][j];

	BIT bit(n);
	rep(i,n)
		bit.add(in[0][i],bit.query(in[0][i])+in[1][i]);
	cout<<bit.query(n)<<endl;
}


Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];


int main()
{
	long long N, K, cnt = 0, tmp, ans = 0;
	cin >> N >> K;

	double time = (double)((double)N/(double)K);

	cout << time << endl;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define vl vector
#define pb push_back
#define ff first
#define ss second
using namespace std;

vl<ll> sieve()
{
    vl<ll> v(10000005);
    int i,j;
    for(i=0;i<10000005;i++) v[i]=0;
    for(i=2;i<10000005;i++) 
    {
        for(j=i;j<=10000004;j+=i) 
        {
            v[j]++;
        }
        v[i]++;
    }
    v[1]=1;
    return v;
}

int main()
{
    ll n,m,i,a=0,b=0,k,j,count=0;
    vl<ll> v;
    v=sieve();
    cin>>n;
    ll ans=0;
    for(i=1;i<=n;i++)
    {
        ans+=v[i]*i;
    }
    cout<<ans;
    
}

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

int main() {
	while (1) {
		int n;//ÔDÌ
		int r;//VbtÌñ
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int cards[n];//J[h
		for (int i = 0; i < n; i++) {
			cards[i] = n - i;
		}
		//rñVbt·é
		for (int i = 0; i < r; i++) {
			int p, c;//pÚ©çc
			cin >> p >> c;
			int tmp[c];//ð·ÌêL¯p
			//tmpÉpÚ©çcði[
			for (int j = p - 1; j < p + c - 1; j++) {
				tmp[j - p + 1] = cards[j];
			}
			//tmpÉi[µ½ªðã«µÄlßé
			for (int j = p - 2; j >= 0; j--) {
				cards[j + c] = cards[j];
			}
			//tmpðãÉß·
			for (int j = 0; j < c; j++) {
				cards[j] = tmp[j];
			}
		}
		cout << cards[0] << endl;
	}
	return 0;
}

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

int main(){
    string s;
    cin>>s;
    long long ans=0;
    long long n=s.size();
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]){
            ans++;
            if(s[i]=='0') s[i]='1';
            else s[i]='0';
        }
    }
    cout<<ans<<endl;

    
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    double sum=0;
    for(int i=0;i<n;i++){
        cin >>a[i];
        sum+=1.0/a[i];
    }
    cout <<setprecision(20) <<1.0/sum << endl;
    return 0;
}


Measured memory_bytes: 384
def otoshidama(N, Y):
    for a in range(N+1):
        for b in range(N+1-a):
            c = N - a - b
            if c < 0:
                break
            r = (10000 * a) + (5000 * b) + (1000 * c)
            if r == Y:
                return (a,b,c)

    return (-1,-1,-1)

N, Y = map(int, input().split())
r = otoshidama(N, Y)
print('{0} {1} {2}'.format(r[0], r[1], r[2]))


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

    set<string> subs;

    int len = s.length();
    REP(i, len) {
        FOR(j, i, min(len, i + K+1)) {
            subs.insert(s.substr(i, j - i + 1));
        }
    }

    auto itr = subs.begin();
    REP(i, K-1) ++itr;
    cout << *itr << endl;
    return 0;
}

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

#define eb emplace_back
#define ld long double
#define ll long long

using namespace std;

const int nm = 200002;

int n, m;
vector<int> adj[nm];
int nc, cnt[nm], comp[nm];

void dfs(int i) {
	cnt[nc]++;
	comp[i] = nc;
	for (int j: adj[i]) {
		if (!comp[j]) {
			dfs(j);
		}
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		adj[u].eb(v);
		adj[v].eb(u);
	}
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		if (!comp[i]) {
			nc++;
			dfs(i);
			res = max(res, cnt[nc]);
		}
	}
	cout << res << "\n";
}


Measured memory_bytes: 21580
#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1)
#define set(x,i) (x|(1<<i))
#define unset(x,i) (x&~(1<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 4000005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() while(t--)
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}

int main()
{
	boost
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);    
    freopen("output.txt", "w", stdout);
#endif
 ll n,m,x,i,j;
 cin>>n>>m>>x;
vector<ll> v[n];
REP(i,n)
{
	REP(j,m+1)
	{
		ll x;
		cin>>x;
	v[i].pb(x);
}
}

ll cost=INF;
for(i=1;i<(1<<n);i++)
{
	ll b[m];
	for(j=0;j<m;j++)
		b[j]=0;
	ll c=0;
for(j=0;j<n;j++)
{
	if(i&(1<<j))
	{
    for(ll k=1;k<m+1;k++)
      b[k-1]+=v[j][k];
  c=c+v[j][0];
	}
}
int f=0;
for(j=0;j<m;j++)
{
	if(b[j]<x)
	{
     f=1;
     break;
	}
}
if(f==0&&c<cost)
	cost=c;
}
if(cost==INF)
cout<<"-1";
else
cout<<cost;

}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define float double
int arr[200005];
int id[200005];
int ans[200005];
signed main()
{
   int n;
   cin>>n;
   
   for(int i=1;i<=n;i++)
   {
       cin>>arr[i];
       id[arr[i]]++;
   }
   int sum=0;
   for(int i=1;i<=n;i++)
   {
       if(id[i]>=2)
       {
           sum+=(id[i]*(id[i]-1)/2);
       }
    }
    for(int i=1;i<=n;i++)
    {
        if(id[arr[i]]>=2)
        {
            int x=id[arr[i]];
            ans[i]=sum-x*(x-1)/2+(x-1)*(x-2)/2;
        }
        else 
        {
            ans[i]=sum;
        }
    }
    for(int i=1;i<=n;i++)
    {
        cout<<ans[i]<<"\n";
    }
    



}


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

int main(void){
    int N, M;
    cin >> N >> M;
    int sum = 1900*M+100*(N-M);
    for(int i = 0; i < M; i++)
        sum*=2;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    print(max(a+b,a-b,a*b))
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39152
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = nm[0];
        var M = nm[1];
        var list = new List<int[]>();
        var listCount = 0;
        for (int i = 0; i < N; ++i)
        {
            var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            if (M < ab[0]) continue;
            list.Add(new int[] { ab[0], ab[1] });
            listCount++;
        }
        list = list.OrderBy(x => x[0]).ToList();
        var tempList = new List<int>();
        var index = 0;
        var ans = 0;
        if(1 <= listCount)
        {
            for (int i = 1; i <= M; ++i)
            {
                while (index < listCount && list[index][0] <= i)
                {
                    var ins = LowerBound(list[index][1], tempList);
                    tempList.Insert(ins, list[index][1]);
                    index++;
                }
                if (1 <= tempList.Count)
                {
                    var n = tempList.Last();
                    ans += n;
                    tempList.RemoveAt(tempList.Count-1);
                }
            }
        }
        Console.WriteLine(ans);
    }

    static int LowerBound(long value, List<int> array)
    {
        var low = 0;
        var high = array.Count();
        
        while (low < high)
        {
            var middle = (high + low) / 2;
            if (value <= array[middle]) high = middle;
            else low = middle + 1;
        }
        return low;
    }
}


Measured memory_bytes: 29752
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  cin>>n;
  vector<ll>a(n-1,0);
  for(ll i=0;i<n-1;i++){
    cin>>a[i];
  }
  ans=a[0]+a[n-2];
  for(ll i=1;i<n-1;i++){
    ans+=min(a[i-1],a[i]);
  }
  cout<<ans<<endl;
}


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

int main() {
  string S;
  int A,B,C,D;
  cin >> S;
  A = S[0] - '0';
  B = S[1] - '0';
  C = S[2] - '0';
  D = S[3] - '0';
  int sum = 0;
  vector<char> op(3);
  rep(i,(1<<3)){
    sum = A;
    if(i & 1){
      sum += B;
      op[0] = '+';
    }else{
      sum -= B;
      op[0] = '-';
    }
    if((i>>1) & 1){
      sum += C;
      op[1] = '+';
    }else{
      sum -= C;
      op[1] = '-';
    }
    if((i>>2) & 1){
      sum += D;
      op[2] = '+';
    }else{
      sum -= D;
      op[2] = '-';
    }
    if(sum == 7) break;
  }
  cout << A << op[0] << B << op[1] << C << op[2] << D << "=7" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<limits>
#include<queue>
#include<stack>
#include<math.h>
#include<array>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main(){
    int X;
    cin >> X;
    if(X == 3 || X == 5 || X == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <sstream>
#include <string>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=100001;
bool vis[N];
vector <int> adj[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
// ll binaryNum[64];
// void decToBinary(ll n, ll k) 
// { 
//     // binaryNum[64]={0};
//     rep(i,64){
//         binaryNum[i]=0;
//     }
//     int i = 0; 
//     while (n > 0) { 
//         binaryNum[i] = n % k; 
//         n = n / k; 
//         i++; 
//     } 
// }
// ll dp[2001][2001]; 
// ll countPartitions(ll n, ll k) 
// {   
//     if (n < k) 
//         return 0;
//     if (n < 2 * k) 
//         return 1; 
//     if (dp[n][k] >= 0) 
//         return dp[n][k]; 
//     ll answer = 1; 
//     for (int i = k; i < n; i++) 
//         answer = answer + countPartitions(n - i, k); 
//     dp[n][k] = answer%mod; 
//     return answer%mod; 
// } 
int M = LONG_MAX;

void solve(){
    ll n,x,m;
    cin>>n>>x>>m;
    vl a;
    a.pb(x);
    set<ll> st;
    st.insert(x);
    int flag=0;
    ll curr=x;
    ll ind=0;
    while(!flag){
        curr = (curr*curr)%m;
        // if(curr>=10000){
        //     cout<<curr<<'\n';
        // }
        if(st.find(curr) != st.end()){
            flag=1;
            break;
        }
        else{
            // ind++;
            a.pb(curr);
            st.insert(curr);
        }
    }
    // cout<<ind<<'\n';
    rep(i,a.size()){
        if(a[i]==curr){
            ind=i;
            break;
        }
    }
    ll tot = a.size();
    ll count = (n-ind)/(tot-ind);
    ll rem = (n-ind)%(tot-ind);
    // cout<<count<<'\n';
    // cout<<rem<<'\n';
    ll ans = 0;
    rep(i,ind){
        ans += a[i];
    }
    loop(i,ind,a.size()-1){
        ans += count*a[i];
    }
    loop(i,ind,ind + rem-1){
        ans += a[i];
    }
    cout<<ans;



}


int main()
{

    // cout<<1<<endl;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 8436
#include <stdio.h>

int gcd(int a, int b);

int main(void)
{
    int a, b;

    while (scanf("%d %d", &a, &b) == 2){
        printf("%d %d\n", gcd(a, b), a / gcd(a, b) * b);
    }

    return (0);
}

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

Measured memory_bytes: 592
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> P;
double cross(P a, P b) {return (a.real() * b.imag() - a.imag() * b.real());}
int main(){
  char z;
  double p,q,r,s,t,u,v,w;
  P a,b,c,d;
  while(cin>>p>>z>>q>>z>>r>>z>>s>>z>>t>>z>>u>>z>>v>>z>>w){
  a = P(p,q);b = P(r,s);c = P(t,u);d = P(v,w);
  if ((cross(b-a,c-a)*cross(d-a,c-a))<0&&(cross(a-b,d-b)*cross(c-b,d-b))<0)cout<<"YES"<<endl;
  else cout << "NO" << endl;}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
ll a[200001],b[200001],c[200001];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    ll ans=0;
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,30){
        rep(j,n) c[j]=b[j]%(1ll<<(i+1));
        sort(c,c+n);
        ll t=1ll<<i;
        ll cnt=0;
        rep(j,n){
            ll cur=a[j]%(1ll<<(i+1));
            cnt+=lower_bound(c,c+n,t*2-cur)-lower_bound(c,c+n,t-cur);
            cnt+=lower_bound(c,c+n,t*4-cur)-lower_bound(c,c+n,t*3-cur);   
        }
        if(cnt%2==1) ans+=t;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n,r;
	cin>>n>>r;
	ll arr[r],sum=0;
	for(int i=0;i<r;i++){
		cin>>arr[i];
		sum += arr[i];
	}
	if(sum>n) cout<<"-1";
	else cout<<(n-sum);
	return 0;
}

Measured memory_bytes: 3704
import java.io.*;

class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String cmd[] = br.readLine().split(" ", 0);
			int S[] = new int[100];
			for(int i=0, p=0; i<cmd.length; i++){
				if(cmd[i].equals("+")){
					p--;
					S[p-1] += S[p];
				} else if(cmd[i].equals("-")){
					p--;
					S[p-1] -= S[p];
				} else if(cmd[i].equals("*")){
					p--;
					S[p-1] *= S[p];
				} else{
					S[p] = Integer.parseInt(""+cmd[i]);
					p++;
				}
			}
			System.out.println(S[0]);
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	}
}

Measured memory_bytes: 17048
#include <stdio.h>

int main()
{

    int n, k;
    scanf("%d %d", &n,&k);
    int have[101];

    //歌詞
    int many;
    for (int i = 0; i < n; i++)
    {
      
      
            have[i] = 0; //所有0
      
    }
    int p;
    for (int i = 0; i < k; i++)
    {
        scanf("%d", &many);
        for (int j = 0; j < many;j++){
            scanf("%d", &p);
            have[p-1] = 1;//所有
        }
    }
    int count = 0;
    for (int i = 0; i < n; i++)
    {

   if(have[i] == 0)count++; //所有0
    }

    printf("%d", count);
    printf("\n");
}

Measured memory_bytes: 2132
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

struct S {
    int x,y,h;
};

void solve() {
    int n;
    cin >> n;
    vector<S> ss(n);
    REP(i,0,n) cin >> ss[i].x >> ss[i].y >> ss[i].h;
    sort(all(ss), [](auto &l, auto &r) {
        return l.h > r.h;
    });
    REP(i,0,101) REP(j,0,101) {
        int ch = ss[0].h + abs(i - ss[0].x) + abs(j - ss[0].y);
        bool b = true;
        REP(k,1,n) {
            int tmp = ss[k].h + abs(i - ss[k].x) + abs(j - ss[k].y);
            if (tmp > ch && ss[k].h == 0) continue;
            if (tmp != ch) {
                b = false;
                break;
            }
        }
        if (b) {
            cout << i << " " << j << " " << ch << endl;
            return;
        }
    }
}

int main() {
    solve();
    
    return 0;
}

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

int m, n;
int a[7], b[7];

int rec(int p, int sum) {
  if(p == m) return sum == n;
  int cnt = 0;
  for(int i = 0; i <= b[p]; ++i)
    cnt += rec(p+1,sum+a[p]*i);
  return cnt;
}

int main() {
  while(cin >> m && m) {
    for(int i = 0; i < m; ++i) cin >> a[i] >> b[i];
    int g;
    cin >> g;
    while(g--) {
      cin >> n;
      cout << rec(0,0) << endl;
    }
  }
  return 0;
}

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

    int n;
    cin >> n;

    vector<int> data;
    for (int i = 0; i<n; i++){
        int a;
        cin >> a;

        data.push_back(a);
    }

    sort(data.begin(), data.end());

    int check = 0;
    for (int i = 0; i<data.size(); ){
        int count = 1;
        if (i+1 <= n-1){
            while(data.at(i) == data.at(i+1)){
                count++;
                i++;
                if (i+1 > n-1){
                    break;
                }
            }
        }

        if (count%2 != 0){
            check++;
        }

        i++;
    }

    cout << check << endl;

}


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

int main()
{
	int x, tmp, max = 1;
	cin >> x;
	if( x == 1 )
		cout << 1;
	else{
		for(int i = 2; i*i <= x; i++)
		{
			tmp = 1;
			while( tmp <= x )
				tmp *= i;
			tmp /= i;
			if( tmp > max )
				max = tmp;
		}
		cout << max;
	}
}

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

typedef pair<int,int> P;
const int POINT = 300000;
struct Edge{int to;int cost;};
void Dijk(vector<Edge> G[],int s,int res[POINT]){
	bool vis[POINT]={0};
	fill(res,res+POINT,-3);
	priority_queue<P,vector<P>,greater<P>> que;
	P p;
	vis[s]=true;
	res[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		p = que.top();
		que.pop();
		for(Edge e:G[p.second]){
			if(!vis[e.to] || res[e.to]>res[p.second]+e.cost){
				vis[e.to]=true;
				res[e.to]=res[p.second]+e.cost;
				que.push(P(res[e.to],e.to));
			}
		}
	}
}
int main(){
	int N,M,S,T,u,v;
	int ans[POINT];
	vector<Edge> G[POINT];
	cin>>N>>M;
	for(int i=0;i<M;i++){
		cin>>u>>v;u--;v--;
		G[u].push_back({v+N,1});
		G[u+N].push_back({v+2*N,1});
		G[u+2*N].push_back({v,1});
	}
	cin>>S>>T;S--;T--;
	Dijk(G,S,ans);
	cout<<ans[T]/3;
	return 0;
}

Measured memory_bytes: 18176
package main

import "fmt"

var N, M int
var H []int
var graph []map[int]int
var done []bool
var highest []bool

func main() {
	fmt.Scan(&N, &M)
	H = make([]int, N)
	done = make([]bool, N)
	highest = make([]bool, N)
	graph = make([]map[int]int, N)

	for i := range graph {
		graph[i] = make(map[int]int)
	}

	for i := range H {
		fmt.Scan(&H[i])
	}
	var a, b int
	for i := 0; i < M; i++ {
		fmt.Scan(&a, &b)
		a--
		b--
		graph[a][b]++
		graph[b][a]++
	}

	cnt := 0
	for i := range graph {
		if search(i) {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func search(i int) bool {
	if done[i] {
		return highest[i]
	}
	h := H[i]
	for j := range graph[i] {
		if H[j] < h {
			done[j] = true
			highest[j] = false
		} else {
			done[i] = true
			highest[i] = false
		}
	}
	if !done[i] {
		done[i] = true
		highest[i] = true
	}
	return highest[i]
}


Measured memory_bytes: 30072
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    if (X > Y) {
        swap(A, B);
        swap(X, Y);
    }

    cout << X * min(A+B, 2*C) + (Y-X) * min(B, 2*C) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int x,n;

int main(){
	cin>>x>>n;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		x-=t;
	}
	if(x<0) x=-1;
	cout<<x<<endl;
}

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

int main()
{
    char n;
    scanf("%c",&n);
    if(n=='A')
        printf("T");
    if(n=='T')
        printf("A");
    if(n=='C')
        printf("G");
    if(n=='G')
        printf("C");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

char key[10][10] = {
  {},
  { 5, '.', ',', '!', '?', ' ' },
  { 3, 'a', 'b', 'c' },
  { 3, 'd', 'e', 'f' },
  { 3, 'g', 'h', 'i' },
  { 3, 'j', 'k', 'l' },
  { 3, 'm', 'n', 'o' },
  { 4, 'p', 'q', 'r', 's' },
  { 3, 't', 'u', 'v' },
  { 4, 'w', 'x', 'y', 'z' },
};

int main(void) {
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
	cin >> s;
	int k = 0, cnt = -1, d = 0;
	for (int j = 0; j < s.length(); j++) {
	  k = s[j] - '0';
	  if (k == 0) {
		if (d != 0) {
		  cout << key[d][cnt%key[d][0] + 1];
		}
		d = 0; cnt = -1;
	  }
	  else {
		d = k;
		cnt++;
	  }
	}
	cout << endl;
  }
}

Measured memory_bytes: 2984
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
for i in range(1,N+1):
    S[i] = S[i-1] + A[i-1]
ans = 0
dic = defaultdict(int)
for i in range(N+1):
    ans += dic[S[i]]
    dic[S[i]] += 1
print(ans)


Measured memory_bytes: 41684
#include<bits/stdc++.h>
#define  __  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
    __;

        int R,G,B,n,cnt=0;

        cin >> R >> G >> B >> n;

        for (int i=0;i<=3000;i++)
        {
            for(int j=0;j<=3000;j++)
            {
               if((n-(i*R)-(j*G))>=0 && ((n-(i*R)-(j*G))%B == 0)) cnt++;
            }
        }

        cout<< cnt;


    return 0;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = int(input())
    s = input()
    rR = [0] * (n + 1)
    rG = [0] * (n + 1)
    rB = [0] * (n + 1)
    
    for i in range(n - 1,-1,-1):
        if s[i] == 'R':
            rR[i] = rR[i + 1] + 1
            rG[i] = rG[i + 1]
            rB[i] = rB[i + 1]
        elif s[i] == 'B':
            rR[i] = rR[i + 1] 
            rG[i] = rG[i + 1]
            rB[i] = rB[i + 1] + 1
        else:
            rR[i] = rR[i + 1] 
            rG[i] = rG[i + 1] + 1
            rB[i] = rB[i + 1]
    
    ans = 0
    for i in range(1,n - 1):
        if s[i] == 'R':
            for j in range(i):
                if s[j] == 'B':
                    if 2 * i - j < n and s[2 * i - j] == 'G':
                        ans += rG[i + 1] - 1
                    else:
                        ans += rG[i + 1]
                elif s[j] == 'G':
                    if 2 * i - j < n and s[2 * i - j] == 'B':
                        ans += rB[i + 1] - 1
                    else:
                        ans += rB[i + 1] 
        elif s[i] == 'B':
            for j in range(i):
                if s[j] == 'R':
                    if 2 * i - j < n and s[2 * i - j] == 'G':
                        ans += rG[i + 1] - 1
                    else:
                        ans += rG[i + 1]
                elif s[j] == 'G':
                    if 2 * i - j < n and s[2 * i - j] == 'R':
                        ans += rR[i + 1] - 1
                    else:
                        ans += rR[i + 1] 
        
        elif s[i] == 'G':
            for j in range(i):
                if s[j] == 'R':
                    if 2 * i - j < n and s[2 * i - j] == 'B':
                        ans += rB[i + 1] - 1
                    else:
                        ans += rB[i + 1]
                elif s[j] == 'B':
                    if 2 * i - j < n and s[2 * i - j] == 'R':
                        ans += rR[i + 1] - 1
                    else:
                        ans += rR[i + 1] 
                        
    print(ans)

if __name__ =='__main__':
    main()  

Measured memory_bytes: 69300
from sys import setrecursionlimit


def dfs(v):
    def dfs_rec(v):
        for nv in g[v]:
            if d[nv] >= 0:
                continue
            d[nv] = d[v] + 1
            dfs_rec(nv)

    d = [-1] * N
    d[v] = 0
    dfs_rec(v)
    return d


def get_diameter():
    d = dfs(0)
    far = max((d[i], i) for i in range(N))[1]
    return max(dfs(far))


setrecursionlimit(400_000)
N, *ab = map(int, open(0).read().split())
g = [[] for _ in range(N)]
for a, b in zip(*[iter(ab)] * 2):
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

print("Second") if get_diameter() % 3 == 1 else print("First")


Measured memory_bytes: 292428
IDENTIFICATION DIVISION.
PROGRAM-ID. 160E.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1100000).
*>
WORKING-STORAGE SECTION.
01 S          PIC  X(100).
01 X          PIC  9(6).
01 Y          PIC  9(6).
01 A          PIC  9(6).
01 B          PIC  9(6).
01 C          PIC  9(6).
01 D          PIC  9(6).
01 A-TBL.
   03 PA      PIC  9(10) OCCURS 100000 DEPENDING ON A.
01 B-TBL.
   03 PB      PIC  9(10) OCCURS 100000 DEPENDING ON B.
01 C-TBL.
   03 PC      PIC  9(10) OCCURS 100000 DEPENDING ON C.
01 D-TBL.
   03 PD      PIC  9(10) OCCURS 300000 DEPENDING ON D.
01 P1         PIC  9(7) COMP.
01 P2         PIC  9(7) COMP.
01 I          PIC  9(6) COMP.
01 J          PIC  9(6) COMP.
01 K          PIC  9(6) COMP.
01 CNT        PIC  9(16) COMP.
01 OUT        PIC  Z(15)9.
*> 
PROCEDURE DIVISION.
  ACCEPT S.
  UNSTRING S DELIMITED BY ' '
      INTO X Y A B C.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > A
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO PA(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  READ STDIO.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > B
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO PB(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  READ STDIO.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > C
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO PC(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  CLOSE STDIO.
*>
  SORT PA DESCENDING KEY PA.
  SORT PB DESCENDING KEY PB.
  SORT PC DESCENDING KEY PC.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > X
    MOVE PA(I) TO PD(I)
  END-PERFORM.
  PERFORM VARYING J FROM 1 BY 1 UNTIL J > Y
    MOVE PB(J) TO PD(I)
    ADD 1 TO I
  END-PERFORM.
  PERFORM VARYING K FROM 1 BY 1 UNTIL K > C
    MOVE PC(K) TO PD(I)
    ADD 1 TO I
  END-PERFORM.
*>
  COMPUTE D = X + Y + C.
  SORT PD DESCENDING KEY PD.
*>
  MOVE 0 TO CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > X + Y
    ADD PD(I) TO CNT
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 10920