akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#define N 1005
using namespace std;

int n, t, s, x[N], y[N];
vector<int> a[N];
bitset<5005> bs;
int main()
{
	int i, j;
	cin >> n;
	for (i = 2; i <= n; i++) {
		scanf ("%d", &t);
		a[t].push_back(i);
	}
	for (i = 1; i <= n; i++) {
		scanf ("%d", &x[i]);
	}
	for (i = n; i >= 1; i--) {
		bs = 1;
		s = 0;
		for (j = 0; j < a[i].size(); j++) {
			t = a[i][j];
			bs = (bs << x[t] | bs << y[t]);
			s += x[t] + y[t];
		}
		for (j = x[i]; j >= 0; j--) if (bs[j]) break;
		y[i] = s - j;
		if (j < 0) {
			cout << "IMPOSSIBLE";
			return 0;
		}
	}
	cout << "POSSIBLE";
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

# Name: Transit Tree Path
# Level: 2
# Category: Graph, 最短経路問題
# Note: 深さ優先探索

import sys

sys.setrecursionlimit(200000)

N = int(raw_input())
tree = [[] for _ in xrange(N)]

for i in range(N-1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1;
    tree[a].append((b, c))
    tree[b].append((a, c))

Q, K = map(int, raw_input().split())
K -= 1

depth = [0 for _ in xrange(N)]

def dfs(v, p = -1, d = 0):
    St = []
    St.append([v, p, d])
    while len(St) != 0:
        cur = St.pop()
        depth[cur[0]] = cur[2]
        for i, j in tree[cur[0]]:
            if i == cur[1]:
                continue
            St.append([i, cur[0], cur[2] + j])

dfs(K)

for i in range(Q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print depth[x] + depth[y]


Measured memory_bytes: 49496
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[100005];

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	LL s=0;
	LL co[5];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
	}
	for(i=n-1;i>=0;i--){
		if(t[i]!=t[n-1]-n+1+i)break;
		a=3;
		if(i==0)co[0]=0,co[1]=0,co[2]=0;
		else co[0]=t[i-1],co[1]=t[i],co[2]=i-1-co[0]-co[1],a*=2;
		if(co[2]<0)continue;
		for(j=i-2;j>=0;j--){

			b=0;
			for(k=0;k<3;k++){
				if(co[k]==t[j]+1)b++;
			}
			a*=b;
			if(a>=MAX)a%=MAX;
			for(k=0;k<3;k++){
				if(co[k]==t[j]+1){
					co[k]--;
					break;
				}
			}
		}
		if(co[0]+co[1]+co[2]>0)continue;
		s+=a;
		if(s>=MAX)s-=MAX;
	}
	cout<<s<<endl;

}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    if(h%3==0){
        cout<<0<<endl;
        return 0;
    }
    if(w%3==0){
        cout<<0<<endl;
        return 0;
    }
    int ans=min(h,w);
        if(w%2==0)ans=min(ans,w/2);
        else ans=min(ans,max(w/2+h/3,(h/3)*2)+1);
        
        if(h%2==0)ans=min(ans,h/2);
        else ans=min(ans,max(h/2+w/3,(w/3)*2)+1);
    
    cout<<ans<<endl;
    
    return 0;
    
}


Measured memory_bytes: 256
from sys import maxint

N, K = map(int,raw_input().split())
stones = map(int,raw_input().split())

costs = [maxint] * N 
costs[0] = 0
for n in range(N) :
  for k in range(1,min(K, N-n-1)+1) : 
    costs[n+k] = min(costs[n+k], costs[n] + abs(stones[n]-stones[n+k]))
  
print costs[-1]

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

int main(){
	int c[3][3];
	for(int i =0 ; i<3; i++){
		cin >> c[i][0] >> c[i][1] >> c[i][2];
	}
	if(
		c[0][0] - c[0][1] == c[1][0] - c[1][1] &&
		c[2][0] - c[2][1] == c[1][0] - c[1][1] &&
		c[0][2] - c[0][1] == c[1][2] - c[1][1] &&
		c[2][2] - c[2][1] == c[1][2] - c[1][1] &&
		
		c[1][0] - c[0][0] == c[1][1] - c[0][1] &&
		c[1][1] - c[0][1] == c[1][2] - c[0][2] &&
		c[1][0] - c[2][0] == c[1][1] - c[2][1] &&
		c[1][1] - c[2][1] == c[1][2] - c[2][2]
	) cout << "Yes";
	else cout << "No";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define endl "\n"
#define nl cout<<endl
#define pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define txti freopen("input.txt", "r", stdin);
#define txto freopen("output.txt", "w", stdout);


bool compare(char &s1,char &s2) 
{ 
    return s1 > s2; 
} 

bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
   
    if(a.first<b.first )
        return true;
    if( a.first==b.first && a.second<b.second )
        return true;
        
    return false;
    
}
//ll const mod = 1e9+7;
ll const inf = 1e9+7;;

