akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline
n,h=map(int,input().split())
bnowa=0
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0], reverse=True)
abb=ab[1:]
abb.sort(key=lambda x:x[1], reverse=True)
i=0
ans=0
while i<n-1 and h>0:
    if abb[i][1]<=ab[0][0]:
        break
    h-=abb[i][1]
    ans+=1
    i+=1
if h>0:
    h-=ab[0][1]
    ans+=1
    if h<=0:
        print(ans)
        exit()
    if h%ab[0][0]==0:
        ans+=h//ab[0][0]
    else:
        ans+=h//ab[0][0]+1
print(ans)


Measured memory_bytes: 68956
N = int(input())
A = [int(input()) for i in range(N)]

M = 998244353

S = sum(A)
dp = [0 for _ in range(S + 1)]
dp[0] = 1
for a in A:
    for i in range(S, a - 1, -1):
        dp[i] = (2 * dp[i] + dp[i - a]) % M
    for i in range(a - 1, -1, -1):
        dp[i] = (2 * dp[i]) % M
dp2 = [0 for _ in range(S + 1)]
dp2[0] = 1
for a in A:
    for i in range(S, a - 1, -1):
        dp2[i] = (dp2[i] + dp2[i - a]) % M
s = 0
for i in range((S + 1) // 2, S + 1):
    s = (s + dp[i]) % M
ans = (3**N - 3 * s) % M
if S % 2 == 0:
    ans = (3**N - 3 * s + 3 * dp2[S // 2]) % M
print(ans)


Measured memory_bytes: 49288
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 1001; //N+1
int V_MAX = 20001; //W+1
int INF=1e9;
typedef pair<int,int> P;
int main()
{
  int n,v,i,j;
  int w[N_MAX][V_MAX];
  P ww[N_MAX]; //(v,w)
  cin >> v >> n;
  for(i=1;i<=n;i++)
    cin >> ww[i].first >> ww[i].second;
  w[0][0]=0;
  fill(w[0]+1,w[0]+V_MAX,INF);
  for(i=1;i<=n;i++)
    for(j=0;j<V_MAX;j++)
      if(j<ww[i].first){
        w[i][j]=w[i-1][j];
      }else{
        w[i][j]=min(w[i-1][j],w[i][j-ww[i].first]+ww[i].second);
      }
  cout << *min_element(w[n]+v,w[n]+V_MAX) << endl;
  return 0;
}

Measured memory_bytes: 81764
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, S;
    cin >> N >> K >> S;
    ll ans[N];
    if (S == 1000000000) {
        REP(i, 0, K) {
            ans[i] = S;
        }
        REP(i, K, N) {
            ans[i] = 1;
        }
    } else {
        REP(i, 0, K) {
            ans[i] = S;
        }
        REP(i, K, N) {
            ans[i] = S + 1;
        }
    }
    REP(i, 0, N) {
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 2176
n = int(input())
size = 200100
total = [0 for _ in range(size)]
for _ in range(n):
  s = sum(map(int, input().split()))
  total[s] += 1

for i in range(size - 1):
  if total[i] % 2:
    print(i, 0)
  total[i + 1] += total[i] // 2


Measured memory_bytes: 7560
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> H >> W;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			string S;
			cin >> S;
			if (S == "snuke") {
				char key = 'A' + j;
				cout << key << i + 1 << endl;
			}
		}
	}
}

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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
vector<int> z(string s)
{
  int n=s.size();
  vector<int> a(n);
  a[0]=n;
  int i=1, j=0;
  while(i<n)
  {
    while(i+j<s.size()&&s[j]==s[i+j])j++;
    a[i]=j;
    if(j==0)
    {
      i++;
      continue;
    }
    int k=1;
    while(i+k<s.size()&&k+a[k]<j)
    {
      a[i+k]=a[k];
      k++;
    }
    i+=k;
    j-=k;
  }
  return a;
}

int main()
{
  int n;string s;cin>>n>>s;
  int i;
  int beg=0;
  int ans=0;
  while(beg<n)
  {
    string subs=s.substr(beg,n-beg);
    vector<int> a(n-beg);
    a=z(subs);
    rep(i,n-beg)ans=max(ans,min(a[i],i));
    beg++;
  }
  cout<<ans<<endl;
}


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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { for (auto& _e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

int main(void) {
	int N, D, X;
	cin >> N >> D >> X;
	vec<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int ans = X;
	for (int i = 0; i < N; ++i) {
		++ans;
		int j = 1;
		while (1) {
			if (j * A[i] + 1 <= D)++ans;
			else break;
			++j;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	string a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		cout<<a[i];
	}
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 256
until (num = gets.chomp.to_i) == 0 
	list = Array.new
	decision = Struct.new(:name,:win,:lose,:num)
	num.times do |i|
		temp = gets.chomp.split
		list[i] = decision.new(temp[0],temp.count("0"),temp.count("1"),i)
	end
	list.sort!{|a,b| (b.win <=> a.win).nonzero? or (a.lose <=> b.lose).nonzero? or (a.num <=> b.num).nonzero?}
	list.each do |ele|
		puts ele.name
	end
end

Measured memory_bytes: 6148
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


s = input()
ans = 0
cnt = 0

for i in s:
    if i in 'ACGT':
        cnt += 1
        ans = max(ans, cnt)
    else:
        cnt = 0
print(ans)


Measured memory_bytes: 3832
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
string revj(string a)
{
  string answer=a+a;
  return string(answer.begin()+a.size()-1,answer.end()-1);
}
string revc(string a)
{
  string answer=a+a;
  return string(answer.begin()+1,answer.begin()+a.size()+1);
}
string reve(string a)
{
  return string(a.end()-a.size()/2,a.end())+string(a.begin()+a.size()/2,a.end()-a.size()/2)+string(a.begin(),a.begin()+a.size()/2);
}
string reva(string a)
{
  return string(a.rbegin(),a.rend());
}
string revp(string a)
{
  string answer=a;
  REP(i,answer.size()) if(0<= answer[i]-'0' && answer[i]-'0' <= 9) answer[i]=(answer[i]-'0'+9)%10+'0';
  return answer;
}
string revm(string a)
{
  string answer=a;
  REP(i,answer.size()) if(0<= answer[i]-'0' && answer[i]-'0' <= 9) answer[i]=(answer[i]-'0'+1)%10+'0';
  return answer;
}
int main(void)
{
  int n;    
  cin >> n;
  REP(i,n){
    string cmd,tmp;
    cin >> cmd >> tmp;
    string rcmd(cmd.rbegin(),cmd.rend());
    for(auto i:rcmd){
      if(i=='J') tmp=revj(tmp);
      if(i=='C') tmp=revc(tmp);
      if(i=='E') tmp=reve(tmp);
      if(i=='A') tmp=reva(tmp);
      if(i=='P') tmp=revp(tmp);
      if(i=='M') tmp=revm(tmp);
    }
    cout << tmp << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
memo = [-1] * (10**6)
def find(p, tree, query):
    global memo
    if p == 0:
        return 0
    if memo[p] < 0:
        memo[p] = find(tree[p], tree, query) + query[p]
    return memo[p]

def main():
    n, q = map(int, input().split())
    tree = [0]*(n+1)
    tree[1] = 0
    for _ in range(n-1):
        a, b = map(int, input().split())
        tree[b] = a
    query = [0] * (n+1)
    for _ in range(q):
        p, x = map(int, input().split())
        query[p] += x
    print(' '.join([str(find(i+1, tree, query)) for i in range(n)]))

main()


Measured memory_bytes: 51452
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N;
	int A;
	cin >> N >> A;
	if(N%500 > A){
		cout << "No" << endl;
	}else{                   
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
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();
		
		
		

		System.out.println(a>=13 ? b : a>=6? b/2 : 0);

	}
}

Measured memory_bytes: 21844
a,b,c = map(int,input().split())

count = 0
while True:
    if a%2==1 or b%2==1 or c%2==1 :
        break
    else:
        x = b//2 + c//2
        y = a//2 + c//2
        z = a//2 + b//2
        a = x
        b = y
        c = z   
        if a==b and b==c:
            count = -1
            break
        count += 1
print(count)

Measured memory_bytes: 38256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int n;
  cin >> n;
  vector<int>t(n + 1),x(n + 1),y(n + 1);
  rep(i,n)cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
  int time = 0;
  bool can = true;
  rep(i,n){
    int tmp = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    int time = t[i + 1] - t[i];
    if(time >= tmp){
      if(tmp % 2 == 0 && time % 2 == 0)continue;
      else if(tmp % 2 != 0 && time % 2 != 0)continue;
      else can = false;
    }
    else{
      can = false;
    }
  }
  cout << (can ? "Yes" : "No") << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
	int sum=0,card,one=0,i;
	char code;

	while(0==0){
		scanf("%d%c",&card,&code);
		if(card>10) card=10;
		else if(card==1) one++;

		sum+=card;

		if(code=='\n'){
			if(sum==0) break;
			else if(sum>21) sum=0;

			else if(one>0){
				for(i=0;i<one;i++)
					if(sum<=11) sum+=10;
			}
			printf("%d\n",sum);
			sum=0; one=0;
		}
	}
	return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;
    import java.util.ArrayList;
     
    public class Main { //クラス名はMain
        public static void main(String[] args) {
            //コード
          Scanner sc = new Scanner(System.in);
          int mojilen = sc.nextInt();
          String c2 = sc.next();
		  String[] strArray = c2.split("",0);  
          int c = 0;	//カウンタ
          //空文字挿入
          ArrayList<String> array = new ArrayList<String>();
          loop: for(int i=0;i<=mojilen-1;i++) {
            array.add(new String(strArray[i]));
          }
          array.add(new String(" "));
          
          //判定
          loop: for(int i=0;i<=mojilen-1;i++) {
           		if (array.get(i).equals(array.get(i+1))) {
                	//等しいとき
           	}
          	else {
              		//等しくないとき
            		c++;
         		}
          }
          System.out.println(c);
        }
    }

Measured memory_bytes: 36084
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

/*
<url:https://arc077.contest.atcoder.jp/tasks/arc077_b>
問題文============================================================
 1,…,n の n 個の整数からなる長さ n+1 の数列 a1,a2,…,an+1 が与えられます。
 この数列には 1,…,n のどの整数もかならず 1 回以上出現することが分かっています。
 
 k=1,…,n+1 のそれぞれについて、与えられた数列の長さ k の（連続とは限らない）部分列の個数を求め、
 109+7 で割ったあまりを出力して下さい。
 
 2 つの部分列が数列として同じであれば、元の数列での位置が異なっていたとしても、1 通りと数えます。
 
 数列 a の長さ k の部分列とは、a の要素のうち k 個を選んで、
 それらを順番を変えずに取り出して並べた数列のことを指します。
 例えば、数列 1,2,3,4,5 の長さ 3 の部分列には、
 1,3,5 や 1,2,3 などがあります。 一方で、3,1,2 や 1,10,100 はこの数列の部分列ではありません。
 
 1≤n≤10^5
 1≤ai≤n
 1,…,n のどの整数も必ず数列に出現する。
 n,ai は整数である。
=================================================================

解説=============================================================
同一文字を x とすれば　こういった区間ができる
 [ l ]x[ m ]x[ r ]
 
 ここで、同一部分列の選ばれ方は
 
 [l] から i 個 左or右のxから 1 個 [r] から k-i-1個選ばれる選ばれ方であり
 iは0も許すので
 [l] or [r] から k-1個　、 左or右のxから 1 個　選ぶ選ばれ方の数だけ重複文字列ができる
 
 全体の選び方は n+1Ck なので
 nCr において n < r ならば 0 と定義すれば
 
 答えは　(n+1)Ck - (lsize + rsize)C(k-1)
 となる
 
================================================================
*/

const ll MAX_N = 2e5 + 10;
const ll MOD = 1e9+7;
ll Inv[MAX_N];
ll fact[MAX_N];
ll factInv[MAX_N];
void Inv_init(){
    Inv[1] = 1;
    for(int i = 2; i < MAX_N; i++) {
        Inv[i] = Inv[MOD%i] * (MOD - MOD/i) % MOD;
    }
}
void fact_init(){
    fact[0] = fact[1] = factInv[0] = factInv[1] = 1;
    for(int i = 2; i < MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        factInv[i] = (factInv[i-1] * Inv[i])%MOD;
    }
}

// a^b % MOD;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// 逆元 1/a % MOD
ll inversemod(ll a) { return powmod(a,MOD - 2);}
ll nCr(int n,int r) {
    if(n < r) return 0;
    return (fact[n] * (factInv[r] * factInv[n-r] % MOD)) % MOD;
}

void init(){
    Inv_init();
    fact_init();
}

void solve(){
    ll n; cin >> n;
    vector<ll> a(n+1); for(auto &in:a){ cin >> in; in--; }
    vector<ll> idx(n,-1);
    ll lx = -1,rx = -1;
    for(int i = 0; i <= n;i++){
        if(idx[a[i]] == -1) idx[a[i]] = i;
        else{ lx = idx[a[i]]; rx = idx[a[i]] = i;}
    }
    ll lnum = lx, mnum = rx - lx - 1, rnum = (n+1) - rx - 1;

    // output
    for(ll i = 1; i <= n+1; i++){
        cout << (nCr(n+1,i) - nCr(lnum+rnum,i-1) + MOD)%MOD << endl;
//        if(i <= lnum + rnum + 1){
//            cout << (nCr(n+1,i) - nCr(lnum+rnum,i-1) + MOD)%MOD << endl;
//        }else{
//            cout << nCr(n+1,i) << endl;
//        }
    }
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    init();
    solve();
	return 0;
}


Measured memory_bytes: 7552
#include<stdio.h>
int main (void)
{
char S[3];
int i,n=0;
scanf("%s",S);
for(i=0;i<3;i++)
{if(S[i]=='a')
n=n+1;
if(S[i]=='b')
n=n+2;
if(S[i]=='c')
n=n+3;}
if(n==6)
printf("Yes");
else
printf("No");
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vll t(n);
  for (ll i = 0; i < n; i++) cin >> t[i];
  ll m;
  cin >> m;
  vll p(m), x(m);
  for (ll i = 0; i < m; i++) cin >> p[i] >> x[i];
  for (ll i = 0; i < m; i++) {
    ll sum = 0;
    for (ll j = 0; j < n; j++) {
      if (j + 1 == p[i]) sum += x[i];
      else sum += t[j];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>

//typedef pair<int,int> P;

using namespace std;

int main(){
	long long X,Y;
	scanf("%lld %lld", &X,&Y);


	if(X%Y==0){
		printf("-1\n");
	}else{
		printf("%lld\n", X);
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#pragma warning (disable: 4996)

int N, M;
int A[1 << 18], B[1 << 18];
vector<int> X[1 << 18];

int dp[1 << 18];
int pres[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) cin >> A[i] >> B[i];
	for (int i = 1; i <= M; i++) {
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}
	for (int i = 1; i <= N; i++) dp[i] = (1 << 30);
	
	queue<int> Q; Q.push(1); dp[1] = 0;
	while (!Q.empty()) {
		int pos = Q.front(); Q.pop();
		for (int i : X[pos]) {
			if (dp[i] != (1 << 30)) continue;
			Q.push(i);
			dp[i] = dp[pos] + 1;
			pres[i] = pos;
		}
	}

	cout << "Yes" << endl;
	for (int i = 2; i <= N; i++) cout << pres[i] << endl;
	return 0;
}

Measured memory_bytes: 16196
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int main() {
    i64 N, M;
    cin >> N >> M;
    cout << ((1 << M) * (100 * N + 1800 * M)) << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> ans(100000);
  for(int x = 1; x * x < n; x++){
    for(int y = 1; y * y < n; y++){
      for(int z = 1; z * z < n; z++){
        int k = x * x + y * y + z * z + x * y + y * z + z * x;
        ans.at(k)++;
      }
    }
  }
  
  for(int i = 0; i < n; i++) cout << ans.at(i+1) << endl;
}


Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  long a,b,c;
  cin >> a >> b >> c;
  
  int x,y;
  cin >> x >> y;
  
  long d = a * x + b * y;
  long e = c * max(x,y) * 2;
  long f;
  if(x >= y)
    f = c * 2 * y + a * (x - y);
  else
    f = c * 2 * x + b * (y - x);
  
  cout << min({d,e,f}) << endl;
  
  return 0;
  
}

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

int main(){
  int N,D;
  cin >> N >> D;
  int count=0;
  long double d=0;
  for(int i=0; i<N; i++){
    long int x,y;
    cin >> x >> y;
    d=sqrt(x*x+y*y);
    if(d<=D){
      count = count + 1;
    }
  }
  cout << count << endl;
  return 0;
}  

Measured memory_bytes: 3640
n=int(input())
l=[0]*(n+1)
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            s=i**2+j**2+k**2+i*k+i*j+j*k
            if(s<=n):
                l[s]+=1
for i in range(1,n+1):
    print(l[i])


Measured memory_bytes: 74604
class Kokuban

  attr_accessor :ary

  def add_column(b, num)
    tmp = Marshal.load(Marshal.dump(ary))
    if (b)
      # puts tmp
      tmp << num
    else
      tmp.unshift(num)
    end
    return tmp
  end

  def Kokuban.flush(ary)
    ans = [[], []]
    ary.each{ |x|
      if x == 0
        ans[0] << '.'
        ans[1] << '.'
      elsif x == 1
        ans[0] << '.'
        ans[1] << '#'
      elsif x == 2
        ans[0] << '#'
        ans[1] << '.'
      else
        ans[0] << '#'
        ans[1] << '#'
      end
    }
    puts ans[0].join("")
    puts ans[1].join("")
    STDOUT.flush
  end
  
end

n = gets.to_i
kokuban = Kokuban.new
kokuban.ary = []

bol = false

while true
  added = false
  for i in 0..3
    tmp = kokuban.add_column(bol, i)
    Kokuban.flush(tmp)
    r = gets.chomp
    if r == "end"
      exit
    elsif r == 'T'
      kokuban.ary = tmp
      added = true
      break
    else
      #
    end
  end
  if added
    #
  else
    # puts "next state"
    bol = true
  end
end


Measured memory_bytes: 2384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
 
int main() {
int n,k;
cin >> n >> k;
if((n+1)/2>=k)cout<<"YES"<<endl;
else cout <<"NO" << endl;
}

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

using namespace std;

int com_2(int k){
  return k*(k-1)/2;
}

int main(){
  int n;
  int m;
  cin >> n >> m;
  int ans=0;
  // cout << com_2(n+m) << endl;
  // cout << n*m << endl;
  ans = com_2(n+m) - n*m;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
int fact(int n){
  int m;
  if (n == 0)
      return 1;
  m = fact(n - 1);    
  return n * m;       
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y,count=0;
    cin>>x>>y;
    if(x==1 && y==1){
        count+=400000;
    }
    if(x==3){
        count+=100000;
    }
    if(x==2){
        count+=200000;
    }
    if(x==1){
        count+=300000;
    }
      if(y==3){
        count+=100000;
    }
    if(y==2){
        count+=200000;
    }
    if(y==1){
        count+=300000;
    }
    cout<<count<<'\n';
    return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  string S ;
  cin >> S ;
  string A = {S.at(0),S.at(1),S.at(2),S.at(3),S.at(5),S.at(6),S.at(8),S.at(9)} ;
  int B = stoi(A) ;
  if ( B <=20190430 ) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

A_sorted = sorted(A)
B_sorted = sorted(B)
C_sorted = sorted(C)

ans = 0
for b in B_sorted:
    #Aのうちbより小さいの数
    a_count = bisect.bisect_left(A_sorted, b)
    
    #Cのうちbより大きいの数
    c_count = N - bisect.bisect_right(C_sorted, b)
    
    ans += a_count * c_count

print(ans)

Measured memory_bytes: 23232
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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()
{
    string s, t; cin >> s >> t;
    vint a(26);
    vint b(26);
    vint c(200005);
    vint d(200005);

    rep(i,s.size()){
        a[s[i]-'a']++;
        b[t[i]-'a']++;
    }

    rep(i, 26){
        c[a[i]]++;
        d[b[i]]++;
    }

    // prvec(c);
    // prvec(d);

    if(c==d){
        pr("Yes");
    }else pr("No");
    return 0;}

Measured memory_bytes: 5424
def add(A, B):
    return (A + B)

def sub(A, B):
    return (A - B)

def mult(A, B):
    return (A * B)


def main():
    inp = input('')
    inp = inp.split()
    A = int(inp[0])
    B = int(inp[1])

    C = []
    C.append(add(A,B))
    C.append(sub(A,B))
    C.append(mult(A,B))

    ans = max(C)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define len(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}


void solve(){
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  for(int i = K; i < N; i++){
    if(A[i-K] < A[i]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

}

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


Measured memory_bytes: 4740
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	boolean[][] map;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int t=1;t<=n;t++) {
			map = new boolean[15][15];
			for (int i=0;i<8;i++) {
				String l = sc.next();
				for (int j=0;j<8;j++) map[i+3][j+3] = l.charAt(j) == '1';
			}
			int x = sc.nextInt() + 2, y = sc.nextInt() + 2;
			dfs(x, y);
			print(t);
		}
	}
	
	void print(int t) {
		System.out.println("Data " + t + ":");
		for (int i=3;i<11;i++) {
			for (int j=3;j<11;j++) System.out.print((map[i][j] ? "1": "0"));
			System.out.println();
		}
	}
	
	void dfs(int x, int y) {
		map[y][x] = false;
		for (int i=-3;i<=3;i++) {
			if (map[y][x+i]) dfs(x+i, y);
			if (map[y+i][x]) dfs(x, y+i);
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 17240
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a,inc=(b-a)/abs(b-a); i!=b ; i+=inc)
#define deb(x) cout<<#x<<"->"<<x<<endl;
#define print(arr,a,b) for(int i=a;i!=b;i++){cout<<arr[i]<<" ";}cout<<endl;
using ll=long long int;
int arr_min(int arr[],int a,int b){ int min=arr[0]; for(int i=a;i!=b;i++){if(min>arr[i]) min=arr[i];}return min;}
int arr_max(int arr[],int a,int b){ int max=arr[0]; for(int i=a;i!=b;i++){if(max<arr[i]) max=arr[i];}return max;}

signed main()
{
	ios_base::sync_with_stdio(false);   
    cin.tie(NULL);

	#ifndef ONLINE_JUDGE
      	freopen("input.txt", "r", stdin);
      	freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t-->0){
    	string str;
    	cin>>str;
    	int flag=0;
    	for(int i=0;i<str.length();i++)
    	{
            if(str[i]=='7')
            	flag=1;
    	}
    	(flag)?cout<<"Yes":cout<<"No";cout<<endl;
    	
    	
    }
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main()
{
	int x;
	while(cin>>x)
	{
		int a[100000+20];
		int flag1=0;
		for(int i=1;i<=x;i++)
		{
			cin>>a[i];
			if(a[i]==2)
			flag1=1;
		}
		if(flag1==0)
		{
			cout<<"-1"<<endl;
			continue;
		}
		int t=a[1],p=1;
		a[1]=-1;
		int a1[100000+20];
		int flag=0;
		a1[0]=a[1];
		while(t!=2)
		{
			int b=t;
			t=a[t];
			if(t==-1)
			{
				cout<<"-1"<<endl;
				flag=1;
				break;
			}
			a[b]=-1;
			a1[p]=t;
			p++;
		}
		if(flag==0)
		cout<<p<<endl;
	}
} 

Measured memory_bytes: 640
/**
 *      ABC 102 A
 *      author  : kyomukyomupurin
 *      created : 2018/08/20
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    long N;
    cin >> N;
    N % 2 == 0 ? cout << N : cout << N * 2;

    return 0;
    
}


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

using namespace std;

int ans;
bool visited[8];
bool all_visited;
vector<int> G[8];

void dfs(int cur, int n) {
    visited[cur] = true;
    all_visited = true;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            all_visited = false;
            break;
        }
    }
    if (all_visited) { ans++; }
    for (auto e: G[cur]) {
        if (!visited[e]) {
            dfs(e, n);
            visited[e] = false;
        }
    }
}

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

    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    dfs(0, n);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	In := readLineInt()
	A, B := In[0], In[1]
	AMap, BMap := map[int]int{}, map[int]int{}
	End := max(A, B)
	for prime := 2; prime <= End; prime++ {
		isPrime := true
		for p := 2; p < sqrt(prime); p++ {
			if (prime % p) == 0 {
				isPrime = false
				break
			}
		}

		if isPrime {
			p, c := multiplier(A, prime)
			if c != -1 {
				A /= p
				AMap[prime] = c
			}

			p, c = multiplier(B, prime)
			if c != -1 {
				B /= p
				BMap[prime] = c
			}
		}

		if A == 1 && B == 1 {
			break
		}

		if prime != 2 {
			prime++
		}
	}

	Max := AMap
	for k, v := range BMap {
		mv := Max[k]
		Max[k] = max(mv, v)
	}

	result := 1
	for k, v := range Max {
		result *= pow(k, v)
	}
	fmt.Println(result)
}

func multiplier(value int, prime int) (int, int) {
	now, previous, count := 1, 0, 1
	for {
		now = now * prime
		if value%now != 0 {
			if previous != 0 {
				value = value / previous
				return previous, count - 1
			}
			break
		} else {
			previous = now
		}
		count++
	}
	return -1, -1
}

/////////////////////////////////////////
func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}

func Loop(start, end int, f func(i int)) {
	for i := start; i < end; i++ {
		f(i)
	}
}

func pow(a, b int) int {
	result := a
	Loop(0, b-1, func(i int) {
		result = result * a
	})

	return result
}

func max(a ...int) int {
	result := 0

	for _, i := range a {
		if result < i {
			result = i
		}
	}

	return result
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}


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


int main() {
 #define int long long
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  int a,sum;
  for(int i=0;i<N;i++){
    cin >> a;
    A[i]=a;
    B[a-1]++;
  }
  for(int j=0;j<N;j++){
    sum+=(B[j]*(B[j]-1)*0.5);
  }
  int ans;
  for(int i=0;i<N;i++){
    ans=0;
    ans=sum - (B[A[i]-1]*(B[A[i]-1]-1)*0.5);
    B[A[i]-1]--;
    ans+=(B[A[i]-1]*(B[A[i]-1]-1)*0.5);
    cout << ans << endl;
    B[A[i]-1]++;
  }

}

Measured memory_bytes: 5760
n,k = map(int, input().split())
As = list(map(int, input().split()))
from itertools import accumulate

def modconb(n,mod):
    # テーブルを作る
    fac = [0]*(n+1)
    finv = [0]*(n+1)
    inv = [0]*(n+1)  

    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,n+1):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] %mod
    # 計算
    if n<k: return 0
    if n<0 or k<0: return 0
    return fac, finv
mod = 10**9+7
fac, finv = modconb(n, mod)
As.sort()
acc = list(accumulate(As))
As.sort(reverse=True)
acc_r = list(accumulate(As))
ans = 0
for d in range(1,n):
    if d-1 < k-2:
        continue
    if k-2 <= 0:
        c = 1
    else:
        c = fac[d-1]*(finv[k-2]*finv[d-1-(k-2)]%mod)%mod
        # c = modconb(d-1,k-2,mod)
    ind = min(d-1, n-d-1)
    mn = acc[ind]
    mx = acc_r[ind]
    ans += (mx-mn)*c
    # print(d,c,mn,mx,"d",(mx-mn)*c)
    ans %= mod
print(ans)

Measured memory_bytes: 30316
def main():
    H, W, D = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    num_to_xy = {}
    d_sum = [[] for _ in range(D)]
    for h in range(H):
        for w in range(W):
            num_to_xy[A[h][w]] = (h+1, w+1)
            d_sum[A[h][w] % D].append((A[h][w]))
    for d in range(D):
        d_sum[d].sort()
        cur = []
        y, x = -1, -1
        j, i = -1, -1
        for i, a in enumerate(d_sum[d]):
            if i == 0:
                y, x = num_to_xy[a]
                continue
            j, i = num_to_xy[a]
            cur.append(abs(x - i) + abs(y - j))
            y, x = j, i
        s = [0] * (len(cur) + 1)
        for i in range(0, len(cur)):
            s[i+1] = s[i] + cur[i]
        d_sum[d] = s
    Q = int(input())
    for q in range(Q):
        le, ri = (int(i) for i in input().split())
        if le % D != 0:
            print(d_sum[le % D][(ri - le % D)//D] -
                  d_sum[le % D][(le - le % D)//D])
        else:
            print(d_sum[le % D][(ri - le % D)//D-1] -
                  d_sum[le % D][(le - le % D)//D-1])


if __name__ == '__main__':
    main()


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

int main()
{
    int n,l;
    cin >> n>>l;
    vector<string> words(n);
    for (auto &w : words)
    {
        cin >> w;
    }
    sort(words.begin(), words.end());

    for (auto w : words)
    {
        cout << w;
    }
    
}

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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			while (true)
			{
				int n = int.Parse(Console.ReadLine());
				if (n == 0) break;

				Dictionary<int, long> d = new Dictionary<int, long>();
				List<int> l = new List<int>();

				while (n-- != 0)
				{
					string[] line = Console.ReadLine().Split(' ');
					var num = int.Parse(line[0]);
					var a = long.Parse(line[1]);
					var b = long.Parse(line[2]);
					if (!d.ContainsKey(num))
					{
						l.Add(num);
						d.Add(num, 0);
					}
					d[num] += a * b;
				}
				var f = true;
				for (int i = 0; i < l.Count; i++)
				{
					if (d[l[i]] >= 1000000)
					{
						f = false;
						Console.WriteLine(l[i]);
					}
				}
				if (f) Console.WriteLine("NA");
			}
		}
	}
}

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

using namespace std;

long mod = 1e9 + 7;
long L(long d) {
	if (!d) return 1;
	auto t = L(d / 2);
	return (d % 2 ? (t * t%mod) * 10 : t * t) % mod;
}
int main()
{
	long s;
	cin >> s;
	long res = 0, d = 0, d8 = 0;
	for (int i = 1; i <= s / i; i++) {
		if (s%i) continue;
		d++;
		auto j = s / i;
		if (i < 9) res += max(0l, L(i - 1) * 9 - j + 1), d8++;
		else res += L(i - 1) * 9 - j + 1 + mod;
		res %= mod;
		if (i == j) break;
		d++;
		if (j < 9) res += max(0l, L(j - 1) * 9 - i + 1), d8++;
		else res += L(j - 1) * 9 - i + 1 + mod;
		res %= mod;
	}
	res = (res + (s - 1) / 8 + d8 - d) % mod;
	long l = 1, ll = 1, r = 1, rr = 1, t = 1, LL = 10, RR = 10;
	while (r < 30000000) {
		if (ll == rr || t < s) {
			if (++r == RR) rr++, RR *= 10;
			t += rr;
		}
		else {
			if (t == s) res++, res %= mod;
			t -= ll;
			if (++l == LL) ll++, LL *= 10;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, l, r;
	cin >> N;
	int sum = 0;
	rep(i, N) {
		cin >> l >> r;
		sum += r - l + 1;
	}
	cout << sum;
}

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

typedef long long ll;
ll n, ans, l, r, x1, x2, md, d[800000], a[200005];
ll f(ll p, ll q) {
	ll u =2e9;
	while (p < q) {
		if (p % 2 == 1) u = min(u, d[p++]);
		if (q % 2 == 0) u = min(u, d[q--]);
		p /= 2;
		q /= 2;
	}
	if (p == q) u = min(u, d[p]);
	return u;
}
int main()
{
	ll i, j, k;
	cin >> n;
	for (k = 1; k < n; k *= 2);
	for (i =0; i < n; i++) {
		scanf("%lld", &a[i]);
		d[k + i] = a[i];
	}
	for (i = k + n; i <= n * 2; i++) d[i] = 2e9;
	for (i = k - 1; i >= 1; i--) {
		d[i] = min(d[i * 2], d[i * 2 + 1]);
	}
	for (i = 0; i < n; i++) {
		l = 0;
		r = i;
		x1 = i;
		while (l <r) {
			md = (l + r) / 2;
			if (f(k + md, k + i) == a[i]) {
				r = md;
				x1 = md;
			} else {
				l = md + 1;
			}
		}

		l = i;
		r = n;
		x2 = i;
		while (l <r) {
			md = (l + r) / 2;
			if (f(k + i, k + md) == a[i]) {
				l = md + 1;
				x2 = md;
			} else {
				r = md;
			}
		}
		ans += a[i] * (i - x1 + 1) * (x2 - i + 1);
	}
    cout << ans;
    return 0;
}

Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {
    private static final int MOD = 1000000007;
    private static final int MAX_N = 200005;
    private static final long[] MODULAR_INVERSE = new long[MAX_N];
    private static final long[] FACTORIAL = new long[MAX_N];
  
	public static long pow_mod(long base, long exp, long modulo) {
        long result = 1;
        base = base % modulo;
        // exponent e be converted to binary notation
        // exp = ∑_{i=0}^{n-1} exp_i*2^i; exp_i in {0, 1}
        // base^e = base^{∑_{i=0}^{n-1} exp_i*2^i} = ∏_{i=0}^{n-1} base^2^i)^exp_i
        // result = ∏_{i=0}^{n-1} (b^2^i)^exp_i (mod m)
        while (exp > 0) {
            // if exp_i = 0; pass; because base^0 = 1
            // if exp_i = 1; (b^2^i * (∏_{j=0}^{i-1} (b^2^j)^exp_j mod m)) mod m
            if ((exp & 0x1) != 0) {
                // ab mod m ≡ (a * (b mod m)) mod m
                result = (result * base) % modulo;
            }
            // a ≡ b mod m => a^2 ≡ b^2 mod m
            // b^2^(i+1) ≡ (b^2^(i) * b^2^(i)) mod m
            base = (base * base) % modulo;
            exp >>= 1;
        }
        return result;
    }
  
    static {
        FACTORIAL[0] = 1;
        for (int i = 1; i < MAX_N; i++) FACTORIAL[i] = FACTORIAL[i - 1] * i % MOD;
        // in the special case where m is a prime
        // a modular inverse is given by a^{-1} = a^{m-2} mod m
        MODULAR_INVERSE[MAX_N - 1] = pow_mod(FACTORIAL[MAX_N - 1], MOD - 2, MOD);
        // same as divide FACTORIAL[0]
        MODULAR_INVERSE[0] = 1;
        // 1^{-1} = 1 mod p
        // if b_n = ∏_{i=0}^{n} a_i, compute b_n^{-1}
        // then from n down to 2: b_{i-1}^{-1} = b_i^{-1} * a_i
        for (int i = MAX_N - 1; i >= 2; i--) MODULAR_INVERSE[i - 1] = MODULAR_INVERSE[i] * (i) % MOD;
    }

    private static long binomial_coefficient(int n, int r) {
        return FACTORIAL[n] * MODULAR_INVERSE[r] % MOD * MODULAR_INVERSE[n - r] % MOD;
    }

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            int A = sc.nextInt();
            int B = sc.nextInt();
            long ans = 0;
            /*
             * |S|Y|Y|
             * |X| |E|
             */
            for (int i = B + 1; i <= W; i++) {
                int x = (i - 1); // the number of horizontal step can move from start to one of the yellow square
                int y = (H - A - 1); // the number of vertical step can move from start to one of the yellow square
                int a = W - i; // the number of horizontal step can move from one of the yellow square to end
                int b = A - 1; // the number of vertical step can move from one of the yellow square to end
                ans += binomial_coefficient(x + y, x) * binomial_coefficient(a + b, a) % MOD;
                ans %= MOD;
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 27860
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
	int N;
	char *s;
	scanf("%d\n",&N);
	s = malloc(N+1);
	char *a;
	char *b;
	int i;
	a = malloc(N/2 + 1);
	b = malloc(N/2 + 1);
	fgets(s,N+1,stdin);
	for(i = 0;i < N/2;i++){
		a[i] = s[i];
	}
	a[i+1] = '\0';
	int j;
	for(j = N/2,i = 0;j <= N;j++,i++){
		b[i] = s[j];
	}
	b[j+1] = '\0';
	//printf("%s:%s",a,b);
	if(!strcmp(a,b)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

int main() {
    int A, B;
    std::cin >> A >> B;
    std::string S;
    std::cin >> S;
    
    bool ans = true;
    if (S[A] == '-') {
        for (int i=0; i<=A-1; ++i) {
            if (S[i] < '0' || S[i] > '9')
                ans = false;
        }
        for (int i=A+1; i<=(A+B); ++i) {
            if (S[i] < '0' || S[i] > '9')
                ans = false;
        }
    } else {
        ans = false;
    }
    std::cout << (ans ? "Yes" : "No") << std::endl;
}

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

int main(){

    int n;
    cin >> n;

    rep(i,n){
        int a;
        cin >> a;
        if(a%2 == 0){
            if(a%3 != 0 && a%5 !=0 ){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    
    
    return 0;
}




Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,a = LI()
    print(math.ceil(h/a))
    return

#Solve
if __name__ == "__main__":
    solve()


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

using namespace std;

int main(void) {
    long N, ans = 0;
    long tbl[] = {0, 0, 0, 0, 0};
    cin >> N;
    for (int i = 0; i < N; i++) {
        string S; cin >> S;
        switch (S[0])
        {
            case 'M':
                tbl[0]++;
                break;
            case 'R':
                tbl[1]++;
                break;
            case 'A':
                tbl[2]++;
                break;
            case 'C':
                tbl[3]++;
                break;
            case 'H':
                tbl[4]++;
                break;
        }
    }

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  static long n, a, b;

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

    n = sc.nextInt();
    a = sc.nextInt();
    b = sc.nextInt();

    if(a > b || (a != b && n == 1)){
      System.out.println(0);
      return;
    }

    System.out.println(b * (n - 2) - a * (n - 2) + 1);
  }
}


Measured memory_bytes: 23636
from collections import deque

def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

Measured memory_bytes: 137016