akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int sum = 0;
    int x = 0;
    while(sum < n){
        sum += ++x;
    }

    if(sum != n){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    vector<vector<int>> ans(x+1, vector<int>());

    int y = 1;
    for(int s = 1; s <= x; s++){
        for(int t = 0; t < s; t++){
            ans[s].push_back(y);
            ans[t].push_back(y);
            y++;
        }
    }

    cout << x+1 << endl;
    rep(i, x+1){
        int m = ans[i].size();
        cout << m << " ";
        rep(j, m-1){
            cout << ans[i][j] << " ";
        }
        cout << ans[i][m-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
*/

ll mp[5000] = {0};
vector<ll> rt[2000];
queue<ll> ans;
bool rp(ll pos)
{
	mp[pos] = 1;
	int al = 0;
	int al_num = 0;
	for(ll i=0;i<rt[pos].size();++i)
	{
		if(mp[rt[pos][i]]==1)
		{
			al_num = rt[pos][i];
			al ++;
		}
		mp[rt[pos][i]]+=2;
	}
	if(al==1)
	{
		ans.push(al_num);
		return false;
	}

	for(ll i=0;i<rt[pos].size();++i)
	{
		if(mp[rt[pos][i]]==2)
		{
			mp[rt[pos][i]] = 1;
			if(!rp(rt[pos][i]))
			{
				ans.push(rt[pos][i]);
				return false;
			}
			mp[rt[pos][i]] = 2;
		}
	}
	for(ll i=0;i<rt[pos].size();++i)
	{
		mp[rt[pos][i]]-=2;
	}
	mp[pos] = 0;
	return true;
}
int main()
{
	ll i,j,k,a,b;
	ll N,M,K;
	cin >> N>> M;
	for(i=0;i<M;++i)
	{
		cin>>j>>k;
		rt[j-1].push_back(k-1);
	}
	for(i=0;i<N;++i)
	{
		if(!rp(i))
		{
			ans.push(i);
			break;
		}
		mp[i]=2;
	}
	ll last[5000] = {0};
	vector<ll> r_ans;
	if(ans.size()==0)
		cout << -1 << endl;
	else
	{
		while(!ans.empty())
		{
			if(last[ans.front()] == 1)
				break;
			last[ans.front()]=1;
			r_ans.push_back(ans.front());
			ans.pop();
		}
		cout << r_ans.size() << endl;
		while(!r_ans.empty())
		{
			cout << r_ans.back()+1 << endl;
			r_ans.pop_back();
		}
	}
	return 0;
}




















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

#define pb push_back
#define sz(v) ((int)(v.size()))
#define all(v) v.begin(), v.end()
#define nie NULL
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
typedef vector<pii> vpi;

const int inf(1e9);
const int maxN(3e5 + 10);
const ll mod(1e9 + 7);

template <typename T1>
inline void in(T1 &a1) { cin >> a1; }
template <typename T1, typename T2>
inline void in(T1 &a1, T2 &a2) { cin >> a1 >> a2; }
template <typename T1, typename T2, typename T3>
inline void in(T1 &a1, T2 &a2, T3 &a3) { cin >> a1 >> a2 >> a3; }

void _main();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/*--------------------------------------*/
	_main(); return 0;
}

/*--------------------------------------------------------------*/

void _main() {
	int ans = inf;
	int n, k, i; in(n, k);
	for (i = 0; i <= n; i++) {
		ans = min(ans, (1 << i) + (n - i) * k);
	} printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define INF (1LL << 31)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

int main()
{
    ll n, x, l; cin >> n;
    vector<P> arm(n);
    rep(i, n) {
        cin >> x >> l;
        arm[i].first = x + l;
        arm[i].second = x - l;
    }

    sort(arm.begin(), arm.end());
    ll ra = -INF;
    ll cnt = 0;

    rep(i, n) {
        if (ra <= arm[i].second){
            ++cnt;
            ra = arm[i].first;
        }
    };
    // rep(i, n) cout << arm[i].first << " " << arm[i].second << endl;
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int A, B;
	cin >> A >> B;

	cout << (((A + B) % 3 == 0 || (A % 3 == 0) || (B % 3 == 0)) ? "Possible" : "Impossible") << endl;
	return 0;
}


Measured memory_bytes: 256
n,C = map(int,input().split())
d = [[int(i) for i in input().split()] for _ in range(C)]
c = [[int(i)-1 for i in input().split()] for _ in range(n)]

cnt0 = [0]*C
cnt1 = [0]*C
cnt2 = [0]*C
for i in range(n):
    for j in range(n):
        for k in range(C):
            if (i+j)%3 == 0: cnt0[k] += d[c[i][j]][k]
            elif (i+j)%3 == 1: cnt1[k] += d[c[i][j]][k]
            else: cnt2[k] += d[c[i][j]][k]

ans = float("inf")
for i in range(C):
    for j in range(C):
        if i == j: continue
        for k in range(C):
            if i == k or j == k: continue
            ans = min(ans, cnt0[i] + cnt1[j] + cnt2[k])
print(ans)

Measured memory_bytes: 46172
N = int(input())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
C = list(map(int, input().split())) 
total = 0
preDish = -10
for a in A:
  total += B[a-1]
  if preDish == a - 1 and preDish <= len(C):
    total += C[preDish - 1]
  preDish = a

print(total)

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

using static Input;
using static Util;
class Program
{
    static string S;
    static string T;
    static void INPUT()
    {
        S = NextString();
        T = NextString();
    }
    static void OUT()
    {
        var t = T.ToCharArray();
        for (var idx = S.Length - T.Length; idx >=0; idx--)
        {
            var ca = S.Substring(idx).ToCharArray();
            var b = true;
            for(var i = 0; i < t.Length; i++)
            {
                if (ca[i] != '?' && t[i] != ca[i])
                {
                    b = false;
                    break;
                }
            }

            if (b)
            {
                Console.WriteLine(S.Substring(0, idx).Replace('?','a') + T + S.Substring(idx + T.Length).Replace('?', 'a'));
                return;
            }
        }
        Console.WriteLine("UNRESTORABLE");
    }
    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
        S = "?tc????tc????";
       T = "coder";
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 13268
def main():
  n = int(input())
  a = list(map(int, input().split()))

  if 0 in a:
    print(0)
    return

  prod = 1
  for a in a:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  
  print(prod)
  
main()

Measured memory_bytes: 21644
x,y=map(int,input().split())
if abs(x) == abs(y):
    print(1)
elif x==0:
    if y < 0:
        print(1+abs(y))
    else:
        print(abs(y))
elif x > 0:
    if abs(y) < x:
        if y == 0:
            print(1+y+x)
        elif y>0:
            print(abs(abs(y)-abs(x))+2)
        else:
            print(y+x+1)
    else:
        if y > 0:
            print(y-x)
        else:
            print(abs(y)-x+1)
else:
    if abs(y) <abs(x):
        if y >0 :
            print(1+abs(abs(x)-abs(y)))
        elif y==0:
            print(abs(x))
        else:
            print(abs(-x+y))
    else:
        if y >0:
            print(1+y+x)
        else:
            print(2+x-y)


Measured memory_bytes: 61984
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val length = sc.nextInt()
    val input: Array[Int] = Array.fill(length)(sc.nextInt())

    val min = input.min
    val max = input.max
    val ans = min
      .to(max)
      .map { position =>
        input.map(_ - position).map(distance => distance * distance).sum
      }
      .min

    println(ans)
  }
}


Measured memory_bytes: 27724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int sum=0;
    int number_of_items,max=INT_MIN;
    cin>>number_of_items;
    for(int i=0;i<number_of_items;i++)
    {
        int this_item;
        cin>>this_item;
        sum+=this_item;
        max=(this_item>max)?this_item:max;
    }
    sum=sum-max+(max/2);
    cout<<sum<<endl;
    return 0;
}

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

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main()
{
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin>>n>>m;
    cout<<(n*(n-1))/2 + (m*(m-1))/2;
    
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
 
    char ch;
    int counter[26] = {};
 
    while(cin >> ch){
        if(islower(ch)) counter[ch - 'a']++;
        if(isupper(ch)) counter[ch - 'A']++;
    }
 
    for(int i = 0; i < 26; i++){
        char ch2 = i + 'a';
        cout << ch2 << " : "<< counter[i] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3068
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(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;


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

    int l=0;
    int r=0;
    bool flg=false;
    for(int i=0;i<n;i++){
        int tmp;cin >> tmp;
        if(tmp==1) {
            flg=true;
            continue;
        }
        if(flg){
            r++;
        } else {
            l++;
        }
    }
    k--;
    p(l/k+r/k+(l%k+r%k+k-1)/k)
} 

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<iostream>
#include<vector>
#include<bitset>
#include<ctime>
#include<cmath>
#include<queue>

using namespace std;

#define bomb exit(1)
#define INF 1061109567
#define LINF 4557430888798830399ll
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
#define EE(x); struct edge { int nxt,to,w; }e[M << 1]; int head[N],ecnt = 1;\
	void add(int u,int v,ll w = 0) { e[++ecnt].w = w,e[ecnt].to = v,e[ecnt].nxt = head[u];head[u] = ecnt; }\
	void add_edge(int u,int v,ll w = 0) { add(u,v,w),add(v,u,w * x); }
#define ll long long
const double pi = acos(-1);
int mod = 1000000007;
ll Mod(ll x) { return x >= mod ? x - mod : x; }
#define eps 0.0000000001
#define sqr(x) ((x) * (x))
#define iter iterator
#define fi first
#define se second
//#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
//char BB[1 << 15],*SS = BB,*TT = BB;
ll read()
{
	ll x = 0;int f = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') f = -1;
	for(;isdigit(ch);ch = getchar()) x = x * 10 + (ch ^ 48);
	return x * f;
}
void print(ll x)
{
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);putchar(x % 10 + '0');
}

const int N = 1000010;
int n,ans;char s[N],t[N];
queue<int> q;

int main()
{
	n = read();scanf("%s %s",s,t);
	if(!strcmp(s,t)) { puts("0");return 0; }
	int up(n - 1),down(n - 1);
	while(~down)
	{
		while(down && t[down - 1] == t[down]) down--;
		while(~up && (up > down || s[up] != t[down])) up--;
		if(up < 0) { puts("-1");return 0; }
		while(!q.empty() && q.front() - q.size() >= down) q.pop();
		if(up ^ down) q.push(up);
		ans = max(ans,(int)q.size() + 1);
		down--;
	}fprint(ans);
	return 0;
}

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

 int main() {
 int r, g, b;
 cin >> r >> g >>b;
 if((r * 100 + g * 10 + b) % 4 == 0){
 cout << "YES" << endl;
}
 else{
 cout << "NO" << endl;
}
}




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

  int main(){
  	string A;
	cin >> A;
	int a = 0 , b = 0  , c =  0;
	for(int i =0  ;i  < A.size() ; ++i){
		if(A[i] == 'a')a++;
		if(A[i] == 'b')b++;
		if(A[i] == 'c')c++;
 	}
	if(a ==1 and b == 1 and c == 1)printf("Yes");
	else printf("No"); 
 }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String[] args){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		try{

			String[] strLine = insBR.readLine().split(" ");
			List<Double> list = new ArrayList<Double>();
			for(int i = 0; i < strLine.length; i++){
				list.add(Double.parseDouble(strLine[i]));
			}
			double dbX = list.get(2) - list.get(0);
			double dbY = list.get(3) - list.get(1);
			double dbPowXY = dbX * dbX + dbY * dbY;
			double dbXY = Math.sqrt(dbPowXY);
			String strXY = String.format("%1$.5f", dbXY);
			System.out.println(strXY);

		}catch(IOException e){
			e.printStackTrace();
		}catch(NumberFormatException e){
			e.printStackTrace();
		}

	}

}



