akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int>P;

int h, w, c, Max;
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
vector<vector<int>>a;
void mark(int x, int y, int b, int c) {
	a[x][y] = c;
	rep(i, 4) {
		int nx = x + dx[i], ny = y + dy[i];
		if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&a[nx][ny] == b)mark(nx, ny, b, c);
	}
}
int cnt = 0;
void dfs(int t) {
	if (t == 0) {
		rep(i, h)rep(j, w) {
			if (a[i][j] != c) {
				if (i == 0 && j == 0)mark(0, 0, a[0][0], c);
				else continue;
			}
			mark(i, j, c, 10);
			int cnt = 0;
			rep(l, h)rep(k, w)if (a[l][k] == 10)Max = max(Max, ++cnt);
			mark(i, j, 10, c);
		}
		return;
	}
	vector<vector<int>>b = a;
	rep(i, 6) {
		if (a[0][0] == i)continue;
		mark(0, 0, a[0][0], i);
		dfs(t - 1); a = b;
	}
}
int main() {
	while (scanf("%d%d%d", &h, &w, &c), h) {
		a = vector<vector<int>>(h, vector<int>(w)); c--;
		rep(i, h)rep(j, w)scanf("%d", &a[i][j]), a[i][j]--;
		Max = 0; dfs(4);
		printf("%d\n", Max);
	}
}

Measured memory_bytes: 3276
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	auto result = N;
	if (N == 100)
	{
		++result;
	}

	for (auto i = 0; i < D; ++i)
	{
		result *= 100;
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
cnt = [0] * (10 ** 5 + 1)
A = [int(_) for _ in input().split()]
for i in range(N):
    cnt[A[i]] += 1
m = 0
for i in range(10 ** 5 + 1):
    if cnt[i] > 0 and cnt[i] % 2 == 0:
        m += 1
print(len(set(A)) - int(m % 2 == 1))


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


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, T;
  cin >> N >> T;
  vector<pair<ll, ll>> AB(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> AB.at(i).first >> AB.at(i).second;
  }
  sort(AB.begin(), AB.end());

  vector<vector<ll>> dp(3333, vector<ll>(6333, 0));
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j < 6300; j++)
    {
      chmax(dp.at(i + 1).at(j), dp.at(i).at(j));

      if (j < T)
        chmax(dp.at(i + 1).at(j + AB.at(i).first), dp.at(i).at(j) + AB.at(i).second);
    }
  }

  ll ans = 0;
  for (ll i = 0; i < 6300; i++)
  {
    chmax(ans, dp.at(N).at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 165376
#include <stdio.h>
#include <string.h>
using namespace std;
char words[100][11];
int main(void){
    // Your code here!
    int N;
    scanf("%d",&N);
    for(int i = 0; i < N; i++){
        scanf("%s",words[i]);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            //printf("%s, %s\n",words[i],words[j]);
            if(i!=j&&strcmp(words[i],words[j]) == 0){
                puts("No");
                return 0;
            }
        }
    }
    for(int i = 1; i < N; i++){
        if(words[i-1][strlen(words[i-1])-1] != words[i][0]){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    
}


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

using namespace std;

void solve(){
    int K, X;
    cin >> K >> X;
    if (500*K >= X) {
        printf("Yes");
    }
    else {
        printf("No");
    }
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd

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

a = sorted(A)
B = [a[0]]
C = []
for i in range(1,N):
    x = a[i]%a[0]
    if x != 0:
        B.append(x)
b =sorted(B)
for i in range(len(b)-1):
    y = gcd(b[i],b[-1])
    C.append(y)
    
if len(b) == 1:
    print(b[0])
else:
    print(min(C))

Measured memory_bytes: 16240
import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    int[][] card = new int[3][3];
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        card[i][j] = in.nextInt();
      }
    }
    int n = in.nextInt();
    int[] target = new int[n];
    for(int i=0; i<n; i++){
      target[i] = in.nextInt();
    }
    System.out.println(bingo(card, target));
  }
  
  static String bingo(int[][] card, int[] target){
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        for(int k=0; k<target.length; k++){
          if(card[i][j] == target[k]){
            card[i][j] = 0;
            break;
          }
        }
      }
    }
    if(card[0][0]==0 && card[0][1]==0 && card[0][2]==0) return "Yes";
    if(card[1][0]==0 && card[1][1]==0 && card[1][2]==0) return "Yes";
    if(card[2][0]==0 && card[2][1]==0 && card[2][2]==0) return "Yes";

    if(card[0][0]==0 && card[1][0]==0 && card[2][0]==0) return "Yes";
    if(card[0][1]==0 && card[1][1]==0 && card[2][1]==0) return "Yes";
    if(card[0][2]==0 && card[1][2]==0 && card[2][2]==0) return "Yes";

    if(card[0][0]==0 && card[1][1]==0 && card[2][2]==0) return "Yes";
    if(card[0][2]==0 && card[1][1]==0 && card[2][0]==0) return "Yes";
    return "No";
  }
}


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

int main(){
    int n, b, f, r, v;
    cin >>n;
    int room[4][3][10]={{{}}};
    for (int i=0; i<n; i++){
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] +=v;
    }

    for (int k=0; k< 4; k++){
        for(int i=0; i<3; i++){
            for(int j=0; j<10; j++){
                cout << " ";
                cout << room[k][i][j];
            }
            cout << endl;
        }
        if (k<3) cout << "####################" << endl;
    }
    
}



Measured memory_bytes: 3116
using System;
using System.Linq;
using System.Collections.Generic;

