akhauriyash/Code-Regression huggingface dataset:
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var A = myconv(input[1],4)[0];
  var B = myconv(input[1],4)[1];
  var list = myconv(input[2],4);
  var output = [0,0,0];
  for(var i = 0; i < N; i++){
    if(list[i] <= A){
       output[0]++;
    }else if(list[i] > A && list[i] <= B){
       output[1]++;      
	}else if(list[i] > B){
       output[2]++;      
	}
  }
  myout(Math.min.apply(null,output));
}
Main(myin());

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;
const int N = 1E6+7;

long long f[N];
long long a[N];
int n;

int main()
{
    fastIO
    cin>>n;
    
    for (int i = 1;i <= n;++i) cin>>a[i];

  	f[2] = abs(a[1]-a[2]);
    for (int i = 3;i <= n;++i)
        f[i] = min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));

    cout<<f[n];
}

Measured memory_bytes: 5180
import sys

input=sys.stdin.readline

N=int(input())
robot=[]
for i in range(N):
    x,d=map(int,input().split())
    robot.append((x,d))
mod=998244353

robot.sort()
move=[i for i in range(0,N)]
for i in range(0,N):
    x,d=robot[i]
    start=i
    end=N-1
    while end-start>1:
        test=(end+start)//2
        if x+d>robot[test][0]:
            start=test
        else:
            end=test

    if x+d>robot[end][0]:
        move[i]=end
    else:
        move[i]=start


n=N
#####segfunc######
def segfunc(x,y):
    return max(x,y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele =0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

chain=[i for i in range(N)]
for _ in range(0,N):
    i=N-1-_
    if move[i]==i:
        chain[i]=i
        update(i,chain[i])
    else:
        chain[i]=query(i+1,move[i]+1)
        update(i,chain[i])

dp=[0 for i in range(0,N+1)]
dp[N]=1
for j in range(0,N):
    i=N-1-j
    if chain[i]==i:
        dp[i]=(2*dp[i+1])%mod
    else:
        dp[i]=(dp[i+1]+dp[chain[i]+1])%mod

print(dp[0])

Measured memory_bytes: 104104
H, W = map(int, input().split())
a = [list(map(int, input().split()))for _ in range(H)]
ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] % 2 == 1:
            a[i][j] -= 1
            a[i][j+1] += 1
            ans.append([i, j, i, j+1])

w = W - 1
for i in range(H-1):
    if a[i][w] % 2 == 1:
        a[i][w] -= 1
        a[i+1][w] += 1
        ans.append([i, w, i+1, w])
print(len(ans))
aaaa = [list(map(lambda x: x+1, li)) for li in ans]
for x,y,z,a in aaaa:
    print(x, y, z, a)

Measured memory_bytes: 56868
#include <stdio.h>

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void pri(int n, int *a){
    int i;
    for(i = 0;i < n; i++) {
        if(i)printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
}

void bubbleSort(int n, int *a){
    int flg = 1;
    int cou = 0;
    int i;
    while (flg) {
        flg = 0;
        for(i = n-1; i > 0; i--) {
            if(a[i] < a[i-1]){
                swap(&a[i], &a[i-1]);
                cou++;
                flg = 1;
            }
        }
    }

    pri(n,a);
    printf("%d\n",cou);
}

int main() {
    int n;
    scanf("%d",&n);

    int a[100]={};
    int i;
    for(i = 0;i < n; i++){
        scanf("%d",&a[i]);
    }

    bubbleSort(n,a);
    return 0;
}



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

void solve() {
  int n;
  cin >> n;
  string s(n, ' ');
  rep(i, n) cin >> s[i];
  for (int i = 0;; i++) {
    if (s.find(to_string(i)) == string::npos) {
      cout << i << endl;
      return;
    }
  }
}

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


pair<int,int> e[100001];
vector<int> edge[100001];
map<int,int> ans[100001];
void dfs(int x,int p,int c){
	int nc=1;
	for(int it:edge[x])
		if(it!=p){
			if(nc==c)	nc++;
			ans[x][it]=ans[it][x]=nc;
			dfs(it,x,nc);
			nc++;
		}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>e[i].first>>e[i].second;
		edge[e[i].first].emplace_back(e[i].second);	
		edge[e[i].second].emplace_back(e[i].first);	
	}
	dfs(1,0,0);
	int out=0;
	for(int i=1;i<n;i++)
		out=max(ans[e[i].first][e[i].second],out);
	cout<<out<<'\n';
	for(int i=1;i<n;i++)
		cout<<ans[e[i].first][e[i].second]<<'\n';
}


