akhauriyash/Code-Regression huggingface dataset:
// Ver19.03
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n, ans = 0;
  ll hoge[101];
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &hoge[i]);
  }
  sortdown(hoge, n);
  for (int i = 0; i < n; i++)
  {
    if (i % 2 == 0)
      ans += hoge[i];
    else
      ans -= hoge[i];
  }
  printf("%lld\n", ans);
  return 0;
}

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

//C++のヘッダ
#include <string> //文字のやりくりに必要
#include <iostream> //コンソール入出力命令使用に必要
#include <cstdlib>
#include <typeinfo>
using namespace std; //この名前空間で上のコンソール入出力を使用する


int main(void)
{

	long long s;
	int dig[11];
	int thr,c=0;
	int diff;
	int diffmin = 999;

	cin >> s;

	for (int i = 0; i < 11; i++){
		dig[i] = s % 10;
		s /= 10;
		c++;
		//cout << dig[i] << endl;
		if (s < 1) break;
	} 
	
	for (int i = 0; i < c-2; i++){
		thr = dig[i + 2] * 100 + dig[i + 1] * 10 + dig[i];
		diff = 753 - thr;
		if (diff < 0) diff *= (-1);
		if (diff < diffmin) diffmin = diff;
	}

	cout << diffmin << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n;
P x[100010],y[100010];
int par[100010],rankh[100010];
void init(int n) {
	for(int i=0; i<=n;i++){
		par[i]=i;
		rankh[i]=0;
	}
}
int find(int x){
	if(par[x]==x)return x;
	else return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(rankh[x]<rankh[y])par[x]=y;
	else{
		par[y]=x;
		if(rankh[x]==rankh[y])rankh[x]++;
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}
struct edge{int cost,from,to;};
bool operator<(const edge &a,const edge &b){
	return a.cost<b.cost;
};
vector<edge> vec;
int kruscal(){
	sort(vec.begin(),vec.end());
	int ans=0;
	init(n);
	for(edge e:vec){
		if(!same(e.from,e.to)){
			unite(e.from,e.to);
			ans+=e.cost;
		}
	}
	return ans;
}
signed main(){
	cin>>n;
	rep(i,n){
		cin>>x[i].first>>y[i].first;
		x[i].second=y[i].second=i;
	}
	sort(x,x+n);
	sort(y,y+n);
	rep(i,n-1){
		vec.push_back({x[i+1].first-x[i].first,x[i].second,x[i+1].second});
	}
	rep(i,n-1){
		vec.push_back({y[i+1].first-y[i].first,y[i].second,y[i+1].second});
	}
	cout<<kruscal()<<endl;
	return 0;
}

Measured memory_bytes: 11632
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    LS = list(map(int, input().split()))
    LS.sort()
    if LS[-1] >= sum(LS[:-1]):
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3952
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var a = Reads();
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[a[i]-1] == i + 1) ans++ ;
            }
            Console.WriteLine(ans / 2);

                Console.Out.Flush();
        }
    }
}




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

int main(){
	int n; cin >> n;
	string s; cin >> s;
	if(n%2 != 0){
		cout << "No" << endl;
	}else{
		for(int i = 0; i < n/2; i++){
			if(s[i] != s[n/2 + i]){
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String r=scan.next();
		String g = scan.next();
		String b = scan.next();
		String rbg = r+g+b;
		int rbgI = Integer.parseInt(rbg);
		if(rbgI%4==0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	 ll n,a,b;
	 cin>>n>>a>>b;
	 ll ans=0;
	 if((a+b)>0)
	 ans= min((n%(a+b)),a);
	 if((a+b)>0)
	 ans+=a*(n/(a+b));
	 cout<<ans;
	cout<<"\n"; 
 } 
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        String s=sc.next();
        String year0=s.substring(0,4);
        int year1=Integer.parseInt(year0);
        String day0=s.substring(8);
        int day1=Integer.parseInt(day0);

        if(year1<=2019){
            if(s.charAt(5)=='0'&&s.charAt(6)<='4'){
                if(day1<=30){
                    System.out.println("Heisei");
                }
                else{
                    System.out.println("TBD");
                }
            }
            else{
                System.out.println("TBD");
            }
        }
        else{
            System.out.println("TBD");
        }
        sc.close();
    }
}

Measured memory_bytes: 23380
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

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

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

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

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

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

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

	q := scanInt()

	pq0 := priorityQueue0{}
	pq1 := priorityQueue1{}
	heap.Init(&pq0)
	heap.Init(&pq1)

	ans := 0
	_ = scanInt()
	mid := scanInt()
	heap.Push(&pq0, mid)
	b := scanInt()
	c := 1

	for i := 0; i < q-1; i++ {
		query := scanInt()
		if query == 1 {
			a := scanInt()
			b += scanInt()
			c++

			if mid < a {
				heap.Push(&pq1, a)
			} else {
				heap.Push(&pq0, a)
			}

			if len(pq0) < len(pq1) {
				heap.Push(&pq0, heap.Pop(&pq1).(int))
			}

			if len(pq0) > len(pq1)+1 {
				heap.Push(&pq1, heap.Pop(&pq0).(int))
			}

			now := pq0[0]

			if c&1 == 0 {
				ans += abs(mid - now)
			}
			mid = now

			ans += abs(mid - a)

		} else {
			fmt.Fprintln(wr, mid, ans+b)
		}
	}

}

type priorityQueue0 []int

func (pq priorityQueue0) Len() int            { return len(pq) }
func (pq priorityQueue0) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq priorityQueue0) Less(i, j int) bool  { return pq[i] > pq[j] }
func (pq *priorityQueue0) Push(x interface{}) { *pq = append(*pq, x.(int)) }
func (pq *priorityQueue0) Pop() interface{} {
	res := (*pq)[len(*pq)-1]
	*pq = (*pq)[0 : len(*pq)-1]
	return res
}

