akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  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].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // ????????????????????¨??????????????????????????????????????????
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 4188
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull =  unsigned long long;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define pii pair<int,int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<"# "<<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))

int n,k;
int a[105];
int dp[100007];
int solve(int stone)
{
	if(stone<a[0])return 0;
	if(dp[stone]!=-1)return dp[stone];
	
	for(int i=0;i<n;i++){
		if(stone>=a[i]){
			int ret = solve(stone-a[i]);
			if(ret==0){
				return dp[stone]=1;

			}
		}
	}
	return dp[stone]=0;
}
int main()
{
	mem(dp,-1);
	fast_io
	cin >>n>>k;
	for(int i=0;i<n;i++)cin >>a[i];

	int ans=solve(k);
	
	if(ans)puts("First");
	else puts("Second");
	return 0;	
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <inttypes.h>

#define MOD_BY UINT32_C(1000000007)

uint32_t add(uint32_t a, uint32_t b) {
	return a + b - MOD_BY * (a + b >= MOD_BY);
}

uint32_t sub(uint32_t a, uint32_t b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

uint32_t mul(uint32_t a, uint32_t b) {
	uint32_t r = 0;
	while (b > 0) {
		if (b & 1) r = add(r, a);
		a = add(a, a);
		b >>= 1;
	}
	return r;
}

uint32_t N;
uint64_t A[333333];

uint32_t sum[333333];
uint32_t count[333333][64];

int main(void) {
	uint32_t i, j;
	uint32_t answer = 0;
	if (scanf("%" SCNu32, &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%" SCNu64, &A[i]) != 1) return 1;
	}
	for (i = 1; i <= N; i++) {
		sum[i] = add(sum[i - 1], (uint32_t)(A[i] % MOD_BY));
		for (j = 0; j < 64; j++) {
			count[i][j] = count[i - 1][j] + ((A[i] >> j) & 1);
		}
	}
	for (i = 1; i < N; i++) {
		uint32_t delta = 0;
		for (j = 0; j < 64; j++) {
			if ((A[i] >> j) & 1) {
				uint32_t one = count[N][j] - count[i][j];
				uint32_t zero = (N - i) - one;
				uint32_t thisDelta = (uint32_t)((UINT64_C(1) << j) % MOD_BY);
				delta = add(delta, mul(thisDelta, sub(zero, one)));
			}
		}
		answer = add(answer, add(sub(sum[N], sum[i]), delta));
	}
	printf("%" PRIu32 "\n", answer);
	return 0;
}


Measured memory_bytes: 81024
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int N = sc.nextInt();
			if (N == 0) {
				return;
			}
			int a[] = new int[N];
			int get[] = new int[N];
			for (int i = 0; i < N; i++) {
				a[i] = sc.nextInt();
			}
			int cnt = 0;
			boolean judge = false;
			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < N; j++) {
					if (a[j]-- > 0) {
						cnt++;
						get[j]++;
					}
					if (get[j] == 2) {
						judge = true;
						break;
					}
				}
			}
			System.out.println(judge ? cnt : "NA");
		}
	}
}

Measured memory_bytes: 159436
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int n , m;

