akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

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

        while (true) {
            String line = sc.nextLine();
            if(line.equals("0 0")) {
                return;
            }

            int countCard1 = Integer.valueOf(line.split(" ")[0]);
            int countCard2 = Integer.valueOf(line.split(" ")[1]);

            int[] arrCard1 = new int[countCard1];
            int[] arrCard2 = new int[countCard2];

            int totalVal1 = 0;
            int totalVal2 = 0;
            for (int i = 0; i < countCard1; i++) {
                arrCard1[i] = Integer.valueOf(sc.nextLine());
                totalVal1 += arrCard1[i];
            }

            for (int i = 0; i < countCard2; i++) {
                arrCard2[i] = Integer.valueOf(sc.nextLine());
                totalVal2 += arrCard2[i];
            }

            if ((totalVal1 + totalVal2) % 2 != 0) {
                System.out.println("-1");
            } else {
                int avg = (totalVal1 + totalVal2) / 2;
                int missingValue1 = avg - totalVal1;

                String result = null;
                Integer minResult = null;

                for (Integer number1 : arrCard1) {
                    for (Integer number2 : arrCard2) {
                        if(number1 + missingValue1 == number2) {
                            if(minResult == null || number1 + number2 < minResult) {
                                result = number1 + " " + number2;
                                minResult = number1 + number2;
                            }
                        }
                    }
                }

                if(result == null) {
                    System.out.println("-1");
                } else {
                    System.out.println(result);
                }
            }
        }


    }

}



Measured memory_bytes: 29504
import numpy as np
N, K = map(int, input().split())
mod = 2*K
field = [[0]*(2*K+1) for _ in range(2*K+1)]

def gen_pattern(x):
    if x < K-1:
        return [[0, x+1], [x+K+1, 2*K]]
    else:
        return [[x-K+1, x+1]]

for _ in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == 'W':
        y += K
    x %= mod
    y %= mod
    for tmp in [0, K]:
        for l, r in gen_pattern((x+tmp) % mod):
            for b, t in gen_pattern((y+tmp) % mod):
                field[l][b] += 1
                field[l][t] -= 1
                field[r][b] -= 1
                field[r][t] += 1

print(np.max(np.cumsum(np.cumsum(field, axis=0), axis=1)))


