akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = 1ll << 62;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
//#define pi 3.14159265358979323846
#define pc putchar
#define gc getchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
//char __wzp[1<<15|1],*__S=__wzp+32768;
//#define gc() (__S>=__wzp+32768?(__wzp[fread(__wzp,sizeof(char),1<<15,stdin)]=EOF),*((__S=__wzp)++):*(__S++))
#define rd read
#define mem(x,v) memset(x,v,sizeof(x))
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
int n,a[200005],b;
ll ans = 0;
int main(){
	n = rd();
	Rep(i,1,n) a[i] = rd() - i;
	sort(a+1,a+1+n);
	b = a[(n+1)/2];
	Rep(i,1,n){
		ans += abs(a[i] - b);
	}
	printf("%lld\n",ans);
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int l;
  cin >> l;
  
  int n = 20;
  
  vector<int> u, v, w;
  for(int i = 1; i < 20; i++){
    u.emplace_back(i);
    v.emplace_back(i + 1);
    w.emplace_back(0);
  }
  
  int next = 1;
  
  int boundary = 1;
  while(true){
    if(pow(2, boundary + 1) - 1 < l) boundary++;
    else break;
  }
  for(int i = 1; i <= boundary; i++){
    u.emplace_back(i);
    v.emplace_back(i + 1);
    w.emplace_back(pow(2, i - 1));
  }
  
  next = pow(2, boundary);
  
  while(next != l){
    int dif = l - next;
    boundary = 0;
    while(true){
      if(pow(2, boundary + 1) - 1 < dif) boundary++;
      else break;
    }
    u.emplace_back(boundary + 1);
    v.emplace_back(20);
    w.emplace_back(next);
    next += pow(2, boundary);
  }
  
  cout << n << " " << u.size() << '\n';
  for(int i = 0; i < u.size(); i++){
    cout << u.at(i) << " " << v.at(i) << " " << w.at(i) << '\n';
  }
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int in(){ int x; scanf("%d", &x); return x; }
int main(){
	int n;
	for(int i = 1;; i++){
		n = in();
		if(n == 0) break;
		printf("Case %d: %d\n", i, n);
	}
	return 0;
}

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = [(Ai, i+1) for i, Ai in enumerate(A)]
    B.sort()
    print(" ".join([str(Bi[1]) for Bi in B]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 24188
#include<stdio.h>


int main (){

  int S[100000],T[50000];
  int s,t,i,j=0,l,r,m=0;
  
  

  scanf("%d",&s);

  for(i=0;i<s;i++)
    scanf("%d",&S[i]);

  scanf("%d",&t);

  for(i=0;i<t;i++)
    scanf("%d",&T[i]);

   for(i=0;i<t;i++){
     l = 0;
     r = s;
     while(l<r){
       m = (l+r)/2;
       if(S[m]==T[i]){
	 j++;
	 break;
       }
       else if(T[i]<S[m])
	 r = m;
       else
	 l = m+1;
     }
   }
    printf("%d\n",j);
  return 0;
}
    



Measured memory_bytes: 2352
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
	int R[MAX],n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> R[i];
	int maxv = -2000000000;
	int minv=R[0];
	for (int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=5e3+5;

int p[maxn],c[maxn];

void cycle(int id, int base, int &turns, int &ans, bool flag = 0){
	if(id == base and flag) return ;
	flag = 1;
	turns++;
	ans += c[p[id]];
	cycle(p[id], base, turns, ans, flag);
}

void get(int id, int turns, int &ans, int curr = 0){
	if(turns <= 0) return ;
	curr += c[p[id]];
	ans = max(ans, curr);
	turns--;
	get(p[id], turns, ans, curr);
}

int32_t main(){
    fast_io;
    int n,k;
    cin>>n>>k;
    for (int i = 0; i < n; ++i)
    {
    	cin>>p[i];
    	p[i]--;
    }
    int ans = -1e18;
    for (int i = 0; i < n; ++i)
    {
    	cin>>c[i];
    	ans = max(ans, c[i]);
    }
    for (int i = 0; i < n; ++i)
    {
    	int temp = 0, turns = 0;
    	cycle(i, i, turns, temp);
    	int d = k / turns;
    	int rem = k % turns;
    	int curr = 0;
    	if(temp >= 0 and d > 1){
    		curr = temp * (d - 1);
    		int value = 0;
    		get(i, rem + turns, value);
    		curr += value;
    	}
    	else{
    		// show("Fdsa");
    		rem = min(n + n, k);
    		curr = -1e18;
    		get(i, rem, curr);
    	}
    	ans = max(ans, curr);
    }
    show(ans);
    return 0;
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
long n,a[100010][4],kq[100010][4],maxx;
main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=3;j++) cin>>a[i][j];
    for (int i=1;i<=n;i++)
    {
        kq[i][1]=max(kq[i-1][2],kq[i-1][3])+a[i][1];
        kq[i][2]=max(kq[i-1][3],kq[i-1][1])+a[i][2];
        kq[i][3]=max(kq[i-1][1],kq[i-1][2])+a[i][3];
    }
    for (int i=1;i<=3;i++)
        maxx=max(maxx,kq[n][i]);
    cout<<maxx;
}



Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

template<typename T>
class DAG{
  private:
    int v;
    std::vector<std::vector<std::pair<int,T>>> to;
    std::vector<int> rank;
    std::vector<T> dp;
  public:
    DAG(int v,const T &x=T(0)):v(v){
        to.resize(v);
        rank.resize(v);
        dp.resize(v,x);
        std::iota(rank.begin(),rank.end(),0);
    }
    void add(int a,int b,const T &c=0){
        to[a].push_back(std::make_pair(b,c));
        if(rank[a]>rank[b]) std::swap(rank[a],rank[b]);
    }
    void set(int i,const T &x){
        dp[i]=x;
    }
    std::vector<T> calc(std::function<T(T,T)> f,std::function<T(ll,T)> h=[](ll a,T b){return b;},std::function<T(T,T)> g = std::plus<T>()){
        std::vector<int> vertex(v);
        std::vector<T> tmp=dp;
        for(int i=0;i<v;++i) vertex[rank[i]]=i;
        for(int i=0;i<v;++i){
            ll sz=to[vertex[i]].size();
            for(const auto &e:to[vertex[i]]){
                tmp[e.first]=f(tmp[e.first],g(h(sz,tmp[i]),e.second));
            }
        }
        return tmp;
    }
};

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> h(N);
    REP(i, N) cin >> h[i];
    DAG<int> D(N,1e9);
    REP(i,N) REP(j,K){
        if(i+j+1<N) D.add(i,i+j+1,llabs(h[i+j+1]-h[i]));
    }
    D.set(0,0);
    cout<<D.calc([](int a,int b){return min(a,b);})[N-1]<<endl;
}


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

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

    Scanner sc = new Scanner(System.in);

    int S = sc.nextInt();
    String T = sc.next();

    System.out.println(S >= 3200 ? T : "red");
  }
}


