akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, k: i64,
        a: [i64; n],
    }
    let mut a = a;
    for i in 0..n {
        a[i] = (a[i] + k - 1) % k;
    }
    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = (acc[i] + a[i]) % k;
    }
    let mut hm: HashMap<i64, i64> = HashMap::new();
    let mut ans = 0i64;
    for i in 0..n + 1 {
        *hm.entry(acc[i]).or_insert(0) += 1;
        if i as i64 >= k {
            *hm.entry(acc[i - k as usize]).or_insert(0) -= 1;
        }
        let val = hm[&acc[i]];
        ans += val - 1;
    }
    puts!("{}\n", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    long X;
    cin>>X;
    long D = 100;
    long count = 0;
    while(D < X){
        D *= 1.01;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll                          long long
#define in(a)                       ll a; cin>>a;
#define in2(a,b)                    ll a,b; cin>>a>>b;
#define in3(a,b,c)                  ll a,b,c; cin>>a>>b>>c;
#define in4(a,b,c,d)                ll a,b,c,d; cin>>a>>b>>c>>d;
#define in5(a,b,c,d,e)              ll a,b,c,d,e; cin>>a>>b>>c>>d>>e;
#define lelo(b)                     for(auto &i:b)cin>>i;
#define ff                          first
#define ss                          second
#define call(v)                     v.begin(),v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define show(x)                     for(auto t:x)cout<<t<<" ";
#define pb                          push_back
#define bhar(s,v)                   memset(s,v,sizeof(s))
#define endl                        "\n"                       
#define ce(x)                       cout<<x<<"\n";
#define nl                          cout<<endl;
#define jaldi                       ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dekh_lo                     ce("dekh_lo");
#define sz(x)                       (ll)x.size()
#define re                          return

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod=1e9+7;
const ll N=4e5+5;
ll i,j;

/*


*/
vi dp(N,0);
std::vector<bool> vis(N,0);
vi adj[N];
ll dfs(ll x){
	if(vis[x]){
		re dp[x];
	}
	vis[x]=1;
	ll ans=0;
	for(auto next:adj[x]){
		ans=max(ans,dfs(next)+1);
	}
	re dp[x]=ans;
}
void solve(){
    in2(n,m);
    for(i=0;i<m;i++){
    	in2(x,y);
    	adj[x].pb(y);
    }
    ll ans=0;
    for(i=1;i<=n;i++){
    	ans=max(ans,dfs(i));
    }
    ce(ans);
}

int32_t main(){
    // jaldi
    ll t; 
    // cin>>t;
    t=1;     
    while(t--){
        solve();
    }
}

/*


*/

  

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

int main(){
  int n; cin >> n;
  int m = n%10;
  string res="";
  if(m==3){
      res="bon";
  } else if(m==0 || m==1 || m== 6 || m==8){
      res="pon";
  } else{
      res="hon";
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
	int x,y;
	while(1){
		cin>>x>>y;
		if(x==0&&y==0)break;
		if(x>y)
		cout<<y<<" "<<x<<endl;
		else
		cout<<x<<" "<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 2976
S = input()
odd0 = 0
odd = 0
even0 = 0
even = 0
for i in range(len(S)):
    if i%2==0:
        even += 1
        if S[i] == "0":
            even0 += 1
    if i%2==1:
        odd += 1
        if S[i] == "0":
            odd0 += 1
print(min(even - even0 + odd0, odd - odd0 + even0))

Measured memory_bytes: 39664
import sys 
def minimumChar(S1, S2): 
    n, m = len(S1), len(S2) 
    ans = sys.maxsize 
    for i in range(m - n + 1): 
        minRemovedChar = 0
        for j in range(n): 
            if (S1[j] != S2[i + j]): 
                minRemovedChar += 1
        ans = min(minRemovedChar, ans) 
    return ans 

s = input()
t = input()
print(minimumChar(t,s))
    



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

using namespace std;
using ll = long long;

int main() {
    int n,m;
    cin>>n>>m;

    vector<vector<int>> G(n);
    for(int i = 0;i < m;++i) {
        int a,b;
        cin>>a>>b;
        --a;--b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    queue<pair<int,int>> q;
    q.emplace(0,-1);
    vector<int> ans(n,-1);
    while(!q.empty()) {
        int x,from;
        auto t=q.front();
        q.pop();
        x=t.first;
        from=t.second;
        cerr<<x<<endl;
        for(auto to:G[x]) {
            if(to==from)continue;
            if(ans[to]!=-1)continue;
            q.emplace(to,x);
            if(ans[to]==-1)ans[to]=x;
        }
    }
    cout<<"Yes\n";
    for(int i = 1;i < n;++i) {
        cout<<ans[i]+1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 10740
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(S: str):
    if len(set(S)) != 2:
        no()
        return

    if S.count(S[0]) != 2:
        no()
        return
    yes()
    return


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 <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int K;
	string S;
	cin >> K;
	cin >> S;
	if (S.size() > K) {
		for (int i = 0; i < K; ++i) cout << S[i];
		cout << "...";
	} else cout << S;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int w=3e5+5;
const ll mod=1e9+7;
map<string,int> ma;
set<string> se;
int main()
{
    int i,j;
    int n;
    cin>>n;
    string a;
    int max1=0;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        ma[a]++;
        max1=max(max1,ma[a]);
        if(ma[a]==1)
            se.insert(a);
    }
    set<string> ::iterator it;
    for(it=se.begin();it!=se.end();it++)
        if(ma[*it]==max1)
            cout<<*it<<endl;
    return 0;
}


Measured memory_bytes: 34560
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: usize = scan(tokens);
    let b: usize = scan(tokens);
    let a0 = (a * 100 + 7) / 8;
    let a1 = (a * 100 + 99) / 8;
    let b0 = (b * 100 + 9) / 10;
    let b1 = (b * 100 + 99) / 10;
    if a1 < b0 || b1 < a0 {
        println!("-1");
    } else {
        println!("{}", std::cmp::max(a0, b0));
    }
}


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


int main()
{
  ll n;
  int m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n)
    cin >> a[i];
  sort(a.begin(), a.end());
  vector<pair<int, int>> c(m);
  rep(i, m)
    cin >> c[i].second >> c[i].first;
  sort(c.begin(), c.end(), greater<pair<int, int>>());
  auto itr = a.begin();
  for (auto i : c)
    rep(j, i.second)
      if (itr == a.end() || *itr >= i.first)
        break;
      else
      {
        *itr = i.first;
        itr++;
      }
  ll ans = 0;
  rep(i, n)
    ans += a[i];
  cout << ans << endl;
  return 0;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int N, K, tmp, ans = 0;
    cin >> N >> K;

    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        if (tmp >= K)
            ans++;
    }
    cout << ans;
}

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

using namespace std;

#define ll long long 
#define forn(i,n) for(int i = 0;i<int(n);i++)

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    bool a = false;
    forn(i,s.length())
    {
        if(s[i]=='7'){
            a = true;
            break;
        }
    }
    if(a)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3652
#include <stdio.h>
  
int main(void){
        int N,i,v,j,k;
        scanf("%d",&N);
        int A[N];
        for(i=0;i<N;i++){
                scanf("%d",&A[i]);
        }
        for(i=0;i<N;i++){
                v=A[i];
                j=i-1;
                while(j>=0 && A[j]>v){
                        A[j+1]=A[j];
                        j--;
                }
                A[j+1]=v;
                for(k=0;k<N;k++){
                        printf("%d",A[k]);
                        if(k<N-1) printf(" ");
                }
                printf("\n");
        }
        return 0;
}


Measured memory_bytes: 2060
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 100000

struct Info{
	void set(int arg_start,int arg_end){
		start = arg_start;
		end = arg_end;
	}
	int start,end;
};

int table1_start[100002],table1_end[100002],table2[100002];
Info info[200000];


int main(){

	int N;
	scanf("%d",&N);

	for(int i = 0; i <= 100001; i++){
		table1_start[i] = 0;
		table1_end[i] = 0;
		table2[i] = 0;
	}

	int a,b,maximum = 0;

	for(int loop = 0; loop < N; loop++){
		scanf("%d %d",&a,&b);
		maximum = max(maximum,b);
		info[loop].set(a,b);
		table1_start[a]++;
		table1_end[b]++;
		table2[a]++;
		table2[b]--;
	}

	for(int i = 1; i <= maximum; i++){
		table1_start[i] += table1_start[i-1];
		table1_end[i] += table1_end[i-1];
	}

	int max_1 = 0;
	int end_after_i_start_num,start_after_i_end_num;

	for(int i = 0; i < N; i++){
		end_after_i_start_num = table1_end[maximum]-table1_end[info[i].start];
		start_after_i_end_num = table1_start[maximum]-table1_start[info[i].end-1];
		max_1 = max(max_1,end_after_i_start_num-start_after_i_end_num);
	}

	int max_2 = 0;
	for(int i = 1; i <= 100000; i++){
		table2[i] += table2[i-1];
		max_2 = max(max_2,table2[i]);
	}

	printf("%d %d\n",max_1,max_2);

	return 0;
}

Measured memory_bytes: 5940
#include <cstdio>
#include <algorithm>

using namespace std;

int cont[26];
char s[11];

int main(){
    int N,K;

    scanf("%d %d",&N,&K);

    for(int i = 0;i < N;++i){
        scanf("%s",s);
        ++cont[ s[0] - 'A' ];
    }

    int ans = 0;

    for(int j = N;j >= 1;--j){
        int maxCont = 0,have = 0;
        for(int i = 0;i < 26;++i){
            int aux = min(j,cont[i]);
            maxCont = max(maxCont,aux);
            have += aux;
        }

        while((maxCont + 1) * K <= have){
            ++maxCont;
        }

        if(maxCont * K > have){
            maxCont = 0;
        }

        ans = max(ans,maxCont);
    }

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

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define ll long long int
using namespace std;
int main()
{
    ll a,b,c,n,x,y,z,cnt=0,sum=0;
    string s,t;
    cin>>s>>t;
    if(s<t)
        swap(s,t);
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }

cout<<cnt<<endl;
}




Measured memory_bytes: 3916
N = int(input())
s = [int(input()) for _ in range(N)]
s.sort()
sums = sum(s)

if sums % 10 != 0:
    print(sums)
else:
    for p in s:
        if p % 10 != 0:
            print(sums - p)
            break
    else:
        print(0)

Measured memory_bytes: 9056
#include <stdio.h>

int main()
{
    int a, b;
    char c;
    scanf("%d ", &a);
    scanf("%c", &c);
    scanf(" %d", &b);
    if(c=='+')
        printf("%d", a+b);
    else if(c=='-')
        printf("%d", a-b);

    return 0;
}


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

int N, M;
#define MAX_N 100000
vector<int> A[MAX_N];
int C[MAX_N];
long long S, O, X;

bool see(int v, int c) {
  bool res = false;
  C[v] = c;
  for(int w : A[v]) {
    if(!C[w]) res |= see(w, -c);
    else if(C[w] == c) res = true;
  }
  return res;
}

int main() {
  cin >> N >> M;
  for(int i = 0; i < M; ++i) {
    int u, v; cin >> u >> v; --u; --v; A[u].push_back(v); A[v].push_back(u);
  }
  for(int v = 0; v < N; ++v) if(!C[v]) {
    if((int)A[v].size() == 0) ++S;
    else ++(see(v, 1) ? O : X);
  }
  cout << 2 * N * S - S * S + (O + X) * (O + X) + X * X << endl;
  return 0;
}


Measured memory_bytes: 9984
// Coins
#include <iostream>

using namespace std;

// 500, 100, 50円
int a, b, c;
int x;

bool check_sum(int i) {
    if (i == x) {
        return true;
    }
    return false;
}

int main() {
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;

    int total = 0;
    int tmp1, tmp2, tmp3;

    int count = 0;

    for (int i = 0; i <= a && i*500 <= x; i++) {
        tmp1 = 500 * i;
        if (check_sum(total + tmp1)) {
            count++;
            break;
        }
        total += tmp1;
        for (int j = 0; j <= b && total + j*100 <= x; j++) {
            tmp2 = 100 * j;
            if (check_sum(total + tmp2)) {
                count++;
                break;
            }
            total += tmp2;
            for (int k = 0; k <= c && total + k*50 <= x; k++) {
                tmp3 = 50 * k;
                if (check_sum(total + tmp3)) {
                    count++;
                    break;
                }
            }
            total -= tmp2;
        }
        total -= tmp1;
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <cstdlib>
#include <bitset>
#include <math.h>
#include <vector>

using namespace std;
int main(void){
    // Your code here!
    string str;
    string str1;
    string re;
    cin >> str;
    for (int i = 0; i < pow(2,(str.length() - 1)); i++) {
        long result = 0;
        str1 = str;
        for(int j=0; j < str1.length(); j+=2){
            int length = str1.length() -1 - j;
            int a = i >> length;
            if (a & 1) {
                re = str1[j];
                result -= stol(re);
                str1.insert(j, "-");
            }else {
                 re = str1[j];
                result += stol(re);
                str1.insert(j, "+");
            }
            
        }
        
        if (result == 7){
            break;
        }
           
    }
    
    std::cout << str1.substr(1) << "=7"<<std::endl;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
n = len(s)
MOD = 10**9 + 7

dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1

for i, si in enumerate(s):
    if si == '?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(10*j + k) % 13] += dp[i][j]
                dp[i + 1][(10 * j + k) % 13] %= MOD

    else:
        k = int(si)
        for j in range(13):
            dp[i + 1][(10 * j + k) % 13] += dp[i][j]
            dp[i + 1][(10 * j + k) % 13] %= MOD

print(dp[n][5])

Measured memory_bytes: 61980
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int C = int.Parse(str[2]);
		int ans = Math.Min(B/A,C);
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = int.Parse(Console.ReadLine());
            long ans = 0;

            for (int a = 1; a <= K; a++)
            {
                for (int b = 1; b <= K; b++)
                {
                    for (int c = 1; c <= K; c++)
                    {
                        ans += Gcd(a, b, c);
                    }
                }
            }

            Console.WriteLine(ans);
        }

        static long Gcd(long a, long b)
        {
            if (b == 0) return a;
            else return Gcd(b, a % b);
        }

        static long Gcd(long a, long b, long c)
        {
            return Gcd(a, Gcd(b, c));
        }
    }
}


Measured memory_bytes: 27524
n = int(input())
arr = list(map(int, input().strip().split(" ")))

mod = int(1e9)+7
ans = [0]*n
sm = arr[-1]
for i in range(n-2,-1,-1):
    ans[i] = sm
    sm += arr[i]
    sm = sm%mod

fa = 0
for i in range(n):
    fa += ans[i]*arr[i]
    fa = fa%mod
    
print(fa)
    


    

Measured memory_bytes: 31692
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
const int N = 1e5 + 5;
vector<int> g[N];
int d[N], anc[N], a[N];
int n;
 
bool on_diam[N];
 
int bfs(int s) {
    fill(d, d + n, -1);
    d[s] = 0;
 
    queue<int> q;
    q.push(s);
 
    while (!q.empty()) {
        int node = q.front();
        q.pop();
 
        for (int to : g[node]) {
            if (d[to] == -1) {
                d[to] = d[node] + 1;
                anc[to] = node;
                q.push(to);
            }
        }
    }
 
    return max_element(d, d + n) - d;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    cin >> n;
 
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
 
    int x = bfs(bfs(0));
 
    vector<int> diam;
 
    while (true) {
        diam.push_back(x);
        on_diam[x] = true;
        if (d[x] == 0)
            break;
        x = anc[x];
    }
 
    bool ok = true;
 
    for (int y : diam) {
        for (int to : g[y]) {
            if (!on_diam[to] && g[to].size() != 1) {
                ok = false;
                break;
            }
        }
    }
 
    if (ok) {
        for (int i = 0; i < diam.size(); i++) {
            a[i] = g[diam[i]].size();
            if (i > 0)
                a[i]--;
            if (i + 1 < diam.size())
                a[i]--;
        }

        
        for (int i = 0; i < diam.size(); i++) {
            if (a[i] != a[diam.size() - i - 1]) {
                if (a[i] > a[diam.size() - i - 1]) {
                    reverse(a, a + diam.size());
                }
                break;
            }
        }

        int last = 0;
        for (int i = 0; i < diam.size(); i++) {
            int x = ++last;
            for (int j = 0; j < a[i]; j++) {
                cout << ++last << " ";
            }
            cout << x << " ";
        }
    }
    else {
        cout << "-1\n";
    }
 
    return 0;
}

Measured memory_bytes: 8056
#include<stdio.h>
int main(void){
    int n,d;
    scanf("%d",&n);
    if(n<10) d=n;
    else d=n%10;
    
    if(d==3) printf("bon");
    else if(d==2||d==4||d==5||d==7||d==9) printf("hon");
    else printf("pon");
    return 0;
}

Measured memory_bytes: 1688
from collections import deque

def main():
    n, q = map(int, input().split())
    a = [[] for _ in range(n)]
    for i in range(n - 1):
        x, y = map(int, input().split())
        a[x - 1].append(y - 1)
        a[y - 1].append(x - 1)
    p = [0] * n
    for i in range(q):
        x, y = map(int, input().split())
        p[x - 1] += y
    c = [0] * n
    c[0] = 1
    que = deque([])
    que.append(0)
    while len(que) > 0:
        e = que.popleft()
        for i in a[e]:
            if c[i] > 0:
                continue
            c[i] = 1
            p[i] += p[e]
            que.append(i)
    for i in range(n):
        print(p[i])
main()

Measured memory_bytes: 53008
def factorial(n, mod=10**9 + 7):
    a = 1
    for i in range(1, n + 1):
        a = a * i % mod
    return a


def main():
    N, M = map(int, input().split())
    mod = 10 ** 9 + 7
    if abs(N - M) > 1:
        ans = 0
    elif abs(N - M) == 1:
        ans = (factorial(min(N, M))**2 * max(N, M)) % mod
    else:
        ans = (factorial(N)**2 * 2) % mod

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#include <iostream>
#include <vector>


using namespace std;


void white_cells()
{
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H * W) - (h * W) - (H * w) + (h * w) << "\n";
}


void double_helix()
{
  char b;
  cin >> b;

  if (b == 'A') cout << "T\n";
  else if (b == 'T') cout << "A\n";
  else if (b == 'C') cout << "G\n";
  else  cout << "C\n";

}


void five_antennas()
{
  vector<int> a(5);
  for (int i = 0; i < 5; ++i) cin >> a[i];
  int k;
  cin >> k;

  if (a[4] - a[0] > k)
  {
    cout << ":(\n";
    return;
  }
  cout << "Yay!\n";

}


int main()
{
  //white_cells();
  //double_helix();
  five_antennas();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  int n,k;cin>>n>>k;
  string s;cin>>s;
  int h=0;
  rep(i,s.size()){
    if(s[i]=='L'){
      if(i+1==(int)s.size())continue;
      if(s[i+1]=='L')h++;
    }
    else{
      if(i==0)continue;
      if(s[i-1]=='R')h++;
    }
  }
  cout<<min(n-1,2*k+h)<<endl;
}

Measured memory_bytes: 512
X = int(input())

import math

def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False

  # nの平方根まで計算する
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
      if n % p == 0:
        return False
  return True

for x in range(X, 10**6):
    if isPrime(x):
        print(x)
        exit()


Measured memory_bytes: 3060
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    a = list(sorted(list(map(int, input().split()))))
    print(a[0] + a[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3944
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    for(int n; cin >> n && n;)
	{
		vector<pint> v(n);
		
		rep(i, n)
		{
			int num, m[4], s[4];
			cin >> num;
			
			rep(j, 4) cin >> m[j] >> s[j];
			
			v[i] = mp(accumulate(m, m + 4, 0) * 60 + accumulate(s, s + 4, 0), num);
		}
		
		sort(ALL(v));
		
		cout << v[0].second << endl;
		cout << v[1].second << endl;
		cout << v[v.size() - 2].second << endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
int cnt[1 << 18];
int main() {
	int N;
	cin >> N;
	int M = 1 << N;
	vector<int> S(M);
	for (int i = 0; i < M; i++) {
		cin >> S[i];
	}
	vector<int> v = S;
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int k = v.size();
	for (int i = 0; i < M; i++) {
		int idx = lower_bound(v.begin(), v.end(), S[i]) - v.begin();
		cnt[idx]++;
	}
	if (cnt[k - 1] > 1) {
		cout << "No" << endl;
		return 0;
	}
	set<int> need;
	for (int i = 0; i < k - 1; i++) if (cnt[i] > 0) need.insert(-i);
	multiset<int> now;
	now.insert(k - 1);
	for (int i = 0; i < N; i++) {
		vector<int> next;
		for (int e : now) {
			auto itr = need.upper_bound(-e);
			if (itr == need.end()) continue;
			int v = -(*itr);
			cnt[v]--;
			next.push_back(v);
			if (cnt[v] == 0) need.erase(itr);
		}
		for (int v : next) now.insert(v);
	}
	if (need.empty()) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

const ll mod = 1e9 + 7;

int main() {
    ll n;
    cin >> n;
    string ans = "";
    while(n){
        n--;
        ans += (n % 26) + 'a';
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
	string s;
	gets(s)
	s[5] = ' ',s[13] = ' ';
	puts(s)
}


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

const int N = 200010;

int a[N], p[N], f[N], ans[N];
int n;

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &a[i]);
		p[a[i]] = i;
	}
	for (int i = n; i; -- i){
		if (!ans[i + 1]){
			if (i == n || p[i] < p[i + 1]){
				continue;
			}
			ans[i] = 1;
			f[i] = i + 1;
			continue;
		}
		if (p[f[i + 1]] < p[i] && p[i] < p[i + 1] || p[i] < p[i + 1] && p[i + 1] < p[f[i + 1]] || p[i + 1] < p[f[i + 1]] && p[f[i + 1]] < p[i]){
			ans[i] = ans[i + 1];
			f[i] = f[i + 1];
		}
		else{
			ans[i] = ans[i + 1] + 1;
			f[i] = i + 1;
		}
	}
	return printf("%d\n", ans[1]), 0;
}

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

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

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

	const int INF = 0xffffff;

	int pos[256];
	pos['1'] = pos['4'] = pos['7'] = 0;
	pos['2'] = pos['8'] = 1;
	pos['3'] = pos['6'] = pos['9'] = 2;

	for(string arrows; cin >> arrows, arrows != "#";) {
		vector<vector<vector<int> > > dp(3, vector<vector<int> >(3, vector<int>(2, INF)));
		dp[2][0][false] = dp[2][0][true] = 0;

		for(int i = 0; i < (int)arrows.size(); ++i) {
			vector<vector<vector<int> > > tmp(3, vector<vector<int> >(3, vector<int>(2, INF)));
			const int next_pos = pos[arrows[i]];
			for(int rx = 0; rx < 3; ++rx) {
				for(int lx = 0; lx < 3; ++lx) {
					for(int p_left = 0; p_left < 2; ++p_left) {
						if(next_pos >= lx)
							chmin(tmp[next_pos][lx][false], dp[rx][lx][p_left] + 1 - p_left);

						if(next_pos <= rx)
							chmin(tmp[rx][next_pos][true], dp[rx][lx][p_left] + p_left);
					}
				}
			}
			dp.swap(tmp);
		}

		int ans = INF;
		for(int rx = 0; rx < 3; ++rx)
			for(int lx = 0; lx < 3; ++lx)
				for(int p_left = 0; p_left < 2; ++p_left)
					chmin(ans, dp[rx][lx][p_left]);

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1352
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;

int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    int a[n], h;
    for (int i = 0; i < n; i++) {
        a[i] = k - q;
    }

    for (int i = 0; i < q; i++) {
        cin >> h;
        a[h - 1]++;
    }

    for (int i = 0; i < n; i++) {
        if (a[i] > 0) {
            puts("Yes");
        }
        else {
            puts("No");
        }
    }
}


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

int N;
string s;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> s;
    rep(a, 2) rep(b, 2) {
        int A[N];
        A[0] = a;
        A[1] = b;
        for (int i=2; i<N; i++) {
            if (s[i-1]=='o' && A[i-1]==0) A[i] = A[i-2];
            else if (s[i-1]=='o' && A[i-1]==1) A[i] = 1^A[i-2];
            else if (s[i-1]=='x' && A[i-1]==0) A[i] = 1^A[i-2];
            else A[i] = A[i-2];
        }
        
        bool flag = true;
        if (s[0]=='o' && A[0]==0) flag &= A[1]==A[N-1];
        else if (s[0]=='o' && A[0]==1) flag &= A[1]!=A[N-1];
        else if (s[0]=='x' && A[0]==0) flag &= A[1]!=A[N-1];
        else if (s[0]=='x' && A[0]==1) flag &= A[1]==A[N-1];
        
        if (s[N-1]=='o' && A[N-1]==0) flag &= A[0]==A[N-2];
        else if (s[N-1]=='o' && A[N-1]==1) flag &= A[0]!=A[N-2];
        else if (s[N-1]=='x' && A[N-1]==0) flag &= A[0]!=A[N-2];
        else if (s[N-1]=='x' && A[N-1]==1) flag &= A[0]==A[N-2];
        
        if (flag) {
            rep(i, N) {
                if (A[i]==0) cout << 'S';
                else cout << 'W';
            }
            cout << endl;
            exit(0);
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 1360
# https://atcoder.jp/contests/abc164/tasks/abc164_d

import sys
input = sys.stdin.readline


S = input().rstrip()

res = 0

T = [0]
x = 0
p = 1
L = len(S)
MOD = 2019
for s in reversed(S):
    """ 累積和 """
    x = (int(s)*p + x)%MOD
    p = p*10%MOD
    T.append(x)

reminder = [0]*2019
for i in range(L+1):
    reminder[T[i]%MOD] += 1

for c in reminder:
    res += c*(c-1)//2

print(res)

Measured memory_bytes: 84280
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 17304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by hwzheng on 2017/3/27.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader Reader = new BufferedReader (new InputStreamReader(System.in));
        int N = Integer.parseInt(Reader.readLine());
        String A[] = Reader.readLine().split(" ",0);
        int[] arr = new int[N];
        for (int i=0; i < N; i++){
            arr[i] = Integer.parseInt(A[i]);
        }
        selectionSort(arr,N);
    }

    private static void selectionSort(int[] arr, int N){
        int count = 0;
        for (int i = 0; i < N; i++){
            int min = i;
            for (int j = i; j < N; j++){
                if (arr[j] < arr[min]){
                    min = j;
                }
            }
            if (min != i){
                exch(arr, min, i);
                count++;
            }
        }
        String str = "";
        for (int i = 0; i < arr.length; i++){
            str += arr[i] + " ";
        }
        System.out.println(str.substring(0,str.length()-1));
        System.out.println(count);
    }

    private static void exch(int[] arr, int i, int j){
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}

Measured memory_bytes: 24344
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <tuple>
#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 pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    string S;
    cin >> S;
    int cnt = 0;
    int M = 0;
    REP(i, S.size())
    {
        if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T')
        {
            cnt++;
            M = max(cnt, M);
        }
        else
        {
            cnt = 0;
        }
    }

    cout << M << endl;
}


Measured memory_bytes: 256
import itertools
n = int(input())
m = []
a = []
r = []
c = []
h = []
for i in range(n):
    t = input()
    if t[0] == 'M':
        m.append(t)
    elif t[0] == 'A':
        a.append(t)
    elif t[0] == 'R':
        r.append(t)
    elif t[0] == 'C':
        c.append(t)
    elif t[0] == 'H':
        h.append(t)
seq = (len(m), len(a), len(r), len(c), len(h))
t3 = list(itertools.combinations(seq, 3))
out = 0
for j in t3:
    out += j[0]*j[1]*j[2]
print(out)


Measured memory_bytes: 10100
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0 for _ in range(n + 1)]
        self.size = [1] * (n + 1)
        self.group = [[i] for i in range(n + 1)]

    def find(self, x):
        # If x is root
        if self.parent[x] == x:
            return x
        # If x is not root, search again by using x's parent
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        # Make an edge from the root of lower tree to the root of higher tree
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            # If the height of tree the tree is the same, increase one of the heights by 1
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def check_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]

    def merge(self, x, y):
        """
        "データ構造をマージする一般的なテク"
        """
        x = self.find(x)
        y = self.find(y)
        if len(self.group[x]) < len(self.group[y]):
            x, y = y, x
        self.group[x].extend(self.group[y])
        self.group[y] = []
        self.parent[y] = x


def combination(n, r):
    """
    :param n: the count of different items
    :param r: the number of select
    :return: combination
    n! / (r! * (n - r)!)
    """
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


N, M = map(int, input().split())
items = []
for i in range(M):
    a, b = map(int, input().split())
    items.append((a, b))
items = list(reversed(items))

union_find = UnionFind(N)
ans = (N - 1) * N // 2
minus = 0

result = []
for i, ab in enumerate(items):
    a, b = ab
    ans -= minus
    result.append(ans)
    if union_find.check_same(a, b):
        minus = 0
    else:
        sa = union_find.get_size(a)
        sb = union_find.get_size(b)
        minus = sa * sb
    union_find.union(a, b)

for r in result[::-1]:
    print(r)


Measured memory_bytes: 38536
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
#define watch(x) cout << (#x)<<" = "<<x<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}


int main() {
	file();
	fast();
	int n; cin >> n;
	vi v1(n);
	for (auto& it : v1) cin >> it;
	sort(allr(v1));
	ll ans = v1[0];
	int cnt = n - 2, stand = 1;
	while (cnt) {
		ans += v1[stand];
		cnt--;
		if (cnt) ans += v1[stand], cnt--;
		stand++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;

int main(){
	int n, k;
	cin>>n>>k;
	ll adder = n, subber = 0, ans=0;
	for(int i=1;i<=n+1;i++){
		if(i>=k)
			ans = (ans + adder - subber + 1)%mod;
		//cout<<i<<" "<<adder<<" "<<ans<<"\n";
		adder = (adder + n-i)%mod;
		subber = (subber+i)%mod;
	}
	while(ans < 0)
		ans += mod;
	cout<<ans%mod<<"\n";
	return 0;
}

Measured memory_bytes: 3660
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

int readInt(){
  return readln.chomp.to!int;
}

int[] readInts(){
  return readln.chomp.split.to!(int[]);
}

void main(){
  int[] nk = readInts();

  int ret = nk[0] - nk[1] + 1;
  writeln(ret);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    long long int i,a,b,c,d,k=-1;
    
    cin>>a>>b;
    
    for( i=0;i<=1000000000;i++){
         
        if( abs(a-i) == abs(b-i) ){
            k = i ;
            break;
        }
    }


    if( k>-1 ) {
        cout<<k;
    }
    else if( k==-1 ){
        cout<<"IMPOSSIBLE";
    }
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int n;
ll a[100005];
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld",a+i);
    sort(a,a+n);
    ll s=a[0],x=1;
    for(int i=1;i<n;i++){
        if(s*2>=a[i])x++;
        else x=1;
        s+=a[i];
    }
    printf("%lld\n",x);
}

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

using namespace std;

int x, n, p[100], ans = -1;
bool in[201];

int main()
{
    cin >> x >> n;
    for(int i = 0; i<n; i++)
        cin >> p[i];
    for(int i = 0; i<n; i++)
        in[p[i]] = true;
    for(int i = 0; i<201; i++)
        if((!in[i])&&(abs(x-i)<abs(x-ans)))
            ans = i;
    cout << ans << endl;
}


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

struct skill{
    int max,min;
    skill(){
        max=100;
        min=0;
    }
};

typedef vector<int> V;
vector<V> G(100);
bool isVisited[100];
bool isChecked[100];

bool rec(int i){
    isVisited[i]=true;
    isChecked[i]=true;
    for(auto&e:G[i]){
        if(isVisited[e]){
            return true;
        }else if(!isChecked[e]){
            if(rec(e)){
                return true;
            }
        }
    }
    isVisited[i]=false;
    return false;
}

int main(){
    int M,N;
    cin>>M>>N;
    skill S[100][100];
    for(int i=0;i<M;i++){
        int K;
        cin>>K;
        for(int j=0;j<K;j++){
            int s,t;
            string cond;
            cin>>s>>cond>>t;
            s--;
            if(cond=="<="){//SP<=t
                if(t<S[i][s].min){
                    cout<<"No"<<endl;
                    return 0;
                }else if(t<S[i][s].max){
                    S[i][s].max=t;
                }
            }else{//t<=SP
                if(t>S[i][s].max){
                    cout<<"No"<<endl;
                    return 0;
                }else if(t>S[i][s].min){
                    S[i][s].min=t;
                }
            }
        }
    }
    for(int i=0;i<M;i++){
        for(int j=i+1;j<M;j++){
            int i_over_j=0;
            for(int k=0;k<N;k++){
                if(S[i][k].min>S[j][k].max){
                    if(i_over_j==-1){
                        cout<<"No"<<endl;
                        return 0;
                    }else{
                        i_over_j=1;
                    }
                }
                if(S[i][k].max<S[j][k].min){
                    if(i_over_j==1){
                        cout<<"No"<<endl;
                        return 0;
                    }else{
                        i_over_j=-1;
                    }
                }
            }
            if(i_over_j==1){
                // cout<<i<<"->"<<j<<endl;
                G[i].push_back(j);
            }
            if(i_over_j==-1){
                // cout<<i<<"<-"<<j<<endl;
                G[j].push_back(i);
            }
        }
    }
    for(int i=0;i<M;i++){
        fill(isVisited,isVisited+100,false);
        fill(isChecked,isChecked+100,false);
        if(rec(i)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
#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-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
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 <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    int n,d;
    cin >> n;
    set<int> D;
    rep(i,n) {
        cin >> d;
        D.insert(d);
    }
    cout << D.size() << "\n";
}


Measured memory_bytes: 256
a = int(input());
n = a % 10;
if n == 0:
    print("pon");
elif n == 1:
    print("pon");
elif n == 6:
    print("pon");
elif n == 8:
    print("pon");
    
elif n == 3:
    print("bon");
    
else:
    print("hon");

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    ll N, M;
    cin>>N>>M;
    vector<ll> X(M);
    vector<ll> Y(M-1);
    rep(i, M){
        cin>>X[i];
        
    }
  	sort(ALL(X));
  	rep(i, M-1){
      	Y[i]=X[i+1]-X[i];
    }
    sort(ALL(Y));
    if(N>=M){
        cout<<0<<endl;
        return 0;
    }
    ll Ans=0;
    rep(i, M-N){
        Ans+=Y[i];
    }
    cout<<Ans<<endl;
}
     

Measured memory_bytes: 1792