int main(){
  cin >> n >> m;
  cout << ll(n >= 2 ? n - 2 : 1) * (m >= 2 ? m - 2 : 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string.h>
#include <string>

int main()
{
        std::string a, b;
        std::cin >> a >> b;

        size_t sz = a.size();
        for (int i = 0; i < sz; ++i) {
                if (strncmp(a.c_str(), b.c_str() + i, sz - i) == 0 && strncmp(a.c_str() + sz - i, b.c_str(), i) == 0) {
                        std::cout << "Yes\n";
                        return 0;
                }
        }
        std::cout << "No\n";
}

Measured memory_bytes: 256
def factorization(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            e[i] = max(e[i], cnt)

    if n != 1:
        e[n] = max(e[n], 1)


def mod_pow(a, n):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


n = int(input())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
e = [0] * 10 ** 6

for v in a:
    factorization(v)

lcm = 1
for i, c in enumerate(e):
    if c > 0:
        lcm = lcm * mod_pow(i, c) % mod

res = 0
for v in a:
    res = (res + lcm * mod_pow(v, mod - 2)) % mod

print(res)

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

int main(void)
{
  char cards[1024];
  while (fgets(cards, sizeof(cards), stdin), *cards != '0') {
    int ones = 0;
    int score = 0;
    char *card = strtok(cards, " ");
    for (; card != NULL; card = strtok(NULL, " ")) {
      int num = atoi(card);
      if (num == 1) {
        score += 10;
        ones++;
      }
      score += fmin(num, 10);
    }
    while (ones--) {
      if (score > 21) score -= 10;
    }
    if (score > 21) score = 0;
    printf("%d\n", score);
  } 
  return (0);
}

Measured memory_bytes: 532
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int ans=0;
  for(int i=0;i<N;i++){
    int h=0;
    cin>>h;
    if(K<=h){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3544
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	s = input()
	ret = 'Yes' if '7' in s else 'No'
	print(ret)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 61856
program main;
var a: array[1..100] of integer;
    m,n,i,v,total : integer;
    q: real;
begin
    v:=0;
    q:=0;
    total:=0;

    readln(m,n);
    
    for i := 1 to m do begin
        read(a[i]);
        total:= total + a[i];
    end;
    
    q:=(1/(4*n))*total;
    
    for i := 1 to m do
        if a[i] >= q
        then inc(v);

    if v >= n
    then writeln('Yes')
    else writeln('No');    
end.

Measured memory_bytes: 1320
#include<stdio.h>

int main(){
  int x, y;
  int tmp=0;

  scanf("%d%d", &x, &y);
  if(x < y){
    tmp = x;
    x = y;
    y = tmp;
  }

  while(y > 0){
    tmp = y;
    y = x%y;
    x = tmp;
  }

  printf("%d\n",tmp);
  return 0;
}



Measured memory_bytes: 2064
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int k, n;
    int maxdis = 0;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    for (int i = 0; i < n - 1; i++) {
        maxdis = max(maxdis, a.at(i + 1) - a.at(i));
    }
    maxdis = max(maxdis, a.at(0) + (k - a.at(n - 1)));
    cout << k - maxdis << endl;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(){
  int n, i, j, prime[10001] = {};
  prime[0] = prime[1] = 1;
  for(i = 2;i < 10001;i++)
    if(prime[i] != 1)
      for(j = i * 2;j < 10001;j += i) prime[j] = 1;

  while(scanf("%d", &n) && n){
    for(i = n;i >= 0;i--)
      if(prime[i] != 1 && prime[i - 2] != 1)
        break;

    printf("%d %d\n", i - 2, i);
  }
  return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> P;
ll N;
ll A[300005];
ll ans=-1e17;
ll nowredsum=0;
ll nowbluesum=0;
ll Redsumlist[100005];
ll Bluesumlist[100005];
priority_queue<ll,vector<ll> > Bluepq;
priority_queue<ll,vector<ll>,greater<ll> > Redpq;
int main(void)
{
  cin >> N;
  for (int i = 1; i <= 3*N; ++i)
    {
      cin >> A[i];
    }
  for (int i = 1; i <= N; ++i)
    {
      Redpq.push(A[i]);
      nowredsum+=A[i];
    }
  for (int i = 2*N+1; i <= 3*N; ++i)
    {
      Bluepq.push(A[i]);
      nowbluesum+=A[i];
    }
  Redsumlist[0]=nowredsum;
  Bluesumlist[N]=nowbluesum;
  for (int i = N+1; i <= 2*N; ++i)
    {
      ll Rfro=Redpq.top();
      if(Rfro<A[i])
	{
	  Redpq.pop();
	  nowredsum-=Rfro;
	  Redpq.push(A[i]);
	  nowredsum+=A[i];
	}
      Redsumlist[i-N]=nowredsum;
    }
  for (int i = 2*N; i >= N+1; --i)
    {
      ll Bfro=Bluepq.top();
      if(Bfro>A[i])
	{
	  Bluepq.pop();
	  nowbluesum-=Bfro;
	  Bluepq.push(A[i]);
	  nowbluesum+=A[i];
	}
      Bluesumlist[i-N-1]=nowbluesum;
    }
  for(int i=0;i<=N;i++)
    {
      ans=max(ans,Redsumlist[i]-Bluesumlist[i]);
    }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    string s_1, s_2;
    cin >> s_1 >> s_2;
    
    bool first = s_1.at(0) == s_2.at(2);
    bool second = s_1.at(1) == s_2.at(1);
    bool third = s_1.at(2) == s_2.at(0);
    
    if(first && second && third) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef long long ll;
typedef pair<ll,ll> ii;
ll n,mxr[55];
struct 
{
	ll value;
	ll biao;
}maxx,minn;
vector<ii>tt;
int main()
{
	int ans=0;
	scanf("%lld",&n);
	maxx.value=-inf;
	minn.value=inf;
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&mxr[i]);
		if(maxx.value<mxr[i])
		{
			maxx.value=mxr[i];
			maxx.biao=i;
		}
		if(minn.value>mxr[i])
		{
			minn.value=mxr[i];
			minn.biao=i;
		}
	}
	if(minn.value==maxx.value)
	{
		printf("0\n");
		return 0;
	}
	else if(minn.value>=0)
	{
		ex1:for(ll i=2;i<=n;i++)
		{
			while(mxr[i]<mxr[i-1])
			{
				ii dui(maxx.biao,i);
				tt.push_back(dui);
				mxr[i]+=maxx.value;
				if(mxr[i]>maxx.value)
				{
					maxx.value=mxr[i];
					maxx.biao=i;
				}
			}
		}
			
	}
	else if(maxx.value<=0){
		ex2:for(ll i=n-1;i>0;i--)
		{
			while(mxr[i]>mxr[i+1])
			{
				ii dui(minn.biao,i);
				tt.push_back(dui);
				mxr[i]+=minn.value;
				if(mxr[i]<minn.value)
				{
					minn.value=mxr[i];
					minn.biao=i;
				}
			}
		}
	}
	else{
		if(-minn.value<maxx.value)
		goto ex1;
		else
		goto ex2;
	}
	printf("%d\n",tt.size());
	for(ll i=0;i<tt.size();i++)
	{
		printf("%lld %lld\n",tt[i].first,tt[i].second);
	}
	return 0;
}

Measured memory_bytes: 384
card = []

for _ in range(3):
    card.append(list(map(int, input().split())))
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))

for i in range(3):
    if card[i][0] in b and card[i][1] in b and card[i][2] in b:
        print('Yes')
        exit()
for i in range(3):
    if card[0][i] in b and card[1][i] in b and card[2][i] in b:
        print('Yes')
        exit()
if card[0][0] in b and card[1][1] in b and card[2][2] in b:
    print('Yes')
    exit()
if card[0][2] in b and card[1][1] in b and card[2][0] in b:
    print('Yes')
    exit()


print('No')

Measured memory_bytes: 3064
from math import ceil, floor

def main():
    a, b = map(int, input().split())
    p8_l = ceil(a / 0.08)
    p8_h = int((a+1) // 0.08)
    p10_l = int(b / 0.10)
    p10_h = int((b+1) / 0.10) - 1
    if p8_h >= p10_h >= p8_l and p8_l >= p10_l:
        print(p8_l)
    elif p8_l <= p10_l <= p8_h and p8_l <= p10_l:
        print(p10_l)
    else:
        print(-1)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int ALP = 26;

const int N = 1010;
int dp[N][1<<12];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int hp_i, hp_m;
    while(cin >>hp_i >>hp_m, hp_i){
        int h,w;
        cin >>h >>w;
        vector<string> s(h);
        rep(i,h) cin >>s[i];

        int T;
        cin >>T;
        vector<int> trap(ALP,0);
        rep(i,T){
            char c;
            int d;
            cin >>c >>d;
            trap[c-'A'] = d;
        }

        int S;
        cin >>S;
        vector<int> damage;
        int px = 0, py = 0;
        rep(i,S){
            char c;
            int d;
            cin >>c >>d;
            while(d--){
                if(c=='U') --py;
                if(c=='D') ++py;
                if(c=='L') --px;
                if(c=='R') ++px;
                damage.pb(trap[s[py][px]-'A']);
            }
        }

        int P;
        cin >>P;
        vector<int> p(P);
        rep(i,P) cin >>p[i];

        int SZ = damage.size();
        memset(dp,0,sizeof(dp));
        dp[0][0] = hp_i;
        rep(i,SZ)rep(mask,1<<P)if(dp[i][mask]>0){
            // move
            dp[i+1][mask] = max(dp[i+1][mask], dp[i][mask]-damage[i]);

            // use potion
            rep(j,P)if(!(mask>>j&1)){
                int nmask = mask | (1<<j);
                dp[i][nmask] = max(dp[i][nmask], min(hp_m, dp[i][mask]+p[j]) );
            }
        }

        string ans = "NO";
        if(dp[SZ][(1<<P)-1]>0) ans = "YES";
        cout << ans << endl;
    }
    return 0;
}



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

#define REP(i, n) for(lint i = 0; i < n; ++i)
#define ln "\n"

using namespace std;
using lint = long long;

int main() {
    lint N, A, B;
    cin >> N >> A >> B;
    unordered_map<lint, lint> memo;

    if(A > B) {
        cout << 0 << ln;
        return 0;
    }
    if(N == 1) {
        if(A == B) {
            cout << 1 << ln;
            return 0;
        }
        else {
            cout << 0 << ln;
            return 0;
        }
    }
    cout << ((N - 2) * (B - A) + 1) << ln;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int d[] = {0, 0, 0};

    int N; cin >> N;
    ll ans = 1;
    F0R(i, N) {
        int X; cin >> X;
        int C = 0;
        F0R(i, 3) if (d[i] == X) C++;
        ans *= C; ans %= MOD;
        F0R(i, 3) {
            if (d[i] == X) {
                d[i]++; break;
            }
        }
    }

    cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using P = pair<int,int>;

// code starts
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  ll now = 1000;
  int lbuy = 0;
  ll stock = 0;
  int i;
  rep(i,n) cin >> a[i];
  for(i=0;i<n-1;i++)
  {
    if(a[i] <= a[i+1])
    {
      stock += now/a[i];
      now %= a[i];
      lbuy = a[i];
    }
    else
    {
      now += stock*a[i];
      stock = 0;
    }
  }
  if(lbuy > 0)
  {
    now += stock*max(a[n-1],lbuy);
  }
  cout << now << endl;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<vector<int>> jcat(k);
	rep(i, n) {
		int c, v;
		cin >> c >> v;
		jcat[c - 1].push_back(v);
	}
	for(auto& c: jcat) {
		if (c.size() <= 1) continue;
		sort(c.rbegin(), c.rend());
	}
	sort(jcat.begin(), jcat.end(), [](vector<int>& c1, vector<int>& c2) {
			return c1[0] + c1[1] > c2[0] + c2[1];
			});

	queue<ll> trimax;
	{
		vector<ll> tm(jcat.size());
		ll mx = -1;
		for(int i = jcat.size() - 1; i >= 0; i--) {
			auto& c = jcat[i];
			if (c.size() >= 3) chmax(mx, (ll)c[0] + c[1] + c[2]);
			tm[i] = mx;
		}
		for(ll val: tm) trimax.push(val);
	}
	multiset<int, greater<int>> singles;
	queue<vector<int>> unseen;
	for(auto& c: jcat) unseen.push(c);

	ll acc = 0, last_single = -1, last_double = -1;
	int flag = 0;
	rep(i, n) {
		if (flag) {
			flag = 0;
			vector<int>& c = unseen.front();
			auto it = c.begin();
			ll inc = *(it++) + *(it++);
			acc += inc;
			last_double = inc;
			singles.insert(it, c.end());
			unseen.pop();
			trimax.pop();
			cout << acc << endl;
		} else {
			auto take_single = [&](){
				auto it = singles.begin();
				acc += *it;
				last_single = *it;
				singles.erase(it);
				cout << acc << endl;
			};
			if (unseen.empty()) {
				if (singles.empty()) cout << -1 << endl;
				else take_single();
				continue;
			}
			vector<int>& c = unseen.front();
			ll m = trimax.front();
			auto nxt = singles.begin();
			if (!singles.empty() && *nxt * 2 >= c[0] + c[1]) {
				take_single();
				continue;
			}
			flag = 1;
			ll ans = -1;
			if (!singles.empty()) chmax(ans, acc + *nxt);
			if (last_single != -1) chmax(ans, acc - last_single + c[0] + c[1]);
			if (last_double != -1 && m != -1) chmax(ans, acc - last_double + m);
			cout << ans << endl;
		}
	}
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 2010000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

	COMinit();

	int R1, C1, R2, C2;
	cin >> R1 >> C1 >> R2 >> C2;

	int ans = 0;
	int cnt = 0;

	rep(i, 0, R2 - R1)
	{
		cnt += COM(C2 - C1 + i + 1, i + 1) - COM(C2 - C1 + i, i);
		cnt %= MOD;
		ans += COM(R2 - i + C1, C1)*(cnt+1);
		ans %= MOD;
	}

	cnt = 0;

	rep(i, 0, C2 - C1)
	{
		cnt += COM(R2 - R1 + i + 1, i + 1) - COM(R2 - R1 + i, i);
		cnt %= MOD;
		ans += COM(C2 - i + R1, R1)*(cnt+1);
		ans %= MOD;
	}

	ans += COM(C1 + R1, R1);
	ans %= MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 47360
#include <bits/stdc++.h>
#include <boost/foreach.hpp>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
#define _GLIBCXX_DEBUG
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
vector<long> Primelist;
//template functions
/////////////////////////
void Prinit(){
long PR=10000001;
vector<long> P(PR,0);
for(long i=2;i*i<PR;i++){
    if(P.at(i)==0){
        long j=i;
      j+=i;
        while(j<PR){
            P.at(j)=1;
             j+=i;         
        }
    }
}

for(long i=2;i*i<PR;i++){//Primelist.size()=446
    if(P.at(i)==0){
        Primelist.push_back(i);
    }
}
}

void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

long strtolong(string str){
istringstream ss;
ss=istringstream(str);
long num;
ss>>num;
return num;
}

long chartolong(char ch){
long num;
num=ch-'0';
return num;
}

string longtostr(long N){
    string str;
    str=to_string(N);
    return str;
}









/////////////////////////


//Answer


int main() {
long N,amax,bmax,cmax,dmax;
cin>>N;
typedef pair<long,long> P;
vector<P> p(N);
vector<P> px(N);
vector<P> py(N);
vector<long> x(N);
vector<long> y(N);
vector<long> a(N);
vector<long> b(N);
vector<long> c(N);
vector<long> d(N);
vector<long> max(4);
for(long i=0;i<N;i++){
cin>>x.at(i);
cin>>y.at(i);
a.at(i)=x.at(i)+y.at(i);
b.at(i)=x.at(i)-y.at(i);
c.at(i)=-x.at(i)+y.at(i);
d.at(i)=-x.at(i)-y.at(i);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
sort(c.begin(),c.end());
sort(d.begin(),d.end());
amax=a.at(N-1)-a.at(0);
bmax=b.at(N-1)-b.at(0);
cmax=c.at(N-1)-c.at(0);
dmax=d.at(N-1)-d.at(0);
max.at(0)=amax;
max.at(1)=bmax;
max.at(2)=cmax;
max.at(3)=dmax;
sort(max.begin(),max.end());
cout<<max.at(3)<<endl;


}







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

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

int N;
int D[100010];
int mod = 998244353;

signed main()
{
    cin >> N;
    rep(i, N)
    {
        int d;
        cin >> d;
        D[d]++;
        if(i == 0 && d != 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    int ans = 1;
    rep(i, N)
    {
        if(i == 0 && D[i] != 1)
        {
            cout << 0 << endl;
            return 0;
        }
        int tmp = 1;
        if(i != 0)
            rep(j, D[i])tmp = tmp * D[i - 1] % mod;
        ans = ans * tmp % mod;
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4252
#include <bits/stdc++.h>
#define ll long long int
#define N int(1e6+10)
using namespace std;
ll spf[N];
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		spf[i] = i;
	}
	for (int i = 2; i * i <= n; i++) {
		if (spf[i] == i) {
			for (int j = i * i; j <= n; j += i) {
				if (spf[j] == j)
					spf[j] = i;
			}
		}
	}
	ll ans = 1ll;
	for (int i = 2, x, y, a, z; i < n; i++) {
		x = i;
		z = 1;
		while (x > 1) {
			y = spf[x];
			a = 0;
			while (x % y == 0) {
				x /= y;
				a++;
			}
			z = z * (a + 1);
		}
		ans += 1ll * z;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    ll N,M;
    cin >> N >> M;
    vector<vector<char>> A(N,vector<char>(N,0)), B(M,vector<char>(M,0));
    rep(i,N){
        rep(j,N){
            cin >> A[i][j];
        }
    }
    rep(i,M){
        rep(j,M){
            cin >> B[i][j];
        }
    }
    bool flag = true;
    rep(i,N-M+1){
        rep(j,N-M+1){
            flag = true;
            rep(k,M){
                rep(l,M){
                    if(A[i+k][j+l] != B[k][l]){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag)break;
        }
        if(flag)break;
    }
    cout << (flag?("Yes"):("No")) << endl;
}


Measured memory_bytes: 256
#include <iostream>
//#include <vector>
//#include <string>
#include <numeric>
#include <algorithm>
using namespace std;
int main(void){
    int n,k;
    cin>>n>>k;
    int p[n];//n受ける前だと無理
    for (int i =0;i<n;i++){
        cin>>p[i];
    }
    sort(p,p+n);
    int ans =0;
    for (int i=0;i<k;i++){
        ans+=p[i];
    }
    cout <<ans<<endl;
    
}


Measured memory_bytes: 3640
use proconio::input;

fn main() {
  input! {
    n: i64,
  }
  let mut res: i64 = 0;

  for i in 1..n+1 {
    if i % 3 != 0 && i % 5 != 0 {
      res += i;
    }
  }
  println!("{}", res);
}

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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LINF = 4e18;
const ll delta = 96181;

const int N = 2e5 + 20;
ll n, a[N], ans;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (a[0] > 0)
		return cout << -1 << endl, 0;
	for (int i = 1; i < n; i++)
		if (a[i] - a[i - 1] > 1)
			return cout << -1 << endl, 0;
	ll prv = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (prv != a[i]) {
			ans += a[i];
			prv = a[i] - 1;
		}
		else
			prv = a[i] - 1;
	}
	cout << ans << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll n,ans=1;cin>>n;
  vector<ll> sum(n+1,0),v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(all(v));
  for(int i=1;i <= n;i++)
  {
    sum[i]=sum[i-1]+v[i-1];
  }

  for(int i=n-1;0<i;i--){
    if(v[i]<=2*sum[i])ans++;
    else break;
  }

  cout<<ans<<endl;


}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int n;
	int i,j;
	int a[10+1][10+1];
	
	scanf("%d",&n);
	
	while(n!=0){
		
		for (i=0; i<=n; i++) 
			for (j=0; j<=n; j++)
				a[i][j]=0;
		
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&a[i][j]);
			}
		}
		for (i=0; i<n; i++) 
			for (j=0; j<n; j++) 
				a[i][n]+=a[i][j];
		
		for (i=0; i<n; i++) 
			for (j=0; j<n; j++) 
				a[n][j]+=a[i][j];
		
		for (i=0; i<n; i++) 
			a[n][n]+=a[i][n];
		
		for (i=0; i<=n; i++) {
			for (j=0; j<=n; j++) 
				printf ("%5d",a[i][j]);
			printf ("\n");
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b;
    string s;
    bool flag=false;
    cin>>a>>s>>b;
    s=="+" ? cout<<a+b<<endl : cout<<a-b<<endl;

    return 0;
}

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

int digits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int d = N;
  
  for (int i = 1; i < N; i++) {
    int a = digits(i);
    int b = digits(N - i);
    d = min(d, a + b);
  }
  cout << d << endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n, dp[100100], x, y, M, N;
vector<ll>adj[100010];
bool vis[100010];
int bfs(int x)
{
    if(adj[x].size()==0)
        return 0;
    int ans = 0;
    if(vis[x])
        return dp[x];
    vis[x] = true;
    for(int i=0;i<adj[x].size();i++)
        ans = max(ans, bfs(adj[x][i])+1);
    return dp[x] = ans;
}
int main()
{
    //I am Monim, a tiny creature of Allah
    cin >> N >> M;
    int ans= 0;
    for(i=1;i<=M;i++)
    {
        cin >> x >> y;
        adj[x].push_back(y);
    }
    for(i=1;i<=N;i++)
        if(!vis[i])
            ans = max(ans,bfs(i));
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 11940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,st;
    int i,flag=0;
    cin>>s>>st;
    if (s.length()==st.length())
    {
        for (i=0;i<s.length();i++) cout<<s[i]<<st[i];
    }
    else 
    {
        for (i=0;i<st.length();i++)
        cout<<s[i]<<st[i];
        cout<<s[s.length()-1];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long double PI =(acos(-1));

int main(){
    int n;
    cin >> n;
    vector<int> S(14);
    vector<int> H(14);
    vector<int> C(14);
    vector<int> D(14);

    for(int i=0;i<n;++i){
        char c;
        int j=0;
        cin >> c >> j;
        if(c=='S'){
            S.at(j)++;
        }else if(c=='H'){
            H.at(j)++;
        }else if(c=='C'){
            C.at(j)++;
        }else if(c=='D'){
            D.at(j)++;
        }
    }
    for(int i=1;i<=13;++i){
        if(S.at(i)==0){
            cout << "S " << i << endl;;
        }
    }
    for(int i=1;i<=13;++i){
        if(H.at(i)==0){
            cout << "H " << i << endl;
        }
    }
    for(int i=1;i<=13;++i){
        if(C.at(i)==0){
            cout << "C " << i << endl;
        }
    }
    for(int i=1;i<=13;++i){
        if(D.at(i)==0){
            cout << "D " << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define maxn 200005
#define LL long long
#define lc u<<1
#define inf 0x3f3f3f3f3f3f3f3fll
#define rc lc|1
using namespace std;

int n,Q,A,B;
struct Seg{
	LL mn[maxn<<2],ad[maxn<<2];
	Seg(){ memset(mn,0x3f,sizeof mn),memset(ad,0,sizeof ad); }
	void dtp(int u,LL v){ ad[u] +=v , mn[u] += v; }
	void dt(int u){ if(ad[u]) dtp(lc,ad[u]),dtp(rc,ad[u]),ad[u]=0; }
	
	void ckm(int u,int l,int r,int p,LL v){
		if(l==r) return (void)(mn[u]=min(mn[u],v));
		int m=l+r>>1;dt(u);
		p<=m?ckm(lc,l,m,p,v):ckm(rc,m+1,r,p,v);
		mn[u]=min(mn[lc],mn[rc]);
	}
	LL qry(int u,int l,int r,int ql,int qr){
		if(l>qr||ql>r) return inf;
		if(ql<=l&&r<=qr) return mn[u];
		int m=l+r>>1;dt(u);
		return min(qry(lc,l,m,ql,qr),qry(rc,m+1,r,ql,qr));
	}
}T[2];
LL ans = inf;

void dfs(int u,int l,int r){
	if(l==r){//printf("@%lld %d\n",T[0].mn[u],l);
		ans = min(ans , T[0].mn[u] + l);
		return;
	}
	int m = l + r >> 1;T[0].dt(u);
	dfs(lc,l,m),dfs(rc,m+1,r);
}

int main(){
	scanf("%d%d%d%d",&n,&Q,&A,&B);
	int x,p;scanf("%d",&x);p=x;
	T[0].ckm(1,1,n,A,abs(x-B)-A),T[0].ckm(1,1,n,B,abs(x-A)-B);
	T[1].ckm(1,1,n,A,abs(x-B)+A),T[1].ckm(1,1,n,B,abs(x-A)+B);
	for(Q--;Q--;){
		scanf("%d",&x);
		LL t = min(x+T[0].qry(1,1,n,1,x),T[1].qry(1,1,n,x,n)-x);
		T[0].dtp(1,abs(x-p)),T[1].dtp(1,abs(x-p));
		T[0].ckm(1,1,n,p,t-p),T[1].ckm(1,1,n,p,p+t);
		p=x;
	}
	dfs(1,1,n);
	printf("%lld\n",ans);
}

Measured memory_bytes: 25216
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	h,w=MI()
	n=II()
	A=LI()

	G=[]

	for i,v in enumerate(A):
		G+=[i+1]*v

	GG=[]

	for i in range(h):
		if i%2==0:
			GG.append(G[i*w:i*w+w])
		else:
			GG.append(G[i*w:i*w+w][::-1])

	for a in GG:
		print(*a)














if __name__ == "__main__":
	main()


Measured memory_bytes: 9656
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 1e5+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int main()
{
    int i,j,k,l,p,q,x,y,n;
    cin >> n;
    vector<int> a,b;
    for(i=0;i<n;i++)
    {
        cin >> x >> y;
        a.pb(x);
        b.pb(y);
    }
    sort(all(a));sort(all(b));
    if(n%2==0)
    {
        x = (n/2)-1;y = n/2;
        p = a[x]+a[y];q = b[x]+b[y];
    }
    else
    {
        y = n/2;
        p = a[y];q = b[y];
    }
    cout << q-p+1;
}

Measured memory_bytes: 5104
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// constexpr std::int64_t INF = 1ull << 50;
constexpr int INF = 1 << 20;

static std::array<std::uint32_t, 100000> as{};
static std::array<std::uint32_t, 100000> bs{};

auto main() -> int {
  std::uint32_t n;
  std::cin >> n;

  for (auto i = 0ul; i < n; ++i) {
    std::uint32_t vi;
    std::cin >> vi;
    if (i & 1u)
      as[vi]++;
    else
      bs[vi]++;
  }

  using pt = std::pair<std::uint32_t, std::uint32_t>;
  std::vector<pt> ap{{0, INF}};
  std::vector<pt> bp{{0, INF}};
  for (auto i = 0ul; i < as.size(); ++i) {
    if (as[i] > 0) ap.emplace_back(as[i], i);
    if (bs[i] > 0) bp.emplace_back(bs[i], i);
  }
  std::sort(ap.begin(), ap.end(), std::greater<pt>{});
  std::sort(bp.begin(), bp.end(), std::greater<pt>{});

  if (ap[0].second != bp[0].second) {
    std::cout << (n - ap[0].first - bp[0].first) << std::endl;
  } else {
    std::cout << std::min(n - ap[1].first - bp[0].first, n - ap[0].first - bp[1].first)
              << std::endl;
  }
}


Measured memory_bytes: 2044
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main() {
   int N, A, B;
   cin >> N >> A >> B;
   int sum;
   int ans = 0;
   for (int i = 1; i <= N; i++) {
      string S = to_string(i);
      sum = 0;
      for (int j = 0; j < S.size(); j++) {
         sum += ctoi(S[j]);
      }
      if (A <= sum && sum <= B) ans += i;
   }
   cout << ans << endl;
   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++)
 
int main(){
  char x, y;
  cin >> x >> y;
  if(x<y){cout<< '<' <<endl;}
  else if(x==y){cout<< '=' <<endl;}
  else{cout << '>' << endl;}
 
  return 0;
}

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

def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"):
    import numpy as np
    from scipy.sparse.csgraph import floyd_warshall
    from itertools import chain
    mat = floyd_warshall(np.array(c, dtype=np.int64), directed=True)    
    return int(sum(mat[a][1] for a in filter(lambda x: x >= 0, chain.from_iterable(A))))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    c = [[int(next(tokens)) for _ in range(9 - 0 + 1)] for _ in range(9 - 0 + 1)]  # type: "List[List[int]]"
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    print(solve(H, W, c, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

int n,res;
map<int,int> ans;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int m;
		cin>>m;
		ans[m]++;
		if(m!=0) ans[m-1]++;
		ans[m+1]++;
	}
	
	for(map<int,int>::iterator i=ans.begin();i!=ans.end();i++) res=max(res,(*i).second);
	cout<<res;
	
	return 0;
}

Measured memory_bytes: 4736
K,N=map(int,input().split())
a=list(map(int,input().split()))

arukanaikyori=K-(a[N-1]-a[0])
for i in range(N-1):
    arukanaikyori=max(arukanaikyori,a[i+1]-a[i])
print(K-arukanaikyori)

Measured memory_bytes: 77260
h, w= map(int,input().split())

mass = [input() for i in range(h)]

ans = [[0] * w for i in range(h)]

bomb_pos = []


for i in range(h):
  if mass[i].find("#") == -1:
    continue
  index_num = [n for n, v in enumerate(mass[i]) if v == "#"]
  for index in index_num:
    bomb_pos.append([i,index])

for xy in bomb_pos:
  for i in range(max(0,xy[0]-1),min(xy[0]+2,h)):
      for j in range(max(0,xy[1]-1),min(xy[1]+2,w)):
        ans[i][j] += 1

for xy in bomb_pos:
  ans[xy[0]][xy[1]] = '#'
  
for arr in ans:
  print(''.join([str(n) for n in arr]))

Measured memory_bytes: 3188
from collections import deque
a = int(input())

res = deque()

for i in range(a):
    temp = list(map(int, input().split()))
    if temp[0] == 0:
        if temp[1] == 0:
            res.appendleft(temp[2])
        elif temp[1] == 1:
            res.append(temp[2])
    elif temp[0] == 1:
        print(res[temp[1]])
    else:
        if temp[1] == 0:
            res.popleft()
        elif temp[1] == 1:
            res.pop()


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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        while(a!=0)
        {
            cout<<b;
            a--;
        }
    }
    else
    {
        while(b!=0)
        {
            cout<<a;
            b--;
        }
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int t = N, c = 0;
  while (t > 0) {
    c += t % 10;
    t /= 10;
  }
  if (N % c == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
long long a[100];
int main() {
    int n, mi, ma;
    long long ans = 0, sum, change;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    if (sum <= 500000) {
        while (true) {
            ma = 0;
            for (int i = 1; i < n; i++) {
                if (a[ma] < a[i]) ma = i;
            }
            if (a[ma] < n) break;
            a[ma] -= n;
            for (int i = 0; i < n; i++) {
                if (i == ma) continue;
                a[i]++;
            }
            ans++;
        }
        printf("%lld\n", ans);
        return 0;
    }
    while (true) {
        mi = ma = 0;
        for (int i = 1; i < n; i++) {
            if (a[ma] < a[i]) ma = i;
            if (a[mi] > a[i]) mi = i;
        }
        if (a[ma] - a[mi] <= 1000) break;
        //printf("%lld %lld\n", a[ma], a[mi]);
        change = (a[ma] - a[mi]) / (n + 1);
        a[ma] -= change * n;
        for (int i = 0; i < n; i++) {
            if (i == ma) continue;
            a[i] += change;
        }
        ans += change;
        mi = 0;
        for (int i = 1; i < n; i++) {
            if (a[mi] > a[i]) mi = i;
        }
        change = (a[mi] - n);
        ans += change * n;
        for (int i = 0; i < n; i++) a[i] -= change;
    }
    while (true) {
        ma = 0;
        for (int i = 1; i < n; i++) {
            if (a[ma] < a[i]) ma = i;
        }
        if (a[ma] < n) break;
        a[ma] -= n;
        for (int i = 0; i < n; i++) {
            if (i == ma) continue;
            a[i]++;
        }
        ans++;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
	long long a,k,b;
	cin >> k >> a >> b;
	if(b - a <= 2){
		cout << k + 1 << endl;
	}else{
		k -= a - 1;
		if(k&1){
			cout << a + k/2*(b - a) + 1LL << endl;
		}else{
			cout << a + k/2*(b - a) << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct num{
	long long aaa,bbb,ccc;
};
vector<num> vec;
vector<long long> vec2;
long long check[10000005] = {0};
long long prime[10000005] = {0};
int main(){
    int pos=0;
    int flag;
    for (int i = 2 ; i < 10000002 ; i++)
    {
        if (!check[i])
            prime[pos++] = i;

        for (int j = 0 ; j < pos && i*prime[j] <10000002 ; j++)
        {
            check[i*prime[j]] =prime[j];
            if (i % prime[j] == 0)
                break;
        }
    }
    long long n;
    cin>>n;
	long long ss=0;
	for(long long i=1;i<=n;i++){
		if(i==1){
			ss+=1;
			continue;
		}
		int q=i;
		int p=1;
		if(check[i]==0){
			num h;
			h.aaa=1;
			h.bbb=i;
			h.ccc=1;
			vec.push_back(h);
		}else{
			if(vec[q/check[i]-2].bbb==check[i]){
				num h;
				h.aaa=vec[q/check[i]-2].aaa;
				h.bbb=vec[q/check[i]-2].bbb;
				h.ccc=vec[q/check[i]-2].ccc+1;
				vec.push_back(h);
			}else{
				num h;
				h.aaa=vec[q/check[i]-2].aaa*(vec[q/check[i]-2].ccc+1);
				h.bbb=check[i];
				h.ccc=1;
				vec.push_back(h);
			}
		}
		ss+=vec[i-2].aaa*i*(vec[i-2].ccc+1);
	}
	cout<<ss<<endl;
}


Measured memory_bytes: 480012
h,w = map(int,input().split())
a = []
for i in range(h):
    ai = input()
    if ai.count("#") >0:
        a.append(ai)

b = []
for i in range(w):
    b.append([])
    for j in range(len(a)):
            b[i].append(a[j][i])

c = []
for i in range(len(b)):
    if b[i].count("#")>0:
        c.append(b[i])

ans = []
for i in range(len(c[0])):
    ans.append([])
    for j in range(len(c)):
        ans[i].append(c[j][i])

for i in range(len(ans)):
    print("".join(ans[i]))

Measured memory_bytes: 39152
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

class BTwoAnagrams {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s,t;
        in>>s>>t;
        sort(all(s));
        sort(all(t));
        reverse(all(t));
        if(s<t) out<<"Yes";
        else out<<"No";

	}
};


int main() {
	BTwoAnagrams solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    L, R, d = NMI()
    print(R//d - (L-1)//d)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
double dp[305][305][305];
int N;
double dfs(int a, int b, int c)
{
  if (a == 0 && b == 0 && c == 0) return 0;
  if (dp[a][b][c]) return dp[a][b][c];
  double res = 1.0 * N / (a + b + c);
  if (a) res += 1.0 * a / (a + b + c) * dfs(a - 1, b, c);
  if (b) res += 1.0 * b / (a + b + c) * dfs(a + 1, b - 1, c);
  if (c) res += 1.0 * c / (a + b + c) * dfs(a, b + 1, c - 1);
  return dp[a][b][c] = res;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N;
  int a[4];
  memset(a, 0, sizeof(a));
  int in;
  for (int i = 0; i < N; ++i)
    {
      cin >> in;
      a[in]++;
    }
  memset(dp, 0, sizeof(dp));
  cout << setprecision(20) << dfs(a[1], a[2], a[3]) << endl;
  return 0;
}


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

using namespace std;

int main()
{
	int N, K;

	cin >> N >> K;

	double R = 0;
	for ( int d = 1; d <= N; d ++ ) {
		double ratio = 1.0 / N;
		int p = d;
		while ( p < K ) {
			p *= 2;
			ratio /= 2;
		}
		R += ratio;
	}

	cout.precision(12);
	cout << R << endl;


    return 0;
}




Measured memory_bytes: 256