akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int INF=1e9;
int dp[1<<13];

int main(){
    int N,M; cin >> N >> M;
    for(int i=0;i<(1<<13);i++){
        dp[i]=INF;
    }
    dp[0]=0;
    for(int i=0;i<M;i++){
        int a,b; cin >> a >> b;
        int k=0;
        for(int j=0;j<b;j++){
            int c; cin >> c; c--;
            k+=(1<<c);
        }
        for(int bit=0;bit<(1<<N);bit++){
            dp[bit|k]=min(dp[bit|k],dp[bit]+a);
        }
    }
    if(dp[(1<<N)-1]==INF){
        cout << -1 << endl;
    }else{
        cout << dp[(1<<N)-1] << endl;
    }
}

Measured memory_bytes: 256
from heapq import heappop, heappush

n = int(input())
_, a, b = map(int, input().split())
l = []
r = []
med_val = a
sum_l = 0
sum_r = 0
sum_b = b

for _ in range(n-1):
    query = input().split()
    if query[0] == '1':
        _, a, b = map(int, query)
        if len(l) < len(r):
            if a <= med_val:
                heappush(l, -a)
                sum_l += a
            else:
                heappush(l, -med_val)
                sum_l += med_val
                heappush(r, a)
                sum_r += a
                med_val = heappop(r)
                sum_r -= med_val
        else:
            if med_val < a:
                heappush(r, a)
                sum_r += a
            else:
                heappush(r, med_val)
                sum_r += med_val
                heappush(l, -a)
                sum_l += a
                med_val = -heappop(l)
                sum_l -= med_val
        sum_b += b
    else:
        f = len(l) * med_val - sum_l + sum_r - len(r) * med_val + sum_b
        print("{} {}".format(med_val, f))



    
        



Measured memory_bytes: 89240
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let n: usize = read!();
    let mut ans: u128 = 1;
    let mut vec = vec![];
    for _ in 0..n {
        let b: u128 = read!();
        if b == 0 {
            println!("0");
            std::process::exit(0);
        } else {
            vec.push(b);
        }
    }

    for x in vec {
        if (1000000000000000000) / ans < x {
            println!("-1");
            std::process::exit(0);
        } else {
            ans *= x;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 3724
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  int n,x,y;
  cin>>n>>x>>y;
  
  repo(i,n){
    set<pair<int,int>> p;
    repo(j,n-i+1){
      if((abs(j-x)+1+abs(j+i-y))>=i) {
      auto z=mp(j,j+i);
      p.insert(z);
      }
    }
    rep(j,i) {
      if(abs((y+i-1-j)-(x-j))>=i && y+i-1-j<=n && x-j>=1) {
      auto z=mp(x-j,y+i-1-j);
      p.insert(z);    
      }
      if(abs((y+i-1-j)-(x+j))>=i && y+i-1-j<=n && x+j<=n) {
      auto z=mp(x+j,y+i-1-j);
      p.insert(z);    
      }     
      if(abs((y-i+1+j)-(x+j))>=i && y-i+1+j>=1 && x+j<=n) {
      auto z=mp(x+j,y-i+1+j);
      p.insert(z);    
      }   
      if(abs((y-i+1+j)-(x-j))>=i && y-i+1+j>=1 && x-j>=1) {
      auto z=mp(x-j,y-i+1+j);
      p.insert(z);    
      }          
    }
    
  cout << p.size() << endl;
  }
  
  
}


Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll one_cnt = 0;
    ll two_cnt = 0;
    rep(i, n) {
        ll diff = b[i] - a[i];
        if ( diff < 0 ) one_cnt += -diff;
        if ( diff > 0 ) two_cnt += diff / 2;
    }
    if ( two_cnt >= one_cnt ) cout << "Yes" << endl;
    else                      cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 384
package main

import "fmt"

func main() {
	// Code for C - Build Stairs
	var N int
	fmt.Scanf("%d", &N)

	H := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &H[i])
	}

	var temp int = H[N-1]
	var ans int
	var flag int
	for i := N - 2; 0 <= i; i-- {
		A := temp - H[i]

		if A == -1 {
			ans++
		} else if A < -1 {
			flag++
		} else {
			temp = H[i]
		}
	}
	if flag == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 6316
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
ll n;
ll pro(ll a,ll b) {
	return llabs(b-a);
}
int main()
{
	FAST
	cin>>n;
	vector<ll> A(n+1, 0);
	FOR(i,1,n) cin>>A[i];
	ll total=accumulate(A.begin()+1, A.end(), 0ll);
	ll sum = 0;
	FOR(i,1,n) {
		sum += A[i];
		if(i > 1 && sum >= total/2) {
			ll other=total-sum;
			sum -= A[i];
			cout<<min(pro(sum+A[i],other), pro(other+A[i],sum))<<'\n';
			return 0;
		}
	}
	assert(0);
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string ss;
int main() {
	cin>>ss;
	if (ss=="SUN") puts("7");
	else if (ss=="MON") puts("6");
	else if (ss=="TUE") puts("5");
	else if (ss=="WED") puts("4");
	else if (ss=="THU") puts("3");
	else if (ss=="FRI") puts("2");
	else puts("1");
	return 0;
}

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

public class Main {

   void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}



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

namespace _20180319_AOJ
{
    class ALDS1_11D
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int[] n_m = line.Split(' ').Select(int.Parse).ToArray();
                int n = n_m[0];
                int m = n_m[1];

                HashSet<int>[] groups = new HashSet<int>[n];
                for(int i=0;i<n;i++)
                {
                    groups[i] = new HashSet<int>(new int[] { i });
                }

                for (int i = 0; i < m; i++)
                {
                    int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    int s = s_t[0];
                    int t = s_t[1];
                    
                    if(!groups[s].Equals(groups[t]))
                    {
                        if(groups[s].Count > groups[t].Count)
                        {
                            groups[s].UnionWith(groups[t]);
                            foreach(var v in groups[t])
                            {
                                groups[v] = groups[s];
                            }
                        }
                        else
                        {
                            groups[t].UnionWith(groups[s]);
                            foreach (var v in groups[s])
                            {
                                groups[v] = groups[t];
                            }
                        }
                    }
                }

                int q = int.Parse(Console.ReadLine());
                for (int i = 0; i < q; i++)
                {
                    int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    if (groups[s_t[0]].Equals(groups[s_t[1]]))
                    {
                        Console.WriteLine("yes");
                    }
                    else
                    {
                        Console.WriteLine("no");
                    }
                }
            }
        }
    }
}



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