Measured memory_bytes: 106344
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int INF = 1e9+5;
int main(){
    int N;
    scanf("%d",&N);
    vector<int> h(N);
    for(int& x:h)
        scanf("%d",&x);
    vector<int> dp (N,INF);
    dp[0]=0;
    for(int i=0;i<N;i++){
        for(int j:{i+1,i+2}){
            if(j<N){
                dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    printf("%d",dp[N-1]);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    double ans = 0;
    double x;
    char u[5];
    for (i = 0; i < n; i++)
    {
        scanf("%lf %s", &x, u);
        if (u[0] == 'J')
            ans += x;
        else
            ans += x * 380000;
    }
    printf("%.20lf\n", ans);
    return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int inf = int (1e9) + int (1e5);
const ll infl = ll (2e18) + ll (1e10);
const ui M=1E9+7;
const double eps = 1e-9;

int main()
{
    std::ios_base::sync_with_stdio (false);
    int A,B;
    cin >> A >> B;
    if (A%3==0 || B%3==0 || (A+B)%3==0)
        cout << "Possible";
    else
        cout << "Impossible";

    return 0;
}


Measured memory_bytes: 256
for(t in l=require("fs").readFileSync("/dev/stdin","utf8").split("\n"),c={0:{},1:{}},l[1].split(" ").forEach((s,e)=>{t=c[1&e],t[s]=t[s]?t[s]+1:1}),s={},c)s[t]=Object.keys(c[t]).sort((s,e)=>c[t][e]-c[t][s]);g=((t,e)=>s[t][e]?c[t][s[t][e]]:0),s[0][0]!=s[1][0]&&(s[1][1]=s[1][0]),console.log(l[0]-Math.max(g(0,0)+g(1,1),g(0,1)+g(1,0)));

Measured memory_bytes: 36192
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int a,b,c,d;
    while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
    {
        printf("%d\n",max(0,min(d,b)-max(a,c)));
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int  vac,ass,day=0,i,rem;
    cin>>vac>>ass;
    int assi[ass+2];
    for(i=0; i<ass; i++)
    {

        cin>>assi[i];
        day=day+assi[i];
    }
    if(vac>=day)
       cout<<vac-day<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define MAX 1000000000000000

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  ll sum = 0;
  vector<ll> x(N, 0);
  vector<ll> y(N, 0);
  REP(i, N) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  x.at(0) = a.at(0);
  y.at(0) = sum - x.at(0);
  REP2(i, 1, N - 1) {
    x.at(i) = x.at(i - 1) + a.at(i);
    y.at(i) = sum - x.at(i);
  }

  ll ans = MAX;
  REP(i, N - 1) ans = min(ans, abs(x.at(i) - y.at(i)));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main()
{
	int cnt[26] = { 0 };
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		cnt[s[i] % 26]++;
		if(cnt[s[i] % 26] == 2){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

bool cmp(pii a,pii b){
	return a.S<b.S;
}

int find(vector<int> &dp,int t){
	int hi=sz(dp)-1,lo=-1;
	while(hi-lo>1){
		int m=(hi+lo)/2;
		if(dp[m]<=t) lo=m;
		else hi=m;
	}
	return hi;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,h,w; cin>>n>>h>>w;
	int x,y,cnt=0;
	while(n--){
		cin>>x>>y;
		if(x>=h && y>=w) cnt++;
	}
	cout<<cnt<<"\n";
}



























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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  int n, m;

  cin >> n >> m;
  std::vector<int> v(n);
  int tot = 0;
  for(int i = 0; i < n; i++){
    cin >> v[i]; tot += v[i];
  }
  sort(v.begin(), v.end(), greater<int>());

  bool flag = 0;
  for(int i = 0; i < m; i++){
    if(v[i] * 4 * m < tot){
      flag = 1; break;
    }
  }

  if(flag)cout << "No\n";
  else cout << "Yes\n";

  return 0;
}

Measured memory_bytes: 256
use itertools::Itertools;
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
        q: usize,
        s: Chars,
        lr: [(usize, usize); q],
    }
    let mut data = vec![0; n];
    for (i, (&p, &c)) in s.iter().tuple_windows().enumerate() {
        data[i + 1] = data[i] + (p == 'A' && c == 'C') as usize;
    }
    for (l, r) in lr {
        println!("{}", data[r - 1] - data[l - 1]);
    }
}


Measured memory_bytes: 6024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
int main() {
	char s[233];
	scanf("%s",s); int len=strlen(s);
	char mx=' ';
	for(char c='1';c<='9';c++) {
		bool flag=1;
		for(int i=0;i<len;i++)
			if(s[i]==c)continue;
			else
			if(s[i]>c) {
				flag=0; break;
			}else break;
		if(flag) {
			for(int i=0;i<len;i++)putchar(c);
			break;
		}
	}
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int quotient = a/b;
		int rest = a%b;
		String str = String.format("%.6f", 1.0*a/b);
		


		System.out.println(quotient+" "+rest+" "+str);
	}
}

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

using namespace std;

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

    int n;
    cin>>n;
    
    if(n%2==0)
        cout<<n;
    else
        cout<<2*n;
    return 0;
}


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }
  else if(abs(a-b)<=d&&abs(b-c)<=d){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

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

using namespace std;

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;

    vector<char> ans;
    ans.push_back(S[0]);

    for (int i = 1; i < N; i++)
        if (S[i] != S[i - 1])
            ans.push_back(S[i]);

    cout << ans.size() << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#define x first
#define y second
namespace Luan_Gao
{
	typedef long long ll;
	typedef std::pair<ll,int> pii;
	bool iscubic(ll x)
	{
		ll y=floor(std::pow(double(x),1.0/3)+0.5);
		if(y*y*y==x)return 1;
		return 0;
	}
	ll ispsn(ll x)
	{
		ll y=floor(std::sqrt(double(x))+0.5);
		if(y*y==x)return y;
		return 0;
	}
	const int N=100500,M=3000,MOD=1004535809,H=19260817,TOP=2200;
	int pri[M],tot;
	bool isit[M];
	void getpri()
	{
		for(int i=2;i<M;i++)
		{
			if(!isit[i])pri[++tot]=i;
			for(int j=1,x;(x=i*pri[j])<M;j++)
			{
				isit[x]=1;
				if(i%pri[j]==0)break;
			}
		}
	}
	std::map<ll,int> G;
	ll s[N];
	pii t[40];
	int n,ans,cntp;
	void initialize()
	{
		scanf("%d",&n);ans=0;
		int tmp=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",s+i);
			if(iscubic(s[i]))ans=1;
			else s[++tmp]=s[i];
		}
		n=tmp;
	}
	void divide(ll x)
	{
		cntp=0;
		for(int i=1;i<=tot;i++)
			if(x%pri[i]==0)
			{
				cntp++;
				t[cntp]=pii(pri[i],0);
				for(;x%pri[i]==0;x/=pri[i])
					t[cntp].y++;
				if((t[cntp].y%=3)==0)cntp--;
			}
		if(x>1)
		{
			ll y=ispsn(x);
			if(y)t[++cntp]=pii(y,2);
			else t[++cntp]=pii(x,1);
		}
		
	}
	ll calc()
	{
		ll ret=1;
		for(int i=1;i<=cntp;i++)
			for(int j=1;j<=t[i].y;j++)
				ret*=t[i].x;
		return ret;
	}

	void solve()
	{
		getpri();
		initialize();

		for(int i=1;i<=n;i++)
		{
			divide(s[i]);
			ll hx=calc(),hy;
			for(int j=1;j<=cntp;j++)
				t[j].y=3-t[j].y;
			hy=calc();

			int cx=G[hx],cy=G[hy];
			if(cx>=cy)ans++;
			G[hx]++;
		}
		printf("%d\n",ans);
	}
}
int main()
{
	Luan_Gao::solve();
	return 0;
}


Measured memory_bytes: 13568
import math
N,M = map(int, input().split())
l = [[int(i) for i in input().split()] for j in range(N)]

l.sort()
count = 0
i = 0
while(M > 0):
    M -= l[i][1]
    count += l[i][0]*l[i][1]
    if(M < 0):
        count -= abs(M)*l[i][0]
    i += 1
print(count)

Measured memory_bytes: 25864
N,T = map(int, input().split())
min_cost = 10**9
for i in range(N):
    c,t = map(int, input().split())
    if T >= t and min_cost > c:
        min_cost = c
if min_cost == 10**9:
    print("TLE")
    exit()
print(min_cost)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a * b) / 2 << endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,H,W;
int main(){
	H=read(),W=read(),n=read();
	printf("%d\n",(n-1)/max(H,W)+1);
	return 0;
}



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

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b)
{
    while (b != 0) swap(b, a %= b);
    return a;
}

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x : vect)
        cout << x << " ";
    cout << "\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//Top down:
