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


using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から
#define REP(i,N) for(int j=i;j<N;j++) //iから

typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+7 + 9)




//cout<<fixed<<setprecision(10);
int main(){
    int n;
    cin>>n;
    cout<<1-n<<endl;

    return 0;
}



Measured memory_bytes: 3628
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, z, w = map(int, readline().split())
    a = list(map(int, readline().split()))

    if n == 1:
        print(abs(a[0] - w))
    else:
        first = abs(a[-2] - a[-1])
        second = abs(a[-1] - w)
        print(max(first, second))


if __name__ == '__main__':
    main()


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

template<typename T>
T get() { return 0; }
template<>
int get() { int x; scanf("%d", &x); return x; }
template<>
long get() { long x; scanf("%ld", &x); return x; }
template<>
std::string get() { std::string str; std::cin >> str; return str; }

template<typename T>
void put(T x) {}
template<>
void put(int x) { printf("%d\n", x); }
template<>
void put(long x) { printf("%ld\n", x); }
template<>
void put(std::string str) { printf("%s\n", str.c_str()); }
template<>
void put(const char* str) { printf("%s\n", str); }

long n, l;
long a[112345];
long left;
long right;
long sum;

void load() {
  n = get<long>();
  l = get<long>();
  sum = 0;
  for(long i = 0; i < n; ++i) {
    a[i] = get<long>();
    sum += a[i];
  }
  left = 0;
  right = n - 1;
}

std::vector<long> answer;


int main() {
  load();

  for(int i = 0; i < n - 1; ++i) {
    if( a[i] + a[i+1] >= l ) {
      for(int j = 0; j < i; ++j) {
        answer.push_back(j);
      }
      for(int j = n - 2; j >= i + 1; --j) {
        answer.push_back(j);
      }
      answer.push_back(i);
      break;
    }
  }

  if( (int)answer.size() != 0 ) {
    puts("Possible");
    for(long x : answer) {
      printf("%ld\n", x + 1);
    }
    
  }
  else {
    puts("Impossible");
  }
  
  return 0;
}



Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    int c = 0;
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if(sqrt(1ll*x*x+1ll*y*y) <= d) c++; 
    }
    cout << c;

    return 0;
}

Measured memory_bytes: 3692
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int dp[1000001][2];
int main(){
	string S;
	scan(S);
	int N=S.size();
	dp[N-1][0]=10-(S[N-1]-'0');
	dp[N-1][1]=(S[N-1]-'0');
	brep1(i,N-1){
		dp[i-1][0]=min(dp[i][0]+10-(S[i-1]-'0')-1,dp[i][1]+10-(S[i-1]-'0'));
		dp[i-1][1]=min(dp[i][1]+(S[i-1]-'0'),dp[i][0]+(S[i-1]-'0')+1);
	}
	prin(min(dp[0][0]+1,dp[0][1]));
	return 0;
}


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

int compare(const void*a,const void *b) {
	return *(int*)a - *(int*)b;
}

int main() {
	int l,r,d,k = 0, n, a[4] = { 0 }, ans = 0;
	char s[3], cas[4][4] = {"AC","WA","TLE","RE"};
	scanf("%d%d%d", &l,&r,&d);
	for (int i = l; i <= r; i++) {
		if (i % d == 0)ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1728
"use strict";
function main(input) {
    const S = input.replace("\n", "");
    let flg = false;
    for (let i = 1; i < S.length; i++) {
        if (S[i - 1] === S[i]) {
            flg = true;
            break;
        }
    }
    console.log(flg ? "Bad" : "Good");
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30432
#pragma warning (disable :4996)
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const double PI = cos(-1.0);
const double eps = 1e-12;
#define For(i,n,m) for(int i=n;i<=m;++i)

ll a, b;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> b >> a;
	if (a >= b) cout << "unsafe" << "\n";
	else cout << "safe" << "\n";
	return 0;
}




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


int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;

  string res = "";
  rep(i,dx) res += "R";
  rep(i,dy) res += "U";
  rep(i,dx) res += "L";
  rep(i,dy) res += "D";

  res += "L";
  rep(i,dy+1) res += "U";
  rep(i,dx+1) res += "R";
  res += "D";
  res += "R";
  rep(i,dy+1) res += "D";
  rep(i,dx+1) res += "L";
  res += "U";
  cout << res << endl;
  return 0;
}

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

int main() {
	int a,b;
  cin >>a>>b;
  int ans =0;
  ans += max(a,b);
  if(max(a,b) ==a) a--;
  else b--;
  ans += max(a,b);
  cout <<ans <<endl;
}

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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.141592653589793238462643383279;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} init;

