akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long

int main(){
    string s; cin >> s; int n = s.size(); int ans = 1e7;
    rep(i, n-1){
        if(s[i] != s[i+1]) ans = min(ans, max(i+1, n-i-1));
    }
    if(ans == 1e7) ans = n;
    cout << ans << endl;
}

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

int n,k,a[100001],dp[100001];

int cal(int idx)
{
    if (idx==n) return 0;
    if (idx>n) return 1e9;
    if (dp[idx]!=-1) return dp[idx];
    dp[idx]=1e9;

    for (int i=idx+1;i<=idx+k;i++) dp[idx]=min(dp[idx], cal(i)+abs(a[idx]-a[i]));
    return dp[idx];
}

int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++) dp[i]=-1;
    cout<<cal(1);
}


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

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	
	int ans = 0;
	while(n>0) {
		n/=k;
		ans++;
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define INF 1.0e9
using namespace std;
typedef long long ll;

string n;

int main() {
    cin >> n;
    for (int i =0; i < 3; i++) {
        if (n[i] == '1') n[i] = '9';
        else if (n[i] == '9') n[i] = '1';
    }
    cout << n << endl;
    return 0;
}

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

int a[3];
int main(){
    for(int i=0;i<3;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+3);
    printf("%d\n", a[2] - a[1] + (a[1]-a[0])/2 + ((a[1]-a[0])%2 ? 2 : 0));
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int x, y;
   cin >> x >> y;
   if (x == 2) x = 2;
   else if (x == 4 || x == 6 || x == 9 || x == 11) x = 0;
   else x = 1;
   if (y == 2) y = 2;
   else if (y == 4 || y == 6 || y == 9 || y == 11) y = 0;
   else y = 1;

   if (x == y) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[])
{
    int N, K;
    scanf("%d%d", &N, &K);
    ll v[N];
    REP(i, N)
    {
        scanf("%lld", &v[i]);
    }

    ll ans = 0;
    // 左からn個, 右からm個, 戻すのはl個
    REP(n, K + 1) REP(m, K - n + 1) REP(l, K - n - m + 1)
    {
        if (n + m > N) continue;
        if (n + m < l) continue;
        vector<ll> itm;
        REP(i,n)
            itm.PB(v[i]);
        REP(i,m)
            itm.PB(v[N-1-i]);
        sort(ALL(itm));
        ll sum = accumulate(ALL(itm),0);
        ll minus = 0;
        REP(i,l)
            minus -= itm[i];
        sum += minus;
        if (ans < sum)
            ans = sum;
    }

    printf("%lld\n", ans);
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> cnt(n + 1, 0);
    int now = - 1;
    int tmp = 0;
    for (int i = 0; i < n; i++){
        if (a[i] != now){
            now = a[i];
            tmp = 1;
        }
        else tmp++;
        cnt[tmp]++;
    }
    vector<int> acc(n + 1, 0);
    for (int i = 1; i <= n; i++) acc[i] = acc[i - 1] + cnt[i];
    int ok = n; vector<int> ans(n);
    for (int i = 1; i <= n; i++){
        while(acc[ok] < (long long)ok * i) ok--;
        ans[i - 1] = ok;
    }
    for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
}


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

int main(){
    string s; cin >> s;
    if(s[2] != s[3]){
        cout << "No" << endl;
        return 0;
    }
    if(s[4] != s[5]){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("03", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i,n) for(i=0;i<n;i++)
#define FORn(i,j,n) for(i=j;i<n;i++)
#define pb push_back
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define vli vector<lli>
#define vi vector<int>
#define vs vector<string>
#define vprint(v) for(auto t:v)cout<<t<<" "
#define endl "\n"

typedef long long int lli;
typedef long int li;

const lli mod=1000000007;
const lli limit=1000000;

using namespace std;

void fc(lli &x)
    {
        bool neg=false;
        register char c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

int main() {

    fast()
    lli n,q,t;
    lli temp,temp1,temp2,temp3;
    lli i,j,k;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

 
}

Measured memory_bytes: 256
#include <stdio.h>
#pragma warning(disable:4996)

int main(void)
{
	int N, K, i;
	long long int count = 1;
	scanf("%d%d", &N, &K);
	for (i = 0; i < N; i++) {
		if (i > 0)count *= (K - 1);
		else count *= K;
	}
	printf("%lld\n", count);
	return 0;
}

Measured memory_bytes: 128
# N = gets.chomp.to_i
A, B, C, D = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

def main(a, b, c, d)
  
while (a > 0 && c > 0) 
  c -= b
  if (c <= 0) 
    print "Yes\n"
    return
  end
  a -= d
  if (a <= 0) 
    print "No\n"
    return
  end
end
end

main(A, B, C, D)

Measured memory_bytes: 14268
r,c = gets.split.map(&:to_i)
sum = Array.new(c,0)
while line = gets
    ans = line.split.map(&:to_i)
    ans.each_with_index do |n , i|
        print "#{n} "
        sum[i] += n 
    end
    puts ans.inject(:+)
end

sum.each do |n|
    print "#{n} "
end
puts sum.inject(:+)


Measured memory_bytes: 6880
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a.begin(), a.end());
    cout << a.back() - a[0] << endl;

    return 0;
}

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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

ll cross(point a, point b) { return imag(conj(a) * b); }

int qua(point x)
{
	if (x.real() > 0 && x.imag() >= 0) return 0;
	if (x.real() <= 0 && x.imag() > 0) return 1;
	if (x.real() < 0 && x.imag() <= 0) return 2;
	return 3;
}

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

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

	ll ans = 0;
	sort(v.begin(), v.end(), [](const point &x, const point &y)
	{
		int qx = qua(x);
		int qy = qua(y);
		if (qx != qy) return qx < qy;
		if (cross(x, y) == 0) return norm(x) < norm(y);
		return cross(x, y) > 0;
	});

	for (int i = 0; i < n; ++i)
	{
		point p = { 0, 0 };
		for (int j = i, k = n; k--; j = (j+1) % n)
		{
			p += v[j];
			ans = max(ans, norm(p));
		}
	}
	cout << setprecision(20) << fixed << sqrtl(ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long chmin(long A, long B){
	if(A>B)return B;
	else return A;
	return -1;
}
int main(){
	long i,j,k;
	long N,max,s,a;
	scanf("%ld",&N);
	max = N;
	for(i=1;i*i<=N;i++){
		s = N/i;
		a = N%i;
		if(a==0){
			max = chmin(max,s+i-2);
		}
	}
	printf("%ld\n",max);
	
  return 0;

}


Measured memory_bytes: 128
/* ファイル名：ITP1_3_D.c	*/
/* 内容：３つの整数 a、b、c を読み込み、a から b までの整数の中に、c の約数がいくつあるかを求める	*/

/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:３つの整数 a、b、c を読み込み、a から b までの整数の中に、c の約数がいくつあるかを求める	*/
int main( void )
{
	/* 内部変数定義	*/
	int a;		/* 入力される変数a		*/
	int b;		/* 入力される変数b		*/
	int c;		/* 入力される変数c		*/
	int i;		/* ループ用変数			*/
	int cnt;	/* 約数のカウント変数	*/
	
	cnt = 0;	/* カウント変数の初期化	*/
	
	scanf("%d %d %d",&a,&b,&c);	/* a、b、c を取得	*/
	
	/* a から b までループ	*/
	for(i = a; i <= b; i++){
		if((c % i) == 0){	/* 約数だった場合	*/
			cnt++;			/* カウントする		*/
		}
		else{
			/* 処理なし	*/
		}
	}
	
	printf("%d\n",cnt);/* 結果の出力	*/
	
	return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define int long long

int n,k;
int t[100010];

int check(int m){
  int ret = 0;
  for(int i = 0; i < k; i++){
    int sum = 0;
    while(sum + t[ret] <= m){
      sum += t[ret];
      ret++;
      if(ret == n) return n;
    }
  }
  return ret;
}

signed main(){

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

  int left = 0,right = 1e9+10;
  while(left + 1 < right){
    int mid = (left+right)/2;
    if(check(mid) >= n) right = mid;
    else left = mid;
    //cout << left << " " << right << endl;
  }

  cout << right << endl;

  return 0;
}



Measured memory_bytes: 3904
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 1 && b % 2 == 1) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

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

int A, B;

int main () {
  cin >> A >> B;

  int M = (A+B)/2;
  if(abs(A-M) == abs(B-M)) {
    cout << M << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


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

void stack(char parts[],int n){
	char *temp;
	int i=-1;
	temp = (char *)calloc(n+1,sizeof(char));temp[n]=0;
	strcpy(temp,parts);
	while(1){
		i++;
		parts[i]=temp[n-i-1];
		if(n-i-1 == 0)
			break;
	
	}
}
void assemble(char line[],char finish[],int pattern,int start,int len){
	char *parts1,*parts2;
	parts1=(char *)calloc(len+1,sizeof(char));
	parts2=(char *)calloc(len+1,sizeof(char));
	parts1[start]=0;parts2[len-start]=0;
	int i,o;
	for(i=0;i<start;i++)
		parts1[i]=line[i];
	o=i;
	for(i=0;i<len-start;i++){
		parts2[i]=line[o];
		o++;
	}
	if(pattern == 2){
		strcat(parts2,parts1);
		strcpy(finish,parts2);
	}
	if(pattern == 3 || pattern == 4){
		stack(parts1,start);
		if(pattern == 3){
			strcat(parts1,parts2);
			strcpy(finish,parts1);
		}
		else{
			strcat(parts2,parts1);
			strcpy(finish,parts2);
		}
	}
	if(pattern == 5 || pattern == 6){
		stack(parts2,len-start);
		if(pattern == 5){
			strcat(parts1,parts2);
			strcpy(finish,parts1);
		}
		else{
			strcat(parts2,parts1);
			strcpy(finish,parts2);
		}
	}
	if(pattern == 7 || pattern == 8){
		stack(parts1,start);
		stack(parts2,len-start);
		if(pattern == 7){
			strcat(parts1,parts2);
			strcpy(finish,parts1);
		}
		else{
			strcat(parts2,parts1);
			strcpy(finish,parts2);
		}
	}
}
int main(void){
	int n;
	scanf("%d",&n);
	char line[73];char finish[73];char memo[500][73];
	while(n){
	int len,i,o,p=0,sum=1,sign=0,t=0;
	scanf("%s",line);
	strcpy(memo[0],line);
	len=strlen(line);
	for(i=1;i<=len-1;i++){
		for(o=2;o<=8;o++){
			assemble(line,finish,o,i,len);
			sign=0;
			for(t=0;t<=p;t++){
				if(strcmp(finish,memo[t]) ==0){
					sign=1;
					break;
				}
			}
			if(sign == 0){
				p++;
				strcpy(memo[p],finish);
				sum++;
			}
		}
	}
	printf("%d\n",sum);
	n--;
	}
	return 0;
}

Measured memory_bytes: 12472
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
int h,w;
  cin>>h>>w;
  int ans;
  if(h==1 || w==1)
  {
  	ans=1;
  }
  else
  {
  int z=h*w;
  if(z%2==0)
  {
    ans=z/2;
  }
  else
  {
    ans=z/2+1;
  }
}
  cout<<ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int main()
{
int x;
scanf("%d",&x);
if(x>=30){printf("Yes");}
else{printf("No");}

}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    ll n;
    cin >> n;
    ll ans = n - 1;
    for (ll i = 2;i*i <= n;i++){
        if(n%i==0){
            ll tmp = (i - 1) + (n / i - 1);
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#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)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int f(int i){
  int res=0;

  return res;
}

int main()
{
  int n; cin >> n;
  int sum = 0;
  int n2 = n;
  while(n>0){
    sum += n % 10;
    n /= 10;
  }
  if(n2 % sum == 0) printf("Yes");
  else printf("No");
}

Measured memory_bytes: 256
#include <stdio.h>

int checkHit(char have[], char hit[]){
	int i;
	for(i = 0; i < 9; i++){
		if(hit[i] != '*' && hit[i] != have[i]){
			return 0;
		}
	}
	return 1;
}

int main(void){
	int n,m,i,j;
	int money;
	char hitnum[100][9];
	int g[100];
	char havenum[9];
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0){break;}
		money = 0;
		for(i = 0; i < n; i++){
			scanf("%s%d",hitnum[i],&g[i]);
		}
		for(i = 0; i < m; i++){
			scanf("%s",havenum);
			for(j = 0; j < n; j++){
				if(checkHit(havenum,hitnum[j])){
					money += g[j];	
					break;
				}
			}
		}
		printf("%d\n",money);
	}

	return 0;
}

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

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1<<30;
const ll MOD = 1e9 + 7;

int main(){
	int n;
	string s;
	vector<int> r, g, b;
	ll ans = 0;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i] == 'R')
			r.pb(i);
		else if(s[i] == 'G')
			g.pb(i);
		else
			b.pb(i);
	}

	for(int i=0;i<r.size();i++){
		for(int j=0;j<g.size();j++){
			ans += b.size();
		}
	}
	for(int gap=0;gap<=n;gap++){
		for(int strt=0;strt+2*gap<n;strt++){
			if(s[strt] == 'R' && s[strt+gap] == 'G' && s[strt+2*gap] == 'B'){
				ans--;
			}
			if(s[strt] == 'R' && s[strt+gap] == 'B' && s[strt+2*gap] == 'G'){
				ans--;
			}
			if(s[strt] == 'G' && s[strt+gap] == 'R' && s[strt+2*gap] == 'B'){
				ans--;
			}
			if(s[strt] == 'G' && s[strt+gap] == 'B' && s[strt+2*gap] == 'R'){
				ans--;
			}
			if(s[strt] == 'B' && s[strt+gap] == 'R' && s[strt+2*gap] == 'G'){
				ans--;
			}
			if(s[strt] == 'B' && s[strt+gap] == 'G' && s[strt+2*gap] == 'R'){
				ans--;
			}
		}
	}

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N;
    if(N == 3){
        cout<<2<<' '<<5<<' '<<63<<endl;
    }else if(N <= 24){
        vec ans = {2,3,4,9};
        rep(i, N - 4) ans.push_back((i+1)*6);
        rep(i, ans.size()){
            cout<<ans[i];
            i == ans.size() - 1 ? cout<<endl : cout<<' ';
        }
    }else{
        ll num_6 = min(2500LL, N/6);
        vec ans(0);
        rep(i, num_6 * 2) rep(j, 3) ans.push_back(i*6 + j + 2);
        ll rest = N - ans.size();
        rep(i, rest) ans.push_back((i+1) * 6);
        rep(i, ans.size()){
            cout<<ans[i];
            i == ans.size() - 1 ? cout<<endl : cout<<' ';
        }
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    bool ok = true;
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        ok &= a & 1 || a % 3 == 0 || a % 5 == 0;
    }
    std::cout << (ok ? "APPROVED" : "DENIED") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int const maxn=2000;
double a[maxn];
int main(){
	int i,n;
	double tmp,ans=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>tmp;
		a[i]=1/tmp;
	}
	for(i=1;i<=n;i++) ans+=a[i];
	ans=1/ans;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 300005;
int bit[MAX_N+1];
int nn = MAX_N; //　1-index

void adds(int a, int w){
    for(int x = a; x <= nn; x += x & -x) bit[x] += w;
}
int sums(int a){ // bit[1,a]の和を返す.
    int ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x];  
    return ret;
}

queue<int> que[MAX_N];

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> v;
    rep(i,n){
        int l,r;
        cin >> l >> r;
        v.push_back(P(l,r));
    }
    sort(v.begin(), v.end());

    int ans[m+1] = {};
    int now = 0;
    srep(i,1,m+1){
        while(now < n && v[now].first == i){
            adds(i, 1);
            adds(v[now].second + 1, -1);
            now++;
        }
        ans[i] += sums(i) - sums(i+i);
        que[i+i].push(i);
        while(que[i].size() > 0){
            int x = que[i].front(); que[i].pop();
            ans[x] += sums(i) - sums(i+x);
            que[i+x].push(x);
        }
    }
    // srep(i,1,11)cout << sums(i);
    // cout << endl;
    srep(i,1,m+1)cout << ans[i] << endl;
    return 0;
}