namespace ZTP001
{
    class C
    {
        static void Main(string[] args)
        {
            //入力
            int N = int.Parse(Console.ReadLine());

            //各値の和とインデックス情報を持つ配列 Tuple<sum,index>
            Tuple<int, int>[] res = new Tuple<int, int>[N];
            //A,B
            int[] A = new int[N];
            int[] B = new int[N];

            //sumの計算をする
            for (int i = 0; i < N; i++)
            {
                int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                A[i] = input[0];
                B[i] = input[1];
                res[i] = Tuple.Create(i, A[i] + B[i]);
            }

            //和の値で降順でソートする
            var res2 = res.OrderByDescending(x => x.Item2);

            //ソートされたデータからインデックスの情報を取り出して、
            //高橋くんのときは奇数番目のA[i]をたす。青木くんのときは偶数番目のB[i]を引く
            long count = 0;
            int index = 0;
            foreach (var i in res2)
            {
                if (index % 2 == 0) count += A[i.Item1];
                else count -= B[i.Item1];
                index++;
            }

            Console.WriteLine(count);
        }
    }
}


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

typedef unsigned long long ull;
int dp[45] = {0};

ull fib(int n) {
  // ???????????????
  if(dp[n] != 0)return dp[n];
  if(n == 1 || n == 0)return 1;
  return dp[n] = fib(n - 2) + fib(n - 1);
}

