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

main() {
    int H,W; cin >> H >> W;
    int N; cin >> N;
    int data[H][W];
    int A[N];
    rep(i,N) cin >> A[i];
    queue<int> q;
    rep(i,N){
        rep(j,A[i]){
            q.push(i);
        }
    }
    rep(i,H){
        rep(j,W){
            data[i][j]=q.front()+1;
            q.pop();
        }
    }
    rep(i,H){
        if(i%2!=0){
            reverse(data[i],data[i]+W);
        }
    }
    rep(i,H){
        rep(j,W){
            cout << data[i][j] << " " << flush;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 512
n,m=map(int,input().split())
ac=set()
from collections import Counter
w=Counter()
wa=0
for i in range(m):
    p,s=input().split()
    if s=="AC":
        if p not in ac:
            wa+=w[p]
        ac.add(p)
    else:
        if p not in ac:
            w[p]+=1
print(len(ac),wa)

Measured memory_bytes: 14308
a=0
sum=0
list=[]
for i in range(0,6):
    n=int(input())
    list.append(n)
    
for i in range(0,3):
    if list[i]<list[i+1]:list[i],list[i+1]=list[i+1],list[i]
    sum=sum+list[i]

if list[4]<list[5]:sum=sum+list[5]
else:sum=sum+list[4]
print(sum)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    int ans=0;
    if(a>=b){
        ans+=a;
        a--;
    }else{
        ans+=b;
        b--;
    }
    printf("%d\n",max(a,b)+ans);
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;


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

    vector<bool> ans(x+200,false);
    ans[0] = true;
    for (int i=0; i<=x; i++) {
        for (int j=100; j<=105; j++) {
            ans[i+j] = ans[i+j] || ans[i];
        }
    }
    cout << ans[x] << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		long n = Long.parseLong(br.readLine());
		int f = Integer.MAX_VALUE;
		for(long i = 100000; i > 0; i--){
			if(n%i==0){
				long a = n/i;
				f = Math.min(f,Math.max(String.valueOf(a).length(),String.valueOf(i).length()));
			}
		}
		System.out.println(f);
	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int a, b, c, n;
    while(cin >> a >> b >> c, a|b|c){
        cin >> n;
        vector<int> v(a+b+c+1, 0);
        vector<vector<int>> vv;
        for (int i = 0; i < n; ++i) {
            int p, q, r, s;
            cin >> p >> q >> r >> s;
            if(s == 1) {
                v[p] = v[q] = v[r] = 1;
            }else vv.push_back({p, q, r});
        }
        for (auto &&j : vv) {
            if (v[j[0]] + v[j[1]] + v[j[2]] == 2){
                for (int i = 0; i < 3; ++i) if(v[j[i]] == 0) v[j[i]] = 10;
            }
        }
        for (int i = 1; i <= a+b+c; ++i) {
            if(v[i] == 0) cout << 2 << "\n";
            else if(v[i] == 1) cout << 1 << "\n";
            else if(v[i] == 10) cout << 0 << "\n";
        }
    }
    
    return 0;
}



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

#define ll long long

int main() {
	string s, t, t1;
	cin >> s;
	cin >> t;
	t1 = t.substr(0,s.length() );
	if (t1.compare(s) == 0 && s.length() + 1 == t.length())cout << "Yes";
	else cout << "No";
	return 0;
}

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

int main(){
    int n,x;
    cin >> n;
    x = n%10;
    if(x== 2 || x == 4 || x == 5 || x == 7 || x == 9){
        cout << "hon";
    }else if(x == 0 || x == 1 || x == 6 || x == 8){
        cout << "pon";
    }else{
        cout << "bon";
    }
    return 0;
}

Measured memory_bytes: 3596
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
 
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  
  int a, b;
  vector<int> roads(N, 0);
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    roads[a-1]++;
    roads[b-1]++;
  }
  for (int i=0; i<N; i++) {
    cout << roads[i] << endl;
  }
}

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

typedef long long ll;
const int mod=1000000007;

int n,k;
int a[2005];
ll pre[2005];
ll cnt;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        for(int j=1;j<i;j++){
            cnt+=a[j]>a[i];
        }
    }
    cnt=cnt*k%mod;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            pre[i]+=a[j]>a[i];
        }
        cnt+=(pre[i]*((ll(k))*(k-1)/2%mod))%mod;
        cnt%=mod;
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPre
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = N[0];
            int B = N[1];

            int plus = A + B;
            int minus = A - B;
            int mult = A * B;

            int[] all = new int[3] { plus, minus, mult };
            int allMax = all.Max();

            Console.WriteLine(allMax);
        }

    }
}



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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1000 + 7;
int n;
int m;
int r1;
int c1;
int r2;
int c2;
int a[N][N];
int d[N][N];

deque<pair<int, int>> q;