Measured memory_bytes: 209136
#include<stdio.h>
#include<math.h>

typedef long long ll;

int main() {
	ll n, v[20], c[20],ans=0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &v[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%lld", &c[i]);
	}
	for (int i = 0; i < pow(2, n); i++) {
		ll sum=0;
		for (int mask = 0; mask < n; mask++) {
			if (i & (ll)pow(2, mask)) sum += v[mask]-c[mask];
		}
		ans = (ans < sum) ? sum : ans;
	}
	printf("%lld", ans);

	return 0;
}

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

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
int main()
{
    int x;
    cin>>x;

    cout<<x*x*x<<endl;
 
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll              long long 
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N=2e5+4;

int main()
{
    IOS
    ll n;
    cin>>n;
    ll ans[n];
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        ans[x-1]=i+1;
    }
    for(ll x:ans)
    cout<<x<<" ";
    
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
void DFS(void);
void DFS_Visit(int );
#define WHITE 0
#define BLACK 1
#define GRAY 2
#define MAX 101
int G[MAX][MAX];
int vertex[MAX],edge[MAX];
int color[MAX];
int time,n;
int d[MAX],f[MAX];  /*vの最初の時間、終了の時間*/
int main() 
{
 int i,j;
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
	scanf("%d%d",&vertex[i],&edge[i]);
	for(j=1;j<=edge[i];j++)
	{
		scanf("%d",&G[vertex[i]][j]);
	}
 }

 DFS();
 for(i=1;i<=n;i++) printf("%d %d %d\n",vertex[i],d[vertex[i]],f[vertex[i]]);
 return 0;
}