int dp[100005];
int solve(int current, int n, vector<int> &vect,int k)
{
    //Base Case:


    dp[1] = 0;
    dp[2] = abs(vect[2] - vect[1]);



    for(int i = 3; i <= n; i++)
    {
        int res = INT_MAX;

        for(int start = max(i - k, 1); start < i; start++)
        {
            res = min(res, dp[start] + abs(vect[i] - vect[start]));
        }
        dp[i] = res;
    }

    return dp[n];



}



int main()
{
    FASTIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n,k;
    cin >> n>>k;

    vector<int>vect(n + 1);
    memset(dp, -1, sizeof dp);

    f(i, 1, n + 1)
    cin >> vect[i];

    cout << solve(n, n, vect,k) << "\n";

    return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <string>
#include <map>
#include <utility>

using namespace std;
typedef pair<int, int> facePair;

class Dice{
public:
    Dice(int labels[]);
    void rotate(char);
    void rotate(string);
    void spinClockwise();
    int getTop(){return t;};
    int getFront(){return s;};
    int getRight(){return e;};
    friend bool operator==(Dice &lhs, const Dice &rhs);

private:
    int t, s, e, w, n, b;
    void rotate(int &direction, int &opposite);
};

Dice::Dice(int labels[]){
    t = labels[0];
    s = labels[1];
    e = labels[2];
    w = labels[3];
    n = labels[4];
    b = labels[5];
}

void Dice::rotate(char direction){
    if(direction == 'N') rotate(n, s);
    if(direction == 'E') rotate(e, w);
    if(direction == 'S') rotate(s, n);
    if(direction == 'W') rotate(w, e);
}

void Dice::rotate(int &direction, int &opposite){
    int old = direction;
    direction = t;
    t = opposite;
    opposite = b;
    b = old;
}

void Dice::rotate(string directions){
    for(auto ch : directions) rotate(ch);
}

void Dice::spinClockwise(){
    int old = n;
    n = w;
    w = s;
    s = e;
    e = old;
}

bool operator==(Dice &lhs, const Dice &rhs){
    string directions("EEESEE");
    int t = rhs.t;
    int b = rhs.b;
    int n = rhs.n;
    int e = rhs.e;
    int s = rhs.s;
    int w = rhs.w;
    for(auto dir : directions){
        lhs.rotate(dir);
        if(lhs.t != t || lhs.b != b) continue;
        for(int i = 0; i < 4; ++i){
            lhs.spinClockwise();
            if(lhs.n == n && lhs.e == e && lhs.s == s && lhs.w == w){
                return true;
            }
        }
    }
    return false;
}


int main(){
    int labels1[6] = {}, labels2[6] = {};
    for(auto &face : labels1) cin >> face;
    for(auto &face : labels2) cin >> face;
    Dice dice1(labels1);
    Dice dice2(labels2);
    if(dice1 == dice2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1204
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where
 
import qualified Data.ByteString.Char8 as C8
import Data.Bool
import qualified Data.Char as C
import qualified Data.List as L
 
main :: IO ()
main = do
  [k] <- readInts
  readInts >>= output . solve k
 
solve :: Int -> [Int] -> _
solve k [a,b]
  | k == 1 = True
  | (b-a) <= k = not $ null $ filter (\v -> v `mod` k == 0) $ [a..b]
  | otherwise = k <= b-a
 
output :: _ -> IO ()
output = putStrLn . bool "NG" "OK"
 
-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

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

typedef long long int ll;
typedef vector<int> vi; 
typedef pair<int,int> pi; 
typedef vector<ll> vll; 


#define F first;
#define S second;
#define PB push_back;
#define MP make_pair;
#define rep(i, a, b) for (int i=a; i<b; i++)

int main(){
	ll t;
	cin >>t;
    if(t==1){
        cout <<"Hello World";
    }
    else if(t==2){
        ll a,b;
        cin>>a>>b;
        cout << a+b;
    }

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
 
int main() {
  int K, X; cin >> K >> X;
  int ans_min, ans_max;
  ans_min = X-(K-1);
  ans_max = X+(K-1);
  for (int i = ans_min; i <= ans_max; i++) {
    cout << i;
    if (i != ans_max) cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
X = list(map(int, input().split()))
Xs = sorted(X)
c1 = np.median(Xs[1:]).astype(int)
c2 = np.median(Xs[:-1]).astype(int)

for i in range(N):
    if X[i] < c1:
        print(c1)
    else:
        print(c2)

Measured memory_bytes: 34160
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

ll dp[3001][3001][4];

int main() {
    int r, c, k;
    cin >> r >> c >> k;
    auto v = make_v(r, c, 0);
    for (int i = 0; i < k; ++i) {
        int a, b, cc;
        scanf("%d %d %d", &a, &b ,&cc);
        v[a-1][b-1] = cc;
    }
    dp[0][0][1] = v[0][0];
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            for (int k = 0; k <= 3; ++k) {
                if(i+1 < r) {
                    chmax(dp[i+1][j][1], dp[i][j][k]+v[i+1][j]);
                    chmax(dp[i+1][j][0], dp[i][j][k]);
                }
                if(j+1 < c) {
                    if(k < 3) chmax(dp[i][j+1][k+1], dp[i][j][k]+v[i][j+1]);
                    chmax(dp[i][j+1][k], dp[i][j][k]);
                }
            }
        }
    }
    cout <<  *max_element(begin(dp[r-1][c-1]),end(dp[r-1][c-1])) << "\n";

    return 0;
}

Measured memory_bytes: 319832
using System;

namespace ALDS1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Int32.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            var array = new int[n];
            for(int i=0;i<n;i++) { array[i] = Int32.Parse(input[i]); }
            printArray(array);
            sort(array);
        }

        static void printArray(int[] array)
        {
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write("{0}",array[i]);
                if (i != array.Length - 1) { Console.Write(" "); }
            }
            Console.WriteLine();
        }

        static void sort(int[] array)
        {
            for(int i=1;i<array.Length;i++)
            {
                var v = array[i];
                int j = i - 1;
                while(j>=0&&array[j]>v)
                {
                    array[j + 1] = array[j];
                    j--;
                }
                array[j + 1] = v;

                printArray(array);
            }
        }
    }
}