void put(int r, int c, int x, int fi) {
  if (x >= d[r][c]) return;
  d[r][c] = x;
  if (fi)
  q.push_front({r, c}); else q.push_back({r, c});
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> r1 >> c1 >> r2 >> c2;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= m; j++) {
      if (s[j - 1] == '.') {
        a[i][j] = 1;
        d[i][j] = (int) 1e9;
      } else {
        d[i][j] = 9;
      }
    }
  }
  if (a[r1][c1] == 0 || a[r2][c2] == 0) {
    cout << "-1\n";
    return 0;
  }
  int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};
  put(r1, c1, 0, 1);
  while (!q.empty()) {
    int r = q.front().first;
    int c = q.front().second;
    q.pop_front();
    for (int k = 0; k < 4; k++) {
      int r2 = r + dr[k];
      int c2 = c + dc[k];
          if (1 <= r2 && 1 <= c2 && r2 <= n && c2 <= m && a[r2][c2]) {
        put(r2, c2, d[r][c], 1);
        }
    }
    for (int dx = -2; dx <= +2; dx++) {
      for (int dy = -2; dy <= +2; dy++) {
        int r2 = r + dx, c2 = c + dy;
        if (1 <= r2 && 1 <= c2 && r2 <= n && c2 <= m && a[r2][c2]) {
        put(r2, c2, d[r][c] + 1, 0);
        }
      }
    }
  }
  if (d[r2][c2] == (int) 1e9) d[r2][c2] = -1;
  cout << d[r2][c2] << "\n";
  return 0;
}


Measured memory_bytes: 11492
#include<iostream>
using namespace std;
int main(){
int n;
  cin >> n;
  int div = n;// divident
  int quo, rem;
  string res = "";
  while(div){
  	rem = div % (-2);
    div = div/(-2);
    (rem == -1)? div += 1 : div = div;
    (rem == 0)? res = "0"+res : res = "1"+res;
  }
  (n==0)? cout << "0\n" : cout << res <<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int C[VMAX+ 1];
int n;
void CountingSort(unsigned short A[],unsigned short B[], int k) {
    for ( int i = 0; i <= k; i++) {
        C[i] = 0;
    }

    for( int j = 1; j <= n; j++) {
        C[A[j]]++;
    }

    for ( int i = 1; i <= k; i++) {
        C[i] += C[i-1];
    }

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

int main() {
    unsigned short *A,*B;
    int i, j;
    scanf("%d", &n);

    A = (unsigned short*)malloc(sizeof(short) * n + 1);
    B = (unsigned short*)malloc(sizeof(short) * n + 1);

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

    for ( i = 0; i < n; i++ ) {
        scanf("%hu", &A[i + 1]);
    }

    CountingSort(A,B,VMAX);

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



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

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	x--, y--;
	vector<int> c(n);
	for (int i = 0, d; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (j <= x || i >= y)
				c[j - i]++;
			else if (i <= x && j >= y)
				c[x - i + j - y + 1]++;
			else if (i <= x) {
				d = min(j - i, x - i + 1 + y - j);
				c[d]++;
			} else if (j >= y) {
				d = min(j - i, j - y + i - x + 1);
				c[d]++;
			} else {
				d = min(j - i, i - x + y - j + 1);
				c[d]++;
			}
		}
	}
	for (int i = 1; i < n; i++) {
		cout << c[i] << endl;
	}
}


Measured memory_bytes: 256
n = int(input())
cnt = {}
for _ in range(n):
    sorted_s = "".join(sorted(input()))
    cnt.setdefault(sorted_s, 0)
    cnt[sorted_s] += 1
ans = 0
for v in cnt.values():
    if v < 2: continue
    ans += int(v * (v - 1) / 2)
print(ans)

Measured memory_bytes: 17848
from collections import deque
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(a[0])
else:
    ans=deque()
    ans.append(a[0])
    if (n-1)%2==0:
        s=0 #うしろ
    else:
        s=1
    for i in range(1,n):
        if s==0:
            ans.append(a[i])
        else:
            ans.appendleft(a[i])
        s=(s+1)%2
    for i in range(n):
        print(ans[i],end=" ")

Measured memory_bytes: 97748
#include <iostream>
#include <cstdio>
using namespace std;
int n,a[100005],c[100005],b,aa=-1,cc=-1,aaa,ccc,xl[100005];
inline int ri(){
	char c=getchar();int x=0,w=1;
	while(!isdigit(c)){if(c=='-')w=-1;c=getchar();}
	while( isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*w;
}
int main(){
	int ans=0;
	n=ri();
	for(register int i=1;i<=n;i++){
		b=ri();xl[i]=b;
		if(i&1){
			a[b]++;
			if(a[b]>aa)aa=a[b],aaa=b;
		}
		else{
			c[b]++;
			if(c[b]>cc)cc=c[b],ccc=b;
		} 
	}
//	if(aa==n/2&&cc==n/2&&aaa==ccc)cout<<n/2;
	if(aaa!=ccc)cout<<(n/2-aa)+(n/2-cc);
	else{
		int jsmax=-1,jsmm,osmax=-1,osmm;
	//	int jsmax=aaa,osmax=ccc;
		a[aaa]=0;c[ccc]=0;
		for(int i=1;i<=n-1;i+=2)
			if(jsmax<a[xl[i]])jsmax=a[xl[i]],jsmm=xl[i];
		for(int i=2;i<=n;i+=2)
			if(osmax<c[xl[i]])osmax=c[xl[i]],osmm=xl[i];
		jsmax>=osmax?cout<<n/2-jsmax+n/2-cc:cout<<n/2-osmax+n/2-aa;
	} 
	
	
	return 0;
} 

Measured memory_bytes: 1408
while True:
    table = input().split()
    
    a = int(table[0])
    op = table[1]
    b = int(table[2])
    
    if op == '?':
        break
        
    if op == '+':
        print("%d"%(a+b))
    elif op =='-':
        print("%d"%(a-b))
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))


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