void solve()
{   
    ll n;
    cin >> n;
    cout << n + n*n + n*n*n  <<endl;
}  



int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/
            
       
        ll t=1;
        //ll t;cin>>t;
        while(t-->0){
            solve();
            
        }
        
        

       
    return 0;
}




Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int visit[212345];
int cycle_find(const vector<vint>& G,int v,int c){
  if(visit[v]==c){
    return v;
  }else if(visit[v]>=0){
    return -1;
  }
  visit[v]=c;
  for(int u:G[v]){
    int find=cycle_find(G,u,c);
    if(find>=0) return find;
  }
  return -1;
}
int a[212345];
void dfs(const vector<vint>& G,int v){
  if(visit[v]) return;
  visit[v]=true;
  set<int> st;
  for(int u:G[v]){
    dfs(G,u);
    st.insert(a[u]);
  }
  a[v]=0;
  while(st.count(a[v]++));
  a[v]--;
}

int main(){
  int N;cin>>N;
  vector<vint> g(N);
  vint p(N);
  repeat(i,N){
    cin >> p[i];p[i]--;
    g[p[i]].push_back(i);
  }
  fill(visit,visit+N,-1);
  int rcycle=-1;
  repeat(i,N){
    rcycle=cycle_find(g,i,i);
    if(rcycle>=0)break;
  }
  //debug(rcycle);
  //debug(p[rcycle]);
  fill(visit,visit+N,false);
  set<int> st;
  for(int u:g[p[rcycle]]){
    if(u==rcycle)continue;
    dfs(g,u);
    st.insert(a[u]);
  }
  int first=0;
  while(st.count(first++));
  int second=first;
  first--;
  while(st.count(second++));
  second--;
  //debug(first);
  //debug(second);
  bool ans = false;
  visit[p[rcycle]]=true;
  a[p[rcycle]]=first;
  repeat(i,N){
    dfs(g,i);
  }
  ans |= a[p[rcycle]]!=a[rcycle];
  //debug(ans);
  //debugArray(a,N);
  fill(a,a+N,0);
  fill(visit,visit+N,false);
  for(int u:g[p[rcycle]]){
    if(u==rcycle)continue;
    dfs(g,u);
  }
  visit[p[rcycle]]=true;
  a[p[rcycle]]=second;
  repeat(i,N){
    dfs(g,i);
  }
  ans |= (first==a[rcycle]);
  //debug(ans);
  //debugArray(a,N);
  cout << (ans? "POSSIBLE":"IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 31232
N = int(input())
ct = []
 
for i in range(N):
  ct.append([int(i) for i in input().split()])
 
dist = 0
for a in ct:
  for b in ct:
    dist += (abs(a[0] - b[0])**2 +abs(a[1] - b[1])**2)**0.5
print(dist/N)


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, D;
    cin >> N >> D;

    ll ans = 0;
    REP(i, N){
        ll x, y;
        cin >> x >> y;

        if(x*x + y*y <= D*D){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
 vector<vector<int>>bingo(3,vector<int>(3)); 
  for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
          cin >> bingo.at(i).at(j);
      }
  }
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
      cin >> vec.at(i);
  }
 vector<vector<int>>ok(3,vector<int>(3,0));
  for(int k: vec){
    for(int i=0;i<3;i++){
       for(int j=0;j<3;j++){
          if (bingo.at(i).at(j) == k){
            ok.at(i).at(j) = 1;
          }
      }
    }
  }
    bool ans =false;
    
    //よこ
    for(int i=0;i<3;i++){
        if (ok.at(i).at(0) == ok.at(i).at(1) && ok.at(i).at(1) == ok.at(i).at(2) && ok.at(i).at(1) == 1){
          ans =true;
          break;
        }
    }
    for(int i=0;i<3;i++){
        if (ok.at(0).at(i) == ok.at(1).at(i) && ok.at(1).at(i) == ok.at(2).at(i) && ok.at(1).at(i) == 1){
          ans = true;
          break;
        }
  }
  
  if (ok.at(0).at(0) == ok.at(1).at(1) && ok.at(1).at(1) == ok.at(2).at(2)  && ok.at(1).at(1) == 1)ans =true;
  
  else if (ok.at(0).at(2) == ok.at(1).at(1) && ok.at(1).at(1) == ok.at(2).at(0) && ok.at(1).at(1) == 1)ans =true;

  if (ans ==true) cout << "Yes"<< endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	char ninput[7];
	char *ainput;
	int n;
	int *numbers;
	int i;
	int j = 1;
	int temp;
	long int total = 0;
	
	fgets(ninput, sizeof(ainput), stdin);
	n = atoi(ninput);
	
	ainput = (char *)malloc(sizeof(char) * n * 9 + 1);
	numbers = malloc(sizeof(int) * n);
	
	fgets(ainput, sizeof(char) * n * 9 + 1, stdin);
	numbers[0] = atoi(strtok(ainput, " "));
	
	for (i = 1; i < n; i++)
		numbers[i] = atoi(strtok(NULL, " "));
	
	for (j = 1; j < n; j++){
		for (i = 0; i < (n - j); i++){
			if (numbers[i] > numbers[i + 1]){
				temp = numbers[i];
				numbers[i] = numbers[i + 1];
				numbers[i + 1] = temp;
			}
		}
	}
	
	for (i = 0; i < n; i++){
		total += numbers[i];
	}
	
	printf("%d %d %ld\n", numbers[0], numbers[n - 1], total);
	
	
	return 0;
}

