akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <climits>
#include <queue>
#include <algorithm>
using namespace std;

#define MAX_N 42
#define MAX_M 420

int gcd(int a, int b) {
    return (b == 0 ? a : gcd(b, a%b));
}

int dp[MAX_N][MAX_M][MAX_M];

int main() {

    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;

    // init
    for (int k=0; k<MAX_N; k++) {
        for (int i=0; i<MAX_M; i++) {
            for (int j=0; j<MAX_M; j++) {
                dp[k][i][j] = INT_MAX;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i=0; i<N; i++) {
        int a,b,c;
        cin >> a >> b >> c;

        for (int j=0; j<MAX_M; j++) {
            for (int k=0; k<MAX_M; k++) {
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]); // 薬iを使わないとき
                if (j-a >= 0 && k-b >= 0 && dp[i][j-a][k-b] != INT_MAX) { // 薬iを使うとき
                    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j-a][k-b] + c);
                }
            }
        }
    }

    int ans = INT_MAX;
    for (int i=1; i<MAX_M; i++) {
        for (int j=1; j<MAX_M; j++) {
            int g = gcd(i,j);
            if (i/g == Ma && j/g == Mb) {
                ans = min(ans, dp[N][i][j]);
            }
        }
    }
    cout << (ans == INT_MAX ? -1 : ans) << endl;

    return 0;
}


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

int main() {
    string a, b, s1, s2;
    cin >> a >> b;
    int a1, b1;
    a1 = stoi(a);
    b1 = stoi(b);
    for(int i = 0; i < b1; i++) {
        s1 += a;
    }
    for(int i = 0; i < a1; i++) {
        s2 += b;

    }
    if(s1 <= s2) cout << s1 << endl;
    if(s2 < s1) cout << s2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  int x;cin>>x;
  int n=sqrt(2*x);
  if(n*(n+1)<2*x)n++;
  cout<<n<<endl;
}

Measured memory_bytes: 256
N = gets.to_i
Ss = gets.split.map(&:to_i)
INF = 10**9 + 5
M = 1 << N

ss = Ss.sort.reverse
pp = [ss[0]]
ss[0] = INF
N.times do
  pp.sort!
  i = 1
  np = pp.dup
  while !pp.empty?
    p = pp.pop
    loop do
      if ss[i] < p
        np << ss[i]
        ss[i] = INF
        break
      else
        i += 1
      end
      if i == M
        puts 'No'
        exit
      end
    end
  end
  pp = np
end
puts 'Yes'

Measured memory_bytes: 37660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll x;
    cin >> x;
    ll a = 100;
    ll cnt = 0;
    for(int i = 0; ; i++){
        if(a >= x)
        break;
        cnt++;
        a += 0.01 * a;
    }
    cout << cnt << endl;
}

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

x = [input().split() for i in range(n)]
for i in range(n):
	for j in range(len(x[i])):
		x[i][j] = int(x[i][j])

y = [int(input()) for k in range(m)]

for l in range(n):
	t=0
	for o in range(m):
		t += x[l][o]*y[o]
	print(t)



Measured memory_bytes: 6248
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};


string S;
string T;
bool f;


int main() {
	cin>>S>>T;
	for(int i=S.size()-T.size();i>=0;i--){
      f = true;
		Rep(j,T.size()){
			if(T[j]!=S[i+j] && S[i+j]!='?'){
				f = false;
			}
		}
		if(f){
			Rep(j,T.size()){
				S[i+j] = T[j];
				}
			Rep(k,S.size()){
				if(S[k]=='?'){
					S[k] = 'a';
				}
			}
			cout<<S<<endl;
			return 0;
		}
	}
	
	cout<<"UNRESTORABLE"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
stats=[]
res={}

for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    if s in res:
        res[s]+=1
    else:
        res[s]=1

ans=0
for i in res:
    ans+=res[i]*(res[i]-1)//2
print(ans)

Measured memory_bytes: 17932
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
using ha = pair<ll, ll>;
struct RollingHash {
	static const ll mul0 = 10009, mul1 = 10007;
	static const ll add0 = 1000010007, add1 = 1003333331;
	size_t len;
	//vector<ll> hash_, hash2_;
	vector<ha>hash_;
	//static vector<ll> pmo_, pmo2_;
	static vector<ha>pmo_;
	void init(const vector<ll>& s) {
		len = s.size();
		hash_.resize(len + 1);
		hash_[0] = make_pair(0, 0);

		if (pmo_.empty()) {
			pmo_.push_back(make_pair(1, 1));
		}
		while (pmo_.size() <= len) {
			pmo_.push_back(make_pair(pmo_.back().first*mul0, pmo_.back().second*mul1));
		}
		for (unsigned int i = 0; i < len; ++i) {
			hash_[i + 1] = make_pair((hash_[i].first * mul0 + s[i]), (hash_[i].second*mul1 + s[i]));
		}
		return;
	}
	void init(const string& s) {
		vector<ll>v;
		for (char c : s) {
			v.push_back(c);
		}
		init(v);
	}
	ha hash(const int l, const int r)const { // s[l..r]
		return make_pair(hash_[r + 1].first - hash_[l].first * pmo_[r + 1 - l].first,
			hash_[r + 1].second - hash_[l].second * pmo_[r + 1 - l].second);
	}
	ha  hash()const { // s[all]
		return hash(0, len - 1);
	}

	//hashの結合　
	static ha concat(const ha L, const ha R, const int RLength) { // hash(L+R) 
		return make_pair((R.first + L.first*pmo_[RLength].first), (R.second + L.second*pmo_[RLength].second));
	}

	//indexの位置をfromからtoに変えたもののハッシュを返す。
	ha get_changed_hash(const int index, const ll from, const ll to)const {
		const ha p(hash());
		return make_pair(
			p.first + (to - from) * pmo_[len - index - 1].first,
			p.second + (to - from) * pmo_[len - index - 1].second);
	}
}rh;
vector<ha> RollingHash::pmo_;
int main() { 
	int N, M; cin >> N >> M;
	string st; cin >> st;
	rh.init(st);
	int l = 0;
	int r = 1;
	set<ha>has;
	while (M--) {
		string a; cin >> a;
		bool is_l = a[0] == 'L';
		bool plus = a[1] == '+';
		if (is_l) {
			if (plus)l++;
			else l--;
		}
		else {
			if (plus)r++;
			else r--;

		}
		has.emplace(rh.hash(l, r-1));
	}
	cout << has.size() << endl;
	return 0;
}

Measured memory_bytes: 31132
n, a = map(int, input().split())
x = list(map(int, input().split()))
dp = [[[0]*(50*n+1) for _ in range(n+1)] for _ in range(n+1)]
for i in range(n+1):
    for j in range(n+1):
        for k in range(50*n+1):
            if i == 0 and j == 0 and k == 0:
                dp[i][j][k] = 1
            elif i and k < x[i-1]:
                dp[i][j][k] = dp[i-1][j][k]
            elif i and j and k >= x[i-1]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]]