Measured memory_bytes: 21504
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll a,b,c;
	cin >> a >> b >> c;
	if(c<a+b){
		cout << "No" << endl;
	}else{
		cout << ((a*b*4<(c-a-b)*(c-a-b))?"Yes":"No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N,0);
  for (int i = 0; i < N; i++){
    int A;
    cin >> A;
    vec.at(i) = A;
  }
  
  int M = 1000000000;
  for (int i = 0; i < N; i++){
    int t = 0;
    while (vec.at(i) % 2 == 0){
      vec.at(i) /= 2;
      t++;
    }
    M = min (M, t);
  }
  cout << M << endl;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
num = A[0]
for a in A[1:]:
    num ^= a

answer = [None] * N
for i, a in enumerate(A):
    answer[i] = num^a

print(*answer)

Measured memory_bytes: 31692
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
    int n; cin>>n;
    VI a(n); rep(i,n) cin>>a[i];
    VI b(n); rep(i,n) cin>>b[i];
    VI c(n-1); rep(i,n-1) cin>>c[i];
    int sum=0,mem=-5;
    for(int i=0;i<n;i++){
        sum+=b[a[i]-1];
        //cout<<mem<<" "<<a[i]<<endl;
        if(mem==a[i]-1){
            sum+=c[mem-1];
        }
        mem=a[i];
    }
    cout<<sum<<endl;

 }



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <stack>

using namespace std;

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

const ll mod = 1e9 + 7;
const ll mmod = 998244353;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<vector<ll>> g;
vector<vector<ll>> par;
vector<vector<ll>> dp;
vector<ll> d;


int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    vector<ll> c(1e6 + 1);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        c[a[i]]++;
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i)
    {
        bool f = 1;
        if (c[a[i]] > 1)
        {
            continue;
        }
        for (int j = 1; j <= sqrt(a[i]); ++j)
        {
            if (a[i] % j == 0)
            {
                if (j != a[i])
                {
                    if (c[j] > 0)
                    {
                        f = 0;
                        break;
                    }
                }
                if (a[i] / j != a[i])
                {
                    if (c[a[i] / j] > 0)
                    {
                        f = 0;
                        break;
                    }
                }
            }
        }
        if (f)
        {
            ret++;
        }
    }
    
    cout << ret << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 12660
package main

import (
  "fmt"
)

func main() {
  var a, b, c int
  fmt.Scanf("%d %d %d", &a, &b, &c)
  
  ans := "No"
  if a < c && c < b {
    ans = "Yes"
  }
  if b < c && c < a {
    ans = "Yes"
  }
  
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1832
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
   uniform_int_distribution<int> uid(l, r);
   return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
const int mex = 2e6 + 0;
int fact[mex+5], inv[mex+5];

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

int Inv(int x){  return toPower(x, mod - 2); }
int add(int a, int b) { a %= mod; b %= mod; return ((a + b) % mod); }
int sub(int a, int b) { a %= mod; b %= mod; return  ((a - b + mod) % mod);}
int mul(int a, int b) { a %= mod; b %= mod; return ((a * b) % mod); }

void initialize(){
    inv[0] = Inv(fact[0]);fact[0] = inv[0] = 1;
    
    for(int i = 1; i <= mex; i++){
        fact[i] = (ll(i) * fact[i - 1]) % mod;
        inv[i] = Inv(fact[i]);
    }
}

int C(int n, int k){
    if (n < 0 || k < 0 || k > n) return 0;
    return ll(fact[n]) * inv[k] % mod * inv[n - k] % mod;                 
}

void solve() {
   int n, k; 
   cin >> k;
   int ans = 0;
   string s; cin >> s;
   n = k + sz(s); 
   int t = sz(s);
   for(int i = t; i <= n; i++) {
      int cur = toPower(26, n-i);
      cur = mul(cur, toPower(25, i-t));
      cur = mul(cur, C(i-1, t-1));
      ans = add(ans, cur);
   }
   cout << ans << '\n';
}

signed main() {   
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
   initialize();
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
      solve();
  }
}    


Measured memory_bytes: 35512
def main():
    #import sys
    #input=sys.stdin.readline
    n=int(input())
    m=int(input())
    ab=[list(map(int,input().split())) for _ in [0]*m]
    g=[[] for _ in [0]*n]
    dp=[0]*n
    [g[a-1].append(b-1) for a,b in ab]
    for i,l in enumerate(g):
        for j in l:
            dp[j]+=1
    l=[i for i,j in enumerate(dp) if j==0]
    ans=[i for i,j in enumerate(dp) if j==0]
    while l:
        i=l.pop()
        for j in g[i]:
            dp[j]-=1
            if dp[j]==0:
                l.append(j)
                ans.append(j)
    for i in ans:
        print(i+1)
    for i in range(n-1):
        if ans[i+1] not in g[ans[i]]:
            print(1)
            break
    else:
        print(0)
    
if __name__=='__main__':
    main()


Measured memory_bytes: 27720
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College
    Date:12/06/2020
*/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
ll mod=1000000007;
int dx[]={1,0};
int dy[]={0,1};

