akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
 
using namespace std;
 
string s;
int K;
 
string cbest[5];
 
void update (string C)
{
    for (int i = 0; i < 5; i++)
    {
        if (C < cbest[i])
        {
            for (int j = 4; j > i; j--)
                cbest[j] = cbest[j-1];
            cbest[i] = C;
            break;
        }
        else if (C == cbest[i])
            break;
    }
}
 
int main()
{
    cin >> s >> K;
    for (int i = 0; i < 5; i++)
    {
        cbest[i] = "zzzzzz";
    }
 
    int N = s.length();
    string t;
    for (int i = 0; i < N; i++)
    {
        t = "";
        for (int j = i; j < min (N, i + 5); j++)
        {
            t += s[j];
            update (t);
        }
    }
 
    cout << cbest[K-1] << "\n";
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

string f(vs s) {
  rep(i, 3) {
    if (s[i][0] == s[i][1] && s[i][1] == s[i][2] && s[i][2] != '+') return s[i][2] == 'b' ? "b" : "w";
    if (s[0][i] == s[1][i] && s[1][i] == s[2][i] && s[2][i] != '+') return s[2][i] == 'b' ? "b" : "w";
  }
  if (s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[2][2] != '+') return s[2][2] == 'b' ? "b" : "w";
  if (s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[2][0] != '+') return s[2][0] == 'b' ? "b" : "w";
  return "NA";
}

void solve() {
  vs s(3);
  while (cin >> s[0], s[0] != "0") {
    cin >> s[1] >> s[2];
    cout << f(s) << endl;
  }
}

Measured memory_bytes: 3120
is_prime = [1]*101010
is_prime[0] = 0
is_prime[1] = 0
max = 101010

for i in range(2,max):
    if is_prime[i]:
        j = i*2
        while j <= max-1:
            is_prime[j] = 0
            j += i

a = [0]*max
for i in range(max):
    if(i%2==0): 
        continue
    if(is_prime[i]==1 and is_prime[(i+1)//2]==1):
        a[i]=1

s = [0]*(max+1)
for i in range(max):
    s[i+1] = s[i]+a[i]


q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    r += 1
    
    print(s[r]-s[l])

Measured memory_bytes: 53080
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define N 150
int n,m,a[N],b[N];
int main() {
	scanf("%d%d",&n,&m);
	int i,flg=0;
	for(i=1;i<=m;i++) scanf("%d",&a[i]),flg+=(a[i]&1);
	if(m==1&&a[1]==1) {puts("1\n1\n1\n");return 0;}
	if(m==1) {printf("%d\n2\n%d %d\n",a[1],a[1]-1,1); return 0;}
	if(flg>2) {puts("Impossible"); return 0;}
	for(i=2;i<=m;i++) {
		if(a[i]&1) {
			if(a[1]&1) swap(a[i],a[m]);
			else swap(a[i],a[1]);
		}
	}
	for(i=1;i<=m;i++) printf("%d ",a[i]); puts(""); 
	i=1;
	if(a[1]==1) i++;
	printf("%d\n",m-i+1);
	a[1]--,a[m]++;
	for(;i<=m;i++) printf("%d ",a[i]); puts("");
}


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

typedef struct diceelem {
        int str[6];
}Dice;

void e(Dice *a);
void n(Dice *a);
void s(Dice *a);
void w(Dice *a);
void spin(Dice *a);

int main(void)
{
  Dice *a=NULL;
  unsigned int i=0,j=0, plane[48] ,num;

  a = (Dice *) malloc(sizeof(Dice));
  if(a == NULL){
      perror("mallocでメモリ領域が確保できませんでした");
      exit(1);
  }

  scanf("%d %d %d %d %d %d", &(a->str[0]), &(a->str[1]), &(a->str[2]), &(a->str[3]), &(a->str[4]), &(a->str[5]));
  scanf("%d", &num);//何個のデータがあるか
  for(i=0, j=0; i < num; i++, j+=2){
    scanf("%d %d", &plane[j], &plane[j+1]);
  }
  for(i=0, j=0; i < (int)num; i++, j+=2){
    while(plane[j] != a->str[0]){
      n(a);
      if (plane[j] == a->str[0]){
        break;
      }
      n(a);
      if (plane[j] == a->str[0]){
        break;
      }
      n(a);
      if (plane[j] == a->str[0]){
        break;
      }
      e(a);
      if (plane[j] == a->str[0]){
        break;
      }
    }
    while(plane[j+1] != a->str[1]){
      spin(a);
      if (plane[j+1] == a->str[1]){
        break;
      }
    }
    printf("%d\n",a->str[2]);
  }

  return 0;
}

void e(Dice *a){
  int tmp;
  tmp = a->str[0];
  a->str[0] = a->str[3];
  a->str[3] = a->str[5];
  a->str[5] = a->str[2];
  a->str[2] = tmp;
}

void n(Dice *a){
  int tmp;
  tmp = a->str[0];
  a->str[0] = a->str[1];
  a->str[1] = a->str[5];
  a->str[5] = a->str[4];
  a->str[4] = tmp;
}

void s(Dice *a){
  int tmp;
  tmp = a->str[0];
  a->str[0] = a->str[4];
  a->str[4] = a->str[5];
  a->str[5] = a->str[1];
  a->str[1] = tmp;
}

void w(Dice *a){
  int tmp;
  tmp = a->str[0];
  a->str[0] = a->str[2];
  a->str[2] = a->str[5];
  a->str[5] = a->str[3];
  a->str[3] = tmp;
}

void spin(Dice *a){
  int tmp;
  tmp = a->str[1];
  a->str[1] = a->str[2];
  a->str[2] = a->str[4];
  a->str[4] = a->str[3];
  a->str[3] = tmp;
}

Measured memory_bytes: 596
/*
 * main.c
 *
 *  Created on: 2016/12/23
 *      Author: stoneriver
 */

#include <stdio.h>

int main() {
	int S, h, m, s;
	scanf("%d", &S);
	h = S / 3600;
	S %= 3600;
	m = S / 60;
	S %= 60;
	s = S;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 2724
line = input()
X, Y = [int(n) for n in line.split()]

value = "TLE"
route_cost = []
for _ in range(X):
    line = input()
    cost, time = [int(n) for n in line.split()]
    route_cost.append([cost, time])

route_cost.sort(key=lambda x: x[0])
for cost, time in route_cost:
    if time > Y:
        continue
    else:
        value = cost
        break
print(value)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 105

using namespace std;

int n, m;
int f[N][N], a[N][N];

inline void cmin(int &u, int v) { if(u > v) u = v; }

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j) {
			char ch = getchar();
			while(ch != '.' && ch != '#') ch = getchar();
			a[i][j] = (ch == '.');
		}
	memset(f, 32, sizeof f);
	f[1][1] = (a[1][1] == 0);
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(i != 1) {
				cmin(f[i][j], f[i - 1][j] + (a[i][j] == 0 && a[i - 1][j] == 1));
			}
			if(j != 1) {
				cmin(f[i][j], f[i][j - 1] + (a[i][j] == 0 && a[i][j - 1] == 1));
			}
		}
	}
	printf("%d\n", f[n][m]);
	return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    N, M = map(int, input().split(' '))

    likes = set([int(c) for c in input().split(' ')][1:])
    for _ in range(N - 1):
        likes = likes & set([int(c) for c in input().split(' ')][1:])
    print(len(likes))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,y;
    cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            int z=y-(10000*i+5000*j);
            if(z%1000==0){
                z/=1000;
                if(0<=z && i+j+z==n){
                    cout<<i<<" "<<j<<" "<<z<<endl;
                    return 0;
                }
            }
        }
    }
   cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=-10000000000;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N,A,B; cin>>N>>A>>B;
	ll ans=0;
	rep1(i,N){
		ll tmp=i;
		ll sum=tmp/10000;
		tmp%=10000;
		sum+=tmp/1000;
		tmp%=1000;
		sum+=tmp/100;
		tmp%=100;
		sum+=tmp/10;
		tmp%=10;
		sum+=tmp;
		if(A<=sum && sum<=B) ans+=i;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 4e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

ll a[N], b[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n;
  cin >> n;
  ll total = inf, sum = 0;
  bool lsa = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    if(a[i] != b[i])
      lsa = 1;
    sum += b[i];
    if(a[i] > b[i]) {
      total = min(b[i], total);
    }
  }
  if(!lsa) {
    cout << 0;
    return 0;
  }
  if(total == inf)
    total = 0;
  cout << sum - total;
  return 0;
}


