akhauriyash/Code-Regression huggingface dataset:
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N;


signed main() {
int N,point=0;
ll K;
cin >> N;
vector<int> A(N);
REP(i,N){
    cin >> A[i];
}
sort(A.begin(),A.end());
reverse(A.begin(),A.end());

vector<int> B(N,0);
K=0;
B[0]=1;
for(int i=1 ;i<N;i++){
    if(B[point] == 2){
        point +=1;
    }

    K +=A[point];
    B[point] +=1;

}

answer(K);
return 0;

}

Measured memory_bytes: 4836
def judegStable(A, B):
    num_dict_input = dict(zip(map(lambda x: str(x), range(1, 10)), [[]] * 9))
    num_dict_output = dict(zip(map(lambda x: str(x), range(1, 10)), [[]] * 9))

    for i in range(0, N):
        num_dict_input[A[i][1]] = num_dict_input[A[i][1]] + [A[i]]
        num_dict_output[B[i][1]] = num_dict_output[B[i][1]] + [B[i]]
    for key, val in num_dict_input.items():
        for i in range(len(val)):
            if val[i] != num_dict_output[key][i]:
                print "Not stable"
                return False
    print "Stable"
    return True


def bubbleSort(A, N):
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(A[j][1]) < int(A[j - 1][1]):
                v = A[j]
                A[j] = A[j - 1]
                A[j - 1] = v
    return A          

