akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  REP(i,n){
    if(A[i]%2==1) z++;
  }
  YES(z%2==0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
 int H,W;
  in(H>>W);
 vector<char> E={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

  rep(i,H){
   vs a(W);
    rep(j,W) in(a[j]);
    rep(j,W){
     if(a[j]=="snuke") out(E[j]<<i+1);
    }
    
  }
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main() {
    ll a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    ll ans = - LINF;
    ans = max(a*c, b*d);
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 int a[n];
 int i;
 int sum=0;
 for(i=0;i<n;i++)
 {
 cin>>a[i];
 sum+=a[i];
 }
 float m=1.0;
 m*=sum;
 m/=n;
 float x=m-floor(m);
 if(x>=0.5 && sum>=0)
 {
 	int p=m+1;
 	int ans1=0;
 	for(i=0;i<n;i++)
 	ans1+=pow(abs(a[i]-p),2);
 //	cout<<ans<<endl;
 	 p=m;
 	int ans2=0;
 	for(i=0;i<n;i++)
 	ans2+=pow(abs(a[i]-p),2);
 	cout<<min(ans1,ans2)<<endl;
 }
 else
 {
 	 		int p=m+1;
 	int ans1=0;
 	for(i=0;i<n;i++)
 	ans1+=pow(abs(a[i]-p),2);
 	 p=m;
 	int ans2=0;
 	for(i=0;i<n;i++)
 	ans2+=pow(abs(a[i]-p),2);
 	cout<<min(ans1,ans2)<<endl;
 }
 return 0;
}


Measured memory_bytes: 256
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0]);
    var K = Number(lines[0].split(" ")[1]);
    var A = lines[1].split(" ").map(i => Number(i));
    var ans;

    if (K < N) {
        N -= K;
        ans = Math.ceil(N / (K - 1)) + 1
    }
    else {
        ans = 1;
    }
    console.log(ans)
});

Measured memory_bytes: 17228
import java.util.*;

public class Main{

	private void doit(){
		Scanner sc = new Scanner(System.in);
		int dataset = sc.nextInt();
		while(dataset-- > 0){
			int p = sc.nextInt();
			int q = sc.nextInt();
			int maxrange = Math.max(p, Math.max(-p, Math.max(q, -q)));
			int minrange = Math.min(p, Math.min(-p, Math.min(q, -q)));
			int count = 0;
			for(int m = minrange; m <= maxrange; m++){
				for(int n = minrange; n <= maxrange; n++){
					if(m == 0 && n == 0) continue;
					int a = m * p + n * q;
					int b = m * q - n * p;
					int mn = m * m + n * n;
					
					if(a % mn == 0 && b % mn == 0){
						count++;
					}
				}
			}
			System.out.println(count == 8 ? "P" : "C");
		}
	}


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 20376
#include<bits/stdc++.h>
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
#define SIEVELIM 10000000+10
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
inline int nextint(){ int temporary; scanf("%d",&temporary); return temporary; }
inline ll nextll(){ ll temporary; scanf("%lld",&temporary); return temporary; }
inline double nextdouble(){double temporary; scanf("%lf",&temporary); return temporary;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll leftChild(ll p ){return p<<1;}
ll rightChild(ll p ){return (p<<1)+1;}
inline ll mid(ll l, ll r){ return (l+r)/2;}
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define deb(x )     cerr << #x << " here "<< x; 
#define endl    "\n"
#define pb push_back
#define mp make_pair
#define all(cc) (cc).begin(),(cc).end()

inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }

template<typename T > void modulize(T & a, const T & b) { if (a >= b) { a %= b; } }
ll mulmod(ll a, ll b, ll m) { ll q = (ll)(((ld)a*(ld)b) / (ld)m); ll r = a*b - q*m; if (r>m)r %= m; if (r<0)r += m; return r; }
template <typename T, typename S>T expo(T e, S n) { T x = 1, p = e; while (n) { if (n & 1)x = x*p; p = p*p; n >>= 1; }return x; }
template <typename T>T power(T e, T n, T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mod(x*p, m); p = mod(p*p, m); n >>= 1; }return x; }
template <typename T>T powerL(T e, T n, T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; }return x; }
template <typename T> T InverseEuler(T a, T & m) { return (a == 1 ? 1 : power(a, m - 2, m)); }

inline int two(int n) { return 1 << n; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    
    int d,n;
    cin>>d>>n;

    if (!d)
    {
    	if (n<100)
    	{
    		cout<<n;
    	} else {
    		cout<<n+1<<endl;	
    	}
    } else {
    	ll num = 1;
    	F(i, 0, d){
    		num *= 100;
    	}
    	if (n<100)
    	{
    		cout<<num*n;
    	} else {
    		num = num*(n+1);
    		cout<<num;
    	}
    }
    return 0;          
}/*
    
*/
 

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

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<ll,ll> pii;

