akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	if (n+1)/2 < k {
		fmt.Fprintln(writer, "NO")
		return
	}
	fmt.Fprintln(writer, "YES")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;

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

int main(){
	int N;
	ll b = INF;
	std::cin >> N;
	for ( int i = 0 ; i < N ; i++ ) {
		ll a;
		std::cin >> a;
		if(a%2 == 1){
			b = 0;
			break;
		}else{
			int cnt=0;
			while(!(a%2)){
				a=a/2;
				cnt ++;
			}
			b = (cnt < b) ? cnt : b;
		}
	}
	std::cout << b << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int c[500];
int s[500];
int f[500];
int ans[500];

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>c[i]>>s[i]>>f[i];
    }
    for(int i=n-2;i>=0;i--){
        int time=s[i]+c[i];
        if(i==n-2){
            ans[i]=time;
            continue;
        }
        for(int j=i+1;j<n-1;j++){
            if(s[j]>=time){
                ans[i]=ans[j];
                break;
            }
            else{
                if(time%f[j]==0) time=time+c[j];
                else time=(time/f[j]+1)*f[j]+c[j];
                if(j==n-2) ans[i]=time;
            }
        }
    }
    ans[n-1]=0;
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF 1LL<<60
typedef long long ll;

int N, M;

ll d1[200][200]; // Land
ll d2[200][200]; // Sea

ll dp[1010][200];

int R;
int Z[1010];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while (cin >> N >> M)
	{
		if (N == 0) return 0;
		
		rep(i, 0, N) rep(j, 0, N) d1[i][j] = d2[i][j] = INF;
		rep(i, 0, N) d1[i][i] = d2[i][i] = 0;

		rep(i, 0, M)
		{
			int x, y, t; char sl;
			cin >> x >> y >> t >> sl;
			x--; y--;

			if (sl == 'L')
				d1[x][y] = d1[y][x] = t;
			else
				d2[x][y] = d2[y][x] = t;
		}

		rep(k, 0, N) rep(i, 0, N) rep(j, 0, N)
			d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);
		rep(k, 0, N) rep(i, 0, N) rep(j, 0, N)
			d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);

		cin >> R;
		rep(i, 0, R) cin >> Z[i];
		rep(i, 0, R) Z[i]--;

		rep(i, 0, R) rep(j, 0, N) dp[i][j] = INF;
		dp[0][Z[0]] = 0;

		rep(i, 0, R - 1) rep(j, 0, N) if (dp[i][j] != INF)
		{
			ll dd = dp[i][j] + d1[Z[i]][Z[i + 1]];
			dp[i + 1][j] = min(dp[i + 1][j], dd);

			rep(k, 0, N)
			{
				dd = dp[i][j] + d1[Z[i]][j] + d2[j][k] + d1[k][Z[i + 1]];
				dp[i + 1][k] = min(dp[i + 1][k], dd);
			}
		}

		ll ans = INF;
		rep(i, 0, N) ans = min(ans, dp[R - 1][i]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 5332
let pi x = 2.0 *. acos 0.0 *. x
let () =
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun i -> Scanf.scanf " %f %f" (fun x y -> i,x,y)) in
  Array.init n (fun i ->
    let _, x, y = a.(i) in
    let f o pr = Array.fold_left (fun (l, u) (j, x', y') ->
      if i = j then l, u else
      let rad = mod_float (o +. pi 1.0 +. atan2 (y' -. y) (x' -. x)) (pi 2.0) in
      max l (rad -. pi 0.5), min u (rad +. pi 0.5)
    ) pr a in
    let l0, u0 = f 0.0 (pi 0.5, pi 1.5) in
    let l1, u1 = f (pi 1.0) (pi 0.5, pi 1.5) in
    ( max 0.0 (u0-.l0) +. max 0.0 (u1-.l1) ) /. pi 2.0
  ) |> Array.iter (Printf.printf "%.10f\n")


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(ll)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,i;cin>>n>>i;
    cout<<n-i+1<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

int SumDigitValues(int x)
{
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x = x / 10;
	}

	return sum;
}

int Factorial(int n)
{
	if (n < 0) return 0;
	if (n == 0) return 1;
	return n * Factorial(n - 1);
}

int factorial(int n)
{
	if (n > 1)
	{
		return n * factorial(n - 1);
	}
	else
	{
		return 1;
	}
}

