akhauriyash/Code-Regression huggingface dataset:
/**
 * Created by hiramekun at 20:39 on 2020-05-10.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    vector<bool> visits(n);
    vector<ll> cnts(n);
    ll now = 0;
    ll cnt = 0;
    while (!visits[now] && k) {
        cnts[now] = cnt;
        visits[now] = true;
        now = a[now];
        cnt++;
        k--;
    }
    if (k <= 0) {
        cout << now + 1 << '\n';
    } else {
        k %= (cnt - cnts[now]);
        while (k) {
            now = a[now];
            k--;
        }
        cout << now + 1 << '\n';
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 6428
N, M, P = map(int, input().split())
E = [list(map(int, input().split())) for _ in range(M)]
A = [-float("inf")] * (N+1)
A[1] = 0
for v in range(N):
    for a, b, c in E:
        t = A[a] + c - P
        if t > A[b]:
            A[b] = t
ans = A[N]
for v in range(N):
    for a, b, c in E:
        t = A[a] + c - P
        if t > A[b]:
            A[b] = t
if ans!=A[N]:
    print(-1)
else:
    print(max(0, ans))


Measured memory_bytes: 53976
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL a, b;
    cin >> a >> b;
    vector<string> mat(100, string(100, '.'));
    for(LL i = 50; i < 100; ++i){
        mat[i] = string(100, '#');
    }
    for(LL i = 0; i < a-1; ++i){
        LL y = i / 50 * 2;
        LL x = i % 50 * 2;
        mat[99 - y][x] = '.';
    }
    for(LL i = 0; i < b-1; ++i){
        LL y = i / 50 * 2;
        LL x = i % 50 * 2;
        mat[y][x] = '#';
    }

    cout << "100 100" << endl;
    for(LL y = 0; y < 100; ++y){
        cout << mat[y] << endl;
    }
    return 0;
}



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

bool possible(vector<int> a, int turn) {
	for (auto &x : a) x *= 9;
	a[0] += 9 * turn;
	for (int i = 0; i < (int) a.size(); ++i) {
		if (a[i] > 9) {
			if (i + 1 == (int) a.size()) a.push_back(0);
			a[i + 1] += a[i] / 10;
			a[i] %= 10;
		}
	}
	int sum = accumulate(a.begin(), a.end(), 0);
	return sum <= 9 * turn;
}

int main() {
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int n = s.size();
	vector<int> a (n);
	for (int i = 0; i < n; ++i) a[i] = s[i] - '0';
	reverse(a.begin(), a.end());
	int low = 1, high = n;
	while (low < high) {
		int mid = (low + high) / 2;
		if (possible(a, mid)) high = mid;
		else low = mid + 1;
	}
	cout << low << '\n';
	return 0;
}


Measured memory_bytes: 8604
void mD(char C, int *D) {
  switch (C) {
    int t;
  case 'N':
    t = D[0]; D[0] = D[1]; D[1] = D[5]; D[5] = D[4]; D[4] = t;
    break;
  case 'S':
    t = D[0]; D[0] = D[4]; D[4] = D[5]; D[5] = D[1]; D[1] = t;
    break;
  case 'E':
    t = D[0]; D[0] = D[3]; D[3] = D[5]; D[5] = D[2]; D[2] = t;
    break;
  case 'W':
    t = D[0]; D[0] = D[2]; D[2] = D[5]; D[5] = D[3]; D[3] = t;
    break;
  }
  return;
}

int main(void) {
  int D[6], d, Q, q;
  char C[]={'N','N','E','E'}; int c;
  for(d=0;d<6;d++)
    scanf("%d",&D[d]);
  scanf("%d",&Q);
  for (q=0;q<Q;q++) {
    int t,f;
    scanf("%d %d\n",&t,&f);
    for (c=0;D[0] != t;c++)
      mD(C[c], D);
    while(D[1] != f) {
      int t;
      t = D[1]; D[1] = D[2]; D[2] = D[4]; D[4] = D[3]; D[3] = t;
    }
    printf("%d\n", D[2]);
  }
  return 0;
}

Measured memory_bytes: 600
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int n = Integer.parseInt(st.nextToken());
      int m = Integer.parseInt(st.nextToken());
      
      HashSet<Integer> hset = new HashSet<Integer>();
      
      Pair[] answer = new Pair[m];
      
      for(int k = 1; k <= m; k++){
         int i = n-k+1;
         while(hset.contains(i-k) || hset.contains(n-(i-k)) || i-k == (n-(i-k))){
            i--;
         }
         hset.add(i-k);
         hset.add(n-(i-k));
         answer[k-1] = new Pair(k,i);
      }
      
      for(int k = 0; k < m; k++){
         out.println(answer[k].a + " " + answer[k].b);
      }
      
      
      
      
      
      
      
      out.close();
   }
   
   public static class Pair{
      int a;
      int b;
      public Pair(int c, int d){
         a = c;
         b = d;
      }
   }
   
      
}

Measured memory_bytes: 64184
#include "iostream"
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a,b,c;
  std::cin >> a >> b >>c;
  bool ans=false;


  for(int i=a; i<=a*b; i+=a){
    if(i%b==c) {
      ans=true;
      break;
    }

  }

  if(ans) printf("YES");
  else printf("NO");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<iomanip>

#define pii pair<int,int>
#define ll long long
#define IMAX 1000000007
#define in2d(i,j,H,W)(0<=i&&i<H&&0<=j&&j<W)

using namespace std;

int main(){
	cout<<fixed<<setprecision(11);
	
	int N,K;cin>>N>>K;
	vector<ll>a(N+1);for(int i=1;i<=N;i++)cin>>a[i];
	vector<vector<ll> >dp(N+1,vector<ll>(K+1,0));
	for(int i=0;i<=N;i++)dp[i][0]=1;
	for(int i=1;i<=N;i++)for(int j=1;j<=K;j++){
		dp[i][j]=(dp[i][j-1]+dp[i-1][j])%IMAX;
		if(j>a[i])dp[i][j]=(dp[i][j]+IMAX-dp[i-1][j-a[i]-1])%IMAX;
	}
//	for(int i=0;i<=N;i++){
//		for(int j=0;j<=K;j++){
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	cout<<dp[N][K]<<endl;
	return 0;
}



Measured memory_bytes: 80256
#include <stdio.h>

typedef struct Item {
	struct Item *next;
	int to;
} Item;
#define MAX_NODE (200000)
Item *train[MAX_NODE] = {0}, *road[MAX_NODE] = {0};
int parent[MAX_NODE], sizes[MAX_NODE] = {0};
int setted[MAX_NODE] = {0}, resetted[MAX_NODE] = {0};
int ans[MAX_NODE] = {0};

void add(Item* list[], int from, int to){
	Item *p = (Item*)malloc(sizeof(Item));
	p->next = list[from];
	p->to = to;
	list[from] = p;
}
void setParent(int p, int n){
	Item *it;
	int next;
	for(it=road[n]; it!=NULL; it=it->next){
		next = it->to;
		if(parent[next]!=next || p==next){ continue; }
		parent[next] = p;
		setParent(p, next);
	}
}
void setSize(int n){
	Item *it;
	int next;
	setted[n] = 1;
	sizes[parent[n]]++;
	for(it=train[n]; it!=NULL; it=it->next){
		next = it->to;
		if(setted[next]){ continue; }
		setSize(next);
	}
}
void getSize(int n){
	Item *it;
	int next;
	ans[n] = sizes[parent[n]];
	for(it=train[n]; it!=NULL; it=it->next){
		next = it->to;
		if(ans[next]){ continue; }
		getSize(next);
	}
}
void resetSize(int n){
	Item *it;
	int next;
	resetted[n] = 1;
	sizes[parent[n]] = 0;
	for(it=train[n]; it!=NULL; it=it->next){
		next = it->to;
		if(resetted[next]){ continue; }
		resetSize(next);
	}
}

int main(void){
	int i, j;
	int N, K, L, from, to;
	scanf("%d%d%d", &N, &K, &L);
	for(i=0;i<N;i++){
		parent[i] = i;
	}
	for(i=0;i<K;i++){
		scanf("%d%d", &from, &to); from--; to--;
		add(road, from, to);
		add(road, to, from);
	}
	for(i=0;i<N;i++){ if(parent[i]==i){ setParent(i, i); } }
	
	for(i=0;i<L;i++){
		scanf("%d%d", &from, &to); from--; to--;
		add(train, from, to);
		add(train, to, from);
	}
	for(i=0;i<N;i++){
		if(ans[i]){ continue; }
		setSize(i);
		getSize(i);
		resetSize(i);
	}
	printf("%d", ans[0]);
	for(i=1;i<N;i++){
		printf(" %d", ans[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 19712
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, a, n) for(int i=a; i<n; ++i)
#define all(c) c.begin(), c.end()
#define INF 1e18+1

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, k, c;
  string s;
  cin >> n >> k >> c;
  cin >> s;
  vector<int> l(n), r(n);
  int lc = 1;
  for (int i = 0; i < n;) {
    if (s[i] == 'o') {
      l[i] = lc++;
      i += c+1;
    } else {
      ++i;
    }
  }
  int rc = k;
  for (int i = n-1; i >= 0;) {
    if (s[i] == 'o') {
      r[i] = rc--;
      i -= c+1;
    } else {
      --i;
    }
  }
  bool ok = (lc == k+1) && (rc == 0);
  for (int i = 0; i < n; ++i) {
    if (ok && l[i] > 0 && r[i] > 0) {
      cout << i+1 << endl;
    }
  }
}

Measured memory_bytes: 3348
from itertools import accumulate
from bisect import bisect_left,bisect_right
n,m,k=map(int,input().split())
a=[0]+list(accumulate(map(int,input().split())))
b=[0]+list(accumulate(map(int,input().split())))
ans=[0]
for i in range(n+1):
    c=bisect_right(b,k-a[i])-1
    if c!=-1:
        ans.append(c+i)
print(max(ans))

Measured memory_bytes: 48540
#include <stdio.h>

int main(void)
{

        int a,b,c,s;

        scanf("%d%d",&a,&b);

        if ((a<1)||(b<1)||(a>20)||(b>20)){
                return 1;
                }
        c=b%a;
        if(c==0){
        s=a+b;
        }
        else s=b-a;

        printf("%d",s);
        return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
    int nmax = 2e5;
    int mmax = 2e5;

    int n, m;
    cin >> n;
    cin >> m;
    int lst[m][2];
    for (int i = 0; i < m; i++){
        cin >> lst[i][0];
        cin >> lst[i][1];
    }
    int rout1[n];
    int routn[n];
    // 初期化
    for (int i = 0; i < n; i++){
        rout1[i] = 0;
        routn[i] = 0;
    }

    // 渡れる場合はflagをつける
    for (int i = 0; i < m; i++){
        if (lst[i][0] == 1) {
            rout1[lst[i][1]] = 1;
        }
        if (lst[i][1] == n) {
            routn[lst[i][0]] = 1;
        }
    }

    // for (int i = 0; i < n; i++){
    //     cout << rout1[i] << " " << routn[i] << '\n';
    // }
    for (int i = 0; i < n; i++){
        if (rout1[i] == 1 and routn[i] == 1) {
            cout << "POSSIBLE";
            return 0;
        }
    }   
    cout << "IMPOSSIBLE";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#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 print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 

unordered_map<int ,int> calc_pdeconv(int a) {
    unordered_map<int, int> ret;
    for (int p = 2; p*p <= a; ++p) {
        while(a%p==0) {
            ret[p] += 1;
            a /= p;
        }
    }
    if (a != 1) ret[a] = 1;
    return ret;
}

ll modpow(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n&1) res = res*x%MOD;
        x = x * x % MOD;
        n >>= 1;
    } 
    return res;
} 

int main() {
    int n, l=1;
    cin >> n;
    // vector<unordered_map<int, int>> v_apmap;
    vector<int> as;
    unordered_map<int, int> lpmap;
    rep(i, n) {
        int a;
        cin >> a; 
        auto amap = calc_pdeconv(a);
        for (auto& ap : amap) {
            lpmap[ap.first] = max(lpmap[ap.first], ap.second);
        } 
        as.push_back(a); 
        //v_apmap.emplace_back(amap); 
    }

    ll c = 1;
    for (auto e : lpmap) {
        c = (c * modpow(e.first, e.second)) % MOD;
    } 

    ll ret = 0;
    for (int a : as) {
        ll b = (c * modpow((ll)a, MOD-2)) % MOD;
        ret = (ret + b) % MOD;
    } 
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int a,b,c,x,y;

int main(){
  cin >> a >> b >> c >> x >> y;
  if(a + b <= c * 2){
    cout << a*x+b*y << endl;
    return 0;
  }
  int ans = 0;
  int mai = min(x,y);
  ans += mai*2*c;
  x -= mai;
  y -= mai;
  if(x==0) ans += y*min(b,2*c);
  else ans += x * min(a,2*c);
  cout <<ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<ll, int>> f(ll n)
  {vector<pair<ll, int>> r;
  ll c = 0, d = 2, m = n;
  while (d <= m && d * d <= n)
    {if (m % d == 0) {m = m / d; ++c;}
    else {if (c > 0) r.push_back({d, c}); c = 0; ++d;}}
  if (c > 0) r.push_back({d, c}); else if (m > 1) r.push_back({m, 1});
  return r;}
int main()
  {int64_t N, ans{}; cin >> N;
  for (auto [_, e] : f(N)) for (int i{1}, s{}; (s += i) <= e; ++i) ++ans;
  cout << ans << endl;}

Measured memory_bytes: 3600
from math import gcd

N,K=map(int,input().split())
A=list(map(int,input().split()))

G=A[0]
for a in A:
    G=gcd(G,a)

F=False
for a in A:
    if a>=K and (K-a)%G==0:
        F=True

if F:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 84988
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(const auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

    ll n;
    cin >> n;
    map<string, int> vote_papers;
    rep(i, 0, n) {
        string s;
        cin >> s;
        vote_papers[s] += 1;
    }
    int max_occurs = 0;
    trav(i, vote_papers) {
        int v = i.second;
        if (v > max_occurs)
            max_occurs = v;
    }
    for (auto it = vote_papers.begin(); it != vote_papers.end(); it++) {
        if (it->second == max_occurs)
            cout << it->first << endl;
    }
    return 0;
}

Measured memory_bytes: 23808
import numpy as np
w, h, n = map(int, input().split())
xy = np.zeros((w,h))
xya = [[int(a) for a in input().split()] for _ in range(n)]
for i in range(n):
    if xya[i][2]==1:
        for x in range(xya[i][0]):
            xy[x][:h] = 1
    elif xya[i][2] == 2:
        for x in range(xya[i][0], w):
            xy[x][:h] = 1
    elif xya[i][2]==3:
        for x in range(w):
            for y in range(xya[i][1]):
                xy[x][y] = 1
    elif xya[i][2] == 4:
        for x in range(w):
            for y in range(xya[i][1], h):
                xy[x][y] = 1
wh = [int(item) for wh in xy for item in wh]
print(wh.count(0))

Measured memory_bytes: 21548
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
li = []
for i in range(h):
    li.append(input())
for i in range(h):
    for j in range(w):
        ct = 0
        if li[i][j] == "#":
            print("#", end="")
        else:
            ppp = []
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if 0 <= i + k <= h-1 and 0 <= j + l <= w-1:
                        ppp.append(li[i+k][j+l])
            for p in ppp:
                if p == "#":
                    ct += 1
            print(ct, end="")
    print()


Measured memory_bytes: 5656
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;i++)

int n,m,ans,a[5000],b[5000];

int main(){
	scanf("%d%d", &n, &m);
	rep(i,n) scanf("%d",&a[i]);
	rep(i,m) scanf("%d",&b[i]);
	rep(i,m){
		if(ans>=m-i)break;
		int cnt=0;
		rep(j,n){
			if(i+cnt>=m)break;
			if(a[j]==b[i+cnt])cnt++;			
		}
		if(cnt>ans)ans=cnt;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1064
n = int(input())
A = list(map(int, input().split()))
q = int(input())
for i in range(q):
    a = int(input())
    left = 0
    right = n
    flag = 0
    mid = (right - left) // 2 
    while left < right:
        if A[mid] == a:
            flag = 1
            break
        if a > A[mid]:
            left = mid+1
        else:
            right = mid
        mid = (left + right) //2
    print(flag)


Measured memory_bytes: 17196
N = int(input())
sum = 0

for i in range(1,N+1):
        if i % 3 == 0 and i % 5 == 0:
            i = ["FizzBuzz"]
        elif i % 3 == 0:
            i = ["Fizz"]
        elif i % 5 == 0:
            i = ["Buzz"]
    # if i % 3 == 0 and i % 5 == 0:
        else:
            sum += i
print(sum)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> ans(n, 0);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		ans.at(a)++;
		ans.at(b)++;
	}
	for (int i = 0; i < n; i++) {
		cout << ans.at(i) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	string t;
	cin>>s;
	cin>>t;
	int len=s.size();
	int f1=0;
	for(int i=0;i<len;i++){
		if(s[i]!=t[i])f1=1;
	}
	if(f1==1)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

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

int main(){
	int n,m,e,j;
	while(cin >> n,n){
		for(int i = 0;i < n;i++){
			cin >> m >> e >> j;
			if(m == 100 || e == 100 || j == 100 || m + e >= 180 || m + e + j >= 240) cout << "A" << endl;
			else if(m + e + j >= 210 || (m + e + j >= 150 && (m >= 80 || e >= 80))) cout << "B" << endl;
			else cout << "C" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
a,b,c,d=map(int,input().split())
def gcd(x,y):
    if x==0:
        return y
    else:
        return gcd(y%x,x)
def lcm(x,y):
    return x*y//gcd(x,y)
 
e=lcm(c,d)
ans=0
ans=b//c-(a-1)//c+b//d-(a-1)//d
ans-=b//e-(a-1)//e
print(b-a+1-ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b))?(b):(a))
#define chmin(a, b) a = (((a)<(b))?(a):(b))

const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<double> VD;

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}




signed main(){
  ll n, k, s; cin>>n>>k>>s;
	rep(i,k) cout << s << ' ';
	if(s-1==0) s = s+2;
	rep(i,n-k) cout << s-1 << ' ';

  return 0;
}


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

using namespace std;
typedef pair<long long, long long> ii;
static map<long long, vector<ii> > m;
int main(){
	long long n, x, d;
	cin >> n >> x >> d;
	if(d < 0) x *= -1, d *= -1;
	if(d == 0){
		if(x == 0) cout << 1;
		else cout << n+1;
		return 0;
	}
	
	for(long long a = 0;a <= n;a++){
		long long xTerm = a * x;
		
		long long smallD = d * ((a)*(a-1)/2);
		long long bigD = d * (a*n - (a)*(a+1)/2);
		if(smallD > bigD) swap(smallD, bigD);
		smallD += xTerm;
		bigD += xTerm;
		
		long long R = xTerm;
		R %= d;
		if(R < 0) R += d;
		
		m[R].push_back(ii(smallD,-1));
		m[R].push_back(ii(bigD,1));
	}
	
	long long ans = 0;
	for(pair<long long, vector<ii> > ss : m){
		vector<ii> v = ss.second;
		sort(v.begin(),v.end());
		
		int cnt = 0;
		long long pre = -1;
		for(ii x : v){
			//cout << x.first << " " << x.second << "\n";
			if(x.second == -1){
				if(pre == -1) pre = x.first;
				cnt++;
			}
			else{
				cnt--;
				if(cnt == 0){
					ans += ((x.first - pre) / d + 1);
					pre = -1;
				}
			}
		}
	}
	
	cout << ans;
}


Measured memory_bytes: 25216
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            money = i * 500 + j *100 + k*50
            
            if money == x:
                count += 1
                
print(count)

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

int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    
    int count=0;
    if(a>=k){
        cout<<k;
    }else{
        count += a*1;
       	k -= a;
        if(b>=k){
            if(a==0) cout<<0;
          	else cout<<count;
        }else{
        	count += b*0;
            k -= b;
          	if(c>=k){
            	if(a==0 && b==0) cout<<k*(-1);
              	else cout<<count-k;
            }
            else{
            	count -= k;
            }
        }
    }
  
}

Measured memory_bytes: 3624
# include <vector>
# include <iostream>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    vector<int> nums(3); rep (i, 3) cin >> nums[i];
    sort(nums.begin(), nums.end());
    cout << nums[2]*10+nums[1]+nums[0] << endl;
    return 0;
}



Measured memory_bytes: 512
N = int(input())

k = (N + 1) // 2
pow2, pow5 = k, 0
# pow2
tmp = k
while tmp > 0:
    pow2 += (tmp // 2)
    tmp = (tmp // 2)
# pow 5
tmp = k
while tmp > 0:
    pow5 += (tmp // 5)
    tmp = (tmp // 5)


if N % 2 == 0:
    print(min(pow2, pow5))
else:
    pow2 = -pow2
    pow5 = -pow5
    k = 2 * k
    tmp = k
    while tmp > 0:
        pow2 += (tmp // 2)
        tmp = (tmp // 2)
    tmp = k
    while tmp > 0:
        pow5 += (tmp // 5)
        tmp = (tmp // 5)
    print(min(pow2, pow5))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
 
using namespace std;
 
/* template */
 