Measured memory_bytes: 22996
def yaku(n):
    yalu_l = []
    for j in range(1, int(n ** 0.5) + 1):
        if n % j == 0:
            yalu_l.append([n // j, j])
        else:
            continue
    return yalu_l


ans = 10 ** 9

n = int(input())

for i in yaku(n):
    p = len(str(i[0]))
    q = len(str(i[1]))
    ans = min(max(p, q), ans)

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

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

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int n, ave;
	int s[10000];
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> s[i];
		}
		sort(s, s + n);
		ave = 0;
		for(int i = 1; i < n - 1; i++){
			ave += s[i];
		}
		ave /= (n - 2);
		printf("%d\n", ave);
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>

using namespace std;

int ruijou(int n);

int main(){
	
	int table[20],num;
	
	//累乗の末尾の0の個数は5がいくつ入っているかで求められる。ｋｗｓｋはggrks
	for(int i=0;i<14;i++){
		table[i]=ruijou(i);
	}
	
	while(cin>>num,num){
		int a=0,sum=0;
		for(int i=0;table[i]<=num;i++){
			a=num/table[i];
			sum=sum+a;
		}
		cout<<sum<<endl;
	}
}

int ruijou(int n){
	int rai=1;
	for(int i=0;i<=n;i++){
		rai=rai*5;
	}
	return rai;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>

bool check(std::string &T){
    for(int i = 0; i < 3; i++){
        if(T[0] != T[i]){
            return false;
        }
    }
    return true;
}

int main(){
    std::string N;
    std::cin >> N;
    for(int i = 0; i + 2 < 4; i++){
        std::string T = N.substr(i, 3);
        if(check(T)){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
slist = [ss for ss in s]

slen = len(s)
start = 0
count = 0

while True:
    for i in range(start, slen - 1):
        if slist[i] != slist[i+1]:
            slist.pop(i)
            slist.pop(i)
            slen -= 2
            start = max(0, i - 1)
            count += 2
            break
    else:
        break


print(count)


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

typedef long long ll;
const long long INF = 1LL << 60;

ll L,R,r,MIN = INF;
int main(){
  cin >> L >> R;
  if(R-L >= 2019){
    cout << "0" << endl;
    return 0;
  }
  for(ll i = L; i < R; ++i){
    for(ll j = i+1; j <= R; ++j){
      //cout << "i = " << i << " j = " << j << endl;
      //cout << "i * j = " << i*j << endl;
      r = (i*j)%2019;
      //cout << "r = " << r << endl;
      if(r < MIN) MIN = r;
    }
  }
  cout << MIN << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char s[20];
    scanf("%s", s);
    char t[20] = "CODEFESTIVAL2016";
    int i;
    int ans = 0;
    for (i = 0; i < 16; i++)
        if (s[i] != t[i])
            ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  lint pxpymax = -1e9;
  lint pxpymin = 1e9;
  lint pxmymax = -1e9;
  lint pxmymin = 1e9;
  REP(i, N) {
    lint x, y;
    cin >> x >> y;
    chmax(pxpymax, x+y);
    chmin(pxpymin, x+y);
    chmax(pxmymax, x-y);
    chmin(pxmymin, x-y);
  }
  lint ans = 0;
  chmax(ans, pxpymax-pxpymin);
  chmax(ans, pxmymax-pxmymin);
  cout << ans << endl;
}

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

class P
{
    static void Main()
    {
        long[] hw = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long res;
        if ((hw[1] % 3) * (hw[0] % 3) == 0)
        {
            res = 0;
        }
        else
        {
            long[] a = { hw[0] / 3 * hw[1], (hw[0] - hw[0] / 3) * (hw[1] / 2), (hw[0] - hw[0] / 3) * (hw[1] - hw[1] / 2) };
            long[] b = { (hw[0] / 3 + 1) * hw[1], (hw[0] - (hw[0] / 3 + 1)) * (hw[1] / 2), (hw[0] - (hw[0] / 3 + 1)) * (hw[1] - hw[1] / 2) };

            long[] c = { hw[1] / 3 * hw[0], (hw[1] - hw[1] / 3) * (hw[0] / 2), (hw[1] - hw[1] / 3) * (hw[0] - hw[0] / 2) };
            long[] d = { (hw[1] / 3 + 1) * hw[0], (hw[1] - (hw[1] / 3 + 1)) * (hw[0] / 2), (hw[1] - (hw[1] / 3 + 1)) * (hw[0] - hw[0] / 2) };
            //Console.WriteLine($"{a.Max() - a.Min()} {b.Max() - b.Min()} {c.Max() - c.Min()} {d.Max() - d.Min()}");
            res = Math.Min(hw.Select(x => x == 2 ? int.MaxValue : x).Min(), Math.Min(Math.Min(a.Max() - a.Min(), b.Max() - b.Min()), Math.Min(c.Max() - c.Min(), d.Max() - d.Min())));
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 13396
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

class State
{
public:
	int p,c,u;
	State(int p, int c, int u)
	:p(p),c(c),u(u)
	{}
	
	bool operator<(const State& s) const
	{
		return c>s.c;
	}
};

typedef vector<pair<int, int> > Node;

int main()
{
	int c,n,m,s,d;
	while(scanf("%d%d%d%d%d", &c,&n,&m,&s,&d), (c||n||m||s||d))
	{
		Node node[101];
		while(m--)
		{
			int a,b,f;
			scanf("%d%d%d", &a,&b,&f);
			node[a].push_back(make_pair(b,f));
			node[b].push_back(make_pair(a,f));
		}
		
		priority_queue<State> q;
		q.push(State(s,0,0));
		bool v[10][101]={0};
		
		while(!q.empty())
		{
			State S=q.top(); q.pop();
			if(S.p==d)
			{
				printf("%d\n", S.c);
				break;
			}
			if(v[S.u][S.p]) continue;
			v[S.u][S.p]=1;
			
			for(int i=0; i<node[S.p].size(); i++)
			{
				pair<int, int> next=node[S.p][i];
				if(!v[S.u][next.first]) q.push(State(next.first, S.c+next.second, S.u));
				if(S.u!=c)
				{
					if(!v[S.u+1][next.first]) q.push(State(next.first, S.c+next.second/2, S.u+1));
				}
			}
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const int limit=1e5+10;
using edge=struct{int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];
void dfs(int v,int p,ll d){
	depth[v]=d;
	for(auto &e:tree[v]){
		if(e.to==p) continue;
		dfs(e.to,v,d+e.cost);
	}
}
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n-1;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--,b--;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	}

	int q,k;
	cin >> q >> k;
	k--;

	dfs(k,-1,0);
	for(int i=0;i<q;i++){
		int x,y;
		cin >> x >> y;
		x--,y--;
		cout << depth[x]+depth[y] << endl;
	}
	return 0;
}


Measured memory_bytes: 14336
import math

n, k = map(int, input().split())
A = list(map(int, input().split()))

l = 1
r = 10**9+1

while l < r:
    mid = (l+r)//2
    count = 0
    for i in range(n):
        if A[i] > mid:
            count += math.ceil(A[i]//mid)

    if count <= k:
        r = mid
    else:
        l = mid+1


print(l)

Measured memory_bytes: 30976
a, b, c, x, y = map(int, input().split())
ans = 10 ** 9
for cn in range(0, max(x, y) * 2 + 1, 2):
    may = max(0, x - cn // 2) * a + max(0, y - cn // 2) * b + cn * c
    ans = min(ans, may)
print(ans)


Measured memory_bytes: 2940
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3

output:
0 0
1 2
2 2
3 1
4 3
"""

import sys
import heapq as hp

WHITE, GRAY, BLACK = 0, 1, 2


def generate_adj_table(v_table):
    for each in v_table:
        v_index, v_adj_length, *v_adj_list = map(int, each)
        # assert len(v_adj_list) == v_adj_length * 2
        for pair in zip(v_adj_list[::2], v_adj_list[1::2]):
            init_adj_table[v_index][pair[0]] = pair[1]

    return init_adj_table


def dijkstra_path_heap():
    # path search init
    distance[init_vertex] = 0
    path_heap = []
    # heapq: rank by tuple[0], at here it's d[u]
    hp.heappush(path_heap, (0, init_vertex))

    while path_heap:
        current_vertex = hp.heappop(path_heap)[1]

        color[current_vertex] = BLACK

        for adj_vertex, adj_weight in adj_table[current_vertex].items():
            if color[adj_vertex] is not BLACK:
                # alt: d[u] + w[u,v]
                alt_path = distance[current_vertex] + adj_weight
                if alt_path < distance[adj_vertex]:
                    # update path_list
                    distance[adj_vertex] = alt_path
                    # update heap
                    hp.heappush(path_heap, (alt_path, adj_vertex))
                    color[adj_vertex] = GRAY

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    init_vertices_table = map(lambda x: x.split(), _input[1:])
    # assert len(init_vertices_table) == vertices_num

    distance = [float('inf')] * vertices_num
    color = [WHITE] * vertices_num
    init_adj_table = tuple(dict() for _ in range(vertices_num))
    init_vertex = 0

    adj_table = generate_adj_table(init_vertices_table)
    ans = dijkstra_path_heap()
    for i, v in enumerate(ans):
        print(i, v)

Measured memory_bytes: 62900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, k, a[200005];
vector<int> cnt[200002];
ll jump[200005];
ll cycle_cnt = 0;
ll ans[200005];
int ansl = 0;
int chk[200005];
ll step[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> k;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        cnt[a[i]].push_back(i);
    }
    for(int i=1;i<=200000;i++)
    {
        for(int x=0;x<cnt[i].size();x++)
        {
            int nxt = (x == cnt[i].size() - 1 ? cnt[i].front() : cnt[i][x+1]);
            if(nxt == cnt[i][x])
            {
                jump[cnt[i][x]] = n+1;
            }
            else jump[cnt[i][x]] = (nxt-cnt[i][x]+n) % n + 1;
            //cout << "jump " << cnt[i][x] << ' ' << jump[cnt[i][x]] << '\n';
        }

    }

    memset(step, -1, sizeof(step));
    while(step[cycle_cnt % n] == -1)
    {
        step[cycle_cnt % n] = cycle_cnt;
        cycle_cnt += jump[cycle_cnt % n];
    }
    ll offset = step[cycle_cnt % n];
    ll looping = cycle_cnt - step[cycle_cnt % n];

    //cout << offset << ' ' << looping << endl;
    ll target = n * k;
    if(target > offset)
    {
        target -= offset;
        target %= looping;
        target += offset;
    }
    cycle_cnt = 0;
    while(1)
    {
        if(cycle_cnt + jump[cycle_cnt % n] < target)
        {
            cycle_cnt += jump[cycle_cnt % n];
        }
        else break;
    }
    //cout << cycle_cnt << '\n';
    while(cycle_cnt < target)
    {
        if(chk[a[cycle_cnt % n]])
        {
            while(ansl)
            {
                ansl--;
                chk[ans[ansl]]--;
                //cout << "chk " << ans[ansl] << '\n';
                if(ans[ansl] == a[cycle_cnt%n]) break;
            }
        }
        else
        {
            //cout << "add " << a[cycle_cnt % n] << '\n';
            ans[ansl++] = a[cycle_cnt % n];
            chk[a[cycle_cnt % n]]++;
        }
        cycle_cnt++;
    }
    for(int i=0;i<ansl;i++)
        cout << ans[i] << (i+1 != ansl ? " " : "");
}


Measured memory_bytes: 19456
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto K = s[2];

    foreach (i; 0..H+1) {
        foreach (j; 0..W+1) {
            long tmp = i * W + j * H - (i * j) * 2;
            if (tmp == K) {
                writeln("Yes");
                return;
            }
        }
    }

    writeln("No");
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e6 + 5;
char tmp[maxn];
int n;
string s;

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  return true;
}

void solve() {
  for (int i = 0; i < n; i++) {
    s[i]--;
  }
  bool one = false;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      one = true;
      break;
    }
  }
  if (one) {
    for (int i = 0; i < n; i++) {
      if (s[i] == '2') {
        s[i] = '0';
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (((n - 1) & i) == i && s[i] != '0') {
      res ^= 1;
    }
  }
  if (!one) {
    res <<= 1;
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

namespace AtCoderTemplate {
    class Program {
        static void Main (string[] args) {
            var b = Console.ReadLine ();
            char res;
            if (b == "A") {
                res = 'T';
            } else if (b == "T") {
                res = 'A';
            } else if (b == "C") {
                res = 'G';
            } else {
                res = 'C';
            }
            Console.WriteLine (res);
        }
        /* Input & Output*/
        static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }
        static List<int> ReadInts () {
            return Console.ReadLine ().Split (' ').Select (c => int.Parse (c)).ToList ();
        }
        static List<List<int>> ReadColumns (int n) {
            /*
            入力例
            A1 B1
            A2 B2
            ...
            An Bn

            出力例
            [[A1,A2,...,An], [B1,B2,...,Bn]]
            */
            var seq = Enumerable.Range (0, n).Select (i => ReadInts ()).ToList ();
            return Enumerable.Range (0, seq.First ().Count ()).Select (i => seq.Select (items => items[i]).ToList ()).ToList ();
        }
        static void PrintEnum<T> (IEnumerable<T> list) {
            Console.Write (list.First ());
            foreach (var item in list.Skip (1)) {
                Console.Write ($" {item}");
            }
            Console.Write ("\n");
        }
        static void PrintLnEnum<T> (IEnumerable<T> list) {
            foreach (var item in list) {
                Console.WriteLine (item);
            }
        }

        /* Numeric Function */
        static int Fact (int n) {
            return Enumerable.Range (1, n).Aggregate (1, ((i, k) => i * k));
        }
        static int PermNum (int n, int m) {
            if (m > n) {
                return 0;
            }
            return Enumerable.Range (n - m, m + 1).Aggregate (1, ((i, k) => i * k));
        }
        static int CombNum (int n, int m) {
            return PermNum (n, m) / Fact (m);
        }
        // 最大公約数 (m ≧ n)
        static int GCD (int m, int n) {
            if (n == 0) {
                return m;
            } else {
                return GCD (n, m % n);
            }
        }
        // 最小公倍数 (m ≧ n)
        static int LCM (int m, int n) {
            return GCD (m, n) / (m * n);
        }

    }
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int GCD(int u, int v) {
    while (v != 0) {
        int r = u % v;
        u = v;
        v = r;
    }
    return u;
}

int main() {
    int n;
    cin >> n;
    int ret;
    cin >> ret;
    for (int i = 1; i < n; i++) {
        int x;
        cin >> x;
        ret = GCD(ret, x);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll q, a, b, c, d;
	cin >> q;
	rep(i, q) {
		cin >> a >> b >> c >> d;
		bool ans = d>=b;
		if (a < b)ans = false;
		if (ans) {
			if (b <= c)ans	 = true;
			else {
				a %= b;
				ll dif = gcd(b, d);
				if ((b - a - 1) / dif*dif > (c - a))ans = false;
			}
		}
		
		cout << (ans ? "Yes" : "No") << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#define sorn(i, n) char((i == n-1)?'\n':' ')
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;
using P = pair<int, int>;

int main(){
    int h, w; cin >> h >> w;
    int s_i, s_j; cin >> s_i >> s_j;
    s_i--; s_j--;
    int g_i, g_j; cin >> g_i >> g_j;
    g_i--; g_j--;
    char m[h][w];
    bool vis[h][w];
    rep(i, h)rep(j, w){
        cin >> m[i][j];
        vis[i][j] = false;
    }

    deque<pair<P, int>> q;
    q.push_back({{s_i, s_j}, 0});
    while(q.size()){
        int now_i = q.front().first.first, now_j = q.front().first.second;
        int bnum = q.front().second;
        q.pop_front();
        if(vis[now_i][now_j]) continue;
        vis[now_i][now_j] = true;
        if(now_i == g_i && now_j == g_j) {
            cout << bnum << endl;
            return 0;
        }
        for(int di = -2; di <= 2; di++)for(int dj = -2; dj <= 2; dj++) {
            int next_i = now_i + di, next_j = now_j + dj;
            if(0 <= next_i && next_i < h && 0 <= next_j && next_j < w
                && !vis[next_i][next_j] && m[next_i][next_j] == '.'){
                if(abs(di) + abs(dj) <= 1) q.push_front({{next_i, next_j}, bnum});
                else q.push_back({{next_i, next_j}, bnum+1});
            }
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 6028
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

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

const ll mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin >> n >> k;
    ll total = 0;
    for(ll i = k; i<= n+1; i++){
        ll a1 = ((i)*(i-1))/2;
        ll a2 = ((i)*(n+n+1-i))/2;
        a2 -= a1;
        total += a2+1;
        total = total%mod;
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define deb(a) cout << #a << ": " << a << ENDL
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

vi p;
vi c;
lli k, n;

lli f(lli u) {
    if(p[u] == u) {
        if(c[u] < 0) return c[u];
        else return c[u] * k;
    }
    vector<bool> vis(n, false);
    vi path; path.pb(u);
    int st = 0;
    int sti = 0;
    lli prev = 0;
    while(sz(path) <= n + 100) {
        int cur = path.back();
        int nxt = p[cur];
        if(vis[nxt]) {
            st = nxt;
            break;
        }
        else {
            path.pb(nxt);
            vis[nxt] = true;
        }
    }
    lli ans = -1e18;
    if(k < sz(path) - 1) {
        fore(i, 1, k + 1) {
            prev += c[path[i]];
            ans = max(ans, prev);
        }
        return ans;
    }
    fore(i, 1, sz(path)) {
        if(path[i] == st) {
            sti = i;
            break;
        }
        else {
            prev += c[path[i]];
            ans = max(ans, prev);
        }
    }
    vi cycle(sz(path) - sti + 1);
    vi vmxc(sz(cycle));
    lli mxc;
    cycle[0] = 0;
    vmxc[0] = 0;
    if(sti == 1) mxc = -1e18;
    else mxc = 0;
    lli cycleSz = sz(cycle) - 1;
    lli pprev = prev;
    fore(i, sti, sz(path)) {
        pprev += c[path[i]];
        ans = max(ans, pprev);
        int ind = i - sti + 1;
        cycle[ind] = cycle[ind - 1] + c[path[i]];
        mxc = max(mxc, cycle[ind]);
        vmxc[ind] = max(mxc, vmxc[ind - 1]);
    }
    if(cycle.back() < 0) {
        return ans;
    }
    lli kk = k - sti + 1;
    lli rem = kk % cycleSz;
    lli rep = (kk - rem) / cycleSz;
    lli cans;
    if(vmxc.back() > cycle.back() + vmxc[rem]) cans = prev + (rep - 1) * cycle.back() + vmxc.back();
    else cans = prev + rep * cycle.back() + vmxc[rem];
    return max(ans, cans);
}

int main()
{   ///_
    cin >> n >> k;
    p.resize(n); c.resize(n);
    fore(i, 0, n) {cin >> p[i]; --p[i];}
    fore(i, 0, n) cin >> c[i];
    lli ans = f(0);
    fore(i, 1, n) ans = max(ans, f(i));
    cout << ans << ENDL;
    return 0;
}


Measured memory_bytes: 3772
def scan(s):
    m = 0
    a = 0
    for c in s:
        if c == '(':
            a += 1
        elif c == ')':
            a -= 1
        m = min(m, a)
    return m, a


def key(v):
    m, a = v
    if a >= 0:
        return 1, m, a
    else:
        return -1, a - m, a

N = int(input())
S = [input() for _ in range(N)]

c = 0
for m, a in sorted([scan(s) for s in S], reverse=True, key=key):
    if c + m < 0:
        c += m
        break
    c += a

if c == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 171416
#include <stdio.h>

int main() {
    int h, m, s, S;
    scanf("%d", &s);
    h = s/3600;
    m = (s-3600*h)/60;
    S = s-3600*h-60*m;
    printf("%d:%d:%d\n", h, m, S);
    return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define ll long long int
#define INF 0x7fffffff
#define me(a,b) memset(a,b,sizeof(a))
using namespace std;
int main(){
    char a,b;
    cin>>a>>b;
    if(a==b)
        cout<<"="<<endl;
    if(a>b)
        cout<<">"<<endl;
    if(a<b)
        cout<<"<"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,n="CODEFESTIVAL2016";
	int cnt=0;
    cin>>a;
    for(int i=0;i<16;i++){
        if(a[i]!=n[i])
            cnt++;
    }
    cout<<cnt;
    return 0;
}

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

n, p = map(int, input().split())

s = list(input().strip())

if p == 2 or p == 5:
    ans = 0
    while s:
        if p == 2 and int(s.pop()) % 2 == 0 or p == 5 and int(s.pop()) % 5 == 0:
            ans += n
        n -= 1
    print(ans)
    exit()

a = [0] * p

i = 1
k = 0
while s:
    k = (k + int(s.pop()) * i) % p
    a[k] += 1
    i *= 10
    i %= p

ans = a[0]
for i in a:
    if i >= 2:
        ans += i * (i - 1) // 2
print(ans)


Measured memory_bytes: 83300
from sys import stdin
input = stdin.readline

A, B, C = map(int, input().split())
K = int(input())

cnt = 0

while B <= A:
    B *= 2
    cnt += 1

while C <= B:
    C *= 2
    cnt += 1

if cnt <= K:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
s=StoI()
ans=0

for i in groupby(s):
    ans+=1
print(ans)


Measured memory_bytes: 45552
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long

int main(){

	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust"<<endl;
	else cout<<"win"<<endl; 
	return 0;
}


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

int gcd(int x, int y){
  if(y ==0 )
    return x;
  if(x >= y){
    return gcd(y, x%y);
  }
  return 0;
}
int main(){
  int n, m;
  cin>> n >> m;
  cout<<gcd(max(n,m), min(n,m)) <<endl;
  return 0; 
}


Measured memory_bytes: 3112
#include<iostream>
using namespace std;
int main(){
    int N,mult=false;
    cin>>N;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
                if(N==i*j)
               mult=true;

        }
    }
    if(mult)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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

int N, A, B, C;
vector<int> l;

int magic(int i, int a, int b, int c){

    if(i == N){
        if(!(a && b && c)) return 1e9;
        return abs(A - a) + abs(B - b) + abs(C - c);
    }

    int ans = magic(i + 1, a, b, c);
    ans = min(ans, magic(i + 1, a + l[i], b, c) + (a ? 10 : 0));
    ans = min(ans, magic(i + 1, a, b + l[i], c) + (b ? 10 : 0));
    ans = min(ans, magic(i + 1, a, b, c + l[i]) + (c ? 10 : 0));

    return ans;
}

int main(){

    cin >> N >> A >> B >> C;
    l.resize(N);
    for(int i = 0; i < N; i++) cin >> l[i];

    cout << magic(0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,a,b,c=0,d=0;
    
    cin>>n>>a>>b;
    
    if(a<=b) c=a;
    else if(b<a) c=b;
    
    if(n>a+b) d=0;
    else if(n<=a+b) d=(a+b)-n;
    
    cout<<c<<" "<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define fi first
#define se second 
#define pb push_back
#define sci(x) scanf("%d",&(x))
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
const int N=2e5+10,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
char s[15];
int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	bool ok=1;
	if(len&1)ok=0;
	for(int i=1;i<=len;i+=2)
	if(s[i]!='h'){ok=0;}
	for(int i=2;i<=len;i+=2)
	if(s[i]!='i'){ok=0;}
	puts(ok?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
  int i,k,t,end=0,slen,plen,correct=0;
  char s[200]={0};
  char p[200]={0};
  char c[200]={0};
  scanf("%s",s);
  scanf("%s",p);
  slen=strlen(s);
  plen=strlen(p);
  for(i=0;i<slen;i++){
    for(k=0;k<plen;k++){
      if(k==0)t=i+k;
      c[k]=s[t];
      t++;
      if(i+k+1==slen)t=0;
    }
    if(strcmp(c,p)==0){
      correct=1;
    }
  }
  if(correct==1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 2752
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;

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

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

int x=0;

for(int j=0;j<n-1;j++){
  if(w[j][(int)(w[j].length())-1]!=w[j+1][0]){
    x=1;
    break;
  }
}

for(int k=0;k<n;k++){
  int a=0;
  for(int l=0;l<n;l++){
    if(w[k]==w[l]){
      a++;
    }
  }
  if(a!=1){
    x=1;
    break;
  }
}

if(x==0){
cout<<"Yes"<<endl;
}else{
  cout<<"No"<<endl;
}

}
  


Measured memory_bytes: 256
#include<stdio.h>
void trace(int A[],int n ){
	int i;
	for(i=0 ; i<n ; i++){
			if(i > 0) printf(" ");
			printf("%d",A[i]);
	}

    printf("\n");
} 

void insertionSort(int A[],int n){
	int i,j,v;
	for( i=1 ; i<n ; i++){
	 v = A[i];	int j = i-1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
			A[j+1] = v;
		}
		   trace(A,n);
	}
}

int main(){
	int A[1000],n,i;
	scanf("%d",&n);
	for (i = 0 ; i<n ;i++) scanf("%d",&A[i]);
	trace(A,n);
    insertionSort(A,n);


   	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
const int N = 2e5 + 5;
ll a[N],b[N];

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

    ll n,m,k;
    cin>>n>>m>>k;
    for(int i = 1; i<=n ;i++){
        cin>>a[i];
        a[i]+=a[i-1];
    }
    for(int i = 1; i<=m; i++){
        cin>>b[i];
        b[i]+=b[i-1];
    }
    ll ans = 0;
    for(ll i = 0; i<=n; i++){
        if(a[i] > k){
            break;
        }
        ll x = k - a[i];
        ll j = upper_bound(b,b+m+1,x) - b - 1;
        ans = max(ans , i + j);
    }
    cout<<ans;

}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int N,X,T;
  cin >> N >> X >> T;

  cout << ((N-1)/X+1)*T << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin >> a;
    int count = 0;
    for(int i=0; i<4; i++){
        if(a[i]=='+'){
            count++;
        }else{
            count--;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector> 
#include <queue>
#include <limits.h>
#include <algorithm>

using namespace std;

int main(){
int N,K;
vector<int> V;
cin >> N >> K;
for (int i=0;i<N;i++)
{
int a;
cin >> a;
V.push_back(a);
}

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

int min = INT_MAX;
for(int i=0;i<N;i++)
{
if(K+i-1>=N)
break;
if(V[i+K-1]-V[i]<min)
min=V[i+K-1]-V[i];
}
cout << min << endl;
}

Measured memory_bytes: 892
import sys
import math
from itertools import accumulate as acc
import bisect

N=int(input())
x=list(map(int,input().split()))

x.sort()
ans=0
for i in range(2,N):
    for j in range(1,i):
        p=x[i]-x[j]
        if p<x[j]:
            k=bisect.bisect_right(x,p)
            ans+=j-k
print(ans)

Measured memory_bytes: 3188
from fractions import gcd
from functools import reduce
N,X=map(int,input().split())
x=list(map(int,input().split()))
if N == 1:
  print(abs(x[0]-X))
  exit()
x.append(X)
x.sort()
y=[]
for i in range(N):
  y.append(x[i+1]-x[i])
print(reduce(gcd,y))

Measured memory_bytes: 16240
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

vector<int> g[100005];

// cost, index
pair<int, int> dfs(int cur, int prev) {
	pair<int, int> ret(0, cur);
	rep(i, g[cur].size()) {
		int to = g[cur][i];
		if(to == prev) continue;
		pair<int, int> t = dfs(to, cur);
		t.first++;
		if(ret.first < t.first) ret = t;
	}
	return ret;
}

int root = 0;
int parent[20][100005];
int depth[100005];

void dfs2(int v, int p, int d) {
	parent[0][v] = p;
	depth[v] = d;
	rep(i, g[v].size()) {
		if(g[v][i] != p) dfs2(g[v][i], v, d+1);
	}
}

void init(int V) {
	dfs2(root, -1, 0);
	for(int k = 0; k + 1 < 20; k++) {
		rep(v, V) {
			if(parent[k][v] < 0) parent[k + 1][v] = -1;
			else parent[k + 1][v]= parent[k][parent[k][v]];
		}
	}
}

int lca(int u, int v) {
	if(depth[u] > depth[v]) swap(u, v);
	rep(k, 20) {
		if((depth[v] - depth[u]) >> k & 1) {
			v = parent[k][v];
		}
	}
	if(u == v) return u;
	for(int k = 20 - 1; k >= 0; k--) {
		if(parent[k][u] != parent[k][v]) {
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}

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

	rep(i, n-1) {
		int a, b;
		cin >> a >> b;

		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	// cout << "input" << endl;
	// rep(i, n) {
	// 	cout << " i : " << i << " | ";
	// 	rep(j, g[i].size()) cout << g[i][j] << " ";
	// 	cout << endl;
	// }


	P s = dfs(0, -1);
	P t = dfs(s.second, -1);
	// cout << s.second << " " << t.second << endl;

	init(n);

	rep(i, n) {
		int c = lca(i, s.second);
		int a = (depth[i] - depth[c]) + (depth[s.second] - depth[c]);

		int d = lca(i, t.second);
		int b = (depth[i] - depth[d]) + (depth[t.second] - depth[d]);

		cout << 2 * (n - 1) - max(a, b) << endl;
	}

	return 0;
}

Measured memory_bytes: 21132
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S;cin>>S;
    const int L=S.size();
    for(int i=0;i<L;i++){
        if(i%2){
            if(S[i]=='R'){
                cout<<"No"<<endl;return 0;
            }
        }else{
            if(S[i]=='L'){
                cout<<"No"<<endl;return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main()
{
    char S[200001],T[200001];
    int ans=0;

    scanf("%s", S);
    scanf("%s", T);

    for(int i=0; S[i]!='\0'; i++){
        if(S[i]!=T[i]) ans++; 
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2080
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  if(s[n-1]=='0'||s[n-1]=='1'||s[n-1]=='6'||s[n-1]=='8')
  {
    cout <<"pon";
  }
  else if(s[n-1]=='3') cout << "bon";
  else cout << "hon";
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long l, r; cin >> l >> r;
	r = min(r, l + 2019);
	long long ans = 1e18;
	for (long long i = l; i <= r; ++i) 
		for (long long j = i + 1; j <= r; ++j)
			ans = min(ans, (i * j) % 2019);
	cout << ans << '\n';	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


int count_divisor(int n){
  int cnt=0;
  for(int div=1; div <= n; div+=2){
    if(n%div == 0) cnt++;
  }
  return cnt;
}

int main (void)
{
  int n; cin>>n;
  int cnt=0;
  for(int i=105; i<=n; i+=2){
    if(count_divisor(i) == 8) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var A = input[0];
        var B = input[1];
        var C = input[2];
        var D = input[3];

        var i = 0;
        while (A > 0 && C > 0)
        {
            if (i % 2 == 1)
            {
                A -= D;
            }
            else
            {
                C -= B;
            }
            i++;
        }
        Console.WriteLine(A <= 0 ? "No" : "Yes");
    }
}


Measured memory_bytes: 28236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, l;
    cin >> n >> l;

    ll sum = 0;
    rep(i, 1, n+1) sum += l+i-1;    
    
    ll ans = 0, cnt = INF;
    rep(i, 1, n+1) {
        if (abs(cnt) > abs(l+i-1)) {
            ans = (l+i-1);
            cnt = abs(l+i-1);
        }
    }
    cout << sum - ans << endl;
}

Measured memory_bytes: 256