akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


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

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a, b,c;

	cin >> a >> b >> c;

	cout << a[0] << b[1] << c[2];

	
	return 0;
}

Measured memory_bytes: 256
# D - Alter Altar
N = int(input())
c = input()
white_l = 0
red_r = 0
for i in range(N):
    if c[i]=='R':
        red_r += 1
ans = red_r
for i in range(N):
    if c[i]=='W':
        white_l += 1
    else:
        red_r -= 1
    ans = min(ans, max(red_r,white_l))
print(ans)

Measured memory_bytes: 69956
n = int(input())
list_S = []
for _ in range(n):
    list_S.append(input())

dic_S = dict()
set_S = set()
for s in list_S:
    if s in set_S:
        dic_S[s] += 1
    else:
        dic_S[s] = 1
        set_S.add(s)

list_ans = sorted(dic_S.items(), key=lambda x:x[1], reverse=True)
a = 0
ans = []
for i in range(len(list_ans)):
    l = list_ans[i]
    a = max(a, l[1])
    if a <= l[1]:
        ans.append(l[0])
ans.sort()
for s in ans:
    print(s)

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  rep(i, 2) rep(j, n) cin >> a[i][j];
  int ans = 0;
  rep(k, n) {
    int i = 0;
    int c = 0;
    rep(j, n) {
      c += a[i][j];
      if (j == k) c += a[++i][j];
    }
    ans = max(ans, c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  vector<vector<int>> A(3,vector<int>(3));
  cin>>A[0][0]>>A[0][1]>>A[1][1];
  A[2][0]=A[0][0]+A[0][1]-A[1][1];
  A[1][2]=A[0][0]+A[2][0]-A[1][1];
  A[2][2]=A[0][0]+A[0][1]-A[1][2];
  int n=A[0][0]+A[1][1]+A[2][2];
  A[0][2]=n-A[0][0]-A[0][1];
  A[1][0]=n-A[1][1]-A[1][2];
  A[2][1]=n-A[2][0]-A[2][2];
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++){
      cout<<A[i][j];
      if(j==2)
        cout<<endl;
      else
        cout<<' ';
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

    int s,w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int A[200001];
int cnt[200001];

int main()
{
	int N;

	cin >> N;
	repc(i, 2, N) cin >> A[i];

	repc(i, 2, N) cnt[A[i]]++;

	repc(i, 1, N) cout << cnt[i] << endl;

	return 0;
}


Measured memory_bytes: 5168
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    double R;
    cin >> R;
    const double pi = acos(-1.0);
    double d = 2 * pi * R;
    cout << setprecision(20) << fixed << d << endl;
    return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e3 + 5;
ll h , n;
int a[maxn] , b[maxn];
int dp[maxn * 20];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> h >> n;
	int mx = 0;
	for(int i =1; i <= n; ++i) {
		cin >> a[i] >> b[i];
		mx = max(a[i] , mx);
	}
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	dp[0] = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = a[i]; j < h + mx; ++j)
			dp[j] = min(dp[j] , dp[j - a[i]] + b[i]);
	int ans = 0x3f3f3f3f;
	for(int i = h; i < h + mx; ++i)
		ans = min(ans , dp[i]);
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 384
def print_array(a):
    s = str(a[0])
    for i in range(1,n):
        s += ' '+str(a[i])
    print(s)
    return 0
n = int(input())
a = list(map(int, input().split()))

print_array(a)

for i in range(1,n):
    v = a[i]
    j = i -1
    while(j>=0 and a[j]>v):
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    print_array(a)


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

int main(){
string S;
cin >> S;
if (S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]) cout <<"Yes";
else if (S[0]==S[2] && S[2]!=S[1] && S[1]==S[3]) cout <<"Yes";
else if (S[0]==S[3] && S[0]!=S[1] && S[1]==S[2]) cout << "Yes";
else cout << "No";
return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    stack = []
    for i in range(len(S)):
        stack.append(S[i])
        while len(stack) > 1 and "".join(stack[-2:]) == "ST":
            stack.pop()
            stack.pop()
        # print(stack)
    return len(stack)


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 53452
a=Array.new(12).map{Array.new(10,0)}
gets.to_i.times do
  x=gets.split.map &:to_i
  a[(x[0]-1)*3+x[1]-1][x[2]-1]+=x[3]
end
a.size.times do|i|
  a[i].each{|j|print" #{j}"}
  if (i+1)%3==0&&i+1<a.size then print"\n","#"*20 end
  print "\n"
end



Measured memory_bytes: 8892
# ABC137C - Green Bin
import sys
input = sys.stdin.readline

from collections import Counter


def main():
    N = int(input())
    A = Counter("".join(sorted(input())) for _ in range(N))
    ans = sum(i * (i - 1) // 2 for i in A.values())
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
    vector<string> l;

    int n, L;
    cin >> n >> L;

    string s;
    for(int i = 0; i < n; i++){
        cin >> s;
        l.push_back(s);
    }

    sort(l.begin(), l.end());

    for(string x : l)   cout << x;
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define reps(i, s, n) for (int i = (s); i < (n); ++i)
#define repse(i, s, n) for (int i = (s); i <= (n); ++i)
#define repsr(i, n, s) for (int i = (n); i >= (s); --i)
#define all(xs) (xs).begin(), (xs).end()
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;

int main() {
  int A, B, C; cin >> A >> B >> C;
  cout << min(B / A, C) << endl;
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
int main(){
    ll n;cin>>n;
    vl c(n);rep(i,n)cin>>c[i];
    sort(c.begin(),c.end());
    vector<mint> two(n+1);
    two[0]=1;
    mint ans=0;
    rep(i,n) two[i+1]=two[i]*2;
    rep(i,n){
        ll l=i,r=n-1-i;
        mint now=two[r];
        if(r!=0) now+=two[r-1]*r;
        now*=two[l];
        now*=c[i];
        ans+=now;
    }
    ans*=two[n];
    cout<<ans.x<<endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

#define ALL(a) a.begin(), a.end()

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n;
    cin >> n;
    int a[2][n];
    FOR_EX(i, 0, n)
    cin >> a[0][i];
    FOR_EX(i, 0, n)
    cin >> a[1][i];
    FOR_EX(i, 0, 2) {
        FOR_EX(j, 0, n) {
            if (i == 0 && j == 0) {
                continue;
            } else if (i == 0) {
                a[i][j] += a[i][j - 1];
            } else if (j == 0) {
                a[i][j] += a[i - 1][j];
            } else {
                a[i][j] += max(a[i - 1][j], a[i][j - 1]);
            }
        }
    }
    cout << a[1][n - 1] << endl;
}


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

int main(){
    int n; cin >> n;
    bool flg=true;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(x%2==0){
            if(x%3!=0 && x%5!=0){
                flg=false;
                break;
            }
        }
    }
    if(flg==true){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

const int N = 3000+1;
const int M = 6000+2;
ll dp[N][M];
int main(){
	IOS

	int n,t;
	cin>>n>>t;
	vp v(n);
	cin>>v;
	sort(all(v));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=t+v[i-1].fi-1;j++)
		{
			if(i==0||j==0)
			{
				dp[i][j]=0;
			}
			else if(v[i-1].fi>j)
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-v[i-1].fi]+v[i-1].se);
		}
	}
	
	ll ans=0;
 	for(int i=1;i<M;i++)
 		ans = max(ans,dp[n][i]);
 	cout<<ans<<endl;
	return 0;	
}