int main()
{
	int a;
	string s;
	cin >> a;
	cin >> s;
	if (a >= 3200)
	{
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    set<int> info;
    rep(i,3){
        int A;cin>>A;
        info.insert(A);
    }
    if(info.size()==2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main() {
    char c[100000];
    cin >> c;
    for(int i = 0; i < strlen(c); i = i + 2) {
        cout << c[i];
    }
    cout << endl;
}

Measured memory_bytes: 384
N,M = map(int,input().split())
p=10**9+7

def comb(a,p):
    ini=1
    for i in range(1,a+1):
        ini = (ini*i)%p
    return ini


if abs(N-M)>1:
    ans=0
else:
    if N!=M:
        k=1
    else:
        k=2
       
    dog=comb(N,p)
    mon=comb(M,p)
    tot=comb(N+M,p)
   
    ans= (k*dog*mon)%p
   
print(ans)

Measured memory_bytes: 3064
import math
n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        a = 0
        for k in range(d):
            a += (x[i][k] - x[j][k])**2
        if math.sqrt(a)==int(math.sqrt(a)):
            ans += 1
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;
//
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] ACs =new int[n+1];
		int[] WAs =new int[n+1];
		for (int i=0;i<n+1;i++) {
			ACs[i]=0;
			WAs[i]=0;
		}
		for (int i=1;i<=m;i++) {
			int p=sc.nextInt();
			String s=sc.next();
			if (s.equals("AC")&&ACs[p]==0) {
				ACs[p] ++;
			} else if (s.equals("WA")&&ACs[p]==0){
				WAs[p] ++;
			}
		}
		int sumAC =0;
		int sumWA =0;
		for (int i=1;i<=n;i++) {
			sumAC += ACs[i];
			if (ACs[i]==1){
				sumWA += WAs[i];
			}

		}
		System.out.println(sumAC);
		System.out.println(sumWA);
		
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
	//----------------------------------------
	//メソッド置き場

	//----------------------------------------
}

Measured memory_bytes: 64304
#include <iostream>
#include "algorithm"
using namespace std;
int main(int argc, char *argv[])
{
	int n,m,x,y;
	while(cin>>n>>m>>x>>y)
	{
		int i;
		int a[105],b[105];
		for(i = 0;i<n;i++)
		{
			cin>>a[i];
		}
		for(i = 0;i<m;i++)
		{
			cin>>b[i];
		}
		sort(a,a+n);
		sort(b,b+m);
		
		int flag = 0;
		if (x < y)
		{
			for(i =x + 1;i<=y;i++)
			{
				if (i <= b[0]&&i>a[n - 1])
				{
					flag = 1;
				}
			}
		}
		else
		{
			for(i =y + 1;i<=x;i++)
			{
				if (i <= a[0]&&i>b[n - 1])
				{
					flag = 1;
				}
			}	
		}
		if (flag)
		{
			cout<<"No War"<<endl;
		}
		else
		{
			cout<<"War"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}

int main() {
    string s; cin >> s;
    int ans = 0;
    for(int i = 0;i < s.length();i++){
        if(s[i] == '1') ans++;
    }
    cout << ans;
}




Measured memory_bytes: 3596
#include<stdio.h>
 
int main(void){
  int A,B;
  int count = 0;
  scanf("%d%d",&A,&B);
  if(B <= 1){
    printf("0");
    return 0;
  }
  while(1){
    if(B <= (count * (A - 1) + A)){
      printf("%d",count + 1);
      return 0;
    }
    count++;
  }
  return 0;
}


Measured memory_bytes: 128
import java.math.BigDecimal;
import java.util.Scanner;
 
public class Main {    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        BigDecimal abi = new BigDecimal(a);
        String b = sc.next();
        BigDecimal bbi = new BigDecimal(b);
        BigDecimal ans = abi.multiply(bbi);
        long pri = ans.longValue();

        System.out.println(pri);
        sc.close();
    }
}

Measured memory_bytes: 36016
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    H,W =map(int,input().split())
    A =[]
    h = []
    w = []
    count =0
    for i in range(H):
        a = list(str(input()))
        if a.count('#')==0:
            continue
        else:
            A.append(a)
            count +=1


    for j in range(W):
        for i in range(count):
            if A[i][j] =="#":
                break

            if i == count-1:
                w.append(j)

    for i in range(count):
        for j in range(W):
            if j not in w:
                print(A[i][j],sep="",end="")
        print("")







if __name__ == "__main__":
    main()


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

int validCheck(vector<vector<int>> &vec, int n, int t, int cur)
{
    if(vec[n].empty()
    || (int)vec[n].size() < t+1)
    {
        return -1;
    }
    vector<int>::iterator it = lower_bound(vec[n].begin(), vec[n].end(), cur);
    if(it == vec[n].end()
    || *it < cur)
    {
        return -1;
    }
    return *it;
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> vec(10);
    string lucky;
    cin >> lucky;
    for(int i = 0; i < n; ++i)
    {
        int t = lucky[i] - '0';
        if(vec[t].empty())
        {
            vec[t] = vector<int>();
        }
        vec[t].push_back(i);
    }

    int ans = 0;
    vector<int> idxInfo(10);
    for(int i = 0; i < 1000; ++i)
    {
        int t = 0;
        int current = 0;
        idxInfo = vector<int>(10);
        int n1 = i / 100;
        int n2 = i % 100 / 10;
        int n3 = i % 10;

        t = idxInfo[n1];
        current = validCheck(vec, n1, t, -1);
        if(current < 0)
        {
            continue;
        }
        idxInfo[n1] += 1;
        
        t = idxInfo[n2];
        current = validCheck(vec, n2, t, current+1);
        if(current < 0)
        {
            continue;
        }
        idxInfo[n2] += 1;
        
        t = idxInfo[n3];
        current = validCheck(vec, n3, t, current+1);
        if(current < 0)
        {
            continue;
        }
        idxInfo[n3] += 1;
        ++ans;
    }
    cout << ans << endl;
}

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

#define N 15 //魔法陣の最大サイズ

int main(void) {
	int A[N][N] = {};
	int n;
	
	while(cin >> n) {
		if(n == 0) break;
		
		//初期化
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				A[i][j] = 0;
			}
		}
		
		int i = n / 2 + 1; //1を埋める行
		int j = n / 2; //1を埋める列
		int t = 1; //代入する値
		while(true) {
			A[i][j] = t;
			++t;
			if(t > n*n) break;
			++i;
			++j;
			if(i == n) i = 0;
			if(j == n) j = 0;
			if(A[i][j] != 0) {
				++i;
				--j;
				if(i == n) i = 0;
				if(j < 0) j = n - 1;
			}
		}
		
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				printf("%4d", A[i][j]);
			}
			cout << endl;
		}
	}
	
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        c += int(x % 2 == 0 && x % 4 != 0);
        a += int(x % 2 == 1);
        b += int(x % 4 == 0);
    }
    if (c != 0)
        b--;
    if (b + 1 >= a)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