const ll MAX=2e5+9;
const ll INF=1e12;

ll A,B,C,pos;

int main()
{
   
	cin>>A>>B>>C;
	pos=min(C,(A+B+1));
	pos+=B;
	cout<<pos;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        k: usize,
    }

    if k % 2 == 0 {
        println!("-1");
        return;
    }

    let mut a = 7 % k;
    let mut m = HashSet::new();
    let mut c = 1;
    while a % k != 0 {
        if !m.insert(a % k) {
            println!("-1");
            return;
        }
        c += 1;
        a = (a % k) * 10 + 7 % k;
    }
    println!("{}", c);
}


Measured memory_bytes: 29668
N=int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
sumA1=[A1[0]]
sumA2=[A2[-1]]
for i in range(2,N+1):
    sumA1.append(sumA1[-1]+A1[i-1])
    sumA2.append(sumA2[-1]+A2[-i])

sumA2.reverse()
ans=sumA1[0]+sumA2[0]
for i in range(1,N):
    ans=max(ans,sumA1[i]+sumA2[i])
print(ans)

Measured memory_bytes: 38256
#include<stdio.h>
using namespace std;

void outPut(int Array[],char mark){
	for(int i=1;i<=13;i++){
		if(Array[i]==0) printf("%c %d\n", mark,i);
	}
}

int main(){
	char mark[2]; //charは空白改行を読み込むため2文字分用意しておく
	int n,S[14],H[14],C[14],D[14],tmp;
	for(int i=0;i<14;i++) S[i]=H[i]=C[i]=D[i]=0;  //全部0を格納
	scanf("%d", &n);  //先頭の数字を読み込む

	for(int i=0;i<n;i++){
		scanf("%s %d\n", mark,&tmp);
		switch(mark[0]){
			case 'S':
				S[tmp]=1;
				break;
			case 'H':
				H[tmp]=1;
				break;
			case 'C':
				C[tmp]=1;
				break;
			case 'D':
				D[tmp]=1;
				break;
		}
	}
	outPut(S, 'S');
	outPut(H, 'H');
	outPut(C, 'C');
	outPut(D, 'D');
}


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

const int INF = 2e9;

int main(){
    ll x;
    cin >> x;
    ll ans = x/11*2;
    ll res = x%11;
    if(res == 0)cout << ans << endl;
    else if(0 < res && res < 7) cout << ans + 1 << endl;
    else cout << ans + 2 << endl;
}

Measured memory_bytes: 3616
def solve(A,op):
    result=[0]*4
    result[0]=A[0]
    for i in range(2):
        if i==0:
            result[1]=result[0]+A[1]
            op[0]="+"
        else:
            result[1]=result[0]-A[1]
            op[0]="-"
        for j in range(2):
            if j==0:
                result[2] = result[1]+A[2]
                op[1]="+"
            else:
                result[2] = result[1]-A[2]
                op[1]="-"
            for k in range(2):
                if k==0:
                    result[3] = result[2]+A[3]
                    op[2]="+"
                else:
                    result[3] = result[2]-A[3]
                    op[2]="-"
                #print("{}{}{}{}{}{}{}?7".format(A[0],op[0],A[1],op[1],A[2],op[2],A[3]))
                #print(result[3])
                if result[3]==7:
                    print("{}{}{}{}{}{}{}=7".format(A[0],op[0],A[1],op[1],A[2],op[2],A[3]))
                    return

def main():
    A=[0]*4
    op=[""]*3
    A=list(map(int,input()))
    solve(A,op)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		System.out.println((m-1)*(n-1));
	}

}


Measured memory_bytes: 21844
import itertools
def calc(a,op,b):
    if op=="+":
        return a+b
    if op=="-":
        return a-b
    if op=="*":
        return a*b
while True:
    nums=map(int,raw_input().split())
    if nums==[0,0,0,0]:
        break
    ans="0"
    for a,b,c,d in itertools.permutations(nums,4):
        if ans=="0":
            for ops in itertools.product(["+","-","*"],repeat=3):
                if calc(calc(a,ops[0],calc(b,ops[1],c)),ops[2],d)==10:
                    ans="(({}{}({}{}{})){}{})".format(a,ops[0],b,ops[1],c,ops[2],d)
                    break
                if calc(calc(a,ops[0],b),ops[1],calc(c,ops[2],d))==10:
                    ans="(({}{}{}){}({}{}{}))".format(a,ops[0],b,ops[1],c,ops[2],d)
    print ans

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