Measured memory_bytes: 140928
import collections, numbers
import random

def compute(array, window, maximize):
    if not isinstance(window, numbers.Integral):
        raise TypeError()
    if not isinstance(maximize, bool):
        raise TypeError()
    if window <= 0:
        raise ValueError("Window size must be positive")

    result = []
    deque = collections.deque()
    for i, val in enumerate(array):
        val = array[i]
        while len(deque) > 0 and ((not maximize and val < deque[-1]) or (maximize and val > deque[-1])):
            deque.pop()
        deque.append(val)

        j = i + 1 - window
        if j >= 0:
            result.append(deque[0])
            if array[j] == deque[0]:
                deque.popleft()
    return result


class SlidingWindowMinMax(object):

    def __init__(self):
        self.mindeque = collections.deque()
        self.maxdeque = collections.deque()

    def get_minimum(self):
        return self.mindeque[0]

    def get_maximum(self):
        return self.maxdeque[0]

    def add_tail(self, val):
        while len(self.mindeque) > 0 and val < self.mindeque[-1]:
            self.mindeque.pop()
        self.mindeque.append(val)

        while len(self.maxdeque) > 0 and val > self.maxdeque[-1]:
            self.maxdeque.pop()
        self.maxdeque.append(val)

    def remove_head(self, val):
        if val < self.mindeque[0]:
            raise ValueError("Wrong value")
        elif val == self.mindeque[0]:
            self.mindeque.popleft()

        if val > self.maxdeque[0]:
            raise ValueError("Wrong value")
        elif val == self.maxdeque[0]:
            self.maxdeque.popleft()

if __name__ == "__main__":
    n, l = (int(x) for x in input().split())
    array = list((int(x) for x in input().split()))

    answer = compute(array, l, False)
    print(*answer)



Measured memory_bytes: 122040
use std::io;