Measured memory_bytes: 9416
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

class IntArray2D(val size1: Int, val size2: Int) {
  private val innerArray = IntArray(size1 * size2)

  operator fun get(i1: Int, i2: Int): Int = innerArray[i2 + size2 * i1]

  operator fun set(i1: Int, i2: Int, v: Int) {
    innerArray[i2 + size2 * i1] = v
  }
}

data class Query(val v: Int, val d: Int, val c: Int)

fun main(args: Array<String>) {
  val (n, m) = fastReadInts(2)
  val mutableGraph = Array(n, { mutableListOf<Int>() })
  repeat(m) {
    val (rawV1, rawV2) = fastReadInts(2)
    val v1 = rawV1 - 1
    val v2 = rawV2 - 1
    mutableGraph[v1].add(v2)
    mutableGraph[v2].add(v1)
  }
  val graph = mutableGraph.map { it.toIntArray() }

  val q = readLine()!!.toInt()
  val queries = Array(q, {
    val (vRaw, d, c) = fastReadInts(3)
    val v = vRaw - 1
    Query(v, d, c)
  })
  queries.reverse()

  val dp = IntArray2D(n, 11)

  fun dfs(v: Int, d: Int, c: Int) {
    if (dp[v, d] > 0) return
    for (k in d downTo 0) {
      if (dp[v, k] > 0) break
      dp[v, k] = c
    }

    if (d == 0) return

    for (u in graph[v]) {
      dfs(u, d - 1, c)
    }
  }

  for (query in queries) {
    dfs(query.v, query.d, query.c)
  }

  for (v in 0 until n) {
    println(dp[v, 0])
  }
}


Measured memory_bytes: 80012
# -*- coding: utf-8 -*-


class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper

    def roll_side(self):
        self.ahead, self.right, self.backward, self.left = self.left, self.ahead, self.right, self.backward


dice_info = Dice(list(map(int, input().split())))
q = int(input())

for i in range(q):
    upper, ahead = map(int, input().split())

    if upper is dice_info.left:
        dice_info.roll_east()
        
    elif upper is dice_info.right:
        dice_info.roll_west()

    while not (upper == dice_info.upper or ahead == dice_info.ahead):
        dice_info.roll_north()

    while upper != dice_info.upper:
        dice_info.roll_east()

    while ahead != dice_info.ahead:
        dice_info.roll_side()

    print(dice_info.left)


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll n, a, sma, t[10], sum;
vector<ll> vec, G;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