using ll = long long;
 
void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
 
template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;
 
 
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};
 
/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = INF;
    rep(i,0,n-m+1){
        int a = 0;
        rep(j,0,m){
            if(s[i+j]!=t[j]){
                a++;
            }
        }
        chmin(ans,a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;
using un = unsigned;

int main()
{
	int a, b; cin >> a >> b;
	cout << a * b;
	return 0;
}


Measured memory_bytes: 3628
N, A, B = map(int, input().split())
M, m = max(A, B), min(A, B)

if (M - m) % 2 == 0:
  ans = (M - m) // 2
else:
  ans = min(N-M, m-1)
  ans += (M - m + 1)//2

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int M,D,x=0;
	cin>>M>>D;
	for (int i=1;i<=M;i++){
		for(int j=1;j<=D;j++){
			if (j>=10){
				int u,d;
				u=j%10;
				d=(j-u)/10;
				if((d*u)==i && d>=2 && u>=2){
					x++;
				
				}
			}
		}
	
	
	}
cout<<x;






}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int c[3][3];
	rep(i,3){
		rep(j,3){
			cin >> c[i][j];
		}
	}
	int c10 = c[0][1] - c[0][0];
	int c20 = c[0][2] - c[0][0];
	int r10 = c[1][0] - c[0][0];
	int r20 = c[2][0] - c[0][0];
	for(int i=1; i<3; i++){
		if(c[i][1] - c[i][0] != c10 || c[i][2] - c[i][0] != c20 || c[1][i] - c[0][i] != r10 || c[2][i] - c[0][i] != r20){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";

}

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

const int mod = 1e6+3;

long long int mypow(long long int a,long long int b){
	long long int res=1;
	a%=mod;
	while(b){
		if(b&1)
			res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
long long int fac[1000003];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long int q,x,d,n;
	fac[0]=1;
	for(int i=1;i<mod;i++)
		fac[i]=fac[i-1]*i%mod;
	cin>>q;
	while(q--){
		cin>>x>>d>>n;
		if(x==0)	cout<<0<<'\n';
		else if(d==0){
			cout<<mypow(x,n)<<'\n';
		}
		else{
			x=x*mypow(d,mod-2)%mod;
			long long int y=x+n-1;
			if(y>=mod)	cout<<0<<'\n';
			else
				cout<<fac[y]*mypow(fac[x-1],mod-2)*mypow(d,n)%mod<<'\n';
		}
	}
}



Measured memory_bytes: 8704
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		long sum = 0;
		for(long i = 0; i < M; i++) {
			long a = sc.nextLong();
			sum += a;
		}
		sc.close();
		System.out.println(N < sum ? -1 : N - sum);
	}
}

Measured memory_bytes: 39364
n, m = map(int, input().split())
S = set()
G = set()

for i in range(m):
    s, g = map(int, input().split())
    if s == 1:
        G.add(g)
    if g == n:
        S.add(s)

if len(S&G) != 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 18892
#include<iostream>

using namespace std;

int main() { 
    int weeks; 

    while( cin >> weeks ) {

	int sum = 100000;
	
    for(int i=0;i<weeks;i++){
    	
    sum *= 1.05;
    if( sum % 1000 !=0 )
    sum = ( sum / 1000 +1 ) * 1000;
    
	}
    cout << sum << "\n";
	}
    return 0; 
} 


Measured memory_bytes: 3032
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int N, N_1;
    cin>>N;

    if(N%111==0){
        
    } else {
        N_1 = N /100;
        if(N<N_1*111){
            N = N_1 * 111;
        } else {
            N = (N_1 + 1) * 111;
        }
    }
    
    cout<<N<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
n = int(input())
a =list(map(int, input().split()))

N = sum(a)
r = float('inf')
x = 0
 
for i in range(n-1):
    x += a[i]
    y = N - x
    if r > abs(x -y):
        r = abs(x -y)
print(r)

Measured memory_bytes: 24936
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
ll mod = 2e18;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll n;
ll d[100010];
ll total = 1;
bool check() {
	rep(i, 0, n + 1) {
		if (d[i] > total)return false;
		total = (total - d[i]) * 2;
		if (total > (int)1e9)return true;
	}
	return true;
}
void solve() {
	//cout <<(1LL<<63) << endl;
	cin >> n;
	rep(i, 0, n + 1)cin >> d[i];
	if (!check()) {
		cout << -1 << endl;
		return;
	}
	vector<ll> most(n + 1);
	most[n] = d[n];
	for (int i = n-1; i >= 0; i--) {
		if(i<63)most[i] = min((1LL << i), most[i+1] + d[i]);
		else most[i] = most[i + 1] + d[i];
	}
	ll ans = 1, lo = 1 - d[0], hi = 2 * lo;
	for (int i = 1; i < n + 1; i++) {
		while (lo < hi) {
			ll mid = (lo + hi + 1) / 2;
			if (mid <= most[i]) {
				lo = mid;
			}
			else {
				hi = mid - 1;
			}
		}
		ans += lo;
		lo -= d[i];
		hi = 2 * lo;
	}
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 4748
N, M=map(int,input().split())
s=list()
c=list()
a=0
for i in range(0,M):
    s.append(0)
    c.append(0)
for i in range(0,M):
    s[i], c[i]=map(int,input().split())
for i in range(0,M):
    for j in range(0,M):
        if s[i]==s[j] and c[i]!=c[j]:
            print("-1")
            break
    else:
        continue
    break
else:
    if N==1:
        b=[0]
        for i in range(0,M):
            b[s[i]-1]=c[i]
        print(b[0])
    else:
        b=[1]
        for i in range(0,N-1):
            b.append(0)
        for i in range(0,M):
            if s[i]==1 and c[i]==0:
                print("-1")
                break
        else:
            for i in range(0,M):
                b[s[i]-1]=c[i]
            for i in range(0,N):
                print(b[i],end='')

Measured memory_bytes: 9144
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

struct P {
  char flag;
  char Start_or_End; // Start is 1
  char character;
};

int main() {
  string S;
  cin >> S;
  ll Q;
  cin >> Q;
  vector<P> query(Q);
  rep(i,Q) {
    cin >> query[i].flag;
    if (query[i].flag == '1') {
      continue;
    } else {
      cin >> query[i].Start_or_End >> query[i].character;
    }
  }

  bool is_back = false;
  string Top;
  string Tail;
  rep(i,Q) {
    if (query[i].flag == '1') {
      is_back = !is_back;
    } else {
      if (query[i].Start_or_End == '1') {
        if (is_back == false) {
          Top += query[i].character;
        } else {
          Tail += query[i].character;
        }
      } else { // '2'
        if (is_back == false) {
          Tail += query[i].character;
        } else {
          Top += query[i].character;
        }
      }
    }
  }
  if (is_back == true) {
    for (auto it = Tail.rbegin(); it != Tail.rend(); ++it) {
      cout << *it;
    }
    for (auto it = S.rbegin(); it != S.rend(); ++it) {
      cout << *it;
    }
    cout << Top << '\n';
  } else {
    for (auto it = Top.rbegin(); it != Top.rend(); ++it) {
      cout << *it;
    }
    cout << S << Tail << '\n';
  }
}


Measured memory_bytes: 1600
import java.util.*;

public class Main {

	static class Unionfind{
		private int par[];
		private int rank[];
		private int size[];
		
		public Unionfind(int n) {
			par = new int[n + 1];
			rank = new int[n + 1];
			size = new int[n + 1];
			for (int i = 0; i <= n; ++i) {
				par[i] = i;
				rank[i] = 0;
				size[i] = 1;
			}
		}

		public int size(int x){
			int rx = root(x);
			return size[x] = size[rx];
		}

		public int root(int x) {
			if (par[x] != x)
				par[x] = root(par[x]);
			return par[x];
		}
	
		public void unite(int x, int y) {
			int rx = root(x);
			int ry = root(y);
			int sx = size[rx];
			int sy = size[ry];
			if (rank[rx] < rank[ry]){
				par[rx] = ry;
				size[ry] = sx + sy;
			}
			else if (rank[ry] < rank[rx]) {
				par[ry] = rx;
				size[rx] = sx + sy;
			} else if (rx != ry) {
				par[ry] = rx;
				size[rx] = sx + sy;
				rank[rx]++;
			}
		}
	
		public boolean isSame(int x, int y) {
			int rx = root(x);
			int ry = root(y);
			return rx == ry;
		}
	}

	static Unionfind uniontree;

	public static class Graph {
		List<Integer> friend = new ArrayList<Integer>();
		List<Integer> block = new ArrayList<Integer>();
		int number;

		public Graph(int num){
			number = num;
		}

		public void addfriend(int b) {
			friend.add(b);
		}

		public void addblock(int b) {
			if(uniontree.isSame(number, b))
			block.add(b);
		}
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
		Graph graph[] = new Graph[n + 1];
		uniontree = new Unionfind(n);
		for (int i = 0; i <= n; ++i)
			graph[i] = new Graph(i);
		for (int i = 0; i < m; ++i) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			graph[a].addfriend(b);
			graph[b].addfriend(a);
			uniontree.unite(a, b);
		}
		for (int i = 0; i < k; ++i) {
			int c = sc.nextInt();
			int d = sc.nextInt();
			graph[c].addblock(d);
			graph[d].addblock(c);
		}
		sc.close();
		for (int i = 1; i <= n; ++i) {
			int num = uniontree.size(i) - (graph[i].friend.size() + graph[i].block.size()) - 1;
			// int num = uniontree.size(i);
			System.out.print(num + " ");
		}
	}
}


Measured memory_bytes: 151276
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    i64 ans;

    ans = a*d;
    ans = max(ans, a*c);
    ans = max(ans, b*c);
    ans = max(ans, b*d);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }

int h,w,n;
set<pair<int,int>> se;

int check(int x,int y){
  int cnt = 0;
  for(int i=0;i<=2;i++){
    for(int j=0;j<=2;j++){
      if(x+i>=1&&x+i<=h&&y+j>=1&&y+j<=w) cnt+=se.count({x+i,y+j});
      else return 0;
    }
  }
  return cnt;
}

int32_t main(){
    
  fast;
  cin >> h >> w >> n;
  for(int i=1;i<=n;i++){
    int x,y; cin >> x >> y;
    se.insert({x,y});
  }

  vector<pair<int,int>> vp(all(se));
  int ans[10]={0};
  set<pair<int,int>> used;

  for(int idx=0;idx<vp.size();idx++){
    int x = vp[idx].f , y = vp[idx].s;
    for(int i=-2;i<1;i++){
      for(int j=-2;j<1;j++){
        if(!used.count({x+i,y+j})){
          ans[check(x+i,y+j)]++;
          used.insert({x+i,y+j});
        }
      }
    }
  }

  int sum = 0;
  for(int k=1;k<10;k++) sum+=ans[k];
  ans[0] = (h-2)*(w-2) - sum;
  for(int k : ans) cout << k << '\n';
  return 0;

}


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

const int MAX_N = 1e5+10;
int A, B, Q;
ll s[MAX_N],t[MAX_N],x[MAX_N];