Measured memory_bytes: 24712
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    double tmp1 = 1.0;
    rep(i,N){
        tmp1 *= A[i];
    }
    double tmp2 = 0.0;
    double tmp;
    rep(i,N){
        tmp = 1.0;
        rep(j,N){
            if(i == j)continue;
            tmp *= A[j];
        }
        tmp2 += tmp;
    }

    cout << fixed << setprecision(10) << tmp1/tmp2 << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        Map<String, Integer> count = new HashMap<>();
        int n = in.nextInt();
        long res = 0;
        for (int i = 0; i < n; i++) {
            String s = sort(in.next());
            res += (count.containsKey(s) ? count.get(s) : 0);
            if (count.containsKey(s)) {
                count.replace(s, count.get(s) + 1);
            } else {
                count.put(s, 1);
            }
        }

        System.out.println(res);
    }

    private static String sort(String text) {
        char[]chars = text.toCharArray();
        Arrays.sort(chars);
        return new String(chars);
    }
}

Measured memory_bytes: 55252
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int a,b;
     cin>>a>>b;
     int c=a+b;
     if(c%2!=0)
     {
         cout<<"IMPOSSIBLE"<<endl;
     }
     else
     {
         cout<<c/2<<endl;
     }
     return 0;

 }


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;

  cin >> n;
  cin.ignore();
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);

    int pos;
    while ((pos = s.find("Hoshino")) != -1) {
      s[pos + 6] = 'a';
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int n;
int o;
string s;

int rui[4]={0};

int main(){
    cin>>n;
    while(n!=0){
        cin>>s;
        if(s=="HIT"){
            for(int i=3; i>=1; i--){
                if(rui[i-1]!=0){
                    rui[i]+=rui[i-1];
                    rui[i-1]--;
                }
            }
            rui[0]++;
        }else if(s=="HOMERUN"){
            for(int i=2; i>=0; i--){
                rui[3]+=rui[i];
                rui[i]=0;
            }
            rui[3]++;
            
        }else if(s=="OUT"){
            o++;
            if(o==3){
                n--;
                cout<<rui[3]<<endl;
                for(int i=3; i>=0; i--){
                    rui[i]=0;
                    o=0;
                }
            }
        }
    }
}

Measured memory_bytes: 1208
#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if (a * n > b)printf("%d\n", b);
	else printf("%d\n", a * n);
	

		return 0;
}

