akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(x-b) > abs(x-a)){
    cout << "A" << endl;
  }else
    cout << "B" << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[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(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))

for i in range(N-1) :
    if i == 0 :
        p = L[i]
        q = sum(L)-p
        ans = abs(p-q)
    else :
        p += L[i]
        q -= L[i]
        if ans > abs(p-q) :
            ans = abs(p-q)
        
print(ans)


Measured memory_bytes: 24948
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    let s = get!(String);
    let ss = s.as_bytes().into_iter()
        .map(|as_char| {
            as_char - 48
        })
        .collect::<Vec<_>>();

    if ss[0] < ss[1] {
        print!("{}{}{}", ss[0] + 1, ss[0] + 1, ss[0] + 1);
    } else if ss[0] < ss[2] && ss[0] == ss[1] {
        print!("{}{}{}", ss[0]+1, ss[0]+1, ss[0]+1);
    } else {
        print!("{}{}{}", ss[0], ss[0], ss[0]);
    }
}

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

int main(){
  //入力
  int A,B;
  //A,Bの絶対値は100以下の整数からOK
  scanf("%d %d", &A, &B);

  //計算
  int Max;
  //最大値は-100以上10000以下から良い
  if(B>0){
    if(A+B > A*B){
      Max = A+B;
    }else{
      Max = A*B;
    }
  }else if(B<0){
    if(A-B > A*B){
      Max = A-B;
    }else{
      Max = A*B;
    }
  }else{
    Max = abs(A);
    //この時B=0からsetはA,A,0から正しい
  }

  //出力
  printf("%d", Max);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        sc.close();
        if(a<b&&b<c)
        System.out.println("Yes");
        else
        System.out.println("No");
    }
}


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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int n;
  bool b = true;
  long long c = pow(10, 18);

  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i] == 0) {
      cout << 0 << endl; return 0;
    }
  }
  
  long long ans = 1;
  for(int i = 0; i < n; i++) {
    if(a[i] <= c / ans) {
      ans *= a[i];
    }
    else {
      b = false; break;
    }
    
  }
  
  if(b == true) cout << ans << endl;
  else cout << -1 << endl;
  
  return 0;
}

Measured memory_bytes: 3996
def method3():
    n = (int(input()))
    nums = list(map(int, input().split()))
    result = 1
    hantei = True
    for i in range(1,n):
        hantei = True
        for j in range(i):
            if nums[i]<nums[j]:
                hantei = False
                break
        if hantei:
            result = result + 1
    print(result)
    
if __name__ == "__main__":
    method3()

Measured memory_bytes: 3064
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
x, y = [], []
for i, j in xy:
    x += [i]
    y += [j]
memo = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[j] - x[i]
        q = y[j] - y[i]
        pq = str(i) + '_' + str(j)
        for k in range(N):
            for l in range(N):
                if k == l:
                    continue
                if (x[k] - x[l]) == p and (y[k] - y[l]) == q:
                    if pq in memo:
                        memo[pq] += 1
                    else:
                        memo[pq] = 1
if N != 1:
    print(N-max(memo.values()))
else:
    print('1')

Measured memory_bytes: 3316
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] a=sc.next().toCharArray();
		char[] b=sc.next().toCharArray();
		int l=a.length;
		for(int i=0;i<l;i++){
			if(Arrays.equals(a,b)){
				System.out.println("Yes");
				return;
			}else{
				rotate(b);
			}
		}
		System.out.println("No");
	}
	
	static void rotate(char[] b){
		char c0=b[0];
		for(int i=0;i<b.length-1;i++){
			b[i]=b[i+1];
		}
		b[b.length-1]=c0;
	}
}


Measured memory_bytes: 23636
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	/*if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;*/
	return ((a.x + 1)*(a.y + 1)) < ((b.x + 1)*(b.y + 1));
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
int ctoi(char a) {
	return (int)a - '0';
}
 //#define int long long
const long long Inf = 4523372036854775807;
const int inf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[100002];
signed main() {
	cin >> n;
	n++;
	for (int i = 1; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += abs(a[i] - a[i - 1]);
	}
	for (int i = 1; i < n; i++) {
		if (a[i - 1]<a[i]&&a[i]<a[i+1]) {
			cout << ans << endl;
		}
		else if (a[i + 1] < a[i] && a[i] < a[i - 1]) {
			cout << ans << endl;
		}
		else{
			cout << ans - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
		}
	}
	getchar(); getchar();
}

Measured memory_bytes: 1664
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

bool mark[MAXN];
int pri[MAXN], ans[MAXN];

int pre ()
{
    memset (mark, false, sizeof (mark));
    int cnt = 0;
    for (int i = 2; i < MAXN; i ++)
    {
        if (!mark[i])
        {
            cnt ++;
            pri[cnt] = i;
        }
        for (int j = 1; j <= cnt && pri[j] * i < MAXN; j ++)
        {
            mark[pri[j] * i] = true;
            if (i % pri[j] == 0)
            {
                break;
            }
        }
    }
    return cnt;
}

