akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect

n,x=nii()
a=lnii()
a.sort()

b=[0]
for i in range(1,n+1):
  b.append(a[i-1]+b[i-1])
b=b[1:]

if b[-1]<x:
  print(n-1)
else:
  inx=bisect(b,x)
  print(inx)

Measured memory_bytes: 9232
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
const ll linf = 1LL << 60;
using namespace std;

vector<pair<int, int> > mp[2501];
vector<int> mp2[2501];
int N;
bool canGoN[2501]={false,};

int main() {
    ios::sync_with_stdio(false);
    int M,P,A,B,C;

    cin>>N>>M>>P;
    REP(i,0,M){
        cin>>A>>B>>C;
        mp[A-1].push_back(make_pair(B-1, -(C-P)));
        mp2[B-1].push_back(A-1);
    }

    queue<int> q;
    q.push(N-1);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        REP(i,0,mp2[now].size()){
            int next = mp2[now][i];
            if(canGoN[next])continue;
            canGoN[next]=true;
            q.push(next);
        }
    }

    vector<ll> upper(2501, linf);
    int s = 0;
    bool updated;
    upper[0] = 0;

    REP(i,0,N) {
        REP(here,0,N) {
            if(upper[here]==linf)continue;
            REP(j,0,mp[here].size()){
                int there = mp[here][j].first;
                int cost = mp[here][j].second;
                upper[there]=min(upper[there],upper[here]+cost);
            }
        }
    }
    canGoN[N-1]=true;
    ll last = upper[N-1];
    REP(here,0,N) {
        REP(j,0,mp[here].size()){
            if(upper[here]==linf||upper[mp[here][j].first]==linf)continue;
            int there = mp[here][j].first;
            int cost = mp[here][j].second;
            if(upper[there]>upper[here]+cost&&canGoN[there]){
                cout<<"-1";
                return 0;
            }
        }
    }
    cout << max(0LL,-upper[N-1]);

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  while(true){
    int mx,n;
    cin>>mx;
    if(!mx)break;
    cin>>n;
    vi d(n+2);
    d[0] = 0;
    d[n+1] = 0;
    REP(i,n) cin>>d[i+1];
    vi edges[n+2];
    vi revedges[n+2];
    // 0: begin
    // 1~n: land
    // n+1: end
    vector<bool> used(n+2,false);
    queue<int> Q;
    Q.push(0);
    used[0] = true;
    while(Q.size()){
      ll t = Q.front(); Q.pop();
      FOR(to,t+1,min<ll>(t+mx,n+1)+1){
        // to position to
        ll nxt = to + d[to];
        nxt = max<ll>(0,min<ll>(n+1,nxt));
        if(t == nxt)continue;
        edges[t].push_back(nxt);
        revedges[nxt].push_back(t);
        if(used[nxt])continue;
        if(nxt == n+1)continue;
        used[nxt] = true;
        Q.push(nxt);
      }
    }
    set<int> jun,gyaku;
    Q.push(0);
    jun.insert(0);
    while(Q.size()){
      int t = Q.front(); Q.pop();
      REP(i,edges[t].size()){
        int nxt = edges[t][i];
        if(jun.count(nxt))continue;
        jun.insert(nxt);
        Q.push(nxt);
      }
    }
    Q.push(n+1);
    gyaku.insert(n+1);
    while(Q.size()){
      int t = Q.front(); Q.pop();
      REP(i,revedges[t].size()){
        int nxt = revedges[t][i];
        if(gyaku.count(nxt))continue;
        gyaku.insert(nxt);
        Q.push(nxt);
      }
    }
    if(jun == gyaku){
      cout<<"OK"<<endl;
    }else{
      cout<<"NG"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1264
'use strict'
function Main(input) {
  let data = input.trim().split("\n");
  let info = data.shift();
  let slims = data[0];
  let ans = 1;
  for(let i = 0; i < info - 1; i++){
  	if(slims[i] != slims[i + 1]){
      ans++;
    }
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define ref(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef pair<int,int> P;

int a[20001],n;


int main()
{
    cin>>n;
    int ans=0;
    ref(i,150){
        int k=pow(i,2);
        ref(j,150){
            k+=pow(j,2);
            ref(t,150){
                k+=pow(t,2);
                if(k<=20000&&i+j>t&&i+t>j&&i<j+t)a[k]++;
                k-=pow(t,2);
            }
            k-=pow(j,2);
        }
    }
    ref(i,n) cout<<a[2*i]<<endl;

}


Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cstdio>

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main(){
    int N;
    
    while (1) {
        scanf("%d", &N);
        if (N == 0)
            break;
        vector< pair<int, int> > v;
        rep(i, N){
            int takara, bridge;
            scanf("%d%d", &takara, &bridge);
            v.push_back(make_pair(bridge, takara));
        }

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

        int amount = 0;
        int success = 1;
        rep(i, N){
            amount += v[i].second;
            if ( amount > v[i].first ){
                success = 0;
                break;
            }
        }

        printf(success ? "Yes\n" : "No\n");
    }
}

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

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

    int n, x;
    cin >> n >> x;
    vector<int> as(n);
    for (int i = 0; i < n; i++) cin >> as[i];

    long long ans = 0;
    if (as[0] > x) {
        ans += as[0] - x;
        as[0] = x;
    }
    for (int i = 1; i < n; i++) {
        if (as[i - 1] + as[i] > x) {
            int dif = as[i - 1] + as[i] - x;
            ans += dif;
            as[i] -= dif;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
    int i,n,sum=0;
    cin>>n;
    vector<int> l(123);
    for(i=0;i<n;i++)
        cin>>l[i];
    sort(l.begin(),l.end());
    sum=accumulate(l.begin(),l.end(),0);

    if(sum-l.back()>l.back()){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}
   

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 100000
#define NIL -1

int top=0, S[MAX];

int n;
int G[MAX][100];
int color[MAX];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

void dfs(int r, int c){
  int u, v, i;
  push(r);
  color[r] = c;
  while( top != 0 ){
    u = S[top];
    pop();
    for( i = 0 ; i < len(u) ; i++ ){
      v = G[u][i];
      if( color[v] == NIL ){
        color[v] = c;
        push(v);
      }
    }
  }
}

void assignColor(){
  int id=1, i, u;
  for( i = 0 ; i < n ; i++ ){
    color[i] = NIL;
  }
  for( u = 0 ; u < n ; u++ ){
    if( color[u] == NIL ) dfs(u, id++);
  }
}

int len(int s){
  int i;
  for( i = 0 ; i < MAX ; i++ ){
    if( G[s][i] == '\0' ) return i;
  }
}

int main(){
  int i, s, t, m, q;

  scanf("%d%d",&n,&m);

  for( i = 0 ; i < m ; i++ ){
    scanf("%d%d",&s,&t);
    G[s][len(s)] = t;
    G[t][len(t)] = s;
  }

  assignColor();

  scanf("%d",&q);

  for( i = 0 ; i < q ; i++ ){
    scanf("%d%d",&s,&t);
    if( color[s] == color[t] ){
      printf("yes\n");
    }
    else printf("no\n");
  }

  return 0;
}



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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m,k,i,j,a,b;
	cin >> n;
	ll f=0;
	for(i=0;i<801;i++)
	{
		a=i;
		for(j=-800;j<801;j++)
		{
			b=j;
			if(pow(i,5)-pow(j,5)==n)
			{
				f=1;
				break;
			}
		}
		if(f==1)
			break;
	}
	cout << a << " " << b << endl;
	return 0;
}

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

int main() {
  int H, W;
  while(true) {
    cin >> H >> W;
    if (H == 0 && W == 0) break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cout << '#';
      }
      cout << '\n';
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int h,w,n;
int x[200005],y[200005];
int p[200005];
set<pair<int,int> > s;

int main(){
	scanf("%d%d%d",&h,&w,&n);
	fore(i,0,n)scanf("%d%d",x+i,y+i),x[i]--,y[i]--,s.insert(mp(x[i],y[i]));
	int r=h;
	int l=0;
	fore(i,1,h){
		if(!s.count(mp(i,l+1)))l++;
		p[i]=l;
	}
	fore(i,0,n)if(x[i]&&p[x[i]-1]>=y[i])r=min(r,x[i]);
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 11904
C = 10** 9 + 7
n = int(input())
a = list(map(int, input().split()))

s = set()
result = [x for x in a if x in s or s.add(x)]
indices = [i for i, x in enumerate(a) if x == result[0]]

l = indices[0]+1
r = indices[1] +1

fact = [1]
for x in range(1, n+2):
	fact.append( (x * fact[x-1]) % C )
 
factinv = [1] * (n+2)
factinv[n+1] = pow(fact[n+1], C-2, C)
 
for x in range(n, -1, -1):
	factinv[x] = ( factinv[x+1] * (x+1) ) % C
 
def nCr(n,r):
    if n < 0 or r < 0 or n < r:
        return 0
    else:
        return ( fact[n] * factinv[r] * factinv[n-r] ) % C

for i in range(1, n+2):
    print( (nCr(n+1, i) - nCr(n-(r-l), i-1) ) % C )

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

int main() {
  int n;
  cin >> n;
  string ans = "Three";
  for (int i=0;i<n;i++) {
    string c;
    cin >> c;
    if (c == "Y") {
      ans = "Four";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll mod=1000000007;

using namespace std;

int main(){

    int n,cnt=0;
    cin>>n;
    char arr[n+1][n+1];

    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		cin>>arr[i][j];	
    	}
    }

   for(int k=0;k<n;k++){
   		bool chek=true;

   		for(int i=0;i<n;i++){
   			for(int j=0;j<n;j++){
   				if(arr[(i+k)%n][j]!=arr[(j+k)%n][i]){
   					chek=false;
   				}
   			}
   		}
   		if(chek)
   			cnt+=n;
   } 

   cout<<cnt;
  return 0;
}



Measured memory_bytes: 384
# ABC 85, C - otoshidama

def answer():
    n, y = map(int, input().split(' '))
    for i in range(n+1):
        for j in range(0, n-i+1):
            total = 10000 * i + 5000 * j + 1000 * (n-i-j)
            if total == y:
                return '{} {} {}'.format(i, j, n-i-j)


    return '{} {} {}'.format(-1, -1, -1)
print(answer())


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
# 標準入力の取得
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
A, B = [], []
for m in range(M):
    A_m, B_m = list(map(int, input().split()))
    A.append(A_m)
    B.append(B_m)

# 求解処理
observatory = [True for n in range(N)]
for A_m, B_m in zip(A, B):
    lower_observatory = int()
    if H[A_m-1] < H[B_m-1]:
        observatory[A_m-1] = False
    elif H[A_m-1] > H[B_m-1]:
        observatory[B_m-1] = False
    else:
        observatory[A_m-1] = False
        observatory[B_m-1] = False

result = sum(observatory)

# 結果出力
print(result)


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

int main(){
	int r,g,b,n;
	cin >> r >> g >> b >> n;
	int cnt=0;
	for(int i=0;i<=3000;i++){
		for(int j=0;j<=3000;j++){
			int a = n-i*r-j*g;
			if(a%b==0&&a>=0) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
#define MOD 1000000007
#define M 2005
using namespace std;

L pow_mod(L x,L k){
	L ans=1;
	while(k){
		if(k&1) ans=ans*x%MOD;
		x=x*x%MOD; k>>=1;
	}
	return ans;
}

L f[M*2][M*2]={0}; 
L a[M*M]={0},b[M*M]={0},n;
L fac[M*4]={0},invfac[M*4]={0};
L C(L n,L m){return fac[n]*invfac[m]%MOD*invfac[n-m]%MOD;}
signed main(){
	cin>>n;
	fac[0]=1; for(L i=1;i<M*4;i++) fac[i]=fac[i-1]*i%MOD;
	invfac[M*4-1]=pow_mod(fac[M*4-1],MOD-2);
	for(L i=M*4-2;~i;i--) invfac[i]=invfac[i+1]*(i+1)%MOD;
	for(L i=1;i<=n;i++){
		scanf("%lld%lld",a+i,b+i);
		f[M-a[i]][M-b[i]]++;
	}
	for(L i=1;i<M*2;i++)
	for(L j=1;j<M*2;j++)
	f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%MOD;
	L ans=0;
	for(L i=1;i<=n;i++)
		ans=(ans+f[a[i]+M][b[i]+M]-C((a[i]+b[i])<<1,a[i]<<1)+MOD)%MOD;
	cout<<ans*invfac[2]%MOD<<endl;
}

Measured memory_bytes: 133120
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rer(i,l,r) for(int(i)=(l); (i)<(r); ++(i))
#define rep(i,n) rer(i,0,n)
#define gnr(i,l,r) for(int (i)=(r)-1; (i)>=(l); --(i))
#define pri(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<(p).fi<<' '<<(p).se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  cin>>n; Int ans,mi=1e10,ma=0,mae=1e10;
  rep(i,n){
    cin>>x>>y;
    if(cmax(ma,x))mae=y;
    cmin(mi,x);
  }
  ans=mae+ma;
  END
}


Measured memory_bytes: 3556
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, W = map(int, input().split())
    w = [0]
    v = [0]
    for i in range(N):
        weight, value = map(int, input().split())
        w.append(weight)
        v.append(value)

    dp = [[0] * (W + 1) for _ in range(N + 1)]


    for i in range(1, N + 1):
        for j in range(1, W + 1):
            if j - w[i] < 0:
                dp[i][j] = dp[i - 1][j]
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i])
    # print(w, v, dp)
    print(dp[N][W])


if __name__ == "__main__":
    main()


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

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

    if(n[0]==n[1] && n[1]==n[2] || n[1]==n[2]&&n[2]==n[3]){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll K, N;
  //cin >> K >> N;
  cin >> K;
  N=50;
  //N=5;
  ll from = K/(N);
  ll exception = K/(N)+N-(K%(N));
  //cout << exception << endl;
  cout << N <<endl;
  FOR(i, from, from+N+1){
    if(i==exception)continue;
    cout << i << " ";
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def is_kaibun(s):
    #print("checking:", s)
    rev_s = ''.join(list(reversed(s)))
    #print(s, rev_s)
    return s == rev_s

def solve(S: str):
    if not is_kaibun(S):
        print(NO)
        return
    N = len(S)
    if N % 2 == 0:
        print(NO)
        return
    if not is_kaibun(S[0:(N-1)//2]):
        print(NO)
        return
    if not is_kaibun(S[(N+3)//2-1:]):
        print(NO)
        return

    print(YES)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  int n;
  cin>>n;

  string s;
  cin>>s;

  //赤を左に寄せる
  //左からと右から探す
  int64_t left=0,right=n-1;

  int64_t cnt=0;
  while(left<right){

    while(s.at(left)=='R'){
      left++;
      if(left==n-1)
        break;
    }

    while(s.at(right)=='W'){
      right--;
      if(left==0)
        break;
    }

    if(s.at(left)=='W' && s.at(right)=='R' && left<right){
      char wk=s.at(left);
      s.at(left)=s.at(right);
      s.at(right)=wk;
      cnt++;
    }
  }

  cout<<cnt<<endl;

	return 0;
}

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

using namespace std;

int N;
int P[20001];
int A[20001];
int B[20001];
int C[20001];

int main()
{
    scanf("%d", &N);
    for(int i=0; i<N; i++)
        scanf("%d", P+i), A[P[i]-1]=i;
    int x=0, y_old=1000000000;
    int minx=0x3f3f3f3f, miny=0x3f3f3f3f;
    for(int i=0; i<N; i++)
    {
        int y=A[i]-x;
        if(y>=y_old)
        {
            x+=y-y_old+1;
            y=A[i]-x;
        }
        B[i]=x;
        C[i]=y;
        minx=min(minx, x);
        miny=min(miny, y);
        x++;
        y_old=y;
    }
    for(int i=0; i<N; i++)
        printf("%d ", B[i]-minx+1);
    printf("\n");
    for(int i=0; i<N; i++)
        printf("%d ", C[i]-miny+1);
    printf("\n");
    return 0;
}


Measured memory_bytes: 896
//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define se second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;


int main()
{
	fast;
	
	string s;
	cin>>s;
	ll n=s.size();
	if(s[n-1]=='s')
	{
		cout<<s<<"es"<<endl;
	}
	else
	{
		cout<<s<<"s"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3648
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


n = int(input())  
if n == 1:
  print(0)
  quit()
soinsu = factorization(n)
ans = 0
for i in range(len(soinsu)):
  a = 1
  b = 2
  temp = soinsu[i][1]
  num = 0
  while a <= temp:
    a += b
    b += 1
    num +=1
  ans+=num
  
print(ans)


Measured memory_bytes: 9496
i[100012], d[100012],s,w,n,a,x,y;
main()
{
  for(w=scanf("%d",&n);a++<n;d[y]++)
      scanf("%d%d",&x,&y),i[x]++;
  for(a=2;a<=n+1;a++)
    {
      w+=i[a];
      if(w>=a)s=a-1;
      w-=d[a];
    }
  printf("%d\n",s);
  exit(0);
}

Measured memory_bytes: 1144
#include<iostream>
using namespace std;
int main() {
  int n, ans = 0;
  long long h,w,a,b;
  cin >> n >> h >> w;
  for(int i = 0; i < n; i++){
    cin >> a >> b;
    if(a >= h && b >= w) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    string s, t;
    cin >> s >> t;
    if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
s = input()
t = input()

DP = [[0 for i in range(len(s)+1)] for i in range(len(t)+1)]
ans = ''
for i in range(len(t)):
    for j in range(len(s)):
        if t[i] == s[j]:
            DP[i+1][j+1] = DP[i][j]+1
        else:
            DP[i+1][j+1] = max(DP[i][j+1],DP[i+1][j])

i = len(t)
j = len(s)
ans = ''
while i>=0 and j>=0:
    if DP[i][j] == DP[i-1][j]:
        i -= 1
    elif DP[i][j] == DP[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans = ans + t[i]
ans = ans[::-1]
print(ans)

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    vector<i64> A(N);
    REP(i, N) cin >> A[i];

    i64 cnt = 0;
    unordered_map<i64, i64> L;
    REP(i, N) {
        cnt += L[i - A[i]];
        L[A[i] + i]++;
    }

    cout << cnt << endl;
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,M,K;
int C[111111];
signed main(){
    cin>>N>>M>>K;
    rep(i,N)cin>>C[i],C[i]--;

    UnionFindTree uf(N+K);

    vector<tuple<int,int,int>>es;
    rep(i,N)if(C[i]>=0)es.pb(make_tuple(0,i,N+C[i]));
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        es.pb(make_tuple(c,a,b));
    }
    sort(all(es));

    vint lis;
    int ans=0;
    for(auto &w:es){
        int c,a,b;
        tie(c,a,b)=w;
        if(uf.areSame(a,b))continue;
        ans+=c;
        uf.unite(a,b);
        lis.pb(c);
    }


    int f=0;
    rep(i,N)if(C[i]<0)f++;

    if(f+lis.size()<N+K-1){
        cout<<-1<<endl;
        return 0;
    }

    while(lis.size()&&f+lis.size()-1>=N+K-1){
        ans-=lis.back();
        lis.pop_back();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 13676
import java.util.*;

public class Main {
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Integer[] d = new Integer[n];
        for(int i = 0; i < n; i++) d[i] = scan.nextInt();
        Arrays.sort(d, Comparator.reverseOrder());
        int out = 1;
        for(int i = 0; i < n - 1; i++){
            if(d[i] > d[i + 1]){
                out++;
            }
        }
        System.out.println(out);
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 35932
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	llint n,A,B;cin>>n>>A>>B;
	if(A>B){swap(A,B);}
	if(A%2==B%2){cout<<(B-A)/2<<endl;}
	else{
		llint ans=(A+B)/2;
		A=n+1-A;B=n+1-B;swap(A,B);
		chmin(ans,(A+B)/2);
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
ll n,sum=0,resum,ensum=0,ans=0;
std::vector<ll> a;
int main(){
  cin >> n;
  a.resize(n);
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  resum = sum; int most=INT_MAX;
  for (int i = 0; i < n-1; i++) {
    resum -= a[i]; ensum += a[i];
    if(abs(resum-ensum) < most){
      most = abs(resum-ensum);
    }
  }
  cout << most << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String S=gs();
        
        int b=Integer.parseInt(S.substring(0,2));
        int a=Integer.parseInt(S.substring(2,4));

        //System.out.print(v);

        if (b>=1 && b<=12) {
        	if(a>=1 && a<=12) {
        	    System.out.println("AMBIGUOUS");
        	} else {
        		System.out.println("MMYY");
        	}
        }else {
        	if(a>=1 && a<=12) {
        	    System.out.println("YYMM");
        	} else {
        		System.out.println("NA");
        	}
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  long long N;
  cin >>N;
  vector<long long> F;
  for(long long A=1;A<=sqrt(N);A++){
    if(N%A==0){
      long long B=N/A;
      string S=to_string(B),D=to_string(A);
      F.push_back(max(S.size(),D.size()));
    }
  }
  sort(F.begin(),F.end());
  cout << F.at(0) << endl;
      
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
from operator import itemgetter
n=int(input())
l=[]
for i in range(n):
    a,b=map(str,input().split(" "))
    l.append((a,int(b),i+1))

c=sorted(l,key=itemgetter(1),reverse=True)
d=sorted(c,key=itemgetter(0))
for i in range(n):
    print(d[i][2])

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll px[100], py[100];
ll cx[100], cy[100];
ll cost(ll p, ll c){
    return abs(px[p] - cx[c]) + abs(py[p] - cy[c]);
}

int main(){

    ll N, M;
    cin >> N >> M;
    rep(i, N)cin >> px[i] >> py[i];
    rep(i, M)cin >> cx[i] >> cy[i];
    rep(i, N){
        ll ans = 0;
        rep(j, M)if(cost(i, ans) > cost(i, j))ans = j;
        cout << ans + 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
typedef long long ll;
const ll mod=1e9+7;
ll n,cnt[65];
void via(ll x){
	int p=0;
	while(x){
		if(x%2)cnt[p]++;
		x>>=1;p++;
	}
}
ll C(ll x){
	return x*(x-1)/2;
}
int main(){
	cin>>n;ll sum=0;
	for(ll i=1;i<=n;i++){
		ll x;cin>>x;
		via(x);
	}
	ll tmp=0,j=1;
	for(ll i=0;i<=62;i++){
			tmp+=(cnt[i]*(n-cnt[i])%mod*((j)%mod))%mod;
			tmp%=mod;j*=2;
	}
	cout<<tmp<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int h,w,i,j;
    while(1)
    {
     scanf("%d%d",&h,&w);
     if(h==0&&w==0)
        break;
     for(i=1;i<=h;i++)
     {
         for(j=1;j<=w;j++){
                if(i==1||i==h||j==1||j==w)
            printf("#");
         else
            printf(".");
     }
        printf("\n");
    }
    printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2096
N = int(input())

H = list(map(int, input().split()))

m = [[0 for _ in range(max(H) + 1)] for _ in range(N)]

for i in range(N):
    for j in range(H[i]):
        m[i][j] = 1

c = 0
for j in range(max(H)):
    prev = 0
    for i in range(N):
        if prev == 0 and m[i][j] == 1:
            c += 1
        prev = m[i][j]

print(c)


Measured memory_bytes: 39536
#include <iostream>

using namespace std;

int N, K, a, b;
int ans;

int main() {
    cin >> N >> K;
    while (K--) {
        cin >> a >> b;
        if (--a > N / 2 - 1) a = N - a - 1;
        if (--b > N / 2 - 1) b = N - b - 1;
        cout << min(a, b) % 3 + 1 << endl;
    }
}


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

#undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int N;
double dp[3000][3000];
vector<double> p, q, r;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  cin >> N;
  for (int i = 0; i < N; i++) {
    double d;
    cin >> d;
    p.push_back(d);
    q.push_back(1 - d);
  }
  dumpv(p);
  dumpv(q);
  dp[0][0] = p[0];
  dp[1][0] = q[0];
  dumpv(dp, N, N);
  for (int i = 1; i < N; i++) {
    dp[0][i] = dp[0][i - 1] * p[i];
    for (int j = 1; j <= i + 1; j++) {
      dp[j][i] += dp[j - 1][i - 1] * q[i];
      dp[j][i] += dp[j][i - 1] * p[i];
    }
    dumpv(i, dp, N, N);
  }
  double ans = 0.0;
  for (int i = 0; i < (N + 1) / 2; i++) {
    ans += dp[i][N - 1];
    dump(ans);
  }
  printf("%.10f\n", ans);
  // ans = 0.0;
  // for (int i = 0; i < N; i++) {
  //   ans += dp[i][N - 1];
  // }
  // dump(ans);
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector <char> arr(n);
  rep(i, n) cin >> arr[i];
  bool yellow = false;
  rep(i, n) {
    if (arr[i] == 'Y') {
      yellow = true;
    }
  }
  if (yellow) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));

    unordered_map<int, int> b, cou;
    rep(i, n) {
        b[a[i]] = 1;
    }

    rep(i, n) {
        if(b[a[i]] == 0) continue;
        cou[a[i]]++;
        if(cou[a[i]] == 2) {
            b[a[i]] = 0;
        } else if(cou[a[i]] == 1) {
            for(ll j = 2; j*a[i] < 1000010; ++j) {
                if(b.count(j*a[i])) b[j*a[i]] = 0;
            }
        }
    }

    int ans = 0;
    for(P x:b) {
        ans += x.second;
    }

    cout << ans << endl;
}

Measured memory_bytes: 20660
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.math, std.typecons;

  int n, z, w; rd(n, z, w);
  auto a=readln.split.to!(int[]);

  auto mm=new int[][](n, 2);
  foreach(i; 0..n) fill(mm[i], -1);
  int f(int i, int t, int x, int y){
    if(i==n) return (x-y).abs;
    if(mm[i][t]>=0) return mm[i][t];
    int ret;
    if(t){
      ret=-1;
      foreach(j; i..n) ret=max(ret, f(j+1, t^1, a[j], y));
    }else{
      ret=1_000_000_000+1;
      foreach(j; i..n) ret=min(ret, f(j+1, t^1, x, a[j]));
    }
    return mm[i][t]=ret;
  }

  writeln(f(0, 1, z, w));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 2684
N, K = map(int,input().split())
P = list(map(int,input().split()))
Ex = [0 for _ in range(N)]
for i in range(N):
    Ex[i] = P[i]*(P[i]+1)/(2*P[i])
wa = 0
for i in range(K):
    wa += Ex[i]
maxi = wa
for i in range(N-K):
    wa = wa - Ex[i] + Ex[K+i]
    maxi = max(maxi,wa)
print(maxi)

Measured memory_bytes: 24812
#include "bits/stdc++.h"
using namespace std;

long long INF = 1000000000000000;
long long MAXW = 100000;

int main() {
	long long N, Q;
	cin >> N;
	vector<long long> V(1 << 18), W(1 << 18);
	for (int i = 1; i <= N; i++) cin >> V[i] >> W[i];
	for (int i = N + 1; i < 1 << 18; i++) V[i] = 0, W[i] = 0;
	N = 1 << 18;
	vector<vector<long long> > DP1(256, vector<long long>(MAXW + 1, 0));
	for (int i = 256; i < 512; i++) {
		for (int j = 0; j < 512; j++) {
			int I = i, J = j;
			long long VC = 0, WC = 0;
			for (int k = 0; k < 9; k++) {
				if (J % 2 == 1) VC += V[I], WC += W[I];
				I /= 2, J /= 2;
			}
			if (WC <= MAXW) DP1[i - 256][WC] = max(DP1[i - 256][WC], VC);
		}
		for (int j = 0; j < MAXW; j++) {
			DP1[i - 256][j + 1] = max(DP1[i - 256][j + 1], DP1[i - 256][j]);
		}
	}
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		long long v, L;
		cin >> v >> L;
		if (v < 512) {
			vector<pair<long long, long long> > P;
			int w = v;
			while (w >= 1) {
				P.push_back({ V[w], W[w] });
				w /= 2;
			}
			long long ANS = 0;
			for (int j = 0; j < 1 << P.size(); j++) {
				int J = j;
				long long VC = 0, WC = 0;
				for (int k = 0; k < P.size(); k++) {
					if (J % 2 == 1) VC += P[k].first, WC += P[k].second;
					J /= 2;
				}
				if (WC <= L) ANS = max(ANS, VC);
			}
			cout << ANS << endl;
		}
		else {
			vector<pair<long long, long long> > P;
			int w = v;
			while (w >= 512) {
				P.push_back({ V[w], W[w] });
				w /= 2;
			}
			w -= 256;
			long long ANS = 0;
			for (int j = 0; j < 1 << P.size(); j++) {
				int J = j;
				long long VC = 0, WC = 0;
				for (int k = 0; k < P.size(); k++) {
					if (J % 2 == 1) VC += P[k].first, WC += P[k].second;
					J /= 2;
				}
				if (WC <= L) ANS = max(ANS, VC + DP1[w][L - WC]);
			}
			cout << ANS << endl;
		}
	}
}

Measured memory_bytes: 208920
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main implements Runnable {

	public static void main(String[] args) {

		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

	}

	@Override
	public void run() {
		exec();
	}

	private void exec() {

		FastScanner sc = new FastScanner(System.in);
		String s = sc.next();
		if(s.equals("Sunny")) {
			System.out.println("Cloudy");
		} else if(s.equals("Cloudy")) {
			System.out.println("Rainy");
		} else if(s.equals("Rainy")) {
			System.out.println("Sunny");
		}

	}

}

class FastScanner {

	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public FastScanner(InputStream in) {
		this.in = in;
	}

	private boolean hasNextByte() {
		if(ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if(hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


Measured memory_bytes: 19412
#include <iostream>
using namespace std;
int main()
{
    unsigned int long long  H, W;
    cin>> H >> W;
    unsigned int long long result = H * W;
    unsigned int long long final = result / 2;
    if(result % 2 != 0){
        final = final + 1;
    }
    if(W == 1 || H == 1){
        final = 1;
    }
    cout<< final;
    return 0;
}

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

int main(){
  ll n;cin >> n;
  vector<ll> f(n+1);

  for(ll x=1;x*x/3<=n;++x){
    for(ll y=1;y*y/3<=n;++y){
      for(ll z=1;z*z/3<=n;++z){
        ll num = x*x + y*y + z*z + x*y + y*z + z*x;
        if( num <= n ) f.at(num)++;
      }
    }
  }
  for(ll i=1;i<=n;++i){
    cout << f.at(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>
#include <string.h>
 
int main()
{
 char s[100],n,i,flag=0,flag2=0;
 
 scanf("%s",s);
 
 n=strlen(s);
 for(i=0;i<(n-1)/2;i++){
     if(s[i]==s[n-1-i]){flag=1;}
     else{flag=0;break;}
 }
 for(i=0;i<n/2;i++){
     if(s[i]==s[n/2-1-i]){flag2=1;}
     else{flag2=0;break;}
 }

 if(flag==1&&flag2==1){printf("Yes\n");}
 else{printf("No\n");}
 return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var maxValue = -1000000000;
            var minValue = int.Parse(Console.ReadLine());

            for (int i = 0; i < n - 1; i++)
            {
                var oneLine = int.Parse(Console.ReadLine());
                maxValue = maxValue < oneLine - minValue ? oneLine - minValue : maxValue;
                minValue = minValue > oneLine ? oneLine : minValue;
            }

            Console.WriteLine(maxValue);
        }
    }
}



Measured memory_bytes: 20036
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans_list = [None for _ in range(N)]

    for i in range(N):
        ans_list[A[i] - 1] = i

    for v in ans_list:
        print(v + 1, end=" ")

    print()


if __name__ == "__main__":
    main()


Measured memory_bytes: 14008
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int n[100000] = {};
  for (int i = 0; i < N; i++)
    n[A[i]]++;
  long ans = 1;
  for (int i = 0; i < N / 2; i++)
  {
    ans *= 2;
    ans %= 1000000007;
  }
  if (N % 2 == 1 && n[0] != 1)
    ans = 0;
  for (int i = N - 1; i > 0; i -= 2)
  {
    if (n[i] != 2)
      ans = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct UnionFind {
  vector<int> d;
  UnionFind(int n) : d(n, -1) {}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<vi> fr(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    fr[a].push_back(b);
    fr[b].push_back(a);
    uf.unite(a, b);
  }
  vi ans(n, 0);
  rep(i, n) ans[i] = uf.size(i) - fr[i].size() - 1;
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    if(uf.same(c, d)) {
      ans[c]--;
      ans[d]--;
    }
  }
  rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
}

Measured memory_bytes: 7416
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

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

	string S;
	cin >> S;

	const char BLACK = '#';
	const char WHITE = '.';
	vector<int> black(N + 1, 0);
	vector<int> white(N + 1, 0);
	for (int i = 0; i < N; i++) {
		black[i + 1] += black[i];
		if (S[i] == BLACK)
			black[i + 1]++;

		white[i + 1] += white[i];
		if (S[i] == WHITE)
			white[i + 1]++;
	}

	int ans = N;
	for (int i = 0; i <= N; i++) {
		int cnt = 0;
		cnt += black[i];
		cnt += white[N] - white[i];

		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2180
N=int(input())
D=list(map(int,input().split()))
MOD=998244353
goal=-1
tree=[0]*(N)
ans=1
for i in range(N):
    a=D[i]
    goal=max(a,goal)
    tree[a]+=1
if tree[0]==1 and D[0]==0:
    for i in range(1,goal+1):
        ans*=pow(tree[i-1],tree[i],MOD)
        ans%=MOD
    print(ans)
else:
    print(0)

Measured memory_bytes: 20700
from collections import deque

h,w = map(int, input().split( ))

s = ["#"*(w+2)]
for i in range(h):
    si = "#"+input()+"#"
    s.append(si)
s.append("#"*(w+2))
nb = [(-1,0),(1,0),(0,1),(0,-1)]
inf = 10000
def bfs(x_,y_):
    dist = [[inf for i in range(w+2)] for j in range(h+2)]
    Q = deque()
    dist[x_][y_] = 0
    Q.append((x_,y_))
    while Q:
        x,y = Q.popleft()
        for u,v in nb:
            if s[x+u][y+v]!="#":
                if dist[x+u][y+v]>dist[x][y]+1:
                    dist[x+u][y+v]=dist[x][y]+1
                    Q.append((x+u,y+v))
    res = -1
    for i in range(h+2):
        for j in range(w+2):
            if dist[i][j]<inf:
                res = max(res,dist[i][j])
    return res
ans = 0
for i in range(1,h+1):
    for j in range(1,w+1):
       if s[i][j]!="#":###
            ans = max(ans,bfs(i,j))
print(ans)
    
    

Measured memory_bytes: 44396