akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Map.Entry;


class Main {

	public static void main(String[] args) {	
		//FastScanner sc = new FastScanner();
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] L = new int[2 * N];
		for(int i = 0; i < 2 * N; i++) {
			L[i] = sc.nextInt();
		}
		Arrays.sort(L);
		int sum = 0;
		for(int i = 0; i < 2 * N; i += 2) {
			sum += L[i];
		}
		System.out.println(sum);
	}
	


	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        if (!hasNext()) throw new NoSuchElementException();
	        long n = 0;
	        boolean minus = false;
	        int b = readByte();
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        if (b < '0' || '9' < b) {
	            throw new NumberFormatException();
	        }
	        while(true){
	            if ('0' <= b && b <= '9') {
	                n *= 10;
	                n += b - '0';
	            }else if(b == -1 || !isPrintableChar(b)){
	                return minus ? -n : n;
	            }else{
	                throw new NumberFormatException();
	            }
	            b = readByte();
	        }
	    }
	    public int nextInt() {
	        if (!hasNext()) throw new NoSuchElementException();
	        int n = 0;
	        boolean minus = false;
	        int b = readByte();
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        if (b < '0' || '9' < b) {
	            throw new NumberFormatException();
	        }
	        while(true){
	            if ('0' <= b && b <= '9') {
	                n *= 10;
	                n += b - '0';
	            }else if(b == -1 || !isPrintableChar(b)){
	                return minus ? -n : n;
	            }else{
	                throw new NumberFormatException();
	            }
	            b = readByte();
	        }
	    }
	}
}