const int N=1e3+5;
int cache[N][N];
char a[N][N];
int h,w;
void bfs()
{
    int x,y;
    queue<pair<int,int>>q;
    q.push(mp(0,0));
    cache[0][0]=1;
    while(!q.empty())
    {
        x=q.front().ff;
        y=q.front().se;
        q.pop();
        for(int i=0;i<2;i++)
        {
            int x1=x+dx[i];
            int y1=y+dy[i];
            if(x1<0 or y1<0 or x1>=h or y1>=w or a[x1][y1]=='#')
            continue;
            if(cache[x1][y1]==-1)
            {
                cache[x1][y1]=cache[x][y];
                q.push(mp(x1,y1));
            }
            else
            cache[x1][y1]+=cache[x][y];
            cache[x1][y1]%=mod;
        }
    }
    
}

bool test=0;
void solve()
{
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
            cin>>a[i][j];
    }
    memset(cache,-1,sizeof(cache));
    bfs();
    if(cache[h-1][w-1]==-1)
    cache[h-1][w-1]=0;
    cout<<cache[h-1][w-1];
}







signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin.exceptions(cin.failbit);
//     #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// 	#endif
    int t=1;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

int main(void) {
  int n,d,x;
  cin >> n >> d >> x;
  int a[n];
  int cnt=0;
  for (int i=0;i<n;i++) {
    cin >> a[i];
    for (int k=0;(k*a[i]+1)<=d;k++) {
      cnt++;
    }
  }
  cout << cnt + x << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,v,o[100005],e[100005],m=0,om,em,ans;
int o1=0,o2=0,e1=0,e2=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>v;
	    if(i%2==0) e[v]++;
	    else o[v]++;
	    if(m<v) m=v;//最 大 
	}
	for(int i=1;i<=m;i++){
    	if(o[i]>o1) o1=o[i],om=i; 
    	if(e[i]>e1) e1=e[i],em=i;
  	}	
	for(int i=1;i<=m;i++){
	    if(i!=om){
	      	if(o[i]>o2) o2=o[i];
	    }
	    if(i!=em){
	      	if(e[i]>e2) e2=e[i];
	    }
	}
	if(om==em)	ans=min(n-o1-e2,n-o2-e1);
	else  ans=n-o1-e1;
	
	cout<<ans<<endl;
  	return 0;
}

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

int main(){
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);

  if(C - (A - B) < 0)
    cout << 0 << endl;
  else
    cout << C - (A - B) << endl;
  return 0;
}

Measured memory_bytes: 256
//
// Created by admin on 2020/7/11.
//
#include <bits/stdc++.h>
using namespace std;
int n,a[150],ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i+=2)
        if(a[i]%2==1)
            ans++;
    cout<<ans<<endl;
}


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

int main(){
    int h,w;cin>>h>>w;
    vector<string> s(h);
    for(int i=0;i<h;i++) cin>>s[i];
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)if(s[i][j]=='#'){
            bool flag=false;
            if(i>=1&&s[i-1][j]=='#') flag=true;
            if(j>=1&&s[i][j-1]=='#') flag=true;
            if(i<=h-2&&s[i+1][j]=='#') flag=true;
            if(j<=w-2&&s[i][j+1]=='#') flag=true;

            if(flag) continue;
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }

    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
<?php
$W=trim(fgets(STDIN));
$Wl=strlen($W);
for($k=0;$k<$Wl;$k++){
  $n=ord($W[$k]);
  if($n<65) continue;
  if($n<91) $W[$k]=chr($n+32);
}
$C=0;
while(1){
  $T=trim(fgets(STDIN));
  if($T=='END_OF_TEXT') break;
  $Tl=strlen($T);
  for($k=0;$k<$Tl;$k++){
    $n=ord($T[$k]);
    if($n<65) continue;
    if($n<91) $T[$k]=chr($n+32);
  }
  $tl=$Tl-$Wl;
  for($i=0;$i<=$tl;$i++){
    if($T[$i]!=$W[0]) continue;
    $f=1;
    for($j=1;$j<$Wl;$j++){
      if($T[$i+$j]!=$W[$j]){$f=0;break;}
      ++$f;
    }
    if($i==0){
      if($i==$tl) ++$C;
      else if($T[$i+$f]==' ') ++$C;
    }
    else{
      if($T[$i-1]==' '){
        if($i==$tl) ++$C;
        else if($T[$i+$f]==' ') ++$C;
      }
    }
  }
}
echo $C;
?>

