akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

c = [[0 for _ in range(w)] for _ in range(h)]
s = []
for i in range(len(a)):
    for j in range(a[i]):
        s.append(i+1)

idx = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            c[i][j] = s[idx]
            idx += 1
    else:
        for j in reversed(range(w)):
            c[i][j] = s[idx]
            idx += 1

for i in range(len(c)):
    print(" ".join(list(map(str, c[i]))))




Measured memory_bytes: 40944
#include <iostream>
#include <cctype>
using namespace std;
 
int main(){
    while(true){
        char s;
        cin.get(s);
        if(islower(s)){
            s = toupper(s);
        }
        cout << s;
        if(s == '\n'){
            break;
        }
    }
    return(0);
}

Measured memory_bytes: 1092
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


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

  return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type card struct {
	mark string
	number int
}

// return 1 if x > y
// return -1 if x < y
// return 0 if x == y
func compare(x, y card) int {
	if x.number > y.number {
		return 1
	} else if x.number < y.number {
		return -1
	} else {
		return 0
	}
}

func isSame(x, y []card) bool {
	if len(x) != len(y) {
		return false
	}
	for i := 0; i < len(x); i++ {
		if x[i] != y[i] {
			return false
		}
	}
	return true
}

func partition(cards []card) int {
	n := len(cards)
	pos := 0
	pivot := cards[n-1]
	for i := 0; i < n-1; i++ {
		if compare(cards[i], pivot) <= 0 {
			cards[i], cards[pos] = cards[pos], cards[i]
			pos++
		}
	}
	cards[pos], cards[n-1] = pivot, cards[pos]
	return pos
}

func quickSort(cards []card) {
	if len(cards) <= 1 {
		return
	}
	p := partition(cards)
	quickSort(cards[:p])
	quickSort(cards[(p+1):])
}

func mergeSort(cards []card) []card {
	SENTINEL := card{mark: "X", number: 1000000001} // for merge sort
	if len(cards) == 1 {
		return []card{cards[0]}
	}
	mid := len(cards) / 2
	leftCards := append(mergeSort(cards[:mid]), SENTINEL)
	rightCards := append(mergeSort(cards[mid:]), SENTINEL)

	var li, ri, i int
	newCards := make([]card, len(cards))
	for i < len(cards) {
		if compare(leftCards[li], rightCards[ri]) <= 0 {
			newCards[i] = leftCards[li]
			li++
		} else {
			newCards[i] = rightCards[ri]
			ri++
		}
		i++
	}
	return newCards
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	cards := make([]card, n)

	for i := 0; i < n; i++ {
		mark := nextText(sc)
		number, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		cards[i] = card{mark: mark, number:number}
	}

	sortedByMerge := mergeSort(cards)
	quickSort(cards)

	if isSame(sortedByMerge, cards) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}

	for i := 0; i < n; i++ {
		fmt.Printf("%s %d\n", cards[i].mark, cards[i].number)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}


Measured memory_bytes: 19072
from math import gcd
k = int(input())
total = 0
ab_gcd = []
for a in range(1,k+1):
    for b in range(1,k+1):
        ab_gcd.append(gcd(a,b))
for ab in ab_gcd:
    for c in range(1,k+1):
        abc = gcd(ab,c)
        total += abc
print(total)

Measured memory_bytes: 9292
#include <iostream>
#include <queue>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprv(i, n) for (int i = n - 1; i >= 0; i--)
#define ll long long
using namespace std;

using pair_work = pair<ll,ll>;

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

    priority_queue<pair_work, vector<pair_work>, greater<pair_work>> work_queue;

    rep(i, n) {
        pair_work p;
        cin >> p.second >> p.first;
        work_queue.push(p);
    }

    // work_queue内では 締め切りが少ない順に割り振られる.
    ll total = 0;
    bool can_work_in_time = true;
    while(!work_queue.empty() && can_work_in_time) {
        total += work_queue.top().second;
        if (total > work_queue.top().first) {
            can_work_in_time = false;
        }
        work_queue.pop();
    }

    cout << (can_work_in_time ? "Yes" : "No") << endl;

}