int gcd(int a, int b){
    if(a < b){
        swap(a, b);
    }
    int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> gcdl(N);
    vector<int> gcdr(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    gcdl.at(0) = A.at(0);
    gcdr.at(N-1) = A.at(N-1);
    for(int i=1;i<N;i++){
        gcdl.at(i) = gcd(gcdl.at(i-1), A.at(i));
        gcdr.at(N-i-1) = gcd(gcdr.at(N-i), A.at(N-i-1));
    }
    int max_number = max(gcdl.at(N-2), gcdr.at(1));
    for(int i=1;i<N-1;i++){
        max_number = max(max_number, gcd(gcdl.at(i-1), gcdr.at(i+1)));
    }
    cout << max_number;

    return 0;

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long n,m,a,b,c,d[2000],P;
vector<pair<long,long>>x[3000];
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){cin>>a>>b>>c;a--;b--;x[a].push_back(make_pair(b,c));}
  for(int i=0;i<n;i++)d[i]=-(1L<<60);
  d[0]=0;
  P=d[n-1];
  for(int i=0;i<n*2;i++){
    for(int j=0;j<n;j++){
      for(auto k:x[j]){
        d[k.first]=max(d[k.first],d[j]+k.second);
      }
    }
    if(P!=d[n-1]&&i>=n){cout<<"inf"<< endl;return 0;}
    P=d[n-1];
  }
  cout<<d[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n: u64,
        Y: u64,
    }

    for x in (0..n+1).rev(){
        for y in (0..(n + 1) - x).rev(){
            let z = n - (x + y);
            if x * 10000 + y * 5000 +  z * 1000 == Y {
                println!("{} {} {}",x,y,z);
                return;
            }
        }
    }
    println!("-1 -1 -1");


}  


Measured memory_bytes: 4352
import bisect
from operator import itemgetter
import math
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def combi(a,b):
  C = 1
  for j in range(b):
    C = C*(a-j)//(j+1)
  return C

N,K = IL()

num = combi(N-1,2)
if num < K:
  print(-1)
  exit()
else:
  print(N-1 + num-K)
  for i in range(2,N+1):
    print(1,i)
data = [i for i in range(2,N+1)]

for i in itertools.combinations(data,2):
  if K == num:
    break
  print(i[0],i[1])
  num -= 1

Measured memory_bytes: 12688
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long ll;
typedef vector< ll > vl;
typedef vector< vl > vvl;
const ll MAX = 1e5+5;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define EE '\n'
#define ll long long int
#define forn(i,j,n) for ( auto i=j ; i<n ; i++ )
#define fornd(i,j,n) for ( auto i=j ; i>n ; i-- )
#define PI 3.14159265
#define g(a,b) a>b?a:b
#define l(a,b) a<b?a:b
#define SOT(A) sort(A.begin(),A.end())
#define SOTR(A) sort(A.rbegin(),A.rend())

