akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    string s; int k; cin >> k >> s;
    int length = s.size();
    fo(i, min(length, k)) cout << s[i];
    if (s.size() > k) cout << "...";
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;
vector<vector<pair<int,int>>> z(100010);

int main()
{
    string T;
    cin >> T;
    size_t u=T.size();
    for(int i=0;i<u;i++){
        if(T.at(i)=='?'){
            
                T.at(i)='D';
                  
           
        }
    }
    cout << T <<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 1000000007;

void update(int &a, int b) {
    a = min(a, b);
    return;
}

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

    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<int, ll> > v(n);
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) x[i] = v[i].first;
    ll currx = v[n - 1].first - d, dam = 0, ans = 0;
    vector<ll> upd(n);
    int l, r = n - 1;
    while (r >= 0) {
        // update new health of r after dealing dam damage
        v[r].second -= dam;
        if (v[r].second < 1) {
            dam += upd[r];
            r--;
            continue;
        }

        // update x
        currx = max(0LL, v[r].first - d);

        // find number of bombs
        ll temp = v[r].second / a;
        if (v[r].second % a != 0) {
            temp++;
        }
        ans += temp;

        // update l so that the left most monster is just inside currx-d
        l = lower_bound(x.begin(), x.end(), currx - d) - x.begin();

        // update in upd at currx - d, the damage dealt by these bombs
        upd[l] -= temp * a;

        // update damage, new = old + damage by bombs + upd[r];
        dam += temp * a + upd[r];

        r--;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,k;
  cin >> n >> k;
  double u[n+1];
  u[0]=0;
  double ans=0;
  rep(i,n){
    double y;
    cin >> y;
    y++;
    y/=2;
    u[i+1]=u[i]+y;
  }
  rep(i,n-k+1){
    ans=max(ans,u[i+k]-u[i]);
  }
  cout << fixed << setprecision(20);
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int N,K,X,Y,ans=0;
    cin >> N >> K>> X>>Y;
    if(N>K)cout<<K*X+(N-K)*Y;else cout<<X*N;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };

#define INF 1e+9
#define MAX_V 2010