Measured memory_bytes: 6512
import sys
import itertools

N, M = map(int, input().split())
S = [[int(x) for x in sys.stdin.readline().split()][1:] for _ in range(M)]
P = [int(x) for x in input().split()]

ans = 0

for state in itertools.product([0, 1], repeat=N):
    is_ans = True
    for bulb, p in zip(S, P):
        connected = 0
        for idx in bulb:
            if state[idx - 1] == 1:
                connected = connected + 1
        if connected % 2 != p:
            is_ans = False
            break
    if is_ans:
        ans = ans + 1

print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Integer, Map<Integer, ABC166EAgent>> map = new HashMap<>();
        ABC166EAgent[] agents = new ABC166EAgent[n+1];
        for(int i=1; i<=n; i++) {
            ABC166EAgent a = new ABC166EAgent();
            a.num = i;
            a.height = in.nextInt();
            int key = a.num - a.height;
            if(map.containsKey(key)) {
                Map<Integer, ABC166EAgent> innerMap = map.get(key);
                innerMap.put(a.num, a);
            }
            else {
                Map<Integer, ABC166EAgent> innerMap = new HashMap<>();
                innerMap.put(a.num, a);
                map.put(key, innerMap);
            }
            agents[i] = a;
        }
        
        long ans = 0;
        for(int i=1; i<=n; i++) {
            ABC166EAgent a = agents[i];
            int myKey = a.num - a.height;
            map.get(myKey).remove(a.num);
            
            int searchKey = a.num + a.height;
            Map<Integer, ABC166EAgent> innerMap = map.get(searchKey);
            if(innerMap != null) {
                ans += innerMap.size();
            }
        }
        System.out.println(ans);
    }
}
class ABC166EAgent {
    int num;
    int height;
}


Measured memory_bytes: 114964
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
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); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m); 
}