ans = 0
for j in range(1, n+1):
    ans += dp[n][j][a*j]
print(ans)


Measured memory_bytes: 92636
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto a = readln.split[0].to!int;
	auto b = readln.split[0].to!int;
	auto c = readln.split[0].to!int;
	auto d = readln.split[0].to!int;
	auto e = readln.split[0].to!int;
	
	int f(int x) {
		if (x % 10 == 0) return x;
		else return x + 10 - x%10;
	}
	
	writeln(min(
		f(a) + f(b) + f(c) + f(d) + e,
		f(a) + f(b) + f(c) + d + f(e),
		f(a) + f(b) + c + f(d) + f(e),
		f(a) + b + f(c) + f(d) + f(e),
		a + f(b) + f(c) + f(d) + f(e)
	));
	
	
}




Measured memory_bytes: 256
H, W, h, w = gets.split.map(&:to_i)
if H % h == 0 && W % w == 0
    puts 'No'
    exit
else
    puts 'Yes'
end

plus = 10**9/h/w
minus = -(plus * (h * w - 1) + 1)

(1..H).each do |i|
    (1..W).each do |j|
        if i % h == 0 && j % w == 0
            print minus
        else
            print plus
        end
        if j == W
            print "\n"
        else
            print ' '
        end
    end
end

Measured memory_bytes: 4988
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,r,t;
int l[301];
int p[200001],req[200001];
int fie[301][301];
int tmpf[301][301];
int tmpl[301];
int cnt[301];
bool used[301];

bool C(int vt){
	memset(used,0,sizeof(used));
	memset(cnt,0,sizeof(cnt));
	for(int i=0;i<r;i++){
		tmpl[i]=l[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<r;j++){
			tmpf[i][j]=0;
			if(tmpf[i][j]==fie[i][j])cnt[i]++;
		}
	}
	for(int i=0;i<n;i++){
		if(cnt[i]==r){
			used[i]=true;
		}
	}
	int restcnt=n;
	for(int i=0;i<vt;i++){
		if(tmpl[req[i]]==0)continue;
		tmpf[p[i]][req[i]]++;
		tmpl[req[i]]--;
		if(tmpf[p[i]][req[i]]==fie[p[i]][req[i]])cnt[p[i]]++;
		if(cnt[p[i]]==r){
			used[p[i]]=true;
			restcnt--;
			for(int j=0;j<r;j++){
				tmpl[j]+=tmpf[p[i]][j];
			}
		}
	}
	bool update=true;
	while(update){
		update=false;
		for(int i=0;i<n;i++){
			if(!used[i]){
				bool flag=true;
				for(int j=0;j<r;j++){
					if(fie[i][j]-tmpf[i][j]>tmpl[j])flag=false;
				}
				if(flag){
					used[i]=true;
					update=true;
					restcnt--;
					for(int j=0;j<r;j++){
						tmpl[j]+=tmpf[i][j];
					}
				}
			}
		}
	}
	return (restcnt>0);
}

