akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<time.h>
#include<vector>
#include<cstring>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define R register
#define LL long long
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
const LL inf=1e18;

LL a,b,c,k;

namespace FastIO {
	template<typename tp> inline void read(tp &x) {
		x=0; register char c=getchar(); register bool f=0;
		for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
		for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
		if(f) x=-x;
	}
	template<typename tp> inline void write(tp x) {
	  if (x==0) return (void) (putchar('0'));
     if (x<0) putchar('-'),x=-x;
     int pr[20]; register int cnt=0;
     for (;x;x/=10) pr[++cnt]=x%10;
     while (cnt) putchar(pr[cnt--]+'0');
	}
	template<typename tp> inline void writeln(tp x) {
		write(x);
		putchar('\n');
	}
}
using namespace FastIO;

int main() {
	read(a); read(b); read(c); read(k);
	k%=2;
	for (int i=1;i<=k;i++) {
		LL x=a,y=b,z=c;
		a=y+z; b=x+z; c=x+y;
	}
	if (abs(a-b)>inf) puts("Unfair");
	else cout<<a-b;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string s;cin >> s;
  if(s=="Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(s=="Cloudy"){
    cout << "Rainy" << endl;
  }
  else{
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ShekharN
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        MedianSum solver = new MedianSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class MedianSum {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = IntStream.range(0, n).map(id -> in.nextInt()).toArray();
            int sum = Arrays.stream(arr).sum();
            BigInteger now = BigInteger.ONE;
            now = now.or(BigInteger.ONE.shiftLeft(arr[0]));
            for (int j = 1; j < n; j++) {
                now = now.or(now.shiftLeft(arr[j]));
            }
            int start = sum / 2 + (sum & 1);
            for (int i = start; i <= sum; i++) {
                if (!BigInteger.ONE.shiftLeft(i).and(now).equals(BigInteger.ZERO)) {
                    out.println(i);
                    break;
                }
            }
        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 343044
#include <bits/stdc++.h>
typedef long long ll;
#define mx 400
#define pb push_back
ll mod = 1e9 + 7;
using namespace std;
ll arr[mx + 3];
ll dp[mx + 3][mx + 3];
ll inf = 1e18;
ll solve(int i, int j) {
	if (i == j)
		return 0;
	if (dp[i][j] != inf)
		return dp[i][j];
	for (int k = i; k < j; ++k)
		 dp[i][j] = min(dp[i][j], solve(i, k) + solve(k + 1, j));
	return dp[i][j] +=  arr[j] - arr[i - 1];
}
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			dp[i][j] = inf;

	for (int i = 1; i <= n; ++i)
		cin >> arr[i], arr[i] += arr[i - 1];
	cout << solve(1, n) << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a.at(i) = tmp - 1;
    }

    int pt = 0;
    int count = 0;
    bool flag = false;

    for (int i = 0; i < n; i++) {
        pt = a.at(pt);
        count++;
        if (pt == 1) {
            flag = true;
            break;
        }
    }
    if (flag)
        cout << count << endl;
    else
        cout << -1 << endl;
}


Measured memory_bytes: 640
from copy import*
n,a,b,c,d=map(int,input().split())
s=input()
if "##" in s[a-1:c] or "##" in s[b-1:d]:
    print("No")
else:
    if c<d:
        print("Yes")
    else:
        if "..." in s[max(0,b-2):min(d+1,n)]:
            print("Yes")
        else:
            print("No")


Measured memory_bytes: 4084
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

const double EPS = 1e-10;

double add(double a,double b){
	if(abs(a+b) < EPS* (abs(a)+abs(b))) return 0;
	return a+b;
}

struct V{
	double x,y;
	V() {}
	V(double x,double y) : x(x), y(y){
	}
	V operator + (V p){
		return V(add(x, p.x), add(y, p.y));
	}
	V operator - (V p){
		return V(add(x,-p.x),add(y,-p.y));
	}
	V operator * (double d){
		return V(x*d,y*d);
	}
	bool operator == (V p){
		return add(x,-p.x)==0&&add(y,-p.y)==0;
	}
	double dot(V p){
		return add(x*p.x, y*p.y);
	}
	double det(V p){
		return add(x*p.y, -y*p.x);
	}
};

bool on_seg(V v1, V v2, V q){//v1-v2上にqがあるか判定
	return (v1 - q).det(v2 - q) == 0 && (v1 - q).dot(v2 - q) <= 0;
}

V intersection(V v1,V v2,V q1,V q2){ //直線v1-v2とq1-q2の交点
	return v1 + (v2-v1) * ( (q2-q1).det(q1-v1) / (q2-q1).det(v2-v1) );
}

bool cmp_x(const V& p,const V& q){
	if(p.x != q.x) return p.x<q.x;
	else return p.y<q.y;
}

double dist(V p,V q){
	return (p-q).dot(p-q);
}

vector<V> cnv(V* vs,int n){
	sort(vs,vs+n,cmp_x);
	int k=0;
	vector<V> qs(n*2);
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(vs[i]-qs[k-1])<=0) k--;
		qs[k++] = vs[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(	k>t	&&	(qs[k-1]-qs[k-2]).det(vs[i]-qs[k-1])<=0		) k--;
		qs[k++] = vs[i];
	}
	qs.resize(k-1);
	return qs;
}