Measured memory_bytes: 10068
/*input
oxxx
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;
string s;
int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>s;
	int i=0,j=s.size()-1;
	while(i<j){
		if(s[i]==s[j]){
			++i,--j;
			continue;
		}
		if(s[i]!='x' && s[j]!='x')
			return cout<<-1,0;
		else if(s[i]=='x'){
			++ans,++i;
		}
		else if(s[j]=='x'){
			++ans,--j;
		}
		else assert(0);
	}
	cout<<ans;
}

Measured memory_bytes: 512
s=gets.chomp.to_s.chars
t = s
k=gets.to_i
array=[]
length=s.length.to_i
l=0
span=0
if s.size < 50
while span < length  do
  while l + span < length do
    array<<s[l..(l+span)].join
    l += 1
  end
  l = 0
  span += 1
end
# puts array.to_s
else
  characters = ('a'..'z').to_a
  cs = 0
  28.times do
    while s.find_index(characters[cs]) != nil do
      l = s.find_index(characters[cs])
      q = s.find_index(characters[cs])
      span = 0
        5.times do
          array<<s[l..(l+span)].join
          span += 1
        end
      s = s[(q+1)..-1]
    end
    s = t
    cs += 1
  end
end
array = array.uniq.sort
puts array[k-1]


Measured memory_bytes: 8572
import math
 
N,M=map(int,raw_input().split())
m=int(math.sqrt(M))+2
 
mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, 10**5+10000):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))
 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:
		return 0
	else:
		return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod
 
ans=1
 
for i in range(2, m):
	cnt=0
	while M%i==0:
		M/=i
		cnt+=1
	ans*=ncr(N+cnt-1,cnt)
	ans%=mod
 
if M!=1:
	ans*=N
	ans%=mod

print ans

Measured memory_bytes: 51612
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


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


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    H, N = read_int_list()
    A = read_int_list()
    res = 'Yes' if sum(A) >= H else 'No'
    print(res)

main()


Measured memory_bytes: 14596
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;

int main() {

    string S,T;
    cin >> S >> T;
    ll out = 0;
    rep(i,3){
        if(S[i] == T[i]) out++;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline().strip()
def LIST(): return list(map(int, input().split()))

def main():
    ans = []
    
    while 1:
        n = int(input())
        if n == 0:
            break
        else:
            a = LIST()
            heikin = sum(a) / n
            tmp = [x for x in a if x <= heikin]
            ans.append(len(tmp))
        
    for x in ans:
        print(x)


if __name__ == '__main__':
    main()



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

int b[100010];

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

    int n;cin>>n;

    for(int i=0;i<n;i++)
    {
        int a;cin>>a;

        b[a]++;
        b[a+1]++;
        b[a+2]++;
    }

    int ans=0;

    for(int i=0;i<100010;i++)ans=max(ans,b[i]);

    cout<<ans<<"\n";

    return 0;
}


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

int main(){
  long long n, a, b;
  cin >> n >> a >> b;
  long long z = n % (a+b);
  long long p = n / (a+b);
  if(z>a){
    cout << a * (p + 1) << endl;
  }else{
    cout << a * p + z << endl;
  }
}


Measured memory_bytes: 256
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

cnt = 0 
for j in range(N):
  i = bisect.bisect_left(A, B[j])
  k = bisect.bisect_right(C, B[j])
  cnt += i * (N - k)
  
print(cnt)

Measured memory_bytes: 23360
from bisect import bisect_left as bl
from bisect import bisect_right as br
n=int(input())
s=sorted(list(map(int,input().split())))
q=0
d=[[""]*(1001)for i in range(1001)]
for i in range(n):
    for j in range(i+1,n):
        x,y=max(s[i],s[j]),min(s[i],s[j])
        if d[x][y]=="":
            c=br(s,x+y-1)-bl(s,x-y+1)-1
            if x-y<y:
                c-=1
            c=max(c,0)
            d[x][y]=c
        q+=d[x][y]
print(q//3)


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

int main() {

    int n;
    long long pairs=0;
    cin >> n;

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

    for (int i=0;i<n-1; i++){
        if (arr[i] % 2 == 0){
          pairs += (long long) arr[i]/2;
        } else {
            pairs += arr[i]/2;
            if (arr[i+1] != 0){
                arr[i+1] = (long long)arr[i+1] + 1;
            }
                
        }
    }

    pairs += (long long) arr[n-1]/2;
    cout << pairs << '\n';
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  int n, k, q; cin >> n >> k >> q; int a, b[n]; fill(b, b+n, 0);
  for(int i=0; i<q; i++) {
    cin >> a; a--; b[a]++;
    //cout << a;
  }
  for(int i=0; i<n; i++) {
    //cout << k - (q - b[i]) << " ";
    if (k - (q - b[i]) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

int main(){
  long long int h; cin >> h;
  int j = 0;
  while(h > 1){
    h = h/2;
    j++;
  }
  long long int ans = 1,nijo = 1;
  for(int i = 1; i <= j; i++){
    ans = ans + nijo*2;
    nijo *= 2;
  }
  cout << ans << endl;
}

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

int main ()
{
    int i,a[1000];
    for(i=0; i<5; i++)
        cin>>a[i];
    for(i=0; i<5; i++)
    {
        if(a[i]!=i+1)
        {
            cout<<i+1<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3560
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();

int main(){
  int l;
  cin>>l;
  double ans=(double)l/3;
  ans=ans*ans*ans;
  cout<<std::setprecision(12) << std::fixed;
  cout<<ans<<"\n";  
}

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

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];

int main(void){

  cin.tie(0);
  ios::sync_with_stdio(false);

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

  if((C >= A) && (C <= B)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    ll h;cin>>h;
    int s = floor(log2(h));
    ll sum = 0;
    ll tmp = 1;
    rep(i,s+1){
        sum+=tmp;
        tmp*=2;
    }
    co(sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N; cin >> N;
  ll ans = 0;
  ll temp = 0;
  rep(i,N) {
    ll person; cin >> person;
    if (person < temp) {
      ans += temp - person;
    }
    else temp = person;

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

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define for1(i,l,r) for(int i=(l);i<(r);i++)
#define for2(i,l,r) for(int i=(l);i>(r);i--)
using namespace std;
long long queries,a,b;
signed main(){
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>queries;
	while(queries--){
		cin>>a>>b;
		if(a==b){
			cout<<2*(a-1)<<endl;
			continue;
		}
		long long tmp=sqrt(a*b);
		if(tmp*tmp==a*b) tmp--;
		if(tmp*(tmp+1)<a*b) cout<<2*tmp-1<<endl;
		else cout<<2*tmp-2<<endl;
	}
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class hello
{
    public static int n, r;
    public static string s0;
    public static Dictionary<char, int> d;
    public static void Main()
    {
        s0 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX";
        d = new Dictionary<char, int>();
        for (int i = 0; i < 50; i++) d[s0[i]] = i;
        string line0;
        for (; (line0 = Console.ReadLine()) != null;)
        {
            string[] line = line0.Trim().Split(' ');
            n = int.Parse(line[0]);
            r = int.Parse(line[1]);
            line = Console.ReadLine().Trim().Split(' ');
            var c = Array.ConvertAll(line, int.Parse);
            getAns(c);
        }
    }
    static void getAns(int[] c)
    {
        var s = s0.Substring(0, n);
        for (int i = 0; i < r; i++) s = shuffle(s, c[i]);
        Console.WriteLine(d[s[n - 1]]);
    }
    static string shuffle(string s, int c)
    {
        var aL = (n + 1) / 2;
        var bL = n - aL;
        var a = s.Substring(bL);
        var b = s.Substring(0, bL);
        var imax = bL / c;
        var ns = "";
        for (int i = 0; i < imax; i++)
        {
            ns += a.Substring(i * c, c);
            ns += b.Substring(i * c, c);
        }
        ns += a.Substring(imax * c);
        ns += b.Substring(imax * c);
        return ns;
    }
}



Measured memory_bytes: 14084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

const int MAX_V = 510;
int V; //????????°
struct edge { int to, cap, cost, rev; };
vector<edge> G[MAX_V];
int dist[MAX_V]; //???????????¢
int prevv[MAX_V], preve[MAX_V];
void add_edge(int from, int to, int cap, int cost) { // from->to????????????cap,?????????cost???????????????
	G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
	G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}
// s??????t????????????f???????°??????¨???????±??????? ??????????????´??????-1
int min_cost_flow(int s, int t, int f) {
	int res = 0;
	while(f > 0) {
		fill(dist, dist + V, INF);
		dist[s] = 0;
		bool update = true;
		while(update) {
			update = false;
			for (int v = 0; v < V; ++v){
				if(dist[v] == INF)continue;
				for (int i = 0; i < G[v].size(); ++i){
					edge &e = G[v][i];
					if(e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;
						preve[e.to] = i;
						update = true;
					}
				}
			}
		}
		if(dist[t] == INF) return -1;
		
		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main(void) {
	int v, E, F;
	cin >> v >> E >> F;
	V = v;
	rep(i, E) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		add_edge(a, b, c, d);
	}
	int ans = min_cost_flow(0, v - 1, F);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3300
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { min(p, o.p) };
        }
        pair<int, int> p;
    };

    SegmentTree(int n) : e({ { n * 2 + 1, -1 } }), n(n) {
        for (m = 2; m < n; m *= 2); // m >= n
        t = vector<Node>(m + n + n % 2, e);
    }
    Node *data() {
        return &t[m];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) {
            t[i] = t[i * 2] * t[i * 2 + 1];
        }
    }
    const Node& root() const {
        return t[1];
    }
    void update(int i, const Node& o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) const {
        Node o[2] = { e, e };
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o[1] = t[--r] * o[1];
            if (l & 1) o[0] = o[0] * t[l++];
        }
        return o[0] * o[1];
    }
    void print() {
        for (int j = 1; j <= m; j *= 2) {
            int k = min(j * 2, m + n);
            for (int i = j; i < k; i++) {
                cout << t[i].p.first << ',' << t[i].p.second << " \n"[i == k - 1];
            }
        }
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

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

    int n;
    cin >> n;

    SegmentTree st[2] = { n / 2, n / 2 };
    for (int i = 0; i < n; i++) {
        auto& p = st[i % 2].data()[i / 2].p;
        cin >> p.first;
        p.second = i;
    }
    for (int j = 0; j < 2; j++) {
        st[j].build();
    }

    using A = array<int, 4>;
    priority_queue<A, vector<A>, greater<>> q;
    auto& p = st[0].root().p;
    q.push({ p.first, p.second, 0, n });

    for (int i = 0; i < n; i += 2) {
        auto a = q.top(); q.pop();
        cout << a[0] << ' ';
        int j = a[1] % 2;
        st[j].update(a[1] / 2, st[j].e);

        auto p = st[j ^ 1].query((a[1] + 1) / 2, (a[3] + 1) / 2).p;
        cout << p.first << " \n"[i == n - 2];
        if (p.second <= a[1]) {
            cout << a[1] << ' ' << a[3] << endl;
            cout << p.first << ' ' << p.second << endl;
        }
        st[j ^ 1].update(p.second / 2, st[j ^ 1].e);

        auto f = [&](int l, int r) {
            if (l == r) return;
            auto p = st[l % 2].query(l / 2, r / 2).p;
            q.push({ p.first, p.second, l, r });
        };
        f(a[2], a[1]);
        f(a[1] + 1, p.second);
        f(p.second + 1, a[3]);
    }

    return 0;
}

Measured memory_bytes: 5876
h, w = map(int, input().split())
A = [input() for i in range(h)]
cnt = 0
for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            cnt += 1
if cnt == w + h - 1:
    print('Possible')
else:
    print('Impossible')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
struct tree
{
	int addv[770001],maxv[770001];
	void build(int o,int l,int r,int n)
	{
		if(l==r){maxv[o]=-(n-l+1);return;}
		int m=(l+r)/2;
		build(o*2,l,m,n);
		build(o*2+1,m+1,r,n);
		maxv[o]=max(maxv[o*2],maxv[o*2+1]);
	}
	void add(int o,int d){addv[o]+=d;maxv[o]+=d;}
	void pushdown(int o,int l,int r)
	{
		if(l==r||!addv[o])return;
		add(o*2,addv[o]);
		add(o*2+1,addv[o]);
		addv[o]=0;
	}
	void add(int x,int y,int d,int o,int l,int r)
	{
		if(x<=l&&r<=y)return add(o,d);
		pushdown(o,l,r);
		int m=(l+r)/2;
		if(x<=m)add(x,y,d,o*2,l,m);
		if(y>m)add(x,y,d,o*2+1,m+1,r);
		maxv[o]=max(maxv[o*2],maxv[o*2+1]);
	}
	int query(int x,int y,int o,int l,int r)
	{
		if(x<=l&&r<=y)return maxv[o];
		pushdown(o,l,r);
		int m=(l+r)/2,ans=0;
		if(x<=m)ans=max(ans,query(x,y,o*2,l,m));
		if(y>m)ans=max(ans,query(x,y,o*2+1,m+1,r));
		return ans;
	}
}T;
int n,m;
vector<int> v[330001];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,l,r;i<=n;i++)scanf("%d%d",&l,&r),v[l].push_back(r);
	T.build(1,0,m+1,m);
	int ans=n-m;
	for(int i=0;i<=m;i++)
	{
		for(int j:v[i])T.add(0,j,1,1,0,m+1);
		ans=max(ans,T.query(i+1,m+1,1,0,m+1)-i);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
 
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
struct UnionFind {
	vector<int> par, rank;
 
	UnionFind(int n) : par(n, -1), rank(n, 0) { }
	void init(int n) { par.assign(n, -1), rank.assign(n, 0); }
 
	int root(int x) {
		if (par[x] == -1) return x;
		else return par[x] = root(par[x]);
	}
 
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
 
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y);
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		return true;
	}
};
 
int main() {
	ll N, K;
	cin >> N >> K;
  	vector<ll> h(N);
  	rep(i, N) cin >> h[i];
  	vector<ll> dp(N);
  	rep(i,N) dp[i] = INF;
  	dp[0] = 0;
  	REP(i, 1, N){
      REP(j, 1, K + 1) {
        if(i >= j) chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
      }
    }
	
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
    int h,w;
    int bh,bw;
    int m;
    int ans;
  
    scanf("%d",&h);
    scanf("%d",&w);
    scanf("%d",&bh);
    scanf("%d",&bw);

    m=h*w;
    ans=m-(h*bw)-(w*bh)+(bh*bw);
    printf("%d",ans);

  return 0;
}


Measured memory_bytes: 128
use std::io::{stdout, Write, BufWriter};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn trivial_division(n: usize) -> Vec<usize> {
    let mut result = n;
    for i in 2..((n as f64).sqrt() as usize)+1 {
        if n % i == 0 {
            result = i;
            break;
        }
    }

    if result == n {
        return vec![n];
    } else {
        let mut v1 = vec![result];
        let mut v2 = trivial_division(n / result);

        v1.append(&mut v2);

        return v1;
    }
}

use std::collections::HashSet;
fn main() {
    input!{
        n: usize,
        p: usize,
    }

    let sosus = trivial_division(p);
    let unique: HashSet<usize> = sosus.clone().into_iter().collect();

    let mut ans = 1;
    for sosu in unique {
        let kosu = sosus.iter().filter(|&&e| e == sosu).count() / n;
        ans = ans * sosu.pow(kosu as u32);
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    writeln!(out, "{}", ans).unwrap();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 998244353;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

mint dp[3005][3005];
map<int, int> mp[3005];

int main(){
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    dp[0][0] = mint(1);

    rep(i, n) rep(j, s+1) {
        dp[i+1][j] += dp[i][j]*2;
        if (j+a[i]<=s) {
            dp[i+1][j+a[i]] += dp[i][j];
        }
    }
    /*
    mp[0][0]++;
    rep(i, n) {
        rep(j, n) {
            if (mp[j].size()==0) continue;
            for (auto m: mp[j]) {
                if (m.first+a[i]>s) continue;
                mp[j+1][m.first+a[i]] += mp[j][m.first];
                //debug(m.first+a[i]);
            }
            //debug(j);
        }
    }
    */