Measured memory_bytes: 680
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const long double pi = acos(-1.0);

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

  ld a,b; cin >> a >> b;
  ll ans = floor(a * b);
  cout << ans << endl;
}


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

int main(){
	int a[26]={};
	string s;
	cin >> s;
	bool ok = true;

	for(int i=0;i<s.size();i++){
		a[s[i]-'a']++;
	}

	for(int i=0;i<sizeof(a)/sizeof(int);i++){
		if(a[i]%2==1){
			ok=false;
		}
	}
	
	string j;
	j = ok ? "Yes" : "No";
	cout<<j<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




struct MyStruct
{
	vector<int>list;
};

bool flag[100002];
int flag2[100002];
int a, b, n, m;
vector<MyStruct>slist(100005);


int func(int no) {

	flag[no] = true;

	int size = slist[no].list.size();

	for (int i = 0; i < size; i++) {
	/*	if (i + 1 < slist[no].size() && slist[no].list[i + 1] == slist[no].list[i]) {
			continue;
		}*/

		int num = slist[no].list[size - (i + 1)];
		slist[no].list.pop_back();
		func(num);
	}


	return 0;
}

signed main() {
	
	cin >> n >> m;

	memset(flag, false, sizeof(flag));
	//memset(flag2, 1, sizeof(flag2));

	for (int i = 0; i < 100005; i++) {
		flag2[i] = 1;
	}

	flag[1] = true;

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		//slist[x].list.push_back(y);
		if (flag[x] == true) {
			flag[y] = true;
			flag2[x]--;
			if (flag2[x] <= 0) {
				flag[x] = false;
			}

			flag2[y]++;
		}
		else {
			if (flag2[x] > 0) {
				flag2[x]--;
				flag2[y]++;
			}
		}

		
	}

	//for (int i = 0; i < 100005; i++) {
	//	vector<int>list2 = slist[i].list;

	//	//sort(slist[i].list.begin(), slist[i].list.end());
	//	sort(list2.begin(), list2.end());

	//	//slist[i].list.erase(std::unique(slist[i].list.begin(), slist[i].list.end()), slist[i].list.end());
	//	list2.erase(std::unique(list2.begin(), list2.end()), list2.end());
	//	slist[i].list = list2;
	//}

	//func(1);

	int cnt = 0;

	for (int i = 0; i < 100005; i++) {
		if (flag[i] == true)cnt++;
	}

	cout << cnt << endl;


	getchar();
	getchar();
	return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int l=(n-1)/(k-1);
    if((n-1)%(k-1)==0)
       cout<<l;
    else
        cout<<l+1;
}


Measured memory_bytes: 3976
def check_match(A, B):
    N = len(A)
    M = len(B)
    for i in range(N):
        for j in range(N):
            match = True
            for k1 in range(M):
                for k2 in range(M):
                    if i+k1 >= N or j+k2 >= N or A[i+k1][j+k2] != B[k1][k2]:
                        match = False
                        break
            if match == True:
                return True
    return False