int main ()
{
    int cnt = pre ();
    memset (ans, 0, sizeof (ans));
    for (int i = 2; i < MAXN; i ++)
    {
        ans[i] = ans[i - 1];
        if ((i % 2 == 1) && (!mark[i]) && (!mark[(i + 1) / 2]))
        {
            ans[i] ++;
        }
    }
    int n;
    scanf ("%d", &n);
    for (int i = 1; i <= n; i ++)
    {
        int x, y;
        scanf ("%d%d", &x, &y);
        printf ("%d\n", ans[y] - ans[x - 1]);
    }
    return 0;
}


Measured memory_bytes: 1152
import itertools

def main():
    N = int(input())

    num = ['3','5','7']
    num_list = set()

    for a in num:
        for b in num:
            for c in num:
                num_list.add(a+b+c)
                for d in num:
                    num_list.add(a+b+c+d)
                    for e in num:
                        num_list.add(a+b+c+d+e)
                        for f in num:
                            num_list.add(a+b+c+d+e+f)
                            for g in num:
                                num_list.add(a+b+c+d+e+f+g)
                                for h in num:
                                    num_list.add(a+b+c+d+e+f+g+h)
                                    for i in num:
                                        num_list.add(a+b+c+d+e+f+g+h+i)

    cnt = 0
    for i in num_list:
        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
            if int(i) <= N:
                cnt += 1

    print(cnt)
    

main()

Measured memory_bytes: 7024
#include<iostream>
#include<algorithm>
using namespace std;
long long N,X;
long long dp[55],sum=0;
long long len[55];
int main(){
    int a[7]={0,0,1,2,3,3,3};
    dp[1]=3;len[1]=5;
    for(int i=2;i<=50;i++)
        dp[i]=dp[i-1]*2+1;
    for(int i=2;i<=50;i++)
        len[i]=len[i-1]*2+3;
    scanf("%lld %lld",&N,&X);
    while(1){
        if(N==1||X==0)
            break;
        long long temp=len[N]/2;
        if(X*2>len[N]){
            bool f=0;
            if(X==len[N])
                f=1;
            sum+=dp[N-1]+1;
            X-=len[N]/2+1;
            X-=f;
        }
        else
            X--;
        N--;

    }
    if(N==1){
        sum+=a[X];
    }
    printf("%lld\n",sum);


}



Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define min(a,b) (((a) > (b))?(b):(a))
#define INF 1000001

int dp[100][100];
int V;

int warshall_floyd(int k) {
    int i;

    for (i=0;i<V;i++) {
        int j;
        for (j=0;j<V;j++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    }
}

int main() {
    while (1) {
        int i;
        int n, k;

        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) return 0;

        V = n;
        for (i=0;i<n;i++) {
            int j;
            for (j=0;j<n;j++) {
                if (i == j) {
                    dp[i][j] = 0;
                } else {
                    dp[i][j] = INF;
                }
            }
        }

        for (i=0;i<k;i++) {
            int c, d;
            int query;

            scanf("%d", &query);
            if (query) {
                int e;

                scanf("%d%d%d", &c, &d, &e);
                c--;
                d--;
                if (dp[c][d] > e) dp[c][d] = e;
                if (dp[d][c] > e) dp[d][c] = e;
                warshall_floyd(c);
                warshall_floyd(d);
            } else {
                int c, d;

                scanf("%d%d", &c, &d);
                c--;
                d--;
                if (dp[c][d] == INF) printf("%d\n", -1);
                else printf("%d\n", dp[c][d]);
            }
        }
    }
}

Measured memory_bytes: 1064
import numpy as np
import sys

def main():
  input = sys.stdin.readline
  n = int(input())
  a = np.array([int(x) for x in input().split()])
  inf = pow(10, 9)+7
  max_a = np.max(a)
  bit = 1
  ans = 0
  num = 0
  while max_a:
    num += 1
    max_a //= 2
  for _ in range(num):
    bit_count = np.sum(a%2)
    ans += ((((bit_count%inf)*((n-bit_count)%inf))%inf)*(bit%inf))%inf
    ans %= inf
    a //= 2
    bit *= 2
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 49984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

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

using namespace std;

struct W
{
	string s;
	int num;
	
	W(string s = "",int num = 0) : s(s),num(num) {}
};

char change(char a,char b)
{
	if((a == 'r' && b == 'g') || (a == 'g' && b == 'r'))
	{
		return 'b';	
	}
	else if((a == 'r' && b == 'b') || (a == 'b' && b == 'r'))
	{
		return 'g';
	}
	else if((a == 'g' && b == 'b') || (a == 'b' && b == 'g'))
	{
		return 'r';
	}
	return 'N';
}