def selectionSort(A, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A

N = input()
line_ = raw_input()
line = line_.strip().split()
line2 = line_.strip().split()
line3 = line_.strip().split()

output_bubble = bubbleSort(line, N)
print(' '.join(output_bubble))
judegStable(line2, output_bubble)

output_select = selectionSort(line2, N)
print(' ' .join(output_select))
judegStable(line3, output_select)






Measured memory_bytes: 4700
n = int(input())

t = [[] for i in range(n)]
s = [[] for i in range(n)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        if y == 1:
            t[i].append(x-1)
        else:
            s[i].append(x-1)
res = 0
# 1 : honest
for k in range(pow(2,n)):
    judge = True
    cnt = 0
    for i in range(n):
        if (k>>i)&1 == 1:
            for e in t[i]:
                if (k>>e)&1 == 0:
                    judge = False
            for e in s[i]:
                if (k>>e)&1 == 1:
                    judge = False
            cnt += 1
    if judge:
        res = max(res,cnt)

print(res)

Measured memory_bytes: 44652
from bisect import bisect_left
N=int(input())
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    for j in range(i+1,N):
        if j==i+1:
            delta=bisect_left(ll,ll[i]+ll[i+1],lo=i+1)-i-2
            if delta>0:
                ans+=delta
            in_b=delta+i+1+1
        else:
            if in_b!=N:
                delta=bisect_left(ll,ll[i]+ll[j],lo=in_b)-j-1
            else:
                delta=N-j-1
            if delta>0:
                ans+=delta
            in_b=delta+j+1
print(ans)

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

int main() {
	string s;
	cin>>s;
	int e=s.size();
	if(e%2==0) {
		for(int i=0;i<e;i+=2) {
			cout<<s.at(i);
		}
	}
	else {
		for(int i=0;i<=e;i+=2) {
			cout<<s.at(i);
		}
	}
	cout<<endl;
}


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

int main() {
  int u = 0;
  long long m;
  std::cin >> m;
  u += ((m / 500) * 1000);
  u += (((m % 500) / 5) * 5);
  std::cout << u << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

int main()
{
	int32_t N, C;
	scanf("%d%d", &N, &C);

	vector<pair<int32_t, int32_t>> band[30];
	for (int32_t i = 0; i < N; i++) {
		int32_t s, t, c;
		scanf("%d%d%d", &s, &t, &c);
		c--;
		band[c].push_back(make_pair(s, t));
	}

	for (int32_t i = 0; i < C; i++) {
		sort(band[i].begin(), band[i].end());
		// merge continuous band
		int32_t prev_index = 0;
		for (int32_t j = 1; j < (int32_t)band[i].size(); j++) {
			if (band[i][prev_index].second == band[i][j].first) {
				band[i][prev_index].second = band[i][j].second;
				band[i][j].first = band[i][j].second = 0;
			} else
				prev_index = j;
		}

		// append channel switch duration
		for (int32_t j = 0; j < (int32_t)band[i].size(); j++) {
			if (band[i][j].first > 1)
				band[i][j].first--;
		}
	}

	int32_t imos[100002];
	memset(imos, 0, sizeof(imos));
	for (int32_t i = 0; i < C; i++) {
		for (int32_t j = 0; j < (int32_t)band[i].size(); j++) {
			imos[band[i][j].first + 1]++;
			imos[band[i][j].second + 1]--;
		}
	}

	int32_t res = 0;
	for (int32_t i = 1; i < 100002; i++) {
		imos[i] += imos[i - 1];
		res = max(res, imos[i]);
	}

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

	return 0;
}


Measured memory_bytes: 1920
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        String str = scn.nextLine();
        double r = Double.parseDouble(str);


        double s = (double)r * (double)r * (double)(Math.PI);
        double l = (double)2 * (double)r * (double)(Math.PI);

        System.out.printf("%.6f %.6f", s, l);

        scn.close();


    }
}


Measured memory_bytes: 26292
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=55;
int n,lim,d;
int p[N],sz[N],que[N]; 
ll y[N],dp[N*N*N]; 
inline void insert(int a,ll b){
	for(int i=n*n*n;i>=a;--i) dp[i]=min(dp[i],dp[i-a]+b); 
}
int main(){
	scanf("%d%d%d%lld",&n,&lim,&d,&y[1]); ++sz[1];
	for(int i=2;i<=n;++i) scanf("%lld%d",&y[i],&p[i]); 
	for(int i=n;i>=2;--i) ++sz[i],sz[p[i]]+=sz[i],y[p[i]]+=y[i];
	memset(dp,0x3f,sizeof(dp));//得到i收益最少用多少代价
	int cnt=min(d,n); d-=cnt; dp[0]=0; int ans=0;
	for(int i=1;i<=n;++i){
		int e=cnt;
		for(int j=0;j<=5;++j) if(1<<j<=e) insert(sz[i]<<j,y[i]<<j),e-=1<<j;
		if(e) insert(sz[i]*e,y[i]*e);
	}
	for(int i=1;i<=n;++i) que[i]=i;
	sort(que+1,que+n+1,[](int a,int b){return sz[a]*y[b]>sz[b]*y[a];});
	for(int i=0;i<=n*n*n;++i){
		if(dp[i]>lim) continue;
		int lst=lim-dp[i],add=0;
		for(int j=1;j<=n;++j){
			int x=que[j],e=min(0ll+(x==1?lst:d),lst/y[x]);
			lst-=y[x]*e; add+=sz[x]*e;
		}
		ans=max(ans,i+add);
	}
	return printf("%d\n",ans),0;
}
 

Measured memory_bytes: 5080
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,a[22][22],dp[(1<<18)];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(((i>>j)&1)==1)
			{
				dp[i]=dp[i-(1<<j)];
				for(int k=0;k<n;k++)
				{
					if(((i>>k)&1)==1)
					{
						dp[i]+=a[j][k];
					}
				}
			}
		}
	}
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=i;j;j=(j-1)&i)
		{
			dp[i]=max(dp[i],dp[j]+dp[i^j]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
 
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)  for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;
 
using namespace std;
 
bool dp[100*100+1][100];
 
int main(void){
    int n;
    vector<int> p;
    cin>>n;
    REP(i,n){
        int a;cin>>a;p.pb(a);
        //cout<<a<<endl;
    }
    dp[0][0]=1;
    REP(j,n){
        REP(i,100*100+1){
            if(dp[i][j]){
                // printf("i=%d j=%d p[j]=%d \n",i,j,p[j]);
                dp[i][j+1]=1;
                dp[i+p[j]][j+1]=1;
            }
        }
    }
    int answer=0;
    REP(i,100*100+1)
        if(dp[i][n] && i%10!=0)
            answer = i;
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;

template <class T> using Vec = vector<T>;

/* 定数 */
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;

#define ALL(v) v.begin(), v.end()

#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    string S;
    cin >> S;
    if (S[0] == S[1] && S[0] == S[2])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

typedef struct{
	int a,b,c;
}result;

int p[301];
result test[1000];

int main(){
	int a,b,c,n;
	while(cin>>a>>b>>c){
		if(a==0 && b==0 && c==0)break;
		cin>>n;
		
		memset(p,-1,sizeof(p));
		memset(test,0,sizeof(test));
		
		int idx=0;
		for(int i=0;i<n;i++){
			int ai,bi,ci,k;
			cin>>ai>>bi>>ci>>k;
			if(k==1){
				p[ai]=1;
				p[bi]=1;
				p[ci]=1;
			}else{
				test[idx]=(result){ai,bi,ci};
				++idx;
			}
		}
		
		int update=1;
		while(update){
			update=0;
			for(int i=0;i<idx;i++){
				if(test[i].a==0)continue;
				int pass=0;
				if(p[test[i].a]==1)++pass;
				if(p[test[i].b]==1)++pass;
				if(p[test[i].c]==1)++pass;
				
				if(pass==2){
					if(p[test[i].a]==-1)p[test[i].a]=0;
					if(p[test[i].b]==-1)p[test[i].b]=0;
					if(p[test[i].c]==-1)p[test[i].c]=0;
					update=1;
					test[i].a=0;
				}
			}
		}
		
		for(int i=1;i<=a+b+c;i++){
			if(p[i]==-1)cout<<2<<endl;
			else cout<<p[i]<<endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>

int main()
{
    char c;
    std::cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    {
        std::cout << "vowel";
    }
    else
    {
        std::cout << "consonant";
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
S = [list(input()) for i in range(h)]
dy = [1,1,1,0,-1,-1,-1,0]
dx = [1,0,-1,-1,-1,0,1,1]
for y in range(h):
    A = []
    for x in range(w):
        if S[y][x] == '#':
            A.append('#')
        else:
            cnt = 0
            for i in range(8):
                ny = y+dy[i]
                nx = x+dx[i]
                if 0<=ny<h and 0<=nx<w and S[ny][nx]=='#':
                    cnt += 1
            A.append(str(cnt))
    print("".join(A)) 


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void){
    long long n,a,b,sum=0;
    cin >> n >> a >> b;
    sum += n/(a+b)*a;
    n = n%(a+b);
    if(n>a)
        sum += a;
    else
        sum += n;
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		for (int i = 0; i < s.length; i++) {
			if (s[i] == (i % 2 == 0 ? 'L' : 'R')) {
				System.out.println("No");
				return;
			}
		} System.out.println("Yes");
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
		int x = sc.nextInt();
		int y = sc.nextInt();
		if(x==0 && y == 0)break;
		if(x >= y ) {
			System.out.println(y + " " + x);
		}else if(x <= y) {
			System.out.println(x + " " + y);
		}

	}
  }

}


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

const ll INF = 1LL << 50;
ll land[200][200];
ll sea[200][200];
ll dp[1010][200];
int z[1000];

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

	int N, M, R;
	while(cin >> N >> M, N) {
		fill((ll*)begin(land), (ll*)end(land), INF);
		fill((ll*)begin(sea), (ll*)end(sea), INF);
		for(int i = 0; i < N; i++) {
			land[i][i] = sea[i][i] = 0;
		}

		for(int i = 0; i < M; i++) {
			int x, y;
			ll t;
			char sl;
			cin >> x >> y >> t >> sl;
			x--, y--;
			if(sl == 'L') {
				t = min(t, land[x][y]);
				land[x][y] = land[y][x] = t;
			}
			else{
				t = min(t, sea[x][y]);
				sea[x][y] = sea[y][x] = t;
			}
		}

		for(int k = 0; k < N; k++) {
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < N; j++) {
					land[i][j] = min(land[i][j], land[i][k] + land[k][j]);
					sea[i][j] = min(sea[i][j], sea[i][k] + sea[k][j]);
				}
			}
		}

		cin >> R;
		for(int i = 0; i < R; i++) {
			cin >> z[i];
			z[i]--;
		}

		if(R == 1) {
			cout << 0 << endl;
			continue;
		}

		fill((ll*)begin(dp), (ll*)end(dp), INF);
		dp[0][z[0]] = 0;
		for(int i = 0; i < R - 1; i++) {
			for(int j = 0; j < N; j++) {
				if(dp[i][j] == INF) continue;
				int A = z[i], B = z[i + 1];

				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + land[A][B]);

				for(int u = 0; u < N; u++) {
					ll cost = land[A][j] + sea[j][u] + land[u][B];
					if(cost < INF) {
						dp[i + 1][u] = min(dp[i + 1][u], dp[i][j] + cost);
					}
				}
			}
		}

		ll ans = INF;
		for(int j = 0; j < N; j++) {
			ans = min(ans, dp[R - 1][j]);
		}
		assert(ans < INF);
		cout << ans << endl;
	}
}

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

