akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;
int siz[MAX];//錬結成分のサイズ
int par[MAX];//親
int Rank[MAX];//木の深さ

int N, K;
int dp[101][100010];
int sdp[100010];
int num[100010];

void solve() {
	cin >> N >> K;
	int iter = 0;
	for (int i = 1; i <= N;) {
		int j = N / i;
		if (i <= j)num[iter++] = 1, i++;
		else num[iter++] = N / j - i + 1, i = N / j + 1;
	}
	dp[0][0] = 1;
	for (int k = 0; k < K; k++) {
		memset(sdp, 0, sizeof(sdp));
		for (int j = 0; j <= iter; j++)sdp[j + 1] = sdp[j] + dp[k][j], sdp[j + 1] %= MOD;
		for (int j = 0; j < iter; j++)dp[k + 1][j] = sdp[iter - j] * num[j] % MOD, dp[k + 1][j] %= MOD;

	}
	ll res = 0;
	for (int j = 0; j <= iter; j++)res+= dp[K][j], res %= MOD;
	print(res);
}


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

	solve();
}




Measured memory_bytes: 81408
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) (int)(x).size()
using namespace std;

#define N 207

int n, res;

int a[N];

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

	n *= 2;

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

	sort(a, a+n);

	for(int i = 0; i < n; i += 2)
		res += a[i];

	cout << res;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long K, long long S) {
  ll ans1 = 0;
  ll ans3 = 0;
  ll ans6 = 0;
  REP(x, K + 1) {
    FOR(y, x, K + 1) {
      FOR(z, y, K + 1) {
        if (S == x + y + z) {
          if (x == y && y == z) {
            ans1++;
          } else if (x == y || z == y || x == z) {
            // cout << x << " " << y << " " << z << endl;
            ans3++;
          } else {
            ans6++;
          }
        }
      }
    }
  }

  cout << ans1 + ans3 * 3 + ans6 * 6 << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long K;
  long long S;
  cin >> K;
  cin >> S;
  solve(K, S);
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, a, b := intScanner(), intScanner(), intScanner()
	fmt.Println(smaller(n*a, b))
}


Measured memory_bytes: 1772
#include<stdio.h>
#define N 1000001
typedef struct
{
  char name[10];
  int time;
} P;//structure of process
P p[N];
int top=0,bottom;//points for queue
void enqueue(P);
void dequeue();
int main(void)
{
  int i;//counter
  int q;//quantum
  int sum=0;//sum of time
  scanf("%d%d",&bottom,&q);
  for(i=0;i<bottom;i++) scanf("%s%d",p[i].name,&p[i].time);
  while(top!=bottom)
    {
      if(p[top].time>q)
	{
	  sum+=q;
	  p[top].time-=q;
	  enqueue(p[top]);
	  dequeue();
	}
      else
	{
	  sum+=p[top].time;
	  printf("%s %d\n",p[top].name,sum);
	  dequeue();
	}
    }
  return 0;
}
void enqueue(P enp)
{
  p[bottom]=enp;
  bottom++;
  if(bottom>=N) bottom=0;
}
void dequeue(void)
{
  top++;
  if(top>=N) top=0;
}




