akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int>P;

char s[1000][1001];
int h, w, dp[1000][1000][1 << 5], dx[]{ -1,0,1,0 }, dy[]{ 0,-1,0,1 };
int a[]{ 0,2,4,3 }, b[]{ 0,2,3,1 };

int s1(int t) {
	int u = 0;
	if (t >> 3 & 1)u |= 1;
	if (t >> 4 & 1)u |= 1 << 2;
	return u;
}
int s2(int t) {
	int u = 0;
	if (t >> 1 & 1)u |= 1;
	if (t >> 3 & 1)u |= 1 << 2;
	return u;
}
int rec(int x, int y, int t) {
	int T = t;
	if (dp[x][y][t] != -1)return dp[x][y][t];
	int res = INT_MAX, p = 0;
	if ((!(t >> 3 & 1)) && '1' <= s[x][y] && s[x][y] <= '9') {
		t |= 1 << 3; p = s[x][y] - '0';
	}
	if (x == h - 1 && y == w - 1)return dp[x][y][t] = p;
	vector<P>v;
	rep(i, 4) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] < '1' || '9' < s[nx][ny])continue;
		if (i < 2 && (t >> a[i] & 1))continue;
		v.push_back(P(s[nx][ny] - '0', i));
	}
	if (v.empty()) {
		if (x + 1 < h)res = min(res, rec(x + 1, y, s1(t)) + p);
		if (y + 1 < w)res = min(res, rec(x, y + 1, s2(t)) + p);
	}
	rep(i, v.size()) {
		if (x + 1 < h) {
			int sum = p, r = t, u = 0;
			rep(j, v.size()) {
				if (i == j)continue;
				sum += v[j].first;
				if (v[j].second >= 2)u |= 1 << b[v[j].second];
				else r |= 1 << b[v[j].second];
			}
			res = min(res, rec(x + 1, y, s1(r) | u) + sum);
		}
		if (y + 1 < w) {
			int sum = p, r = t, u = 0;
			rep(j, v.size()) {
				if (i == j)continue;
				sum += v[j].first;
				if (v[j].second >= 2)u |= 1 << a[v[j].second];
				else r |= 1 << a[v[j].second];
			}
			res = min(res, rec(x, y + 1, s2(r) | u) + sum);
		}
	}
	return dp[x][y][T] = res;
}
int main() {
	scanf("%d%d", &h, &w);
	rep(i, h)scanf("%s", s[i]);
	memset(dp, -1, sizeof(dp));
	printf("%d\n", rec(0, 0, 0));
}

Measured memory_bytes: 129564
import sys
sys.setrecursionlimit(300000)
from bisect import bisect_left

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


# 区間updateと要素クエリ
class SegmentTree(object):

    def __init__(self, A, e, fn):
        self.fn = fn
        self.length = 1 << len(A).bit_length()
        self.data = [e] * (self.length * 2)
        for i in range(len(A)):
            self.data[i + self.length - 1] = A[i]
        for i in reversed(range(self.length - 1)):
            self.data[i] = self.fn(self.data[2 * i + 1], self.data[2 * i + 2])

    # 区間[l, r)の値とxをfnで比較して更新する
    def update(self, l, r, x):  # O(logN)
        l += self.length
        r += self.length
        while l < r:
            if l & 1:
                self.data[l] = self.fn(self.data[l], x)
                l += 1
            if r & 1:
                self.data[r - 1] = self.fn(self.data[r - 1], x)
                r -= 1
            l //= 2
            r //= 2

    # i番目の要素の値を取得する
    def query(self, i):  # O(logN)
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.fn(ret, self.data[i])
        return ret

N, Q = MI()
STX = [tuple(MI()) for _ in range(N)]
D = [I() for _ in range(Q)]

seg = SegmentTree([INF] * Q, INF, min)
for S, T, X in STX:
    # [S - X, T - X) に出発する人[l番目の人, r番目の人)が影響を受ける
    l = bisect_left(D, S - X)
    r = bisect_left(D, T - X)
    seg.update(l, r, X)

for i in range(Q):
    ans = seg.query(i)
    if ans == INF:
        print(-1)
    else:
        print(ans)

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



int main(){
    ll h,w,d;cin>>h>>w>>d;
    pair<ll,ll> a[100010];
    rep(i,0,h){
        rep(j,0,w){
            ll b;cin>>b;
            a[b]=make_pair(i+1,j+1);
        }
    }
    vector<ll> mod[100010];
    rep(i,1,d+1){
        ll j=0;
        while(i+j*d<=h*w){
            if(j==0)mod[i].push_back(0);
            else mod[i].push_back(mod[i][mod[i].size()-1]+abs(a[i+j*d].first-a[i+(j-1)*d].first)+abs(a[i+j*d].second-a[i+(j-1)*d].second));
            j++;
        }
    }
    ll q;cin>>q;
    rep(i,0,q){
        ll x,y;cin>>x>>y;
        ll ama=x%d;
        if(ama==0)ama=d;
        ll l=(x-ama)/d,r=(y-ama)/d;
        cout<<mod[ama][r]-mod[ama][l]<<endl;
    }
}







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

