akhauriyash/Code-Regression huggingface dataset:
program travel_by_car
  implicit none
  integer(8), parameter :: inf64 = 1000000000000000000_8
  integer, parameter :: inf32 = 1000000000
  integer :: n, m, a, b, q, s, t, i, j, k
  integer(8) :: l, c
  integer(8) :: g1(300,300) = inf64
  integer :: g2(300,300) = inf32
  read(*,*) n, m, l
  do i = 1, n
    g1(i,i) = 0_8
    g2(i,i) = 0
  end do
  do i = 1, m
    read(*,*) a, b, c
    g1(a,b) = c
    g1(b,a) = c
  end do
  do k = 1, n
    do i = 1, n
      do j = 1, n
        g1(i,j) = min(g1(i,j),g1(i,k)+g1(k,j))
      end do
    end do
  end do
  do concurrent(i = 1:n, j = 1:n, i /= j)
    if (g1(i,j) <= l) g2(i,j) = 1
  end do
  do k = 1, n
    do i = 1, n
      do j = 1, n
        g2(i,j) = min(g2(i,j),g2(i,k)+g2(k,j))
      end do
    end do
  end do
  read(*,*) q
  do i = 1, q
    read(*,*) s, t
    if (g2(s,t) == inf32) then
      write(*,'(i0)') -1
    else
      write(*,'(i0)') g2(s,t)-1
    end if
  end do
end program travel_by_car

Measured memory_bytes: 1664
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define EPS 1e-6
#define pi 3.14159265358979323846
int main()
{
    fast;
    double r;
    cin>>r;
    cout<<fixed<<setprecision(20)<<(2*(pi)*r);
    
    return 0;
}

Measured memory_bytes: 3800
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 998244353;
vel kai(4001, 1);
vel ink(4001, 1);
int le = (1 << 20) + 1;
vel BIT(le, 0);
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	list = ql;
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 4000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 4001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
signed main() {
	int n, m; cin >> n >> m;
	int mn = 0, mx = n;
	rep(i, m) { int l, r; cin >> l >> r; mmax(mn, l); mmin(mx, r); }
	int ze = 0;
	cout << max(mx- mn + 1,ze) << endl;
	return 0;
}


Measured memory_bytes: 8448
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static int n;

	public static void main(String[] args) {

		Main main = new Main();

		List<Integer> list = new ArrayList<>();
		int[][] arr = main.scan();
		int candies = 0;

		int f = 0;
		for (int i = 0; i < n; i++) {
			f += arr[0][i];
			for (int j = i; j < n; j++) {
				candies += arr[1][j];
			}
			list.add(f + candies);
			candies = 0;
		}

		System.out.println(Collections.max(list));
	}

	private int[][] scan() {

		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[][] arr = new int[2][n];
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				arr[i][j] = sc.nextInt();
			}
		}
		sc.close();
		return arr;
	}
}

Measured memory_bytes: 24020
from collections import defaultdict

class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod

N, M = map(int, input().split())
com = Combinatorics(N, M)
ans = 0

