akhauriyash/Code-Regression huggingface dataset:
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    mon=0
    for i,x in enumerate(b):
        mon = mon+min(a[i],x)
        tmp=x-a[i]
        if tmp>0:
            u = min(a[i+1],tmp)
            mon = mon+u
            a[i+1] = a[i+1]-u
    print(mon)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin >> n ;
	cout << 3  * n * n ;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
	int n; cin >> n;
	map<string,int>mep;
	for(int i = 0 ; i < n ; i++){
		string s; cin >> s;
		mep[s]++;
	}
	cout << "AC x " << mep["AC"] << endl;
	cout << "WA x " << mep["WA"] << endl;
	cout << "TLE x " << mep["TLE"] << endl;
	cout << "RE x " << mep["RE"] << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

int main(){
    int n, l; cin >> n >> l;
    int prev; int index = -1;
    for(int i=0; i<n; i++){
        if(i == 0){
            cin >> prev;
            continue;
        }
        int val;
        cin >> val;
        if(prev + val >= l){
            index = i-1;
            break;
        }
        prev = val;
    }
    if(index == -1){
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    for(int i=0; i<index; i++){
        cout << i + 1 << endl;
    }
    for(int i=n-2; i>index-1; i--){
        cout << i + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 768
import java.math.*

fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toInt() }
    
    val cakes = mutableListOf<Triple<Long, Long, Long>>()
    
    for (i in 1..N) {
        val (x, y, z) = readInputLine().split(" ").map { it.toLong() }
        cakes.add(Triple(x, y, z))
    }
    
    var ans = 0L
    
    for (x in LongRange(-1L, 1L)) {
        if (x == 0L) {
            continue
        }
        for (y in LongRange(-1L, 1L)) {
            if (y == 0L) {
                continue
            }
            for (z in LongRange(-1L, 1L)) {
                if (z == 0L) {
                    continue
                }
                val cakesTmp = cakes.map { it -> it.first * x + it.second * y + it.third * z }
                ans = Math.max(ans, cakesTmp.sortedDescending().take(M).sum())
            }
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main(void){
    std::vector<int> vec;
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++){
        int tmp;
        std::cin >> tmp;
        vec.push_back(tmp);
    }

    int res = 0;
    int tmpres = 0;
    for (int i = vec.size() - 1; i > 0; i--){
        if (vec[i - 1] >= vec[i]){
            ++tmpres;
        } else {
            if (res < tmpres)
                res = tmpres;
            tmpres = 0;
        }
    }
    std::cout << (res >= tmpres ? res : tmpres) << std::endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int N, M;
int main(void){
    cin >> N >> M;
    if(N==M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include "iostream"

using namespace std;

int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    cout << (double)w*h/2.0 ;
    if(x == w/2 && y == h/2 && w%2==0 && h%2==0){
        cout << " " << 1 << endl;
    }
    else{
        cout << " " << 0 << endl;
    }

}

Measured memory_bytes: 256
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    S = input()
    L = len(S)
    d = deque()
    for i in range(L):
        if S[i]=='0':
            d.append(0)
        elif S[i]=='1':
            d.append(1)
        else:
            if len(d)!=0:
                d.pop()
    print(''.join(map(str,d)))



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
function Main(input) {
    const A = parseInt(input[0])
    const B = parseInt(input[1])
    const C = parseInt(input[2])
    
    if((A < C && C < B) || (B < C && C < A)) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}

// 改行・空白で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(b - a == c - b)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3548
package main

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()

	for i := 0; i < n; i++ {
		j := n - i - 1
		l := a + i*c - j*d
		r := a + i*d - j*c
		if l <= b && b <= r {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1772
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] kachi = br.readLine().split(" ");
		String[] cost = br.readLine().split(" ");

		int k = 0;
		int c = 0;
		int sum = 0;

		for(int i=0;i<n;i++) {
			k = Integer.parseInt(kachi[i]);
			c = Integer.parseInt(cost[i]);

			if(k-c>0) {
				sum += k-c;
			}

		}


		System.out.println(sum);

	}

}


Measured memory_bytes: 21204
import sys
N, T = map(int, input().split())
c = [0] * N
t = [0] * N
for i in range(N):
    c[i], t[i] = map(int, input().split())

if min(t) > T:
    print("TLE")
    sys.exit()

cost = float("inf")
for i in range(N):
    if t[i] <= T:
        cost = min(cost, c[i])
print(cost)

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

string s, ans;

void solve(int t, string S, int sum){
// t;カウンター、S;式、sum;合計値
	if(t == 4) {
		if(sum == 7) ans = S;
		return;
	}

	solve(t+1, S+"+"+s[t],sum+(s[t]-'0'));
	solve(t+1,S+"-"+s[t],sum-(s[t]-'0'));

}

int main(){
	cin >> s;
	solve(1,"",s[0]-'0'); //１つ目には演算子をつけないので最初からsumにいれている。
	cout << s[0] << ans << "=7" << endl;
}

Measured memory_bytes: 256
cou = int(input())
a = list(map(int,input().split()))
ans = 0

for i in range(cou):
    b = a[i]
    if b % 2 == 0:
        if b % 3 == 0:
            ans += 1
        elif b %5 == 0:
            ans += 1
        else:
            break
    else:
        ans += 1

if ans == cou:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38416
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
        int k, s;
        scanf("%d %d", &k, &s);
        int ans = 0;
        rep(i, 0, k+1){
                rep(j, 0, k+1){
                        if(0<=s-i-j and s-i-j<=k){
                                ans++;
                        }
                }
        }
        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int dp[2000][2000];

int main(){
    int N,x;
    cin>>N>>x;
    for(int i=0;i<N;i++){
        cin>>dp[i][0];
    }
    for(int k=1;k<N;k++){
        for(int i=0;i<N;i++){
            dp[i][k]=min(dp[i][k-1],dp[(i-1+N)%N][k-1]);
        }
    }
    long long int ans=1LL<<60;
    for(int k=0;k<N;k++){
        long long int sum=0;
        for(int i=0;i<N;i++){
            sum+=dp[i][k];
        }
        sum+=k*x;
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16000
#include<stdio.h>
int main(void)
{
  int P,Q,R;
  int min;
  scanf("%d%d%d",&P,&Q,&R);
  
  min=P+Q;
  if(min>=(Q+R)){
    min=Q+R;
  }
  if(min>=(R+Q)){
    min=R+Q;
  }
  if(min>=(P+R)){
    min=P+R;
  }
  
  printf("%d",min);
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	
	int a,b;
	cin>>a>>b;
	if(a<=5){
		cout<<0<<endl;
	}
	else if(a<=12)cout<<b/2<<endl;
	else cout<<b<<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;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(ki, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(i + a[i] + 1, n);
      b[l]++;
      b[r]--;
    }
    rep(i, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b) break;
    a = b;
  }
  rep (i, n) {
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 4840
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[100010],b[100010],q,p,max1,max2,xam1,xam2,m1,m2,x1,x2;
int main()
{
	cin>>n;
	for(int i=1;i<=n>>1;i++)
	{
		cin>>p;
		a[p]++;
		if(a[p]>=max1)
		{
			if(p!=m1)
            {
				max2=max1;
				m2=m1;
			}
			max1=a[p];
			m1=p;
			
		}
		else
		    if(a[p]>max2)
		    {
				max2=a[p];
				x2=p;
		    }
        cin>>q;
		b[q]++;
		if(b[q]>=xam1)
		{
			if(q!=x1)
			{
				xam2=xam1;
				x2=x1;
			}
			xam1=b[q];
			x1=q;
		}
		else
		    if(b[q]>xam2)
		    {
				xam2=b[q];
				x2=q;
		    }
	}
	if(m1==x1)
		cout<<n-max(max1+xam2,xam1+max2)<<endl;
	else cout<<n-max1-xam1<<endl;
//	system("pause");
	return 0;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
a = input()
l = []
if a[0] == '0':
    l.append(0)
sum = []
i = 0
while i < len(a):
    j = i
    while j < len(a) and a[j] == a[i]:
        j += 1
    l.append(j-i)
    i = j
if a[-1] == '0':
    l.append(0)
num = [0]*(len(l)+1)
for i in range(0, len(l)):
    num[i+1] = num[i]+l[i]
ans = -1
for i in range(0, len(num), 2):
    j = i + k*2+1
    if j >= len(num):
        j = len(num)-1
    ans = max(ans, num[j] - num[i])
print(ans)


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

const int mod = 2019;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll r = 0, g = 0, b = 0;
    rep(i,n) {
        if (s[i] == 'R') r++;
        if (s[i] == 'G') g++;
        if (s[i] == 'B') b++;
    }
    ll ans = r*g*b;
    for (int j = 1; j <= n-2; j++) {
        for (int i = 0; i < j; i++) {
            int k = 2*j-i;
            if (k > n-1) continue;
            if (s[i] == s[j]) continue;
            if (s[j] == s[k]) continue;
            if (s[k] == s[i]) continue;
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int flag = 2;//0が買った、1が売った、2が決まっていない(最初だけ)
    vi ans(n,0);//1の時に買い、2の時に売る
    rep(i, n) {
        if(i==n-1) {
            if(a[i]>=a[i-1]&&flag==0) {
                ans[i]=2;
            }
        }
        else if(a[i]<=a[i+1]&&(flag==2||flag==1)) {
            ans[i]=1;
            flag=0;
        }
        else if(a[i]>=a[i+1]&&flag==0) {
            ans[i]=2;
            flag=1;
        }
    }
    // for(auto p:ans)cout << p << ' ';
    // cout << endl;
    int money = 1000;  
    int kub = 0;  
    rep(i, n) {
        if(ans[i]==1) {
            kub+=money/a[i];
            money%=a[i];
        }
        else if(ans[i]==2) {
            money+=kub*a[i];
            kub=0;
        }
        // cout << money << endl;
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)
#define f(i, k, j) for(int i = k; i < j; i++)
#define P pair<int, int>
const int INF = (1 << 26);
const int MAX_N = 301;

int dp[MAX_N], n;

void solve(){
    int c[16];
    for(int i = 2; i <= 17; i++) c[i - 2] = i * i;
    rep(i, MAX_N) dp[i] = 1;

    rep(i, 16){
        for(int j = c[i]; j < MAX_N; j++) dp[j] += dp[j - c[i]];
    }
}

int main(){
    solve();
    while(cin >>n && n != 0) cout <<dp[n] <<endl;
    return 0;
}

Measured memory_bytes: 1160
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-08-30 13:03:34
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

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

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       int(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

int n , ans;
vector<int> vec;
string s;

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

	cin >> s;
	n = SZ(s);
	for(int i = n - 1 ; i >= 0 ; i--){
		vec.push_back(s[i] - 48);
	}
	int ptr = SZ(vec) - 1;
	while(1){
		int prv = 0;
		/*for(int i = SZ(vec) - 1 ; i >= 0 ; i--)	cout << vec[i];
		cout << endl;*/
		//vector<int> res;
		//cout << SZ(vec) << sep << ptr << endl;
		ptr = min(ptr , SZ(vec) - 1);
		while(ptr > 0 && vec[ptr - 1] >= vec[ptr]){
			ptr--;
		}
		while(SZ(vec) && (vec.back() < vec[ptr] || ptr == 0)){
		//	res.push_back(vec.back());
			vec.pop_back();
		}
		if(SZ(vec)){
		//	res.push_back(vec.back());
			vec.pop_back();
		}
		/*int x = res.back();
		res.pop_back();
		res.push_back(x - 1);
		for(int i = 0 ; i < SZ(vec) ; i++)	res.push_back(9);
		//reverse(all(res));
		for(int i : res)	cout << i;
		cout << endl;
		cout << "=============" << endl;*/
		ans++;
		if(SZ(vec) == 0)	return cout << ans << endl , 0;
		int rem = 1;
		for(int i = 0 ; i < SZ(vec) ; i++){
			if(rem == 0)	break;
			vec[i] += rem;
			rem = vec[i] / 10;
			vec[i] %= 10;
		}
	}

    return 0;
}
/*

*/


Measured memory_bytes: 5920
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans=min(b,d)-max(a,c);
  if(ans>=0){
    cout<<ans<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n, m = [int(s) for s in input().strip().split()]
    result = n * (n - 1) // 2 + m * (m - 1) // 2
    print(result)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
import sys
input = sys.stdin.readline
import statistics

n = int(input())
C = [list(map(int,input().split())) for i in range(n)]

A = [C[i][0] for i in range(n)]
B = [C[i][1] for i in range(n)]

ans = 0
if n%2==1:
    ans = statistics.median(B)-statistics.median(A)+1
    print(ans)
else:
    a = statistics.median(A)
    b = statistics.median(B)
    eps = 10**-3
    print(int(b*2+eps)-int(a*2+eps)+1)

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

using namespace std;

#define INF 100010001000
#define MOD 1000000007
#define int long long
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef pair<int, int> P;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M)  //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) {           //bit計算
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) {   //素数判定
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    int d = c - a - b;
    if (4 * a * b < d *d && d > 0)
         cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
    ll n;
    cin>>n;
    string ans="";
    while(n>0){
        n--;
        ans+=(char)('a'+n%26);
        n/=26;
    }

    reverse(all(ans));
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int max=1;
		for(int i=0; i<N; i++) {
			max*=2;
		}
		max--;
		if(K>max) {
			System.out.println(-1);
		}
		else {
			if(N==0) {
				System.out.println("0 0");
			}
			else if(N==1) {
				if(K==0) {
					System.out.println("0 0 1 1");
				}
				else {
					System.out.print(-1);
				}
			}
			else {
				if(max==K) {
					StringBuffer sb=new StringBuffer();
					sb.append(K+" ");
					for(int i=max; i>=0; i--) {
						if(i!=K) {
							sb.append(i+" ");
						}
					}
					sb.append(K+" ");
					for(int i=0; i<max; i++) {
						if(i!=K) {
							sb.append(i+" ");
						}
					}
					System.out.println(sb.toString());
				}
				else {
					StringBuffer sb=new StringBuffer();
					sb.append(K+" ");
					for(int i=max; i>=0; i--) {
						if(i!=K) {
							sb.append(i+" ");
						}
					}
					sb.append(K+" ");
					for(int i=0; i<max; i++) {
						if(i!=K) {
							sb.append(i+" ");
						}
					}
					sb.append(max);
					System.out.println(sb.toString());
				}
			}
		}
	}
}

Measured memory_bytes: 49764
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}



//提出コード↓

int n, w[100], sm,S ,D = 100000;




int main() {
	cin >> n;
	rep(i, n) {
		cin >> w[i];
		sm += w[i];
	}
	
	rep(j, n) {
		S += w[j];
		D = min(D, abs(S - (sm - S)));

	}
	cout << D << endl;


	return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
s = input().strip()
t = input().strip()

ans = n * 2
for i in range(0, n):
    if s[i:n] == t[0:n-i]:
        ans -= (n - i)
        break
print(ans)


Measured memory_bytes: 61900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  double a,b,x;
  cin>>a>>b>>x;
  
  double h=(2*x)/(a*b*1.0);
   double pi;
  pi     = 4.0 * atan(1.0);            /* πの値 */

	double unit_r = 180.0 / pi;/* ラジアン → 度 */
 double atan(double t);
  
  if(h<=a){
    //return 1;
    printf("%0.10lf\n",1.0*atan(b/h)*unit_r);
    
  }
  else{
    printf("%0.10lf\n",1.0*atan((2*b*pow(a,2)-2*x)/pow(a,3))*unit_r);
    
  }
  
  //cout<<pi<<endl;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");
   //  String nyu=sc.nextLine();

int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);

String ny[]=sc.nextLine().split("");

for(int i=0;i<ny.length;i++){
if(i==B-1){
System.out.print(ny[i].toLowerCase());
}else{
System.out.print(ny[i]);
}

}

	}
}

Measured memory_bytes: 21588
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  const double  pi=3.1415926535; 
  const ll MAXN=1e6+1;
  struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
ll spf[MAXN];
 void sieve() 
    { 
        spf[1] = 1; 
        for (int i = 2; i < MAXN; i++) 
      
            // marking smallest prime factor for every 
            // number to be itself. 
            spf[i] = i; 
      
        // separately marking spf for every even 
        // number as 2 
        for (int i = 4; i < MAXN; i += 2) 
            spf[i] = 2; 
      
        for (int i = 3; i * i < MAXN; i++) 
        { 
            // checking if i is prime 
            if (spf[i] == i) 
            { 
                // marking SPF for all numbers divisible by i 
                for (int j = i * i; j < MAXN; j += i) 
      
                    // marking spf[j] if it is not  
                    // previously marked 
                    if (spf[j] == j) 
                        spf[j] = i; 
            } 
        } 
    } 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	sieve();
	ll n,i,j;cin>>n;
	ll v[n];
	set<ll> s;
	bool ff=false;
	for(i=0;i<n;i++){
		cin>>v[i];
		ll a=v[i];
		while(a>1){
			if(s.count(spf[a])==0){
				s.insert(spf[a]);
				ll z=spf[a];
				while(a%z==0)
					a/=z;
			}
			else {
				ff=true;
				break;
			}
		}
		
	}
	if(ff==false){
		cout<<"pairwise coprime";
		return 0;
	}
	ll g=__gcd(v[0],v[1]);
	for(i=2;i<n;i++){
		g=__gcd(g,v[i]);
	}
	if(g==1)
		cout<<"setwise coprime";
	else cout<<"not coprime";


	return 0;
} 

Measured memory_bytes: 22920
using System;

namespace ITP1_9_B
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                string str = Console.ReadLine();
                if (str == "-")
                {
                    break;
                }

                int count = int.Parse(Console.ReadLine());
   
                for (int i=0; i<count; i++)
                {
                    int num = int.Parse(Console.ReadLine());
                    string str_b = str.Substring(0, num);
                    string str_f = str.Substring(num, (str.Length - num));
                    str = str_f + str_b;
                }
                Console.WriteLine(str);            
            }
        }
    }
}