fn main() {
    let mut buf = String::new();

    // 1行目の読み込み
    io::stdin().read_line(&mut buf).expect("Failed to read line");
    let vec_1: Vec<&str> = buf.split_whitespace().collect();
    let n: i32 = vec_1[0].parse().unwrap_or(0);
    let k: i32 = vec_1[1].parse().unwrap_or(0);
    
    let mut d = k;
    let mut ans: u32 = 0;

    while d <= n {
        d = d * k;
        ans = ans + 1;
    };

    ans = ans + 1;

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	char s[100001];
	cin>>s;
	if(strlen(s)%2){
		if(s[0]==s[strlen(s)-1])
			cout<<"Second"<<endl;
		else
			cout<<"First"<<endl;
	}
	else{
		if(s[0]!=s[strlen(s)-1])
			cout<<"Second"<<endl;
		else
			cout<<"First"<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

#define N 310
ll n,m;
ll a[N][N];
bool th[N];
ll solve(){
    ll cnt[N];
    for(int i=0;i<m;i++){
	cnt[i]=0;
    }
    for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
	    if(th[a[i][j]]){
		cnt[a[i][j]]++;
		break;
	    }
	}
    }
    ll ma=-1,pnt=-1;
    for(int i=0;i<m;i++){
	if(cnt[i]>ma){
	    ma=cnt[i];
	    pnt=i;
	}
    }
    th[pnt]=0;
    return ma;
}
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
	    cin>>a[i][j];
	    a[i][j]--;
	}
    }
    for(int i=0;i<m;i++)th[i]=1;
    ll ans=1e17;
    for(int i=0;i<m;i++){
	chmin(ans,solve());
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=210;
const int mod=1000000007;
int n,m,k,first[maxn],nxt[maxn],to[maxn],e;
void AddEdge(int u,int v) {
	to[e]=v;nxt[e]=first[u];first[u]=e++;
	to[e]=u;nxt[e]=first[v];first[v]=e++;
}
int findset(int x,int* pa) {return x==pa[x]?x:pa[x]=findset(pa[x],pa);}
int pa[maxn],tree[maxn],cnt,sum[maxn],yes[maxn];
int vis[maxn],fa[maxn],dep[maxn],clo;
void merge(int x,int y) {
	sum[y]+=sum[x];yes[y]+=yes[x];
	pa[x]=y;
}
void dfs(int x,int la) {
	vis[x]=++clo;dep[x]=dep[fa[x]]+1;
	for(int i=first[x];~i;i=nxt[i]) if(i!=(la^1)) {
		if(!vis[to[i]]) fa[to[i]]=x,dfs(to[i],i);
		else if(vis[to[i]]<vis[x]) {
			int j=findset(x,tree);
			while(dep[j]>dep[to[i]]+1) {
				tree[j]=fa[j];
				merge(findset(j,pa),findset(fa[j],pa));
				j=findset(j,tree);
			}
			cnt++;pa[cnt]=cnt;sum[cnt]=yes[cnt]=1;
			merge(findset(j,pa),cnt);
		}
	}
}
int pw[maxn],inv[maxn],fac[maxn],ifac[maxn];
int S[maxn][maxn];
int gcd(int a,int b) {return !b?a:gcd(b,a%b);}
int C(int a,int b) {return (ll)fac[a]*ifac[b]%mod*ifac[a-b]%mod;}
void init() {
	pw[0]=inv[1]=fac[0]=ifac[0]=1;
	rep(i,1,m) pw[i]=(ll)pw[i-1]*k%mod;
	rep(i,2,m+k) inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	rep(i,1,m+k) fac[i]=(ll)fac[i-1]*i%mod,ifac[i]=(ll)ifac[i-1]*inv[i]%mod;
}
int main() {
	memset(first,-1,sizeof(first));
	n=read();m=read();k=read();
	rep(i,1,m) AddEdge(read(),read());
	init();
	rep(i,1,n) pa[i]=i,tree[i]=i,sum[i]=1;
	cnt=n;
	rep(i,1,n) if(!vis[i]) dfs(i,-1);
	int circle=0,complex=0,ans=1;
	rep(i,n+1,cnt) if(findset(i,pa)==i) {
		if(yes[i]!=1) {
			complex+=sum[i];
			ans=(ll)ans*C(sum[i]+k-1,k-1)%mod;
		}
		else {
			circle+=sum[i];
			int res=0;
			rep(j,0,sum[i]-1) (res+=pw[gcd(sum[i],j)])%=mod;
			res=(ll)res*inv[sum[i]]%mod;
			ans=(ll)ans*res%mod;
		}
	}
	rep(i,1,m-circle-complex) ans=(ll)ans*k%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Digit Sum 2
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 16;

/* typedef */

/* global variables */

int ds[MAX_N];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

inline int sumds(int n, int ds[]) {
  int sum = 0;
  for (int i = 0; i < n; i++) sum += ds[i];
  return sum;
}

/* main */

int main() {
  string s;
  cin >> s;
  int n = s.size();

  for (int i = 0; i < n; i++) ds[i] = s[i] - '0';
  int maxdsum = sumds(n, ds);

  for (int i = n - 1; i > 0; i--)
    if (ds[i] < 9) {
      ds[i] = 9;

      int k = i - 1;
      while (k >= 0) {
	if (--ds[k] >= 0) break;
	ds[k--] = 9;
      }
      if (k < 0) break;

      setmax(maxdsum, sumds(n, ds));
    }
  
  printf("%d\n", maxdsum);
  return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    llong N,A,B,na,nb;
    string S;
    cin >> N>>A>>B>>S;
    llong ans[N];
    nb=0;
    na=0;
    
    for(int i=0;i<N;i++){
        if(S[i]=='a'){
            if(na<(A+B)){
                ans[i]=1;
                na++;
            }else{
                ans[i]=0;
            }
        }else if((char)S[i]=='b'){
            if(na<(A+B) && nb<B){
                ans[i]=1;
                na++;
            }else{
                ans[i]=0;
            }
            nb++;
        }else{
            ans[i]=0;
        }
    }

    for(int i=0;i<N;i++){
        printf("%s\n",(ans[i]?"Yes":"No"));
    }
    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		m=max(m,a[2]);
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])puts("YES");
		else{
			if(m<11)puts("NO");
			else puts("YES");
		}
	}
}

