akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

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; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

bool is_prime[1000010];


int main() {
    int n,ans = 0;
    cin >> n;
    vector<int> x(n),l(n);
    vector<pair<int,int>> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> l[i];
        p[i].first = x[i]+l[i];
        p[i].second = x[i]-l[i];
    }
    sort(p.begin(),p.end());
    int migihasi = 0;
    for (int i = 0; i < n; ++i) {
        if(i == 0) {
            ans++;
            migihasi = p[i].first;
        }else if(migihasi <= p[i].second){
            ans++;
            migihasi = p[i].first;
        }else continue;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4768
h = int(input())
d = {}

def caracal(h):
    if h in d.keys():
        return d[h]
    else:
        if h == 1:
            d[h] = 1
            return d[h]
        else:
            d[h] = 2 * caracal(h // 2) + 1
            return d[h]

print(caracal(h))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	private void rect(){
		Scanner scanner = new Scanner(System.in);
		
		while(scanner.hasNextInt()){
			int h =scanner.nextInt();
			int w =scanner.nextInt();
			if(h==0 && w==0)break;
			
			if(h<=300 && w<=300){
				for(int i=0; i<h; i++){
					for(int j=1; j<w; j++){
						System.out.printf("#");
					}
					System.out.println("#");
				}
				System.out.println("");
				
			}
			
		}
	}
	
	public static void main(String[] args) {
		Main run =new Main();
		run.rect();

	}
}

Measured memory_bytes: 42884
import math

def solve(a,n):
  dp = [0]*(n)
  dp[0]=0
  for i in range(1,n):
    op1 = abs(a[i]-a[i-1])+dp[i-1]
    if i==1:
    	op2 = 1000000000
     
    else:
    	op2 = abs(a[i]-a[i-2])+dp[i-2]
    dp[i]=min(op1,op2)
  #print(dp)
  return dp[n-1]
n=int(input())
a=list(map(int,input().split()))
dp = [0]*10**5
print(solve(a,n))


Measured memory_bytes: 14356
N,C=map(int, input().split())
D=[tuple(map(int, input().split())) for _ in range(C)]
c = [[0 for i in range(C)] for j in range(3)]
for j in range(N):
    i=0
    for v in list(map(int, input().split())):
        c[(i+j)%3][v-1] += 1
        i += 1

ans = float("inf")
for i in range(C):
    for j in range(C):
        if i!=j:
            for k in range(C):
                if i!=k and j!=k:
                    tmp = 0
                    for l in range(C):
                        tmp+=D[l][i]*c[0][l]
                    for l in range(C):
                        tmp+=D[l][j]*c[1][l]
                    for l in range(C):
                        tmp+=D[l][k]*c[2][l]
                    if tmp<ans:
                        ans=tmp

print(ans)

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

vector<vector<int>> V;
vector<int> vis;
int a, b;

void dfs(int f){
	if(vis[f]) return;
	vis[f] = 1;
	for(int t:V[f]) if(f!=a || t!=b) dfs(t);
}

int main(){
	int N, M; cin>>N>>M;
	V.resize(N);
	vis.resize(N);
	vector<pair<int,int>> E;
	for(int i=0; i<M; ++i){
		cin>>a>>b; --a, --b;
		E.emplace_back(a, b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	int ans = 0;
	for(auto [u,v]:E){
		a = u, b = v;
		for(auto& x:vis) x = 0;
		dfs(u);
		if(!vis[v]) ans++;
	}
	cout<< ans <<endl;
}


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

int main(){
  int N,flag=0;char last[11];
  scanf("%d",&N);
  char word[N][11];
  for(int i=0;i<N;i++) scanf("%s",&word[i]);

  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(strcmp(word[i],word[j])==0){
        flag=1;
        break;
      }
    }
      if(word[i][strlen(word[i])-1]!=word[i+1][0]){
        flag=1;
        break;
      }
  }
  if(flag==1)printf("No");
  else printf("Yes");
}


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

int main(){
  vector<char> s(10);
  for(int i=0;i<10;i++){
    cin >> s.at(i);
  }
  
    if(s.at(6)=='4'||s.at(6)=='3'){
      cout << "Heisei" << endl;
    }else if(s.at(6)=='2' && s.at(5)=='0'||s.at(6)=='1' && s.at(5)=='0'){
      cout << "Heisei" << endl;
    }else{
      cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  ll ans=1000;
  for(int i=0;i<n-1;i++){
    if(a.at(i)<a.at(i+1)){
      ans=ans%a.at(i)+(ans/a.at(i))*a.at(i+1);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n-1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}
	for i := 0; i < n-1; i++ {
		fmt.Scan(&c[i])
	}
	ans := 0
	ans += b[a[0]-1]
	for i := 1; i < n; i++ {
		ans += b[a[i]-1]
		if a[i]-a[i-1] == 1 {
			ans += c[a[i-1]-1]
		}
	}
	fmt.Println(ans)
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

//ａをbで割る
long long mod_div(long long a,long long b){
	if(a % b == 0)return a/b;
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}
 
#define MAX_K 333333
vector<long long> kaijo(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(kaijo[0] != 1){
		kaijo[0] = 1;
		for(long long i = 1;i < MAX_K;i++)kaijo[i] = (kaijo[i-1] * i) % MOD;
	}
    long long ret = kaijo[n];
	long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
    return mod_div(ret,tmp);
}

ll mpow(ll a,ll b){
	ll ret = 1;
	ll tmp = a;
	for(ll i = 0;i <= 60;i++){
		if(b & (1LL << i)){
			ret *= tmp;
			ret %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ret;
}

ll dp[1111][1111];

int main(){
	
	ll n,a,b,c,d;cin >> n >> a >> b >> c >> d;
	dp[0][0] = 1;
	
		
	REP(i,b+1){
		REP(j,n+1)if(dp[i][j]){
			dp[i+1][j] += dp[i][j];
			dp[i+1][j] %= MOD;
			if(i < a)continue;
			ll kake = 1;
			for(ll k = 1;k <= d;k++){
				ll tmp = i * k;
				if(j + tmp > n)break;
				kake = (kake * combination(n-j-tmp+i,i)) % MOD;
				kake = mod_div(kake, k);
				if(k < c)continue;
				dp[i+1][j+tmp] += (dp[i][j] * kake) % MOD;
				dp[i+1][j+tmp] %= MOD;
			}
		}
	}
	
	
	cout << dp[b+1][n] << endl;
	
	return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int N; cin>>N;
    vector<ll> cnt(5,0ll);
    string name;
    for (int i = 0; i < N; ++i) {
        cin>>name;
        char n=name[0];
        if(n=='M') cnt[0]++;
        else if(n=='A') cnt[1]++;
        else if(n=='R') cnt[2]++;
        else if(n=='C') cnt[3]++;
        else if(n=='H') cnt[4]++;
    }

    ll ans=0ll;
    for (int i = 0; i < 5; ++i) {
        for (int j = i+1; j < 5; ++j) {
            for (int k = j+1; k < 5; ++k) {
                ans+=1ll*cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    cout<<ans<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
    cin>>a>>b>>k;
    if (k<a)
        cout<<a-k<<' '<<b;
    else
    {
        cout<<0<<' ';
        if ((k-a)>b)
            cout<<0;
        else
            cout<<b-(k-a);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, double> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };

int main() {

	vector<int> c(3);
	rep(i, 3) cin >> c.at(i);

	sort(c.begin(), c.end());

	int a = c.at(0) + c.at(1);

	if (a == c.at(2)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int n,ans=0;
  string str;
  string cmp = "ABC";
  cin >> n >> str;
  rep(i,0,n-cmp.size()+1) {
    string tmp = str.substr(i,cmp.size());
    if(tmp == cmp) ans++;
  }
  printf("%d\n",ans);
  return 0;
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

long count_p(long X,int L, long* num, long* P, long tmp){
    long ans;
    if(L==0) ans=tmp+P[0];
    else{
        if(X==1) ans=tmp+0;
        else if(X==num[L]/2+1) ans=tmp+P[L-1]+1;
        else if(X==num[L]) ans=tmp+P[L];

        else if(X<(num[L]/2+1)){
            ans=count_p(X-1,L-1,num,P,tmp+0);
        }
        else{
            ans=count_p(X-num[L-1]-2,L-1,num,P,tmp+P[L-1]+1);
        }
    }

    return ans;
}

int main(void){
    int N;
    long X;
    scanf("%d%ld",&N,&X);

    //num[i]...レベルiバーガーが何枚か
    //P[i]...レベルiバーガーが何枚のパティがあるのか
    long num[N+1];
    long P[N+1];
    num[0]=P[0]=1;
    for(int i=1;i<=N;i++){
        num[i]=2*num[i-1]+3;
        P[i]=2*P[i-1]+1;
    }

    long ans=0;
    ans=count_p(X,N,num,P,ans);

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

    return 0;
}

//0 P
//1 B0P0B
//2 B1P1B = B B0P0B P B0P0B B
//3 B2P2B = B B B0P0B P B0P0B B P B B0P0B P B0P0B B B
//4 B B B B0P0B P B0P0B B P B B0P0B P B0P0B B B P B B B0P0B P B0P0B B P B B0P0B P B0P0B B B B

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

int main(void) {
	int n;
	cin >> n;
	string s[50];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}

	int exist;
	int flag[50];
	char c = 'a';
	char ans[50];
	int anslen = 0;

	for (int i = 0; i < 26; i++) {
		int exmin = 50;
		for (int k = 0; k < n; k++){
			exist = 0;
			for (int j = 0; j < (int)(s[k].length()); j++) {
				if (s[k][j] == c) {
					exist++;
				}
			}
			if (exmin > exist) exmin = exist;
		}
		if (exmin > 0) {
			for (int t = 0; t < exmin; t++) {
				ans[anslen] = c;
				anslen++;
			}
		}
		c++;
	}
	for (int i = 0; i < anslen; i++) {
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <tuple>
#include <string>

size_t constexpr m1 = -1;
size_t constexpr di[] = {m1, m1, m1, 0, 0, 1, 1, 1};
size_t constexpr dj[] = {m1, 0, 1, m1, 1, m1, 0, 1};

using zahyo = std::pair<size_t, size_t>;

bool nyan(std::vector<std::string>& s, std::queue<zahyo>& q) {
  size_t h = s.size();
  size_t w = s[0].length();
  std::queue<zahyo> r;
  bool res = false;
  while (!q.empty()) {
    size_t i, j;
    std::tie(i, j) = q.front();
    q.pop();
    for (size_t k = 0; k < 8; ++k) {
      size_t ni = i + di[k];
      size_t nj = j + dj[k];
      if (!(ni < h && nj < w)) continue;
      if (s[ni][nj] == '.') continue;
      if (--s[ni][nj] == '0') {
        s[ni][nj] = '.';
        res = true;
        r.emplace(ni, nj);
      }
    }
  }
  q = r;
  return res;
}

int main() {
  size_t h, w;
  scanf("%zu %zu", &h, &w);

  std::vector<std::string> s(h);
  std::queue<zahyo> q;
  for (size_t i = 0; i < h; ++i) {
    char buf[1024];
    scanf("%s", buf);
    s[i] = buf;
    for (size_t j = 0; j < w; ++j) {
      if (s[i][j] == '.') q.emplace(i, j);
    }
  }

  // for (auto const& si: s)
  //   fprintf(stderr, "%s\n", si.c_str());
  // fprintf(stderr, "---\n");
  int res = 0;
  while (nyan(s, q)) {
    ++res;
    // for (auto const& si: s)
    //   fprintf(stderr, "%s\n", si.c_str());
    // fprintf(stderr, "---\n");
  }

  printf("%d\n", res);
}



Measured memory_bytes: 4124
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n = II()
    ans = []
    sosu = [2]
    i = 2
    while len(ans) != n:
        for k in sosu:
            if i % k == 0:
                i += 1
                break
        else:
            sosu.append(i)
            if i % 5 == 1:
                ans.append(i)
            i += 1
    for i in ans:
        print(i, end=" ")
    print()
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()


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

struct combination {
    combination(ll Nmax, ll mod){
        (this -> MOD) = mod;
        (this -> Nmax) = Nmax;
        factorial.resize(Nmax+1, 1);
        inverse_factorial.resize(Nmax+1, 1);
        init_factorial();
    }

    ll calc(ll n, ll r){
        if(r < 0 || r > n) return 0;
        ll ret = (factorial[n]*inverse_factorial[r])%MOD;
        ret = (ret*inverse_factorial[n-r])%MOD;
        return ret;
    }

    private:
        ll MOD, Nmax;
        vector<ll> factorial;
        vector<ll> inverse_factorial;
        ll mod_pow(ll n, ll p, ll mod){
            n %= mod;
            if(p==0) return 1;
            ll res = mod_pow(n*n%mod, p/2, mod);
            if(p%2==1) res = res * n % mod;
            return res;
        }

        void init_factorial(){
            for(ll i=1; i<=Nmax; i++){
                factorial[i] = (factorial[i-1] * i)%MOD;
            }
            inverse_factorial[Nmax] = mod_pow(factorial[Nmax], MOD-2, MOD);
            for(ll i=Nmax-1; i>=1; i--){
                inverse_factorial[i] = (inverse_factorial[i+1]*(i+1))%MOD;
            }
        }
};

int main(){
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll mod = 1e9+7;
    combination comb(r2+c2+10, mod);

    ll ans = 0;
    for(int r = r1; r<=r2; r++){
        ans += comb.calc(r + c2 + 1, r + 1);
        ans -= comb.calc(r + c1, r + 1);
        while(ans < 0) ans += mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 31488
/*=================================
# Created time: 2018-12-15 20:02
# Filename: a.cpp
# Description: 
=================================*/
#include <bits/stdc++.h> 
 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define lb lower_bound 
#define ub upper_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x) 
#define pii pair<int, int> 
#define ls(a,b) (((a)+(b)) << 1) 
#define rs(a,b) (((a)+(b)) >> 1) 
#define fin(a) freopen(a,"r",stdin); 
#define fout(a) freopen(a,"w",stdout); 
#define FORP(i,a,b) for(int i=(a);i<=(b);i++) 
#define FORM(i,a,b) for(int i=(a);i>=(b);i--) 
 
#define maxn 100005 
#define maxm 100005 
#define MOD 1000000007 
#define INF 1070000000 
using namespace std; 
typedef long long ll; 
typedef unsigned long long ull; 
 
template<class T> inline   
void read(T& num){   
    num = 0; bool f = 1;char ch = getchar();   
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}   
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}   
    num = f ? num: -num;   
}  
template<class T> inline 
void write(T x,char ch){ 
	int s[100]; 
	if (x==0) {putchar('0'); putchar(ch); return;} 
	if (x<0) {putchar('-'); x=-x;} int num=0; 
	while (x){ s[num++]=(x%10); x=x/10;} 
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch); 
} 
/*==================split line==================*/ 
const double pi = acos(-1); 
const double eps = 1e-8; 
char s[200005]; 
int main(){ 
	int len; scanf("%s",s);
	len = strlen(s);
	int sum = 0;
	ll ans = 0;
	FORM(i, len - 1, 0){
		if (s[i] == 'B') ans += sum;
		else sum ++;
	}	
	write(ans,'\n');
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  __int64_t Anum,Bnum,maxi;
  cin >> Anum >> Bnum >> maxi;
  __int64_t nowminu,nowAbook,nowBbook;
  __int64_t ans = 0;
  vector<__int64_t> Abook(Anum);
  vector<__int64_t> Bbook(Bnum);
  for(int i = 0;i < Anum;i++){
    cin >> Abook[i];
    nowminu = nowminu + Abook[i];
  }
  for(int i = 0;i < Bnum;i++){
    cin >> Bbook[i];
  }
  nowAbook = Anum;
  nowBbook = 0;
  for(int i =  0;i <= Anum;i++){
    while(nowminu <= maxi){
      if(ans < nowAbook+nowBbook){
        ans = nowAbook+nowBbook;
      }
      if(nowBbook < Bnum){
        nowminu = nowminu + Bbook[nowBbook];
        nowBbook++;
      }else{
        break;
      }
    }
    if(Anum-1-i>=0){
      nowminu = nowminu - Abook[Anum-1-i];
      nowAbook--;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6372
#include <stdio.h>

int main() {
	int A,B,N;
	char a[256];

	fgets(a, 256, stdin);
	sscanf(a, "%d %d %d", &N, &A, &B);
	
	if (A*N < B) {
		printf("%d\n", A*N);
	}
	else if(A*N > B) {
		printf("%d\n", B);
	}
	else{
		printf("%d\n", B);
	}
}

Measured memory_bytes: 128
#include<stdio.h>
int table[1000];
int move[1000];
int main(){
	int a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(a+b==0)return 0;
		for(int i=0;i<a;i++){
			scanf("%d",table+i);
		}
		for(int i=0;i<b;i++)scanf("%d",move+i);
		int now=0;
		for(int i=0;i<b;i++){
			now+=move[i];
			now+=table[now];
			if(now>=a-1){
				printf("%d\n",i+1);
				break;
			}
		}
	}
}

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

using namespace std;
string s;
int main()
{
	cin>>s;
	for(int cur=s.size();cur;)
		if(cur>=5&&s.substr(cur-5,5)=="erase") cur-=5;
		else if(cur>=5&&s.substr(cur-5,5)=="dream") cur-=5;
		else if(cur>=6&&s.substr(cur-6,6)=="eraser") cur-=6;	
		else if(cur>=7&&s.substr(cur-7,7)=="dreamer") cur-=7;
		else return puts("NO"),0;
	puts("YES");
	return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n+1);
  cin>>a;

  if(a[0]==1&&accumulate(begin(a)+1,end(a),0ll)==0){
    cout<<1<<endl;
    return 0;
  }
  else if(a[0]>=1){
    cout<<"-1"<<endl;
    return 0;
  }

  vector<ll> sum(n+2);
  rep(i,n+1)sum[i+1]=sum[i]+a[i];

  ll ans = 1;
  ll base = 1;
  for(int i=1;i<=n;++i){
    ll tmp = INF;
    if(a[i]>base*2){
      cout<<"-1"<<endl;
      return 0;
    }
    chmin(tmp,base*2);
    chmin(tmp,sum.back()-sum[i]);
    dump(i,tmp,base,tmp-a[i]);
    base = tmp-a[i];
    ans += tmp;
  }
  cout<<(ans)<<endl;

}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int s;
  cin >> s;
  const int MAX = 1000010;
  vector<int> a(MAX, -1);
  int val = s;
  a[s] = 1;
  FOR(i, 1, MAX){
    if (val % 2 == 0) val = val/2;
    else val = 3 * val + 1;
    if (a[val] == -1){
      a[val] = 1;
    }
    else{
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 7208
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//236
	double n;
	cin>>n;
	double mi = LONG_MAX;
	REP(i,1,5){
		double val;
		cin>>val;
		mi=min(mi,val);
	}
	if(n<=mi)cout<<5;
	else printf("%lld",(ll)ceil(n/mi)+4);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3868
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

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

    deque<long long> ans;
    for(int i = 0; i < n; i++){
        if(i % 2 == (n-1) % 2){
            ans.push_front(a[i]);
        }else{
            ans.push_back(a[i]);
        }
    }

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


    return 0;
}

Measured memory_bytes: 5376
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int n = sc.nextInt();
 
        Map<Long, Long> map = new HashMap<>();
        for (int i = 1; i <= n; ++i) {
            map = d(i, map);
        }
        long ans = 1;
        for (Map.Entry<Long, Long> entry : map.entrySet()) {
            ans *= entry.getValue() + 1;
            ans %= 1_000_000_007;
        }
        _out.println(ans % 1_000_000_007);
    }
    private Map<Long, Long> d(long n, Map<Long, Long> map) {
        for (long i = 2; i <= n; ++i) {
            if (n % i == 0) {
                long cnt = 0;
                while (n % i == 0) {
                    n /= i;
                    ++cnt;
                }
                Long l = map.get(i);
                if (l == null) {
                    map.put(i, cnt);
                } else {
                    map.put(i, cnt + l);
                }
            }
        }
        return map;
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 24276
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
using namespace std;

typedef pair<int,int> pii;

const int MAXN = 1e5 + 5;
const int MAXM= 2e5 + 5;
const int INF=0x3f3f3f3f;

struct Edge
{
	int v, w, next;
	Edge(int v = 0, int w = 0, int next = -1) :v(v), w(w), next(next) {}
}edge[MAXM<<5];

struct Node
{
	int u, dis;
	bool operator<(const Node&p)const
	{
		return dis > p.dis;
	}
};

int head[MAXN<<5], edgetot;
int cnt,dis[MAXN<<5];
map<pii, int> mp;

void addEdge(int u, int v, int w)
{
	edge[edgetot] = Edge(v, w, head[u]);
	head[u] = edgetot++;
	edge[edgetot] = Edge(u, w, head[v]);
	head[v] = edgetot++;
}

void dijs(int s)
{
    for(int i=0;i<=cnt;i++)
        dis[i]=INF;
	priority_queue<Node> q;
	q.push({ s,0 });
	dis[s]=0;
	while (!q.empty())
	{
		Node u = q.top();
		q.pop();
		for (int i = head[u.u]; i != -1; i = edge[i].next)
		{
			int v = edge[i].v;
			if(dis[v] > u.dis+edge[i].w)
            {
                dis[v] = u.dis+edge[i].w;
                q.push({ v,dis[v] });
            }
		}
	}
}

int findId(pii p)
{
    if(mp.count(p)) return mp[p];
    return mp[p]=++cnt;
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
    mp.clear();
    memset(head, -1, sizeof(head));
    edgetot = 0,cnt=n;
    for (int i = 1; i <= m; i++)
    {
        int p, q, c;
        scanf("%d%d%d", &p, &q, &c);
        int u=findId(make_pair(p,c));
        int v=findId(make_pair(q,c));
        addEdge(p, u, 1);
        addEdge(u,v,0);
        addEdge(v, q, 1);
    }
    dijs(1);
    if (dis[n] == INF) printf("-1\n");
    else printf("%d\n", dis[n]/2);
	return 0;
}


Measured memory_bytes: 116092
import Data.List ( sort )
import qualified Data.Vector.Unboxed as U

import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

getParm
  :: IO [Int]
getParm = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,x] <- getParm
  as    <- getParm
  print $ f n x as

f :: Int -> Int -> [Int] -> Int
f n x as
  | t < x     = n-1
  | k <= n    = k   
  | otherwise = 0
  where
    ai = U.head as'
    t = sum as

    lengthUpto x = U.length . U.takeWhile (<= x) 
    k = lengthUpto x sums
    sums = U.scanl1 (+) as'
    as' = U.fromList $ sort as

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    ll n,k,a[BIG],ans;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>n >>k;
    for (int i=0; i<n; i++) {
        cin >>a[i];
    }
    sort(a , a+n);
    for (int i=0; i<k; i++)
        ans += a[i];
    cout <<ans;



    return 0;
}


Measured memory_bytes: 3592
from sys import stdin
import itertools

H, W, K = map(int, input().split())
table = []

all = 0  # 黒の総計
row = [0] * H  # 各行の黒の数
column = [0] * W  # 各列の黒の数

for i in range(H):
    h_i = list(stdin.readline()[:-1])
    table.append(h_i)
    row[i] = h_i.count("#")
    all += row[i]

for j in range(W):
    for i in range(H):
        column[j] += table[i][j] == "#"

# print(row)
# print(column)

ans = 0
for x in range(H):  # 赤く塗る行の数
    for rs in itertools.combinations(range(H), x):  # 赤く塗る行の組み合わせ
        for y in range(W):  # 赤く塗る列の数
            for cs in itertools.combinations(range(W), y):  # 赤く塗る列の組み合わせ
                # print(f"row: {list(rs)}, colums: {list(cs)}", end=" ")
                painted = 0  # 塗られた黒の数
                for i in rs:
                    painted += row[i]
                for j in cs:
                    painted += column[j]
                for i in rs:
                    for j in cs:
                        painted -= table[i][j] == "#"  # 行と列の分を引き、重なったところが黒なら二重で引かないようにする
                if all - painted == K:
                    ans += 1

print(ans)


Measured memory_bytes: 9020
n,q=map(int,input().split())
s=input()

a = [0] * n
num = 0

for i in range(1, n):
    if s[i]=='C' and s[i-1]=='A':
        num += 1

    a[i] = num
for _ in range(q):
  l,r=map(int,input().split())
  print(a[r-1] - a[l-1])

Measured memory_bytes: 7748
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 18:06:22 2019

@author: reira
"""

S = input()
r = 0
l = 0
flag = 0
Ans = [0] * len(S)
for i in range(0, len(S)):
    if  flag == 0:
        if S[i] == "R":
            r += 1
        elif S[i] == "L":
            l += 1
            flag = 1
            r_place = i-1
            if i == len(S)-1:
                if (r+l)%2 == 0:
                    Ans[r_place] = int((r+l)/2)
                    Ans[r_place+1] = int((r+l)/2)
                elif l%2 == 0:
                    Ans[r_place] = int(((r+l)+1)/2)
                    Ans[r_place+1] = int(((r+l)-1)/2)
                else:
                    Ans[r_place] = int(((r+l)-1)/2)
                    Ans[r_place+1] = int(((r+l)+1)/2)
    elif flag == 1:
        if S[i] == "R":
            flag = 0
            if (r+l)%2 == 0:
                Ans[r_place] = int((r+l)/2)
                Ans[r_place+1] = int((r+l)/2)
            elif l%2 == 0:
                Ans[r_place] = int(((r+l)+1)/2)
                Ans[r_place+1] = int(((r+l)-1)/2)
            else:
                Ans[r_place] = int(((r+l)-1)/2)
                Ans[r_place+1] = int(((r+l)+1)/2)
            r = 1
            l = 0
        elif S[i] == "L":
            l += 1
            if i == len(S)-1:
                if (r+l)%2 == 0:
                    Ans[r_place] = int((r+l)/2)
                    Ans[r_place+1] = int((r+l)/2)
                elif l%2 == 0:
                    Ans[r_place] = int(((r+l)+1)/2)
                    Ans[r_place+1] = int(((r+l)-1)/2)
                else:
                    Ans[r_place] = int(((r+l)-1)/2)
                    Ans[r_place+1] = int(((r+l)+1)/2)

print(' '.join(map(str, Ans)))


Measured memory_bytes: 10612
#include<stdio.h>
int main(void){
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(w<x+r || h<y+r || 0>x-r ||0>y-r){
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}

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

using namespace std;

#define N 8
#define FREE -1
#define NOT_FREE 1

bool X[N][N];
int row[N], col[N];
int lowerLeft[N * 2 - 1], lowerRight[N * 2 - 1];

void init() {
	for (int i = 0; i < N; ++i) {
		row[i] = col[i] = FREE;
	}
	for (int i = 0; i < N * 2 - 1; ++i) {
		lowerLeft[i] = lowerRight[i] = FREE;
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			X[i][j] = false;
		}
	}
}

void printBoard() {
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (X[i][j] && row[i] != j)
				return;
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (row[i] == j)
				cout << "Q";
			else
				cout << ".";
		}
		cout << endl;
	}
}

void backTrack(int i) {
	if (i == N) {
		printBoard();
		return;
	}

	for (int j = 0; j < N; ++j) {
		if (col[j] == NOT_FREE || lowerLeft[i + j] == NOT_FREE || lowerRight[i - j + N - 1] == NOT_FREE)
			continue;
		row[i] = j;
		col[j] = lowerLeft[i + j] = lowerRight[i - j + N - 1] = NOT_FREE;
		backTrack(i + 1);
		row[i] = col[j] = lowerLeft[i + j] = lowerRight[i - j + N - 1] = FREE;
	}
}

int main() {

	init();

	int k;
	scanf("%d", &k);
	for (int i = 0; i < k; ++i) {
		int r, c;
		scanf("%d %d", &r, &c);
		X[r][c] = true;
	}
	backTrack(0);

	return 0;
}

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

typedef long long ll;

int main(){
    
    int N, K;
    cin >> N >> K;
    
    ll x[N], y[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    
    ll xM, xm, yM, ym;
    int cnt;
    ll S, ans = 4e18;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                for(int l=0; l<N; l++){
                    xM = max(x[i],x[j]);
                    xm = min(x[i],x[j]);
                    yM = max(y[k],y[k]);
                    ym = min(y[l],y[l]);
                    cnt = 0;
                    for(int m=0; m<N; m++){
                        if(xm<=x[m] && x[m]<=xM && ym<=y[m] & y[m]<=yM) cnt++;
                    }
                    S = 1LL * (xM-xm) * (yM-ym);
                    if(cnt>=K && S>0){
                        ans = min(ans, S);
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
    
}


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

int main() {
    long long n;cin>>n;
    long long ma=INT_MIN,sum=0;
    for(int i=0;i<n;i++)
    {
        long long x;cin>>x;
        ma=max(ma,x);
        sum+=ma-x;
    }
    cout<<sum;
	return 0;
}

Measured memory_bytes: 3584
//#define _LIBCPP_DEBUG 0
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define acc(v) accumulate(v.begin(), v.end(),0);
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> test(n);
  rep(i,n) {
    int a;
    cin >> a;
    rep(j,a) {
      int x, y;
      cin >> x >> y;
      x--;
      test[i].emplace_back(x,y);
    }
  }
  int res = -1;
  for(int bit = 0; bit < (1 << n); bit++) {
    bool ok = true;
    int cnt = 0;
    bitset<15> b(bit);
    rep(i,n) {
      if((bit >> i) & 1) {
        cnt++;
        for(auto p : test[i]) { if(b[p.fi] != p.se) ok = false; }
      }
    }
    if(ok) res = max(res, cnt);
  }
  cout << res << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int x = e*a;
		int y = 0;
		if(c<e){
			y=b+(e-c)*d;
		}else{
			y=b;
		}
		if(y<x) System.out.println(y);
		else System.out.println(x);
	}
}

Measured memory_bytes: 17348
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n, m;
	cin >> n >> m;
	vector<int> ans(m);
	int le = 0, ri = m - 1;
	while(le <= ri) {
		ans[le] = (n - 1 - le) % n;
		le++;
		if(le > ri) break;
		int dst = m - 1 - ri;
		ans[ri] = m + dst + 1;
		ri--;
	}
	for(int i = 0; i < m; i++) cout << i + 1 << ' ' << ans[i] + 1 << '\n';
}



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

typedef long long LL;

LL a, b, x, y;

int main() {
	cin>>a>>b;
	if(a <= 0 && b >= 0) {
		cout<<"Zero"<<endl;
		return 0;
	}
	if(0 <= a) {
		cout<<"Positive"<<endl;
		return 0;
	}
	if(a < 0 && b > 0) {
		cout<<(((-a)%2 == 1) ? "Negative":"Positive")<<endl;
		return 0;
	}
	cout<<(((b - a)%2 == 0) ? "Negative":"Positive")<<endl;
	return 0;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	matrix := make([][]int, 10)
	for i := 0; i < 10; i++ {
		matrix[i] = make([]int, 10)
	}
	for i := 1; i < n+1; i++ {
		tail := i % 10
		head := i
		tmp := head / 10
		for tmp != 0 {
			head = tmp
			tmp = tmp / 10
		}
		matrix[head][tail]++
	}
	count := 0
	for sento := 1; sento <= 9; sento++ {
		for matsu := 1; matsu <= 9; matsu++ {
			count += matrix[sento][matsu] * matrix[matsu][sento]
		}
	}
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	return int(math.Pow(float64(a), float64(n)))
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a,b,c,count;
		
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		count=0;
		
		for(int t=a;t<=b;t++) {
			if(c%t==0) {
				count++;
			}
		}System.out.println(count);
    }
}



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

int main(){
    int n;
    cin >> n;
    bool can = true;
    vector<int> h(n),v(1);
    for(int i=0;i<n;i++){
        cin >> h.at(i);
    }
    reverse(h.begin(),h.end());
    for(int i=0;i<n-1;i++){
        if(h.at(i)>=h.at(i+1)) continue;
        if(h.at(i)==h.at(i+1)-1) {h.at(i+1)--;}
        else {cout << "No" << endl; return 0;}
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<cmath>
using namespace std;


#define ll long long
#define fr(m) for(int i=0; i<m; i++)
#define frj(m) for(int j=0; j<m; j++)
#define frr(n) for(int i=n; i>=0; i--)
#define pb push_back
#define orr ||
#define nl \n
#define sci(n) scanf("%lld ", &n)
#define pri(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

int main()
{

    ll n,l;
    cin>>n>>l;
    string arr[n];
    fr(n) cin>>arr[i];
    sort(arr,arr+n);
    fr(n) cout<<arr[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

/*
    Author: Koushik Sahu
    Created: 08 September 2020 Tue 23:56:17
*/

ll n, wt;
vll w, v;

const int INF = 1e18L + 5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>n>>wt;
    w.resize(n);
    v.resize(n);
    for(int i=0; i<n; i++){
        cin>>w[i]>>v[i];
    }
    int val_sum = accumulate(v.begin(), v.end(), 0);
    // cout<<val_sum<<"\n";
    vvll dp(n+1, vll(val_sum+1, INF));
    for(int i=0; i<=n; i++) dp[i][0] = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=val_sum; j++){
            if(j>=v[i-1]) dp[i][j] = min(dp[i-1][j], w[i-1]+dp[i-1][j-v[i-1]]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    ll answer = 0;
    for(int i=0; i<=val_sum; i++){
        if(dp[n][i]<=wt){
            answer = max(answer, (ll)i);
        }
    }
    cout<<answer<<"\n";
    return 0;
}

Measured memory_bytes: 83108
fn solve(aa: Vec<usize>, n: usize, k: usize, q: usize) -> Vec<bool> {
    let mut v = vec![k as i32 - q as i32; n];

    for a in aa {
        v[a - 1] += 1;
    }

    v.iter().map(|&x| x > 0).collect::<Vec<_>>()
}

#[test]
fn solve_test() {
    assert_eq!(
        solve(vec![3, 1, 3, 2], 6, 3, 4),
        vec![false, false, true, false, false, false]
    );
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (n, k, q) = parse_line!(usize, usize, usize);
    let aa = (0..q).map(|_| parse_line!(usize)).collect::<Vec<_>>();

    for b in solve(aa, n, k, q) {
        println!("{}", if b { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 4732
N=int(input())
P=tuple(map(str,input().split()))
Q=tuple(map(str,input().split()))
count=0
a,b=0,0
import itertools
if P==Q:
    print(0)
else:
    for i in itertools.permutations(sorted(P),len(P)):
        count+=1
        if i==P:
            a=count
        elif i==Q:
            b=count
    print(abs(a-b))

Measured memory_bytes: 3064
#include <stdio.h>


int main(){
  int N,A[100],i=0,j,flag,tmp;

    scanf("%d",&N);
  if(1<=N && N<=100){
    for(j=0;j<N;j++){
      scanf("%d",&A[j]);
    }

    flag = 1;
    
    while(flag != 0){
      flag = 0;
      for(j=N-1;j>=1;j--){
	if(A[j] < A[j-1]){
	  tmp = A[j];
	  A[j] = A[j-1];
	  A[j-1] = tmp;
	  flag = 1;
	  i++;
	}
      }
    }
    for(j=0;j<N-1;j++){
      printf("%d ",A[j]);
    }
    printf("%d\n",A[N-1]);
    printf("%d\n",i);
  }

  return 0;
}



Measured memory_bytes: 2140