int main() {
  int t, n, k, x, pre_x, len, start;

  cin >> t;

  while(t--) {
    priority_queue<int> que;

    cin >> n >> k;

    for(int i = 0; i < n; i++) {
      cin >> x;
      if(i == 0){
	start = pre_x = x;
      } 
      else{
        que.push(x - pre_x);
        pre_x = x;
      } 
    }

    len = x - start;

    for(int i = 0; i < k-1 && que.size(); ++i){
      len -= que.top();
      que.pop();
    }

    cout << len << endl;
  }

  return 0;
}

Measured memory_bytes: 3540
import fractions

# divisor
def div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

def factor(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr

def main():
    A, B = map(int, input().split())
    d = fractions.gcd(A, B)
    #print('d={}'.format(d))

    if d == 1:
        print(1)
    else:
        print(1 + len(factor(d)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 64492
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	int N;
	cin >> N;
	long long sum;
	int i, j = 0;
	sum = 0;
	for (i = 1; i <= N; i++) {
		if (i % 3 == 0 || i % 5 == 0) {
			j++;
		}
		else {
			sum = sum + i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3632
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
--import Debug.Trace

fromLeft :: String -> Int -> Int -> Int -> [(Int,Int)] -- cnt,pos
fromLeft [] cnt pos now = [(cnt `div` 2,pos),(cnt - (cnt `div` 2), pos+1)]
fromLeft (c:s) cnt pos now = if c == 'R' then (cnt `div` 2,pos):(cnt - (cnt `div` 2), pos+1):(fromLeft s 0 now (now+1))
  else fromLeft s (cnt+1) pos (now+1)

fromRight:: String -> Int -> Int -> Int -> Int -> [(Int,Int)] -- cnt,pos
fromRight [] len cnt pos now = [(cnt `div` 2,len-pos-1),(cnt - (cnt `div` 2),len- pos-2)]
fromRight (c:s) len cnt pos now = if c == 'L' then (cnt `div` 2,len-pos-1):(cnt - (cnt `div` 2),len- pos-2):(fromRight s len 0 now (now+1))
  else fromRight s len (cnt+1) pos (now+1)

cnt :: Int -> [(Int,Int)] -> [(Int,Int)] -> [Int]
cnt n as bs = runST $ do
  vec <- VM.replicate n 0
  forM_ as $ \(c,p) -> VM.modify vec (+c) p
  forM_ bs $ \(c,p) -> VM.modify vec (+c) p

  forM [0..n-1] $ \i -> VM.read vec i

main :: IO ()
main = do
  s <- getLine --traceShowM (hs, scanr1 min hs)
  let ls = fromLeft s 0 0 0
      rs = fromRight (reverse s) (length s) 0 0 0
  forM_ (cnt (length s) ls rs) $ \x -> putStr $ (show x) ++ " "
  putStrLn ""


Measured memory_bytes: 9852
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun abs(x: Int, y: Int): Int {
    return when {
        x - y < 0 -> -(x - y)
        else -> x - y
    }
}

fun func() {
    val (x, a, b) = listOfInt()
    println(when{
        abs(x, a) < abs(x, b) -> "A"
        else -> "B"
    })
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 38124
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int bit[100001], n0;
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=(i&(-i));
	}
	return s;
}
void add(int i, int x){
	while(i<=n0){
		bit[i]+=x;
		i+=(i&(-i));
	}
}
int main()
{
	int n;
  cin>>n;
  ll s[100001]; s[0]=0;
  ll ss[100001]; ss[0]=0;
  for(int i=1; i<=n; i++){
    ll p; cin>>p;
    s[i]=s[i-1]+p;
    ss[i]=s[i];
  }
  sort(ss+1, ss+n);
  ll l[100001];
  for(int i=1; i<=n; i++){
    cin>>l[i];
    if(ss[i]-ss[i-1]<l[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  map<ll, int> mp;
  for(int i=1; i<n; i++){
    mp[s[i]]=0;
  }
  for(auto& p:mp){
    n0++;
    p.second=n0;
  }
  ll ans=0;
  for(int i=1; i<n; i++){
    int t=mp[s[i]];
    add(t, 1);
    ans+=((ll)(i-sum(t)));
  }
  cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 12084
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    var ans = 0
    for (i in 0 until 1000) {
        val pin = i.toString().padStart(3, '0')
        var j = 0
        for (c in s) {
            if (j < 3 && c == pin[j]) {
                j++
            }
        }
        if (j == 3) {
            ans++
        }
    }
    println(ans)
}


Measured memory_bytes: 34660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}


ll n;
ll a[maxs];
pair<ll,ll> b[maxs];
ll dp[2005][2005];

void solve(){    
    cin >> n;
    for(ll i=1;i<=n;i++){
        cin >> a[i];
        b[i] = {a[i],i};
    } 
    sort(b+1,b+n+1,greater<pair<ll,ll>>());

    for(ll i=1;i<=n;i++){
        for(ll j=0;j<i;j++){
            ll L = j;
            ll R = i - j - 1;
            dp[L+1][R] = max(dp[L+1][R] , dp[L][R] + abs(L+1 - b[i].ss)*b[i].ff);
            R = j;
            L = i-j-1;
            dp[L][R+1] = max(dp[L][R+1] , dp[L][R] + abs(n-R - b[i].ss)*b[i].ff);
        }
    }

    ll ans=0;
    for(ll i=0;i<=n;i++){
        ans = max(ans,dp[i][n-i]);
    }

    cout << ans << endl;
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){  
        solve();
    }
    return 0;
}

Measured memory_bytes: 26380
//Bismillahir Rahman-ir Rahim
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000002
#define PI acos(-1)
#define debug(x) cout << '>' << #x << " : " << x << endl;
//#define m (pow(10, 9)+7)
typedef unsigned long long ull;
typedef long long ll;


int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cout << fixed << setprecision(12);

    double n;
    cin >> n;

    cout << (n/3)*(n/3)*(n/3) << endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int input;
    int hour;
    int min;
    int sec;
    
    cin >> input;
    
    hour = input / 3600;
    min = (input - (hour * 3600)) / 60;
    sec = input - (hour *3600) - (min *60);
    
    cout << hour << ":" << min << ":" << sec << endl;
    
    return 0;
}


Measured memory_bytes: 3116
import bisect
N = int(input())
*A, = map(int,input().split())
B = {}
for a in A:B[a] = B.get(a,0) + 1
B = sorted(map(list,B.items()))
bl = bisect.bisect_left

ans = 0
while B:
    b,n = B.pop()
    c = (1<<(len(bin(b))-2)) - b
    if c==b :
        ans += n//2
        continue
    i = bl(B,[c,0])
    if i>=len(B): continue
    if B[i][0] == c:
        m = min(n,B[i][1])
        ans += m
        B[i][1] -= m
print(ans)

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

int main(){
  string s;
  cin>>s;
  for(int i=s.size()-2;i>0;i-=2){
    if(s.substr(0,i/2)==s.substr(i/2,i/2)){
      cout<<i<<endl;
      return 0;
    }
  }
}
  


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        if (a.equals("H")) {
            System.out.println(b);
        } else if (a.equals("D")) {
            System.out.println(b.equals("D") ? "H" : "D");
        }
    }
}


Measured memory_bytes: 20820
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 21;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

int v[maxN], c[maxN], a[(1 << maxN)];
int mx = 0;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	for (int i = 0; i < n; i++){
		cin >> c[i];
	}
	for (int i = 1; i < (1 << n); i++){
		int ind = 31 - __builtin_clz(i);
		a[i] = a[i ^ (1 << ind)] - c[ind] + v[ind];
		mx = max(mx, a[i]);
	}
	cout << mx << endl;
	return 0;
}



Measured memory_bytes: 6400
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int main (int argc, char* argv[]) {
	int n;
	cin >> n;
	priority_queue<double, vector<double>, greater<double>> q;
	for (int i = 0; i < n; i++) {
		double num;
		cin >> num;
		q.push(num);
	}

	while (q.size() > 1) {
		auto next_one = q.top();
		q.pop();
		auto next_two = q.top();
		q.pop();
		q.push((next_one + next_two) / 2.0);
	}

	cout << setprecision(20) << q.top() << endl;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d ;

  if (abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))
    cout << "Yes" << endl;
  else
    cout << "No"  << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long double DB;typedef long long LL;

LL n,ans;

inline LL Mul(LL x,LL y,LL MOD) {return (x*y+MOD-(LL)((DB)x/MOD*y)*MOD)%MOD;}
LL exgcd(LL a,LL b,LL &x,LL &y){
	if (!b) {x=1;y=0;return a;}
	LL r=exgcd(b,a%b,y,x);y-=a/b*x;return r;
}
LL Solve(LL A,LL B,LL C){
	LL x,y,r=exgcd(A,B,x,y);if (C%r) return 1e18;
	LL T=B/r;x=Mul((C/r)%T,x%T,T);
	if ((DB)A*x>1e18) return 1e18;return A*x;
}
int main(){
	scanf("%lld",&n);n<<=1;ans=n-1;
	for (int S=sqrt(n),i=2;i<=S;i++)
		if (!(n%i)) ans=min(ans,Solve(n/i,i,i-1)),ans=min(ans,Solve(i,n/i,n/i-1));
	printf("%lld\n",ans);return 0;
}

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

#define FOR(i, a, b) for(int i=a; i<b; i++)
#define FOR1(i, a, b, flag) for(int i=a; i<b && flag; i++)
typedef long long ll;

int c=1000000007;

int main(){
    ios_base::sync_with_stdio(false);
    string k;
    getline(cin, k);
    int d;
    cin>>d;
    int n=k.size();
    int dp[n+1][d];
    memset(dp, 0, sizeof(int)*(n+1)*d);
    dp[n][0]=1;
    FOR(i1, 0, 10){
        dp[n-1][i1%d]++;
    }
    
    for(int i1=n-2; i1>0; i1--){
        FOR(i2, 0, 10){
            FOR(i3, 0, d){
                dp[i1][(i2+i3)%d]+=dp[i1+1][i3];
                dp[i1][(i2+i3)%d]%=c;
            }
        }
    }
    // FOR(i1, 0, )
    int tillnow=0;
    int ans=0;
    for(int i1=0; i1<n; i1++){
        int dig=k[i1]-'0';
        FOR(i2, 0, dig){
            ans=(ans+dp[i1+1][(d-((tillnow+i2)%d))%d])%c;
        }
        tillnow=(tillnow+dig)%d;
    }
    if(tillnow==0){
        ans++;
        ans%=c;
    }
    
    cout<<((ans>=1)?ans-1:c+ans-1)<<endl;
    return 0;
}

Measured memory_bytes: 4224
import java.util.*;

class Main {
		public static void main (String[]agrs){
			int s;
			int m;
			int h;
			Scanner sc = new Scanner(System.in);
			 s =sc.nextInt();
			 m =s/60;
			 h=m/60;
			 s=s%60;
			 m=m%60;
			 h=h%60;
			 System.out.println(h+":"+m+":"+s);
			 
			
		
	 
	}

}

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

int Max(int a,int b,int c){
    if(a < b){
        if(b < c)return c;
        return b;
    }else{
        if(a < c)return c;
        return a;
    }
}
int Min(int a,int b,int c){
    if(a > b){
        if(b > c)return c;
        return b;
    }else{
        if(a > c)return c;
        return a;
    }
}

int main(){
    // 整数の入力
    int x,y,z;
    cin >> x >> y >> z;
    // 出力
    cout << Max(x,y,z) - Min(x,y,z) << endl;
    return 0;
}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == b)
    {
        if (b == c) cout << "No\n";
        else cout << "Yes\n";
    }
    else if (b == c)
    {
        cout << "Yes\n";
    }
    else if (a == c) cout << "Yes\n";
    else cout << "No\n";
}