int H, W;
bool r[550][550], b[550][550];
signed main() {
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            char c;
            cin >> c;
            r[i][j] = b[i][j] = c == '#';
        }
    }
    rep(i, H) { r[i][0] = b[i][W - 1] = true; }
    rep(i, H) {
        reps(j, W - 2) {
            if (i & 1) { r[i][j] = true; }
            else { b[i][j] = true; }
        }
    }
    rep(i, H) {
        rep(j, W) {
            cout << (r[i][j] ? '#' : '.');
        }
        cout << endl;
    }
    cout << endl;
    rep(i, H) {
        rep(j, W) {
            cout << (b[i][j] ? '#' : '.');
        }
        cout << endl;
    }
}

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

typedef long long ll;
typedef vector<ll> v1;
typedef vector<vector<ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;
ll l[2000];
ll a,b;
ll ans = 0;

int main(){
    cin >> n;
    for(ll i = 0;i < n;i++){
        cin >> l[i];
    }
    sort(l,l+n);
    for(ll i = 0;i < n;i++){
        a = l[i];
        for(ll j = i+1;j < n;j++){
            b = l[j];
            ans += upper_bound(l+j+1,l+n,a+b-1)-lower_bound(l+j+1,l+n,b-a+1);
        }
    }
    cout << ans << endl;
}


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

