akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc137/tasks/abc137_a
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a;
	cin>>a;
	ll b;
	cin>>b;
	ll c;
	ll d;
	ll e;
	vector<ll> lis;
	c=a+b;
	d=a-b;
	e=a*b;
	lis.push_back(c);
	lis.push_back(d);
	lis.push_back(e);
	sort(lis.begin(),lis.end());
	cout<<lis[2]<<"\n";
	return 0;
}

Measured memory_bytes: 3624
using System;

namespace ABC121A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            string[] vv = Console.ReadLine().Split(' ');
            c = int.Parse(vv[0]);
            d = int.Parse(vv[1]);
            Console.WriteLine(a * b - (b * c) - (a * d) + (c * d));
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


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


def main():
    # write codes here
    N = I()
    print(math.ceil(N/2))
    return 0


# Main
if __name__ == "__main__":
    main()


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

import numpy as np

n = int(readline())
a = np.array(read().split(), np.int64)
ans = 0
mod = 10 ** 9 + 7
for i in range(63):
    b = (a >> i) & 1
    x = np.count_nonzero(b)
    y = n - x
    x *= y
    for j in range(i):
        x *= 2
        x %= mod
    ans += x
print(ans % mod)


Measured memory_bytes: 36624
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int N=4;
int mat[4][4]={};
string ans="NO";
int used[4]={};

void dfs(int c,int d)
{
	if(d==N-1)
	{
		bool ok=true;
		for(int i=0;i<N;i++)
		{
			if(used[i]==0)ok=false;
		}
		if(ok)ans="YES";
		return;
	}
	
	for(int i=0;i<N;i++)
	{
		if(mat[c][i]==1 && used[i]==0)
		{
			used[i]=1;
			dfs(i,d+1);
			used[i]=0;
		}
	}
	return;
}

int main()
{
	
	for(int i=0;i<3;i++)
	{
		int a,b;
		cin >> a >> b;
		mat[a-1][b-1]=1;
		mat[b-1][a-1]=1;
	}
	
	for(int i=0;i<N;i++)
	{
		used[i]=1;
		dfs(i,0);
	}
	cout << ans << endl;
	return 0;
}



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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n;
	ll ans = 1, mod=pow(10, 9) + 7;
	string s;
	cin >> n >> s;
	unordered_map<char, int> m;
	REP(i, 0, n) ++m[s[i]];
	
	for(auto it = m.begin(); it != m.end(); it++){
		ans *= (it->S+1);
		ans %= mod;
	}
	cout << ans-1;

}


Measured memory_bytes: 512
H, W, K = [int(i) for i in input().split()]
a = [[] for i in range(H)]
for i in range(H):
    a[i] = list(input())
counter = 0
for i in range( 2 ** H):
    for p in range( 2 ** W):
        tmp = 0
        for j in range(H):
            for q in range(W):
                if ((i >> j) & 1):
                    if ((p >> q) & 1):
                        if a[j][q] == '#':
                            tmp += 1
        if tmp == K:
            counter += 1
print(counter)

            

Measured memory_bytes: 73752
#include <iostream>
using namespace std;
int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << ((a == 1 || b == 1 || c == 1 || d == 1) &&
             (a == 9 || b == 9 || c == 9 || d == 9) &&
             (a == 7 || b == 7 || c == 7 || d == 7) &&
             (a == 4 || b == 4 || c == 4 || d == 4) ?
             "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using LP = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

int mod = 1e9+7;
const long long INF = 1LL<<60;

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

  vector<vector<ll>> dp(N+1, vector<ll>(H+1, INF));
  rep(i, N+1) rep(j, H+1) dp[i][j] = INF;

  vector<int> a(N), b(N);

  rep(i, N){
    cin >> a[i] >> b[i];
  }

  dp[0][0] = 0;
  rep(i, N){
    for(int j=0; j<=H; j++){
      int next_j = min(j+a[i], H);
      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i+1][next_j], dp[i+1][j] + b[i]);
    }
  }

  cout << dp[N][H] << endl;

  return 0;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	char N[200010];
  	cin >> N;
  	int n = strlen(N);
  	int sum = 0;
  	for(int i = 0; i<n; i++){
     sum += N[i] - '0';
    }
  sum %= 9;
  if(sum == 0) cout << "Yes" << endl;
  if(sum != 0) cout << "No" << endl;
}