/*
    mint ans = 0;
    rep(i, n+1) {
        ll num = mp[i][s];
        if (num==0) continue;
        debug(num);
        ans += mint(2).pow(n-i) * num;
    }
    */
    mint ans = dp[n][s];
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 74332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;

int x,y;
int a[15];

int main(){
 
cin>>x>>y;

a[4]=1; a[6]=1; a[9]=1; a[11]=1; a[2]=2;

if(a[x]==a[y]) puts("Yes");
else puts("No");

}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n,k;cin>>n>>k;

  int res=1;
  ll t = k;
  while(1){
    if(t>n)break;
    t *= k;
    res++;
  }
  cout<<res<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n;
	int a[200010];
	cin >> n;
	rep(i, n) cin >> a[i];
	if(n%2==0)
	{
		rep(i, n/2)
		{
			cout << a[n-1-2*i] << " ";
		}
		rep(i, n/2)
		{
			cout << a[2*i];
			if(i!=n/2-1) cout << " ";
			else cout << endl;
		}
	}
	else if(n>1)
	{
		rep(i, 1+n/2)
		{
			cout << a[n-1-2*i] << " ";
		}
		rep(i, n/2)
		{
			cout << a[2*i+1];
			if(i!=n/2-1) cout << " ";
			else cout << endl;
		}
	}
	else cout << a[0] << endl;
	return 0;
}