int main(void){
	scanf("%d%d%d",&n,&r,&t);
	for(int i=0;i<r;i++){
		scanf("%d",&l[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<r;j++){
			scanf("%d",&fie[i][j]);
		}
	}
	for(int i=0;i<t;i++){
		scanf("%d%d",&p[i],&req[i]);
		p[i]--;
		req[i]--;
	}
	int l=0,r=t+1;
	while(l+1<r){
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r==(t+1)?-1:r);
	return 0;
}


Measured memory_bytes: 5432
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

string aite;
int dp[2][100001] = {};
int nG,nP,lst;

int recur(int index,int me,int pp){
    int point = pp;
    int lsp = 0;
    if(dp[me][index] > -200000)
        return dp[me][index];

    if(index==lst){
        return dp[me][index] = pp;
    }

    if(aite[index]=='g'&& me == 1)
        point++;
    else if(aite[index]=='p'&& me == 0)
        point--;


    if(nP < nG){
        nP++;
        lsp = recur(index+1,1,point);
        nP--;
    }
    nG++;
    lsp = max(lsp,recur(index+1,0,point));
    nG--;
    return dp[me][index] = lsp;
}

int main(){
    cin >> aite;
    lst = aite.length();
    nG = 1;
    nP = 0;
    for(int i=0;i<=lst;i++)
        dp[0][i] = dp[1][i] = -200000;
    cout<<recur(0,0,0)<<endl;
}


Measured memory_bytes: 5888
#include <iostream>

using namespace std;
int main(){
  int A,B,sum=0;
  cin >> A >> B;
  for(int i=0;i<2;i++){
    if(A>B){sum+=A;A--;}
    else {sum+=B;B--;}
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import math

n,d = map(int,input().split())
string_list=[input().split() for i in range(n)]

xl = 0
for item in string_list:
    xkyori = int(item[0])**2
    ykyori = int(item[1])**2
    kyori = math.sqrt(xkyori+ykyori)
    if kyori <= d:
        xl +=1

print(xl)

Measured memory_bytes: 67684
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i64 = input();
    let b: i64 = input();
    let c: i64 = input();

    let mut v = vec![false; b as usize];
    let mut sum = 0;
    let mut ok = false;
    loop {
        sum += a;
        sum %= b;
        if sum == c {
            ok = true;
            break;
        }
        if v[sum as usize] {
            break;
        }
        v[sum as usize] = true;
    }
    println!("{}", if ok { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

int main()
{
    int r;
    cin >> r;
    cout << fixed << setprecision(10) << 2. * M_PI * r  << endl;
    return 0;
}

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

int main(){
    int ans = 0;
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    h.push_back(0);

    for(;;){
        int s = -1, e = -1;
        //自然数の始まりと終わりを探す
        for(int i = 0; i <= n; i++){
            if(h[i] > 0 && s < 0){
                s = i;
            }
            if(s > -1){
                if(h[i] < 1){
                    e = i;
                    break;
                }
            }
        }
        //自然数の連続区間を最小値で引く
        if(s > -1 && e > -1){
            int minn = *min_element(h.begin()+s,h.begin()+e-1);
            for(int j = s; j < e; j++){
                h[j] -= minn;
            }
            ans += minn;
        }
        //for(auto a:h) cout << a << " ";
        //cout << ": " << ans << endl;
        if(s < 0){ break; }
    }
    
    put(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(i = j; i <= k; i++)
#define per(i,j,k) for(i = k; i >= j; i--)
using namespace std;

struct sushi {
    long long x;
    long long v;
    long long w1 = 0;
    long long w2 = 0;
} s[100005];
long long ans, n, c, i;

int cmp(sushi a, sushi b) {return a.x < b.x;}

int main(void) {
    scanf("%lld%lld", &n, &c);
    rep(i, 1, n) scanf("%lld%lld", &s[i].x, &s[i].v);
    sort(s+1, s+n+1, cmp);
    rep(i, 1, n) s[i].w1 = s[i-1].w1 + s[i].v;
    rep(i, 1, n) s[i].w1 = max(s[i-1].w1, s[i].w1 - s[i].x);
    per(i, 1, n) s[i].w2 = s[i+1].w2 + s[i].v;
    per(i, 1, n) s[i].w2 = max(s[i+1].w2, s[i].w2 - c + s[i].x);
    ans = 0;
    rep(i, 0, n) {
        ans = max(ans, max(s[i].w1, s[i].w2));
        ans = max(ans, max(s[i].w1, 0ll) + max(s[i+1].w2, 0ll) - min(s[i].x, c - s[i+1].x));
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
  string S;
  cin >> S;

  
  bool flag_s = false;
  bool flag_l = false;
  long long cl=0,cs=0,res=0;
  long long cdiff = 0;
  bool start_s = false;
  bool flag_count = false;
  long long count_s = 0;
  
  if(S.size() == 2 && S.at(0) == '>' && S.at(1) == '<'){
    cout << 2 << endl;
    return 0;
  }
  
  if(S.at(0) == '>'){

    for (long long i = 0; i < S.size(); i++) {


      if(S.at(i) == '<'){
        flag_count = true;
      }
    
      if(flag_count == true ){  

        if(cl < cs){    
          res += ((1+cs)*cs)/2;
          res += (cl*(cl-1))/2;
        }
        else{
          res += (cs*(cs-1))/2;
          res += ((1+cl)*cl)/2;
        }
//        cout << "cdiff:" << cdiff << endl;
//        cout << "i:" << i << " <" << cl  << " >:" << cs << " res:" << res << endl;
        cl = 0;
        cs = 0;
        
        cdiff =0;
        flag_count = false;
        break;
      }
    count_s++;
 	if(S.at(i) == '<' ){
      cl++;
    }
    else{
      cs++;    
    }
  
  }
  }
  
  
//  cout << "count" << count_s << endl;
  for (long long i = count_s ; i < S.size(); i++) {
      if(i == count_s){
        cdiff++;
      }
      else{
        if(S.at(i-1) != S.at(i)){
          cdiff++;
        }
      }
 //     cout << "diff" << cdiff << endl;
      if(start_s == false && cdiff > 1 && cdiff%2 == 1){
        flag_count = true;
      }
    
      if(flag_count == true ){  

        if(cl < cs){    
          res += ((1+cs)*cs)/2;
          res += (cl*(cl-1))/2;
        }
        else{
          res += (cs*(cs-1))/2;
          res += ((1+cl)*cl)/2;
        }
//       cout << "cdiff:" << cdiff << endl;
//       cout << "i:" << i << " <:" << cl  << " >:" << cs << " res:" << res << endl;
        cl = 0;
        cs = 0;
        
        cdiff =1;
        flag_count = false;
      }
    
 	if(S.at(i) == '<' ){
      cl++;
//      cout << "i:" << i << " <" << endl;
    }
    else{
      cs++;  
    }
  
  }

  if(cl < cs){    
    res += ((1+cs)*cs)/2;
    res += (cl*(cl-1))/2;
  }
  else{
    res += (cs*(cs-1))/2;
    res += ((1+cl)*cl)/2;
  }          
//  cout << "i:" << S.size() << " <:" << cl  << " >:" << cs << " res:" << res << endl;
  cout << res << endl;
}






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

typedef long long ll;

ll addsolve(ll a) {
  return (a+1)/2 % 2;
}

ll solve(ll a) {
  if ( a % 2 == 1 ) return addsolve(a);
  else return addsolve(a+1)^(a+1);
}

int main() {
  ll A,B; cin >> A >> B;
  cout << (solve(A-1)^solve(B)) << endl;
  return 0;
}


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

int main(){
	
	int N,K;
    long long ans =0;
    cin >> N >> K;
    vector<int> H(N);
    rep(i,N)cin >> H[i];
    sort(H.begin(),H.end());
    if(N<=K){
        ans = 0;
    }
    else{
        rep(i,N-K)ans += H[i];
    }
    cout << ans;
	return 0;
}

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

#define MAX 2000001
#define VMAX 10000

int main(void)
{
  unsigned short *A, *B;
  
  int C[VMAX+1];
  int n, i, j;
  scanf("%d",&n);
  
  A = malloc(sizeof(short)*n+1);
  B = 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]);
    C[A[i+1]]++;
  }
  
  for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];
  
  for(j=1;j<=n;j++) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1;i<=n;i++) {
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    vector<int> cnt(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i] - 1]++;
    }

    sort(cnt.begin(), cnt.end());

    int ans = 0;
    for (int i = 0; i < n-k; i++) {
        ans += cnt[i];
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << (x) << '\n'

using namespace std;
using Graph = vector<vector<int>>;

typedef int64_t Int;
const double pi = M_PI;

vector<bool> seen;
vector<int> counter;

void dfs(const Graph &G, int v) {
    seen[v] = true; // v を探索済みにする

    // v から行ける各頂点について
    for (auto next_v : G[v]) {
        if (seen[next_v])
            continue; // 探索済みなら飛ばす

        counter[next_v] += counter[v];
        dfs(G, next_v); // 再帰探索
    }
}

int main() {
    // 入力
    int N, Q;
    cin >> N >> Q;

    // グラフの入力
    Graph G(N);
    for (int n = 0; n < N - 1; n++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 初期化
    seen.assign(N, false);
    counter.assign(N, 0);

    // 累積和とる前準備
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        p--;

        counter[p] += x;
    }

    dfs(G, 0);

    // 出力
    for (int n = 0; n < N - 1; n++) {
        cout << counter[n] << ' ';
    }
    cout << counter[N - 1];
}


Measured memory_bytes: 23552
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
char s[1001][1001];
int i,j;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int d[1001][1001];

int bfs(){
  queue<P> que;
  rep(i,n){
    rep(j,m){
      if(s[i][j]=='#'){
        d[i][j]=0;
        que.push(P(i,j));
      }
      else d[i][j]=INF;
    }
  }
  while(que.size()){
    P p = que.front();que.pop();
    rep(i,4){
      int nx=p.first+dx[i];
      int ny=p.second+dy[i];
      if(0<=nx and nx<n and 0<=ny and ny<m and s[nx][ny]=='.'){
        s[nx][ny]='#';
        que.push(P(nx,ny));
        d[nx][ny]=d[p.first][p.second]+1;
        //cout<<que.size()<<endl;
      }
    }
  }
  int r=0;
  rep(i,n){
    rep(j,m){
      r=max(r,d[i][j]);
      //cout<<d[i][j]<<endl;
    }
  }
  return r;
}


int main(){
  cin>>n>>m;
  rep(i,n){
    rep(j,m){
      cin>>s[i][j];
    }
  }
  int ans=bfs();
  cout<<ans<<endl;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
bool cmp1(pair<long long,long long>p1,pair<long long,long long>p2){   
    return p1.first>p2.first;
}
bool cmp2(pair<long long,long long>p1,pair<long long,long long>p2){   
    return p1.second>p2.second;
}
long long getabs(pair<long long,long long>p1,pair<long long,long long>p2){
    return abs(p1.first-p2.first)+abs(p1.second-p2.second);
}
long long solve_simple(vector<pair<long long,long long>>p){
    long long ret=0;
    for(int i=0;i<p.size()-1;i++){
        for(int k=i;k<p.size();k++){
            ret=max(getabs(p[i],p[k]),ret);
        }
    }
    return ret;
}
long long solve(vector<pair<long long,long long>>p){
    vector<long long>z;
    vector<long long>w;
    for(int i=0;i<p.size();i++){
        z.push_back(p[i].first+p[i].second);
        w.push_back(p[i].first-p[i].second);
    }
    sort(z.begin(),z.end());
    sort(w.begin(),w.end());
    return max(z[p.size()-1]-z[0],w[p.size()-1]-w[0]);
}

int main(){
    long long n;
    cin>>n;

    vector<pair<long long,long long>>point(n);
    
    for(int i=0;i<n;i++){
        long long x,y;
        cin>>x>>y;
        point[i]=(make_pair(x,y));
    }


    //cout<<solve_simple(point)<<endl;
    
    cout<<solve(point)<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 12896
#include <stdio.h>

#define arr_print_d0dn(a, n) for(int i=0;i<(n);++i)printf(i==(n)-1?"%d\n":"%d ",(a)[i])
#define arr_rprint_d0dn(a, n) for(int i=(n)-1;i>=0;--i)printf(i?"%d ":"%d\n", (a)[i])
#define arr_print_dndn(a, n) for(int i=0;i<(n);++i)printf("%d\n", (a)[i])

int insertion_sort(int *a, const int N, const int G) {
    int cnt = 0;
    for(int i = G; i < N; ++i) {
        int tmp = a[i];
        int j = i - G;
        while(j >= 0 && a[j] > tmp) {
            a[j + G] = a[j];
            j -= G;
            cnt++;
        }
        a[j + G] = tmp;
    }
    return cnt;
}

void shell_sort(int *a, const int N) {
    int cnt = 0;
    int m = 0;
    int G[100] = {};
    for(int h = 1; h <= N; h = 3 * h + 1) {
        G[m] = h;
        m++;
    }
    for(int i = m - 1; i >= 0; --i) {
        cnt += insertion_sort(a, N, G[i]);
    }

    printf("%d\n", m);
    arr_rprint_d0dn(G, m);
    printf("%d\n", cnt);
    arr_print_dndn(a, N);
}

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    shell_sort(a, n);
    return 0;
}



Measured memory_bytes: 6656
#include <iostream>
#include <string>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

// 入力
string s, t;

// DPテーブル
int dp[3100][3100] = {0}; // 初期値も初期条件も 0

int main() {
    cin >> s >> t;

    // DPループ
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    // 復元
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    cout << res << endl;
}

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

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

int main(){
	while(true){
		int a,b;
		cin>>a>>b;
	
		if(cin.eof())
			break;
	
		int g=gcd(a,b);
		cout<<g<<' '<<a/g*b<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
  int X;
  cin >> X;
  int ans = 1;
  for (int i = 2; i <= (int)sqrt(X); i++) {
    int exp = i;
    for(;;) {
      exp *= i;
      if (exp > X) break;
      ans = max(ans, exp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,x;
  	cin>>k>>x;
  	
  	for(int i=x-(k-1);i<x+k;i++){
    	if(i==x+k-1){
          cout<<i;
        }
      	else{
        	cout<<i<<' ';
        }
    }
}

Measured memory_bytes: 256
x, n = map(int, input().split())
p = list(map(int, input().split()))

p.sort()

arr = [False] * 102

for i in range(len(p)):
    arr[p[i]] = True

dist = 10*10

ans = -99

search = list(range(-100,102))
search.reverse()

for i in search:
    if arr[i] == False:
        dist = min(abs(x - i), dist)
        if dist == abs(x - i):
            ans = i
print(ans)


Measured memory_bytes: 9088
#include <iostream>
#include <string>
using namespace std;
int main() {  
  int n, count=0;  
  string str;   
  cin >> str >> n; 
  for(int i=0; i<n; i++) { 
    string a;   
    cin >> a;    
    for(int j=0; j<a.size();j++) { 
      int check=0, b=j;   
      if(a[j]==str[0]) {    
	for(int k=0; k<str.size(); k++) { 
	  if(a[b]==str[k]) check++;   
	  else break;     
	  b++;     
	  if(b==a.size()) b=0;    
	}   
      }   
      if(check==str.size()) {   
	count++;   
	break;     
      }  
    } 
  }  
  cout << count << endl; 
  return 0;
}


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

//INFの定義
const int INF = pow(10, 7);

//Nの約数を列挙したものを取得する関数
vector<ll> func(ll num){
    vector<ll> p;
    for(ll i = 1; i*i <= num; i++){
        if(num % i == 0) p.push_back(i);
    }
    return p;
}

//桁数を求める関数
int keta(int num){
    int k = 1;
    while(num / 10 != 0){
        num /= 10;
        k++;
    }
    return k;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> p = func(N);
    ll len = (ll)p.size();
    int mn = INF;
    rep(i, len){
        ll a = p[i];
        ll b = N / a;
        int val = keta(max(a, b));
        mn = min(mn, val);
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 3612
import itertools
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
g = [[0] * n for i in range(n)]
for i,j in itertools.combinations(range(n),2):
  i,j = min(i,j),max(i,j)
  g[i][j] = ((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2) ** 0.5
a = 0
c = 0
for i in itertools.permutations(range(n)):
  c += 1
  cur = i[0]
  for j in i[1:]:
    pre,cur = cur,j
    a += g[min(pre,cur)][max(pre,cur)]
print(a/c)

Measured memory_bytes: 3188
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def factorization(n):
    d = {}
    tmp = n
    for i in range(2, int(n ** 0.5) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            d[i] = cnt

    if tmp != 1:
        d[tmp] = 1

    return d


def main():
    N = int(input())
    d = factorization(N)
    ans = 0
    for k, v in d.items():
        i = 1
        while v - i >= 0 and N % (k ** i) == 0:
            v -= i
            ans += 1
            N //= k ** i
            i += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////


int main(){fastio
    
    ll a,p;cin>>a>>p;
    p+=3*a;
    cout<<p/2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <limits>
#include <vector>
#include <string>
#include <cinttypes>
#include <algorithm>

using namespace std;

typedef unsigned char u8;
typedef int16_t  i16;
typedef int32_t  i32;
typedef int64_t  i64;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;

int A, B, C, X;

int resolve(int a, int b, int c)
{
    return (500 * a + 100 * b + 50 * c) == X ? 1 : 0;
}

int main(int argc, char** argv)
{
    int ans = 0;

    scanf("%d\n%d\n%d\n%d", &A, &B, &C, &X);

    for (auto a = 0; a <= A; ++a) {
        for (auto b = 0; b <= B; ++b) {
            for (auto c = 0; c <= C; ++c) {
                ans += resolve(a, b, c);
            }
        }
    }

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

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int unko(int rate) {
	if (rate < 400) return 1;
	if (rate < 800) return 1<<1;
	if (rate < 1200) return 1<<2;
	if (rate < 1600) return 1<<3;
	if (rate < 2000) return 1<<4;
	if (rate < 2400) return 1<<5;
	if (rate < 2800) return 1<<6;
	if (rate < 3200) return 1<<7;
	else return 0;
}

int main() {
	int N;
	cin >> N;
	int c = 0, cnt = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		cnt += !unko(a);
		c |= unko(a);
	}
	cout << max(1, __builtin_popcount(c)) << " " << cnt+__builtin_popcount(c) << endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a,b;
    vector <int> ans2(n,0);
    vector <int> c(n);
    vector <vector <int>> m(n);

    rep(i,n-1){
        cin >> a >> b;
        m[a-1].push_back(b-1);
        m[b-1].push_back(a-1);
        
    }
    ll ans=0;

    rep(i,n){
        cin >> c[i];
        ans+=c[i];
    }

    sort(c.rbegin(),c.rend());
    ans-=c[0];

    queue <int> q;
    int qq;
    q.push(0);
    int k=0;
    int l;

    while(q.size()!=0){
        qq=q.front();
        q.pop();
        ans2[qq]=c[k];
        ++k;
        l=m[qq].size();
        rep(j,l){
            if(ans2[m[qq][j]]==0){
                q.push(m[qq][j]);
            }
        }

    }

    cout << ans << endl;
    rep(i,n){
        cout << ans2[i] << " "; 
    }

    cout << endl;



    return 0;
}

Measured memory_bytes: 4004
;; C - Poll

(defun main ()
  (let* ((n  (read))
         (ss (loop repeat n collect (read-line))))
    (format t "~{~a~%~}" (solve n ss))))

(defun solve (n ss)
  (let ((sa (make-array n :initial-contents (sort ss #'string<)))
        (count (make-array n)))
    (setf (aref count 0) 1)
    (loop for i from 1 below n
          do (setf (aref count i)
                   (if (string= (aref sa i) (aref sa (1- i)))
                       (1+ (aref count (1- i)))
                       1)))
    (let ((m (loop for c across count maximize c)))
      (loop for i below n
            when (= (aref count i) m)
            collect (aref sa i)))))

(main)


Measured memory_bytes: 69736
#include <bits/stdc++.h>
using namespace std;
#define _  << ' ' <<
#define squ(x)  ((x) * (x))
#define VAR_NAME(var)  cout << #var << " : ";
#define debug(var)  VAR_NAME(var); view(var);
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
template <class T>
using VVV = vector<vector<vector<T>>>;
//// view vector functions
template<typename T>
void view(T e){
  cout << e << endl;
}
template<typename T>
void view(vector<T>& v){
  for(const auto& e : v){
    cout << setw(5)<< e << " ";
  }
  cout << endl;
}

template<typename T>
void view(const vector<vector<T>>& vv){
  for(const auto& v : vv){
    for(const auto& e : v)
      cout << setw(5) << e << " ";
    cout << endl;
  }
}

int main(){
  int i, j;
  int R, D;
  cin >> R >> D;
  V<int> x(11);
  cin >> x[0];
  for(i=1; i<x.size(); ++i){
    x[i] = R*x[i-1] - D;
  }
  for(i=1; i<x.size(); ++i){
    cout << to_string(x[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<double, double>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;

double dist (double a, double b) {
    return sqrt(a*a+b*b);
}

int main(){
    int n;
    cin >> n;
    vector<P> e(n);
    rep(i, n) cin >> e[i].first >> e[i].second;
    auto comp = [](P a, P b) {
        return atan2(a.second, a.first)<atan2(b.second, b.first);
    };
    sort(e.begin(), e.end(), comp);
    vector<double> theta(2*n);
    rep(i, n) {
        theta[i] = atan2(e[i].second, e[i].first);
        theta[i+n] = theta[i] + 2*M_PI;
    }
    double ans = 0.0;

    rep(i, n) {
        rep(j, n) {
            //double ang = theta[i];
            //ang += M_PI;
            double sumx = 0.0;
            double sumy = 0.0;
            int id = i;
            int k = j;
            if (k<id) k+=n;
            while (id<=k) {
                sumx += e[id%n].first;
                sumy += e[id%n].second;
                id++;
            }
            ans = max(ans, dist(sumx, sumy));
        }
    }
    
    
    
    printf("%.15lf\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdint>

using namespace std;

int main(int argc, char const* argv[]) {
	uint32_t s, w;
	cin >> s;
	cin >> w;

	if (s <= w)
		cout << "unsafe";
	else
		cout << "safe";
	cout << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <string.h>
#include <cstdarg>
 
using namespace std;
 
typedef long long ll;
 
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)
 
using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;
 
 
// Extended Print Func
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& input){
    os << "[ ";
    REP(i, input.size()){
        os << input[i];
        if (i < input.size()-1) { os << " "; }
    }
    os << " ]";
    return os;
}
void print() { std::cout << "\n"; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }
 
ll A[1001][1001];
ll done[1001];
ll ne[1001];
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  memset(done,0,sizeof(done));
  ll N;
  cin >> N;
 
  REP(i,N){
      REP(j,N-1){
          cin >> A[i][j]; A[i][j]--;
          ne[i] = 0;
      }
  }
 
  
  ll day = 0;
  for(;;) {
      bool is_match = false;
      day++;
      REP(i,N){
          if (done[i] == day) continue;
          ll opp = A[i][ne[i]];
          if (done[opp] == day) continue;
          if (ne[i]<N-1 && ne[opp]<N-1 && i==A[opp][ne[opp]]) {
              is_match = true;
              ne[i]++; ne[opp]++;
              done[i]=day; done[opp]=day;
          }
      }
      if (!is_match) {
          day--;
          break;
      }
  }
 
  REP(i,N){
      if (ne[i] != N-1){
          cout << -1 << "\n";
          return 0;
      }
  }
  
  std::cout << day << "\n";  
  return 0;
}

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

int main() {
    int n,x;
    cin>>n>>x;
    vector<int> m(n);
    int min = 1001;
    for(int i=0; i<n; i++) {
        cin>>m[i];
        x -= m[i];
        if(min>m[i]) min = m[i];
    }
    cout<<n+x/min<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def merge(A, left, mid, right):
    global count

    L = A[left:mid] + [1e9]
    R = A[mid:right] + [1e9]

    i, j = 0, 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    count += right - left
    return None


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    assert array_length == len(array)
    count = 0
    print(*merge_sort(A=array, left=0, right=array_length))
    print(count)

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

int main() {
	
	ll n, k, s;
	cin >> n >> k >> s;

	if (s == 1000000000) {
		REP(i, n) {
			if (i < k)cout << s << ' ';
			else cout << 1 << ' ';
		}
	}
	else {
		REP(i, n) {
			if (i < k)cout << s << ' ';
			else cout << 1000000000 << ' ';
		}
	}


	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }
 
    // 素数である
    return 1;
}
 
   
 
 
  int main(){
      lint N,Q,s;
      cin>>N>>Q>>s;
     if(N+Q<=s)cout<<0<<" "<<0;
     else if(N<=s)cout<<0<<" "<<N+Q-s;
     else cout<<N-s<<" "<<Q;
  }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, a, b, c, d,day,day2,ans;
	cin >> n >> a >> b >> c >> d;
	day = a / c;
	if (a%c != 0) {
		day = day + 1;
	}
	day2 = b / d;
	if (b%d != 0) {
		day2 = day2 + 1;
	}
	ans = n - max(day, day2);
	cout << ans << endl;
}


Measured memory_bytes: 3092
#include<stdio.h>

void spin_w(int x[]){
  int sai1[6],i;

  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }

  sai1[0]=x[2];
  sai1[2]=x[5];
  sai1[3]=x[0];
  sai1[5]=x[3];

  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }

}

void spin_side(int x[]){
int sai1[6],i;

for(i=0;i<6;i++){
  sai1[i]=x[i];
 }

sai1[1]=x[2];
sai1[2]=x[4];
sai1[3]=x[1];
sai1[4]=x[3];

for(i=0;i<6;i++){
  x[i]=sai1[i];
 }
}


void spin_s(int x[]){
	int sai1[6],i;
	
  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }
  sai1[0]=x[4];
  sai1[1]=x[0];
  sai1[4]=x[5];
	sai1[5]=x[1];
	
  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }
}

int conf(int x[],int y[]){
	
	int i,count=0,count2=0,a=0,sai1[6],sai2[6];
	
	for(i=0;i<6;i++){
		sai1[i]=x[i];
		sai2[i]=y[i];
	}
	
	for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
    }
	}
	
  if(count!=6){
		for(i=0;i<=3;i++){
			spin_w(sai1);
			count2++;
		if(sai1[0]==sai2[0])break;
		}
		if(count2==4){
			for(i=0;i<=3;i++){
			spin_s(sai1);
		if(sai1[0]==sai2[0])break;
			}
		}
			
    for(i=0;i<=3;i++){
      spin_side(sai1);
      if(sai1[1]==sai2[1] && sai1[2]==sai2[2] && sai1[3]==sai2[3] && sai1[4]==sai2[4])break;
		}
  }

  count=0;


  for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
		}
	}
	if(count==6){
		return 1;
	}else{
		return 0;
	}
}

int main(){
  int i,j,k,l,sai1[6],sai2[6],sai_c[105][6],n,a=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<6;j++){
			scanf("%d",&sai_c[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<6;j++){
			sai1[j]=sai_c[i][j];
		}
		for(k=i+1;k<n;k++){
			for(l=0;l<6;l++){
				sai2[l]=sai_c[k][l];
			}
				if(conf(sai1,sai2)==1){
			a++;
			}
		}
	}
  if(a==0){
	  printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdlib.h>

using namespace std;
int main()
{
  int K, len;
  string S;
  cin >> K >> S;

  len = S.length();

  if (K >= len)
  {
    cout << S << endl;
  }
  else
  {
    S.replace(K, len - K, "...");
    cout << S << endl;
  }

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
ll n, m, a, b, c, dist[2000];
vector<pair<ll, ll>> x[3000];
void solve()
{
    dist[0] = 0;
    ll P = dist[n - 1];
    for (int i = 0; i < 8 * n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (pair<ll, ll> k : x[j])
                dist[k.first] = max(dist[k.first], dist[j] + k.second);
        }
        if (P != dist[n - 1] && i >= 5 * n)
        {
            cout << "inf" << endl;
            return;
        }
        P = dist[n - 1];
    }
    cout << dist[n - 1] << endl;
    return;
}
main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    rep(i, m)
    {
        cin >> a >> b >> c;
        a--, b--;
        x[a].push_back(make_pair(b, c));
    }
    rep(i, n) dist[i] = -(1LL << 60);
    solve();
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,k,a[100001],ans=0;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=n;i>=n-k+1;i--){
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define num first
#define ch  second

const int score[4]={0,60,70,80};

int getstate(int *in){
  int ret=0;
  for(int i=0;i<5;i++){
    ret=(ret<<2)+in[i];
  }
  return ret;
}

int dp[5][(1<<11)]={0};
bool isexist[5][5];
bool vis[5][(1<<11)];
int button(int n,int ini[5],int next[5]){
//   if (n== 2 && vis[n-1][getstate(ini)]){
//     rep(i,5)cout << ini[i] <<" " ;
//   }
  if (!vis[n-1][getstate(ini)])return 0;
  int maxi=0;
  rep(i,4){
    rep(j,4){
      rep(k,4){
	rep(l,4){
	  int next1[5],next2[5];
	  rep(jj,5)next1[jj]=ini[jj],next2[jj]=next[jj];
	  next1[0]=(next1[0]+i)%4;
	  next1[1]=(next1[1]+i+j)%4;
	  next1[2]=(next1[2]+j+k)%4;
	  next1[3]=(next1[3]+k+l)%4;
	  next1[4]=(next1[4]+l)%4;
	  
	  next2[0]=(next2[0]+i)%4;
	  next2[1]=(next2[1]+i+j)%4;
	  next2[2]=(next2[2]+j+k)%4;
	  next2[3]=(next2[3]+k+l)%4;
	  next2[4]=(next2[4]+l)%4;
	  rep(jj,5){
	    if (!isexist[n-1][jj])next1[jj]=0;
	    if (!isexist[n  ][jj])next2[jj]=0;
	  }

	  int a=getstate(next2),b=getstate(ini);
	  int tmp=0,tmp2=0;
	  rep(jj,5){
	    if (isexist[n-1][jj])tmp+=score[next1[jj]];
	  }
	  rep(jj,5){
	    if (isexist[n  ][jj])tmp2+=score[next2[jj]];
	  }
	  dp[n][a]=max(dp[n][a],dp[n-1][b]+tmp);
	  vis[n][a]=true;
	  maxi=max(dp[n][a]+tmp2,maxi);
	}
      }
    }
  }
  return maxi;
}

int search(int n,int now,int *ini,int *next){
  if (now == 5){
    return button(n,ini,next);
  }
  if (!isexist[n-1][now]){
    ini[now]=0;
    return search(n,now+1,ini,next);
  }
  int maxi=0;
  rep(i,4){
    ini[now]=i;
    maxi=max(maxi,search(n,now+1,ini,next));
  }
  return maxi;
}

main(){
  int te;
  cin>>te;
  while(te--){
    rep(i,5)rep(j,(1<<11))dp[i][j]=0,vis[i][j]=false;
    int a[5][5];
    int arr[5];
    rep(i,5){
      rep(j,5){
	cin>>a[i][j];
	if (a[i][j] == 0)isexist[i][j]=false;
	else {
	  isexist[i][j]=true;
	  a[i][j]--;
	}
      }
    }

    vis[0][getstate(a[0])]=true;
    
    int ans=0;
    REP(i,1,5){
      ans=max(ans,max(ans,search(i,0,arr,a[i])));
    }
    cout << ans << endl;

  }
  return false;
}

Measured memory_bytes: 912
#include<bits/stdc++.h>
#include<set>
#include<iterator>
#include<algorithm>
using namespace std;
#define forr(a,n) for(int i=a;i<=n;i++)
#define MAX 1000000007LL
#define mod 998244353
#define forn(n,a) for(int i=n;i>=a;i--)
#define all(x) x.begin() , x.end()
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pii pair<int,int>
#define ll long long
const int N = (int)1e5 + 9;
ll power(ll x,ll y)
{
    ll ans = 1;
    while(y>0)
    {
        if(y%2 == 1)
            ans = ans*x;
        x=x*x;
        y=y>>1;
    }
    return ans;
}
int n;
ll fact[10];
vector<int> x;
vector<int> y;
string s = "";
double ans = 0;
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("in.txt" , "r" , stdin);
    // // freopen("out.txt" , "w" , stdout);
    // #endif
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    fact[0] = 1;
    fact[1] = 1;
    forr(2,9)
        fact[i] = fact[i-1] * i;
    cin>>n;
    forr(0,n-1)
    {
        s = s + to_string(i);
        int a,b;
        cin>>a>>b;
        x.pb(a); y.pb(b);
    }

    do{
        // cout<<s<<"\n";
        double value = 0;
        for(int i=1;i<n;i++)
        {
            int j = int(s[i]) - 48;
            int k = int(s[i-1]) - 48;
            value = value + sqrt((x[j] - x[k])*(x[j] - x[k]) + (y[j] - y[k])*(y[j] - y[k]));
        }
        // cout<<s<<" "<<value<<"\n";
        ans+=value;
    } while (next_permutation(s.begin() , s.end()));

    ans = (double) ans / (double) fact[n];
    printf("%.10f",ans);
    return 0;
}

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

from collections import Counter

ac = Counter(a)
acm = ac.most_common()

ans = 0

for i in range(len(acm)):
    ans += acm[i][1]*(acm[i][1]-1)//2

for ai in a:
    print(ans - ac[ai] + 1)


Measured memory_bytes: 30112
# coding: utf-8
# Your code here!

N,D = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(N)]
count = 0
for j in range(N-1):
    for i in range(j+1,N):
        a = 0
        for d in range(D):
           #print(lst[j][d],lst[i][d])
            a+= (abs(lst[j][d] - lst[i][d]))**2
        if (a**0.5 % 1 == 0):
            count+=1
        
print(count)

Measured memory_bytes: 38384