int N;
V v[100],tmp[100];
double ans[100];
int id[100];
double calc(V p1,V p2,V p3){
	V s=p3-p2,t=p1-p2;
	if(s==t) return 0.5;
	return ( M_PI - acos(s.dot(t)/ ( sqrt(s.dot(s))*sqrt(t.dot(t))	)	)     )/(2*M_PI);
}
int main()
{
	memset(id,-1,sizeof(id));
	cin>>N;
	rep(i,N){
		cin>>v[i].x>>v[i].y;
		tmp[i]=v[i];
	}
	vector<V> nv=cnv(v,N);
	rep(i,N){
		rep(j,nv.size()){
			if(tmp[i]==nv[j]){
				id[j]=i;
			}
		}
	}
	rep(i,nv.size()){
		if(i==0){
			ans[id[i]]=calc(nv[nv.size()-1],nv[0],nv[1]);
		}
		else if(i==nv.size()-1){
			ans[id[i]]=calc(nv[i-1],nv[i],nv[0]);
		}
		else ans[id[i]]=calc(nv[i-1],nv[i],nv[i+1]);
	}
	rep(i,N) printf("%.50lf\n",ans[i]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int N;
    scanf("%d", &N);
    int a[N];
    int sm = 0, sq = 0; //総和,二乗和
    REP(i, 0, N) {
        scanf("%d", &a[i]);
        sm += a[i], sq += a[i]*a[i];
    }
    int X1 = sm/N;
    int X2 = X1 + 1;
    int res1 = N*X1*X1 - 2*X1*sm + sq;
    int res2 = N*X2*X2 - 2*X2*sm + sq;
    printf("%d\n", min(res1, res2));
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str;

fn main() {
    let a = read_vec::<i32>();
    let x = a[0];
    let y = a[1];
    println!("{}", x + y / 2);
}

fn read<T: str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
/**
*    author:  souzai32
*    created: 15.08.2020 01:38:51
**/

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
typedef long long ll;
using namespace std;

int main() {

    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<int> white(n+1),black(n+1);
    for(int i=1; i<n+1; i++){
        if(s.at(i-1)=='#') black.at(i)++;
        if(i!=n) black.at(i+1)=black.at(i);
    }
    reverse(all(s));
    for(int i=1; i<n+1; i++){
        if(s.at(i-1)=='.') white.at(i)++;
        if(i!=n) white.at(i+1)=white.at(i);
    } 

    int ans=2e5;
    for(int i=0; i<=n; i++) ans=min(ans,black.at(i)+white.at(n-i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5148
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		int n;
		long[] arr;
		if (k <= 50) {
			if (k == 0) {
				n = 2;
				arr = new long[]{1, 1};
			} else if (k == 1) {
				n = 2;
				arr = new long[]{0, 2};
			} else {
				n = (int)k;
				arr = new long[n];
				for (int i = 0; i < n; i++) {
					arr[i] = i + 1;
				}
			}
		} else {
			long div = k / 50;
			long mod = k % 50;
			n = 50;
			arr = new long[50];
			for (int i = 0; i < 50; i++) {
				arr[i] = i + div;
			}
			for (int i = 0; i < mod; i++) {
				arr[n - 1 - i]++;
			}
		}
		StringBuilder sb = new StringBuilder();
		sb.append(n).append("\n");
		for (int i= 0; i < n; i++) {
			if (i != 0) {
				sb.append(" ");
			}
			sb.append(arr[i]);
		}
		System.out.println(sb);
	}
}


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

int main() {
  int N, A;
  int rest;
  cin >> N >> A;

  rest = N % 500;
  if(rest == 0) {
    cout << "Yes" << endl;
  } else if(A == 0) {
    cout << "No" << endl;
  } else if(A < rest) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(cal("", n));
    }
    public static int cal(String s, int N){
        if(s.equals("")){
            int ret = 0;
            ret += cal("3", N);
            ret += cal("5", N);
            ret += cal("7", N);
            return ret;
        }else{
            if(Integer.parseInt(s) > N) return 0;
            int ret = 0;
            boolean a = false;
            boolean b = false;
            boolean c = false;
            for(int i = 0;i < s.length();i++){
                if(s.charAt(i) == '3')  a = true;
                else if(s.charAt(i) == '5') b = true;
                else if(s.charAt(i) == '7') c = true;
            }
            if(a && b && c) ret++;
            if(s.length() == 9) return ret;
            ret += cal(s+3, N);
            ret += cal(s+5, N);
            ret += cal(s+7, N);
            return ret;
        }
    }
}

Measured memory_bytes: 26836
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

R1 = [0] * N
R2 = [0] * N
for i in range(N - 1, -1, -1):
    R1[i] = min(A[i + 1], B[i])
    B[i] -= R1[i]
    R2[i] = min(A[i], B[i])
    A[i] -= R2[i]

ans = sum(R1) + sum(R2)
print(ans)


Measured memory_bytes: 20416
#ifdef __cplusplus
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#endif

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
#define BIG_PRIME 1000000007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF (1 << 30)
#define INF_NEG (INF * -1)
#define INF_LONG (1LL << 62)
#define INF_LONG_NEG (INF_LONG * -1L)

typedef long long ll;
typedef char str255[256];
int StrLen(char *s) { for(int ptr = 0;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除, 削除後の文字数を返す
int StrDel(char *s, int n) { int l = StrLen(s); s[l - n + 1] = '\0'; return l - n; }

int NumDigits(int i){ char s[20]; return sprintf(s, "%d", i); }
int NumDigitsLL(long long l){ char s[30]; sprintf(s, "%lld", l); return strlen(s); }

int is1stAns = 1;
#ifdef __cplusplus
template <class T> 
void print(T t) { if (is1stAns) cout << t, is1stAns = 0; else cout << " " << t; }
#else
void printI(int    i) { if (is1stAns) printf(  "%d", i), is1stAns = 0; else printf(  " %d", i); }
void printL(ll     l) { if (is1stAns) printf("%lld", l), is1stAns = 0; else printf(" %lld", l); }
void printD(double d) { if (is1stAns) printf("%.9f", d), is1stAns = 0; else printf(" %.9f", d); }
void printC(char   c) { if (is1stAns) printf(  "%c", c), is1stAns = 0; else printf(  " %c", c); }
void printS(char  *s) { if (is1stAns) printf(  "%s", s), is1stAns = 0; else printf(  " %s", s); }
#endif

signed main()
{
#ifdef __cplusplus
    cout << fixed << setprecision(9);
#endif

    ll N, D; scanf("%lld %lld", &N, &D);
    ll d21 = D * 2 + 1;
    ll ans = N / d21;
    if (N % d21) ++ans;

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define ull unsigned long long
#define inf 0x3f3f3f3f
#define mod 1000000009
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
int n;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int solve()
{
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++)
		if(a[i]&1)cnt1+=(a[i]>1);
		else ++cnt0;
	int ret=cnt0&1;
	if(cnt1==1){
		int d=0;
		for(int i=1;i<=n;i++)
			if(a[i]&1)d=gcd(d,a[i]-1);
			else d=gcd(d,a[i]);
		for(int i=1;i<=n;i++)
			a[i]/=d;
		ret|=!solve();
	}
	return ret;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	puts(solve()?"First":"Second");
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }


vector<int> t_parent;
vector<int> t_ord;

void tree_getorder(const vector<vi> &g, int root) {
	int n = g.size();
	t_parent.assign(n, -1);
	t_ord.clear();

	vector<int> stk; stk.push_back(root);
	while(!stk.empty()) {
		int i = stk.back(); stk.pop_back();
		t_ord.push_back(i);
		for(int j = (int)g[i].size() - 1; j >= 0; j --) {
			int c = g[i][j];
			if(t_parent[c] == -1 && c != root) {
				t_parent[c] = i;
				stk.push_back(c);
			}
		}
	}
}

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<vector<int> > g(N);
		for(int i = 0; i < N - 1; ++ i) {
			int u, v;
			scanf("%d%d", &u, &v), -- u, -- v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		int K;
		scanf("%d", &K);
		vector<pair<int, int>> ranges(N, make_pair(-INF, INF));
		vector<int> parity(N, 3);
		rep(i, K) {
			int u; int p;
			scanf("%d%d", &u, &p), -- u;
			ranges[u] = { p, p };
			parity[u] = 1 << (p & 1);
		}
		tree_getorder(g, 0);
		for(int ix = (int)t_ord.size() - 1; ix > 0; -- ix) {
			int i = t_ord[ix], p = t_parent[i];
			amax(ranges[p].first, ranges[i].first - 1);
			amin(ranges[p].second, ranges[i].second + 1);
			parity[p] &= (parity[i] & 1) << 1 | (parity[i] & 2) >> 1;
		}
		vector<int> ans(N, -INF);
		bool ok = true;
		for(int ix = 0; ix < (int)t_ord.size(); ++ ix) {
			int i = t_ord[ix], p = t_parent[i];
			auto r = ranges[i];
			ok &= r.first <= r.second;
			ok &= parity[i] != 0;
			if(!ok) break;
			if(p != -1) {
				amax(r.first, ans[p] - 1);
				amin(r.second, ans[p] + 1);
			}
			assert(r.first <= r.second && (p == -1 || (ans[p] & 1) != (r.first & 1)));
			ans[i] = r.first;
		}
		puts(ok ? "Yes" : "No");
		if(ok) {
			for(int i = 0; i < N; ++ i)
				printf("%d\n", ans[i]);
		}
	}
	return 0;
}


Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N, K;
    cin >> N >> K;
    bool flag = false;
    //vector<vector<ll>> G(N,vector<ll>(N,1));
    vector<vector<ll>> G(N,vector<ll>(N,0));
    ll MM = 0;
    REP(i,1,N-1){
        MM += i;
    }
    if(K > MM){
        cout << -1 << endl;
        return 0;
    }
    rep(i,N-1){
        G[0][i+1] = 1;
        G[i+1][0] = 1;
    }
    cout << MM - K + N-1 << endl;
    ll cnt = 0;
    rep(i,N){
        REP(j,i+1,N){
            if(cnt == MM - K + N-1){
                flag = true;
                break;
            }
            cnt++;
            cout << i+1 << " " << j+1 <<endl;
        }
        if(flag) break;
    }
    /*
    rep(i,N){
        G[i][i] = 0;
    }
    ll cnt = 0;
    rep(i,N){
        REP(j,i+1,N){
            if(cnt == K){
                flag = true;
                break;
            }
            G[i][j] = 0;
            G[j][i] = 0;
            cnt++;
        }
        if(flag) break;
    }
    cout << (N*(N-1))/2 - K << endl;
    rep(i,N){
        REP(j,i+1,N){
            if(G[i][j]==0)continue;
            cout << i+1 <<" "<< j+1 << endl;
        }
    }
    /*
    ll s,t;
    REP(i,1,N){
        if(2*K == i*(i-1) + (N-i)*(N-i-1)){
            flag = true;
            s = i;
            t = N - i;
            break;
        }
    }
    if(K < N-1){
        flag = true;
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    if(K >= N-1){
        cout << s*t << endl;
        REP(i,1,s+1){
            REP(j,s+1,N+1){
                cout << i << " " << j << endl;
            }
        }
    }else{
        cout << N*(N-1)/2 - K << endl;
        REP(i,1,N+1){
            REP(j,i+1,N+1){
                if(i == 1 && i > K) continue;
                cout << i << " " << j << endl;
            }
        }
    }*/
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
vector<int> data[100];
pair<int, int> finds[100];

int dfs(int foo, int timer)
{
    //foo is node number
    if (finds[foo].first != -1)
        return timer;
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i, data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second = ++result;
    return result;
}

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        cin >> temp;
        rep(j, temp)
        {
            int foo;
            cin >> foo;
            data[i].push_back(foo - 1);
        }
    }
    rep(i, 100)
    {
        finds[i].first = -1;
    }
    int hoge = 0;
    rep(i, n) if (finds[i].first == -1)
        hoge = finds[i].second = dfs(i, hoge);
    rep(i, n)
    {
        cout << i + 1 << " " << finds[i].first << " " << finds[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1e9
using namespace std;
typedef long long ll;

int main() {
		int N, K, H[101010];
		scanf("%d %d", &N, &K);
		for ( int i = 0; i < N; i++ ) scanf("%d", &H[i]);

		sort(H, H + N);

		int ans = INF;
		for ( int L = 0; L < N-K+1; L++ ) {	
				int x;
				int R = L + K - 1;
				x = H[R] - H[L];
				if ( x < ans ) ans = x;
		}

		printf("%d\n", ans);

		return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef tuple<int,int,int> tii;

#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int main(){
  vector<ll> A;
  A.push_back(0);
  ll K; cin >> K;
  if(K<10){
    cout << K << endl;
    return 0;
  }
  int cnt = 0;
  queue<pii> que;
  for(int i=1;i<=9;i++){
    que.push(make_pair(i,i));
    A.push_back(i);
    cnt++;
  }
  while(cnt<K){
    pii P = que.front(); que.pop();
    ll x = P.first,y = P.second;
    for(int i=-1;i<=1;i++){
      ll nx = x + i;
      ll ny = 10*y + nx;
      if(nx>=0&&nx<=9){
        que.push(make_pair(nx,ny));
        A.push_back(ny);
        cnt++;
      }
    }  
    
  }
  cout << A[K] << endl;
}

Measured memory_bytes: 5168
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		int array[] = new int[N];
		for(int i=0;i<N;i++) {
			int P = scan.nextInt();
			array[i] = P;
		}
		Arrays.sort(array);

		int sum = 0;
		for(int j=0;j<K;j++) {
			sum = sum + array[j];
		}
		System.out.println(sum);

	}

}


Measured memory_bytes: 38856
n = int(input())
arr = []
arr = input().split() 
arr = [int(l) for l in arr]
even = [l for l in arr if l % 2 == 0]      
answer = []
for i in even: 
    if i % 3 == 0 or i % 5 == 0:
        answer.append(True)
if len(answer) == len(even): 
    print("APPROVED")
else: 
    print("DENIED")

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

int main()
{
    int n;
    cin >> n;
    int a[n];
    long long s=0;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        s+=a[i];
    }    
    long long es=0;
    for(int i=1;i<n;i+=2)   es+=a[i];
    long long m[n];
    m[0]=s-(2*es);
    for(int i=1;i<n;i++)
    {
        m[i]=(2*a[i-1])-m[i-1];
    }
    for(int i=0;i<n;i++)    cout << m[i] << " ";
    return 0;
}

Measured memory_bytes: 2432
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    l,r=parseMap(split(readline()))
    if l+2019-l%2019<=r
        println(0)
    else
        l%=2019
        r%=2019
        ans=2020
        for i in l:r
            for j in i+1:r
                ans=min(ans,(i*j)%2019)
            end
        end
        println(ans)
    end
end
main()

Measured memory_bytes: 110216
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int a[25],b[5];
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	memset(a,0,sizeof(a));
	int n,sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n-1;i++)
	{
		b[0]=a[i-1];b[1]=a[i];b[2]=a[i+1];
		sort(b,b+3);
		if(b[1]==a[i])sum++; 	
	}
	cout<<sum;
	
	
	}
	

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

