akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.*;
import java.io.*;

class Edge implements Comparable<Edge> {

  int to;
  int fee;
  long time;

  Edge(int to, int fee, long time){
    this.to = to;
    this.fee = fee;
    this.time = time;
  }

  @Override
  public int compareTo(Edge o) {
    if(time > o.time) return 1;
    if(time < o.time) return -1;
    return 0;
  }

}

class Graph {
  public ArrayList<Edge>[] adjacency;

  Graph(int n){
    adjacency = new ArrayList[n];
    for(int i = 0; i < n; i++){
      adjacency[i] = new ArrayList<Edge>();
    }
  }

  public void add_edge(int from, int to, int fee, int time){
    adjacency[from].add(new Edge(to, fee, time));
    adjacency[to].add(new Edge(from, fee, time));        
  }
}

public class Main {

  static int n, m, s, maxFee;
  static int[] c, d;
  static long[] ans;
  static long[][] dp;

  static final long INFL = 0xfffffffffffffffL;

  static Graph g;
  
  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    m = Integer.parseInt(in[1]);
    s = Integer.parseInt(in[2]);

    g = new Graph(n);

    int[] a;
    for(int i = 0; i < m; i++){
      in = br.readLine().split(" ");
      a = Stream.of(in).mapToInt(Integer::parseInt).toArray();
      g.add_edge(a[0]-1, a[1]-1, a[2], a[3]);
    }

    c = new int[n];
    d = new int[n];

    for(int i = 0; i < n; i++){
      in = br.readLine().split(" ");
      c[i] = Integer.parseInt(in[0]);
      d[i] = Integer.parseInt(in[1]);
    }
    
    br.close();

    maxFee = (n-1) * 50;
    s = Math.min(maxFee, s);

    dp = new long[n][2525];

    for(int i = 0; i < n; i++){
      Arrays.fill(dp[i], INFL);
    }

    PriorityQueue<Edge> pq = new PriorityQueue<>();
    pq.add(new Edge(0, s, 0));

    while(!pq.isEmpty()){
      Edge e = pq.poll();
      if(dp[e.to][e.fee] <= e.time) continue;

      for(int i = e.fee; i >= 0 && dp[e.to][i] > e.time; i--){
        dp[e.to][i] = e.time;
      }

      int nextFee = Math.min(e.fee + c[e.to], maxFee);
      pq.add(new Edge(e.to, nextFee, e.time + d[e.to]));
      for(Edge nextEdge : g.adjacency[e.to]){
        if(nextEdge.fee > e.fee) continue;
        pq.add(new Edge(nextEdge.to, e.fee - nextEdge.fee, e.time + nextEdge.time));
      }
    }

    for(int i = 1; i < n; i++){
      System.out.println(dp[i][0]);
    }
    
  }

}

Measured memory_bytes: 55288
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000ll
using namespace std;
signed main(){
  ll n,a,mi=INF;
  cin>>n;
  while(n > 0){
    a = abs((n % 1000) - 753);
    n /= 10;
    mi = min(mi,a);
  }
  cout<<mi<<"\n";
  return 0;
}