int main()
{
	string s;
	while(cin >> s)
	{
		if(s == "0") break;
		
		string t = "",t2 = "",t3 = "";
		rep(i,s.size())
		{
			t += "r";
			t2 += "g";
			t3 += "b";
		}

		queue<W> que;
		que.push(W(s,0));
		map<string,int> m;
		int ans = 0;
		bool flag = true;

		while(!que.empty())
		{
			W w = que.front();
			que.pop();

			if(m[w.s] > 0) 
			{
				continue;
			}

			if(w.s == t || w.s == t2 || w.s == t3)
			{
				flag = false;
				ans = w.num;
				break;
			}

			m[w.s] = w.num;

			rep(i,s.size()-1)
			{
				string temp = w.s;
				if(change(w.s[i],w.s[i+1]) == 'N') continue;
				
				temp[i] = temp[i+1] = change(w.s[i],w.s[i+1]);
				que.push(W(temp,w.num+1));
			}
		}
		if(flag) cout << "NA" << endl;
		else cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3396
use itertools::Itertools;
use proconio::{derive_readable, fastout, input};

#[derive_readable]
#[derive(PartialEq, Debug, Clone)]
struct Pair {
  a: usize,
  b: usize,
  c: i32,
  d: u32,
}

#[allow(non_snake_case)]
#[fastout]
fn main() {
  input! {
    N: usize,
    M: i32,
    Q: usize,
    pairs: [Pair; Q],
  }

  let mut max_score = 0;
  // {A} := N 個で 1 以上 M 以下の数の組み合わせ
  for A in (1..=M).combinations_with_replacement(N) {
    // A[b] - A[a] が c なら d を得点する
    let pointables = pairs
      .iter()
      .filter(|&Pair { a, b, c, .. }| A[b - 1] - A[a - 1] == *c);
    let score = pointables.map(|&Pair { d, .. }| d).sum();
    max_score = max_score.max(score);
  }
  println!("{}", max_score);
}


Measured memory_bytes: 2184
#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class T1, class T2, class T3> void sortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){
  int i;
  pair<T1, pair<T2, T3> > *arr=(pair<T1, pair<T2, T3> > *) mem;
  for(i=0;i<N;i++){
    arr[i].first = a[i];
    arr[i].second.first = b[i];
    arr[i].second.second = c[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second.first;
    c[i] = arr[i].second.second;
  }
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
char memarr[96000000];
int N;
int M;
int P[100000];
int Y[100000];
int ind[100000];
long long res[100000];
int main(){
  int i, j;
  wmem = memarr;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<M;Lj4PdHRW++){
      rd(P[Lj4PdHRW]);
      rd(Y[Lj4PdHRW]);
    }
  }
  for(i=0;i<M;i++){
    ind[i] = i;
  }
  sortA_L(M, P, Y, ind);
  for(i=0;i<M;i++){
    if(i==0 || P[i]!=P[i-1]){
      j=0;
    }
    j++;
    res[ind[i]] = (long long)P[i] * 1000000 + j;
  }
  for(i=0;i<M;i++){
    printf("%012lld\n", res[i]);
  }
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N, M;
// int P[1d5], Y[1d5];
// 
// int ind[1d5];
// ll res[1d5];
// 
// {
//   int i, j;
//   
//   rd(N,M,(P,Y)(M));
//   rep(i,M) ind[i] = i;
// 
//   sortA(M, P, Y, ind);
// 
//   rep(i,M){
//     if(i==0 || P[i]!=P[i-1]) j=0;
//     j++;
//     res[ind[i]] = (ll)P[i] * 1d6 + j;
//   }
// 
//   rep(i,M) printf("%012lld\n", res[i]);
// }


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
bool k[10];
int b[11];
int main()
{
	int a[10];
	for(int i=1;i<=9;i++)
		cin>>a[i];
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		for(int j=1;j<=9;j++)
		{
			if(b[i]==a[j])
				k[j]=true;
		}
	}
	if((k[1]==true&&k[2]==true&&k[3]==true)||(k[4]==true&&k[5]==true&&k[6]==true)||
		(k[7]==true&&k[8]==true&&k[9]==true)||(k[1]==true&&k[4]==true&&k[7]==true)||
		(k[2]==true&&k[5]==true&&k[8]==true)||(k[3]==true&&k[6]==true&&k[9]==true)||
		(k[1]==true&&k[5]==true&&k[9]==true)||(k[3]==true&&k[5]==true&&k[7]==true))
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int floor [4][3][10]={{{}}},n,b,f,r,v;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        floor [b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
    for(int k=0;k<10;k++){
        cout<<" "<<floor[i][j][k];
    }
    cout<<endl;
    }
    if(i!=3)
    cout<<"####################"<<endl;
    }  
}


Measured memory_bytes: 3072
n,*ab = map(int,open(0).read().split())
abc = [(ab[i*2],ab[i*2+1],ab[i*2]+ab[i*2+1]) for i in range(n)]
abc.sort(key=lambda x:x[2],reverse = True)
print(sum([abc[i][0] if i%2==0 else -abc[i][1] for i in range(n)]))

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

def solve():
    K = int(input())
    a = 7%K
    i = 1
    Kset = set()
    Kset.add(a)
    while a!=0:
        a = (a*10+7)%K
        i += 1
        if a in Kset:
            print(-1)
            return
        Kset.add(a)
    print(i)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 77732
L = input()
Digit = len(L)
dp = [[0]*2 for _ in range(Digit+1)]
dp[0][0] = 1
mod = 10**9+7
# 配りdp
for i in range(Digit):
    next_digit = L[i]
    
    if next_digit == '0':
        # not smallからnot smallへの遷移
        dp[i+1][0] += dp[i][0]
        # not smallからsmallへの遷移はない

        # smallからsmallへの遷移
        dp[i+1][1] += (3*dp[i][1])%mod
        
    else:
        # not smallからnot smallへの遷移
        dp[i+1][0] += (2*dp[i][0])%mod
        # not smallからsmallへの遷移
        #print(dp[i][0])
        dp[i+1][1] += dp[i][0]%mod
        # smallからsmallへの遷移
        dp[i+1][1] += (3*dp[i][1])%mod
    #print(dp[i],dp[i+1])
    #print('---')