tmp = 1000000
for i in range(N):
  target1 = W[0:i+1]
  target2 = W[i+1:N]
  if tmp > abs(sum(target1)-sum(target2)):
    tmp = abs(sum(target1)-sum(target2))
print(tmp)

Measured memory_bytes: 3060
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (string &str : s)
  {
    cin >> str;
  }

  vector<int> dx{1, 0, -1, 0};
  vector<int> dy{0, -1, 0, 1};

  bool ok = false;

  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (s.at(i).at(j) == '#')
      {
        ok = true;
        for (int k = 0; k < 4; k++)
        {
          int x = j + dx.at(k);
          int y = i + dy.at(k);
          if (x < 0 || x >= w || y < 0 || y >= h)
          {
            continue;
          }
          if (s.at(y).at(x) == '#')
          {
            ok = false;
            break;
          }
        }
      }
      if(ok){
        break;
      }
    }
    if(ok){
      break;
    }
  }

  if (ok)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

ll bigmod(ll a, ll p, ll m){
    ll res=1,x=a;
    while(p){
        if(p&1) res=(res*x)%m;
        x=(x*x)%m;
        p=p>>1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n,zero=0;
    cin>>n;
    map <pll,ll> mp;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        ll gcd=__gcd(a,b);
        if(gcd==0) zero++;
        else{
            a/=gcd,b/=gcd;
            if(a<0) a=-a,b=-b;
            mp[{a,b}]++;
        }
    }
    ll ans=1;
    for(auto x: mp){
        if(x.ss==0) continue;
        ll tmp=bigmod(2,x.ss,mod);
        ll a=x.ff.ff,b=x.ff.ss;
        b=-b;
        if(b<0) b=-b,a=-a;
        if(mp.count({b,a})){
            tmp=(tmp+bigmod(2,mp[{b,a}],mod)+mod-1)%mod;
            mp[{b,a}]=0;
        }
        ans=(ans*tmp)%mod;
    }
    ans=(ans+zero+mod-1)%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16156
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define swap(type,x,y) do{type t=x; x=y; y=t;}while(0)

void quick(int a[][4],int left,int right,int num){
	int i;
	int pl=left;
	int pr=right;
	int x=a[(pl+pr)/2][num];
	
	do{
		while(a[pl][num]<x) pl++;
		while(a[pr][num]>x) pr--;
		if(pl<=pr){
			for(i=0;i<=3;i++){
				swap(int,a[pl][i],a[pr][i]);
			}
			pl++;
			pr--;
		}
	}while(pl<=pr);
	if(left<pr) quick(a,left,pr,num);
	if(pl<right) quick(a,pl,right,num);
}

int main(void){
	int i,j;
	
	int n,m;
	scanf("%d%d",&n,&m);
	
	int b[n+1];
	for(i=1;i<=n;i++){
		b[i]=1;
	}
	
	int a[m+1][4];
	for(i=1;i<=m;i++){
		scanf("%d%d",&a[i][1],&a[i][2]);
		a[i][0]=i;
	}

	quick(a,1,m,2);
	
	for(i=1;i<=m;i++){
		a[i][3]=b[a[i][1]];
		b[a[i][1]]++;
	}
	
	quick(a,1,m,0);
	
	for(i=1;i<=m;i++){
		printf("%06d%06d\n",a[i][1],a[i][3]);
	}
	
	return 0;
}

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

int n,m,cnt[2000];

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<1<<10;++i)
		cnt[i]=(cnt[i>>1]^(i&1));
	for(int i=1;i<1<<n;++i) {
		for(int j=1;j<1<<m;++j)
			printf("%d",cnt[i&j]^cnt[(i-1)&j]^cnt[i&(j-1)]^cnt[(i-1)&(j-1)]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

string N;
ll dp[15][10][10][2][2]; // i桁目まで決めた, Aの開始, Bの開始, Aのmax, Bのmax

ll dfs(int d, int As, int Bs, bool Am, bool Bm) {
	if (d == -1) return 1;
	ll &res = dp[d][As][Bs][Am][Bm];
	if (~res) return res;
	res = 0;
	REP(i, 10) REP(j, 10) {
		if (d == 0 && (i == 0 || j == 0)) continue;
		int nAs = As == 0 ? i : As;
		int nBs = Bs == 0 ? j : Bs;
		if (Am && i > N[d] - '0') continue;
		if (Bm && j > N[d] - '0') continue;
		if (d == 0 && (i != nBs || j != nAs)) continue;
		res += dfs(d - 1, nAs, nBs, Am & (i == N[d] - '0'), Bm & (j == N[d] - '0'));
	}
	return res;
}

int main() {
	cin >> N;
	reverse(ALL(N));
	while (N.size() < 15) N += '0';
	memset(dp, -1, sizeof(dp));
	cout << dfs(14, 0, 0, true, true) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":"\n");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        #define endl "\n"
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    vector<int> a(3);
    cin >> a;
    sort(ALL(a));
    int mn = a[0];
    REP(i, 3) a[i] -= mn;

    int ans = 0;
    if (a[1] % 2) {
        ans += (a[1] + 1) / 2 + 1;
    } else {
        ans += a[1] / 2;
    }
    ans += a[2] - a[1];
    cout << ans << endl;
    return 0;
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  int a=0,b=0,c=0;
  for(int i = 0; i < n; ++i){
    int x; cin >> x;
    if(x % 2 == 1)c++;
    else if(x % 4 == 0)a++;
    else b++;
  }
  int pre = 2;
  bool f = true;
  while(a > 0 || b > 0 || c > 0){
    if(pre == 2){
      if(c > 0){
	c--;
	pre = 0;	
      }
      else break;
    } else if(pre == 1){
      if(b > 0){
	b--;
	pre = 1;
      } else if(a > 0){
	a--;
	pre = 2;
      } else {
	f = false;
	break;
      }
    } else {
      if(a > 0){
	a--;
	pre = 2;
      } else {
	f = false;
	break;
      }
    }
  }
  cout << (f?"Yes":"No") << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
using namespace std;

void solve(){
	int n; cin >> n;
	vector<int> x(n),y(n);
	vector<int> sum(n),diff(n);
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
		sum[i] = x[i]+y[i];
		diff[i] = x[i] - y[i];
	}
	sort(sum.begin(),sum.end());
	sort(diff.begin(),diff.end());
	cout << max(sum[n-1]-sum[0],diff[n-1]-diff[0]) << endl;
}

int main(){

/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif*/
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//int t;cin >> t;while(t--){solve();}
	solve();
	return 0;
}

Measured memory_bytes: 6256
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
using multiInt = boost::multiprecision::cpp_int;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

int main()
{
  init_main();

  int h, w;
  cin >> h >> w;
  string s[50];
  rep(i, h) cin >> s[i];
  rep(i, h) rep(j, w)
  {
    if (s[i][j] == '.')
      continue;
    bool black = false;
    if (i + 1 != h && s[i + 1][j] == '#')
      black = true;
    if (i - 1 >= 0 && s[i - 1][j] == '#')
      black = true;
    if (j + 1 != w && s[i][j + 1] == '#')
      black = true;
    if (j - 1 >= 0 && s[i][j - 1] == '#')
      black = true;
    if (!black)
    {
      Yes(0);
      return 0;
    }
  }
  Yes(1);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 998244353
const int N = 3010;
int dp[N][N];

int main(){
	int a , b , c , d;
	cin >> a >> b >> c >> d;
	for(int i = a;i <= c;i++){
		for(int j = b;j <= d;j++){
			if(i == a && j == b){
				dp[i][j] = 1;
				continue;
			}
			if(i == a)
				dp[i][j] = (long long)dp[i][j - 1] * i % mod;
			else if(j == b)
				dp[i][j] = (long long)dp[i - 1][j] * j % mod;
			else{
				dp[i][j] = (long long)dp[i][j - 1] * i % mod;
				dp[i][j] += (long long)dp[i - 1][j] * j % mod;
				if(dp[i][j] >= mod) dp[i][j] -= mod;
				dp[i][j] -= (long long)dp[i - 1][j - 1] * ((i - 1) * (j - 1)) % mod;
				if(dp[i][j] >= mod) dp[i][j] -= mod;
				if(dp[i][j] < 0) dp[i][j] += mod;
			}
		}
	}
	cout << dp[c][d] << endl;
	return 0;
}


Measured memory_bytes: 38844
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float('inf')]*n
dp[-1] = 0
dp[-2] = abs(h[-1]-h[-2])

for i in range(n-3,-1,-1):
  for j in range(i+1,min(i+k+1,n)):
    dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
                
print(dp[0])


Measured memory_bytes: 85776
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    while(q--) {
        int b, e, k;
        cin >> b >> e >> k;
        int res = 0;
        for(int i = b; i < e; i++) {
            if(a[i] == k) res++;
        }
        cout << res << '\n';
    }
}


Measured memory_bytes: 3240
import java.util.Scanner;

public class Main {

	private static int N = 200;

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

		int cnt = 0;

		while (sc.hasNext()) {
			cnt++;
			if (cnt > 200)
				break;

			int a = sc.nextInt();
			int b = sc.nextInt();

			int sum = a + b;
			int count = 1;

			while ((sum /= 10) != 0) {
				count++;
			}

			System.out.println(count);
		}
	}

}