Measured memory_bytes: 256
function isprime(x){
if(x==2)return true;
if(x<2 || x%2==0)return false;
var i=3;
while(i<=Math.sqrt(x)){
   if(x%i==0)return false;
   i=i+2;
}
return true;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
Arr.shift();
var cnt=0;
Arr.forEach(function(v){
if(isprime(v))cnt++;
});
console.log(cnt);

Measured memory_bytes: 10196
#include <bits/stdc++.h>
using namespace std;
#define maxn 2000000
#define INF 99999999
int n, m, mn[maxn], mark[maxn];
int ans = INF;

int read()
{
    int x = 0, k = 1;
    char c; c = getchar();
    while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * k;
}

struct node
{
    int l, r;
    friend bool operator <(const node& a, const node& b)
    { return a.r > b.r; }
}P[maxn];

void push_down(int p)
{
	if(!mark[p]) return;
    mark[p << 1] += mark[p], mark[p << 1 | 1] += mark[p];
    mn[p << 1] += mark[p], mn[p << 1 | 1] += mark[p];
    mark[p] = 0;
}

void Update(int p, int l, int r, int L, int R, int x)
{
    if(L <= l && R >= r) { mn[p] += x; mark[p] += x; return; }
    if(L > r || R < l) return;
    int mid = (l + r) >> 1;
    push_down(p);
    Update(p << 1, l, mid, L, R, x); 
    Update(p << 1 | 1, mid + 1, r, L, R, x);
    mn[p] = min(mn[p << 1], mn[p << 1 | 1]);
}

void Build(int p, int l, int r)
{
    if(l == r) { mn[p] = l; return; }
    int mid = (l + r) >> 1;
    Build(p << 1, l, mid), Build(p << 1 | 1, mid + 1, r);
    mn[p] = min(mn[p << 1], mn[p << 1 | 1]); 
}

int Query(int p, int l, int r, int x)
{
	if(l == r) return mn[p];
	int mid = (l + r) >> 1;
	push_down(p);
	if(x <= mid) return Query(p << 1, l, mid, x);
	else return Query(p << 1 | 1, mid + 1, r, x);
}

int main()
{
    n = read(), m = read(); 
    for(int i = 1; i <= n; i ++) P[i].l = read(), P[i].r = read();
    sort(P + 1, P + 1 + n);
    int now = 1; Build(1, 0, m);
    for(int i = m + 1; i >= 0; i --)
    {
        while(now <= n && P[now].r >= i) 
        	Update(1, 0, m, P[now].l, m, -1), now ++;
        Update(1, 0, m, i, m, -1);
        ans = min(ans, (m - i + 1) + mn[1]);
    }
    if(ans < 0) printf("%d\n", -ans);
    else printf("0\n");
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main() {
    fast();
    ll n,a,b;cin>>n>>a>>b;
    ll arr[n];
    for (int i = 0; i < n; ++i) {
    cin>>arr[i];
    }
    ll ans=0;
    for (int j = 0; j+1 <n ; ++j) {
        if((arr[j+1]-arr[j])*a<b)ans+=((arr[j+1]-arr[j])*a);
        else ans+=b;
    }
    cout<<ans;
}

Measured memory_bytes: 1024
import numpy as np

N,M = map(int,input().split())
lst = [ list(map(int,input().split())) for i in range(N)]
lst.sort()

ans = 0
tmp = M
for i in range(N):
  tmp -= lst[i][1]
  if tmp <= 0:
    ans += lst[i][0] * M
    break
  else:
    ans += lst[i][0] * lst[i][1]
  M -= lst[i][1]

print(ans)

Measured memory_bytes: 36876
N = int(input())
A = list(map(int, input().split()))

B = [i for i in range(1,N+1)]

index = 0
ans = 0
for i in range(len(A)):
    if A[i] == B[index]:
        index += 1
    else:
        ans += 1

if index == 0:
    print('-1')
else:
    print(ans)


Measured memory_bytes: 86348
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<ll, ll> pll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;






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

	vector<vector<ll>> dp(64, vector<ll>(3));
	dp[0][0] = 1;

	for (int i = 1; i < 64;i++) {
		if ((1LL << (63 - i)) <= n) {
			if ((n >> (63 - i)) % 2 == 1) {
				dp[i][0] = dp[i - 1][0];

				dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) % MOD_CONST;

				dp[i][2] = (2 * dp[i - 1][1] + 3 * dp[i - 1][2]) % MOD_CONST;
			}
			else {
				dp[i][0] = (dp[i - 1][0] + dp[i-1][1])%MOD_CONST;

				dp[i][1] = (dp[i - 1][1]) % MOD_CONST;

				dp[i][2] = ( dp[i - 1][1] + 3 * dp[i - 1][2]) % MOD_CONST;
			}
			
			
		}
		else {
			dp[i][0] = dp[i - 1][0];
		}
		
		
	}

	ll ans = 0;
	for (int i = 0; i < 3;i++) {
		ans = (ans + dp[63][i]) % MOD_CONST;
	}
	cout << ans << endl;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
struct z{
  ll x,y,d;
  z(ll a,ll b,ll c):x(a),y(b),d(c){};
};
vector<vector<ll>>dist(5005,vector<ll>(5005,INF));
void bfs(ll h,ll w,vector<string>&a,ll sx,ll sy){
  rep(i,0,h)rep(j,0,w)dist[i][j]=INF;
  queue<struct z>que;
  que.emplace(sx,sy,0);
  while(!que.empty()){
    auto pos = que.front();
    que.pop();
    if(dist[pos.x][pos.y]!=INF||a[pos.x][pos.y]=='#')continue;
    dist[pos.x][pos.y]=pos.d;
    for(ll i=0;i<4;i++){
      ll x=pos.x+dx[i],y=pos.y+dy[i],d=pos.d+1;
      if(x<0||x>=h||y<0||y>=w)continue;
      que.emplace(x,y,d);
    }
  }
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll h,w;cin>>h>>w;
  vector<string>a(h);
  rep(i,0,h)cin>>a[i];
  rep(i,0,h)rep(j,0,w){
    if(a[i][j]=='.'){
      bfs(h,w,a,i,j);
      rep(i,0,h)rep(j,0,w)if(dist[i][j]!=INF)chmax(res,dist[i][j]);
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 196096
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
    long n,i;
    cin>>n;
    long a[n]={0},p;
    if(n&1){
        for(i=0;i<n;i++){
            cin>>p;
            if(p&1){
                cout<<0;
                return 0;
            }
            a[p]++;
            if(p==0 && a[p]>1){
                cout<<0;
                return 0;
            }
            if(a[p]>2){
                cout<<0;
                return 0;
            }
        }
    } else {
        for(i=0;i<n;i++){
            cin>>p;
            if(p&1==0){
                cout<<0;
                return 0;
            }
            a[p]++;
            if(a[p]>2 && p!=0){
                cout<<0;
                return 0;
            }
        }
    }
     unsigned long long ans=1;
    for(i=0;i<n/2;i++){
        ans=ans*2;
        if(ans>mod) ans=ans%mod;
    }
    cout<<ans%mod;
    return 0;
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x = int(readline())
for a in range(-500, 500):
    for b in range(-500, 500):
        if pow(a, 5) == x + pow(b, 5):
            print(a, b)
            exit()


Measured memory_bytes: 65176
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<int,P> PP;
struct edge { int to; int to2;int cost; };
string s[405];
int p[105];
signed main() {
	int n; cin >> n;
	int a, b; cin >> a >> b;
	rep(i, n)cin >> p[i];
	int la = 0, ab = 0, ub = 0;
	rep(i, n) {
		if (p[i] <= a)la++;
		else if (p[i] > b)ub++;
		else ab++;
	}
	cout << min(la, min(ab, ub)) << endl;
}

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

int main() {
    int a;
    cin>>a;
    int b;
    cin>>b;
    int c;
    int d;
    d=a%(b*2+1);
    if(d==0){
        c=a/(2*b+1);
    }
    else {
        c=a/(2*b+1)+1;
    }
    cout<<c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define N 200005
#define Inf 1e18L + 5
using namespace std;
int n , m;
vector < pair < int , ll > > Interval[N];

ll st[4*N] , lazy[4*N];
void push(int p ,int l ,int r)
{
    if(lazy[p])
    {
        st[p] += lazy[p];
        if(l != r)
        for(auto i : {2*p , 2*p+1})
            lazy[i] += lazy[p];
        lazy[p] = 0;
    }
}
void update(int a, int b , ll val , int l = 0 ,int r = n+1 , int p = 1)
{
    push(p,l,r);
    if(b < l || r < a)return;
    if(a <= l && r <= b)
    {
        lazy[p] += val;
        push(p,l,r);
        return;
    }
    int mid = (l+r)>>1;
    update(a,b,val,l,mid,2*p);
    update(a,b,val,mid+1,r,2*p+1);
    st[p] = min(st[2*p],st[2*p+1]);
}
ll q(int a, int b, int l = 0 , int r = n+1 , int p = 1)
{
    push(p,l,r);
    if(b < l || r < a) return Inf;
    if(a <= l && r <= b)return st[p];
    int mid = (l+r)>>1;
    return min(q(a,b,l,mid,2*p) , q(a,b,mid+1,r,2*p+1));
}
int main()
{
    ll sum_of_cost = 0;
    scanf("%d%d",&n,&m);
    for(int i = 0 ; i < m ; i++)
    {
        int l , r , x;
        scanf("%d%d%d",&l,&r,&x);
        Interval[r].push_back({l,x});
        sum_of_cost += x;
    }

    ll ans = 0;
    update(0,n,0);
    for(int i = 1 ; i <= n + 1; i++)
    {
        for(auto range : Interval[i-1])
            update(0,range.first - 1, range.second);

        ll res = q(0,i-1);
        if(i == n+1)
            ans = res;
        update(i,i,res);
    }
    printf("%lld\n", sum_of_cost - ans);
    return 0;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = 1;
    while(d*a<10000){
        if((d*a)%b==c){
            cout << "YES" << "\n";
            return 0;
        }
        ++d;
    }
    cout << "NO" << "\n";
    return 0;
}

Measured memory_bytes: 256
class Queue():
    def __init__(self):
        self.data = []
        self.idx = 0
        self.size = 0

    def get(self):
        self.idx += 1
        self.size -= 1
        return self.data[self.idx-1]

    def put(self, item):
        self.size += 1
        self.data.append(item)

    def qsize(self):
        return self.size

        # input
H, W = map(int, input().split())
A = [input() for i in range(H)]

# bfs
bfs = [[-1 for j in range(W)] for i in range(H)]
que = Queue()
for i in range(H):
    for j in range(W):
        if(A[i][j] == '#'):
            que.put((i, j))
            bfs[i][j] = 0
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

while(que.qsize()):
    p = que.get()
    for i in range(4):
        if(0 <= p[0]+dx[i] < H and 0 <= p[1]+dy[i] < W):
            if(bfs[p[0]+dx[i]][p[1]+dy[i]] == -1):
                que.put((p[0]+dx[i], p[1]+dy[i]))
                bfs[p[0]+dx[i]][p[1]+dy[i]] = bfs[p[0]][p[1]] + 1

# print ans
print(max([max(l) for l in bfs]))


Measured memory_bytes: 127792
/*
ID: arthurc4
TASK: test
LANG: C++11
*/

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<bool> vb;
typedef vector<vb> vvb;

typedef map<string,int> msi;
typedef map<int,int> mii;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll; // note 'single' ls

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

#define pb \
push_back

#define ff \
first

#define ss \
second

int main()
{
	//ifstream cin("input.txt"); // L==R WORKS!!!
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	int n;
	cin >> n;

	vi A={-1};

	REP(i, 1, n)
	{
		int a;
		cin >> a;
		A.pb(a);
	}

	vvi last_one_occurrence = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
	// cout << last_one_occurrence.back().size() << endl;

	REP(i, 1, n)
	{
		int a = A[i];
		last_one_occurrence.pb({});

		REP(j, 0, 19)
		{
			if (a%2 == 1) last_one_occurrence.back().pb(i);
			else last_one_occurrence.back().pb(last_one_occurrence[i-1][j]);

			a /= 2;
		}

		// for (auto one:last_one_occurrence.back())
		// {
		// 	cout << one << " ";
		// }

		// cout << endl;
	}

	ll no_pairs=0;
	int old_closest_wrong = 0;

	REP(i, 1, n)
	{
		int closest_wrong = 0;

		REP(j, 0, 19)
		{
			if (last_one_occurrence[i][j]==i)
			{
				closest_wrong = max(last_one_occurrence[i-1][j], closest_wrong);
			}
		}

		closest_wrong = max(closest_wrong, old_closest_wrong);
		old_closest_wrong = closest_wrong;

		//cout << i-closest_wrong << endl;
		no_pairs += ll(i-closest_wrong);
	}

	//cout << endl;
	cout << no_pairs << endl;

	return 0;
}

Measured memory_bytes: 34920
n = int(input())
s = input()

e = [0 for i in range(n)]
w = [0 for i in range(n)]
for i in range(0, n - 1):
    et = e[i - 1] if i != 0 else 0
    et += 1 if s[i] != "E" else 0
    e[i] = et
    wt = w[(n - 1 - i) + 1] if i != 0 else 0
    wt += 1 if s[n - 1 - i] != "W" else 0
    w[n - 1 - i] = wt
# import pdb; pdb.set_trace()
tmin = 0
for i in range(0, n):
    t = 0
    t += e[i - 1] if i != 0 else 0
    t += w[i + 1] if i != (n - 1) else 0
    if t < tmin or i == 0:
        tmin = t 
print(tmin)

Measured memory_bytes: 27304
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const ll inf = 1e16;

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

   int n;
   cin >> n;
   vector <ll> a(n + 1);
   for (int i = 1; i <= n; i++)
      cin >> a[i];

   vector <vector <ll>> dp(n + 1, vector <ll> (n + 1, inf));

   for (int i = 1; i <= n; i++) {
      dp[i][i] = 0;
      a[i] += a[i - 1];
   }
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n - i + 1; j++) {
         int l = j, r = j + i - 1;
         for (int k = j; k < j + i - 1; k++) {
            dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + a[r] - a[l - 1]);
         }
      }
   }

   cout << dp[1][n] << '\n';

   return 0;
}

Measured memory_bytes: 1536
a = []
A,B,K  = map(int, input().split())
min = 0
 
if A > B:
	min = B
else:
  min = A
for i in range(1, min + 1):
  if(A % i == 0 and B % i == 0):
    a.append(i)
    
print(a[len(a) - K])

#no 1 is a(len-1)
# no k is a(lent-K)

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

int main()
{
	int n;
	stack<int> car;
	vector<int> out;

	while (cin >> n){
		if (n == 0){
			out.push_back(car.top());
			car.pop();
		}
		else {
			car.push(n);
		}
	}

	for (int i = 0; i < out.size(); i++){
		cout << out[i] << endl;
	}

	return (0);
}

Measured memory_bytes: 1220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  if (count(begin(s), end(s), '9')) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7



int main() {
	int A, B;
	char S[3];
	scanf("%d%c%c%c%d", &A, &S[0], &S[1], &S[2], &B);

	if (S[1] == '+') {
		printf("%d", A + B);

	}
	else {
		printf("%d", A - B);
	}



}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

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

void Eratos(map<int, int> & mp, vector<int> & p) {
	int i, j;
	if (mp.count(1)) {
		p = vector<int>(1000001, 0);
		p[1] = 1;
		return;
	}
	for(auto it = mp.begin(); it != mp.end(); it++) {
		for (j = (*it).first << 1; j < p.size(); j += (*it).first)
			p[j] = 0;
	}
	return;
}

int main(void) {
	int num, i, a, ans = 0;
	cin >> num;
	vector<int> p(1000001, 1);
	map<int, int> mp;
	rep(i, num) {
		cin >> a;
		mp[a]++;
	}
	Eratos(mp, p);
	for(auto it = mp.begin(); it != mp.end(); it++) {
		if ((*it).second == 1 && p[(*it).first])
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

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

bool is_bingo(int f[3][3])
{
	for(int y = 0; y < 3; y++){
		if(f[y][0] +  f[y][1] + f[y][2] == 3) return true;
	}
	for(int x = 0; x < 3; x++){
		if(f[0][x] +  f[1][x] + f[2][x] == 3) return true;
	}
	if(f[0][0] +  f[1][1] + f[2][2] == 3) return true;
	if(f[0][2] +  f[1][1] + f[2][0] == 3) return true;
	
	return false;
}

int main() 
{
    int A[3][3], N;

    cin >> A[0][0] >> A[0][1] >> A[0][2];
    cin >> A[1][0] >> A[1][1] >> A[1][2];
    cin >> A[2][0] >> A[2][1] >> A[2][2];
    cin >> N;
    
    int f[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
    
    for(int i = 0; i < N; i++){
    	int B;
    	cin >> B;
    	
    	for(int x = 0; x < 3; x++){
	    	for(int y = 0; y < 3; y++){
	    		if(A[y][x] == B) {f[y][x] = 1;}
	    	}
    	}
    	
    	if(is_bingo(f)){
		    cout << "Yes" << endl;
			return 0;
    	}
    }
  
    cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 256
def landscape(n, m, a, b):
  MOD = 10 ** 9 + 7
  ans = 1
  r = 0  # raw <= N
  c = 0  # column <= M
  
  for x in range(n * m, 0, -1):
    if x in a and x in b:
      r += 1
      c += 1
    elif x in a:
      ans *= c
      r += 1
    elif x in b:
      ans *= r
      c += 1
    else:
      ans *= r * c - (n * m - x)
    ans %= MOD
  return ans


def main():
  n, m = map(int, input().split())
  a = set(map(int, input().split()))
  b = set(map(int, input().split()))

  if len(a) != n or len(b) != m:
    print(0)
  else:
    print(landscape(n, m, a, b))

  
if __name__ == '__main__':
  main()


Measured memory_bytes: 3188
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int count (string rs) {

  vector<string> se;

  string sa,sb,rsa,rsb,rsb2,s;

  s = rs;
  reverse(rs.begin(), rs.end() );

  for(int i=0; i<s.length(); i++) {
    rsa = s.substr(0,i);
    rsb = s.substr(i,s.length()-i);

    sa = rsa;
    sb = rsb;

    reverse(sb.begin(), sb.end());
    reverse(sa.begin(), sa.end());

    se.push_back( sa + sb );
    se.push_back( sb + sa );
    se.push_back( rsa + rsb );
    se.push_back( rsb + rsa );
    se.push_back( rsa + sb );
    se.push_back( rsb + sa );
    se.push_back( sa + rsb );
    se.push_back( sb + rsa );

  }

  sort(se.begin(), se.end());
  vector<string>::iterator uni = unique(se.begin(),se.end());
  se.erase(uni,se.end());

  return se.size();
}

int main() {

  int m;
  scanf("%d",&m);

  char c[80];
  while(m--) {
    string s;
    scanf("%s", c);
    printf("%d\n",count(string(c)));
  }
}

Measured memory_bytes: 920
from collections import Counter
N, P = map(int, input().split())

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            factors.append(i)
        i += 1
    if n > 1:
        factors.append(n)
    return factors

fs = Counter(prime_factors(P))

d = 1
for k, c in fs.most_common():
    if c >= N:
        for _ in range(int(c/N)):
            d *= k
print(d)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int arr[100010];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
    long long answer = 0;
    for (int i = 1; i < n; ++i) {
        if (arr[i] + arr[i + 1] > x) {
            int d = arr[i] + arr[i + 1] - x;
            answer += d;
            if (d > arr[i + 1]) {
                arr[i + 1] = 0;
                d -= arr[i + 1];
                arr[i] -= d;
            } else {
                arr[i + 1] -= d;
            }
        }
    }
    cout << answer;
}

Measured memory_bytes: 4028
n = int(input())
S = [input() for x in range(n)]

D = {}
for i in list("abcdefghijklmnopqrstuvwxyz"):
    D[i] = 50

for s in S:
    d = {}
    for i in list("abcdefghijklmnopqrstuvwxyz"):
        d[i] = 0
    for ss in list(s):
        d[ss] += 1
    for i in list("abcdefghijklmnopqrstuvwxyz"):
        D[i] = min(d[i],D[i])

D = sorted(D.items(),key=lambda x:x[0])
print(''.join(map(lambda x:x[0]*x[1],D)))

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

using namespace std;
#define ll long long int
#define pb push_back
#define rep(i, a, v) for(int i = a; i <= v; ++i)
#define vi vector<int>
#define vll vector<ll>
#define maxi 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
const double pie = 3.1415926535;
const string spaces = "    ";

ll i, j, k;
ll temp;

int main(){
    cout.tie(0);
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, w;
    cin >> n >> w;
    ll wt, val, sum = 0;
    // dp[i] = Minimum weight given value i
    vll dp(1000 * n + 1, maxi);
    vi wts(n + 1), vals(n + 1);

    for(int i = 0; i < n; ++i){
        cin >> wts[i];
        cin >> vals[i];
        sum += vals[i];
    }

    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        val = vals[i];
        wt = wts[i];
        for(int val_red = sum - val; val_red >= 0; --val_red){
            dp[val_red + val] = min(dp[val_red + val], dp[val_red] + wt);
        }
    }

    int answer = maxi;
    for(int i = 1000 * n; i >= 1; --i){
        if(dp[i] <= w){
            answer = i;
            break;
        }
    }   

    cout << answer << "\n";
    return 0;
}
    

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

int h,w;
int mas[60][60];

void solve(int x,int y){
  for(int i=-1;i<=1;i++){
    for(int j=-1;j<=1;j++){
      int nx = x + i;
      int ny = y + j;
      if(nx >= 0 && ny >= 0 && nx < w && ny < h && mas[ny][nx] == 1){
	mas[ny][nx] = 0;
	solve(nx,ny);
      }
    }
  }
  return;
}

int main(){
  while(cin >> w >> h , w){
    int cnt = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> mas[i][j];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(mas[i][j] == 1){
	  mas[i][j] = 0;
	  solve(j,i);
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
}
		     

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

using ll = long long;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 0 && b >= 0) {
        cout << "Zero" << endl;
    } else if(a >= 0 && b >= 0) {
        cout << "Positive" << endl;
    } else {
        int d = b - a;
        if(d & 1) {
            cout << "Positive" << endl;
        } else {
            cout << "Negative" << endl;
        }
    }
}



Measured memory_bytes: 256
def DFS(s):
    global ans,color
    color[s]="black"
    if "white" not in color:
        ans +=1
    for i in M[s]:
        if color[i]=="white":
            DFS(i)
    color[s]="white"


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

M=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    M[a-1].append(b-1)
    M[b-1].append(a-1)

color=["white" for _ in range(n)]
ans=0
DFS(0)

print(ans)

Measured memory_bytes: 41820
#include<stdio.h>
#include<math.h>

int main(){
  int a,b,x;
  scanf("%d %d %d",&a,&b,&x);
  if(a*a*b*0.5 < x){
    printf("%f\n",180*atan((double)(a*a*b-x)/a/a/a*2)/3.14159265358979);
  }else{
    printf("%f\n",90-180*atan((double)x/a/b/b*2)/3.14159265358979);
  }return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
ans = -inf
for i in range(n):
    for j in range(n):
        ans = max(ans, abs(a[i]-a[j]))
print(ans)

Measured memory_bytes: 39024
//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

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

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int a[N];

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> v;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  vector <int> ret;
  while (!v.empty()) {
    bool ch = 0;
    for (int i = (int)v.size() - 1; i >= 0; i--) {
      if (v[i] == i + 1) {
        ch = 1;
        ret.push_back(v[i]);
        v.erase(v.begin() + i);
        break;
      }
    }
    if (!ch) {
      cout << "-1";
      return 0;
    }
  }
  reverse(ret.begin(), ret.end());
  for (auto x : ret)
    cout << x << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
#define newline std::cout<<'\n';
#define newlinedx(num) for(int i=0;i<num;i++)std::cout<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template <class T>
inline T Max(const T a,const T b) {
    return (a >= b) ? a : b;
}

template <class T>
inline T Min(const T a,const T b) {
    return (a <= b) ? a : b;
}

template <class T>
inline void show(T a) {
    cout << a << endl;
}

typedef struct{
    ll x;
    ll y;
}idx;


//------------------------main function-------------------------------
void Main(){
    ll n, k, max = -1e18, idx = 0, ans =0 ; cin >> n >>k;
    vector<ll> p(n), a(n-k+1);
    rep(i, n) cin >> p[i];
    a[0] = 0;
    for(int i = 1; i < n - k + 1; i++){
        a[i] = a[i-1] + p[i+k-1] - p[i-1];
    }
    rep(i, n-k+1){
        if(max < a[i]){
            max = a[i];
            idx = i;
        }
    }
    for(ll i = idx ; i < idx + k ; i++){
        ans += p[i];
    }
    ans += k;
    cout << (double)ans/2.0 << endl;
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
     
    Main();
    return 0;
}

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

double n,k,h,w,va,vb,l;
string s;

int main() {
  cin >> s;
  bool ok=false;
  rep(i,s.size()){
    if(s[i]=='A' && s[i+1]=='C') ok=true;
  }
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, t1 = 0, x1 = 0, y1 = 0, t2, x2, y2;
  int flag = 1;
  cin >> N;
  int dt, dx, dy;
  for(int i = 0; i < N; i++){
    cin >> t2 >> x2 >> y2;
    dx = abs(x1 - x2);
    dy = abs(y1 - y2);
    dt = t2 - t1;
    if(dt < dx + dy || (dt >= dx + dy && (dt - dx - dy) % 2 == 1)){
      flag = 0;
      break;
    }
    t1 = t2;
    x1 = x2;
    y1 = y2;
  }
  if(flag == 1)cout << "Yes" << endl;
  else cout << "No" << 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();
        int m = sc.nextInt();
        int l = sc.nextInt();
        int arrayA[][] = new int[n][m];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                arrayA[i][j] = sc.nextInt();
            }
        }
        int arrayB[][] = new int[m][l];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < l; j++){
                arrayB[i][j] = sc.nextInt();
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
                long sum = 0;
                for(int k = 0; k < m; k++){
                    sum += arrayA[i][k] * arrayB[k][j];
                }
                if(j != 0){
                    System.out.print(" ");
                }
                System.out.print(sum);
            }
            System.out.println();
        }
        
        
    }
}