Measured memory_bytes: 888
s = input()
a, b = int(s[:2]), int(s[2:])

if 1<=a<=12 and 1<=b<=12:
  print('AMBIGUOUS')
elif 1<=b<=12:
  print('YYMM')
elif 1<=a<=12:
  print('MMYY')
else:
  print('NA')

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

int main(){
  int x,y,z,d,a,b;
  scanf("%d %d",&a,&b);
  if(a<1 || a>10e9 || b<1 || b>10e9) exit(2);
  if(a<b){
    x = b;
    y = a;
  }else{
    x = a;
    y = b;
  }
  d = x % y;
  while(d!=0){
    x = y;
    y = d;
    d = x % y;
  }
  printf("%d\n",y);
  
  return 0;
}



Measured memory_bytes: 2144
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc096/tasks/abc096_d

//ポイント：
//自由に生成する問題では如何に条件を絞れるかが重要

//5つの数の和が合成数
//合成数の集合をまず考える
//合成数という集合の中には5の倍数が含まれる
//5つの数の和が5の倍数であるようにするには、5つの数の一桁めが全部同じなら良い

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//xが素数ならtrueを返す
bool factorial(LL x){
	for(LL i=2;i*i<=x;i++){
		if(x%i==0) return false;
	}
	return true;
}