int main() {
    int N, A, B;
    string S;
    cin >> N >> A >> B >> S;
    int cnt=0, b_num=0;
    for(int i=0;i<N;i++){
    	if(S[i]=='a'){
    		if(cnt<A+B){
    			cnt++; cout << "Yes" << endl;
    		}
    		else cout << "No" << endl;
    	}
    	else if (S[i]=='b'){
    		if(cnt<A+B && b_num<B){
    			cnt++; b_num++; cout << "Yes" << endl;
    		}
    		else cout << "No" << endl;
    	}
    	else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 896
/*
    oj d https://atcoder.jp/contests/abc165/tasks/abc165_b
    g++ B.cpp
    oj t
    oj s https://atcoder.jp/contests/abc165/tasks/abc165_b B.cpp
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll X;
    cin >> X;
    
    ll money = 100;
    for(int i=1;i<5000;i++){
        money += money/100;
        if(money >= X){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
	// freopen("in.txt","r",stdin);
	int N,C,K;
	long long ans=1;
	//N：乗客 C:定員 K:待ち時間限界
	int T[100100];//客が来る時間
	cin >> N >> C >> K;
	for (int i = 0; i < N; ++i)
	{
		scanf("%d",&T[i]);
	}
	sort(T,T+N);
	int tc = C-1;
	int tt = T[0];
	for (int i = 1; i < N; ++i)
	{
		if(tt+K<T[i]||tc==0){
			tt = T[i];
			tc = C-1;
			ans++;
			// cout << tt << ":"<<tc<<endl;
		}else{
			tc--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
while True:
    n = int(input())
    max = 0
    min = 1000
    sum = 0
    ave = 0
    if n == 0:
        break
    for i in range(n):
        s = int(input())
        sum += s
        if s < min:
            min = s
        if max < s:
            max = s
    ave = (sum - min - max) // (n - 2)
    print(ave)


Measured memory_bytes: 5592
#include<iostream>
#include<string>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

	char a,b;
	char result='D';
	cin >> a;
    cin >> b;
    if(a==b) result='H';
    
	cout << result << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "["; for (int i=0; i<(int)v.size(); i++) cout << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p>>=1;){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

int N,dp[200010],t[6000000][2],val[6000000],K,cnt[30];

void ins(int nod, int v, int d, int ndp){
    if (d==26){
        val[nod]=min(val[nod],ndp);
        return;
    }

    int nxt=v%2; v/=2;
    if (t[nod][nxt]==0){
        t[nod][nxt]=++K;
        val[K]=10*N;
    }
    ins(t[nod][nxt],v,d+1,ndp);
}

int getmin(int nod, int v, int d, bool c){
    if (nod==0) return 10*N;

    if (d==26) return val[nod];

    int res=10*N,nxt=v%2;
    v/=2;
    res=getmin(t[nod][nxt],v,d+1,c);

    if (c==0) res=min(res,getmin(t[nod][!nxt],v,d+1,1));
    return res;
}

string s;

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

    K=1; N=s.length();
    val[1]=10*N;
    ins(1,0,0,0);

    int i,j;
    for (i=0; i<N; i++){
        cnt[s[i]-'a']++;
        cnt[s[i]-'a']%=2;
        int val=0;

        for (j=0; j<26; j++)
            val=val*2+cnt[j];

        dp[i]=1+getmin(1,val,0,0);
        ins(1,val,0,dp[i]);
    }

    cout << dp[N-1] << "\n";
	return 0;
}


Measured memory_bytes: 21840
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  double sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i >= k) {
      sum += 1;
    } else {
      sum += pow(0.5, ceil(log2((double)k / i)));
    }
  }
  cout.precision(std::numeric_limits<double>::max_digits10);
  cout << sum / n << endl;
  return 0;
}


Measured memory_bytes: 384
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
OutV = lambda x: print(*x, sep='\n')
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

## 10進数をn進数に変換(出力はstr)
## in: int X
## in: int n
## out: str
## (n-1)の桁数に合わせて0埋めをする
def Base_10_to_n(X, n):
    digit = len(str(n - 1))
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n).zfill(digit)
    return str(X%n).zfill(digit)

import string
alphabet = list(string.ascii_lowercase)


N = iIn()

s = Base_10_to_n(N, 26)

lst = []
for i in range(len(s)//2):
    var = s[2*i] + s[2*i+1]
    lst.append(int(var))
lst = lst[::-1]
## N = 26 -> lst = [0, 1]

solver = []
for i in range(len(lst)):
    if lst[i] > 0:
        solver.append(lst[i])
    else:
        if i == len(lst) - 1:
            break
        lst[i+1] -= 1
        solver.append(lst[i]+26)
solver = solver[::-1]

ans = ''
for i in range(len(solver)):
    ans += alphabet[solver[i]-1]

print(ans)

Measured memory_bytes: 73856
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	double pi,a,b,C,S,L,h,c;
	cin >> a>>b >>C ;
	c = C*3.1415926535*2.0/360.0;
	S =1.0/2.0*sin(c)*a*b;
	L =sqrt(a*a+b*b-2.0*a*b*cos(c))+a+b;
	h =b*sin(c);
	printf("%.8f %.8f %.8f\n",S,L,h);
	return 0;
}

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

const int MX = 100005;

int main() {
  int n;
  cin >> n;
  vector<ll> cnt(MX);
  rep(i,n) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll tot = 0;
  rep(i,MX) tot += i*cnt[i];

  int q;
  cin >> q;
  rep(i,q) {
    int b, c;
    cin >> b >> c;
    tot -= b*cnt[b];
    tot -= c*cnt[c];
    cnt[c] += cnt[b]; cnt[b] = 0;
    tot += b*cnt[b];
    tot += c*cnt[c];
    cout << tot << endl;
  }
  return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll s[101];
int main() {
	ll n; cin >> n;
	ll total = 0;
	ll t = 1 << 21;
	rep(i, 0, n) {
		ll s; cin >> s;
		total += s;
		if (!(s % 10 == 0) && t > s) {
			t = s;
		}
	}

	if (total % 10 != 0)cout << total;
	else {
		if (t == 1 << 21)cout << 0;
		else cout << total - t;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	ans = -ones(Int,2*n)
	str = "?"
	for i in 1:n
		str *= " "*string(i)
	end
	println(str)
	la = readline() |> chomp
	str = "?"
	for i in n+1:2n
		str *= " "*string(i)
	end
	println(str)
	ra = readline() |> chomp
	l = 1
	r = n+1
	while r-l>1
		m = (l+r)>>1
		str = "?"
		for i in m:m+n-1
			str *= " "*string(i)
		end
		println(str)
		ma = readline() |> chomp
		if ma!=la
			r = m
			ra = ma
		else
			l = m
			la = ma
		end
	end
	if la == "Red"
		ans[l] = 1
		ans[r+n-1] = -1
	else
		ans[l] = -1
		ans[r+n-1] = 1
	end
	for i in 1:l-1
		str = "? "*string(i)
		for j in l+1:l+n-1
			str *= " "*string(j)
		end
		println(str)
		xa = readline() |> chomp
		if xa == "Red"
			ans[i] = 1
		else
			ans[i] = -1
		end
	end
	for i in r+n:2n
		str = "? "*string(i)
		for j in l+1:l+n-1
			str *= " "*string(j)
		end
		println(str)
		xa = readline() |> chomp
		if xa == "Red"
			ans[i] = 1
		else
			ans[i] = -1
		end
	end
	stb = "?"
	lc = 0
	rc = 0
	for i in 1:l-1
		if ans[i]==1&&lc<n>>1
			stb *= " "*string(i)
			lc += 1
		elseif ans[i]==-1&&rc<n>>1
			stb *= " "*string(i)
			rc += 1
		end
	end
	for i in r+n:2n
		if ans[i]==1&&lc<n>>1
			stb *= " "*string(i)
			lc += 1
		elseif ans[i]==-1&&rc<n>>1
			stb *= " "*string(i)
			rc += 1
		end
	end
	for i in l+1:l+n-1
		str = stb*" "*string(i)
		println(str)
		xa = readline() |> chomp
		if xa=="Red"
			ans[i] = 1
		else
			ans[i] = -1
		end
	end
	str = "! "
	for i in 1:2n
		if ans[i]==1
			str *= "R"
		else
			str *= "B"
		end
	end
	println(str)
end
main()

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

using namespace std;

const int N = 567890, mod = 924844033, root = 5;

void add(int& x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}

void sub(int& x, int y) {
  x -= y;
  if (x < 0) {
    x += mod;
  }
}

int mul(int x, int y) {
  return (long long) x * y % mod;
}

int qpow(int x, int y) {
  int result = 1;
  for (; y; y >>= 1, x = mul(x, x)) {
    if (y & 1) {
      result = mul(result, x);
    }
  }
  return result;
}

int n, size[N], rev[N], fac[N], ifac[N], inv[N];
vector<int> adj[N];

int binom(int n, int m) {
  return n < 0 || m < 0 || n < m ? 0 : mul(fac[n], mul(ifac[m], ifac[n - m]));
}

void dft(vector<int>& buffer, bool inv = false) {
  int n = buffer.size();
  for (int i = 0; i < n; ++i) {
    if (i < rev[i]) {
      swap(buffer[i], buffer[rev[i]]);
    }
  }
  for (int i = 1; i < n; i <<= 1) {
    int x = qpow(root, inv ? mod - 1 - (mod - 1) / (i << 1) : (mod - 1) / (i << 1));
    for (int j = 0; j < n; j += i << 1) {
      int y = 1;
      for (int k = 0; k < i; ++k, y = mul(y, x)) {
        int p = buffer[j + k], q = mul(y, buffer[i + j + k]);
        buffer[j + k] = (p + q) % mod;
        buffer[i + j + k] = (p - q + mod) % mod;
      }
    }
  }
  if (inv) {
    int x = qpow(n, mod - 2);
    for (int i = 0; i < n; ++i) {
      buffer[i] = mul(buffer[i], x);
    }
  }
}

vector<int> pmul(vector<int> x, vector<int> y) {
  int n = x.size() + y.size() - 1, len = 0;
  for (; (1 << len) < n; ++len);
  for (int i = 0; i < (1 << len); ++i) {
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << len - 1);
  }
  x.resize(1 << len);
  y.resize(1 << len);
  dft(x);
  dft(y);
  for (int i = 0; i < (1 << len); ++i) {
    x[i] = mul(x[i], y[i]);
  }
  dft(x, true);
  x.resize(n);
  return x;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
  for (int i = 2; i <= n; ++i) {
    inv[i] = mul(mod - mod / i, inv[mod % i]);
    fac[i] = mul(fac[i - 1], i);
    ifac[i] = mul(ifac[i - 1], inv[i]);
  }
  for (int i = 1, x, y; i < n; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vector<int> f(n + 1), g(n + 1);
  for (int i = 0; i <= n; ++i) {
    g[i] = ifac[i];
  }
  function<void (int, int)> dfs = [&] (int x, int z) {
    size[x] = 1;
    for (auto y : adj[x]) {
      if (y != z) {
        dfs(y, x);
        ++f[size[y]];
        ++f[n - size[y]];
        size[x] += size[y];
      }
    }
  };
  dfs(1, 0);
  for (int i = 0; i <= n; ++i) {
    f[i] = mul(f[i], fac[i]);
  }
  reverse(f.begin(), f.end());
  f = pmul(f, g);
  for (int i = 1; i <= n; ++i) {
    int answer = mul(n, binom(n, i));
    sub(answer, mul(ifac[i], f[n - i]));
    cout << answer << '\n';
  }
  return 0;
}

Measured memory_bytes: 51828
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Hello{
    public static void Main(){
        var n = Int32.Parse(Console.ReadLine());
        long ret = 0;
        for(var i = 1; i <= n; ++i){
            if (i % 3 != 0 && i % 5 != 0){
                ret += i;
            } 
        }
        
        Console.WriteLine(ret);
    }
}


Measured memory_bytes: 17616
from functools import reduce

def main():
    n = int(input())
    thumbnails = []
    thumbnails = list(map(lambda x: (x[0], int(x[1])), enumerate(input().split(' '))))

    thumbnails.sort(key=lambda t: t[1])

    average = reduce(lambda x, y: x + y[1], thumbnails, 0) / n

    min_diff = 100
    t_options = []

    for i, t in thumbnails:
        diff = abs(average - t)
        if min_diff > diff:
            t_options = [i]
            min_diff = diff
        elif min_diff == diff:
            t_options.append(i)
    print(min(t_options))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
import itertools
import math

N = int(input())
coodinate_list = [tuple(map(int, input().split(' '))) for _ in range(N)]
idx_list = [x for x in range(N)]
idx_permutations = itertools.permutations(idx_list)

total_dist = 0
permutaions_len = 0
for one_case in idx_permutations:
    permutaions_len += 1
    dist = 0
    for idx in range(len(one_case)):
        if idx > 0:
            dist += math.sqrt(math.pow(coodinate_list[one_case[idx]][0]-coodinate_list[one_case[idx-1]][0], 2)+math.pow(coodinate_list[one_case[idx]][1]-coodinate_list[one_case[idx-1]][1], 2))
    total_dist += dist
print(total_dist / permutaions_len)

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

#define MAX_N 100
#define MAX_M 50

int n, m;
int F[MAX_N][MAX_N];
int P[MAX_M][MAX_M];

void rotate90() {
    int buf[m][m];
    for (int i = 0; i < m; i++) 
        for (int j = 0; j < m; j++) 
            buf[i][j] = P[m-j-1][i];
    for (int i = 0; i < m; i++) 
        for (int j = 0; j < m; j++)
            P[i][j] = buf[i][j];
}

pair<int, int> ans;

bool check(int y, int x) {
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            if (P[i][j] != -1 && F[y+i][x+j] != P[i][j]) 
                return false;
        }
    }
    //for (int i = 0; i < m; i++) {
    //    for (int j = 0; j < m; j++) 
    //        printf("%3d ", P[i][j]);
    //    printf("\n");
    //}

    return true;
}

void find() {
    for (int i = 0; i < n-m+1; i++) {
        for (int j = 0; j < n-m+1; j++) {
            if (check(i, j)) {
                pair<int, int> t;
                t.first = i+1;
                int k = 0;
                while (P[0][k] == -1) k++;
                t.second = j+k+1;
                ans = min(ans, t);
                return;
            }
        }
    }
}

#define INF (1<<28)

int main() {
    while (cin >> n >> m, n || m) {
        ans.first = ans.second = INF;
        for (int i = 0; i < n; i++) 
            for (int j = 0; j < n; j++) 
                cin >> F[i][j];
        for (int i = 0; i < m; i++) 
            for (int j = 0; j < m; j++) 
                cin >> P[i][j];
        find(); 
        rotate90(); find();
        rotate90(); find();
        rotate90(); find();
        if (ans.first == INF && ans.second == INF) cout << "NA" << endl;
        else cout << ans.second << ' ' << ans.first << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
vector<string> now(9);
vector<string> prevv(9);
void func() {
  vector<string> tmp;
  for(int i=0;i<prevv.size();i++) {
    string s = prevv[i];
    if(s.back() == '0') {
      tmp.emplace_back(s + '0');
      tmp.emplace_back(s + '1');
      now.emplace_back(s + '0');
      now.emplace_back(s + '1');
    }
    else if(s.back() == '9') {
      string a, b;
      a = s + '8';
      b = s + '9';
      tmp.emplace_back(a);
      now.emplace_back(a);
      tmp.emplace_back(b);
      now.emplace_back(b);
    }
    else {
      string a, b, c;
      char ch = prevv[i].back();
      char c1 = ch - 1;
      char c2 = ch + 1;
      a = s + c1;
      b = s + ch;
      c = s + c2;
      tmp.emplace_back(a);
      tmp.emplace_back(b);
      tmp.emplace_back(c);
      now.emplace_back(a);
      now.emplace_back(b);
      now.emplace_back(c);
    }
  }
  prevv.clear();
  prevv.resize(tmp.size());
  prevv = tmp;
}
int main() {
  int k;
  cin >> k;
  iota(now.begin(), now.end(), '1');
  iota(prevv.begin(), prevv.end(), '1');
  while(now.size() < k) {
    func();
  }
  cout << now[k-1] << endl;
  return 0;
}


Measured memory_bytes: 18468
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	vector<string> c(3);
	for (auto &x : c) {
		cin >> x;
	}
	for (int i = 0; i < 3; ++i) {
		cout << c[i][i];
	}
	cout << endl;
}


Measured memory_bytes: 256
import math
n, k = map(int,input().split())
ans = 0

for i in range(1, n+1):
    if k <= i:
        ans += 1 / n
    else:
        cnt = math.ceil(math.log(k/i, 2))
        ans += (1/n) * ((1/2) ** cnt)
print(ans)

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

#define ISLOOSE(a,b)    (disdis(a, b) + get<2>(a) * get<2>(a) <= get<2>(b) * get<2>(b))

using namespace std;

double disdis(const tuple<double, double, double>& a, const tuple<double, double, double>& b)
{
	return (get<0>(a) - get<0>(b)) * (get<0>(a) - get<0>(b)) + (get<1>(a) - get<1>(b)) * (get<1>(a) - get<1>(b));
}

double heron(double a, double b, double c)
{
	double s = (a + b + c) / 2;
	return sqrt(s*(s - a)*(s - b)*(s - c));
}

double heron2(double a, double b, double c, double d, double e, double f)
{
	return sqrt((a*d*(b + c + e + f - a - d) + b*e*(c + a + f + d - b - e) + c*f*(a + b + d + e - c - f) - a*b*f - a*e*c - d*b*c - d*e*f) / 144.0);
}

tuple<double, double, double> com(const tuple<double, double, double>& a, const tuple<double, double, double>& b)
{
	if (ISLOOSE(a, b)) {
		return a;
	}
	else if (ISLOOSE(b, a)) {
		return b;
	}
	else {
		double l = heron(get<2>(a), get<2>(b), sqrt(disdis(a, b))) * 2 / sqrt(disdis(a, b));
		double d1 = sqrt(get<2>(a) * get<2>(a) - l * l);
		double d2 = sqrt(get<2>(b) * get<2>(b) - l * l);
		return tuple<double, double, double>(get<0>(a) + (get<0>(b) - get<0>(a)) * d1 / (d1 + d2), get<1>(a) + (get<1>(b) - get<1>(a)) * d1 / (d1 + d2), l);
	}
}

double two(const tuple<double, double, double>& a, const tuple<double, double, double>& b)
{
	if (ISLOOSE(a, b)) {
		return (double)get<2>(a);
	}
	else if (ISLOOSE(b, a)) {
		return (double)get<2>(b);
	}
	else {
		double d = sqrt(disdis(a, b));
		return heron(get<2>(a), get<2>(b), d) * 2 / d;
	}
}

double three(const tuple<double, double, double>& a, const tuple<double, double, double>& b, const tuple<double, double, double>& c)
{
	tuple<double, double, double> temp;

	if (ISLOOSE(a, b) && ISLOOSE(a, c))
		return get<2>(a);
	if (ISLOOSE(b, a) && ISLOOSE(b, c))
		return get<2>(b);
	if (ISLOOSE(c, a) && ISLOOSE(c, b))
		return get<2>(c);

	if (ISLOOSE(temp = com(a, b), c))
		return get<2>(temp);
	if (ISLOOSE(temp = com(b, c), a))
		return get<2>(temp);
	if (ISLOOSE(temp = com(c, a), b))
		return get<2>(temp);

	return heron2(get<2>(a) * get<2>(a), get<2>(b) * get<2>(b), get<2>(c) * get<2>(c), disdis(b, c), disdis(c, a), disdis(a, b))
		* 3.0 / heron(sqrt(disdis(a, b)), sqrt(disdis(b, c)), sqrt(disdis(c, a)));
}

int main()
{
	int n;
	double res;
	cin.sync_with_stdio(false);
	cout << fixed << setprecision(7);
	while (cin >> n, n) {
		vector< tuple<double, double, double> > str(n);
		for (int i = 0; i < n; i++) {
			cin >> get<0>(str[i]) >> get<1>(str[i]) >> get<2>(str[i]);
		}
		if (n == 1) {
			cout << (double)get<2>(str[0]) << endl;
		}
		else if (n == 2) {
			cout << two(str[0], str[1]) << endl;
		}
		else {
			res = 100000000.0;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					for (int k = j + 1; k < n; k++) {
						res = min(res, three(str[i], str[j], str[k]));
					}
				}
			}
			cout << res << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3232
S = input()

Ls = [len(word) for word in S.split("L") if word != ""]
Rs = [len(word) for word in S.split("R") if word != ""]

res = []
for l, r in zip(Ls, Rs):
    nl = nr = (l + r) // 2
    if (l - r) % 2 != 0:
        if l % 2 != 0:
            nl += 1
        else:
            nr += 1
    for _ in range(l - 1):
        res += ["0"]
    res += [str(nl), str(nr)]
    for _ in range(r - 1):
        res += ["0"]

print(" ".join(res))

Measured memory_bytes: 10732
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int n;  cin >> n;
  ll ans = 0;
  rep0(i,n){
    ll a;  cin >> a;
    while(a % 2 == 0){
      a /= 2;
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  P ma = P(-INF,-1);
  P mi = P(INF,-1);
  rep(i,N) {
    cin >> A[i];
    if(ma.first < A[i]) {
      ma = P(A[i],i);
    }
    if(mi.first > A[i]) {
      mi = P(A[i],i);
    }
  }
  vp op;
  if(abs(ma.first) >= abs(mi.first)) {
    rep(i,N) {
      if(i == ma.second) continue;
      op.push_back(P(ma.second,i));
      A[i] += ma.first;
    }
    op.push_back(P(ma.second,ma.second));
    A[ma.second] += ma.first;
    rep(i,N-1) {
      while(1) {
        if(A[i] <= A[i+1]) break;
        A[i+1] += A[i];
        op.push_back(P(i,i+1));
      }
    }
  } else {
    rep(i,N) {
      if(i == mi.second) continue;
      op.push_back(P(mi.second,i));
      A[i] += mi.first;
    }
    op.push_back(P(mi.second,mi.second));
    A[mi.second] += mi.first;
    drep(i,N-1) {
      while(1) {
        if(A[i] <= A[i+1]) break;
        A[i] += A[i+1];
        op.push_back(P(i+1,i));
      }
    }
  }
  
  
  cout << sz(op) << endl;
  rep(i,sz(op)) {
    cout << op[i].first+1 << " " << op[i].second+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr first
#define sc second
using namespace std;

const int mnx = 1e6 + 9;
const int mod =  1e9 + 7;

ll n, m, q, cl[mnx], v[mnx], d[mnx], c[mnx], r[mnx];
vector<int> g[mnx];

void funk(int v, int d, int c){
    if(d < 0) return;
    if(cl[v] == 0) cl[v] = c;
    if(r[v] < d){
        r[v] = d;
        for(int to : g[v]){
            funk(to, d - 1, c);
        }
    }
}

int main(){

cin >> n >> m;

for(int i = 0, v, u; i < m; i++){
    cin >> v >> u;
    g[v].pb(u);
    g[u].pb(v);
}

cin >> q;

for(int i = 1; i <= q; i++){
    cin >> v[i] >> d[i] >> c[i];
}

for(int i = q; i >= 1; --i){
    funk(v[i], d[i], c[i]);
    r[v[i]] = d[i];
}

for(int i = 1; i <= n; i++){
    cout << cl[i] << '\n';
}

return 0;

}


Measured memory_bytes: 40952
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>
#include <cassert>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N; cin>>N;
    vector<int>a(3*N);
    for (int i = 0; i < 3*N; i++) {
        cin>>a[i];
    }

    ll psum=0, ssum=0;
    priority_queue<int , vector<int>, greater<int>> pre;
    priority_queue<int> suf;

    for (int i = 0; i < N; i++) {
        psum+=a[i];
        ssum+=a[3*N-1-i];
        pre.push(a[i]);
        suf.push(a[3*N-1-i]);
    }

    vector<ll> pret, sret;
    pret.push_back(psum);
    sret.push_back(ssum);

    for (int i = N; i < 2*N; i++) {
        //前半部分
        int pt = a[i];
        pre.push(pt);
        psum+=pt;
        psum-=pre.top();
        pre.pop();
        pret.push_back(psum);
    }
    
    for (int i = 2*N-1; i >= N; i--) {
        //後半部分
        int rt = a[i];
        suf.push(rt);
        ssum+=rt;
        ssum-=suf.top();
        suf.pop();
        sret.push_back(ssum);
    }
    reverse(all(sret));
    
    ll res = (ll)-1e15;
    for (int i = 0; i <= N; i++) {
        res=max(res, pret[i]-sret[i]);
    }

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 4464
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>
#include <algorithm>
#include<iomanip>

using namespace std;
typedef long long ll;

int main() {
  int N;
  int x[8];
  int y[8];
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i]; 
  }
  
  int array[]={0,1,2,3,4,5,6,7};

  double sum = 0;
  int cnt = 0;
  do{
    int pre = array[0];
	
    for(int i=1; i<N; i++){
	  double a = (x[array[i]] - x[pre])*(x[array[i]] - x[pre]);
      double b = (y[array[i]] - y[pre])*(y[array[i]] - y[pre]);
      double len = sqrt(a+b);
      sum += len;
      pre = array[i];
      //cout << array[i] << " ";
    }
    cnt++;
    //cout << "cnt:" << cnt << endl;
    
  }while(next_permutation(array,array+N));

  cout << std::fixed << setprecision(15);
  cout  << (sum / cnt);
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int ans=111;
    for(int i = 0; i < (int)s.size(); i++)
    {
        char c = s[i];
        int cnt=0, num=0;
        for(int j = 0; j < (int)s.size(); j++)
        {
            if(s[j]==c){
                cnt = max(cnt, j-num);
                num = j+1;
            }
        }
        int len = s.size();
        cnt = max(cnt, len-num);
        ans = min(ans, cnt);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int num, digit, rev=0,n;
cin>>num;
n=num;
do{
digit=num%10;
rev=(rev*10)+digit;
num=num/10;
 
} while(num!=0) ;
if(n==rev)
cout<<"Yes";
else
cout<<"No";
	return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007
#define sz(a) a.size()
#define pii pair<ll,ll> 
#define nl "\n"
#define ff first
#define ss second
#define c(n) ll n; cin>>n;
#define ca(n) ll a[n]; rep(n) cin>>a[i];
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(a) a.begin(),a.end()
#define sort_stl(a) sort(a.begin(),a.end())
#define srt(a) sort(a,a+n)
#define fl(a,x) memset(a,x,sizeof(a))

typedef vector<ll> vll ;

int main(){
    
    fast;
    ll n,m; cin>>n>>m; cout << n*(n-1)/2 + m*(m-1)/2;
    
	return 0;
}


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

int main(void) {
  long long N, M, A;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A;
    N -= A;
  }
  if (N < -1) {
    cout << -1 << endl;
  } else {
    cout << N << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,N) for(int i=0;i<N;i++)
#define print(S) cout<<S<<endl;
using namespace std;

int main() {
	int N,x=0,max=0;
	string S;
	cin>>N>>S;
	REP(i,N){
		if(S[i]=='I'){
			x++;
			if(max<x) max=x;
		}else if(S[i]=='D'){
			x--;
		}
	}
	print(max);
	return 0;
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

vector<pii> cv[30];
int n,c;
vector<pii> all;
vector<pii> now;

int main(){
  cin >> n >>c;
  REP(i,n){
    int l,r,a;
    cin >> l >> r>> a;
    cv[a-1].push_back(pii(l,r));
  }
  REP(i,c){
    if(cv[i].size()==0) continue;
    sort(cv[i].begin(),cv[i].end());
    int prev = cv[i][0].second;
    all.push_back(cv[i][0]);
    FOR(j,1,cv[i].size()){
      if(prev == cv[i][j].first){
        all[all.size()-1].second = cv[i][j].second;
      }else{
        all.push_back(cv[i][j]);
      }
      prev = cv[i][j].second;
    }
  }
  sort(all.begin(),all.end());
  now.push_back(all[0]);
  FOR(i,1,all.size()){
    bool flag = false;
    REP(j,now.size()){
      if(now[j].second<all[i].first){
        now[j] = all[i];
        flag = true;
        break;
      }
    }
    if(flag) continue;
    now.push_back(all[i]);
  }
  cout << now.size() <<endl;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> H(N); REP(i,N) cin >> H[i];
    int ans = 0;
    while(1){
        bool flag = false;
        int zeros = 0;
        REP(i,N){
            if(H[i]==0 && flag==true){//0以外が続いた後に0が来た場合
                ans ++;
                flag = false;
            }
            if(H[i]==0) zeros++;
            
            if(H[i]!=0){
                H[i]--;
                flag = true;
            }
        }
        if(flag==true) ans++;
        if(zeros==N) break;
    }

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

Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	
	while (1){
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		i = 0;
		
		while (n != 1){
			
			if (n % 2 == 0){
				n /= 2;
			}
			
			else {
				n = (n * 3) + 1;
			}
			i++;
		}
		printf ("%d\n", i);
	}
	
	return (0);
	
}

Measured memory_bytes: 600
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.map(String).reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && (arr[left]) > (arr[i])) largest = left;
    if (right < n && (arr[right]) > (arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2 - 1); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 156220
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from bisect import bisect_left
setrecursionlimit(1000000)

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]


def main():
    from builtins import int, map
    K = int(input())
    A, B = map(int, input().split())
    for n in range(A, B+1):
        if n % K == 0:
            print("OK")
            exit()
    print("NG")


if __name__ == '__main__':
    main()

Measured memory_bytes: 64964
import sys

N=int(raw_input())
a=map(int,raw_input().split())

T=0
for i in a:
    if i != a[0]:
        if i - a[0] >= 2 or a[0] - i >= 2:
            print "No"
            sys.exit()
        T=max(i,a[0])
        break

if T == 0:
    if a[0] <= N/2 or a[0] == N-1:
        print "Yes"
    else:
        print "No"
    sys.exit()

uni=0
nu=0
for i in a:
    if i==T:
        nu+=1
    else:
        uni+=1

if T>=uni+1 and T<=uni+nu/2:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 11328
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m;
	while(cin>>n,n){
		double sum=0;
		int sumi=0;
		rep(i,n-1){
			int in;
			cin>>in;
			sum+=10000.0*sin(in*PI/180.0);
			sumi+=in;
		}
		sum+=10000.0*sin((360-sumi)*PI/180.0);
		cin>>n;
		double sumq=0;
		int sumiq=0;
		rep(i,n-1){
			int in;
			cin>>in;
			sumq+=10000.0*sin(in*PI/180.0);
			sumiq+=in;
		}
		sumq+=10000.0*sin((360-sumiq)*PI/180.0);
		if(sum>sumq)cout<<1<<endl;
		else if(sum<sumq)cout<<2<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 1196
from functools import reduce
from math import gcd

N, *A = map(int, open(0).read().split())

C = [0] * (max(A) + 1)
for a in A:
    C[a] += 1

if reduce(gcd, A) != 1:
    print("not coprime")

elif all(sum(C[i::i]) <= 1 for i in range(2, len(C))):
    print("pairwise coprime")

else:
    print("setwise coprime")

Measured memory_bytes: 121944
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
vector <int> v;

int32_t main()
{
	usecppio
	int n;
	cin >> n;
	if (n%2==1)
	{
		cout << 0 << '\n';
		return 0;
	}
	int x = 10;
	int ans = 0;
	while(x <= n)
	{
		ans += n/x;
		x *= 5;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
a, b, n = (int(i) for i in input().split())  

while n>0:
    if a % 2 ==1:
        a = (a-1)/2
        b = b + a
    else:
        a = a/2
        b = b + a
    a1=a
    b1=b
    if b % 2 ==1:
        b = (b-1)/2
        a = b + a
    else:
        b = b/2
        a = b + a
    a2=a
    b2=b
    n=n-2

if n%2==0:
    print(int(a2),int(b2))
else:
    print(int(a1),int(b1))
    


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	string s;
	cin>>s;
	int n  = s.length();
	for(int i=n-1;i>=0;i--){
		if(s[i]=='?'){
			s[i] = 'D';
		}
	}
	cout<<s;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long

typedef pair<int,int> pii;
const int N = 2e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, a[N];
int f[N];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	int ans = -1;
	f[0] = 1;
	for(int i=0; i<n; i++){
		int &x(a[i]);
		if (f[x-1]) {
			f[x] = f[x-1]+1;
			ans = max(ans, f[x]);
		}
	}
	if (ans == -1) cout << -1 << endl;
	else {
		cout << n - ans + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 1792