vector<ll>dist;

struct edge{
  int to;
  ll cost;
  edge(int to,ll cost):to(to),cost(cost){}
};

void dijkstra(vector<vector<edge>> &g,int s){//sは始点
  const auto INFTY=numeric_limits<ll>::max();
  dist.resize(g.size(),INFTY);
  using P=pair<ll,int>;//firstは最短距離,secondは頂点の番号
  priority_queue<P,vector<P>,greater<P>>pq;
  dist[s]=0;
  pq.emplace(dist[s],s);

  while(!pq.empty()){
    auto x=pq.top();pq.pop();
    int v=x.second;
    if(dist[v]<x.first)continue;//最短距離でなければ飛ばす
    for(auto e:g[v]){
      if(dist[e.to]>dist[v]+e.cost){
        dist[e.to]=dist[v]+e.cost;
        pq.emplace(dist[e.to],e.to);
      }
    }
  }
  return ;
}

int main(){
    int n;
    cin>>n;
    vector<vector<edge>>g(n);
    ll a,b,c;
    rep(i,n-1){
        cin>>a>>b>>c;
        a--;b--;
        g[a].eb(b,c);
        g[b].eb(a,c);
    }
    int q,k;
    cin>>q>>k;
    k--;
    dijkstra(g,k);
    rep(i,q){
        int x,y;
        cin>>x>>y;
        x--;y--;
        cout<<dist[x]+dist[y]<<endl;
    }

    return 0;
    }


