akhauriyash/Code-Regression huggingface dataset:
n = gets.chomp.to_i
#k,x = gets.chomp.split().map(&:to_i)

s = []
n.times do
  s.push gets.chomp.split('').sort.join('')
end

s.sort!

ans = 0
current = ''
count = 0
s.each do |e|
  if current == e
    count += 1
  else
    ans += count * (count - 1) / 2 if count >= 2
    current = e
    count = 1
  end
end
ans += count * (count - 1) / 2 if count >= 2


puts ans


Measured memory_bytes: 27640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
//#define len length()
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect 

void solve() {
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << a[k - 1];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 256
def main():
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    p = p[:X]
    q = q[:Y]

    apple = list()
    apple.extend(p)
    apple.extend(q)
    apple.extend(r)

    apple.sort(reverse=True)
    ans = 0
    for i in range(X+Y):
        ans += apple[i]

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  double dif;
  double difradi=0.0;
  double ans=0.0;
  
  dif = abs(30*(H+M/60)-M*6);
  if(dif>180) dif = 360-dif;
  difradi = dif*M_PI/180;
  //cout << dif << endl;
  //cout << difradi << endl;
  ans = sqrt(A*A+B*B-2*A*B*cos(difradi));
  cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 4208
#include<iostream>
using namespace std;
int fast_exp(int x,int p)
{
    int res = 1;
    while(p)
    {
        res = res*x;
        x = x*x;
        p>>=1;
    }
    return res;
}
int main()
{
    int n;
    cin>>n;
    cout<<(fast_exp(n,3))<<"\n";
    return 0;
}


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

double Cal(int n, double d, double x)
{
	if(n == 1)
	{
		return (d + d + x) / 2;
	}
	return Cal(n - 1, d * (n + 1) / n + x * 5 / (n * 2), x * (n + 2) / n) + (d + d +(n * 2 - 1) * x) / 2;
}
int n;
double d, x;


int main()
{
	scanf("%d%lf%lf", &n, &d, &x);
	printf("%.15f\n", Cal(n, d, x));
	return 0;
}

Measured memory_bytes: 6528
class UnionFind:
    def __init__(self,size):
        self.par = list(range(size))
        self.rank = [0]*size
        self.sizeof = [1]*size 
    def find(self,x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                tmp = self.sizeof[x]
                self.par[x] = y
                self.sizeof[y] += tmp
            else:
                tmp = self.sizeof[y]
                self.par[y] = x
                self.sizeof[x] += tmp
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
    def same(self,x,y):
        return self.find(x) == self.find(y)
    def sizeOf(self,x): 
        return self.sizeof[self.find(x)]
N,M = map(int,input().split())
ab = []
for i in range(M):
    a,b = map(int,input().split())
    ab.append((a,b))
uf = UnionFind(N+1)
ans = [0]*M
ans[M-1] = N*(N-1)//2
for i in range(M):
    a,b = ab[M-1-i][0],ab[M-1-i][1]
    if i != M-1:
        if uf.same(a,b):
            ans[M-2-i] = ans[M-1-i]
        else:
            ans[M-2-i] = ans[M-1-i] - uf.sizeOf(a)*uf.sizeOf(b)
            uf.union(a,b)
for i in range(M):
    print(ans[i])

Measured memory_bytes: 24088
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int maxn=51;
set<int> v[maxn];
void compare(int a,int b);
int main()
{
   int n,a,b;
   scanf("%d%d%d",&n,&a,&b);
   if(n==1)
   {
       if(a==b)
        printf("1\n");
       else
       {
           printf("0\n");
       }
   }
   else
   {
       if(a>b)
        printf("0\n");
       else
        printf("%lld\n",(long long)(b-a)*(n-2)+1);
   }
    return 0;
}




Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

now_h = H[0]
e = 0
for h in H:
    if h - now_h == -1:
        if e > h:
            print('No')
            exit()
        else:
            e = h
            now_h -= 1
    elif h - now_h < -1:
        print('No')
        exit()
    now_h = h

print('Yes')

Measured memory_bytes: 14224
/*
=============================================================

------------------Welcome To My Code-------------------------

---------Ankit Kumar || IIITBH || CSE || 2018-2022-----------

=============================================================
*/

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
map<ll, ll>::iterator itr;
vector<ll>::iterator it, it1;
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;
	ll t;


        ll i,j,k,x,y,z,m,n,a,b,c,c1=0,c2=0,flag=0,sum=0;
	string s1,str;
	map<ll,ll>MAP;
	vector<ll>v;
	set<ll>s;
    cin>>n;
    FOR(i,n)
        cout<<"ACL";


}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();

        long result = 0;
        int max = a[0];
        for(int i = 0; i < n; i++) {
            if (max <= a[i]) max = a[i];
            result += max - a[i];
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 60220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main(){
  string s;
  cin>>s;
  if(s[s.size()-1]=='s') s+="es";
  else s+="s";
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main() {
  double r;
  cin >> r;
  printf("%.6lf", M_PI * r * r);
  cout << " ";
  printf("%.6lf", 2 * M_PI * r);
  cout << endl;
}


Measured memory_bytes: 3236
#include <iostream>
#include <stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn 0x3f3f3f3f
int a[5][105];
int main()
{
    memset(a,0,sizeof(a));
    int N;
    scanf("%d",&N);
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=N;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    a[2][1]+=a[1][1];
    for(int j=2;j<=N;j++)
    {
        a[1][j]+=a[1][j-1];
    }
    for(int j=2;j<=N;j++)
    {
        a[2][j]+=max(a[1][j],a[2][j-1]);
    }
    printf("%d\n",a[2][N]);
    return 0;
}

Measured memory_bytes: 256
/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
using namespace std;
typedef long long ll;
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
const long long mod = 1e9 + 7;
const int N = 1e5 + 5;
int main()
{
        ll a, b, c, k;
        cin >> a >> b >> c >> k;
        if (k % 2 == 1)
        {
                cout << b - a << endl;
        }
        else
        {
                cout << a - b << endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

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

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1234567;
signed main(){
	int n;
	cin>>n;
	int a[110000];
	rep(i,n)cin>>a[i];
	int ans=0;
	rep(i,1,n){
		if(a[i]>a[i-1])ans++;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3908
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-9
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll N;
	scan(N);
	prin(N*(N-1)/2);
	return 0;
}


Measured memory_bytes: 256
from math import sqrt
N = int(input())
flg = False
g = 0
for i in range(1,int(sqrt(2*N))+1):
    if (2*N) % i == 0:
        if abs(i - (2*N//i)) == 1:
            flg = True
            g = (2*N//i)
            break

if not flg:
    print("No")
    exit(0)


print("Yes")
print(g)
e = 2*N//g
output = [[] for _ in range(g)]

k = 0
l = 1
for i in range(1,N+1):
    output[k].append(i)
    output[l].append(i)
    l += 1
    if l == g:
        k += 1
        l = k + 1

for i in range(g):
    print(e , end=" ")
    print(*output[i])



Measured memory_bytes: 9424
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e3 + 5;
int main() {
    abdelrahman010
    ll sum = 0;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= n;j++)
            for(int k = 1;k <= n;k++)
                sum += __gcd(i , __gcd(j , k));
    cout << sum;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{   
    int k;
    cin>>k;
    int ida;
    unsigned long long int ans = 0; 
    for(int i = 1; i <= k; ++i)
    {
        for(int j = 1; j <= k; ++j)
        {
            for(int l = 1; l <= k; ++l)
            {
                ida = __gcd(i,j);
                ans += __gcd(ida, l);    
            }
        }
    }
    cout<<ans<<"\n";
}

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

int main() {
  int A=0, B=0, C=0;
  cin >> A >> B;
  
  for(int i=A; i<=B; i++){
    if(i / 10000 == i % 10){
      if(i / 1000 % 10 == i / 10 % 10){
        C += 1;
      }
    }
  }
  cout << C << endl; 
}

Measured memory_bytes: 3640
#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>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const int INF = 2147483647;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int x,n;cin >> x >> n;
    vector<int> p(n),a;
    rep(i,n) cin >> p[i];
    for(int i=0;i<300;i++){
	bool ok = true;
	for(int j=0;j<n;j++){
	    if(p[j]==i-120) ok = false;
	}
	if(ok)a.push_back(i-120);
    }

    auto itr = lower_bound(a.begin(),a.end(),x);
    int t = (*itr), k = *(itr-1);
    int ans;
    if(abs(x-k) > abs(t-x)) ans = t;
    else ans = k;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
using namespace std;
 
int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }
    int ans = 12345678;
    int all = 1<<n;
    for(int mask = 0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
  	else cout << ans << endl;
  
}


Measured memory_bytes: 3616
N, M = map(int, input().split())

Q = [list(map(int, input().split())) for _ in range(M)]

if M == 0:
    if N == 1:
        print(0)
    else:
        print(10**(N-1))
    exit()

for i in range(10 ** (N - 1), 10 ** N):
    t = list(str(i))

    f = True
    for s, c in Q:
        f &= t[s - 1] == str(c)

    if f:
        print(i)
        exit()

if N == 1:
    f = True
    for _, c in Q:
        f &= c == 0

    if f:
        print(0)
        exit()

print(-1)


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	ll N;cin>>N;

	ll ans = N-1;

	for(ll i=2;i*i<=N;++i){
		if(N%i==0){
			ans = min(ans,i+(N/i)-2);
		}
	}

	cout << ans << endl;


	return 0;
}




Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        String s = scanner.next();
        int k = scanner.nextInt(), n = s.length();
        System.out.println(new ArrayList<>(IntStream.range(0, n)
                .boxed()
                .flatMap(i -> IntStream.rangeClosed(i + 1, Math.min(i + k, n))
                        .mapToObj(j -> s.substring(i, j)))
                .collect(Collectors.toCollection(TreeSet::new))).get(k - 1));
    }
}

Measured memory_bytes: 31388
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto X = RD;
	long ans, y;
	while (y != 360)
	{
		y %= 360;
		y += X;
		++ans;
	}
	
	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2696
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0

for n in range(N):
  if B[n]<=A[n]:
    ans+=B[n]
  elif B[n]<=A[n]+A[n+1]:
    ans+=B[n]
    A[n+1]-=B[n]-A[n]
  else:
    ans+=A[n]+A[n+1]
    A[n+1] = 0

print(ans)

Measured memory_bytes: 24152
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    rep(i,h){
        rep(j,w)cout<<(i<b xor j<a);
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int n, k, a[112345];
bool flag, tmp;
int res, ans;

int main()
{
	while (true)
	{
		memset(a, 0, sizeof(a));
		res = ans = 1;

		in >> n >> k;
		if (n == 0 && k == 0) { break; }
		rep(i, k) { in >> a[i]; }

		std::sort(a, a + k);
		tmp = flag = (a[0] == 0 ? true : false);
		rep(i, k - 1)
		{
			if (a[i] == 0) { continue; }
			if (a[i] + 1 == a[i + 1]) { ++res; }
			else if (a[i] + 2 == a[i + 1] && tmp)
			{
				res += 2;
				tmp = false;
			}
			else
			{
				ans = std::max(ans, res);
				res = 1;
				tmp = flag;
				if (a[i] + 1 == a[i + 1]) { ++res; }
				else if (a[i] + 2 == a[i + 1] && tmp)
				{
					res += 2;
					tmp = false;
				}
			}
		}
		out << std::max(ans, res) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3488
a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)
price = []
price.append(min(a) + min(b))
for i in range(m):
    price.append(a[x[i]-1] + b[y[i]-1] - c[i])
print(min(price))




Measured memory_bytes: 28076
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

vector<vector<int> >adj;
int vis[100005];
int ind=1;
int parent[100005];

void dfs(int ver,int pr)
{
    parent[ver]=pr;
    vis[ver]=1;
    int cnt=0;
    for(auto i:adj[ver])
    {
        if(!vis[i])
        {
            ++cnt;
            dfs(i,ver);
        }
        else if(vis[i]==2)
        {
            cnt++;
        }
    }
    vis[ver]=2;
    if(cnt==0)
    {
        ind=ver;
        return ;
    }
}

vector<int>path;
int fi=0;
void dfs2(int ver,int pr)
{
    if(fi)
        return ;
    vis[ver]=1;
    parent[ver]=pr;
    int x=0;
    if(!path.empty())
    {
        x=path.back();
        path.pop_back();
        dfs2(x,ver);
    }

    int cnt=0;
    for(auto i:adj[ver])
    {
        if(x!=0 && i==x)
            continue;
        if(!vis[i])
        {
            ++cnt;
            dfs2(i,ver);
        }
        else if(vis[i]==2)
        {
            cnt++;
        }
    }

    if(cnt==0 && fi==0)
    {
        fi=ver;
        return ;
    }
    vis[ver]=2;
}


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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m;
    cin>>n>>m;
    adj.resize(n+1);
    int x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    
    dfs(1,0);
    int ini=ind;
    while (ini!=1)
    {
        path.push_back(ini);
        ini=parent[ini];
    }
    path.push_back(1);
    fill_n(vis,n+1,0);
    reverse(path.begin(),path.end());
    x=path.back();
    path.pop_back();
    dfs2(x,0);
    path.clear();
    while (fi!=ind)
    {
        path.push_back(fi);
        fi=parent[fi];
    }
    path.push_back(fi);
    cout<<path.size()<<'\n';
    for(auto i:path)
        cout<<i<<" ";

} 
    

Measured memory_bytes: 18936
/*input
ataatmma
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 2e5+1;
int mat[N];
vector<int> all[26];
int pos[N];
int n;
int freq[26];
string s;
queue<int> q[26];
int bit[N];
vector<int> actual;
vector<int> res;

void upd(int ind){
	while(ind <= n){
		bit[ind]++;
		ind += ind&(-ind);
	}
}

int sum(int ind){
	int res = 0;
	while(ind){
		res += bit[ind];
		ind -= ind&(-ind);
	}
	return res;
}

int suma(int l,int r){
	return sum(r)-sum(l-1);
}

string alpha = "abcdefghijklmnnopqrstuvwxyz";

void solve(){
  	cin >> s;
  	n = s.size();
  	REP(i,n){
  		all[s[i]-'a'].pb(i+1);
  	}
  	int cnt = 0;
  	int which = 0;
  	REP(i,26){
  		cnt += all[i].size()%2;
  		if(all[i].size()%2)which = i;
  	}
  	if(cnt > 1){
  		cout << -1;
  		return;
  	}
   	REP(i,n){	
  	//	cout << freq[s[i]-'a'] << " " << all[s[i]-'a'].size() << endl;
  		if(freq[s[i]-'a'] < all[s[i]-'a'].size()/2){
  	//		cout << "HEre " << i << endl;
  			res.pb(s[i]-'a');
  		}
  		freq[s[i]-'a']++;
  	}
  	vector<int> tem = res;
  	if(cnt)tem.pb(which);
  	reverse(all(res));
  	REP(i,res.size())tem.pb(res[i]);
  	//cout << s;
  	REP(i,n){
  		q[s[i]-'a'].push(i);
  	}
  	REP(i,n){
  		pos[q[tem[i]].front()] = i+1;
  		q[tem[i]].pop(); 
  	}

  	int ans = 0;
 	REP(i,n){
 		ans += i-sum(pos[i]);
 		//cout << pos[i] << " ";
 		upd(pos[i]);
 	} 	
 	//cout << endl;
 	cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 11628
n,x,y = map(int,input().split())
ans = [0]*(n)
for i in range(n):
    tbl = [0]*n
    for j in range(i,n):
        tbl[j] = min(abs(j+1-i-1),abs(i+1-x)+1+abs(j+1-y))
        ans[tbl[j]] += 1
[print(i) for i in ans[1:]]

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

int n, ans[10001];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i * i <= n; i++)
        for(int j = 1; j * j <= n; j++)
            for(int k = 1; k * k <= n; k++){
                int val = i * i + j * j + k * k + i * j + j * k + i * k;
                if(val <= n) ans[val]++;
            }
    for(int i = 1; i <= n; i++)
        cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,k,i;
    scanf("%d %d",&n,&k);
    if(n<=k)
        {for(i=0;i<k;i++)
        {
            printf("%d",n);
        }}
    else
        {for(i=0;i<n;i++)
        {
            printf("%d",k);
        }}
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1e15+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<pair<int,int>,ll> m;
    rep(i,1,n+1){
        ll x = i;
        while(x>9){
            x /=10;
        }
        m[{x,i%10}]++;
    }
    ll ans = 0;
    rep(i,1,10){
        rep(j,1,10){
            ans += m[{i,j}]*m[{j,i}];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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 ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    ll ans=0;
    rep(i,n){
        bool ok=true;
        rep(j,30){
            if((k>>j)%2==0 && (a[i]>>j)%2==1){
                ok=false;
                break;
            }
        }
        if(ok){
            ans+=b[i];
        }
    }
    rep(i,30){
        if((k>>i)%2==1){
            ll sum=0;
            ll v=k;
            v&=~(1<<i);
            for(ll j=i-1;j>=0;j--){
                if((v>>j)%2==0){
                    v|=(1<<j);
                }
            }
            rep(j,n){
                bool ok=true;
                rep(p,30){
                    if((v>>p)%2==0 && (a[j]>>p)%2==1){
                        ok=false;
                        break;
                    }
                }
                if(ok){
                    sum+=b[j];
                }
            }
            ans=max(ans,sum);
            //cout << i << " " << v << " " << sum << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

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


void solve() {
    int n, k;
    cin >> n >> k;
    unordered_map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mp[x]++;
    }
    set<array<int, 2>> s;
    for (auto p : mp) {
        s.insert({p.second, p.first});
    }
    int sz = (int) s.size();
    int i = max(0, sz - k);
    int ans = 0;
    for (auto x : s) {
        if(!i) {
            break;
        }
        ans += x[0];
        i--;
    }
    cout << ans;

}


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


Measured memory_bytes: 20728
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)2e9 + 1;
const ll mod = (ll)1e9 + 7;

int main()
{
	ll l, r;
	cin >> l >> r;

	ll c = inf;

	for (ll i = l; i < r; i++)
	{
		for (ll j = i + 1; j <= i + 2019; j++)
		{
			if (j > r)
			{
				break;
			}
			ull x = (i * j) % 2019;
			if (c > x)
			{
				c = x;
			}
		}
		if (i == l + 2019)
		{
			break;
		}
	}

	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int memo[100010];
int solve(int N) {
    if (memo[N]) return memo[N];
    if (N < 6) return memo[N] = N;
    int res = N;
    for (int i = 9; i <= N; i*=9) {
        res = min(res, solve(N-i)+1);
    }
    for (int i = 6; i <= N; i*=6) {
        res = min(res, solve(N-i)+1);
    }
    return memo[N] = res;
}
int main () {
    int N;
    cin >> N;
    cout << solve(N) << endl;
}

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

using namespace std;

// Union-Find木
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
            par[i] = i;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る
        if (par[x] == x) {
            return x;
        }

        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) {
            return; //xとyの根が同じ(=同じ木にある)時はそのまま
        }

        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N,M;
    cin >> N >> M;

    vector<int> a(M), b(M);
    int count = 0;

    for(int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    // それぞれの辺について取り除く
    for(int i = 0; i < M; i++) {
        UnionFind U(N);

        // それ以外の辺で繋がれる頂点を併合する
        for(int j = 0; j < M; j++) {
            if(j == i) {
                continue;
            }

            U.unite(a[j], b[j]);
        }

        // 取り除いた辺で繋がれる頂点が連結されているか判断する
        if(U.same(a[i], b[i]) == false) {
            count++;
        }
    }

    cout << count << endl;
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n),b(n),c(n-1); for(auto&&i:a)cin>>i; for(auto&&i:b)cin>>i; for(auto&&i:c)cin>>i;
	int ans=0;
	for(int i=0,p=-1;i<n;++i){
		ans+=b.at(a.at(i)-1);
		if(a.at(i)-p==1)ans+=c.at(p-1);
		p=a.at(i);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)

int N;
vector<int> L;

signed main()
{
	cin >> N;

	L.resize(N+1);
	rep(i, N) cin >> L[i];
	L[N] = 1e9;

	sort(begin(L), end(L));

	int ans = 0;

	rep(i, N) rep(j, i) {
		int l = i, r = N;

		while (r - l > 1) {
			int m = (r + l) / 2;
			if (L[m] < L[j] + L[i]) {
				l = m;
			} else {
				r = m;
			}
		}

		ans += l - i;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<vector>
#include<deque>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
inline void writeln(int x) {
	int s = 0; char f[7];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}

vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000]{ 1 }, cnt = 1;
char b[200000], ok[100000]{ 1 };
deque<int>que;

void bfs(int u, char t) {
	que.emplace_back(u);
	while (!que.empty()) {
		int p = que.front(); que.pop_front();
		for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.emplace_back(v);
				}
			}
			else if (!d[v]) {
				d[v] = d[p] + 1; que.emplace_back(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(&n); reader(&m); reader(&q);
	rep(i, m) {
		reader(&u[i]); reader(&v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(&r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)writeln(ans[i]);
}

Measured memory_bytes: 12956
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, m = M()
li = LI()
li.sort(reverse=True)
S = sum(li)
if li[m-1] >= S / (4*m):
    print('Yes')
else:
    print('No')

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

int main() {
  string s;
  string ans = "";
  cin >> s;
  string num = to_string(s.length()-2);
  ans+= s[0];
  ans+= num;
  ans+= s[s.length()-1];
  cout << ans << endl;
    
  return 0;
}


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

using namespace std;
#define rep(i,n) for(int i =0;i<n;++i)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define FOR(it,a ) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)

int h,w,c;

int in[10][10];

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

void dfs(int a){
  if(a == 5){
    queue<PI> q;
    bool vis[10][10] = {};
    q.push(mp(0,0));
    int tans=0;
    
    while(!q.empty()){
      int cx = q.front().F;
      int cy = q.front().S;
      q.pop();
      if(vis[cx][cy]) continue;
      ++tans;
      vis[cx][cy]=1;
      rep(i,4){
        int nx = cx + dx[i];
        int ny = cy + dy[i];
        if(min(nx,ny)<0 || nx>=h || ny>=w )continue;
        if(in[nx][ny] != in[cx][cy]) continue;
        q.push(mp(nx,ny));
      }
    }
    ans=max(ans,tans);
    return;
  }
  
  int ba[10][10];
  rep(i,h)rep(j,w) ba[i][j] = in[i][j];

  queue<PI> q;
  bool vis[10][10] = {};
  q.push(mp(0,0));
    
  while(!q.empty()){
    int cx = q.front().F;
    int cy = q.front().S;
    q.pop();
    if(vis[cx][cy]) continue;
    
    vis[cx][cy]=1;
    rep(i,4){
      int nx = cx + dx[i];
      int ny = cy + dy[i];
      if(min(nx,ny)<0 || nx>=h || ny>=w )continue;
      if(in[nx][ny] != in[cx][cy]) continue;
      q.push(mp(nx,ny));
    }
  }
  
  rep(jj,6){
    if(a==4 && jj+1!=c) continue;
    rep(i,h)rep(j,w) if(vis[i][j]) in[i][j] = jj+1;
    dfs(a+1);
  }
  
  rep(i,h)rep(j,w) in[i][j] = ba[i][j];
}

void solve(){
  rep(i,h)rep(j,w) cin >> in[i][j];
  ans = 1;
  dfs(0);
  cout << ans << endl;
}

int main(){
  while(cin >> h >> w >> c,h) solve();
}

Measured memory_bytes: 1208
#include<iostream>
#include<string>
using namespace std;
int main (){
    int x=0;
    string a;
    cin>>a;
    if(a[0]==a[1] && a[1]==a[2])x++;
    if(a[1]==a[2] && a[2]==a[3])x++;
    if(a[0]==a[1]&&a[1]==a[2]&&a[3]==a[0])x++;
    if(x>0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  rep(i,N){
    cin >> x.at(i);
  }
  ll ans = 1e10;
  rep(i,N-K+1){
    ll xmin = x.at(i);
    ll xmax = x.at(i+K-1);
    if(xmin*xmax<0){
      ans = min(ans,xmax-2*xmin);
      ans = min(ans,2*xmax-xmin);
    }else{
      if(xmin>=0){
        ans = min(ans,xmax);
      }else{
        ans = min(ans,-xmin);
      }
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
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 INF = 1LL << 60;

int main ()
{
    int n,k;
    long long c=0;
    cin >> n >> k;
    vector<int> h(n);

    for(int i=0;i<n;i++){
    cin >> h[i];
    }
    sort(h.begin(),h.end());
if(n>k){
    for(int i=0;i<k;i++){
        h.at(n-i-1)=0;
    }
    for(int i=0;i<n;i++){
        c+=h.at(i);
    }
cout << c << endl;
}
else cout << 0 << endl;

    
}


Measured memory_bytes: 1024
// Aizu Vol-1 0190: Eleven Puzzle
// 2017.8.23 bal4u@uu
// 2017.11.21

#include <stdio.h>
#define TM 0
#if TM
#include <time.h>
#endif

typedef unsigned long long UL;

#define HASHSIZ 900001
typedef struct { UL s; char m; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(UL s)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) return p->m;
		if (++p == hashend) p = hash;
	}
	return -1;
}

int insert(UL s, char m)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) return 0;
		if (++p == hashend) p = hash;
	}
	p->s = s, p->m = m;
	return 1;
}

#define MAX 500000
typedef struct { UL s; char b1, b2; } QUE;
QUE Q[MAX+3], *top, *end, *qmax = Q+MAX;

int move[13][5] = {
	/*  0 */{ 2, -1 },
	/*  1 */{ 2, 5, -1 },
	/*  2 */{ 0, 1, 3, 6, -1 },
	/*  3 */{ 2, 7, -1 },
	/*  4 */{ 5, -1 },
	/*  5 */{ 1, 4, 6, 9, -1 },
	/*  6 */{ 2, 5, 7, 10, -1 },
	/*  7 */{ 3, 6, 8, 11, -1 },
	/*  8 */{ 7, -1 },
	/*  9 */{ 5, 10, -1 },
	/* 10 */{ 6, 9, 11, 12, -1 },
	/* 11 */{ 7, 10, -1 },
	/* 12 */{ 10, -1 } };

UL swap(UL s, int p, int sp)
{
	UL n;
	p = (12 - p) << 2, sp = (12 - sp) << 2;
	n = (s >> p) & 0xf;
	s &= ~(0xfULL << p);
	return s | (n << sp);
}

int sach(UL s, int b1, int b2, int mode, int lim)
{
	int i, j, x, b[2], step = 1;
	UL s2;

	top = end = Q, end->s = s, end->b1 = b1, end->b2 = b2, end++, end->s = 0, end++;
	while (top+1 < end) {
		s = top->s, b[0] = top->b1, b[1] = top->b2, top++;
		if (!s) { step++, end->s = 0, end++; continue; }
		if (step > lim) break;
//	printf("%#15llx, b1 %2d, b2 %2d, step %2d\n", s, b[0], b[1], step);
		for (i = 0; i < 2; i++) {
			for (j = 0; (x = move[b[i]][j]) >= 0; j++) {
				if (x == b[0] || x == b[1]) continue;
				s2 = swap(s, x, b[i]);
				if (mode) { if (lookup(s2) >= 0) return step; }
				else if (!insert(s2, step)) continue;
				end->s = s2;
				if (i) end->b1 = b[0], end->b2 = x;
				else   end->b1 = x, end->b2 = b[1];
				end++;
			}
		}
	}
	return step;
}

int main()
{
	UL s;
	int i, ans, p, b1, b2;
#if TM
	clock_t start, finish;
	start = clock();
#endif
	s = 0x123456789ab0ULL, insert(s, 0);
	sach(s, 0, 12, 0, 14);
	while (1) {
		for (b1 = -1, s = i = 0; i < 13; i++) {
			scanf("%d", &p);
			if (p < 0) goto done;
			if (!p) { if (b1 < 0) b1 = i; else b2 = i; }
			s = (s << 4) | p;
		}
		if ((ans = lookup(s)) < 0) {
			if ((ans = sach(s, b1, b2, 1, 6)) > 6) ans = -1;
			else ans += 14;
		}
		printf(ans < 0 ? "NA\n" : "%d\n", ans);	
	}
done:
#if TM
	finish = clock();
	printf("time %lf\n", (double)(finish-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 18028