Measured memory_bytes: 3824
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  [n, m] <- readInts
  edges <- replicateM m $ do
    [a, b] <- readInts
    return (a-1, b-1)
  let graph = createGraph n edges
  print $ solve n graph

type Graph = [[Int]]

createGraph :: Int -> [(Int, Int)] -> Graph
createGraph n edges = foldr addUEdge (replicate n []) edges
  where addEdge i v graph = concat [take i graph, [v : (graph !! i)], drop (i+1) graph]
        addUEdge (a, b) = addEdge a b . addEdge b a

solve :: Int -> Graph -> Int
solve n graph = dfs 0 1 [0]
  where dfs i depth visited
          | depth == n = 1
        dfs i depth visited
          | nexts == [] = 0
          | otherwise = sum $ flip map nexts $ \w -> dfs w (depth+1) (w:visited)
            where nexts = filter (not . (`elem` visited)) $ graph !! i

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	if(t.length()-s.length()!=1){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main() {
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < 111; i++) {
		s = s.substr(1) + s[0];
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

using namespace std;
int main(){
    long long a,b,c,k,ans;
    cin>>a>>b>>c>>k;
    if(k%2)ans=b-a;
    else ans=a-b;


    if(a-b<=1e18 && a-b>=-1e18)
    cout << ans << endl;
    else
        cout << "Unfair\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#define int long long
#define ld double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define sz(x) ((long long)x.size())
#define all(x) (x).begin(), (x).end()
#define popcount(x) __builtin_popcountll(x)
const int MOD =1e9+7;

mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> istream& operator >> (istream &in,vector<T> &A){ for(auto &x:A) in>>x; return in; };
template<typename T> ostream& operator << (ostream &out,vector<T> &A){ for(auto &x:A) out<<x<<" "; return out; };
template<typename T,typename W> istream& operator >> (istream &in,pair<T,W> &A){ in>>A.fi>>A.se; return in; };
const int N = 5*1e6+10;

void solve()
{	
	int n;
	cin>>n;
	cout<<(((n+1000-1)/1000)*1000)-n;
}

int32_t main(){
	cin.tie(0)->sync_with_stdio(0);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	#endif
	int t=1;
	// cin>>t;
	for(int _t=1;_t<=t;_t++){
		// cout<<"Case #"<<_t<<": ";
		solve();
	}
} 


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
int from[4];
int to[4];

ll hoge(string S) {
	vector<int> V;
	V.push_back(0);
	FORR(c,S) {
		if(c=='0') V.push_back(0);
		else V.back()++;
	}
	
	ZERO(from);
	for(int i=1;i<V.size();i++) {
		
		// 0-none 1-left 2-right 3-keep
		if(V[i]==1) {
			to[0]=max({from[0],from[1]+V[i-1]-1,from[2]+1,from[3]+V[i-1]});
			to[1]=max({from[0],from[1]+V[i-1]-1,from[3]+V[i-1]});
			to[2]=max({from[0],from[1],from[2],from[3]});
		}
		else {
			to[0]=max({from[0],from[1]+V[i-1]-1,from[2]+V[i]});
			to[1]=max({from[0],from[1]+V[i-1]-1,from[3]+V[i-1]});
			to[2]=max({from[0],from[1]+V[i-1]-1,from[2]+V[i]-1,from[3]+V[i-1]});
		}
		to[3]=max({from[0],from[1],from[2],from[3]});
		
		
		swap(from,to);
	}
	int ret=max({from[0],from[1],from[2],from[3]});
	//cout<<S<<" "<<ret<<endl;
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	N+=2;
	S+="00";
	ll ret=0;
	FOR(i,N) {
		if(S[i]=='0') continue;
		for(j=i+1;j<N;j++) {
			if(S[j]=='0' && S[j+1]=='0') {
				ret+=hoge(S.substr(i,j-i));
				i=j+1;
				break;
			}
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}
const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n,m;cin>>n>>m;
	
	if(n ==m){
		writeln("Yes");
	}else {
		writeln("No");
	}
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef long long ll;

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

map<char, char> map_work = {
    {'o', true},
    {'x', false},
};

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n, k, c;
    cin >> n >> k >> c;
    vector<char> can_work(n);
    rep(day, n)
    {
        char c;
        cin >> c;
        can_work[day] = map_work[c];
    }

    vector<int> day_front(k), day_back(k);
    for (int day = 0, num_chosen_days = 0; num_chosen_days < k; day++)
    {
        if (can_work[day])
        {
            day_front[num_chosen_days] = day;
            num_chosen_days++;
            day += c;
        }
    }
    for (int day = n - 1, num_chosen_days = 0; num_chosen_days < k; day--)
    {
        if (can_work[day])
        {
            day_back[k - 1 - num_chosen_days] = day;
            num_chosen_days++;
            day -= c;
        }
    }

    rep(i, k)
    {
        if (day_front[i] == day_back[i])
        {
            cout << day_front[i] + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4916
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final long MOD = 1000000007;
		int N = sc.nextInt();
		int[] x = new int[N];
		for(int i=0; i<N; i++)
			x[i] = sc.nextInt();
		
		long ans = 1;
		int num = 0;
		for(int i=0; i<N; i++) {
			if(i<N-1) {
				int next = num*2+1;
				if(next <= x[i])
					num++;
				else
					ans = (ans * (num + 1))%MOD;
			} else {
				for(int j=num+1; j>=1; j--)
					ans = (ans * j)%MOD;
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 50436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
using namespace std;


int main() {
	string s;
	cin >> s;
	string ans = (( s == "ABC") ? "ARC":"ABC");
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    vector<double> v;
    rep(i,n){
        double a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    double sum = (v[0] + v[1])/2.0;
    for(int i = 2;i < n;i++){
        sum = (sum + v[i])/2.0;
    }
    P(sum);
}

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


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

struct event{
    int type;//1:Y????????????????????? 0:X????????????????????????????§? 2:??????
    int x1,y1,x2,y2;
    event(int type, int x1, int y1, int x2, int y2){
        this->type=type, this->x1=x1, this->y1=y1, this->x2=x2, this->y2=y2;
    }
    bool operator<(const event&b) const{
        if(type!=b.type){
            return type<b.type;
        }else{
            return y1==b.y1?y2<b.y2:y1<b.y1;
        }
    }
    bool operator>(const event&b) const{
        if(type!=b.type){
            return type>b.type;
        }else{
            return y1==b.y1?y2>b.y2:y1>b.y1;
        }
    }
};

int main(){
    int n,x1,x2,y1,y2;
    cin >> n;
    vector<pair<int,event>> E;//<x??§?¨?,event>
    while(n--){
        cin >> x1 >> y1 >> x2 >> y2;
        if(y1==y2){//x????????????
            if(x1<x2){
                E.push_back(pair<int,event>(x1,event(0,x1,y1,x2,y2)));
                E.push_back(pair<int,event>(x2,event(2,x1,y1,x2,y2)));
            }else{
                E.push_back(pair<int,event>(x2,event(0,x1,y1,x2,y2)));
                E.push_back(pair<int,event>(x1,event(2,x1,y1,x2,y2)));
            }
        }else{//y????????????
            if(y1<y2){
                E.push_back(pair<int,event>(x1,event(1,x1,y1,x2,y2)));
            }else{
                E.push_back(pair<int,event>(x1,event(1,x2,y2,x1,y1)));
            }
        }
    }
    sort(E.begin(),E.end());
    map<int,int> M;
    int c=0;
    for(auto i : E){
        switch(i.second.type){
            case 1:
                for(auto ite=M.lower_bound(i.second.y1);ite!=M.upper_bound(i.second.y2);++ite) c++; 
                break;
            case 0:
                M[i.second.y1]=1;
                break;
            case 2:
                M.erase(i.second.y1);
                break;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 10216
MOD = 998244353
n, k = map(int, input().split())
l, r = [0]*k, [0]*k
for i in range(k):
    _l, _r = map(int, input().split())
    l[i], r[i] = _l, _r
dp, dpsum = [0]*(n+1), [0]*(n+1)
dp[1], dpsum[1] = 1, 1
for i in range(2, n+1):
    for j in range(k):
        li = i - r[j]
        ri = i - l[j]
        if ri<0: continue
        li = max(li, 1)
        dp[i] += dpsum[ri] - dpsum[li-1]
        dp[i] %= MOD
    dpsum[i] = dpsum[i-1] + dp[i]
print(dp[n])


Measured memory_bytes: 76768
#include <bits/stdc++.h>
#define INF 990000000

using namespace std;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int main() {
    // 頂点数と辺数
    int n,m; 
cin >>n>>m;

int s[m];
int c[m];

int mini=10000000;
int flag=1;

int beg=1;
for(int i=0;i<n-1;i++)beg*=10;
int end=beg*10-1;

if(n==1){

beg=0;
end=9;
}

//cout << beg<<"--"<<end<<"\n";

for(int i=0;i<m;i++){
cin>>s[i]>>c[i];

}

for(int i=beg;i<=end;i++){
string str=to_string(i);
//cout << str << "\n";
flag=1;
for(int j=0;j<m;j++){
//cout << str[(s[j])-1]<<"---"<< c[j][0] <<"\n";
if(ctoi(str[(s[j])-1])!=c[j]){
flag=0;
}
//cout << "================"<<flag<<endl;
}

if(flag==1){
mini=min(mini,i);

}

flag=1;
}

if(mini==10000000)
cout << -1;
else
cout << mini;

}


Measured memory_bytes: 256
#include <iostream>

int main() {
	signed int a, b;

	std::cin >> a;	
	std::cin >> b;	

	signed int add = a+b;
	signed int sub = a-b;
	signed int mul = a*b;
	signed int max;

	if (add >= sub) {
		max = add;
	} else {
		max = sub;
	}

	if (mul >= max) {
		max = mul;
	}

	std::cout << max << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    string s;
    string t;
    cin >> s >> t;
    vector<ll> alph[26];
    rep(i, s.size()) alph[s[i]-'a'].push_back(i);

    ll idx = -1; // s中のどの文字を使ったか
    ll d = 0; // 繰り返し数
    rep(i, t.size()){
        char c = t[i];
        if (alph[c-'a'].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        else if (idx >= alph[c-'a'].back()){
            idx = alph[c-'a'][0];
            d++;
        }
        else {
            ll nxt = *upper_bound(alph[c-'a'].begin(), alph[c-'a'].end(), idx);
            idx = nxt;
        }
        // cout << idx << " " << d << endl;
    }

    cout << ll(s.size()) * d + idx + 1 << endl;

    return 0;
}


Measured memory_bytes: 4628
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

int main() {
	ll N;
	cin >> N;
	string S;
	cin >> S;

	vector<ll> D(N + 1,0), M(N + 1,0), C(N + 1,0);

	repn(i, N) {
		D[i] = D[i - 1];
		if (S[i - 1] == 'D') { D[i]++; }

		M[i] = M[i - 1];
		if (S[i - 1] == 'M') { M[i]++; }

		C[i] = C[i - 1];
		if (S[i - 1] == 'C') { C[i]++; }
	}

	ll Q;
	cin >> Q;

	rep(x, Q) {
		ll K;
		cin >> K;

		ll ans = 0;

		rep(i, N) {
			if (S[i] == 'C') {
				ans += M[i] * (D[i] - D[max(0, i - K + 1)]);
			}

			if (S[i] == 'D') {
				ans -= M[i] * (C[min(N, i + K)] - C[i + 1]);
			}
		}

		cout << ans<<endl;
	}
	system("PAUSE");
}


Measured memory_bytes: 25084
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int ans = 0;
            ans = line1.First() + line2.Sum();
            int temp = ans;
            for(int i = 1; i < n; i++)
            {
                temp = temp + line1[i] - line2[i - 1];
                ans = Math.Max(ans, temp);
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        System.out.println((R < 1200)?"ABC":(R<2800)?"ARC":"AGC");
        sc.close();
    }
}

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

int main(){
    int f,i,g,j,k,l,n,a,b,c,d,e;
    int score,ed;

    while(1){
        vector< vector<int> > bd(5);
        score=0;
        cin >> n;
        if(!n){break;}
        for(i=0;i<n;i++){
            cin>>a>>b>>c>>d>>e;
            bd[0].push_back(a);
            bd[1].push_back(b);
            bd[2].push_back(c);
            bd[3].push_back(d);
            bd[4].push_back(e);
        }
        
        ed=1;
        while(ed){
            ed=0;
            for(i=0;i<5;i++){
                reverse(bd[i].begin(),bd[i].end());
            }
            
            for(g=0;g<n;g++){
                for(i=0;i<3;i++){ //start
                    if(!bd[i][g]){continue;}
                    for(j=4;j>=2;j--){ //width
                        if((i+j)>4){continue;}
                        if(!bd[i+j][g]){continue;}
                        f=1;
                        for(k=i;k<=i+j;k++){
                            if(bd[k][g]!=bd[i][g]){f=0;break;}
                        }
                        if(f){
                            ed=1;
                            for(k=i;k<=j+i;k++){
                                if(bd[k][g]!=-1){
                                    score+=bd[k][g];
                                    bd[k][g]=-1;
                                }
                            }
                        }
                    }
                }
            }

            for(i=0;i<5;i++){
                while(1){
                    auto q=find(bd[i].begin(),bd[i].end(),-1);
                    if(q!=bd[i].end()){bd[i].erase(q);bd[i].push_back(0);}
                    else{break;}
                }
                reverse(bd[i].begin(),bd[i].end());
            }
        }
        cout<<score<<endl;
        bd.clear();
        bd.shrink_to_fit();
    }
    return 0;
}




Measured memory_bytes: 3056
N,K=map(int,input().split())
dp=[[[0]*3 for j in range(2)] for i in range(N+1)]
#dp[i][j][k] iコメまででj+1回連続でkを食べる組み合わせ
G=[-1]*(N+1)
INF=10000
for i in range(K):
    a,b=map(int,input().split())
    b-=1
    G[a]=b
if G[1]!=-1:
    dp[1][0][G[1]]=1
else:
    dp[1][0][0]=dp[1][0][1]=dp[1][0][2]=1
for i in range(2,N+1):
    if G[i]!=-1:
        dp[i][0][G[i]]=(dp[i-1][0][(G[i]+1)%3]+dp[i-1][0][(G[i]+2)%3]+dp[i-1][1][(G[i]+1)%3]+dp[i-1][1][(G[i]+2)%3])%INF
        dp[i][1][(G[i])]=(dp[i-1][0][(G[i])])%INF
        continue
    for k in range(3):
        dp[i][0][k]=(dp[i-1][0][(k+1)%3]+dp[i-1][0][(k+2)%3]+dp[i-1][1][(k+1)%3]+dp[i-1][1][(k+2)%3])%INF
        dp[i][1][k]=(dp[i-1][0][k])%INF
ans=0
for j in range(2):
    for k in range(3):
        ans+=dp[N][j][k]
        ans%=INF
print(ans)



Measured memory_bytes: 5640
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(3*N);
    REP(i, 3*N)cin >> a[i];
    sort(ALL(a));
    reverse(ALL(a));
    LL res = 0;
    REP(i, N){
        res += a[2*i+1];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		int n = getInt(sc);
		String s = getString(sc);
		String[] sa = s.split("");
		int max = 0;
		int score = 0;
		for (int i = 0; i < n; i++) {
			if (sa[i].equals("I")) {
				score += 1;
			} else {
				score -= 1;
			}

			if (max < score) {
				max = score;
			}
		}

		System.out.println(max);
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	long x;
	long tmpCoins;

	public Status(long x, long tmpCoins) {
		this.x = x;
		this.tmpCoins = tmpCoins;
	}
}


Measured memory_bytes: 21712
mod = 10 ** 9 + 7

n, k = gets.split.map(&:to_i)

a = [1] * (k+1)
# b = Array.new(k+1){|i| i }

ans = 0
(k/2).downto(1) do |i|
  cnt = ( k/i ).pow( n, mod )
  
  j = i * 2
  while j <= k
    cnt = ( cnt - a[j] ) % mod
    j += i
  end
  
  a[i] = cnt
  ans += i * cnt % mod
  # ans %= mod if ans >= mod
end

puts (ans + (k-k/2) * ( k + k/2+1) / 2 ) % mod

Measured memory_bytes: 15124
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

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

    vector<double> x(N), y(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i] >> y[i];
    }

    vector<int> ans(N);
    constexpr int times = 1000000;
    double t = M_PI * 2 / times;
    for(int i = 0; i < times; ++i){
        double m = cos(i * t) * x[0] + sin(i * t) * y[0];
        int num = 0;
        for(int j = 0; j < N; ++j){
            double mj = cos(i * t) * x[j] + sin(i * t) * y[j];
            if(m < mj){
                m = mj;
                num = j;
            }
        }
        ans[num]++;
    }

    for(int i = 0; i < N; ++i){
        cout << fixed << std::setprecision(10) <<  double(ans[i] / double(times)) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int A, B;
  cin >> A >> B;
  if(A == 1) A = 14;
  if(B == 1) B = 14;
  
  if(A > B) cout << "Alice" << endl;
  else if(B > A) cout << "Bob" << endl;
  else cout << "Draw" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
import sys
N = int(input())
X = [int(_) for _ in input().split()]
ans_list = []
if N == 1:
    print('0')
    sys.exit()
for i in range(min(X), max(X) + 1):
    ans = 0
    for j in X:
        ans += (j - i) ** 2
    ans_list.append(ans)

print(min(ans_list))


Measured memory_bytes: 3060
N,X,Y = map(int,input().split())
D= [0]*(N-1)
for i in range(1,N+1):
    for j in range(i+1,N+1): # i<j
        d = min(j-i,abs(X-i)+abs(Y-j)+1)
        D[d-1] += 1
for d in D:
    print(d)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int mod7=1e9+7;
const int mod9=1e9+9;
const int inf=1<<30;
const ll INF=1LL<<60;
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):abs(a);}
template<typename T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename A,size_t N,typename T> void Fill(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}

int main(){
    int n;cin>>n;
    rep(i,n+1)if(i*108/100==n){cout<<i<<endl;return 0;}
    cout<<":("<<endl;
}

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

int main(){
  ll a, b;
  cin >> a >> b;
  --a;
  ll ans = 0;
  for(ll i=(a/4)*4; i<=a; ++i){
    ans ^= i;
  }
  for(ll i=(b/4)*4; i<=b; ++i){
    ans ^= i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#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()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int a,b;
	cin >> a >> b;
	cout<<max(0,a-b*2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

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

int main(void){
  LL a, b;
  cin >> a >> b;

  if (a > 0) cout << "Positive" << endl;
  else if (a <=0 && 0 <= b) cout << "Zero" << endl;
  else {
    LL number = b - a + 1;
    if (number % 2 == 0) cout << "Positive" << endl;
    else cout << "Negative" << endl;
  }

  return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
  int n;
  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  int ans = 0;
  vi dp(n+1);
  rep(i, 0, n){
    dp[a[i]] = dp[a[i]-1] + 1;
    chmax(ans, dp[a[i]]);
  }

  cout << n-ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++)
    {
        int x = i * 111;
        if (x >= n){
            cout << x << endl;
            return 0;
        }
    }
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ; 
ll _abs (ll x ) { return (x>0?x:-x); }

const int N = 105 , MV = 1e5+5; 
int n , W , v[N] , w[N] ,V; 
ll dp[N][MV] ; // max value at index i with weight
int main(){
    fastio; 
    cin>>n>>W; 
    for(int i = 0 ; i < n ;i++ ){
        cin>>w[i]>>v[i] ; 
        V += v[i] ; 
    }
    ll ans = 0 ;
    for(int i = 0 ; i <= V ; i++ )dp[0][i]=2e9;  
    dp[0][0]=0;
    for(int i = 1 ; i <= n ; i++ ){
        for(int j = 1 ; j <= V ; j++ ){
            ll& r = dp[i][j] ; 
            r = 2e9 ;  
            r = min ( r , dp[i-1][j]); 
            if( j - v[i-1] >= 0 )r = min(r,dp[i-1][j-v[i-1]]+w[i-1]); 
            if( r <= W )ans = max ( ans , (ll)j ) ;
      //      cout<<i<<" "<<j<<" "<<r<<endl; 
        }
    }
    cout<<ans<<endl; 
}

Measured memory_bytes: 80128
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int N = str.length();
        String ans = "";
        
        for(int i=0; i<N; i++){
            if(str.charAt(i) == '0'){
                ans += '0';
                //System.out.println("0:"+ans);
            }else if(str.charAt(i) == '1'){
                ans += '1';
                //System.out.println("1:"+ans);
            }else{
                if(ans.length() != 0){
                    ans = ans.substring(0,ans.length()-1);
                }
                //System.out.println(ans.length()+":"+ans);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 38468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.Integer.parseInt;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        int t = parseInt(read.readLine());
        int ac =0,wa=0,tle=0,re=0;
        for (int i = 0;i<t;i++){
            String S = read.readLine();
            if (S.contains("AC")){
                ac++;
            }
            else if (S.contains("WA")){
                wa++;
            }
            else if (S.contains("TLE")){
                tle++;
            }
            else if (S.contains("RE")){
                re++;
            }
        }
        System.out.println("AC x "+ac+"\nWA x "+wa+"\nTLE x "+tle+"\nRE x "+re);
    }
}


Measured memory_bytes: 43788
#include <bits/stdc++.h>
using namespace std;
#define LL long int

int main(){
    int n,q;
    cin >> n >> q;
    vector<vector<int> > pas(n);

    vector<int> counter(n,0);

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

    for(int i = 0; i < q; ++i){
        int p,x;
        cin >> p >> x;
        counter[--p] += x;
    }

    queue<int> que;

    que.push(0);

    vector<bool> flag(n,false);

    while(!que.empty()){
        int v = que.front();
        que.pop();
        flag[v] = true;

        for(int i = 0; i < pas[v].size(); ++i){
            if(flag[pas[v][i]]) continue;
            counter[pas[v][i]] += counter[v];
            que.push(pas[v][i]);
        }
    }

    for(int i = 0; i < n; ++i){
        cout << counter[i] << " ";
    }

    cout << endl;

    return 0;
}


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

int main(){
	int h, w;
	cin >> h >> w;
	char a[h][w];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> a[i][j];
		}
	}

	for(int i=0; i<h+2; i++){
		for(int j=0; j<w+2; j++){
			if(i == 0 || j ==0 || i == h+1 || j == w+1) cout << "#";
			else cout << a[i-1][j-1];
		}
		cout << endl;
	}

	return 0;
}

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)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a;
    cin>>a;
    n-=a;
  }
  if(n<0)n=-1;
  cout<<n<<endl;
  return(0);
}


Measured memory_bytes: 3596
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 
const ll inf=1e18+1e17;
const ll mod =1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=	(a*a)%mod;b>>=1;}return (res%mod);}

const int N=2e5+5;
void solve(){
	ll n;
	cin>>n;
	ll x;
	cin>>x;
	ll p=x;
	ll ans=0;
	ans+=p;
	ll tt=n-x;
	while ( true){
		if (p%tt==0){
			ans+=p*2;
			break;
		}
		else{
			ll val=p/tt;
			ll x=p-val*tt;
			val=val*2+1;
			ans+=tt*val;
			p=tt-x;
			tt=x;
			ans+=tt;
		}
	}
	cout<<ans<<'\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
}

Measured memory_bytes: 3652
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};

int main()
{
    string s;
    int K;
    cin >> s >> K;
    set<string> S;
    REP(i, s.size())
    {
        for (int j = 1; j <= 5; ++j)
        {
            S.insert(s.substr(i, min(j, (int)s.size() - i)));
        }
    }
    int k = 0;
    for (const auto& str : S)
    {
        ++k;
        if (k == K)
        {
            cout << str << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1664
function setUp(input) {
  input = input.split("\n");
  tmp = input[0].split(" ");
  A = Number(tmp[0]);
  B = Number(tmp[1]);
  T = Number(tmp[2]);
  main();
}
function main() {
  var time = Math.floor(T / A);

  console.log(time * B);
}

setUp(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piiii pair<pii,pii>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define logg2 0.30102999566398119521373889472449L
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;


vector<int> adj2[maxn+1];
int nex_node[maxn+1];
int red[maxn+1],ball[maxn+1];
int x,y;
void solve(){
    int n,m;cin>>n>>m;
    red[1]=1;ball[1]=1;
    for(int i=2;i<=n;i++) {red[i]=0;ball[i]=1;}
    while(m--){
        cin>>x>>y;
        if(red[x]==0){
            ball[x]--;
            ball[y]++;
        }
        else if(red[x]==1 && ball[x]==1){
            red[x]=ball[x]=0;
            red[y]=1;ball[y]++;
        }
        else{
            red[y]=1;ball[y]++;
            ball[x]--;
        }


    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(red[i]) cnt++;
    }
    cout<<cnt;
    return;
}
int main(){
    IO

    //TEST
    solve();
    return(0);
}


Measured memory_bytes: 6700
N = [int(input()) for i in range(5)] 
list_sho = []
list_amari = []

for i in range(len(N)):
  list_sho.append(N[i]//10)
  list_amari.append(N[i]%10)
  
min1 = list_amari.index(min(list_amari))#あまりが最小になるうち一つの位置を取得
sum1 = 0

for i in range(len(N)):
  if N[i] % 10 == 0:
    sum1 += N[i]
  else:
    sum1 += ((N[i]//10) + 1) * 10

if N[min1]%10 == 0:
  while min(list_amari) == 0:
    list_amari.remove(0)
    if len(list_amari) == 0:
      break
  if len(list_amari) == 0:
    sum1 =  sum1
  else:
    sum1 =  sum1 - 10 +  min(list_amari)
  print(sum1)
else:
  sum1 = sum1 - 10 +  N[min1]%10
  print(sum1)

Measured memory_bytes: 3064
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define swap(a,b) (a+=b,b=a-b,a-=b)
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void AscRadix32(int *a,const int sz,const int minus)
{
  /*http://users.encs.concordia.ca/~chvatal/notes/rsort.html*/
  int x,shift=0,elem[256],temp[sz];
  while(shift<32)
  {
    int bucket[256]={0};rep(i,sz){x=(a[i]>>shift)&255;bucket[x]++;temp[i]=a[i];}
    elem[0]=0;rep(i,255)elem[i+1]=elem[i]+bucket[i];
    rep(i,sz){x=(temp[i]>>shift)&255;a[elem[x]]=temp[i];elem[x]++;}
    shift+=8;
  }
  rep(i,minus/2)swap(a[sz-minus+i],a[sz-1-i]);
  rep(i,(sz-minus)/2)swap(a[i],a[sz-minus-1-i]);
  rep(i,sz/2)swap(a[i],a[sz-1-i]);
}
int main(void)
{
  int N=IN(),c=CH(),i=0,m=0,p=0,z=0,temp,A[N];
  long K=0,low=-1e18,mid,high=-low,count;while(c>47&&c<58){K=K*10+c-48,c=CH();}
  rep(j,N){A[j]=IN();if(A[j]<0)m++;else if(A[j]>0)p++;else z++;}
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;else temp=0;
  AscRadix32(A,N,m);
  if(K<=1l*m*p)high=1l;else low=-1l;
  while(high-low>1)
  {
    mid=(low+high)/2,count=0;
    if(!mid)count=1l*m*p;
    else if(mid>0)
    {
      count=1l*m*p+1l*z*(m+p)+1l*z*(z-1)/2;temp=N-1;i=m+z;if(count>=K){high=mid;continue;}
      while(i<N){while(1l*A[temp]*A[i]>=mid){temp--;}if(temp>i)count+=1l*temp-i,i++;else break;}
      temp=0;i=m-1;if(count>=K){high=mid;continue;}
      while(i>=0){while(1l*A[temp]*A[i]>=mid){temp++;}if(temp<i)count+=1l*i-temp,i--;else break;}
    }
    else{temp=m-1;i=N-1;while(i>=m+z){while(temp>=0&&1l*A[temp]*A[i]>=mid){temp--;}if(temp>=0){count+=1l*temp+1;}i--;}}
    if(count<K)low=mid;else high=mid;
  }
  return OUT(low),0;
}

Measured memory_bytes: 3124
_, M = map(int,input().split())
A = list(map(int,input().split()))
sum_A = sum(A)
count = 0
result = "No"
for i in A:
    if i >= sum_A * 1/(4*M):
        count += 1
    if count == M:
        result = "Yes"
        break
print(result)

Measured memory_bytes: 38384
R,G,B,N = map(int, input().split())

cnt = 0
for i in range(N//R+1):
    for j in range((N-R*i)//G+1):
#         print(N-R*i-G*j)
        if (N-R*i-G*j) % B == 0:
#             print(i,j)

            cnt += 1
    
print(cnt)

Measured memory_bytes: 40432
#include<iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int N,K,cnt = 0 ;
    cin>>N>>K;
 int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a,a+N);

       for(int i = 0;i<K;i++){cnt=cnt+a[i];}
       cout << cnt ;

return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define fr(i,n) for(i = 0; i <n; i++)
#define rep(i,n) for(i = 1; i <= n; i++)
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
    fastinput;
    LL n,i,j,k,t,temp,tc;
    LL jane;
    cin>>n;
    if(n>=30)
    {
        cout<<"Yes";
    }
    else
    {
         cout<<"No";
    }
    
    
    return 0;
}

Measured memory_bytes: 3688