int main() {

	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	if (a == f && b == e && c == d) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
void fastio(){
	 ios_base::sync_with_stdio(false);
	 cin.tie(0);
	 cout.tie(0);
}
ll dp[100005][2],ar[100005];
int main() {
	fastio();
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>ar[i];
	}
	dp[1][0]=ar[1];
	dp[1][1]=-ar[1];
	for(int i=2;i<=n;i++)
	{
		dp[i][0]=max(dp[i-1][0]+ar[i],dp[i-1][1]-ar[i]);
		dp[i][1]=max(dp[i-1][0]-ar[i],dp[i-1][1]+ar[i]);
	}
	cout<<dp[n][0];
	
	
	
	return 0;
}

Measured memory_bytes: 2560
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));default:return i;}}
function Main(input) {
  input = myconv(input,4);
  if(input[0] * 500 >= input[1]){
     myout("Yes");
     }else{
     myout("No");
     }
}

Measured memory_bytes: 22076
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,a[50],b[50],x[50];
    cin>>n>>m;
    for(int i=0;i<n;i++)x[i]=0;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        x[a[i]-1]++;
        x[b[i]-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<x[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
P = [0] + list(map(int,read().split()))

# permutationになっている極小区間に分ける

intervals = []
left = 0
right = -1
for i,p in enumerate(P):
    if right < p:
        right = p
    if i == right:
        intervals.append((left,right))
        left = i+1
        right = -1

def check(L,R):
    if L == R:
        return True
    to_left = []
    fixed = []
    to_right = []
    for i,p in enumerate(P[L:R+1],L):
        if i > p:
            to_left.append(p)
        elif i == p:
            fixed.append(p)
        else:
            to_right.append(p)
            
    if fixed != list(range(L+1,R+1,2)):
        return False
    if any(x > y for x,y in zip(to_left, to_left[1:])):
        return False
    if any(x > y for x,y in zip(to_right, to_right[1:])):
        return False
    return True

answer = 'Yes' if all(check(L,R) for L,R in intervals) else 'No'
print(answer)

Measured memory_bytes: 49440
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int r,d,x;
int main()
{
	fast;
	cin>>r>>d>>x;
	for (int i=1;i<=10;i++)
	{
		x=r*x-d;
		cout<<x<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/math/common_factor.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

	s64 a_min = INT64_MAX;
	s64 a_max = INT64_MIN;
	s64 b_min = INT64_MAX;
	s64 b_max = INT64_MIN;

	for(u64 i=0; i<N; i++) {
		s64 x, y;
		cin >> x >> y;

		a_min = min(a_min, x + y);
		a_max = max(a_max, x + y);
		b_min = min(b_min, x - y);
		b_max = max(b_max, x - y);
	}

	s64 ans = max(a_max - a_min, b_max - b_min);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <cstdio>

int main() {
	int sx, sy, tx, ty;
	scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
	int yGap=ty-sy, xGap=tx-sx;
	for(int i=0; i<yGap; i++) printf("U");
	for(int i=0; i<xGap; i++) printf("R");
	for(int i=0; i<yGap; i++) printf("D");
	for(int i=0; i<xGap; i++) printf("L");
	printf("L");
	for(int i=0; i<yGap+1; i++) printf("U");
	for(int i=0; i<xGap+1; i++) printf("R");
	printf("DR");
	for(int i=0; i<yGap+1; i++) printf("D");
	for(int i=0; i<xGap+1; i++) printf("L");
	printf("U");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string s;
    cin >> s;
    for (char& c: s) {
        if (c==',') c = ' ';
    }
    
    
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){

int A,B,C,D;
cin>>A>>B>>C>>D;

int x=A*B;
int y=C*D;
if(x>=y){
cout<<x<<endl;
}
if(x<y){
cout<<y<<endl;
}
}

Measured memory_bytes: 3576
#include<iostream>
#include<cstdlib>
#include<map>
#define HMAX 300
#define WMAX 300
using namespace std;

int H,W,D,Q;
int A[HMAX][WMAX];
long long C[HMAX][WMAX];
int L, R;
long long ans;

map<int, int> AtoH;
map<int, int> AtoW;

int main() {
	cin >> H >> W >> D;

	for (int i = 0; i<H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
			AtoH.emplace(A[i][j], i);
			AtoW.emplace(A[i][j], j);
		}
	}

	for (int i = 1; i <= D; i++) {
		for (int k = i; k <= H*W-D; k+=D) {
			C[AtoH[k + D]][AtoW[k + D]] = C[AtoH[k]][AtoW[k]] + abs(AtoW[k] - AtoW[k + D]) + abs(AtoH[k] - AtoH[k + D]);
		}
	}


	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> L >> R;
		cout << C[AtoH[R]][AtoW[R]]- C[AtoH[L]][AtoW[L]] << endl;
	}


	return 0;
}

Measured memory_bytes: 10624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 
#define ll long long
#define db double
#define dbg1(x) cout<<#x<<"="<<x<<" "
#define dbg2(x) cout<<#x<<"="<<x<<"\n"
int T,a,b;ll ans;
db cal(ll x) {return (-(ll)b*x-1)*1./(a+x);}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	for(scanf("%d",&T);T--;)
	{
		scanf("%d%d",&a,&b),ans=0;
		if(a<b) swap(a,b);
		if(a==1&&b==1) {puts("0");continue;}
		if(b>=10000000)
		{
			ll dd=sqrt(1ll*a*b),ans=dd*2-1;
			if(dd*dd==1ll*a*b)
			{
				if(a==b)ans--;
				else ans-=2;
			}
			else if(dd*(dd+1)>=1ll*a*b)ans--;
			cout<<ans<<endl;
			continue;
		}
		/*
		for(ll x=-a+1,y,tmp;;x++)
		{
			tmp=floor(((ll)-b*x-1)*1./(a+x));
			dbg1(x),dbg2(tmp);
			if(tmp==-b) break;
			if(tmp)
			{
				if(tmp^last) ans++,last=tmp;
				else
				{
					ans+=tmp+b-1;
					if(tmp>0) ans--;
					break;
				}
			}
		}
		dbg2(ans);*/
		ll l=-a+1,r=1e10,mid;
		for(;l<r;)
		{
			mid=l+r>>1;
//			dbg2(mid);
//			dbg1(cal(mid+1)),dbg2(cal(mid));
			cal(mid)-cal(mid+1)<1?r=mid:l=mid+1;
		}
//		dbg2(l);
		ll tmp1=floor((-(ll)b*l-1)*1./(a+l));
		ans=l+a+tmp1+b-1;
		if(l==-a+1)
		{
			if(tmp1>=0) ans--;
			cout<<ans<<"\n";
			continue;
		}
		ll tmp2=floor((-(ll)b*(l-1)-1)*1./(a+l-1));
//		dbg1(l-1),dbg1(cal(l-1)),dbg2(tmp2);
//		dbg1(l),dbg1(cal(l)),dbg2(tmp1);
//		dbg1(tmp1),dbg2(tmp2);
		if(tmp1>=0||tmp2<=0) ans--;
//		printf("%lld\n",ans);
		cout<<ans<<"\n";
	}
	return 0;
}


Measured memory_bytes: 256
from math import pi,atan2
q = 2*pi
def deg(a,b):
    d = b-a
    t = atan2(d.real, d.imag)
    if t<0: t += q
    return t
n = int(input())
cs = []
for _ in range(n):
    a,b = map(int,input().split())
    cs += [complex(a,b)]
for i in range(n):
    args = [deg(cs[i],cs[j])/q for j in range(n) if j!=i]
    args = sorted(args)
    dif = [args[i]-args[i-1] for i in range(n-1)]
    dif[0] += 1
    print(max(max(dif) - 1/2, 0))

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;

typedef long long ll;

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

int Mygcd(int a, int b)
{
	if (a % b == 0)return b;
	return Mygcd(b, a % b);
}

long long Mylcm(long long a, long long b)
{
	return a * b / Mygcd(a, b);
}

int Mylcm(int a, int b)
{
	return a * b / Mygcd(a, b);
}

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

	int A, B, C, D;

	cin >> A >> B >> C >> D;

	while (1) {	
		C -= B;
		if(C <= 0){
			cout << "Yes" << endl;
			break;
		}

		A -= D;
		if (A <= 0)
		{
			cout << "No" << endl;
			break;
		}
	}

	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll w, h, x, y;
  cin >> w >> h >> x >> y;

  cout << setprecision(10) << ((ld)(w * h) / 2.0) << " " << ((w == x * 2 && h == y * 2) ? 1 : 0) << endl;

  return 0;
}


