akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	f := factorize(n)

	ans := 0
	for _, p := range f {
		t := p
		i := 1
		for t-i >= 0 {
			ans++
			t -= i
			i++
		}
	}
	fmt.Fprintln(wr, ans)
}

func factorize(n int) map[int]int {
	res := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			res[i]++
			n /= i
		}
	}
	if n != 1 {
		res[n] = 1
	}
	return res
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define TRAV(a, x) for(const auto& a : x)
#define ALL(x) x.begin(), x.end()
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

typedef long long ll;

ll k, x;

void solve() {
  int r = 500 * k;
  string re = (r >= x) ? "Yes" : "No";
  cout << re;
}

void input() {
  cin >> k >> x;
}
 
int main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 384
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<limits>;

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const ll INF=1<<30;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
ll A[500010];
ll cnt = 0;
void merge(ll *A,int left,int mid,int right){
	int n1 = mid-left;
	int n2 =right -mid;
	ll L[n1+1];
	ll R[n2+1];
	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]=INF;
	R[n2]=INF;
	int i = 0;
	int j = 0;
	for(int k = left;k <=right-1;k++){
		if(L[i]<=R[j]){
			A[k] =L[i];
			i++;
			cnt++;
		}else{
			A[k] = R[j];
			j++;
			cnt++;
		}
	}
}
void merge_sort(ll *A,int left,int right){
	if(left+1<right){
		int mid = (left+right)/2;
		merge_sort(A,left,mid);
		merge_sort(A,mid,right);
		merge(A,left,mid,right);
	}
}
int main(){
	int n;
	cin>>n;
	for(int i = 0;i < n;i++){
		cin>>A[i];
	}
	int left = 0;
	int right = n;
	merge_sort(A,left,right);
	for(int i = 0;i < n;i++){
		cout <<A[i];
		if(i!=n-1){
			cout <<" ";
		}else{
			cout <<endl;
		}
	}
	cout <<cnt<<endl;
	return 0;
}

Measured memory_bytes: 8972
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
string s,t;
  ll result=0;
cin >>s;
cin >>t;
for(int i=0;i<s.size();i++){
  if(s[i]!=t[i])result++;
}
cout <<result;
return 0;
}






ll gcd(ll a, ll b){

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

}

Measured memory_bytes: 3856
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll ruijo(ll x,ll n){
	long long p,ans;
	if(n==0)return 1;
	if(n==1)return x;
	if(n%2){
		p = ruijo(x,n/2);
		ans = (x*p)%mod;
		ans = (ans*p)%mod;
		return ans;
	}else{
		p = ruijo(x,n/2);
		ans = (p*p)%mod;
		return ans;
	}
}

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
            a.push_back(i);
            if(i!=n/i){
                a.push_back(n/i);
            }
        }
    }
    map<ll,ll> mp;
    ll ans = 0;
    sort(a.begin(),a.end());
    rep(i,a.size()){
        ll t = a[i];
        ll sz = 0;
        if(t%2==0){
            sz = ruijo(k,t/2);
        }else{
            sz = ruijo(k,t/2+1);
        }

        if(t==1){
            ans += sz;
            ans %= mod;
        }else{
            for(ll j=1;j<=sqrt(t);j++){
                if(t%j==0){
                    sz += mod-mp[j];
                    sz %= mod;
                    if(j!=t/j){
                        sz += mod-mp[t/j];
                        sz %= mod;
                    }
                }
            }
            if(t%2==0){
                ans += sz*t/2%mod;
                ans %= mod;
            }else{
                ans += sz*t%mod;
                ans %= mod;
            }

        }
        mp[t] = sz;
        //cerr << t << " " << mp[t] << " " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


void solve(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    int n=min(s.size(),t.size());
    for(int i=0;i<n;i++){
        if(s[i]<t[i]){
            cout << "Yes" << endl;
            return;
        }
    }
    if(s[n-1]==t[n-1] && s.size()<t.size())cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


Measured memory_bytes: 256
// C++ program to get updated array after many array range 
// add operation 
#include <bits/stdc++.h> 
using namespace std; 

int main() 
{ 
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int cnt=0,m=a[0];
	for(int i=0;i<n;i++)
	{
	    if(a[i]<=m)
	    {
	        cnt++;
	        m=a[i];
	    }
	}
	cout<<cnt;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		long[] a = new long[n];
		
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextLong();
		}
		
		boolean[] bad = new boolean[n];
		for(int i = 0; i < m; i++)
		{
			int ta = sc.nextInt()-1;
			int tb = sc.nextInt()-1;
			
			if(a[ta] >= a[tb]) //b is bad
			{
				bad[tb] = true;
			}
			if(a[tb] >= a[ta]) //a is bad
			{
				bad[ta] = true;
			}
			
		}
		
		int c = 0;
		for(int i = 0; i < n; i++)
		{
			if(!bad[i])c++;
		}
		System.out.println(c);
	}

}