type priorityQueue1 []int

func (pq priorityQueue1) Len() int            { return len(pq) }
func (pq priorityQueue1) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq priorityQueue1) Less(i, j int) bool  { return pq[i] < pq[j] }
func (pq *priorityQueue1) Push(x interface{}) { *pq = append(*pq, x.(int)) }
func (pq *priorityQueue1) Pop() interface{} {
	res := (*pq)[len(*pq)-1]
	*pq = (*pq)[0 : len(*pq)-1]
	return res
}


Measured memory_bytes: 9088
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;

#define MAX 256

int main(void){

	int a[10], b;

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

	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 9; j++){
			if (a[j] < a[j + 1]){
				b = a[j];
				a[j] = a[j + 1];
				a[j + 1] = b;
			}
		}
	}

	printf("%d\n%d\n%d\n", a[0], a[1], a[2]);

	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <map>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
int main() {
  int N, K; cin >> N >> K;

  ll A[N], sum[N+1];
  sum[0] = 0;
  rep(i, N) {
    cin >> A[i];
    --A[i];
    sum[i+1] = sum[i] + A[i];
    sum[i+1] %= K;
  }
  ll ans = 0;
  map<ll, int> m;
  rep(i, min(N+1, K)) {
    ++m[sum[i]];
  }
  rep(l, N) {
    --m[sum[l]];
    ans += m[sum[l]];
    if (l+K < N+1)
      ++m[sum[l+K]];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
import * as fs from "fs";
const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");

const [n, s, k] = input;
const char = s[Number(k) - 1];
let result = "";
for (const charS of s) {
    if (charS !== char) {
        result = result + "*";
    } else {
        result = result + char;
    }
}
console.log(result);

Measured memory_bytes: 7372
(defun f1(c)
  (cond
    ((equal c #\A) (princ "T"))
    ((equal c #\T) (princ "A"))
    ((equal c #\C) (princ "G"))
    ((equal c #\G) (princ "C"))
    )
  )

(setf c (read-char))
(f1 c)



Measured memory_bytes: 9828
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string solve(int a[])
{
	int box[2]={0};
	rep(i,10){
		if(box[box[0]<box[1]]<a[i])
			box[box[0]<box[1]]=a[i];
		else if(box[box[0]>box[1]]<a[i])
			box[box[0]>box[1]]=a[i];
		else
			return "NO";
	}
	return "YES";
}

int main()
{
	int n;
	cin>>n;
	rep(loop,n){
		int a[10];
		rep(i,10)
			cin>>a[i];
		cout<<solve(a)<<endl;
	}
	
	return 0;
}

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

const int N=400005;
int n,a[N],sum[N];
int v[N],nxt[N],head[N];
long long sz[N],ans[N];

void dfs(int x,int fa)
{
	sz[x]=1;
	int ts=sum[a[x]];
	for(int i=head[x];i>0;i=nxt[i])
	{
		if(v[i]==fa) continue;
		int tmp=sum[a[x]];
		dfs(v[i],x);
		int d=(sz[v[i]]-sum[a[x]]+tmp);
		ans[a[x]]+=1ll*d*(d+1)/2;
		sz[x]+=sz[v[i]];
	}
	sum[a[x]]=ts+sz[x];
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&v[i],&v[i+n]);
		nxt[i]=head[v[i+n]],head[v[i+n]]=i;
		nxt[i+n]=head[v[i]],head[v[i]]=i+n;
	}
	dfs(1,0);
//	for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
//	cout<<endl;
//	cout<<sz[3]<<endl;
	for(int i=1;i<=n;i++)
	{
//		cout<<ans[i]<<' '<<sum[i]<<endl;
		ans[i]+=1ll*(n-sum[i])*(n-sum[i]+1)/2;
		printf("%lld\n",1ll*n*(n+1)/2-ans[i]);
	}
}

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

int f(int x){
  if(x < 0){
    x = x * (-1);
  }
  return x;
}

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  
  vector<int> v(N - 1);
  for(int i = 0; i < N - 1; i++){
    v[i] = N - 1 - i;
  }
  
  for(int i = 1; i <= N; i++){
    for(int j = i + 1; j <= N; j++){
      if((j - i) > f(X - i) + f(Y - j) + 1){
        v[j - i - 1]--;
        v[f(X - i) + f(Y - j)]++;
      }
    }
  }
  
  for(int x : v){
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	char a[100];
	int i=0;
	cin >> a;
	if (a[0] == a[1] && a[2] == a[3]) {
		++i;
	}
 
	if (a[0] == a[2] && a[1] == a[3]) {
		++i;
	}
 
	if (a[0] == a[3] && a[1] == a[2]) {
		++i;
	}
 
	if (i == 1) {
		cout << "Yes";
	}
	else if (i != 1) {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int s,x,y,n;
	scanf("%d",&n);
	if (n<15){
		x=800*n;
	}
	else{
		x=(800*n)-200*(n/15);
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    [a,b,c,d] <- r'
    let nC = div b c - div' a c
    let nD = div b d - div' a d
    --print (nC,nD)
    let nCD = div b (lcm c d) - div' a (lcm c d)
    --print (nCD)
    print $ (b-a+1)-(nC+nD)+nCD

div' x y = if y * (div x y) == x then div x y - 1 else div x y


Measured memory_bytes: 380
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const int dy[4] = {-1, 0, 1, 0};
static const int dx[4] = {0, 1, 0, -1};
struct C1 {
    ll H_{};
    ll W_{};
    vector<string> v_{};
    vector<vector<ll>> dist{};
    vector<vector<bool>> visited{};
    explicit C1(vector<string> v) : H_(v.size()), W_(v[0].size()), v_(move(v)){
        dist.resize(H_, vector<ll>(W_, INT64_MAX));
        visited.resize(H_, vector<bool>(W_, false));
    }
    ll resolve() {
        queue<pll> q{};
        for(ll i=0; i < H_; ++i) {
            for(ll j=0; j < W_; ++j) {
                if (v_[i][j] == '#') {
                    q.push({i, j});
                    dist[i][j] = 0;
                }
            }
        }

        while(!q.empty()) {
            auto p = q.front();
            q.pop();
            ll y = p.first;
            ll x = p.second;
            if (visited[y][x]) {
                continue;
            }
            visited[y][x] = true;
            for(ll i=0; i < 4; ++i) {
                ll yy = min(H_-1, max(0LL, y+dy[i]));
                ll xx = min(W_-1, max(0LL, x+dx[i]));
                if ((xx != x || yy != y) && v_[yy][xx] == '.' && !visited[yy][xx]) {
                    dist[yy][xx] = min(dist[yy][xx], dist[y][x] + 1);
                    q.push({yy, xx});
                }
            }
        }
        ll max_dist = 0;
        for (auto&& a : dist) {
            for (auto&& b : a) {
                max_dist = max(max_dist, b);
            }
        }
        return max_dist;
    }
};

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> v{};
    for (int i=0; i < H; ++i) {
        string x;
        cin >> x;
        v.emplace_back(x);
    }
    C1 c{move(v)};
    cout << c.resolve() << endl;
    return 0;
}


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

int main(){
	long int M = pow(10, 9) + 7;
	int n;
	cin >> n;

	long int ans = 1;
	for(int i=1; i<=n; i++){
		ans *= (i%M);
		ans %= M;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
DIV = 1_000_000_007
n = gets.to_i
l = n.times.map{ gets.chomp }
l.delete('-')
s = l.size
u = l.count('U')
d = l.count('D')
pos_u = [0]*s
pos_d = [0]*s
l.each_with_index do |str, i|
  if str == 'U' then (i+1...s).each{ |j| pos_u[j]+= 1 }
  else (0...i).each{ |j| pos_d[j]+= 1 }
  end
end
dp = 2.times.map{ [0]*(s+1) }
dp[0][0] = 1
for i in (1..s)
  for j in (0..i)
    dp[1][j] = j > 0 ? dp[0][j-1]*(pos_u[i-1]-(j-1)) : 0
    dp[1][j] += dp[0][j]*(pos_d[i-1]-d+(i-j)) if j < i
    dp[1][j] %= DIV
  end
  dp.rotate!
end
p dp[0][u]

Measured memory_bytes: 8744
#include<iostream>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int H,W,h,w;
int main()
{
    scanf("%d%d%d%d",&H,&W,&h,&w);
    cout<<H*W-h*W-H*w+h*w;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

vector<string> split(string &str, const char *delim){
	vector<string> result;
	int cutAt;
	while( (cutAt = str.find_first_of(delim)) != str.npos ){
		if(cutAt > 0){
			result.push_back(str.substr(0, cutAt));
		}
		str = str.substr(cutAt + 1);
	}
	if(str.length() > 0){
		result.push_back(str);
	}
	return result;
}

void reversepoland(string &exp){
	vector<string> token = split(exp," ");
	vector<double> resolveNumber;
	vector<string> resolveString;
	for(int i=0;i<token.size();i++){
		char *p=NULL;
		double d=strtod(token[i].c_str(),&p);
		if(p-token[i].c_str()==token[i].size()){
			resolveNumber.push_back(d);
			resolveString.push_back(token[i]);
		}else{
			//if(resolveNumber.size()<2){printf("stack few\n");return;}
			double d2=resolveNumber[resolveNumber.size()-1],d1=resolveNumber[resolveNumber.size()-2];
			resolveNumber.pop_back(),resolveNumber.pop_back();
			string s2=resolveString[resolveString.size()-1],s1=resolveString[resolveString.size()-2];
			resolveString.pop_back(),resolveString.pop_back();
			double ret;

			if(token[i]=="+"){ret=d1+d2;}
			else if(token[i]=="-"){ret=d1-d2;}
			else if(token[i]=="*"){ret=d1*d2;}
			else if(token[i]=="/"){ret=d1/d2;}
			//else if(token[i]=="%"){ret=d1%d2;}
			//else if(token[i]=="**"){ret=pow(d1,d2);}
			//else{printf("unknown OP %s\n",token[i].c_str());return;}

			resolveNumber.push_back(ret);
			resolveString.push_back("("+s1+token[i]+s2+")"); //this won't emit "optimized" expression. full of parens.
		}
	}
	//if(resolveNumber.size()!=1){printf("result stack not 1");return;}
	printf("%f\n",resolveNumber[0]);
}
int main(){for(string str;getline(cin,str);reversepoland(str));}

Measured memory_bytes: 1276
#include<stdio.h>

int main(){
  int n;
  int i, j, k;
  int b, f, r, v;
  int arr[4][3][10];

  // array initialization
  for(i = 0; i < 4; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
	arr[i][j][k] = 0;
      }
    }
  }

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d %d %d %d", &b, &f, &r, &v);
    arr[b - 1][f - 1][r - 1] += v;
  }

  for(i = 0; i < 4; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
	printf(" %d", arr[i][j][k]);
      }
      printf("\n");
    }
    if(i != 3){
      printf("####################\n");
    }
  }

  return 0;
}


Measured memory_bytes: 2076
import sys
def input(): return sys.stdin.readline().rstrip()

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

d = []
A = []

for i in range(K):
    x = int(input())
    d.append(x)
    a = list(map(int,input().split()))
    A.append(a)

vec = [0] * N

for a in A:
    for i in a:
        i -= 1
        vec[i] += 1

ans = 0
for i in range(N):
    if vec[i] == 0:
        ans += 1

print(ans)
        
    




Measured memory_bytes: 9192
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int x = scan.nextInt();

    if(a+b < x){
      System.out.println("NO");
      return;
    }else{
      if(x - a < 0){
        System.out.println("NO");
        return;
      }else if(x - a == 0){
        System.out.println("YES");
        return;
      }else{
        System.out.println("YES");
        return;
      }

    }
  }
}


Measured memory_bytes: 22356
import qualified Data.IntMap.Lazy as M
import Data.IntMap.Lazy ((!))
import Data.Char
import Data.List

type Atlas = M.IntMap Bool
type Coordinate = Int
size = 12

main = interact $ unlines . map (show . num_of_island) . read' . lines
 where
  read' [] = []
  read' xs = read_atlas (concat (take size xs)) : read' (drop (size+1) xs)

num_of_island :: Atlas -> Int
num_of_island a = num_to_fix paint_island a

paint_island :: Atlas -> Atlas
paint_island a
 | or (M.elems a) = foldr (\i a' -> M.adjust not i a') a (contiguous_from start a)
 | otherwise = a
    where start = head $ M.keys $ M.filter id a

num_to_fix :: Eq a => (a -> a) -> a -> Int
num_to_fix f x = if f x == x then 0 else 1 + num_to_fix f (f x)

read_atlas :: String -> Atlas
read_atlas = M.fromList . zip [0..] . map to_boolean
 where to_boolean d = case d of {'0'->False; '1'->True}

contiguous_from :: Coordinate -> Atlas -> [Coordinate]
contiguous_from i a = M.keys $ M.filterWithKey (\i' _ -> are_contiguous i i' a) a

are_contiguous :: Coordinate -> Coordinate -> Atlas -> Bool
are_contiguous c1 c2 a = if a!c1 /= a!c2 then False else investigate c1 []
 where
  investigate c trace
   | c == c2 = True
   | a!c /= a!c2 = False
   | otherwise = or $ map (flip investigate (c:trace)) (neighbors c \\ trace) 

neighbors :: Coordinate -> [Coordinate]
neighbors c = filter (not . is_outside) [pred c, succ c, c-size, c+size]
 where
  is_outside c' = is_westout c' || is_eastout c' || is_northout c' || is_southout c'
   where
    is_westout c' = div c size == succ (div c' size) && c == succ c'
    is_eastout c' = div c size == pred (div c' size) && c == pred c'
    is_northout c' = c' < 0
    is_southout c' = c' >= size*size
  

Measured memory_bytes: 5404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<double,double> PDD;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const double eps = 1e-10;

double dis(PDD x, PDD y){
  return sqrt((x.first - y.first)*(x.first - y.first) + (x.second - y.second)*(x.second - y.second));
}

bool allin(vector<PDD> &v, PDD center, double r){
  for(PDD & p:v) if(dis(p,center) > r + eps) return false;
  return true;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<PDD> v(N);
  rep(i,N)cin >> v[i].first >> v[i].second;
  auto f = [&](double R){
    bool sat = false;
    rep(i,N-1)repp(j,i+1,N){
      if(dis(v[i],v[j]) > 2*R+eps) return false;
      double x = v[i].first - v[j].first;
      double y = v[i].second - v[j].second;
      double a = (x*x + y*y)/2.0;
      PDD p;

      p.first = (x*a + y* sqrt((x*x+y*y)*R*R - a*a))/(x*x+y*y) + v[j].first;
      p.second = (y*a - x* sqrt((x*x+y*y)*R*R - a*a))/(x*x+y*y) + v[j].second;

      bool s = true;
      rep(k,N) if(dis(v[k],p) > R+eps) s = false;
      if(s) sat = true;

      p.first = (x*a - y* sqrt((x*x+y*y)*R*R - a*a))/(x*x+y*y) + v[j].first;
      p.second = (y*a + x* sqrt((x*x+y*y)*R*R - a*a))/(x*x+y*y) + v[j].second;

      s = true;
      rep(k,N) if(dis(v[k],p) > R+eps) s = false;
      if(s) sat = true;

      if(sat) return true;
    }
    return false;
  };
  double l = 0, r = 1000;
  rep(i,100){
    double m = (l+r)/2.0;
    if(f(m)) r = m;
    else l = m;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 256
//404 Not Found {=}7 (o)7 (x)7
#include<bits/stdc++.h>
using namespace std;
#define apppend push_back
#define endl "\n"
#define dbug(x) cout<<#x<<"="<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 1e5, inf = 1e9, mod= 1e9+7;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout << setprecision(30);
    char a;
    cin >> a;
    cout << ++a;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        String s = bf.readLine();
        String t = bf.readLine();
        ArrayList<TreeSet<Integer>> pos = new ArrayList<TreeSet<Integer>>();
        for(int i=0; i<26; i++) pos.add(new TreeSet<Integer>());
        for(int i=0; i<s.length(); i++) {
          pos.get(s.charAt(i)-'a').add(i);
        }
        int cur = -1;
        int fullcycles = 0;
        for(int i=0; i<t.length(); i++) {
          TreeSet<Integer> ts = pos.get(t.charAt(i)-'a');
          if(ts.size() == 0) {
            out.println("-1");
            out.close();
            System.exit(0);
          }
          if(ts.last() <= cur) {
            fullcycles++;
            cur = ts.first();
          }
          else cur = ts.higher(cur);
        }
        long ans = 0L + cur + 1L*fullcycles*s.length()+1;
        out.println(ans);
        // int n = Integer.parseInt(bf.readLine());
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 34132
#include<iostream>

int n;
int p;
int prime[1000000];
bool isprime[1000000];

void sieve()
{
	p = 0;
	isprime[0] = isprime[1] = false;
	for( int i = 2; i <= n; i++ ) isprime[i] = true;
	
	for( int i = 2; i <= n; i++ ){
		if( isprime[i] ){
			isprime[i] = false;
			prime[p++] = i;
			for( int j = i * 2; j <= n; j += i ) isprime[j] = false;
		}
	}

 	return;
}

int main()
{
	while( std::cin >> n ){	
		sieve();
		std::cout << p << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 2448
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var M int64
	scanner.Scan()
	M, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	A := make([]int64, M)
	for i := int64(0); i < M; i++ {
		scanner.Scan()
		A[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}
	fmt.Println(solve(N, M, A))
}
func solve(N int64, M int64, A []int64) int64 {
	cnt := int64(0)
	for _, a := range A {
		cnt += a
	}
	if N < cnt {
		return -1
	}
	return N - cnt
}


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

int main() {
  int K;
  cin >> K;
  vector<vector<int>> numrec(12, vector<int>(12));
  rep(i, 10) { numrec.at(1).at(i + 1) = 1; }
  for (int deg = 2; deg < 12; deg++) {
    for (int j = 1; j < 11; j++) {
      numrec.at(deg).at(j) = numrec.at(deg - 1).at(j - 1) +
                             numrec.at(deg - 1).at(j) +
                             numrec.at(deg - 1).at(j + 1);
    }
  }
  int sum = 0;
  int knr = 0;
  int res = 0;
  int knnr = 0;
  for (int nr = 1; nr < 12; nr++) {
    for (int nnr = 2; nnr < 11; nnr++) {
      sum += numrec.at(nr).at(nnr);
      if (sum >= K) {
        knr = nr;
        knnr = nnr;
        res = K - sum + numrec.at(nr).at(nnr);
        break;
      }
    }
    if (sum >= K) {
      break;
    }
  }
  string ans;
  int nr = knr;
  int nnr = knnr;
  while (nr > 0) {
    ans += to_string(nnr - 1);
    nr--;
    for (int i = -1; i < 2; i++) {
      if (numrec.at(nr).at(nnr + i) < res) {
        res -= numrec.at(nr).at(nnr + i);
      } else {
        nnr = nnr + i;
        break;
      }
    }
  }

  // if (knnr > 2) {
  //   knnr--;
  // } else {
  //   knnr = 9;
  //   knr--;
  // }

  cout << ans << endl;
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> v(N, 0);
    for (int i = 0; i < N-1; i++)
    {
        int x;
        cin >> x;
        x--;
        v[x]++;
    }

    for (int i = 0; i < N; i++)
    {
        cout << v[i] << endl;
    }
}

Measured memory_bytes: 3992
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

n = int(input())

l = []

l = [str(input()) for i in range(n)]

ans = 0

for i in range(n):
	if i == n-1:
		pass
	else:
		if l[i][len(l[i])-1] == l[i+1][0]:
			ans = ans + 1

print('Yes' if ans==n-1 and len(l)==len(set(l)) else 'No')





Measured memory_bytes: 3064
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);

		String input1 = reader.nextLine();
		String input2 = reader.nextLine();

		BigInteger b1 = new BigInteger(input1);
		BigInteger b2 = new BigInteger(input2);

		if (b1.compareTo(b2) < 0) {
			System.out.println("LESS");
		} else  if (b1.compareTo(b2) > 0) {
			System.out.println("GREATER");
		} else {
			System.out.println("EQUAL");
		}

		reader.close();
	}
}


Measured memory_bytes: 21716
from itertools import accumulate
n = int(input())
lst = [0] * 100002
for _ in range(n):
  a, b = map(int, input().split())
  lst[a - 1] += 1
  lst[b] -= 1
lst = list(accumulate(lst))
for i in range(n, -1, -1):
  if i <= lst[i]:
    print(i)
    break


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

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf

int x, y;

int main() { 

  cin >> x >> y;
  cout << x + y / 2 << endl;

  return 0;
}


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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            if(N == 3 || N == 5 || N == 7)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11092
N, M = [int(i) for i in input().split()]
road = [list() for i in range(N + 1)]
for i in range(M):
    a, b = [int(i) for i in input().split()]
    road[a].append(b)
    road[b].append(a)


def solve(before, visited, now):
    visited.append(now)
    if len(visited) is N:
        return 1
    pattern = 0
    for way in road[now]:
        if way is now:
            continue
        if way in visited:
            continue
        pattern += solve(now, visited[:], way)
    return pattern


print(solve(0, [], 1))


Measured memory_bytes: 3064
main = do
  li <- getLine
  let k = read li
  let ans = compute k
  print ans

{-
n桁のルンルン数の列に対して、
それらを10倍して、元の1の位を-1,+-0,+1した数を
加えたものがn+1桁のルンルン数になる。
ただし、0-1や9+1は却下する。
-}

lunluns = [1..9] ++
  [ x*10+e
  | x <- lunluns
  , let d = mod x 10
  , e <- [d-1,d,d+1]
  , 0 <= e, e <= 9
  ]

compute :: Int -> Int
compute k = lunluns !! pred k

Measured memory_bytes: 4988
import scala.collection.mutable._

object Main extends App{
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val in = Array.fill(N)(sc.nextInt)
    
    val pts = in.sorted
    val all_pt = pts.sum
    
    if (all_pt % 10 == 0) {
        val diffs = pts.filter(x => x % 10 != 0)
        if (diffs.isEmpty) {
            println(0)
        } else {
            println(all_pt - diffs.head)
        }
    } else {
        println(all_pt)  
    }
        
}   




Measured memory_bytes: 25920
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    final Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int tmp = 0;
    int r = 0;
    
    if (a < b) {
      tmp = a;
      a = b;
      b = tmp;
    }
    
    while (b > 0) {
      r = a % b;
      a = b;
      b = r;
    }
    
    System.out.println(a);
  }
}



Measured memory_bytes: 26204
#include<bits/stdc++.h>
using namespace std;
const int N=505;
int ans[N*N],x[N],f[N],n;
int cmp(int a,int b){
	return x[a]<x[b];
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&x[i]),f[i]=i;
	sort(f+1,f+n+1,cmp);
	int k=1;
	for (int i=1;i<=n;i++){
		ans[x[f[i]]]=f[i];
		for (int j=1;j<f[i];j++){
			while (ans[k])k++;
			if (k>x[f[i]]){
				puts("No");
				return 0;
			}
			ans[k]=f[i];
		}
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n-f[i];j++){
			while (ans[k])k++;
			if (k<x[f[i]]){
				puts("No");
				return 0;
			}
			ans[k]=f[i];
		}
	puts("Yes");
	for (int i=1;i<=n*n;i++)printf("%d ",ans[i]);
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

int calc(ll y, ll x, int sta = 59) {
	if (x <= 0)return 0;
	if (y < 0) {
		ll memo = 1;
		while (memo < -y)memo *= 2;
		ll d = x / memo;
		int res = 0;
		if (d % 2)res ^= calc(y + memo, memo);
		ll r = x % memo;
		res ^= calc(y + memo, r);
		return res;
	}
	if (y == 0)return 1;
	ll memo = 1;
	int chk;
	for (int i = sta; i >= 0; i--) {
		ll k = (ll)1 << i;
		if (k <= y) {
			memo = k; chk = i - 1; break;
		}
	}
	while (memo * 2 <= y)memo *= 2;
	if (memo <= x) {
		int res = calc(y - memo, x - memo,chk);
		if (memo == y)res ^= 1;
		return res;
	}
	else {
		return calc(y - memo, x,chk);
	}
}
void solve() {
	int n; cin >> n;
	vector<ll> x(n), y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	ll le = -(1e+17) - 1; ll ri = -le;
	while (ri - le > 1) {
		ll mid = (le + ri) / 2;
		int res = 0;
		rep(i, n) {
			ll dy = y[i];
			ll dx = mid - x[i] + 1;
			res ^= calc(dy, dx);
		}
		if (res)ri = mid;
		else le = mid;
	}
	cout << ri << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(17);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
    string N;
    cin >> N;
    if(N[0] == N[1])
    {
        if(N[1] == N[2])
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(N[1] == N[2])
    {
        if(N[2] == N[3])
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int n,m;
    cin >> n >> m;
    ve<pair<int,int>> key;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        int cost = 0;
        rep(j,b){
            int c;
            cin >> c;
            c--;
            cost |= (1<<c);
        }
        key.push_back({a,cost});
    }
    
    const int INF = 1000000000;
    
    ve<int> dp(1<<n,INF);
    dp[0] = 0;
    
    for (int i = 0; i < (1<<n); i++) {
        for (int j = 0; j < m; j++) {
            int tt = i | key[j].se;
            dp[tt] = min(dp[tt], dp[i]+key[j].fi);
        }
    }
    
    if(dp[(1<<n)-1] == INF) out(-1);
    else out(dp[(1<<n)-1]);



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    long long n,m;cin >> n >> m;
    vector<long long> a;
    long long sum = 0;
    for(long long i = 0; i < n;i++ ){
        long long an; cin >> an;
        a.push_back(an);
        sum += an;
    }
    sort(a.begin(), a.end());

    vector<pair<long long, int> > pv;

    for(long long i = 0; i < m; i++){
        pair<long long, int> p; cin >> p.second >> p.first;
        pv.push_back(p);
    }
    sort(pv.rbegin(), pv.rend());
    
    // for(long long i = 0; i < m ; i++){
    //     cout << pv[i].first << endl;
    // }
    // for(long long i = 0; i < n ; i++){
    //     cout << a[i] << endl;
    // }

    long long index = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < pv[i].second; j++){
            if(pv[i].first < a[index] || index > n - 1){
                cout << sum << endl;
                exit(0);
            }else{
                //a[index] = pv[i].first;
                
                //cout << "pv: " << pv[i].first << "== a: " << a[index] << endl;
                sum += (pv[i].first - a[index]); 
                //cout << index << ": "<< a[index] << endl;
                index++;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <queue>
using namespace std;
const int N=1e2+10;
const int INF=1e9+10;
int graph[N][N],ans=0;
void flow(int s,int t,int n){
    int dis[n],p[n],nxt,f=INF;
    queue<int> q;
    for(int i=0;i<n;i++)dis[i]=INF;
    for(int i=0;i<n;i++)if(graph[s][i]!=0){
        q.push(i);
        dis[i]=1;
        p[i]=s;
    }
    while(!q.empty()){
        nxt=q.front();
        q.pop();
        if(nxt==t){
            while(nxt!=s){
                f=min(f,graph[p[nxt]][nxt]);
                nxt=p[nxt];
            }
            ans+=f;
            nxt=t;
            while(nxt!=s){
                graph[p[nxt]][nxt]-=f;
                graph[nxt][p[nxt]]+=f;
                nxt=p[nxt];
            }
            flow(s,t,n);
            return ;
        }
        dis[nxt]++;
        for(int i=0;i<n;i++)if(graph[nxt][i]!=0&&dis[i]>dis[nxt]){
            dis[i]=dis[nxt];
            p[i]=nxt;
            q.push(i);
        }
    }
}
int main(){
    int n,m,l,r,w;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)graph[i][j]=0;
    while(m--){
        scanf("%d%d%d",&l,&r,&w);
        graph[l][r]+=w;
    }
    flow(0,n-1,n);
    printf("%d\n",ans);
}


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

int main(){
    int A1,A2,A3;
    int sum = 0;
    cin >> A1 >> A2 >> A3;
    
    sum = A1 + A2 + A3;
    if (sum >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 3560
while 1:
    n,l,r=map(int,input().split())
    if n==l==r==0:break
    a=[]
    for i in range(n):
        a.append(int(input()))
    ans=0
    a.append(1)
    for i in range(l,r+1):
        for j in range(n+1):
            if i%a[j]==0:
                if j%2==0:ans+=1
                break
    print(ans)


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

int main()
{
    string s;
    cin >> s;
    int c=0;
    for(int i=0;i<3;i++){
        if(s[i]==s[i+1])
            c=1;
    }
    if(c==1){
        cout << "Bad"<< endl;
    }
    else{
        cout << "Good"<< endl;
    }
    return 0;
}


Measured memory_bytes: 256
def inputV(h):
	return [list(map(int,input().split())) for i in range(h)]

def calcC(A,B,i,j):
	cij = 0
	for k in range(m):
		cij += A[i][k]*B[k][j]
	return cij

n,m,l = map(int,input().split())

A=inputV(n) #[n][m]

B=inputV(m) #[m][l]

for i in range(n):
	for j in range(l):
		if j > 0 :
			print(" ",end="")
		print(calcC(A,B,i,j),end="")
	print()



Measured memory_bytes: 6564
N = gets.to_i
array = gets.split(" ").map(&:to_i)
count = 0
i = 0
while i < N-1
    j = i+1
    minj = i
    while j < N
        if array[minj] > array[j]
            minj = j
        end
        j += 1
    end
    if array[minj] != array[i]
        array[i], array[minj] = array[minj], array[i]
        count += 1
    end
    i += 1 
end
puts array.join(" "),count


Measured memory_bytes: 6872
#include<stdio.h>
#include<math.h>

int main(void)
{
	double x1, x2, y1, y2;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	/*２点間の距離を求めて表示*/
	printf("%f\n", sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)));
	return 0;
}


Measured memory_bytes: 2056
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root=NIL;
/*
Node treeMinimum(Node x){
 
 
}
*/
 
Node treeSearch(Node u, int k){
  if (u == NIL ||  k == u->key){
    return u;
  }
  else if (k < u->key){
    return treeSearch(u->left,k);
  }
  else return treeSearch(u->right,k);
}
  /*
Node treeSuccessor(Node x){
 
 
}
  
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 
 
 
}*/
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
     
    while(x/*->key*/ != NIL){
        y=x;
        if(z->key < x->key)x=x->left;
        else x=x->right;
    }
        z->parent=y;
        if (y==NIL)root=z;
        else if(z->key < y->key)y->left=z;
        else y->right = z;
}
 
void inorder(Node u){
    if(u->left != NIL){
        inorder(u->left);
    }
        printf(" %d",u->key);
    if(u->right != NIL){
        inorder(u->right);
    }
 
}
void preorder(Node u){
    printf(" %d",u->key);
    if(u->left != NIL){
        preorder(u->left);
    }
    if(u->right != NIL){
        preorder(u->right);
    }
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      //return 0;
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }  else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }/* else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }*/
  }
 
  return 0;
}

Measured memory_bytes: 19364
#include <iostream>
using namespace std;
int main(){
	/*int a,b;
	cin>>a>>b;
	cout<<b-a%b<<endl;*/
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char *getsn(char *s, int n);

int main(void)
{
	char instr[1201];
	int nums;

	getsn(instr, 1201);
	int i=0;
	char c;
	while((c=instr[i]) != 0){
		if(c > 0x40 && c<0x5b){
			c = c + 0x20;
		}else if(c > 0x60 && c<0x7b){
			c = c - 0x20;
		}
		putchar(c);
		i++;
	}
	putchar('\n');
	
	return 0;
}

char *getsn(char *s, int n){
	if(fgets(s, n, stdin) == NULL) return NULL;
	char *ln = strchr(s, '\n');
	if(ln) *ln = 0;
	else
	while(1){
		int c = getchar();
		if(c == '\n' || c == EOF) 
			break;
	}
	return s;
}



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

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

    int ans = x / 500 * 1000 + (x % 500) / 5 * 5;

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


Measured memory_bytes: 256
X = list(map(int, input().split()))
A = list(map(int, input().split()))
N = X[0]
M = X[1]
O = 0
for i in range(N):
  if A[i] >= sum(A) / (4 * M):
    O += 1

if O >= M:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3188
process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
reader.on('line', (line) => {
    lines.push(line);
});
reader.on('close', () => {
    let [N, K] = lines[0].split(" ");
    const n = parseInt(N);
    let k = BigInt(K);
    const a = lines[1].split(" ").map(e => parseInt(e));

    let s = [];
    let ord = new Array(n + 1).fill(-1);
    
    let v = 1;
    while (ord[v] === -1) {
        ord[v] = s.length;
        s.push(v);
        v = a[v - 1];
    }
    let l = ord[v];
    let c = s.length - l;
    
    if (k < l) {
        console.log(s[k]);
    } else {
        k -= BigInt(l);
        const mod = parseInt(k % BigInt(c));
        console.log(s[l+mod]);
    }
});

Measured memory_bytes: 52696
#include <iostream>
#include <string>
int main(void){
	std::string s;
	std::cin>>s;
	bool cflag=false,fflag=false;
	for(int i=0;i<s.length();i++){
		if(s[i]=='C'){
			cflag=true;
		}
		if(cflag){
			if(s[i]=='F'){
				fflag=true;
			}
		}
	}
	if(cflag && fflag){
		std::cout<<"Yes"<<std::endl;
	}else {
		std::cout<<"No"<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 256