int main(void)
{
	int a[6], k;
	for (int i = 0; i < 5; i++) cin >> a[i];
	cin >> k;
	sort(a, a + 5);
	if (a[4] - a[0] <= k)
	{
		cout << "Yay!" << endl;
	}
	else
	{
		cout << ":(" << endl;
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 256
import math

N, K = map(int, input().split())

if N >= K:
    sum_ = (N - (K - 1)) / N
else:
    sum_ = 0

for i in range(1, min(N + 1, K)):
    y = math.ceil(math.log2(K / i))
    sum_ += pow(1 / 2, y) / N

print(sum_)


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(void){
    long long int X;
    cin>>X;
    long long int i=0;
    long long int a=100;
    while(a<X){
        a=a*(1+0.01);
        i++;
    }
    cout<<i<<endl;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int a, b, h; cin >> a >> b >> h;
	int ans = (a+b)*h/2;
	cout << ans << endl;
	


	return 0;

}


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

#入力
n=int(readline())
m=n+1
u,k,v=[0]*m,[0]*m,[0]*m
for i in range(1,m):
    u[i],k[i],*v[i]=map(int,readline().split())

d=[0]*m
f=[0]*m
flags=[False]*m
t=0
def dfs(now):
    global t
    t+=1
    d[now]=t
    flags[now]=True
    for nex in v[now]:
        if flags[nex]==False:
            dfs(nex)
    t+=1
    f[now]=t
now=1
while True:
    dfs(now)
    for i in range(1,m):
        if flags[i]==False:
            now=i
            break
    else:
        break

for i in range(1,m):
    print(i,d[i],f[i])


Measured memory_bytes: 5672
import java.util.HashMap;
import java.util.Scanner;


public class Main {
	
       public static void main(String[] args) {
    	  Scanner input=new Scanner( System.in);
    	  
    	  int ans=0;
    	  int n=input.nextInt();
    	  int m=input.nextInt();
    	  int []a=new int[100005];
    	  HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
    	  long min=(long) 1e18;
    	  long dmax=(long) -1e18;
    	  for(int i=1;i<=n;i++)
    	  {
    		  a[i]=input.nextInt();
    		  min=Math.min(a[i], min);
    		  dmax=Math.max(dmax, a[i]-min);
    	  }
    	  //System.out.println(dmax);
    	  min=(long) 1e18;
    	  for(int i=1;i<=n;i++)
    	  {
    		  min=Math.min(a[i], min);
    		  if(a[i]-min==dmax)
    		  {
    			  ans++;
    		  }
    	  }
    	  System.out.println(ans);
          
	}
}


Measured memory_bytes: 48676
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;


int main(int argc, char* argv[]){
	int K;
	scanf("%d", &K);
	int init=0;
	int i = 0;
	while(K>init){
		init += 7 * pow(10.0, i);
		i++;
	}
//	printf("%d\n",init);
	vector<int> syo;
	int warukazu = init;
	int flag = false;
	for(int i=0; i<10000000; i++){
		syo.push_back(warukazu / K);
//		printf("%d\n", syo[i]);
		int amari = warukazu % K;
		if(amari==0){
			flag = true;
			break;
		}else{
			warukazu = amari*10+7;
		}
	}
	if(flag){
		int syo_log10 = (int)syo.size()-1;
		int K_log10 = (int)log10((float)(K));
		if((float)K/pow(10.0, K_log10)<=7.77777){
			int answer = syo_log10 + K_log10 + 1;
//			printf("%d %d %d\n", syo_log10, K_log10, answer);
			printf("%d\n", answer);
		}else{
			int answer = syo_log10 + K_log10 + 2;
//			printf("%d %d %d\n", syo_log10, K_log10, answer);
			printf("%d\n", answer);
		}
	}else{
		printf("%d\n", -1);
	}


}


Measured memory_bytes: 69516
import java.util.Scanner;

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        if (n % k == 0)
            System.out.println(0);
        else
            System.out.println(1);
    }
}

Measured memory_bytes: 21716
while True:
    H, W = map(int,input().split())
    if H + W == 0:
        exit()
    s = "#" * W
    d = "#" + "." * (W - 2) + "#"
    print(s)
    for i in range(H-2):
        print(d)
    print(s)
    print("")


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

