akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    int ans = (N+2-1)/2;
    cout << ans << endl;
}


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

using namespace std;

int gcd(int a, int b){
    if(a < b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    if(r == 0)return b;
    return gcd(b, r);
}

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

    vector<long int> A(N);
    for(int i = 0; i < N; i++)cin >> A[i];

    int ans = A[0];
    for(int i = 1; i < N; i++){
        ans = gcd(ans, A[i]);
    }

    cout << ans;
    return 0;
    
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define INF 100000000

class weightedUnionFind{
public:
  vector<int> par; // 親の番号
  vector<int> ws; // 親との重みの差

  weightedUnionFind(int n){
    par = vector<int>(n);
    ws = vector<int>(n);
    rep(i,n)par[i] = -1;
  }

  int find(int x){
    if(par[x]<0) return x;
    else {
      int parent = find(par[x]);
      ws[x] += ws[par[x]];
      return par[x] = parent;
    }
  }

  int weight(int x){
    int dummy = find(x);
    return ws[x];
  }

  bool unite(int x, int y, int w){
    int ww = w + weight(x);
    ww -= weight(y);
    x = find(x);
    y = find(y);

    if(x != y){
      if(par[y] < par[x]){
        swap(x,y);
        ww = -ww;
      }
      par[x] += par[y];
      par[y] = x;
      ws[y] = ww;
      return true;
    } else {
      return false;
    }
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }

  int diff(int x, int y){
    if(!same(x,y)) return INF;
    return weight(y) - weight(x);
  }
};

int main(){

  while(1){
    int n,m;
    cin >> n >> m;
    if(!n)break;
    weightedUnionFind wuf(n);
    rep(i,m){
      char sign;
      cin >> sign;
      if(sign == '!'){
        int a,b,w;
        cin >> a >> b >> w;
        a--;b--;
        wuf.unite(a,b,w);
      } else {
        int a,b;
        cin >> a >> b;
        a--;b--;
        int w = wuf.diff(a,b);
        if(w==INF)cout << "UNKNOWN" << endl;
        else {cout << w << endl;}
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3560
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<vector<ll>> g(n+1);
    vector<ll> order(n);
    FOR(i,0,n-1){
        ll from,to;
        cin>>from>>to;
        g[from].push_back(to);
        order[i] = to;
    }
    deque<ll> q;
    q.push_back(1);
    vector<ll> res(n+1);
    while(!q.empty()){
        ll from = q.front();
        q.pop_front();
        map<ll,ll> key;
//        cout<<from<<endl;
        key[res[from]] = 1;
        ll t = 1;
        FOR(i,0,g[from].size()){
            ll to = g[from][i];
//            cout<<" "<<i<<endl;
            FOR(j,t,1e5+1){
//                cout<<"  "<<j<<endl;
                if(key[j] == 0){
                    res[to] = j;
                    key[j] = 1;
                    t = j;
                    break;
                }
            }
            q.push_back(to);
        }
    }
    ll ma = 0;
    FOR(i,1,n+1) ma = max(ma, res[i]);
    cout<<ma<<endl;
    FOR(i,0,n-1){
        cout<<res[order[i]]<<endl;
    }
}

Measured memory_bytes: 6648
N, M = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse = True)
i = 0
for j in range(M):
	A[i] = A[i]//2
	if i <= N-2 and A[i] < A[i+1] and A[0] < A[i+1]:
		i += 1
	else :
		A.sort(reverse=True)
		i = 0
print(str(sum(A)))

Measured memory_bytes: 14224
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        if (n == 1)  Console.WriteLine("Hello World"); 
        else
        {
            var a = int.Parse(Console.ReadLine().Trim());
            var b = int.Parse(Console.ReadLine().Trim());
            Console.WriteLine(a + b);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, a; cin >> n >> a;
	while(n>=500){
		n = n-500;
	}
	if(n<=a){
		cout << "Yes" << endl;
		return 0;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for (int i = 0; i < M; i++)
        cin >> X[i];

    sort(X.begin(), X.end());
    vector<int> diff(M - 1);
    for (int i = 0; i < M - 1; i++)
        diff[i] = X[i + 1] - X[i];
    sort(diff.begin(), diff.end());

    int res = 0;
    for (int i = 0; i < M - N; i++)
        res += diff[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll n;
    cin>>n;
    ll c0,c1,c2,c3;
    c0 = 0;
    c1 = 0;
    c2 = 0;
    c3 = 0;
    while (n--)
    {
        /* code */
        string s;
        cin>>s;
        if(s.compare("AC") == 0)
        {
            c0++;
        }
        else if(s.compare("WA") == 0)
        {
            c1++;
        }
        else if(s.compare("TLE") == 0)
        {
            c2++;
        }
        else
        {
            c3++;
        }
    }
    cout<<"AC x "<<c0<<'\n';
    cout<<"WA x "<<c1<<'\n';
    cout<<"TLE x "<<c2<<'\n';
    cout<<"RE x "<<c3<<'\n';
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    new Main().solve();
  }

  public void solve() {

    Scanner input = new Scanner(System.in);
    int a = input.nextInt();
    int b = input.nextInt();
    int c = input.nextInt();
    long k = input.nextLong();

    if (Math.abs(a - b) >= Math.pow(10, 18)) {
      System.out.println("Unfair");
      return;
    }

    if (k % 2 == 0) {
      System.out.println(a-b);
    } else {
      System.out.println(b-a);
    }
  }
}


Measured memory_bytes: 23508
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int n,W;
    cin >> n >> W;
    long long dp[100005];
    long long w,v;
  	for(int j=0; j<=W; j++){
        dp[j]=0;
    }
    for(int i=1; i<=n; i++){
        cin >> w >> v;
        for(int j=W-w; j>=0; j--){
            if(j+w<=W&&dp[j]!=0)dp[j+w]=max(dp[j+w],dp[j]+v);
        }
        dp[w]=max(dp[w],v);
    }
    long long ans=0;
    for(int i=0; i<=W; i++){
        ans=max(ans,dp[i]);
    }
    cout << ans << endl;
    return 0;
}

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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007
#define tc             ll tc;scanf("%lld",&tc);while(tc--)

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

ll col[100010];
vector<pll> adj[100010];
bool vis[100010];

void dfs(ll nd, ll cl)
{

    vis[nd]=1;
    col[nd]=cl;
    ll rev;
    if(cl==1) rev=0;
    else rev=1;
    for(ll i=0;i<adj[nd].size();i++)
    {

        ll v=adj[nd][i].ff;
        ll dis=adj[nd][i].ss;
        if(vis[v]) continue;
        if(dis%2) dfs(v,rev);
        else dfs(v,cl);
    }
}

int main()
{

    ll n;
    cin >> n;
    for(ll i=1;i<n;i++)
    {

        ll x,y,w;
        cin >> x >> y >> w;
        adj[x].pb(mp(y,w));
        adj[y].pb(mp(x,w));
    }
    dfs(1,0);
    for(ll i=1;i<=n;i++) cout << col[i] << endl;
}


Measured memory_bytes: 13228
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n,k;
    cin >> n >> k;
    unordered_set<int> m;
    while(k--){
        int d;
        cin >> d;
        while(d--){
            int x;
            cin >> x;
            m.insert(x);
        }
    }
    cout<<n-m.size()<<endl;
}


Measured memory_bytes: 3652
def dijkstra_heap(s,edge,mask):
    dist = defaultdict(lambda: float("inf"))
    q = [s]  # 0 が会社に属していない状態
    dist[s] = 0
    d = 0; q0 = []; q1 = []
    while q:
        for x in q:
            if x & mask == 0:
                for y in edge[x]:
                    if dist[y[1]] <= d + y[0]:
                        continue
                    dist[y[1]] = d + y[0]
                    q1.append(y[1])
            else:
                for y in edge[x]:
                    if dist[y[1]] <= d+ y[0]:
                        continue
                    dist[y[1]] = d+ y[0]
                    q0.append(y[1])
        if q0:
            q = q0
            q0 = []
            continue
        q = q1
        q1 = []
        d += 1
    return dist

def examE(inf):
    N, M = LI()
    edge = defaultdict(list)
    # edge[i] : iから出る道の[重み,行先]の配列
    L = 32
    Mask = (1 << L) - 1
    for i in range(M):
        p, q, c = map(int, input().split())
        p -=1; q -=1
        p <<= L
        q <<= L
        #同じ路線だとコスト０ 乗るときだけコスト１
        edge[p].append((1,p + c))
        edge[p + c].append((0,p))
        edge[q].append((1,q + c))
        edge[q + c].append((0,q))
        edge[p + c].append((0,q + c))
        edge[q + c].append((0,p + c))
    start = 0
    goal = (N-1) << L
    res = dijkstra_heap(start, edge, Mask)
#    print(res)
    ans = res[goal]
    if ans == inf:
        ans = -1
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examE(inf)


Measured memory_bytes: 196824
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

void Koch(double *p1, double *p2,int n){
	n--;
	double c[2],d[2],e[2];
	c[0] = p1[0]+(p2[0]-p1[0])/3.0; c[1] = p1[1]+(p2[1]-p1[1])/3.0;
	e[0] = p1[0]+(p2[0]-p1[0])/3.0*2.0; e[1] = p1[1]+(p2[1]-p1[1])/3.0*2.0;
	d[0] = (e[0]-c[0])*cos(M_PI/3.0)-(e[1]-c[1])*sin(M_PI/3.0)+c[0];
	d[1] = (e[0]-c[0])*sin(M_PI/3.0)+(e[1]-c[1])*cos(M_PI/3.0)+c[1];
	if( n > 0 ) Koch(p1,c,n);
	cout << c[0] << "\t" << c[1] << endl;
	if( n > 0 ) Koch(c,d,n);
	cout << d[0] << "\t" << d[1] << endl;
	if( n > 0 ) Koch(d,e,n);
	cout << e[0] << "\t" << e[1] << endl;
	if( n > 0 ) Koch(e,p2,n);
}

main(){
	int n;
	cin >> n;
	double s[2] = {0.0,0.0}, t[2] = {100.0,0.0};
	cout << setprecision(8) << fixed << s[0] << "\t" << s[1] << endl;
	if( n > 0 ) Koch(s,t,n);
	cout << t[0] << "\t" << t[1] << endl;
	
}


Measured memory_bytes: 3236
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] array = new int[26];
        Arrays.fill(array,0);
        char[] c_array;
        String str;
        do{
            if((str=br.readLine())==null) break;
            c_array=str.toCharArray();
            for(char c:c_array){
                if('a'<=c&&c<='z') array[c-'a']++;
                else if('A'<=c&&c<='Z') array[c-'A']++;
            }
        }while(true);
        for(int i=0;i<26;i++){
            System.out.println((char)('a'+i)+" : "+array[i]);
        }
    }
}