Measured memory_bytes: 50388
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int month1 = sc.nextInt();
    int day1 = sc.nextInt();
    int month2 = sc.nextInt();
    int day2 = sc.nextInt();

    if(month1 != month2)
      System.out.println(1);
    else
      System.out.println(0);
  }
}

Measured memory_bytes: 22356
def boxes():
    N, x = input().split()
    N, x = int(N), int(x)
    arr = [int(a) for a in input().split()]

    total = 0
    for i in range(1, N):
        a, b = arr[i-1], arr[i]
        extra = a + b - x
        if extra > 0:
            total += extra
            if b >= extra:
                arr[i] -= extra
            else:
                arr[i] = 0
    print(total)
boxes()

Measured memory_bytes: 20004
import sys
n=int(input())
l=n//100
d=n%100
for i in range(5, 0, -1):
  if d // i > 0:
    l = l - (d // i)
    d = d - i * (d // i)
  if d == 0 and l >= 0:
    print(1)
    sys.exit()
  if l < 0:
    break
print(0)

Measured memory_bytes: 3064
#include<cstdio>
#define reg register
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg bool f=false;
	reg char ch=getchar();
	reg int res=0;
	while(ch<'0'||'9'<ch)f|=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
	return f?-res:res;
}

int a,b;

int main(void){
	a=read(),b=read();
	if(1<=a&&a<=9&&1<=b&&b<=9)
		printf("%d\n",a*b);
	else
		puts("-1");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if(a > b)
	{
	    printf("a > b\n");
	}
	else if(a < b)
	{
		printf("a < b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
} 


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int MAX = 5e5 + 5;
vector<ii> ranges[MAX];
int dp[MAX];
char str[MAX];

int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", str);
	
	fori(i, 1, n - 1) {
		if(str[i] == '0' && str[i - 1] == '1' && str[i + 1] == '1') {
			int k = i - 1;
			int ones = 0;
			while(k >= 0 && str[k] == '1') {
				ones++;
				ranges[k].emplace_back(i + 1, ones);
				k--;
			}
			k = i + 1;
			ones = 0;
			while(k < n && str[k] == '1') {
				ones++;
				ranges[i - 1].emplace_back(k, ones);
				k++;
			}
		}
	}

	fori(i, 0, n) {
		if(i) {
			dp[i] = max(dp[i], dp[i - 1]);
		}
		for(auto &each : ranges[i]) {
			int right, value;
			tie(right, value) = each;
			dp[right] = max(dp[right], (i > 0 ? dp[i - 1] : 0) + value);
		}
	}

	printf("%d\n", dp[n - 1]);

	return 0;
}



Measured memory_bytes: 35328
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A, B;

int main() {
  INCANT;
  cin >> A >> B;
  int cnt=0;
  for (int j=A; j<=B; j++) {
    int i=j;
    int a1 = i/10000;
    i%=10000;
    int a2 = i/1000;
    i%=1000;
    int a3 = i/100;
    i%=100;
    int a4 = i/10;
    i%=10;
    if (a1==i && a2==a4)cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << fixed << setprecision(20);
    int a,b,t; cin >> a >> b >> t;
    cout << b* (t/a) << endl;
    return 0;
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

get_numbers_2(0, _, []).
get_numbers_2(N1, N2, [X|Xs]) :- 
    get_numbers(N2, X), 
    N12 is N1 - 1, 
    get_numbers_2(N12, N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

get_i_to_x_rbtree0(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 0, T2, T).

get_i_to_x_rbtree1(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 1, T2, T).

get_i_to_x_rbtree(0, _, T, T).
get_i_to_x_rbtree(N, I, T2, T) :-
    get_number(X),
    rb_insert(T2, I, X, T3),    
    N2 is N - 1,
    I2 is I + 1,
    get_i_to_x_rbtree(N2, I2, T3, T).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)

    include(f, Xs, Ys) : filter f

    findall(使う変数のタプル, (hoge), hogeが通るタプルのリスト)
*/
    
main :-
    get_number(N),
    X is (1000 - (N mod 1000)) mod 1000,
    writeln(X).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8276
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s = read::<String>().as_bytes().to_vec();
    let k: usize = read();
    let mut substrings = vec![];

    for i in 1..k + 1 {
        let mut s: Vec<_> = s.windows(i).collect();
        substrings.append(&mut s);
    }
    substrings.sort();
    substrings.dedup();
    println!("{}", String::from_utf8_lossy(&substrings[k - 1]));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
	int x,y;
	int max,min;
		while(scanf("%d %d",&x,&y)){
			if(x==0 && y==0){
				break;
			}
		if(x>y){
			max=x;
			min=y;
		}
		else if(x<y){
			max=y;
			min=x;
		}
		else{
			max=min=x;
		}
		printf("%d %d\n",min,max);
	}
	return 0;
}

Measured memory_bytes: 600
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	list := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}

	sort.Sort(sort.IntSlice(list))

	min := 1000000000
	for i := 0; i < n-k+1; i++ {
		now := list[i+k-1] - list[i]
		if min > now {
			min = now
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 5504
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
string lower(string s) {
  string t = "";
  for(int i = 0; i < s.length(); i++) {
    if('A' <= s[i] && s[i] <= 'Z')
      t += s[i] - ('A' - 'a');
    else
      t += s[i];
  }
  return t;
}

int main(void) {
  string s;
  cin >> s;
  s = lower(s);
  int ans = 0;
  while(1) {
    string t;
    cin >> t;
    if(t == "END_OF_TEXT")
      break;
    t = lower(t);
    if(t == s)
      ans++;
  }
  cout << ans << endl;

  return 0;
}



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

typedef long long ll;
typedef pair<int, int> P;

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int main(){
    int c[3][3];

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

    bool flag=true;
    for(int i=0; i<2; i++){
        if(!(c[i][0] - c[i+1][0] == c[i][1] - c[i+1][1])) flag=false;
        if(!(c[i][1] - c[i+1][1] == c[i][2] - c[i+1][2])) flag=false;
        if(!(c[i][0] - c[i+1][0] == c[i][2] - c[i+1][2])) flag=false;
    }

    for(int i=0; i<2; i++){
        if(!(c[0][i] - c[0][i+1] == c[1][i] - c[1][i+1])) flag=false;
        if(!(c[1][i] - c[1][i+1] == c[2][i] - c[2][i+1])) flag=false;
        if(!(c[0][i] - c[0][i+1] == c[2][i] - c[2][i+1])) flag=false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> Cards(N);
    for (int i = 0; i < N; i++){
      cin >> Cards.at(i);
    }
  
  sort(Cards.begin(), Cards.end());
  reverse(Cards.begin(), Cards.end());
  
  int Alice = 0;
  int Bob = 0;
  
  for (int i = 0; i < N; i++){
    int point = Cards.at(i);
    if (i % 2 == 0){
      Alice += point;
    } else {
      Bob += point;
    }
  }
  
  cout << Alice - Bob << endl;
  
}
    
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 10000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

map<ll,ll> prime_factor(ll n){
  map<ll,ll> res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n] = 1;
  return res;
}

ll n;

ll f(ll c){
  ll l =1,r=INF;
  while(r-l>1){
    ll m = (l+r)/2;
    if(c >= m*(m+1)/2)l=m;
    else r=m;
  }
  return l;
}

int main(){
  cin >> n;
  map<ll,ll> m = prime_factor(n);
  ll ans=0;
  for(auto p : m){
    ll c = p.second;
    ans += f(c);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

    vector<int> a(n,0);

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

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


Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require sqrt ceil floor
#include <climits>	// require INT_MAX etc
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <stdint.h>	// require uint64_t
#include <fstream>	// require freopen

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.riffle_shuffle", "r", stdin );
	int n, r;

	while (cin >> n >> r && n && r ){
		vector <int> c (r, 0 );

		for (int i = 0; i < r; ++i){
			cin >> c[i];
		} // end for

		deque<int> A, B, C;
		for (int i = 0; i < n; ++i ){
			C.push_back (i);
		} // end for
		int size = C.size();

		for (int i = 0; i < r; ++i ){
			for (int j = 0; j < size/2; ++j ){
				B.push_back (C.front() ); C.pop_front();
			} // end for
			while (!C.empty() ){
				A.push_back (C.front() ); C.pop_front();
			} // while
			while (!A.empty() || !B.empty() ){
				for (int j = 0; j < c[i] && !A.empty(); ++j ){
					C.push_back (A.front() ); A.pop_front();
				} // end for
				for (int j = 0; j < c[i] && !B.empty(); ++j ){
					C.push_back (B.front() ); B.pop_front();
				} // end for
			} // end while
		} // end for
		cout << C.back() << endl;	
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
sa, sb, sc = [input() for i in range(3)]
sa = [str(i) for i in sa]
sb = [str(i) for i in sb]
sc = [str(i) for i in sc]
play = len(sa+sb+sc)
    
next = eval("s" + sa.pop(0))

for i in range(1, play+1):
    if next == []:
        last = next
        break
    next = eval("s" + next.pop(0))

if last is sa:
    print("A")
elif last is sb:
    print("B")
else:
    print("C")


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	int n, m, t, p;
	while (cin >> n >> m >> t >> p, n) {
		int pepar[32][32],cop[32][32];
		rep(i, m) {
			rep(j, n) {
				pepar[i][j] = 1;
			}
		}
		rep(i, t) {
			rep(j, 32) {
				rep(k, 32) {
					cop[j][k] = 0;
				}
			}
			int d, c; cin >> d >> c;
			if (d == 1) {
				Rep(j, c, n) {
					rep(k, m) {
						cop[k][j - c] += pepar[k][j];
					}
				}
				per(j, c) {
					rep(k, m) {
						cop[k][c - j - 1] += pepar[k][j];
					}
				}
				n = max(n-c,c);
			}
			else {
				Rep(k, c, m) {
					rep(j, n) {
						cop[k - c][j] += pepar[k][j];
					}
				}
				per(k, c) {
					rep(j, n) {
						cop[c - k - 1][j] += pepar[k][j];
					}
				}
				m = max(m - c, c);
			}
			rep(j, m) {
				rep(k, n) {
					pepar[j][k] = cop[j][k];
				}
			}
		}
		rep(i, p) {
			int x, y; cin >> y >> x;
			cout << pepar[x][y] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3096
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    
    int cnt=0;
    int h_max=0;
    for(int i=0; i<N; ++i){
        int h; cin >> h;
        if(h >= h_max){ ++cnt; }
        h_max = max(h_max, h);
    }
    
    cout << cnt << endl;
    
    return 0;
}

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

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>=k){
        cout<<a-k<<" "<<b<<endl;
    }else if(a+b>=k){
        cout<<0<<" "<< a+b-k<<endl;
    }else{
        cout<<0<<" "<< 0<<endl;
    }
    return 0;
}



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

///2009~
llint s(llint B,llint C,llint D){return B-B/C-B/D+B/lcm(C,D);}
int main(void){
	llint A,B,C,D;cin>>A>>B>>C>>D;
	cout<<s(B,C,D)-s(A-1,C,D);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct edge{
    int y,c,w;
    edge(){y=c=w=0;}
    edge(int _y,int _c,int _w){y=_y;c=_c;w=_w;}
};
int n;
vector<edge> g[100005];
int dep[100005];
int fa[100005][17];
void dfs4lca(int x,int p,int cd){
    fa[x][0]=p;
    dep[x]=cd;
    for(edge &e:g[x])if(e.y!=p){
        dfs4lca(e.y,x,cd+1);
    }
}
void init4lca(){
    dfs4lca(1,-1,0);
    for(int j=0;j<16;j++){
        for(int i=1;i<=n;i++){
            if(fa[i][j]==-1)fa[i][j+1]=-1;
            else fa[i][j+1]=fa[fa[i][j]][j];
        }
    }
}
int lca(int x,int y){
    if(dep[x]<dep[y])swap(x,y);
    for(int i=16;i>=0;i--){
        if(fa[x][i]!=-1&&dep[fa[x][i]]>=dep[y])x=fa[x][i];
    }
    if(x==y)return x;
    for(int i=16;i>=0;i--){
        if(fa[x][i]!=fa[y][i]){
            x=fa[x][i];
            y=fa[y][i];
        }
    }
    return fa[x][0];
}
struct query{
    int id,x,y;
    query(int _id=-1,int _x=-1,int _y=-1){
        id=_id;x=_x;y=_y;
    }
};
vector<query> qs[100005];
int sum[100005],cnt[100005],ans[300005];
void dfs(int x,int p,int d){
    for(query q:qs[x]){
        ans[q.id]=d+cnt[q.x]*q.y-sum[q.x];
    }
    for(edge e:g[x])if(e.y!=p){
        sum[e.c]+=e.w;
        cnt[e.c]++;
        dfs(e.y,x,d+e.w);
        sum[e.c]-=e.w;
        cnt[e.c]--;
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int q;
    cin>>n>>q;
    for(int i=1;i<n;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        g[a].push_back(edge(b,c,d));
        g[b].push_back(edge(a,c,d));
    }
    init4lca();
    for(int i=1;i<=q;i++){
        int x,y,u,v,anc;
        cin>>x>>y>>u>>v;
        anc=lca(u,v);
        qs[anc].push_back(query(i,x,y));
        qs[u].push_back(query(i+q,x,y));
        qs[v].push_back(query(i+q+q,x,y));
    }
    dfs(1,-1,0);
    for(int i=1;i<=q;i++){
        cout<<-ans[i]-ans[i]+ans[i+q]+ans[i+q+q]<<endl;
    }
    return 0;
}


Measured memory_bytes: 28984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push back
int main()
{
    map<string,int>m;
    m["SUN"]=1;
    m["MON"]=2;
    m["TUE"]=3;
    m["WED"]=4;
    m["THU"]=5;
    m["FRI"]=6;
    m["SAT"]=7;
    string x;
    cin>>x;
    cout<<m["SUN"]-m[x]+7<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n,i,cnt=0;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=0;n>i;++i)
    scanf("%d",&a[i]);
    for(i=0;n>i;++i){
        if(a[i]%2==0)
        b[i]=a[i];
        else
        {
            b[i]=0;
        }
        
    }
    for(i=0;n>i;++i){
        if(b[i]%3==0||b[i]%5==0)
        ++cnt;
    }
    if(cnt==i)
    printf("APPROVED");
    else
    {
        printf("DENIED");
    }
    return 0;
}

Measured memory_bytes: 128
i=0
while True:
    n=int(input())
    list=[]
    for i in range(n):
        s=int(input())
        list.append((s))
        if i==n-1:
            list.sort()
            list.pop(n-1)
            list.pop(0)
            ave = sum(list)//len(list)
            print(ave)
    if n==0:
        break


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;
int calc(int num) {
    if(num >= 100) {
        num = num%100;
    }
    if (num >= 10) {
        num = num%10;
    }
    if (num == 0) {
        num = 10;
    }
    return num;
}

int main() {
    int A, B, C, D, E;
    int res;
    cin >> A >> B >> C >> D >> E;
    res = A + B + C + D + E + (10-calc(A)) + (10-calc(B)) + (10-calc(C)) + (10-calc(D)) + (10-calc(E));
	res = res - (10-min({calc(A), calc(B), calc(C), calc(D), calc(E)}));
	cout << res << endl;
	return 0;
}

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

/* 
 * g++ -std=c++17 A.cpp -o A
 */
int main() {
  ios_base::sync_with_stdio(false);
  int n, K;
  cin>>n>>K;
  vector<int> H(n+1);
  for (int i = 1; i<=n; i++) {
    int h;
    cin>>h;
    H[i]=h;
  }
  vector<int> dp(n+1);
  for(int i = 2; i <= n; ++i) {
    vector<int> hops;
    for (int k = 1; k <= K; ++k) {
      if (i>=k+1)
        hops.push_back(abs(H[i]-H[i-k])+dp[i-k]);
      else
        break;
    }
    dp[i] = *min_element(hops.begin(), hops.end());
  }
  cout<<dp[n];
  cout<<endl;
}

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

int main () {
	string s;
	cin >> s;
	
	int n = s.size();
	int n1 = (n-1) / 2;
	int n2 = (n+1) / 2;
	
	for (int i = 0; i < n1; ++i) {
		if (s[i] != s[n1-i-1]) {
			cout << "No\n";
			return 0;
		}
	}
	for (int i = n2; i < n; ++i) {
		if (s[i] != s[n-i-1]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 256
n=int(input())
if n<10:
  print(n)
if 9<n<100:
  print(9)
if 99<n<1000:
  print(n-90)
if 999<n<10000:
  print(909)
if 9999<n<100000:
  print(n-9090)
if n==100000:
  print(90909)

Measured memory_bytes: 3060
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 1000008
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;


void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}


int main() {
int n;
cin>>n;
int a[n];
FOR(i,n){cin>>a[i];}
int y;
int ans=INT_MAX;
for(int i=-100;i<=100;i++){
  int sum=0;
    FOR(j,n){
        y=abs(i-a[j]);
    sum+=y*y;
    }
    ans=min(ans,sum);
}
out(ans);
}





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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  int k;
  cin >> s >> k;

  vector<string> ans;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < s.size() - i; ++j) {
      ans.push_back(s.substr(j, i + 1));
    }
  }

  sort(ans.begin(), ans.end());
  unique(ans.begin(), ans.end());

  cout << ans[k - 1] << '\n';
  return 0;
}


Measured memory_bytes: 1660
package main

import "fmt"

type dice struct {
	top, bottom, right, left, up, down int
}

func move(d *dice, dir byte) {
	now := d.top
	switch dir {
	case 'N':
		d.top = d.down
		d.down = d.bottom
		d.bottom = d.up
		d.up = now
	case 'S':
		d.top = d.up
		d.up = d.bottom
		d.bottom = d.down
		d.down = now
	case 'W':
		d.top = d.right
		d.right = d.bottom
		d.bottom = d.left
		d.left = now
	case 'E':
		d.top = d.left
		d.left = d.bottom
		d.bottom = d.right
		d.right = now
	}
}

func main() {
	var d dice
	// fmt.Scan(&d.up, &d.top, &d.right, &d.left, &d.bottom, &d.down)
	fmt.Scan(&d.top, &d.down, &d.right, &d.left, &d.up, &d.bottom)
	var s string
	fmt.Scan(&s)
	for i := 0; i < len(s); i++ {
		// fmt.Printf("[BEFORE] move %d, op %s, top %d\n", i, string(s[i]), d.top)
		move(&d, s[i])
		// fmt.Printf("[AFTER ] move %d, op %s, top %d\n", i, string(s[i]), d.top)
	}
	fmt.Println(d.top)
}



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

int main(){
  int n;
  cin >> n;
  vector<long double> V(n);
  for (int i = 0; i < n; ++i){
  	cin >> V[i];
  }
  sort(V.begin(), V.end());
  long double factor = 2;
  long double max = V[n-1]/2;
  for (int i = n - 2; i >= 0; --i){
  	if (i != 0) factor *= 2;
    max += V[i]/factor;
  }
  cout << max;
}


Measured memory_bytes: 256
package main

import (
	"bytes"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	if false {
		test()
	} else {
		solve(os.Stdin, os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n int // number of participants
	var m int // number of languages
	fmt.Fscanln(r, &n, &m)
	// planet: paticipant -> lang -> bool
	planet := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		planet[i] = make(map[int]bool)
		var langs int
		fmt.Fscan(r, &langs)
		for j := 0; j < langs; j++ {
			var lang int
			fmt.Fscan(r, &lang)
			planet[i][lang-1] = true
		}
	}

	if communicatable(planet, n, m) {
		fmt.Fprintln(w, "YES")
	} else {
		fmt.Fprintln(w, "NO")
	}
}

func communicatable(planet map[int]map[int]bool, n, m int) bool {
	g := make(map[int][]int)
	for i := 0; i < n+m; i++ {
		g[i] = make([]int, 0)
	}

	for p, langs := range planet {
		g[p] = make([]int, len(langs))
		for l := range langs {
			// fmt.Println("p", p)
			// fmt.Println("n+l", n+l)
			langi := n + l
			g[p] = append(g[p], langi)
			g[langi] = append(g[langi], p)
		}
	}

	seen := make([]bool, n+m)
	traverse(g, 0, seen)
	for i := 0; i < n; i++ {
		if !seen[i] {
			return false
		}
	}
	return true
}

func traverse(g map[int][]int, i int, seen []bool) {
	seen[i] = true
	for _, v := range g[i] {
		if !seen[v] {
			traverse(g, v, seen)
		}
	}
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `4 6
3 1 2 3
2 4 2
2 4 6
1 6`,
			want: `YES
`,
		},
		{
			in: `4 4
2 1 2
2 1 2
1 3
2 4 3`,
			want: `NO
`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(tt.in), buf)
		if got := buf.String(); got != tt.want {
			fmt.Printf("%d: got %v, want %v\n", i, got, tt.want)
		}
	}
}


Measured memory_bytes: 50812
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<sstream>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;


int main()
{
	string s1,s2;
	int n;
	cin >> n >> s1 >> s2;
	for(int i = 0;i < n;i++){
		printf("%c%c",s1[i],s2[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
 
using namespace std;
const double PI=3.14159265358979323846;
 
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

	int n, m;
	cin >> n >> m;
	int values[n];

	int nVote = 0;
	rep(i, n) {
		cin >> values[i];
		nVote += values[i];
	}

	int count = 0;
	rep(i, n) {
		if ( (double)values[i] / (double)nVote >= (double)1 / ((double)4*(double)m))
			count++;
	}

	string ans = "No";
	if (m <= count) ans = "Yes";

	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int INF = 1e15;

signed main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i, N) cin >> a[i];

    vi sum(N+1, 0);

    FOR(i, 1, N+1) {
        sum[i] = sum[i-1]+a[i-1];
    }

    int res = INF;
    FOR(i, 1, N) {
        int su = sum[i];
        int ar = sum[N]-sum[i];
        //cout << su << " " << ar << endl;
        res = min(res, abs(su-ar));
        
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

LL n, m;
map<LL, LL> ma;
vector<pair<LL, LL>> v;

void solve() {
  cin >> n >> m;
  REP(_, n) {
    LL a;
    cin >> a;
    ma[a]++;
  }
  REP(_, m) {
    LL b, c;
    cin >> b >> c;
    ma[c] += b;
  }
  for(auto x : ma) {
    LL num = x.first;
    LL cnt = x.second;
    v.push_back({num, cnt});
  }
  sort(ALL(v));
  reverse(ALL(v));
  LL res = 0;
  for(auto x: v) {
    LL num = x.first;
    LL cnt = x.second;
    res += num * min(cnt, n);
    n -= cnt;
    chmax(n, 0LL);
  }
  cout << res << endl;
}

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


Measured memory_bytes: 17776
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=300005,mod=1e9+7;
int dp[maxn][3][3];//dp[i][j][k]有j个1，k个0
char s[maxn+10];
int n;

int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    dp[0][0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
            {
                if(s[i+1]!='0')
                {
                    if(k==0) (dp[i+1][j+(j!=2)][k]+=dp[i][j][k])%=mod;
                    else (dp[i+1][j][k-1]+=dp[i][j][k])%=mod;
                }
                if(s[i+1]!='1')
                {
                    if(k==2) (dp[i+1][j][k-1]+=dp[i][j][k])%=mod;
                    else (dp[i+1][j][k+1]+=dp[i][j][k])%=mod;
                }
            }
    }
    int ans=0;
    for(int i=0;i<3;i++)
        for(int j=0;j<=i;j++)
            ans=(ans+dp[n][i][j])%mod;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 11136
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<utility>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;
using ll = long long;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

const long long MOD = 1e9+7;
const long long MAX = 3e5+1;
const long double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    long double A, B, H, M;
    in(A); in(B); in(H); in(M);

    long double a1, a2, angle;
    a1 = (H + M/60.0L) / 12.0L;
    a2 = M/60.0L;
    angle = (long double) max(0.L, min(abs(a1-a2), 1.L - abs(a1 - a2)));
    angle *= 2L;
    angle *= PI;

    double ans = sqrt(A*A + B*B - 2*A*B*cos(angle));
    out(ans);


    return 0;
}


Measured memory_bytes: 4112
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 1e9+7;
const int nax = 1e5 + 5;
ll sil[nax];
int A[nax];

ll pot(ll a, int wyk) {
	ll res = 1;
	while (wyk) {
		if (wyk&1) {
			res = (res * a) % mod;
		}
		a = (a*a) % mod;
		wyk >>= 1;
	}
	return res;
}

ll odw(ll a) {
	return pot(a, mod -2);
}

ll choose(ll n, ll k) {
	ll pom = (sil[n] * odw(sil[k])) % mod;
	return (pom * odw(sil[n - k])) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	REP(i, n) {
		cin >> A[i];
	}
	sort(A, A + n);
	sil[0] = 1;
	FOR(i, 1, n-1) sil[i] = (sil[i-1]*i) % mod;
	ll gora = 0;
	FOR(i, k-1, n-1) {
		ll pom = (choose(i, k - 1) * A[i]) % mod;
		gora = (gora + pom) % mod;
	}
	debug() << imie(gora);
	REP(i, n - k + 1) {
		ll pom = (choose(n - i - 1, k-1) * A[i]) % mod;
		gora = (gora - pom + mod) % mod;
	}
	cout << gora << endl;
}

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

int main(){
  int N,M,K;
  cin>>N>>M>>K;

  bool flg=false;
  for(int i=0;!flg&&i<=N;i++){
    for(int j=0;!flg&&j<=M;j++){
      int sum = (N-i)*j + (M-j)*i;
      if(sum==K)
        flg=true;
    }
  }

  if(flg)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define IVSN(expr) ((expr) ? 1 : 0)
using namespace std;

const int WMAX = 1024, HMAX = 1024;
int w, h;
char flag[WMAX][HMAX];
char em[4];

bool is_emblem(int x, int y) {
  return (em[0] == flag[x][y] and em[1] == flag[x+1][y]
      and em[2] == flag[x][y+1] and em[3] == flag[x+1][y+1]);
}

int difference(char c, int x, int y) {
  char temp = flag[x][y];
  if (temp == c) return 0;
  flag[x][y] = c;

  int ans = IVSN(is_emblem(x,y)) +
    IVSN(is_emblem(x-1,y)) +
    IVSN(is_emblem(x,y-1)) +
    IVSN(is_emblem(x-1,y-1));
  flag[x][y] = temp;
  return ans;
}

int count_emblems() {
  int ans = 0;
  for (int y = 1; y < h; y++) {
    for (int x = 1; x < w; x++) {
      if (is_emblem(x, y))
        ans++;
    }
  }
  return ans;
}

int solve() {
  char joi[3] = {'J', 'O', 'I'};
  int ans = 0;

  REP(c, 3) {
    for (int y = 1; y <= h; y++) 
      for (int x = 1; x <= w; x++) {
      ans = max(ans, difference(joi[c], x, y));
    }
  }
  return ans;
}

int main() {
  cin >> h >> w;
  for (int y = 1; y <= h; y++) {
    string low;
    cin >> low;
    for (int x = 1; x <= w; x++) {
      flag[x][y] = low[x-1];
    }
  }
  for (int i = 0; i <= 2; i += 2) {
    string low;
    cin >> low;
    em[i] = low[0], em[i + 1] = low[1];
  }
  cout << count_emblems() + solve() << endl;
}

Measured memory_bytes: 2208
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		for j := i; j > 0 && aa[j] < aa[j-1]; j-- {
			aa[j], aa[j-1] = aa[j-1], aa[j]
		}
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Fprint(writer, " ")
			}
			fmt.Fprint(writer, aa[j])
		}
		fmt.Fprintln(writer, "")
	}
}



Measured memory_bytes: 1228