Measured memory_bytes: 2944
#D
N=int(input())
N_C=N
P={}
for i in range(2,10**6+1):
    if N%i==0:
        P[i]=0
        while True:
            N=N/i
            P[i]+=1
            if N%i!=0:
                break
    if N==1:
        break
if N_C==1:
    print(0)
elif P=={}:
    print(1)
else:
    ans=0
    for key,v in P.items():
        z=key**v
        L=[0]+[True for i in range(v)]
        for i in range(1,v+1):
            if L[i]:
                if z%(key**i):
                    break
                z=z/(key**i)
                L[i]=False
                ans+=1
    if N!=1:
        ans+=1
    print(ans)

Measured memory_bytes: 63460
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		scanner.close();
		int l = str.length();
		if (l <= 1) {
			System.out.println(str);
			return;
		}
		
		List<Long> strList = 
				Stream
					.of(str.split(""))
					.map(s -> Long.parseLong(s))
					.collect(Collectors.toList());
		
		int gaps = l - 1;
		
		Long result = 0L;
		
		for (int bit = 0; bit < (1 << gaps); bit++) {
			ArrayList<Long> digits = new ArrayList<Long>(); 
			Long temp = strList.get(0);
			for (int i = 0; i < gaps; i ++) {
				if((bit & (1 << i)) != 0) {
					digits.add(temp);
					if (i < strList.size()) {
						temp = strList.get(i + 1);
					} else {
						temp = null;
					}
				} else {
					temp = 10 * temp + strList.get(i+1);
				}
			}
			if (temp != null) digits.add(temp);
			result += digits.stream().mapToLong(v -> v).sum();
		}
		System.out.println(result);
	}

}