Measured memory_bytes: 24152
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
      int N = int.Parse(Console.ReadLine());
      int[] H = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      
      
      int ans = 0;
      int count = 0;
      for(int i = 0;i < N - 1; i++)
      {
        if(H[i] < H[i + 1])
        {
            if(ans < count)
            {
              ans = count;
            }
            count = 0;
        }
        else
        {
            count++;
        }
      }
      if(ans<count)
        ans=count;
      Console.WriteLine(ans);
    }
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
	int A, B;
	scanf("%d %d", &A, &B);
	if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 764
# -*- coding:utf-8 -*-
from functools import reduce
from operator import add


def main(n, min_limit, max_limit):
    result = 0

    for i in range(1, n+1):
        tmp = reduce(add, [int(n) for n in str(i)])
        if min_limit <= tmp <= max_limit:
            result += i

    print(result)


if __name__ == "__main__":
    lst = [int(val) for val in input().split()]
    main(lst[0], lst[1], lst[2])

Measured memory_bytes: 3828
#![allow(unused_imports, unused_macros, non_snake_case)]
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{ macros missing in 1.15.1
#[macro_use]
mod macros {
    macro_rules! eprint {
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = write!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! eprintln {
        () => { eprintln!(""); };
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = writeln!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! dbg {
        ($val:expr) => {
            match $val {
                tmp => {
                    eprintln!(
                        "[{}:{}] {} = {:#?}",
                        file!(),
                        line!(),
                        stringify!($val),
                        &tmp
                    );
                    tmp
                }
            }
        };
    }
}
//}}}

fn single(n: usize) -> usize {
    match n {
        1 => 300000,
        2 => 200000,
        3 => 100000,
        _ => 0,
    }
}

fn run() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut ans = single(n) + single(m);
    if n == 1 && m == 1 {
        ans += 400000;
    }
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".to_string())
        .stack_size(1024 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap()
}

//{{{ Scanner
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
//}}}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
#define ull            unsigned long long int
#define ll             long long int
#define pb(x)          push_back(x)
#define mp(a,b)        make_pair(a,b)
#define li(ini)        for(ull i=ini;;i++)
#define lf(i,ini,n)    for(ull i=ini;i<n;i++)
#define lfd(i,n)       for(ull i=n;i>=1;i--)
#define lit(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define sorta(v)       sort(v.begin(),v.end())
#define sortd(v)       sort(vec.begin(), vec.end(), greater<>())
#define vf(i)          v[i].first
#define vs(i)          v[i].second
#define fast_io        ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

vector<ll>v;
ll memo[100001];
void dp(ll n)
{
    lf(i,2,n)
    {
        memo[i]=min(memo[i-2]+abs(v[i]-v[i-2]),memo[i-1]+ abs(v[i]-v[i-1]));

    }

}

int main()
{
    //fast_io

    ll n=0,x=0,res=0,i=0,j=0;
    cin>>n;

    lf(i,0,n)
    {
        cin>>x;
        v.pb(x);
    }
    //ll memo[100001]={0};
    memo[0]=0;
    memo[1]=abs(v[0]-v[1]);///base case definition

    dp(n);
    cout<<memo[n-1]<<"\n";

    return 0;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int x;
  cin >> x;

  cout << 1 - x << endl;
  
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<stdlib.h>
using namespace std;

int main (){
  int n, m;
  int b, count, answer;
  int *list, *result;
  list = (int*)malloc(sizeof(int)*n);
  result = (int*)malloc(sizeof(int)*n);

  cin >> n >> m;
  for(int i = 0; i<n; i++){
    cin >>list[i];
    result[i] = 0;
  }

  for(int i= 0; i< m; i++){
    count = 0;
    cin >>b;
    while(1){
      if(list[count] < b+1) break;
      count++;
    }
    //cout <<count <<endl ;
    result[count] ++;
  }
  answer = 0;
  for(int i =0; i<n; i++){
    if(result[answer] < result[i])
      answer = i ;
  }

  cout << answer + 1 <<endl;
  return 0;
}
    
    
      
      
    
  
  

Measured memory_bytes: 1184
import math

N,D=map(int,input().split())

arr=[list(map(int,input().split())) for i in range(N)]
count=0

def dis(x,y):
    a=0
    for i in range(len(x)):
        a+=(x[i]-y[i])*(x[i]-y[i])
    return math.sqrt(a)
    
for i in range(N-1):
    for j in range(i+1,N):
        if dis(arr[i],arr[j])%1==0:
            count+=1

print(count)


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

int main() {
int k;
  cin >> k;
 if(k%2 != 0){
   int t = (k-1)/2;
   int d = (k+1)/2;
   cout << d*t << endl;
 }
  else cout << (k/2)*(k/2) << endl;
}

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

int main(void){
  int column,row,start_x,start_y,goal_x,goal_y,mod,vertical,horizontal,num,res,multi;
  mod=100000007;
  cin>>column>>row>>start_x>>start_y>>goal_x>>goal_y;
  vector<vector<int>> vec(row+column,vector<int>(row+column,0));

  for(int i=0;i<row+column;i++){
    for(int j=0;j<=i;j++){
      if(j==0){ vec.at(i).at(0) = 1; continue; }
      else{ vec.at(i).at(j) = (vec.at(i-1).at(j) + vec.at(i-1).at(j-1))%mod;   }
    }
  }
multi=1;
horizontal=abs(goal_x-start_x);
vertical=abs(goal_y-start_y);

if(start_x<=goal_x){
  if(horizontal>abs(start_x+column-goal_x)){ horizontal = abs(start_x+column-goal_x); }
  else if(horizontal==abs(start_x+column-goal_x)){multi*=2; }
}
else{
  if(horizontal>abs(goal_x+column-start_x)){ horizontal = abs(goal_x+column-start_x); }
  else if(horizontal==abs(goal_x+column-start_x)){multi*=2; }
}
if(start_y<=goal_y){
  if(vertical>abs(start_y+row-goal_y)){ vertical = abs(start_y+row-goal_y); }
  else if(vertical==abs(start_y+row-goal_y)){ multi*=2; }
}
else{
  if(vertical>abs(goal_y+row-start_y)){ vertical = abs(goal_y+row-start_y); }
  else if(vertical==abs(goal_y+row-start_y)){ multi*=2; }
}
res=(vec.at(horizontal+vertical).at(horizontal)*multi)%mod;
cout<<res<<endl;
return 0;
}



Measured memory_bytes: 18652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

int ans = 0;
bool e[9][9] = {{}}; //edge
int n,m;
void ss( int a, bool* b){
    //printf ("%d\n", a);
    for (int i = 1; i <= n+1; i++){
        if( i == n+1 ){ ans++; return; }
        if( !b[i] ) break;
    }
    for (int i = 1; i <= n; i++){
        if(e[a][i] && !b[i]){
            b[i] = true;
            ss(i,b);
            b[i] = false;
        }
    }
}

int main() {

    int a, b;

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

    for (int i = 0; i < m; i++){
        scanf("%d %d", &a, &b);
        e[a][b] = true;
        e[b][a] = true;
    }

    bool c[9] = {};
    c[1] = true;
    ss(1, c);

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int P = 1'000'000'007;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> c;
	c.resize(n);
	for(int i = 0; i < n; ++i) {
		cin >> c[i];
	}
	sort(c.begin(), c.end());
	// i
	// \sum {2 ^ {i - 1} * \sum{C(n - i, j) * 2 ^ {j} * 2 ^ {n - i - j}}}
	// = \sum {2 ^ {n} }
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		ans = (ans + 1LL * c[i] * (n - i + 1) % P) % P;
	}
	for(int i = 0; i < 2 * n - 2; ++i) {
		ans = ans * 2 % P;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 47332
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def solver(x: int):
    if x < 100:
        return 0
    n = x // 100
    m = x % 100
    for _ in range(n):
        if m > 5:
            m -= 5
        else:
            return 1

    if m == 0:
        return 1
    else:
        return 0


def main():
    X = int(input())
    print(solver(X))


if __name__ == "__main__":
    main()

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

A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
cnt = 0
ans = []

for i in range(N):
    for j in range(N):
        if i < j:
            cnt += B[j]
        elif i == j:
            cnt += A[i] + B[j]
        elif i > j:
            cnt += A[j]
    ans.append(cnt)
    cnt = 0

print(max(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  cin >> n;
  vector<bool> x(1000000001, false);
  int cnt = 0;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    if( x[a] ){
      x[a] = false;
      cnt--;
    }else{
      x[a] = true;
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}

// EOF


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var index = 0;

            for (var i = 0; i < S.Length; i++)
            {
                if (S[i] != '1')
                {
                    index = i;
                    break;
                }
            }

            var K = long.Parse(Console.ReadLine());

            if (index >= K)
                Console.WriteLine(S[0]);
            else
                Console.WriteLine(S[index]);
        }
    }
}


Measured memory_bytes: 13140
module IntMap = Map.Make(struct type t = int let compare = compare end)
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern

let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let aa = read_line () |> split_string ~pattern:" " |> List.map int_of_string
let q = Scanf.sscanf (read_line ()) "%d" @@ fun q -> q
let bc = Array.init q @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d" @@ fun b c -> (b, c)

let find map n = try IntMap.find n map with Not_found -> 0

let add map n =
  let v = find map n in
  IntMap.add n (v + 1) map
let map = ref @@ List.fold_left add IntMap.empty aa

let () =
  let sum = ref @@ IntMap.fold (fun k v sum -> sum + k * v) !map 0 in
  Array.iter (fun (b, c) ->
    let b_cnt = find !map b in
    let c_cnt = find !map c in
    sum := !sum + b_cnt * (c - b);
    Printf.printf "%d\n" !sum;
    map := !map |> IntMap.remove b |> IntMap.add c (c_cnt + b_cnt)
  ) bc

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

MAX_VOTE_NUM = 1000

x = [-1] * MAX_VOTE_NUM
total_vote_num = 0
for i in range(n):
  x[a[i] - 1] = i
  total_vote_num += a[i]

popular_num = 0
for i in range(MAX_VOTE_NUM):
  index = MAX_VOTE_NUM - i
  if x[index - 1] != -1 and (index * 4 * m) >= total_vote_num:
    popular_num += 1

if popular_num >= m:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#coding:utf-8
n,x=map(int, input().split())

a,p=[1],[1]
for i in range(n):
	a.append(a[i]*2+3)
	p.append(p[i]*2+1)

def f(n,x):
	if n==0:
		return 0 if x<=0 else 1
	elif x<=1+a[n-1]:
		return f(n-1,x-1)
	else:
		return p[n-1]+1+f(n-1,x-2-a[n-1])

print(f(n,x))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int par[100001]={};
int r[100001]={};
int clob[100001]={};

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

void unite (int x, int y){
	if(x == y) return;
	if(r[x] < r[y]){
		par[x] = y;
	}else {
		par[y] = x;
		if(r[x] == r[y]) r[x]++;
	}
}


int main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0; i<n; i++) par[i]=i;
	int ans=0;
	for(int i=0; i<k; i++){
		int t,a,b;
		cin>>t>>a>>b;
		if(t==1){
			a=find(a); b=find(b);
			if(clob[a]==0 || clob[b]==0){
				unite(a,b);
				clob[a]=max(clob[a],clob[b]);
				clob[b]=max(clob[a],clob[b]);
			}else if(clob[a] != clob[b]){
				if(ans==0)ans=i+1;
			}
			
		}else{
			a=find(a);
			if(clob[a]==0){
				clob[a]=b;
			}else if(clob[a] != b){
				if(ans == 0) ans=i+1;
			}
		}
	}
	cout<<ans<<endl;
}




Measured memory_bytes: 4260
program sample
	implicit none
    integer(8) :: x(5)
    
    read(*,*) x
    
    if (x(1) ==0) then
    	write(*,*) 1
    else if (x(2) ==0) then
    	write(*,*) 2
    else if (x(3) ==0) then
    	write(*,*) 3
    else if (x(4) ==0) then
    	write(*,*) 4
    else if (x(5) ==0) then
    	write(*,*) 5        
    end if
    stop
end program sample

Measured memory_bytes: 2664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    for (int i = 1; i < s.length(); i++)
    {
        if (s[i] != '9')
        {
            cout << s[0] - '0' - 1 + (s.length() - 1) * 9 << endl;
            return 0;
        }
    }
    cout << s[0] - '0' + (s.length() - 1) * 9 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
using namespace std;
#define fo(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define fon(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
//short hand for usual tokens
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
#define INF (int)1e9
// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())
//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())
// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())
// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    int arr[5];
    fo(i,5){
        cin>>arr[i];
    }
 
    if(arr[0]==0){
        cout<<1<<endl;
    }else if(arr[1]==0){
        cout<<2<<endl;
    }else if(arr[2]==0){
        cout<<3<<endl;
    }else if(arr[3]==0){
        cout<<4<<endl;
    }else{
        cout<<5<<endl;
    }
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s.at(i);
    // m,a,r,c,hのそれぞれでフィルタリング
    int64_t m=0,a=0,r=0,c=0,h=0;
    rep(i,n) {
        if(s.at(i).at(0)=='M') m++;
        if(s.at(i).at(0)=='A') a++;
        if(s.at(i).at(0)=='R') r++;
        if(s.at(i).at(0)=='C') c++;
        if(s.at(i).at(0)=='H') h++;
    }
    // cout << m << endl;
    // cout << a << endl;
    // cout << r << endl;
    // cout << c << endl;
    // cout << h << endl;
    int64_t res =
      m * a * r
    + m * a * c
    + m * a * h
    + m * r * c
    + m * r * h
    + m * c * h
    + a * r * c
    + a * r * h
    + a * c * h
    + r * c * h;
    cout << res << endl;
}

Measured memory_bytes: 5760
// 2006ツ年ツアツジツアツ地ツ凝ヲツ予ツ選C : Cubic Eight Puzzle
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

char dx[] = {-1,1,0,0};
char dy[] = {0,0,-1,1};
char dice[6][2] = {
  {4,2}, {3,5}, {5,0}, {1,4}, {0,3}, {2,1}
};
int board[9], goal[9];

inline int compress(int space){
  int res = space;
  for(int i=0;i<9;i++){
    if(board[i]!=6) { res = 6*res+board[i]; }
  }
  return res;
}

inline int decode(int state){
  for(int i=8;i>=1;i--) { board[i] = state%6; state /= 6; }
  for(int i=0;i<state;i++) board[i] = board[i+1];
  board[state] = 6;
  return state;
}

inline void initialize(int p){
  memset(board,0,sizeof(board));
  board[p] = 6;
}

inline int err(){
  int res = 0;
  for(int i=0;i<9;i++) res += (goal[i]!=board[i]/2);
  return res;
}

int main(){
  int x, y;
  static bool visit[9*6*6*6*6*6*6*6*6];
  while(cin >> x >> y, x){
    memset(visit,false,sizeof(visit));
    char c;
    for(int i=0;i<9;i++) {
      cin >> c;
      if(c=='W') goal[i] = 0;
      if(c=='B') goal[i] = 1;
      if(c=='R') goal[i] = 2;
      if(c=='E') goal[i] = 3;
    }
    vector<int> cur, next;
    int start = 3*(y-1)+x-1;
    initialize(start);
    visit[compress(start)] = true;
    cur.push_back(compress(start));
    int ans = (err()==0) ? 0 : -1;
    for(int st=1;st<=30&&ans==-1;st++){
      next.clear();
      for(int pos=0;pos<cur.size();pos++){
	int space = decode(cur[pos]);
	int copy[9];
	memcpy(copy, board, sizeof(copy));
	x = space/3, y = space%3;
	for(int i=0;i<4;i++){;
	  int nx = x + dx[i], ny = y + dy[i];
	  if(nx<0||3<=nx||ny<0||3<=ny) continue;
	  int mv = 3*nx+ny;
	  board[space] = dice[board[mv]][i/2];
	  board[mv] = 6;
	  int state = compress(mv);
	  if(!visit[state]){
	    visit[state] = true;
	    int dist = err();
	    if(dist==0) ans = st;
	    if(!(st+dist-1>30)) next.push_back(state);
	  }
	  board[space] = copy[space];
	  board[mv] = copy[mv];
	}
      }
      swap(cur,next);
    }
    cout << ans << endl;
  }
}

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

#define fi first
#define se second
#define ll long long

const int N = 200200;
const int block = 444;

using namespace std;

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        string s;
        cin >> s;
        ll a = 0, b = 0;
        for(int i = 0; i < s.size(); i++){
                if(s[i] == 'B'){
                        a++;
                }
                else{
                        b += a;
                }
        }
        cout << b << "\n";
}




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