# Preprocess
# calculate 2**n and 2**(2**n)
pow2 = [0] * (N*N // 4 + 1)
pow_pow2 = [0] * (N+1)
pow2[0] = 1; pow_pow2[0] = 2
for i in range(1, N*N // 4 + 1):
    pow2[i] = (pow2[i-1] * 2) % M
for i in range(1, N+1):
    pow_pow2[i] = pow(pow_pow2[i-1], 2, M)

# (#ways to order i ramens, with each of n toppings chosen at most once)
ways2 = {n: defaultdict(int) for n in range(N+1)}
for n in range(N+1):
    ways = 0 # (#ways to choose n toppings, with each topping chosen at most once)
    temp = 0
    if n >= 1:
        for i in range(n+1):
            ways2[n][i] = (ways2[n][i] +  ways2[n-1][i]) % M # n-th topping is not used
            if i >= 1: ways2[n][i] = (ways2[n][i] + ways2[n-1][i-1]) % M # only n-th topping is used in an order
            ways2[n][i] = (ways2[n][i] + (i*ways2[n-1][i]) % M) % M # n-th topping is chosen with another topping
            temp = (temp + (ways2[n][i] * pow2[(N-n)*i]) % M) % M # degree of freedom on each order is 2**(N-n)
    else: # n = 0
        ways2[n][0] = 1
        temp += ways2[n][0]
    ways = (temp * pow_pow2[N-n]) % M
    if n % 2 == 0:
        ans = (ans + (com.binom(N, n) * ways) % M) % M
    else:
        ans = (ans - (com.binom(N, n) * ways) % M) % M
print(ans)


Measured memory_bytes: 482568
from itertools import groupby

def RLE(string): #ランレングス圧縮、リストで返す
    grouped = groupby(string)
    res = []
    for k, v in grouped:
        res.append((k, (len(list(v)))))
    return res

s = input()
n = len(s)
ans = [0]*(n) #解答の配列,基本は0。'RL'のときだけ要素を変える

lst = RLE(s)
m = len(lst)//2 #操作回数
r_index = -1
for i in range(m):
    r = lst[2*i][1]
    l = lst[2*i+1][1]
    
    r_index += r
    if (r+l)%2 == 0:
        ans[r_index] = (r+l)//2
        ans[r_index+1] = (r+l)//2
    else:
        if r % 2 == 0:
            ans[r_index] = (r+l)//2
            ans[r_index+1] = (r+l)//2 + 1
        else:
            ans[r_index] = (r+l)//2 + 1
            ans[r_index+1] = (r+l)//2
    r_index += l
print(*ans)

Measured memory_bytes: 60636
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long N, X, M; cin >> N >> X >> M; 
	long long loopin = -1; 
	long long period = 0; 
	long long tmp = X; 
	long long A[114514] = {}; 
	long long S[114514] = {}; 
	A[1] = X; 
	for(int i = 2; i <= 100050; i++){
		tmp *= tmp; tmp %= M; 
		A[i] = tmp; 
	}
	for(int i = 1; i <= 100050; i++){
		S[i] = A[i] + S[i-1]; 
	}
	int exist[100010] = {}; 
	for(int i = 1; i <= 100050; i++){
		if(exist[A[i]]){
			loopin = exist[A[i]]; 
			period = i - exist[A[i]]; 
			break; 
		}
		exist[A[i]] = i; 
	}
	if(N <= M){
		cout << S[N] << "\n"; return 0; 
	}else{
		long long cycle = S[loopin + period - 1] - S[loopin - 1]; 
		long long rem = N - loopin + 1; 
		long long times = rem / period; 
		long long nokori = rem % period; 
		cout << cycle * times + S[loopin + nokori - 1] << "\n"; 
		return 0; 
	}
}

Measured memory_bytes: 5824
n,k = map(int,input().split())
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a = 1
  b = 1
  c = 1
  for i in range(1,n+1):
    a = (a*i)%p
  for i in range(1,k+1):
    b = (b*i)%p
  for i in range(1,n-k+1):
    c = (c*i)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
mod = 10**9 + 7
zeronum = min(n-1,k)
comblist1 = []
comblist2 = []
ac = 1
for i in range(1,zeronum+1):
    ac = (ac*(n-i+1)*power_func(i,mod-2,mod))%mod
    comblist1.append(ac)
ac = 1
for i in range(1,zeronum+1):
    ac = (ac*(n-i)*power_func(i,mod-2,mod))%mod
    comblist2.append(ac)

ans = 1
for zero in range(1,zeronum+1):
    count = (comblist1[zero-1]*comblist2[zero-1])%mod
    ans = (ans+count)%mod
print(ans)

Measured memory_bytes: 112732
N, M = map(int, input().split())
edges = []
for i in range(M):
    a, b, c = map(int, input().split())
    edges.append([a, b, -c])
def bellman_ford(edges, N):
    dist = [float('inf') for i in range(N)]
    dist[0] = 0
    for i in range(N-1):
        for edge in edges:
            if dist[edge[1] - 1] > dist[edge[0] - 1] + edge[2]:
                dist[edge[1] - 1] = dist[edge[0] - 1] + edge[2]
    negative = [False] * N

    for i in range(N):
        for edge in edges:
            if dist[edge[1] - 1] > dist[edge[0] - 1] + edge[2]:
                dist[edge[1] - 1] = dist[edge[0] - 1] + edge[2]
                negative[edge[1] - 1] = True
            if negative[edge[0] - 1] == True:
                negative[edge[1] - 1] =True
    
    return 'inf' if negative[-1] else -dist[-1]

print(bellman_ford(edges, N))

Measured memory_bytes: 3380
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf 1000000000000000000

using namespace std;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed;
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(3*n);
    rep(i,3*n){
        cin>>a[i];
    }
    vi s1;
    priority_queue<int> q1;
    int s=0;
    rep(i,n){
        s+=a[i];
        q1.push(-a[i]);
    }
    s1.pb(s);
    Rep(i,n,2*n){
        q1.push(-a[i]);
        int t=q1.top();
        if(t!=-a[i]){
            s=s+t+a[i];
        }
        q1.pop();
        s1.pb(s);
    }
    vi s2;
    priority_queue<int> q2;
    s=0;
    for(int i=3*n-1;i>=2*n;i--){
        s+=a[i];
        q2.push(a[i]);
    }
    s2.pb(s);
    for(int i=2*n-1;i>=n;i--){
        q2.push(a[i]);
        int t=q2.top();
        if(t!=a[i]){
            s=s-t+a[i];
        }
        q2.pop();
        s2.pb(s);
    }
    reverse(all(s2));
    int ans=-inf;
    rep(i,s1.size()){
        ans=max(ans,s1[i]-s2[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6516
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Modified: <20/Jul/2019 05:43:16 PM>


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    arr = [0] * n
    for i in range(n):
        arr[i] = int(input())
    tmp = sorted(arr)
    mx = tmp[-1]
    mx1 = tmp[-2]
    for i in range(n):
        if arr[i] == mx:
            print(mx1)
        else:
            print(mx)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()


Measured memory_bytes: 54212
function memoit(f::Function, param)
    if !isdefined(Main, :memoit_cache)
        global memoit_cache = Dict{Function, Dict{Any, Any}}()
    end
    cache = haskey(memoit_cache, f) ? memoit_cache[f] : memoit_cache[f] = Dict()
    haskey(cache, param) ? cache[param] : cache[param] = f(param)
end

macro memo(arg)
    (!(typeof(arg) <: Expr) || !(arg.head == :call)) && error("wrong atgs")
    return quote
        memoit($(esc(arg.args[1])), $(esc(arg.args[2])))
    end
end

read(T) = parse(T, readline())
reads(T) = map(x->parse(T,x),split(readline()))

function dp(n::Int)
    ret = 1000000000
    if (n == 1) ret = 0 end
    if (n > 1) ret = min(ret, ((@memo dp(n-1)) + abs(v[n] -  v[n-1]))) end
    if (n > 2) ret = min(ret, ((@memo dp(n-2)) + abs(v[n] -  v[n-2]))) end
    ret
end

function main()
    n = read(Int)
    global v = reads(Int)
    println(dp(n))
end

@inbounds main()


Measured memory_bytes: 217916
#include <stdio.h>

int main(){
	char s[200001];
	scanf("%s",s);
	int sc=0,i,ans=0,l=0;
	while(s[l]!=0)l++;
	for(i=0;i<l;i++){
		if(s[i]=='S')sc++;
		if(s[i]=='T'){
			if(sc>0){
				sc--;
				ans++;
			}
		}
	}
	printf("%d\n",l-2*ans);
	return 0;
}


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

s = input().strip()
qq = int(input())

rev = False
pre = ''
suf = ''
for _ in range(qq):
    q = input().strip()
    if q[0] == '1':
        rev = not rev
    else:
        c = q[4]
        if not rev:
            if q[2] == '1':
                pre += c
            else:
                suf += c
        else:
            if q[2] == '1':
                suf += c
            else:
                pre += c
ans = pre[::-1] + s + suf
if rev:
    ans = ans[::-1]
print(ans)


Measured memory_bytes: 224676
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,m;
  cin  >> n >> m;
  if (n == m){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
  return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int popcnt(int x){return __builtin_popcount(x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	double ans=0;
	cin>>n>>m;
	vd l(n),a(n),b(n);
	rep(i,n)cin>>l[i]>>a[i]>>b[i];
	vvd dist(n,vd(n));
	rep(i,n)range(j,i+1,n){
		double d=0;
		d+=(l[i]-l[j])*(l[i]-l[j]);
		d+=(a[i]-a[j])*(a[i]-a[j]);
		d+=(b[i]-b[j])*(b[i]-b[j]);
		dist[i][j]=dist[j][i]=d;
	}
	rep(i,1<<n){
		if(popcnt(i)!=m)continue;
		vi lis;
		rep(j,n)if((1<<j)&i)lis.push_back(j);
		double sum=0;
		rep(j,m){
			range(k,j+1,m){
				sum+=dist[lis[j]][lis[k]];
			}
		}
		chmax(ans,sum);
	}
	fcout(7)<<ans<<endl;

}


Measured memory_bytes: 3308
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
int main(){
  ll n,k,ans;cin>>n>>k;
  COMinit();
  ans=COM(2*n-1,n-1);
  if(k<n-1){
    ans=0;
    rep(i,0,k+1){
      ans+=(COM(n-1,n-i-1)*COM(n,i))%MOD;
      ans%=MOD;
    }
  }
  cout<<ans%MOD<<endl;
}



Measured memory_bytes: 12160
#https://atcoder.jp/contests/abc086/tasks/abc086_a
#入力を受け取る
a, b = map(int, input().split())
#掛け算をする
mul = a*b

#a,bの積が偶数か奇数か判定する
if mul%2 == 0:
    print("Even")
else:
    print("Odd")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    int k;
    cin >> s >> k;
    vector<string> ans;
    for(int i = 0; i < s.size(); i++){
        string now = "";
        for(int j = i; j < i+k; j++){
            if(j >= s.size())break;
            now += s[j];
            ans.push_back(now);
        }
    }
    sort(all(ans));
    ans.erase(unique(all(ans)), ans.end());
    cout << ans[k-1] << endl;
}
    

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000000

int n;
int a[MAX_N], d[MAX_N];

int main(){
	cin.sync_with_stdio(false);
	cin >> n;

	int max = 0, idx = 0;
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		if (max < a[i]) {
			max = a[i];
			idx = i;
		}
		sum += (ll)a[i];
		if (i > 0) d[i - 1] = a[i] - a[i - 1];
	}
	d[n - 1] = a[0] - a[n - 1];
	ll p = (ll)n;

	if (sum % (p*(p + 1)/2) != 0) {
		cout << "NO" << endl; 
	} else {
		int k = sum / (p*(p + 1)/2), tmp = k;
		bool ok = true;
		rep(i, n) {
			d[i] -= k;
			if (d[i] % n != 0) {
				ok = false;
				break;
			} else {
				tmp -= abs(d[i] / n);
				if (tmp < 0) {
					ok = false;
					break;
				}
			}
		}

		if (ok) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,L;cin >> N >> L;
    vector<string>  S(N);rep(i,N)cin >> S[i];

    sort(all(S));
    rep(i,N)cout << S[i];
    cout << endl;
}


Measured memory_bytes: 256
s = input()
stack = [s[0]]
now = s[0]
ans = 0
#print(stack)

for i in range(1,len(s)):
    cha = s[i]
    if cha == now:
        stack.append(cha)
        now = cha
        #print(stack)
    else:
        if now != "a":
            stack.pop()
            #print(stack)
            ans += 2
            if stack:
                now = stack[-1]
            else:
                now = "a"
        else:
            stack.append(cha)
            now = cha

print(ans)


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const double PI = 3.14159265358979;

double rad2deg(double rad) {
  return rad * 180 / PI;
}
int main() {
  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  if(x <= a * b / 2) {
    double c = x * 2 / b;
    cout << setprecision(10) << rad2deg(atan(b / c)) << endl;
  } else {
    double c = x * 2 / a - b;
    cout << setprecision(10) << rad2deg(atan((b - c) / a)) << endl;
  }
  return 0;
}



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

int main() {
	int N, a[100], count = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < N; i++) {
		if (a[i] == a[i - 1]) {
			count++;
			i++;
		}
	}
	cout << count << endl;
}

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

n,k=map(int,input().split())
L=[0]*(n+1)
und=0
top=10**5
for i in range(k):
    a,b=map(int,input().split())
    und=max(und,a)
    top=min(b,top)
print(top-und+1 if top>=und else 0)


Measured memory_bytes: 41324
import math

k = int(input()) + 1
ans = 0
for a in range(1, k):
    for b in range(a, k):
        x = math.gcd(a, b)
        for c in range(b, k):
            if a == b and b == c:
                ans += a
            elif a == b:
                ans += math.gcd(x, c) * 3
            elif b == c:
                ans += x * 3
            else:
                ans += math.gcd(x, c) * 6
print(ans)

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

l = [i for i in range(n)]
r = [i for i in range(n)]

for i in range(n):
    l[i], r[i] = map(int, input().split())

ans = 0

for i in range(n):
    ans += r[i] - l[i] + 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	sort(p.begin(), p.end());
	int ans = 0;
	for (int i = 0; i < k; i++) ans += p[i];
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
bool done[100001];
vector<vector<int>> adj;
void dfs(int node)
{
	if (done[node])
		return;
	done[node] = true;
	for (int c = 0; c < adj[node].size(); c++)
		dfs(adj[node][c]);
	return;
}
void solve()
{
	int n, m;
	cin >> n >> m;
	adj.assign(n, vector<int>());
	for (int c = 0; c < m; c++)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	memset(done, 0, sizeof(done));
	int ans = 0;
	for (int c = 0; c < n; c++)
	{
		if (!done[c])
		{
			ans++;
			dfs(c);
		}
	}
	cout << ans - 1 << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	t = 1;
	for (; t > 0; t--)
		solve();
}

Measured memory_bytes: 9228
import sys
from io import StringIO
import unittest

def resolve():
    k = int(input())
    a, b = map(int, input().split())

    ans = False

    for i in range(a, b + 1):
        if i % k == 0:
            ans = True
            break

    if ans:
        print('OK')
    else:
        print('NG')

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """7
500 600"""
        output = """OK"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
5 7"""
        output = """NG"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1
11 11"""
        output = """OK"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 16344
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	int n,ans=0;
	cin >> n;
	vector<int> v(n), c(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	for (int i = 0; i < n; i++) cin >> c[i];
	for (int i = 0; i < n; i++) {
		v[i] -= c[i];
		if (v[i] > 0) ans += v[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
 
int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    ll h[N], hMax = 0;
    for(ll i = 0; i < N; ++i){
        cin >> h[i];
        hMax = max(h[i], hMax);
    }
   
    ll ok = 1 + hMax / B, ng = 0;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        ll cnt = 0;
        for(ll i = 0; i < N; ++i){
            int diff = h[i] - B * mid;
            if(diff > 0) cnt += 1 + (diff - 1) / (A - B);
        }
        if(cnt <= mid) ok = mid;
        else ng = mid;
    }
 
    cout << ok << endl;
 
    return 0;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pi> vpi;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

/*
PROG:
LANG: C++
*/

class BCountABC {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        string str;
        in >> str;
        int res = 0;
        FOR(i, 0, n - 2) {
            if (str.substr(i, 3) == "ABC") {
                res++;
            }
        }
        out << res << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BCountABC solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip()) + "@"
cnt = 1
ans = N
for i in range(0,N):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        if cnt != 1:
            ans -= (cnt-1)
        cnt = 1
print(ans)

Measured memory_bytes: 3316
#include<iostream>

bool field[12][12];

void dfs( int x, int y )
{
	field[y][x] = false;

	static const int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 };
	for( int d = 0; d != 4; ++d )
	{
		int nx = x + dx[d], ny = y + dy[d];

		if( nx < 0 || nx >= 12 || ny < 0 || ny >= 12 || !field[ny][nx] )
			continue;

		dfs( nx, ny );
	}

	return;
}

int main()
{
	while( true )
	{
		for( int i = 0; i != 12; ++i )
		{
			for( int j = 0; j != 12; ++j )
			{
				char c;
				if( !( std::cin >> c ) )
					goto end;
				field[i][j] = c - '0';
			}
		}

		int ans = 0;
		for( int i = 0; i != 12; ++i )
		{
			for( int j = 0; j != 12; ++j )
			{
				if( field[i][j] )
				{
					dfs( j, i );
					++ans;
				}
			}
		}

		std::cout << ans << std::endl;
	}

end:;

	return 0;
}

Measured memory_bytes: 1144
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long
#define mp make_pair

mt19937 rnd(51);

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	if (s == "ABC"){
        cout << "ARC";
	}
	else{
        cout << "ABC";
	}
	return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>

static int stack[100];
static int sp;

void push(int d)
{
    stack[sp] = d;
    sp++;
}

int pop(void)
{
    int d;
    sp--;
    return stack[sp];
}

int main()
{
    char op[8];
    int op1;
    int op2;
    int value;

    sp = 0;
    while(scanf("%s", op) != EOF) {
        //fprintf(stderr, "%s\n", op);
        if(strpbrk(op, "+-/*") == NULL) {
            sscanf(op, "%d", &value);
            //fprintf(stderr, "push %d\n", value);
            push(value);
        } else {
            op1 = pop();
            op2 = pop();
            //fprintf(stderr, "%s\n", op);
            if(op[0] == '+') {
                //fprintf(stderr, "%d = %d + %d\n", op2+op1, op2, op1);
                push(op2+op1);
            } else if(op[0] == '-') {
                //fprintf(stderr, "%d = %d - %d\n", op2-op1, op2, op1);
                push(op2-op1);
            } else if(op[0] == '/') {
                //fprintf(stderr, "%d = %d / %d\n", op2/op1, op2, op1);
                push(op2/op1);
            } else if(op[0] == '*') {
                //fprintf(stderr, "%d = %d * %d\n", op2*op1, op2, op1);
                push(op2*op1);
            }
        }
    }

    printf("%d\n", pop());

    return 0;
}


Measured memory_bytes: 2100
import sys

n, *xyh = map(int, sys.stdin.read().split())
xyh = list(zip(*[iter(xyh)] * 3))

def contradict(cx, cy, ch, x, y, h):
    return max(ch - abs(x - cx) - abs(y - cy), 0) != h

def main():
    for x, y, h in xyh:
        if h: x0, y0, h0 = x, y, h; break

    for cx in range(101):
        for cy in range(101):
            ch = h0 + abs(cx - x0) + abs(cy - y0)
            for x, y, h in xyh:
                if contradict(cx, cy, ch, x, y, h): break
            else:
                print(cx, cy, ch)
                return

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3192
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ld r;
  cin >> r;
  cout << 2.0 * PI * r << endl;
  return 0;
}


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

using namespace std;

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG(x) cout << "> " << #x << ": " << x << endl;

typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
const int inf = 1e9+7;
const ll longinf = 1LL<<60;

// Start Coding...

void solve() {
    int N, M;
    cin >> N >> M;
    double sum = 0;
    vector<int> f(N);
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        sum += A;
        f[i] = A;
    }
    double cal = sum / (4 * M);
    int cnt = 0;
    bool flag = false;
    for (int i = 0; i < N; i++) {
        if (f[i] >= cal) cnt++;
        if (cnt >= M) {
            cout << "Yes" << endl;
            flag = true;
            break;
        }
    }
    if (!flag) cout << "No" << endl;
    return;
}

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

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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  int n;
  cin >> n;

  int a[n + 1];

  int cnt[2][Sz];
  memset (cnt, 0, Sz*2*4);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[i&1][a[i]]++;
  }

  int mx[2][2];
  for (int j = 0; j < 2; j++)
    mx[0][j] = mx[1][j] = (j == 0 ? 0 : (int)1e5 + 1);

  for (int i = 1; i <= n; i++) {
    int *m = mx[i&1];
    int *c = cnt[i&1];
    if (c[a[i]] > c[m[0]])
      m[1] = m[0], m[0] = a[i];
    else {
      if (a[i] != m[0] && c[m[1]] < c[a[i]])
        m[1] = a[i];
    }
  } 
  int ans = n;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      if (mx[0][i] != mx[1][j])
        ans = min (ans, n - cnt[0][mx[0][i]] - cnt[1][mx[1][j]]);
  
  cout << ans;
  return 0;
}






// Coded by Z..


Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}

bool sosu(ll p){
    bool ans = true;
    double psqrtd = pow(p, 0.5);
    ll psqrt = psqrtd;
    for(ll i = 2; i <= psqrt; i++){
        if(p%i==0)ans = false;
    }
    if(p==1)ans = false;
    return ans;
}



int main(void){
    ll n;
    cin >> n;
    ll ans = n*n*n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let () =
    let main () =
        let ar = Array.make 101 1024 in
        for i = 0 to 8 do
            Scanf.scanf " %d" (fun a -> ar.(a) <- 1 lsl i)
        done;
        let n = Scanf.scanf " %d" (fun n -> n) in
        let rec loop i map =
            if i = 0 then map else
                let b = Scanf.scanf " %d" (fun b -> b) in
                loop (i - 1) (map lor ar.(b))
        in
        let m = loop n 0 in
        let l = [
            (1 lsl 0) lor (1 lsl 1) lor (1 lsl 2) ;
            (1 lsl 3) lor (1 lsl 4) lor (1 lsl 5) ;
            (1 lsl 6) lor (1 lsl 7) lor (1 lsl 8) ;
            (1 lsl 0) lor (1 lsl 3) lor (1 lsl 6) ;
            (1 lsl 1) lor (1 lsl 4) lor (1 lsl 7) ;
            (1 lsl 2) lor (1 lsl 5) lor (1 lsl 8) ;
            (1 lsl 0) lor (1 lsl 4) lor (1 lsl 8) ;
            (1 lsl 2) lor (1 lsl 4) lor (1 lsl 6)
        ] 
        in
        print_endline (if List.exists (fun a -> a land m = a) l then "Yes" else "No")
    in
    main ()

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
  
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
  
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next next
#define sz(x) ((int)x.size())
  
template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }
  
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int mod = 1e9 + 7;
  
#define FILENAME ""
  
const ll MAXN = 1000000 + 10;   

int dp[3005][3005], pref[3005][3005];

void add_self (int& a, int b) {
	a += b;
	if (a >= mod) {
		a -= mod;
	}
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
//    freopen("symposium.in", "r", stdin);
//    freopen("symposium.out", "w", stdout);
   	int n;
   	cin >> n;
   	string s;
   	cin >> s;
   	dp[1][1] = 1;
   	for (int len = 2; len <= n; len++) {
   		for (int i = 1; i <= len - 1; i++) {
   			pref[len - 1][i] = (pref[len - 1][i - 1] + dp[len - 1][i]) % mod;
   		}
   		for (int b = 1; b <= len; b++) {
   			int l, r;
   			if (s[len - 2] == '<') {
   				l = 1;
   				r = b - 1;
   			}
   			else {
   				l = b;
   				r = len - 1;
   			}
   			if (l <= r) {
   				add_self(dp[len][b], (pref[len - 1][r] - pref[len - 1][l - 1] + mod) % mod);
   			}
   		}
   	}
   	int ans = 0;
   	for (int i = 1; i <= n; i++) {
   		add_self(ans, dp[n][i]);
   	}
   	cout << ans;
    re 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'

int main()
{
	//IOS
	
	
	int a,b;
	cin >> a >>b;
	if((a >=1 && a<=9) && (b  >= 1 && b <= 9))
	{
		cout << a*b << endl;
	}
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
dic={}
for a,b in enumerate(A):
  dic[b]=a
B=[-1]*len(A) # A[i] on cnt
cnt=0
i=0 # current town
flg=0
while True:
  if B[i] == -1:#first time
    B[i]=cnt
  elif flg == 0:#loop
    delta=cnt-B[i]
    nokori=(K-cnt) % delta # after loop
    if nokori == 0:
      break
    flg = 1
    cnt = K - nokori
    #print('loop',delta,nokori,cnt)
  i=A[i]-1
  cnt+=1
  
  #print(cnt,i,A[i])
  if cnt == K:
    break

print(i+1)

Measured memory_bytes: 39376
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vi c(2);
	rep(i, n) {
		if (s[i] == '0') c[0]++;
		else c[1]++;
	}
	int ans = min(c[0], c[1]);
	ans *= 2;
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int N=get_int();
    vector<int> v(N);
    FOR(i,N)cin>>v[i];
    sort(ALL(v));
    int c=N;
    for(int i=1;i<N;++i){
        if(v[i-1]==v[i])--c;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

llint n, m;
llint a[100005];
llint sum[100005];

bool check(llint x)
{
	llint cnt = 0;
	for(int i = 1; i <= n; i++){
		llint p = lower_bound(a+1, a+n+1, x-a[i]) - a;
		cnt += (n+1)-p;
	}
	return cnt >= m;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	
	
	llint ub = 1e11, lb = 0, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check(mid)) lb = mid;
		else ub = mid;
	}
	
	llint ans = 0, cnt = 0;
	for(int i = 1; i <= n; i++){
		llint p = upper_bound(a+1, a+n+1, lb-a[i]) - a;
		cnt += (n+1)-p;
		ans += sum[n] - sum[p-1] + ((n+1)-p) * a[i];
	}
	ans += (m-cnt) * lb;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1920