int main(){
    ll s;
    cin >> s;
    vector<ll> a(1000010);
    ll i = 0;
    map<ll, ll> seen;
    a[0] = s;
    seen[a[i]]++;
    while(true){
        if(a[i] % 2 == 0) a[i+1] = a[i] / 2;
        else a[i+1] = 3 * a[i] + 1;
        seen[a[i+1]]++;
        if(seen[a[i+1]] > 1){
            cout << i+2 << endl;
            break;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::map;
int n,i,j,rank;
char suit;
bool card[4][13];
// map<char,int> suit2id={{'S',0},{'H',1},{'C',2},{'D',3}};
// map<int,char> id2suit={{0,'S'},{1,'H'},{2,'C'},{3,'D'}};
map<char,int> suit2id;
char id2suit[4]={'S','H','C','D'};
int main(void){
  suit2id['S']=0;
  suit2id['H']=1;
  suit2id['C']=2;
  suit2id['D']=3;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>suit>>rank;
    card[suit2id[suit]][rank-1]=true;
  }
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(!card[i][j])cout<<id2suit[i]<<" "<<j+1<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,a[100],ans=1145141919810364364;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=-100;i<=100;i++){
        int cnt=0;
        for(int j=0;j<n;j++){
            cnt+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main() {
	int ans = INT_MIN,mi=INT_MAX;
	int n;
	int tmp;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> tmp;
		ans = max(ans, tmp - mi);
		mi = min(mi, tmp);
		
	}
	

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3120
#if 0
date +%Y.%m.%d

不妨令 m = 1 ，设 n 为奇数。
将矩阵黑白染色，确定白色的值，然后令黑色的值为周围白色的值的 lcm + 1 。
一个简单的构造时在两个对角线上放质数，然后把白格子按两个对角线建坐标轴，
每个白色的值钦定为在在两个坐标轴上对应的质数的乘积。
那么每个黑色的格子一定是四个质数的乘积加一。
然而第 1000 个质数是 7000+ ，四个如此大小的质数相乘会超出范围。
因此放质数也有讲究，要把最大的和最小的交替放，避免两个大质数相乘。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
} read;

const int maxn = 505;
int prime[maxn << 1], tmp[maxn << 1], pp;
ll a[maxn][maxn];

ll gcd(ll x, ll y) {
	if(!y) return x;
	return gcd(y, x % y);
}

ll lcm(ll x, ll y) {
	if(!x or !y) return x + y;
	return x / gcd(x, y) * y;
}

int main() {
	int n = read;
	bool mark = !(n & 1);
	if(mark) ++ n;

	for(int x = 2; pp < n * 2; x ++) {
		bool ok = 1;
		for(int d = 2; d * d <= x; d ++)
			// XXX: 震惊！这里不强制转 bool 竟然会出错？！
			ok &= bool(x % d);
		if(ok)
			tmp[++ pp] = x;
	}

	for(int i = 1; i <= n; i ++)
		prime[i * 2 - 1] = tmp[i];
	for(int i = 1; i <= n; i ++)
		prime[pp - i * 2 + 2] = tmp[n + i];

	for(int i = 1; i <= n; i ++)
		a[i][i] = prime[i];

	for(int i = 1; i <= n; i ++)
		a[i][n - i + 1] = prime[n + i];

	for(int i = 1; i <= n; i ++)
		for(int j = (i & 1) ? 1 : 2; j <= n; j += 2)
			if(!a[i][j])
				a[i][j] = a[(i + j) >> 1][(i + j) >> 1] *
					a[(n + 1 + i - j) >> 1][(n + 1 + j - i) >> 1];

	for(int i = 1; i <= n; i ++)
		for(int j = (i & 1) ? 2 : 1; j <= n; j += 2)
			a[i][j] = lcm(a[i - 1][j], lcm(a[i][j - 1],
						lcm(a[i + 1][j], a[i][j + 1]))) + 1;

	if(mark) -- n;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= n; j ++)
			printf("%lld ", a[i][j]);
		puts("");
	}
}


Measured memory_bytes: 4992
def print_arr(arr):
	arr_str = ''
	for i in range(len(arr)):
		arr_str += str(arr[i])
		if i != len(arr) - 1:
			arr_str += ' '
	print(arr_str)

n = int(input())
arr = list(map(int, input().split()))

swap_count = 0
for i in range(n):
	mini = i
	for j in range(i, n):
		if arr[j] < arr[mini]:
			mini = j
	if mini != i:
		temp = arr[i]
		arr[i] = arr[mini]
		arr[mini] = temp
		swap_count += 1

print_arr(arr)
print(swap_count)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
 
#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef vector <vector <ll>> vvl;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n;

void read() {
  cin >> n;
}
void solve() {
  ll ans = 0;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ans += x - 1;
  }
  cout << ans << "\n";
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve(); 
  }
  return 0;
}


Measured memory_bytes: 256
str = list(input())
num = int(input())

for num in range(num):
	ord = input().split()
	start = int(ord[1])
	end = int(ord[2]) + 1
	
	if ord[0] == 'replace':
		rep = list(ord[3])
		for i in range(start, end):
			str[i] = rep[i - start]
			
	elif ord[0] == 'reverse':
		temp = ''.join(str[start:end])
		rev = list(temp[::-1])
		
		for i in range(start, end):
			str[i] = rev[i - start]
	else:
		print(''.join(str[start:end]))

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

using P = pair<ll,ll>;
#define v first
#define w second

// v高い順（vが同じならw軽い方優先）
bool comp(P a, P b){
    return a.v == b.v ? a.w < b.w : a.v > b.v;
}

int main(void){
    ll N,W;
    cin>>N>>W;
    vector<P> a(N);
    rep(i,N){
        ll v,w;
        cin>>v>>w;
        a[i] = {v,w};
    }
    vector<P> dp = {{0,0}};

    rep(i,N){
        vector<P> tmp;
        for(P s : dp){
            tmp.push_back(s);
            tmp.push_back({s.v + a[i].v, s.w + a[i].w});
        }

        sort(all(tmp),comp);
        dp.clear();
        ll w_border = W+1;
        for(P s : tmp){
            if( w_border > s.w){
                w_border = s.w;
                dp.push_back(s);
            }
        }
        assert((ll)dp.size() <= N*N+1);
    }
    cout<<dp[0].v<<endl;
    return 0;
}



Measured memory_bytes: 3212
/*  ex3_2
    kosaq       */

#include <stdio.h>

int main(void){
    int n_pen;    //n_pen means the number of pencils(N)
    int first_digit;    // the first digit of N

    scanf("%d", &n_pen);    //output N
    first_digit = n_pen % 10;    //this formula represents the first digit of N


    if(first_digit == 2 || first_digit == 4 || first_digit == 5 || first_digit == 7 || first_digit == 9){    //if the first digit is 2 or 4 or 5 or 7 or 9
        printf("hon\n");    //output hon
    }
    else if(first_digit == 0 || first_digit == 1 || first_digit == 6 || first_digit == 8){    //if the first digit is 0 or 1 or 6 or 8
        printf("pon\n");    //output pon
    }
    else {    //the first digit is 3
        printf("bon\n");    //output bon
    }

    return 0;
}