Measured memory_bytes: 8816
package main

import (
	"fmt"
	"math"
)

const th = math.Pi * 60.0 / 180.0

type point struct {
	x, y float64
}

func main() {
	n := 0
	fmt.Scanf("%d", &n)

	a := point{0, 0}
	b := point{100, 0}

	fmt.Printf("%.8f %.8f\n", a.x, a.y)
	koch(n, a, b)
	fmt.Printf("%.8f %.8f\n", b.x, b.y)
}

func koch(d int, p1, p2 point) {
	if d == 0 {
		return
	}

	var (
		s point
		t point
		u point
	)

	s.x = (2.0*p1.x + 1.0*p2.x) / 3.0
	s.y = (2.0*p1.y + 1.0*p2.y) / 3.0
	t.x = (1.0*p1.x + 2.0*p2.x) / 3.0
	t.y = (1.0*p1.y + 2.0*p2.y) / 3.0
	u.x = (t.x-s.x)*math.Cos(th) - (t.y-s.y)*math.Sin(th) + s.x
	u.y = (t.x-s.x)*math.Sin(th) + (t.y-s.y)*math.Cos(th) + s.y

	koch(d-1, p1, s)
	fmt.Printf("%.8f %.8f\n", s.x, s.y)
	koch(d-1, s, u)
	fmt.Printf("%.8f %.8f\n", u.x, u.y)
	koch(d-1, u, t)
	fmt.Printf("%.8f %.8f\n", t.x, t.y)
	koch(d-1, t, p2)
}



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