Measured memory_bytes: 256
'''input
2
100 0
'''
n = input()
arr = map(int,raw_input().split())
m = max(arr)
zz = float(m)/2
diff = 10**20
arr.sort()
for i in range(n):
	if abs(arr[i]-zz) < diff:
		diff = abs(arr[i]-zz)
		ans = arr[i]
print m,ans

Measured memory_bytes: 41196
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    ll n,lack = 0,sum = 0,ans = 0;
    cin >> n;
    vector<ll> a(n),b(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        sum += a[i];
    }

    for(int i = 0;i < n;i++){
        cin >> b[i];
        sum -= b[i];
        if(a[i] < b[i]){
            lack += b[i] - a[i];
            ans++;
        }
    }

    if(sum < 0){
        cout << "-1" << endl;
        return 0;
    }

    vector<ll> vec;

    for(int i = 0;i < n;i++){
        if(a[i] > b[i]){//動かせる量
            vec.push_back(a[i]-b[i]);
        }
    }

    sort(vec.begin(),vec.end(),greater<ll>());


    for(int i = 0;i < vec.size();i++){
        if(lack <= 0){
            break;
        }
        lack -= vec[i];
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2556
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> h = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            h.add(sc.nextInt());
        }
        sc.close();

        Collections.sort(h);

        int ans = Integer.MAX_VALUE;
        for (int i = k - 1; i < n; i++) {
            int candidate = h.get(i) - h.get(i - (k - 1));
            if (candidate < ans) {
                ans = candidate;
            }
        }
        System.out.println(ans);

    }

}


Measured memory_bytes: 59232
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define mod 10e9+7

