akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<bool> is_prime(1000001,true);

void sieve() {
  for(ll i = 2;i <= 1000000; i++) {
    if(is_prime[i]) {
      for(ll j = i * i; j <= 1000000; j+=i) {
        is_prime[j] = false;
      }
    }
  }
}

typedef long long ll;
int main() {
  ll n;
  cin>>n;
  sieve();
  
  ll temp = n;
  ll count = 0;
  for(ll i = 2;i <= 1000000; i++) {
    if(is_prime[i]) {
      if(n % i == 0) {
        ll x = i;
        while(n % x == 0){
          n/=x;
          x*=i;
          count++;
        }
      }
    }
  }
  if(n > 1000000)
      count++;
  
  	 cout<<count;  
  return 0;
}

Measured memory_bytes: 3752
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

N = int(input())
A = [input() for i in range(N)]

mx = 0
d = {}
r = []

for a in A:
    if not a in d:
        d[a] = 0
    d[a] += 1
    if d[a] > mx:
        r = [a]
        mx = d[a]
    elif d[a] == mx:
        r.append(a)

r.sort()
for i in r:
    print(i)


Measured memory_bytes: 36392
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
#define MAX 105
 
typedef long long ll;
 
int main(int, char**)
{
    int n, k;
    cin >> n >> k;

    int d, a;
    int count[MAX] = {0};
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            count[a-1]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (count[i] == 0) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

struct Weighted_Graph {
  struct edge { ll node, cost; };
  vector<vector<edge>> e;

  void set(ll x){ e.resize(x + 1); }

  void add_edge(ll a, ll b, ll c) { e[a].pb(edge{ b,c }); }

  vll dijkstra(ll start) {
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll u;
	pll p;
	vll dist(e.size(), inf);
	dist[start] = 0;
	pq.push(pll(0, start));

	while (!pq.empty()) {
	  p = pq.top(); pq.pop();
	  u = p.second;
	  if (dist[u] < p.first) continue;
	  for (edge e1 : e[u]) {
		if (dist[e1.node] > dist[u] + e1.cost) {
		  dist[e1.node] = dist[u] + e1.cost;
		  pq.push(pll(dist[e1.node], e1.node));
		}
	  }
	}
	return dist;
  }

  void floyd(vvll &dist) {
	ll x = e.size();
	dist.resize(x);
	rep(i, x) dist[i].resize(x, inf);
	rep(i, x) rep(j, e[i].size()) dist[i][e[i][j].node] = e[i][j].cost;
	rep(k, x) {
	  rep(i, x) {
		if (dist[i][k] == inf) continue;
		rep(j, x) {
		  if (dist[k][j] == inf) continue;
		  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	  }
	}
  }

};

int main(void) {
  Weighted_Graph wg;
  vvll d;
  wg.set(10);
  cin >> n >> m;
  rep(i, 10) {
	rep(j, 10) {
	  cin >> tmp;
	  wg.add_edge(i, j, tmp);
	}
  }
  wg.floyd(d);

  rep(i, n) {
	rep(j, m) {
	  cin >> tmp;
	  if (tmp == -1) continue;
	  ans += d[tmp][1];
	}
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
	int N, a[200000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	int ch = 0, s = 0,b = 0;

	while (s < N) {
		for (int i = s; i < N; i++) {
			if (a[i] == ch + 1) {
				s = i;
				ch++;
				break;
			}
			if (i == N - 1) {
				b = 1;
			}
		}
		if (b == 1) {
			break;
		}
	}
	if (ch != 0) {
		cout << N - ch << endl;
	}
	else cout << -1 << endl;

	return 0;
}









Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 1000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

string ans = "Yes";

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

	int A,B;
	cin >> A >> B;

	rep(i,1e9){
		if(abs(A-i) == abs(B-i)){
			cout << i << endl;
			return 0; 
		}
	}
	cout << "IMPOSSIBLE" << endl;
 	return 0;
}

Measured memory_bytes: 384
import sys
from collections import deque
 
h,w = map(int, sys.stdin.readline().split())
maze = [list(sys.stdin.readline()) for _ in range(h)]
dis = [[-1 for _ in range(w)] for _ in range(h)]
 
que = deque()
que.append((0,0))
dis[0][0] = 1
 
while que:
    y,x = que.popleft()
    for dx, dy in ((1,0), (0,1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if (nx < 0) or (nx > w-1) or (ny < 0) or (ny > h-1): continue
        if (maze[ny][nx] == '.') and (dis[ny][nx] == -1):
            dis[ny][nx] = dis[y][x] + 1
            que.append((ny, nx))
 
ans = 0
black_num = 0
for m in maze:
    black_num += m.count('#')
 
if dis[h-1][w-1] == -1:
    ans = -1
else:
    ans = w*h - black_num - dis[h-1][w-1]
 
print(ans)

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

int main() {
    string s, t;
    cin >> s >> t;

    int slen = s.size();
    int tlen = t.size();
    
    vector<vector<int>> dp(slen + 1, vector<int>(tlen + 1, 0));
    
    for (int i = 1; i <= slen; i++) {
        for (int j = 1; j <= tlen; j++) {
            if (s.at(i - 1) == t.at(j - 1)) {
                dp.at(i).at(j) = dp.at(i - 1).at(j - 1) + 1;
            }
            else {
                dp.at(i).at(j) = max(dp.at(i - 1).at(j), dp.at(i).at(j - 1));
            }
        }
    }
  
    int length = dp.at(slen).at(tlen);
    int i = slen;
    int j = tlen;
    string ans = "";

    while (length > 0) {
        if (s.at(i - 1) == t.at(j - 1)) {
            ans = s.at(i - 1) + ans;
            length--;
            i--;
            j--;
        }
        else if (dp.at(i).at(j) == dp.at(i - 1).at(j)) {
            i--;
        }
        else { //dp.at(i).at(j) == dp.at(i).at(j - 1)
            j--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 38884
{-# LANGUAGE BangPatterns #-}
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS

main = do
  [n,m] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  ab <- fmap sort $ sequence $ replicate n $ do
    [a,b] <- map (read . BS.unpack) . BS.words <$> BS.getLine
    return (a :: Int64, b :: Int64)
  let solve !k !yen ((a,b):xs) | k <= b = yen + a * k
                               | otherwise = solve (k - b) (yen + a * b) xs
  print $ solve (fromIntegral m) 0 ab


Measured memory_bytes: 54652
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
//void solve(bool a) { cout << ((a) ? "Yes" : "No") << endl; }
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main() {
	string s, t;
	bool ans = true;
	cin >> s >> t;
	map<char, char> trans;
	set<char> ch;
	rep(i, s.size()) { trans[s[i]] = t[i]; }
	rep(i, s.size()) {
		ans &= (trans[s[i]] == t[i]);
		ch.insert(trans[s[i]]);
	}
	ans &= (ch.size() == trans.size());
	cout<<solve(ans)<<endl;
}

Measured memory_bytes: 3908
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	LL A, B, C, D;

	cin >> A >> B >> C >> D;

	LL ret = B - A + 1;

	ret -= B / C - (A - 1) / C;
	ret -= B / D - (A - 1) / D;
	ret += B / (C * D / __gcd(C, D)) - (A - 1) / (C * D / __gcd(C, D));

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
    int n, l, i;
    double t = 0, v = 0;
    deque <pair<double, double> > d;
    
    scanf("%d %d", &n, &l);
    
    for (i = 0; i < n; i++) {
        double tx, vx;
        
        scanf("%lf %lf", &tx, &vx);
        
        if (l == vx) {
            d.clear();
            t = 0;
            v = 0;
        }
        
        while (v + vx > l && d.size() > 0) {
            double t1 = d.front().first;
            double v1 = d.front().second;
            double v2 = min(v1, v + vx - l);
            
            t = (t * v - t1 * v2) / (v - v2);
            v = v - v2;
            
            if (v1 == v2) {
                d.pop_front();
            } else {
                d.front().second -= v2;
                break;
            }
        }
        
        t = (t * v + tx * vx) / (v + vx);
        v = v + vx;
        
        printf("%.12lf\n", t);
        
        while (d.size() > 0) {
            double t1 = d.back().first;
            double v1 = d.back().second;
            
            if (t1 < tx) break;
            
            tx = (tx * vx + t1 * v1) / (vx + v1);
            vx = vx + v1;
            
            d.pop_back();
        }
        
        d.push_back(make_pair(tx, vx));
    }
    
    return 0;
}


Measured memory_bytes: 19600
class Node():
    def __init__(self, value, parent=None):
        self.value = value
        self.parent = parent
        self.left_child = None
        self.right_sibling = None

    def set_left_child(self, child):
        self.left_child = child

    def set_right_sibling(self, sibling):
        self.right_sibling = sibling

    def set_parent(self, parent):
        self.parent = parent

    def get_depth(self):
        if self.parent is None:
            return 0

        return self.parent.get_depth() + 1

    def get_childs(self):
        r = []
        child = self.left_child
        while child is not None:
            r.append(child.value)
            child = child.right_sibling
        return r

    def print(self):
        childs = self.get_childs()
        depth = self.get_depth()
        p = str(self.parent.value if self.parent else -1)
        t = 'leaf'
        if self.parent is None:
            t = 'root'
        elif childs and self.parent:
            t = 'internal node'

        print('node ' + str(self.value) + ': parent = ' + p + ', depth = ' + str(depth) + ', ' + t + ', ' + str(childs))


n = int(input())
m = {}
for _ in range(n):
    l = list(map(int, input().split()))
    p = m[l[0]] if m.get(l[0]) else Node(l[0])
    if l[1] >= 1:
        sibling = None
        for i in range(2, 2 + l[1])[::-1]:
            node = m[l[i]] if m.get(l[i]) else Node(l[i])
            node.right_sibling = sibling
            node.parent = p
            sibling = node
            m[node.value] = node
        p.left_child = node
    m[l[0]] = p

for i in range(n):
    m[i].print()



Measured memory_bytes: 33280
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int, int> P;

vector< vector<int> > change(vector< vector<int> > p, int c) {
	int cc = p[0][0];
	int h = p.size();
	int w = p[0].size();
	int dx[] = { 1,0,-1,0 };
	int dy[] = { 0,1,0,-1 };
	vector< vector<int> > p2(h, vector<int>(w, 0));
	queue<P> q;
	q.push(P(0, 0));
	p[0][0] = c;
	p2[0][0] = 1;
	while (!q.empty()) {
		P pp = q.front();
		q.pop();
		int x = pp.first;
		int y = pp.second;
		for (int i = 0; i < 4; i++) {
			if (0 <= x + dx[i] && x + dx[i] < w && 0 <= y + dy[i] && y + dy[i] < h) {
				if (p2[y + dy[i]][x + dx[i]] == 0) {
					if (p[y + dy[i]][x + dx[i]] == cc) {
						p[y + dy[i]][x + dx[i]] = c;
						p2[y + dy[i]][x + dx[i]] = 1;
						q.push(P(x + dx[i], y + dy[i]));
					}
				}
			}
		}
	}
	return p;
}

int calcpanel(vector< vector<int> >p) {
	int cc = p[0][0];
	int h = p.size();
	int w = p[0].size();
	int dx[] = { 1,0,-1,0 };
	int dy[] = { 0,1,0,-1 };
	vector< vector<int> > p2(h, vector<int>(w, 0));
	queue<P> q;
	q.push(P(0, 0));
	p2[0][0] = 1;
	int count = 1;
	while (!q.empty()) {
		P pp = q.front();
		q.pop();
		int x = pp.first;
		int y = pp.second;
		for (int i = 0; i < 4; i++) {
			if (0 <= x + dx[i] && x + dx[i] < w && 0 <= y + dy[i] && y + dy[i] < h) {
				if (p2[y + dy[i]][x + dx[i]] == 0) {
					if (p[y + dy[i]][x + dx[i]] == cc) {
						count++;
						p2[y + dy[i]][x + dx[i]] = 1;
						q.push(P(x + dx[i], y + dy[i]));
					}
				}
			}
		}
	}
	return count;
}

int calc(vector< vector<int> > p, int limit, int c) {
	int h = p.size();
	int w = p[0].size();
	if (limit == 0) {
		return calcpanel(p);
	}
	int MAX = 0;
	for (int i = 1; i <= 6; i++) {
		if (limit > 1) {
			MAX = max(MAX, calc(change(p, i), limit - 1, c));
		}
	}
	if (limit == 1) {
		MAX = calc(change(p, c), limit-1, c);
	}
	return MAX;
}

int main() {
	int h, w, c;
	while (cin >> h >> w >> c) {
		if (h == 0 && w == 0 && c == 0) {
			break;
		}
		vector< vector<int> > p(h, vector<int>(w));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> p[i][j];
			}
		}
		cout << calc(p, 5, c) << endl;
	}
	return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
long long  a[10001];
int k,t,i,n;
int main()
{
a[0]=2;
a[1]=1;
cin>>n;
for (i=2; i<=n; i++)
  a[i]=a[i-1]+a[i-2];
cout<<a[n]<<endl;  
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  ll N,M;
  cin >> N >> M;
  vll A(N);
  rep(i,0,N) cin >> A[i];
  sort(all(A));
  vp ba(M);
  rep(i,0,M){
    ll a,b;
    cin >> a >> b;
    ba[i] = mp(b,a);
  }

  SORT(ba);

  ll index = 0;
  rerep(i,M-1,0){
    rep(j,0,ba[i].second){
      if(index >= N) break;
      if(ba[i].first > A[index]){
        A[index] = ba[i].first;
        index++;
      }
      else break;
    }
  }

  print(vec_sum(A));


 return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		
		
		sc.close();
	}
}


Measured memory_bytes: 22860
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
char mp[50][101];
int m, n;
void fill_mp(int num, int x, char ch)
{
	for (int i = x; ; i += 2)
	{
		for (int j = 0; j < 100; j += 2)
		{
			if (num == 0)	return;
			mp[i][j] = ch;
			num--;
		}
	}
}
int main()
{
	while (~scanf("%d%d", &m, &n))
	{
		for (int i = 0; i < 25; i++)
		{
			memset(mp[i], '#', sizeof(mp[i]));
		}
		for (int i = 25; i < 50; i++)
		{
			memset(mp[i], '.', sizeof(mp[i]));
		}
		for (int i = 0; i < 50; i++)	mp[i][100] = 0;
		m--, n--;
		fill_mp(m, 0, '.'), fill_mp(n, 26, '#');
		printf("50 100\n");
		for (int i = 0; i < 50; i++)	printf("%s\n", mp[i]);
	}
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  n--;

  vll s;
  ll num=26;
  ll sum=0;
  ll cnt=0;
  while(sum<n){
    if(sum+num<=n){
      sum+=num;
      num*=26;
      cnt++;
    }
    else
      break;
  }

  n-=sum;
  while(cnt>=0){
    ll c=n%26;
    s.push_back(c);
    n/=26;
    cnt--;
  }

  ll g=s.size();
  REP(i,g)
    cout<<char(s[g-1-i]+'a');
  cout<<endl;

}



Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define pb push_back
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>
#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

bool visited[100009][2];
vector<LL> adj[100009];
LL dp[100009][2];
//0 white
//1 black
LL dfs(LL s, LL my_color, LL parent = -1)
{
    if (!visited[s][my_color])
    {
        //debug(s);

        visited[s][my_color] = true;
        LL cnt = 1;
        LL k = 0;
        for (auto x : adj[s])
        {
            if (x != parent)
            {
                k=0;
                k+= (dfs(x, 0, s)) % MOD;
                if (my_color != 1)
                {
                    k+= (dfs(x, 1, s)) % MOD;
                    k%=MOD;
                }
                cnt *=k;
                cnt%=MOD;
            }
        }
        dp[s][my_color] = cnt;
    }

    return dp[s][my_color];
}
int main()
{
    fastinput;
    LL n, i, j, k, t, temp;
    cin >> n;
    for (i = 1; i <= n - 1; i++)
    {
        cin >> j >> k;
        adj[j].pb(k);
        adj[k].pb(j);
    }

    for (i = 1; i <= n; i++)
    {
        for (j = 0; j < 2; j++)
        {
            visited[i][j] = false;
            dp[i][j] = -1;
        }
    }

    LL ans = (dfs(1, 1) + dfs(1, 0)) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  vector<int> x(26, 0);

  int n = s.size();
  rep(i, 0, n) x[s[i] - 'a']++;

  rep(i, 0, 26) {
    if (x[i] == 0) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }

  cout << "None" << endl;
}


Measured memory_bytes: 512
from itertools import permutations


def warshall_floyd(n, d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])


N, M, R = map(int, input().split())
r = list(map(int, input().split()))

d = [[1000000000] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    A, B, C = map(int, input().split())
    d[A][B] = C
    d[B][A] = C
warshall_floyd(N + 1, d)

result = 1000000000
for p in permutations(r):
    t = 0
    for i in range(R - 1):
        t += d[p[i]][p[i + 1]]
    result = min(result, t)
print(result)


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

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

  map<string,int> mp;

  for(int i=0; i < n; i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }


  long long ans=0;

  for(auto& p : mp){
    int s = p.second;
    ans += (long long)s*(s-1)/2;
  }

  cout << ans << endl;
}



Measured memory_bytes: 11136
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = a + a
c = 0
(a.size - 1).times do |i|
  (i + 1).upto(a.size - 1) do |j|
    c += 1 if a[i] > a[j]
  end
end
d = 0
(b.size - 1).times do |i|
  (i + 1).upto(b.size - 1) do |j|
    d += 1 if b[i] > b[j]
  end
end
def modpow(n, p, mod)
  r = 1
  while p > 0
    r = r * n % mod if p & 1 == 1;
    n = n * n % mod
    p >>= 1
  end
  r
end
def modinv(n, mod)
  modpow(n, mod - 2, mod)
end
d -= c * 2
MOD = 1_000_000_007
ans = (k - 1) * d % MOD
ans += 2 * c
ans %= MOD
ans *= k
ans %= MOD
ans *= modinv(2, MOD)
ans %= MOD
puts ans

Measured memory_bytes: 1916
import sys
import numpy as np
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    np.set_printoptions(threshold=20)
    N = int(input())
    A = list(map(int, input().rstrip().split()))
    A.sort()
    ans = 1
    for v in A:
        ans *= v
        if ans > pow(10, 18):
            ans = -1
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40196
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
    vector<int> par; // uf(x,y)->y
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
    void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/













int N, M, A[101010], B[101010];
UnionFind uf(101010);
int cnt[101010];
ll ans[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    rep(i, 0, N) cnt[i] = 1;

    ans[M-1] = 1LL * N * (N - 1) / 2;
    rrep(i, M - 1, 1) {
        int a = A[i], b = B[i];

        if (uf[a] == uf[b]) ans[i - 1] = ans[i];
        else {
            ans[i - 1] = ans[i] - 1LL * cnt[uf[a]] * cnt[uf[b]];
            int sm = cnt[uf[a]] + cnt[uf[b]];
            uf(a, b);
            cnt[uf[a]] = sm;
        }
    }

    rep(i, 0, M) printf("%lld\n", ans[i]);

}

Measured memory_bytes: 3832
def rate(n):
    if n <= 399:
        return "gray"
    elif n <= 799:
        return "brown"
    elif n <= 1199:
        return "green"
    elif n <= 1599:
        return "water"
    elif n <= 1999:
        return "blue"
    elif n <= 2399:
        return "yellow"
    elif n <= 2799:
        return "orange"
    elif n <= 3199:
        return "red"
    else:
        return "pro"

n = int(input())
a = list(map(int, input().split()))
ans = []

for i in a:
    ans.append(rate(i))

pro = ans.count("pro")
ANS = set(ans)
ANS.discard("pro")
MIN = len(ANS)
MAX = MIN + pro

print(max(MIN, 1), MAX)


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

using namespace std;

int main(){
        string s1, s2, res;
        cin>>s1>>s2;
        for(int i=0;i<min((int)s1.size(), (int)s2.size());i++){
                res+=s1[i];
                res+=s2[i];
        }
        if(s1.size()-s2.size()==1){
                res+=s1[s1.size()-1];
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    //    std::ios_base::sync_with_stdio(false);
    //    cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    stack<char>st;
    string ans = "";
    rep(i,n){
        if(s[i] == '('){
            st.push('(');
            ans.push_back('(');
        } else {
            if(st.empty())ans = "(" + ans;
            else st.pop();
            ans.push_back(')');
            
        }
    }
    while(!st.empty())st.pop(),ans.push_back(')');
    cout << ans << endl;
}




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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;
const double EPS = 1e-10;

double cross(P a, P b) {
    return imag(conj(a) * b);
}

double dot(P a, P b) {
    return real(conj(a) * b);
}

struct L {
    P a, b, v;
    L(){}
    L(P _a, P _b) {a = _a, b = _b, v = b - a;}
    L(double _ax, double _ay, double _bx, double _by) {
        a = P(_ax, _ay), b = P(_bx, _by), v = b - a;
    }
};

// +1: counter-clockwise
// -1: clockwise
// +2: online_back
// -2: online_front
// 0: on_segment
int ccw(P p0, P p1, P p2) {
    if (cross(p1 - p0, p2 - p0) > 0) return +1;
    if (cross(p1 - p0, p2 - p0) < 0) return -1;
    if (dot(p1 - p0, p2 - p0) < 0) return +2;
    if (dot(p0 - p1, p2 - p1) < 0) return -2;
    return 0;
}

bool intersectSS(L l1, L l2) {
    return (ccw(l1.a, l1.b, l2.a) * ccw(l1.a, l1.b, l2.b) <= 0 &&
            ccw(l2.a, l2.b, l1.a) * ccw(l2.a, l2.b, l1.b) <= 0);
}

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

    int q;
    cin >> q;
    while (q--) {
        double v[4][2];
        rep(i, 4) rep(j, 2) cin >> v[i][j];
        L l1(v[0][0], v[0][1], v[1][0], v[1][1]);
        L l2(v[2][0], v[2][1], v[3][0], v[3][1]);
        cout << intersectSS(l1, l2) << endl;
    }

}

Measured memory_bytes: 3268
#include <stdio.h>
int main(void)
{
	int i,n,m;
	char array[256];
	char a[2];
	char b[2];
	char input[2];
	while(1)
	{
		for(i=0;i<256;i++)
		{
			array[i] = i;
		}
		scanf("%d",&n);
		if(n == 0)return 0;
		for(i=0;i<n;i++)
		{
			scanf("%s %s",a,b);
			array[a[0]] = b[0];
		}
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%s",input);
			printf("%c",array[input[0]]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 576
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
visited = Array.new(n,-1)
count = 0
nextplace = a[0]
visited[0] = 0
now = 1
while visited[nextplace-1] == -1
  count += 1
  now = nextplace
  if count == k
    puts now
    exit
  end
  visited[nextplace-1] = count
  nextplace = a[nextplace-1]
end
loop = count + 1 - visited[nextplace-1]
rest = (k-count)%loop
while rest != 0
  now = nextplace
  nextplace = a[nextplace-1]
  rest -= 1
end
puts now

Measured memory_bytes: 30192
#include <stdio.h>

int main(){
    char m[4][4];
    for(int i = 0; i < 3; ++i)
        scanf("%s", m[i]);

    for(int i = 0; i < 3; ++i){
        printf("%c", m[i][i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}




int main(){
  int N;
  cin>>N;
  int A[N+2];
  A[0]=0;
  for(int i=1;i<N+1;i++){
    cin>>A[i];
  }
  A[N+1]=0;
  int sum=0;
  for(int i=0;i<N+1;i++){
    sum+=abs(A[i]-A[i+1]);
  }
  for(int i=1;i<N+1;i++){
    cout<<sum+abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])<<endl;
  }
  
  


}



Measured memory_bytes: 1664
import Control.Monad

main :: IO ()
main = do
  [n, x] <- map read . words <$> getLine
  ms <- replicateM n readLn
  print $ solve x ms

solve :: Int -> [Int] -> Int
solve x ms = (p `div` q) + r
  where
    p = x - sum ms
    q = minimum ms
    r = length ms


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  //string a,b,c,d;cin>>a>>b>>c>>d;
  char o;cin>>o;
  if(o=='a'||o=='i'||o=='u'||o=='e'||o=='o'){
    cout << "vowel";
  }else{
    cout << "consonant";
  }
}


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

using namespace std;

int main(){
	double r;
	cin>>r;
	long double a,b;
	a= r*r*M_PI;
	b= 2*r*M_PI;
	cout<<fixed<<setprecision(5)<<a<<' ';
	cout<<fixed<<setprecision(5)<<b<<endl;
} 


Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1e18
vector<ll> v;

void primeFactors(ll n)
{
    // Prll the number of 2s that divide n
    while (n % 2 == 0)
    {
        //cout << 2 << " ";
        v.push_back(2);
        n = n / 2;
    }

    // n must be odd at this poll. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, prll i and divide n
        while (n % i == 0)
        {
            
            v.push_back(i);
            n = n / i;
        }
    }
    if (n > 2)
        v.push_back(n);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    if (n == 1)
    {
        cout << "0\n";
        exit(0);
    }
    primeFactors(n);
    map<ll, ll> m;
    for (ll i = 0; i < v.size(); i++)
    {   
        m[v[i]]++;
    } 
    vector<ll> sum;
    ll count = 0;
    for (ll i = 1;; i++)
    {
        count = count + i;
        sum.push_back(count);
        if (count > 1e12)
            break;
    }
    ll ans = 0;
    for (auto i : m)
    {
        ll var = upper_bound(sum.begin(), sum.end(), i.second) - sum.begin();
        ans = ans + var;
    }
    cout << ans << "\n";

    return (0);
}

Measured memory_bytes: 19704
listA=[]
import collections 
for i in range(3):
    B = list(map(int,input().split()))
    listA.append(B[0])
    listA.append(B[1])
listA=collections.Counter(listA)
listA = listA.most_common()
if listA[0][1] == 2 and listA[1][1] == 2 and listA[2][1] == 1 and listA[3][1] == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define X first
#define Y second
#define pb push_back

void solve();

int main() {
    // freopen("schools.in", "r", stdin);
    // freopen("schools.out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0);
	int t;
	// cin >> t;
	t = 1;	
	while(t--) solve();
	return 0;
}

ll k, a, b;

void solve() {
	cin >> k >> a >> b;
	if (a >= b) {
		cout << k + 1 << '\n';
		return;
	}
	if (a + 1 > k) {
		cout << k + 1 << '\n';
		return;
	}
	ll ans = k + 1;
	k -= a + 1;
	cout << max({ans, b + (k / 2) * (b - a) + k % 2}) << '\n';
}

Measured memory_bytes: 256
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn f(n: i64, r: i64) -> i64 {
    let mut m = n;
    let mut s = 0;
    while m > 0 {
        s += m % r;
        m /= r;
    }
    s
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i64 = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = n;
    for i in 0..n + 1 {
        ans = min(ans, f(i, 6) + f(n - i, 9));
    }
    println!("{}", ans);
}


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

#define MOD 1000000007

int N, M;
long long dp[100005];
bool a[100005];

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int b;
    cin >> b;
    a[b] = true;
  }

  dp[0] = 1;
  dp[1] = (!a[1]) ? 1 : 0;

  for (int i = 2; i <= N; i++) {
    if (!a[i]) dp[i] = (dp[i-1] + dp[i-2]) % MOD;
  }

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


Measured memory_bytes: 1152
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int a = Integer.parseInt(br.readLine());
        
        out.println(a + a * a + a * a * a);
        out.close();
        
    }
}


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

using namespace std;

const int N = 300 * 300 + 10;
typedef pair<int, int>	pii;
int suf[N];
int d;
pii p[N];

int main (){
	int n, m;

	cin >> n >> m >> d;

	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			int x;

			cin >> x;

			p[x] = make_pair(i, j);
		}
	}

	int q;

	for(int i = n * m - d ; i >= 1 ; i--){
		suf[i] = abs(p[i].first - p[i + d].first) + abs(p[i].second - p[i + d].second) + suf[i + d];
	}

	cin >> q ;

	while(q--){
		int l, r;

		cin >> l >> r;

		cout << suf[l] - suf[r] << '\n';
	}

	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<math.h>
#include <stdlib.h>

int main(){
	int a[10], b[10], ah[3], bh[3], as, bs, i, j, store;
	as = 0;
	bs = 0;
	for(i = 0; i < 10; i++){
		scanf("%d", &a[i]);
	}
	for(i = 0; i < 10; i++){
		scanf("%d", &b[i]);
	}
	for(i = 0; i < 3; i++){
		ah[i] = 0;
		bh[i] = 0;
	}
	for(i = 0; i < 3; i++){
		for(j = 0; j < 10; j++){
			if(ah[i] < a[j]){
				store = ah[i];
				ah[i] = a[j];
				a[j] = store;
			}
			if(bh[i] < b[j]){
				store = bh[i];
				bh[i] = b[j];
				b[j] = store;
			}
		}
	}
	for(i = 0; i < 3; i++){
		as += ah[i];
		bs += bh[i];
	}
	printf("%d %d\n", as, bs);
	return 0;
}

Measured memory_bytes: 596
#pragma warning (disable:4996)
#include"bits/stdc++.h"
#include<cassert>
#define int long long
#define MRE assert(0);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

struct BIT {
	int N; vector<int> bit;
	void init(int n) {
		N = n;
		bit.resize(n + 1);
	}
	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i&-i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= N) {
			bit[i] += x; i += i&-i;
		}
	}
};
BIT B[26];
signed main() {
	int n, q; string s; cin >> n >> s >> q;
	rep(i, 26)B[i].init(n+1);
	rep(i, n) {
		B[s[i] - 'a'].add(i + 1, 1);
	}
	rep(X, q) {
		int qk; cin >> qk;
		if (qk == 1) {
			int a; char c; cin >> a >> c; a--;
			B[s[a] - 'a'].add(a + 1, -1);
			s[a] = c;
			B[s[a] - 'a'].add(a + 1, 1);
		}
		else {
			int l, r; cin >> l >> r;
			int cnt = 0;
			rep(i, 26) {
				if (B[i].sum(r) - B[i].sum(l - 1))cnt++;
			}
			cout << cnt << endl;
		}
	}
}

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

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           (int)1e9

typedef   pair<int,int> P;

int main() {

	int n,a;
	scanf("%d%d",&n,&a);
	printf(a>=(n%500)?"Yes\n":"No\n");
}




Measured memory_bytes: 256
program main;
var
m, n, i, total, count : integer;
a : array[1..1000] of integer;

begin
	read(n, m);
    total := 0;
    for i := 1 to n do begin
    	read(a[i]);
        total := total + a[i];
    end;
    
    
    count := 0;
    
    for i := 1 to n do begin
        if (a[i]/total) >= (1/(4*m))
            then count := count + 1
    end;
    if count >= m 
        then writeln('Yes')
            else writeln('No');
end.

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

//int _; 

int n,ans[11]={0,3,14,39,84,155,258,399,584,819,1110};

int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	printf("%d\n",ans[n]);
	return 0;
}