struct edge {
    int to;
    int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

vector<edge> G[MAX_V];
int d[MAX_V];
int N;

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+N, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

signed main() {
  int ans = 0;
  int X,Y;
  cin >> N >> X >> Y;
  X--; Y--;
  for (int i=0; i<N; ++i) {
      edge e = {i+1, 1};
      G[i].push_back(e);
      e = {i, 1};
      G[i+1].push_back(e);
  }
  edge e = {Y, 1};
  G[X].push_back(e);
  e = {X, 1};
  G[Y].push_back(e);
  // vector<vector<int>> memo(N, vector<int>(N, -1));
  vector<int> memo(N, 0);
  for (int s = 0; s < N; s++) {
    dijkstra(s);
    for (int i=0; i < N; ++i) {
      // memo[k][i] = d[i];
      memo[d[i]]++;
    } 
  }
  for (int k = 1; k < N; k++) {
    cout << memo[k]/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int Binary_Search(int *,int,int,int);
int main(){
  int i,key,count=0,L,M,R,data1,data2,S[100000];
  
  scanf("%d",&data1);
  for(i=0;i<data1;i++)scanf("%d",&S[i]);
  scanf("%d",&data2);
  for(i=0;i<data2;i++){
    scanf("%d",&key);      
    if(Binary_Search(S,0,key,data1) != -1)count++;
  }
  printf("%d\n",count);
  return 0;
}

int Binary_Search(int *array,int L,int key,int R){
  if(L == ((L+(R))/2)){
    if(*(array + ((L+(R-1))/2)) == key) return key;
    else return -1;
  }
  else if(*(array + ((L+(R))/2)) < key) return Binary_Search(array,(L+(R))/2+1,key,R); 
  else if(*(array + ((L+(R))/2)) > key) return Binary_Search(array,L,key,(L+(R))/2); 
  else return key;
}



Measured memory_bytes: 2136
from heapq import heappush, heappop
from collections import defaultdict

N, K = map(int, input().split())
TD = []

sushi = []
kinds = []


for i in range(N):
  t, d = map(int, input().split())
  sushi.append((d, t))
  kinds.append(t)

sushi.sort(key=lambda x: x[0], reverse=True)
sushidict = defaultdict(int)
kind_all = len(set(kinds))

cnt = 0
sushiq = []

for i in range(K):
  d, t = sushi[i]
  heappush(sushiq, (d, t))
  sushidict[t] += 1
  cnt += d

n_kind = len(sushidict)
res = []
res.append(cnt+n_kind**2)

for i in range(K, N):
  d, t = sushi[i]

  if sushidict[t] > 0:
    continue

  d_min, t_min = heappop(sushiq)
  while sushidict[t_min] == 1 and sushiq:
    d_min, t_min = heappop(sushiq)

  if not sushiq:
    break

  sushidict[t_min] -= 1
  sushidict[t] += 1
  n_kind += 1
  cnt = cnt - d_min + d

  res.append(cnt+n_kind ** 2)
  if n_kind == kind_all:
    break

print(max(res))

Measured memory_bytes: 29784
#include<iostream>
#include<algorithm>
using namespace std;
int dp[100005];
int arr[100005];
int main()
{
    int n;
    cin>>n;
    //int arr[n];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    dp[1]=0;
    dp[2]=abs(arr[1]-arr[2]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]) , dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 4276
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep (i, n) cin >> p[i];
  rep (i, n) cin >> q[i];
  vector<int> v(n);
  iota(all(v), 1);
  int a, b, i = 1;
  do {
    if (v == p) a = i;
    if (v == q) b = i;
    ++i;
  } while (next_permutation(all(v)));
  cout << abs(a - b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

using namespace std;

int hasil,input; 

int main()
{
	while(scanf("%d",&input) != EOF)
	{	
	hasil=0;
	for (int a=0;a<=9;a++)
	{
		for (int b=0;b<=9;b++)
		{
			for (int c=0; c<=9; c++)
			{
				for (int d=0;d<=9; d++)
				{
					if(input==a+b+c+d)
					{
						hasil++;
					}
				}
			}
		}
	}
	printf("%d\n",hasil);
	}
	return 0;
}

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


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


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


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


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


a = z()
print(a+a**2+a**3)


Measured memory_bytes: 27112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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

const int MAX = 100010;

int n, m;
ll dp[MAX];
bool broken[MAX];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        broken[a] = true;
    }
    dp[0] = 1;
    if (!broken[1])
    {
        dp[1] = 1;
    }
    for (int i = 2; i <= n; i++)
    {
        dp[i] = (dp[i - 2] + dp[i - 1]) % MOD;
        if (broken[i])
        {
            dp[i] = 0;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4456
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

A, B, C, D = list(map(int, input().split()))
_all = B - A + 1
lcm = int(C * D / gcd(C, D))
x = (A-1) - ((A-1) // C) - ((A-1) // D) + ((A-1) // lcm)
y = B - (B // C) - (B // D) + (B // lcm)
print(y - x)


Measured memory_bytes: 3060
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n, k = map(int, input().split())
r_max = n - k
b_max = k
for x in range(k):
    i = x + 1
    b = b_max - i
    r = r_max - i + 1
    if b < 0 or r < 0:
        print(0)
        continue
    r_count = cmb(i + r, i)
    b_count = cmb(b + i - 1, i - 1)
    # print("i({}), r({}), b({}), rc({}), bc({})".format(i, r, b, r_count, b_count))
    print(r_count * b_count % 1000000007)


Measured memory_bytes: 3944
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,sei,fu;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n){
        cin>>a[i];
        if(a[i]==0)continue;
        if(a[i]<0)fu++;
        else sei++;
    }
    if(sei==0&&fu==0)Cout(0);
    else if(sei==0&&fu!=0){
        Cout(n-1);
        rrrep(i,n,2){
            cout<<i<<" "<<i-1<<"\n";
        }
    }
    else if(sei!=0&&fu==0){
        Cout(n-1);
        rrep(i,1,n){
            cout<<i<<" "<<i+1<<"\n";
        }
    }
    else{
        rep(i,n){
            if(pos<=abs(a[i])){
                pos=abs(a[i]);
                tmp=i;
            }
        }
        Cout((n-1)*2);
        rep(i,n){
            if(tmp==i)continue;
            cout<<tmp+1<<" "<<i+1<<"\n";
        }
        if(a[tmp]>0){
            rrep(i,1,n){
                cout<<i<<" "<<i+1<<"\n";
            }
        }
        else{
            rrrep(i,n,2){
                cout<<i<<" "<<i-1<<"\n";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final int x = scanner.nextInt();
        final int t = scanner.nextInt();

        System.out.println((n + x - 1) / x * t);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 32692
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long i,n;
    cin>>n;
  	long f[n],h[n];
    for(i=0;i<n;i++)
        cin>>h[i];
  	f[0] = 0;
    f[1] = abs(h[0]-h[1]);
    f[2] = min(abs(h[0]-h[2]),f[1]+abs(h[1]-h[2]));
    for(i=3;i<n;i++)
        f[i] = min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
    cout<<f[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
    
    int x = 700;
    char s[4];
    
    if( scanf("%s", s)) {
     
        for(int i = 0; i < 3; ++i) {
            if (s[i] == 'o') {
                x += 100;
            }
        }
   
    }
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)
// コンパイル　g++ -std=c++17 a.cpp

int main() {
    double n, k;
    cin >> n >> k;
    vector<double> vec(n);
    rep(i, n) cin >> vec.at(i);

    vector<double> dice(n);
    rep(i,n){
        dice.at(i) = ((1+vec.at(i)) * vec.at(i) / 2) / vec.at(i);
    }
    
    /*
    rep(i,n){
        cout << dice.at(i) << " ";
    }
    cout << endl;
    cout << "----" << endl;
    */
    
   ll flag = 0;
   double ans = 0;
   double tmp = 0;
   rep(i,n){
       if(i >= k-1){
           if(flag == 0){
                rep(j, k){
                    tmp += dice.at(j);
                }
                flag = 1;
           }else{
               tmp -= dice.at(i - k);
               tmp += dice.at(i);
           }
       }

       if(ans < tmp){
           ans = tmp;
       }
   }

    /*
    double ans = 0;
    rep(i, n-k+1){
        double tmp = 0;
        rep(j, k){
            tmp += dice.at(i+j);
        }

        if(ans < tmp){
            ans = tmp;
        }
    }
    */

    cout << fixed << setprecision(6) << ans << endl;;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        System.out.println(a.substring(0, 1).toUpperCase() + b.substring(0, 1).toUpperCase() + c.substring(0, 1).toUpperCase());
    }

}

Measured memory_bytes: 21844
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int w,h,n,a[16],m[10][10],bx[16],by[16],mans[10][10],ans;
void dfs(int c){
	if(c==n+1){
		rep(i,h)rep(j,w)mans[i][j]=m[i][j];
		ans++;return;
	}
	for(int i=1;i<=a[c];i++)if(a[c]%i==0){
		int x=i,y=a[c]/i;
		rep(j,x)rep(k,y){
			int l=bx[c]-j,r=l+x,t=by[c]-k,b=t+y;
			if(l<0||r>w||t<0||b>h)continue;
			for(int ii=l;ii<r;ii++)for(int jj=t;jj<b;jj++)if(m[jj][ii]!=0&&m[jj][ii]!=c)goto NEXT;
			for(int ii=l;ii<r;ii++)for(int jj=t;jj<b;jj++)m[jj][ii]=c;
			dfs(c+1);
			for(int ii=l;ii<r;ii++)for(int jj=t;jj<b;jj++)m[jj][ii]=0;
			m[by[c]][bx[c]]=c;
			NEXT:;
		}
	}
}
int main(){
	while(cin>>w>>h>>n,w){
		int t,u,sum=0;
		rep(i,n)cin>>t>>u,a[t]=u,sum+=u;
		rep(i,h)rep(j,w){
			cin>>t;m[i][j]=t;
			if(t!=0)bx[t]=j,by[t]=i;
		}
		if(sum!=w*h)goto FAIL;
		ans=0;dfs(1);
		if(ans==1){
			rep(i,h)rep(j,w)cout<<mans[i][j]<<(j==w-1?'\n':' ');
			continue;
		}
		FAIL:cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 868
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        int N = cin.Nextint;
        var A = cin.Scanlong;
        var C = Enumerable.Range(0, N).ToArray();
        var G = A.Select((x, y) => new { x, y }).OrderByDescending(z => z.x).ThenByDescending(z => z.y).ToArray();

        var ans = new long[N];
        int min = G[0].y;
        for (int i = 1; i < N; i++)
        {
            ans[min] += i * (G[i - 1].x - G[i].x);
            min = Math.Min(min, G[i].y);
        }
        ans[0] = A.Sum() - (ans.Sum() - ans[0]);

        foreach (var v in ans)
        {
            WriteLine(v);
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 36188
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    int q;
    cin >> q;
    bool reversed = false;
    string ini = ""; // reverse after
    string end = "";
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {
            reversed = !reversed;
        }else {
            int t2;
            cin >> t2;
            char c;
            cin >> c;
            if(t2 == 1) {
                if(reversed) end += c;
                else ini += c;
            }else {
                if(reversed) ini += c;
                else end += c;
            }
        }
    }
    reverse(ini.begin(), ini.end());
    if(!reversed) {
        cout << ini << s << end << endl;
    }else {
        reverse(ini.begin(), ini.end());
        reverse(end.begin(), end.end());
        reverse(s.begin(), s.end());
        cout << end << s << ini << endl;
    }
}


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

int main() {

  long long N,sum;

  sum=0;

  cin >> N;
  for(int i=1; i<N+1; i++ ){

    if(i%15==0){
      continue;
    }

    if(i%3==0){
      continue;
    }

    if(i%5==0){
      continue;
    }


    sum=sum+i;

  }

  cout << sum ;

}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {
int a,b,c,d;
scanf("%d",&a);
b = a / 3600;
c = ( a % 3600) /60;
d = a-(b*3600)-(c*60);
printf("%d:%d:%d\n",b,c,d);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 200010;
int64_t S[MAXN][20]; // Aのi番目までの、j桁目(2進数)の和

int main()
{
  int64_t N, a, j, ans = 0, prev = -1;
  cin >> N;
  vector<pair<int64_t, int64_t>> A;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    if (i >= 1 && a == 0)
    {
      if (prev == 0)
        A.at(A.size() - 1).second++;
      else
        A.push_back({0, 1});
    }
    else
    {
      A.push_back({a, 1});
    }
    prev = a;
  }
  int64_t n = A.size();
  for (int i = 0; i < n; i++)
  {
    a = A.at(i).first, j = 0;
    for (int j = 0; j < 20; j++)
    {
      S[i + 1][j] = S[i][j] + (a % 2);
      a /= 2;
    }
  }
  for (int l = 1; l <= n; l++)
  {
    bool ok = 1;
    for (int r = l; r <= n; r++)
    {
      for (int j = 0; j < 20; j++)
      {
        if (S[r][j] - S[l - 1][j] > 1)
        {
          ok = 0;
          break;
        }
      }
      if (ok)
      {
        if (A.at(l - 1).first == 0 && A.at(r - 1).first == 0)
        {
          int64_t lz = A.at(l - 1).second, rz = A.at(r - 1).second;
          if (l == r)
          {
            ans += lz * (lz + 1) / 2;
          }
          else
          {
            ans += lz * rz;
          }
        }
        else if (A.at(l - 1).first == 0)
        {
          ans += A.at(l - 1).second;
        }
        else if (A.at(r - 1).first == 0)
        {
          ans += A.at(r - 1).second;
        }
        else
        {
          ans++;
        }
      }
      else
      {
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 35692
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n,p,x=1;
    string s;
    cin >> n;
    vector<pair<string,int>> r(n),c(n);
    for(int i=0;i<n;i++){
        cin >> s >> p;
        r[i].first=s;
        r[i].second=-10000*p-x;
        x++;
    }
    sort(r.begin(),r.end());
    for(int i=0;i<n;i++){
        int y=r[i].second;
        cout << (-1*y)%1000 << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#define M 55
#define ll long long
using namespace std;
template <class T>
inline void Rd(T &res){
	char c;res=0;int k=1;
	while(c=getchar(),c<48&&c!='-');
	if(c=='-'){k=-1;c='0';}
	do{
		res=(res<<3)+(res<<1)+(c^48);
	}while(c=getchar(),c>=48);
	res*=k;
}
template <class T>
inline void Pt(T res){
	if(res<0){
		putchar('-');
		res=-res;
	}
	if(res>=10)Pt(res/10);
	putchar(res%10+48);
}
int n,p;
int A[M];
ll dp[6005];
int main(){
	Rd(n);Rd(p);
	for(int i=1;i<=n;i++)Rd(A[i]);
	dp[0]=1;
	for(int i=1;i<=n;i++)
	for(int j=5000;j>=0;j--)
	if(dp[j]){
		dp[j+A[i]]+=dp[j];
	}
	ll ans=0;
	for(int i=0;i<=5000;i++)
	if(dp[i]&&i%2==p)ans+=dp[i];
	Pt(ans);
	return 0;
}

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]


s1,s2,s3 = map(str, input().split())

print(s1[0].upper()+s2[0].upper()+s3[0].upper())


Measured memory_bytes: 9024
import java.io.*;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.ArrayList;

public class Main {
    public static void main(String [] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        int [] logs = new int[n];
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){
            logs[i] = Integer.parseInt(st.nextToken());
        }

        Arrays.sort(logs);

        int ans = logs[n-1], l = 1, r = logs[n-1];
        while(l <= r){
            int m = (l + r) / 2;
            int knum = k;
            for(int i=n-1;i>=0;i--){
                if(m >= logs[i]) break;
                knum -= (logs[i] / m -1);
                if(logs[i] % m != 0) knum -= 1;
            }

            if(knum >=0){
                ans = (ans > m ? m : ans);
                r = m-1;
            }else{
                l = m+1;
            }
        }
        bw.write(ans+"");
        bw.flush();
        bw.close();
        br.close();
    }
}


Measured memory_bytes: 60564
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,j,N,K,a=LLONG_MAX;
  string ss;
  cin>>N>>K;
  vec v(N);
  rep(i,N){
    cin>>v[i];
    a=min(a,v[i]);
    K-=v[i];
  }
  j=K/a;
  cout<<N+j<<endl;
 
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace d
{
    class Program
    {
        public static int Main()
        {
            new Program().calc();
            return 0;
        }

        Scanner sc;

        public void calc()
        {
            sc = new Scanner();
            int n = sc.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = sc.nextInt();
            }
            long ans = 0;
            int now = 1;
            int max = 0;
            for (int i = 0; i < n; i++)
            {
                if(a[i] > now)
                {
                    ans += (a[i] - 1) / now;
                    max = Math.Max(max, 1);
                    now = max + 1;
                }
                else
                {
                    max = Math.Max(max, a[i]);
                    now = max + 1;
                }
            }
            Console.WriteLine(ans);

        }

    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            while (i >= s.Length)
            {
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
            }
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

    }
}

Measured memory_bytes: 7128
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];

int H, W;

long long dp[1005][1005];
long long a[1005][1005];

int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

double dist[8][8];

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

int dfs(int y, int x) {
	if (dp[y][x] != -1)return dp[y][x];
	ll count = 1;
	for (int i = 0; i < 4;++i) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (ny < 0 || H <= ny || nx < 0 || W <= nx)continue;
		if (a[y][x] < a[ny][nx]) {
			count = (count + dfs(ny, nx)) % MOD;
		}
	}
	dp[y][x] = count;
	return count;
}

int main() {
	int X, Y;
	cin >> X >> Y;

	ll ans = 0;
	if ((X + Y) % 3 == 0) {
		double n, m;
		m = (2 * X - Y) / 3;
		n = (2 * Y - X) / 3;
		int N = (int)n;
		int M = (int)m;
	
		if (n == N && m == M && 0 <= n && 0 <= m) {
			initCombination(n + m);
			ans = combination(n + m, n);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 14592
#include <vector>
#include <array>
#include <algorithm>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <iomanip>
#include <numeric>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;

#define fi first
#define se second

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll INF = (ll) 1e15;

struct SegmentTree {
    SegmentTree(ll n) : n(n), t(n * 2, {0, 0}) {}
    SegmentTree(vl x) : n(x.size()), t(n * 2, {0, 0}) {
        for (int i = 0; i < n; ++i) {
            t[i + n] = {x[i], i};
        }
        build();
    }

    pll combine(pll a, pll b) {
        return max(a, b);
    }

    void build() {  // build the tree
        for (ll i = n - 1; i > 0; --i) t[i] = combine(t[i << 1], t[(i << 1) | 1]);
    }

    void modify(ll p, ll value) {  // set value at position p
        for (t[p += n].fi = value; p > 1; p >>= 1) t[p >> 1] = combine(t[p], t[p ^ 1]);
    }

    pll query(ll l, ll r) {  // [l, r)
        pll res = {-INF, 0};
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res = combine(res, t[l++]);
            if (r & 1) res = combine(res, t[--r]);
        }
        return res;
    }

    ll n;
    vector<pll> t;
};

void no() {
    cout << "-1" << endl;
    exit(0);
}

int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    cin >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

    for (int i = 0; i < n; ++i) {
        if (a[i] > b[i]) no();
    }

    ll ans = 0;
    SegmentTree st(b);
    while (true) {
        auto res = st.query(0, n);
        ll bb = res.first;
        ll i = res.second;

        if (bb == -INF) break;
        if (bb == a[i]) {
            st.modify(i, -INF);
            continue;
        }
        ll aa = b[(i - 1 + n) % n];
        ll cc = b[(i + 1) % n];
        assert(aa <= bb && cc <= bb);
        ll dd = aa + cc;

        assert(bb > a[i]);
        ans += (bb - a[i]) / dd;
        bb = a[i] + (bb - a[i]) % dd;
        if (b[i] == bb) no();
        b[i] = bb;

        st.modify(i, bb);
    }

    cout << ans << endl;

    return 0;
}

// BBRGRRGRGGRBBGB

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 + 7;
const int K = 100 * 1000 + 13;

int n, k;
int a[N];

bool read () {
	if (scanf("%d%d", &n, &k) != 2)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	return true;
}

int dp[2][K];
int sum[2][K];

int add(int a, int b){
	a += b;
	if (a < 0)
		a += MOD;
	if (a >= MOD)
		a -= MOD;
	return a;
}

void solve(){
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	fore(i, 1, k + 2)
		sum[0][i] = 1;
	
	forn(ii, n){
		int i = ii & 1;
		int ni = i ^ 1;
		memset(dp[ni], 0, sizeof(dp[ni]));
		forn(j, k + 1){
			dp[ni][j] = add(dp[ni][j], add(sum[i][j + 1], -sum[i][max(0, j - a[ii])]));
			sum[ni][j + 1] = add(sum[ni][j], dp[ni][j]);
		}
	}
	
	printf("%d\n", dp[n & 1][k]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
}node;

typedef struct node *Node;

Node root;

Node treeMinimum(Node x){
  while(x -> left != NIL)
    x = x -> left;
  return x;
}

Node treeMaximum(Node x){
  while(x -> right != NIL)
    x = x -> right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL && k == u ->key)
    return u;

  if(k < u -> key)
    return treeSearch(u -> left, k);

  if(k > u -> key)
    return treeSearch(u -> right, k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x -> right != NIL)
    return treeMinimum(x -> right);

  y = x -> parent;

  while(y != NIL && x == y -> right){
    x = y;
    y = y -> parent;
  }

  return y;
}

void treeDelete(Node z){
  Node x;
  Node y;

  if(z -> left == NIL || z -> right == NIL)
    y = z;

  else
    y = treeSuccessor(z);

  if(y -> left != NIL)
    x = y -> left;

  else
    x = y -> right;

  if(x != NIL)
    x -> parent = y -> parent;

  if(y -> parent == NIL)
    root = x;

  else if(y == y -> parent -> left)
    y -> parent -> left = x;

  else 
    y -> parent -> right = x;

  if(y != z)
    z -> key = y -> key;
}

void insert(int k){
  Node x = root;
  Node y = NIL;
  Node z;

  z = malloc(sizeof(node));

  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while( x != NIL){
    y = x;
    if(z -> key < x -> key)
      x = x -> left;

    else
      x = x -> right;
  }

  z -> parent = y;

  if(y == NIL)
    root = z;

  else if(z -> key < y -> key)
    y -> left = z;

  else
    y -> right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u -> left);
    
    printf(" %d", u -> key);
    
    inorder(u -> right);
  }
}

void preorder(Node u){
  if(u != NIL){
    printf(" %d", u -> key);
    
    preorder(u -> left);
    preorder(u -> right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25244
#include<stdio.h>
int main(){
  int h,w,n,a,i,j,d[100010],r=0;
  scanf("%d %d %d",&h,&w,&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    for(j=0;j<a;j++)d[r++]=i+1;
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(j)printf(" ");
      printf("%d",d[i*w+(i%2?w-j-1:j)]);
    }
    printf("\n");
  }
  return 0;
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

ll n, k;

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

    cout << min(n%k, k-n%k) << '\n';

    return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**9)


INF = 10**20
def main():
    N,M = map(int,input().split())

    graph = [[] for _ in range(N)]
    for i in range(M):
        A,B = map(int,input().split())
        graph[B-1].append(A-1)
        graph[A-1].append(B-1)

    stack = deque([0])
    ans = [0]*N
    visited = set()
    while len(stack) > 0:
        x = stack.popleft()
        for next in graph[x]:
            if not next in visited:
                ans[next] = x
                visited.add(next)
                stack.append(next)

    if len(visited) != N:
        print("No")
    else:
        print("Yes")
        for i in ans[1:]:
            print(i+1)



if __name__ == "__main__":
  main()

Measured memory_bytes: 105672
import sys
n = int(input())
b = [0]
pushed = [0] * (n + 1)
for i in range(n):
  b.append(int(input()))
push = 1
cnt = 0
while(push != 2):
  if (pushed[push] != 1):
    pushed[push] = 1
    cnt += 1
    push = b[push]
  else:
    print(-1)
    sys.exit()
print(cnt)

Measured memory_bytes: 7848
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_set>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int S(ll a) {
  int sum = 0;
  while(a > 0) {
    sum += a % 10;
    a /= 10;
  }
  return sum;
}

int main() {
  int K;
  cin >> K;
  vector<ll> c;
  for (int i = 1; i <= 999; i++) {
    c.push_back(i);
  }
  string s = "99";
  for(int i = 2; i < 15; i++) {
    for (int j = 1; j <= 999; j++) {
      stringstream ss;
      ss << j << s;
      c.push_back(stoll(ss.str()));
    }
    s += "9";
  }
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());


  for (int i = 0; i < c.size(); i++) {
    bool flag = true;
    for (int j = i + 1; j < c.size(); j++) {
      if ((double)c[i] * S(c[j]) > (double)c[j] * S(c[i])) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << c[i] << endl;
      K--;
      if (K == 0) break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 512
{-# LANGUAGE BangPatterns, MultiWayIf #-}

import Control.Applicative
import Control.Monad
import Data.List

f (a, b) acc
    | a < b      = (b - a + 1) `div` 2 + acc
    | otherwise  = acc

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- fmap read . words <$> getLine :: IO [Int]
    bs <- fmap read . words <$> getLine :: IO [Int]
    let k  = sum bs - sum as
    let ak = foldr f 0 (zip as bs)
    if ak <= k
        then putStrLn "Yes"
        else putStrLn "No"

Measured memory_bytes: 11644
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main() {
    cin>>a;
    b=a;
    int j=a.size();
    for(int i=0; i<a.size(); i++)
        a[--j]=b[i];
    for(int i=0; i<a.size(); i++) {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b)
    cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 512
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w,a,b = map(int, input().split())


M = 10**9+7 # 出力の制限
N = h+w+10 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

ans = 0
for i in range(h-a-1):
    ans += cmb(b+i, i, M) * cmb(w-b-2+h-1-i, w-b-2, M)
    ans %= M
i = h-a-1
ans += cmb(b+i, i, M) * cmb(w-b-1+a, a, M)
print(ans%M)

Measured memory_bytes: 93836
#include <stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N],dpos[2 * N -1],dneg[2 * N -1];
int Aray[N][N];

void printBoard(){
    int i,j;
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(Aray[i][j] == NOT_FREE){
                if(row[i] != j) return;
            }
        }
    }
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(row[i]==j){ printf("Q");
     }else printf(".");
    }
     printf("\n");
    }
}

void recursive(int i){
    int j;
    if(i==N){ //You can put the Queen
        printBoard();
        return;
    }
    for(j=0;j<N;j++){
        if(NOT_FREE == col[j] || NOT_FREE == dpos[i+j] || NOT_FREE == dneg[i-j + N -1]){
            continue;
        }
        row[i] = j;

        col[j] = NOT_FREE;
        dpos[i+j] = NOT_FREE;
        dneg[i-j + N -1] = NOT_FREE;

        recursive(i+1);
        row[i] = FREE;
        col[j] = FREE;
        dpos[i+j] = FREE;
        dneg[i-j + N -1] = FREE;
    }
}

int main(){
  int i,n,a1,a2;

    for(i=0;i<N;i++){
        row[i] = FREE;
        col[i] = FREE;
    }

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&a1,&a2);
    Aray[a1][a2]=1;
  }
 
  recursive(0);
 
  return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;

int main()
{
  int A,B;
  string S;
  cin >> A >> S >>  B;
  cout << (S=="+" ? A+B : A-B) << endl;
  return 0;
}



Measured memory_bytes: 256