const int N = 200043;
const int MOD = 998244353;
//////////////// ncr ///////////////////////
int mul(int x, int y) {return (x * 1ll * y) % MOD;}
int binpow(int x, int y){
    int z = 1;
    while(y){
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}
int inv(int x) {return binpow(x, MOD - 2);}
int divide(int x, int y) {return mul(x, inv(y));}
int fact[N];
void precalc(){
    fact[0] = 1;
    for(int i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
}
int C(int n, int k)  {return divide(fact[n], mul(fact[k], fact[n - k]));}

/////////////// ncr  ///////////////////////


//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve(){
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) {
    	if (is_prime[i]) {
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int main()
{
	int n;
	cin>>n;
	ll x,y;
	vvl A;
    forn(i,0,n) {cin>>x>>y;A.pb({y,x});}
    SOT(A);
    ll s=0;
    forn(i,0,n){
        s+=A[i][1];
        if(s>A[i][0]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    
    
}	




Measured memory_bytes: 12588
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main(){
	IO_STREAM;
	int K;
	cin>>K;

	queue<ll> q;
	int cnt=0;
	ll ans=0;
	rep(i,1,10){
		q.push(i);
		cnt++;
		if(cnt==K){
			ans=i;
			goto OWARI;
		}
	}
	while(!q.empty()){
		ll v=q.front();q.pop();
		ll next;
		if(v%10!=0){
			next=v*10+v%10-1;
			q.push(next);
			cnt++;
			if(cnt==K){
				ans=next;
				goto OWARI;
			}
		}
		next=v*10+v%10;
		q.push(next);
		cnt++;
		if(cnt==K){
			ans=next;
			goto OWARI;
		}
		if(v%10!=9){
			next=v*10+v%10+1;
			q.push(next);
			cnt++;
			if(cnt==K){
				ans=next;
				goto OWARI;
			}
		}
	}
	DBG("","","","");
OWARI:
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,K,n,m=50;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) cin >> A.at(i);
  n=min(K,m);
  rep(i,n){
    vector<ll> dpr(N+1,0),dpl(N+1,0),dp(N,0);
    for(ll j=1;j<N;j++){
      if(A.at(j)-j>=0){
        dpr.at(N)++;
      }else{
        dpr.at(N+A.at(j)-j)++;
      }
    }
    for(ll j=1;j<N;j++){
      if(A.at(N-1-j)-j>=0){
        dpl.at(N)++;
      }else{
        dpl.at(N+A.at(N-1-j)-j)++;
      }
    }
    dp.at(0)+=dpr.at(N);
    dp.at(N-1)+=dpl.at(N);
    for(ll j=1;j<N;j++){
      dpr.at(N)+=dpr.at(N-j)-1;
      dp.at(j)+=dpr.at(N);
      dpl.at(N)+=dpl.at(N-j)-1;
      dp.at(N-1-j)+=dpl.at(N);
    }
    rep(j,N){
      A.at(j)=dp.at(j)+1;
    }
  }
  rep(i,N){
    cout << A.at(i) << " ";
  }
  cout << endl;
}


Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int a = (s[0] - '0') * 10 + (s[1] - '0');
	int b = (s[2] - '0') * 10 + (s[3] - '0');
	bool x = a <= 12 && a >= 1;
	bool y = b <= 12 && b >= 1;
	if (x && y)
		cout << "AMBIGUOUS" << endl;
	else if (x)
		cout << "MMYY" << endl;
	else if (y)
		cout << "YYMM" << endl;
	else
		cout << "NA" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll mod(ll a, ll b)
{
  if (a >= 0)
    return a % b;
  else
    return (b - (-a) % b) % b;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  ll n, k;
  cin >> n >> k;
  ll a[200010];
  rep(i, n) cin >> a[i];
  ll S[200010];
  S[0] = 0;
  rep(i, n) S[i + 1] = S[i] + a[i];
  unordered_map<ll, ll> mp;

  ll ans = 0;
  for (int i = 0; i <= n + k; i++)
  {
    //追加
    if (i <= n)
    {
      ans += mp[mod(S[i] - i, k)];
      mp[mod(S[i] - i, k)]++;
    }

    //破棄
    if (i + 1 - k >= 0)
    {
      mp[mod(S[i + 1 - k] - (i + 1 - k), k)]--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11592
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    cin >> N;
    veci S(N-1),C(N-1),F(N-1);
    REP(i,N-1) cin >> C[i] >> S[i] >> F[i];
    veci ans(N);
    for(int i = 0; i < N; i++) {
        int t = 0;
        for(int j = i; j < N-1; j++) {
            if(t < S[j]) t = S[j] + C[j];
            else if(t%F[j] == 0) t = t + C[j];
            else t = t+F[j]-(t%F[j]) + C[j];
        }
        cout << t << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,m,k,dp[4444][4444],ans,all;
void add(int &x,int y)
{
	x+=y;
	if (x>=mod) x-=mod;
}
bool check(int x,int y)
{
	return (x<=n && y<=m && (n-x)%(k-1)==0 && (m-y)%(k-1)==0);
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	all=(n+m-1)/(k-1);
	dp[0][0]=1;
	for (int i=0;i<all;i++)
	{
		for (int j=0;j<=n+m;j++)
		{
			if (!dp[i][j]) continue;
			for (int p=0;p<k;p++)
			{
				add(dp[i+1][j+p],dp[i][j]);
			}
		}
	}
	for (int i=0;i<all;i++)
	{
		for (int j=0;j<=n+m;j++)
		{
			for (int p=1;p<k;p++)
			{
				if (check((k-1)*i+k-j-p,j+p)) 
				{
					add(ans,dp[i][j]);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 68352
#include <stdio.h>
#include <stdlib.h>
#define MAXVAL  10000

int main(){

    long i, n;
    int *a, *b, c[MAXVAL];

    for( i=0; i<MAXVAL; i++ ) c[i] = 0;

    scanf( "%ld", &n );

    
    a = (int*)malloc(sizeof(int)*n);
    b = (int*)malloc(sizeof(int)*n);

    for( i=0; i<n; i++ ){
        scanf( "%d", &a[i] );
    }


    for( i=0; i<n; i++ ) c[ a[i] ]++;
    for( i=1; i<MAXVAL; i++ ) c[i] = c[i]+c[i-1];

    for( i=n-1; i>=0; i-- ){
        b[ c[a[i]]-1 ] = a[i];
        c[ a[i] ] = c[ a[i] ] - 1;
        //printf( " %ld: %d\n", i , a[i]);
        //for( j=0; j<40; j++ ) printf( "%d%c", c[j], ((40-1)>j)?' ':'\n');
    }

    for( i=0; i<n; i++ ) printf( "%d%c", b[i], ((n-1)>i)?' ':'\n');

    free(b);
    return 0;
}



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


def judge(a, v, b, w, t):
    return abs(b - a) <= t * (v - w)


def main():
    a, v = (int(z) for z in input().split())
    b, w = (int(z) for z in input().split())
    t = int(input())
    if judge(a, v, b, w, t):
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
  while ( u != NIL && k != u->key ) {
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

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

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

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

  if ( y == NIL ) {
    root = z;
  } else {
    if ( z->key < y->key )
      y->left = z;
    else
      y->right = z;
  }
}

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

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

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

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

  return 0;
}


Measured memory_bytes: 15780
-- fo "http://abc042.contest.atcoder.jp/tasks/arc058_a"

import Data.List
import Control.Applicative

main = do
  p <- getContents
  let n = read $ head $ words $ head $ lines p :: Int
      k = read $ last $ words $ head $ lines p :: Int
      d  =   map ( flip (!!) 0 ) $ words $last  $ lines p -- d !! i = D_i
      pre = [n..]
      result = ( find (myNotElem d )  pre )
      result' = (\(Just x) -> x) result
  putStr $  show result'


myNotElem :: [Char] -> Int -> Bool  
-- myNotElem  (s:st) n | s `notElem` n' = myNotElem st n
--                    | otherwise = False
--   where n' = show n
-- myNotElem [] _ = True

myNotElem st n = and $ map (flip notElem n') st                    
  where n' = show n

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  string T = "AKIHABARA";
  int N = T.size();
  bool ok = false;
  for (int i = 0; i < (1 << 4); i++){
    string T2;
    int cnt = 0;
    for (int j = 0; j < T.size(); j++){
      if (T[j] != 'A'){
        T2.push_back(T[j]);
      } else {
        if ((i >> cnt) & 1){
          T2.push_back(T[j]);
        }
        cnt++;
      }
    }
    if (S == T2){
      ok = true;
    }
  }
  if (ok){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;
const int N = 100010;
int n, a[N], st, now;
ll ans, p[N];

int main() {
	scanf("%d%d", &n, &st);
	rep(i, 1, n) scanf("%d%lld", &a[i], &p[i]);
	int l = 1, r = n;
	for(; l <= r;) {
		if(st < a[l] || (a[r] > st && p[l] >= p[r])) {
			if(now) ans += abs(a[r] - now); now = a[r];
			p[l] += p[r], --r;
		}
		else {
			if(now) ans += abs(now - a[l]); now = a[l];
			p[r] += p[l], ++l;
		}
	}
	ans += abs(now - st), printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn= new Scanner(System.in);
        int n = scn.nextInt();
        int a[]=new int[4];
        for(int i=0;i<4;i++){
            a[i]=0;
        }
        for(int i=0;i<n;i++){
            char buf = scn.next().charAt(0);
            switch(buf){
                case 'P':
                    a[0]++;
                    break;
                case 'W':
                    a[1]++;
                    break;
                case 'Y':
                    a[2]++;
                    break;
                case 'G':
                    a[3]++;
                    break;
            }
        }
        int cnt=0;
        for(int i=0;i<4;i++){
            if(a[i]>0)cnt++;
        }
        if(cnt==3){
          System.out.println("Three");
        }else{
          System.out.println("Four");
        }
    }
}

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

#define ll long long
#define MOD 1000000007

using namespace std;

int main() {
  ll N;
  cin >> N;
  string s;
  cin >> s;
  ll ans = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int num[5];
int main()
{
	memset(num,-1,sizeof(num));
	int n,m,i,x,y;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		if(num[x]!=-1&&num[x]!=y||x==1&&!y&&n!=1)
		{
			cout<<-1;
			return 0;
		}
		num[x]=y;
	}
	if(n==1&&num[1]==-1)
	{
		cout<<0;
		return 0;
	}
	if(num[1]==-1)
		cout<<1;
	else
		cout<<num[1];
	for(i=2;i<=n;i++)
		if(num[i]==-1)
			cout<<0;
		else
			cout<<num[i];
	return 0;
}

Measured memory_bytes: 256
import itertools
N = int(input())
S = [input() for _ in range(N)]
lis = []
for i in range(N):
    for j in ['M','A','R','C','H']:
        if S[i][0] == j:
            lis.append(j)

cnt = [lis.count('M'),lis.count('A'),lis.count('R'),lis.count('C'),lis.count('H')]
ans = 0
for a, b, c in itertools.combinations(cnt, 3):
    ans += a*b*c
print(ans)

Measured memory_bytes: 10540
#include<stdio.h>

int main(){
int N,f=0;
  int a[4];
  scanf("%d",&N);
  a[0]=N/1000;
  a[3]=N%10;
  a[2]=(N%100-a[3])/10;
  a[1]=(N%1000-a[2]*10-a[3])/100;
  for(int i=0;i<3;i++){
  if(a[i]==a[i+1]){
	f=1;
    break;
  }
  }
if(f==1)printf("Bad\n");
  else printf("Good\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007;
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)
        res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
       
        ll n,num;cin>>n;ll arr[n+1]={0};
        for(ll i=0;i<n-1;i++)cin>>num,arr[num]++;
        for(ll i=1;i<=n;i++)cout<<arr[i]<<endl;
}


Measured memory_bytes: 5216
S = input()
n = len(S)
childs = [0 for _ in range(n)]

# n += 1 if n%2 else 0
nr = 0
nl = 0
mode_R = True
last_L = None
for i in range(n):
    if mode_R:
        if S[i] == "R":
            nr += 1
        if S[i] == "L":
            nl += 1
            last_L = i
            mode_R = False
    else:
        if S[i] == "L":
            nl += 1
        if S[i] == "R":
            tmp = nr // 2 + nl // 2
            childs[last_L-1] = tmp + (1 if nr%2 else 0)
            childs[last_L] = tmp + (1 if nl%2 else 0)
            nr = 1
            nl = 0
            mode_R = True
tmp = nr // 2 + nl // 2
childs[last_L-1] = tmp + (1 if nr%2 else 0)
childs[last_L] = tmp + (1 if nl%2 else 0)
print(*childs)

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

using namespace std;

#pragma GCC optimize("O3")
static const auto __ = [] {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return nullptr;
}();

int solve(int A, int B, int C) {
  return min(B / A, C);
}

int main(int argc, char* argv[]) {
  int A, B, C;
  cin >> A >> B >> C;
  cout << solve(A, B, C) << '\n';
  return 0;
}


Measured memory_bytes: 256
n=int(input())
mx=1
for i in range(n-1):
  ans=[]
  for j in range(n-1-i):
    count=1
    tmp=(i)^(i+j+1)
    while tmp%2==0:
      count+=1
      tmp=tmp//2
    ans.append(str(count))
  print(' '.join(ans))

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

using namespace std;

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

typedef pair<int, int> P;
typedef pair<P, int> PP;

int N, M;
vector< vector<edge> > G;

const int inf = 1<<25;

int dijkstra()
{
  vector<int> mindist(N, inf);
  priority_queue<PP, vector<PP>, greater<PP> > que;
  que.push(PP(P(0, 0), 0));
  int ret = 0;
  while(!que.empty()) {
    PP p = que.top(); que.pop();
    int now = p.second, dist = p.first.first, cost = p.first.second;
    if(mindist[now] <= dist) continue;
    mindist[now] = dist;
    ret += cost;
    for(edge& e : G[now]) {
      if(mindist[e.to] >= dist + e.dist) {
	que.push(PP(P(dist + e.dist, e.cost), e.to));
      }
    }
  }
  return ret;
}

int main()
{
  while(cin >> N >> M, N || M) {
    G.clear(); G.resize(N);
    for(int i = 0; i < M; i++) {
      int u, v, d, c;
      cin >> u >> v >> d >> c;
      u--, v--;
      G[u].push_back(edge(v, d, c));
      G[v].push_back(edge(u, d, c));
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 4436
#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 pair<ll,ll> pll;

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 DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
ll modpow(ll a,ll b){
  ll r=1;
  while(b){
    if(b&1)r=r*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return r;
}

const int MX = 25212521;
// const int MX = 2521;

ll fact[MX];
ll ifact[MX];

int h,w,k;

// ll dp[252][252];

int main(){
  scanf("%d%d%d",&h,&w,&k);
  fact[0] = 1;
  FOR(i,1,MX)fact[i] = fact[i-1]*i%MOD;
  ifact[MX-1] = modpow(fact[MX-1], MOD-2);
  FORR(i,1,MX)ifact[i-1] = ifact[i]*i%MOD;
  ll ans = 0;
  // dp[0][0] = 0;
  // REP(x,h+1)REP(y,w+1){
  //   if(x==0 && y==0)continue;
  //   dp[x][y] = 0;
  //   if(x>0)dp[x][y] += dp[x-1][y];// + (x+1)*(y+1);
  //   if(y>0)dp[x][y] += dp[x][y-1];// + (x+1)*(y+1);
  //   dp[x][y] += fact[x+y] * ifact[x] % MOD * ifact[y] % MOD * (x+1) % MOD * (y+1) % MOD;
  //   dp[x][y] %= MOD;
  // }
  // REP(X,h+1)REP(Y,w+1){
  //   ll val = fact[X+Y+1] * ifact[X] % MOD * ifact[Y+2] % MOD;
  //   val = val * ifact[3] % MOD * (Y+1) % MOD * (Y+2) % MOD * (2*X*Y%MOD + 3*X + 3*Y + 6) % MOD;
  //   val = (val - 1ll*fact[X+Y]*ifact[X]%MOD*ifact[Y]%MOD + MOD) % MOD;
  //   if(val != dp[X][Y]){
  //     DEBUG(X); DEBUG(Y); DEBUG(dp[X][Y]); DEBUG(val);
  //     exit(0);
  //   }
  // }
  FOR(p,max(0,k-w),min(h,k)+1){
    ll X = p;
    ll Y = k-X;
    ll hPx = fact[h] * ifact[h-X] % MOD;
    ll wPy = fact[w] * ifact[w-Y] % MOD;
    // ll val = dp[X][Y];
    ll val = fact[X+Y+1] * ifact[X] % MOD * ifact[Y+2] % MOD;
    val = val * ifact[3] % MOD * (Y+1) % MOD * (Y+2) % MOD * (2*X*Y%MOD + 3*X + 3*Y + 6) % MOD;
    val = (val - 1ll*fact[X+Y]*ifact[X]%MOD*ifact[Y]%MOD + MOD) % MOD;
    ans += hPx * wPy % MOD * val % MOD;
    ans %= MOD;
  }
  // REP(i,11)REP(j,11)printf("%9lld%c",dp[i][j],j==10 ? '\n' : ' ');
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 394240
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int INFTY = 1001001001;

int main()
{
    int N, K, nd;
    cin >> N >> K;
    vector<int> D(K);
    for (int i = 0; i < K; ++i)
    {
        cin >> D[i];
    }

    string num;
    bool flag;
    for(int i=N; i<N*10;++i){
        num = to_string(i);
        flag = true;
        for(auto c : num){
            for(int i=0;i<K;++i){
                if(c - '0' == D[i]) flag = false;
            }
        }
        if(flag){
            break;
        }
    }
    cout << num << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int c=0;
            
            if(n == 0 && x == 0 )
                break;
            
            for(int i=1 ;i<=n;i++){
                for(int j= i+1 ;j<=n;j++){
                    for(int k= j+1 ;k<=n;k++){
                       if(i+j+k==x){
                       	 c++;
                    	}
                    }
                }
            }
            System.out.println(c);
        }
        sc.close();
    }
} 



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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int h,w,n;
    cin >> h >> w >> n;
    vector<int> a(n+1);
    for(int i = 1;i < n+1;i ++){
        cin >> a.at(i);
    }

    vector<vector<int>> ans(h,vector<int>(w));

    for(int i = 0;i < h ;i ++){
        for(int j = 0;j < w;j ++){

            int c;
            for(int k = 1;k < n+1;k ++){
                if(a.at(k) > 0){
                    c = k;
                    a.at(k) --;
                    break;
                }
            }

            if(i % 2 == 0){
                ans.at(i).at(j) = c;
            }else{
                ans.at(i).at(w-1 - j) = c;
            }
        }
    }

    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            cout << ans.at(i).at(j) << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  map<i64, i64> mp;
  rep(i,0,N) {
    cin >> A[i];
    mp[A[i]]++;
  }
  i64 Q;
  cin >> Q;
  i64 ans = 0;
  for(auto p: mp) {
    ans += p.first * p.second;
  }
  while(Q--) {
    i64 b, c;
    cin >> b >> c;
    i64 cnt = mp[b];
    ans -= b * cnt;
    mp[b] = 0;
    mp[c] += cnt;
    ans += c * cnt;
    cout << ans << endl;
  }
}



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

int main(void) {
    int i;

    int counts[26];
    for(i = 0; i < 26; i ++)
        counts[i] = 0;

    char s[100000];
    scanf("%s", s);

    for(i = 0; i < strlen(s); i ++)
        counts[(int)(s[i] - 'a')] ++;

    for(i = 0; i < 26; i ++) {
        if(counts[i] == 0) {
            printf("%c\n", i + 'a');
            return 0;
        }
    }

    printf("None\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

bool Y[10];
ll P[100][11];
int F[100][11];
int z = 0;
int N;
ll maxProfit = -1000000000;
void calculate(bool Y[10])
{
	int both[100];
	for (int i = 0; i < 100; i++)
	{
		both[i] = 0;
	}

	ll profit = 0;
	for (int n = 0; n < N; n++)
	{
		ll both = 0;
		for (int i = 0; i < 10; i++)
		{
			if (Y[i] == true && F[n][i + 1] == true)
			{
				both++;
			}
		}

		profit += P[n][both];
	}

	maxProfit = max(maxProfit, profit);
}

void dfs(int index, bool Y[10])
{
	if (index == 10)
	{
		//All Close case of josino store
		bool isOpen = false;
		for (int i = 0; i < 10; i++)
		{
			isOpen |= Y[i];
		}
		if (!isOpen)
		{
			return;
		}
		calculate(Y);
		//z++;
		//cout << z << " " << endl;
		//for (int i = 0; i < 10; i++)
		//{
		//	cout << Y[i] << " ";
		//}
		//cout << endl;
		return;
	}

	index++;
	Y[index] = true;
	dfs(index, Y);
	Y[index] = false;
	dfs(index, Y);
}
int main()
{
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		for (int j = 1; j <= 10; j++)
		{
			cin >> F[i][j];
		}
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j <= 10; j++)
		{
			cin >> P[i][j];
		}
	}
	Y[0] = true;
	dfs(0, Y);
	Y[0] = false;
	dfs(0, Y);

	cout << maxProfit << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
list($w) = strs();
for ($i = 0; $i < strlen($w); ++$i) {
    if (isset($c[$w[$i]])) $c[$w[$i]]++;
    else $c[$w[$i]] = 1;
}
foreach ($c as $v) if ($v % 2) exit('No');
echo 'Yes';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


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

int main() {
        int N;
        int count = 0;
        string S;
        cin >> S;
        cin >> N;
        vector<string> R(N);

        rep(n, N) {
                cin >> R.at(n);
                R.at(n) += R.at(n);
        }
        for (auto RS : R) {
                if (RS.find(S) != string::npos) {
                        count++;
                }
        }
        cout << count << endl;
        return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
 
/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/ 
 
int sc1() {int x; scanf("%d", &x); return x;}
 
long long sc2() {long long x; scanf("%lld", &x); return x;}
 
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
 
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}
 

 
 
int solve() {
 
	ll h,n;
	cin>>h>>n;
	ll sum=0;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		sum+=x;
	}
	if(sum>=h) puts("Yes");
	else puts("No");
 
	return 0;
}
 
 
 
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int a,b,c;
	while(cin>>s,s!="#"){
		cin>>a>>b>>c;
		if(a>31||(a==31&&b>4))cout<<"?",a-=30;
		else cout<<s;
		cout<<' '<<a<<' '<<b<<' '<<c<<endl;
	}
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main(){
    int N,Q;
    while(scanf("%d%d",&N,&Q),(N|Q)){
        int s[128]={0};
        int length = 0;
        rep(i,N){
            int c;
            scanf("%d",&c);
            rep(j,c){
                int t;
                scanf("%d",&t);
                s[t]++;
                length = max(length,t);
            }
        }
        length++;
        int ans = 0;
        int index = 0;
        rep(i,length){
            if(s[i]>=Q && ans < s[i]){
                ans = s[i];
                index = i;
            }
        }
        printf("%d\n",index);
    }
    return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
using ll=long long;

int main(void){
  int N;
  string  S;
   cin >> N >> S;
  vector<int> number(26);
  for(int i=0;i<26;i++) {
    number.at(i)++;
  }
  
  for(int i=0;i<N;i++){
    if(S.at(i)=='a') number.at(0)++;
    if(S.at(i)=='b') number.at(1)++;  
    if(S.at(i)=='c') number.at(2)++;
    if(S.at(i)=='d') number.at(3)++;
    if(S.at(i)=='e') number.at(4)++;  
    if(S.at(i)=='f') number.at(5)++;
    if(S.at(i)=='g') number.at(6)++;
    if(S.at(i)=='h') number.at(7)++;  
    if(S.at(i)=='i') number.at(8)++;
    if(S.at(i)=='j') number.at(9)++;
    if(S.at(i)=='k') number.at(10)++;  
    if(S.at(i)=='l') number.at(11)++;
    if(S.at(i)=='m') number.at(12)++;
    if(S.at(i)=='n') number.at(13)++;  
    if(S.at(i)=='o') number.at(14)++;
    if(S.at(i)=='p') number.at(15)++;
    if(S.at(i)=='q') number.at(16)++;  
    if(S.at(i)=='r') number.at(17)++;
    if(S.at(i)=='s') number.at(18)++;
    if(S.at(i)=='t') number.at(19)++;  
    if(S.at(i)=='u') number.at(20)++;
    if(S.at(i)=='v') number.at(21)++;
    if(S.at(i)=='w') number.at(22)++;  
    if(S.at(i)=='x') number.at(23)++;
    if(S.at(i)=='y') number.at(24)++;
    if(S.at(i)=='z') number.at(25)++;
  }
  ll ans=1LL;
   for(int i=0;i<26;i++) {
     ans=(ans*number.at(i))%1000000007;
   }
  cout << ans-1 << endl; 
}


Measured memory_bytes: 512
def main():
	n = int(input())

	plan = [[0,0,0]]
	for i in range(n):
		plan.append(list(map(int, input().split())))

	for i in range(len(plan)-1):
		delta_t = plan[i+1][0] - plan[i][0]
		delta_x = plan[i+1][1] - plan[i][1]
		delta_y = plan[i+1][2] - plan[i][2]

		if (delta_t < (delta_x + delta_y)) or ((delta_t - (delta_x + delta_y)) % 2 != 0):
			print("No")
			return

	print("Yes")
	return

if __name__ == '__main__':
	main()

Measured memory_bytes: 27380
a = int(input())
b = [int(input())for _ in range(a)]
c = 0
d = 1
while True:
    if b[d-1] == 2:
        c += 1
        break
    elif c > a:
        print(-1)
        exit()
    else:
        d = b[d-1]
        c += 1
print(c)


Measured memory_bytes: 7340
s = Array.new(1001,  0)
1.upto(500) do |i|
    sum = i
    (i+1).upto(500) do |j|
        sum += j
        break if sum > 1000
        s[sum] += 1
    end
end
loop do
    n = gets.to_i
    break if n == 0
    puts s[n]
end

Measured memory_bytes: 6084
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, y;
	cin >> n >> y;
	int a = -1, b = -1, c = -1;
	int tmp = y/1000-n;
	for (int ta = 0; ta <= tmp / 9; ta++) {
		int t = tmp - 9 * ta;
		if (t < 0) break;
		if (t % 4 == 0) {
			int tb = t / 4;
			int tc = n - ta - tb;
			if (tc >= 0) {
				a = ta;
				b = tb;
				c = tc;
				break;
			}
		}
	}
	printf("%d %d %d\n", a, b, c);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long n,a,b;
	cin>>n>>a>>b;
	cout<<n/(a+b)*a+min(n%(a+b),a)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int p, q, r;
  std::cin >> p >> q >> r;

  if (p < q) {
    if (q < r) std::cout << p + q << std::endl;
    else std::cout << p + r << std::endl;
  } else {
    if (p < r) std::cout << p + q << std::endl;
    else std::cout << q + r << std::endl;
  } 
}

Measured memory_bytes: 256