Measured memory_bytes: 4696
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int a[100] = {0}; // the sums of columns                                                                                                                                
  for (int i = 0; i < r; ++i) {
    int s = 0;
    int x;
    for (int j = 0; j < c; ++j) {
      cin >> x;
      s += x;
      a[j] += x;
      printf("%d ", x);
    }
    a[c] += s;
    printf("%d\n", s);
  }
  for (int j = 0; j <= c; ++j) {
    if (j > 0)
      printf(" ");
    printf("%d", a[j]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9+7

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n;

    cin >> n;

    vector<int> a(n);

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

    vector<int> b(n);

    int idx = n/2,r = n-1,l = 0,j = 0;

    for(int i = n-1;i >= 0;i--)
    {
        if(j%2==0){ b[l] = a[i]; l++; }
        else{ b[r] = a[i]; r--; }
        j++;
    }

    for(int i = 0;i < n;i++) cout << b[i] << ' ';

}


Measured memory_bytes: 3712
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
inline bool 
operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
vector<int> 
string_to_vector_int(const string& input){vector<int> out(input.length());rep(i,input.length()){out[i] = (int)(input[i]-'0');} return out;}
template<class T> map<T,int> 
count_same_elements(const vector<T>& v){map<T,int>cmap; for_each(cmap.begin(),cmap.end(),[&cmap](T x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A,class B> vector<B> 
tryple_map(const vector<A>& v,const function<B(A,A,A)>& func){vector<B> v_(v.size()-2);rep(i,v.size()-2){ v_[i]=func(v[i+2],v[i+1],v[i]); }return v_;}
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const B& (*func)(A)){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,B (*func)(A,A)){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A,class B> vector<B> 
tryple_map(const vector<A>& v,B (*func)(A,A,A)){vector<B> v_(v.size()-2);rep(i,v.size()-2){ v_[i]=func(v[i+2],v[i+1],v[i]); }return v_;}

int twosame(int a,int b){return a==b;}
int tryple_same(int a,int b,int c){return a==b and b==c;}
int integer_sumnation(int a,int b){return a+b;}

ll a,b,c,d,x;
vector<ll>v;
string s;
void input(){
    cin>>s;
    s.shrink_to_fit();
}
void src(){
    auto f=tryple_map(string_to_vector_int(s),(*tryple_same));
    cout<< (ALL(accumulate,f,0)>0? "Yes":"No");
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
  int N,T,A,i,j,k;
  double temp;
  j=0;
  int H[1000]={};
  if(scanf("%d",&N)>1){
    exit(0);
  }
  if(scanf("%d%d",&T,&A)>2){
    exit(0);
  }
  for(i=0;i<N;i++){
    if(scanf("%d",&H[i])>1){
    exit(0);
  }
  }
  temp=fabs(T-H[0]*0.006-A);
  k=0;
  for(j=1;j<N;j++){
    if(temp>fabs(T-H[j]*0.006-A)){
        temp=fabs(T-H[j]*0.006-A);
  k=j;
    }
  }
  printf("%d",k+1);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl "\n"
#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cout<<#x<<" : {"<<x<<"}"<<endl;
#endif
using namespace std;
typedef long long int lli;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	vector<int> dp(n+1);
	for(int i=1; i<=100; ++i){
		for(int j=1; j<=100; ++j){
			for(int k=1; k<=100; ++k){
				int res = (i+j)*(i+j) + (j+k)*(j+k) + (k+i)*(k+i);
				if(res & 1 || res/2 > n) break;
				res /= 2;
				dp[res]++;
			}
		}
	}
	for(int i=1; i<=n; ++i)
		cout << dp[i] << endl;
	return 0;
}


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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s; cin >> s;

  s[3] = '8';
  cout << s << endl;
  
  return (0);
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

void svtr(vector<int> &a){
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
}

int main() {
  int a,p;
  cin >> a >> p;
  cout << (a*3+p)/2 << endl;
  return 0;
}


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

int main() {
  int N,L;
  cin >> N >> L;
  vector<string> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<N;i++){
    cout << vec.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main()
	{
		int a,b;
		string[] s=Console.ReadLine().Split(' ');
		a=int.Parse(s[0]);
		b=int.Parse(s[1]);
		Console.WriteLine(Math.Max(a+b,Math.Max(a-b,a*b)));
	}
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 998244353;

lnt fact[210000], invfact[210000];

lnt invmod(lnt a, lnt p){ // a^-1 mod p
	lnt b = p, u = 1, v = 0;
	while(b){
		lnt t = a / b;
		a -= t*b; swap(a, b);
		u -= t*v; swap(u, v);
	}
	u %= p;
	if(u < 0) u += p;
	return u;
}

void factmod(lnt m){
	fact[0] = invfact[0] = 1;
	for(lnt i = 1; i < 210000; i++){
		fact[i] = (fact[i-1] * i) % m;
		invfact[i] = (invfact[i-1] * invmod(i, m)) % m;
	}
}

lnt nCrmod(lnt n, lnt r, lnt m){
	return (((fact[n] * invfact[r]) % m) * invfact[n-r]) % m;
}

lnt powmod(lnt a, lnt p, lnt m){
	lnt res = 1, tmp = a;
	while(p != 0){
		if(p % 2) res = (res*tmp) % m;
		tmp = (tmp*tmp) % m;
		p /= 2;
	}
	return res;
}

int main(){
	summon_tourist;

	lnt N, M, K; cin >> N >> M >> K;
	lnt ans = 0;
	factmod(MOD);
	REP(i, K+1){
		lnt block = N-i;
		lnt plus = nCrmod(N-1, i, MOD);
		plus *= M; plus %= MOD;
		plus *= powmod(M-1, block-1, MOD); plus %= MOD;
		ans += plus;
		ans %= MOD;
	}
	cout << ans << ln;
}

Measured memory_bytes: 6944
import sys

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

n,m=intinput()
a = list(intinput())
a = [(a[x],1) for x in range(n)]
for i in range(m):
    b,c=intinput()
    a.append((c,b))
a.sort(reverse=1)
res,cnt=0,n
for (x,y) in a:
    k = min(cnt,y)
    res += k*x
    cnt -= k
print(res)

Measured memory_bytes: 27580
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = long.Parse(ReadLine());
        if (N<10)
        {
            WriteLine(N);
            return;
        }
        long max = CalcDigitSum(N);
        long tmp = 10;
        while (tmp <= N)
        {
            var val = CalcDigitSum(N - (N % tmp + 1));//n > m*10^p -1を満たす最大のm*10^p - 1の値
            if (val > max) max = val;
            tmp *= 10;
        }
        WriteLine(max);
    }
    static long CalcDigitSum(long num)
    {
        long res = 0;
        foreach (var item in num.ToString())
        {
            res += long.Parse(item.ToString());
        }
        return res;
    }
}

Measured memory_bytes: 11092
N = int(input())
a=0
cnt = 0
num = N
while 10<=num:
  num/=10;a+=1
if a%2==0:
  for i in range(10**a,N+1):
    cnt += 1
if 4 < a:
  print(cnt + 90909)
elif 2 < a:
  print(cnt + 909)
elif 0 < a:
  print(cnt + 9)
else:
  print(cnt)

Measured memory_bytes: 3064
n, m = map(int, input().split())

a = [False]*n
b = [False]*n
for i in range(m):
    left, right = map(int, input().split())
    if left == 1:
        b[right-1] = True
    if right == n:
        a[left-1] = True

ans = 'IMPOSSIBLE'
for i in range(n):
    if a[i] == True and b[i] == True:
        ans = 'POSSIBLE'
print(ans)


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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int pos_one;
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    if (A.at(i) == 1) pos_one = i;
  }
  int num_left = 0, num_right = 0;
  num_left = (pos_one) / (K-1);
  if (pos_one % (K-1) != 0) num_left++;
  num_right = (N-1-num_left*(K-1)) / (K-1);
  if ((N-1-num_left*(K-1)) % (K-1) != 0 && N-1-num_left*(K-1) > 0) num_right++;
  cout << num_left + num_right << endl;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

using pii = pair<int, int>;

int n;
vec<pii> c;

signed main() {
	cin >> n;
	rep (i, n) {
		int s, t;
		cin >> s >> t;
		c.push_back({s, t});
	}
	sort(all(c), [&](pii a, pii b) {
		return a.second < b.second;
	});

	int t = 0;
	rep (i,  n) {
		int num = c[i].first;
		t += num;
		if (t > c[i].second) {
			puts("No");
			return 0;
		}
	}

	puts("Yes");
	return 0;

	return 0;
}

Measured memory_bytes: 6256
using System;
class Program {
    static void Main() {
        int i = 1;
        while (true) {
            string str = Console.ReadLine();

            if(str == null || str == "0") {
                break;
            }
            else {
                Console.WriteLine("Case {0}: {1}", i, int.Parse(str));
            }

            i++;
        }
    }
}

Measured memory_bytes: 9312
#include<iostream>
#include<queue>
using namespace std;
signed main(){
    int n,m;
    queue<int> que[15];    //制約でレーンの数が10以下となっているから。
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        if(a==0){
            cout<<que[b].front()<<'\n';
            que[b].pop();
        }else{
            int minp=1;
            for(int j=2;j<=n;j++){
                if(que[j].size()<que[minp].size()){
                    minp=j;
                }
            }
            que[minp].push(b);
        }
    }
    return(0);
}


Measured memory_bytes: 3184
N = int(input())
S = input()

d = {'R':[],'G':[],'B':[]}
for i,c in enumerate(S):
    d[c].append(i)
ld = set(d['B'])

ans = 0
for si in d['R']:
    for sj in d['G']:
        tmp = len(ld)
        if max(si,sj) + abs(si-sj) in ld:
            tmp -= 1
        if min(si,sj) - abs(si-sj) in ld:
            tmp -= 1
        if min(si,sj) + abs(si-sj)/2 in ld:
            tmp -= 1
        ans += tmp

print(ans)

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

#define int long long

const int N = 1e5 + 10;
int n, ans = 1, ar[N], l[N], r[N];

int gcd(int a, int b) {
	return !b? a: gcd(b, a % b);
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	
	for (int i = 1; i <= n; i++)
		l[i] = gcd(l[i - 1], ar[i - 1]);
	for (int i = n - 2; i >= 0; i--)
		r[i] = gcd(r[i + 1], ar[i + 1]);
	
	for (int i = 0; i < n; i++)
		ans = max(ans, gcd(l[i], r[i]));
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",a-b+1);
    return 0;
}

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

typedef vector<int> vec;
typedef vector<vec> mat;//[y][x] == [行][列]
typedef long long ll;
int N,M,A,B,C,T;

void view(const mat& a ){
  cout << "view mat" << endl;
  for(int i=0;i<a.size();i++){
    for(int j=0;j<(int)a[i].size();j++){
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}


int mult(int a,int b,int mod){
  ll x,y,z;
  x = a; y = b; z = mod;
  x = ( x * y ) % z;
  return(int)x;
}

mat matrixmult( const mat &a, const mat &b ,int mod){
  mat ret( a.size(),vec(b[0].size(),0) );
  for(int i=0;i<a.size();i++){
    for(int j=0;j<b[0].size();j++){
      int x = 0;
      for(int k=0;k<min(a[0].size(),b.size());k++){
        x += mult(a[i][k] ,b[k][j], mod);
        x %= mod;
      }
      ret[i][j] = x;
    }
  }
  return ret;
}

mat powm(mat a,mat b,int t){
  //  view(a);
  //view(b);
  while(t>0){
    if( t & 1 ){
      a = matrixmult(a,b,M);
    }
    b = matrixmult(b,b,M);
    t>>=1;
    //view(a);
    // view(b);
  }
  return a;
}


int main(){
  while( cin >> N >>M >>A >> B >> C >> T && (N|M|A|B|C|T) ){
    mat s( 1, vec(N,0) );
    for(int i=0;i<N;i++){
      cin >> s[0][i];
    }
    mat b(N,vec(N,0));
    for(int i=0;i<N;i++){
      if( i-1 >= 0 ) b[i-1][i] = A;
      b[i][i] = B;
      if( i+1 < N ) b[i+1][i] = C;
    }

    mat res = powm(s,b,T);

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

Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#define rep(j, n) for (int i = j; i < n; i++)
#define repd(j, n) for (int i = j; i > n; i--)
#define ll long long
using namespace std;

int main() {
	string ans = "NO";
	int road[4];
	rep(0, 4) {
		road[i] = 0;
	}
	rep(0, 6) {
		int a;
		cin >> a;
		road[a-1] += 1;
	}
	for(int i=0;i<4;i++){
		for (int k = 0; k < 4; k++) {
			if (road[i] == 2&&road[k] == 2) {
				ans = "YES";
			}
			
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

const long long MOD = 1000000007;

void solve(long long N){
  N--;
  ll hb = 0;
  ll h0 = 1;
  ll h9 = 1;
  ll hn = 8;
  for(;N-->0;) {
    tie(hb, h0, h9, hn) = make_tuple(
        (((10*hb % MOD) + h0 + h9) % MOD),
        (1*hn+9*h0)% MOD,
        (1*hn+9*h9)% MOD,
        (8 * hn) % MOD);

  }
  cout << hb << endl;
}

int main() {
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}


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


typedef long long lli;
typedef unsigned long ul;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
#define rep(i,n) for(lli i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i,n) for(lli i=1, i##_len=(n); i<i##_len; ++i)
#define rrep(i,x) for(lli i=((n)-1); i>=0; --i)
#define rreps(i,x) for(lli i=((n)); i>0; --i)
#define REP(i,n) for(lli i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(lli i=1, i##_len=(n); i<i##_len; ++i)
#define RREP(i,x) for(lli i=((n)-1); i>=0; --i)
#define RREPS(i,x) for(lli i=((n)); i>0; --i)
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define FT first
#define SD second
#define y0 y348
#define y1 y348
#define next asdnext
#define prev asdprev
#define all(a) (a).begin(),(a).end()
#define eps pow(10,-7)
#define SZ(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))

lli gcd(lli a,lli b){return b?gcd(b,a%b):a;}
lli dx[4]={1,0,-1,0};
lli dy[4]={0,1,0,-1};

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


int main(){
  lli N,I;

  cin >> N>>I;

  cout << N-I+1 << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  while (n--) {
    vi32 v(10); cin >> v;
    bool ans = false;
    rep(i, bit(10)) {
      stack<int> a, b;
      bool f = true;
      rep(j, 10) {
        stack<int> *x;
        if (i & bit(j)) x = &a; else x = &b;
        if (x->size() == 0) x->push(v[j]);
        else {
          if (x->top() > v[j]) f = false;
          else x->push(v[j]);
        }
      }
      if (f) {
        ans = true;
        break;
      }
    }
    if (ans) cout << "YES" << '\n';
    else cout << "NO" << '\n';
  }
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(x) begin(x), end(x)
 
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
 
const int MAXN = 55;
int n;
int x[MAXN], y[MAXN];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
 
    map<pii, int> freq;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        for (int j = 0; j < i; ++j) {
            int dx = x[i] - x[j];
            int dy = y[i] - y[j];
            ++freq[{dx, dy}];
            ++freq[{-dx, -dy}];
        }
    }
 
    int ans = n;
    for (auto it : freq) {
        ans = min(ans, n - it.second);
    }
 
    cout << ans << '\n';
 
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
#define MAX_N 200001
int counter[MAX_N] = {0};
bool visit[MAX_N] = {false};
vector<vector<int>> tree(MAX_N, vector<int>(1, 0));

void dfs(int v){
  int i;
  int now, next;
  for(i=1; i<tree[v].size(); i++){
    now = v; next = tree[v][i];
    //cout << "now, next " << now << ", " << next << endl; 
    if(visit[next] == false){
      counter[next] += counter[now];
      visit[next] = true;
      dfs(next);
    }
  }
}


int main(void){
  int N, Q;
  cin >> N >> Q;
  int i;

  //木の作成
  int s, g;
  for(i=1; i<=N-1; i++){
    cin >> s >> g; 
    tree[s].push_back(g);
    tree[g].push_back(s);
  }

  //カウンターの初期化
  int p, x;
  for(i=1; i<=Q; i++){
    cin >> p >> x;
    counter[p] += x;
  }

  visit[1] = true;
  dfs(1);

  for(i=1; i<=N; i++)
    cout<< counter[i] << " ";
  cout << endl;

  
  return 0;
}


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

using namespace std;

const int MAX = 1e4 + 9;
int digit[11] = {2, 5, 5, 4, 5, 6, 3, 7, 6}, dp[MAX], n, m;
vector<pair<int, int>> stick;

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	if (a.first < b.first) {
		return true;
	} else {
		if (a.first == b.first) {
			if (a.second > b.second) return true;
			return false;
		}
		return false;
	}
}

void print_dp() {
	for (int i = 0; i <= n; i++) {
		cout << dp[i] << ' ';
		int n;
		cin >> n;
	}
}

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

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a; 
		stick.push_back(make_pair(digit[a-1], a));
	}
	dp[0] = 1;
	for (int i = 0; i <= n; i++) {
		for (auto p : stick) {
			if (i - p.first < 0) continue;
			if (dp[i - p.first] > 0) dp[i] = max(dp[i], dp[i - p.first] + 1);
			//print_dp();
		}
	}
	int len = dp[n];
	string s;
	while (n) {
		vector<int> tmp;
		for (auto p : stick) {
			if (n - p.first < 0) continue;
			if (dp[n - p.first] == len - 1) {
				tmp.push_back(p.second);
			}
		}
		sort(tmp.begin(), tmp.end());
		reverse(tmp.begin(), tmp.end());
		s.push_back(tmp[0] + '0');
		n -= digit[tmp[0] - 1];
		len--;
	}
	cout << s << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N,X,DATA[3][100]={0},ka[3]={0},sum=0;
	cin>>N;
	int data[N+1]={0};
	for (int A=0;A<3;A++){
		cin>>ka[A];
		for (int B=0;B<ka[A];B++) cin>>DATA[A][B];
	}
	for (int A=0;A<ka[2];A++){
		sum=0;
		for (int B=0;B<ka[0];B++){
			if (DATA[2][A]==DATA[0][B]) sum++;
		}
		if (sum==0) data[DATA[2][A]]=1;
	}
	sum=0;
	for (int A=0;A<ka[1];A++){
		sum=0;
		for (int B=0;B<ka[2];B++){
			if (DATA[2][B]==DATA[1][A])sum++;
		}
		if (sum!=0) data[DATA[1][A]]=1;
	}
	sum=0;
	for (int A=1;A<=N;A++){
		if (data[A]==1) sum++;
	}
	cout<<sum<<endl;
	return 0;
}
			


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>



int main(){
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int arr[n], cost[n]={0};
    for (int i = 0 ; i < n ; ++i)
        cin >> arr[i];
    cost[0] = 0;
    cost[1] = abs(arr[1]-arr[0]);
    for (int i = 2 ; i < n ; ++i)
        cost[i] = min(cost[i-1]+abs(arr[i]-arr[i-1]), cost[i-2]+abs(arr[i]-arr[i-2]));
    cout << cost[n-1];
    return 0;
}


Measured memory_bytes: 1024
N = int(input())


def f(x):
    c = 0
    for i in range(1, int(x**.5)+1):
        if x%i==0:
            c += 1 if i*i==x else 2
    return c

c = 0
for i in range(1, N+1, 2):
    if f(i)==8:
        c += 1

print(c)

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

int main() {
  ll k, q; cin >> k >> q;
  vector<ll> d(k);
  for (int i = 0; i < k; ++i) cin >> d[i];
  
  while (q--) {
    ll n, x, m; cin >> n >> x >> m;
    ll xmod = x % m;
    vector<ll> dmod(k);
    ll sum = 0, cnt0 = 0;
    for (int i = 0; i < k; ++i) {
      dmod[i] = d[i] % m;
      sum += dmod[i];
      if (dmod[i] == 0) ++cnt0;
    }
    
    int p = (n-1) / k;
    int q = (n-1) % k;
    sum *= p; sum += xmod;
    cnt0 *= p;
    
    for (int i = 0; i < q; ++i) {
      sum += dmod[i];
      if (dmod[i] == 0) ++cnt0;
    }
    
    cout << n-1 - (sum/m + cnt0) << endl;
  }
}

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

string s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	int n = s.length() - 1;
	if (n % 2) n--;
	while (s.substr(0, n / 2).compare(s.substr(n / 2, n / 2)) != 0) n -= 2;
	cout << n;
}

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

int main(){

  while(1){
    int a, b;
    string op;
    cin >> a >> op >> b;
    if(op == "?") break;
    
    int ans;
    if(op == "+") ans = a + b;
    if(op == "-") ans = a - b;
    if(op == "*") ans = a * b;
    if(op == "/") ans = a / b;

    cout<<ans<<endl;
   }

   return 0;
}


Measured memory_bytes: 3108
#include <iostream>
using namespace std;
#define ll long long

const ll inf = 1LL << 50;

int N,M;
int a[2000], b[2000];
ll c[2000];



int solve(){
	ll dist[N];
	for(int i=0;i<N;i++){
		dist[i]=inf;
	}
	dist[0]=0;

	for(int loop=0;loop<N-1;loop++){
		for(int i=0;i<M;i++){
			if(dist[a[i]]==inf) continue;

			if(dist[b[i]] > dist[a[i]]+c[i]){
				dist[b[i]] = dist[a[i]] + c[i];
			}
		}
	}
	ll ans = dist[N-1];

	bool neg[N];
	for(int i=0;i<N;i++){
		neg[i] = false;
	}

	for(int loop=0;loop<N;loop++){
		for(int i=0;i<M;i++){
			if(dist[a[i]]==inf) continue;

			if(dist[b[i]] > dist[a[i]]+c[i]){
				dist[b[i]] = dist[a[i]] + c[i];
				neg[b[i]] = true;
			}

			if(neg[a[i]]) neg[b[i]] = true;
		}
	}

	if(neg[N-1]) cout << "inf" << endl;
	else cout << -ans << endl;

	return 0;
}

int main(){
	cin >> N >> M;

	for(int i=0;i<M;i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		c[i] = -c[i];
	}
	solve();
	return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    ll N; cin >> N;
    const ll n = sqrt(N)+1;
    int ans = 11;
    FOR(A, 1, n) {
        if(N % A != 0) continue;
        ll B = N / A;
        int cnt = 1;
        rep(i, 11) {
            if(B < 10) break;
            B /= 10;
            cnt++;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector <int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    
    vector <int> Alice(N);
    vector <int> Bob(N);
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            Alice.push_back(vec.at(i));
            
        }else {
            Bob.push_back(vec.at(i));
        }
    }
    int awa = 0;
    for (int i = 0; i < Alice.size(); i++) {
        awa += Alice.at(i);
    }
    int bwa = 0;
    for (int i = 0; i < Bob.size(); i++) {
        bwa += Bob.at(i);
    }
    cout << awa - bwa << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    int N;
    vector<ll> A;
    void input() {
        cin >> N;
        A.resize(N + 1);
        REP(i, N + 1) { cin >> A[i]; }
    }
    void output() {
        if (N == 0) {
            cout << (A[0] == 1 ? 1 : -1) << endl;
            return;
        }
        if (A[0] > 0) {
            cout << -1 << endl;
            return;
        }
        vector<ll> mn(N + 1), mx(N + 1);
        mn[N] = mx[N] = A[N];
        REPR(i, N) {
            mn[i] = (mn[i + 1] + 1) / 2 + A[i];
            mx[i] = mx[i + 1] + A[i];
        }
        mn[0] = mx[0] = 1;
        REP(i, N) {
            mn[i + 1] = max(mn[i + 1], mn[i] - A[i]);
            mx[i + 1] = min(mx[i + 1], 2 * (mx[i] - A[i]));
            if (mn[i + 1] > mx[i + 1]) {
                cout << -1 << endl;
                return;
            }
        }
        ll res = 0;
        REP(i, N + 1) { res += mx[i]; }
        cout << res << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


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

int d, w;
vector<vector<int>> e;

int solve(int sx, int sy, int tx, int ty) {
    int rake = 10;
    int sum = 0;
    for (int i = sx; i <= tx; ++i) {
        for (int j = sy; j <= ty; ++j) {
            if (i == sx || i == tx || j == sy || j == ty) {
                rake = min(rake, e[i][j]);
            }
        }
    }
    for (int i = sx + 1; i < tx; ++i) {
        for (int j = sy + 1; j < ty; ++j) {
            if (e[i][j] >= rake) return 0;
            sum += rake - e[i][j];
        }
    }
    return sum;
}

int main(void) {
    while (cin >> d >> w, d) {
        e = vector<vector<int>>(d, vector<int>(w));
        for (int i = 0; i < d; ++i) {
            for (int j = 0; j < w; ++j) cin >> e[i][j];
        }
        int ans = 0;
        for (int sx = 0; sx < d; ++sx) {
            for (int sy = 0; sy < w; ++sy) {
                for (int tx = sx + 2; tx < d; ++tx) {
                    for (int ty = sy + 2; ty < w; ++ty) ans = max(ans, solve(sx, sy, tx, ty)); 
                }
            }
        }
        cout << ans << endl;
    }
}



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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m, a, b;
  cin >> n >> m;
  vector<ii> dias(n);
  for (int i = 0; i < n; i++) {
    cin >> dias[i].fi >> dias[i].se;
  }
  sort(all(dias));
  int i = 0;
  priority_queue<int> pq;
  int ans = 0;
  for (int dia = 1; dia <= m; dia++) {
    while ((i < dias.size()) && (dias[i].fi <= dia)) {
      pq.push(dias[i].se);
      i++;
    }
    if (pq.size()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << ende;
  return 0;}


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

int main(){
    int PW , PH , W , H , x , y , r;
    cin >> W >> H >> x >> y >> r;
    PW = W - r;
    PH = H - r;
    if ( PH >= y && y >= r && PW >= x && x >= r ){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3112
#include <vector>
#include <iostream>
#include <string>
#include <climits>

class M{
  int left, right;
  int cnt;
public:
  M(int l = 0, int r = 0, int c = 0):left(l),right(r),cnt(c){}
  const bool is_init(){return left != 0;}
  int get_l(){return left;}
  int get_r(){return right;}
  int get_c(){return cnt;}
  void show(){std::cout << "[ " << left << "," << cnt << "," << right << " ]";}
  M operator+(M &other){
	  M res(left, other.get_r(), cnt + other.get_c() + left * right * other.get_r());
    return res;
  }
  bool operator>(M &other){
	  return cnt > other.get_c();
  }
};
void show_line(int line){
  std::cout << "start dp line " << line << std::endl;
}
void show_all(std::vector<M> &vec){
  for (auto i = vec.begin(); i != vec.end(); ++i){
    i->show();
    std::cout << "-";
  }
  std::cout << std::endl;
}
M Max(0, 0, INT_MAX);
int dp(std::vector<std::vector<M>> memo){
  if (memo.back().size() != 1){
  	std::vector<M> vec;
  	const int n = memo[0].size() - memo.size();
  	for (auto i = 0; i < n; ++i){
      M min = Max;
  		for (auto j = 0; j < memo.size(); ++j){
  			M temp = memo.at(j).at(i) + memo.at(memo.size() - j - 1).at(i + j + 1);
  			if (min > temp){
  				min = temp;
  			}
  		}
  		vec.push_back(min);
  	}
  	memo.push_back(vec);
  	return dp(memo);
	}else{
    return memo.back().back().get_c();
  }
}
int main(){
  int n;
  std::vector<M> v;
  std::cin >> n;
  for (auto i = 0; i < n; ++i){
	  int a, b;
	  std::cin >> a >> b;
	  v.push_back(M(a, b));
  }
  std::vector<std::vector<M>> memo;
  memo.push_back(v);
  std::cout << dp(memo) << std::endl;
  return 0;

}

Measured memory_bytes: 5216
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a, b;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    if (n % 2)
    {
        for (int i = 0; i < m; i++)
        {
            cout << i + 1 << " " << n - i << "\n";
        }
    }
    else{
        int j=0;
        int cur=n/2;
        int count=0;
        int d=0;
        bool c=false;
        int dd=0;
        rep(i,m){
            if(count%2){
                cout<<2+dd<<" "<<n-dd<<"\n";
                dd++;
                count++;
            }
            else{
                cout<<cur-d<<" "<<cur+1+d<<"\n";
                d++;
                count++;
            }
        }
    }
}


Measured memory_bytes: 3696
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            s = 500 * a + 100 * b + 50 * c
            ans += X == s
print(ans)


Measured memory_bytes: 7116
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		while(t-->0)
		{
			int n=in.nextInt();
			int k=in.nextInt();
			int a[]=new int[n];
			int d[]=new int[n-1];
			int c=0;
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			for(int i=0;i<n-1;i++)
				d[i]=a[i+1]-a[i];
			Arrays.sort(d);
			for(int i=0;i<d.length-k+1;i++)
				c+=d[i];
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 114144
count = 0
coins =[10,50,100,500]
while 1:
    price = int(input())
    if price ==0:break
    if count !=0:print('')
    wallet= list(map(int,input().split(' ')))
    cash = wallet[0]* 10 + wallet[1] * 50 + wallet[2] * 100 + wallet[3] * 500
    charge = cash - price
    chargecoins = ((charge % 50) // 10,(charge % 100)//50,(charge % 500)//100,charge // 500)
    for  i in range(4):
        if wallet[i] > chargecoins[i]:print('{} {}'.format(coins[i],wallet[i]-chargecoins[i]))
    count +=1


Measured memory_bytes: 5616