akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations

n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = - 10 ** 18
for i in range(1, 11):
    for pat in combinations(range(10), i):
        cnt = [0] * n
        for e in pat:
            for j in range(n):
                cnt[j] += f[j][e]

        score = 0
        for i, e in enumerate(cnt):
            score += p[i][e]

        ans = max(ans, score)

print(ans)


Measured memory_bytes: 9228
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;

int main(){
  int a,b,c; cin>>a>>b>>c;
  if(a==b and b != c){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(a==c and b != c){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(c==b and b != a){
    cout<<"Yes"<<endl;
    return 0;
  }

  cout<<"No"<<endl;
  return 0;

}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
int s[1311][7],t[7],cnt,a[11][11];
int n,m,k;
void dfs(int x)
{
    //printf("x=%d,t=%d\n",x,t[x-1]);
    if(x==4)
    {
        for(int i=0;i<4;i++)
        s[cnt][i]=t[i];
        cnt++;
        return;
    }
    for(int i=1;i<7;i++)
    {
        t[x]=i;
        dfs(x+1);
    }
}
void init()
{
    int i,j;
    cnt=0,dfs(0);
//    for(i=0;i<cnt;i++)
//    {
//        if(s[i][0]==5&&s[i][1]==2&&s[i][2]==3&&s[i][3]==2)
//        printf("i=%d\n",i);
//    }
}
struct node
{
    int x,y;
}re[111];
int dir[4][2]={1,0,-1,0,0,1,0,-1};
int solve(int x)
{
    int i,j,tt,l;
    int b[11][11],flag[11][11];
    node st,t1,t2;
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)b[i][j]=a[i][j];
    queue<node>q;st.x=st.y=1;l=1;re[0]=st;
    memset(flag,0,sizeof(flag));flag[st.x][st.y]=1;
    for(int i1=0;i1<6;i1++)
    {
        if(i1<4)tt=s[x][i1];
        else tt=k;
        for(j=0;j<l;j++)
        q.push(re[j]);
//        if(x==913)
//        {
//            printf("ii=%d,l=%d\n",i1,l);
//            for(j=0;j<l;j++)
//            printf("%d %d %d\n",re[j].x,re[j].y,b[re[j].x][re[j].y]);
//        }
        while(!q.empty())
        {
            t1=q.front();q.pop();
            for(i=0;i<4;i++)
            {
                if(t1.x+dir[i][0]>0&&t1.x+dir[i][0]<=n&&t1.y+dir[i][1]>0&&t1.y+dir[i][1]<=m)
                {
                    t2.x=t1.x+dir[i][0];t2.y=t1.y+dir[i][1];
                    if(!flag[t2.x][t2.y]&&b[t2.x][t2.y]==b[t1.x][t1.y])
                    {
                        q.push(t2);re[l++]=t2;
                        flag[t2.x][t2.y]=1;
                    }
                }
            }
        }
        for(j=0;j<l;j++)
        b[re[j].x][re[j].y]=tt;
    }
    return l;
}
int main()
{
   //freopen("c.in","r",stdin);
//    freopen("c.out","w",stdout);
     int i,j,ans;
     init();
     while(scanf("%d%d%d",&n,&m,&k)==3)
     {
         if(n==0&&m==0&&k==0)break;
         for(i=1;i<=n;i++)
         for(j=1;j<=m;j++)
         scanf("%d",&a[i][j]);ans=0;
         for(i=0;i<cnt;i++)
             ans=max(ans,solve(i));
         printf("%d\n",ans);
     }
     return 0;
}

Measured memory_bytes: 1228
//
// Created by Myabu on 2020/01/25.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int A,B,C;
    
    cin>>A>>B>>C;
    
    if(A==B){
        cout<<C<<endl;
    }else if(A==C){
        cout<<B<<endl;
    }else{
        cout<<A<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int H, W, K;
string arr[6];
string backup[6];

void color_col(int n) {
	for (int i = 0; i < H; i++) arr[i][n] = 'R';
}

void color_row(int n) {
	for (int i = 0; i < W; i++) arr[n][i] = 'R';
}

int count_black() {
	int ret = 0;
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++)
			if (arr[i][j] == '#') ret++;
	return ret;
}

void print() {
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)
			cout << arr[i][j];
		cout << '\n';
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++) cin >> arr[i];

	int ans = 0;
	for (int i = 0; i <= (1 << H) - 1; i++)
		for (int j = 0; j <= (1 << W) - 1; j++) {
			for (int k = 0; k < H; k++) backup[k] = arr[k];

			for (int k = 0; k < H; k++) if (i & (1 << k)) color_row(k);
			for (int k = 0; k < W; k++) if (j & (1 << k)) color_col(k);
			if (count_black() == K) {
				ans++;
			}

			for (int k = 0; k < H; k++) arr[k] = backup[k];
		}
	cout << ans << '\n';
	return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll N = 0;
    Scll(N);

    ll ans = N*(N-1)/2;
    printf ("%lld\n", ans );

    return 0;
}