Measured memory_bytes: 3776
#include<stdio.h>
long long int gcd(long long int a, long long int b)
{
    if(a%b == 0)
    {
        return b;
    }else
    {
        return gcd(b, a%b);
    }
}
long long int lcm(long long int a,long long int b)
{
    return a*b / gcd(a, b);
}
int main(void)
{
    long long int a,b,x;
    scanf("%lld %lld",&a,&b);
    x = lcm(a,b);
    printf("%lld\n",x);
    return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B = MAP()

print(max(A+B, A-B, A*B))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string S,T,U;
  int H,A;
  
  cin >> H >>A;
  if(H%A != 0)cout << H/A+1 << endl;
  else cout << H/A<< endl;
  }



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

int main(int argc, char *argv[]){
  int n;
  int a_add_b[2001] = {0};
  
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a_add_b[i + j]++;
    }
  }
  
  while(scanf("%d", &n) != EOF){
    long long int  ans = 0;
    for (int i = 0; i <= 2000; i++) {
      if(0 <= n - i && n - i <= 2000)
        ans += a_add_b[i] * a_add_b[n - i];
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

template<typename T>
void p(T elem) {cout << elem << endl;}
template<typename T>
void ps(vector<T>& arr) { for(T e: arr) p(e); }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

int main(void) {
    string str;
    cin >> str;
    int len = str.length();
    vector<int> lefts;
    vector<int> rights;
    for(int i = 0; i < len; i++) {
        if(str[i] == 'L') {
            lefts.push_back(i);
        } else if(str[i] == 'R') {
            rights.push_back(i);
        }
    }

    vector<int> map(len);
    for(int i = 0; i < len; i++) {
        int res = 0;
        if(str[i] == 'L') {
            auto pos = lower_bound(rights.begin(), rights.end(), i);
            // maximum
            res = *(pos-1);
            if(abs(i-res)%2) res++;
            map[res]++;
        } else {
            // minimum
            auto pos = lower_bound(lefts.begin(), lefts.end(), i);
            res = *pos;
            if(abs(i-res)%2) res--;
            map[res]++;
        }
        debug("%d -> %d\n", i, res);
    }
    for(int i = 0; i < len; i++) {
        cout << map[i];
        cout << ((i == len-1) ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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 namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep (i, N) {
    cin >> A[i] >> B[i];
  }

  ll sum = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (A[i] == 0) continue;
    ll tmp = A[i] + sum;
    if (tmp < B[i]) {
      sum += B[i] - tmp;
    } else if (tmp % B[i] != 0){
      ll x = (tmp - tmp % B[i]) + B[i];
      sum += x - tmp;
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4796
#include <iostream>
#include <string>
#include <cmath>
#include<iomanip>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
  	if (k <= 1) {
      cout << 1 << endl;
      return(0);
    }
  	double a = 0;
  	if (n >= k) {
      a = n - k + 1;
    }
    int b = a;
  	double c = n;
	int d = 2;
  	while (1) {
      int x = (k + 1) / 2;
      if (n >= x) {
        int w = n - x + 1;
	    a = (a * 2) + (w - b);
        b = w;
      }
      c *= 2;
      d *= 2;
      if (x <= 1) {
        break;
      }
      k = x;
    }
  
    std::cout<<std::fixed<<std::setprecision(10);
  	cout << a / c << endl;
	return(0);
}


Measured memory_bytes: 256