Measured memory_bytes: 20424
n = int(input())
w = []
st = set()
for i in range(n):
    s = input()
    st.add(s)
    w.append(s[0] + s[-1])
if len(st) != n:
    print('No')
    exit()
for i,j in zip(w, w[1:]):
    if i[-1] != j[0]:
        print('No')
        exit()
print('Yes')

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

int main(void){
    int n;
    cin >> n;
  	int p[n];
    rep(i,n){
        int x;
        cin >> x;
        p[i] = x;
    }
    int num = p[0];
    int ans = 1;
  
    rep(i,n-1){
        if(p[i+1]<=num){
            num = p[i+1];
            ans += 1;
        }
    }
    
    cout << ans <<endl;
    
    return 0;
    
}























































Measured memory_bytes: 1024
#!/usr/bin/env ruby
n = STDIN.readline.strip.to_i

def make_753()
  p = []
  for i in 1..9 do
    p += _make_753(i)
  end
  p
end

def _make_753(d)
  p = ['7', '5', '3']
  for i in 2..d
    p = p.product(['7', '5', '3']).map{|d| d.join}.flatten
  end
  p.select{|s| exist_753(s)}.map(&:to_i)
end

def exist_d(d, s)
  s.split('').include?(d.to_s)
end

def exist_753(s)
  exist_d(7, s) and exist_d(5, s) and exist_d(3, s)