int main(void){
    long long int i, j, k, n, ans=0, po=0, nn;
    scanf("%lld", &n);
    long long int f[n+1];
    for(i=0; i<n+1; i++) f[i] = 0;
    for(i=1; i<100; i++){
        for(j=1; j<100; j++){
            for(k=1; k<100; k++){
                nn = i*i+j*j+k*k+i*j+j*k+k*i;
                if(nn<=n) f[nn]++;
            }
        }
    }
    for(i=1; i<=n; i++) printf("%lld\n", f[i]);
    
}

Measured memory_bytes: 1724
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int A[2020200];
int H;
// 1-indexed
void maxHeapify(int i){
  int l = i * 2;
  int r = i * 2 + 1;
  int largest;
  if(l <= H && A[l] > A[i]) {
    largest = l;
  } else {
    largest = i;
  }
  if(r <= H && A[r] > A[largest]) {
    largest = r;
  }
  if(largest != i){
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}
void insert(int x){
  int i = ++H;
  A[i] = x;
  // 親より大きかったら入れ替える
  while(i>1&&A[i]>A[i/2]){
    swap(A[i], A[i/2]);
    i /= 2;
  }
}
int extract(){
  int ret = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  while(cin>>s&&s!="end"){
    if(s=="insert") {
      int x;
      cin >> x;
      insert(x);
    } else {
      cout<<extract()<<endl;
    }
  }
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

bool ume(map<ll, ll> ms, vector <ll> chizu){
    int len = chizu.size();
    REP(i, len){
        ll num = chizu[i];
        map<ll, ll> hiku;
        for(auto pa: ms){
            ll hik = min(pa.second, num);
            //dump(pa.first)
            //dump(pa.second)
            num -= hik;
            hiku[pa.first] = hik;
            if (num == 0){
                break;
            }
        }
        if (num > 0){
            return false;
        }
        for(auto pa: hiku){
            ms[pa.first] -= pa.second;
            if (ms[pa.first] == 0){
                ms.erase(pa.first);
            }
            if (pa.first+1 < 0){
                ms[pa.first+1] += pa.second;
            }
        }
    }
    return true;
}


int main2(void){
    map <ll, ll> m1; m1[-2] = 3;
    vector <ll> c1 = {2, 2, 2};
    //dump(ume(m1, c1))
    map <ll, ll> m2; m2[-3] = 1;
    vector <ll> c2 = {1,2};
    //dump(!ume(m2, c2))
    map <ll, ll> m3; m3[-3] = 5;
    vector <ll> c3 = {5,4,3,2,1};
    map <ll, ll> m4; m4[-3] = 6;
    vector <ll> c4 = {6,4,3,3};
    dump(ume(m4, c4))
}






int main(void){
    ll n; ll m; ll v; ll p;
    cin >> n >> m >> v >> p;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    sort(as.rbegin(), as.rend());
    vector <ll> id; REP(i, n){id.push_back(i);}
    //dumparr(id)
    //dumparr(as)
    //dump(m)
    //dump(v)
    //dump(p)
    map <ll, ll> minos;
    minos[v-n] = m;
    ll can = 0;
    ll cant = n;
    ll mid;
    while(cant - can > 1){
        mid = (can + cant) / 2;
        vector <ll> bs = as;
        vector <ll> cs;
        for(int i=p-1; i<n; i++){
            if (bs[i]<=bs[mid]){
                break;
            }
            cs.push_back(bs[i] - bs[mid]);
        }
        //dump(mid)
        //dumparr(cs)
        if (ume(minos, cs)){
            can = mid;
            continue;
        } else {
            cant = mid;
            continue;
        }
    }
    cout << can + 1 << endl;
    return 0;
}

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

int main() {
  int n, m;
  cin>>n>>m;
  int a[n][m];
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      cin>>a[i][j];
      --a[i][j];
    }
  }
  set<int> sports;
  for (int i=0; i<m; i++) sports.insert(i);

  int idx[n];
  for (int i=0; i<n; i++) idx[i] = 0;

  int ans = n;
  while (sports.size() > 1) {
    int cnt[m];
    for (int i=0; i<m; i++) cnt[i] = 0;
    for (int i=0; i<n; i++) {
      ++cnt[a[i][idx[i]]];
    }
    pair<int, int> max_v = make_pair(-1, 0);
    for (int i=0; i<m; i++) {
      if (cnt[i] > max_v.second) {
        max_v = make_pair(i, cnt[i]);
      }
    }
    ans = min(max_v.second, ans);
    sports.erase(max_v.first);

    for (int i=0; i<n; i++) {
      while (sports.find(a[i][idx[i]]) == sports.end()) {
        ++idx[i];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-6
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
//ll n, m, cnt;
//map<ll, int> MP;
//vector<ll> vec[SIZE];
//ll deg[SIZE], num[SIZE], a[SIZE], b[SIZE];
//
//void bfs(int x) {
//	for (auto i : vec[x]) {
//		if (b[i]) ++deg[MP[x]];
//	}
//}
//
//int main() {
//	io(); cin >> n >> m;
//	rep(i, 1, n) {
//		cin >> a[i] >> b[i];
//		MP[a[i]] = ++cnt;
//	}
//	rep(i, 1, m) {
//		int u, v; cin >> u >> v;
//		u = MP[u]; v = MP[v];
//		vec[u].emplace_back(v);
//		vec[v].emplace_back(u);
//	}
//	rep(i, 1, n) bfs(i);
//	bool f = true;
//	rep(i, 1, n) {
//		if ((deg[i] + b[i]) % 2 == 0) continue;
//		cout << "-1";
//		return 0;
//	}
//	cout << "Yes";
//}
ll a[SIZE], k, n;

bool check(ll limit) {
	ll res = 0;
	rep(i, 1, n) {
		if (a[i] > 0) {
			int L = 1, R = n, mid, ans = 0;
			while (L <= R) {
				mid = (L + R) >> 1;
				if (a[mid] * a[i] <= limit) {
					ans = mid;
					L = mid + 1;
				}
				else R = mid - 1;
			}
			res += ans;
			if (a[i] * a[i] <= limit) res--;
		}
		else if (a[i] < 0) {
			int L = 1, R = n, mid, ans = n + 1;
			while (L <= R) {
				mid = (L + R) >> 1;
				if (a[mid] * a[i] <= limit) {
					ans = mid;
					R = mid - 1;
				}
				else L = mid + 1;
			}
			res += n + 1 - ans;
			if (a[i] * a[i] <= limit) res--;
		}
		else {
			if (limit >= 0) res += n - 1;
		}
	}
	return res / 2 >= k;
}

int main() {
	io(); cin >> n >> k;
	rep(i, 1, n) cin >> a[i];
	sort(a + 1, a + n + 1);
	ll L = -1e18, R = 1e18, mid, ans;
	while (L <= R) {
		mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		}
		else L = mid + 1;
	}
	cout << ans;
}

Measured memory_bytes: 1792
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let K: usize = read();
    let S: usize = read();
    use std::iter;
    let other_num = if S == 1 { 2 } else { S - 1 };
    let ans_vec: Vec<String> = iter::repeat(S.to_string())
        .take(K)
        .chain(iter::repeat((other_num).to_string()).take(N - K))
        .collect();
    println!("{}", ans_vec.join(" "));
}


Measured memory_bytes: 11516
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n, W, ans = 0;
	cin >> n >> W;
	int w[105], v[105];
	rep(i, n) {
		cin >> w[i] >> v[i];
	}
	int dp[105][100002];
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= 100000; j++) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (j <= v[i - 1]) dp[i][j] = min(w[i - 1], dp[i - 1][j]);
			else {
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 100000; j++) {
			if (dp[i][j] <= W) {
				ans = max(ans, j);
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 80640
# 2020/05/10
# AtCoder Beginner Contest 167 - C

def search(idx, ra, pr):
    if idx >= n:
        if min(ra) >= x:
            return pr
        else:
            return 10**9
    else:
        # Buy Book[idx]
        w_ra = list()
        for j in range(m):
            w_ra.append(ra[j] + ca[idx][j+1])
        
        a1 = search(idx+1, w_ra, pr+ca[idx][0])
        # Don't Buy Book[idx]
        a2 = search(idx+1, ra, pr)
        
        if a1 == 10**9 and a2 == 10**9:
            return 10**9
        elif a1 == 10**9:
            return a2
        elif a2 == 10**9:
            return a1
        else:
            return min(a1, a2)

# Input
n, m, x = map(int,input().split())

ca = list()
for i in range(n):
    ca.append(list(map(int,input().split())))

minpr = 10**9

wkl = [0] * m
minpr =search(0, wkl, 0)
if minpr == 10**9:
    minpr = -1

print(minpr)


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

using namespace std;

const int INF = 1 << 29;

int dp[500001][27];
int nxt[21][500001];

int main() {
  string s;
  cin >> s;
  for(auto &c : s) c -= 'a';

  fill_n(*dp, 500001 * 27, INF);
  for(int i = (int) s.size() - 1; i >= 0; i--) {
    dp[i][s[i]] = i + 1;
    for(int j = s[i] + 1; j <= 26; j++) {
      if(dp[i][j - 1] == INF) break;
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
    }
    if(dp[i][26] != INF) {
      for(int j = 0; j < s[i]; j++) dp[i][j] = dp[dp[i][26]][j];
    }
  }

  fill_n(*nxt, 21 * 500001, INF);
  for(int i = 0; i < s.size(); i++) {
    nxt[0][i] = dp[i][26];
  }
  for(int i = 1; i < 21; i++) {
    for(int j = 0; j < s.size(); j++) {
      if(nxt[i - 1][j] == INF) continue;
      nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
    }
  }

  int Q;
  cin >> Q;
  while(Q--) {
    int L, R;
    cin >> L >> R;
    --L;
    int pos = L;
    for(int i = 20; i >= 0; i--) {
      if(nxt[i][pos] <= R) pos = nxt[i][pos];
    }
    if(pos == R) cout << "Yes\n";
    else cout << "No\n";
  }

}

Measured memory_bytes: 94980