#print(dp)
print((dp[-1][1]+dp[-1][0])%mod)

Measured memory_bytes: 85348
#include <iostream>
#include <algorithm>
#include <vector>

constexpr int MAX_N = (int)1e5, INF = (int)1e9;

using ll = long long int;

using P = std::pair<int, int>;

using Node = std::pair<int, P>;

int parent[MAX_N];
int rank[MAX_N];

int n;

void init() {

	for (int i = 0; i < n; ++i)
		parent[i] = i;
}

int find(int x) {

	if (parent[x] == x)
		return x;
	else
		return parent[x] = find(parent[x]);
}

void unite(int x, int y) {

	x = find(x);

	y = find(y);

	if (rank[x] < rank[y])
		parent[x] = y;
	else {
		parent[y] = x;
		if (rank[x] == rank[y])
			++rank[x];
	}
}

bool same(int x, int y) {

	return find(x) == find(y);
}

P XX[MAX_N], YY[MAX_N];

std::vector<Node> vec;

int main() {

	std::cin >> n;

	init();

	for (int i = 0; i < n; ++i) {
		std::cin >> XX[i].first >> YY[i].first;
		XX[i].second = i;
		YY[i].second = i;
	}

	std::sort(XX, XX + n);

	std::sort(YY, YY + n);

	for (int i = 0; i < n - 1; ++i) {

		vec.emplace_back(XX[i + 1].first - XX[i].first, P(XX[i].second, XX[i + 1].second));

		vec.emplace_back(YY[i + 1].first - YY[i].first, P(YY[i].second, YY[i + 1].second));
	}

	std::sort(vec.begin(), vec.end());

	ll ans = 0;

	for (auto& x : vec) {

		if (!same(x.second.first, x.second.second)) {

			ans += x.first;

			unite(x.second.first, x.second.second);
		}
	}

	std::cout << ans << std::endl;

	//system("pause");

	return 0;
}

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


void solve(long long X, long long Y){
    long long ans=X+Y/2;
    printf("%lld\n",ans);
}


int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;

int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  double v = 0, dn = n;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(!(i == j)) {
        v += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
      }
    }
  }
  cout << v / dn;
}
 

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=998244353

#+++++

def main():
	# = int(input())
	n, k = tin()
	#s = input()
	al = []
	for _ in range(k):
		l,r = tin()
		al.append([l,r])
	
	dd = [0]*(n)
	dd[0] = 1
	
	ruiseki=[0]*(n)
	ruiseki[0]=1
	ruiseki[1]=-1
	rui=0
	for pos, num in enumerate(ruiseki):
		rui += ruiseki[pos]
		rui %= mod
		dd[pos]=rui
		for l,r in al:
			if pos + l < n:
				ruiseki[pos+l] += rui
			if pos + r + 1 < n:
				ruiseki[pos + r + 1] -= rui
		#pa(dd)
		#pa(ruiseki)
		
	return rui%mod
		
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 76748
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.map(_.split(' ').map(_.toInt).toIndexedSeq).head
  val A = ls(0)
  val B = ls(1)
  val C = ls(2)
  
  val ret = Math.min(C, B/A)
  println(ret)
}


Measured memory_bytes: 27336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout<<"siktim seni\n";
ll int a,b,c;
int main(){	cin>>a;	while(a--){		cin>>c;		if(c%2==0){			if(c%3!=0 and c%5!=0){				cout<<"DENIED";
				return 0;
			}	
		}
	}
	cout<<"APPROVED";
}

Measured memory_bytes: 256
# abc105c

N = int(input())

if N==0:
    print(0)
    exit()

a = ""
b = -2

while N!=1:
    if N%b==0:
        a += "0"
        N = N//b
    else:
        a += "1"
        if N>0:
            N = N//b + 1
        else:
            N = N//b + 1
if N==1:
    a += "1"
print(a[::-1])

Measured memory_bytes: 3064
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,*A = map(int, read().split())
dp = [0 for i in range(N+1)]
for i in range(1,N):
  if i == 1:
    dp[i+1] = abs(A[1]-A[0])
  else:
    dp[i+1] = min((dp[i-1] + abs(A[i]-A[i-2])),(dp[i] + abs(A[i]-A[i-1])))
print(dp[N])

Measured memory_bytes: 11588
n,m,x=map(int, input().split())

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

mas=[0]*(n+1)

for i in range(len(a)):
    mas[a[i]-1]=1

left_count=mas[:x].count(1)
right_count=mas[x:].count(1)

print(min(left_count,right_count))


Measured memory_bytes: 3060
#include <stdio.h>
#define TG 1000000
#include <math.h>

int main(void){
    int p[TG]={0};
    int i,j,a,d,n,c,v;
    for(i=1;i<TG;i+=2){
        if(i%3 && i%5 && i%7){p[i]=i;}
    }
    p[1]=0;p[2]=2;p[3]=3;p[5]=5;p[7]=7;
    for(i=2;i<sqrt(TG);i++){
        if(!p[i]){continue;}
        for(j=i+1;j<TG;j++){
            if(!(p[j]%i)){p[j]=0;}
        }
    }
    while(1){
        scanf("%d",&a);
        scanf("%d",&d);
        scanf("%d",&n);
        if(!a && !d && !n){break;}
        v=a;c=0;
        while(1){
            if(p[v]){c++;}
            if(c==n){break;}
            v+=d;
        }
        printf("%d\n",p[v]);
    } 
    return 0;
}



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