Measured memory_bytes: 0
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int mi[200100];
int main()
{
	int n,h,w,x,y,now=1;
	cin>>h>>w>>n;
	rep(i,h+10) mi[i]=w+1;mi[h+1]=0;
	rep(i,n){
		cin>>x>>y;mi[x]=min(mi[x],y);
	}
	REP(i,2,h+10){
		if(mi[i]<=now){
			cout<<i-1<<endl;return 0;
		}
		now++;if(now==mi[i]) now--;
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int i=0, f=0;
    string s;
    cin >> s;
    while(s[i]!='\0'){
        if((i+1)%2==0){
            if(s[i]=='R') f=1;
        }
        else{
            if(s[i]=='L') f=1;
        }
        i++;
    }
    if(f==0) cout << "Yes" <<endl;
    else cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int sol = 0;
	for (int ii = 0; ii < 4; ++ii){
		if (S[ii] == '+'){
			sol++;
		} else {
			sol--;
		}
	}

	cout << sol << endl;

	return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>
int main(void){
int w,h,x,y,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
if(x-r<0||x+r>w||y-r<0||y+r>h){
	printf("No\n");
}else{
	printf("Yes\n");
}
return 0;
}

Measured memory_bytes: 584
from collections import Counter
N = int(input())
S = [str(input()) for _ in range(N)]

SC = Counter(S)
max_count = max(SC.values())

ans = []

for key,value in SC.items():
  if value == max_count:
    ans.append(key)

ans.sort()

for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 35568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

ll a[100005];

int sign(ll a)
{
	return (a > 0) - (a < 0);
}

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> a[i];
	}

	ll ans1 = 0, sum = 0;
	//! 奇数番目を-にする
	REP(i, N)
	{
		sum += a[i];
		if (i % 2 == 0 && sign(sum) != -1)
		{
			ll d = abs(sum);
			ans1 += d + 1;
			sum = -1;
		}
		else if (i % 2 == 1 && sign(sum) != 1)
		{
			ll d = abs(sum);
			ans1 += d + 1;
			sum = 1;
		}
	}
	ll ans2 = 0;
	sum = 0;
	//! 奇数番目を+にする
	REP(i, N)
	{
		sum += a[i];
		if (i % 2 == 0 && sign(sum) != 1)
		{
			ll d = abs(sum);
			ans2 += d + 1;
			sum = 1;
		}
		else if (i % 2 == 1 && sign(sum) != -1)
		{
			ll d = abs(sum);
			ans2 += d + 1;
			sum = -1;
		}
	}
	cout << std::min(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N;
   cin>>N;
   vector<double> A(N);
   for(int i=0;i<N;i++){
      cin>>A.at(i);
   }
   double total=0;
   
   for(int i=0;i<N;i++){
      total+=1/A.at(i);
   }
   cout<<1/total<<endl;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = sum(B)
for i in range(N-1):
    if A[i] == A[i+1]-1:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    for (int i = 0; ; i++) {
        if (7 * i > n) {
            break;
        }
        if ((n - 7 * i) % 4 == 0) {
            put("Yes");
            return 0;
        }
    }
    put("No")
    return 0;
}

Measured memory_bytes: 3572
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

constexpr ll ten(int n) {
  ll v = 1;
  for (int i = 0; i < n; i++) v *= 10;
  return v;
}

const ll INF = ten(18) + 10;

struct rational {
  ll n, d;

  rational()
      : n(0), d(1) {
  }
  rational(ll n_, ll d_)
      : n(n_), d(d_) {
    if (d < 0) {
      n = -n;
      d = -d;
    }
  }
  bool operator<(const rational& rhs) const {
    return n * rhs.d < rhs.n * d;
  }
};

ll solve(const vector<rational>& A, ll X) {
  int N = A.size();
  ll cnt = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A[i].n == 0) {
      if (X >= 0) {
        cnt += N - i - 1;
      }
      continue;
    }
    if (A[i].n < 0) {
      auto it = lower_bound(A.begin() + i + 1, A.end(), rational(X, A[i].n));
      cnt += distance(it, A.end());
    } else {
      auto it = upper_bound(A.begin() + i + 1, A.end(), rational(X, A[i].n));
      cnt += distance(A.begin() + i + 1, it);
    }
  }
  return cnt;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<rational> A(N);
    for (auto& x : A) cin >> x.n;
    sort(A.begin(), A.end());
    ll fail = -INF, pass = INF;
    while (pass - fail > 1) {
      ll X = (pass + fail) / 2;
      if (solve(A, X) >= K) {
        pass = X;
      } else {
        fail = X;
      }
    }
    cout << pass << endl;
  }
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