Measured memory_bytes: 1628
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
pair<int,int> a[300010],c;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q;
int main(){int n,r=0;cin>>n;for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;sort(a,a+n);long long s=0;for(int i=0;i<n;i++){s+=a[i].x,c.x=a[i].y,c.y=a[i].x;Q.push(c);while(!Q.empty()){if(s<=Q.size()*Q.top().x)break;s-=Q.top().y,Q.pop();}if(r<Q.size())r=Q.size();}cout<<r<<endl;return 0;}

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

const int maxn = 40005;
char s[maxn];
int t[5][maxn];

int v( char c ){
    if ( c == 'R' ) return 0;
    if( c == 'G' )return 1;
    return 2;
}

int suma( int val, int a, int b ){
    if( a > b )return 0;
    return t[val][b] - t[val][a-1];
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm

    int n;
    cin >> n >> (s+1);

    for( int i = 1; i <= n; i++ ){
        for( int j = 0; j < 3; j++ )
            t[j][i] = t[j][i-1];
        t[v(s[i])][i]++;
    }

    long long sol = 0;
    for( int i = 1; i <= n; i++ ){
        for( int j = i+1; j <= n; j++ ){
            if( s[i] == s[j] )continue;

            int k = j + (j-i);
            int val = 0;
            while( val == v(s[i]) || val == v(s[j]) )val++;
            sol += suma(val, k+1, n);
            sol += suma(val, j+1, min(k-1, n));
        }
    }

    cout << sol << "\n";

    return 0;
}


Measured memory_bytes: 3676
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int p = 2019;
        char c[] = str.toCharArray();
        int n = str.length();
        int[] d = new int[n+1];
        int ten = 1;
        for (int i = n - 1; i >= 0; i--) {
            int a = (c[i] - '0') * ten % p;
            d[i] = (d[i+1]+a) % p;
            ten *= 10;
            ten %= p;
        }
        
        int[] cnt = new int[p];
        long ans = 0;
        for (int i = n; i >= 0; i--) {
            ans += cnt[d[i]];
            cnt[d[i]]++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 41740
//#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <queue>
#include <stack>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define umap unordered_map
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

string a, b, c;
void solve() {
  cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 764
//1回の移動で行ける範囲→2回の移動で行ける範囲→4回の移動で行ける範囲…をダブリングで求める。
//移動回数を2分探索, 2^n回単位でシミュレーションする。
//O(Q * log^2n)
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n;
int x[100000];
int a[100001];			//累積和
int l;
int q;
int from, to;

int _right[20][100000];	//_right[i][j] = ホテルjから2^i日右移動して到達できる最も右のホテルの番号
int _left[20][100000];	//_left[i][j]  = ホテルjから2^i日右移動して到達できる最も左のホテルの番号

//ホテル[l, r]間の距離
int dist(int l, int r) {
	if (l > r) swap(l, r);
	return x[r] - x[l];
}

bool checkL(int mid) {
	int i = 19;
	int pos = from;
	
	while (i >= 0) {
		if ((mid >> i) % 2 == 1) pos = _left[i][pos];
		i--;
	}
	return (pos <= to);
}

bool checkR(int mid) {
	int i = 19;
	int pos = from;
	
	while (i >= 0) {
		if ((mid >> i) % 2 == 1) pos = _right[i][pos];
		i--;
	}
	return (pos >= to);
}

bool check(int mid) {
	if (from >= to) return checkL(mid);
	return checkR(mid);
}

signed main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> x[i];
	cin >> l;
	
	//前処理
	j = 0;
	for (i = 0; i < n; i++) {	//ホテルiからスタート
		for (j = max(j, i); j < n && dist(i, j) <= l; j++); j--;
		_right[0][i] = j;
	}
	for (i = 1; i < 20; i++) {
		for (j = 0; j < n; j++) {
			_right[i][j] = _right[i-1][_right[i-1][j]];
		}
	}
	
	j = n - 1;
	for (i = n - 1; i >= 0; i--) {	//ホテルiからスタート
		for (j = min(j, i); j >= 0 && dist(i, j) <= l; j--); j++;
		_left[0][i] = j;
	}
	for (i = 1; i < 20; i++) {
		for (j = 0; j < n; j++) {
			_left[i][j] = _left[i-1][_left[i-1][j]];
		}
	}
	
	//クエリ
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> from >> to;
		from--;
		to--;
		
		//移動回数で2分探索
		int st = 0, ed = n + 5, mid;	//xxxxxooooo, (st, ed]
		while (ed - st >= 2) {
			mid = (st + ed) / 2;
			if (check(mid)) { ed = mid; }
			else { st = mid; }
		}
		cout << ed << endl;
	}
	return 0;
}

Measured memory_bytes: 32896
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const ll MOD = 998244353;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