Measured memory_bytes: 28624
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};

signed main() {
	int n;
	while (scanf("%d", &n)) {
		if (!n)
			break;

		vector<vector<bool>> m(5001,vector<bool>(5001));
		vector<pii> st;
		REP(i, n) {
			int x, y;
			scanf("%d %d", &x, &y);
			m[x][y] = 1;
			st.push_back({ x,y });
		}
		sort(ALL(st));
		int ans = 0;
		REP(i, n) {
			rep(j, i + 1, n) {
				pii sa = { st[j].first - st[i].first, st[j].second - st[i].second };
				bool f = 0;
				pii nex = { st[j].first+sa.second, st[j].second-sa.first };
				pii nexx = { nex.first- sa.first, nex.second - sa.second };
				if (RANGE(nex.first, 0, 5000) && RANGE(nex.second, 0, 5000) && RANGE(nexx.first, 0, 5000) & RANGE(nexx.second, 0, 5000)) {
					if (m[nex.first][nex.second] && m[nexx.first][nexx.second]) {
						ans = max(ans, PW(sa.first)+ PW(sa.second));
					}
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

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

#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
}c(200005);


//m^n
mint f(int m, int n) {
	if (0 == n) {
		return 1;
	}
	mint x = f(m, n / 2);
	x *= x;
	if (1 == n % 2) {
		x *= (mint)m;
	}
	return x;
}
// nCa
mint choose(int n, int a) {
	mint x = 1;
	mint y = 1;
	for (int m = 0; m < a; ++m) {
		x *= (mint)(n - m);
		y *= (mint)(a - m);
	}
	return x / y;
}

int main() {
	int X,Y;
	cin >> X>>Y;
	int a3 = 2 * Y - X;
	int b3 = 2 * X - Y;
	if (0 != a3%3 || a3 < 0) {
		cout << 0 << endl;
		return 0;
	}	
	if (0 != b3 % 3 || b3 < 0) {
		cout << 0 << endl;
		return 0;
	}
	int a = a3 / 3;
	int b = b3 / 3;
	cout << choose(a+b,a)<<  endl;

	return 0;
}

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

using namespace std;

namespace {

    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    ll to_i(const string& s) {
        istringstream is(s);
        ll n; is >> n;
        return n;
    }

    string s;
    bool valid;

    map< char, map<ll, ll> > M;
    map< char, ll > L;
    
    const string E = "ERROR";

    ll num(int& i) {
        assert(isdigit(s[i]));
        string n;
        while (i < s.size() && isdigit(s[i])) {
            n.push_back(s[i]);
            i++;
        }
        return to_i(n);
    }
    ll expr(int& i) {
        if (isdigit(s[i])) {
            return num(i);
        } else {
            char name = s[i++];
            assert(s[i] == '[');
            i++;
            ll v = expr(i);
            assert(s[i] == ']');
            i++;
            if (not M.count(name)) throw E;
            if (not M[name].count(v)) throw E;
            return M[name][v];
        }
    }
    void decl(int& i) {
        char name = s[i++];
        assert(s[i] == '[');
        i++;
        ll len = expr(i);
        assert(s[i] == ']');
        i++;
        L[name] = len;
    }
    void assign(int& i) {
        char name = s[i++];
        if (not L.count(name)) throw E;
        assert(s[i] == '[');
        i++;
        ll index = expr(i);
        assert(s[i] == ']');
        i++;
        assert(s[i] == '=');
        i++;
        ll v = expr(i);
        assert(i == s.size());
        i++;
        if (L[name] <= index) throw E;
        M[name][index] = v;
    }

    void parse() {
        bool d = true;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '=') {
                d = false;
                break;
            }
        }
        int i = 0;
        if (d) decl(i);
        else assign(i);
    }

    bool solve() {
        M.clear();
        L.clear();
        s = "";
        valid = false;
        getline(cin, s);
        if (s[0] == '.') return false;
        int t = 0;
        bool has_error = false;
        do {
            if (s[0] == '.') break;
            try {
                parse();
            } catch(string e) {
                cout << t + 1 << endl;
                has_error = true;
                while (true) {
                    getline(cin, s);
                    if (s[0] == '.') break;
                }
                break;
            }
            t++;
            getline(cin, s);
        } while (true);
        if (!has_error) {
            cout << 0 << endl;
        }
        return true;
    }
}

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

Measured memory_bytes: 3208
#include <stdio.h>

int main(void){
  int a,b;
  
  scanf("%d %d",&a,&b);
  
  int ans=0;
  
  while(((a-1)*ans+1<b)){
    ans++;
  }
  
  
  
  printf("%d",ans);
  
  return 0;
}



Measured memory_bytes: 128
use std::i64;
use std::f64;
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };

    (stream = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };

    ($($r:tt)*) => {
        use std::io::*;
        let mut stream = stdin();
        let stream = &mut stream;
        input_inner!{stream, $($r)*}
    };
}