int main() {
  string s;
  cin >> s;
  if (s.at(2) == s.at(3)) {
    if (s.at(4) == s.at(5)) {
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;

int main()
{
	string s;
	int n;
	map< string, set<int> > index;
	map< string, set<int> >::iterator it;
	set<int>::iterator its;
	while (cin>>s>>n)
		index[s].insert(n);
	for (it = index.begin(); it != index.end(); it++) {
		cout<<(*it).first<<endl;
		for (its = index[(*it).first].begin(); its != index[(*it).first].end(); its++) {
			if (its != index[(*it).first].begin()) cout<<" ";
			cout<<*its;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
ansl1 = list("#" * (100 * 25))
ansl2 = list("." * (100 * 25))

a,b = map(int,input().split())

for i in range(a-1):
    ansl1[2*i] = "."

for i in range(b-1):
    ansl2[2*i] = "#"
print(100, 100)

for i in range(25):
    print("".join(ansl1[(i*100):(i*100)+100]))
    print("#"*100)

for j in range(24, -1, -1):
    print("".join(ansl2[(j*100):(j*100)+100]))
    print("." * 100)

Measured memory_bytes: 38384
dp = [999999] * 100100
n = int(input())
dp[0] = 0
for i in range(0, 100010):
    dp[i+1] = min(dp[i+1], dp[i] + 1)
    for j in range(1,100):
        c = i + 6**j
        if (c) > 100000:
            break
        dp[c] = min(dp[c], dp[i] + 1)

    for j in range(1,100):
        c = i + 9**j
        if (c) > 100000:
            break
        dp[c] = min(dp[c], dp[i] + 1)

#print(dp[:100])
print(dp[n])

Measured memory_bytes: 42860
#pragma GCC optimize("O4")
#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 (9e18)
#define int ll
#define EPS (1e-6)
#define DB(x) #x<<":"<<x<<" "
using namespace std;
using ll=long long;
using pii=pair<int,int>;

void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

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){
	b%=MOD;
	int ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int32_t main() {
	INIT();
	//code...
	string s; cin>>s;
	int now=0;
	int ans=0;
	For(i,0,sz(s)-1){
		if(s[i]=='W'){
			ans+=i-now;
			now++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


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

using namespace std;

const int N = 1e5 + 7;

bool viz[N][3];
int d[N][3];
pair < int, int > q[3 * N];
vector < int > E[N];
int st, dr(-1);

void bfs() {
    while (st <= dr) {
        int x = q[st].first;
        int n = q[st++].second;
        int m = n + 1 - (n == 2 ? 3 : 0);
        for (int y : E[x]) {
            if (!viz[y][m]) {
                viz[y][m] = 1;
                d[y][m] = d[x][n] + 1;
                q[++dr] = {y, m};
            }
        }
    }
}

int main()
{
    int n, m, a, b, s, t;
    cin >> n >> m;
    while (m--)
        cin >> a >> b, E[a].push_back(b);
    cin >> s >> t;
    viz[s][0] = 1;
    q[++dr] = {s, 0};
    bfs();
    if (viz[t][0])
        cout << d[t][0] / 3;
    else
        cout << -1;
    return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

constexpr int MAX_N = 10000000;
int par[MAX_N];
int r[MAX_N];

void init(int n){
    for(int i = 0; i < n; ++i){
        par[i] = i;
        r[i] = 0;
    }
}

int find(int x){
    if(par[x] == x){
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(r[x] < r[y]){
        par[x] = y;
    } else {
        par[y] = x;
        if(r[x] == r[y]) r[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

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

    int p[100001];
    for(int i = 0; i < N; ++i){
        cin >> p[i];
        --p[i];
    }
    init(N);
    for(int i = 0; i < M; ++i){
        int x, y;
        cin >> x >> y;
        --x, --y;
        unite(x, y);
    }

    int cnt = 0;
    for(int i = 0; i < N; ++i){
        if(same(i, p[i])) ++cnt;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n, m;
    cin >> n >> m;
    
    vector<ll> a(m),  b(m);
    rep(i, m)cin >> a[i] >> b[i];

    vector<ll> ord(m);
    iota(ALL(ord), 0);

    sort(ALL(ord), [&](ll x, ll y){
        return b[x] < b[y];
    });

    ll ans = 0;
    ll back = -1;
    rep(i, m){
        if(a[ord[i]] < back)continue;
        
        ans++;
        back = b[ord[i]];
    }

    cout << ans << endl;
}


Measured memory_bytes: 5636
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
const int maxn = 1e5 + 10;
int s[maxn], n, L, Q;
int cnt[maxn], c[36][maxn];

int main(){
	s[0]=0;
	while(~scanf("%d", &n)){
		for(int i=1; i<=n; i++) scanf("%d", &s[i]);
		scanf("%d", &L);
		for(int i=1; i<n; i++){
			int tmp=cnt[i-1];
			while(s[tmp]-s[i]<=L && tmp <=n) tmp++;
			cnt[i]=tmp-1;
			c[0][i]=tmp-1;
		}
		c[0][n]=n;
		for(int i=1;i<25;i++)
			for(int j=1;j<=n;j++)
				c[i][j]=c[i-1][c[i-1][j]];
		scanf("%d", &Q);
		while(Q--){
			int a, b, ans=0;
			scanf("%d%d", &a, &b);
			if(a>b) swap(a,b);
			int tmp=a, sum=0;
			
			while(a<b){
				int ss=0;
				for(ss=0;ss<25;ss++){
					if(c[ss][a]>=b) break; 
				}
				if(ss>0) ss--;			
				a=c[ss][a];
				ans+=1<<ss;
			//	cout<<a<<endl;
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}
/*
4
1 3 5 7
2
4
1 2
1 4
2 3
2 4
*/


Measured memory_bytes: 11392
x,y, a, b, c= map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))

fr = sorted(red, reverse= True)[:x]
fg = sorted(green, reverse= True)[:y]
candidate = fr + fg + trans
candidate = sorted(candidate, reverse= True)
candidate = candidate[:x+y]
print(sum(candidate))

Measured memory_bytes: 23328
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int ans = 0;
    rep(i, 5) {
        int a;
        cin >> a;
        if (a == 0) ans = i+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

require 'pp'

def dfs(e,s)
	stack = [] # stack
	f = Array.new(e.size){false} # is searched flag
	d = Array.new(e.size)
	tr = Array.new(e.size){nil}
	# init
	f[s]=true
	d[s]=0
	tr[s]=s
	e[s].each{|v|
		stack.push([v,s,1]) #v,d to v
	} 
	while(!stack.empty?)
		curv,curp,curd = stack.pop
		f[curv]=true
		d[curv]=curd
		tr[curv]=curp
		dputs "(curv,curd,curp) = (#{curv},#{curd},#{curp})"
		e[curv].each{|v|
			if !f[v]
				stack.push([v,curv,curd+1])
			end
		}
	end
	return d
end

N,_=gets.chomp.split(' ').map{|n| n.to_i}
E = Array.new(N){[]}
1.upto(N-1){
	p=gets.chomp.split(' ').map{|n| n.to_i}
	p[0]-=1
	p[1]-=1
	E[p[0]].push(p[1])
	E[p[1]].push(p[0])
}
fd = dfs(E,0)
sd = dfs(E,N-1)
fcnt = 0
scnt = 0
for i in 0..(N-1)
	fd[i] <= sd[i] ? fcnt+=1 : scnt+=1
end
puts fcnt > scnt ? "Fennec" : "Snuke"



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

using namespace std;

int main() {
    long long N;
    long long p[5];
    long long minp;

    cin >> N;

    for(int i = 0; i<5 ;i++) {
        cin >> p[i];
        if(i == 0) minp = p[i];
        else minp = min(minp, p[i]);
    }
    if (N%minp == 0) {
        cout << 5 + (long long)(N / minp) - 1 << endl;
    } else {
        cout << 5 + (long long)(N / minp) << endl;
    }
}

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

void solve(){
    char a;
    cin >> a;
    char b = a+1;
    cout << b << endl;
}



int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(0);
    // freopen("a.txt","r",stdin);
    solve();
    return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>; 

int main(){
    ll x; cin>>x;
    while(true){
        bool non;
        non = false;
        for(int i = 2;i < sqrt(x);i++){
            if(x%i == 0){
                non = true;
            }
        }
        if(!non){
            cout<<x<<endl;
            break;
        }else ++x;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int i,j,k,v,N;
  
  scanf("%d",&N);
  j=N;
  int A[N];
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N;i++){
    
    v=A[i];
    
    j=i-1;
    
    while(j>=0 && A[j]>v){
      
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
      
    }
    
    for(k=0;k<N;k++){
      if(k!=N-1) printf("%d ",A[k]);
      else printf("%d",A[k]);
    }
    printf("\n");
  }
  
  
  return 0;
}



Measured memory_bytes: 2124
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 1000
    for i in range(n - 1):
        if a[i] < a[i + 1]:
            buy = ans // a[i]
            sell = buy * a[i + 1]
            ans += sell - buy * a[i]
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9196
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

vector<ll> v;
ll ans[10];
ll h, w, n;

int main()
{
    scanf("%lld%lld%lld", &h, &w, &n);
    ans[0] = (h-2)*(w-2);
    while (n--)
    {
        ll a, b;
        scanf("%lld%lld", &a, &b);
        for (int i = -1; i <= 1; ++i)
            for (int j = -1; j <= 1; ++j)
                if (a+i >= 2 && a+i <= h-1 && b+j <= w-1 && b+j >= 2)
                    v.push_back(mod*(a+i)+b+j);
    }
    sort(v.begin(), v.end());
    v.push_back(0);
    int cnt = 1;
    for (int i = 0; i < v.size(); ++i)
    {
        if (v[i] == v[i+1]) ++cnt;
        else ans[cnt]++, cnt = 1, ans[0]--;
    }
    for (int i = 0; i < 10; ++i)
        printf("%lld\n", ans[i]);
	return 0;
}


Measured memory_bytes: 10220
s = input()
n = len(s)

r = 0
b = 0
ans = 0

for i in range(n):
    if s[i] == "0":
        r += 1
    elif s[i] == "1":
        b += 1
    
    if 0 < r and 0 < b:
        r -= 1
        b -= 1
        ans += 2

print(ans)
    

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//127 A
int main(void) {
	int a, b;
	cin >> a >> b;
	if (a >= 13)cout << b << endl;
	else if (a >= 6)cout << b / 2 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;


pair<double, double>a[(int)1e5 + 7];

double dis(pair<double, double>x, pair<double, double>y) {
	return sqrt((x.first - y.first) * (x.first - y.first) + ((x.second - y.second) * (x.second - y.second)));
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	double ans = 0;
	
	double low = 1;
	for (int i = 1; i <= n; i++) {
		low *= i;
	}
	

	vector<int>v;
	for (int i = 0; i < n; i++) {
		v.push_back(i);
	}
	int cnt = 0;
	do {

		for (int i = 0; i < n - 1; i++) {
			ans += dis(a[v[i]], a[v[i + 1]]);
		}
		
	} while (next_permutation(v.begin(),v.end()));
	std::cout << std::fixed << std::setprecision(9) << (ans / low) << endl;



}

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

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  sort(t, t + n);

  int bus = 0;
  int man = 0;
  while (man < n) {
    bus++;
    int fst = man;  // 最初に乗る人

    // 到着順に乗れるだけ乗っていく
    while (1) {
      man++;
      if (man >= n) break;             // 最後の人
      if (t[man] - t[fst] > k) break;  // 最初の人からk分以内
      if (man - fst >= c) break;       // 一度にc人まで
    }
  }

  cout << bus << endl;
  return 0;
}


Measured memory_bytes: 3988
"use strict";

function main(arg){
  const input = arg.trim().split(' ').map(_=>parseInt(_, 10)).sort((a,b)=>{return a-b});
  if(input[0] + input[1] == input[2])
    console.log("Yes");
  else
    console.log("No");
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 7372
var
	f,a:array[0..100010] of longint;
	n,i:longint;
function g(x,y:longint):longint;
begin
	g:=abs(a[x]-a[y]);
end;
function min(x,y:longint):longint;
begin
	if x<y then exit(x) else exit(y);
end;
begin
	readln(n);
	for i:=1 to n do read(a[i]);
	f[1]:=0;
	f[2]:=g(1,2);
	for i:=3 to n do
		f[i]:=min(f[i-1]+g(i,i-1),f[i-2]+g(i,i-2));
	writeln(f[n]);
end.

Measured memory_bytes: 896
"use strict";
var print=function(line){
    for(var i=0;line[i] != 0;i++)
        console.log("Case "+(i+1)+": "+line[i]);
};
function Main(input) {
    input=input.split("\n").map(Number);
    print(input);
}
function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20520
import java.util.Scanner;

public class Main{

	void run() {
		Scanner sc = new Scanner(System.in);
		while(true){
		    int n = sc.nextInt();
		    if(n==0) break;
		    int s=0;
		    for(int i=0;i<n/4;i++) s += sc.nextInt();
		    System.out.println(s);
		}
	}

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


Measured memory_bytes: 26408
#include<stdio.h>
#include<limits.h>

#define N 20001
#define nil -1
#define WHITE 0
#define BLACK 1

int n,G[N][N];

int prim(int , int);

int main(){

  int i,j,w=-1,r;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
      if(G[i][j]!=-1 && w==-1){ 
	w=G[i][j];
	r=i;
      }

    }
  }
 

  

  printf("%d\n",prim(w,r));
  
  return 0;
}


int prim(int w , int r){

  int i,u,v,d[N],pi[N],color[N],mincost,sum=0;

  for(u=0;u<n;u++){
    d[u]=99999999;
    pi[u]=nil;
    color[u]=WHITE;
  }
  d[r]=0;

  while(1){

    mincost=9999999;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
      if(mincost==9999999) break;

      color[u]=BLACK;

      for(v=0;v<n;v++){
	if(G[u][v]!=-1) w=G[u][v];
	else continue;
		
	if(color[v]!=BLACK && w<d[v]){
	  pi[v]=u;
	  d[v]=w;
	}
      }
  }
  for(i=0;i<n;i++) sum+=d[i];

  return sum;
}

Measured memory_bytes: 6868
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;

int main()
{
	int N;
	cin>>N;
	vector<vector<int>> yes(N),no(N);
	rep(i,N){
		int A;
		cin>>A;
		rep(j,A){
			int x,y;
			cin>>x>>y;
			x--;
			(y==0?no:yes)[i].push_back(x);
		}
	}

	int res=0;
	rep(way,(1<<N)){
		vector<bool> flags(N);
		rep(i,N)flags[i]=(way>>i)&1;

		bool safe=true;
		rep(i,N)if((way>>i)&1){
			for(auto num:yes[i])if(flags[num]==false)safe=false;
			for(auto num:no[i])if(flags[num]==true)safe=false;
		}
		if(safe){
			int cnt=0;
			int tmp=way;
			while(tmp>0)cnt+=tmp&1,tmp>>=1;
			res=max(res,cnt);
			//cout<<way<<endl;
		}
	}
	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define ll long long
using namespace std;
inline int read(){
	int k=1,sum=0;
	char c=getchar();
	for(;c<'0' || c>'9';c=getchar()) if(c=='-') k=-1;
	for(;c>='0' && c<='9';c=getchar()) sum=sum*10+c-48;
	return sum*k;
}
int h,w,a,b;
const int p=1e9+7;
ll fac[300000],inv[300000];
ll ans;
inline ll qsm(ll x,ll k)
{
	ll anss=1,base=x;
	while(k)
	{
		if(k&1) anss=(anss*base)%p;
		base=(base*base)%p;
		k>>=1;
	}
	return anss;
}		
inline ll C(int m,int n){
	if(m==n || m==0) return 1;
	return ((fac[n]*inv[m])%p*inv[n-m])%p;
}
int main(){
	fac[0]=1;
	for(int i=1;i<=200001;++i) fac[i]=(fac[i-1]*i)%p;
	h=read(),w=read(),a=read(),b=read();
	inv[200001]=qsm(fac[200001],p-2);
	for(re int i=200000;i>=1;--i) inv[i]=(inv[i+1]*(i+1))%p;
	for(re int i=1;i<=h-a;++i){
		//cout<<b-1<<" "<<i+b-2<<" "<<w-b-1<<" "<<w+h-b-i-1<<endl;
		//cout<<C(1,2)<<endl;
		ans=(ans+(C(b-1,i+b-2)*C(w-b-1,w+h-b-i-1))%p)%p;
	}
	cout<<ans;
	return 0;
}
/*
6 3
2 3
1 2 
1 4 
4 5 
4 6 
0 2 5 1 2 3 
1 5 
1 3 
2 6 
*/

Measured memory_bytes: 3840
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
using namespace std;
typedef pair<int,int> P;

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

Measured memory_bytes: 256
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=i
 if l<H and A[g]<A[l]:g=l
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 65136
from collections import deque
n,q = map(int,input().split())
time = 0
tl=deque()
d=dict()
for i in range(n):
    key,value = input().split()
    d[key] = int(value)

for i in d.items():
    tl.append(i)
#print(tl)

while len(tl)!=0:
    tmp = tl.popleft()
    if list(tmp)[1] <= q:
        time+=list(tmp)[1]
        #print(m[1])
        #print(time)
        #list(m)[1]=time
        print(f"{list(tmp)[0]} {time}")
    else:
        time+=q
        l=list(tmp)#tupleの中身書き換える時はlist型にしなきゃいけないからめんどい
        l[1]-=q
        nt=tuple(l)
        tl.append(nt)
        

"""

def main():
    n,q = map(int,input().split())
    que = []
    for _ in range(n):
        name,time = input().split()
        que += [[name, int(time)]]
    anst = 0
    while que ! = []:
        temp = que.pop(0)
        if temp[1] <= q:
            anst += temp[1]
            print(f"{temp[0]} {anst}")
        else:
            anst += q
            que += [[temp[0],temp[1]-q]]
main()
"""


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; cin>>n;
	vector<int> l(n);
	rep(i,n) cin>>l[i];

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

	int ans=0;
	rep(j,n) rep(i,j) {
		ans+=lower_bound(l.begin()+j+1,l.end(),l[i]+l[j])
			-upper_bound(l.begin()+j+1,l.end(),abs(l[i]-l[j]));
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T, class U> inline int add(T& a, U bb, T M = MOD){T b = bb;a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T, class U> inline int mul(T& a, U bb, T M = MOD){T b = bb;if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret);
  if(n%2)((ret *= a));
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}

vector<ll> fac, finv, inv;
void COMinit(const int MAX = 5000000, const ll &MOD = MOD){
  fac.resize(MAX);finv.resize(MAX);inv.resize(MAX);
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  repd(i,2,MAX){
    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 COM(int n, int k){
  if(n < k)return 0;
  if(n < 0 || k < 0)return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


////////////////////////////////////////////////////////////////////

int n;string s, t;
vector<int> v;
signed main(){
  cin>>n>>s>>t;
  rep(i,n){
    if(s[i] == t[i])v.push_back(1);
    else{
      v.push_back(0);i++;
    }
  }
  int ans = (v[0] ? 3 : 6);
  repd(i,1,v.size()){
    if(v[i]){
      if(v[i-1]){
        mul(ans, 2);
      }
    }else{
      if(v[i-1]){
        mul(ans, 2);
      }else{
        mul(ans, 3);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int keta ( ll a ) {
    int cnt = 0;
    while(a>0) {
        a /= 10;
        ++cnt;
    }
    return cnt;
}

int main(){
    ll n;
    cin >> n;

    int ans = keta(n);

    for ( ll i = 1LL; i * i <= n; ++i ) {
        if ( n % i != 0 ) {
            continue;
        }
        ll b = n/i;
        int keta_a = keta(i);
        int keta_b = keta(b);
        int bigger_num = max(keta_a, keta_b);
        if ( ans > bigger_num ) {
            ans = bigger_num;
        }
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    int p = min(a, b);
    int q = max(a, b);
    int ans = max(0, q - p - w);
    cout << ans << endl;
    return 0;
}

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

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	vector <int> arr(3);

	for (int i = 0; i < 3; ++i)
		cin >> arr[i];

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

	cout << arr[0] + arr[1];
	
	return 0;
}

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




int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> A(H, vector<char>(W));

	//int count = 0;

	queue<vector<int>> q;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
			if (A[i][j] == '#') {
				q.push({ i,j });
			}
		}
	}
	if (q.size() == H * W) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> dirx = { -1,0,1,0 };
	vector<int> diry = { 0,-1,0,1 };

	int res = 0;

	vector<vector<int>> v(H, vector<int>(W, 1));
	int count = q.size();
	int step=0;
	while (count < H*W) {
		step++;
		int n = q.size();
		for (int i = 0; i < n; i++) {
			vector<int> tmp = q.front();
			q.pop();
			if (tmp[0] < 0 || tmp[0] >= H || tmp[1] < 0 || tmp[1] >= W || v[tmp[0]][tmp[1]] == 0) continue;
			else {
				v[tmp[0]][tmp[1]] = 0;
				if (A[tmp[0]][tmp[1]] != '#') {
					A[tmp[0]][tmp[1]] = '#';
					count++;

				}
				for (int k = 0; k < 4; k++) {
					q.push({ tmp[0] + dirx[k],tmp[1] + diry[k] });
				}
			}
		}
	}

	cout << step-1 << endl;
	return 0;
}


Measured memory_bytes: 143040
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while(true){
        cin>>H>>W;
        if(H==0 && W==0){
            break;
        }
        for(int j=0; j<W; j++){
            cout<<'#';
        }
        cout<<endl;
        for(int i=1; i<H-1; i++){
            cout<<'#';
            for(int j=1; j<W-1; j++){
                cout<<'.';
            }
            cout<<'#'<<endl;
        }
        for(int j=0; j<W; j++){
            cout<<'#';
        }
        cout<<endl<<endl;
    }
}



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

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

    string s[3];

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
        char c1, c2, c3;
        c1 = s[0][i];
        c2 = s[1][i];
        c3 = s[2][i];

        if (c1 != c2) {
            ans++;
        }

        if (c1 != c3 && c2 != c3) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int ans;
char S[5];

int main(void) {
    scanf("%s", S);
    
    ans = 700;
    
    int x = 0;
    REP(i, 0, 3) if (S[i] == 'o') ans += 100;
    
    
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
<?php

while (true) {
    $height_width = explode(" ", trim(fgets(STDIN)));
    $h = $height_width[0];
    $w = $height_width[1];
    if ($h == 0 && $w == 0){
        break;
    }
    for($i = 1; $i <= $h; $i++){
        for($j = 1; $j <= $w; $j++){
            if ($i % 2 == 0 && $j % 2 == 1 || $i % 2 == 1 && $j % 2 == 0) {
                echo '.';
            } else {
                echo '#';
            }
        }
        echo PHP_EOL;
    }
    echo PHP_EOL;
}

Measured memory_bytes: 15408
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    if(m==n)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}









Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define ll long long
#define mod 1000000007LL
#define INF 123456789012345
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e4 + 10;

ll keta(ll n)
{
	ll ans = 0;
	while(n)
	{
		n /=10;
		ans++;
	}
	return  ans;
}

int main() {
	
	ll n;cin>>n;
	ll cnt = 0;
	ll ans= INF;
	while(cnt * cnt <= n)
	{
		cnt++;
		if(n%cnt != 0) continue;

		ans = min(ans,keta(n/cnt));
	}


	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 384
n=int(input())
l=[int(i) for i in input().split()]
dp=[-1]*(n)
dp[0]=0
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i-2]-l[i]))
            
print(dp[-1])


Measured memory_bytes: 20468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){
    int n;
    cin >> n;
    int a[3][n+10];
    rep(i,n){
        cin >> a[0][i];
    }
    rep(i,n){
        cin >> a[1][i];
    }
    int m = 0;
    rep(i,n){
        int sum = 0;
        for(int j=0; j<=i; j++){
            sum += a[0][j];
        }
        for(int k=i; k<n; k++){
            sum += a[1][k];
        }
        m = max(m,sum);
    }
    cout << m << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1e18L + 5;
int main() {
    string s,t;
    cin>>s>>t;
    int l1=s.length();
    int l2=t.length();
    int n=max(l1,l2);
    int dp[n+1][n+1]={0};
    int ans=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=0;
        }
    }
    int maxx=0,row=0,col=0;
    for(ll i=1;i<=l1;i++){
        for(ll j=1;j<=l2;j++){
            if(s[i-1]==t[j-1]){
             dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
            }
            else{
               dp[i][j]= max(dp[i][j-1],dp[i-1][j]);
            }
            if(dp[i][j]>maxx){
                maxx=dp[i][j];
                row=i-1;
                col=j-1;
            }
        }
    }
    string fin;
    while(dp[row+1][col+1]!=0){
        if(s[row]==t[col]){
            fin+=s[row];
            row--;
            col--;
        }
        else if(dp[row][col+1]>dp[row+1][col])
            row--;
        else col--;
    }
    reverse(fin.begin(),fin.end());
    cout<<fin;
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main(void) {
    int N;
    cin>>N;
    map<string, int> mp;
    for (int i = 0; i < N; i++) {
        string s;
        cin>>s;
        if (mp.find(s) != mp.end()) mp[s] += 1;
        else mp[s] = 1;
    }
    map<int, set<string> > result;
    for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
        result[it->second].insert(it->first);
    }
    map<int, set<string> >::iterator result_p = result.end();
    result_p--;
    set<string> e = result_p->second;
    for (set<string>::iterator it = e.begin(); it != e.end(); ++it) cout << *it << endl;
    return 0;
}

Measured memory_bytes: 42624
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
struct po{
    int a,b;
}f[100010];
bool cmp(po x,po y)
{
    if(x.a==y.a)
        return x.b<y.b;
    return x.a<y.a;
}
int main()
{
    int n,m,ans=0,t=INF;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
        scanf("%d%d",&f[i].a,&f[i].b);
    sort(f+1,f+1+m,cmp);//for(int i=1;i<=m;i++)printf("%d %d %d %d\n",f[i].a,f[i].b,f[i].id,f[i].c);
    for(int i=m;i>=1;i--)
    {
        if(f[i].a!=f[i-1].a&&f[i].b<=t)
        {
            ans++;
            t=f[i].a;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
vector<int> g[100005];
bool visited[100005];
int dp[100005];
int n , m ;
int pl(int node)
{
    //visited[node] = true ;
    if(dp[node]!=-1)
        return dp[node] ;
    int maxi = 0 ;
    for(int i = 0 ; i <g[node].size();++i)
    {
       // cout<<"in for edge "<<node<<" "<<g[node][i]<<endl;
        int temp = 1 + pl(g[node][i]);
        maxi = max(temp,maxi);
    }
    return dp[node] = maxi ;
}
int main()
{
   // fill(visited,visited+100001,false);
    fill(dp,dp+100001,-1);
    scanf("%d%d",&n,&m) ;
    for(int i = 0; i < m ;++i)
    {
        int x , y ;
        scanf("%d%d",&x,&y) ;
        g[x].push_back(y);
    }
    int maxi = 0 ;
    for(int i = 1 ; i <=n ; ++i)
    {
        int temp = pl(i);
        maxi = max(maxi,temp);
    }
    printf("%d",maxi);
}



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

void Solve(){
	int n, k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i = 0; i < n; i++)
		cin>>v[i];
	sort(v.begin(), v.end());
	long long res = 0;
	for(int i = 0; i < k; i++)
		res += v[i];
	cout<<res<<'\n';
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T = 1;
	//cin>>T;
	while(T--){
		Solve();
	}
}

Measured memory_bytes: 3620