int main(void) {
  int n;
  cin >> n;
  //cout << fib(n) << endl;
  dp[0] = 1;
  dp[1] = 1;
  for(int i = 2; i <= n; i++){
    dp[i] = dp[i - 1] + dp[i - 2];
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>

int main(void){
	int N,i,j,a=0,c=0;
	scanf("%d",&N);
	int sort[N];
	for(i=0;i<N;i++)
	{
		scanf("%d",&sort[i]);
	}
	
	for(i=0;i<N-1;i++)
	{
		for(j=N-1;j>i;j--)
		{
			if(sort[j-1]>sort[j])
			{
				a=sort[j-1];
				sort[j-1]=sort[j];
				sort[j]=a;
				c=c+1;
			}
		}
	}
	
	for(i=0;i<N-1;i++)
		{
			printf("%d ",sort[i]);
		}
	printf("%d",sort[N-1]);
	printf("\n");
	printf("%d\n",c);
	
	return 0;
}


Measured memory_bytes: 2040
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

vector<int> func(vector<int>);
int func1(vector<int>,int);

int main(){
  int n,num,flag,kazu;
  int i,l;
  vector<int> taro,hanako;
  
  for(;;){
    cin>>n;
    if(n==0) break;
    
    taro.clear();hanako.clear();
    for(i=0;i<n;i++){
      cin>>num;
      taro.push_back(num);
    }
    sort(taro.begin(),taro.end());
    l=0;
    for(i=1;i<=2*n;i++){
      if(i==taro[l]){
        l++;continue;
      }
      else
        hanako.push_back(i);
    }
    
    sort(hanako.begin(),hanako.end());
    
    num=0;flag=2;
    while(taro.empty()==false&&hanako.empty()==false){
      if(num==0){
        if(flag==2){
          num=taro[0];
          taro[0]=0;
          taro=func(taro);
        }
        else if(flag==3){
          num=hanako[0];
          hanako[0]=0;
          hanako=func(hanako);
        }
      }
      else{
        if(flag==2){
          //Ôq³ñÌ
          kazu=func1(hanako,num);
          if(kazu!=-1){
            num=hanako[kazu];
            hanako[kazu]=0;
            hanako=func(hanako);
          }
          else if(kazu==-1){
            num=0;
            flag=2;
            continue;
          }
          
          //¾Y³ñÌ
          kazu=func1(taro,num);
          if(kazu!=-1){
            num=taro[kazu];
            taro[kazu]=0;
            taro=func(taro);
          }
          else if(kazu==-1){
            num=0;
            flag=3;
            continue;
          }
        }
        
        else if(flag==3){
          //ÌÔªt
          
          //¾Y³ñÌ
          kazu=func1(taro,num);
          if(kazu!=-1){
            num=taro[kazu];
            taro[kazu]=0;
            taro=func(taro);
          }
          else if(kazu==-1){
            num=0;
            flag=3;
            continue;
          }
          
          //Ôq³ñÌ
          kazu=func1(hanako,num);
          if(kazu!=-1){
            num=hanako[kazu];
            hanako[kazu]=0;
            hanako=func(hanako);
          }
          else if(kazu==-1){
            num=0;
            flag=2;
            continue;
          }
        }
      }
    }
    printf("%d\n%d\n",hanako.size(),taro.size());
  }
  return 0;
}

vector<int> func(vector<int> a){
  vector<int> A;
  int i;
  A.clear();
  for(i=0;i<(int)a.size();i++){
    if(a[i]!=0)
      A.push_back(a[i]);
  }
  return A;
}

int func1(vector<int> a,int num){
  int i;
  for(i=0;i<(int)a.size();i++){
    if(a[i]>num)
      return i;
  }
  return -1;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
string gay;
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
	    cin>>gay;
	    cout<<gay<<endl<<gay<<endl;
	}
	return 0;
}

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

num = [0] * (10 ** 5 + 1)
for i in A:
    num[i] += 1

ans = sum(A)
for _ in range(Q):
    b, c = map(int, input().split())
    ans += (c - b) * num[b]
    num[c] += num[b]
    num[b] = 0
    print(ans)

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

int ds = 6;

void dprint( int a[] ){
	for( int i = 0; i < ds; i++ ) {
		cout << a[i] << ":";
	}
	cout << endl;

	return; 
}

void dsort( int a[], int i0, int i1, int i2, int i3 ) {
	int ta[] = { a[i0], a[i1], a[i2], a[i3] };
	int min = ta[0];
	for( int i = 0; i < 4; i++ ) {
		if( min > ta[i] ) {
			min = ta[i];
		}
	}

	int t = 0;
	while( true ) {
		if( a[i0] == min ) {
			break;
		}
		t = a[i0];a[i0]=a[i1];a[i1]=a[i2];a[i2]=a[i3];a[i3]=t;
	}

	return;
}

bool dcomp( int a[], int b[] )
{
	for( int i = 0; i < ds; i++ ) {
		if( a[i] != b[i] ) {
			return false;
		}
	}

	return true;
}

bool drollcomp( int a[], int b[], int i0, int i1, int i2, int i3 )
{
	bool ret = false;
	int t = 0;
	for( int i = 0; i < 4; i++ ) {
		t = b[i0];b[i0]=b[i1];b[i1]=b[i2];b[i2]=b[i3];b[i3]=t;
		ret = dcomp( a, b );
		if( ret == true ) {
			break;
		}
	}
	return ret;
}

bool dcheck( int a[], int b[] ) {
	bool ret = false;

	ret = dcomp( a, b );
	if( ret == true ) {
		return ret;
	}

	ret = drollcomp( a, b, 1, 2, 4, 3 );
	if( ret == true ) {
		return ret;
	}

	ret = drollcomp( a, b, 0, 1, 5, 4 );
	if( ret == true ) {
		return ret;
	}

	ret = drollcomp( a, b, 0, 3, 5, 2 );
	if( ret == true ) {
		return ret;
	}

	return ret;
}

int main()
{
	int dx[ds], dy[ds];

	for( int i = 0; i < ds; i++ ) {
		cin >> dx[i];
	}
	dsort( dx, 1, 2, 4, 3 );
	dsort( dx, 0, 1, 5, 4 );

	for( int i = 0; i < ds; i++ ) {
		cin >> dy[i];
	}
	dsort( dy, 1, 2, 4, 3 );
	dsort( dy, 0, 1, 5, 4 );

	bool ret = false;
	ret = dcheck( dx, dy );
	cout << ( ret?"Yes":"No" ) << endl;
	
	return 0;
}


Measured memory_bytes: 3128
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		int cnt = 0;
		for(int i = 0; i < N; i ++) {
			a[i] = sc.nextInt();
			if(a[i] % 2 == 0) {
				if(a[i] % 4 == 0) {
					cnt += 2;
				} else {
					cnt++;
				}
			}
		}
		int goal = (N / 2) * 2;
		if(goal <= cnt) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 51176
import java.util.Scanner;

public class Main{
	public static void main(String [] args){
		//????????£?????????????????????
		Scanner sc = new Scanner (System.in);
		//??°?????????????????????
		int n = sc.nextInt();
		//n????????°?????°?????????
		for(int i = 1; i<= n; i++){

			//??????????????°???
			if(i % 3 == 0 || Integer.toString(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 29184
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by kennzya on 2017/09/30.
 */
public class Main {
    public Main() {
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int lowNumber= sc.nextInt();
        int score = sc.nextInt();
        for(int i = 1;i < count ;i++){
            int tmpNumber = sc.nextInt();
            int tmpScore = sc.nextInt();
            if(tmpNumber > lowNumber){
                lowNumber = tmpNumber;
                score = tmpScore;
            }
        }

        System.out.println(lowNumber + score);
    }
}


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

int main(){
  int n;
  cin >> n;
  int mn = 3000000,cn=0;
  for(int i=0; i<n;i++){
    int p;
    cin >> p;
    if(p<mn) {mn=p; cn++;}
  }
  cout << cn;
  return 0;

}

Measured memory_bytes: 256
n = int(input())
lst = [0]
lst += [int(input()) for i in range(n)]
cnt = 1
flashed = lst[1]

while True:
    if flashed == 2:
        print(cnt)
        break
    elif cnt <= 10**6:
        flashed = lst[flashed]
        cnt += 1
    else:
        print(-1)
        break
    

Measured memory_bytes: 7852
def f(a, b):
    return a**4 + a**3 * b + a**2 * b**2 + a * b**3 + b**4


x = int(input())
pair = [(1, x)]
i = 2
while i*i <= x:
    if x % i == 0:
        pair.append((i, x//i))
    i += 1

for i, j in pair:
    # print(f"pair:{i} {j}")
    a = 0
    b = -i
    while b <= 0 or f(a, b) <= j:
        # print(f(a, b))
        a += 1
        b += 1
        if f(a, b) == j:
            print(f"{a} {b}")
            exit(0)


Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[30010],dp[30010];
int main()
{
    ll n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j+i-1<=n; j++)
        {
            dp[j]=max(a[j]-dp[j+1],a[j+i-1]-dp[j]);
        }
    }

    cout<<dp[1]<<endl;
}


Measured memory_bytes: 256
n = int(input())
cnt = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
    cnt[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b, d;
	ll c;
	//char c;
	ll h, w;
	ll k;
	string s, t;
	ll l_ans = 0;
	string s_ans = "NG";
	ll l, r;

	cin >> a >> b;

	l_ans = max(0LL, a - 2*b);

	cout << l_ans << "\n";

	return;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_a();

	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int c;
    if((a + b) % 2 == 0){
        cout << (a + b) / 2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b = [0],[0]
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])

ans,j = 0,M
for i in range(N+1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)

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

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(Re int i = a;i <= b;++i)
#define nfor(i,a,b) for(Re int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int n;
struct node
{
    int a,b;
}jb[maxn];

bool cmp(node x,node y)
{
    return x.b<y.b;
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>jb[i].a>>jb[i].b;

    sort(jb,jb+n,cmp);
    int now=0;
    int i;
    for(i=0;i<n;i++)
    {
        if(now+jb[i].a<=jb[i].b)
        {
            now+=jb[i].a;
        }
        else
            break;
    }
    if(i==n)
        cout<<"Yes";
    else
        cout<<"No";
	return 0;
}


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

const int MOD = (int)1e9+7;

int main(){
	int N,Q;
	string S;
	cin >> N >> Q >> S;
	vector<int> l(Q);
	vector<int> r(Q);
	for(int i=0;i<Q;i++)	cin >> l.at(i) >> r.at(i);

	vector<int> ac(S.size(),0);
	for(int i=1;i<S.size();i++){
		ac.at(i)=ac.at(i-1);
		if(S.at(i)=='C' && S.at(i-1)=='A')	ac.at(i)++;
		//cout << ac.at(i) << ",";
	}

	for(int i=0;i<Q;i++){
		int L=ac.at(l.at(i)-1);
		int R=ac.at(r.at(i)-1);
		//cout << L << "," << R << ":";
		cout << R-L << endl;
	}

	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s;cin>>s;
  vector<int> a;
  a.push_back(s);
  while(1)
  { 
    int t = a.back();
    t%2==0?t=t>>1:t = 3*t+1;
    auto it = find(a.begin(),a.end(), t);
    if(it!=a.end())break;
    a.push_back(t);
  }
  cout<<a.size()+1<<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() {
    vector<int> x(5);
    rep(i, 5){
        cin >> x[i];
    }

    rep(i, 5){
        if(x[i] == 0){
            cout << i+1 << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = new HashSet<string>(Console.ReadLine().Split());

            Console.WriteLine(s.Count == 3 ? "Three" : "Four");
        }
    }
}


Measured memory_bytes: 13280
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main(){
  int f, m, r;
  for ( int i = 0; i < 50; i++){
    cin >> f >> m >> r;
    
    if (f == -1 && m == -1 && r == -1) break;
    if (f == -1 || m == -1) cout << 'F' << endl;
    else if (f + m >= 80) cout << 'A' << endl;
    else if (f + m >= 65) cout << 'B' << endl;
    else if (f + m >= 50) cout << 'C' << endl;
    else if (f + m >= 30 && r >= 50) cout << 'C' << endl;
    else if (f + m >= 30) cout << 'D' << endl;
    else cout << 'F' << endl;
  }
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;

int main(){
    int a, b, c; cin >> a >> b >> c;
    int largest;
    largest = max(a,b);
    largest = max(largest, c);
    int s = a+b+c;
    int ans=0;
    bool default_parity = (3*largest)%2==0;
    bool s_parity = s%2==0;
    if((default_parity && s_parity) || (!default_parity && !s_parity)){
        ans = ((3*largest)-s)/2;
    }else{
        ans = ((3*(largest+1))-s)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int n;
int id;
int t[100000];
int u[100000];
int v[100000];
int w[100000];
int tmp[100000];
 
void setdepth(int x){
  if(t[x]==-1){
    w[x]=0;
    return;
  }
  if(w[x]!=-1)return;
  setdepth(t[x]);
  w[x]=w[t[x]]+1;
}
 
void init(){
  int i;
  for(i=0;i<100000;i++){
    t[i]=-1;
    u[i]=-1;
    v[i]=-1;
    w[i]=-1;
  }
}
 
int main(){
  int i,j,k,pos;
 
  init();
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&tmp[j]);
      t[tmp[j]]=id;
      if(j>0)v[tmp[j-1]]=tmp[j];
    }
    if(k)u[id]=tmp[0];
  }
 
 
  for(i=0;i<n;i++){
    setdepth(i);
    printf("node %d: parent = %d, depth = %d, ",i,t[i],w[i]);
    if(w[i]==0)printf("root, ");
    else if(u[i]==-1)printf("leaf, ");
    else printf("internal node, ");
    pos=u[i];
    printf("[");
    if(pos!=-1){
      while(1){
    printf("%d",pos);
    pos=v[pos];
    if(pos==-1)break;
    printf(", ");
      }
    }
    printf("]\n");
     
  }
  return 0;
}




Measured memory_bytes: 4636
import java.util.Scanner;

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

        while(sc.hasNext()) {
        	str += sc.nextLine();
        }
        str = str.toLowerCase();

        char[] alphabet = new char[] {'a','b','c','d','e','f','g','h','i','j','k',
        							  'l','m','n','o','p','q','r','s','t','u','v',
        							  'w','x','y','z'};

        int[] ans = new int[alphabet.length];

        for(int i = 0; i < str.length(); ++i) {
        	for(int j = 0; j < alphabet.length; j++) {
        		if(str.charAt(i) == alphabet[j]) {
        			ans[j]++;
        		}
        	}
        }

        for(int i = 0; i < alphabet.length; i++) {
        	System.out.println(String.format("%s : %d", alphabet[i], ans[i]));
        }

    }
}


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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  if((a+b) % 2 == 0) cout << (a+b) /2 << endl;
  else cout << (a+b) /2 + 1 << endl;
  
}


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

#define f first
#define s second
#define n a.length()
#define m b.length()

using namespace std;

const int N = 5005;

pair<int,int> cnt[N][N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string a, b;
    cin >> a >> b;
    if (a.length() < b.length()) {
        swap(a, b);
    }
    for (int i = 0; i<a.length(); i++) {
        for (int j = 0; j<b.length(); j++) {
            if (a[i] == b[j]) {
                if (i > 0) {
                    cnt[i][j].f = cnt[i-1][j-1].f + 1;
                    cnt[i][j].s = 3;
                }
                else
                    cnt[i][j].f = 1, cnt[i][j].s = 3;
            }
            else {
                if (i > 0) {
                    if (cnt[i-1][j].f > cnt[i][j-1].f) {
                        cnt[i][j].f = cnt[i-1][j].f;
                        cnt[i][j].s = 1;
                    }
                    else {
                        cnt[i][j].f = cnt[i][j-1].f;
                        cnt[i][j].s = 2;
                    }
                }
            }
        }
    }
    //cout << cnt[n-1][m-1].f << endl;
    int left = n-1;
    int right = m-1;
    string s = "";

    while( left >= 0 && right >= 0 && cnt[left][right].s) {
        if (cnt[left][right].s == 1)
            left--;
        else if (cnt[left][right].s == 2)
            right--;
        else {
            s.push_back(a[left]);
            left--;
            right--;

        }
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a, b; cin >> a >> b;
    if( b % a == 0 ) cout << -1 << endl;
    else{
        int ans = b + a - b % a;
        if( ans - b <= ans / a - 1 ) cout << -1 << endl;
        else cout << ans << endl;
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1, 0,-1};

int main(){
    int h, w; cin >> h >> w;
    vector<string> g(h);
    rep(i,h) cin >> g.at(i);
    
    rep(i,h){
        rep(j,w) {
            if(g.at(i).at(j) == '#'){
                bool flag2 = 0;
            rep(k,4){
                int ny = i + dy.at(k);
                int nx = j + dx.at(k);
                if(ny > h -1 || ny < 0 || nx > w -1 || nx < 0) continue;
                if(g.at(ny).at(nx) == '#') flag2 = 1;
                }
                if(!flag2) {cout << "No" << endl; return 0;}
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3580
import sys

X,K,D = list(map(int, input().split()))

ans = 9999999
if abs(X) >= K * D:
    ans = abs(X) - K*D
else:
    A = abs(X) % D
    B = K - (abs(X) // D)

    if B % 2 == 0:
        ans = A
    else:
        ans = abs(A - D)

print(ans)

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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(x-a)>=abs(x-b)) cout << "B" << endl;
  else cout << "A" << endl;
}

Measured memory_bytes: 3592
import sys
import math 
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,K=na()
n=N
k=10**9
cnt=0
if(N==1):
    if(K==1):
        print(1)
        exit()
    else:
        ans=0
        while(N<K):
            ans+=1
            N*=2
            #print(N)
        print(0.5**ans)
        exit()
while(N<K):
    #print(N,K)
    K=math.ceil(K/2)
    cnt+=1
k=K

ans=0
first=True
while(True):
    if(first):
        ans+=(N-k+1)*(0.5**cnt)
        first=False
    else:
        ans+=(N-k)*(0.5**cnt)

    #print("ddd",(N-k+1)*(0.5**cnt),"N",N,"k",k,"n-k+1",N-k+1,"cnt",cnt)
    #print("ans",ans)
    cnt+=1
    N=k
    k=math.ceil(k/2)
    #print("k",k)
    if(k==1):
        ans+=1*(0.5**cnt)
        #print("ddd",1*(0.5**cnt))
        #print("cnt",cnt)
        break
#print(ans,n)
ans=ans/n
print(ans)

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

#define MAX 2000001
#define VMAX 10000

int A[MAX],B[MAX];

int main(){
  int n,i,j;
  int C[VMAX+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
    if(A[i]<0 || A[i]>VMAX){
      exit(1);
    }
  }

  for(i=0;i<VMAX+1;i++){
    C[i]=0;
  }

  //C[i]にiの出現数を記録する
  for(i=1;i<=n;i++){
    C[A[i]]++;
  }

  //C[i]にi以下の数の出現数を記録する
  for(i=1;i<VMAX+1;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n-1;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n]);

  return 0;
}

Measured memory_bytes: 16264
#include <set>
#include <cstring>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

using namespace std;

char g[25][25];
int memo[25][25][25][25][15];
char pat[15];

int dx[10] = {
  0, 0, 0, 0, -1, 0, 1, 0, 0, 0
};
int dy[10] = {
  0, 0, 1, 0, 0, 0, 0, 0, -1, 0
};

const int _dx[] = {0,1,0,-1,0};
const int _dy[] = {-1,0,1,0,0};

struct data{
  int x1, y1, x2, y2;
  int p;
};

int main(){
  while(true){
    int h = getInt();
    int w = getInt();
    int len;
    int x1, x2, y1, y2;
    queue<data> que;
    bool ok = false;

    if(h + w == 0) break;
    REP(i,h) scanf("%s", g[i]);
    REP(i,h) REP(j,w){
      if(g[i][j] == 'A'){
        x1 = j; y1 = i;
        g[i][j] = '.';
      }else if(g[i][j] == 'B'){
        x2 = j; y2 = i;
        g[i][j] = '.';
      }
    }

    scanf("%s", pat);
    len = strlen(pat);

    memset(memo, -1, sizeof(memo));
    que.push((data){x1,y1,x2,y2,0});
    memo[y1][x1][y2][x2][0] = 0;

    while(que.size()){
      data d = que.front(); que.pop();
      int x1 = d.x1;
      int y1 = d.y1;
      int x2 = d.x2;
      int y2 = d.y2;
      int p  = d.p;
      int t  = memo[y1][x1][y2][x2][p];

      if(x1 == x2 && y1 == y2){
        ok = true;
        printf("%d %d %d\n", t, y1, x1);
        break;
      }

      REP(i,5){
        int xx1 = x1 + _dx[i];
        int yy1 = y1 + _dy[i];

        int xx2 = x2 + dx[pat[p] - '0'];
        int yy2 = y2 + dy[pat[p] - '0'];
        int pp  = (p + 1) % len;

        if(!ISIN(xx2,yy2,w,h)){
          xx2 = x2;
          yy2 = y2;
        }

        if(ISIN(xx1,yy1,w,h) && memo[yy1][xx1][yy2][xx2][pp] == -1 &&
           g[yy1][xx1] == '.'){

          memo[yy1][xx1][yy2][xx2][pp] = t + 1;
          que.push((data){xx1,yy1,xx2,yy2,pp});
        }
      }
    }

    if(!ok) puts("impossible");
  }

  return 0;
}

Measured memory_bytes: 23000
#include <stdio.h>
int min(int a, int b) {
	if(a < b) return a;
	return b;
}
int main() {
	while(1) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if(a == 0 && b == 0 && c == 0) break;
		int m, n;
		n = min(a, b);
		m = min(c, a + b - n);
		int I, N;
		scanf("%d", &N);
		for(I = 0; I < N; ++ I) {
			int r;
			scanf("%d", &r);
			if(n * n + m * m < 4 * r * r) printf("OK\n");
			else printf("NA\n");
		}
	}
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>>bfr(H,vector<char>(W,' '));
  for(int i = 0;i < H;i++)
  {
  	for(int j = 0;j < W;j++)
  	{
  		cin >> bfr.at(i).at(j);
  	}
  }
//高さを削っていく
  vector<vector<char>>aft1(H,vector<char>(W,' '));
  int i1 = 0,i2 = 0;
  for(int i = 0;i < H;i++)
  {
  	int cnt1 = 0;
  	for(int j = 0;j < W;j++)
  	{
  		if(bfr.at(i).at(j) == '#')
  		{
  			cnt1++;
  		}
  	}
  	if(cnt1 > 0)
  	{
  		for(int j = 0;j < W;j++)
  		{
  			aft1.at(i1).at(j) = bfr.at(i).at(j);
  		}
  		i1++;
  	}
  }
  vector<vector<char>>aft2(H,vector<char>(W,' '));
  for(int i = 0;i < W;i++)
  {
  	int cnt2 = 0;
  	for(int j = 0;j < H;j++)
  	{
  		if(aft1.at(j).at(i) == '#')
  		{
  			cnt2++;
  		}
  	}
  	if(cnt2 > 0)
  	{
  		for(int j = 0;j < H;j++)
  		{
  			aft2.at(j).at(i2) = aft1.at(j).at(i);
  		}
  		i2++;
  	}
  }
  for(int i = 0;i < H;i++)
  {
  	for(int j = 0;j < W;j++)
  	{
  		if(aft2.at(i).at(j) == ' ')
  		{
  			cout << endl;
  			break;
  		}
  		else if(j == W - 1)
  		{
  			cout << aft2.at(i).at(j) << endl;
  		}
  		else 
  		{
  			cout << aft2.at(i).at(j);
  		}
  	}
  }
}


Measured memory_bytes: 256
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()
    
    n = int(input())
    red = [tuple(map(int, input().split())) for _ in range(n)]
    blue = [tuple(map(int, input().split())) for _ in range(n)]

    red.sort()
    blue.sort()

    now = 0
    for i in blue:
        while now < len(red) and red[now] < i:
            now += 1
        
        l = red[:now]
        if l == []:
            continue

        l = sorted(l, key=lambda x: x[1])
        if l[0][1] > i[1]:
            continue
        
        # binary search
        left = 0
        right = len(l) - 1
        while left < right:
            center = (left + right + 1) // 2
            if l[center][1] < i[1]:
                left = center
            else:
                right = center - 1

        red.remove(l[left])
        now -= 1

    print(n - len(red))

main()

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int N = 2e5 + 5;

int n;
int h[N], a[N];
ll ft[N];

void update(int i, ll x) {
    for (; i <= n; i += i&-i) ft[i] = max(ft[i], x);
}

ll qmax(int i) {
    ll maxi = 0;
    for (; i; i -= i&-i) maxi = max(maxi, ft[i]);
    return maxi;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    FOR(i,1,n) cin >> h[i];
    FOR(i,1,n) cin >> a[i];

    memset(ft, 0, sizeof ft);

    ll dp[n+1];
    FOR(i,1,n) {
        dp[i] = qmax(h[i]-1) + a[i];
        update(h[i], dp[i]);
    }

    cout << qmax(n) << '\n'; // lis can end anywhere
}



Measured memory_bytes: 4992
#include <iostream>
using namespace std;
 
int c[27];
int s[366][27];
int t[366];
int last[27];


 
/*int dissatisfied(int d){
    int dis=0;
    for(int j=1;j<=26;j++){
        dis+=c[j]*(d-last[t[d]]);
    }
    return dis;
}
 
 
int solve(int d){
    int res=0;
    for(int i=1;i<=d;i++){
        res=res+s[i][t[i]]-dissatisfied(i);
    }
    return res;
}*/
 
 
int main(void){
    int D;cin>>D;
    
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    
    for(int i=1;i<=D;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
    
    for(int i=1;i<=D;i++){
        cin>>t[i];
    }
    int v=0;
    for(int i=1;i<=D;i++){
        cin>>t[i];
        last[t[i]]=i;
        v+=s[i][t[i]];
        
        for(int j=1;j<=26;j++) v-=c[j]*(i-last[j]);
        cout<<v<<endl;
        
        
        //cout<<solve(i)<<endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 3628
/* ex7_3 
melo */
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int row_N,col_N,i,j;//整数の箱を４つ用意する
    char **arrayc;//二重ポインタ
    int *row_TorF, *col_TorF;//黒があるかないか判別する
    scanf("%d %d",&row_N,&col_N);//行と列を代入
    arrayc=(char**)calloc(row_N,sizeof(char*));//領域を確保して確保した領域を0に初期化する
    if(arrayc==NULL){
        fprintf(stderr,"memory allocation error.\n");
        exit(1);
    }
    for(int i=0;i<row_N;i++){
        arrayc[i]=(char*)calloc(col_N,sizeof(char));
        if(arrayc[i]==NULL){
            fprintf(stderr,"memory allocation error.\n");
            exit(1);
        }
    }
    row_TorF=(int*)calloc(row_N,sizeof(int));
    if(row_TorF==NULL){
        fprintf(stderr,"memory allocation error.\n");
        exit(1);
    }
    col_TorF=(int*)calloc(col_N,sizeof(int));
    if(col_TorF==NULL){
        fprintf(stderr,"memory allocation error.\n");
        exit(1);
    }
    for(i=0;i<row_N;i++){//二次元の文字配列を代入
        for(j=0;j<col_N;j++){
            scanf(" %c",&arrayc[i][j]);
        }
    }
    for(i=0;i<row_N;i++){//黒がある行と列を探す
        for(j=0;j<col_N;j++){
            if(arrayc[i][j]=='#'){
                row_TorF[i]=1;//i列には黒がある
                col_TorF[j]=1;//i行には黒がある
            }
        }
    }
    for(i=0;i<row_N;i++){//白いマスのみからなる列または行以外（黒があった列または行）を表示する
        for(j=0;j<col_N;j++){
            if(row_TorF[i]==1&&col_TorF[j]==1){
                printf("%c",arrayc[i][j]);
            }
        }
        if(row_TorF[i]==1){
                printf("\n");//1列分表示されたら改行する
        }
    }
    free(row_TorF);
    free(col_TorF);
    for(int i=0;i<row_N;i++){
        free(arrayc[i]);
    }
    free(arrayc);
    return 0;//正常終了
}

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

using namespace std;

#define x first
#define y second
typedef long long ll;
const int N = 200010;
const int mod = 1000000007;
const int oo = 1e9;
const int base = 27;
typedef pair<int,int> pii;

int L , a[N],f,s;
ll dp[N][6];

int cost(int num , int type){
  if(type == 1 || type == 5)return num;
  if(type == 2 || type == 4)return (num == 0?2:num%2 != 0);
  return num%2 == 0;
}
ll calc(int idx , int type){
  if(idx == L+1)return 0;
  ll &ret = dp[idx][type];
  if(ret != -1)return ret;
  ret = calc(idx+1,type)+cost(a[idx],type);
  if(type != 5)ret = min(ret,calc(idx,type+1));
  return ret;
}
int main() {
  memset(dp,-1,sizeof dp);
  cin >> L;
  for(int i =1 ; i <= L ; ++i)cin >> a[i];
  
  cout << calc(1,1) << endl;
/*  int odd = 0 , even = 0;
  for(int i = f ; i <= s ; ++i){
    odd += (a[i]%2 == 0);
    even += (a[i]%2 == 1);
    if(!a[i])even += 2;
  }
  int ans = min(odd,even);
  ans = min(calc(f,1),ans);
  cout << ans << endl;*/
 
  return 0;
}

Measured memory_bytes: 19712
N = int(input())
A = list(map(int,input().split()))
data = [0] * (N+1)
preans = [0] * (N+1)

for i in range(N):
    data[A[i]] += 1

for i in range(1,N+1):
    preans[i] = (data[i]*(data[i]-1))//2

s = sum(preans)

for i in range(N):
    print(s-data[A[i]]+1)
    


Measured memory_bytes: 24748
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    X = [0 for _ in range((N-1)//2)]
    l, r = 1, N // 2
    for i in range((N//2)//2):
        X[i] = [l, r]
        l += 1
        r -= 1
    l, r = N, N // 2 + 2
    for i in range((N-1)//2-(N//2)//2):
        X[i+(N//2)//2] = [l, r]
        l -= 1
        r += 1
    for i in range(M):
        print(X[i][0], X[i][1])
else:
    for i in range(M):
        print(N-i, i+1)


Measured memory_bytes: 19236
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<functional>

using namespace std;

typedef pair<int, int> P;
typedef long long int ll;

int N, K;

int main() {
	cin >> N >> K;

	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - K << endl;
	}


}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Vector;
import java.math.BigInteger;

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

    int n = sc.nextInt();
    while(sc.hasNextBigInteger()){
      BigInteger bi1 = sc.nextBigInteger();
      BigInteger bi2 = sc.nextBigInteger();
      if ( 80 < bi1.toString().length() || 80 < bi2.toString().length() ){
        System.out.println("overflow");
        continue;
      }
      BigInteger sum = bi1.add(bi2);
      if ( 80 < sum.toString().length() ){
        System.out.println("overflow");
        continue;
      }
      System.out.println( sum ); 
    }
  }
}

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

int main(){
  int N,M,R;
  cin >> N >> M >> R;
  vector<int> r(R);
  for(int i=0;i<R;i++){
    cin >> r.at(i);
    r.at(i)--;
  }
  vector<vector<int>> graph(N,vector<int>(N,1e9));
  for(int i=0;i<M;i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    graph.at(a).at(b)=c;
    graph.at(b).at(a)=c;
  }

  //warshall-floyd
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        graph.at(i).at(j)=min(graph.at(i).at(j),graph.at(i).at(k)+graph.at(k).at(j));
        graph.at(j).at(i)=graph.at(i).at(j);
      }
    }
  }
  int ans=1e9;
  sort(r.begin(),r.end());
  do{
    int res=0;
    for(int i=0;i<R-1;i++){
      res+=graph.at(r.at(i)).at(r.at(i+1));
    }
    ans=min(ans,res);
  }while(next_permutation(r.begin(),r.end()));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
/** coder Mohammad Al-Hussein *_^ */
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod  1000000007
#define write freopen("output.txt","w",stdout)
#define read freopen("test (1).txt","r",stdin)
#define FIO std::ios_base::sync_with_stdio(false);
using namespace std;

int main()
{
    bool ok = 0;
    string s;
    cin >> s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i] == 'C') ok = 1;
        if(s[i] == 'F' && ok)
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";



    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 a = sc.nextInt();
        int p = sc.nextInt();

        int piece = a*3 + p;
        int applepie = piece/2;

        System.out.println(applepie);
    }
}

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

bool ok(int x, int y, int z, int N)
{
  return 0 <= x && x < N && 0 <= y && y < N && 0 <= z && z < N;
}

bool finish(const vector<vector<vector<int> > >& c, int M, int me)
{
  const int N = c.size();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        for (int d = 0; d < 27; d++) {
          int x = i, y = j, z = k;
          int m = 0;
          int dx = (d%3)-1;
          int dy = (d/3%3)-1;
          int dz = (d/9%3)-1;
          if (dx == 0 && dy == 0 && dz == 0) {
            continue;
          }
          while (ok(x, y, z, N)) {
            if (c[x][y][z] == me) {
              ++m;
            } else {
              m = 0;
            }
            if (m >= M) {
              return true;
            }
            x += dx;
            y += dy;
            z += dz;
          }
        }
      }
    }
  }
  return false;
}

int main()
{
  int N, M, P;
  while (cin >> N >> M >> P && N != 0) {
    vector<pair<int,int> > xy(P);
    for (int i = 0; i < P; i++) {
      cin >> xy[i].first >> xy[i].second;
      --xy[i].first;
      --xy[i].second;
    }

    vector<vector<vector<int> > > cube(N, vector<vector<int> >(N, vector<int>(N, -1)));
    for (int i = 0; i < P; i++) {
      vector<int>& v = cube[xy[i].first][xy[i].second];
      for (int j = 0; j < N; j++) {
        if (v[j] == -1) {
          v[j] = i&1;
          break;
        }
      }
      if (finish(cube, M, i&1)) {
        cout << (i&1 ? "White" : "Black") << ' ' << i+1 << endl;
        goto NEXT;
      }
    }
    cout << "Draw" << endl;
NEXT:
    ;
  }
  return 0;
}

Measured memory_bytes: 916
package main

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

func main() {

	answer := "123"
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := 0; i < 2; i++ {
		sc.Scan()
		s := sc.Text()
		answer = strings.Replace(answer, s, "", 1)
	}

	fmt.Println(answer)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define pii pair<int, int>
#define fi first
#define sc second
typedef long long ll;
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a_ori(n);
    rep(i, n)cin >> a_ori[i];
    
    ll ans = ll(1) << 40;
    rep(i, 1<<n){             //ビット全探索で、1になった建物を必ず見えるようにする。
        vector<int> a(a_ori);
        vector<int> list;
        rep(j, n)if(i & 1<<j)list.push_back(j);
        
        ll cost = 0;
        rep(j, list.size()){
            int targ = list[j];
            int max_h = 0;     // jより前の建物の中で一番高いやつの高さ。
            rep(k, targ)max_h = max(max_h, a[k]);
            if(max_h>=a[targ]){
                int diff = max_h - a[targ] + 1;
                a[targ] += diff;
                cost += diff;
            }
        }
        
        int max_h = 0;
        int cnt = 0;
        rep(j, n){
            if(a[j]>max_h){
                max_h = a[j];
                cnt++;
            }
        }
        
        if(cnt>=k && cost<ans)ans = cost;
    }
    
    
    cout << ans << endl;
}

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

int main() {
    cin.tie(0); cin.sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
dp = [float("inf")]*(1<<n)
dp[0]=0
kagi = []
for i in range(m):
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    kagi.append([a,b,c])
for j in range(m):
    for i in range(1<<n):
        tmp = i+0
        for k in kagi[j][2]:
            tmp = tmp | 1<<(k-1)
        dp[tmp] = min(dp[tmp],dp[i]+kagi[j][0])
print(dp[(1<<n)-1] if dp[(1<<n)-1] != float("inf") else -1)

Measured memory_bytes: 49496
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b,x=mp()
if a*a*b>=2*x:
    print(math.degrees(math.atan((b*b*a)/(2*x))))
else:
    print(math.degrees(math.atan(2*b/a-2*x/(a**3))))

Measured memory_bytes: 10612
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <set>
#include <map>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 3e18;
const unsigned long long HASHBASE = 1222827239ull;
const long long MOD = 1000000007ll;
const double Pi = acos(-1.0);
const double eps = 1e-6;
/////////////////////////

/////////////////////////
int main()
{
    //ios::sync_with_stdio(false); cin.tie(0);
    long long n;
    scanf("%lld",&n);
    if(n<=1000000000ll)
    {
        printf("0 0 0 1 %lld 0\n",n);
    }
    else
    {
        if(n==1000000000000000000ll)
        {
            printf("0 0 0 1000000000 1000000000 0\n");
            return 0;
        }
        long long q=n/1000000000ll+1;
        long long d1=q*1000000000ll-n;
        printf("0 0 1 1000000000 %lld %lld\n",q,d1);
    }
    return 0;
}


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

using namespace std;

#define MAX 10000

int main(){
    int n;
    cin >> n;
    int T,A;
    cin >> T >> A;
    int H[MAX];
    double diff = 1000000000;

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

    int ans=0;
    double v=0.0;
    for (int i=0;i<n;i++){
        v=abs(A-T+H[i]*0.006);
        // cout << v << endl;
        if(diff > v){
            diff=v;
            ans=i;
        }
    }
    cout << ans+1 << endl;

    

    return 0;
}

Measured memory_bytes: 3648