if __name__ == "__main__":
    size = [int(i) for i in input().split()]
    N = size[0]
    M = size[1]
    A = []
    B = []
    for i in range(N):
        A.append(input())
    for i in range(M):
        B.append(input())
    if check_match(A, B) == True:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
dp=[False]*(10**6+1)
A.sort()
ans=0
before_ = -1
for i in A:
  if dp[i]==False:
    for j in range(2*i,10**6+1,i):
      dp[j]=True
  if before_ == i:
      dp[i]=True
  before_=i

for i in A:
  if dp[i]==False:
    ans+=1
print(ans)

Measured memory_bytes: 32248
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,mx=0,sum=0;
    cin>>n;
    while(n--){
        int a;
        cin>>a;
        mx=max(mx,a);
        sum+=a;
    }
    sum-=mx;
    sum+=(mx/2);
    cout<<sum<<endl;



    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

int X, Y;

int main() {
    cin >> X >> Y;
    if (X%Y == 0) cout << -1 << endl;
    else cout << X << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
num = [i for i in range(1,n+1)]
count = []
for i in range(n):
    j = 0
    while num[i]*(2**j)<k:
        j += 1
    count.append((1/2)**j)
ans = sum(count)*(1/n)
print(ans)

Measured memory_bytes: 46004
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n = 0;
    int i;
    char buf[2*1000000];
    char buf2[2*1000000];

    fgets(buf, sizeof(buf),stdin);
    fgets(buf2, sizeof(buf2),stdin);


	i = 0;
	while(buf[i] != '\0'){
		n++;
		i++;
	}

int count = n;
    for (i=0; i<count;i++){
        if(buf[i]==buf2[i]){
            n--;
        }
    }
    printf("%d\n", n);

}

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

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  map<int, int> mp;
  rep(i, n) mp[a[i]]++;
  multiset<int> mst;
  for (auto i : mp)
    mst.insert(i.second);
  int ans = 0;
  while (mst.size() > k)
    ans += *mst.begin(), mst.erase(mst.begin());
  cout << ans << endl;
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}

const LL N=1e6+5;
struct NODE{
	LL i,r,c,num;
}tt,ss;
LL t,n,m,q,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;
map<LL,LL> ma;
LL a[55],dp[55][2555];

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v,tmp;
	cin>>n>>m;
//	repu(i,1,n){
//		cin>>a[i];
//	}
	
	for(i=1;i<=n;i++){
		cin>>a[i];
		for(j=i+1;j;j--){
			for(k=0;k<=2500;k++){
				dp[j][k+a[i]]+=dp[j-1][k];
			}
		}
		dp[1][a[i]]++;
	}
//	for(i=1;i<=n;i++){
//		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
//				if(dp[i][j][k]&&k==m*j)ans++;
				ans+=dp[k][k*m]; 
			}
//		}
//	}
		
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919

int N, K, MOD;
int dp[301][301];
int dp2[301][301];
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> K >> MOD;
  rep(n, 301) {
    dp[n][0] = 1;
    rep(i, n+1) rep(cur, 300) add(dp[n][cur+1], (1LL*dp[n][cur]*(i+1))%MOD);
  }
  dp2[0][0] = 1;
  rep(k, K) {
    rep(cur, N+1) rep(n, N+1) if (cur+n <= N) add(dp2[k+1][cur+n], (1LL*dp2[k][cur]*dp[cur][n])%MOD);
  }
  cout << dp2[K][N] << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
const int N = 1e5;
#define min(x,y) (x<y)?x:y
ll n,k,m,res;
int main()
{
  cin>>n>>k;
  if(n==0)res=0;
  else if(n>=k)
  {
    res=n%k;
    res=min(res,fabs(res-k));
  }
  else res=min(n,k-n);
  cout<<res<<endl;
}


Measured memory_bytes: 256
//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int mod = 1e9+7;