LL N;
 
vector<LL> ans;

void solve(){
	vector<LL> prime;
	for(int i=3;i<=55555;i++){
		if(factorial(i)) prime.push_back(i);
	}
	for(int i=0;i<prime.size() && ans.size()<N;i++){
		if(prime[i]%10==1) ans.push_back(prime[i]);
	}
}

int main(){
    cin >> N;
 
    solve();
 
    for(int i=0;i<ans.size();i++) cout << ans[i] << " ";
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        long[] a = sc.LongArray();
        long[] afterSum = new long[n + 1];
        for (int i = n; i >= 0; i--)
        {
            if (i == n)
            {
                afterSum[i] = a[i];
            }
            else
            {
                afterSum[i] = a[i] + afterSum[i + 1];
            }
        }

        if (n == 0)
        {
            if (a[0] == 1)
            {
                Console.WriteLine(1);
                return;
            }
            else
            {
                Console.WriteLine(-1);
                return;
            }
        }

        if (a[0] != 0)
        {
            Console.WriteLine(-1);
            return;
        }

        long answer = 1;
        long current = 1;

        for (int i = 1; i <= n; i++)
        {
            current *= 2;
            current = Math.Min(afterSum[i], current);
            answer += current;
            current -= a[i];
            if (current < 0)
            {
                Console.WriteLine(-1);
                return;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 38264
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	
	public static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());
		string[] w = Input();
		long[] h = new long[n];
		for(int i = 0; i < n; i++)
		{
			h[i] = long.Parse(w[i]);
		}
		int r = 0;
		for(int i = 0 ; i < n-1; i++)
		{
			int cnt = 0;
			for(; i < n-1; i++)
			{
				if(h[i] < h[i+1])
				{
					break;
				}
				cnt++;
			}
			r = Math.Max(r, cnt);
		}
		Console.WriteLine(r);
	}
	
	public static long GCD(long a, long b)
	{
		if(b == 1)
			return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	public static string[] Input()
	{
		return Console.ReadLine().Split(' ');
	}

	
	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}

}



