akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, H;
  cin >> N;

  int maxH = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> H;
    if (maxH <= H) ans++;
    maxH = max(maxH, H);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
#print(n)
l = []
for i in range(0,2*k): 
  #print('i:',i)
  A = list(map(int, input().split()))
  if i % 2 != 0:
    l.extend(A)
#print(l)
ans = n - int(len(set(l)))
print(ans)

Measured memory_bytes: 9220
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)__attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int compare_short(const void *a, const void *b){return *(short*)a - *(short*)b;}
int compare_long(const void *a, const void *b){if(*(long long int*)a - *(long long int*)b < 0){return -1;}else if(*(long long int*)a - *(long long int*)b > 0){return 1;}else{return 0;}}
short n, ans, i;
int a[100], x;
int main(){
 n = nextShort();
 x = nextInt();
 for(i=0; i<n; i++){
  a[i] = nextInt();
 }
 qsort(a, n, sizeof(int), compare_int);
 for(i=0; i<n-1; i++){
  if(x>=a[i]){ans++; x-=a[i];}
 }
 if(x==a[n-1]){ans++;}
 printInt(ans);
 println();
}


Measured memory_bytes: 128
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $k = <STDIN>);
my @que;
my $cnt;
for my $i (1..9) {
  push @que, $i;
  $cnt++;
  if ($cnt == $k) {
    say $i;
    exit;
  }
}
while (@que) {
  my $i = shift @que;
  if ($i % 10 == 0) {
    $cnt++;
    if ($cnt == $k) {
      say $i.'0';
      exit;
    }
    push @que, $i.'0';
    $cnt++;
    if ($cnt == $k) {
      say $i.'1';
      exit;
    }
    push @que, $i.'1';
  } elsif ($i % 10 != 0 && $i % 10 != 9) {
    $cnt++;
    if ($cnt == $k) {
      say $i.($i % 10 - 1);
      exit;
    }
    push @que, $i.($i % 10 - 1);
    $cnt++;
    if ($cnt == $k) {
      say $i.($i % 10);
      exit;
    }
    push @que, $i.($i % 10);
    $cnt++;
    if ($cnt == $k) {
      say $i.($i % 10 + 1);
      exit;
    }
    push @que, $i.($i % 10 + 1);
  } else {
    $cnt++;
    if ($cnt == $k) {
      say $i.'8';
      exit;
    }
    push @que, $i.'8';
    $cnt++;
    if ($cnt == $k) {
      say $i.'9';
      exit;
    }
    push @que, $i.'9';
  }
}