signed main()
{
    fast;
    int h , w;
    cin >> h >> w;
    char c[h+1][w+1];
    for(int i=1 ; i<=h ; i++ )
        for(int j=1 ; j<=w ; j++ )
            cin >> c[i][j];
        
    int dp[h+1][w+1] ;
    memset( dp,0,sizeof(dp) );
    dp[1][1] = 1;
    
    int dx[] = {0,-1};
    int dy[] = {-1,0};
    
    for(int i=1 ; i<=h ; i++ )
    {
        for(int j=1 ; j<=w ; j++ )
        {
            if( c[i][j] == '.' )
            {
                for(int k=0 ; k<2 ; k++ )
                    dp[i][j] += dp[i+dx[k]][j+dy[k]];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[h][w] ;
}





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

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N+1), y(M+1);
  for(int i=0; i<N; i++){
    cin >> x.at(i);
  }
  for(int i=0; i<M; i++){
    cin >> y.at(i);
  }
  x.at(N)=X;
  y.at(M)=Y;
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  if(x.at(N)<y.at(0)){
    cout << "No War" << endl;
  }
  else{
    cout << "War" << endl;
  }
}


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

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    int ac[a], bc[b];
    for (int i = 0; i < a; i++) cin >> ac[i];
    for (int i = 0; i < b; i++) cin >> bc[i];
    int x[m], y[m], c[m];
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i] >> c[i];
        x[i]--;
        y[i]--;
    }

    int acmin = 1000000, bcmin = 1000000;
    for (int i = 0; i < a; i++) {
        acmin = min(acmin, ac[i]);
    }
    for (int i = 0; i < b; i++) {
        bcmin = min(bcmin, bc[i]);
    }

    int ans = acmin + bcmin;

    for (int i = 0; i < m; i++) {
        ans = min(ans, ac[x[i]] + bc[y[i]] - c[i]);
    }

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

Measured memory_bytes: 2176
#include <cstdio>
#include <queue>
#include <algorithm>

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

using namespace std;

typedef pair<int, int> P;

const int inf = (int)1e9;

struct E{
	E(int t, int c) :
		t(t), c(c)
	{}

	int t, c;
};

int n, m, s;
vector<E> g[(int)1e5];
int d[(int)1e5];

int main(){
	scanf("%d%d%d", &n, &m, &s);
	rep(i, m){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		g[a].push_back(E(b, c));
	}

	fill(d, d + n, inf);

	priority_queue<P, vector<P>, greater<P> > q;
	d[s] = 0;
	q.push(P(0, s));
	while(!q.empty()){
		P v = q.top();
		q.pop();

		if(v.first > d[v.second]){
			continue;
		}

		rep(i, g[v.second].size()){
			E e = g[v.second][i];
			if(d[e.t] > d[v.second] + e.c){
				d[e.t] = d[v.second] + e.c;
				q.push(P(d[e.t], e.t));
			}
		}
	}

	rep(i, n){
		if(d[i] != inf){
			printf("%d\n", d[i]);
		}
		else{
			puts("INF");
		}
	}
	return 0;
}

Measured memory_bytes: 11164
#include<iostream>
using namespace std;
int main(){
  int a;
  double b,total=0;
  string z;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b>>z;
    if(z=="JPY") total+=b;
    else total+=(b*380000.0);
  }
  cout << total<< endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,x;
  cin >> n >> x;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  sort(a.rbegin(),a.rend());
  mat dp(n,vec(x+1,0));
  for(ll i=0;i<=x;i++)  dp[n-1][i]=i%a[n-1];
  for(ll i=n-2;i>=0;i--) {
    for(ll j=0;j<x+1;j++) {
      dp[i][j]=(dp[i+1][j%a[i]]+(n-i-1)*dp[i+1][j]%mod)%mod;
    }
  }
  cout << dp[0][x] << endl;
}

Measured memory_bytes: 160860
k = int(input())
def gcd2(a,b):
    if b ==0:
        return a
    else:
        return gcd2(b, a%b)
    
def gcd3(a,b,c):
    d = gcd2(a,b)
    return gcd2(d,c)

total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for h in range(1,k+1):
            total += gcd3(i,j,h)
print(total)

Measured memory_bytes: 81488
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String O = sc.next();
    String E = sc.next();
    String ans = "";
    for (int i=0; i<E.length(); i++) {
      ans += O.charAt(i);
      ans += E.charAt(i);
    }
    if (O.length() > E.length()) ans += O.charAt(O.length() - 1); 
    System.out.println(ans);
  }
}

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

using namespace std;

const double pi = acos(-1.0);

struct Point{
    double x, y;
    Point(double x = 0.0, double y = 0.0): x(x), y(y) {}
};

void koch(int n, Point p1, Point p2) {
    if (n == 0) return;

    Point s, t, u;
    double rad = pi / 3.0;
    s.x = (2 * p1.x + p2.x) / 3.0;
    s.y = (2 * p1.y + p2.y) / 3.0;
    t.x = (p1.x + 2 * p2.x) / 3.0;
    t.y = (p1.y + 2 * p2.y) / 3.0;
    u.x = (t.x - s.x) * cos(rad) - (t.y - s.y) * sin(rad) + s.x;
    u.y = (t.x - s.x) * sin(rad) + (t.y - s.y) * cos(rad) + s.y;

    koch(n - 1, p1, s);
    printf("%.10f %.10f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.10f %.10f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.10f %.10f\n", t.x, t.y);    
    koch(n - 1, t, p2);
}