void DFS()
{
 int i;
 for(i=1;i<=n;i++) color[i] = WHITE;
 time = 0;
 for(i=1;i<=n;i++)
 {
	if(color[i] == WHITE) DFS_Visit(i);
 }
}

DFS_Visit (int u)
{
 int i,v;
 color[u] = GRAY;
 d[u] = ++time;
 for(i=1;i<=edge[u];i++)
 {
 	v = G[u][i];
	if(color[v] == WHITE ) DFS_Visit(v);
 }
 color[u] = BLACK;
 f[u] = ++time;
}

Measured memory_bytes: 636
// C - 白昼夢 / Daydream
#include <bits/stdc++.h>
using namespace std;

int main(){
	string s1="remaerd", s2="resare", s3="esare", s4="maerd";

	string S; cin>>S;
	reverse(S.begin(), S.end());

	string s;
	for(int i=0; i<S.size(); ++i){
		s += S[i];
		if(s==s1 || s==s2 || s==s3 || s==s4) s = "";
	}
	cout<< (s==""? "YES":"NO") <<endl;

}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const ll MOD = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N * 3);
    for (int i = 0; i < 3 * N; i++) {
        cin >> A[i];
    }
    priority_queue<int, vector<int>, greater<int>> first_half;
    priority_queue<int> second_half;
    vector<ll> diff(3 * N, -1e18);
    ll val = 0;
    for (int i = 0; i < 2 * N; i++) {
        if ((int)first_half.size() < N) {
            val += A[i];
            first_half.push(A[i]);
        } else {
            int top = first_half.top();
            if (top < A[i]) {
                val += A[i] - top;
                first_half.pop();
                first_half.push(A[i]);
            }
        }

        diff[i] = val;
    }
    val = 0;
    for (int i = 3 * N - 1; i >= N; i--) {
        if ((int)second_half.size() < N) {
            val += A[i];
            second_half.push(A[i]);
        } else {
            int top = second_half.top();
            if (top > A[i]) {
                val += A[i] - top;
                second_half.pop();
                second_half.push(A[i]);
            }
        }

        diff[i - 1] -= val;
    }
    ll ans = -1e18;
    for (int i = N - 1; i < 2 * N; i++) {
        ans = max(ans, diff[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4984
# Implement (union by size) + (path compression)
# Reference:
# Zvi Galil and Giuseppe F. Italiano,
# Data structures and algorithms for disjoint set union problems
class DSU():
    @classmethod
    def dsu(cls, n):
        return cls.InnerDSU(n)

    class InnerDSU():
        _n = 0
        # root node: -1 * component size
        # otherwise: parent
        parent_or_size = []

        def __init__(self, n=0):
            self._n = n
            self.parent_or_size = [-1] * n

        def merge(self, a, b):
            assert(0 <= a < self._n)
            assert(0 <= b < self._n)
            x = self.leader(a); y = self.leader(b)
            if x == y:
                return x
            if -self.parent_or_size[x] < -self.parent_or_size[y]:
                x,y = y,x
            self.parent_or_size[x] += self.parent_or_size[y];
            self.parent_or_size[y] = x;
            return x

        def same(self, a, b):
            assert(0 <= a < self._n)
            assert(0 <= b < self._n)
            return self.leader(a) == self.leader(b)

        def leader(self, a):
            assert(0 <= a < self._n)
            if self.parent_or_size[a] < 0:
                return a
            self.parent_or_size[a] = self.leader(self.parent_or_size[a])
            return self.parent_or_size[a]

        def size(self, a):
            assert(0 <= a < self._n)
            return -self.parent_or_size[self.leader(a)]

        def groups(self):
            leader_buf = [0] * self._n
            group_size = [0] * self._n
            for i in range(self._n):
                leader_buf[i] = self.leader(i)
                group_size[leader_buf[i]] += 1
            result = [[] for _ in range(self.n)]
            for i in range(self._n):
                result[leader_buf[i]].append(i)
            return [r for r in result if r]


N, Q = tuple(map(int, input().split()))
tuv = [tuple(map(int, input().split())) for _ in range(Q)]

dsu = DSU.dsu(N)
for t,u,v in tuv:
    if t == 0:
        dsu.merge(u, v)
    else:
        if dsu.same(u, v):
            print(1)
        else:
            print(0)


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

static const int inf = 1000;

struct node{
  int x;
  int y;
};



int hor[36][36] = {{}};
int vir[36][36] = {{}};
int d[36][36] ;
int h,w,a = 0,b;

void bfs(int r,int s){

  queue <node> q;
  node locate; 
  node u,t;

  locate.y = r;
  locate.x = s;

  // cout << "lx = " << locate.x << ' ' << "ly = " << locate.y << endl;

  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      d[i][j] = inf;
    }
  }

  q.push(locate);

  d[0][0] = 1;

  while(!q.empty()){
    u = q.front(); q.pop();
    a++;
    if(hor[u.y][u.x] != 1 && u.y < h - 1  && (d[u.y][u.x] + 1 < d[u.y + 1][u.x])){
      d[u.y + 1][u.x] = d[u.y][u.x] + 1;
      t.x = u.x;
      t.y = u.y + 1; 
      q.push(t);
     
    }
    if(vir[u.y][u.x] != 1 && u.x < w - 1 && (d[u.y][u.x] + 1 < d[u.y][u.x + 1])){
      d[u.y][u.x + 1] = d[u.y][u.x] + 1;
      t.y = u.y;
      t.x = u.x + 1;
      q.push(t);
    }

    if((hor[u.y - 1][u.x] != 1) &&( u.y > 0 )/*&& (d[u.y][u.x] + 1 <  d[u.y - 1][u.x]) && (( vir[u.y][u.x] == 1) ||( hor[u.y][u.x] == 1))*/){
      d[u.y - 1][u.x] = d[u.y][u.x] + 1;
      t.x = u.x;
      t.y = u.y - 1; 
      q.push(t);
     
    }

    if((vir[u.y][u.x - 1] != 1) &&( u.x > 0 ) && (d[u.y][u.x] + 1 < d[u.y][u.x - 1]) && (( vir[u.y][u.x] == 1) ||( hor[u.y][u.x] == 1))){
      d[u.y][u.x - 1] = d[u.y][u.x] + 1;
      t.y = u.y;
      t.x = u.x - 1;
      q.push(t);
    }

    //   cout << "x = " << u.x << ' ' << "y = " << u.y << endl;
   
  }
}


int main(){

  while(1){
    cin >> w >> h;

    // cout << " w = " << w << ' ' << "h = " << h << endl; 
    if(w == 0 && h == 0) break;

    for(int i = 0;i < h - 1;i++){
      for(int j = 0;j < w - 1;j++) cin >> vir[i][j];
      for(int j = 0;j < w ;j++) cin >> hor[i][j];
    }

    for(int j = 0;j < w - 1;j++) cin >> vir[h - 1][j];

   

    bfs(0,0);
    // cout << "a = " << a << endl;

    if(d[h - 1][w - 1] != 1000) cout  << d[h - 1][w - 1] << endl;
    else cout << '0' << endl;

    for(int i = 0;i < 36;i++){
      for(int j = 0;j < 36;j++){
	vir[i][j] = 0;
	hor[i][j] = 0;
	d[i][j] = 0;
      }
    }
    a = 0;
  }
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if (B % A == 0) cout << A + B << endl;
    else cout << B - A << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
public class C{
    public static void Main(){
        int n;
        n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        string[] aSt = Console.ReadLine().Split().ToArray();
        for (int i =0;i<n;i++){
            a[i] = int.Parse(aSt[i]);
        }
        int[] check = new int[9];
        for (int i= 0;i<n;i++){
            a[i]/=400;
            if (a[i]<=7){
            check[a[i]]=1;
            }
            else{
                check[8]++;
            }
        }
        int ansMin = 0;
        for (int i = 0;i<=7;i++){
            ansMin += check[i];
        }
        int ansMax = ansMin;
        if (ansMin==0 && check[8]>0){
            ansMin++;
        }
        ansMax+=check[8];

        Console.Write(ansMin);
        Console.Write(' ');
        Console.WriteLine(ansMax);
        
    }
}


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

int main(){
    string s = "abcdefghijklmnopqrstuvwxyz";
    char c; cin >> c;
    char ans;
    for(int index = 0; index <= s.size(); index++){
        if(c == s[index]){
            ans = s[index+1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int result = 0;
        for (int i = 0; i < n; i++) {
            if ((i+1)%2 != 0) {
                if (list[i]%2 != 0) result++;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 27200
//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	while (1) {
		int n, m;
		int mini = INF;

		cin >> n >> m;
		if (n == 0) {
			break;
		}
		vector<int> c(m + 1,0);
		vector<int> x(n + 1,0);
		vector< vector<int> > dp(n + 1, vector<int>(256, INF));

		FOR(i, 1, m) {
			cin >> c[i];
		}
		FOR(i, 1, n) {
			cin >> x[i];
		}

		dp[0][128] = 0;

		FOR(i, 1, n) {
			FOR(k, 0, 255) {
				FOR(j, 1, m) {
					//cout << i << " " << j << " " << k << endl;//1 3 128
					
					if (dp[i - 1][k] != INF) {
						int p;
						if (k + c[j] >= 255) {
							p = 255;
						}
						else if (k + c[j] <= 0) {
							p = 0;
						}
						else {
							p = k + c[j];
						}
						dp[i][p] = min(dp[i][p], dp[i - 1][k] + (abs(x[i] - p))*(abs(x[i] - p)));
					}

				}
			}
		}

		FOR(i, 0, 255) {
			//cout << i << " " << dp[n][i] << endl;
			if (dp[n][i] < mini) {
				mini = dp[n][i];
			}
		}
		
		cout << mini << endl;
	}
	return 0;
}


Measured memory_bytes: 23720
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s, t;
	cin >> s >> t;
	int n = s.length();
	int ans = 0;
	for (int i=0; i<n; i++) {
		if (s[i] != t[i]) ans++;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<int> cubic;
		for (int i = 1; i <= n; ++i)
		{
			cubic.push_back(i * i * i);
		}
		n = n * n * n;
		int minDiff = 1e9;
		for (int i = 0; i < cubic.size(); ++i)
		{
			for (int j = 0; j < cubic.size(); ++j)
			{
				int sum = cubic[i] + cubic[j];
				if (sum > n)
				{
					break;
				}
				minDiff = min(minDiff, n - sum);
			}
		}
		cout << minDiff << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
    int N;
    cin >> N;
    vector<int> T(N);
    rep(i, N)
    {
        cin >> T.at(i);
    }
    int M;
    cin >> M;
    vector<pair<int, int>> P(M);
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        P.at(i) = make_pair(a, b);
    }
    int result = 0;
    rep(i, N) result += T.at(i);
    rep(i, M)
    {
        pair<int, int> m = P.at(i);
        cout << result - T.at(m.first - 1) + m.second << endl;
    }
}


Measured memory_bytes: 256
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

class Node:
    def __init__(self):
        self.edge = []
        self.count = 0

def dfs(tree,node,p_node,p_count,counts):
    count = tree[node].count + p_count
    counts[node] = count
    for x in tree[node].edge:
        if x == p_node:
            continue
        dfs(tree,x,node,count,counts)

N,Q = inm()

tree = []
for _ in range(N):
    tree.append(Node())

#node = Node()
#tree = [node]*N

for _ in range(N-1):
    a,b = inm()
    tree[a-1].edge.append(b-1)
    tree[b-1].edge.append(a-1)

for _ in range(Q):
    p,x = inm()
    tree[p-1].count += x

val = []
for _ in range(N):
    val.append(0)

#for i in range(N):
#    print(tree[i].edge)
#    print(tree[i].count)

dfs(tree,0,-1,0,val)

counts_str = [str(n) for n in val]
s = " ".join(counts_str)
print(s)


Measured memory_bytes: 271928
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<a[i]<<c;
	cout<<"\n";
}

lli tmod(lli x,lli m){return (x%m+m)%m;}//USE AT YOUR OWN RISK
lli power(lli x, lli y) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;  
    }
    if(res<0)
       res+=mod; 
    return res; 
}
lli modInverse(lli a, lli m) 
{
    lli m0 = m; 
    lli y = 0, x = 1; 
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    {  
        lli q = a / m; 
        lli t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }  
    if (x < 0) 
       x += m0; 
    return x; 
} 
const int N=(1<<20);

int main() 
{ 
  fastio;
  int n,k;
  cin>>n>>k;
  int ans=0;
  while(n){
      ans++;
      n/=k;
  }
  cout<<ans<<"\n";
  return 0; 	
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
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; }
int N,i,ans;
vector<int> a;

inline void solve(){
  IN(N);
  a.resize(N);
  INS(i,N,a);
  sort(ALL(a));
  REP(i,N){
    chmax(ans,(int)(upper_bound(ALL(a),a[i]+2)-lower_bound(ALL(a),a[i])));
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 640
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, M, *T = map(int, read().split())

    counter = Counter()
    counter_h = [0] * H
    counter_w = [0] * W
    for h, w in zip(*[iter(T)] * 2):
        counter[(h - 1, w - 1)] += 1
        counter_h[h - 1] += 1
        counter_w[w - 1] += 1

    max_h = max(counter_h)
    max_w = max(counter_w)
    max_h_index = [False] * H
    max_w_index = [False] * W
    for i in range(H):
        if counter_h[i] == max_h:
            max_h_index[i] = True
    for j in range(W):
        if counter_w[j] == max_w:
            max_w_index[j] = True

    n = 0
    for h, w in zip(*[iter(T)] * 2):
        h -= 1
        w -= 1
        if max_h_index[h] and max_w_index[w]:
            n += 1

    if n == sum(max_h_index) * sum(max_w_index):
        ans = max_h + max_w - 1
    else:
        ans = max_h + max_w

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 182904
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

vvi to(2*1e5+7,vi());
vi ans;

void bfs(int x){
    queue<int> q; q.push(x);
    vector<int> dis(2*1e5+7,-1); dis[x] = 0;
    while(!q.empty()){
        int num = q.front(); q.pop();
        for(int i: to[num]){
            if(dis[i] != -1) continue;
            if(ans[i] == -1) ans[i] = num;
            q.push(i);
            dis[i] = dis[num]+1;
        }
    }
}

int main(){
    cout << fixed << setprecision(20);
    int n,m; cin >> n >> m;
    ans.resize(n,-1);
    rep(i,m){
        int x,y; cin >> x >> y;
        x--; y--;
        to[x].eb(y);
        to[y].eb(x);
    }
    bfs(0);
    yes();
    rng(i,1,n) cout << ans[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 13464
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    auto T = aryread();
    long M = lread();
    auto P = new long[](M);
    auto X = new long[](M);
    foreach (i; 0 .. M)
        scan(P[i], X[i]);
    long s = T.sum();
    foreach (i; 0 .. M)
    {
        writeln(s - T[P[i] - 1] + X[i]);
    }
}


Measured memory_bytes: 3628
N, K = map(int,input().split( ))
H =[]
for i in range(N):
	h = int(input())
	H.append(h)
ansl = []
H.sort()

for i in range(N - K + 1):
	#HK = H[i:i+K]
	#ans = max(HK)-min(HK)
	ans = H[i + K - 1] - H[i]
	ansl.append(ans)

print(min(ansl))


Measured memory_bytes: 11292
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
const ll LINF = 1e18;

ll gcd(ll a,ll b){ return b? gcd(b,a%b) : a;}
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll res = a[0];
  rep(i,n){
    res = gcd(res,a[i]);
  }
  cout << res <<endl;
}

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

using namespace std;
typedef long long ll;
string s;
int main(){
    ll sum=0;
    ll cnt_bc=0;
    ll cnt_a=0;
    cin >> s;
    for( ll i=s.length()-1; i>=0; i--){
        if( (s[i]=='C')&&(s[i-1]=='B') ){
            //cerr << "BC" << endl;
            sum += cnt_a*cnt_bc;
            cnt_a=0;
            cnt_bc++;
            i--;
        }else if( s[i]=='A'){
            if( cnt_bc>0) cnt_a++;
            //cerr << "A" << endl;
        }else{
            sum+=cnt_a*cnt_bc;
            cnt_a=0;
            cnt_bc=0;
        }
    }
    if (cnt_a>0) sum += cnt_a*cnt_bc;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list([int(x) for x in input().split()])

money = 1000
stock = 0

for i in range(N-1):
    if A[i] <= A[i+1]:
        stock += money // A[i]
        money -= (money // A[i]) * A[i]
    else:
        money += A[i] * stock
        stock = 0

print(money + stock * A[N-1])


Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
#define pii pair<int,int>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define inf 1e9
vector<string> v;
void solve(){
	int n;
	cin>>n;
	string a="";
	for(int i=1;i<=n;i++){
		a+='0'+i;
	}
	v.push_back(a);
	while(next_permutation(a.begin(), a.end())){
		v.push_back(a);
	}
	// for(auto i:v){
	// 	cout<<i<<endl;
	// }
	string s1="";
	for(int i=1;i<=n;i++){
		int temp;
		cin>>temp;
		s1+='0'+temp;
	}
	string s2="";
	for(int i=1;i<=n;i++){
		int temp;
		cin>>temp;
		s2+='0'+temp;
	}
	int pos1,pos2;
	for(int i=0;i<v.size();i++){
		if(v[i]==s1){
			pos1=i;
			break;
		}
	}
	for(int i=0;i<v.size();i++){
		if(v[i]==s2){
			pos2=i;
			break;
		}
	}
	cout<<abs(pos1-pos2)<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

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

int main(){
	int n;
	int i;
	string t[1000];
	string h[1000];
	int scoreT=0;
	int scoreH=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i]>>h[i];
		if (t[i]>h[i]){
			scoreT+=3;
		} else if(t[i]<h[i]){
			scoreH+=3;
		} else {
			scoreT++;
			scoreH++;
		}
	}
	cout << scoreT << " " << scoreH << endl;
	return 0;
}

Measured memory_bytes: 1316
n=int(input())
a=[int(x) for x in input().split()]

goukei=0

saidai=a[0]

for i in range(1,len(a)):
    if a[i]<saidai:
        goukei+=saidai-a[i]
    else:
        saidai=a[i]

print(goukei)

Measured memory_bytes: 94200
#include<bits/stdc++.h>
#define ll          long double
#define c(P)        cout<<P<<"\n"
using namespace std;
// Let f(i, j) be the probability of getting exactly i heads among the first j coins. 

// We have two possibilities for the j-th coin. 

// Case 1 - It is a heads. 

// The probability of getting a head is p[j]. 

// And we need to get exactly (i - 1) heads from the previous (j - 1) coins. 

// This is given by p[j] x f(i - 1, j - 1)

// Case 2 - It is tails

// The probability is given by (1 - p[j])

// We need i heads from the first j - 1 coins. 

// The probability is (1 - p[j]) x f(i, j - 1)

// The base case is that f(0, 0) = 1. 

// ------

// To get the answer we need to sum over all f(i, N) where i > N/2.

void solve()
{
 int n;
 cin>>n;

 std::vector<ll> prob_head(n+1);
 std::vector<vector<ll>> probability(n+1,std::vector<ll>(n+1));
  probability[0][0] = 1;
 for (int i = 1; i <= n; ++i)
 {
  cin>>prob_head[i];
//c(prob_head[i]);
 }
 for (int coin = 1; coin <= n; ++coin)
 {
   for(int i=0;i<=n;i++)
   {
      probability[i][coin] = (i>0? probability[i-1][coin-1]*(prob_head[coin]) : 0) + probability[i][coin-1]*(1-prob_head[coin]);

   }
 }
 ll ans =0;
for (int i = n/2+1; i <= n; ++i)
{
  ans +=probability[i][n];
}
cout<<setprecision(10)<<fixed<<ans<<"\n";
}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
       // c(T);
      solve();
      }
      return 0;
    }


Measured memory_bytes: 141056
from collections import Counter
n = int(input())
a_li = list(map(int,input().split()))
ans = sum(a_li)
a_counter = Counter(a_li)
q = int(input())
for i in range(q):
    a,b = map(int,input().split())
    dum = a_counter[a]
    ans -= dum*a
    ans += dum*b
    a_counter[a] = 0
    a_counter[b] += dum
    print(ans)


Measured memory_bytes: 87960
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int i,len,j,data[7],wk;
	char buf[101];
	for(i=1;i<=6;i++)	scanf("%d",&data[i]);
	scanf("%s",buf);
	len=strlen(buf);
	for(i=0;i<len;i++)	{
		if(buf[i]=='N')	{
			wk=data[1];
			data[1]=data[2];
			data[2]=data[6];
			data[6]=data[5];
			data[5]=wk;
		}
		if(buf[i]=='S')	{
			wk=data[1];
			data[1]=data[5];
			data[5]=data[6];
			data[6]=data[2];
			data[2]=wk;
		}
		if(buf[i]=='E')	{
			wk=data[1];
			data[1]=data[4];
			data[4]=data[6];
			data[6]=data[3];
			data[3]=wk;
		}
		if(buf[i]=='W')	{
			wk=data[1];
			data[1]=data[3];
			data[3]=data[6];
			data[6]=data[4];
			data[4]=wk;
		}
	}
	printf("%d\n",data[1]);
	return 0;
}


Measured memory_bytes: 1028