int main(){
    int input;
    bool stu[31]={};
    for(int i=0;i<28;i++){
        cin>>input;
        stu[input]=true;
    }
    for(int i=1;i<=30;i++){
        if(!stu[i]) printf("%d\n",i);
    }
    return 0;
}

Measured memory_bytes: 1144
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    int a, b;cin>>a>>b;
    cout << a*b << endl;
    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


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

int p, q;
map<int,int> m;

int main() {
  while(cin >> p >> q) {
    m.clear();
    p *= 10;
    m[p] = 0;
    string res = "";
    string res2 = "";
    while(p) {
      int d = p/q;
      p = (p - d*q)*10;
      res += d+'0';
      if(m.count(p)) {
        int i = m[p];
        res2 = string(i, ' ') + string(res.size()-i, '^');
        break;
      }
      m[p] = res.size();
    }
    cout << res << endl;
    if(res2.size()) cout << res2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

const int MAX_N = 202;
const int MAX_X = 1e5 + 1;
const ll MOD = 1e9 + 7;

int S[MAX_N];
ll dp[MAX_N][MAX_X];

int main() {
    int N, X;
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    sort(S, S + N);
    reverse(S, S + N);
    dp[0][X] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= X; j++) {
            dp[i + 1][j] = (dp[i + 1][j] + (dp[i][j] * (N - i - 1)) % MOD) % MOD;
            dp[i + 1][j % S[i]] = (dp[i + 1][j % S[i]] + dp[i][j]) % MOD;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= X; i++) {
        ans = (ans + (dp[N][i] * i) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 157184
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  string s;
  cin>>s;
  Int ans=0;
  for(Int i=0;i<n;i++)
    ans+=s.substr(i,3)=="ABC";
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int H,W,h,w;
    cin >> H >> W;
    cin >> h >> w;
    int allcells;
    allcells = H * W;
    int result;
    result = allcells - (h * W) - (w * H) + (h * w);
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;


void solve(long long D, long long G, std::vector<long long> p, std::vector<long long> c){
    vector<int> v(D);
    iota(all(v), 0);

    int ans = 1e9;
    while (true) {
        int solve = 0, score = 0;
        for (auto i: v) {
            int plus_score = 100*(i+1)*p[i] + c[i]; 
            if (score + plus_score <= G) {
                solve += p[i];
                score += plus_score;
            } else {
                int less = G - score;
                long long part_score = 100 * (i + 1);
                if (less > 0) solve += min(p[i], (less+(part_score-1))/part_score);
                break;
            }
        }
        ans = min(ans, solve);
        if (!next_permutation(all(v))) break;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long D;
    scanf("%lld",&D);
    long long G;
    scanf("%lld",&G);
    std::vector<long long> p(D);
    std::vector<long long> c(D);
    for(int i = 0 ; i < D ; i++){
        scanf("%lld",&p[i]);
        scanf("%lld",&c[i]);
    }
    solve(D, G, std::move(p), std::move(c));
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;

const long mod = 1000000007;
const long indlim = 5368709119;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
long fact(long x) { if (x == 0) return 1; else return((fact(x - 1) * x) % mod); }
long mybase(long N, long B) { if (N == 0) return 0; string S = ""; while (N != 0) { string M = to_string(N % B); N -= N % B; N /= B; S = M + S; }return stol(S); }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long long res = 0;
	long long N, M; cin >> N >> M;
	long long A[100009]; for (int i = 0; i < N; i++) cin >> A[i];
	long long a, b;
	vector<pair<long long, long long>> BC; for (int i = 0; i < M; i++) { cin >> b >> a; BC.push_back(make_pair(a, b)); }
	sort(BC.begin(), BC.end(), [&](pair<long long, long long> p, pair<long long, long  long> q) {return p.first < q.first; });

	sort(A, A + N); //最大値はA[N - 1]

	long long Amaxin = N - 1;
	long long BCmaxin = M - 1;
	while (N != 0) {

		if (A[Amaxin] >= BC[BCmaxin].first) { res += A[Amaxin]; Amaxin--; N--; }
		if (A[Amaxin] < BC[BCmaxin].first) { res += BC[BCmaxin].first * min(BC[BCmaxin].second, N); N = N - min(BC[BCmaxin].second, N); BCmaxin--; }

	}
	cout << res << endl;
}

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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int dp[202][10010];

// ???????????§i???????????§????????????????????\???????\???§??????????????????
// ?????????????????????W-w[i]?????????????????????????????¨?????????i+1????????\?????§?\???§?????\??????
// (i??????????????£???????????°???W-w[i]??\?????§?\???§?????????)
// ?????????i+2~N?????§??§?\???§??????i+1???????????\??????????????§???
// (W-sum[i+1]-w[i+1],W-sum[i+1]-w[i]]

// ????????????????????????????????????

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, W; cin >> N >> W;
  vector<int> w(N), sum(N+1, 0);
  rep(i, N) cin >> w[i];
  sort(all(w));
  rep(i, N) sum[i+1] = sum[i] + w[i];
  
  reverse(all(w));  
  dp[0][0] = 1;
  for(int i = 0; i < N; i++) {
    rep(j, W+1) dp[i+1][j] = dp[i][j];
    for(int j = W-w[i]; j >= 0; j--) {
      dp[i+1][j+w[i]] = (dp[i][j+w[i]] + dp[i][j]) % mod;
    }
  }

  reverse(all(w));
  int ans = 0;
  for(int i = 0; i < N; i++) {
    int s = max(0LL, W - sum[i] - w[i] + 1);
    int t = W - sum[i] - (i ? w[i-1] : 0);
    for(int j = s; j <= t; j++) {
      if(j >= 0) ans = (ans + dp[N-i][j]) % mod;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; ++i)
    cin >> p[i];

  sort(p.begin(), p.end());

  int ans;
  for (ans = p[N - 1]; ans >= 1; --ans) {
    int solved = 0;
    for (int i = 0; i < N; ++i)
      if (p[i] >= ans)
        ++solved;
    if (solved >= ans)
      break;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod2 (long long)1000000007
#define mod (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX




void solve()
{
    int n;
    cin >> n;
    int a[n+1], b[n];
    inp(a, n+1);
    inp(b, n);
    int ans = 0;
    rep(i,0,n-1)
    {
        int x = min(a[i], b[i]);
        ans += x;
        a[i] -= x, b[i] -= x;
        x = min(a[i+1], b[i]);
        ans += x;
        a[i+1] -= x, b[i] -= x;
    }

    cout << ans << endl;
}



signed main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

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

int main(){
  char b;
  cin >> b;
  switch(b){
    case 'A':
      b = 'T';
      break;
    case 'T':
      b = 'A';
      break;
    case 'C':
      b = 'G';
      break;
    case 'G':
      b = 'C';
      break;
  }
  
  cout << b << endl;
  
  return 0;
}

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



int main() 
{ 
	
	int H,W,K;
	cin>>H>>W>>K;
	int grid[H][W];
	for(int i=0;i<H;i++){
		string s;
		cin>>s;
		char mevan[W+1];
		strcpy(mevan, s.c_str());
		for(int j =0;j<W;j++){
			grid[i][j] = mevan[j] - '0';
		//	cout<<mevan[j]<<" ";
		}
		//cout<<endl;
	}
//	for(int x= 0;x<H;x++){
//			for(int xx =0;xx<W;xx++){
//				cout<<grid[x][xx]<<" ";
//			}
//			cout<<endl;
//		}
    int a = 1;
    for(int j=0;j<H-1;j++){
    	a = a*2;
	}
	int mini = 10000;
	for(int j=0;j<a;j++){
	//	cout<<j<<endl;
		vector<int> mev(H-1,0);
		int c = j;
		int i =0;
		while(c>0){
			mev[i] = c%2;
			c = c/2;
			i++;
		}
		vector<int> cuts;
		cuts.push_back(-1);
		int cm =0;
		for(int x = 0 ;x<H-1;x++){
			if(mev[x]){
				cm++;
				cuts.push_back(x);
			}
		}
		cuts.push_back(H-1);
//		for(int o=0;o<cuts.size();o++){
//			cout<<cuts[o]<<" ";
//		}
//		cout<<endl;
		vector<vector<int> > fin;
		
		for(int p = 0 ;p<W;p++){
			vector<int> temp;
			for(int x =1 ;x<cuts.size();x++){
				int sm = 0;
				for(int u = cuts[x-1]+1;u<=cuts[x];u++){
					if(grid[u][p] == 1){
						sm = sm + 1;
					}
				}
				temp.push_back(sm);
			}
			fin.push_back(temp);
		}
		int  y = fin[0].size();
//		for(int x=0;x<y;x++){
//			for(int xx=0;xx<W;xx++){
//				cout<<fin[xx][x]<<" ";
//			}
//			cout<<endl;
//		}
		int mm = 0;
		vector<int> suma(y,0);
		int can = 1;
		for(int i =0;i<W;i++){
			int broken =0;
			for(int ii =0;ii<y;ii++){
				if(suma[ii] + fin[i][ii]>K){
					mm++;
					broken =1;
					break;
					
				}
				else{
					suma[ii] = suma[ii] + fin[i][ii];
				}
			}
			if(broken){
				for(int o =0;o<y;o++){
					suma[o] = fin[i][o];
					if(suma[o]>K){
						can = 0;
						break;
					}
				}
			}
			if(!can){
				break;
			}
		}
		//cout<<cm<<" cm "<<mm<<endl;
		if(can){
			if(cm+mm<=mini){
				mini = cm + mm;
			}
		}
	}
	cout<<mini<<endl;

	
    return 0; 
} 


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

int main()
{
    string N;
    cin >> N;
    bool flag = false;
    rep(i,3){
        if(N.at(i) == '7'){
            cout << "Yes" << endl;
            flag = true;
            break;
        }
    }
    if(flag == false){
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3612
# ABC163b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a = sum(a)
    print(max(-1, n-a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 66692