Measured memory_bytes: 11120
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const ll mod=1e9+7;
using namespace std;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	char c;
	cin>>c;
	cout<<(char)((int)c+1)<<endl;                                                                    
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int n,m,i,j,k,ch,r,live;
int e[1000][1000];

int main(){
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&ch,&k);
		for(;k>0;k--){
			scanf("%d",&r);
			e[ch][r]=1;
		}
	}
	
	m=1;
	while(1){
		ch=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(i!=j && e[i][j]==0){
					for(k=1;k<=n;k++){
						if(e[k][j]==1 && e[i][k]==m){
							e[i][j]=e[i][k]+1;
							ch++;
							break;
						}
					}
				}
			}
		}

		if(ch<1)break;
		m++;

	}

	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%d %d %d",&ch,&r,&live);
		if(e[ch][r]>0 && live>e[ch][r])printf("%d\n",e[ch][r]+1); else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int a, b;
  cin>>a >> b;
  
  while(a % b){
    int k = a % b;
    a = b;
    b = k;

  }
  cout<<b<<endl;
  
  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int a[4];

int main() {
  scanf("%d%d%d", &a[1], &a[2], &a[3]);
  sort(a + 1, a + 3 + 1);
  printf("%d\n", a[1] * a[2] / 2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster
    int a,b;
    cin>>a>>b;

    b=2*b;

    if(a>b)
        cout<<a-b<<endl;
    else
        cout<<0<<endl;




    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, m, in, ot, s, max;
	int i, j;

	scanf("%d%d", &n, &m);
	s = m; max = m;
	for (i = 0; i < n; i++) {
		scanf("%d%d", &in, &ot);
		s += in - ot;
		if (s < 0) {
			max = 0; break;
		}
		else if (s > max)
			max = s;
	}
	printf("%d\n", max);

	return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

template<typename T>
struct BIT {
	int n;
	vector<T> bit;
	BIT() :n(0) {}
	BIT(int _n) :n(_n) { bit = vector<T>(n + 1); }
	void add1(int idx, T val) {
		for (int i = idx; i <= n; i += i & -i) bit[i] += val;
	}
	T sum1(int idx) {
		T res = 0;
		for (int i = idx; i > 0; i -= i & -i) res += bit[i];
		return res;
	}
	//0-indexed
	void add(int idx, T val) { add1(idx + 1, val); }
	//0-indexed [left, right)
	T sum(int left, int right) { return sum1(right) - sum1(left); }

	int lower_bound(T x) {
		int res = 0;
		int k = 1;
		while (2 * k <= n) k <<= 1;
		for (; k > 0; k >>= 1) {
			if (res + k <= n and bit[res + k] < x) {
				x -= bit[res + k];
				res += k;
			}
		}
		return res;
	}
};


template<typename T>
struct RangeAddBIT {
	int n;
	BIT<T> bit[2];
	RangeAddBIT() :n(0) {}
	RangeAddBIT(int _n) :n(_n) { bit[0] = bit[1] = BIT<T>(n); }

	//0-indexed, [left, right)
	void add(int left, int right, T val) {
		bit[0].add(left, -val * (left - 1));
		bit[0].add(right, val * (right - 1));
		bit[1].add(left, val);
		bit[1].add(right, -val);
	}
	
	//0-indexed, [left, right)
	T sum(int left, int right) {
		T suml = bit[0].sum(0, left) + bit[1].sum(0, left) * (left - 1);
		T sumr = bit[0].sum(0, right) + bit[1].sum(0, right) * (right - 1);
		return sumr - suml;
	}
};

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int n, kkt; scanf("%d %d", &n, &kkt);
	RangeAddBIT<ll> bit(n);
	while (kkt--) {
		int t; scanf("%d", &t);
		if (t == 0) {
			int s, t, x; scanf("%d %d %d", &s, &t, &x);
			s--;
			bit.add(s, t, x);
		}
		else {
			int idx; scanf("%d", &idx);
			idx--;
			printf("%lld\n", bit.sum(idx, idx + 1));
		}
	}
	return 0;
}



Measured memory_bytes: 4484
from collections import deque
INF = float('inf')
H,W = map(int,input().split())
s = [input() for _ in range(H)]
cost = [[INF]*W for _ in range(H)]
cost[0][0] = 1
 
def bfs():
    que = deque([])
    que.append([0,0])
    while que:
        h,w = que.popleft()
        for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]:
            if 0<=h+dh<H and 0<=w+dw<W:
                if s[h+dh][w+dw] == '.' and cost[h+dh][w+dw] == INF:
                    cost[h+dh][w+dw] = cost[h][w]+1
                    que.append([h+dh,w+dw])