Measured memory_bytes: 57088
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<unordered_map>
#include<queue>

using namespace std;
class CompareFirst
{
public:
  bool operator()(pair<int,int> n1,pair<int,int> n2) {
    return n1.first>n2.first; //>:desc <:asc
  }
};


int main(){

  string s;
  int b,c,i,j,k,n;
  long long  ans1;
  double ans,tmp;
  vector<string> lst;
  vector<int> cnt;

  //unordered_map<string,int> mp;

  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst pq;

  cin >> n;
  ans = 0;
  vector<int> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
  }

  sort(a.begin(),a.end());
  ans = (double)a[0];
  for(i=1;i<n;i++){
    ans = (ans + a[i])/2;
  }
 // cout << fixed;
//  cout << setprecision(6) << (double)ans << endl;
printf("%.10f\n",ans);
  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;

ll T[1001], A[1001];

int main () {
    ll N;
	cin >> N;
	for(int i = 0; i < N; i++)
	{
		cin >> T[i] >> A[i];
	}
	ll nt = 1, na = 1;
	for(int i = 0; i < N; i++)
	{
		ll mx = max(
			(nt + T[i] - 1) / T[i],
			(na + A[i] - 1) / A[i]
		);
		nt = T[i] * mx;
		na = A[i] * mx;
	}
	cout << nt + na << endl;
	
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    string s, t;
    cin >> s >> t;

    bool f = false;
    for (int i = 0; i <= s.size(); i++)
    {
        char tmp = s[s.size() - 1];
        char c;
        for (int j = s.size() - 1; j >= 1; j--)
        {
            s[j] = s[j - 1];
        }
        s[0] = tmp;
        // cout << s << endl;
        if (s == t)
            f = true;
    }
    if (f)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n=input().split(' ')
a=int(n[0]);b=int(n[1])
def gcd(a,b):
    x=max(a,b);y=min(a,b)
    if x%y==0:
        return y
    while x%y!=0:
        z=x%y ; x=y ; y=z
    return z
print(int(a*b/gcd(a,b)))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define REP(i,b,n) for(int (i)=b; (i)<(int)(n); ++(i))
#define rep(i,n) REP(i,0,n)
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(a) (a).begin(),(a).end()
#define print(var) cout<<#var":"<<(var)<<endl;
#define printkv(key,var) cout<<#key":"<<(var)<<endl;
#define updatemax(dst,src) dst=max(dst,src);
#define updatemin(dst,src) dst=min(dst,src);

typedef long long ll;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
  if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

const ll mod = 1000 * 1000 * 1000 + 7;
int N;

int main() {
  while (cin >> N) {
    ll val = 1;
    rep(i,N) {
      val = (val * (i+1)) % mod;
    }
    cout << val << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int> P(N);
    rep(n,0,N) cin>>P.at(n);

    int ans=0,minN=INT_MAX;
    for(auto p:P){
        if(minN>=p){ans++;minN=p;}
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
      ios_base::sync_with_stdio(false);
      double r,a,pie=3.141592654;
      cin>>r;
      a=2*pie*r;
      cout<<std::setprecision(10)<<a;
      return 0;
}

Measured memory_bytes: 3768
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
hh = inpl()

ans = 0
def bukatu(hh,L):
    global ans
    if L <= 0:
        return
    elif L == 1:
        ans += hh[0]
        return
    else:
        while not 0 in hh:
            ans += 1
            for i in range(L):
                hh[i] -= 1
        nexthh = [list(map(int,' '.join(h.split('*')).split())) for h in ('*'+'*'.join(map(str,hh))+'*').split('*0*')]
        #print(nexthh,ans)
        for hh in nexthh:
            bukatu(hh,len(hh))

bukatu(hh,N)
print(ans)


Measured memory_bytes: 4336
import sys
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            print(i,j,n-i-j)
            sys.exit()
print("-1 -1 -1")

Measured memory_bytes: 2940
def check(N,target,A,K):
  cnt = 0
  for i in range(N):
    cnt += -(-A[i]//target)-1
  if cnt>K:
    return False
  return True

def solve():
  ans = 0
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  low = 0
  high = 10**9
  mid = (low+high)//2
  while high>low+1:
    if check(N,mid,A,K):
      high = mid
    else:
      low = mid
    mid = (low+high)//2
  ans = high
  return ans
print(solve())

Measured memory_bytes: 93856
# -*- coding: utf-8 -*-
N,X = [int(i) for i in input().split()]
L = list(map(int, input().split()))

def D(i):
        if i == 0:
                return 0
        return D(i - 1)+ L[i - 1]

ans = 0
for i in range(N + 1):
    if D(i) <= X:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define    ll long long
using namespace std;
const int maxn  = 2000005;
int mp[405][405];
int vis[405][405];
int dis[405][405];
char a[30][30];
int main()
{
   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++)
        cin>>a[i];
   for(int i=0;i<n*m;i++){
        for(int j=0;j<n*m;j++)
            dis[i][j] = maxn;
        dis[i][i] = 0;
   }

   //cout<<1111<<endl;
   for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(a[i][j]=='.'){
                if(i>0&&a[i-1][j]=='.')     dis[(i-1)*m+j][i*m+j] = 1,dis[(i)*m+j][(i-1)*m+j] = 1;
                if((i+1)<n&&a[i+1][j]=='.') dis[(i+1)*m+j][i*m+j] = 1,dis[(i)*m+j][(i+1)*m+j] = 1;
                if(j>0&&a[i][j-1]=='.')     dis[i*m+j][(i)*m+j-1] = 1,dis[(i)*m+j-1][(i)*m+j] = 1;
                if((j+1)<m&&a[i][j+1]=='.') dis[i*m+j][(i)*m+j+1] = 1,dis[(i)*m+j+1][(i)*m+j] = 1;
            }

    for(int i=0;i<(n*m);i++){
        if(a[i/m][i%m]=='#') continue;
        for(int j=0;j<(n*m);j++){// cout<<222<<endl;
            if(a[j/m][j%m]=='#') continue;
            for(int l=0;l<(n*m);l++){
                if(a[l/m][l%m]=='#') continue;
                if(dis[i][j]>dis[i][l]+dis[l][j]){
                    dis[i][j]=dis[i][l]+dis[l][j];
                    dis[j][i] = dis[i][j];
                }
            }
        }

    }
     for(int i=0;i<(n*m);i++){
        if(a[i/m][i%m]=='#') continue;
        for(int j=0;j<(n*m);j++){// cout<<222<<endl;
            if(a[j/m][j%m]=='#') continue;
            for(int l=0;l<(n*m);l++){
                if(a[l/m][l%m]=='#') continue;
                if(dis[i][j]>dis[i][l]+dis[l][j]){
                    dis[i][j]=dis[i][l]+dis[l][j];
                     dis[j][i] = dis[i][j];
                }
            }
        }

    }
    int minn = 0;
    for(int i=0;i<(n*m);i++){
        if(a[i/m][i%m]=='#') continue;
        for(int j=0;j<(n*m);j++){
            if(a[j/m][j%m]=='#') continue;
           // cout<<i/m<<" "<<i%m<<endl;
           //  cout<<j/m<<" "<<j%m<<":  ";
           // cout<<dis[i][j]<<endl;
            if(dis[i][j]<10000)
                minn = max(minn,dis[i][j]);
        }
    }
    cout<<minn<<endl;


}


Measured memory_bytes: 896
# Heaps - Complete Binary Tree
class Node:
    def __init__(self, key):
        self.key = key


from math import floor
H = int(input())
heap = [None]*(H+1)
for i,k in enumerate(input().split()):
    heap[i+1] = Node(k)

for i,h in enumerate(heap):
    if i == 0: continue
    print('node {0}: key = {1}, '.format(i, h.key), end='')
    p_id = floor(i/2)
    if p_id > 0:
        print('parent key = {0}, '.format(heap[p_id].key), end='')
    l_id = 2 * i
    if 0 < l_id < len(heap):
        print('left key = {0}, '.format(heap[l_id].key), end='')
    r_id = 2 * i + 1
    if 0 < r_id < len(heap):
        print('right key = {0}, '.format(heap[r_id].key), end='')
    print()


Measured memory_bytes: 7880
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

map<int, int> mx, my;

int s[5010][5010];

int get(int x1, int y1, int x2, int y2) {
	return s[y2][x2] - s[y1][x2] - s[y2][x1] + s[y1][x1];
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> x(n), y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
		mx[x[i]]++;
		my[y[i]]++;
	}
	int cnt_x = 0, cnt_y = 0;
	for(auto& p : mx) p.se = ++cnt_x;
	for(auto& p : my) p.se = ++cnt_y;
	for(int i = 0; i < n; i++) s[my[y[i]]][mx[x[i]]]++;
	for(int i = 0; i < 5010; i++) for(int j = 1; j < 5010; j++) s[i][j] += s[i][j-1];
	for(int i = 1; i < 5010; i++) for(int j = 0; j < 5010; j++) s[i][j] += s[i-1][j];
	
	rep(i, m) {
		int qx1, qy1, qx2, qy2;
		cin >> qx1 >> qy1 >> qx2 >> qy2;
		int x1, x2, y1, y2;
		if(mx.lower_bound(qx1) == mx.end() || my.lower_bound(qy1) == my.end()) {
			cout << 0 <<endl;
			continue;
		}
		x1 = (mx.lower_bound(qx1))->se-1;
		y1 = (my.lower_bound(qy1))->se-1;
		x2 = (--mx.upper_bound(qx2))->se;
		y2 = (--my.upper_bound(qy2))->se;
		cout << get(x1, y1, x2, y2) << endl;
	}
}

Measured memory_bytes: 101644
n = gets.to_i
a = gets.split.map(&:to_i)

flag = false
if n==3
  flag = true
elsif n%3==0
  as = a.sort.each_slice(n/3).map(&:to_a).map(&:uniq)
  if as.map(&:count) == [1,1,1]
    ass = as.map(&:pop)
    flag = true if ass[0] ^ ass[1] == ass[2]
  end
else
  flag = true if a.uniq == [0]
end

puts flag ? :Yes : :No

Measured memory_bytes: 10528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, sum = 0, ans = inf;
	cin >> n;
	int w[514];
	rep(i, n) {
		cin >> w[i];
		sum += w[i];
	}
	int st = 0;
	rep(i, n) {
		st += w[i];
		int en = sum - st;
		ans = min(ans, abs(en - st));
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;





int main(){


	string s; cin >> s;


	int n = s.size();

	vector <string> ans;

	ans.push_back(s.substr(0, 1));

	for(int i = 1; i < n; i++){
		for(int j = 1; j < n; j++){
			if(s.substr(i, j) != ans[ans.size() - 1]){
				ans.push_back(s.substr(i, j));
				i = i + j - 1;
				break;
			}
		}
	}


	cout << ans.size() << endl;
	

	




	return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int X=0;
  for(int i=0;i<2;i++){
  if(A>B){
    X +=A;
    A--;
  }
  else{
    X +=B;
    B--;
  }
  }
  cout << X << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#define INF (1e9)

using namespace std;
map<int, int> mp;
int main()
{
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int n, count,a[100005];
int c = -1;
int main()
{
  int i, j;
  bool can = false;
  std::cin >> n;
  for(i=1; i<=n; i++) std::cin >> a[i];
  i = 1;
  while(n>=0)
  {
    count++;
    j = a[i];
    if(j == 2)
    {
       can = true;
       break;
    }
    i = j;
    n--;
  }
  int ans = (can) ? count : c;
  std::cout << ans << '\n';
}


Measured memory_bytes: 640