ll dp[4005][4005];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll n = s.size();
  ll r[n], b[n];
  REP(i,n){
      r[i] = 0;
      b[i] = 0;
  }
  REP(i,n){
      if(s[i] == '0'){
          r[i] += 2;
      }else  if(s[i]=='1'){
          r[i]++;
          b[i]++;
      }else{
          b[i]+=2;
      }
      if(i!=0){
          r[i] += r[i-1];
          b[i] += b[i-1];
      }
  }
  
  dp[0][0] = 1;
  REP(i,2*n){
      REP(j,i+1){
          if(i<n){
              if(r[i]>=j+1){
                  dp[i+1][j+1] += dp[i][j];
                  dp[i+1][j+1] %= MOD;
              }
              if(b[i]>=i+1-j){
                  dp[i+1][j] += dp[i][j];
                  dp[i+1][j] %= MOD;
              }
          }else{
              if(r[n-1]>=j+1){
                  dp[i+1][j+1] += dp[i][j];
                  dp[i+1][j+1] %= MOD;
              }
              if(b[n-1]>=i+1-j){
                  dp[i+1][j] += dp[i][j];
                  dp[i+1][j] %= MOD;
              }
    
          }
      }
  } 
   ll ans = 0;

  REP(i,2*n+1){
      ans += dp[2*n][i];
      ans %= MOD;
  }
  if(n==1){
      if(s[0] == '1'){
          ans = 2;
      }else{
          ans = 1;
      }
  }
  cout << ans << endl;

  

}

Measured memory_bytes: 123776
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, l[MAX];
  scanf("%d", &n);
  rep(i, 0, n) scanf("%d", &l[i]);

  int max = 0;
  int sum = 0;
  rep(i, 0, n)
  {
    max = max(max, l[i]);
    sum += l[i];
  }
  sum -= max;
  if (max < sum)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;
long long N,M,A,B,ans;
int main(){
  cin >> N >> M;
  ans =1;
  for(A=1;A*A<=M;A++){
    B = M/A;
    if(M%A!=0){
      continue;
    }
    if(A*N<=M){
      ans = max(ans,A);
    }
    if(B*N<=M){
      ans = max(ans,B);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  char c;cin>>c;
  char str[27] = "abcdefghijklmnopqrstuvwxyz";
  int r_index;
  REP(i,26) {
    if(str[i]==c) r_index = i;
  }
  p(str[r_index+1]);
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int x, y;
int a[7] = {1, 3, 5, 7, 8, 10, 12};
int b[4] = {4, 6, 9, 11};
int c[1] = {2};
bool flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;

int main ()
{
	scanf ("%d %d", &x, &y);
	if (x == 2 || y == 2){
		printf ("No\n");
		return 0;
	}
	else{
		for (int i = 0; i < 7; i++){
			if (x == a[i])	flag1 = 1;
			if (y == a[i])	flag2 = 1;
		}
		for (int i = 0; i < 4; i++){
			if (x == b[i])	flag3 = 1; 
			if (y == b[i])	flag4 = 1;
		}
	}
	if (flag1 == 1 && flag2 == 1){
		printf ("Yes\n");
		return 0;
	}
	if (flag3 == 1 && flag4 == 1){
		printf ("Yes\n");
		return 0;
	}
	printf ("No\n");
	return 0;
}


Measured memory_bytes: 128
# 190928 D

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A,B = list(map(int,input().split()))
soA = prime_factorize(A)
soB = prime_factorize(B)
output = []
for i in range(len(soA)):
    if soA[i] in soB:
        output.append(soA[i])

print(len(list(set(output))) + 1)


Measured memory_bytes: 3064
#include<stdio.h>
#define N 100000
int isPossible(int[],int,int,int);//judging whether the separating is possible or not
int main(void)
{
  int i;//counter
  int n;//the number of packages
  int k;//the number of trucks
  int w[N];//weights of each packages
  int p;//answer
  int minp=0;//possible minimum value of p
  int maxp=0;//possible maximum value of p
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++)
    {
      scanf("%d",&w[i]);
      if(minp<w[i]) minp=w[i];
      maxp+=w[i];
    }
  //find P as binary search
  p=(minp+maxp)/2;
  while(minp<maxp)
    {
      if(isPossible(w,n,k,p)==1) maxp=p;
      else minp=p+1;
      p=(minp+maxp)/2;
    }
  printf("%d\n",p);
  return 0;
}
int isPossible(int w[],int n,int k,int p)
{
  int i;//counter
  int num=1;//the number of trucks needed
  int temp=0;//temporary weight of packages
  for(i=0;i<n-1;i++)
    {
      temp+=w[i];
      //printf("%d ",w[i]);
      if(temp+w[i+1]>p)
	{
	  num++;
	  temp=0;
	  //printf("| ");
	}
    }
  //printf("\n");
  if(num<=k)
    {
      //printf("p=%d,num=%d:OK\n",p,num);
      return 1;
    }
  else
    {
      //printf("p=%d,num=%d:NG\n",p,num);
      return 0;
    }
}



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

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;

    if (s.size() <= k) {
        cout << s << endl;
    } else {
        string ans = "";

        for (int i = 0; i < k; i++) {
            ans += s[i];
        }

        ans += "...";

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	int a,b;cin>>a>>b;
    cout<<a*b<<endl;
}

Measured memory_bytes: 3600