vector< int64_t > divisor(int64_t n) {
    vector< int64_t > ret;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

void solve() {
    int n; cin >> n;
    int counter = 0;
    for(int i = 1; i <= n; i++){
        if(i % 2 != 0){
            vector<int64_t> a = divisor(i);
            if(a.size() == 8) counter++;
        }
    }
    cout << counter << endl;
}

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

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


int main() {
	int n;
	vector<int> b;
	vector<int> a;
	int temp;
	bool check;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> temp;
		b.push_back(temp);
	}

	while (b.size() != 0) {
		check = false;
		for (int i = b.size() - 1; i >= 0; i--) {
			if (b[i] == i + 1) {
				b.erase(b.begin() + i);
				a.insert(a.begin(), i + 1);
				check = true;
				break;
			}
		}

		if (check == false) {
			break;
		}
	}

	if (check) {
		for (int i = 0; i < n; i++) {
			cout << a[i] << endl;
		}
	}
	else {
		cout << -1 << endl;
	}

	cin >> n;
}

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

int main()
{
    auto a = 0;
    while(cin>>a)
    {
        auto const h = a / 3600;
        auto s = a % 3600;
        auto const m = s / 60;
        s = s % 60;
        cout << h <<":" << m << ":" << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,c=0;
    scanf("%d",&N);
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            for(int k=0;k<N;++k){
                ++c;
            }
        }
    }
    printf("%d",c);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

int main(){
    int x; cin >> x;
    vector<int> ans;
    ans.push_back(1);

    for(int i=2; i*i<=x; ++i){
        int p = 2;
        while(pow(i, p) <= x){
            ans.push_back(pow(i, p));
            ++p;
        }
    }

    sort(ans.begin(), ans.end());
    cout << ans.back() << endl;

    return 0;
}

Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]int)
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		if m[a] > 0 {
			m[a] = 0
		} else {
			m[a]++
		}
	}

	ans := 0
	for _, v := range m {
		ans += v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    } 

    vl dp(k+1);  // dp[i] : 山に石がi個あるとき先手勝ちなら1,後手勝ちなら0
    rep(i, k+1) {  // 山に石がi個あるとき
        rep(j, n) {
            if(i - a[j] >= 0 && dp[i - a[j]] == 0) {  // 遷移先に後手勝ちがあれば先手勝ち
                dp[i] = 1;
            }
        }
    }
    
    if(dp[k] == 1) {
        out("First");
    }
    else {
        out("Second");
    }
    
    re0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    double b;
    double c = 0;
    Rep (i, N) {
        cin >> A[i];
        b = 1.0 / A[i];
        c += b;
    }

    cout << 1/c << endl;
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)

using namespace std;

const int N = 210;

int Begin[N], Next[N], to[N], e = 1;

void add(int u, int v) {
	to[++e] = v, Next[e] = Begin[u], Begin[u] = e;
}

typedef long long LL;

int n;
int dep;
int maxd[N];

void DFS(int o, int f, int d) {
	int deg = 0;
	for (int i = Begin[o]; i; i = Next[i]) {
		int u = to[i];
		if (u == f) continue;
		++deg;
		DFS(u, o, d + 1);
	}
	maxd[d] = max(maxd[d], deg);
	dep = max(dep, d);
}