int main()
{
	vector<long long> A(3);
	cin >> A[0] >> A[1] >> A[2] ;
	sort(A.begin(), A.end());
	if (A[0] % 2 == 0 || A[1] % 2 == 0 || A[2] % 2 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << A[0] * A[1] << endl;
	}
}

Measured memory_bytes: 256
n,m=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(n)]

B=[list(map(int,input().split())) for _ in range(m)]


for a in A:
    D=[]
    for i in range(m):
        D.append([abs(a[0]-B[i][0])+abs(a[1]-B[i][1]),i+1])
    D=sorted(D,key=lambda x:(x[0],x[1]))
    print(D[0][1])

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

#define fir first
#define sec second
using namespace std;
typedef long long LL;
typedef unsigned long long u64;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
int inp() {
	int x = 0, f = 1;char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = -1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return x * f;
}

const int MaxN = 2333;

char a[MaxN], b[MaxN];
int n, ans = ~0U >> 1, x[MaxN], y[MaxN];
int A[MaxN], B[MaxN];

void solve() {
    int i, j;
    for(i = 0; i < n; i++) {
        for(A[i] = 0; b[(i + A[i]) % n] != '1'; ++A[i]);
        for(B[i] = 0; b[(i + B[i] + n) % n] != '1'; --B[i]);
    }
    for(int d = 0; d < n; d++) {
        for(i = 0; i < n; i++) x[i] = 0;
        for(i = j = 0; i < n; i++)
            if(a[i] != b[(i + d) % n]) {
                cmax(x[-B[i]], A[i] - d);
                ++j;
            }
        int L, R, res = 1e9;
        for(L = 0, R = n - 1; ~R; R--) cmin(res, L + R), cmax(L, x[R]);
        cmin(ans, 2 * res + d + j);
    }
}

int main() {
	int i;
	scanf("%s%s", a, b); n = strlen(a);
	if(*max_element(b, b + n) != '1') {
	    cout << (*max_element(a, a + n) != '1' ? 0 : -1) << endl;
	    return 0;
	}
	solve();
	reverse(a, a + n);
	reverse(b, b + n);
	solve();
	
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 384
arr=[]
ta=[]
while true do
  n, r = gets.split.map(&:to_i)
  if n == 0 && r == 0
    break
  end
  arr = (1..n).to_a.reverse
  r.times do
        p, c = gets.split.map(&:to_i)
        p -= 1
        ta = arr[p...p+c] + arr[0...p] + arr[p+c..n]
        arr = ta
  end
  puts arr[0]
end



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

int main () {
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i<N; i++) cin >> A[i]; 

    vector<int> s;
    vector<int> ord(N + 1,-1);
    int c = 1, l = 0;
    {
    int v = 1;
      while (ord[v] == -1) {
        ord[v] = s.size();
        s.push_back(v);
        v = A[v-1];
      }
      c = s.size() - ord[v];
      l = ord[v];
    }
    if (K < l) cout << s[K] << endl;
    else {
      K -= l;
      K %= c;
      cout << s[l + K] << endl;
    }
    return 0;
}

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

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

    cin >> a >> b >> c >> d;
    if((a+b) > (c+d))
        cout << "Left" << endl;
    else if((a+b) < (c+d))
        cout << "Right" << endl;
    else
        cout << "Balanced" << endl;
    
    return 0;
}

Measured memory_bytes: 3620
local n=io.read("n")
local t={}
for i=1,n do
    t[i]={}
    for j=1,3 do
        t[i][j]=io.read("n")
    end
end

local dp={}
for i=1,n+1 do
    dp[i]={0,0,0}
end

for i=1,n do
    for j=1,3 do
        for k=1,3 do
            if j~=k then
                dp[i+1][k]=math.max(dp[i+1][k],dp[i][j]+t[i][k])
            end
        end
    end
end

print(math.max(table.unpack(dp[n+1])))

Measured memory_bytes: 32976
S=input()
Mod=10**9+7
dp=[1,0,0,0]

for s in S:
  if s=="A":
#dp[1]:="A"ができる個数。
    dp[1]+=dp[0]
  elif s=="B":
#dp[2]:="AB"ができる個数="B"が出てきたらこれまでの"A"個数分の"AB"ができる
    dp[2]+=dp[1]
  elif s=="C":
#dp[3]:="ABC"ができる個数="C"が出てきたらこれまでの"AB"個数分の"ABC"ができる
    dp[3]+=dp[2]
  else:
#"?"が登場した場合。"A""B""C"それぞれになるので、dp[0]~dp[3]全てが３通り（=3倍）増える。
#加えて"C"になる場合を考えると、"ABC"になる場合は"AB"の個数分増える。以下"AB""A"も同様。
    dp[3]=dp[3]*3+dp[2]
    dp[2]=dp[2]*3+dp[1]
    dp[1]=dp[1]*3+dp[0]
    dp[0]*=3
