akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long n;
	cin >> n;
	cout << (long long)sqrt(n) * (long long)sqrt(n) << endl;
	return 0;
}


Measured memory_bytes: 256
//Resting_Prince
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000009
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define all(v) v.begin(),v.end()
#define rep(i,a,b)    for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

int main()
{
    ll n,i,j,k,o,l,a[200055];
    ll dp[200055];
    cin>>n;
    rep(i,1,n)cin>>a[i];
    dp[2]=abs(a[2]-a[1]);dp[1]=0;
    rep(i,3,n)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),abs(a[i]-a[i-2])+dp[i-2]);
    }cout<<dp[n];
    return 0;
}


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

int main(){
  int n,k; cin>>n>>k;
  vec p(n);
  rep(i,n)cin>>p[i];
  
  sort(p.begin(),p.end());
  int ans=0;
  
  rep(i,k)ans+=p[i];

  
  cout<<ans<<endl;
  

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
 
const int MAX_N=1<<19;
const int INF=202020;
 
int n, dat[2][2*MAX_N-1];
 
void init(int n_){
  n=1;
  while(n<n_) n*=2;
  for(int i=0;i<=2*n-1;i++) dat[0][i]=dat[1][i]=INF;
}
 
void update(int k, int a,int p){
  k+=n-1;
  dat[p][k]=a;
  while(k>0){
    k=(k-1)/2;
    dat[p][k]=min(dat[p][k*2+1],dat[p][k*2+2]);
  }
}
 
int query(int a, int b, int k, int l, int r,int p){
  if(r<=a || b<=l) return INF;
  if(a<=l && r<=b) return dat[p][k];
  else{
    int vl=query(a,b,k*2+1,l,(l+r)/2,p);
    int vr=query(a,b,k*2+2,(l+r)/2,r,p);
    return min(vl,vr);
  }
}

int pos[202020],N,P[202020];

pair<int,int> cal(int l, int r){
  int x=query(l,r+1,0,0,n,l%2);
  int y=query(pos[x],r+1,0,0,n,(l+1)%2);
  return {-x,-y};
}
 
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  cin>>N;
  init(N);
  rep(i,N){
    cin>>P[i];
    pos[P[i]]=i;
    update(i,P[i],i%2);
  }
  priority_queue<pair<pair<int,int>,pair<int,int> > > pq;
  pq.push({cal(0,N-1),{0,N-1}});
  while(pq.size()){
    auto t=pq.top(); pq.pop();
    int x=-t.first.first;
    int y=-t.first.second;
    cout<<x<<" "<<y<<" ";
    int l=t.second.first;
    int r=t.second.second;
    x=pos[x], y=pos[y];
    if(l<x-1){
      pq.push({cal(l,x-1),{l,x-1}});
    }
    if(x+1<y-1){
      pq.push({cal(x+1,y-1),{x+1,y-1}});
    }
    if(y+1<r){
      pq.push({cal(y+1,r),{y+1,r}});
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 10484
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int dp[1 << 15][15];
int G[15][15];

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

	int V, E, s, t, d;
	cin >> V >> E;
	rep(i, 0, V)rep(j, 0, V)G[i][j] = INF;
	rep(i, 0, E)
	{
		cin >> s >> t >> d;
		G[s][t] = d;
	}
	rep(i, 0, 1 << V)fill(dp[i], dp[i] + V, INF);
	dp[(1 << V) - 1][0] = 0;

	rrep(i, 0, (1 << V) - 1)rep(u, 0, V)rep(v, 0, V)
	{
		if (((i >> v) & 1) == 0)
		{
			chmin(dp[i][u], dp[i | (1 << v)][v] + G[u][v]);
		}
	}

	printf("%d\n", dp[0][0] == INF ? -1 : dp[0][0]);

	return 0;
}


Measured memory_bytes: 5076
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    R, S, P = [int(x) for x in input().split()]
    s = input()
    ans = 0
    b = []
    for i in range(n):
        e = s[i]
        if i < k or s[i] != s[i-k] or s[i-k] == b[i-k]:
            if e == 'r':
                ans += P
                b.append('p')
            elif e == 'p':
                ans += S
                b.append('s')
            elif e == 's':
                ans += R
                b.append('r')
        else:
            b.append(e)
    print(ans)
    
    

        
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""


Measured memory_bytes: 10360
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    int count = 0;
    vector<int> p;
    const long long int size = 100001;
    //vector<bool> swap(size,0);

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        int num;
        cin >> num;
        p.push_back(num);
    }

    for (int i = 0; i < n; ++i)
    {
        if (p[i]==i+1){
            swap(p[i],p[i+1]);
            ++count;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 200005;
int mx = -1e9 , mn = 1e9 ;
double arr[N] , arr2[N];
double dd[N];

int main()
{

    int a , b , c , d;
    cin >> a >> b >>  c >> d ;
    cout << (a*b)-(c*b+d*a-c*d)<<endl;
   // cout << (a-c)*(b-d) << endl;




    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
    string s;cin>>n;
    cin>>s;
    int ans=0;
    for(int i=0;i<n-1;++i){
        int cnt1[26]={0};
        int cnt2[26]={0};
        int ta=0;
        for(int j=0;j<=i;++j)cnt1[s[j]-'a']=1;
        for(int j=i+1;j<n;++j)cnt2[s[j]-'a']=1;
        for(int j=0;j<26;++j)if(cnt1[j]==cnt2[j] && cnt1[j]==1)ta++;
        ans=max(ans,ta);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
from collections import deque


N = int(input())
S = deque(str(input()))

a = S.popleft()
count = 1
for i in range(N-1):
    b = S.popleft()
    if a == b:
        a = b
        pass
    else:
        count += 1
        a = b

print(count)

Measured memory_bytes: 4212
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int x;
	cin >> x;

	cout << (x == 7 || x == 5 || x == 3 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
A,B,K=map(int,input().split())
if B - A + 1 > 2 * K:
    for i in range(A,A+K):
        print(i)
    for i in range(B-K+1, B+1):
        print(i)
else:
    for i in range(A,B+1):
        print(i)

Measured memory_bytes: 61924
#include<stdio.h>
int main(void)

{
   int a,b,c,d,min1,min2,n;

   scanf("%d%d%d%d",&a,&b,&c,&d);

   if (a >= b) min1=b;
   else if (b >= a) min1=a;
   
   if (c >= d) min2=d;
   else if(d >= c) min2=c;
   
   n=min1+min2;

   printf("%d\n",n);
   
   return 0;
}  


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int m, f, r;
    char result;
    while (true) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) {
            break;
        }
        if ((m + f) >= 80) {
            result = 'A';
        } else if ((m + f) >= 65) {
            result = 'B';
        } else if ((m + f) >= 50) {
            result = 'C';
        } else if ((m + f) >= 30) {
            if (r >= 50) {
                result = 'C';
            } else {
                result = 'D';
            }
        } else {
            result = 'F';
        }
        if (m == -1 || f == -1) {
            result = 'F';
        }
        cout << result << endl;
    }

}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
ll gcd(ll a,ll b){
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll findGCD(vector<ll> arr,ll n) 
{ 
    ll result = arr[0]; 
    for (ll i = 1; i < n; i++) 
        result = gcd(arr[i], result);
    return result; 
}

int main() {
    SPEED;
    cout.precision(8);
    cout << fixed;
    ll m,n;
    cin>>m>>n;
    if(m==n) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <string>
using namespace std;

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

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

long count(long c, long d, long to){
  
  long ret = to;
  
  ret -= to/c;
  ret -= to/d;
  ret += to/lcm(c,d);
  
  return ret;
}
int main() {
  long A, B, C, D;
  cin >> A >> B >> C >> D;
  
  cout << count(C,D,B) - count(C,D,A-1) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll N,K;
        cin>>N>>K;
        vl x(N);
        rep(i,N)cin>>x[i];
        ll time=INF;
        rep(i,N-K+1){
            chmin(time,x[i+K-1]-x[i]+abs(x[i+K-1]));
            chmin(time,x[i+K-1]-x[i]+abs(x[i]));
        }
        cout<<time<<endl;
    }

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

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

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int A, B;
    cin >> A >> B;

    if (B % A == 0) {
        cout << A+B << endl;
    } else {
        cout << B - A << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

map<ll, ll> prime_factorization(ll num)
{
    auto sqrtNum = static_cast<ll>(sqrt(num));
    map<ll, ll> prime_factors;
    for (ll i = 2; i <= sqrtNum;) {
        if (num % i == 0) {
            num /= i;
            prime_factors[i]++;
        } else {
            i++;
        }
    }
    if (num > 1) {
        prime_factors[num]++;
    }
    return prime_factors;
}

void solve(long long A, long long B)
{
    cout << prime_factorization(__gcd(A, B)).size() + 1 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long x, t[51] = {1}, p[51] = {1};

long long dp(int n, long long x){
    if(n == 0){
        return x > 0 ? 1 : 0;
    }else if(x < t[n - 1] + 2){
        return dp(n - 1, x - 1);
    }else{
        return p[n - 1] + 1 + dp(n - 1, x - t[n - 1] - 2);
    }
}

int main(){
    cin >> n >> x;
    for(int i = 1; i <= n; i++){
        t[i] = t[i - 1] * 2 + 3;
        p[i] = p[i - 1] * 2 + 1;
    }
    cout << dp(n, x) << endl;
}


Measured memory_bytes: 256
# 入力
# 値は全てint
# Nは本数、Kは切る回数、AはN本の木のそれぞれの長さ(リスト)
N,K = map(int,input().split())
A = list(map(int,input().split()))

# 二分探索
# lが左端、rが右端
l,r = 0, 10**9

# 整数で返すので、差が１より大きい時はループする
while r - l > 1:
    # 真ん中を設定
    x = (r+l) // 2

    # 切る回数をc
    c = 0
    for a in A:
        # それぞれの丸太の(長さ-1)をxで割った値の合計が、切る回数
        c += (a-1) // x 

    # 切る回数がKよりも小さい時はOKなので右端を寄せる
    if c <= K:
        r = x
    else:
        l = x
    
print(r)


Measured memory_bytes: 30676
def solve(arr)
  return arr.select{|l| l > 0} == [2] if arr.sum == 2

  (0..6).each do |i|
    if arr[i] >= 1 && arr[i + 1] >= 1 && arr[i + 2] >= 1
      da = arr.dup
      da[i] -= 1
      da[i + 1] -= 1
      da[i + 2] -= 1
      return true if solve(da)
    end
  end
  (0..8).each do |i|
    if arr[i] >= 3
      da = arr.dup
      da[i] -= 3
      return true if solve(da)
    end
  end
  false
end

loop do
  l = gets
  break if l.nil?
  next unless l.length == 14

  q = l.strip.split('').map(&:to_i)
  res = []
  9.times do |i|
    line = q + [i + 1]
    arr = [0] * 9
    line.each {|j| arr[j - 1] += 1 }
    next if arr.find{|a| a == 5 }
    res << (i + 1) if solve(arr)
  end
  puts res.empty? ? 0 : res.join(' ')
end



Measured memory_bytes: 7320
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int m;
  cin >> m;
  pll p[m];
  rep(i,m)cin >> p[i].first >> p[i].second;
  ll dig=0;
  ll ans=0;
  ll sum=0;
  rep(i,m)dig+=p[i].second;
  ans+=dig-1;
  rep(i,m){
    sum+=p[i].first*p[i].second;
  }
  ans+=sum/9;
  if(sum%9==0)ans--;
//  cout << dig << ' ' << sum << endl;
  cout << ans << endl;
return 0;}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,m,num[20],p[20],sw[20][20];
vector <int> adj[20];
int f;
int deep[20],bulb[20];
void choose (int start, int d, int k){
    if(d<=k){
        for(int i=start;i<=n-(k-d);i++){
            deep[d]=i;
            if(d<k){choose(i+1,d+1,k);}
            else{
                for(int j=1;j<=n;j++){
                    bulb[j]=0;
                }
                for(int j=1;j<=k;j++){
                    for(int l=0;l<adj[deep[j]].size();l++){
                        int idx = adj[deep[j]][l];
                        bulb[idx]++;
                    }
                }
                int m2=0;
                for(int j=1;j<=n;j++){
                    if(bulb[j]%2==p[j]%2){m2++;}
                }
                if(m2==n){f++;}
            }
        }
    }
}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>num[i];
        for(int j=1;j<=num[i];j++){
            cin>>sw[i][j];
            adj[sw[i][j]].pb(i);
        }
    }
    for(int i=1;i<=m;i++)cin>>p[i];
    bool zero = true;
    for(int i=1;i<=m;i++){
        if(p[i]==1){zero=false;break;}
    }
    if(zero)f++;

//    for(int i=1;i<=n;i++){
//        cout<<i<<newl;
//        for(int j=0;j<adj[i].size();j++)cout<<adj[i][j]<<" ";cout<<newl;
//    }


    for(int i=1;i<=n;i++){
        choose(1,1,i);
    }
    cout<<f<<newl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int in,cnt;
const int coin[6] = {500,100,50,10,5,1};

int count(int* x,int y,int* c){
   *c += *x / y;
   *x  = *x % y;
}

int main(){
   while(cin >> in,in){
      cnt = 0;
      in  = 1000 - in;
      for(int i=0;i<6;i++)
	 count(&in,coin[i],&cnt);
      cout << cnt << endl;
   }
   return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    ll n,a,b,c; cin >> n;
    map<ll,ll> m;
    ll ans = 0;
    REP(i,n){
        cin >> a;
        ans+=a;
        m[a]++;
    }
    ll q; cin >> q;
    REP(i,q){
        cin >> b >> c;
        auto ite = m.lower_bound(b);
        if (ite==m.end()){
            cout << ans << endl;
            continue;
        }
        if (ite->first!=b){
            cout << ans << endl;
            continue;
        }
        ll cnt = ite->second;
        m.erase(ite);
        m[c]+=cnt;
        ans+=cnt*(c-b);
        cout << ans << endl;
    }
}

Measured memory_bytes: 7508
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(int i=n;i<=N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define piii pair<int,pii>
#define piiii pair<pii,pll>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 2e6+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll MOD2 = 1000005329;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 200;

ll x,y,ans,inv,z,nw,f[MAX],pre[MAX];
string s;

inline ll pw(ll x,ll y){
	ll ret = 1;
	while(y){
		if(y&1)ret = ret*x%MOD;
		x = x*x%MOD;
		y>>=1;
	}
	return ret;
}

inline ll cb(int a,int b){
	return f[a]*pre[b]%MOD*pre[a-b]%MOD;
}

int main(){
//	cout<<fixed<<setprecision(10);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    f[0] = pre[0] = 1;
    rep(i,1,2000000)f[i] = f[i-1]*i%MOD, pre[i] = pw(f[i],MOD-2);
    cin>>x>>s;
    y = s.size()-1;
    nw = pw(26,x), inv = pw(26,MOD-2)*25%MOD;
    rep(i,0,x){
    	ans = (ans + nw*cb(i+y,i))%MOD;
    	nw = nw*inv%MOD;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  ll X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<ll>p(A),q(B),r(C);
  for(int i=0;i<A;i++)cin>>p[i];
  for(int i=0;i<B;i++)cin>>q[i];
  for(int i=0;i<C;i++)cin>>r[i];
  priority_queue<pair<ll,int>>a;
  for(int i=0;i<A;i++)a.push({p[i],0});
  for(int i=0;i<B;i++)a.push({q[i],1});
  for(int i=0;i<C;i++)a.push({r[i],2});
  vector<int>c(3,0);
  ll ans=0;
  for(int i=0;i<A+B+C;i++){
    int v=a.top().first;
    int k=a.top().second;
    if(k==0){
      if(c[0]>=X){}
      else if(c[0]+c[1]+c[2]>=X+Y){}
      else{
        c[0]++;
        ans+=v;
      }
    }
    if(k==1){
      if(c[1]>=Y){}
      else if(c[0]+c[1]+c[2]>=X+Y){}
      else{
        c[1]++;
        ans+=v;
      }
    }
    if(k==2){
      if(c[0]+c[1]+c[2]>=X+Y){}
      else{
        c[2]++;
        ans+=v;
      }
    }
    a.pop();
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 12908
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<int,ll>;
using Pd = pair<double,double>;
using T = tuple<double,double,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 100005;
const ll lmod = 1e9+7;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define ll              long long
#define dd				double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vll				vector<long long>
#define vpii			vector<pair<int,int>>
#define vpll			vector<pair<long long,long long>>
#define vvi				vector<vector<int>>
#define vvl				vector<vector<long long>>
#define mii             map<int,int>
#define mll  			map<long long,long long>
#define umii			unordered_map<int,int>
#define umll			unordered_map<long long,long long>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)		for(int i=0;i<n;i++)
#define rep2(i,a,b)		for(int i=a;i<b;i++)
#define rev(i,n)		for(int i=n;i>=0;i--)
#define rev2(i,a,b)		for(int i=a;i>=b;i--)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             9e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define fio				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl			'\n'
#define all(x)			x.begin(),x.end()
#define d0(x)			cout <<x<<" "
#define d1(x)			cout <<x<<endl
#define d2(x,y)			cout <<x<<" "<<y<<endl
#define d3(x,y,z)		cout <<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w)		cout <<x<<" "<<y<<" "<<z<<" "<<w<<endl
const ll mod=1e9+7;
const dd pi=M_PI;
const ll MOD=998244353;
void i_o()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
} 
int main()
{
	fio
   	i_o();
	int s,w;
	cin>>s>>w;
	if(w>=s) cout <<"unsafe";
	else cout <<"safe";


    
	return 0;
}



Measured memory_bytes: 3640
package main

import (
  "bufio"
  "container/list"
  "fmt"
  "os"
  "strconv"
  "strings"
)

const INF = 1<<30

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n,m := input.NextInts()
  g := make([][]int,n)
  for i:=0;i<m;i++ {
    a,b := input.NextInts()
    g[a-1] = append(g[a-1],b-1)
  }
  var bfs func(int) []int
  bfs = func(s int) []int {
    dist := make([]int,n)
    prev := make([]int,n)
    queu := list.New()
    for i:=0;i<n;i++ { dist[i],prev[i] = INF,-1 }
    dist[s] = 0
    queu.PushBack(s)
    for queu.Len() > 0 {
      v,_ := queu.Remove(queu.Front()).(int)
      for _,u := range g[v] {
        if dist[u] != INF { continue }
        prev[u] = v
        dist[u] = dist[v]+1
        queu.PushBack(u)
      }
    }
    best := []int{INF,-1}
    for v:=0;v<n;v++ {
      if v == s { continue }
      for _,u := range g[v] {
        if u != s { continue }
        if best[0] > dist[u] { best = []int{dist[v],v} }
      }
    }
    if best[0] == INF { return make([]int,n+1) }
    x := []int{}
    v := best[1]
    for v != -1 {
      x = append(x,v)
      v = prev[v]
    }
    return x
  }
  s := make([]int,n+1)
  for i:=0;i<n;i++ {
    x := bfs(i)
    if len(s) > len(x) { s = x }
  }
  if len(s) == n+1 { fmt.Println(-1);return }
  fmt.Println(len(s))
  for _,v := range s { fmt.Println(v+1) }
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInts() (int,int) {
  s := strings.Fields(i.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}

Measured memory_bytes: 5504
n=int(input())
a = list(map(int,input().split()))

ans = 10**7
for i in range(102):
    p = 0
    m = 0
    for j, aa in enumerate(a):
        p += (aa-i)**2
        m += (aa+i)**2
    ans = min(ans,p,m)

print(ans)


Measured memory_bytes: 3060
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int a,b;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>a>>b;
	cout<<max(max(a+b,a-b),a*b);
	//system("pause");
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int N,K; cin >> N >> K;

    if(K == 1) cout << 0 << endl;
    else cout << N - K << endl;
    return 0;
}



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

struct road{
	int t,val,x;
};

bool comp(road r1,road r2){
	return r1.t <= r2.t;
}

int main() {
	// your code goes here
	
	int n,q;
	cin>>n>>q;
	
	vector<road> vr;
	
	for(int i = 0;i < n;i++){
		int a,b,x;
		cin>>a>>b>>x;
		road r1,r2;
		r1.t = a-x; r1.val = 1,r1.x = x;
		r2.t = b-x; r2.val = -1, r2.x = x;
		vr.push_back(r1);
		vr.push_back(r2);
	}
	
	sort(vr.begin(),vr.end(),comp);
	
	// for(int i = 0;i < vr.size();i++){
	// 	cout<<vr[i].t<<" "<<vr[i].val<<" "<<vr[i].x<<endl;
	// }
	
	map<int,int> mp;
	
	int j = 0;
	
	while(q--){
		int val; cin>>val;
		while(j<vr.size() && vr[j].t <= val){
			int x = vr[j].x;
			if(vr[j].val == 1) {
				if(mp.find(x) == mp.end()){
					mp.insert({x,1});
				}
				else mp[x]++;
			}
			else{
				if(mp[x] == 1) mp.erase(x);
				else mp[x]--;
			}
			j++;
		}
		// cout<<val<<" "<<j<<endl;
		if(mp.empty() == false) cout<<(*mp.begin()).first<<endl;
		else cout<<-1<<endl;
	}
	
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define fore(i,x,n) for(int i=x;i<n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define ordenar(a) sort(all(a))
typedef long long ll;
typedef vector<int> vi;

int n;

int main(){

    cin>>n;

    vi a(n);

    fore(i,0,n) cin>>a[i];

    int cont=0;

    fore(i,1,n-1){
        if(a[i-1]<a[i] && a[i]<a[i+1]) cont++;
        else if(a[i-1]>a[i] && a[i]>a[i+1]) cont++;
    }

    cout<<cont;

    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#define MAX_N 205
#define INF 1000000000
#define A(x) (x)
#define B(x) ((x)+n)

using namespace std;

struct Edge
{
	int dst,cap,rev;
	Edge(int _dst,int _cap,int _rev) { dst=_dst,cap=_cap,rev=_rev; }
	Edge(){}
};

int n,s,t,tot;
int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int d[MAX_N];
int lv[MAX_N];
int it[MAX_N];
vector<Edge> edge[MAX_N];
queue<int> q;

inline void add(int s,int t)
{
	edge[s].push_back(Edge(t,1,edge[t].size()));
	edge[t].push_back(Edge(s,0,edge[s].size()-1));
}

void build()
{
	s=(n<<1)+1,t=s+1,tot=t;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[i]<c[j] && b[i]<d[j]) add(A(i),B(j));
		}
		add(s,A(i)),add(B(i),t);
	}
}

void bfs(int s)
{
	memset(lv+1,0,sizeof(int)*tot);
	lv[s]=1,q.push(s);
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		for(int i=0;i<edge[x].size();i++)
		{
			Edge temp=edge[x][i];
			if(temp.cap>0 && !lv[temp.dst])
			{
				lv[temp.dst]=lv[x]+1;
				q.push(temp.dst);
			}
		}
	}
}

int dfs(int x,int t,int f)
{
	if(x==t) return f;
	for(int &i=it[x];i<edge[x].size();i++)
	{
		Edge &temp=edge[x][i];
		if(temp.cap>0 && lv[x]<lv[temp.dst])
		{
			int d=dfs(temp.dst,t,min(f,temp.cap));
			if(d>0)
			{
				temp.cap-=d,edge[temp.dst][temp.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t)
{
	int ans=0,f;
	while(true)
	{
		bfs(s);
		if(!lv[t]) return ans;
		memset(it+1,0,sizeof(int)*tot);
		while((f=dfs(s,t,INF))>0) ans+=f;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;i++) scanf("%d%d",&c[i],&d[i]);
	build();
	printf("%d\n",max_flow(s,t));
}


Measured memory_bytes: 384
#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>;

int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main(void){
    ll N, ans = 0;
    cin >> N;
    int A[N+1], B[N];
    for(int i=0;i<N+1;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
    for(int i=0;i<N;i++){
        if(A[i] <= B[i]){
            ans += A[i];
            B[i] -= A[i];
            ans += min(A[i+1], B[i]);
            A[i+1] = max(0, A[i+1]-B[i]);
        } else {
            ans += B[i];
        }
    }
    printf("%lld\n",ans);
    return 0;

}

Measured memory_bytes: 1024
# @uthor : Kaleab Asfaw
import sys

input = sys.stdin.readline

def main(n):
    if n <= 599: return 8
    if n <= 799: return 7
    if n <= 999: return 6
    if n <= 1199: return 5
    if n <= 1399: return 4
    if n <= 1599: return 3
    if n <= 1799: return 2
    if n <= 1999: return 1
    


n = int(input())
print(main(n))




Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=654321;
ll n,num;
ll x[maxn];
map<ll,int>q;
int main()
{
    cin>>n>>num;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i];
        q[x[i]]=1;
    }
    x[n+1]=1e10;
    ll tim=0;
    for(int i=1;i<=n;i++)
    {
        ll ans=x[i]+num;
        if(ans>=x[i+1])
        {
            tim+=x[i+1]-x[i];
        }
        else
        {
            tim+=num;
        }
    }
    cout<<tim<<endl;
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> fac(n+1);
    FOR(i,2,n+1){
        int32 p = 2;
        int32 x = i;
        while(p * p <= x){
            while(x % p == 0){
                fac[p]++;
                x /= p;
            }
            ++p;
        }
        if(x != 1)fac[x]++;
    }
    int32 ans = 0;
    FOR(i,2,n+1){
        if(fac[i] >= 74)ans++;
    }
    FOR(i,2,n+1)FOR(j,2,n+1){
        if(i == j)continue;
        if(fac[i] >= 2 && fac[j] >= 24)ans++;
    }
    FOR(i,2,n+1)FOR(j,2,n+1){
        if(i == j)continue;
        if(fac[i] >= 4 && fac[j] >= 14)ans++;
    }
    FOR(i,2,n+1)FOR(j,2,n+1)FOR(k,2,n+1){
        if(i == j || j == k || k == i)continue;
        if(j > k)continue;
        if(fac[i] >= 2 && fac[j] >= 4 && fac[k] >= 4)ans++;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N; cin >> N;
    VL A(N);
    LL sum = 0;
    REP(i,N) {
        cin >> A[i];
        sum += A[i];
    }

    if(sum % (N*(N+1)/2) != 0){
        cout << "NO" << endl;
        return 0;
    }
    LL loop = sum / (N*(N+1)/2);
    VL dif(N);

    REP(i,N-1){
        dif[i] = A[i+1] - A[i];
    }
    dif[N-1] = A[0] - A[N-1];
    LL acc = 0;
    dump(loop)
    REP(i,N){
        dump(dif[i])
        if((dif[i] - loop) % (-N) != 0 || (dif[i]-loop) > 0){
            cout << "NO" << endl;
            return 0;
        }

        dump((dif[i] - loop) / (-N))
        acc += (dif[i] - loop) / (-N);
    }
    if(acc != loop){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }



}

Measured memory_bytes: 1792
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
for key in A:
    d[key] += 1
d[sum] = sum(A)

Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    change_sum = d[b] * (c-b)
    d[sum] += change_sum
    d[c] += d[b]
    d[b] = 0
    print(d[sum])

Measured memory_bytes: 24100
# TLEしない適切な解法を思いつけず

class UnionFind:

  def __init__(self, n):
    self.parents = [-1] * n

  def find(self, n):
    if self.parents[n] < 0:
      return n

    self.parents[n] = self.find(self.parents[n])
    return self.parents[n]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def is_same(self, x, y):
    x = self.find(x)
    y = self.find(y)
    return x == y


N, M = map(int, input().split())
edges = []

for i in range(M):
  x, y = map(int, input().split())
  edges.append((x,y))

uf = UnionFind(N)

ans = [N * (N-1) // 2]

for i in range(M-1, 0, -1):
  x, y = edges[i]
  x -= 1
  y -= 1
  if not uf.is_same(x, y):
    ans.append(ans[-1] - uf.size(x) * uf.size(y))
    uf.union(x, y)
  else:
    ans.append(ans[-1])
    
for a in ans[::-1]:
  print(a)

Measured memory_bytes: 24592
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h=in.nextInt();
        int n=in.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
        }
        Arrays.sort(a);
        for(int i=n-1;i>=0;i--){
            h-=a[i];
            if(h<=0){
                break;
            }
        }
        if(h<=0)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 50636
N=int(input())

ans = 0
def dfs(s, sum):
  global ans
  sum = sum + s


  if int(sum) > N:
    return False

  sum = str(int(sum))
  if sum.count("3") >= 1 and sum.count("5") >= 1 and sum.count("7") >= 1:
    ans += 1
  
  if dfs("3", sum):
    return True
  
  if dfs("5", sum):
    return True
  
  if dfs("7", sum):
    return True
  
  
dfs("0" ,'')
print(ans)

  

Measured memory_bytes: 3064
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]

DP = [0 for i in range(H+1)] #DP[h]=体力hのやつを倒す最小mp

min_mp = 10**9
for i in range(N):
    if min_mp > AB[i][1]:
        min_mp = AB[i][1]
        min_mp_i = i

for h in range(1,min(AB[min_mp_i][0],H)+1):
    #最小消費mpの技でオーバーキルの場合にDP[h]がout of rangeになる
    DP[h] = min_mp

for h in range(AB[min_mp_i][0]+1,H+1):
    DP[h] = min((DP[h - a] + b) for a,b in AB )
    #最小消費mpの技で初期化しないとh - a >= 0を満たすaの存在が怪しい

print(DP[H])


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int n,k,c;//n个数字 k工作天数 c休息天数 
char s[200001];
int start[200001],End[200001],day;
int main()
{
	cin>>n>>k>>c;
	cin>>s;
	day=0;
	for(int i=0;i<n;i++)
	{
		if(day==k)break;
		if(s[i]=='x')continue;
		start[++day]=i;
		i+=c;
	}
	day=0;
	for(int i=n-1;i>=0;i--)
	{
		if(day==k)break;
		if(s[i]=='x')continue;
		End[++day]=i;
		i-=c;
	}
	for(int i=1;i<=k;i++)
		if(start[i]==End[k-i+1])cout<<End[k-i+1]+1<<endl;
	return 0;
}

Measured memory_bytes: 5260