int main(void) {
    int n;
    Point p1(0.0, 0.0), p2(100.0, 0.0);

    cin >> n;
    printf("%.10f %.10f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%.10f %.10f\n", p2.x, p2.y);    

    return 0;    
}


Measured memory_bytes: 3228
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;


	public static void main(String[] args) {

		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		int n = sc.nextInt();
		int k = sc.nextInt();


		//-------------------------------------------------------------------------------------

		if(k >= n) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}

		//-------------------------------------------------------------------------------------

//		for(int i = 0; i < n; i++) {
//			System.out.println(ans[i]);
//		}

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

//		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 35776
n = int(input())
s = input()
d1 = set()
d2 = set()
d3 = set()
for c in s:
    for t in d2:
        d3.add(t + c)
    for t in d1:
        d2.add(t + c)
    d1.add(c)
print(len(d3))


Measured memory_bytes: 3188
#include <stdio.h>
int n, a[100100], m;
int abs(int x)
{
	return x > 0 ? x : -x;
}
int main(void)
{
	scanf("%d", &n);
	for (int i = 1; i <= n+1; i++)
	{
		if(i<=n)scanf("%d", &a[i]);
		m += abs(a[i] - a[i - 1]);
	}
	for (int i = 1; i <= n; i++)
	{
		printf("%d\n", m - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]));
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

vector<int> a;

int cost(int k){
    int ret = 0;
    for(int i : a){
        ret += (k - i) * (k - i);
    }

    return ret;
}

int main() {
    int n;
    cin >> n;
    a = vector<int>(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    cout << min(cost(sum / n), cost(sum / n + 1)) << endl;
}

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

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

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



int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    rp(i, 0, n){
        scanf("%d", &a.at(i));
    }
    int max = *max_element(a.begin(), a.end());
    int maxin = max_element(a.begin(), a.end()) - a.begin();
    a.at(maxin) = -1;
    int second = *max_element(a.begin(), a.end());
    rp(i, 0, n) {
        if(i == maxin) printf("%d\n", second);
        else printf("%d\n", max);
    }
    return 0;
}


Measured memory_bytes: 2432
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

inline void up(int &x,const int &y){if(x<y)x=y;}
const int maxn = 510000;

int n;
char str[maxn];

int f[maxn][3],g[maxn];
int solve(const int l,const int r)
{
	f[l-1][2]=0; g[l-1]=0;
	for(int i=l;i<=r;i++)
	{
		int gg=g[i-1]; up(g[i-1],f[i][2]);
		if(str[i]=='0')
		{
			up(f[i][1],f[i-1][0]);
			up(f[i][2],max(f[i-1][1],f[i-1][2]));
		}
		else
		{
			int j=i+1; for(;j<=r&&str[j]=='1';j++);j--;
			if(j!=i)
			{
				up(f[j][0],max(g[i-1],f[i-1][1]+j-i));
				up(f[j][1],f[i-1][1]+j-i+1);
				up(f[j][2],g[i-1]);
				if(j!=r) up(f[j+2][2],max(gg+j-i+1,g[i-1]+j-i));
				i=j;
			}
			else
			{
				up(f[i][0],gg);
				up(f[i][1],f[i-1][1]+1);
				up(f[i][2],g[i-1]);
			}
		}
		for(int j=0;j<3;j++) up(g[i],f[i][j]);
	}
	return max(g[r],0);
}

