akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define N 200010
int a[N];
int st[1000010];
int main()
{
    int n;std::cin >> n;
    for(int i = 0;i < n;i++)
    {
        scanf("%d",&a[i]);st[a[i]] ++;
    }
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        int flag = 0;
        st[a[i]]--;
        for(int t = 1;t * t <= a[i];t++)
        {
            if(a[i] % t != 0)continue;
            if(st[t] || st[a[i]/t])
            {
                flag = 1;break;
            }
        }
        if(!flag)ans++;
        st[a[i]]++;
    }
    std::cout << ans;
    return 0;
}

Measured memory_bytes: 8340
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string C;
    cin >> C;
    for (int j = 0; j < 2; j++) {cout << C << endl;}
  }
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
using namespace std;
int main(){
    long long A,B,K;
    cin>>A>>B>>K;
    if(A>K){
        cout<<A-K<<" "<<B<<endl;
        return 0;
    }
    if(A+B<K){
        cout<<0<<" "<<0<<endl;
        return 0;
    }
    cout<<0<<" "<<A+B-K<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import math


def minu_int(i):
    return -1*int(i)


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


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


N = z()
A = zz()

A = sorted(A, reverse=True)
if (N == 2):
    print(max(A))
    exit()
elif (N == 3):
    print(sum(A[:2]))
    exit()
else:
    ans = A[0]
    index = 1
    for i in range(1, N-1):
        # print(A[index])
        ans += A[index]
        if (i % 2 == 0):
            index += 1
    print(ans)


Measured memory_bytes: 49536
N = int(input())
A = [[0]*N for _ in range(N)]

for _ in range(N):
    l = list(map(int, input().split()))
    u, k = l.pop(0), l.pop(0)
    
    row = A[u-1]
    for x in l:
        row[x-1] = 1

for row in A:
    print(*row)


Measured memory_bytes: 6380
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  if (x < b - a) cout << "dangerous" << endl;
  else if (b > a) cout << "safe" <<endl;
  else cout << "delicious" << endl;

  return 0;
}


Measured memory_bytes: 3644
#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;

#ifdef LOCAL
  #define debug_echo(e) cin << "L" << __LINE__ << ": " << e
  #define debug_repr(e) cin << "L" << __LINE__ << ": " << #e << " = " << e
#else
  #define debug_echo(e)
  #define debug_repr(e)
#endif

char S[52][52];