Measured memory_bytes: 256
(declaim (optimize (speed 3) (debug 0) (safety 0)))

;;cyclone-loop
(defun cyclone-reader (stream char)
  (declare (ignore char))
  `(loop ,@(read stream t nil t) do ,(read stream t nil t)))
(set-macro-character #\CYCLONE #'cyclone-reader)
;;

(let ((a (* (read) 100))
      (b (* (read) 100))
      (c (read))
      (d (read))
      (e (read))
      (f (read)))
  (declare (fixnum a) 
           (fixnum b)
           (fixnum c)
           (fixnum d)
           (fixnum e)
           (fixnum f))
  🌀 (for an to (truncate f a)
             :with max rational  = -1
             :with amax fixnum = -1
             :with smax fixnum = 0
             :finally (format t "~A ~A~%" amax smax)) 
  🌀 (for bn to (truncate (- f (* an a)) b))
  🌀 (for cn to (truncate (- f (+ (* an a) (* bn b))) c))
  🌀 (for dn to (truncate (- f (+ (* an a) (* bn b) (* cn c))) d)
             :for s fixnum = (+ (* cn c) (* dn d))
             :for w fixnum = (+ (* an a) (* bn b))
             :for all fixnum = (+ w s))
  (when (and (not (zerop all))
             (> (/ s all) max)
             (<= all f)
             (<= (* s 100) (* e w)))
        (setf max (/ s all))
        (setf amax all)
        (setf smax s)))

Measured memory_bytes: 55656
/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  2020.07.14

 * Solution:
  不妨考虑求最小的满足条件的生成树的权值和 >= X 的方案数。那么这个限制就是要求所有权值和
小于 X 的生成树的边的颜色都必须相同。
  不难发现可以把边分为两类：一类是自由边，一类是非自由边，一条边是非自由边当且仅当存在一
颗权值和小于 X 的生成树包含了该边。那么所有非自由边必须染一种颜色，每条自由边可以随意染
色，总方案数就是 2^min(k + 1, m) ，其中 k 是自由边数量。
  求自由边数量只需要暴力判断每条边是否是自由边，也就是对于每条边 e 求出包含 e 的最小生成
树即可。

 * Digression:
  复杂度 O(m^2 a) ，其中 a 是并查集均摊复杂度。但是显然求包含 e 的最小生成树是有更优秀的
做法的。

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct _{
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
} read;

const int maxn = 2020, mod = 1000000007;
struct Edge {
	int u, v, w;
} e[maxn];
int fa[maxn];

ll power (ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

bool cmp (Edge a, Edge b) { return a.w < b.w; }

int find (int x) {
	if (fa[x] == x) return x;
	return fa[x] = find(fa[x]);
}

ll calc (int n, int m, int id) {
	for (int i = 1; i <= n; i ++) fa[i] = i;
	fa[e[id].u] = e[id].v;
	ll sum = e[id].w;
	for (int i = 1; i <= m; i ++) {
		int x = find(e[i].u), y = find(e[i].v);
		if (x != y) {
			fa[x] = y;
			sum += e[i].w;
		}
	}
	return sum;
}

int main () {
	int n = read, m = read;
	ll X = read;
	for (int i = 1; i <= m; i ++) {
		e[i].u = read;
		e[i].v = read;
		e[i].w = read;
	}
	std::sort(e + 1, e + m + 1, cmp);
	int a = 0, b = 0;
	for (int i = 1; i <= m; i ++) {
		ll s = calc(n, m, i);
		/* debug("%lld\n", s); */
		if (s >= X) ++ a;
		if (s > X) ++ b;
	}
	a = std::min(a + 1, m);
	b = std::min(b + 1, m);
	printf("%lld\n", (power(2, a) - power(2, b) + mod) % mod);
}



Measured memory_bytes: 3260
#include <cstdio>
#include <cstdlib>

int main(void){
    char s[5];
    char a[3],b[3];
    scanf("%s",s);
    a[0] = s[0];
    a[1] = s[1];
    a[2] = '\0';
    b[0] = s[2];
    b[1] = s[3];
    b[2] = '\0';
    int c = atoi(a);
    int d = atoi(b);
    bool ym,my;
    if(c==0||c>12){
        if(d==0||d>12){
            printf("NA\n");
        }else{
            printf("YYMM\n");
        }
    }else{
        if(d==0||d>12){
            printf("MMYY\n");
        }else{
            printf("AMBIGUOUS\n");
        }
    }
    return 0;
}


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


using namespace std;
using ll = long long;


int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);

    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());
    ll max_a = *(A.end() - 1);
    vector<ll> count(max_a + 1, 0);
    for (auto a : A) {
        if (count[a] != 0) {
            count[a]++;
            continue;
        }
        for (ll i = a; i <= max_a; i += a) {
            count[i]++;
        }
    }

    ll ans = 0;
    for (auto a : A) {
        if (count[a] == 1)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12692
import java.util.*;

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

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

        scan.close();
        return;
    }
}

Measured memory_bytes: 35652
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  int n,m,c;
  cin>>n>>m>>c;
  vector<int>b(m);
  rep(i,m)cin>>b[i];
  int res=0;
  rep(i,n)
  {
    int tc=c;
    rep(j,m)
    {
      int a;
      cin>>a;
      tc+=b[j]*a;
    }
    if(tc>0)res++;
  }
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
   ll n,d;
   cin>>n>>d;
   ll count=0;
   for(ll i=0;i<n;i++){
       ll x,y;
       cin>>x>>y;
       x = x * x;
       y = y * y;
       if(sqrt(x + y) <= d){
           count++;
       }
   }
   cout<<count<<"\n";
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N; cin >> N;
    cout << 180 * (N - 2) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<(n);i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF 2000000000000
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define Int long long
#define hogea pair<pair<int,int>,int>

signed main(){
  int h,w,x,y;
  cin>>h>>w>>x>>y;
  int a[510][510];
  lp(i,h){
    lp(j,w){
      a[i][j]=2000;
    }
  }
  int base=(x*y-1)*2000*(-1)-1;
  for(int i=x-1;i<h;i+=x){
    for(int j=y-1;j<w;j+=y){
      a[i][j]=base;
    }
  }
  int suma=0;
  lp(i,h){
    lp(j,w){
      suma+=a[i][j];
    }
  }
  if(suma>0){
    cout<<"Yes"<<endl;
    lp(i,h){
      lp(j,w){
        if(j!=0)cout<<" ";
        cout<<a[i][j];
      }
      cout<<endl;
    }
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> cnt(n);
    for(int i = 1; i < n; i++){
        int a;
        cin >> a;
        cnt[a-1]++;
    }
    for(auto c : cnt){
        cout << c << endl;
    }
    return 0;
}

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

typedef vector<int> vi;

signed main()
{
    int k;
    cin >> k;
    vi rem(k);
    int num = 7 % k;
    int cnt = 0;
    while (true)
    {
        cnt++;
        if (num == 0)
        {
            cout << cnt << endl;
            return 0;
        }
        if (rem[num])
        {
            cout << -1 << endl;
            return 0;
        }
        rem[num]++;
        num *= 10;
        num += 7;
        num %= k;
    }
}

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

using namespace std;

const int N = 100005;

int main() {
    
    int a, b;
    scanf("%d %d", &a, &b);
    for (int i = 1; i <= 3; i++) {
        if (a * b * i % 2 == 1) {
            printf("Yes\n");
            return 0;
        }
    }
    
    printf("No\n");
    
    return 0;
}

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

int main(){
    int sx,sy,tx,ty;
    int x,y,x2,y2;
    cin>>sx>>sy>>tx>>ty;
    x=tx-sx;
    y=ty-sy;
    x2=x+1;
    y2=y+1;
    for(int i=0;i<y;i++){
        cout<<"U";
    }
    for(int i=0;i<x;i++){
        cout<<"R";
    }
    for(int i=0;i<y;i++){
        cout<<"D";
    }
    for(int i=0;i<x;i++){
        cout<<"L";
    }
    cout<<"L";
    for(int i=0;i<y2;i++){
        cout<<"U";
    }
    for(int i=0;i<x2;i++){
        cout<<"R";
    }
    cout<<"D";
    cout<<"R";
    for(int i=0;i<y2;i++){
        cout<<"D";
    }
    for(int i=0;i<x2;i++){
        cout<<"L";
    }
    cout<<"U"<<endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end()
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int n; CI n;
	CO "Christmas";
	REP(i, 25-n) {
		CO " Eve";
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

K, X = map(int, input().split())
rmin = -1* (10 ** 6)
rmax = (10 ** 6)

lmin = max(rmin, X-K+1)
lmax = min(rmax, X+K-1)

ans = str(lmin)
for i in range(lmin+1, lmax+1) :
  ans += " " + str(i)

print (ans)


Measured memory_bytes: 3564
#![allow(unused_macros, unused_imports, dead_code)]

use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn main() {
    from_line!(n: isize, k: isize);
    match n % k {
        0 => println!("0"),
        _ => println!("1"),
    }
}


Measured memory_bytes: 4352
x,k,d = list(map(int, input().strip().split()))
x=abs(x)
y=x//d
if y>=k:
    print(x-k*d)
else:
    z=k-y
    w=x%d
    if w>=d-w:
        if (z-1)%2==0:
            print(d-w)
        else:
            print(w)
    else:
        if z%2==0:
            print(w)
        else:
            print(d-w)
        

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int MAX_W=10;
int w,d;
int hw[MAX_W];
int hd[MAX_W];
void solve(){
  int count=0;
  sort(hw,hw+w);
  sort(hd,hd+d);
  for(int i=w-1,j=d-1;i>=0||j>=0;){
    if(i<0){
      count+=hd[j];
      j--;
    }else if(j<0){
      count+=hw[i];
      i--;
    }else if(hw[i]==hd[j]){
      count+=hw[i];
      i--;j--;
    }else if(hw[i]>hd[j]){
      count+=hw[i];
      i--;
    }else{//hw[i]<hd[j]
      count+=hd[j];
      j--;
    }
  }
  cout<<count<<endl;
}
int main(){ _;
  while(cin>>w>>d,(w|d)!=0){
    REP(i,w)cin>>hw[i];
    REP(i,d)cin>>hd[i];
    solve();
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vint a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(rall(a));
    vpair p(m);
    rep(i, m) {
        cin >> p[i].se >> p[i].fi;
    }
    sort(rall(p));

    int p_sz = p.size();
    ll ans = 0;
    int idx1 = 0, idx2 = 0;
    rep(i, n) {
        if (p[idx2].se <= 0) idx2++;
        if (a[idx1] > p[idx2].fi || idx2 >= p_sz) {
            ans += a[idx1];
            idx1++;
        } else {
            ans += p[idx2].fi;
            p[idx2].se--;
        }
    }

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

Measured memory_bytes: 1408
#!/usr/local/gnu/bin/bash
read h w
s=(`tr '.#' '01'`)
for i in `seq 0 $((h-1))`
do
    for j in `seq 0 $((w-1))`
    do
        if((${s[i]:j:1}))
        then
            echo -n "#"
            continue
        fi
        c=0
        if((i>0))
        then
            ((j>0)) && c=$((c+${s[i-1]:j-1:1}))
            c=$((c+${s[i-1]:j:1}))
            ((j<w-1)) && c=$((c+${s[i-1]:j+1:1}))
        fi
        ((j>0)) && c=$((c+${s[i]:j-1:1}))
        ((j<w-1)) && c=$((c+${s[i]:j+1:1}))
        if((i<h-1))
        then
            ((j>0)) && c=$((c+${s[i+1]:j-1:1}))
            c=$((c+${s[i+1]:j:1}))
            ((j<w-1)) && c=$((c+${s[i+1]:j+1:1}))
        fi
        echo -n $c
    done
    echo
done


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

//vector <long long> v;

//stack <long long> s[1000000], wym;

//queue <long long> s;

long long int  x[1000000], y, z;
char s1[1000000], s2[1000000];

int main()
{
    long long int a, b, c, d, k, l, i, j, q, t, p, n, m=131072, w, r;

    t=1;
    //scanf("%lld", &t);
    for(q=0; q<t; q++)
    {
        scanf("%lld%lld", &n, &k);

        for(i=0; i<n; i++)
        {
            scanf("%lld", &x[i]);
            if(i>=k)
            {
                if(x[i]>x[i-k])printf("Yes\n");
                else printf("No\n");
            }
        }
    }
    return(0);
}


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

int main(){
  ll S;
  cin >> S;
  
  ll N = 4000;
  vector<vector<ll>> pascal(N + 1, vector<ll>(N + 1));
  pascal.at(0).at(0) = 1;
  for (int i = 1; i < N + 1; i++){
    pascal.at(i).at(0) = 1;
    pascal.at(i).at(i) = 1;
    for (int j = 1; j < i; j++){
      pascal.at(i).at(j) = pascal.at(i - 1).at(j - 1) + pascal.at(i - 1).at(j);
      pascal.at(i).at(j) %= 1000000007;
    }
  }
  
  ll ans = 0, num = 0;
  S -= 3;
  while (S >= 0){
    ans += pascal.at(S + num).at(num);
    ans %= 1000000007;
    //cout << pascal.at(S + num).at(num) << endl;
    S -= 3;
    num++;
  }
  
  if (ans < 0){
    ans += 1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 128392
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int x;cin>>x;
	if(x==7||x==5||x==3)puts("YES");
	else puts("NO");
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,M;
ll mo=998244353;

ll modpow(ll a, ll n=mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll fib(ll k,ll a1=1,ll a2=1) {
	ll R[2][2]={{1,0},{0,1}};
	ll A[2][2]={{1,1},{1,0}};
	k--;
	
	while(k) {
		ll S[2][2], T[2][2];
		if(k%2) {
			S[0][0]=(A[0][0]*R[0][0]+A[0][1]*R[1][0])%mo;
			S[0][1]=(A[0][0]*R[0][1]+A[0][1]*R[1][1])%mo;
			S[1][0]=(A[1][0]*R[0][0]+A[1][1]*R[1][0])%mo;
			S[1][1]=(A[1][0]*R[0][1]+A[1][1]*R[1][1])%mo;
			swap(S,R);
		}
		T[0][0]=(A[0][0]*A[0][0]+A[0][1]*A[1][0])%mo;
		T[0][1]=(A[0][0]*A[0][1]+A[0][1]*A[1][1])%mo;
		T[1][0]=(A[1][0]*A[0][0]+A[1][1]*A[1][0])%mo;
		T[1][1]=(A[1][0]*A[0][1]+A[1][1]*A[1][1])%mo;
		swap(T,A);
		k>>=1;
	}
	return (R[1][0]+R[1][1])%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	
	M+=2*(N-1);
	ll F=fib(M);
	
	ll a=1,b=1,c=1;
	ll M1=M-1,M2=M1;
	for(i=1;i<N;i++) {
		F=(F+mo-b*modpow(a*c%mo)%mo)%mo;
		
		(a*=M1)%=mo;
		M1=(M1+mo-1)%mo;
		(b*=M2)%=mo;
		M2=(M2+mo-1)%mo;
		(b*=M2)%=mo;
		M2=(M2+mo-1)%mo;
		(c*=i)%=mo;
	}
	cout<<F<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
double dp[3000][3000];

void _main()
{
    int N;
    cin >> N;
    vector<double> p(N);
    rep(i, 0, N) cin >> p[i];

    dp[0][0] = 1.0;
    rep(i, 0, N)
    {
        rep(j, 0, N)
        {
            // 表
            dp[i + 1][j + 1] += dp[i][j] * p[i];

            // 裏
            dp[i + 1][j] += dp[i][j] * (1 - p[i]);
        }
    }

    double ans = 0.0;
    rep(i, (N + 1) / 2, N + 1)
    {
        ans += dp[N][i];
    }
    printf("%.12lf\n", ans);
}


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

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

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

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

vi prime(int n){ // n以下の素数を要素に持つviを返す
  vector<bool> isprime(n+1,true);
  vi ans;
  isprime[0] = isprime[1] = false;
  FOR(i,2,n+1)
    if(isprime[i]){
      ans.pb(i);
      for(int j = 2 * i; j <= n; j += i) isprime[j] = false;
    }
  return ans;
}

main()
{
  vi p = prime(1000000);
  while(1){
    int a,d,n; cin >> a >> d >> n;
    if(a == 0) break;
    int c = 0, i = 0;
    while(1){
      int tmp = a + d * i;
      if(binary_search(all(p),tmp)) c++;
      if(c == n){
	cout << tmp << endl;
	break;
      }
      i++;
    }
  }
}



Measured memory_bytes: 3868
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[200];ll visit[300]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
string s,t;
ll sum = 0;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	ll l,n;
	ll act , sum , diff = INT_MAX, cou = 0, ans;
	cin >> n >> l;
	act = n*(2*l + (n-1))/2;
	sum = act;
	//cout<<act<<" ";
	while(cou<n) {	
		ll val = l + (cou);
		ll other = sum - val;

		if(abs(act - other) < diff) {
			ans = other;
			diff = abs(act - other);
		}
		cou++;
	}
	cout<<ans;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


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

using namespace std;

bool is(char c){
	if (isupper(c)){
		return true ;
	}
   return 0;
}

int main()
{
char c;
  cin >> c;
  if (is(c))
  {
cout << 'A' ;
  }
  else {
  cout << 'a' ; 
  }

}


Measured memory_bytes: 3648
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N = 100000 + 5;
typedef long long ll;

int a[N];

int main()
{
    int n;
    while(scanf("%d",&n) == 1)
    {
        int cnt = 0;
        for(int i=1;i<=n;i++)
        {
            int t;
            scanf("%d",&t);
            if(t & 1) cnt++;
        }
        puts(cnt % 2 == 0 ? "YES" : "NO");
    }
    return 0;
}

Measured memory_bytes: 128
while True:
    N, T, L, B = map(int, input().split())
    if not (N | T | L | B):
        break

    Lose = [False for i in range(N + 1)]
    Back = [False for i in range(N + 1)]
    for i in range(L):
        Lose[int(input())] = True

    for j in range(B):
        Back[int(input())] = True

    dp = [[0.0 for j in range(N + 1)] for i in range(T + 2)]
    dp[0][0] = 1.0

    # 現在地
    for t in range(T):
        # ターン数
        for n in range(N):
            # サイコロ
            for k in range(1, 7):
                tmp = n + k
                if n + k > N:
                    tmp = N - n - k - 1
                if Lose[tmp]:
                    dp[t + 2][tmp] += dp[t][n] / 6
                elif Back[tmp]:
                    dp[t + 1][0] += dp[t][n] / 6
                else:
                    dp[t + 1][tmp] += dp[t][n] / 6

    ans = 0.0
    for i in range(T + 2):
        ans += dp[i][N]
    print("{0:.6f}".format(ans))



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

int main(void){
	int n, q, num=0, a;
	long S[10001], T[501];
	
	std::cin >> n;
	for(int i=0; i<n; i++){
		std::cin >> S[i];
	}
	
	std::cin >> q;
	for(int i=0; i<q; i++){
		std::cin >> T[i];
	}
	
	for(int i=0; i<n; i++){
		for(int j=0; j<q; j++){
			a = 0;
			for(int k=0; k<i; k++){
				if(S[i] == S[k]){
					a = 1;
				}
			}
			
			if(a>=1){
				break;
			}
			if(S[i] == T[j]){
				num+=1;
				break;
			}
		}
	}
	
	cout << num << "\n";
	
	return 0;
}



Measured memory_bytes: 3108
N,K=map(int, input().split())
mod=1000000007
A=[i for i in range(N+1)]
ans=0

S=[0]*(N+1)
for i in range(1,N+1):
    S[i]=S[i-1]+A[i]

for k in range(K,N+1):
    MIN=S[k-1]
    MAX=S[N]-S[N-k]
    ans+=(MAX-MIN+1)%mod
    ans%=mod
print(ans+1)



Measured memory_bytes: 84384
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair <LL, int> P;
const int Maxn = 2e5 + 5;
LL a[Maxn], f[Maxn];
int n;
LL k;
P vec[Maxn];
bool check(LL x){
    LL cnt = 0;
    for (int i = n; i >= 1; i--){
        if (vec[i].first <= x) return true;
        cnt += (vec[i].first - x - 1) / vec[i].second + 1;
        if (cnt > k) return false;
    }
    return true;
}
int main(){
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &f[i]);
    sort(a + 1, a + n + 1);
    sort(f + 1, f + n + 1);
    for (int i = 1; i <= n; i++){
        vec[i] = P(f[i] * a[n + 1 - i], f[i]);
    }
    sort(vec + 1, vec + n + 1);
    LL l = 0, r = vec[n].first;
    while(l < r){
        LL m = (l + r) >> 1;
        if (check(m))
            r = m;
        else
            l = m + 1;
    }
    cout << l << endl;
}

Measured memory_bytes: 6528
<?php
// C
fscanf(STDIN, '%d %d %d %d', $a, $b, $h, $m);
$y = $m / 60;
$x = ($h + $y) / 12;
$rad = deg2rad(($x - $y) * 360);
$ans = sqrt($a ** 2 + $b ** 2 - 2 * $a * $b * cos($rad));
echo $ans;

Measured memory_bytes: 16492
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
#define re register
using namespace std;
struct ios{
	template <typename ty> inline ios& operator >> (ty &x)
	{
		register int f=1;x=0;register char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
		x*=f;return *this;
	}
	template <typename ty>  inline ios& operator << (ty x)
	{
		if(x<0) x=-x,putchar('-');
		if(x>9) *this << x/10;
		putchar(x%10+48);
		return *this;
	}
	inline ios& operator << (char x){putchar(x);return *this;}
}io;
const int N = 10086;
int a,b;
int main()
{
	io>>a>>b;
	io<<(int)ceil(1.0*a/(2*b+1));
	
	return 0;
}

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

#define PB emplace_back

using namespace std;

const int N = 5e5+100;

int par[N], h[N];

int fat(int x) {
    while(x != par[x]) x = par[x];
    return x;
}

void add(int u, int v) {
    u = fat(u);
    v = fat(v);
    if(u != v) {
        if(h[u] > h[v]) swap(u, v);
        h[u] = max(h[u], h[v] + 1);
        par[v] = u;
    }
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, m;
    cin >> n >> m;
    iota(par, par + n , 0);
    while(m--) {
        int t, u1, u2;
        cin >> t >> u1 >> u2;
        if(t) cout << (fat(u1) == fat(u2)) << '\n';
        else add(u1, u2);
    }
}


Measured memory_bytes: 5036
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	long long int a1=1,a2=2,n;
 	cin >> n;
 	long long int a3=a1;
 	for (int i = 0; i < n-1; i++){
 		a3=a1;
 		a1=a1+a2;
 		a2=a3;
 	}
 	if(n==1){
 		cout << 1 << endl;
 	}else{
 		cout << a1<< endl;
 	}
 }


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

int main()
{
	int N;
	cin >> N;
	int now = 1;
	rep(i,N)
	{
		cin >> a[i];
		if (a[i] == now)
		{
			now++;
		}
	}

	if (now == 1)
	{
		cout << "-1" << endl;
	}
	else
	{
		cout << N - now + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
def acinput():
    return list(map(int, input().split(" ")))


import numpy as np

N,K=acinput()
p=np.array(acinput())

pp=(p+1)/2

pp=np.insert(pp,0,0)
p_cs=np.cumsum(pp)

res=0

for i in range(K,N+1):
    res=max(res,(p_cs[i]-p_cs[i-K]))
    #tmp = (p[i:(i+K)]+1)/2
    #res = max(res, np.sum(tmp))


print(res)

Measured memory_bytes: 33964
/*
    quid-pro-quo: LOGIC for AC
    written by: codercell07
    LANG: C++
*/
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false), cin.tie(NULL)
#define testcases freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define asc(x) sort(all(x))
#define desc(x) sort(all(x), greater<int>())
using namespace std;
const int MAX=1e6, M=1e9+7;
const int mod = 998244353;
 
void explore(int i, vi &visited, vvi &v){
    visited[i]=1;
    for(int u: v[i]){
        if(!visited[u])
            explore(u, visited, v);
    }
}
void solve(){
    int n, m; cin>>n>>m;
    vvi v(n, vi());
    for(int i=0; i<m; i++){
        int x, y; cin>>x>>y;
        v[x-1].pb(y-1);
        v[y-1].pb(x-1);
    }
    int cnt=0;
    vi visited(n), arr;
    for(int i=0; i<n; i++){
        if(!visited[i]){
            explore(i, visited, v);
            arr.pb(i+1);
            cnt++;
        }
    }
    cout<<cnt-1;
    
}
int main(){
    fastio;
    // #ifndef ONLINE_JUDGE
    //     testcases;
    // #endif // !DEBUG
 
    //int t; cin>>t; while(t--) solve();
    solve();
    return 0;
}
//check for constraints, mainly array!
//check for integer overflow, use long long!

Measured memory_bytes: 10320
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    string s;
    cin >> s[0] >> s[1] >> s[2];
    int a = atoi(s.c_str());
    cout << (a % 4 == 0 ? "YES" : "NO") << endl;
    return 0;
}

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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int N;
    ll cnt = 0;
    cin >> N;
    vector <int> a(N+1, 0), b(N, 0);
    for (int i = 0; i < N+1; i++) cin >> a[i];
    for (int i = 0; i < N; i++) cin >> b[i];

    for (int i = N-1; i >= 0; i--) {
        if (b[i] <= a[i+1]) {
            cnt += b[i];
            a[i+1] -= b[i];
        } else if (b[i] <= a[i+1] + a[i]){
            cnt += b[i];
            a[i] -= b[i] - a[i+1];
            a[i+1] = 0;
        } else {
            cnt += a[i+1] + a[i];
            a[i+1] = 0;
            a[i] = 0;
        }
    }
    cout << cnt << endl;
    
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll A, B;
  IN(A,B);
  if(A<B) swap(A,B);

  if((A-B)%2==0){
    OUT((A+B)/2);
  }else{
    OUT("IMPOSSIBLE");
  }

  return 0;
}


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

int main(void)
{
    char s[101];
    char s1[300];
    char p[101];
    
    scanf("%s", s);
    strcpy(s1, s);
    strcat(s1, s);
    
    scanf("%s", p);
    
    if (strstr(s1, p) != NULL){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    
    return (0);
}




Measured memory_bytes: 2104
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(e;stdin.byLine())
    {
        alias real F;
        F[] s;
        foreach(v;e.split())
        {
            switch(v)
            {
            case "+": s[$-2]+=s[$-1],s.popBack;break;
            case "-": s[$-2]-=s[$-1],s.popBack;break;
            case "*": s[$-2]*=s[$-1],s.popBack;break;
            case "/": s[$-2]/=s[$-1],s.popBack;break;
            default:  s~=v.to!F();break;
            }
        }
        writefln("%.6f",s[0]);
    }
}

Measured memory_bytes: 1132
#include<stdio.h>

int main(void){
  int num;
  int dig;
  int sum = 0;
  scanf("%d", &num);
  int a[4];
  int count=0;
 
  while(num){
    dig = num % 10;
    a[count] = dig;
    num = num / 10;
    count++;
  }
  int i;
  for(i=0;i<3;i++){
    if(a[i]==a[i+1]){
      printf("Bad");
      return 0;
    }
  }
  printf("Good");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
int K;
int solve(int W,int H){
	int ans=0;
	for(int S=0;S<H-1;++S)
		for(int X=1;X<W && 2*K+W-S*X>=0;++X){
			int R=2*K+__gcd(S,W)-S*X-2;
			if(R>=0){
				int p=min(H-1-S,R/W+1);
				if(W*p-__gcd(X,p)-__gcd(W-X,p+S)>R) --p;
				ans+=p;if(S!=0) ans+=p;
			} 
		} 
	return ans;
}
signed main(){
	int W,H;
	cin>>W>>H>>K;
	cout<<solve(W,H)*2+solve(H,W)*2;
	return 0;
} 

Measured memory_bytes: 3636
#include <stdio.h>

int main() {
	int Zx, Xz;
	scanf("%d %d", &Zx, &Xz);
	if (Xz % Zx == 0) {
		printf("%d", Xz + Zx);
		return 0;
		}
		else {
			printf("%d", Xz - Zx);
		}
	return 0;
}

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

const int N = 5 * 1000, M = 200;
int a[N + 10], b[N + 10][M + 10];
ll sum[N + 10][N + 10];

void add(int x1, int y1, int x2, int y2, int d) {
    sum[x1][y1] += d;
    sum[x1][y2 + 1] -= d;
    sum[x2 + 1][y1] -= d;
    sum[x2 + 1][y2 + 1] += d;
}

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

    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n - 1; i++) {
        scanf("%d", &a[i]);
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            scanf("%d", &b[i][j]);
    for(int j = 1; j <= m; j++) {
        vector<int> l(n + 1, 1), r(n + 1, n), s;
        for(int i = 1; i <= n; i++) {
            while(!s.empty() && b[s.back()][j] < b[i][j])
                s.pop_back();
            if(!s.empty())
                l[i] = s.back() + 1;
            s.push_back(i);
        }
        s.clear();
        for(int i = n; i >= 1; i--) {
            while(!s.empty() && b[s.back()][j] < b[i][j])
                s.pop_back();
            if(!s.empty())
                r[i] = s.back() - 1;
            s.push_back(i);
        }
        for(int i = 1; i <= n; i++) {
            //cout << l[i] << " " << i << " " << i << " " << r[i] << " " << b[i][j] << "\n";
            add(l[i], i, i, r[i], b[i][j]);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
            //cout << sum[i][j] << " ";
        }
        //cout << "\n";
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ll diff = 0;
        for(int j = i; j <= n; j++) {
            ans = max(ans, sum[i][j] - diff);
            diff += a[j];
        }
    }
    cout << ans << "\n";
    return 0;
}

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

int main(){
	int t, n;
	while(1){
		cin >> t;
		if(t == 0) break;
		cin >> n;
		for(int i = 0;i < n;i++){
			int s, f;
			cin >> s >> f;
			t -= f - s;
		}
		if(t <= 0){
			cout << "OK" << endl;
		}
		else{
			cout << t << endl;
		}
	}
	return 0;
}

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

static const int NIL = -1;

int main()
{
    int n;
    int m;
    cin >> n >> m;

    vector<int> color(n, NIL);
    vector<vector<int>> node_list(n, vector<int>(0));

    int v1, v2;
    rep(i, m)
    {
        cin >> v1 >> v2;
        node_list.at(v1).push_back(v2);
        node_list.at(v2).push_back(v1);
    }

    int count = 0;
    auto paint_color = [&](int s) {
        if (color.at(s) != NIL)
        {
            
            return;
        }

        queue<int> q;
        q.push(s);
        color.at(s) = count;

        while (!q.empty())
        {
            v1 = q.front();
            q.pop();
            
            for (size_t i = 0; i < node_list.at(v1).size(); i++)
            {
                if (color.at(node_list.at(v1).at(i)) == NIL)
                {
                    q.push(node_list.at(v1).at(i));
                    color.at(node_list.at(v1).at(i)) = count;
                }
            }
        }

        count++;
    };

    rep(i, n)
    {
        paint_color(i);
    }

    int w;
    cin >> w;
    rep(i, w)
    {
        cin >> v1 >> v2;
        if(color.at(v1)==color.at(v2))
        {
            cout << "yes" << endl ;
        }
        else
        {
            cout << "no" << endl ;
        }
        
    }
    
    return 0 ;
}


Measured memory_bytes: 8608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//ifstream in("input.txt");
	//cin.rdbuf(in.rdbuf());
	ll n;
	cin >> n;
	set<ll> se;
	FOR(i,0,n){
		ll a;
		cin >> a;
		if(se.count(a))se.erase(a);
		else se.insert(a);
	}
	cout << se.size() << endl;
}


Measured memory_bytes: 4992
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] c = sc.next().toCharArray();
		for (int i=0; i<c.length/2; i++) {
			if (c[i] != c[c.length-1-i]) { 
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


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

int main(){
  int N;
  cin >> N;
  //vector<int> vec(N);
  vector<int> vec(N*3);
  for(auto& v : vec){
    cin >> v;
  }
  sort(vec.begin(), vec.end(), greater<int>());
  //int ans = 0;
  long ans = 0;
  int count = N;
  bool second = false;
  for(auto& v : vec){
    if(second == false){
      second = true;
    }
    else{
      ans += v;
      second = false;
      --count;
      if(count == 0){
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main()
{   long long int n,ans=0,r=0,b=0,g=0;
    string s(5000,'\0');
     cin>>n;
     scanf("%s",&s[1]);
     for(long long int i=1;i<=n;i++)
     {  if(s[i]=='R')r++;
        if(s[i]=='B')b++;
        if(s[i]=='G')g++;
     }
     long long int sum=r*b*g;
     for(long long int i=1;i<=n;i++)
     {  for(long long int k=i+2;k<=n;k++)
         {
             long long int j=i+k;
             //printf("%d %d %d\n",i,k,j);
             if(j%2==1)continue;
             j=j/2;
             if(s[i]!=s[k]&&s[i]!=s[j]&&s[k]!=s[j])sum--;

         }
     }
     cout<<sum;


    return 0;
}


Measured memory_bytes: 3700