macro_rules! input_inner {
    ($stream:expr) => {};
    ($stream:expr, ) => {};

    ($stream:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($stream, $t);
        input_inner!{$stream $($r)*}
    };
}

macro_rules! read_value {
    ($stream:expr, ( $($t:tt),* )) => {
        ( $(read_value!($stream, $t)),* )
    };

    ($stream:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($stream, $t)).collect::<Vec<_>>()
    };

    ($stream:expr, chars) => {
        read_value!($stream, String).chars().collect::<Vec<char>>()
    };

    ($stream:expr, usize1) => {
        read_value!($stream, usize) - 1
    };

    ($stream:expr, $t:ty) => {
        $stream.by_ref().bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<$t>()
            .expect("Parse error")
    };
}

fn main() {
    input!{n: i64, m: i64}
    let mut dp: Vec<i64> = vec![i64::MAX; 1 << n];
    dp[0] = 0;
    for _ in 0 .. m {
        input!{
            a: i64,
            b: i64,
            c: [i64; b]
        };

        let mask = c.iter().fold(0, |acc, i| {acc | (1 << (i - 1))});
        for idx in 0 .. (1 << n) {
            if dp[idx] < i64::MAX {
                dp[idx | mask] = cmp::min(dp[idx | mask], dp[idx] + a);
            }
        }
    }

    println!("{}", if dp[(1 << n) - 1] < i64::MAX {dp[(1 << n) - 1]} else {-1});
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
    int a,b,c,i,n;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a; i<=b; i++){
        if(c%i==0) n++;
    }
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}
template <class T1, class T2>
std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) { return in >> x.first >> x.second; }

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    out_impl(std::forward<Args>(args)...);
}
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    auto n = read<int>();
    auto a = read<std::uint64_t>(n);
    while (a.size() >= 2) {
        std::sort(std::begin(a), std::end(a), std::greater<>());
        a.resize(std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), 0, std::greater<>())));
        for (auto i : boost::irange(0ul, a.size() - 1)) {
            a[i] %= a[i + 1];
        }
    }
    out(a.front());
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