int main()
{
	scanf("%d",&n); scanf("%s",str+1);
	for(int i=0;i<=n;i++) for(int j=0;j<3;j++) f[i][j]=-inf;
	
	int ans=0;
	for(int i=1;i<=n;i++) if(str[i]=='1')
	{
		int j=i+1;
		for(int las=i;j<=n;j++)
		{
			if(str[j]=='1') las=j;
			if(j-las>=2) break;
		}j--;
		for(;str[j]=='0';j--);
		ans+=solve(i,j); i=j;
	}
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int INF = 1e18;
vvi G(100050);
vvi dis(100050, vi(3, INF));

void dfs(int now, int cost) {
    int t = (cost+1)%3;
    rep(i, G[now].size()) {
        if(dis[G[now][i]][t]>cost+1) {
            dis[G[now][i]][t] = cost+1;
            dfs(G[now][i], cost+1);
        }
    }
}

void dijkstra(int s) {
    priority_queue<P, V(P), greater<P>> q;
    q.push(P(0, s));

    while(!q.empty()) {
        P p = q.top();
        q.pop();
        int t = (p.fi+1)%3;
        rep(i, G[p.se].size()) {
            if(dis[G[p.se][i]][t] > p.fi+1) {
                dis[G[p.se][i]][t] = p.fi+1;
                q.push(P(p.fi+1, G[p.se][i]));
            }
        }
    }

}


signed main() {
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].pb(v);
    }
    int S, T;
    cin >> S >> T;
    S--; T--;
    dis[S][0] = 0;

    //dfs(S, 0);
    dijkstra(S);

    if(dis[T][0]!=INF) cout << dis[T][0]/3 << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 11392