bfs()
if cost[-1][-1] == INF:
    print(-1)
else:
    ans = H*W-cost[-1][-1]
    for h in range(H):
        ans -= s[h].count('#')
    print(ans)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    cin >> a;
    each (i, a) --i;
    int curr = 0;
    int x = 0;
    set<int> vis;
    while (curr != 1) {
      vis.insert(curr);
      if (vis.count(a[curr])) {
        x = -1;
        break;
      }
      curr = a[curr];
      ++x;
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 5376
#include <cstdio>
#include <queue>

using namespace std;

const int N = 2e5 + 500;

int n;
int a[N],b[N];
deque < int > v;

int main(){
    scanf("%d",&n);
    for(int i = 0;i<n;i++)
        scanf("%d",a+i);
    int rotat = 0;
    for(int i = 0;i<n;i++){
        if(rotat) v.push_back(a[i]);
        else v.push_front(a[i]);
        rotat = 1 - rotat;
    }
    while(v.size() > 0){
        if(rotat)printf("%d ",v.front());
        else printf("%d ",v.back());
        if(rotat) v.pop_front();
        else      v.pop_back();
    }
    printf("\n");
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

bool g[101][101];

int main() {
    int N,K;
    cin >> N >> K;

    if((N-1)*(N-2)/2 < K){
        pl(-1)
        return 0;
    }

    vector<string> ans;
    for(int j=2;j<=N;j++){
        ans.push_back(to_string(1)+" "+to_string(j));
    }
    
    REP(i,N) g[i][i] = true;

    //　辺を決め打ち
    for(int i=1;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(K <= 0) break;
            if(g[i][j]) continue;

            g[i][j]=g[j][i]=true;
            K--;
        }
        if(K <= 0) break;
    }

    for(int i=1;i<N;i++){
        for(int j=1;j<N;j++){
            if(g[i][j]) continue;
            ans.push_back(to_string(i+1)+" "+to_string(j+1));
            g[i][j]=g[j][i]=true;
        }
    }

    pl(ans.size())
    for(auto a:ans) pl(a)

    return 0;
}


Measured memory_bytes: 512
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
//#include<fstream>

#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)


typedef long long ll;

int mx[]={-1,1,0,0};
int my[]={0,0,-1,1};
using namespace std;
int n=0;
void dfs(int startx,int starty,vector<vector<bool> > &map){
    n++;
    map[starty][startx]=false;
    for(int i=0;i<4;i++){
        int x=startx+mx[i],y=starty+my[i];
        if(x>=0 and y>=0 and y<map.size() and x<map[0].size() and map[y][x]==true){
        dfs(x,y,map);}
    }
    
}

int main(){
    int x,y;
    //ofstream outputfile("test.txt");
    while(cin>>x>>y,x|y){
        int startx,starty;
        vector<vector<bool> > map;

        if(x==0 and y==0) return 0;
        for(int i=0;i<y;i++){
            vector<bool> tmp;
            string s;
            cin>>s;
            for(int j=0;j<x;j++){

                if(s[j]=='@') {startx=j;starty=i;tmp.push_back(true);}
                else if(s[j]=='.') tmp.push_back(true);
                else tmp.push_back(false);    
            }
            map.push_back((tmp));
        }
        n=0;
        dfs(startx,starty,map);
        //outputfile<<n;
        //outputfile<<"\n";
        cout<<n<<endl;
        
    }
    //outputfile.close();
    return 0;
};

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


string S;


llint calcExpr(string expr){
	llint ret = 0;
	llint num = 0;
	rep(i, 0, SIZE(expr)){
		if(expr[i] != '+') num = num*10+(expr[i]-'0');
		else ret += num, num = 0;
	}
	return ret;
}


llint solve(){
	llint ans = 0;
	rep(i, 0, 1<<(SIZE(S)-1)){
		string expr;
		rep(j, 0, SIZE(S)-1){
			expr.pb(S[j]);
			if((i>>j)&1) expr.pb('+');
		}
		expr.pb(S.back());
		expr.pb('+');
		ans += calcExpr(expr);
		expr.erase();
	}
	return ans;
}


signed main(){
	cin >> S;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(n - 1):
    if a[i + 1] > a[i]:
        buy = money // a[i]
        stock += buy
        money -= buy * a[i]
    if a[i + 1] < a[i]:
        money += stock * a[i]
        stock = 0
print(money + stock * a[n - 1])


Measured memory_bytes: 61608
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		String[] kai= {"KIH","B","R"};
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		for(int i=0; i<16; i++) {
			String gousei="";
			int tmp=i;
			for(int j=0; j<4; j++) {
				if(tmp%2==1) {
					gousei=gousei+"A";
				}
				if(j<3) {
					gousei=gousei+kai[j];
				}
				tmp/=2;
			}
			if(s.equals(gousei)) {
				pl("YES");
				System.exit(0);
			}
		}
		pl("NO");
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


Measured memory_bytes: 22612
use std::io::Read;

fn main() {
  
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  let mut iter = buf.split_whitespace();
  
  let a: u8 = iter.next().unwrap().parse().unwrap();
  let b: u8 = iter.next().unwrap().parse().unwrap();
  let c: u8 = iter.next().unwrap().parse().unwrap();
  
  println!("{} {} {}", c, a, b);
}

Measured memory_bytes: 4352
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #a,b,c=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    a=int(readline())
    ss=readline().rstrip()
    if a<3200:
        ss="red"
    print(ss)
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 5572
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
using namespace std;

#define int long long

int32_t main() {
//	cout << fixed << setprecision(25);
	//int t;
	
	//cin >> t;
	
//	while(t--){
		
	   int A,B,N;
	   
	   cin >> A >> B >>N;
	  
	   double x =  min (B-1,N);
	   
		 double  ans = floor( (A*x) /B) - A * floor(x/B) ;
	    
	 cout << ans << endl;
		
//	}
	
	
}

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

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

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

// int main(int argc, char const *argv[])
// {
//     int n, p;
//     scanf("%d", &n);
//     char s[110];
//     pair<pair<string, int>, int> pir[n];

//     REP(i, n)
//     {
//         scanf("%s%d", s, &p);
//         pir[i] = make_pair(make_pair(s, -1 * p), i + 1);
//     }

//     sort(pir, pir + n);
//     REP(i, n)
//         printf("%d\n", pir[i].second);
        
//     return 0;
// }

int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    
    // 都市名, 点数, id
    vector<tuple<string, int, int>> ipt; 

    REP(i,n)
    {
        char s[200]; int p;
        scanf("%s%d", s, &p);
        p = -1 * p;
        int idx = i + 1;
        ipt.PB(tie(s, p, idx));
    }

    sort(ALL(ipt));
    REP(i,n)
    {
        string s; int p, idx;
        tie(s,p,idx) = ipt[i];
        printf("%d\n", idx);
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside.
//AVX is better slightly
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ll inf = (1LL<<62);
const int iinf = (1<<30);
//CLOCKS_PER_SEC



int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0); cin.tie(0);
    //ifstream cin ("test.in");
    int a, b, k;
    cin >> k >> a >> b;
    for (int i=a; i<=b; i++){
        if (i % k == 0) rc("OK");
    }
    rc("NG");
    return 0;
}


Measured memory_bytes: 3636
X = int(input())

# 100の位以上の数字Yと、
# 100で割った余りXmodを求める
Y = int(X // 100)
Xmod = X % 100

# Xmod <= 5*Y なら、買い方が存在する
if Xmod <= 5*Y:
  print(1)
else:
  print(0)

Measured memory_bytes: 2940