int main() {

	scanf("%d", &n);
	For(i, 2, n) {
		int u, v;
		scanf("%d%d", &u, &v);
		add(u, v), add(v, u);
	}

	int minL = n;
	LL ans = 1e18;
	
	For(i, 1, n) {
		dep = 0;
		For(j, 1, n) maxd[j] = 0;
		DFS(i, 0, 1);

		LL ret = 1;
		Forr(j, dep - 1, 1) ret = ret * maxd[j];

		if (dep < minL || (dep == minL && ret < ans)) {
			minL = dep; ans = ret;
		}
	}

	For(i, 1, n - 1) {
		dep = 0;
		For(j, 1, n) maxd[j] = 0;

		int u = to[i << 1], v = to[i << 1 | 1];
		DFS(u, v, 1), DFS(v, u, 1);

		LL ret = 1;
		Forr(j, dep - 1, 1) ret = ret * maxd[j];
		ret <<= 1;

		if (dep < minL || (dep == minL && ret < ans)) {
			minL = dep; ans = ret;
		}
	}

	printf("%d %lld\n", minL, ans);

	return 0;
}

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

using namespace std;


string MapData[3];

void judge() {
	for (int i = 0; i < 3; i++) {
		//judgeByRow
		if (MapData[i][0] != '+' && MapData[i][0] == MapData[i][1] && MapData[i][1] == MapData[i][2]) {
			cout << MapData[i][0] << endl;
			return;
		}

		//judgeByCol
		if (MapData[0][i] != '+' && MapData[0][i] == MapData[1][i] && MapData[1][i] == MapData[2][i]) {
			cout << MapData[0][i] << endl;
			return;
		}
	}

	if (MapData[0][0] != '+' && MapData[0][0] == MapData[1][1] && MapData[1][1] == MapData[2][2]) {
		cout << MapData[0][0] << endl;
		return;
	}
	if (MapData[0][2] != '+' && MapData[0][2] == MapData[1][1] && MapData[1][1] == MapData[2][0]) {
		cout << MapData[0][2] << endl;
		return;
	}

	cout << "NA" << endl;
}

int main() {

	while (1) {
		cin >> MapData[0];
		if (MapData[0][0] == '0') {
			break;
		}
		cin >> MapData[1] >> MapData[2];

		judge();
	}
	return 0;
}


Measured memory_bytes: 2996
import collections
n = int(input())
a = list(map(int, input().split()))
d = set(a)
c = collections.Counter(a)
b = 0
for i in c:
	if c[i] >= 2:
		b += c[i]-1
if b%2 == 1:
	ans = len(d)-1
else:
	ans = len(d)
print (ans)

Measured memory_bytes: 24280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=10;
char s[N];
ll NN=123;
poly a,b;
void init(ll x){
	b.clear();
	while(x){
		b.pb(x%10);
		x/=10;
	}
	reverse(b.begin(),b.end());
}
bool check(ll x){
	init(x);
	int n=a.size(),m=b.size();
	if(x<=NN){
		For(i,0,min(n,m)-1){
			if(b[i]<a[i]) return 1;
			if(a[i]<b[i]) return 0;
		}
		return m<=n;
	}
	For(i,0,min(n,m)-1){
		if(b[i]<a[i]) return 0;
		if(b[i]>a[i]) return 1;
	}
	return m>n;
}
int cnt;
void query(ll x){
	// cnt++;
	// init(x);
	printf("? %lld\n",x);
	// if(check(x)) s[0]='Y';
	// else s[0]='N';
	// cout<<s[0]<<endl;
	fflush(stdout);scanf("%s",s);
}
int main(){
	// ll t=NN;
	// while(t) a.pb(t%10),t/=10;
	// reverse(a.begin(),a.end());
	ll alb=1;int pos=10;
	For(i,1,10){
		alb*=10;query(alb);
		if(s[0]=='N'){
			pos=i;break;
		}
	}
	ll ssw=0;
	For(i,1,pos){
		int ksg=-1;
		query(ssw*10+9);
		if(s[0]=='N'){
			int l=(i==1),r=8,mid,pos=9;
			while(l<=r){
				mid=l+r>>1;query(ssw*10+mid);
				if(s[0]=='N') r=(pos=mid)-1;
				else l=mid+1;
			}
			ksg=pos-1;
		}
		if(ksg==-1){
			if(i==1){
				query(1e9);
				if(s[0]=='Y'){
					ssw=1;break;
				}
				if(pos>=2) ssw=ssw*10+9;
				else{
					For(j,1,9){
						query(j*10);
						if(s[0]=='Y'){
							ssw=j;break;
						}
					}
					break;
				}
			}else{
				ll mjn=ssw;
				while(mjn<=1e9) mjn*=10;
				query(mjn);
				if(s[0]=='Y'){
					ssw*=10;break;
				}
				if(i==pos){
					For(j,1,9){
						query(ssw*100+j*10);
						if(s[0]=='Y'){
							ssw=ssw*10+j;break;
						}
					}
					break;
				}else ssw=ssw*10+9;
			}
		}else ssw=ssw*10+ksg;
	}
	// cout<<cnt<<endl;
	printf("! %lld",ssw);
}