Measured memory_bytes: 1024
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	if (N == 0) {
		out << 0 << endl;
		return 0;
	}

	if (N > 0) {
		int64_t add = 0;
		int32_t i = 0;
		for (; i <= 32; i+=2)
		{
			add += int64_t(1) << i;
			if (add >= N) {
				break;
			}
		}

		out << '1';
		--i;
		for (; i >= 0; --i)
		{
			int64_t minus = int64_t(1) << i;
			bool is_minus = (add - N >= minus);
			if (is_minus) {
				add -= minus;
			}

			if ((i % 2 != 0) == is_minus) {
				out << '1';
			}
			else {
				out << '0';
			}
		}
	}
	else {
		int64_t add = 0;
		int32_t i = 1;
		for (; i <= 32; i += 2)
		{
			add += int64_t(1) << i;
			if (add >= -N) {
				break;
			}
		}

		out << '1';
		--i;
		for (; i >= 0; --i)
		{
			int64_t minus = int64_t(1) << i;
			bool is_minus = (add - -N >= minus);
			if (is_minus) {
				add -= minus;
			}

			if ((i % 2 != 0) == is_minus) {
				out << '0';
			}
			else {
				out << '1';
			}
		}
	}

	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
uint64_t M;
uint64_t A[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	for (int32_t i = 0; i < N; i++)
	{
		in >> A[i];
		A[i] %= M;
	}

	for (int32_t i = 0; i < N; i++)
	{
		A[i + 1] += A[i];
		A[i + 1] %= M;
	}
	A[N] = 0;
	std::sort(A, A + N+1);

	uint64_t res = 0;
	for (uint64_t i = 0; i < M; i++)
	{
		auto range = std::equal_range(A, A + N+1, i);
		auto len = range.second - range.first;
		res += len * (len - 1) / 2;
	}
	out << res << endl;

	return 0;
}
#endif


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