#modをとる。
  for i in range(4):
    dp[i]%=Mod

#最終的に"ABC"になる場合の数を示すdp[3]を出力。
print(dp[3])

Measured memory_bytes: 3188
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  Printf.printf "%d\n" @@
  if Array.fold_left ( + ) 0 as_ < Array.fold_left ( + ) 0 bs then -1
  else begin
    let abs = Array.init n @@ fun i -> as_.(i) - bs.(i) in
    Array.sort (fun ab ab' -> compare ab' ab) abs;
    let lack = Array.fold_left (fun acc ab -> acc - min 0 ab) 0 abs in
    Array.fold_left (fun acc ab -> acc + if ab < 0 then 1 else 0) 0 abs
    + fst (Array.fold_left (fun (n, lack) ab ->
      if ab <= 0 || lack <= 0 then (n, lack)
      else (n + 1, lack - ab)) (0, lack) abs)
  end


Measured memory_bytes: 6272
N, T = map(int, input().split())

dishes = sorted([tuple(map(int,input().split())) for i in range(N)])

dp = [[0] * 3100 for _ in range(3100)]
ans = 0

for i in range(1, N + 1):
    for j in range(1, T):
#dpをもとにした最大値の更新
        dp[i][j] = dp[i-1][j] 
        ans = max(ans, dp[i][j] + dishes[i-1][1]) #最後に、最も時間のかかるものを食べて、大きい場合は最大値（ans）を更新

# dpの更新
        if j - dishes[i-1][0] >= 0: #最後に食べる品が持ち時間より長いばあいはNG
            dp[i][j] = max(dp[i][j], dp[i-1][j-dishes[i-1][0]] + dishes[i-1][1]) #ラストオーダーまでにj-dishes[i-1][0]の時間があるので

print(ans)

Measured memory_bytes: 121176
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
vector<string> st;
map<string,int> stm;
main(){
  char hoge[1001];
  string str;
  fgets(hoge,sizeof(hoge),stdin);
  str=hoge;
  int stp=0;
  int n=str.size();
  for(int i=0;i<n;i++){
    if(str.at(i)==' '){
      st.push_back(str.substr(stp,i-stp));
      stp=i+1;
      stm[st.back()]++;
    }
  }
  st.push_back(str.substr(stp,n-stp-1));

  int m=st.size();

  string strmax;
  string stres;
  int count=0;
  int tc=0;
  for(int i=0;i<m;i++){
    if(i==0){
      strmax=st[0];
      stres=st[0];

    }else{
      if(strmax.size() < st[i].size()){
	strmax=st[i];
      } 
      if(stm[st[i]] > stm[stres]){
	stres=st[i];
      }
    }
    
  } 
  cout << stres <<" "<<strmax<<endl;
}

Measured memory_bytes: 0
l = [input() for _ in [0] * 5]
keta =[]
for i in l:
    keta.append(i)
#print(keta)
xxx = []
for j in keta:
    if int(j[-1]) != 0:
        xxx.append(int(j) + (10 - int(j[-1])))
    else:
        xxx.append(int(j))
#print(xxx)
yyy = []
for k in keta:
    yyy.append(int(k[-1]))
#print(yyy)
zzz = []
for m in yyy:
    if int(m) > 0:
        zzz.append(m)
#print(zzz)
if 0 < sum(zzz):
    p = min(zzz)
    print(sum(xxx) - (10 - p))
else:
    p = 0
    print(sum(xxx))



Measured memory_bytes: 3064
# ABC081-B
N = int(input())
A = list(map(int, input().split()))
ans = 0
flag = True
while True:
    if flag == False:
        break
    for k in range(len(A)):
        if flag == False:
            break
        if A[k] % 2 == 0 and k == len(A) - 1:
            A[k] /= 2
            ans += 1
        elif A[k] % 2 == 0:
            A[k] /= 2
        else:
            flag = False
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;


int Main(int N)
{
    return pow(N, 3);
}