int main(void){
	int N,p;
	string s;
	pair<string,int> tem;
	map<pair<string,int>,int> sp;
		
	cin>>N;
	REP(i,N){
		cin>>s>>p;
		tem.first=s;
		tem.second=-p;
		sp[tem]=i+1;
	}
	
	for(auto itr = sp.begin(); itr != sp.end(); ++itr)
		print(itr->second);
	
	return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int k;
  cin >> k;
  if (a < b && b < c) {
    cout << "Yes" << endl;
    return 0;
  }
  bool ok = false;

  for (int i = 0; i <= k; i++) {
    int j = k - i;
    int b1 = b;
    int c1 = c;
    if (i >= 1) b1 = b1 * pow(2, i);
    if (j >= 1) c1 = c1 * pow(2, j);
    if (a < b1 && b1 < c1) ok = true;
  }

  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  
  int l = S.size();
  int check = 0;
  
  for(int i=0; i<l; i++){
    if (S.at(i) == T.at(i)){
    }
    else {
      check = 1;
      break;
    }
  }
  
  if (check == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if ((a + b + 1)>= c) cout << b + c << endl;
  else cout << b + (a + b + 1) << endl;  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353 
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define pi 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long double
typedef pair<int, int> pii;
//#define float unsigned long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y,int m) 
{
	x += y;
	if (x >= m) return x - m;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b,int m) 
{
	return (long long) a * b % m;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
    if(a.first==b.first)
    return a.second<b.second;
      return (a.first > b.first); 
       //return (a.first-a.second)>(b.first-b.second);
}

vector<int> z_function(string &s)
{
	int n=s.size();
	vector<int> z(n);
	for(int i=1,l=0,r=0;i<n;i++)
	{
		if(i<=r)
			z[i]=min(r-i+1, z[i-l]);
		while(i+z[i]<n && s[z[i]]==s[i+z[i]])
			z[i]++;
		if(i+z[i]-1>r)
			l=i, r=i+z[i]-1;
	}
	return z;
}

bool isprime(int n) 
{ 
    if (n <= 1)  return false; 
  
    for (int i=2; i*i<=n; i++) 
        if (n%i == 0) 
            return false; 
  
    return true; 
}

void SieveOfEratosthenes(int n, bool isPrime[]) 
{ 
    isPrime[0] = isPrime[1] = false; 
    for (int i=2; i<=n; i++) 
        isPrime[i] = true; 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (isPrime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                isPrime[i] = false; 
        } 
    } 
}


int32_t main()
{
    /* freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); */
    FAST
    cout << fixed << setprecision(16);

    int n;
    cin>>n;
    if(n>=30)
    cout<<"Yes";
    else
    cout<<"No";
    
    
    return 0;
}





Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:04:29 2018
ALDS1-3a
@author: maezawa
"""
maxn=200
s = input().split()
st = [0 for _ in range(maxn)]
top = 0

for i in range(len(s)):
    c = s.pop(0)
    if c == '+':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a + b
        top += 1
        st[top] = ans
    elif c == '-':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a - b
        top += 1
        st[top] = ans
    elif c == '*':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a * b
        top += 1
        st[top] = ans
    else:
        top += 1
        st[top] = int(c)
print(st[top])


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> a(5);
    for (int& x : a)
        cin >> x;
    int k;
    cin >> k;
    cout << (k >= *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) ? "Yay!" : ":(");            
    return 0;
}
                

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<char>> a(n, vector<char>(n));
  vector<vector<char>> b(m, vector<char>(m));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      cin >> b[i][j];
    }
  }
  bool f=false;
  for(int i=0;i<n-m+1;i++){
    for(int j=0;j<n-m+1;j++){
      bool c=true;
      for(int k=0;k<m;k++){
        for(int l=0;l<m;l++){
          if(b[k][l]!=a[k+i][l+j]){
            c=false;
          }
        }
      }
      if(c){
        f=true;
      }
    }
  }
  if(f){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N,K = map(int,input().split())
V = [0] + list(map(int,input().split())) + [0]
m = min(N,K)

A = []
ans = 0

#左からi個、右からj個除いた時の宝石の価値のmax

for i in range(m+1):
    if i == 0:
        pass
    else:
        A.append(V[i])
    B = []
    for j in range(m-i+1):
        if j == 0:
            pass
        else:
            B.append(V[N-j+1])
        C = A+B
        C.sort()
        a = sum(C)
        for k in range(len(C)):
            if C[k] < 0 and k < K-(i+j):
                a -= C[k]
        ans = max(ans,a)

print(ans)

Measured memory_bytes: 41712
#include<iostream>
#define N_MAX 100000
#define SENTINEL 2000000000
using namespace std;

struct card{
    char suit;
    int num;
};    

card l[N_MAX/2+2],r[N_MAX/2+2];

void merge(card a[],int left,int mid,int right){
    
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) l[i]=a[left+i];
    for(int i=0;i<n2;i++) r[i]=a[mid+i];
    l[n1].num=r[n2].num=SENTINEL;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(l[i].num<=r[j].num) a[k]=l[i++];
        else a[k]=r[j++];
    }
}

void mergeSort(card a[],int left,int right){
    int mid;
    if(right-left>1){
        mid=(left+right)/2;
        mergeSort(a,left,mid);
        mergeSort(a,mid,right);
        merge(a,left,mid,right);
    }
}

int partition(card a[],int p,int r){
    card x=a[r];
    int i=p-1;
    for(int j=p;j<r;j++){
        if(a[j].num<=x.num){
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[++i],a[r]);
    return i;
}

void quickSort(card a[],int p,int r){
    int q;
    if(p<r){
        q=partition(a,p,r);
        quickSort(a,p,q-1);
        quickSort(a,q+1,r);
    }
}

int main(){
    int n;
    card a[N_MAX],b[N_MAX];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].suit>>a[i].num;
        b[i]=a[i];
    }
    quickSort(a,0,n-1);
    mergeSort(b,0,n);
    bool stable=true;
    for(int i=0;i<n;i++){
        if(a[i].suit!=b[i].suit){
            stable=false;
            break;
        }
    }
    if(stable) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    for(int i=0;i<n;i++){
        cout<<a[i].suit<<' '<<a[i].num<<endl;
    }
}


Measured memory_bytes: 5460
#include<bits/stdc++.h>
using namespace std;
long long int knapSack(long long int W,long long int wt[],long long int val[],long long int n) 
{ 
   long long int i, w; 
   long long int K[n+1][W+1]; 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
int main()
{
	ios_base::sync_with_stdio;
	cin.tie(NULL);
	cout.tie(NULL);
	long long int i,j,k,l,m,n,w;
	cin>>n>>w;
	long long wt[n],val[n];
	for(i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	n=knapSack(w,wt,val,n);
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;



void solve() {

	long long MAX = 1000000;
	long long H;
	cin >> H;
	long long ans = 0;
	long long nk = 1;
	if (H == 1) {
		cout << 1 << endl;
	}
	else {
		while (MAX>0) {
			H = H / 2;
			ans+=nk;
			nk *= 2;
			MAX--;
			if (H == 1) {
				ans+=nk;
				cout << ans << endl;
				break;
			}
		}
	}

	

}



int main() {
	solve();

}

Measured memory_bytes: 256
N, M = map(int, input().split())
if N % 2 == 0:
    k = min(M, N // 4)
    i = 0
    j = 1
    for m in range(k):
        print(i + 1, j + 1)
        i = (i - 1) % N
        j = (j + 1) % N
    j = (j + 1) % N
    for m in range(M - k):
        print(i + 1, j + 1)
        i = (i - 1) % N
        j = (j + 1) % N
else:
    i = 0
    j = 1
    for m in range(M):
        print(i + 1, j + 1)
        i = (i - 1) % N
        j = (j + 1) % N

Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n; cin >> n;
  vector<double> a(n);
  rep(i, n) cin >> a[i];

  sort(all(a));
  double tmp;
  for (int i = 1; i < n; i ++) {
    tmp = (a[i] + a[i - 1]) / 2;
    a[i] = tmp;
  }
  cout << setprecision(15) << a[n - 1] << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

struct dat
{
	int n;
	int p;

	dat(int n, int p)
	{
		this->n = n;
		this->p = p;
	}
};

int binary_search(int x, vector<dat> &d)
{
	int l = 0;
	int r = d.size();

	int c = 0;

	for (; r > l;)
	{
		int i = (l + r) / 2;
		if (d.at(i).n == x)
		{
			return d.at(i).p;
		}
		else if (d.at(i).n < x)
		{
			l = i + 1;
		}
		else
		{
			r = i;
		}
	}

	return 0;
}

int main()
{
	int n;
	for (; cin >> n;)
	{
		int count = 0;
		vector<int> a;
		
		for (int i = 0; i <= 9; i++)
		{
			for (int j = 0; j <= 9; j++)
			{
				a.push_back(i + j);
			}
		}

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

		int old = a.at(0);
		int p = 1;
		vector<dat> d;
		for (int i = 1; i < a.size(); i++)
		{
			if (old == a.at(i))
			{
				p++;
			}
			else
			{
				d.push_back(dat(old, p));
				p = 1;
			}

			old = a.at(i);
		}

		d.push_back(dat(old, p));

		for (int i = 0; i <= 9; i++)
		{
			for (int j = 0; j <= 9; j++)
			{
				count += binary_search(n - i - j, d);
			}
		}
		
		cout << count << endl;
	}
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define min(a,b) a<b? a:b

using namespace std;
int main()
{
    int n,A,B;
    cin>>n>>A>>B;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    int la=0,lb=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=A)
            la++;
        else if(a[i]>A && a[i]<=B)
            lb++;
    }
    int minm=min(la,lb);
    minm=min(minm,a.size()-la-lb);
    cout<<minm<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const ll INF = 0x3f3f3f3f;

struct Block
{
    int x, s, t;
    bool operator<(const Block &b){return x<b.x;}
};

vector<Block> vec;
vector<int> ans(200001, -1);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    int n, q, Q, x, s, t;
    cin >> n >> q;
    for(int i=0; i<n; i++)
    {
        cin >> s >> t >> x;
        vec.push_back({x, s, t});
    }
    sort(vec.begin(), vec.end());
    set< pair<int, int> > se;
    for(int i=0; i<q; i++)
    {
        cin >> Q;
        se.insert({Q, i});
    }
    se.insert({1000000000, 0});
    for(auto b : vec)
    {
        auto it = se.lower_bound({b.s-b.x, -1});
        for(;;)
        {
            if(it->first>=b.t-b.x) break;
            ans[it->second]=b.x;
            it = se.erase(it);
        }
    }
    for(int i=0; i<q; i++) cout << ans[i] << endl;
}


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

int main()
{
    int n;
    int i, j;
    
    cin >> n;
    
    int count = 1;
    
    vector<string> s(n);
    
    for(i = 0; i < n; i++) {
        cin >> s[i];
    }
    
    sort(s.begin(), s.end());
    
    for(i = 1; i < n; i++) {
        if(s[i] != s[i-1]) {
            count += 1;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 9600
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),k=in();
    vector<bool>s(n,false);
    for(ll i=0;i<k;++i){
        ll d=in();
        for(ll j=0;j<d;++j)s[in()-1]=true;
    }
    cout<<count(s.begin(),s.end(),false)<<endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int diff = 1e9;
    for (int i = 0; i <= n - 3; ++i)
    {
        int m = 0;
        for (int j = 0; j < 3; ++j)
            m *= 10, m += s[i + j] - '0';
        diff = min(diff, abs(m - 753));
    }
    cout << diff;
}


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


int main() {
  int n;  cin >> n;
  ll ans = 0;
  vector<int> v(n);
  rep (i, n) cin >> v[i];

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

  ans = v[0];
  repp (i, 2, 4) ans += v[1];
  repp (i, 4, n) {
    ans += v[i/2];
  }
  
  if (n == 2) ans = v[0];
  if (n == 3) ans = v[0] + v[1];
  if (n == 4) ans = v[0] + v[1] + v[2];
  cout << ans << endl;
}

Measured memory_bytes: 4056
import itertools

N, P = [int(i) for i in input().split()]
biscuits = [int(i) for i in input().split()]
even = 0
odd = 0
buffer_count = 1
even_c = 1

for i in biscuits:
    if i % 2 == 0:
        even += 1
    elif i % 2 == 1:
        odd += 1

if P == 0:
    # even
    odd_c = 1
elif P == 1:
    # odd
    odd_c = 0

if even > odd:
    for i in range(1, even+1):
        even_c += 2 ** (i-1)
        if i == odd:
            buffer_count = even_c
elif odd >= even:
    for i in range(1, odd+1):
        buffer_count += 2 ** (i-1)
        if i == even:
            even_c = buffer_count

if P == 0:
    # even
    if buffer_count > 2:
        odd_c = (buffer_count / 2)
elif P == 1:
    # odd
    if buffer_count > 1:
        odd_c = (buffer_count / 2)

print(int(even_c * odd_c))

Measured memory_bytes: 3064
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
a_sum = sum(a)

cnt=0
for i in range(m):
    if a[i] < a_sum / (4*m):
        cnt += 1
if cnt > 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    res = min(N%K,K-N%K);
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int BinarySearch(int A[], int n, int key){
    int left = 0;
    int right = n;
    int mid = 0;
    while(left < right){
        mid = (left + right) /2;
        if(A[mid] == key) return 1;
        else if (A[mid] < key) left = mid+1;
        else right = mid;
    }
    return 0;
}

int main(){
    int i, n, A[1000000], q, key, sum = 0;
    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d",&A[i]);

    scanf("%d",&q);
    for(i = 0; i<q; ++i) {
        scanf("%d", &key);
        if(BinarySearch(A, n, key)) sum++;
    }

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

    return 0;    
    
}


Measured memory_bytes: 2124
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
                first = false;
            }
            cout << x;
        }
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();
    std::vector<int> d(N);
    in.read(d.begin(), N);

    std::uint64_t res = 0;
    for (int i : boost::irange(0, N)) {
        for (int j : boost::irange(i + 1, N)) {
            res += d[i] * d[j];
        }
    }
    out << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll p=1000000007;
ll bin(ll x,ll po)
{
    ll ans=1;
    if(po==0)
        return ans;
    if(po%2==1)
    {
        po--;
        ans=ans*x%p;
    }
    ll p1=bin(x,po/2);
    ans=ans*p1%p;
    ans=ans*p1%p;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll fact[101011];
    fact[0]=1;
    ll factinv[101011];
    factinv[0]=1;
    for(ll i=1;i<=101010;i++)
    {
        fact[i]=fact[i-1]*i%p;
        factinv[i]=factinv[i-1]*bin(i,p-2)%p;
    }
    ll a[n+1];
    for(ll i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    ll sum1=0;
    for(ll i=k;i<=n;i++)
    {
        sum1=(sum1+(a[i]*((fact[i-1]*factinv[k-1]%p)*factinv[i-k]%p))%p)%p;
    }
    ll sum2=0;
    sort(a+1,a+n+1,greater<ll>());
    for(ll i=k;i<=n;i++)
    {
        sum2=(sum2+(a[i]*((fact[i-1]*factinv[k-1]%p)*factinv[i-k]%p))%p)%p;
    }
    cout<<((sum1-sum2)%p+p)%p;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			if (i*4+j*7==n || i*7+j*4==n){
				cout<<"Yes"<<endl;
				return 0;
			}	
	cout<<"No"<<endl;
	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct mint {
  ll x;
  mint(ll x=0) : x(x%mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) {
    mint res(*this);
    return res*=a;
  }
};

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

  int n, k; std::cin >> n >> k;
  ll l = 0, r = 0;
  mint ans = 1;
  rep(i, k) l += i, r += (n-i);
  srep(i, k, n+1) {
    ans += r-l+1;
    l += i, r += (n-i);
  }
  std::cout << ans.x << "\n";
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <stdlib.h>
#define NIL -1

typedef struct{
  int parent;
  int left;  //左の子
  int right; //右の兄弟
  int children; //子の数
}Node;

int getDepth(Node**, int);

main(){
  int n, i, j, k, id, child, child_, depth;
  Node **nodes;

  scanf("%d", &n);
  nodes = (Node**)malloc(sizeof(Node*)*n);
  for(i=0; i<n; i++){
    nodes[i] = (Node*)malloc(sizeof(Node));
    nodes[i]->parent = NIL;
    nodes[i]->left = NIL;
    nodes[i]->right = NIL;
  }

  for(i=0; i<n; i++){
    scanf("%d", &id);
    scanf("%d", &(nodes[id]->children));
    for(j=0; j < (nodes[id]->children); j++){
      scanf("%d", &child);
      nodes[child]->parent = id;
      if(j==0) nodes[id]->left = child;
      if(j>0) nodes[child_]->right = child;
      child_ = child;
    }
  }

  for(i=0; i<n; i++){
    depth = getDepth(nodes, i);
    printf("node %d: parent = %d, depth = %d, ",i, nodes[i]->parent, depth);
    
    if(depth == 0) printf("root, [");
    else if(nodes[i]->children == 0) printf("leaf, [");
    else printf("internal node, [");

    for(j = nodes[i]->left; j != NIL;){
      printf("%d", j);
      j = nodes[j]->right;
      if(j != NIL) printf(", ");
    }

    printf("]\n");
  }

  return 0;
}

int getDepth(Node **nodes, int p){
  if(nodes[p]->parent == NIL) return 0;
  else{
    return 1 + getDepth(nodes, nodes[p]->parent);
  }
}

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

int main(){
  int n;
  cin >> n;
  for (int i = 1; i < 10; i++){
    for (int j = i; j < 10; j++){
      if (n == i * j){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import sys


def sum_of(i):
    sum = 0
    for digit in str(i):
        sum += int(digit)
    return sum


n = int(input())
min = sys.maxsize
for i in range(1, n):
    sum_a = sum_of(i)
    sum_b = sum_of(n - i)
    total = sum_a + sum_b
    if min > total:
        min = total
print(min)


Measured memory_bytes: 2940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            out.println(Math.min(b / a, c));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define PI 3.14159265358979

using namespace std;

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

  vector<pair<int, int>> a(n);

  for (int i = 0; i < n; i++){
    cin >> a[i].first;
    a[i].second = i + 1;
  }

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

  for (int i = 0; i < n; i++){
    cout << a[i].second << " ";
  }
  cout << endl;

  return 0;
}


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

int main(){
  long long a, b;
  cin >> a >> b;
  if( a==1 && b==1){
    cout << 1 << endl;
  }
  else if(a==1 || b==1){
    cout << a*b-2 << endl;
  }
  else{
    cout << (a-2)*(b-2) << endl;
  }
}



 
  

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  double W, H, w, h, x, y;
  
  scanf("%lf%lf%lf%lf%lf%lf", &W, &H, &w, &h, &x, &y);

  double l = max(x - w/2, -W/2);
  double r = min(x + w/2, W/2);
  double u = max(y - h/2, -H/2);
  double d = min(y + h/2, H/2);

  
  assert(abs(l+r) > 1e-8);

  
  printf("%.10lf\n",((u+d)/2)/((l+r)/2));
  
  return 0;
}



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

int main() {
  int N, a[200000];
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> a[i];
  }
  int sum = 0, left = 0;
  long long ans = 0;
  for (int i=0; i<N; i++) {
    while (sum & a[i]) {
      ans += i - left;
      sum -= a[left];
      left++;
    }
   sum |= a[i];
  }
  while (left < N) ans += N - left++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define maxn 100005
#define Mod 1000000007
using namespace std;
int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
int a[maxn],f[maxn];
int main(){
	a[1]=1;
	int tmp=6,tot=1;;
	for(int i=1;i<=8;i++)a[++tot]=tmp,tmp=tmp*6;
	tmp=9;
	for(int i=1;i<=7;i++)a[++tot]=tmp,tmp=tmp*9;
	sort(a+1,a+tot+1);int ans=0,n=read();
	while(a[tot]>n)tot--;
	memset(f,127/3,sizeof(f));f[n]=0;
	for(int i=n;i>=0;i--)
		for(int j=1;a[j]<=i&&j<=tot;j++)f[i-a[j]]=min(f[i-a[j]],f[i]+1);
	printf("%d\n",f[0]);
	return 0;
}

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

main(){
	int n;
	cin>>n;
	
	int ans = 100000;
	for(int i=0; i<n; i++){
		ans = (int(ans + ans*0.05 + 999)/1000)*1000;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3056
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include <functional>
#include <array>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
#define FI first
#define SE second
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::string str;
typedef std::pair<str,pi> pspi;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
str S[110];
int P[110];
pspi ps[110];
bool comp(pspi& a,pspi& b){
  if(a.FI==b.FI){
    return a.SE.FI>b.SE.FI;
  }
  else return a.FI<b.FI;
}
int main(){
  int res[110];
  cin>>N;
  rep(i,N){
    cin>>S[i]>>P[i];
  }
  rep(i,N){
    ps[i]=mp(S[i],mp(P[i],i));
  }
  std::sort(ps,ps+N,comp);
  rep(i,N){
    res[i]=ps[i].SE.SE+1;
  }
  rep(i,N){
    prin(res[i]);
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//喜ぶお菓子の数が少ない子供から順にお菓子を配る
//お菓子を全て配らなけばならない
//全員にお菓子を配り終えてなお、お菓子が余っていれば残りを誰か一人にやり、ans-1する
int main(){
  int N,x;
  cin >> N >> x;
  vector<int> a(N);
  rep(i,N){
    cin >> a[i];
  }
  int ans = 0;
  sort(a.begin(),a.end());

  
  for(int i = 0;i<N;i++){
    if(x == 0) break;
    else if(x < a[i] && ans >=1){//既に数人にお菓子を配り、残りのお菓子が、次の子供の満足するお菓子より少ない時、
      
      break;
    }
    else if(x < a[i] && ans == 0){//まだ誰にも配らず、残りのお菓子が、次の子供の満足するお菓子より少ない時、
      break;
    }
    else if(x >= a[i] && i<= N-2){//残りのお菓子が、満足するお菓子より多い時、
      x -= a[i];
      ans++;
    }
    else if(x == a[i] && i==N-1){//最後の一人に、満足するjustのお菓子を配ってしまう時
      ans += 1;
    }
    else if(x > a[i] && i==N-1){//最後の一人に、満足する以上のお菓子を配ってしまう時
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  int x = 0, s = 0;
  rep(i, n - 1) {
    s += a[i];
    if (2 * s < a[i + 1]) x = i + 1;
  }
  cout << n - x << endl;
}


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

long long N, A[100009][4], dp[100009][4];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i][1] >> A[i][2] >> A[i][3];
		for (int j = 0; j <= 3; j++) dp[i][j] = -(1LL << 60);
	}
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= 3; j++) {
			for (int k = 1; k <= 3; k++) {
				if (j == k) continue;
				dp[i][k] = max(dp[i][k], dp[i - 1][j] + A[i][k]);
			}
		}
	}
	cout << max(dp[N][1], max(dp[N][2], dp[N][3])) << endl;
	return 0;
}

Measured memory_bytes: 6528
module Main where

import Data.Functor

main :: IO ()
main = do
  { [x] <- getInts
  ; putInts [x^3]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a+b+c>=22?"bust":"win")<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.awt.Point;
import java.util.*;
   
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
while(!(str=br.readLine()).equals("0 0")){
String[] value=str.split(" ");
int h=Integer.parseInt(value[0]);
int w=Integer.parseInt(value[1]);
char[][] map=new char[h][w];
for(int i=0;i<h;i++){
map[i]=br.readLine().toCharArray();
}
Deque <Point> fifo  =new  ArrayDeque<Point>();
  int ans=0;
   for(int m=0;m<h;m++){
   for(int n=0;n<w;n++){
if(map[m][n]!='.'){
ans++;
Point p = new Point(n,m);
fifo.addLast(p);
while(fifo.peekFirst()!=null){
p=fifo.pollFirst();
int x=p.x;
 int y=p.y;
  char crop = map[y][x];
map[y][x]='.';
 int [] dx ={0,1,0,-1};
 int [] dy ={1,0,-1,0};                   
     for(int i=0;i<4;i++){
      int nx =x+dx[i];
   int ny =y+dy[i];
if(0<=nx&&nx<w&&0<=ny&&ny<h&&map[ny][nx]==crop&&map[ny][nx]!='.'){

          Point np = new Point();
                        np.x=nx;
                        np.y=ny;
                     fifo.addLast(np);                       
}
}
}
}
}
}System.out.println(ans);
}
}
}

Measured memory_bytes: 25840
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
    if(x<0){putchar('-'),write(-x);}
    else{if(x>9)write(x/10);putchar('0'+x%10);}
}




const int N=2e5+5;
int n,k;
double ans,pre[N];

signed main(){
	read(n);read(k);
	for(int i=1,x;i<=n;i++){
		read(x);
		pre[i]=pre[i-1]+1.0*(1+x)*x/2/x;
	}
	for(int i=k;i<=n;i++) ans=max(ans,1.0*(pre[i]-pre[i-k]));
	printf("%.10lf",ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MOD = 998244353;

const double EPS = 1e-6;
const int MAX = 300 * 1000 + 47;


int main()
{
    int n;
    scanf("%d", &n);
    int ans = 0, lst = 0;
    FOR(i, 0, n)
    {
        int x;
        scanf("%d", &x);
        int lg = 0;
        while((1 << lg) < x)++lg;
        ans += lg;
        ans -= min(lst, lg);
        lst = lg - 1 + ((1 << lg) == x || lg-1 >= lst);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256