Measured memory_bytes: 3836
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

using Point = complex<ll>;
using Line = pair<Point, Point>;
using Polygon = vector<Point>;
bool compare(const Point& a, const Point& b) { // x ascending order
  if (a.real() != b.real()) return a.real() < b.real();
  return a.imag() < b.imag();
};
ll dot(Point p, Point q) { return (conj(p) * q).real(); }
ll cross(Point p, Point q) { return (conj(p) * q).imag(); }

ll dist(Point& a, Point& b) {
  return abs(a.real() - b.real()) + abs(a.imag() - b.imag());
}

Polygon convex_hull(Polygon& ps) {
  sort(ps.begin(), ps.end(), compare);
  int n = (int)ps.size(), k = 0;
  Polygon res(n * 2);

  for (int i = 0; i < n; res[k++] = ps[i++])
    while (k >= 2 && cross(res[k - 1] - res[k - 2], ps[i] - res[k - 1]) <= 0)
      --k;

  for (int i = n - 2, t = k + 1; i >= 0; res[k++] = ps[i--])
    while (k >= t && cross(res[k - 1] - res[k - 2], ps[i] - res[k - 1]) <= 0)
      --k;

  res.resize(k - 1);
  return res;
}

ll caliper(Polygon& ps) {
  ps = convex_hull(ps);
  int n = (int)ps.size();
  if (n == 2) { return dist(ps[0], ps[1]); }

  int i = 0, j = 0;
  // j --> (x asc order) --> i
  for (int k = 0; k < n; ++k) {
    if (compare(ps[i], ps[k])) i = k;
    if (compare(ps[k], ps[j])) j = k;
  }

  int si = i, sj = j;
  ll res = 0;
  // rotate 180 degrees
  while (i != sj || j != si) {
    res = max(res, dist(ps[i], ps[j]));
    if (cross(ps[(i + 1) % n] - ps[i], ps[(j + 1) % n] - ps[j]) < 0) {
      i = (i + 1) % n;
    } else {
      j = (j + 1) % n;
    }
  }

  return res;
}

int main() {
  int n;
  cin >> n;
  ll x, y;
  Polygon ps(n);
  rep(i, 0, n) {
    cin >> x >> y;
    ps[i] = {x, y};
  }
  cout << caliper(ps) << '\n';
  return 0;
}

Measured memory_bytes: 12764
<?php 

fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));
$dis_li = array();
$sum_tmp = 0;
$min = 40**6;

for($i=-100;$i<=100;$i++){
	foreach($a_li as $a){
      $sum_tmp+=($a-$i)**2;
    }
  	$min = min($sum_tmp,$min);
  	$sum_tmp = 0;
}

echo $min;

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll=long long;
using P=pair<int,int>;

int main() {
    char str[222];
    scanf("%s",str);
    int n = strlen(str);
    for(int i=n-2; i; i-=2) {
        if(strncmp(str, str+i/2, i/2)==0){
            printf("%d\n" ,i);
            return 0;
        }
    }
    return 0;

}    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
  int a[n],ans=0;
  for (int i=0;i<n;i++){
  cin >> a[i];
  }
  for (int i=0;i<n;i++){
  	for(int j=0;j<n;j++){
    	ans = max (ans, abs (a[i]-a[j]) );
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            Map<Integer, Long> map = new HashMap<>();
            long sum = 0;
            for (int i = 0; i < N; i++)
            {
                int el = in.nextInt();
                map.put(el, map.getOrDefault(el, 0L) + 1);
                sum += el;
            }
            int Q = in.nextInt();

            while (Q-- > 0)
            {
                int B = in.nextInt();
                int C = in.nextInt();

                if (map.containsKey(B))
                {
                    long occ = map.get(B);
                    long term = B * occ;
                    sum -= term;
                    map.put(C, map.getOrDefault(C, 0L) + occ);
                    map.remove(B);
                    sum += occ * C;
                }
                out.println(sum);
            }
        }

    }
}