int main(void){
    int N;
    cin >> N;
    cout << Main(N) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100+3;
int n;
struct node{
	string s;
	int p;
	int id;
}a[MAXN];
bool cmp(node u,node v){
	return u.s==v.s?u.p>v.p:u.s<v.s;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>a[i].s>>a[i].p;
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		printf("%d\n",a[i].id);
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

import re
def findall(string,s):
    return [m.start() for m in re.finditer(s, string)]

from collections import Counter
C1 = Counter(T).most_common()
C2 = Counter(S).most_common()

ans = 'Yes'

for c in C1:
    if c[1] >= 2:
        # import pdb;pdb.set_trace()
        ls = findall(T,c[0])
        s_set = set()
        for num in ls:
            s_set.add(S[num])
        if len(s_set) > 1:
            ans = 'No'
            
for c in C2:
    if c[1] >= 2:
        # import pdb;pdb.set_trace()
        ls = findall(S,c[0])
        s_set = set()
        for num in ls:
            s_set.add(T[num])
        if len(s_set) > 1:
            ans = 'No'
            
print(ans)


Measured memory_bytes: 12196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e3 + 5;
const ll mod = 998244353 ;
const double pi = acos(-1);
ll fastpow(ll b, ll e) {
    if (!e)
        return 1;
    ll ret = fastpow(b, e / 2);
    ret = (ret * ret) % mod;
    if (e % 2)
        ret = (ret * b) % mod;
    return ret;
}
ll modinv(ll x) {
    return fastpow(x, mod - 2);
}
double torad(double ang) {
    return ang * pi / 180.0;
}


int dp[N][N];
int main()
{
    ///smallest/largest case
    ///initialize
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            int a = 0, b = 0, c = 0;
            if (i > 0)
                a = dp[i - 1][j];
            if (j > 0)
                b = dp[i][j - 1];
            if (i > 0 && j > 0)
                c = dp[i - 1][j - 1];
            dp[i][j] = max(a, b);
            if (s[i] == t[j])
                dp[i][j] = max(c + 1, dp[i][j]);
            //cout << dp[i][j] << ' ';
        }
        //cout << '\n';
    }
    //return 0;
    //cout << dp[s.size() - 1][t.size() - 1];
    string res;
    int i = s.size() - 1, j = t.size() - 1;
    while (i >= 0 && j >= 0) {
        //cout << s[i] << ' ' << t[j] << '\n';
        if (s[i] == t[j]) {
            res.push_back(s[i]);
            i--, j--;
        }
        else if (i > 0 && j > 0) {
            if (dp[i - 1][j] > dp[i][j - 1])
                i--;
            else
                j--;
        }
        else if (i > 0)
            i--;
        else
            j--;
    }
    reverse(res.begin(), res.end());
    cout << res;
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <time.h>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#include <math.h>
using namespace std;
typedef long long  ll;
static const ll INF = (ll)1 << 62;
static const ll MOD = 1e9 + 7;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll N, M; cin >> N >> M;
	ll k[10];
	ll s[10][10];
	ll p[10];

	rep(i, 0, M) {
		cin >> k[i];
		rep(j, 0, k[i])cin >> s[i][j];
	}
	rep(i, 0, M)cin >> p[i];

	ll ans = 0;
	for (int n = 0; n < 1 << N; n++) {
		//cout << bitset<10>(n) << endl;
		bool ok = true;
		rep(j, 0, M) {
			ll on = 0;
			rep(x, 0, k[j]) {
				ll swit = s[j][x];
				if (n & (1 << (swit - 1))) {
					on++;
				}
			}
			ok &= (on % 2 == p[j]);
			if (!ok) {
				break;
			}
		}
		if (ok)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import Data.Foldable (for_)
import Data.Functor ((<$>))

main = do
  xs <- takeWhile (/= [0, 0]) . map (map read) . map words . lines <$> getContents
  for_ xs $ \[x, y] -> let zs = if x <= y then [x, y] else [y, x] in putStrLn $ unwords $ map show zs



Measured memory_bytes: 4596
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define ll long long

using namespace std;


void solve(){
    int ac = 0, wa = 0, tle = 0, re = 0;
    int n;
  cin >> n;
  for(int i = 0; i < n; i++)
  {  
      string str;
    cin >> str;
    if(str == "AC")
        ac++;
    else if(str == "TLE")
        tle++;
    else if(str == "RE")
        re++;
    else if(str == "WA")
        wa++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

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

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

vector<long long> candidates;
unordered_map<long long, int> memo;

void init(long long num, int rest) {
	if(num > 1) candidates.emplace_back(num);
	if(rest == 0) return;
	init(num * 10 + 2, rest - 1);
	init(num * 10 + 8, rest - 1);
}

int dfs(const long long n) {
	if(n == 1) return 0;
	if(memo.count(n)) return memo[n];

	int ans = -1;
	for(const auto &e : candidates) {
		if(e > n) break;
		if(n % e == 0) {
			const auto res = dfs(n / e);
			if(res != -1) ans = max(ans, res + 1);
		}
	}

	return memo[n] = ans;
}

int main() {
	init(0, 18);
	sort(begin(candidates), end(candidates));

	long long n;
	cin >> n;

	if(n == 1) {
		cout << -1 << endl;
		return 0;
	}

	cout << dfs(n) << endl;

	return 0;
}

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

int main(void){
	int n,m,i,j,min,sum,sum1,sum2,d;
	int ansa,ansb;
	int a[100];
	int b[100];

	while(scanf("%d%d",&n,&m),n+m){

		sum=sum1=sum2=0;
		min=200;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
			sum1+=a[i];
		}
		for(i=0;i<m;i++){
			scanf("%d",&b[i]);
			sum2+=b[i];
		}

		sum=sum1+sum2;

		if(sum%2){
			printf("-1\n");
		} else {
			d=abs(sum1-sum2)/2;
			for(i=0;i<n;i++){
				for(j=0;j<m;j++){
					if(d==(sum1>sum2?a[i]-b[j]:b[j]-a[i])){
						if(min>a[i]+b[j]){
							ansa=a[i];
							ansb=b[j];
							min=a[i]+b[j];
						}
					}
				}
			}
			if(min==200) printf("-1\n");
			else printf("%d %d\n",ansa,ansb);
		}
	}
	return 0;
}

Measured memory_bytes: 612
import bisect
import itertools

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
dp = [0] * N
for i in range(N):
    up = A[i]
    middleIndex = bisect.bisect(B, up)
    if middleIndex < N:
        if i == 0:
            for j in range(middleIndex, N):
                middle = B[j]
                lowIndex = bisect.bisect(C, middle)
                if lowIndex < N:
                    cnt = N - lowIndex
                    dp[j] = cnt
                    ans += cnt
                else:
                    dp[j] = 0
            dp = list(itertools.accumulate(dp[::-1]))
        else:
            ans += dp[-middleIndex-1]

print(ans)


Measured memory_bytes: 25332
//shara's here
//私は私は大きい男の子
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
const ll MOD = 1e9 + 7;
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll> >
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
	speed;
	ll x,y;
	cin>>x>>y;
	cout<<(x*y)/(__gcd(x,y))<<endl;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	






return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/



Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

bool cmp(int a,int b){
    if (a%10==0 or b%10==0) return (a%10<=b%10);
    return (a%10>=b%10);
}

inline void solve(){
    int a[5],ans=0;
    for (int i=0;i<5;i++) cin >> a[i];
    sort(a,a+5,cmp);
    for (int i=0;i<4;i++){
        if (a[i]%10) a[i]+=(10-(a[i]%10));
    }
    for (int &i: a) ans += i;
    cout << ans << endl;

    
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const int INFI = 1000000000;
 const ll INFL = (1LL << 60);

 int main() {
   int X, Y; cin >> X >> Y;

   bool ok = false;
   rep(i, 0, X + 1) {
     if (i * 2 + (X - i) * 4 == Y) {
       ok = true;
       break;
     }
   }
   if(ok) cout << "Yes" << endl;
   else cout << "No" << endl;
 }


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = 0;
	vector<vector<int>> z;
	
	
	cin>>N;
	
	z.resize(N, vector<int>(N,-1));
	
	for(int i = 0; i < N; i++){
		int A;
		
		cin>>A;
		
		for(int j = 0; j < A; j++){
			int x, y;
			
			cin>>x>>y;
			
			x--;
			
			z[i][x] = y;
		}
	}
	
	for(int i = 0; i < (1<<N); i++){
		int con = 0;
		vector<int> a(N, true);
		bool flag = true;
		
		for(int j = 0; j < N; j++){
			if(((i>>j)&1)) con++;
			for(int k = 0; k < N; k++){
				// if(((i>>j)&1)&&((i>>k)&1)){
				if(((i>>k)&1)){
					
					if(((i>>j)&1) && z[j][k] == 0) flag = false;
				} else {
					if(((i>>j)&1) && z[j][k] == 1) flag = false;
				}
			}
		}
		
		// for(int j = 0; j < N; j++){
			// if() con++;
		// }
		
		// cout<<i<<" "<<con<<endl;
		if(flag) ans = max(ans, con);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    if (s[s.size()-1] == 's'){
        cout << s << "es" << endl;
    } else {
        cout << s << "s" << endl;
    }
    return 0;
}

Measured memory_bytes: 3580
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const n = Number(input);
  const y = Math.floor(n / 15) * 200;
  const x = 800 * n;
  return x - y;
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29400
from numpy import cumsum 
n, m, q = list(map(int, input().split()))
lst = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l, r = list(map(int, input().split()))
    lst[l][r] += 1
ans1 = cumsum(lst, axis=1)
ans = cumsum(ans1, axis=0)
for i in range(q):
    a, b = list(map(int, input().split()))
    print(ans[b, b] - ans[a-1, b])

Measured memory_bytes: 19100
#include<stdio.h>

int sea(int a[],int n,int key);

int main(void){
	int i,n,a[10000+1],q,key,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
		if(sea(a,n,key))sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}

int sea(int a[],int n,int key){
	int i=0;
	a[n]=key;
	while(a[i]!=key)i++;
	
	return i!=n;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+5;
const int mod=998244353;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    if(n%2)
    {
        /*int i=1,j=n;
        while(m--)
        {
            cout<<i<<" "<<j<<'\n';
            i++;
            j--;
        }*/
        if(m==1)
        {
            cout<<1<<" "<<3<<'\n';
            return 0;
        }
        int i=1,j=n/2;
        while(m)
        {
            cout<<i<<" "<<j<<'\n';
            m--;
            i++;
            j--;
            if(i>=j)
                break;
        }
        i=n/2+1,j=n;
        while(m--)
        {
            cout<<i<<" "<<j<<'\n';
            i++;
            j--;
        }
    }
    else
    {
        int i=1,j=n/2;
        while(m)
        {
            cout<<i<<" "<<j<<'\n';
            m--;
            i++;
            j--;
            if(i>=j)
                break;
        }
        i=n/2+2,j=n;
        while(m--)
        {
            cout<<i<<" "<<j<<'\n';
            i++;
            j--;
        }
    }


}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
vector<int> G[200010];
ll par[200010];
void dfs(int s,int p){
    par[s] = p;
    for(int v:G[s]){
        if(v==p) continue;
        dfs(v,s);
    }
}

int main(){
    ll i,n; cin >> n;
    ll ans = 0;
    for(i=0;i<n - 1;i++){
        ll u,v; cin >> u >> v; u--; v--;
        G[u].push_back(v); G[v].push_back(u); 
    }
    dfs(0,n);
    for(i=0;i<n;i++){
        if(par[i]>i) ans += (i + 1)*(par[i] - i);
        else ans += (n - i)*(i - par[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 25392