ll inf =1e9+7;


bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
ll mod(ll a)
{
	if(a<inf)return a;
	else
	return a%inf;
}
void solve()
{

ll k;
cin>>k;
string s;
cin>>s;
if(s.size()<=k)
cout<<s;
else
{
	cout<<s.substr(0,k)<<"...";
}
}

int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 3656
N,Y=gets.split.map &:to_i
Y/=1000

L=[(Y-2*N)/4.to_f,2*(Y-N)/9.to_f,(-Y-N)/5.to_f].max.ceil
H=[(Y-N)/4,(2*Y-N)/9,Y/5].min.floor

if H<L
  print("-1 -1 -1")
else
x=-4*H+Y-N
y=9*H-2*Y+2*N
z=-5*H+Y
print(x," ",y," ",z)
end

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

typedef long long ll;
ll M = 9e19;
ll n, k, s;
ll f(ll p) {
	ll j;
	s = 0;
	j = n;
	while (j > 0) {
		s += j % p;
		j /= p;
	}
	return s;
}
int main()
{
	ll i,j;
	cin >> n >> k;
	if (n < k) {
		cout << -1;
		return 0;
	}
	if (n == k) {
		cout << n + 1;
		return 0;
	}
//	if (k == 1) {
//		cout << n;
//		return 0;
//	}
	for (i = 2; i * i <= n; i++) {
		if (f(i) == k) {
			cout << i;
			return 0;
		}
	}
	for (; i > 0; i--) {
		if ((n - k) % i == 0 && f((n - k) / i + 1) == k) {
			cout << (n - k) / i + 1;
			return 0;
		}
	}
//	for (i = 1; i * i <= n - k; i++) {
//		if ((n - k) % i == 0 && f((n - k) / i + 1) == k) b = min(b, (n - k) / i + 1);
//		if ((n - k) % i == 0) {
//			j = (n - k) / i;
//			if (f((n - k) / j + 1) == k) b = min(b, (n - k) / j + 1);
//		}
//	}
	cout << -1;
    return 0;
}


Measured memory_bytes: 256