h,w = map(int,input().split())
s = [input() for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            st = 0
            if i != 0:
                if s[i-1][j] == "#":
                    st = 1
            if j != 0:
                if s[i][j-1] == "#":
                    st = 1
            if i != h-1:
                if s[i+1][j] == "#":
                    st = 1
            if j != w-1:
                if s[i][j+1] == "#":
                    st = 1
            if st == 0:
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

void trace(int* A, int n)
{
    cout << A[0];
    for(int i=1; i < n; i++)
    {
        cout << " " << A[i];
    }
    cout << endl;

    return;
}

int insertionSort(int A[], int n, int g)
{
    int cnt = 0;

    for(int i = g; i < n; i++)
    {
        int v = A[i];
        int j = i - g;

        while(j >= 0 && A[j] > v)
        {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }

    return cnt;
}

int shellSort(int A[], int n)
{
    int cnt = 0;
    int m = 1;
    int G[100];

    G[0] = 1;
    for(int i = 1; i < 100; i++)
    {
        if(3 * G[i-1] + 1 > n)
            break;
        G[i] = 3 * G[i-1] + 1;
        m++;
    }

    cout << m << endl;
    cout << G[m-1];
    for(int i = m-2; i >= 0; i--)
        cout << " " << G[i];
    cout << endl;

    for(int i = m-1; i >= 0; i--)
    {
        cnt += insertionSort(A, n, G[i]);
    }

    return cnt;
}

int main(void)
{
    int n;
    int A[1000000];

    cin >> n;
    for(int i=0; i < n; i++) cin >> A[i];

    cout << shellSort(A, n) << endl;
    for(int i = 0; i < n; i++)
        cout << A[i] << endl;

    return 0;
}

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int n=sz(s);
  int ans[n];
  rep(i,n) ans[i]=0;

  for(int i=0; i<n-1; i++){
    if(s[i]=='R' && s[i+1]=='L'){
      int l=i-1,r=i+2;
      int cntr=0,cntl=0;
      //RLの左側でRが続く個数
      while(s[l]=='R' && l>=0){
        l--;
        cntr++;
      }

      while(s[r]=='L' && r<n){
        r++;
        cntl++;
      }
      ans[i]=1+cntr/2+cntl-cntl/2;
      ans[i+1]=1+cntl/2+cntr-cntr/2;
    }
  }
  rep(i,n) cout << ans[i] << " ";
  cout  << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
int main(void){
	int a, b, c, d;
	int n, count;
	while(scanf("%d", &n) != EOF){
		count = 0;
		for(a = 0; a < 10; a++){
			for(b = 0; b < 10; b++){
				for(c = 0; c < 10; c++){
					for(d = 0; d < 10; d++){
						if(n == a + b + c + d) count++;
					}
				}
			}
		}
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 596
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = double.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        double ans = 2 * n * Math.PI;
        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27468
#include <iostream>
#include <map>

using namespace std;

int check(int x){
	for(int i=1;i*i<=x;i++){
		if(i * i == x) return i;
	}
	return -1;
}

pair<int, int> calc(int d, int s){
	for(int i=s+1;i*i<d;i++){
		int t = check(d - i*i);
		if(t != -1 && i < t){
			return make_pair(i, t);
		}
	}
	return make_pair(-1, -1);
}

int main(){
	int h, w;
	while(cin >> h >> w && (h|w)){
		int d = h * h + w * w;
		pair<int, int> ans = calc(d, h);
		for(int i=1;ans.first==-1;i++) ans = calc(d+i, 0);
		cout << ans.first << ' ' << ans.second << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	int h,w;
	cin>>h>>w;
	vector<vector<LL>> ans=vector<vector<LL>>(h+1,vector<LL>(w+1,0));
	vector<vector<LL>> b=vector<vector<LL>>(h+1,vector<LL>(w+1,0));
	FOR(i,0,h){
		string s;
		cin>>s;
		FOR(j,0,w){
			if(s[j]=='.')b[i][j]=1;
		}
	}
	ans[0][0]=1;
	FOR(i,0,h){
		FOR(j,0,w){
			if(b[i][j]){
				ans[i+1][j]=add(ans[i+1][j],ans[i][j]);
				ans[i][j+1]=add(ans[i][j+1],ans[i][j]);
			}
		}
	}
	cout<<ans[h-1][w-1]<<endl;
    return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  ll N,M;
  cin>>N>>M;
  vector<vector<ll>> AB;
  FORi(N){
    vector<ll> tm(2);
    cin>>tm[0]>>tm[1]; 
    AB.push_back(tm);
  }
  sort(AB.begin(),AB.end(),[](vector<ll> a,vector<ll> b){
    return a[0]<b[0];
  });
  ll numdri=0;
  ll money=0;
  FORi(N){
    if(numdri+AB[i][1]<M){
      numdri+=AB[i][1];
      money+=AB[i][0]*AB[i][1];
    }else{
      ll less_ =M-numdri;
      money+=AB[i][0]*less_;
      break;
    }
  }
  cout<<money<<endl;
  
  return 0;
}

Measured memory_bytes: 6708
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  string s;
  cin >> s;
  bool ok = false;
  REP(i,s.size()){
    if(s[i]=='7'){ ok = true; break;}
  }
  
  cout << (ok?Liny:Linn) <<"\n";
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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 MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


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

    
    int N, M;
    cin >> N >> M;
    priority_queue<ll> Q;
    for(int i = 0; i < N; i++){
        ll A;
        cin >> A;
        Q.push(A);
    }
    for(int i = 0; i < M; i++){
        Q.push(Q.top()/2);
        Q.pop();
    }
    ull sum = 0;
    for(int i = 0; i < N; i++){
        sum += Q.top();
        Q.pop();
    }
    cout << sum << endl;
}


Measured memory_bytes: 4216
M, D= map(int, input().split())

ans = 0
for m in range(1, M+1):
    for d in range(22, D+1):
        s = str(d)
        if int(s[0])<2 or int(s[1])<2: continue
        if int(s[0])*int(s[1])==m:
            ans += 1

print(ans)


Measured memory_bytes: 39408
h,w,m=map(int,input().split())

cx=[0]*w
cy=[0]*h
xy=set()
for _ in range(m):
    y,x=map(int,input().split())
    x,y=x-1,y-1
    cx[x]+=1
    cy[y]+=1
    xy.add((x,y))

xmx=max(cx)
ymx=max(cy)
xs=[x for x in range(w) if cx[x]==xmx]
ys=[y for y in range(h) if cy[y]==ymx]

ans=xmx+ymx-1
ok=False
for y in ys:
    for x in xs:
        if (x,y) not in xy:
            ans+=1
            ok=True
            break
    if ok:
        break

print(ans)


Measured memory_bytes: 176740
Array.prototype.aggregate = function(){
 	return this.reduce((a,b)=>(a[b]=(a[b]||0)+1)&&a,{});
 }

function Main(input){
input = input.split("\n");
	var N = input.shift();
  N = ~~N;
  var W = input;
  
  for(var i = 1; i < N; i++){
  	var shiri = W[i-1];
    shiri = shiri[shiri.length-1];
    var atama = W[i];
    atama = atama[0];
    if(shiri !== atama)return "No";
  }
  
  var WW = W.aggregate();
  
  for(var i in WW){
  	if(WW[i]!=1)return "No";
  }
  
  return "Yes";
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
8
ba
aa
aaaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa
`);

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    ll ans = 0;
    int tall = -1;

    rep(i,n){
        if(a[i]<tall)ans += tall - a[i];
        else tall = a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4372
(defn input []
  (->> (.split #"\s" (read-line))
    (map #(Integer/parseInt %))))

(defn SmallAndLargeInteger [[A B K]]
  (->>  (concat 
          (take K (range A (inc B))) 
          (take K 
            (take-while #(<= A %) 
              (iterate dec B))))
    (apply sorted-set)
    (map println-str)
    (apply str)))

(->> (input)
  SmallAndLargeInteger
  print)

Measured memory_bytes: 67996