Measured memory_bytes: 256
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

int sum(int x) {
  int s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}

bool solve() {
  int n;
  if (scanf("%d", &n) != 1) { return false; }

  int res = n + 1000;
  for (int a = 1; a < n; ++a) {
    res = min(res, sum(a) + sum(n - a));
  }
  printf("%d\n", res);
  return true;
}

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

Measured memory_bytes: 256
N,M=map(int,input().split())
sum=0
A=[[int(i) for i in input().split()]for j in range(N)]
A.sort()
i=0
while True:
  if A[i][1]>=M:
    sum+=A[i][0]*M
    break
  else:
    sum+=A[i][0]*A[i][1]
  M-=A[i][1]
  i+=1
print(sum)

Measured memory_bytes: 21608
from fractions import gcd
from functools import reduce
#from collections import deque
# from math import factorial
# import collections
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
n = input()
#n, m = list(map(int, input().split()))
a = list(map(int, input().split()))


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


b = lcm_list(a)-1
f = 0
for i in a:
    f += b % i

print(f)


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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> pi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){
    os << v.first <<" "<<v.second<<endl;
    return os;
}

const int maxn = 1e5+5;
const int mod = 1e9+7;
int A[maxn];
LL dp[maxn];
int N,M;

int main()
{
    cin >> N >> M;
    _rep(i,0,N) A[i] = 1;
    dp[0] = 1;
    _for(i,0,M){
        int index;
        cin >> index;
        A[index] = 0;
    }
    _rep(i,1,N){
        if(A[i]){
            if(i == 1){
                dp[i] = dp[0];
            }
            else{
                dp[i] = (dp[i-1] + dp[i-2])%mod;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 1408
n=int(input())
s=input()
l=[[]for i in range(11)]
for i in range(n):
    d=int(s[i])
    l[d].append(i)
ans=0
le=[len(f) for f in l]
from bisect import bisect_left as bl,bisect_right as br
for i in range(0,1000):
    ss=str(i).zfill(3)

    now=-1
    for x in ss:
        c=br(l[int(x)],now)
        if c==le[int(x)]:break
        now=l[int(x)][c]
    else:

        ans+=1
print(ans)

Measured memory_bytes: 4456
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<vector<int>> graph(100010, vector<int>());
int n, k, ans;

int dfs(int n) {
	int res = -1;
	for (int i : graph[n]) {
		int d = dfs(i);
		if (d < k - 1 || d == k - 1 && n == 0) chmax(res, d);
		else ans++;
	}
	res++;
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	cin >> n >> k;
	rep(i, n) {
		int a;
		cin >> a;
		a--;
		if (i == 0 && a != 0) ans++;
		if (i == 0) continue;
		graph[a].pb(i);
	}
	dfs(0);
	cout << ans << endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
constexpr lint MOD = 1000000007;
int N, M;
string S;
vector<int> l, r;
vector<int> con;

vector<int> ac0, ac1;

int main()
{
    cin >> N >> M >> S;
    l.resize(M);
    r.resize(M);
    con.resize(N);
    for (int i=0; i<N; i++) con[i] = i;

    for (int i=0; i<M; i++)
    {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
        for (int j=l[i]; j<r[i]; j++) con[j] = max(con[j], r[i]);
    }
    ac0.resize(N);
    ac1.resize(N);
    {
        int n0 = 0, n1 = 0;    
        for (int i=0; i<N; i++)
        {
            if (S[i] == '0') n0++;
            else n1++;
            ac0[i] = n0;
            ac1[i] = n1;
        }
    }

    vector<vector<lint> > dp(N, vector<lint>(N+1, 0)); // dp[何文字目まで][1の個数]
    dp[0][0] = ac0[con[0]] > 0 ? 1 : 0;
    dp[0][1] = ac1[con[0]] > 0 ? 1 : 0;
    for (int i=1; i<N; i++)
    {
        for (int j=0; j <= i + 1; j++)
        {
            int n0 = i - j + 1;
            int n1 = j;
            if (n0 <= ac0[con[i]] && n1 <= ac1[con[i]])
            {
                dp[i][j] = dp[i-1][j];
                if (j > 0) dp[i][j] += dp[i-1][j-1];
                dp[i][j] %= MOD;
                // cout << i << " " << j << " " << ac0[i] << " " << ac1[i] << endl;
                // cout << "dp[" << i << "][" << j << "]= " << dp[i][j] << endl;
            }
        }
    }
    cout << accumulate(dp[N-1].begin(), dp[N-1].end(), 0LL) << endl;
}


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

int main()
{
  int i,N,K,ax[1000],ay[1000],m=0;

  scanf("%d",&N);
  scanf("%d",&K);

  for(i = 0;i < K;i++){
    scanf("%d %d",&ax[i],&ay[i]);
  }

  for(i = 0;i < K;i++){
    if(ax[i]-1 > ay[i]-1){
      m = ay[i]-1;
    } else {
      m = ax[i]-1;
    }
    if(m > N - ax[i]){
      m = N - ax[i];
    }
    if(m > N - ay[i]){
      m = N - ay[i];
    }

    printf("%d\n",m % 3 +1 );
  }

  return 0;
}

Measured memory_bytes: 1784
from sys import stdin

readline = stdin.readline


def read():
    return map(int, readline().split())


def main():
    input()
    *A, = read()
    *B, = read()
    pre = A[0]
    ans = 0
    for a, b in zip(A[1:], B):
        tmp1 = pre if pre < b else b
        b -= tmp1
        tmp2 = a if a < b else b
        ans += tmp1 + tmp2
        pre = a - tmp2
    print(ans)
    return


main()


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int mod = 924844033;

int f[2010][2010][2], g[2010], t[2010], ans;

int main()
{
	int n, k;
	gii(n, k);
	f[0][0][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
		{
			f[i][j][0] = (f[i][j][0] + f[i - 1][j][0]) % mod;
			f[i][j][0] = (f[i][j][0] + f[i - 1][j][1]) % mod;
			if (j) f[i][j][1] = f[i - 1][j - 1][0];
		}
	}
	g[0] = 1;
	for (int i = 1; i <= k; ++i)
	{
		int len = (n - i) / k;
		for (int i = 0; i <= n; ++i)
			t[i] = g[i], g[i] = 0;
		for (int j = 0; j <= len; ++j)
			for (int l = 0; l <= n - j; ++l)
				g[j + l] = (g[j + l] + 1LL * t[l] * (f[len][j][0] + f[len][j][1])) % mod;
		for (int i = 0; i <= n; ++i)
			t[i] = g[i], g[i] = 0;
		for (int j = 0; j <= len; ++j)
			for (int l = 0; l <= n - j; ++l)
				g[j + l] = (g[j + l] + 1LL * t[l] * (f[len][j][0] + f[len][j][1])) % mod;
	}
	for (int i = n, fac = 1, j = (n & 1) ^ 1; ~i; --i, fac = 1LL * fac * (n - i) % mod, j ^= 1)
	{
		if (j) ans = (ans + 1LL * g[i] * fac) % mod;
		else ans = (ans - 1LL * g[i] * fac) % mod;
	}
	if (ans < 0) ans += mod;
	printf("%d\n", ans);
	return 0;
}



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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int e5 = (int) 1e5 + 5;
//const int MOD = (int) 1e9 + 7;
const int MOD = (int) 998244353;
//int MOD = 998244353;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod; return res;
}

struct Mint
{
    int x;
    Mint() {x = 0;}
    Mint(int _x): x(_x) {if(x < 0 || x >= MOD) x = (x % MOD + MOD) % MOD;}
    Mint(LL _x): x(_x) {if(x < 0 || x >= MOD) x = (x % MOD + MOD) % MOD;}
    Mint operator - () const{
        return Mint(MOD - x);
    }
    Mint operator + (const Mint &rhs) const{
        return Mint(x + rhs.x >= MOD ? x + rhs.x - MOD : x + rhs.x);
    }
    Mint operator - (const Mint &rhs) const{
        return Mint(x - rhs.x < 0 ? x - rhs.x + MOD : x - rhs.x);
    }
    Mint operator * (const Mint &rhs) const{
        return Mint((LL)x * rhs.x % MOD);
    }
    Mint operator / (const Mint &rhs) const{
        return Mint(x * fp(rhs.x, -1) % MOD);
    }
    Mint& operator += (const Mint &rhs) {
        x += rhs.x; if(x >= MOD) x -= MOD; return *this;
    }
    Mint& operator *= (const Mint &rhs) {
        x = ((LL)x * rhs.x) % MOD; return *this;
    }
    bool operator == (const Mint &rhs) const{
        return x == rhs.x;
    }
    bool operator != (const Mint &rhs) const{
        return x != rhs.x;
    }
    friend ostream& operator << (ostream &out, const Mint &rhs){
        return out << rhs.x;
    }
    friend istream& operator >> (istream &in, Mint &rhs){
        return in >> rhs.x;
    }
};


const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;


void work()
{
    int n, m;
    cin >>n >>m;
    for(int i = 0; i < m; i++)
    {
        int x; read(x);
        n -= x;
    }

    Max(n, -1);
    cout <<n <<endl;
}

int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main() {
    ll k;
    string s;
    cin>>k>>s;
    if(s.size()<=k){
        cout<<s<<endl;
    }
else{
    rep(i,k){
        cout<<s[i];
    }
    cout<<"..."<<endl;
}
return 0;
}
    



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using namespace boost::multiprecision;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
    int cnt[100000];
signed main(){
    int n,q;
    char s[100000];
    scanf("%d%d",&n,&q);
    scanf("%s",s);
    rep(i,n-1){
        if(s[i]=='A'&&s[i+1]=='C')cnt[i+1]++;
        cnt[i+1]+=cnt[i];
    }
    rep(i,q){
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",cnt[r-1]-cnt[l-1]);
    }
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a==0&&b!=100) cout<<b;
	else if(a==0&&b==100) cout<<b+1;
	if(a==1&&b!=100) cout<<b*100;
	else if(a==1&&b==100) cout<<b*101;
	if(a==2&&b!=100) cout<<b*10000;
	else if(a==2&&b==100) cout<<b*10100;
}

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

int main(){
  int n;
  double x[10],sum=0;
  string u[10];
  cin >> n;
  for(int i=0; i < n;i++){
    cin>>x[i];
    cin>>u[i];
    if(u[i] == "BTC")sum += x[i]*380000.0;
    else sum +=x[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXS 2097162
#define MAXM 30
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dp[2][MAXM][MAXS],ans;
int nxt[MAXS][MAXM],mp[MAXM][MAXM];
int n,m,p;
int main(){
	SF("%d%d%d",&n,&m,&p);
	n--;
	for(int i=0;i<(1<<n);i++){
		int t=-1;
		for(int j=n-1;j>=0;j--){
			if((i&(1<<j)))
				t=j;
			nxt[i][j]=t;
		}
	}
	for(int i=1;i<=m;i++)
		for(int j=0;j<n;j++)
			mp[i][j]=-1;
	int x,y,z;
	for(int i=1;i<=p;i++){
		SF("%d%d%d",&x,&y,&z);
		mp[x][y-1]=z;	
	}
	dp[0][n][0]=1;
	int now=1;
	for(int i=1;i<=m;i++){
		for(int mask=0;mask<(1<<n);mask++)
			dp[now][0][mask]=dp[now^1][n][mask];
		for(int j=0;j<=n;j++)
			for(int mask=0;mask<(1<<n);mask++)
				dp[now^1][j][mask]=0;
		for(int j=0;j<n;j++)
			for(int mask=0;mask<(1<<n);mask++)
				if(dp[now][j][mask]){
					for(int k=0;k<=1;k++){
						if(mp[i][j]!=-1&&mp[i][j]!=k)
							continue;
						int t=min((mask&(1<<j)),1);
						if(k==0&&t==1)
							continue;
						if(k==t)
							dp[now][j+1][mask]=(dp[now][j+1][mask]+dp[now][j][mask])%MOD;
						else{
							int r=nxt[mask][j];
							if(r==-1)
								dp[now][j+1][mask+(1<<j)]=(dp[now][j+1][mask+(1<<j)]+dp[now][j][mask])%MOD;
							else
								dp[now][j+1][mask+(1<<j)-(1<<r)]=(dp[now][j+1][mask+(1<<j)-(1<<r)]+dp[now][j][mask])%MOD;
						}
					}
				}
		now^=1;	
	}
	for(int mask=0;mask<(1<<n);mask++)
		ans=(ans+dp[now^1][n][mask])%MOD;
	PF("%d",ans);
}

Measured memory_bytes: 227584
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"\Case #"<<x<<"\:"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}


void virus(){
        ll a,b,c,d,e;
        cin>>a>>b>>c>>d>>e;
        if(a == 0) cout<<"1";
        else if(b==0) cout<<"2";
        else if(c==0) cout<<"3";
        else if(d ==0 ) cout<<"4";
        else cout<<"5";
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define N 200100
#define INF 0x3f3f3f3f

int n,c0,q,x,y;
int b[N],cost[N],d[N<<2],dp[N];
vector<int> v[N];

int query(int o,int L,int R,int l,int r) {
	if (l<=L && r>=R) return d[o];
	int mid=(L+R)>>1,ret=INF;
	if (l<=mid) ret=min(ret,query(o<<1,L,mid,l,r));
	if (r>mid) ret=min(ret,query(o<<1|1,mid+1,R,l,r));
	return ret;
}

void upd(int o,int l,int r,int x,int y) {
	if (l==r) {d[o]=min(d[o],y); return;}
	int mid=(l+r)>>1;
	if (x<=mid) upd(o<<1,l,mid,x,y);
	else upd(o<<1|1,mid+1,r,x,y);
	d[o]=min(d[o<<1],d[o<<1|1]);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		if (!b[i]) c0++;
		cost[i]=b[i] ? 1 : -1;
	}
	scanf("%d",&q);
	for (int i=1;i<=q;i++)
	{
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
	}
	memset(d,0x3f,sizeof(d));
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<(int)v[i].size();j++)
		{
			int x=v[i][j];
			int t=min(dp[i-1],query(1,1,n,max(i-1,1),x));
			if (t<dp[x]) {
				dp[x]=t;
				upd(1,1,n,x,t);
			}
		}
		dp[i]=min(dp[i],dp[i-1]+cost[i]);
	}
	printf("%d\n",dp[n]+c0);
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

const int LIM = 61;

vector<int> g(LIM, -1);

void add(int x) {
    for (int i = LIM - 1; i >= 0; i--) {
        if ((x >> i) & 1) {
            if (g[i] == -1) {
                g[i] = x;
                break;
            } else {
                x ^= g[i];
            }
        }
    } 
}

int solve(int x) {
    for (int i = LIM - 1; i >= 0; i--) {
        if ((x >> i) & 1) {
            if (g[i] == -1) {
                return 0;
            } else {
                x ^= g[i];
            }
        }
    } 
    return 1;
}

int can(int need, vector<int> care, vector<int> a) {
    int sm = 0;
    for (auto t : care) {
        sm |= (1LL << t);
    }
    fill(g.begin(), g.end(), -1);
    for (auto &t : a) {
        t &= sm;
        add(t);
    }
    return solve(need);
}

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

    //x + x ^ s
    //s - hv does-not-mattter
    //s -nhv - better1
    int n;
    cin >> n;
    int s = 0;
    vector<int> a;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        add(x);
        s ^= x;
        a.push_back(x);
    }
    int ans = 0;
    int alr = 0;
    vector<int> care;
    for (int i = LIM - 1; i >= 0; i--) {
        if ((s >> i) & 1) {
            ans += (1LL << i);
        } else {
            care.push_back(i);
            if (can(alr | (1LL << i), care, a)) {
                ans += 2 * (1LL << i);
                alr |= (1LL << i);
            } else {
                care.pop_back();
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1908
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define S_MAX 1000
#define N_MAX 2000
#define M_MAX 100000
#define INF 2000000000
#define MOD 1000000007
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;
typedef   signed long long dll;

typedef struct {
	int a;
	int b;
	int c;
} moneydata;

int n, m;
int h, w;
int i, j;
int k;

ull a[N_MAX];
ull dp[N_MAX][N_MAX]; // dp[i][j] := a[i] kara a[i + 2j + b] madede JOIkun ga IOIchan wo ryonareru MAX

ull max(ull a, ull b){
	return (a > b) ? a : b;
}

ull min(ull a, ull b){
	return (a < b) ? a : b;
}

void solve(){
	const int nbool = (n & 1) ^ 1;
	int rangelen;
	ull result = 0;

	switch (nbool) {
	case 0:
		for (i = 0; i < n; i++) {
			dp[i][0] = a[i];
		}
		break;
	case 1:
		for (i = 0; i < n; i++) {
			dp[i][0] = max(a[i], a[(i + 1) % n]);
		}
		break;
	}

	for (rangelen = 1; (rangelen << 1) + nbool < n; rangelen++) {
		for (i = 0; i < n; i++) {
			ull lc, rc;
			if (a[(i + (rangelen << 1) + nbool) % n] > a[(i + 1) % n]) {
				lc = dp[(i + 1) % n][rangelen - 1];
			} else {
				lc = dp[(i + 2) % n][rangelen - 1];
			}
			if (a[(i + (rangelen << 1) + nbool - 1) % n] > a[i]) {
				rc = dp[i][rangelen - 1];
			} else {
				rc = dp[(i + 1) % n][rangelen - 1];
			}
			dp[i][rangelen] = max(
				a[i] + lc, a[(i + (rangelen << 1) + nbool) % n] + rc);
		}
	}

	// for (i = 0; i < n; i++) {
	// 	printf("[%d] ", i);
	// 	for (rangelen = 0; (rangelen << 1) + nbool < n; rangelen++) {
	// 		printf("%d ", dp[i][rangelen]);
	// 	}
	// 	putchar('\n');
	// }

	for (i = 0; i < n; i++) {
		result = max(result, dp[i][((n + 1) >> 1) - 1]);
	}

	printf("%llu\n", result);

	return;
}

int main (void) {
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%llu", &a[i]);
	
	solve();
	
	return 0;
}

Measured memory_bytes: 31228
def examA():
    S = SI(); N = len(S)
    prev = S[0]; cur = ""
    k = 0; ans = 1
    while(k<N-1):
        k +=1
        cur += S[k]
        if cur==prev:
            continue
        prev = cur
        cur = ""
        ans +=1
    print(ans)
    return

def examB():
    N = I()
    S = SI()
    return

def examC():
    N = I()
    A = LI()
    B = LI()
    ans = 0
    que = []
    for i in range(N):
        heappush(que,(-B[i],i))
    flag = True
    while(que):
        b,i = heappop(que)
        b *=(-1)
        if b == A[i]:
            continue
        a, c = B[(i - 1) % N], B[(i + 1) % N]
        if b - A[i] < a + c:
            flag = False
            break
        r = (b - A[i]) // (a + c)
        b -= (a + c) * r
        B[i] = b
        ans += r
        if b != A[i]:
            heapq.heappush(que, (-b, i))
#    print(que)
#    print(K)
    if flag:
        print(ans)
    else:
        print(-1)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18

if __name__ == '__main__':
    examC()


Measured memory_bytes: 121804
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

int N;
int a[101010];
vector<int> G[101010];
bool make[101010];
vector<pair<int, int>> ds[101010];

map<pair<int, int>, int> dp;

//人vを根とするトーナメントの最小の深さ
int f(int v, int i) {
  if (dp.find(P(v, i)) != dp.end()) return dp[P(v, i)]; 
  if (!make[v]) {
    // vector<pair<int, int>> ds;
    for (int nv : G[v]) {
      ds[v].push_back(P(f(nv, 0), nv));
    }
    sort(ds[v].rbegin(), ds[v].rend());
    make[v] = true;
  }
  // if (ds.size() <= i) return 0; 
  if (ds[v].size() <= i) {
    //printf("f(%lld, %lld) = 0\n", v, i);
    return dp[P(v, i)] = 0;
  }
  //printf("f(%lld, %lld) = %lld\n", v, i, max(f(v, i + 1) + 1, f(ds[i].second, 0LL) + 1));
  return dp[P(v, i)] = max(f(v, i + 1) + 1, ds[v][i].first + 1);
}
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> N;
  for (int i=2; i<=N; i++) {
    cin >> a[i];
    G[a[i]].push_back(i);
  }

  cout << f(1, 0) << endl;
}

Measured memory_bytes: 37120
n = gets.chomp.to_i

def koch(depth, ary_p1, ary_p2)
    if depth == 0 then
         return 0
    end
    p1 = ary_p1
    p2 = ary_p2
    # 線分を 3等分する 2点 s, t を算出する。
    s = [(ary_p1[0] * 2 + ary_p2[0] * 1) / 3.0, (ary_p1[1] * 2 + ary_p2[1] * 1) / 3.0]
    t = [(ary_p1[0] * 1 + ary_p2[0] * 2) / 3.0, (ary_p1[1] * 1 + ary_p2[1] * 2) / 3.0]
    # 張り出す三角形の頂点 u を算出する。
    u = []
    u[0] = (t[0] - s[0]) * Math.cos(60 * Math::PI / 180) - (t[1] - s[1]) * Math.sin(60 * Math::PI / 180) + s[0]
    u[1] = (t[0] - s[0]) * Math.sin(60 * Math::PI / 180) + (t[1] - s[1]) * Math.cos(60 * Math::PI / 180) + s[1]
    
    koch(depth - 1, p1, s)
    puts s.join(' ')
    koch(depth - 1, s, u)
    puts u.join(' ')
    koch(depth - 1, u, t)
    puts t.join(' ')
    koch(depth - 1, t, p2)
end

p1 = [0, 0]
p2 = [100, 0]
puts p1.join(' ')
koch(n, p1, p2)
puts p2.join(' ')



Measured memory_bytes: 7064
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

int main(void){
  int k, x;
  cin >> k >> x;

  FOR(i, x-k+1, x+k){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    String ans = str.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","");
    if(ans.length() == 0){
      System.out.println("YES");
    }
    else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 28844
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int mx, nl, ns;
vector<int> res;
bool vis[11][11];
int d[11][11];

void dfs(int p, int cst, vector<int> vec)
{
  bool f = true;

  for(int i = 1; i <= ns; ++i)
    if(vis[p][i]){
      vis[p][i] = vis[i][p] = false;
      vector<int> v = vec;
      v.push_back(i);
      dfs(i, cst+d[p][i], v);
      vis[p][i] = vis[i][p] = true;
      f = false;
    }

  if(f && mx < cst){
    mx = cst;
    res = vec;
  }

  return ;
}

int main()
{
  int s, t, u;

  while(cin>>ns>>nl && nl+ns){
    fill(&vis[0][0], &vis[11][0], false);
    mx = 0;
    while(nl--){
      cin >> s >> t >> u;
      vis[s][t] = vis[t][s] = true;
      d[s][t] = d[t][s] = u;
    }

    for(int i = 1; i <= ns; ++i){
      vector<int> vec;
      vec.push_back(i);
      dfs(i, 0, vec);
    }
    cout << mx << endl << res[0];
    for(int i = 1; i < res.size(); ++i) cout << " " << res[i];
    cout << endl;
  }

  return 0;
}

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

int main(){
    int n, k;
    string s;
    cin >> n >> s >> k;
    char a = s[k-1];
    for(int i=0; i<s.size(); i++){
        if(s[i] != a) cout << "*";
        else cout << a;
    }
    cout << endl;
    return 0;
}

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

int main(){

int n;
cin >> n;
ll ans=0;
vector<int> a(200100);
rep(i,n) cin >> a[i];
rep(i,n-1) if(a[i]>a[i+1]) {
    ans += a[i] - a[i+1];
    a[i+1] = a[i];
}
cout << ans << endl;

}

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(a: int, b: int):
    a_str = str(a)
    b_str = str(b)
    string = a_str + b_str
    integer = int(string)
    if math.sqrt(integer)%1==0:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064