int main() {
  int H, W; cin >> H >> W;
  rep (i, H) rep (j, W) cin >> S[i+1][j+1];

  rep (i, H) {
    rep (j, W) {
      if (S[i+1][j+1] == '.') {
        char cnt = '0';
        if (S[i][j] == '#') cnt++;
        if (S[i+1][j] == '#') cnt++;
        if (S[i+2][j] == '#') cnt++;
        if (S[i][j+1] == '#') cnt++;
        if (S[i+2][j+1] == '#') cnt++;
        if (S[i][j+2] == '#') cnt++;
        if (S[i+1][j+2] == '#') cnt++;
        if (S[i+2][j+2] == '#') cnt++;
        S[i+1][j+1] = cnt;
      }
    }
  }

  rep (i, H) {
    rep (j, W) {
      cout << S[i+1][j+1];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
def ALDS1_4C():
    D = {}
    for i in range(int(input())):
        cmd, key = input().split()
        if cmd == 'insert':
            D[key]='yes'
        else:
            print(D.get(key, 'no'))

if __name__ == '__main__':
    ALDS1_4C()

Measured memory_bytes: 37440
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int D;
    cin >> D;
    
    int x, y;
    cin >> x;

    vector<int> v, w;
    for(int i = 0; i < x; ++i){
        string s;
        int tmp;
        cin >> s >> tmp;
        if(s == "D"){
            v.push_back(tmp);
        }
    }

    cin >> y;
    for(int i = 0; i < y; ++i){
        string s;
        int tmp;
        cin >> s >> tmp;
        if(s ==  "DD"){
            w.push_back(tmp);
        }
    }

    //cout << "hoge" << endl;
    sort(v.begin(), v.end(), greater<int>());
    sort(w.begin(), w.end(), greater<int>());
    int ans = 0;
    for(int i = 0; i <= D; ++i){
        int sum = 0;
        for(int j = 0; j < i && j < v.size(); ++j){
            sum += v[j];
        }
        int res = (D - i) / 2;
        for(int j = 0; j < res && j < w.size(); ++j){
            sum += w[j];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define UNVISITED -1
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
using namespace std;

typedef long long int64;
typedef pair<int, int> ii;

int main(){ _
  int a, b; cin >> a >> b;
  if(a % 2 && b % 2)  cout << "Yes" << endl;
  else  cout << "No" << endl;
  return 0;
}


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

int main() {
  int num = 1;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i ++) {
    if (num * 2 >= num + k) {
      num += k;
    }else
      num *= 2;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

signed main(void){
    string S;
    cin >> S;
    if(S[0]==S[1] || S[1]==S[2] || S[2]==S[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
    
    return 0;
}



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

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=1; i<n; i++) a[0] = gcd(a[0], a[i]);
    for(int i=1; i<=a[0]; i++){
        if(a[0]%i==0) cout << i << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
    int n, T; cin >> n >> T;
    vector<int> c(n), t(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i] >> t[i];
    }
    
    int ans = 1001;

    for (int i = 0; i < n; i++) {
        if (t[i] <= T) {
            ans = min(ans, c[i]);
        }
    }

    if (ans == 1001) cout << "TLE" << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long, long long>;



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

  ll n,u,v;
  std::cin>>n>>u>>v;
  u--;v--;

  std::vector<std::vector<ll>> graph(n);

  rep(i,0,n-1){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  std::vector<ll> taka(n,0),aoki(n,0);
  taka[u]=0;
  aoki[v]=0;

  std::vector<bool> used(n,false);
  used[u]=true;
  auto f=[&](auto f,ll i)->void{
    for(ll e:graph[i]){
      if(!used[e]){
        used[e]=true;
        taka[e]=taka[i]+1;
        f(f,e);
      }
    }
  };
  f(f,u);

  used=std::vector<bool>(n,false);

  used[v]=true;

  auto f2=[&](auto f2,ll i)->void{
    for(ll e:graph[i]){
      if(!used[e]){
        used[e]=true;
        aoki[e]=aoki[i]+1;
        f2(f2,e);
      }
    }
  };

  f2(f2,v);

  ll ans=0;

  rep(i,0,n){
    if(taka[i]<aoki[i]){
      chmax(ans,aoki[i]-1);
    }
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,cnt=0;
string s,ss[220000];
signed main()
{
	cin>>a>>b;
	rep(i,a){
		rep(j,b){
			if(((j+1)/10)*((j+1)%10)==i+1&&(j+1)/10>=2&&(j+1)%10>=2){
				cnt++;
			}
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 1920
import java.util.Scanner;

class Bot{
	int x = 1, y = 1 , dir = 0;
	private int width, height;
	
	private int[][] xy = {
			{0,1},{1,0},{0,-1},{-1,0}
	};
	
	public Bot(int w, int h) {
		width = w;
		height = h;
	}
	
	
	public void  forward(int step){
		x += xy[dir][0]*step;
		y += xy[dir][1]*step;
		beProperly();
	}
	
	public void backward(int step){
		x -= xy[dir][0]*step;
		y -= xy[dir][1]*step;
		beProperly();
	}
	
	public void right(){
		dir = (dir+1)%4;
	}
	
	public void left(){
		if(--dir == -1) dir = 3;
	}
	
	private void beProperly(){
		if(x > width) x = width;
		if(y > height) y = height;
		if(x < 1) x = 1;
		if(y < 1) y = 1;
	}
}


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

		while(true){
			int w = sn.nextInt(), h = sn.nextInt();
			if(w == 0 && h == 0) break;
			Bot bot = new Bot(w, h);
			while(true){

				String cmd = sn.nextLine();
				String[] go = cmd.split(" ");
				String dir;
				
				if(go.length == 2){
					int step = new Integer(go[1]);
					if(go[0].equals("FORWARD")) bot.forward(step);
					else if(go[0].equals("BACKWARD")) bot.backward(step);
				} else{
					
					if(go[0].equals("RIGHT")) bot.right();
					else if(go[0].equals("LEFT")) bot.left();
					else if(go[0].equals("STOP")) break;
				}
			}
			System.out.println(bot.x+" "+bot.y);
		}		
	}
}

Measured memory_bytes: 32776
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define maxn (int) 1e5+3
int a[maxn],b[maxn],c[maxn];
ull d[maxn];
int main()
{
	ull ans=0;
	int n;
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++) cin>>b[i];
	for (int i=1;i<=n;i++) cin>>c[i];
	sort(a+1,a+1+n);sort(b+1,b+1+n);sort(c+1,c+1+n);
	for (int i=1;i<=n;i++) d[i]=upper_bound(c+1,c+1+n,b[i])-c;
	for (int i=1;i<=n;i++) d[i]=n-d[i]+1;
	for (int i=1;i<=n;i++)d[i]=d[i-1]+d[i];
	for (int i=1;i<=n;i++)
	{
		int x=upper_bound(b+1,b+1+n,a[i])-b;
		if (x>n) continue;
		ans=ans+d[n]-d[x-1];
	}
	cout<<ans;
	cout<<endl;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int p = sc.nextInt();
		System.out.println(Math.min(a*p, b+Math.max(p-c, 0)*d));
	}
}

Measured memory_bytes: 26360
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
int n,a[55];
signed main(){
	cin>>n;
	rep(i,50){
		if(i<n%50)a[i]=50;
		else a[i]=49-n%50;
		a[i]+=n/50;
	}
	cout<<50<<endl;
	rep(i,49)cout<<a[i]<<" ";
	cout<<a[49]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, c;
    cin >> n >> c;

    auto tv = make_vec<P>(c, 0);
    rep(i, n) {
        int s, t, ch;
        cin >> s >> t >> ch;
        ch--;
        tv[ch].emplace_back(s, t);
    }
    rep(i, c) sort(tv[i].begin(), tv[i].end());
    
    const int maxt = 100005;
    vector<int> cnt(maxt+1);

    rep(i, c) {
        rep(j, tv[i].size()) {
            P p = tv[i][j];
            if (j+1 < tv[i].size() && tv[i][j+1].first == p.second) {
                tv[i][j+1].first = p.first;
            } else {
                cnt[p.first]++;
                cnt[p.second+1]--;
            }
        }
    }
    int ans = 0;
    rep(i, maxt) cnt[i+1] += cnt[i];
    rep(i, maxt) chmax(ans, cnt[i]); 
    cout << ans << endl;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

class Combination {
public:
    int N;
    ll mod;
    vector<ll> fact;

    Combination(int n, ll m) : N(n), mod(m), fact(n+1) {
        fact[0] = 1;
        for(ll i=1; i<=N; i++){
            fact[i] = i * fact[i-1] % mod;
        }
    }    

    // a ** b (mod m)
    static ll modpow(ll a, ll b, ll m) {
        ll res = 1;
        while(b > 0) {
            if(b & 1) {
                res = res * a % m;
            }
            a = a * a % m;
            b >>= 1;
        }
        return res;
    }

    ll modpow(ll a, ll b) {
        return modpow(a, b, mod);
    }

    // a / b (mod m)
    static ll moddiv(ll a, ll b, ll m) {
        return a % m * modpow(b, m - 2, m) % m;
    }

    ll moddiv(ll a, ll b) {
        return moddiv(a, b, mod);
    }

    ll combin(int n, int k) {
        if(n < 0 || k < 0 || n < k) {
            return 1;
        }
        return fact[n] * modpow(fact[k] * fact[n-k] % mod, mod - 2) % mod;
    }
};

signed main(){
    ll n, k;
    cin >> n >> k;

    vector<ll> dp(k+10, 0);

    ll ans = 0;

    FORR(i, 1, k+1){
        ll a = Combination::modpow(k / i, n, MOD);
        dp[i] += a;
        dp[i] %= MOD;
        ans += i * dp[i];
        ans %= MOD;
        for(int j=1; j*j<=i; j++){
            if(i%j == 0){
                dp[j] += (MOD - dp[i]);
                dp[j] %= MOD;
                if(i/j != j && j > 1){
                    dp[i/j] += (MOD - dp[i]);
                    dp[i/j] %= MOD;
                }
            }
        }
    }

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


Measured memory_bytes: 3996
#include <stdio.h>

int main()
{
    int N,i,x;
    scanf("%d",&N);
    
    for(i=0;i<2;i++)
    {
        x=N%10;
        if(x==9)
        {
            printf("Yes");
            return 0;
        }
        N=N/10;
    }
    printf("No");

    return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

bool pairCompare(const P& firstElof, const P& secondElof)
{
	return firstElof.second > secondElof.second;
}

int main() {
	//input
	int N, M;
	cin >> N >> M;
	vector<ll> A(N), B(M), C(M);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<P> D(M);
	for (int i = 0; i < M; i++) {
		cin >> B[i] >> C[i];
		D[i] = make_pair(B[i], C[i]);
	}

	//DをCの降順ソート
	sort(D.begin(), D.end(), pairCompare);

	//DからN枚取り出して並べる
	vector<ll> D_part(0);
	int count = 0;
	for (int i = 0; i < N && i < M; i++) {
		for (int j = 0; j < D[i].first; j++) {
			D_part.push_back(D[i].second);
			count++;
			if (count == N) {
				break;
			}
		}
		if (count == N) {
			break;
		}
	}

	//Aを昇順ソート
	sort(A.begin(), A.end());

	//AとD_partをどこまで入れ替えるか = D - A < 0 になる直前まで。
	ll B_total = accumulate(B.begin(), B.end(), (ll)0);
	ll A_total = accumulate(A.begin(), A.end(), (ll)0);
	ll total = 0;
	bool switch_flag = false;
	for (int i = 0; i < N && i < B_total; i++) {
		if (D_part[i] > A[i]) {
			A_total += D_part[i] - A[i];
		}
		else {
			break;
		}
	}

	cout << A_total;
	return 0;
}



Measured memory_bytes: 5368
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  int x;
  cin >> x;
  
  FOR(i, x, 100010){
    if(IsPrime(i)){
      cout << i << endl;
      break;
    }
  }
  
}

Measured memory_bytes: 256
#include <bits/stdint-intn.h>
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    int k, a, b; cin >> k >> a >> b;
    repi(i, a, b + 1) {
        if(i % k == 0) {
            println("OK");
            return 0;
        }
    }
    println("NG");

    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long

int main(){
    ll H,W;
    cin >> H >> W;
    ll ans;
    if(H%3==0||W%3==0)ans=0;else ans=min(H,W);
    ll h,w;
    ll a,b,c;
    ll t;
    for(h=1;h<=H-1;h++){
        w=W/2;
        a=h*W;
        b=(H-h)*w;
        c=(H-h)*(W-w);
        t=max(abs(a-b),max(abs(b-c),abs(c-a)));
        ans=min(ans,t);
    }
    for(w=1;w<=W-1;w++){
        h=H/2;
        a=w*H;
        b=(W-w)*h;
        c=(H-h)*(W-w);
        t=max(abs(a-b),max(abs(b-c),abs(c-a)));
        ans=min(ans,t);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7,N = 1e5 + 1;
int dp[2][N],s,t,n,m;
long long dis[2][N];
struct edges{
	int x,y,w;
}e[N<<1];
struct node{
	int x,w;
	node(int a = 0,int b = 0){
		x = a;w = b;
	}
};
void add(int &a,int b){
	a+=b;
	a%=M;
	if(a >= M)a-=M;
	if(a < 0)a+=M;
}
vector<node>g[N];
bool vis[N];
void dijk(int s,bool at){
	long long *dis = ::dis[at];
	memset(vis,0,sizeof vis);
	int *dp = ::dp[at];
	dis[s] = 0;
	dp[s] = 1;
	priority_queue<pair<long long,int>>q;
	q.push({0,s});
	while(!q.empty()){
		int x = q.top().second;
		long long w = -q.top().first;
		q.pop();
		if(vis[x])continue;
		vis[x] = 1;
		for(auto i : g[x]){
			int y = i.x;
			long long cur = w + i.w;
			if(cur == dis[y])add(dp[y],dp[x]);
			if(cur >= dis[y])continue;
			dp[y] = dp[x];
			dis[y] = cur;
			q.push({-dis[y],y});
		}
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	scanf("%d%d%d%d",&n,&m,&s,&t);	
	for(int i = 0;i < m;i++){
		scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
		int a = --e[i].x,b = --e[i].y,c = e[i].w;
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	for(int i = 0;i < n;i++)dis[0][i] = dis[1][i] = 1e18;
	dijk(--s,0);
	dijk(--t,1);
	long long mndis = dis[0][t];
	int ans = dp[0][t]*1LL*dp[0][t]%M,sz = 0;
	for(auto i : e){
		if(sz == m)break;
		++sz;
		long long mn = min(dis[0][i.x],dis[0][i.y]);
		long long mx = min(dis[1][i.x],dis[1][i.y]);
		if(mn == dis[0][i.y])swap(i.x,i.y);
		if(mn + mx + i.w == mndis && mn<<1 < mndis && mx<<1 < mndis)add(ans,-(dp[0][i.x]*1LL*dp[0][i.x]%M)*(dp[1][i.y]*1LL*dp[1][i.y]%M)%M);
	}
	for(int i = 0;i < n;i++)
		if(dis[0][i] == dis[1][i])add(ans,-(dp[0][i]*1LL*dp[0][i]%M)*(dp[1][i]*1LL*dp[1][i]%M)%M);
	printf("%d\n",ans);
}

Measured memory_bytes: 17364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, Ma, Mb;
vector<int> a, b, c;

const int W = 401;
int dp[W][W];

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

  a.resize(N), b.resize(N), c.resize(N);
  rep(i, N) cin >> a[i] >> b[i] >> c[i];

  const int INF = 1e9;

  rep(i, N + 1) rep(j, W) rep(k, W) dp[j][k] = INF;
  dp[0][0] = 0;

  rep(i, N) {
    for (int j = W - 1; j >= 0; --j) {
      for (int k = W - 1; k >= 0; --k) {
        if (dp[j][k] == INF) continue;
        dp[j + a[i]][k + b[i]] = min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
        dp[j][k] = min(dp[j][k], dp[j][k]);
      }
    }
  }

  int ans = INF;
  rep(i, W) rep(j, W) {
    if (i == 0 && j == 0) continue;
    if (i * Mb == j * Ma) ans = min(ans, dp[i][j]);
  }

  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}


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

#define lli long long int
#define pi pair<int,int>
#define mod 1000000007
const int INF=1e9+5;
lli min_cost(vector<int> &v)
{
	int n=v.size();
	vector<lli> dp(n,INF);
	dp[0]=0;
	dp[1]=dp[0]+abs(v[1]-v[0]);
	for(int i=2;i<n;i++)
	{
		// for(int j : {i+1,i+2})
		// {
		// 	if(j<n)
		// 		dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
		// }
		dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
	}
	return dp[n-1];
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);	cout.tie(0);
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	cout<<min_cost(arr)<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}


int main(){
  int n;
  cin >> n;
  cout<< 2*n/gcd(n,2) <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    ll mn=0, mx=0;
    for(ll i = k; i <= n+1; ++i){
        mn = i*(i-1)/2;
        mx = i*(n*2-i+1)/2;
        ans += mx -mn +1;
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, K, Q;
  cin >> N >> K >> Q;
  vector<ll> A(N);

  for (ll i = 0; i < Q; i++) {
    ll x;
    cin >> x;
    x--; // 0-index
    A[x]++; // countUp
  }
  // 不正解の回数に変換
  for_each(begin(A), end(A), [&](auto& x) { x = Q - x; });

  // 不正解がK超えたらNo
  for_each(begin(A), end(A), [&](auto& x) {
    string ans = "Yes";
    if (K - x <= 0) {
      ans = "No";
    }
    cout << ans << endl;
  });

  return 0;
}


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



int main(){
    long long int n,counter=0;
    string s;
    cin>>n;
    cin>>s;
    for(int i=2;i<n;i++){
        if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C'){
            counter++;
        }
    }
    cout<<counter<< "\n";
    return 0;
}



Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_STR_MAX		5000									// 最大文字列長
#define D_LTL_MAX		5										// 最大の小さい位置

// 内部構造体 - 文字列情報
typedef struct Str {
	int miSNo;													// 開始位置
	int miLen;													// 文字列長
} Str;

// 内部変数
static char sc1Str[D_STR_MAX + 5];								// 文字列
static int siLen;												// 文字列長
static Str sz1Str[D_STR_MAX * D_LTL_MAX * 2];					// 文字列情報
static int siSCnt;												// 文字列情報数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// ソート関数 - 昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int liRet;

	Str *lzpVal1 = (Str *)pzpVal1;
	Str *lzpVal2 = (Str *)pzpVal2;

	// 比較長さ
	int liLen, liLRet;
	if (lzpVal1->miLen > lzpVal2->miLen) {
		liLen = lzpVal2->miLen;
		liLRet = 1;
	}
	else if (lzpVal1->miLen < lzpVal2->miLen) {
		liLen = lzpVal1->miLen;
		liLRet = -1;
	}
	else {
		liLen = lzpVal1->miLen;
		liLRet = 0;
	}

	// 文字列比較
	liRet = strncmp(&sc1Str[lzpVal1->miSNo], &sc1Str[lzpVal2->miSNo], liLen);
	if (liRet != 0) {
		return liRet;
	}

	// 文字列長昇順
	return liLRet;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j, liRet;
	char lc1Buf[1024], lc1Out[1024];

	// データ初期化
	siSCnt = 0;													// 文字列情報数

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 文字列取得
#ifdef D_TEST
	fgets(sc1Str, sizeof(sc1Str), szpFpT);
#else
	fgets(sc1Str, sizeof(sc1Str), stdin);
#endif

	// 文字列長
	siLen = strlen(sc1Str);

	// 改行カット
	siLen--;
	sc1Str[siLen] = '\0';

	// 文字列情報登録 - １文字～D_LTL_MAX文字
	for (i = 1; i <= D_LTL_MAX; i++) {
		for (j = 0; j < siLen - i + 1; j++) {
			sz1Str[siSCnt].miSNo = j;
			sz1Str[siSCnt].miLen = i;
			siSCnt++;
		}
	}

	// ソート
	qsort(sz1Str, siSCnt, sizeof(Str), fSortFnc);

	// 重複カット
	int liFNo = 1;
	int liTNo = 0;
	while (liFNo < siSCnt) {

		// 比較
		liRet = fSortFnc(&sz1Str[liFNo], &sz1Str[liTNo]);
		if (liRet == 0) {										// 一致
		}
		else {													// 不一致
			liTNo++;
			if (liFNo != liTNo) {
				memcpy(&sz1Str[liTNo], &sz1Str[liFNo], sizeof(Str));
			}
			if (liTNo >= D_LTL_MAX) {
				break;
			}
		}
		liFNo++;
	}

	// 表示位置取得
	int liDNo;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liDNo);
	liDNo--;

	// 結果セット
	strncpy(lc1Out, &sc1Str[sz1Str[liDNo].miSNo], sz1Str[liDNo].miLen);
	lc1Out[sz1Str[liDNo].miLen] = '\0';
	strcat(lc1Out, "\n");

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  string ans;
  if(a + b == c || b + c == a || c + a == b) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll a[20005];
ll b[20005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    ll N ;
    cin >> N;
    vector<ll> p ;
    ll base = 0;
    rep(i,N){
        ll inp; cin >> inp;
        p.pb(inp);
        base = max(base, inp);
    }
    base *= 2;

    rep(i,N){
        a[i] = (i+1) * base;
        b[N-1-i] = (i+1) * base;
    }
    rep(i, N){
        b[p[i]-1] += i;
    }
    
    rep(i,N){
        cout << a[i] << " " ;
    }
    cout << endl;
    rep(i,N){
        cout << b[i] << " ";
    }
    cout << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main(){

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

    for(int i = n-1; i >= 0; --i){
        printf("%d%c", a[i], i == 0 ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 3156
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll mx = 1000000000000;

int main(){
  int N;
  cin >> N;
  ll a[N];
  for(int i = 0; i < N; i++){
    cin >> a[i];
    a[i] = mx - a[i];
  }

  multiset<ll> st;
  st.insert(a[0]);
  for(int i = 1; i < N; i++){
    auto itr = st.upper_bound(a[i]);
    //cout << "hofe" << endl;
    if(itr == st.end()){
      st.insert(a[i]);
    } else {
      st.erase(itr);
      st.insert(a[i]);
    }
  }

  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 5760
#include <cstdio>

char s[111];

int main(void)
{
	int n, i;
  
	scanf("%d %s" ,&n, &s[1]);
  
	if (n % 2)
    {
    	puts("No");
		return 0;
    }
	
	for (i = 1; i <= n / 2; i++)
		if (s[i] != s[i + n / 2])
        {
        	puts("No");
			return 0;
        }
	puts("Yes");
	return 0;
}

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

int main() {
    int n, y;
    cin >> n >> y;
    rep(i, n+1) rep(j, n-i+1){
        int k = n - i - j;
        if (10000 * i + 5000 * j + 1000 * k == y){
            cout << i << " " << j << " " << k << endl;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;
}


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

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

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

int main(){
fast;
ll a;
string b;
cin>>a;
cin>>b;

ll num = 0;
num += 100*(b[0]-'0');
num += 10*(b[2]-'0');
num += (b[3]-'0');


ll ans = a*num;
cout<<ans/100<<endl;
return 0;
}

Measured memory_bytes: 3636
a, b = map(int, input().split())

A = [str(a) * b]
B = [str(b) * a]

A = int(A[0])
B = int(B[0])

liA = []
liB = []

for a in str(A):
    liA.append(int(a))

for b in str(B):
    liB.append(int(b))


for i in range(len(min(liA, liB)) - 1):
    if liA[i] < liB[i]:
        print(A)
        break
    elif liB[i] < liA[i]:
        print(B)
        break
else:
    print(A)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll n,k,x,y,i,j,q;
   vector<ll>v,u;
   char c;
   string s;
   cin>>n;
   while(n)
   {
       k=n%26;
       if(k==0)
       {
           k=26;
       }
       c=char('a'+k-1);
       s+=c;
       n--;
       n=n/26;
   }
   reverse(s.begin(),s.end());
   cout<<s<<endl;
    return 0;
}


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

#define MOD 1000000007
#define ll long long int 
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

double dp[3000][3001];

int main()
{
    off;

    int n;cin>>n;

    double p[n];

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

    dp[0][0] = 1 - p[0];
    dp[0][1] = p[0];
    for (int i = 2; i < n; ++i)
    {
        dp[0][i] = 0;
    }

    double precise = 1000000000000;
    for (int i = 1; i < n; ++i)
    {
        for (int j = 0; j <= n; ++j)
        {
            dp[i][j] = (dp[i-1][j]*precise)*(1-p[i]);
            if(j>0)
                dp[i][j] += (dp[i-1][j-1]*precise)*p[i];
            dp[i][j] /= precise;
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }

    double ans =0;

    for (int i = (n+1)/2; i <= n; ++i)
    {
        ans += dp[n-1][i];
    }

    cout.precision(10);
    cout<<ans;

    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
 
const int maxn = 20;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    string a,b; cin >> a >> b;
    cout << (b + a) << '\n';
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

Measured memory_bytes: 256
axis_1 = '0154' * 2  # 2 -> 3
axis_2 = '0253' * 2  # 4 -> 1
axis_3 = '3124' * 2  # 0 -> 5

right = [axis_3, axis_2[::-1], axis_1, axis_1[::-1], axis_2, axis_3[::-1], ]
a = list(map(int, input().split()))
n = int(input())
for _ in range(n):
    top, front = map(a.index, map(int, input().split()))
    x = '%d%d' % (top, front)
    for i, axis in enumerate(right):
        if x in axis:
            print(a[i])
            break
    else:
        print('------------------')
        print(x)

Measured memory_bytes: 6724
from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce


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


def iinput():
    return int(input())


def tinput():
    return input().split()


def rinput():
    return map(int, tinput())


def rlinput():
    return list(rinput())


mod = int(1e9)+7


def factors(n):
    return set(reduce(list.__add__,
                      ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))


# ----------------------------------------------------

if __name__ == "__main__":
    a = input()
    b = input()
    n, m = len(a), len(b)
    lcs = [[0 for i in range(n+1)] for j in range(m+1)]


    for i in range(1,m+1):
        for j in range(1,n+1):
            if b[i-1] == a[j-1]:
                lcs[i][j] = 1 + lcs[i-1][j-1]
            else:
                lcs[i][j] = max(lcs[i][j-1],lcs[i-1][j])
    
    s=""
    i=m
    j=n
    # print(lcs)
    while i>0 and j>0:
        if b[i-1] == a[j-1]:
            s+=b[i-1]
            i-=1
            j-=1
        elif lcs[i-1][j] > lcs[i][j-1]:
            i-=1
        else:
            j-=1

    print(s[::-1])
        



Measured memory_bytes: 121180
#!/usr/bin/python3
import sys
from functools import reduce
from operator import mul
input = lambda: sys.stdin.readline().strip()
n, k = [int(x) for x in input().split()]
a = sorted((int(x) for x in input().split()), key=abs)
sgn = [0 if x == 0 else x // abs(x) for x in a]
M = 10**9 + 7
def modmul(x, y):
    return x * y % M
if reduce(mul, sgn[-k:]) >= 0:
    print(reduce(modmul, a[-k:], 1))
else:
    largest_unselected_neg = next(i for i, x in enumerate(reversed(a[:-k])) if x < 0) if any(x < 0 for x in a[:-k]) else None
    largest_unselected_pos = next(i for i, x in enumerate(reversed(a[:-k])) if x > 0) if any(x > 0 for x in a[:-k]) else None
    smallest_selected_neg = next(i for i, x in enumerate(a[-k:]) if x < 0) if any(x < 0 for x in a[-k:]) else None
    smallest_selected_pos = next(i for i, x in enumerate(a[-k:]) if x > 0) if any(x > 0 for x in a[-k:]) else None
    can1 = largest_unselected_neg is not None and smallest_selected_pos is not None
    can2 = largest_unselected_pos is not None and smallest_selected_neg is not None
    def ans1():
        return list(reversed(a[:-k]))[largest_unselected_neg] * reduce(modmul, (x for i, x in enumerate(a[-k:]) if i != smallest_selected_pos), 1) % M 
    def ans2():
        return list(reversed(a[:-k]))[largest_unselected_pos] * reduce(modmul, (x for i, x in enumerate(a[-k:]) if i != smallest_selected_neg), 1) % M
    if can1 and not can2:
        print(ans1())
    elif can2 and not can1:
        print(ans2())
    elif can1 and can2:
        if list(reversed(a[:-k]))[largest_unselected_neg] * a[-k:][smallest_selected_neg] > list(reversed(a[:-k]))[largest_unselected_pos] *  a[-k:][smallest_selected_pos]:
            print(ans1())
        else:
            print(ans2())
    else:
        print(reduce(modmul, a[:k], 1))

Measured memory_bytes: 32108
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()



int main()
{

   int n;
   cin >> n;
   int v[n+1];
   int a;
   for(int i = 1; i <=n; i++)
   {
       cin >> a;
       v[a] = i;
   }
   for(int i = 1; i <=n; i++) cout <<v[i]<<" ";


}




Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int main()
{
    int i,j;
    LLI x,y;

    scanf("%lld %lld", &x, &y);
    LLI a = y/x;
    for( i=0; (a>>i); i++);
    printf("%d\n", i);

    return 0;
}


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

using namespace std;

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

    int arrF[10000] = {0};
    arrF[0] = s;

    int counter = 0;
    int check = 0;

    while(1){
        counter++;
        if( s % 2 == 0 ){
            s = s / 2;
        }
        else{
            s = ( 3 * s  + 1 );
        }

        arrF[counter] = s;

        for( int i = 0 ; i < counter; i++ ){
            for( int j = 0; j < i; j++ ){
                if( arrF[i] == arrF[j] && i != j ){
                    check++;
                    cout << i + 1 << endl;
                }
            }
        }
        if( check != 0 ){
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256