Measured memory_bytes: 6400
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
void solve() {
    int N,K;
    R(N,K);
    VI a(N);
    REP(i,N)R(a[i]);
    sort(ALL(a));
    int an=0;
    REP(i,K)an+=a[i];
    W(an);
}
int main(){
#define MULTITEST 0
#if MULTITEST    
    CASET{
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3784
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
1 < (I=(0..25).select{C[_1]==0}).size and S.each {|s;z|
  I.each {|i| if i!=(z||=i); s[z]<s[i] ? z = i+s[z]=0 : s[i]=0 end }
}
L,M,N = [-1]*27,3,5
def calc(d,n)
  s,x = S[d],0
  t = (0..25).map {s[_1] > 0 ? C[_1]*(d-L[_1])+s[_1] : 0}
  i = (0..25).max_by(M){t[_1]}.max_by {|i|
    next t[i]  if n == 0 || d+1 >= D || 0 == c=t[i]
    l,L[i] = L[i],d
    c += t[i] + (calc(d+1,n-1)>>5)
    L[i] = l
    x < c ? x=c : c
  }
  (x<<5) + i
end
D.times { p 1 + i=calc(_1,N)&31; L[i]=_1 }

Measured memory_bytes: 14872
#include<bits/stdc++.h>
using namespace std;
#define MN 1000000
#define mod 1000000007
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int f[MN+5],p[MN+5],inv[MN+5],Inv[MN+5],n,ans;
inline int C(int n,int m){return 1LL*p[n]*Inv[m]%mod*Inv[n-m]%mod;}
int main()
{
    n=read();p[0]=inv[0]=f[0]=Inv[0]=p[1]=inv[1]=1;
    for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<=n;++i) Inv[i]=1LL*inv[i]*Inv[i-1]%mod;
    for(int i=1,j=2;i<=n;++i,j=j*2%mod) f[i]=(j+mod-f[i-1])%mod;
    int pp=1LL*(mod+1)/3*inv[n]%mod;
    for(int i=2;i<=n+1;++i)  // G(n+1-i,i) -> C(n+1-i+i,i-1)
        ans=(ans+1LL*f[i-2]*C(n,i-1)%mod*pp%mod*inv[i-1])%mod;
    for(int i=1;i<n;++i) ans=1LL*ans*(mod+1)/3%mod;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 15872
#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)

using ll = long long;
#define INF 1e9

int main(){
  string s;
  cin >> s;
  REP(i, 4){
    cout << s[i];
  }
  cout << " ";
  FOR(i, 4, 12){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


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

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

  long long N = __gcd(A, B);
  int ans = 0;

  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      ans++;
      while (N % i == 0) N /= i;
    }
  }

  cout << ((N != 1) ? ans + 2 : ans + 1) << "\n";
}

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

int main(){
	
	string n; cin>>n;
	bool flg{};
	for(int i=0; i<3; i++){
		if(n.at(i)=='7') flg=1;
	}
	cout<<(flg?"Yes":"No")<<endl;
	
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;


int LiangJiaJun(){
    int a,b;
    cin>>a>>b;
    if(a+b==15)cout<<"+"<<endl;
    else if(a*b==15)cout<<"*"<<endl;
    else cout<<"x"<<endl;

    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = h.back() - h.front();
  for (int i = 0; i < n - k + 1; i++) ans = min(ans, h[i + k - 1] - h[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long
#define sz(x) (int)x.size()
#define d double
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n;
	cin >> n;
	if(n % 2)
		cout << ((d)(n / 2) + (d)1) / (d)n << endl;
	else
		cout << (d)(n / 2) / (d)n << endl;
	return 0;
}


Measured memory_bytes: 256
// I am Nothing, You Are Nothing!
// Krishna is Everything ...
// Jai Shree Krishna

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e3 + 5, mod = 1e9 + 7;

string str1, str2;
int dp[N][N];

int length_of_lcs(int i, int j) {
	if (i == str1.size() or j == str2.size())
		return 0;
	if (dp[i][j] != -1)
		return dp[i][j];
	int ans = INT_MIN;

	if (str1[i] == str2[j]) {
		ans = 1 + length_of_lcs(i + 1, j + 1);
	} else {
		ans = max(length_of_lcs(i, j + 1), length_of_lcs(i + 1, j));
	}
	return dp[i][j] = ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> str1 >> str2;
	memset(dp, -1, sizeof dp);
	int len = length_of_lcs(0, 0);

	string ans = "";
	int i = 0, j = 0;

	while (len > 0) {
		if (str1[i] == str2[j]) {
			ans += str1[i];
			len--, i++, j++;
		} else {
			if (dp[i][j + 1] > dp[i + 1][j]) {
				j++;
			} else {
				i++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define MAX 100000

int N;
string s;

char dp[MAX][4];

char rev( char c )
{
	if( c == 'S' ) {
		return 'W';
	}
	else {
		return 'S';
	}
}

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

	dp[N -1][0] = 'S';
	dp[0][0] = 'S';
	dp[N -1][1] = 'S';
	dp[0][1] = 'W';
	dp[N -1][2] = 'W';
	dp[0][2] = 'S';
	dp[N -1][3] = 'W';
	dp[0][3] = 'W';
	for( int i = 0; i < N; i++ ) {
		int next = i + 1;
		int pre = i - 1;
		if( i == 0 ) {
			pre = N - 1;
		}
		if( i == N - 1 ) {
			next = 0;
		}
		for( int j = 0; j < 4; j++ ) {
			if( s[i] == 'o' ) {
				if( dp[i][j] == 'S' ) {
					dp[next][j] = dp[pre][j];
				}
				else {
					dp[next][j] = rev( dp[pre][j] );
				}
			}
			else {
				if( dp[i][j] == 'S' ) {
					dp[next][j] = rev( dp[pre][j] );
				}
				else {
					dp[next][j] = dp[pre][j];
				}
			}
		}
	}
	int idx = -1;
	for( int j = 0; j < 4; j++ ) {
		int flag = 0;
		for( int i = 0; i < N; i++ ) {
			int next = i + 1;
			int pre = i - 1;
			if( i == 0 ) {
				pre = N - 1;
			}
			if( i == N - 1 ) {
				next = 0;
			}
			if( s[i] == 'o' ) {
				if( dp[i][j] == 'S' ) {
					if( dp[pre][j] != dp[next][j] ) {
						flag = 1;
						break;
					}
				}
				else {
					if( dp[pre][j] == dp[next][j] ) {
						flag = 1;
						break;
					}
				}
			}
			else {
				if( dp[i][j] == 'S' ) {
					if( dp[pre][j] == dp[next][j] ) {
						flag = 1;
						break;
					}
				}
				else {
					if( dp[pre][j] != dp[next][j] ) {
						flag = 1;
						break;
					}
				}
			}
		}
		if( flag == 0 ) {
			idx = j;
			break;
		}
	}

	if( idx < 0 ) {
		cout << -1 << endl;
	}
	else {
		for( int i = 0; i < N; i++ ) {
			cout << dp[i][idx];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 896
#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-1); i >= 0; --i)

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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int N;
double dp[305][305][305];
bool flg[305][305][305];

double f(int c1, int c2, int c3) {
    if (flg[c1][c2][c3]) return dp[c1][c2][c3];
    flg[c1][c2][c3] = 1;

    double res = 0, d = 1 - (double)(N-c1-c2-c3) / N;
    if (d == 0) return dp[c1][c2][c3] = 0;
    res += 1 / d;
    if (0 < c1) res += f(c1-1, c2, c3)   * c1/N / d;
    if (0 < c2) res += f(c1+1, c2-1, c3) * c2/N / d;
    if (0 < c3) res += f(c1, c2+1, c3-1) * c3/N / d;

    return dp[c1][c2][c3] = res;
}

int main(){
    cin >> N;

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    int c[3] = {0, 0, 0};
    for (int i : a) c[i-1]++;

    printf("%.10f\n", f(c[0], c[1], c[2]));
}

Measured memory_bytes: 246016
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;
using ll=long long;

#define PRI(n) cout << n <<endl;
#define PRI2(n, m) cout << n << " " << m << endl;
#define PRI3(n, m, o) cout << n << " " << m<< " " << o << endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REPInv(i, n)  for(int i = n-1; i >= 0; --i)

#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)
#define FORInv(i, t, n)  for(int i = t; i >= (int)n; --i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) FORInv (j, min(i, r), 1)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}

int N;
int A[110];

int main() {
    cin >> N;
    REP(i,N)cin >>A[i];
    ll ans = 1e18;
    FOR(i,-100,100){
        ll sum = 0;
        REP(j,N){
           sum += (i - A[j])*(i - A[j]);
        }
        if(ans>sum)ans = sum;
    }
    PRI(ans)
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,x,a,b,ans,t; 
int main ()
{
	cin>>n>>x;
	cin>>a;
	if(a>x)
	ans+=a-x, a=x;
	for(int i=2;i<=n;i++)
	{
		cin>>b;
		if(a+b>x)
		{
			t=a+b-x;ans+=t;b=b-t;
		}
		a=b;
	}
	cout<<ans;
    return 0;
}
   

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

const int INF = 1e7;
int dp[1<<16];
int t[16][17];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    while (cin >> N, N) {
        for (int i=0; i<N; ++i) {
            for (int j=0; j<N+1; ++j) {
                cin >> t[i][j];
            }
        }
        fill(dp, dp+(1<<16), INF);
        dp[0] = 0;
        for (int i=0; i<(1<<N); ++i) {
            for (int j=0; j<N; ++j) {
                if (i & (1<<j)) continue;
                int mn = t[j][0];
                for (int k=0; k<N; ++k) {
                    if (i & (1<<k)) {
                        mn = min(mn, t[j][k+1]);
                    }
                }
                dp[i|(1<<j)] = min(dp[i|(1<<j)], dp[i] + mn);
            }
        }
        cout << dp[(1<<N) - 1] << endl;
    }
    return 0;
}


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

int main(){
    int k;
    cin>>k;
    long long x=7%k;
    long long count=1;
    vector<bool> mod(k,false);
    while(1){
        if(x==0){
            cout<<count<<endl;
            return 0;
        }
        if(mod[x]==true){
            cout<<-1<<endl;
            return 0;
        }
        mod[x]=true;
        x=(x*10+7%k)%k;
        count++;
    }
}


Measured memory_bytes: 3704
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {

			String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			int n = sc.nextInt();
			String s = sc.next();
			StringBuilder sb = new StringBuilder();
			char[] c = s.toCharArray();
			for(int i = 0 ; i < s.length() ; i++) {
				int index = alpha.indexOf(c[i]);
				if(index + n <= 25) {
					sb.append(alpha.charAt(index + n));
				} else {
					sb.append(alpha.charAt(index + n - 26));
				}
			}

			System.out.println(sb.toString());

		}

	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
int main() {
	int n, k; std::cin >> n >> k;
	constexpr long long int mod = 1000000007;
	std::vector<long long int> values(n); for (auto& v : values) std::cin >> v;
	std::vector<long long int> plus, minus;
	for (const auto& v : values) {
		if (v > 0) {
			plus.push_back(v);
		}
		else if (v < 0) {
			minus.push_back(-v);
		}
	}
	const long long int plus_count = plus.size();
	const long long int minus_count = minus.size();
	if (plus_count + (minus_count / 2 * 2) >= k && ((k & 1) == 0 || plus_count > 0)) {
		std::sort(plus.rbegin(), plus.rend());
		std::sort(minus.rbegin(), minus.rend());
		plus.insert(plus.begin(), 1);
		minus.insert(minus.begin(), 1);
		std::vector<long double> plus_log, minus_log;
		for (const auto& v : plus) {
			plus_log.push_back(std::log((long double)v));
		}
		for (const auto& v : minus) {
			minus_log.push_back(std::log((long double) v));
		}
		for (auto i = 1; i < plus.size(); ++i) {
			plus[i] = plus[i] * plus[i - 1] % mod;
			plus_log[i] += plus_log[i - 1];
		}
		for (auto i = 1; i < minus.size(); ++i) {
			minus[i] = minus[i] * minus[i - 1] % mod;
			minus_log[i] += minus_log[i - 1];
		}
		long double max_log = 0;
		long long int max_mod = 1;
		for (auto i = 0; i < minus.size(); i += 2) {
			if (i > k) break;
			if (k - i >= plus.size()) continue;
			const auto log = minus_log[i] + plus_log[k - i];
			if (log > max_log) {
				max_log = log;
				max_mod = minus[i] * plus[k - i] % mod;
			}
		}
		std::cout << max_mod << '\n';
	}
	else {
		std::sort(values.begin(), values.end(), [](const long long int a, const long long int b) {return std::abs(a) < std::abs(b); });
		long long int max_mod = 1;
		for (auto i = 0; i < k; ++i) {
			max_mod = (mod + max_mod * values[i] % mod) % mod;
		}
		std::cout << max_mod << std::endl;
	}
}

Measured memory_bytes: 12180
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[10010],y[10010];
string s,str;
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>x[i];
    a+=x[i];
  }
  for(int i=0;i<n;i++){
    if(x[i]>(a-1)/(4*m)){
      b++;
    }
  }
  if(b>=m)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main() {
    int N;
    cin >> N;
    vector<int>L(N);
    for (int i = 0; i < N; i++) {
        cin >> L.at(i);
    }
    sort(L.begin(), L.end());
    int count = 0;

    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            int add = L.at(i) + L.at(j);
            int ok = j, ng = N;
            while (ng - ok > 1) {
                int mid = ok + (ng - ok) / 2;
                if (L.at(mid) < add) {
                    ok = mid;
                }
                else {
                    ng = mid; 
                }
            }
            count += ok - j;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3576
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

const int MAX_LEN = 6;
const int MAX_N = 40;
const int LIMIT = MAX_LEN * MAX_N;
const string INF(LIMIT, 'z');

struct edge {
	int to;
	string cost;
	edge(int t, const string& c):to(t), cost(c){}
};

bool to_goal[MAX_N];
vector<vector<edge> > es;

string dijkstra(int s, int g) {
	if(!to_goal[s])
		return "NO";

	typedef pair<string, int> P;
	const int n = es.size();
	vector<vector<string> > dist(n, vector<string>(LIMIT + MAX_LEN + 1, INF));
	dist[s][0] = "";
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(make_pair("", s));

	while(!que.empty()) {
		const string spell = que.top().first;
		const int v = que.top().second, len = spell.size();
		que.pop();

		if(dist[v][len] != spell)
			continue;

		if(len > LIMIT)
			return "NO";

		if(v == g)
			return spell;

		for(int i = 0; i < es[v].size(); ++i) {
			const edge& e = es[v][i];
			if(!to_goal[e.to])
				continue;

			const string next_spell = spell + e.cost;
			const int next_len = next_spell.size();
			if(dist[e.to][next_len] > next_spell) {
				dist[e.to][next_len] = next_spell;
				que.push(make_pair(next_spell, e.to));
			}
		}
	}

	return "NO";
}

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

	for(int n, a, s, g; cin >> n >> a >> s >> g, n;) {
		es.clear();
		es.resize(n);
		for(int i = 0; i < a; ++i) {
			int x, y;
			string lab;
			cin >> x >> y >> lab;
			es[x].push_back(edge(y, lab));
		}

		memset(to_goal, false, sizeof(to_goal));
		to_goal[g] = true;
		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j)
				for(int k = 0; k < (int)es[j].size(); ++k)
					if(to_goal[es[j][k].to])
						to_goal[j] = true;

		cout << dijkstra(s, g) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5416
#include <stdio.h>
#define N 100000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};
struct Node T[100000];
int C[100000];

void getDepth(int, int);

int main()
{
  int n, i, j, k, x, y, id, key, root;
  
  for( i=0 ; i<N ; i++ ){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }

  scanf("%d",&n);
  for( i=0 ; i<n ; i++ ){
    scanf("%d %d",&id,&key);
    for( j=0 ; j<key ; j++ ){
      scanf("%d",&x);
      if(j==0)
	T[id].left = x;
      else
	T[y].right = x;
      y = x;
      T[x].parent = id;
    }
  }

  for( i=0 ; i<n ; i++ )
    if(T[i].parent==NIL) root = i;

  getDepth(root,0);

  for( i=0 ; i<n ; i++ ){
    printf("node %d: parent = %d, depth = %d,",i,T[i].parent,C[i]);
    if(T[i].parent==NIL)
      printf(" root, [");
    else if(T[i].left==NIL)
      printf(" leaf, [");
    else
      printf(" internal node, [");
    
    k = T[i].left;
    for( j=0 ; k!=NIL ; j++){
      if(j!=0)printf(", ");
      printf("%d",k);
      k = T[k].right;
    }
    printf("]\n");
  }



  return 0;
}
void getDepth(int r, int d)
{
  C[r] = d;
  if(T[r].right!=NIL)
    getDepth(T[r].right,d);
  if(T[r].left!=NIL)
    getDepth(T[r].left,d+1);
}

Measured memory_bytes: 5292
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x,a,b;
  cin >>x>>a>>b;
  if (a>=b) {
    cout <<"delicious"<<endl;
  }
  else if (b-a<=x){
    cout <<"safe"<<endl;
  }
  else {
    cout <<"dangerous"<<endl;
  }
}

Measured memory_bytes: 256
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a,b in ab:
    if b <= m:
        ans += a*b
        m -= b
    elif b > m:
        ans += m * a
        break
print(ans)

Measured memory_bytes: 27536
n = int(input())

points = []
seen = []
find_time = []
end_time = []
for _ in range(n):
    input_text = list(map(int, input().split()))
    u, k, v_list = input_text[0], input_text[1], input_text[2:]
    seen.append(False)
    points.append(v_list)
    find_time.append(0)
    end_time.append(0)

count = [0]


def dfs(graph, v, count):
    seen[v] = True
    find_time[v] = count[0]
    for next_v in graph[v]:
        if seen[next_v - 1]:
            continue
        count[0] += 1
        dfs(graph, next_v - 1, count)
    count[0] += 1
    end_time[v] = count[0]


for index, seen_point in enumerate(seen):
    if seen_point:
        pass
    else:
        count[0] += 1
        dfs(points, index, count)
# print(find_time)
# print(end_time)


count = 1
for f, e in zip(find_time, end_time):
    print(count, f, e)
    count += 1



Measured memory_bytes: 5716
int main(int argc,const char * argv[])
{
    int H ,W,i,j;
    
    while(1) {
        scanf("%d %d",&H, &W);
        if(H == 0 && W == 0) {
            break;
        }
        
        for (j=1; j<=H; j++) {
            for(i=1; i<=W; i++) {
                if(j == 1 || j == H) {
                    printf("#");
                } else if (j !=1 && j !=H && i==1 || i==W) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll=long long;
using namespace std;
const ll mod=1e9+7;
ll a[220000];
main(){
  ll n,ans=1e16,tmp=0;
  cin>>n;
  rep(i,0,n){cin>>a[i];a[i]-=i;}
  sort(a,a+n);
  rep(i,a[n/2],a[n/2]+2){
    rep(j,0,n)tmp+=labs(a[j]-i);
    ans=min(ans,tmp);
  }
  cout<<ans;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
	int a[10000], b[10000];
	int sumA, sumB;
	int n;
	int i;
	
	sumA = 0;
	sumB = 0;
	
	while(1){
		scanf("%d", &n);
		
		if(n==0) break;
		
		for(i=0; i<n; i++){
			scanf("%d %d", a+i, b+i);
		}
		
		/*
		for(i=0; i<n; i++){
			printf("%d %d\n", a[i], b[i]);
		}
		*/
		
		for(i=0;i<n;i++){
			if(a[i] > b[i]) sumA += a[i]+b[i];
			if(a[i] < b[i]) sumB += a[i]+b[i];
			if(a[i] == b[i]){
				sumA += a[i];
				sumB += b[i];
			}
		}
		
		printf("%d %d\n", sumA, sumB);
		
		sumA = 0;
		sumB = 0;
		
	};
	
	return 0;
}

Measured memory_bytes: 676
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc138/tasks/abc138_d

#define maxN 300005

using Graph = vector<vector<int>>;
// Graph T = Graph(maxN);
Graph T;
ll cnt[maxN];

static void dfs(int p, int u) {

    for (int t : T[p]) {
        if (t == u) continue;
        cnt[t] += cnt[p];
        dfs(t, p);
    }

}

int main() {
    int N, Q; cin >> N >> Q;
    T = Graph(N+3);
    int a, b;
    REP(i, N-1) {
        cin >> a >> b;
        T[a].push_back(b);
        T[b].push_back(a);
    }

    int p, x;
    REP(i, Q) {
        cin >> p >> x;
        cnt[p] += x;
    }

    dfs(1, -1);

    REP(i, N) {
        if (i) cout << " ";
        cout << cnt[i+1];
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 24320
#!python3

def LI():
    return list(map(int, input().split()))

# input
N, M, K = LI()

MOD = 998244353
MAX = 10 ** 6
fac, finv, inv = [None] * MAX, [None] * MAX, [None] * MAX


def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = -inv[MOD%i] * int(MOD / i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def main():
    comb_init()
    pm = [None] * N
    pm[0] = 1
    for i in range(1, N):
        pm[i] = pm[i - 1] * (M - 1) % MOD
    
    ans = 0
    for k in range(K + 1):
        x = comb(N - 1, k) * M * pm[N - k - 1] % MOD
        ans = (ans + x) % MOD
    print(ans)
    

if __name__ == "__main__":
    main()


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

using namespace std;

#define ll long long

int main(){
    ll n,c=1;
    cin>>n;
    string s;
    cin>>s;
    for(ll i=0; i<n-1; i++){
        // for(ll j=i+1; j<n; j++){
            if(s[i]!=s[i+1]){
                c++;
            }

        
    }
    cout<<c<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 ll n, k, q;
 cin >> n >> k >> q;
 int a[n+1]={};
 for(int i=1;i<q+1;i++){
   int b;
   cin >> b;
   a[b]++;
 }
 
 for(int i=1;i<n+1;i++){
//   cout << q << " " << a[i] << " " << k << " ";
   if(q-a[i]-k>=0) cout << "No" << endl;
   else cout << "Yes" << endl;
 } 
 
 return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string s; int n,k; cin >> n >> k >> s;
    s[k-1] = s[k-1]-'A'+'a';
    cout << s << endl ; return 0;
}

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

int main(){
    //freopen("input.txt","r",stdin);    
    int n, q; cin>>n>>q;
    string s; cin>>s;
    s = ' ' + s;
    vector<int> dp(n + 1);
    dp[1] = 0;
    for(int i =2; i<=n; i++){
        if(s[i] =='C' && s[i-1] =='A'){
            dp[i] = dp[i-1] + 1;
        }
        else dp[i] = dp[i-1];
    }
    /*
    for(int i =1; i<=n; i++){
        cout<<dp[i]<<" ";
    }*/
    while(q--){
        int l, r; cin>>l>>r;
        cout<<dp[r] - dp[l]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	rep(i,4) cout<<s[i]; cout << ' '; rep(i,8) cout<<s[i+4];
	cout << endl;
	return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N;

    vector<double> vec(N);
    REP(i, N)
        cin >> vec.at(i);

    sort(vec.begin(), vec.end());
    double tmp =(vec.at(0)+vec.at(1))/2.0;
    REP(i,N-2){
        tmp = (vec.at(i+2) + tmp) / 2.0;
    }
    cout << setprecision(9) << tmp << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void){
    int W, H, x, y, r;
//???????????´??° WW???HH???xx???yy???rr ????????????????????§??????????????????????????????
//
    cin >> W >> H >> x >> y >> r;

    if(x+r > W || y+r > H || x+r <= 0 || y+r <= 0){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>

int main(){
    int a,b,c,ans;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b) a+=b,b=a-b,a-=b;
    if(c<a) ans=abs(b-a)+abs(a-c);
    else if(c>b) ans=abs(c-b)+abs(b-a);
    else ans=abs(b-c)+abs(c-a);
    printf("%d",ans);
    return 0;
}   

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <map>
#define S second

using namespace std;

typedef long long ll;

ll n;
ll a[100005];
map<ll, ll> ma;

bool f(ll p)
{
    ma.clear();
    ma[-1] = p;
    for(ll i = 0; i < n; i++)
    {
        auto t = ma.lower_bound(a[i]);
        if(t == ma.begin())
        {
            return false;
        }
        t--;
        (t->S)--;
        if((t->S) == 0) ma.erase(t);
        ma[a[i]]++;
    }
    return true;
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    ll lt = 1, rt = n, mid, ans;
    while(lt <= rt)
    {
        mid = (lt + rt) / 2;
        if(f(mid)) ans = mid, rt = mid - 1;
        else lt = mid + 1;
    }
    cout<<ans<<endl;
    return 0;
}


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


Measured memory_bytes: 128
// atcoder/abc122/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  int n;
  while (cin >> n) {
    const int A = 0;
    const int C = 1;
    const int G = 2;
    const int T = 3;

    const lli mod = 1e9 + 7;

    const int N = 100 + 5;
    const int M = 4;
    lli dp[N][M][M][M];
    fill(&dp[0][0][0][0], &dp[N - 1][M - 1][M - 1][M - 1] + 1, 0);
    dp[0][T][T][T] = 1;
    for (int i = 0; i < n; ++i) {
      for (int a = 0; a < M; ++a) {
        for (int b = 0; b < M; ++b) {
          for (int c = 0; c < M; ++c) {
            for (int d = 0; d < M; ++d) {
              if (b == A && c == G && d == C) continue;
              if (b == A && c == C && d == G) continue;
              if (b == G && c == A && d == C) continue;
              if (a == A && c == G && d == C) continue;
              if (a == A && b == G && d == C) continue;
              (dp[i + 1][b][c][d] += dp[i][a][b][c]) %= mod;
            }
          }
        }
      }
    }
    lli sum = 0;
    for (int i = 0; i < M; ++i) {
      for (int j = 0; j < M; ++j) {
        for (int k = 0; k < M; ++k) {
          (sum += dp[n][i][j][k]) %= mod;
        }
      }
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
class Range {
    using T = long long;
    class Iterator {
        T val, step, diff;
    public:
        Iterator(T v, T s, T d): val(v), step(s), diff(d) {}
        T operator*() { return val + diff; }
        bool operator!=(const Iterator &itr) { return step > 0 ? val < itr.val : val > itr.val; }
        Iterator operator++() { val += step; return *this; }
    };
    Iterator _begin, _end;
public:
    Range(T b, T e, T s, T d): _begin(b, s, d), _end(e, s, d) {
        if (s < 0) { _begin = Iterator(e - 1, s, d); _end = Iterator(b - 1, s, d); }
    }
    Range(T b, T e, T s): Range(b, e, s, 0) {}
    Range(T b, T e): Range(b, e, 1, 0) {}
    Range(T e): Range(0, e, 1, 0) {}
    Iterator begin() { return _begin; }
    Iterator end() { return _end; }
};
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    n %= 10;
    string ans = "hon";
    if (n == 0 || n == 1 || n == 6 || n == 8) {
        ans = "pon";
    }
    if (n == 3) {
        ans = "bon";
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3656
H, W, K = map(int,input().split())
a = [input() for _ in range(H)]

ans = 0

for cols in range(1 << H):
  for rows in range(1 << W):
    black = 0
    for i in range(H):
      if (cols >> i) & 1:
        continue
      for j in range(W):
        if (rows >> j) & 1:
          continue
        if a[i][j] == "#":
          black += 1
    if black == K:
      ans += 1

print(ans)
        

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<int> data(5);
	cin >> data[0];
	cin >> data[1];
	cin >> data[2];
	cin >> data[3];
	cin >> data[4];
	int Min = 10;
	int res = 0;
	for(int& time : data)
	{
		if(time % 10 == 0)
		{
			res += time;
		}
		else
		{
			res += ((time / 10) + 1) * 10;
			Min = min(Min, time % 10);
		}
	}
	if(Min != 10)
	{
		res = res - 10 + Min;
	}
	cout << res << endl;
	return 0;
}



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

int main(){
  int N;
  string S;
  cin >>N;
  cin >>S;
  if(S.size()%2 !=0){
    cout <<"No"<<endl;
  }
  else{
  	int count=0;
  	bool TF = true;
  	for(int i=0;i<S.size()/2;i++){
    	if(S.at(i)!=S.at(S.size()/2+i)){
      	TF=false;
      	break;
    	}
  	}
  	if(TF){
    	cout <<"Yes"<<endl;
    }
    else{
      cout <<"No"<<endl;
    }
  }
}


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

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

long euclidean_gcd(long a, long b) {
  if(a < b) return euclidean_gcd(b, a);
  long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(void){
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    long n = b-a+1;
    //modC=0
    long m1 = b/c-(a-1)/c;
    //modD=0
    long m2 = b/d-(a-1)/d;
    //modC*D=0
    long gcd_cd = euclidean_gcd(c, d);
    long cd = (c/gcd_cd)*gcd_cd*(d/gcd_cd);
    long m3 = b/cd-(a-1)/cd;
    cout << (n-m1-m2+m3) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll x=4*a*b,y=(c-a-b)*(c-a-b);
    if(c<a+b) cout<<"No";
    else
    {
        if(x<y) cout<<"Yes";
        else cout<<"No";
    }
}


Measured memory_bytes: 256
def resolve():
    a = []
    b = []
    for i in range(3):
        A, B = map(int, input().split())
        a.append(A)
        a.append(B)
    for j in range(1, 5):
        b.append(a.count(j))
    if b.count(2) == 2 and b.count(1) == 2:
        print("YES")
    else:
        print("NO")
resolve()

Measured memory_bytes: 9096
# coding=utf-8

def solve(i, m):
    global A
    if m == 0:
        ever_calc[i][m] = True
        return True
    elif m < 0:
        ever_calc[i][m] = False
        return False
    elif i == n:
        ever_calc[i][m] = False
        return False
    else:
        result = (solve(i+1, m) or solve(i+1, m-A[i]))
        ever_calc[i][m] = result
        return result

n = int(input())
A = tuple(map(int, input().split()))
q = int(input())
M = tuple(map(int, input().split()))
sum_A = sum(A)
ever_calc = [[None] * 2000 for i in range(n+1)]

for m in M:
    if m > sum_A:
        print('no')
    elif solve(0, m):
        print('yes')
    else:
        print('no')

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, k;
    cin >> a >> b >> k;
    int d = __gcd(a, b);
    vector<int> ds;
    for (int i = 1; i * i <= d; ++i) {
        if (d % i == 0) {
            ds.push_back(i);
            if (i != d/i) {
                ds.push_back(d/i);
            }
        }
    }
    sort(ds.begin(), ds.end(), [](int i, int j) { return i > j; });
    cout << ds[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		long top = N;
		long sum = 0;
		for (long i = 1; i <= N; i++) {
			long bottom = N / (i + 1);
			if (top == bottom) {
				break;
			}

			for (long j = top; j > bottom; j--) {
				long mod = N % j;
				if (mod == i) {
					sum += j;
				}
				if (mod >= i) {
					break;
				}
			}
			top = bottom;
		}
		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public char nextChar() throws IOException {
			return (char) skip();
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 23252
import itertools
n = int(input())
s = "".join([str(_) for _ in range(n)])
l = list(itertools.permutations(s, n))
x = []
y = []
for i in range(n):
  xi,yi = map(int,input().split())
  x.append(xi)
  y.append(yi)
c = 0.0
for j in l:
  for k in range(n-1):
    c += ((x[int(j[k])]-x[int(j[k+1])])**2 + (y[int(j[k])]-y[int(j[k+1])])**2)**0.5
print(c/len(l))

Measured memory_bytes: 13892
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

ans = ""
score = 0

for i, t in enumerate(T):
    if t == 'r':
        if i >= K and "p" == ans[-K]:
            ans += " "
        else:
            ans += 'p'
            score += P    

    elif t == 's':
        if i >= K and "r" == ans[-K]:
            ans += " "
        else:
            ans += 'r'
            score += R 
    else:
        if i >= K and 's' == ans[-K]:
            ans += " "
        else:
            ans += 's'
            score += S
print(score)                               

Measured memory_bytes: 3444