void solve()
{
	sort(s,s+A);sort(t,t+B);
	for(int i=0;i<Q;++i){
		ll at=x[i];
		int nxt_s = lower_bound(s,s+A,at)-s;
		int nxt_t = lower_bound(t,t+B,at)-t;
		int prv_s = nxt_s ? nxt_s-1 : -1;
		int prv_t = nxt_t ? nxt_t-1 : -1;
		if(nxt_s == A) nxt_s = -1;
		if(nxt_t == B) nxt_t = -1;
		ll ans = 1e18;
		if(nxt_s!=-1&&nxt_t!=-1) ans=min(ans,max(s[nxt_s],t[nxt_t])-at);
		if(nxt_s!=-1&&prv_t!=-1) ans=min(ans,min(s[nxt_s]-at, at-t[prv_t])+s[nxt_s]-t[prv_t]);
		if(prv_s!=-1&&prv_t!=-1) ans=min(ans,at-min(s[prv_s],t[prv_t]));
		if(prv_s!=-1&&nxt_t!=-1) ans=min(ans,min(t[nxt_t]-at, at-s[prv_s])+t[nxt_t]-s[prv_s]);
		cout << ans << '\n';
	}
}

int main()
{
	cin >> A >> B >> Q;
	for(int i=0;i<A;++i) cin >> s[i];
	for(int i=0;i<B;++i) cin >> t[i];
	for(int i=0;i<Q;++i) cin >> x[i];
	solve();
	return 0;
}