int main(){
    char s[17],t[17] = "CODEFESTIVAL2016";
    cin >> s;
    int ans = 0;
    for(int i = 0;i < 17;i++){
        if(s[i] != t[i])++ans;
    }
    cout << ans << endl;
}

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

int main() {
    char A, B, C, D;
    std::cin >> A >> B >> C >> D;

    const int a = A - '0';
    const int b = B - '0';
    const int c = C - '0';
    const int d = D - '0';

    int op[2] = {1, -1};

    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                const int e = a + op[i] * b + op[j] * c + op[k] * d;
                if (e == 7) {
                    std::printf(
                        "%d%c%d%c%d%c%d=7\n", 
                        a, 
                        ((op[i] == 1) ? '+' : '-'),
                        b, 
                        ((op[j] == 1) ? '+' : '-'),
                        c, 
                        ((op[k] == 1) ? '+' : '-'),
                        d
                    );
                    return 0;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using namespace std;

int main(){
	int A, B;
	scanf("%d%d", &A, &B);
	if (A <= 8 && B <= 8)printf("Yay!");
	else printf(":(");
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        l: usize,
        r: usize,
        d: usize
    };
    let mut count = 0;
    for i in l..=r {
        count += (i % d == 0) as i32;
    }
    println!("{}", count);
}


Measured memory_bytes: 2132
#include <stdio.h>
int main(void){
	int number, han_num, ten_num, one_num;
	scanf("%d", &number);
  	
  	han_num = number / 100;
  	ten_num = (number - han_num * 100) / 10;
  	one_num = number - (han_num * 100) - (ten_num * 10);
  
  	if (han_num == 7 || ten_num == 7 || one_num == 7){
    	printf("Yes\n");
    } else {
    	printf("No\n");
    }
}

Measured memory_bytes: 1664
import numpy as np

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
B = np.array(B)
A = []
for n in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = np.array(A, dtype=int)
count = 0
for i in range(N):
  score = np.dot(A[i], B)
  if score > -C:
    count += 1


print(count)

Measured memory_bytes: 14440
N,K = map(int,input().split(' '))

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
max_N = 2000 #階乗の制限どれだけ
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, max_N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

base_num = N-K+1
for i in range(K):
    select_num = cmb(base_num,i+1,mod)
    seq_num = cmb(K-1,i,mod)
    count_n = (select_num*seq_num)%mod
    print(count_n)


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

int main() {
  int n,m,x,y; cin >>n >>m >>x >>y;
  priority_queue<int> xmax;
  priority_queue<int, vector<int>, greater<int>> ymin;
  int buf;
  for (int i=0; i<n; i++){
    cin >>buf; xmax.push(buf);
  }
  for (int i=0; i<m; i++){
    cin >>buf; ymin.push(buf);
  }
  int xx = xmax.top(), yy = ymin.top();
  string ans = "No War";
  if (xx>=y || yy<=x || xx>=yy){
    ans = "War";
  }

  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define sz(a)           (int)(a).size()
#define all(x)          (x).begin(), (x).end()
#define fore(i,a,b)     for(int i=a; i<b; i+=1)
#define forr(i,a)       for(int i=a; i>=0; i--)
#define F first
#define S second
 
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<string> vs;
const int MAX=1e5+10;

ll min(ll a, ll b){
    if(a>b) return b;
    return a;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,k; cin>>n>>k;
    set<ll> vec;
    ll res=1e18+10;
    while(true){
        ll aux=n%k;
        if(k>n) aux=abs(k-n);
        if(vec.count(aux)){
            break;
        } 
        else{
            vec.insert(aux);
            res=min(res,aux);
        }
        n=aux;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int x[100], y[100];
int mini[100], rr[100];
int main()
{
	int w, a, b;
	scanf("%d%d%d", &w, &a, &b);
	if (a > b)swap(a, b);
	printf("%d\n", max(0, b - a - w));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;



int main(){
   int a, b, k;
   cin >> a >> b >> k;

   int ans=0, kth=0;
   for(int i=min(a,b); i>=1; i--){
       if(a % i ==0 && b % i == 0) kth++;
       if(kth==k){
           ans = i;
           break;
       }
   }
   cout << ans << endl;

}

Measured memory_bytes: 3600
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

struct Elem {
    int pos, chg, cost;
    Elem() {}
    Elem(int a, int b, int c) : pos(a), chg(b), cost(c) {}
    bool operator<(const Elem &e) const {
        return cost > e.cost;
    }
};

int dist[110][110];

void calc_distance(vector< vector< pair<int, int> > > &G) {
    fill(dist[0], dist[105], INF);
    dist[0][0] = 0;
    priority_queue<Elem> que;
    que.emplace(0, 0, 0);

    while(que.size()) {
        Elem cur = que.top(); que.pop();
        for(auto e : G[cur.pos]) {
            int to, d; tie(to, d) = e;
            {
                if(dist[to][cur.chg] > cur.cost + d) {
                    dist[to][cur.chg] = cur.cost + d;
                    que.emplace(to, cur.chg, dist[to][cur.chg]);
                }
            }
            if(cur.chg + 1 <= 105) {
                if(dist[to][cur.chg + 1] > cur.cost) {
                    dist[to][cur.chg + 1] = cur.cost;
                    que.emplace(to, cur.chg + 1, dist[to][cur.chg + 1]);
                }
            }
        }
    }
}

int solve() {
    int N, M, C;
    cin >> N >> M >> C;
    if(N == 0 and M == 0 and C == 0) return 1;
    
    vector< vector< pair<int, int> > > G(N);
    for(int i=0; i<M; i++) {
        int u, v, d; cin >> u >> v >> d;
        u--; v--;
        G[u].emplace_back(v, d);
    }

    calc_distance(G);
    int ans = INF;
    for(int i=0; i<=N; i++) {
        if(dist[N-1][i] <= C) ans = min(ans, i);
    }
    cout << ans << endl;
    return 0;
}

signed main() {
    while(!solve());
    return 0;
}



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

#define int long long int

const int INF=1e9+5;

#undef int
int main()
{
	
	int n,k;
	scanf("%d %d",&n,&k);
	vector<int> dp(n+5,INF);
	vector<int> arr(n,0);
	dp[0]=0;
	
	for(int i=0;i<n;i++)
		scanf("%d",&arr[i]);
	
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i+j<n)
				dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i+j]-arr[i]));
		}
	}
	
	printf("%d",dp[n-1]);
	
	
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<long> x;
    for (int i = 0; i < n; ++i) {
        long t;
        cin>>t;
        x.emplace_back(t);
    }
    long ans=LONG_MAX;
    for (int i = 0; i <= n-k; ++i) {
        bool f=false;
        if(x[i]*x[i+k-1]<0)f=true;
        if(f){
            ans=min(ans, static_cast<long>((abs(x[i])+abs(x[i+k-1])+min(abs(x[i]),abs(x[i+k-1])))));
        }
        else if(x[i]<0)ans=min(ans,static_cast<long>(abs(x[i])));
        else ans=min(ans,static_cast<long>(x[i+k-1]));
    }
    if(ans==LONG_MAX)ans=0;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,k,q,a[2222]={},ans=mod;
	cin>>n>>k>>q;
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,n){
		int th=a[i];
		priority_queue<int> pq;
		priority_queue<int> pq2;
		FOR(j,0,n){
			if(a[j]<th){
				while(pq2.size()>=k){
					pq.push(pq2.top());
					pq2.pop();
				}
				priority_queue<int> newpq;
				pq2=newpq;
			}else{
				pq2.push(-a[j]);
			}
		}
		while(pq2.size()>=k){
			pq.push(pq2.top());
			pq2.pop();
		}
		if(pq.size()<q)continue;
		FOR(i,0,q-1){
			pq.pop();
		}
		int x=-pq.top();
		ans=min(ans,x-th);
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 1;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
ll n, m, x = 0, y,z,w,h, sum= 0, ans = 0;
string s, t;
int main() {
	cin >> h >> w; vector<vector<int>> a(h, vector<int>(w));
	rep(i, h) {
		rep(j, w) cin >> a[i][j];
	}vector<pair<int, int>> p,q;
	rep(i, h) {
		if (i % 2 == 0) {
			rep(j, w - 1) {
				if (a[i][j] % 2 == 1) {
					a[i][j + 1]++;
					sum++;
					p.push_back({ i,j });
					q.push_back({ i,j + 1 });
				}
			}
			if (a[i][w - 1] % 2 == 1 && i != h - 1) {
				a[i + 1][w - 1]++;
				sum++;
				p.push_back({ i,w - 1 });
				q.push_back({ i + 1,w - 1 });
			}
		}
		else {
			rrep(j, w) {
				if (a[i][j] % 2 == 1) {
					a[i][j - 1]++;
					sum++;
					p.push_back({ i,j });
					q.push_back({ i,j - 1 });
				}
			}
			if(a[i][0] % 2 == 1 && i != h - 1) {
				a[i + 1][0]++;
				sum++;
				p.push_back({ i,0 });
				q.push_back({ i + 1,0 });
			}
		}
	}
	cout << sum << endl;
	rep(i, p.size()) {
		cout << p[i].first + 1 << " " << p[i].second+ 1 << " " << q[i].first+1 << " ";
		cout << q[i].second + 1 << endl;
	}
}

Measured memory_bytes: 5228
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int A[2000010],B[2000010];
int C[100010];

int main (){
	int n;
	cin>>n;
	for(int i=0;i<100000;i++) C[i]=0;
	for(int i=0;i<n;i++) {
		cin>>A[i+1];
		C[A[i+1]]++;
	}
	for(int i=1;i<100000;i++) C[i]+=C[i-1];
	for(int i=1;i<=n;i++){
		B[C[A[i]]]=A[i];
		C[A[i]]--;
	}
	for(int i =1;i<=n;i++) cout<<B[i]<<(i==n?"\n":" ");
	return 0;
}


Measured memory_bytes: 19080
#include <iostream>

int main()
{
	int H, W;

	while (std::cin >> H >> W)
	{	
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j) 
			{
				if (i == 0 || i == H - 1 || j == 0 || j == W - 1) std::cout << "#";
				else std::cout << ".";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
 	}

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
     
    using namespace std;
     
    vector<vector<int>> bingo(3, vector<int>(3));
    int N, M;
    int solve(){
      cin >> N;
      cin >> M;
      vector<int> si(M);
      vector<int> ci(M);
      for(int i = 0;i < M;i++){
      	cin >> si[i];
        cin >> ci[i];
      }
      for(int i = 0;i < M;i++){
      	for(int j = 0;j < M;j++){
        	if(si[i] == si[j]){
            	if(ci[i] != ci[j]){
                	cout << -1;
                  	return 0;
                }
            }
        }
      }
      for(int i = 0;i < M;i++){
        if(si[i] == 1 && N > 1){
        	if(ci[i] == 0){
            	cout << -1;
              	return 0;
            }
        }
      }
      if(N == 1&&M==0){
      	cout << 0 << endl;
        return 0;
      }
      int ans = 0;
      vector<int> already(N);
      for(int i = 0;i < M;i++){
      	if(already[si[i]-1] == 0){
          ans += ci[i] * pow(10, N - si[i]);
          already[si[i]-1] = 1;
        }
      }
      if(already[0] == 0 && N > 1){
      	ans += pow(10, N-1);
      }
      
     
      cout << ans;
      return 0;
    }
    int main(){
    	solve();
      	return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>

int c[30],cnt;

int main() {
	int N;
	double x,sum=0;
	char u[4];
	scanf("%d", &N);
	int i;
	for (i = 0; i < N; i++) {
		scanf("%lf", &x);
		scanf("%s", u);
		if (u[0] == 'J') sum += x;
		else sum += x * 380000;
	}
	printf("%lf\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int q;
  list<int>L;
  list<int>::iterator it=L.begin();
  cin>>q;
  while(q--){
    int a,b;
    cin>>a;
    if(a<2)cin>>b;
    if(!a)it=L.insert(it,b);
    else if(a==1){
      r(i,abs(b)){
        if(b<0)it--;
        else it++;
      }
    }
    else it=L.erase(it);
  }
  it=L.begin();
  for(;it!=L.end();it++){
    cout<<*it<<endl;
  }
}



Measured memory_bytes: 18536
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())

vals = [1]*(N)
for num in range(1, N//2+1):
    mlt = 2
    # print('num', num)
    while num*(mlt) <= N:
        v = num*mlt
        # print(' v', v)
        vals[v-1] += 1
        mlt += 1

# print(vals)

cnt = 0
for ind, val in enu(vals):
    cnt += (ind+1)*val
print(cnt)


Measured memory_bytes: 151928
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,q,x,A[200005];
map <long long,long long> mp,mp1;

int main() {
           cin>>n>>k;
           for(long long i=1;i<=n;i++)
           {
                      cin>>A[i];
           }
           sort(A+1,A+1+n);
           for(long long i=n-k;i>=1;i--)
           b+=A[i];
           cout<<b;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll k, s; cin >> k >> s;
  ll ans = 0;
  REP(i, k+1) {
    REP(j, k+1) {
      if (s-i-j >=0 && s-i-j <= k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for(int i = 0; i < N; ++i) {
    if(i % 2 == 0)
      Alice += a[i];
	else
	  Bob += a[i];
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
N = int(input())
Rates = list(map(int, input().split()))
Colors = []
Rainbow = 0

for Rate in Rates:
    if Rate < 400:
        Colors.append("灰色")
    elif Rate < 800:
        Colors.append("茶色")
    elif Rate < 1200:
        Colors.append("緑色")
    elif Rate < 1600:
        Colors.append("水色")
    elif Rate < 2000:
        Colors.append("青色")
    elif Rate < 2400:
        Colors.append("黄色")
    elif Rate < 2800:
        Colors.append("橙色")
    elif Rate < 3200:
        Colors.append("赤色")
    else:
        Rainbow += 1

Color = set(Colors)
if len(Color) != 0:
    print(len(Color) , len(Color) + Rainbow)
else:
    print(1 , len(Color) + Rainbow)

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

int main(){
	int A, B;
	cin >> A >> B;

	for(int i = 1; i <= 3; ++i) {
		if((A * B * i) % 2 == 1) {
			cout << "Yes" << endl;
			break;
		}

		if(i == 3) {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int dp[100005][5]={};
  int a[100005],b[100005],c[100005];

  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
  dp[0][0]=a[0]; dp[0][1]=b[0]; dp[0][2]=c[0];

  for(int i=1;i<n;i++){
    dp[i][0]+=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]+=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]+=max(dp[i-1][0],dp[i-1][1])+c[i];
  }

  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
  return 0;
}


Measured memory_bytes: 3328
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i128; n],
    }
    let find = a.iter().find(|x| x == &&0);
    match find {
        Some(_) => println!("0"),
        None => get_num(a),
    }
}

fn get_num(a: Vec::<i128>) {
    let mut ans = 1;
    let bound = 10i128.pow(18u32);
    for num in a {
        ans *= num;
        if ans > bound {
            println!("-1");
            return;
        }
    }
    println!("{}", ans);
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
  Node treeMinimum(Node x){


  }

  Node treeSearch(Node u, int k){


  }

  Node treeSuccessor(Node x){


  }

  void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



  }
*/
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key<x->key)x=x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL)root = z;
  else if(z->key<y->key)y->left=z;
  else y->right = z;


}

void inorder(Node u){

  if (u!=NIL){

    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){

  if (u!=NIL){

    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    /*  if ( com[0] == 'f' ){
	scanf("%d", &x);
	Node t = treeSearch(root, x);
	if ( t != NIL ) printf("yes\n");
	else printf("no\n");
	} else*/ if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
	} /* else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }*/}

return 0;
}

Measured memory_bytes: 24040
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        in.nextLine();
        int wa=0,ac=0,tle=0,re=0;
        for (int i = 0; i < n; i++) {
            String s=in.nextLine();
            if(s.charAt(0)=='W'){
                wa++;
            }else if(s.charAt(0)=='A'){
                ac++;
            }else if(s.charAt(0)=='T'){
                tle++;
            }else{
                re++;
            }
        }
        System.out.println("AC x "+ac);
        System.out.println("WA x "+wa);
        System.out.println("TLE x "+tle);
        System.out.println("RE x "+re);
    }
}

Measured memory_bytes: 60928
#include <stdio.h>

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a<=b && b<=c){
		printf("%d %d %d\n", a, b, c);
	}
	else if (a<=c && c<=b){
		printf("%d %d %d\n", a, c, b);
	}
	else if (b<=a && a<=c){
		printf("%d %d %d\n", b, a, c);
	}
	else if (b<=c && c<=a){
		printf("%d %d %d\n", b, c, a);
	}
	else if (c<=a && a<=b){
		printf("%d %d %d\n", c, a, b);
	}
	else if (c<=b && b<=a){
		printf("%d %d %d\n", c, b, a);
	}
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(){
  int a[101],b[101],h,n,m,t,r,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&h,&a[i]); 
    a[i]+=h*100;
  }
  a[i]=3000;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&h,&b[i]);
    b[i]+=h*100;
  }
  b[i]=3000;
  for(i=t=r=0;i<n+m;i++){
    if(i)printf(" ");
    if(a[t]==b[r]){
      t++;
      i++;
    }
    if(a[t]<b[r]){
      printf("%d:%02d",a[t]/100,a[t]%100);
      t++;
    }
    else{
      printf("%d:%02d",b[r]/100,b[r]%100);
      r++;
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 616
#include <iostream>
using namespace std;
int main(void){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (x>= r && x + r <= W && y >= r && y + r <= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3116
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
#define ll long long
using namespace std;

struct aa{int x, y, id;}a[N], a1[N], a2[N];
struct data{int l, r;}b[N][4];
int n, X, Y, x, y, f1[N], f2[N], flag[N], op, cl, d[N], pos1[N], pos2[N];
ll ans, p, L, R, D;

inline int abs1(int x){return max(x, -x);}

inline bool cmp1(aa a, aa b){
	if(a.x!=b.x)return a.x<b.x;
	return a.y<b.y;
}
inline bool cmp2(aa a, aa b){
	if(a.y!=b.y)return a.y<b.y;
	return a.x<b.x;
}

inline int gether1(int x){return f1[x]?f1[x]=gether1(f1[x]):x;}
inline int gether2(int x){return f2[x]?f2[x]=gether2(f2[x]):x;}
inline void ins(int i){flag[i]=1; f1[pos1[i]]=pos1[i]+1; f2[pos2[i]]=pos2[i]+1; d[++cl]=i;}

int main(){
	scanf("%d%d%d", &n, &X, &Y);
	for(int i=1; i<=n; i++){scanf("%d%d", &x, &y); a[i].x=x+y; a[i].y=x-y; a[i].id=i;}
	D=max(abs1(a[X].x-a[Y].x), abs1(a[X].y-a[Y].y));
	memcpy(a1, a, sizeof(a1)); memcpy(a2, a, sizeof(a2));
	sort(a1+1, a1+1+n, cmp1); sort(a2+1, a2+1+n, cmp2);
	for(int i=1; i<=n; i++)pos1[a1[i].id]=i;
	for(int i=1; i<=n; i++)pos2[a2[i].id]=i;
	op=1; cl=0;
	for(int i=1; i<=n; i++){
		x=a1[i].id; p=a[x].x-D; L=a[x].y-D; R=a[x].y+D;
		while(op<=n&&(a1[op].x<p||(a1[op].x==p&&a1[op].y<L)))op++;
		while(cl<n&&(a1[cl+1].x<p||(a1[cl+1].x==p&&a1[cl+1].y<=R)))cl++;
		b[x][0].l=op; b[x][0].r=cl;
	}
	op=n; cl=n+1;
	for(int i=n; i; i--){
		x=a1[i].id; p=a[x].x+D; L=a[x].y-D; R=a[x].y+D;
		while(op&&(a1[op].x>p||(a1[op].x==p&&a1[op].y>R)))op--;
		while(cl>1&&(a1[cl-1].x>p||(a1[cl-1].x==p&&a1[cl-1].y>=L)))cl--;
		b[x][1].l=cl; b[x][1].r=op;
	}
	op=1; cl=0;
	for(int i=1; i<=n; i++){
		x=a2[i].id; p=a[x].y-D; L=a[x].x-D+1; R=a[x].x+D-1;
		while(op<=n&&(a2[op].y<p||(a2[op].y==p&&a2[op].x<L)))op++;
		while(cl<n&&(a2[cl+1].y<p||(a2[cl+1].y==p&&a2[cl+1].x<=R)))cl++;
		b[x][2].l=op; b[x][2].r=cl;
	}
	op=n; cl=n+1;
	for(int i=n; i; i--){
		x=a2[i].id; p=a[x].y+D; L=a[x].x-D+1; R=a[x].x+D-1;
		while(op&&(a2[op].y>p||(a2[op].y==p&&a2[op].x>R)))op--;
		while(cl>1&&(a2[cl-1].y>p||(a2[cl-1].y==p&&a2[cl-1].x>=L)))cl--;
		b[x][3].l=cl; b[x][3].r=op;
	}
	memset(f1, 0, sizeof(f1)); memset(f2, 0, sizeof(f2)); memset(flag, 0, sizeof(flag));
	ins(X); ins(Y);
	op=0; cl=2; d[1]=X; d[2]=Y;
	while(op<cl){
		op++; x=d[op];
		for(int i=gether1(b[x][0].l); i<=b[x][0].r; i=gether1(i+1))ins(a1[i].id);
		for(int i=gether1(b[x][1].l); i<=b[x][1].r; i=gether1(i+1))ins(a1[i].id);
		for(int i=gether2(b[x][2].l); i<=b[x][2].r; i=gether2(i+1))ins(a2[i].id);
		for(int i=gether2(b[x][3].l); i<=b[x][3].r; i=gether2(i+1))ins(a2[i].id);
	}
	ans=0;
	for(int i=1; i<=n; i++)if(flag[i])
		for(int j=0; j<=3; j++)ans+=b[i][j].r-b[i][j].l+1;
	ans>>=1; printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 9984
#include<stdio.h>

int main()
{
  int i,j,H,W;

  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0)
      break;
    for(i=1;i++<=H;){
      for(j=1;j++<=W;)
	printf("#");
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <stdio.h>

  int main(){
   int a, b, c;

   scanf("%d" , &a);
   scanf("%d" , &b);
   scanf("%d" , &c);

   if(a <= b&&b <= c){
    printf("%d %d %d\n" , a, b, c);
   }
   else if(a <= c&&c <= b){
    printf("%d %d %d\n" , a, c, b);
   }   
   else if(b <=a&&a <= c){
    printf("%d %d %d\n" , b, a, c);
   }
   else if(b <= c&&c <= a){
    printf("%d %d %d\n" , b, c, a);
   }
   else if(c <= a&&a <= b){
    printf("%d %d %d\n" , c, a, b);
   }
   else if(c <= b&&b <= a){
    printf("%d %d %d\n" , c, b, a);
   }

   return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <map>
#include <vector>
#define lli long long int
using namespace std ;


int main(int argc, char const *argv[])
{

	int n ;
	cin>>n ;
	lli ans = 0 ;
	int carry ;
	for(int i = 0 ; i < n ; i++)
	{
		int temp ;
		cin>>temp ;
		if(i == 0)
		{
			 carry = 1 ;
			if(temp == 1) ;
			else
			{
				ans+=temp-1 ;
			}
			continue ;
		}

		if(temp <= carry) continue ;

		if(temp == carry + 1)
		{
			++carry ;
			continue ;
		}

		if(temp %(carry + 1) == 0)
		{
			++carry ;
			ans+= (temp/carry) ;
			--ans ;
			--carry ;
			continue ;
		}

		else
		{
			++carry ;
			ans+= (temp/carry) ;
			--carry ;

		}

	}

	cout<<ans<<endl ;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


ll n, ans=0;

void dfs(ll m, int a, int b, int c){
    if(m>n) return;
    if(a*b*c==1) ans++;
    dfs(m*10+3,1,b,c);
    dfs(m*10+5,a,1,c);
    dfs(m*10+7,a,b,1);
}

int main(){
    cin>>n;
    dfs(0,0,0,0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
      	int d = sc.nextInt();
      	      
		int count = 0;      
      	for(int j = 1; j <= m; j++){
          for(int i = 1; i <= d; i++){
            int d1 = i%10;
            int d2 = i/10;
            if(d1 >= 2 && d2 >=2 && (d1*d2 == j))
              count++;
          }
        }
      
      	System.out.println(count);
		
	}
}

Measured memory_bytes: 21588
n,m,k = map(int,input().split())
mod = 998244353
l = 10**6
fac = [1]*l
facr = [1]*l

for i in range(l-1):
    fac[i+1] = fac[i]*(i+1)%mod
facr[l-1] = pow(fac[l-1],mod - 2,mod)
for i in range(1,l)[::-1]:
    facr[i-1] = facr[i]*i%mod

def combi(N,K):
    return fac[N]*facr[N-K]%mod*facr[K]%mod

ans = 0
M = m*pow(m-1,n-1-k,mod)%mod
for i in range(n-1-k,n):
    ans += M*combi(n-1,i)%mod
    ans %= mod
    M = M*(m-1)%mod
print(ans)


Measured memory_bytes: 88076
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int res1 = 0;
    int res2 = 1;
    reppe(i, 0, F / (100 * A)) {
        reppe(j, 0, F / (100 * B)) {
            reppe(k, 0, F / C) {
                reppe(l, 0, F / D) {
                    if (i + j + k + l == 0) continue;

                    int a = 100 * (i * A + j * B);
                    int b = k * C + l * D;

                    if (a + b > F) continue;
                    if (b  > (a / 100)  * E) continue;
                    if ((double)(100 * b) / (a + b) >= (double)(100 * res1) / res2) {
                        res1 = b;
                        res2 = a + b;
                    }
                }
            }
        }
    }
    cout << res2 << " " << res1 << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
count=0
lst={}
lst2=[]
now=1
c=0

while True:
    lst2.append(now)
    lst[now]=c
    now=a[now-1]
    if now in lst:
        break
    c+=1



amari=lst[now]
looplen=c-lst[now]+1


if k<=amari:
    print(lst2[k])

else:
    newlst=lst2[amari:]
    
    newk=k-amari
    num=newk%looplen
    print(newlst[num])

Measured memory_bytes: 124468
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
bool isOK(ll index, ll key) {
	if (index*index < key || index * (index - 1) < key)
		return true;
	else return false;
}
int binary_search(ll key) {
	ll left = -1;
	ll right = B+1;
	while (right - left > 1) {
		ll mid = (right + left) / 2;
		if (isOK(mid, key))left = mid;
		else right = mid;
	}
	return right;
}
int main() {
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> A >> B;
		if (A > B)swap(A, B);
		ll key = binary_search(A*B)-1;
		//cout << key << endl;
		if (key*key < A * B) {
			ans = key * 2 - 1;
		}
		else {
			ans = (key - 1) * 2;
		}
		if (A<=key)ans--;
		if (A == B)ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256