#define rep(i,n) for(int i=0;i<n;i++)
int main(){
   ll n,mini=INF,time,a,b;
   cin >> n >> time;
   vector<ll> c(n);
      vector<ll> t(n);

   for(int i=0;i<n;i++){
      cin >> c.at(i) >> t.at(i);
   }
   rep(i,n){
      if(t.at(i)<=time){
         mini=min(mini,c.at(i));
      }
   }
   if(mini==INF){
   cout <<"TLE"<<endl;
    return 0;
   }
   cout << mini << endl;
  }



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)

// エラトステネスの篩

vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true); 
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(size_t j=2; i*j<=max; ++j)
                IsPrime[i*j] = false;
}
int main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<bool> b(1000010,false);
  map<int,int> m;
  map<int,bool> mp;
  rep(i,n){
    cin>>a[i];
    m[a[i]]++;
    b[a[i]]=true;
  }
  sort(all(a));
  for(auto au:a){
    if(mp[au])continue;
    mp[au]=true;
    if(b[au]){
      for(int i=2;au*i<=1000000;i++){
        b[au*i]=false;
      }
    }
  }
  int c=0;
  rep(i,n){
    if(b[a[i]]&&m[a[i]]<=1)c++;
  }
  cout<<c;
}

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

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

    int res = 0;
    for(int m=1; m<=M; m++) {
        //if(m<4) continue;
        for(int d=1; d<=D; d++) {
            if(d<22) continue;
            int d10 = int(d/10);
            int d1 = d-d10*10;
            if(d1<2) continue;
            //cout << d1 << " " << d10 << endl;
            if(d1 * d10 == m) res++;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (n, m) = read_touple::<usize>();
    if m < n {
       println!("No");
    } else {
       println!("Yes");
    }
}


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

int main(void){
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < d; ++j){
			cin >> x[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j < n; ++j){
			int tmp = 0;
			for(int k = 0; k < d; ++k){
				tmp += pow((x[i][k] - x[j][k]), 2);
			}
			if(tmp == pow((int)sqrt(tmp), 2)){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
e=[0]*(n+1)
for i in range(2,n+1):
    cur=i
    for j in range(2,i+1):
        while cur%j==0:
            e[j]+=1
            cur//=j

def num(m):
    return len(list(filter(lambda x:x>=m-1,e)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)


Measured memory_bytes: 3064
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		int n = sc.nextInt();
		int val = n;
		int mod = 0;
		while (val > 0) {
			mod += val % 10;
			val /= 10;
		}
		if (n % mod == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
N = int(input())
S_list = []
for _ in range(N):
  S = str(input())
  S_list.append(S)
# print(S_list)
AC_list = [S == 'AC' for S in S_list]
WA_list = [S == 'WA' for S in S_list]
TLE_list = [S == 'TLE' for S in S_list]
RE_list = [S == 'RE' for S in S_list]
print('AC x {}'.format(sum(AC_list)))
print('WA x {}'.format(sum(WA_list)))
print('TLE x {}'.format(sum(TLE_list)))
print('RE x {}'.format(sum(RE_list)))

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

int main() {
  int a, b;
  cin >> a >> b;
  
  int x;
  x = (a*b) % 2;
  
  if(x == 1){
    cout << "Odd" << endl;
  }else{
    cout << "Even" << endl;
  }
  
  
  //test出力
  /*
  cout << "x:" << x << endl;
  */

}


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

using namespace std;

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

const long long INF = 1LL<<60;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
vector<string> field;
vector<pair<int, int>> points;

int bfs(int sy, int sx, int gy, int gx){
    int dist[H][W];
    REP(i,H){
        REP(j,W) dist[i][j] = -1;
    }
    queue<pair<int, int>> que;

    dist[sy][sx] = 0;
    que.push(pair<int, int> (sy,sx));
    
    while(!que.empty()){
        pair<int, int> p = que.front();
        que.pop();

        REP(d,4){
            int ny = p.first + dy[d];
            int nx = p.second + dx[d];
            if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
            if(field.at(ny)[nx] == '#') continue;
            if(dist[ny][nx] != -1) continue;

            que.push(pair<int, int> (ny,nx));
            dist[ny][nx] = dist[p.first][p.second] + 1;

        }
    }
    return dist[gy][gx];
}

int main(){
    cin >> H >> W;
    field.resize(H);

    REP(i,H) cin >> field[i];

    int ans = 0;
    
    REP(i,H){
        REP(j,W){
            REP(k,H){
                REP(l,W){
                    if(field[i][j] == '.' && field[k][l] == '.'){
                        if(i != k || j != l) ans = max(ans,bfs(i,j,k,l));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
using namespace std;

inline char gc() {
//	static char buf[100000],*p1,*p2;
//	return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	return getchar();
}

template<class T>
int read(T &ans) {
	ans=0;char ch=gc();T f=1;
	while(!isdigit(ch)) {
		if(ch==EOF) return -1;
		if(ch=='-') f=-1;
		ch=gc();
	}
	while(isdigit(ch))
		ans=ans*10+ch-'0',ch=gc();
	ans*=f;return 1;
}

template<class T1,class T2>
int read(T1 &a,T2 &b) {
	return read(a)!=EOF&&read(b)!=EOF?2:EOF;
}

template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
	return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
}

typedef long long ll;
const int Maxn=31000;
const int inf=0x3f3f3f3f;
const ll mod=1000000007;

struct node {
	int w,s;
	ll v;
}a[Maxn];

int n;
ll f[Maxn],ans;

int cmp(node a,node b) {
	return a.w+a.s<b.w+b.s;
}

signed main() {
//	freopen("test.in","r",stdin);
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i].w,a[i].s,a[i].v);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		for(int j=a[i].s;j>=0;j--)
			qmax(f[j+a[i].w],f[j]+a[i].v);
	for(int i=0;i<Maxn;i++) qmax(ans,f[i]);
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-5;

bool eq(double a,double b){
  return -eps < a-b && a-b < eps;
}

double a[3];

int n;
double x[100],y[100],z[100];
double G[100][100];

void solve(){
  for(int i=0;i<n;i++){

    for(int j=0;j<n;j++){
      if(i==j)continue;
      for(int k=0;k<n;k++){
        if(i==k||j==k)continue;
        
        double A=G[j][k];
        double B=G[k][i];
        double C=G[i][j];


        C/=A;
        B/=A;
        A/=A;
        
        if( eq(a[0],A) && eq(a[1],B) && eq(a[2],C) ){
          cout<<i+1<<' '<<j+1<<' '<<k+1<<endl;
          return;
        }
        
      }
    }
  }
}

int main(){
  int Tc;
  cin>>Tc;
  
  while(Tc--){

    for(int i=0;i<3;i++)cin>>a[i];
    a[2]/=a[0];
    a[1]/=a[0];
    a[0]/=a[0];

    cin>>n;

    
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i]>>z[i];
      for(int j=0;j<i;j++){
        double dx=x[i]-x[j];
        double dy=y[i]-y[j];
        double dz=z[i]-z[j];
        G[i][j]=G[j][i]=sqrt(dx*dx+dy*dy+dz*dz);        
      }
    }

    solve();
  }

  return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
    while(1){
        int n; cin >> n;
        if(n==0)break;
        int ans=0,ans1=0;
        for(int i=0;i<n;i++){
            int a,b; cin >> a >> b;
            if(a>b)ans+=a+b;
            if(a<b)ans1+=a+b;
            if(a==b){
                ans+=a;
                ans1+=b;
            }
        }
        cout << ans << " " << ans1 << endl;
    }
}


Measured memory_bytes: 3052
N, M = map(int, input().split())
id_ = [1] * (N+1)
city = []
for i in range(M):
    P, Y = map(int, input().split())
    city.append([P, Y, i, 0])

city.sort(key=lambda t: t[1])
for i in range(len(city)):
    city[i][3] = str(city[i][0]).zfill(6) + str(id_[city[i][0]]).zfill(6)
    id_[city[i][0]] += 1

city.sort(key=lambda c: c[2])

for c in city:
    print(c[3])


Measured memory_bytes: 33052
#include <iostream>
#include <vector>

std::vector<std::vector<unsigned long>> comb(unsigned long n, unsigned long r) {
  std::vector<std::vector<unsigned long>> v(n + 1, std::vector<unsigned long>(n + 1, 0));

  for (unsigned long i = 0; i < v.size(); ++i) {
    v[i][0] = 1;
    v[i][i] = 1;
  }

  for (unsigned long i = 1; i < v.size(); ++i) {
    for (unsigned long j = 1; j < i; ++j) {
      v[i][j] = ((v[i - 1][j - 1] % 1000000007) + (v[i - 1][j] % 1000000007)) % 1000000007;
    }
  }

  return v;
}

int main() {
  unsigned long N, K;
  std::cin >> N >> K;

  const unsigned long max = std::max(K, N - K + 1);
  const std::vector<std::vector<unsigned long>> my_comb = comb(max, K);
  for (unsigned long i = 1; i <= K; ++i) {
    const unsigned long blue = my_comb[K - 1][i - 1];
    const unsigned long red = my_comb[N - K + 1][i];
    std::cout << ((blue % 1000000007) * (red % 1000000007)) % 1000000007 << std::endl;
  }
  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

long double dist(long double a[], long double b[]){
    long double d = 0;
    rep(i, 2) d += (a[i]-b[i])*(a[i]-b[i]);
    return sqrt(d);
}

int main(){
    int N;
    cin >> N;
    long double x[N][2];
    rep(i, N) cin >> x[i][0] >> x[i][1];
    long double ans = 0;
    long double O[2];
    O[0] = 0, O[1] = 0;
    rep(i, N-1) rep2(j, i, N-1){
        long double d = dist(x[i], x[j])/2;
        ans = max(ans, d);
    }
    rep(i, N-2) rep2(j, i+1, N-2) rep2(k, j+1, N-1){
        long double a[2], b[2], o[2];
        rep(l, 2){
            a[l] = x[j][l]-x[i][l];
            b[l] = x[k][l]-x[i][l];
        }
        if(a[0]*b[1] == a[1]*b[0]) continue;
        long double r[3];
        r[0] = (x[i][0]-x[j][0])*(x[i][0]-x[j][0]) + (x[i][1]-x[j][1])*(x[i][1]-x[j][1]);
        r[1] = (x[i][0]-x[k][0])*(x[i][0]-x[k][0]) + (x[i][1]-x[k][1])*(x[i][1]-x[k][1]);
        r[2] = (x[j][0]-x[k][0])*(x[j][0]-x[k][0]) + (x[j][1]-x[k][1])*(x[j][1]-x[k][1]);
        sort(r, r+3);
        if(r[2] >= r[1]+r[0]) continue;
        long double p = (a[0]*a[0]+a[1]*a[1])/2, q = (b[0]*b[0]+b[1]*b[1])/2;
        o[0] = (p*b[1]-q*a[1]) / (a[0]*b[1]-a[1]*b[0]);
        o[1] = (q*a[0]-p*b[0]) / (a[0]*b[1]-a[1]*b[0]);
        long double d = dist(o, O);
        ans = max(ans, d);
    }
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc127/tasks/abc127_d
# 難しいこと考えすぎないこと。数字を書き換えるとは言ってるけどCjをBj枚追加して大きい方からN枚取るのが最適
# 具体的にBj枚追加していくと死ぬので、枚数はタプルでその数とともに保持しておく


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


from collections import Counter

N, M = read_ints()
A = read_ints()
BC = read_tuple(M)


cnter = Counter(A)
for b, c in BC:
    cnter[c] += b

num_and_cnt = list(cnter.items())
num_and_cnt.sort(reverse=True)

ans = 0
total = 0
for num, cnt in num_and_cnt:
    if total + cnt <= N:
        total += cnt
        ans += num * cnt
    else:
        while total < N:
            ans += num
            total += 1

print(ans)


Measured memory_bytes: 98072
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        long [][] DP = new long[H+1][W+1];
        int [][] L = new int[H+1][W+1];
        for(int i=0;i<H+1;i++){
            Arrays.fill(DP[i],0);
            Arrays.fill(L[i],0);
        }
        for(int i=1;i<=H;i++){
            String s = sc.next();
            for(int j=1;j<=W;j++){
                if(s.charAt(j-1)=='.') L[i][j] = 0;
                else L[i][j] = 1;
            }
        }
        DP[1][1]=1;
        for(int i =1;i<=H;i++){
            for(int j=1;j<=W;j++){
                if(L[i-1][j]==0) DP[i][j]=(DP[i][j]+DP[i-1][j])%1000000007;
                if(L[i][j-1]==0)DP[i][j]=(DP[i][j]+DP[i][j-1])%1000000007;
            }
        }
        System.out.println(DP[H][W]);
    }
}

Measured memory_bytes: 54376
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)    
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]    

N, M, K = map(int,input().split())
uf = UnionFind(N)
f_b = [set() for _ in range(N)]
ans = []
for i in range(M):
    A, B = map(int,input().split())
    A -= 1
    B -= 1
    uf.union(A, B)
    f_b[A].add(B)
    f_b[B].add(A)
    
for i in range(K):
    C, D = map(int,input().split())
    C -= 1
    D -= 1
    if uf.same(C, D):
        f_b[C].add(D)
        f_b[D].add(C)    

for i in range(N):
    ans.append(uf.size(i) - len(f_b[i]) - 1)
print(*ans)

Measured memory_bytes: 64560
/* AtCoder Beginner Contest agc035
 * Problem A
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <map>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector <int> a(n);
	map <int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}
	if (mp.size() == 1) {
		cout << (mp.begin()->first ? "No" : "Yes") << endl;
	} else {
		auto a = mp.begin();
		auto b = mp.begin();
		b++;
		int p = a->first, q = b->first;
		for (int i = 0; i < n; i++) {
			if (mp[p ^ q] > 0) {
				mp[p ^ q]--;
				int t = p ^ q;
				p = q;
				q = t;
			} else {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x - r < 0 || W < x + r || y + r<0 || y + r>H){
		cout << "No" << endl;
	}

	else if (x - r >= 0 && x + r <= W&& y + r >= 0 && y + r <= H){
		cout << "Yes" << endl;
	}
	return 0;
}

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

int main() {
    int64_t N;
    std::cin >> N;

    int64_t A[N];
    int64_t all = 0;
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
        all ^= A[i];
    }

    for (int i = 0; i < N; ++i) {
        std::cout << (all ^ A[i]) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 5140
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;
typedef vector<string> Vs;

const int N=300000+19;

int res[N];
int n,m,l,r,x,y;

int main(){
	n=IN(),m=IN();
	For(i,0,n){
		x=IN()-1,y=IN();
		for (l=1;l<=y;l=r+1){
			if (x/l==0) r=y;else r=min(x/(x/l),y/(y/l));
			if (y/l>x/l) res[l]++,res[r+1]--;
		}
	}
	For(i,1,m+1) res[i]+=res[i-1];
	For(i,1,m+1) printf("%d\n",res[i]);
}

Measured memory_bytes: 1280
#include <iostream>

static bool input(int &a, int &b)
{
	if (0x00 == &a || 0x00 == &b) {
		return false;
	}

	std::cin >> a >> b;

	return true;
}

static int calcArea(const int a, const int b)
{
	return a * b;
}

static int calcLengthOfAhou(const int a, const int b)
{
	return a * 2 + b * 2;
}

int main()
{
	int a, b;

	if (true == input(a, b)) {
		std::cout << calcArea(a, b) << " " << calcLengthOfAhou(a, b) << std::endl;
	}

	return (0);
}

Measured memory_bytes: 3076
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200;
const int MAX_R = 1000;

const int INF = 1 << 28;

/* typedef */

/* global variables */

int n, m, r;
int zs[MAX_R];
int lds[MAX_N][MAX_N], sds[MAX_N][MAX_N];
int dists[2][MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) lds[i][j] = sds[i][j] = INF;
      lds[i][i] = sds[i][i] = 0;
    }

    for (int i = 0; i < m; i++) {
      int x, y, t;
      string sl;
      cin >> x >> y >> t >> sl;
      x--, y--;

      if (sl == "L")
	lds[x][y] = lds[y][x] = t;
      else
	sds[x][y] = sds[y][x] = t;
    }

    cin >> r;
    for (int i = 0; i < r; i++) cin >> zs[i], zs[i]--;

    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
	for (int j = 0; j < n; j++) {
	  int ld = lds[i][k] + lds[k][j];
	  if (lds[i][j] > ld) lds[i][j] = ld;
	  int sd = sds[i][k] + sds[k][j];
	  if (sds[i][j] > sd) sds[i][j] = sd;
	}

    int cur = 0, nxt = 1, z0 = zs[0];
    for (int i = 0; i < n; i++) dists[cur][i] = INF;
    dists[cur][z0] = 0;

    for (int ri = 1; ri < r; ri++) {
      int z1 = zs[ri];
      for (int i = 0; i < n; i++) dists[nxt][i] = INF;

      for (int i = 0; i < n; i++) {
	if (dists[cur][i] >= INF) continue;
	for (int j = 0; j < n; j++) {
	  int d =
	    dists[cur][i] +
	    ((i == j) ? lds[z0][z1] : lds[z0][i] + sds[i][j] + lds[j][z1]);
	  if (dists[nxt][j] > d) dists[nxt][j] = d;
	}
      }

      cur ^= 1;
      nxt ^= 1;
      z0 = z1;
    }

    int min_d = INF;
    for (int i = 0; i < n; i++)
      if (min_d > dists[cur][i]) min_d = dists[cur][i];

    cout << min_d << endl;
  }

  return 0;
}

Measured memory_bytes: 1524
#!/usr/bin/env python3

import math


P_NUM = 1000000007


def ncr(n, r):
    return math.factorial(n) // math.factorial(n-r) // math.factorial(r)


def solv(n, k):
    blue = k
    red = n - k
    for i in range(1, k+1):
        # print('blue=', blue, ' i=', i)
        blue_ptn = ncr(blue-1, i-1)
        # print('blue_ptn=', blue_ptn)
        # print('red=', red, ' i=', i)
        if red+1 < i:
            red_ptn = 0
        else:
            red_ptn = ncr(red+1, i)
        # print('red_ptn=', red_ptn)
        print(blue_ptn * red_ptn % P_NUM)


if __name__ == '__main__':

    n, k = map(int, input().split())

    solv(n, k)


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

int main() {
  int N, K, m = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (m * 2 < m + K) m *= 2;
    else m += K;
  }
  cout << m << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

using ll = long long;

int main(void)
{
    int n;
    vector<int> x;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        x.push_back(tmp);
    }

    ll result = 10000000000;
    for (int i = 1; i <= 100; i++) {
        ll tmp = 0;
        for (int j = 0; j < n; j++) {
            tmp += pow(x[j] - i, 2);
        }
        result = min(result, tmp);
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool yes(int x)
{
    int n,m=x;
    while(m)  
    {  
        n=n*10+m%10; 
        m=m/10;  
    }
    if(n==x)
        return 1;
    return 0;
}
int n;
int main()
{
    cin>>n;
    if(yes(n))
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import math
def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a
N, P = map(int, input().split())
d = defaultdict(int)
for i in trial_division(P):
    d[i] += 1
ans = []
for key in d.keys():
    if d[key] >= N:
        ans.append(key**(d[key]//N))
ans2 = 1
for i in ans:
    ans2 *= i
print(ans2)

Measured memory_bytes: 66348
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, c; cin >> a >> b >> c;
    int sum = 0;
    vector<int> s(3);
    s[0] = abs(a-b);
    s[1] = abs(b-c);
    s[2] = abs(a-c);
    sum += s[0] + s[1] + s[2];

    sort(all(s));

    cout << sum - s[2] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int N,K;
  long int n,m,n_min,n_max;
  int i,j,k;
  int a,b,c;
  long int ans=0;
  scanf("%d %d",&N,&K);
  for(i=1;i<=N;i++){
    a=i;
    if((2*a)%K==0){
    n_min=a/K;
    n_max=(N+a)/K;
    n=n_max-n_min;
    ans+=n*n;
    }
  }
  printf("%ld\n",ans);
  return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    double f, d;
  int r;
    r=a%b;
    d=(a-r)/b;
    f=(long double)a/(long double)b;
  cout << fixed << setprecision(10) ;
    cout << d << ' ' << r << ' ' << f << endl;
}


Measured memory_bytes: 3288
H,W=map(int,input().split())

M=[]
for i in range(H):
  s=input()
  M.append(s)

ans=True
for i in range(H):
  for j in range(W):
    if M[i][j]=='#':
      if (j+1 < W and M[i][j+1]=='#') or  (i+1 < H and M[i+1][j]=='#') or (j-1 >= 0 and M[i][j-1]=='#') or (i-1 >=0 and M[i-1][j]=='#'):
        continue
      else:
        ans=False
        break
if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064