Measured memory_bytes: 27356
require "forwardable"

MOD = 2019
class Modint
  extend Forwardable
  def_delegators :@a, :hash, :to_i
  
  def initialize(a); @a = a.to_i % MOD; end
  def + (other); Modint[@a + other.to_i]; end
  def - (other); Modint[@a - other.to_i]; end
  def * (other); Modint[@a * other.to_i]; end
  def ** (other); Modint[@a.pow other.to_i, MOD]; end
  def / (other); Modint[@a * other.to_i.pow(MOD-2, MOD)]; end
  def eql? (other); @a.eql? other.to_i; end
  def inspect; "#{@a}"; end
  def coerce(other); [self, other]; end
  
  alias :pow :**
  class << self; alias :[] :new; end
end
M = Modint

a = gets.chomp.chars.map(&:to_i).reverse
n = a.size
dp = Array.new(n+1)
dp[0] = M[0]

n.times do |i|
  dp[i+1] = 10.pow(i,MOD) * a[i] + dp[i]
end
ans = dp.tally.values.map{ |v| v*(v-1)/2 }.sum
puts ans

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

#define N_MAX 100000
int main(){

  int n, a[N_MAX], cnt_4=0, cnt_2=0;
  
  cin >> n;

  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i]%2==0){
      if(a[i]%4==0){
        cnt_4++;
      } else {
        cnt_2++;
      }
    }
  }

  cnt_2/=2;

  int cnt = cnt_2 + cnt_4;
  if(cnt>=n/2){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N;
    cin >> N;
    string S;
    cin >> S;
    string prev_s = to_string(S[0]);
    long count=1;
    for(size_t i=i;i<N; i++)
    {
        if(prev_s != to_string(S[i])) count++;
        prev_s = to_string(S[i]);
    }
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1 << 30

using namespace std;

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

    int ans = INF;
    REP(i, N) {
        int count = 0;
        cin >> A;
        while (A % 2 == 0) {
            count++;
            A /= 2;
        }
        ans = min(count, ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int,int> > adj[MAX];

void dijkstra(){
  priority_queue<pair<int,int> > PQ;
  int color[MAX];
  int d[MAX];
  for(int i=0;i<n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0,0));
  color[0] = GRAY;

  while(!PQ.empty()){
    pair<int,int> f = PQ.top();PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    if(d[u] < f.first*(-1)) continue;

    for(int j=0;j<adj[u].size();j++){
      int v = adj[u][j].first;
      if(color[v] == BLACK) continue;
      if(d[v] > d[u] + adj[u][j].second){
	d[v] = d[u] +adj[u][j].second;
	PQ.push(make_pair(d[v]*(-1),v));
	color[v] = GRAY;
      }
    }
  }

  for(int i=0;i<n;i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main(){
  int k,u,v,c;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >>v >> c;
      adj[u].push_back(make_pair(v,c));
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 3408
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
 
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	ll n, x; cin >> n >> x;
	cout << min(x-n%x, n%x) << '\n';
 
	return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    ll ans = 0;
    vector<ll> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];
    sort(H.begin(), H.end());
    for (int i = 0; i < N-K; i++) ans += H[i];
    cout << ans << endl;
    return 0;
}

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

int main(){
  int64_t A, V, B, W, T;
  string res = "NO";
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;
  
  for(int i=0; i< T; i++){
	  if(A > B){
    	B = B - W;
    	A = A - V;
    	if(A <= B){
      	res = "YES";
      	break;
    	}
  	}else{
    	B = B + W;
    	A = A + V;
    	if(A >= B){
      	  res = "YES";
      	  break;
    	}
    }
  }
  
  cout << res << endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<vector<int>> g(n, vector<int>(n, -1));
  rep(i, n)
  {
    int a;
    cin >> a;
    rep(j, a)
    {
      int x, y;
      cin >> x >> y;
      x--;
      g[i][x] = y;
    }
  }
  int ans = 0;
  rep(i, 1 << n)
  {
    vector<int> d(n);
    rep(j, n)
    {
      if (i & 1 << j)
        d[j] = 1;
    }
    bool ok = true;
    rep(j, n)
    {
      if (d[j])
      {
        rep(k, n)
        {
          if (g[j][k] == -1)
            continue;
          if (g[j][k] != d[k])
            ok = false;
        }
      }
    }
    if (ok)
      ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#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)<(N);(i)++)
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

int main() {
  int n, k;
  cin >> n >> k;
  mint ans = 0;
  combination comb(n);
  for(int i = 0; i <= min(k, n - 1); ++i) {
    ans += comb(n, i) * comb(n - i - 1 + i, i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
import java.util.*;

import static java.lang.Math.round;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int modl =   l% 2019;
        int modr = r%2019;
        long ans =2018;

        if(modr<= r-l){
            System.out.println(0);
        }else{
            for(int p=modl; p < modr; p++){
                for(int q=p+1; q <= modr; q++){
                    ans = Math.min(ans, (p*q)%2019);

                }
            }
            System.out.println(ans);

        }






        }
    }

Measured memory_bytes: 22868
#encoding:utf-8 No.0013 2014.10.1
shed = []
while gets
  car = $_.chomp
  if car == ""
    break
  end
  shed.push car.to_i
end

cars_out = []

until shed.length == 0
  shed.length.times do |i|
    if shed[i] == 0
      cars_out.push shed[i-1]
      shed.delete_at(i)
      shed.delete_at(i-1)
      break
    end
  end
end

puts cars_out

Measured memory_bytes: 6092
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  _l=[I() for _ in range(n)]
  l=collections.deque()

  for A in _l:
    if len(l)==0:
      l.append(A)
      continue

    lv=l[0]
    rv=l[-1]
    if rv<A:
      l[-1]=A
      continue
    if A<=lv:
      l.appendleft(A)
      continue

    li=0
    ri=len(l)-1
    while ri-li>1:
      mi=(ri+li)//2
      if l[mi]<A:
        li=mi
      else:
        ri=mi

    l[li]=A

  # print(l)
  return len(l)

# main()
print(main())


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

#define rep(i,n) for(int i=0;i<(n);++i)
int n,t=24,c[2],d[50];

int main() {
  cin>>n;
  rep(i,n)cin>>d[i];
  sort(d,d+n);
  rep(i,n) {
    t=min(t,d[i]-c[i&1]);
    c[i&1]=d[i];
  }
  cout<<min(t,24-c[0]-c[1])<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

    

def main():
    mod=10**9+7
    N,M=MI()
    edges=[None]*M
    
    for i in range(M):
        a,b,c=MI()
        a-=1
        b-=1
        c*=-1
        edges[i]=(a,b,c)
        
    ########################    
    #0から他の頂点へ
    def BellmanFord(N, M, edges):
        inf=10**20
        d = [inf] * N
        d[0] = 0

        for i in range(N-1):
            for (u, v, c) in edges:
                if d[u] + c < d[v]:
                    d[v] = d[u] + c

        #for i in range(N):
        for (u, v, c) in edges:
            if d[u] + c < d[v]:
                if v == N-1:
                    return None#負の閉路
                
                d[v] = d[u] + c
        return d[N-1]
    ########################
        
    ans = BellmanFord(N, M, edges)
    if ans is None:
        print('inf')
    else:
        print(-ans)

main()


Measured memory_bytes: 41964
# ABC095C - Half and Half
a, b, c, x, y = list(map(int, input().rstrip().split()))
ans = min(
    c * 2 * max(x, y),
    a * x + b * y,
    c * 2 * y + a * max(0, x - y),
    c * 2 * x + b * max(0, y - x),
)
print(ans)

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

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

using namespace std;

//v.push_back(123);
//sort(v.begin(), v.end(),greater<int>());
//for(int x : v) {cout << x << endl;}

//for(int x: v) cout << x << endl;
//vector<vector<char>> v(H, vector<char>(W));
//vector<int> v(1000);

signed main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];

  sort(a, a+3,greater<int>());

  cout << a[1]+a[2] << endl;
  return 0;
}


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

#define LEN 100005
#define MAX 100000
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0, tail=0, n;

void enqueue(P x){
  Q[tail] = x;
  if((tail+1)==MAX){
    tail=0;
  }else{
    tail++;
  }
}

P dequeue(){
  P x;
  x=Q[head];
  if((head+1)==MAX){
    head=0;
  }else{
    head++;
  }
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", u.name);
    scanf("%d", &u.t);
    enqueue(u);
    //printf("1");
  }
  
  while(head != tail){
    //printf("while\n");
    if(Q[head].t-q<=0){
      //printf("if\n");
      elaps+=Q[head].t;
      printf("%s %d\n",Q[head].name,elaps);
      dequeue();
  }else if(Q[head].t-q>0){
      //printf("else if\n");
      elaps+=q;
      Q[head].t=Q[head].t-q;
      enqueue(dequeue());
    }
  }
  return 0;
}

Measured memory_bytes: 10756
#include<iostream>
main(){int n,X,Y,W,H,N,x,y,a;for(std::cin>>n;n-->(a=0);printf("%d\n",a))for(std::cin>>X>>Y>>W>>H>>N;N-->0;a+=X<=x&x<=X+W&Y<=y&y<=Y+H)std::cin>>x>>y;}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int a[31] ={};
    a[1] =1;
    a[2] =2;
    a[3] =4;
    for (int i=4;i<31;i++){
        a[i]=a[i-1]+a[i-2]+a[i-3];
    }
    while (true){
    int i;
    cin >> i;
    if (i==0){
        break;
    }
    if (a[i]%3650 ==0){
        cout << a[i]/3650 ;
    }
    else {
        cout << a[i]/3650+1 << endl;
    }
}
    
    

    
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long
#define mp make_pair
#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define N 100010
#define Pa 99991
#define Maxi 1e18

int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll i,j;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll dp[n];
    //memset(dp,0,sizeof(dp));
    for(i=0;i<n;i++)
    {
        dp[i]=Maxi;
    }
    dp[0]=0;
    for(i=1;i<n;i++)
    {
        for(j=i-1;j>=i-k&&j>=0;j--)
        {
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    // for(i=0;i<n;i++)
    // {
    //     cout<<dp[i]<<" ";
    // }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main()
{
  int k;
  cin >> k;
  cout << k / 2 * (k - k / 2) << endl;
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
H=[0]+list(map(int,input().split()))
check=[0]+[1]*N
for _ in range(M):
  a,b=map(int,input().split())
  if H[a]>=H[b]:
    check[b]=0
  if H[b]>=H[a]:
    check[a]=0
print(sum(check))


Measured memory_bytes: 19996
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n,m;
  while( (n = getInt()) + (m = getInt()) ){
    vector<pair<int,int> > but[n];
    int rest[n];
    int p[n];

    REP(i,n){
      int d,c;
      while(d = getInt()){
        c = getInt();
        but[i].push_back(mp(d,c));
      }

      rest[i] = but[i][0].f;
      p[i]    = 0;
    }


    queue<int> q;
    int buttery = 0;
    int ans = 0;

    REP(t,m){
      //REP(i,n) printf("%2d ",rest[i]); puts("");

      REP(i,n){
        if(rest[i]){
          rest[i]--;
          if(rest[i] == 0){
            q.push(i);
          }
        }else{
          ans++;
        }
      }

      if(buttery){
        buttery--; ans--;

        if(buttery == 0){
          int id = q.front();
          q.pop();

          p[id] = (p[id] + 1) % but[id].size();
          rest[id] = but[id][p[id]].f;
        }
      }

      if(buttery == 0 && q.size() != 0){
        int id = q.front();
        buttery = but[id][p[id]].s;
      }

    }

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 900
N,Y = map(int,input().split())

for i in range(N+1):
    for j in range(N+1-i):
        if(i*10000+j*5000+(N-i-j)*1000 == Y):
            print(i,j,N-i-j)
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lld n,i,j,i1,k,s;
    cin>>n;
    unordered_map<lld,lld>mp;
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                mp[(i*i+j*j+k*k+i*j+j*k+k*i)]++;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
    cout<<mp[i]<<"\n";
    }
	return 0;
}


Measured memory_bytes: 5108
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long ans = 0;
    vector<long long> a(n);
    vector<long long> t(n);
    for (int i=0; i<n; ++i){
        cin >> t[i] >> a[i];
    }
    // --- solve ---
    long long a_tmp;
    long long t_tmp;
    for (int i=0; i<n; ++i){
        if(i == 0){
            a_tmp = a[0];
            t_tmp = t[0];
        }
        else {
            long long a_d = a_tmp / a[i] + ((a_tmp % a[i] == 0) ? 0 : 1);
            long long t_d = t_tmp / t[i] + ((t_tmp % t[i] == 0) ? 0 : 1);
            long long max_v = max(a_d, t_d);
            a_tmp = a[i] * max_v;
            t_tmp = t[i] * max_v;
            // cout << i << " -> " << a_tmp << " " << t_tmp << endl;
        }
    }
    ans = a_tmp + t_tmp;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,k;
   cin >> n >> k;
   vector<int> A(n);
   f(i,0,n){
      cin >> A[i];
   }

   auto check = [&](int v){
      int R = 0;
      f(i,0,n){
         R += (A[i]-1)/v;
      }
      return R <= k;
   };


   int ans = 1e10;
   int l = 1, h = 1e10;
   while(l <= h){
      int mid = (l+h)/2;
      // debug(l,h);
      if(check(mid)){
         h = mid-1;
         ans = mid;
      }else{
         l = mid+1;
      }
   }
   cout << ans << '\n';
   return 0;
} 


Measured memory_bytes: 4756
#include <stdio.h>
int abs(int a){return a>0?a:-a;}
int n,map[100001],sum[100001],money[100001];
int main(void) {
	int n; scanf("%d",&n);
	for(int i=1;i<=n+1;i++){
		if(i<=n) scanf("%d",&map[i]);
		money[i] = abs(map[i]-map[i-1]);
		//printf("%d ",money[i]);
		sum[i]=sum[i-1]+money[i];
	}
	//puts("");
	for(int i=1;i<=n;i++){
		printf("%d\n",sum[n+1]-money[i]-money[i+1]+abs(map[i+1]-map[i-1]));
		//printf("%d %d %d %d\n",sum[n+1],money[i],money[i+1],abs(map[i+1]-map[i-1]));
	}
	return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int n; cin>>n;
  ll ans = 0;
  for (int i=0; i<n; i++) {
    ll x; cin>>x; ans += x; ans--;
  }
  cout<<ans<<endl;
  

  return 0;
}


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

namespace AtCoder
{
    class Abc162F
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();

            int m = n / 2;

            var dp = new long[n + 1, 2];
            dp[1, 1] = a[0];

            /*
             * dp[i, j] はi文字目までに選んだ値の和の最大値
             * j == 0 なら (i + 1) / 2 - 1 個選んでいる
             * j == 1 なら (i + 1) / 2     個選んでいる
             */

            for (int i = 2; i <= n; i++)
            {
                if (i % 2 == 0)
                {
                    dp[i, 0] = Math.Max(dp[i - 2, 0] + a[i - 1], dp[i - 1, 0]);
                    dp[i, 1] = Math.Max(dp[i - 2, 1] + a[i - 1], dp[i - 1, 1]);
                }
                else
                {
                    dp[i, 0] = Math.Max(dp[i - 2, 0] + a[i - 1], dp[i - 1, 1]);
                    dp[i, 1] = dp[i - 2, 1] + a[i - 1];
                }
            }

            Console.WriteLine(n % 2 == 0 ? dp[n, 1] : dp[n, 0]);
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

template<class T> inline bool chmin(T& a, const T b) { if (a>b) { a=b; return true; } return false; }
template<class T> inline bool chmax(T& a, const T b) { if (a<b) { a=b; return true; } return false; }

#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    //b > a
    //c > b

    while(a>=b && k>0){
        b *= 2;
        k--;
    }
    //DEBUG(k);

    while(b>=c && k>0){
        c *= 2;
        k--;
    }
    //DEBUG(k);

    if(a<b && b<c) yn;
    return 0;
}

Measured memory_bytes: 3652