akhauriyash/Code-Regression huggingface dataset:
l, r = map(int, input().split())

if 2018 <= r-l:
    print(0)
else:
    min_val = 2019
    for i in range(l, r):
        for j in range(i+1, r+1):
            min_val = min(min_val, (i*j)%2019)
            if min_val == 0:
                print(0)
                exit()
    print(min_val)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  int ans = 0;
  for (auto i : m) {
    if (i.first == i.second) continue;
    if (i.first < i.second) {
      ans += i.second - i.first;
    } else {
      ans += i.second;
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 4736
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

int main()
{
    ll n;
    cin >> n;
    ll p;
    ll p_max = 0;
    ll total = 0;
    for (ll i = 0; i < n; i++)
    {
        cin >> p;
        total += p;
        if (p > p_max)
        {
            p_max = p;
        }
    }
    total -= p_max / 2;
    cout << total << endl;
    return 0;
}



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

if n == 0:
    print(0)
    exit()

s = ""

while True:
    if n == 0:
        break
    if n%2 == 0:
        s += "0"
        n = n//(-2)
    else:
        s += "1"
        n = (n-1)//(-2)

print(s[::-1])

Measured memory_bytes: 3060
def comb(p,q,A,fact = None,factinv = None): #pCq modA
  if (q < 0) or (p < q):
    return 0
  q = min(q, p - q)
  return fact[p] * factinv[q] * factinv[p-q] % A
def main():
  mod = 10 ** 9 + 7
  n, k = map(int, input().split())
  
  fact = [1] #n!をmodで割ったあまり、0! = 1
  factinv = [1,1] #(n!)^(-1)をmodで割ったあまり
  inv = [0,1] #n^-1をmodで割ったあまり
  
  for a in range(2, n + 1):
    inv.append((-inv[mod % a] * (mod // a)) % mod)
  for i in range(1, n + 1):
    fact.append((fact[-1] * i) % mod)
  for j in range(2, n + 1):
    factinv.append((factinv[-1] * inv[j]) % mod)
  ans = 0
  for i in range(min(n,k+1)): #i:空の部屋の数
    ans = (ans + comb(n,i,mod,fact,factinv)*comb(n-1,i,mod,fact,factinv)) % mod
  print(ans)
main()

Measured memory_bytes: 26796
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,Ma,Mb = map(int,input().split())
    abc = [list(map(int,input().split())) for i in range(N)]

    INF = N * 100 + 1

    dp = [[[INF for cb in range(411)] for ca in range(411)] for i in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        for ca in range(N*10):
            for cb in range(N*10):
                if dp[i][ca][cb] == INF:
                    continue
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb])
                d = abc[i]
                dp[i+1][ca+d[0]][cb+d[1]] = min(dp[i+1][ca+d[0]][cb+d[1]],dp[i][ca][cb]+d[2])

    res = INF

    for ca in range(1,401):
        for cb in range(1,401):
            if ca * Mb == cb * Ma:
                res = min(res,dp[N][ca][cb])

    if res == INF:
        res = -1

    print(res)



main()


Measured memory_bytes: 68968
#include <iostream>
 
using namespace std;
 
int main() {
    string s;
    cin>>s;
    int ans=0; int mans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='R')ans++;
        else ans=0;
        
        mans=max(ans,mans);
    }
    cout<<mans<<endl;
    return 0;
}

Measured memory_bytes: 3588
#pragma GCC optimize("O3")
 #pragma GCC optimize("unroll-loops")
 #pragma GCC optimize("fast-math")
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
int n;
bool check(int x, vector<int>&a) {
    vector<int>b(a.size());
    for (int i = 0; i < a.size(); ++i)
        b[i] = a[i] >= x;
    for (int i = 0; i + 1 < n; ++i) {
        if ((b[n + i - 1] ^ b[n + i]) == 0)
            return b[n + i];
        if ((b[n - i - 1] ^ b[n - i - 2]) == 0)
            return b[n - i - 1];
    }
    return b[0];
}


signed main() {
    accell();
    cin >> n;
    vector<int>a(2 * n - 1);
    for (int i = 0; i < 2 * n - 1; ++i)
        cin >> a[i];
    int l = 0;
    int r = 2 * n;
    while (r - l > 1) {
        int m = l + r >> 1;
        // cout << l << ' ' << r << endl;
        if (!check(m, a))
            r = m;
        else
            l = m;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
    string S, T;
    cin >> S >> T;
    S = " " + S;
    T = " " + T;

    vector<string> now(3010, ""), before(3010, "");

    rep1(i, S.length()-1){
        rep1(j, T.length()-1){
            if(S[i] == T[j]){
                now[j] = before[j-1] + S[i];
            } else {
                int L1 = before[j].length();
                int L2 = now[j-1].length();

                if(L1 < L2) now[j] = now[j-1];
                else now[j] = before[j];
            }
        }
        
        before = now;
    }

    cout << before[T.length()-1] << endl;
}

Measured memory_bytes: 16908
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $kumi = [];
  for($i=0; $i<$n; $i++){
    list($s) = explode(" ", trim(fgets(STDIN)));
    $s = str_split($s);
    sort($s);
    $s = implode("", $s);
    if(!isset($kumi[$s])){
      $kumi[$s] = 0;
    }
    $kumi[$s]++;
  }

  $ans = 0;
  foreach($kumi as $key => $value){
    $ans += ($value * ($value-1) / 2);
  }
echo $ans;

Measured memory_bytes: 13048
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=3e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);
const lf EPS = 1e-9;


lf dp[MAXn][MAXn][MAXn];

ll n;
lf d(ll a, ll b, ll c)
{
    if(a == 0 && b == 0 && c == 0)return 0;
    else if(dp[a][b][c] >= -EPS)return dp[a][b][c];
    lf tt = 0;
    if(a)tt += lf(a) / lf(n) * d(a-1,b,c);
    if(b)tt += lf(b) / lf(n) * d(a+1,b-1, c);
    if(c)tt += lf(c) / lf(n) * d(a, b+1, c-1);
    tt += 1;
    tt = tt * lf(n) / lf(a+b+c);
    return dp[a][b][c] = tt; 
}

ll ct[4];

int main()
{
    IOS();
    cin>>n;
    REP(i,n)
    {
        ll x;
        cin>>x;
        ct[x]++;
    }
    REP(i,n+1)REP(j,n+1)REP(k,n+1)dp[i][j][k] = -1;
    cout<<fixed<<setprecision(12)<<d(ct[1], ct[2], ct[3])<<endl;;
}


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

const int N = 55;

int pri[55558], pos;
int ans[55555];

void init() {
    for (int i = 2; i <= 55555; ++i) {
        int sqr = (int)sqrt(i + 0.5);
        bool flag = true;
        for (int j = 2; j <= sqr; ++j) {
            if (i % j == 0) {
                flag = false;
                break;
            }
        }
        if (flag) pri[++pos] = i;
    }
}
int main ()
{
    int n;
    cin >> n;
    init();
    int cnt = 0;
    for (int i = 1; i <= pos; ++i) if (pri[i] % 5 == 1) ans[++cnt] = pri[i];
    for (int i = 1; i <= n; ++i) printf(i == 1 ? "%d" : " %d", ans[i]);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N; cin >> N;
    ll ans = LINF;
    for(ll A = 1; A < N; A++){
        ll B = N - A;
        string sA = to_string(A);
        string sB = to_string(B);
        ll sum = 0;
        for(char c:sA) sum += c-'0';
        for(char c:sB) sum += c-'0';
        ans = min(ans,sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1000000007;
const ll INF=1000000000LL;
const int MAX=100001;
const double EPS=1e-10;
struct edge{int to,cost;};
typedef pair<int,int> P;
int main(){
    int n;
    cin>>n;
    int a[110];
    int mi=INF;
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%10){
            mi=min(mi,a[i]);
        }
        sum+=a[i];
    }
    if(mi==INF){
        cout<<0<<endl;
    }else if(sum%10){
        cout<<sum<<endl;
    }else{
        cout<<sum-mi<<endl;
    }
}

Measured memory_bytes: 256
package main

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

const modd int64 = 1000000007

func main() {
	scanInit()

	n := nextInt()
	a := make([]int64, n)
	ru := make([]int64, n+1)

	for i := 0; i < n; i++ {
		a[i] = nextInt64()
	}
	ru[n] = 0
	for i := n - 1; 0 <= i; i-- {
		ru[i] = (a[i] + ru[i+1]) % modd
	}

	var sum int64 = 0
	for i := 0; i < n-1; i++ {
		//fmt.Println("DBG", a[i], ru[i+1], " ->", a[i]*ru[i+1]) //! DBG
		sum += (a[i] * ru[i+1]) % modd
	}
	fmt.Println(sum % modd)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}


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

using namespace std;

const int N = 2e5 + 100;

map <char, int> mp;

int main()
{
	char _s[N];
	scanf("%s", _s);
	string s = _s;
	for (char c : s)
	{
		mp[c]++;
	}
	long long ans = (s.size() * 1ll * (s.size() - 1) >> 1) + 1;
	for (auto it : mp)
	{
		ans -= (it.second * 1ll * (it.second - 1) >> 1);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
  val (A, B, N) = readLongs()
  val n = if (N < B) N else B - 1
  println(A * n / B - A * (n / B))
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

uint64_t gcd(uint64_t a, uint64_t b) {
    uint64_t t;
    if (a < b) {
        t = a;
        a = b;
        b = t;
    }
    while (b > 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

uint64_t lcm(uint64_t a, uint64_t b) {
    return a / gcd(a, b) * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    uint64_t a = 1;
    for (int i = 0; i < N; ++i) {
        uint64_t t;
        cin >> t;
        a = lcm(a, t);
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define fi first
#define se second

ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll gcd(ll a, ll b)
{
	ll temp;
	if(a < b)
	{
		temp = a;
		a = b;
		b = temp;
	}
	while(b)
	{
		temp = b;
		b = a - b;
		a = temp;
	}
	return a;
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

ll mat_power(ll a, ll b, ll c, ll d, ll n, ll z = MOD)
{
	ll a0 = 1, b0 = 0, c0 = 0, d0 = 1;
	while(n)
	{
		if(n&1)
		{
			ll a1 = a0, b1 = b0, c1 = c0, d1 = d0;
			a0 = (a1*a + b1*c)%z;
			b0 = (a1*b + b1*d)%z;
			c0 = (c1*a + d1*c)%z;
			d0 = (c1*b + d1*d)%z;
		}
		ll a1 = a, b1 = b, c1 = c, d1 = d;
		a = (a1*a1 + b1*c1)%z;
		b = (a1*b1 + b1*d1)%z;
		c = (c1*a1 + d1*c1)%z;
		d = (c1*b1 + d1*d1)%z;
		n = n>>1;
	}
	return c0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	// i1(t);
	while(t--)
	{
		int n, k;
		i2(n, k);
		int aray[n];
		for(int i=0;i<n;i++)
			i1(aray[i]);
		sort(aray, aray+n);
		int ans = 0;
		for(int i=0;i<k;i++)
			ans += aray[i];
		o1(ans);
	}
	return 0;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,int(n)+1)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RFOR(i,1,int(n)+1)
#define ALL(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void pvp(T a, T b) { for (T i = a; i != b; ++i) cout << "(" << i->first << ", " << i->second << ") "; cout << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int in() { int x; scanf("%d", &x); return x; }

using ll = long long;
#define int ll

//**********

int a, b, c;
int ans = 0;

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> a >> b >> c;
    
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);

    int sa = a%2;
    int sb = b%2;
    int sc = c%2;
    
    if((sa+sb+sc)%3==0) ans = ((c-b)+(c-a))/2;
    else if(sa==sb) ans = 1 + ((c-b-1)+(c-a-1))/2;
    else if(sa==sc) ans = 1 + ((c-b+1)+(c-a))/2;
    else if(sb==sc) ans = 1 + ((c-b)+(c-a+1))/2;
    
    printf("%lld\n",ans);;
    return 0;
    
}





Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int N;
  int i,flag=0;
    
  do{
    scanf("%d",&N);
  } while(N<100 || N>999);
  
  for(i=1;i<=3;i++){
    if(N % 10 == 7)
      flag = 1;
    N /= 10;
  }
  if(flag == 1)
    puts("Yes");
  else
    puts("No");
  
  return 0;
}

Measured memory_bytes: 1636
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		int[] B = new int[M];
		for (int i=0;i<M;i++) {
			B[i]=sc.nextInt();
		}
		int[][] A = new int[N][M];
		for (int i=0;i<N;i++) {
			for (int j=0;j<M;j++) {
				A[i][j]=sc.nextInt();
			}
		}
		int cnt=0;
		for (int i=0;i<N;i++) {
			int sum=0;
			for (int j=0;j<M;j++) {
				sum=sum+A[i][j]*B[j];
			}
			if (sum+C>0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint x, y, n[3];
vector<llint> vec[3];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> x >> y >> n[0] >> n[1] >> n[2];
	llint z;
	for(int j = 0; j < 3; j++){
		for(int i = 0; i < n[j]; i++){
			cin >> z;
			vec[j].push_back(z);
		}
		sort(vec[j].rbegin(), vec[j].rend());
	}
	vec[0].resize(x), vec[1].resize(y);
	
	llint ans = 0;
	for(int i = 0; i < vec[0].size(); i++) ans += vec[0][i];
	for(int i = 0; i < vec[1].size(); i++) ans += vec[1][i];
	
	vec[0].insert(vec[0].begin(), inf);
	vec[1].insert(vec[1].begin(), inf);
	
	llint p = 0;
	while(p < n[2]){
		if(min(vec[0].back(), vec[1].back()) < vec[2][p]){
			if(vec[0].back() < vec[1].back()){
				ans -= vec[0].back(), vec[0].pop_back();
			}
			else{
				ans -= vec[1].back(), vec[1].pop_back();
			}
			ans += vec[2][p];
			p++;
		}
		else break;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
  	scanf("%d%d%d", &a, &b, &c);
  	int res = (b / a) < c ? (b / a) : c;
  	printf("%d\n", res);
  
  	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  int maxd = 0;
  for (int& e: a) cin >> e;
  for (int i = 0; i < a.size(); i++) {
    for (int j = i + 1; j < a.size(); j++) {
      maxd = max(maxd, abs(a[i] - a[j]));
    }
  }
  cout << maxd << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
  string str1,str2,str3;
  cin >> str1 >> str2 >> str3;
  cout << str1[0] << str2[1] << str3[2];
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int main(int argc, const char * argv[]) {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        int tmp;
        scanf("%d",&tmp);
        n-=tmp;
    }
    printf("%d",0<=n?n:-1);
    return 0;
}


Measured memory_bytes: 1732
function Main(input){
    const score = Number(input);
    let from = 600;
    let kyu = 8;
    while(true){
        if(score < from){
            console.log(kyu);
            return;
        }
        from += 200;
        kyu--;
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
	ios::sync_with_stdio(0); 
	cin.tie(0);
	ll a,b,c;
	cin>>a>>b>>c;
	int flag = 0;
	for(int i=b;i<=c;i++){
	 
	   if(i%a == 0) {
	      flag = 1;
	      break;
	   } 
	}

    if(flag == 1) cout<<"OK";
    else cout<<"NG";
	

	


}



Measured memory_bytes: 3648
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=1e5+10;
int n,m,a[MAXN],rnk[MAXN],V,P;
int calc(int x) // 严格比我大的人数 
{
	int res=0,L=1,R=n;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(a[mid]>x)
			res=mid,L=mid+1;
		else
			R=mid-1;
	}
	return res;
}
bool check(int x)
{
	int t=calc(a[x]+m); // 无论怎样都比我大的人 
	if(t>=P)
		return false;
	int k=V-1-t,s=P-t-1; // 最多容忍 s 个人严格比我大 
	k-=s;
	if(k<=0)
		return true;
	ll tot=0;
	for(int i=1;i<=n;++i)
	{
		if(i==x)
			continue;
		if(i<P)
			continue;
		tot+=min(m,a[x]+m-a[i]);
	}
	return tot>=1LL*k*m;
}
int main()
{
	n=read(),m=read(),V=read(),P=read();
	for(int i=1; i<=n; ++i)
		a[i]=read();
	sort(a+1,a+1+n);
	reverse(a+1,a+1+n);
	for(int i=1; i<=n; ++i)
		rnk[i]=calc(a[i])+1;
	int res=0,L=1,R=n;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(check(mid))
			res=mid,L=mid+1;
		else
			R=mid-1;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main() {
int X,Y,Z,i;
 vector<int> v(3,0);
  for (int i = 0; i < 3; i++) {
 cin >> v.at(i) ;
 }
X=v.at(2);
Y=v.at(0);
Z=v.at(1);
cout<<X<<" "<<Y<<" "<<Z<<" "<<endl;
 
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
string s,cal,kcal;
char j,k,l;
int main(){ 
    cin>>a>>b;
    if(a%2==0 && a/2>=b) cout<<"YES\n";
    else if(a%2==0) cout<<"NO\n";
    if(a%2!=0 && (a/2)+1>=b) cout<<"YES\n";
    else if(a%2!=0) cout<<"NO\n";
}

Measured memory_bytes: 256
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=ja
#https://dai1741.github.io/maximum-algo-2012/docs/shortest-path/

INF = (2*10**7)*100 + 1234567 #十分大きい値にすること!!!!!!

H,W = map(int, input().split())
c = [[int(e) for e in input().split()] for i in range(10)]

#Warshall–Floydで1に変える魔力を求めておく
for k in range(10):
    for i in range(10):
        for j in range(10):
            if c[i][j] > c[i][k] + c[k][j] and c[i][k]!=INF and c[k][j]!=INF:
                c[i][j] = c[i][k] + c[k][j]

ans = 0
for i in range(H):
    A_row = [int(e) for e in input().split()]
    for A in A_row:
        if A != -1:
            ans += c[A][1]
            
print(ans)

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll dp[200001]={0};
int main(){
    ll n,A[200001],B[200002];
    cin>>n;
    rep(i,n) cin>>A[i];
    rep(i,n){
        if(i==1) B[2]=A[0];
        if(i%2&&i>1) B[i+1]=B[i-1]+A[i-1];
    }
    rep(i,n+1){
        if(i<2) continue;
        if(i%2==0) dp[i]=max(B[i],dp[i-2]+A[i-1]);
        else dp[i]=max(dp[i-2]+A[i-1],dp[i-1]);
    }
    //rep(i,n+1) cout<<dp[i]<<"\n";
    cout<<dp[n]<<"\n";
}

Measured memory_bytes: 8320
fun main(args: Array<String>){
  
  val(a, b ,c, d) = readLine()!!.split(" ")
                    .map{ it.toInt() }
  
  val ans = when{
                  a * b >= c * d -> { a * b }
                  a * b <  c * d -> { c * d }
                            else -> { "error" }
            }
  
  println(ans)
    
}

Measured memory_bytes: 35952
function main(input) {
  const args = input.split('\n');
  const row1 = args[0].split(' ').map(n => parseInt(n, 10));
  const row2 = args[1].split(' ').map(n => parseInt(n, 10)); //B配列
  const N = row1[0], //Aのループ回数
        M = row1[1], //Bのループ回数
        C = row1[2]; //C
  let ans = 0;
  
  for (let i = 2; i < args.length; i++) {
    //初期設定
    ary = args[i].split(' ').map(n => parseInt(n, 10));
    total = C;
    for (let j = 0; j < M; j++) {
      total += ary[j] * row2[j];
    }
    if (total > 0) { ans++; }
  }
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	string s[n];
	int t[n];
	for(int i=0; i<n; i++) cin >> s[i] >> t[i];

	string x;
	cin >> x;
	int i=0, ans=0;
	while(s[i]!=x) i++;
	i++;
	for(; i<n; i++) ans+=t[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
 
        try {
            String buffer[] = br.readLine().split("\\s+");
 
            int N = Integer.parseInt(buffer[0]);
            int M = Integer.parseInt(buffer[1]);
            int L = Integer.parseInt(buffer[2]);
 
            int A[][] = new int[N][M];
            int B[][] = new int[M][L];
 
            String buf_A[] = new String[M];
            String buf_B[] = new String[L];
 
            for(int row = 0; row < N; row++){
                buf_A = br.readLine().split("\\s+");
                for(int col = 0; col < M; col++){
                    A[row][col] = Integer.parseInt(buf_A[col]);
                }
            }
 
            for(int row = 0; row < M; row++){
                buf_B = br.readLine().split("\\s+");
                for(int col = 0; col < L; col++){
                    B[row][col] = Integer.parseInt(buf_B[col]);
                }
            }
 
            Long ans;
 
            for(int A_row = 0; A_row < N; A_row++){
                for(int B_col = 0; B_col < L; B_col++){
                    ans = 0L;
                    for(int B_row = 0; B_row < M; B_row++){
                        ans += A[A_row][B_row]*B[B_row][B_col];
                    }
                    if(B_col == 0){
                        System.out.printf("%d", ans);
                    }else{
                        System.out.printf(" %d", ans);
                    }
                }
                System.out.printf("\n");
            }
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 80100
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        String s1=s+s;
        String check=in.nextLine();
        if(s1.contains(check)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26212
#include <limits>
using ll = long long;
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr ll LNF = std::numeric_limits<ll>::max() / 2;

#include <bits/stdc++.h>
using namespace std;

template <typename T>
void print(vector<T> const &x, string s = "") {
}

ll compute(vector<ll> v, int K, int Q, vector<int> &seps) {
    int N = v.size();
    sort(seps.begin(), seps.end());
    seps.push_back(N);
    print(seps, "seps: ");
    for (int i = 1; i < (int)seps.size(); i++) {
        sort(v.begin() + seps[i - 1] + 1, v.begin() + seps[i]);
    }
    print(v, "sorted v: ");

    vector<ll> ans;
    ans.reserve(N);
    for (int i = 1; i < (int)seps.size(); i++) {
        ans.insert(ans.end(), v.begin() + seps[i - 1] + 1,
                   v.begin() + seps[i - 1] + 1 +
                       max(0, seps[i] - seps[i - 1] - 1 - K + 1));
    }
    print(ans, "ans: ");
    sort(ans.begin(), ans.end());
    seps.pop_back();
    return Q <= (int)ans.size() ? ans[Q - 1] - ans[0] : LNF;
}

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> orig(N);
    for (int i = 0; i < N; i++) { cin >> orig[i]; }

    vector<pair<ll, int>> cp(N);
    for (int i = 0; i < N; i++) {
        cp[i].first  = orig[i];
        cp[i].second = i;
    }
    sort(cp.begin(), cp.end());

    vector<int> seps = {-1};
    ll mi            = compute(orig, K, Q, seps);
    for (auto const &p : cp) {
        seps.push_back(p.second);
        ll res = compute(orig, K, Q, seps);
        if (res == LNF) break; // ??????
        mi = min(mi, res);
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define N 8
#define F -1
#define T 1

int Queen[N][N], A[N], B[N], C[2*N-1], D[2*N-1];

void print(int num)
{
  int i, j;
  if(num == N)
    {
      for(i = 0; i < N; i++)
	{
	  for(j = 0; j < N; j++)
	    {
	      if(Queen[i][j] == 1)
		{
		  if(A[i] != j)
		    {
		      return ;
		    }
		}
	    }
	}
      for(i = 0; i < N; i++)
	{
	  for(j = 0; j < N; j++)
	    {
	      if(A[i] == j)
		{
		  printf("Q");
		}
	      else
		{
		  printf(".");
		}
	    }
	  printf("\n");
	}
      return ;     
    }
  else
    {
      for(i = 0; i < N; i++)
	{
	  if(B[i] == T || C[i+num] == T || D[num-i+N-1] == T)
	    {
	      continue;
	    }
	  else
	    {
	      A[num] = i;
	      B[i] = T;
	      C[num+i] = T;
	      D[num-i+N-1] = T;
	      print(num+1);
	      B[i] = F;
	      C[i+num] = F;
	      D[num-i+N-1] = F;
	    }
	}
    }
}
int main()
{
  int n, i, j, v, s;
  scanf("%d", &n);
  for(i = 0; i < N; i++)
    {
      for(j = 0; j < N; j++)
	{
	  Queen[i][j] = 0;
	}
    }
  for(i = 0; i < N; i++)
    {
      A[i] = F;
      B[i] = F;
    }
  for(i = 0; i < 2*N-1; i++)
    {
      C[i] = F;
      D[i] = F;
    }
  for(i = 0; i < n; i++)
    {
      scanf("%d%d", &v, &s);
      Queen[v][s] = 1;
    }
  print(0);
  return 0;
}



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

int main() {
  string S,T;
  cin >>S >>T;
if (S.size()<T.size()){  
  int A=S.size();
  char B=T.at(A);
  if (T==S+B){
  cout <<"Yes" <<endl;
  }
  else {
  cout <<"No" <<endl;
  }
}
  else {
    cout <<"No" <<endl;
  }
}

Measured memory_bytes: 3628
import math

a, b, h, m = map(int, input().split())
h = (h + m // 60) % 12
m %= 60

r1, r2 = h * 30, m % 60 * 6
r1 += r2 / 360 * 30
r = r1 - r2

if r == 0:
    print(abs(a - b))
elif abs(r) == 180:
    print(a + b)
else:
    res = r1 - r2
    if res > 180:
        res = 360 - res
    elif res < - 180:
        res += 360
    elif res < 0:
        res = - res

    cos = math.cos((res / 360) * 2 * math.pi)
    print((a * a + b * b - 2 * a * b * cos) ** 0.5)

Measured memory_bytes: 9564
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
ll longinf=1ll<<60;
int inf=1<<29;
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
int main(){
      ll n,a,b,c,d;
      cin>>n>>a>>b>>c>>d;
      ll diff=b-a;
      bool ok=false;
      rep0(i,n){
            if((n-i-1)*c-i*d<=diff&&diff<=(n-i-1)*d-i*c){
                  ok=true;
            }
      }
      cout<<(ok?"YES":"NO")<<endl;
      
      return 0;
}


Measured memory_bytes: 256
n,x,y = gets.split.map(&:to_i)

distance = -> i,j do
  # i->j
  a = (i-j).abs

  # i -> x -> y -> j
  b = (i-x).abs + 1 + (j-y).abs

  # i -> y -> x -> j
  c = (i-y).abs + 1 + (j-x).abs

  [a,b,c].min
end

ans = Hash.new(0)
1.upto(n-1) do |i|
  (i+1).upto(n) do |j|
    ans[distance[i,j]] += 1
  end
end

1.upto(n-1) do |k|
  puts ans[k]
end



Measured memory_bytes: 1916
#include <stdio.h>

int main()
{
	int a1[100],a2[100],a3[100],a4[100];
	int b1[100],b2[100],b3[100],b4[100];
	int hit[100]={0};
	int blow[100]={0};
	int i=0;
	int ret,count;
	while(1){
		ret=scanf("%d %d %d %d", &a1[i], &a2[i], &a3[i], &a4[i]);
		if(ret==EOF){
			break;
		}
		ret=scanf("%d %d %d %d", &b1[i], &b2[i], &b3[i], &b4[i]);
		if(ret==EOF){
			break;
		}
		else if(a1[i]==b1[i]){
			hit[i]++;
		}
		if(a1[i]==b2[i]){
			blow[i]++;
		}
		if(a1[i]==b3[i]){
			blow[i]++;
		}
		if(a1[i]==b4[i]){
			blow[i]++;
		}
		if(a2[i]==b1[i]){
			blow[i]++;
		}
		if(a2[i]==b2[i]){
			hit[i]++;
		}
		if(a2[i]==b3[i]){
			blow[i]++;
		}
		if(a2[i]==b4[i]){
			blow[i]++;
		}
		if(a3[i]==b1[i]){
			blow[i]++;
		}
		if(a3[i]==b2[i]){
			blow[i]++;
		}
		if(a3[i]==b3[i]){
			hit[i]++;
		}
		if(a3[i]==b4[i]){
			blow[i]++;
		}
		if(a4[i]==b1[i]){
			blow[i]++;
		}
		if(a4[i]==b2[i]){
			blow[i]++;
		}
		if(a4[i]==b3[i]){
			blow[i]++;
		}
		if(a4[i]==b4[i]){
			hit[i]++;
		}
		i++;
	}
	count=i;
	for(i=0; i<count; i++){
		printf("%d %d\n", hit[i], blow[i]);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long lld;
typedef vector<lld> vlld;
const lld mod=(lld)1e9+7;
 
int main() {
      string s;
      cin>>s;
      int n=sz(s);
      if(s[n-1]=='s')
      s+="es";
      else
      s.push_back('s');
      
      cout<<s<<"\n";
 
  return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

int main() {
    long long A, B;
    cin >> A >> B;

    long long cnt = B - A + 1;

    if (cnt & 0x1) {
        long long n = (cnt - 1) / 2;
        long long b = (A & 0x1) ? A : B;
        if (n & 0x1) {
            cout << (0x1 ^ b) << endl;
        } else {
            cout << b << endl;
        }
    } else {
        if (A & 0x1) {
            long long n = cnt / 2 - 1;
            if (n & 0x1) {
                cout << (A ^ 1 ^ B) << endl;
            } else {
                cout << (A ^ B) << endl;
            }
        } else {
            long long n = cnt / 2;
            if (n & 0x1) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }   

/*
    long long ans = A;
    for (long long i = A + 1; i <= B; ++i) {
        ans = ans ^ i;
    }
    cout << ans << endl;
*/

    return 0;
}


Measured memory_bytes: 384
h,w=gets.split.map(&:to_i)
s=h.times.map{'.'+gets.chomp+'.'}
d='.'*(w+2)
s=[d]+s+[d]

flg =false
1.upto(h) do |i|
  1.upto(w) do |j|
    if s[i][j]=='#'
      if s[i-1][j]=='.' && s[i+1][j]=='.' && s[i][j-1]=='.' && s[i][j+1]=='.'
        flg =true
      end
    end
  end
end

if flg
  puts "No"
else
  puts "Yes"
end



Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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


Measured memory_bytes: 256
poly = []
for w in range(2,150):
	for h in range(1,w):
		poly.append((w*w+h*h,h,w))
poly.sort()

while True:
	h,w = map(int,input().split())
	if h + w == 0:
		break
	a = poly.index((w*w+h*h,h,w))
	print(poly[a+1][1],poly[a+1][2])


Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;
 
int main() {
  ll n,m;
  cin >> n >> m;
  mat G(n),GG(n);
  for(ll i=0;i<m;i++) {
    ll a,b;
    cin >> a >> b;
    a--,b--;
    G[a].push_back(b);
    GG[b].push_back(a);
  }
  ll ans=inf;
  vec ansv(n);
  for(ll i=0;i<n;i++) {
    queue<ll> q;
    ll id=-1;
    vec d(n,-1);
    d[i]=0;
    q.push(i);
    while(q.size()) {
      ll f=q.front();
      ll td=d[f];
      q.pop();
      for(ll t:G[f]) {
        ll nd=td+1;
        if(t==i) {
          id=f;
          break;
        }
        if(d[t]>-1) continue;
        d[t]=nd;
        q.push(t);
      }
      if(id>-1) break;
    }
    if(id>-1) {
      if(ans>d[id]+1) {
        ans=d[id]+1;
        for(ll j=0;j<ans;j++) {
          ansv[j]=id+1;
          for(ll f:GG[id]) {
            if(d[f]+1==d[id]) {
              id=f;
              break;
            }
          }
        }
      }
    }
    while(q.size()) q.pop();
  }
  if(ans==inf) ans=-1;
  cout << ans << endl;
  for(ll i=0;i<ans;i++) {
    cout << ansv[i] << endl;
  }
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<vector <int>>vec(N,vector<int>(2));
  for(int i=0;i<N;i++){
    for(int j=0;j<2;j++){
      cin>>vec.at(i).at(j);
    }
  }
  for(int i=0;i<N-2;i++){
    if(vec.at(i).at(0)==vec.at(i).at(1)&&vec.at(i+1).at(0)==vec.at(i+1).at(1)&&vec.at(i+2).at(0)==vec.at(i+2).at(1)){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;      
}
    

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
//#include <windows.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VVC = vector<VC>;
using VS = vector<string>;
using VVS = vector<VS>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
const int INF = 2e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL x, y, ans = 1;
  cin >> x >> y;
  while(x *= 2, x <= y) ans++;
  cout << ans << endl;

  return 0;
}

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

int main(){
	long long A,B,N,sum,amari; cin>>N>>A>>B;
  	sum=A*(N/(A+B));
  	if(N%(A+B)>A) amari=A;
  	else amari=N%(A+B);
  	cout<<sum+amari<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
long long n, c, t, mx, x[N], v[N], a[N], b[N], aa[N], bb[N];
int main() {
	int i;
	scanf("%lld%lld", &n, &c);
	for(i=t=0; i<n; i++) {
		scanf("%lld%lld", &x[i], &v[i]);
		t += v[i];
		a[i] = t - x[i];
		mx = max(mx, a[i]);
	}
	b[n] = -9e20;
	for(i=n-1, t=0; i>0; i--) {
		t += v[i];
		b[i] = max(b[i+1], t - (c-x[i]));
	}
	for(i=n-2; i>=0; i--) {
		mx = max(mx, a[i] + b[i+1] - x[i]);
	}
	for(i=n-1, t=0; i>=0; i--) {
		t += v[i];
		aa[i] = t - (c-x[i]);
		mx = max(mx, aa[i]);
	}
	for(i=0, t=0; i<n-1; i++) {
		t += v[i];
		bb[i] = t - x[i];
	}
	for(i=1; i<n-1; i++) bb[i] = max(bb[i-1], bb[i]);
	for(i=1; i<n; i++) {
		mx = max(mx, aa[i] + bb[i-1] - (c-x[i]));
	}
	cout<<mx;
	return 0;
}


Measured memory_bytes: 4992
s = gets.chomp.split("")
arr = []
arr << s
arr = arr.flatten
#p arr
q = gets.chomp.to_i
key = "a"
q.times do |i|
    qq = gets.chomp.split(" ")
    #p qq[0]
    if qq[0] == "1"
        #arr = arr.reverse
        if key == "a"
            key = "b"
        elsif key == "b"
            key = "a"
        end
    elsif qq[0] == "2"
        if qq[1] == "1" && key == "a"
            arr.unshift(qq[2])
            #p arr
            #arr = arr.join("")
        elsif qq[1] == "2" && key == "a"
            arr << qq[2]
            #p arr
            #arr = arr.join("")
        elsif qq[1] == "1" && key == "b"
            arr << qq[2]
            #arr = arr.join("")
        elsif qq[1] == "2" && key == "b"
            arr.unshift(qq[2])
            #arr = arr.join("")
        end
    end
    #p arr
end
#p arr
if key == "a"
puts arr.join("")
elsif key == "b"
puts arr.reverse.join("")
end

Measured memory_bytes: 36292
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
typedef long long ll;

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

int main()
{
  ll A, B;
  cin >> A >> B;

  if(abs(A-B)%2==0)
    cout << abs(A-B)/2+min(A,B) << endl;
  else
    cout <<  "IMPOSSIBLE" << endl;

  return 0;
}


//cout << setprecision(13);
//next_permutation(v.begin(), v.end());



Measured memory_bytes: 256
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
R=[]
for i in range(0,m):
  t=input()
  x=int((t.split())[0])
  y=int((t.split())[1])
  c=int((t.split())[2])
  R.append(A[x-1]+B[y-1]-c)
r=min((min(A)+min(B)),min(R))
print(r)
  

       

Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ar array

const int mxN = 20;

int p[mxN],num_lights_on[mxN];
vector<int>adj[mxN];
bool switches[mxN];
int N,M;

int check()
{
    memset(num_lights_on,0,sizeof(num_lights_on));

    for(int i = 0 ; i < M; i++)
    {
        for(auto x : adj[i])
        {
            num_lights_on[i] += switches[x];
        }

        if((num_lights_on[i] % 2) != p[i])
            return 0;
    }

    return 1;
}

void solve()
{
    cin>>N>>M;

    for(int i = 0 ; i < M; i++)
    {
        int K;
        cin>>K;

        for(int j = 0 ; j < K; j++)
        {
            int S;
            cin>>S;
            S--; //zero indexing

            adj[i].pb(S);
        }
    }

    for(int i = 0 ; i < M; i++)
        cin>>p[i];

    int ans = 0;

    for(int i = 0 ; i < pow(2,N); i++)
    {
        for(int j = 0 ; j < N ; j++)
        {
            switches[j] = (i >> j) & 1;
        }

        ans += check();
    }

    cout<<ans<<endl;

}

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

    solve();

    return 0;
}

Measured memory_bytes: 4120
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    int N, C;
    cin >> N >> C;
    int imos[C][100010];
    memset(imos, 0, sizeof(imos));

    rep(i, 0, N) {
        int s, t, c;
        cin >> s >> t >> c;
        imos[--c][--s]++;
        imos[c][t]--;
    }

    rep(i, 0, C) rep(j, 1, 100010) imos[i][j] += imos[i][j - 1];
    rep(i, 0, C) rep(j, 0, 100010) if(imos[i][j]) imos[i][j] = 1;


    int rsl = 0;
    rep(j, 0, 100010) {
        int cnt = 0;
        rep(i, 0, C) {
            cnt += imos[i][j];
        }
        rsl = max(rsl, cnt);
    }

    cout << rsl << endl;


}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
 
#define INF 1e18
#define MAX 600005

int op(int a, int b) {
  return max(a,b);
}

int e() {
  return 0;
}

int main() {
  int n, k;
  cin >> n >> k;
  segtree<int, op, e> seg(MAX);
  rep(i,n) {
    int a;
    cin >> a;
    int p = seg.prod(max(0,a-k),min(a+k+1,MAX));
    seg.set(a,p+1);
  }
  cout << seg.all_prod() << endl;

  return 0;
}

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  for (int i = 0; i < n; i++) { 
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i + 1 < n; i++) {
    ans += min(t, a[i + 1] - a[i]);
  }
  ans += t;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3876
n=int(input())
m=[{}for i in range(n+1)]
w=10**9+7
def f(s):
    for i in range(4):
        t=list(s)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if "".join(t).count("AGC")>0:
            return False
    return True
def a(p,q):
    if q in m[p]:
        return m[p][q]
    if p==n:
        return 1
    r=0
    for i in "AGCT":
        if f(q+i):
            r=(r+a(p+1,q[1:]+i))%w
    m[p][q]=r
    return r
print(a(0,"WHY"))

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  cout<<A[N-1]-A[0]<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

namespace {
    int greatest_common_divisor(int x, int y) {
        if (y == 1) {
            return 1;
        } else if (y == 0) {
            return x;
        } else if (x < y) {
            return greatest_common_divisor(y, x);
        } else {
            return greatest_common_divisor(y, x % y);
        }
    }
}

int main() {
    int x,y;
    cin >> x >> y;
    cout << greatest_common_divisor(x,y) << endl;
    return 0;
}

Measured memory_bytes: 1160