end

_753 = make_753()
puts _753.count{|d| n >= d}

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

using namespace std;

int AtoiString(const string);

int main(){
  int n;
  string str, str_;

  cin >> str;
  n = AtoiString(str);

  while(1){
    cin >> str;
    if(str == "=") break;

    cin >> str_;
    if(str == "+") n += AtoiString(str_);
    else if(str == "-") n -= AtoiString(str_);
    else if(str == "*") n *= AtoiString(str_);
    else if(str == "/") n /= AtoiString(str_);
  }

  cout << n << endl;
  return 0;
}

int AtoiString(const string s){
  int i, x, d;
  for(i=s.size()-1, x=0, d=1; i>=0; --i, d*=10)
    x += ((s[i] - 48) * d);
  return x;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {   
    if (v == 0)
        return 1 % mod;
    if (v % 2 == 1)
        return (x * bpow(x, v - 1)) % mod;
    ll r = bpow(x, v / 2);
    return (r * r) % mod;   
}

ll solve(){ 
    string a; cin>>a;
    ll n = sz(a);
    string d = a;
    reverse(all(d));
    if(d!=a) {cout<<"No"; return 0;}
    string c = a.substr(0,(n-1)/2);
    string f = c;
    reverse(all(f));
    if(f!=c) {cout<<"No"; return 0;}
    c = a.substr((n+3)/2 - 1);
    f = c;
    reverse(all(f));
    if(f!=c) {cout<<"No"; return 0;}
    cout<<"Yes";
}

int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
class List
  attr_accessor :data, :nnext, :prev

  @@first_node = nil
  @@current_node = nil
  # @@node_count = 0

  def initialize(data=nil, nnext=nil, prev=nil)
    @data = data
    @nnext = nnext
    @prev = prev
    # unless data == "END"
    #   @@node_count += 1
    # end
  end

  def self.inti
    @@current_node = List.new("END")
    @@first_node = @@current_node
  end

  # def self.node_count
  #   @@node_count
  # end

  # def self.first_node
  #   @@first_node
  # end

  # def self.current_node
  #   @@current_node
  # end
  
  def self.insert(data)
    new_node = List.new(data)
    new_node.nnext = @@current_node

    unless @@current_node.prev.nil?
      new_node.prev = @@current_node.prev
      @@current_node.prev.nnext = new_node
    else
      @@first_node = new_node
    end

    @@current_node.prev = new_node
    @@current_node = new_node

  end

  def self.move(n)
    n.abs.times do
      @@current_node = (n < 0) ? @@current_node.prev : @@current_node.nnext
    end
  end

  def self.erase

    unless @@current_node.prev.nil?
      @@current_node.prev.nnext = @@current_node.nnext
    end

    @@current_node.nnext.prev = @@current_node.prev
    @@current_node = @@current_node.nnext

    if @@current_node.prev.nil?
      @@first_node = @@current_node
    end

    # @@node_count -= 1
  end

  def self.output
    until @@first_node.data == "END"
      puts @@first_node.data
      @@first_node = @@first_node.nnext
    end
  end
end

n = gets(chomp:true).to_i
query = readlines(chomp:true).map{|l|l.split.map(&:to_i)}

List.inti
query.each do |que|
  case que[0]
  when 0
    List.insert(que[1])
  when 1
    List.move(que[1])
  when 2
    List.erase
  end
end
List.output


Measured memory_bytes: 104320
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
const long long MOD=1e9+7;
long long quipow(long long x,long long y){
	long long res=1,tmp=x;
	while(y){
		if(y&1) res=res*tmp%MOD;
		tmp=tmp*tmp%MOD;
		y>>=1;
	}
	return res;
}
long long inv(long long x){
	return quipow(x,MOD-2);
}
long long jie[200005],invjie[200005];
long long C(long long x,long long y){
	if(y==0) return 1;
	return jie[x]*invjie[x-y]%MOD*invjie[y]%MOD;
}

int main(){
	long long n,a,b,c;
	cin>>n>>a>>b>>c;
	jie[0]=1;
	invjie[0]=1;
	for(int i=1;i<=2*n;i++){
		jie[i]=jie[i-1]*i%MOD;
		invjie[i]=invjie[i-1]*inv(i)%MOD;
	}
	long long res=0;
	long long realc=inv(100-c)*100%MOD,reala=inv(a+b)*a%MOD,realb=inv(a+b)*b%MOD;
//	cout<<realc<<endl;
	for(int i=n;i<2*n;i++){
		long long one1=quipow(reala,n)*quipow(realb,i-n)%MOD,one2=quipow(reala,i-n)*quipow(realb,n)%MOD;
		res=(res+(one1+one2)%MOD*C(i-1,n-1)%MOD*realc%MOD*i%MOD)%MOD;;
	}
	cout<<res;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int l,a,b,c,d;
	scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
	printf("%d\n", l-max(a/c+(a%c!=0),b/d+(b%d!=0)));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define forn(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define for1(i, n) for (long long i = 1; i <= (long long)(n); ++i)
#define fore(i, l, r) for (long long i = (long long)(l); i <= (long long)(r); ++i)
#define fordn(i, n) for (long long i = (long long)(n) - 1; i >= 0; --i)
#define ford1(i, n) for (long long i = (long long)(n); i >= 1; --i)
#define all(x) (x).begin(), (x).end()
#define PI 3.141592653589793
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    if(n % 2 == 0) cout << n << endl;
    else cout << n * 2 << endl;
}

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

int main() {
  int n;
  cin >> n;
  n/=2;
  vector<int> v(n),w(n),va(100000),wa(100000);
  
  int i;
  for(i=0; i<n; i++){
    cin >> v.at(i) >> w.at(i);
    va.at(v.at(i)-1)++;
    wa.at(w.at(i)-1)++;
  }
  
  int vmode1=0,vmode2=0,wmode1=0,wmode2=0,vmax1=0,vmax2=0,wmax1=0,wmax2=0;
  for(i=0; i<100000; i++){
    if(va.at(i)>=vmode1){
      vmode2=vmode1;
      vmode1=va.at(i);
      vmax2=vmax1;
      vmax1=i;
    }else if(va.at(i)>=vmode2){
      vmode2=va.at(i);
      vmax2=i;
    }
    if(wa.at(i)>=wmode1){
      wmode2=wmode1;
      wmode1=wa.at(i);
      wmax2=wmax1;
      wmax1=i;
    }else if(wa.at(i)>=wmode2){
      wmode2=wa.at(i);
      wmax2=i;
    }
  }

  if(vmax1!=wmax1){
    cout << n*2-vmode1-wmode1;
  }else{
    cout << n*2-max(vmode1+wmode2,vmode2+wmode1);
  }
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    ll D,G;
    cin>>D>>G;
    V<ll> p(D),c(D);
    rep(i,D) cin>>p[i]>>c[i];
    ll ans=INF;
    for(ll i=0;i<(1<<D);i++){
        string s;
        for(ll j=0;j<D;j++){
            if(i>>j&1){
                s+='1';
            }else{
                s+='0';
            }
        }
        ll cnt=0,sum=0;
        for(ll j=0;j<D;j++){
            if(s[j]=='1'){
                cnt+=p[j];
                sum+=c[j]+100*(j+1)*(p[j]);
            }
        }
        bool ok=0;
        for(ll j=D-1;j>=0;j--){
            if(sum>=G){
                ok=1;
                break;
            }
            if(s[j]=='1') continue;
            ll t=G-sum;
            ll u=t/(100*(j+1));
            if(t%(100*(j+1))!=0) u++;
            if(p[j]-1>=u){
                cnt+=u;
                sum+=100*(j+1)*u;
            }else{
                cnt+=p[j]-1;
                sum+=100*(j+1)*(p[j]-1);
            }
        }
        if(sum>=G) ok=1;
        if(ok) chmin(ans,cnt);
    }
    cout<<ans<<endl;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c)
		cout << '1' << endl;
	else if (a == b || a == c || b == c)
		cout << '2' << endl;
	else
		cout << '3' << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>

int main() {
  char buf[128];
  scanf("%s", buf);

  std::string w=buf;
  int counter[26]={};
  for (char ch: w)
    ++counter[ch-'a'];

  for (char ch='a'; ch<='z'; ++ch)
    if (counter[ch-'a'] % 2)
      return !printf("No\n");

  printf("Yes\n");
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;


int main(){
    int n,m;
    cin>>n>>m;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    
    vector<bool> ok(n,true),v(n,false); 
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a]=v[b]=true;
        if(h[a]<=h[b]){
            ok[a]=false;
        }
        if(h[b]<=h[a]){
            ok[b]=false;
        }
    }
    
    ll ans=0;
    for(int i=0;i<n;i++){
        if(ok[i]||!v[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3756
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  string a,b,c;
  cin >> a >> b >> c;
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    if(a[i] == b[i] && a[i] == c[i]);
    else if(a[i] == b[i] || a[i] == c[i] || b[i] == c[i])
      ans++;
    else
      ans += 2;
  }
  
  cout << ans << endl;
  
  return 0;
}

  


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b
def ceil(x):
    return math.ceil(x)
def floor(x):
    return math.floor(x)

def main():
    N = int(input())
    a = list(map(int, input().split()))

    avg = sum(a) / N
    min_abs = 10**9
    for i in range(N):
        min_abs = min(min_abs, abs(a[i] - avg))
    for i in range(N):
        if abs(a[i] - avg) == min_abs:
            print(i)
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 76792
#include <stdio.h>
#include <string.h>
#define MAX 200000
typedef struct a{
  char name[100];
  int time;
}DATA;
void enqueue(DATA);
DATA dequeue(void);
int isEmpty(void);
int head=0,tail=0,n;
DATA Q[MAX+1];
int main()
{
  int total=0,q,i;
  scanf("%d%d",&n,&q);
  tail=n;
  for(i=0;i<=n;i++)
    {
      scanf("%s%d",Q[i].name,&Q[i].time);
    }
  for(i=0;isEmpty()!=1;i++)
    {
      if(Q[i].time>q)
	{
	  Q[i].time=Q[i].time-q;
	  enqueue(Q[i]);
	  dequeue();
	  total=total+q;
	}
      else if(Q[i].time<=q)
	{
	  total=total+Q[i].time;
	  printf("%s",Q[i].name);
	  printf(" ");
	  printf("%d",total);
	  printf("\n");
	  dequeue(); 
	}
    }
  return 0;
}
void enqueue(DATA x)
{
  Q[tail].time=x.time;
  strcpy(Q[tail].name,x.name);
  if(tail+1==MAX)
    tail=0;
  else tail++;
}
DATA dequeue(void)
{
  DATA x;
  x=Q[head];
  if(head+1==MAX)
    head=0;
  else head++;
  return x;
}
int isEmpty(void)
{
  int flag=0;
  if(head==tail)
    {
      flag=1;
      return flag;
    }
  return flag;
}



Measured memory_bytes: 21024
#155-A

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

D =[A,B,C]

D.sort()

#print(D)

if D.count(A)== 2:
    print("Yes")

elif D.count(A)== 1:
    if B == C:
        print("Yes")

    else:
        print("No")

elif D.count(A)== 3:
    print("No")


Measured memory_bytes: 9112
#include <iostream>

struct Node {
    Node(int key): key(key) {}
    Node *left=nullptr, *right=nullptr, *parent=nullptr;
    int key;
};

struct Tree {
    Node *root=nullptr;
};

void insert(Tree* T, Node *z) {
    Node *y = nullptr;
    Node *x = T->root;
    while (x != nullptr) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == nullptr) {
        T->root = z;
    } else if (z->key < y->key) {
        y->left = z;
    } else {
        y->right = z;
    }
}

void print_lef(Node * n) {
    if (n->left != nullptr) {
        print_lef(n->left);
    }
    std::cout << " " << n->key;
    if (n->right != nullptr) {
        print_lef(n->right);
    }
}

void print_mid(Node *n) {
    std::cout << " " << n->key;
    if (n->left != nullptr) {
        print_mid(n->left);
    }
    if (n->right != nullptr) {
        print_mid(n->right);
    }
}


int main(int argc, char ** argv) {
    int m;
    std::cin >> m;

    Tree t = Tree();
    Node *nodes[m];
    for (int i = 0; i < m; i++) {
        std::string command;
        std::cin >> command;
        if (command == "insert") {
            int k;
            std::cin >> k;
            nodes[i] = new Node(k);
            insert(&t, nodes[i]);
        } else {
            print_lef(t.root);
            std::cout << std::endl;
            print_mid(t.root);
            std::cout << std::endl;
        }
    }
}



Measured memory_bytes: 30528
a = sorted(list(map(int, input().split())))
cnt = 0
while a[1] != a[2]:
    a[0] += 1
    a[1] += 1
    cnt += 1

while a[0] < a[2]:
    a[0] += 2
    cnt += 1
if (a[2] - a[0]) % 2 == 1:
    cnt += 1
print(cnt)


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

int main() {
int ans = 0;
  string S, T;
  cin >> S >> T;
  rep(i, 3){
  if(S.at(i) == T.at(i))
    ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

int n;
int T;
int sa,sb;
vector<int> G[51];
int dp[201][51][51];
const int INF=1000000000;

int dfs(int tern,int apos,int bpos){
    if(tern==200)return INF;
    else if(apos==bpos)return tern/2;
    if(dp[tern][apos][bpos]!=-1)return dp[tern][apos][bpos];
    int res=INF;
    if(tern%2==0)res=0;
    if(tern%2==0){
        for(int i=0;i<G[apos].size();i++){
            int to=G[apos][i];
            res=max(res,dfs(tern+1,to,bpos));
        }
        res=max(res,dfs(tern+1,apos,bpos));
    }
    else{
        for(int i=0;i<G[bpos].size();i++){
            int to=G[bpos][i];
            res=min(res,dfs(tern+1,apos,to));
        }
            res=min(res,dfs(tern+1,apos,bpos));
    }
    return dp[tern][apos][bpos]=res;
}

int main(){

    cin>>T;
    while(T--){
        cin>>n;
        memset(dp,-1,sizeof(dp));
        for(int i=0;i<n;i++)G[i].clear();
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                int a;
                cin>>a;
                if(a==1){
                    G[i].push_back(j);
                    G[j].push_back(i);
                }
            }
        }
        cin>>sa>>sb;
        int res=dfs(0,sa,sb);
        if(res==INF)cout<<"infinity"<<endl;
        else cout<<res<<endl;
    }

    return 0;
}

Measured memory_bytes: 2980