Measured memory_bytes: 2432
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,t,snum[310],len=0,ans[310][310];
string s[310];

int main()
{
	cin>>n>>m>>t;
	rep(i,n)
	{
		cin>>s[i];		
		rep(j,m) if(s[i][j]=='#') snum[i]++;
	}
	rep(i,n)
	{
		if(snum[i]==0) continue;
		len++;
		int j=0,have=0;
		while(j<m)
		{
			if(s[i][j]=='#'&&have==1) len++;
			if(s[i][j]=='#') have=1;
			ans[i][j]=len;
			j++;
		}
	}
	rep(i,n)
	{
		if(snum[i]==0) continue;
		rep(j,m)
		{
			int p=i+1;
			while(p<n&&ans[p][j]==0)
			{
				ans[p][j]=ans[i][j];
				p++;
			}
			p=i-1;
			while(p>=0&&ans[p][j]==0)
			{
				ans[p][j]=ans[i][j];
				p--;
			}
		}
	}
	rep(i,n)
	{
		rep(j,m) cout<<ans[i][j]<<' ';
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    X=int(input())
    l=[]
    for i in range(1,33):
        for j in range(2,11):
            l.append(i**j)
    l.sort()
    print(l[bisect_right(l,X)-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define size(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m,c; cin>>n>>m>>c;
	vector<int> b(m);
	int cnt=0,a;
	For(i,0,m-1) cin>>b[i];
	For(i,1,n)
	{
		int s=c;
		For(i,0,m-1)
		{
			cin>>a;
			s+=a*b[i];
		}
		if(s>0) cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 256
def solve(n, a):
    res, total = 0, 0
    for x in a:
        if x == 0:
            res += total // 2
            total = 0
        else:
            total += x
    return res + total // 2

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

Measured memory_bytes: 12928
#include<stdio.h>
int main(){
	unsigned short usW_D_set;            	/* 使用できる最大値格納用変数 */
	unsigned long ulW_D_tag;            	/* 目標値格納用変数 */
	signed short ssW_D_mid;            	/* 計算用変数 */
	unsigned short usW_D_agg[100];       	/* 計算結果格納用配列 */
	unsigned short usW_C_i, usW_C_j;           	/* ループ変数 */
	unsigned short usW_C_input_count = 0;	/* 入力数カウンタ */
	unsigned short usW_C_num_count = 0;  	/* 目標を満足する値のカウンタ */
	
	/* 配列の初期化 */
	for(usW_C_i = 0;usW_C_i < 100;usW_C_i++){
		usW_D_agg[usW_C_i] = 0;
	}
	
	/* 数値の入力、演算を無限ループ */
	while(1){
		/* 使用できる最大値、目標値の入力 */
		scanf("%d %ld", &usW_D_set, &ulW_D_tag);
		
		/* 終了処理 */
		if(usW_D_set == 0 && ulW_D_tag == 0){
			break;
		}
		/* カウンタをリセット */
		usW_C_num_count = 0;
		
		/* 目標を満足する値をカウント */
		for(usW_C_i = 1;usW_C_i < usW_D_set;usW_C_i++){
			for(usW_C_j = usW_C_i;usW_C_j <= usW_D_set;usW_C_j++){
				/* usW_C_i + usW_C_j と目標値の差をssW_D_midに代入 */
				ssW_D_mid = ulW_D_tag - (usW_C_i + usW_C_j);
				/* ssW_D_misがusW_C_iとusW_C_jの間にある場合カウント*/
				if(ssW_D_mid > usW_C_i && ssW_D_mid < usW_C_j){
					usW_C_num_count++;
				}
			}
		}
		
		/* カウントした結果を格納 */
		usW_D_agg[usW_C_input_count] = usW_C_num_count;
		/* 入力数をカウント */
		usW_C_input_count++;
	}
	
	/* 結果の出力 */
	for(usW_C_i = 0;usW_C_i < usW_C_input_count;usW_C_i++){
		printf("%d\n", usW_D_agg[usW_C_i]);
	}
	
	return 0;
}



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

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

ch = [list(map(int, input().split())) for i in range(m)]

ans = []

for i, p in enumerate(st):
	l = 500000000
	ans.append(0)
	
	for j, d in enumerate(ch):
		if abs(p[0] - d[0]) + abs(p[1] - d[1]) < l:
			ans[i] = j + 1
			l = abs(p[0] - d[0]) + abs(p[1] - d[1])
		
		
for a in ans:
	print(a)

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

using namespace std;

int main()
{
	long long n, m;

	cin >> n >> m;

	if (n % 2 == 1) {
		int a = 1;
		for (int i = 0; i < m; i++) {
			cout << a << " " << n + 1 - a << endl;
			a++;
		}
		return 0;
	}

	int a = 1;
	int i = 0;
	for (i = 0; i < (m + 1) / 2; i++) {
		cout << a << " " << n + 1 - a << endl;
		a++;
	}

	for (; i < m; i++) {
		cout << a << " " << n - a << endl;
      	a++;
	}

}


Measured memory_bytes: 3604
//In The Name Of Godd
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef pair<double, double> dd;
typedef pair<dd, double> ddd;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<dd> vdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

#define forn(i, n) for (ll i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define inf 100000000000
#define eps 1e-9
const int maxv = 2e5, maxn = 101;
ll dp[2][maxv];
ll ww[maxn], v[maxn];

int main() {
  ll n, w; cin >> n >> w;
  ll al = 0;
  forn(i, n) cin >> ww[i] >> v[i], al += v[i];
  forn(i, 2) forn(j, maxv) dp[i][j] = inf;
  dp[0][0] = 0;
  forn(i, n + 1) if(i) {
    for(ll j = 0; j <= maxv; j++){
      ll ni = i % 2, oi = 1 - i % 2;
      dp[ni][j] = dp[oi][j];
      if(j >= v[i - 1]) dp[ni][j] = min(dp[oi][j - v[i - 1]] + ww[i - 1], dp[ni][j]);
    }
  }
  ll ans = -1;
  forn(i, al + 1) {
    int tod = n % 2;
    if(dp[tod][i] <= w) ans = i;
  }
  cout << ans << endl;

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
#define maxsize 1000005
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    float n;
    cin>>n;
    float p = 3.14159265359;
    printf("%.20f",2*p*n);
}


Measured memory_bytes: 3732
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().ToCharArray();

            var flag = false;
            for(var i = 0; i < 2; i++){
                if(n[i] == n[i + 1] && n[i] == n[i+2]){
                    flag = true;
                    break;
                }
            }

            if(flag){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int n;
    cin >> n;
    int value[25];

    REP(i, n) {
        scanf("%d", &value[i]);
    }

    int cost, ans = 0;
    REP(i, n) {
        scanf("%d", &cost);
        value[i] -= cost;
        if (value[i] > 0) ans += value[i];
    }

    OUT(ans);

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<bitset> 
#include<type_traits>
#include<numeric>
#include<array>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int mod = 1000000007;
const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
}

int N;
auto dp = make_vec<double>(310,310,310); 

// あと1枚がi種、あと2枚がj種、あと3枚がk種、
double solve(int i,int j,int k){
    if(dp[i][j][k]>=0) return dp[i][j][k];

    double ret = 0.0;
    if(i>0) ret += solve(i-1,j  ,k  ) * i;
    if(j>0) ret += solve(i+1,j-1,k  ) * j;
    if(k>0) ret += solve(i  ,j+1,k-1) * k;
    ret += N;
    ret *= 1.0 / (i+j+k);

    return dp[i][j][k] = ret;
}

int main(){

    cin >> N;
    fill_v(dp,-1);
    dp[0][0][0]=0;

    map<int,int> mp;
    REP(i,3) mp[i+1]=0;

    REP(i,N) {
        int tmp;cin >> tmp;
        mp[tmp]++;
    }

    printf("%.12f\n",solve(mp[1],mp[2],mp[3]));

    return 0;
}


Measured memory_bytes: 237568
def gauss(n):
    ans = int (n * (n + 1) / 2)
    return(ans) 

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

m = []
for i in range(n):
    a = gauss(p[i]) / p[i]
    m.append(a)

ans = 0
for i in range(k):
    ans += m[i]

b = ans
for i in range(k, n):
    b = b - m[i-k] + m[i]
    ans = max(b, ans)
    
print(ans)


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);


    ll h,w,k; cin>>h>>w>>k;

    vector<string> c(h);
    rep(i,h) cin>>c[i];

    ll cnt = 0;

    rep(ii,(1ll<<h)){
        rep(jj,(1ll<<w)){
            ll tmp = 0;
            rep(i,h){
                if(((ii>>i)&1) == 0) continue;
                rep(j,w){
                    if(((jj>>j)&1) == 0) continue;
                    if(c[i][j]=='#') tmp++;
                }
            }
            // cout<<tmp<<endl;
            if(tmp==k) cnt++;
        }
    }

    cout<<cnt<<endl;

    return 0;

}

Measured memory_bytes: 3628
/*
    WRITER:kakitamasziru
*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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 int INF = 1001001000;
const int MOD = 1000000007;
typedef pair<long,long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    //n!はi = 1;i<=nでする
    for (long long i = n-r+1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

int dp[11451];

int main() {
    int N,W;cin >> N >> W;
    vector<int> value(N);
    vector<int> weight(N);
    for(int i = 0;i<N;i++) cin >> value.at(i) >> weight.at(i);
    for(int j = 0;j<11451;j++) dp[j] = 0;

    for(int i = 0;i<=W;i++){
        for(int j = 0;j<N;j++){
            chmax(dp[i+weight.at(j)],dp[i]+value.at(j));
        }
    }
    int ans = 0;
    for(int i = 0;i<=W;i++){
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
    /*
    g++ abc.cpp
    ./a.out
    */
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n;
    int a[2010];
    memset(a, 0, sizeof(a));
    rep(i,0,1001) rep(j,0,1001) a[i+j]++;
    while(cin >> n) {
        int ans = 0;
        rep(i,0,2001) {
            if(0 <= n-i && n-i <= 2000) ans = ans + a[i] * a[n - i];
        }
        cout << ans << endl;
    }
    return 0;
}

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

int sumf(int x[],int n) {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += x[i];
    }
    return ans;
}

int main(void) {
    int n;
    int w[100];

    scanf("%d",&n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &w[i]);
    }
    int sum = sumf(w, n);

    int min= abs((sum - sumf(w, 1)) - sumf(w, 1));

    for (int i = 1; i <= n; ++i) {
        if (min > abs((sum - sumf(w, i)) - sumf(w, i))) {
            min = abs((sum - sumf(w, i)) - sumf(w, i));
        }
    }
    printf("%d", min);

    return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <cmath>
#include <cstddef>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>

template <typename T, typename F>
class SparseTable {
 private:
  const std::size_t n = 0;
  std::vector<std::vector<T>> table;
  std::vector<std::size_t> lookup;
  const F func;

 public:
  SparseTable(const std::vector<T>& vec, const F& func)
      : n(vec.size()), table(std::log2(n) + 1, std::vector<T>(vec)), lookup(n + 1, 0), func(func) {
    for (std::size_t k = 0; k + 1 < table.size(); k++) {
      for (std::size_t i = 0; i + (1 << k) < n; i++) {
        table[k + 1][i] = func(table[k][i], table[k][i + (1 << k)]);
      }
    }
    for (std::size_t i = 2; i < n + 1; i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  T query(std::size_t l, std::size_t r) const {  // [l, r)
    assert(l < r);
    std::size_t k = lookup[r - l];
    return func(table[k][l], table[k][r - (1 << k)]);
  }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (auto&& e : A) {
    std::cin >> e;
  }
  SparseTable st(A, [](int a, int b) { return std::gcd(a, b); });
  int res = std::max(st.query(1, N), st.query(0, N - 1));
  for (int i = 1; i < N - 1; i++) {
    res = std::max(res, std::gcd(st.query(0, i), st.query(i + 1, N)));
  }
  std::cout << res << '\n';
  return 0;
}


Measured memory_bytes: 11316
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];

    int ans = 0;
    while(true){
        bool flag = false;
        rep(i, n){
            if(a[i]%2 != 0 || a[i] == 0){
                flag = true;
                break;
            }
            a[i]/=2;
        }
        if(flag)break;
        ans++;
    }
    cout << ans;
}

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

using namespace std;

int main(void) {
	int num, i = 0, a;
	long long sumT = 0, sumF = 0, ansT = 0, ansF = 0;
	bool sig = true;
	cin >> num;
	for (; i < num; i++) {
		scanf("%d", &a);
		sumT += a;
		sumF += a;
		if (sig && sumT >= 0) {
			ansT += sumT + 1;
			sumT = -1;
		}
		else if (!sig && sumT <= 0) {
			ansT += 1 - sumT;
			sumT = 1;
		}
		if (!sig && sumF >= 0) {
			ansF += sumF + 1;
			sumF = -1;
		}
		else if (sig && sumF <= 0) {
			ansF += 1 - sumF;
			sumF = 1;
		}
		sig = !sig;
	}
	cout << min(ansT, ansF) << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;

import java.util.*;
import java.util.stream.LongStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /* 標準入力数値配列用 long */
    static long[] inputLongArr() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] longarray = new long[strarray.length];
        for (int i = 0; i < longarray.length; i++) {
            longarray[i] = Long.parseLong(strarray[i]);
        }
        return longarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }

    /*標準入力long*/
    static int inputInt() throws Exception {
        return Integer.parseInt(br.readLine());
    }




    public static void main(String[] args) throws Exception {
        // write your code here
        int n = inputInt();
        long [] al = inputLongArr();
        HashMap<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(al[i], map.getOrDefault(al[i], 0) + 1);
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            int cur = map.get(al[i]) + map.getOrDefault(al[i] - 1, 0) + map.getOrDefault(al[i] + 1, 0);
            max = Math.max(max, cur);
        }
        System.out.println(max);

    }

}



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

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

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> v(n), S(n+1, 0);
    ll s = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
        s += v[i];
        S[i+1] = s;
    }
    vector<ll> vv;
    for (int i = n; i > 0; --i) {
        for (int j = 0; j < n-i+1; ++j) {
            vv.emplace_back(S[j+i]-S[j]);
        }
    }
    ll res = 0;
    for (ll l = 60; l >= 0; --l) {
        ll x = res + (1LL << l);
        int z = 0;
        for (auto &&i : vv) {
            if((x & i) == x) z++;
        }
        if(z >= k) res += x - res;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 6260
// Aizu Vol-5 0517: Longest Steps
// 2017.8.30 bal4u@uu

#include <stdio.h>
#include <string.h>

char c[100005];

int main()
{
	int n, k, a;
	int i, f, w, w0, ans;

	while (scanf("%d%d", &n, &k) && n) {
		memset(c, 0, n+3), f = 0;
		while (k-- > 0) {
			scanf("%d", &a);
			if (a == 0) f = 1;
			else c[a] = 1;
		}
		for (ans = w0 = w = 0, i = 1; i <= n; i++) {
			if (c[i]) w++;
			else if (w > 0) {
				if (w0 + w + f > ans) ans = w0 + w + f;
				if (f && c[i+1]) w0 = w; else w0 = 0;
				w = 0;
			}
		}
		if (w0 + w + f > ans) ans = w0 + w + f;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 704
import sys
import fractions


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    m = 1
    for i in range(2, int(n ** 0.5) + 1):
        m = max(m, fractions.gcd(n, i))
    print(n // m + m - 2)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 67840
#include <bits/stdc++.h>
#define inf (long long)1e9
using namespace std;

template <class T>
struct SegmentTree {
  // 1-indexed
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int newn, F f, T t) : f(f), unit(t) {
    init(newn);
  }
  void init(int newn) {
    n = 1;
    while(n < newn) n <<= 1;
    dat.assign(n << 1, unit);
  }

  // "go up" process
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while(k >>= 1) {
      dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
  }
  // [a,b)
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for(int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) vl = f(vl, dat[l++]);
      if(r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

long long n, k;
vector<long long> a;

long long solve();

int main() {
  cin >> n >> k;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = inf, l = 0, r = 0;
  auto f = [](long long l, long long r) {
    return min(l, r);
  };
  SegmentTree<long long> rmq(1000000, f, 1000000);
  for(int i = 0; i < 1000000; ++i) rmq.update(i, 0);
  for(l = 0; l < n; ++l) {
    long long x;
    while(r < n && rmq.query(0, k) == 0) {
      x = rmq.query(a[r] - 1, a[r]);
      rmq.update(a[r++] - 1, 1 + x);
    }
    if(rmq.query(0, k) != 0) ans = min(ans, r - l);
    x = rmq.query(a[l] - 1, a[l]);
    rmq.update(a[l] - 1, x - 1);
  }
  return ans == inf ? 0 : ans;
}


Measured memory_bytes: 19976
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >>D;
  int E = A/D;
  if(A%D!=0){
    E++;
  }
  int F =C/B;
  if(C%B!=0){
    F++;
  } 
  if(E<F){
    cout<<"No"<<endl;
  }
  else {
    cout <<"Yes"<<endl;
  }
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
    int W,H,x,y,r;
    cin >>W>>H>>x>>y>>r;
    if(x-r>=0&&y-r>=0&&x+r<=W&&y+r<=H){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define rep(i, init, n) for (int i = init; i < n; i++)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define gcd __gcd
# define M_PI 3.14159265358979323846
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 4;
const ll MOD = 998244353;
bool visited[N];
vector<int> edge[N];
vector<int> conc[N];
int c = 0;

ll POW(ll base, ll exponent){
    ll result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % mod;
        exponent = exponent >> 1;
        base = (base * base) % mod;
    }
    return result;
}

ll Inv(ll x){
    return POW(x, MOD - 2);
}

void DFS(int src){
    visited[src] = 1;
    conc[c].pb(src);
    for(auto i : edge[src]){
        if(!visited[i]) DFS(i);
    }
}

void BFS(int s, vector<int> &d){
    d[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto to : edge[v]) {
            if (d[to] == N){
                d[to] = d[v] + 1;
                q.push(to);
            }
        }
    }
}

int main(){
    IOS
    int a, b, h, m;
    cin>>a>>b>>h>>m;
    double theta = 30 * h - (5.5 * m);
    if(theta < 0) theta = -1 * theta;
    double dist = a * a + b * b;
    dist -= 2 * a * b * cos(theta / 180 * M_PI);
    cout<<setprecision(13)<<sqrt(dist);
    return 0;
}

Measured memory_bytes: 8888
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll K;
    cin >> K;
    vector<ll> A(K,0);
    for(ll i=0;i<K;i++){
        cin>>A[i]
    ;}
    ll x=INF;
    for(ll i=0;i<K;i++){
        x=A[i]*(x/A[i])
    ;}
    if(x<2){
        cout<<-1<<endl;return 0;
    }
    ll L=1,R=INF;
    while(L+1<R){
        ll m=(L+R)/2;
        x=m;
        for(ll i=0;i<K;i++){
        x=A[i]*(x/A[i])
        ;}
        if(x>2)R=m;
        else L=m;
    }
    ll Max=L;

    L=1,R=INF;
    while(L+1<R){
        ll m=(L+R)/2;
        x=m;
        for(ll i=0;i<K;i++){
        x=A[i]*(x/A[i])
        ;}
        if(x>=2)R=m;
        else L=m;
    }
    ll Min=R;

    if(Min>Max){cout<<-1<<endl;return 0;}

    cout<<Min<<" "<<Max<<endl;

    return 0;
}


Measured memory_bytes: 1024
import collections
N = int(input())
a = list(map(int,input().split()))

cs = collections.Counter(a)
# print('cs:',cs)

out=0
for key in cs:
    # print( 'key,cs[key]:',key,cs[key])
    if cs[key] > key:
        out+= cs[key] - key
    elif cs[key] < key:
        out+= cs[key]
    # print('out:',out)

print(out)


Measured memory_bytes: 100468
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()
    A = LIST()

    W = sum(A)
    A = sorted(A, reverse=True)

    for i in range(M):
        if A[i] < W / (4*M):
            print("No")
            sys.exit()

    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3980
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    
    int N;
    cin >> N;
    long long A[N];
    for(int i=0;i<N;i++) cin >> A[i];
    sort(A,A+N);
    string out = "YES";
    for(int j=0;j<N;j++){
        if(A[j] == A[j+1]){
            out = "NO";
            break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(){
	int a, b, x;
	scanf("%d %d", &a, &b);
	if(b%a== 0){
	
		printf("%d\n", x=a+b);	
	}else if (b%a>0){
		printf("%d", x=b-a);
	}
		
	return 0;
}

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

using namespace std;
typedef long long ll;
bool valid(vector<ll> &A, vector<ll> &F, ll mid, ll K) {
	for (int i = 0; i < A.size(); i++) {
		ll max_A = mid / F[i];
		K -= max(0LL, A[i] - max_A);
		if (K < 0) {
			return false;
		}
	}
	return true;
}
int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	vector<ll> F(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> F[i];
	}
	sort(A.begin(), A.end());
	sort(F.rbegin(), F.rend());
	ll lo = 0, hi = 1e12, res;
	while (lo <= hi) {
		ll mid = lo + (hi - lo) / 2;
		if (valid(A, F, mid, K)) {
			res = mid;
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main() {
    string str;
    cin >> str;
    
    vector<char> ans;
    for(int i=0; i<str.size(); i++) {
        if(str[i]=='B') {
            if(ans.size()>0) {
                ans.erase(ans.end()-1);
            }
        } else {
            ans.push_back(str[i]);
        }
    }
    
    for(int i=0; i<ans.size(); i++) {
        cout << ans[i];
    }
    cout << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long A, B, C, K;

  std::cin >> A >> B >> C >> K;

  if (K % 2 == 0) {
    std::cout << A - B << std::endl;
  }
  else {
    std::cout << B - A << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	char s[10], string[10], c;
	int ii = 0;
	scanf("%s", s);
	for (int i = 0;i < sizeof(s);i++) {
		if (s[i] != 'B') {
			c = s[i];
			string[ii] = c;//フ対策
			ii++;
		}
		else {
			if (ii > 0) ii--;
		}
	}
	string[ii] = '\0';
	printf("%s\n", string);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	int x, t;
	cin >> x >> t;
	cout << max(0, x - t) << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++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 cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200001
const string alpha = "abcdefghijklmnopqrstuvwxyz";
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll k;
	cin >> k;
	string s;
	cin >> s;
	if (s.length() <= k)
		cout << s << END;
	else
	{
		loop(i, k)	cout << s[i];
		cout << "...\n";
	}


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

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

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

  rep(i, t.size()) {
    if (t.at(i) == '?') t.at(i) = 'D';
  }

  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3756
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char maze[][] = new char[H][W];
		for (int i = 0; i < H; i++) {
			char temp[] = sc.next().toCharArray();
			for (int j = 0; j < W; j++) {
				maze[i][j] = temp[j];
			}
		}
		int max = 0;
		Main main = new Main();
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (maze[i][j] == '.') {
					int m[][] = new int[H][W];
					m[i][j] = -1;
					Queue<Point> q = new ArrayDeque<Point>();
					Point p = main.new Point();
					p.x = i;
					p.y = j;
					q.add(p);
					while (q.isEmpty() != true) {
						Queue<Point> t = new ArrayDeque<Point>();
						while (q.isEmpty() != true) {
							p = q.poll();
							if (p.x - 1 >= 0) {
								if (maze[p.x - 1][p.y] == '.' && m[p.x - 1][p.y] == 0) {
									m[p.x - 1][p.y] = m[p.x][p.y] + 1;
									if (m[p.x - 1][p.y] == 0) {
										m[p.x - 1][p.y] = 1;
									}
									if (m[p.x - 1][p.y] > max) {
										max = m[p.x - 1][p.y];
									}
									Point po = main.new Point();
									po.x = p.x - 1;
									po.y = p.y;
									t.add(po);
								}
							}
							if (p.x + 1 < H) {
								if (maze[p.x + 1][p.y] == '.' && m[p.x + 1][p.y] == 0) {
									m[p.x + 1][p.y] = m[p.x][p.y] + 1;
									if (m[p.x + 1][p.y] == 0) {
										m[p.x + 1][p.y] = 1;
									}
									if (m[p.x + 1][p.y] > max) {
										max = m[p.x + 1][p.y];
									}
									Point po = main.new Point();
									po.x = p.x + 1;
									po.y = p.y;
									t.add(po);
								}
							}
							if (p.y - 1 >= 0) {
								if (maze[p.x][p.y - 1] == '.' && m[p.x][p.y - 1] == 0) {
									m[p.x][p.y - 1] = m[p.x][p.y] + 1;
									if (m[p.x][p.y - 1] == 0) {
										m[p.x][p.y - 1] = 1;
									}
									if (m[p.x][p.y - 1] > max) {
										max = m[p.x][p.y - 1];
									}
									Point po = main.new Point();
									po.x = p.x;
									po.y = p.y - 1;
									t.add(po);
								}
							}
							if (p.y + 1 < W) {
								if (maze[p.x][p.y + 1] == '.' && m[p.x][p.y + 1] == 0) {
									m[p.x][p.y + 1] = m[p.x][p.y] + 1;
									if (m[p.x][p.y + 1] == 0) {
										m[p.x][p.y + 1] = 1;
									}
									if (m[p.x][p.y + 1] > max) {
										max = m[p.x][p.y + 1];
									}
									Point po = main.new Point();
									po.x = p.x;
									po.y = p.y + 1;
									t.add(po);
								}
							}
						}
						q = t;
					}
				}
			}
		}
		System.out.println(max);
	}

	public class Point {
		int x;
		int y;
	}
}

Measured memory_bytes: 45520
#include <bits/stdc++.h>
using namespace std;
inline void chmin (int& a, int b) {
  if (a > b) a = b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> dat(n);
  for (int i = 0; i < n; i++) {
    cin >> dat[i].first;
    dat[i].second = i;
  }
  sort(dat.begin(), dat.end());
  vector<long long> ret(n);
  int mini = n;
  for (int i = n - 1; i >= 1; i--) {
    int crr = dat[i].first;
    int nxt = dat[i - 1].first;
    int ind = dat[i].second;
    chmin(mini, ind);
    ret[mini] += (long long)(crr - nxt) * (n - i);
  }
  ret[0] += (long long)dat[0].first * n;
  for (int i = 0; i < n; i++) {
    cout << ret[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 2688