Measured memory_bytes: 15464
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const int N=200050;
int a[N],b[N];
int main()
{
	int n;
	scanf("%i",&n);
	vector<int> id;
	for(int i=1;i<=n;i++) scanf("%i",&a[i]);
	for(int i=1;i<=n;i++) scanf("%i",&b[i]),id.pb(i);

	ll ans=0;
	set<pair<int,int>> work;
	for(int i=1;i<=n;i++) work.insert({b[i],i});
	while(work.size())
	{
		int i=work.rbegin()->second;
		work.erase(--work.end());
		int z=b[i-1]+b[i+1],mx=max(b[i-1],b[i+1]);
		if(i==1) z=b[n]+b[i+1],mx=max(b[n],b[i+1]);
		if(i==n) z=b[1]+b[i-1],mx=max(b[1],b[i-1]);
		if(b[i]==a[i]) continue;
		if(b[i]-z<a[i]) return 0*printf("-1\n");
		int top=b[i]/z,bot=1,mid,t=0;
		while(top>=bot)
		{
			mid=top+bot>>1;
			if(b[i]-(ll)z*mid>mx && b[i]-(ll)z*(mid+1)>=a[i]) t=mid,bot=mid+1;
			else top=mid-1;
		}
		t++;
		b[i]-=(ll)z*t;
		ans+=t;
		if(b[i]!=a[i]) work.insert({b[i],i});
	}
	/*sort(id.begin(),id.end(),[&](int i, int j){ return b[i]<b[j];});
	ll ans=0;
	for(int i:id)
	{
		int z=a[i-1]+a[i+1];
		if(i==1) z=a[n]+a[i+1];
		if(i==n) z=a[1]+a[i-1];
		printf("%i z:%i a:%i b:%i\n",i,z,a[i],b[i]);
		if(a[i]>b[i] || ((b[i]-a[i])%z!=0)) return 0*printf("-1\n");
		ans+=(b[i]-a[i])/z;
		a[i]=b[i];
	}*/
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 12020
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int count = 0;
  for (int i = 1; i < 10; i++)
  {
    for (int j = 1; j < 10; j++)
    {
      if (n == i * j)
      {
        count += 1;
      }
    }
  }
  if (count != 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 110000
#define L 100000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline int read()
{
	char ch=0;
	int x=0,flag=1;
	while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*flag;
}
int main()
{
	ll n=read(),a=read(),b=read(),ans=n+1;
	if(n<=a-1||a>=b){printf("%lld",ans);return 0;}
	n-=(a-1);printf("%lld",max(ans,a+(b-a)*(n/2)+(n&1?1:0)));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool prime[1000000];
int main(){
	for(int i = 2; i * i <= 1000000; i++){
		if(prime[i] == 0){
			for(int j = i; j <= 1000000; j+=i){
				prime[j] = 1;
			}
			prime[i] = 0;
		}
	}
	int n;
	while(cin >> n,n){
		int cnt = 0;
		for(int i = 2; i <= n/2; i++){
			if(prime[i])continue;
			else {
				if(!prime[n-i])cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){
    string s,t;
    cin >> s>> t;
    string ans{};
    rep(i, t.size()){
        ans.push_back(t[i]);
    }
    rep(i, s.size()){
        ans.push_back(s[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
n=int(input())

a=sorted(list(map(int,input().split())),reverse=True)

stack=-1
t=[]
for i in a:
    if stack==i:
        t.append(i)
        stack=-1
    else:
        stack=i
    
    if len(t)>=2:
        break
try:
    print(t[0]*t[1])
except:
    print(0)

Measured memory_bytes: 14252
#include<iostream>
using namespace std;
int main(){
    int h,w;
    bool judge;
    while(true){
        cin >> h >> w;
        if(h != 0 or w != 0){
            for(int i = 1; i <= h; i++){
                if(i % 2 == 1){
                    judge = true;
                } else {
                    judge = false;
                }
                for(int j = 1; j <= w; j++){
                    if(judge){
                        cout << "#";
                        judge = false;
                    } else {
                        cout << ".";
                        judge = true;
                    }
                }
                cout << endl;
            }
            cout << endl;
        } else {
            break;
        }
    }
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;
    
    vector<vector<bool>> x(n, vector<bool>(n, false));
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int j = 0; j < m; j++) {
        int p;
        cin >> p;
        p--;
        x.at(i).at(p) = true;
      }
    }
    
    int k;
    cin >> k;
    vector<int> y(k);
    for (int i = 0; i < k; i++) {
      cin >> y.at(i);
      y.at(i)--;
    }
    
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      bool flag = true;
      for (int j = 0; j < k; j++) {
        if (x.at(i).at(y.at(j)) == false) flag = false;
      }
      if (flag) ans.emplace_back(i + 1);
    }
    
    if (ans.size() != 1) cout << "-1\n";
    else cout << ans.at(0) << '\n';
  }
}


Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,a[100001]={},sa[100001]={};
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sa[i]=abs(a[i-1]-a[i]);
    }
    sa[0]=abs(a[n]);
    
    for(int i=2;i<=n;i++){
        sa[i]+=sa[i-1];
    }
    
    for(int i=1;i<=n;i++){
        if(i==n)cout<<sa[n-1]+abs(a[n-1])<<endl;
        else if(i==1) cout<<sa[n]-sa[i+1]+sa[i-1]+abs(a[i+1]-a[i-1])<<endl;
        else if(i==n-1)cout<<sa[0]+sa[n-2]+abs(a[n]-a[n-2])<<endl;
        else cout<<sa[n]-sa[i+1]+sa[i-1]+abs(a[i+1]-a[i-1])+sa[0]<<endl;
    }
    
    
}


Measured memory_bytes: 2048
#include<stdio.h>

int main(void){
  int N;
  char S[51];
  scanf("%d\n%s",&N,S);
  
  int i,a;
  a=0;
  for(i=0;i<=N-3;i++){
    if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
      a++;
    }
  }
  
  printf("%d",a);
  
  return 0;
}

Measured memory_bytes: 128
#Kに対して何回コインを投げればよいのか
N, K = map(int, input().split())
each_slow = []
for i in range(1, N+1): #diceの目が1～3の目の間
    d = i
    cnt = 0
    while (d<K):
        cnt += 1
        d *= 2
    each_slow.append(cnt)

#各サイコロの目に対する勝率の算出
dice = 1/N #サイコロの目が出る確率
coin = 1/2 #コインの表が出る確率

win = [] #各勝率を格納するリスト
for i in range(1, N+1):
    #確率算出
    rate = dice * coin ** each_slow[i-1]
    win.append(rate)
    
print(sum(win))

Measured memory_bytes: 7064
#include<stdio.h>

int n,A[50];

int me(int i, int m){
	if(m == 0)
	return 1;
	if(i >= n)
	return 0;
	int res = me(i + 1,m) || me(i + 1,m - A[i]);
	return res;
}
int main(void){
	int q,M,i;
	
	scanf("%d",&n);
	for(i = 0;i < n;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
		for(i = 0;i < q;i++){
			scanf("%d",&M);
			if(me(0,M))
			printf("yes\n");
			else 
			printf("no\n");
		}
	return 0;
}


Measured memory_bytes: 2140
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	vector<ll> powers;
	for(int i = 0;i<=119;i++)
	{
		ll val = pow(i*1ll , 5ll);	
		powers.push_back(val);
	}
	
	ll x;cin>>x;
	//first check for the sum
	for(int i = 0;i<=119;i++)
	{
		for(int j = i;j>=0;j--)
		{
			if(powers[i] + powers[j] == x)
			{
				cout<<i<<" "<<-1*j<<endl;return 0;
			}
			
			if(powers[i] - powers[j] == x)
			{
				cout<<i<<" "<<j<<endl;return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 4060
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int K = sc.nextInt();

   if(K%2 ==1) System.out.println((K/2)*((K/2)+1));
   else System.out.println((K/2)*(K/2));
 }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<n+1;i++)

using namespace std;
using std::swap;

vector<long long int> p;
vector<long long int> q;

int main() {
	int a, b;
	cin >> a >> b;
	if (b * 2 >= a)cout << 0 << "\n";
	else cout << a - b * 2 << "\n";
	return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

// Binary Indexed Tree // {{{
struct BIT {
    vector<int> bit;
    int n;
    BIT(int n) {
        bit.resize(n+1, 0);
        this->n = n;
    }
    int sum(int i) {
        int s = 0;
        while(i > 0){
            s += bit[i];
            // i & -i はiの最後の1のビット
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x) {
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
};

// 順列の転倒数 (1-indexed)
LL inv(vector<int> a) {
    int n = a.size();
    BIT bit(n);
    LL ans = 0;
    for(int j=0;j<n;j++){
        ans += j - bit.sum(a[j]);
        bit.add(a[j], 1);
    }
    return ans;
}
// }}}

// 文字列sは並び替えて回文にできるか
bool palindromable(string s) {
    map<char, int> m;
    for(auto c : s){
        m[c]++;
    }
    int ocnt = 0;
    for(auto kv : m){
        if(kv.second%2 == 1) ocnt++;
    }
    return ocnt < 2;
}

int main() {
    std::ios::sync_with_stdio(false);
    string s;cin >> s;
    int n = s.size();

    // そもそも回文にできない
    if(!palindromable(s)){
        cout << -1 << endl;
        return 0;
    }

    // 左右に分ける
    map<char, int> sum, cnt;
    for(auto c : s) sum[c]++;
    vector<int> p(n);
    int l = 0;
    int r = (n+1)/2;
    string sl = "";
    string sr = "";
    for(int i=0;i<n;i++){
        char c = s[i];
        cnt[c]++;
        if(cnt[c] <= sum[c]/2){
            sl += c;
            p[l] = i+1;
            l++;
        }else if(cnt[c] > (sum[c]+1)/2){
            sr += c;
            p[r] = i+1;
            r++;
        }else{
            p[n/2] = i+1;
        }
    }
    LL ans = 0;
    ans += inv(p);

    // 右を左の逆と同じにする
    reverse(sr.begin(), sr.end());
    map<char, vector<int>> pos;
    cnt.clear();
    p.clear();
    for(int i=0;i<n/2;i++){
        pos[sl[i]].push_back(i+1);
    }
    for(int i=0;i<n/2;i++){
        p.push_back(pos[sr[i]][cnt[sr[i]]++]);
    }
    ans += inv(p);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3280
#include <iostream>

int main(void)
{
    int a,b,c;
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;
    if (a<b && b<c) {
        std::cout<<"Yes\n";
    }else{
        std::cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
string s,t;
int main()
{
	int cnt=0;
	cin>>s>>t;
	for (int i=0;i<s.length();i++)
		if(s[i]!=t[i])
			cnt++;
	cout<<cnt<<endl;
}



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

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll solve(int N, ll M,vector<ll> a){
    while(a[0] % 2 == 0){
        rep(i,N){
            if(a[i] % 2 != 0) return 0;
            a[i] /= 2;
        }
        M /= 2;
    }
    rep(i,N) if(a[i] % 2 == 0) return 0;

    ll lcm = 1;
    rep(i,N){
        ll g = GCD(lcm,a[i]);
        lcm = lcm/g*a[i];
        if(lcm > M) return 0;
    }
    return (M/lcm+1)/2;
}

int main(){
    int N; ll M; cin >> N >> M;
    vector<ll> a(N);
    rep(i,N) cin >> a[i], a[i] /= 2;
    cout << solve(N,M,a) << endl;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  ll ans = INF;
  for (int i = 0; i < n-k+1; i++){
    int l = x[i];
    int r = x[i + k - 1];
    ll tmp = r - l;
    if (r < 0) tmp += abs(r);
    else if (l > 0) tmp += (l);
    else if (l < 0 && 0 < r) tmp += min(abs(l), r);
    ans = min(ans, tmp);
  }
  if (ans == INF) ans = abs(x[0]);
  cout << (ll)ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
	int l,m,n,i,j;
	while(0<=scanf("%d",&l)){
		if(l==0) break;
		j=-1;
		for(i=0;i<12;i++){
			scanf("%d%d",&m,&n);
			l-=(m-n);
			if(j==-1 && l<=0) j=i;
		}
		
		if(j!=-1){
			printf("%d\n",j+1);
			continue;
		}
		
		printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define mp make_pair
typedef long long int ll;

void fun(bool flag){
    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}
 
int main()
{
    fast;
    ll n;
    cin >> n;
    cout << 3.14 * n * 2 << endl;

    return 0;
}

Measured memory_bytes: 3804
#include <stdio.h>

#define N 100     
#define SUCCESS 1 // 成功
#define FAILURE 0 // 失敗
#define INFTY 1 << 21 // 到達不可能を表す大きな値

int queue[N]; // キューの本体
int queue_head = 0; // データ先頭
int queue_num; // データ個数

int node_num, M[N + 1][N + 1];
int d[N]; // 距離で訪問状態(color)を管理する

int enqueue(int enq_data) // キューにデータを追加する
{
  if (queue_head + queue_num < N) {
    queue[queue_head + queue_num] = enq_data;
    queue_num++;
    return SUCCESS;
  } else {
    return FAILURE;
  }
}

int dequeue(int *deq_data) // キューからデータを取り出す
{
  if (queue_num > 0) {
    *deq_data = queue[queue_head];
    queue_num--;
    queue_head++;
    return SUCCESS;
  } else {
    return FAILURE;
  }
}

void bfs(int s) {
  enqueue(s); // 始点をキューに入れる
  for (int i = 1; i <= node_num; i++) d[i] = INFTY; // とりあえず全部INFTYにする
  d[s] = 0; // 始点から自分自身までの距離は0
  int u, p;
  while(queue_num > 0) { // キューが空でない間繰り返す
    u = queue[queue_head]; // キューの先頭からノードを取り出し，訪問
    dequeue(&p); // 同上
    for (int v = 1; v <= node_num; v++) {
        if (M[u][v] == 0) continue; // キュー先頭のノードとvが繋がってないならこのループは終了
        if (d[v] != INFTY) continue; // 既に距離を決めているならこのループは終了
        d[v] = d[u] + 1; // 次に訪問するノードまでの距離は，それまでの距離+1
        enqueue(v); // uに繋がっているノードは将来訪問しないといけない
    }
  }
  for (int i = 1; i <= node_num; i++) { // 表示部
    if (d[i] == INFTY) d[i] = -1;
    printf("%d %d\n", i, d[i]);
  }
}

// mainの流れはdfsと同じ(隣接行列の初期化→隣接行列にノード間の接続関係を登録→bfsを呼び出す)
int main(void)
{
  int u, v, k, i, j;
  
  scanf("%d", &node_num);
  for (i = 0; i <= node_num; i++) {
    for(j = 0; j <= node_num; j++) M[i][j] = 0;
  }

  for (i = 0; i < node_num; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d", &v);
      M[u][v] = 1;
    }
  }

  bfs(1);
  
  return 0;
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c;
    string s;
    cin>>s;
    a=s.size();
    if(s[a-1]=='s')
    s=s+"es";
    else
    s=s+'s';
    cout<<s;
    return 0;
}


Measured memory_bytes: 3628
def sort_three_numbers(num:list) -> None:
    if len(num) != 3:
        raise ValueError('Few input.')
    if any([n < 1 or n > 10000 for n in num]):
        raise ValueError('Input integer is invalid.')

    sorted_str = [str(n) for n in sorted(num)]
    print(' '.join(sorted_str))

if __name__ == "__main__":
    in_str = input()
    in_list = [int(x) for x in in_str.split()]
    sort_three_numbers(in_list)



Measured memory_bytes: 5604
s = list(input())
k = int(input())

for i in range(len(s)):
    if s[i] == "a": continue

    diff = ord("z") - ord(s[i]) + 1

    if diff <= k:
        k -= diff
        s[i] = "a"

if k > 0:
    k %= 26
    s[i] = chr(ord(s[i]) + k)

print("".join(s))

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

int main(){
    string c[3];
    cin>>c[0]>>c[1]>>c[2];
    int player=0;
    while(1){
        if(c[player].empty()){
            char ans=65+player;
            printf("%c\n",ans);
            return 0;
        }
        int next=c[player][0]-97;
        c[player].erase(c[player].begin());
        player=next;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
G = [[i for i in input()] for j in range(H)]

ls = []
dp = [[-1 for i in range(W)] for j in range(H)]
for h in range(H):
    for w in range(W):
        if G[h][w] == "#":
            ls.append([h,w])
            dp[h][w] = 1

ans = -1
while len(ls) > 0:
    ans += 1
    temp = []
    for h, w in ls:
        if 0 <= h+1 <= H-1 and dp[h+1][w] == -1:
            dp[h+1][w] = 1
            temp.append([h+1,w])
        if 0 <= h-1 <= H-1 and dp[h-1][w] == -1:
            dp[h-1][w] = 1
            temp.append([h-1,w])
        if 0 <= w+1 <= W-1 and dp[h][w+1] == -1:
            dp[h][w+1] = 1
            temp.append([h,w+1])
        if 0 <= w-1 <= W-1 and dp[h][w-1] == -1:
            dp[h][w-1] = 1
            temp.append([h,w-1])
    ls = temp

print(ans)

Measured memory_bytes: 179304
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =1e6+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
//F题：C（k+s）里面选k个 *每个可能情况26种qpow(26,k) - 重复出现的字母（没想到） 

char s[MAXN];
ll fac[MAXN*2],inv[MAXN*2];
ll qpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=(ans*a)%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
ll C(int i,int n)
{
	return fac[n]*inv[n-i]%mod*inv[i]%mod;
}
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	int m=strlen(s);
	ll ans=0;
	fac[0]=1;
	for(int i=1;i<=n+m;i++) fac[i]=fac[i-1]*i%mod;
	inv[n+m]=qpow(fac[n+m],mod-2);
	for(int i=n+m-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=0;i<=n;i++)
	{
		ans=(ans+qpow(26,i)*C(m-1,m+n-1-i)%mod*qpow(25,n-i)%mod)%mod;
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 35928
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int A, B;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> A >> B;
	cout << ((A - 2 * B) > 0 ? A - 2 * B : 0);
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<pair<int, int> > v(m);
    for (int i = 0; i < m; i++) cin >> v[i].second >> v[i].first;

    sort(a.begin(), a.end());
    sort(v.begin(), v.end(), greater<pair<int, int> >());

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

    int i = 0, j = 0;
    while (i < m && j < n) {
        if (v[i].first > a[j]) {
            a[j] = v[i].first;
            v[i].second--;
            j++;
            if (v[i].second == 0) i++;
        }
        else break;
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) ans += a[i];

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

Measured memory_bytes: 1408
#include <cstdio>           // printf(), scanf()
#include <cstring>          // memset()
#include <vector>
#include <queue>
#include <algorithm>        // min()

using namespace std;
static const int MAX_X = 100;
static const int MAX_Y = 100;
static const int MAX_V = MAX_X + MAX_Y + 2;
static const int INF = 100000000;

typedef struct edge_tbl
{
	int to, cap;
	unsigned long rev;
} edge;

vector<edge> G[MAX_V];
int level[MAX_V];
unsigned int iter[MAX_V];

void
bfs(int s)
{
	queue<int> que;

	memset(level, -1, sizeof(level));
	level[s] = 0;
	que.push(s);
	while (!que.empty())
	{
		int v = que.front(); que.pop();
		for (unsigned int i = 0; i < G[v].size(); ++i)
		{
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0)
			{
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int
dfs(int v, int t, int f)
{
	if (v == t)
		return f;

	for (unsigned int &i = iter[v]; i < G[v].size(); ++i)
	{
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to])
		{
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0)
			{
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}

	return 0;
}

int
max_flow(int s, int t)
{
	int flow = 0;
	while (true)
	{
		bfs(s);
		if (level[t] < 0)
			return flow;

		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF)) > 0)
			flow += f;
	}
}

int
main(int argc, char** argv)
{
	int X, Y, E;
	int x, y;

	scanf("%d %d %d", &X, &Y, &E);
	int s = X + Y, t = s + 1;
	for (int i = 0; i < X; ++i)
	{
		G[s].push_back((edge){i, 1, G[i].size()});
		G[i].push_back((edge){s, 0, G[s].size() - 1});
	}

	for (int i = 0; i < Y; ++i)
	{
		G[X + i].push_back((edge){t, 1, G[t].size()});
		G[t].push_back((edge){X + i, 0, G[X + i].size() - 1});
	}

	for (int i = 0; i < E; ++i)
	{
		scanf("%d %d", &x, &y);
		G[x].push_back((edge){X + y, 1, G[X + y].size()});
		G[X + y].push_back((edge){x, 0, G[x].size() - 1});
	}

	printf("%d\n", max_flow(s, t));
	return 0;
}

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

int main()
{
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;

    if(u==s)
        cout << a-1 << " " << b << endl;
    else
        cout << a << " " << b-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,k,ans=0;
  int data[200005]={0};
  cin>>n>>k;
  rep(i,n){
    int x;
    cin>>x;
    data[x]++;
  }
  sort(data,data+200005);reverse(data,data+200005);
  REP(i,k,200005){
    ans+=data[i];
  }
  cout<<ans<<endl;
  return 0;
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 3e5 + 5;
const int inf = 1e18 + 2;


void solve(int Case) {
    int n , k ;
    cin >> n >> k;
    //set<int> s ;
    vector<pair<int , int>> seg ;
    while(k --) {
        int a , b ;
        cin >> a >> b ;
        seg.push_back({a , b});
    }
    
    
    //for(auto X : seg) cout << X.ff << ' ' << X.ss << '\n';
    int ad[n + 2] , dp[n + 2];
    memset(ad , 0 , sizeof ad) ;
    memset(dp , 0 , sizeof dp) ;
    dp[1] = 1;
    for(int i = 1 ; i <= n ; i ++) {
        ad[i] = (ad[i] + ad[i - 1] + cmod) % cmod;
        dp[i] = (dp[i] + ad[i] + cmod) % cmod ;
        for(int j = 0 ; j < seg.size() ; j ++) {
            if(i + seg[j].ff > n) continue ;
            ad[i + seg[j].ff] = (ad[i + seg[j].ff] + dp[i] + cmod) % cmod;
            int temp = min(i + seg[j].ss , n) ;
            ad[temp + 1] = (ad[temp + 1] - dp[i] + cmod) % cmod;
        }
    }
    
    cout << dp[n] << '\n';
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case);
    }
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n;
    cin >> n;
    int cnt = 1;
    int ans = 0;
    while (n > 0) {
        ans += cnt;
        cnt *= 2;
        n /= 2;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define MOD 1000000007
#define SIZE 100001
using namespace std;
typedef long long ll;
ll Mp(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b%2 == 0){
            a = (a * a) % MOD;
            b /= 2;
        }else{
            res = (res * a) % MOD;
            b--;
        }
    }
    return res;
}
int main(void){
    int n;
    ll ans = 0, nf = 1, fs[SIZE];
    cin >> n;
    fs[0] = 0;
    for(int i=1;i<=n;i++){
        nf = (nf * i) % MOD;
        fs[i] = (fs[i-1] + Mp(i, MOD-2)) % MOD;
    }
    for(int i=1;i<=n;i++){
        ll a, t = MOD-1;
        cin >> a;
        t += fs[i] + fs[n-i+1];
        t = (t%MOD * nf) % MOD;
        ans = (ans + a*t)%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
S =input()
T =input()
#print(S)
s = len(S)-1
S = list(S)

#print(S)
flag = 0
for i in range(len(S)):
    h = [S[0]]
    S.remove(S[0])
    S = S + h
    str_ = ''.join(S)
    #print(str_)
    if str_ == T:
        flag = 1
        break
    #print(S)

if flag == 1:
    print("Yes")
else :
    print("No")

Measured memory_bytes: 3064
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn readv<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn readvv<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| readv()).collect()
}

fn main() {
    let vs: Vec<usize> = readv();
    let (n, m) = (vs[0], vs[1]);
    let mut mat: Vec<Vec<u64>> = readvv(n);
    mat.sort_by_key(|ab| ab[0]);
    let mut monay = 0;
    let mut k = 0;
    for ab in mat {
        if k + ab[1] > m as u64 {
            monay += ab[0] * ((m as u64) - k);
            break;
        }
        k += ab[1];
        monay += ab[0] * ab[1]
    }
    println!("{}", monay);
}


Measured memory_bytes: 10492
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int CONS = 1e9 + 7;
const ll INF = 1e16 + 7;

//63C
int main(void) {
	int n;
	cin >> n;
	vector<vector<int>> nums = vector<vector<int>>(10);

	int ans = 0;
	rep(0, n) {
		int c;
		cin >> c;
		nums[c % 10].push_back(c);
		ans += c;
	}
	rep(0, 10) {
		sort(nums[i].begin(), nums[i].end());
	}

	int amari = ans % 10;
	if (amari != 0) cout << ans << endl;
	else {
		int removeN = 101;
		rep(1, 10) {
			if (nums[i].size() > 0) {
				removeN = min(nums[i][0], removeN);
			}
		}
		if (removeN == 101)cout << 0 << endl;
		else {
			ans -= removeN;
			cout << ans << endl;
		}
		
	}
}


Measured memory_bytes: 256