Measured memory_bytes: 55784
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll s[n];
	for(int i=0;i<n-1;i++){
		if(a[i]>=a[i+1]){
			s[i]=1;
		}
		else
			s[i]=0;
	}
	s[n-1]=0;
	ll c=0,maxe=-1e9;
	for(int i=0;i<n;i++){
		if(s[i]==1){
			c++;
		}
		else{
			maxe=max(maxe,c);
			c=0;
		}
	}
	cout<<maxe<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
 
int main()
{
  char S[128];
  scanf("%s", S);
 
  for (int i=0;; i++)
  {
    if (S[i] == '\0')
    {
      break;
    }    
    if (i%2==0 && S[i] == 'L')
    {
      printf("No\n");
      return 0;
    }
    else if (i%2==1 && S[i] == 'R')
    {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");
  return 0;  
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main(void){
    double x1, y1, x2, y2;
    cin >> x1 >> y1;
    cin >> x2 >> y2;
    double d = pow( (x1-x2),2 ) + pow ( (y2-y1),2 ) ;
    cout << fixed << setprecision(8) << sqrt (d);
    cout << endl;
 
}


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

int main(int argc, char const *argv[])
{
    int a,b,ans;
    char op;
    while(1) {
        cin >> a >> op >> b;
        if (op == '?') break;
        else if(op == '+') ans=a+b;
        else if(op == '-') ans=a-b;
        else if(op == '*') ans=a*b;
        else if(op == '/') ans=a/b;
        cout << ans << endl;

    }
    return 0;
}


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

ans=float('inf')
for i in range(h):
    ma=max(i*w,(h-i)*(w//2),(h-i)*(-(-w//2)))
    mi=min(i*w,(h-i)*(w//2),(h-i)*(-(-w//2)))
    ma2=max(i*w,((h-i)//2)*w,(-(-(h-i)//2))*w)
    mi2=min(i*w,((h-i)//2)*w,(-(-(h-i)//2))*w)
    
    ans=min(ans, ma-mi, ma2-mi2)
    
for i in range(w):
    ma=max(i*h,(w-i)*(h//2),(w-i)*(-(-h//2)))
    mi=min(i*h,(w-i)*(h//2),(w-i)*(-(-h//2)))
    ma2=max(i*h,((w-i)//2)*h,(-(-(w-i)//2))*h)
    mi2=min(i*h,((w-i)//2)*h,(-(-(w-i)//2))*h)
    
    ans=min(ans, ma-mi, ma2-mi2)
                    
print(ans)

Measured memory_bytes: 3064
N, Y = map(int, input().split())
x, y, z = -1, -1, -1
for i in range(N+1):
    for j in range(N+1-i):
        sum = 10000*i + 5000*j + 1000*(N-(i+j))
        if Y == sum:
            x = i
            y = j
            z = N - i - j

print("{} {} {}".format(x, y, z))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repm(i,m,n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
  int A, B;
  cin >> A >> B;
  
  cout << (A-1)*(B-1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	int AB, BC, CA;
	cin >> AB >> BC >> CA;
	int ans = AB * BC * CA / max({ AB,BC,CA }) / 2;
	cout << ans;
}

Measured memory_bytes: 256
#include <climits>
#include <cstdio>
#include <algorithm>

typedef long long LL;
const int N = 2e5 + 10;

LL x[N], s[N], X, ans = LLONG_MAX;
int n;

int main() {
	scanf("%d%lld", &n, &X);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &x[i]);
		s[i] = s[i-1] + x[i];
	}
	for (int k = 1; k <= n; ++k) {
		LL cur = 0, E = 3;
		for (int i = n; i > 0; i -= k) {
			cur += (s[i] - s[std::max(i-k, 0)]) * std::max(E, 5LL);
			E += 2;
			if (cur >= ans) {
				break;
			}
		}
		cur += X * (k + n); // 捡垃圾和倒垃圾的花费 
		if (cur < ans) ans = cur;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3328
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sm = sum(a)
for i in range(n):
    tmp = a[i]
    a[i] = max(a[i]-b[i], 0)
    b[i] -= tmp - a[i]
    a[i+1] = max(a[i+1]-b[i], 0)

print(sm - sum(a))

Measured memory_bytes: 18392
n = int(input())
li_a = list()
d_a = dict()

for _ in range(n):
    wk = int(input())
    li_a.append(wk)

    get = d_a.get(wk, 0)
    d_a[wk] = get + 1

li_top2 = sorted(d_a.keys(), reverse=True)[:2]

for i in range(n):
    val = li_a[i]

    if val not in li_top2:
        print(li_top2[0])
    else:
        if val == li_top2[0] and d_a.get(val, 0) == 1:
            print(li_top2[1])
        else:
            print(li_top2[0])


Measured memory_bytes: 19420