Measured memory_bytes: 5940
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
ll fastpow(ll num)
{
    ll tmp = num*num;
    return (ll)(tmp*tmp*num);
}
ll a,b;
ll x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>x;
    for(ll i=0;i<=300;i++)
    {
        for(ll j=i-1;j>=-300;j--)
        {
            a = fastpow(i);
            b = fastpow(j);
            if(x+b == a)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

ll dp[100][2];

int main(void){
    ll n, k;
    cin >> n >> k;

    ll a[n];
    rep(i, 0, n){
        cin >> a[i];
    }

    rep(i, 0, 100){
        rep(j, 0, 2){
            dp[i][j] = -1;
        }
    }

    dp[50][0] = 0;

    rrep(i, 49, 0){
        ll mask = 1LL << i;
        ll num = 0;
        rep(j, 0, n){
            if(a[j] & mask){
                num++;
            }
        }

        ll score0 = mask * num;
        ll score1 = mask * (n - num);

        if(dp[i + 1][1] != -1){
            dp[i][1] = max(dp[i][1], max(dp[i + 1][1] + score0, dp[i + 1][1] + score1));
        }

        if(dp[i + 1][0] != -1){
            if(k & mask){
                dp[i][1] = max(dp[i][1], dp[i + 1][0] + score0);
                dp[i][0] = max(dp[i][0], dp[i + 1][0] + score1);
            }else{
                dp[i][0] = max(dp[i][0], dp[i + 1][0] + score0);
            }
        }
    }

    cout << max(dp[0][1], dp[0][0]) << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public Main(int opt1, int opt2) {
		String[] A = {"f","t","t","t"};
		A[opt1]="f";
		A[opt2]="f";
		for(int i =1; i<4; i++)
		{
			if(A[i]=="t")
			{
				System.out.println(i);
				break;
			}
		}

	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int opt1 = sc.nextInt();
		int opt2 = sc.nextInt();
		Main m = new Main(opt1, opt2);
	}	
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define lg2 std::__lg

typedef long long ll;
const int N = 16400, mod = 998244353, root = 31;
typedef int vec[N], *pvec;

vec fact, finv;

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

void init() {
	int i;
	for (*fact = i = 1; i < N; ++i) fact[i] = (ll)fact[i - 1] * i % mod;
	--i, finv[i] = PowerMod(fact[i], mod - 2);
	for (; i; --i) finv[i - 1] = (ll)finv[i] * i % mod;
}

namespace Poly {
	int l, n;
	vec rev, x, y;

	void NTT_init(int len) {
		if (l == len) return; n = 1 << (l = len);
		ll g = PowerMod(root, 1 << (23 - l));
		*x = 1, *rev = 0;
		for (int i = 1; i < n; ++i)
			x[i] = x[i - 1] * g % mod, rev[i] = rev[i >> 1] >> 1 | (i & 1) << (l - 1);
	}

	void DNTT(int *d, int *t) {
		int i, *j, *k, len = 1, delta = n, R;
		for (i = 0; i < n; ++i) t[rev[i]] = d[i];
		for (i = 0; i < l; ++i) {
			delta >>= 1;
			for (k = x, j = y; j < y + len; k += delta, ++j) *j = *k;
			for (j = t; j < t + n; j += len << 1)
				for (k = j; k < j + len; ++k)
					R = (ll)y[k - j] * k[len] % mod,
					k[len] = (*k - R < 0 ? *k - R + mod : *k - R),
					*k = (*k + R >= mod ? *k + R - mod : *k + R);
			len <<= 1;
		}
	}

	vec B1;

	void Mul(int deg, pvec a, pvec b, pvec c) {
		if (!deg) {*c = (ll)*a * *b % mod; return;}
		NTT_init(lg2(deg) + 1);
		int i; ll iv = mod - (mod - 1) / n;
		DNTT(a, c), DNTT(b, B1);
		for (i = 0; i < n; ++i) B1[i] = (ll)B1[i] * c[i] % mod;
		DNTT(B1, c), std::reverse(c + 1, c + n);
		for (i = 0; i < n; ++i) c[i] = c[i] * iv % mod;
	}
}

int R, C;
vec f, g, h;
vec tr, tr_ntt;

int main() {
	int i, j, ans = 0; ll iv; init();
	scanf("%d%d", &R, &C), *f = 1;
	if (R == 1) return printf("%d\n", (int)PowerMod(2, C)), 0;
	for (i = 0; i < R; ++i) tr[i] = finv[i + 3];
	Poly::NTT_init(lg2(R - 1) + 2), iv = mod - (mod - 1) / Poly::n;
	Poly::DNTT(tr, tr_ntt);
	for (j = 0; j < C; ++j) {
		Poly::DNTT(f, g);
		for (i = 0; i < Poly::n; ++i) g[i] = g[i] * (ll)tr_ntt[i] % mod;
		Poly::DNTT(g, h), std::reverse(h + 1, h + Poly::n);
		for (i = 0; i < R; ++i) h[i] = h[i] * iv % mod;
		for (i = 1; i <= R; ++i)
			f[i] = ((i * (i + 1ll) + 2ll) / 2 * f[i] + (i + 1ll) * (i + 2ll) * h[i - 1]) % mod;
	}
	for (i = 0; i <= R; ++i) ans = (ans + (ll)f[i] * finv[R - i]) % mod;
	printf("%d\n", int((ll)ans * fact[R] % mod));
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <array>
#include <algorithm>
#include <numeric>

int main() {
  unsigned int a, b, c, d, e;
  std::cin >> a;
  std::cin >> b;
  std::cin >> c;
  std::cin >> d;
  std::cin >> e;

  const std::array<unsigned int, 5> abcde = {a, b, c, d, e};
  std::array<unsigned int, 5> abcde_10;
  std::array<unsigned int, 5> abcde_error;
  for (size_t i = 0; i < abcde.size(); ++i) {
    const unsigned int shou = abcde.at(i) % 10;
    if (shou == 0) {
      abcde_10.at(i) = abcde.at(i);
    } else {
      abcde_10.at(i) = (abcde.at(i) / 10 + 1) * 10;
    }
    abcde_error.at(i) = abcde_10.at(i) - abcde.at(i);
  }

  const unsigned int sum = std::accumulate(abcde_10.begin(), abcde_10.end(), 0);
  const unsigned int max_error = *std::max_element(abcde_error.begin(), abcde_error.end());

  std::cout << sum - max_error << std::endl;

  return 0;
}


Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, K = reads()
# a == b == c == 0 (mod K)
ans = (N // K) ** 3

if K % 2 == 0:
  # a == b == c == K/2 mod K
  ans += ((N + (K//2)) // K) ** 3

print(ans)


Measured memory_bytes: 38480
import java.util.Scanner;

/**
 * https://atcoder.jp/contests/abc135/tasks/abc135_b
 */
public class Main {

  private static boolean answer(long[] ps) {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  }

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long[] ps = new long[n];
    for (int i = 0; i < n; i++) {
      ps[i] = scan.nextInt();
    }
    scan.close();

    if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define int long long
int s[100010],n,a,b;
bool check(int x){
    int sum=0,k=a-b;
    for(int i=0;i<n;i++) {
        int r=s[i]-b*x;
        if(r>0){
            sum+=r/k; 
            sum+=(r%k!=0);
        }
    }
    if(sum>x)	return false;
    return true;
}
signed main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	for(int i=0;i<n;i++)	scanf("%lld",s+i);
	int l=0,r=1e9,ans=INT_MAX;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))	r=mid-1,ans=min(mid,ans);
		else			l=mid+1;
    }
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    int a, b, c;
    cin >> a >> b >> c;

    int sum = a + b + c;
    int m = max({a, b, c});

    cout << 9*m + sum;

}





//              g++ -std=c++1z

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> arr(100006);
vector<int> dp(100006,-1);
int jump(int n)
{
	if(n == 1)
		return dp[n] = 0;
	if(dp[n] != -1)
		return dp[n];
	if(n == 2)
		return dp[n] = abs(arr[2]-arr[1]); 
	else
		return dp[n] = min(abs(arr[n]-arr[n-1])+jump(n-1),abs(arr[n]-arr[n-2])+jump(n-2));
}

int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> arr[i];
	}
	cout << jump(n);
}

Measured memory_bytes: 3328