akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int A,P;
    cin>>A>>P;
    cout<<(A*3+P)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
 using namespace std;  
ll n,t,m,c,x,y,sum,mx,mn,avg,pos,dif,j,dis;
vector<vector<int>>g;
bool vis[(int)1e5+2];
bool isPrime(int x)
{
for (int i=2;i*i<=x;i++)
if (x%i==0)
return false;
return true;
}
void dfs (int node)
{
vis[node]=true;
for (auto i : g[node])
if (!vis[i])dfs(i);
}
int main(void) 
{ 
   
        SpeeD
cin>>n>>m;
int ans=0,ans1=0;
while (n!=0)
{
    ans+=(--n);
}
while (m!=0)
{
    ans+=(--m);
}
cout<<ans;
}

    

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 200005;
int p[MAXN], ord[MAXN];

int main()
{
	int n;
	scanf("%d", &n);
	for (register int i = 1; i <= n; i++)
	{
		scanf("%d", &p[i]);
		ord[p[i]] = i;
	}
	int ans = 0, len = 1;
	for (register int i = 2; i <= n; i++)
		if (ord[i] >= ord[i-1]) len++;
		else ans = max(ans, len), len = 1;
	ans = max(ans, len);
	printf("%d", n - ans);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
 
 
using namespace std;
 
#define ll long long
#define ul unsigned long long
#define snd second
#define fst first
 

ll a,b,c,d,e,f,n,m;

int main(){
    std::ios::sync_with_stdio(false);
    cin >> a >> b;
    ll cnt = 0;
    vector<ll> v(a);
    for(int i=0;i<a;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    for(int i=0;i < a - b; i++){
        cnt += v[i];
    }

    cout << cnt;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int main () {
  long long n;
  cin >> n;
  long long acc = 0;

  REP(i, n) {
    if(((i+1) % 15) == 0) { }
    else if(((i+1) % 5) == 0) { }
    else if(((i+1) % 3) == 0) { }
    else { acc = (acc + (i+1)); }
  }

  cout << acc << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<map>
using namespace std;
const int MAX=210000;
const long long MOD=1000000007;

typedef long long ll;

ll fac[MAX],finv[MAX],inv[MAX];

ll mod_pow(ll x, ll n){
    ll ans=1;
    while(n!=0){
        if(n&1) ans=ans*x%MOD;
        x=x*x%MOD;
        n=n>>1;
    }
    return ans;
}

void com_init(){
    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;
        finv[i]=finv[i-1]*mod_pow(i,MOD-2)%MOD;
    }
}

ll comb(ll n, ll k){
    if(n<k) return 0;
    if(n<0||k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

map<ll,ll> prime_factor(ll n){
    map<ll,ll> table;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            table[i]++;
            n/=i;
        }
    }
    if(n!=1) table[n]=1;
    return table;
}

int main(){
    ll n;
    ll m;
    com_init();
    cin >> n >> m;
    
    map<ll,ll> res;
    res=prime_factor(m);

    ll ans=1;

    map<ll,ll>::iterator it;
    for(it=res.begin();it!=res.end();it++){
        ll tmp=comb(it->second+n-1,n-1);
        ans*=tmp;
        ans%=MOD;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3584
#include <iostream>

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

using namespace std;

int main(){
	long long x,y;
	cin>>x>>y;

	int i;
	for(i=0;x*(1LL<<i)<=y;i++);
	cout<<i<<endl;

	return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.List


-- space delimited integers
getVals::IO [Int]
getVals = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

-- space delimited strings
getStrings::IO [String]
getStrings = (map BS.unpack . BS.words) <$> BS.getLine


solver:: Int->Int->Bool
solver x y = (mod y 2 == 0) && 2*x <= y && 4*x >= y  

main::IO()
main = do
    val <- getVals
    let x:y:_ = val
    putStrLn $ if solver x y then "Yes" else "No" 



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


int main(){
  int N,M;
  cin >> N >> M;
  int sum =0,s;

  for(int i=0;i<M;++i){
    cin >> s;
    sum += s;
  }
  if(N >= sum){
    cout << N-sum << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3636
N, Y = map(int, input().split())
 
X = (10000 * N - Y) // 1000
 
for y in range(N + 1):
    a = X - 5 * y
    if a >= 0 and a % 9 == 0:
        z = a // 9
        if y + z <= N:
            print(N - y - z, y, z)
            exit()

print('-1 -1 -1')


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

using namespace std;
#define DIM  1007
#define DIM2 507
#define INF 10E16
#define MAXN 107
#define LG 18
#define MODULO 1000000007
typedef long long  ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef ll arr[DIM];
typedef vector<ll> vec;
typedef vector<ll> graph[DIM];
typedef pll parr[DIM];
typedef ll table[DIM][DIM2];
struct pp {
	ll a, b;
	bool operator <(const pp& V)const {
		if (a == V.a)return b < V.b;
		return a < V.a;
	}
	bool operator ==(const pp& V)const {
		if (a == V.a && b == V.b)return 1;
		return 0;
	}
};
ll n, m,A[DIM][DIM],D[DIM][DIM];
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char x; cin >> x;
			if (x == '.')A[i][j] = 1;
		}
	}
	D[n][m] = 1;
	for (int i = n; i >= 1; i--) {
		for (int j = m; j >= 1; j--) {
			if (A[i][j] == 0 || D[i][j]!=0)continue;
			D[i][j] = D[i +1][j] + D[i][j+ 1];
			D[i][j] %= MODULO;
		}
	}
	cout << D[1][1] << endl;
}
// 011 1

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    vll cnt(n);
    rep(i, n) cnt[a[i]]++;

    ll sum = 0;
    rep(i, n) {
        ll x = cnt[i];
        sum += (x * (x - 1) / 2);
    }

    rep(i, n) {
        ll ans = sum;
        ll x = cnt[a[i]];
        ans -= (x * (x - 1) / 2);
        ans += ((x - 1) * (x - 2) / 2);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n,k;cin>>n>>k;
    vin a(n);
    int madd;
    rep(i,n){
        cin>>a[i];
        if(a[i]==1)madd=i;
    }
    int min=inf;
    rep(i,k){
        if(((madd-i)+(k-1)-1)/(k-1)+((n-madd+i-k)+(k-1)-1)/(k-1)<min)min=(madd-i+k-2)/(k-1)+(n-madd+i-2)/(k-1);
    }
    cout<<min+1<<endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int K, X; cin >> K >> X;
    for (int i = X - K + 1; i < max(K, X + K); ++i) {
        if (i < max(K, X + K) - 1) cout << i << ' ';
        else cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull  unsigned long long ;
#define _CRT_SECURE_NO_WARNINGS 
const double  pai= acos(-1.0);
const int max1=5e5+5;
int a[max1];
int b[max1],c[max1],d[max1];
int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n,i,sum=0;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i],d[i]=0;
	for(i=1;i<=n;i++)
	cin>>b[i],sum+=b[i];
	for(i=1;i<n;i++)
	cin>>c[i];
	for(i=2;i<=n;i++)
	{
		if(a[i-1]==a[i]-1)
	sum+=c[a[i]-1];	//cout<<sum<<endl;	
	}
	cout<<sum<<endl;
	return 0;
 }

Measured memory_bytes: 4352
listS = list(str(input()))
n = len(listS)

bef=-1
flag=1
while flag:
    index = 0
    flag=0
    while index < len(listS):
        if index==0:
            bef=listS[index]
            index+=1
        else:
            if bef != listS[index]:
                flag=1
                del listS[index]
                del listS[index-1]
                index = index-1
            else:
                bef = listS[index]
                index+=1
print(n-len(listS))

Measured memory_bytes: 3956
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class modfact(object):
    def __init__(self,n):
        fact=[1]*(n+1)
        invfact=[1]*(n+1)
        for i in range(1,n+1):
            fact[i]=i*fact[i-1]%MOD
        invfact[n]=pow(fact[n],MOD-2,MOD)
        for i in range(n-1,-1,-1):
            invfact[i]=invfact[i+1]*(i+1)%MOD
        self.__fact=fact
        self.__invfact=invfact

    def fact(self,n):
        return self.__fact[n]

    def invfact(self,n):
        return self.__invfact[n]

    def comb(self,n,k):
        if(k<0 or n-k<0): return 0
        return (self.fact(n)*self.invfact(k)*self.invfact(n-k))%MOD

from collections import Counter
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    C=Counter(A).most_common()
    a=C[0][0]
    for i in range(n+1):
        if(A[i]==a):
            A[i]=0
            l=i
            break
    for i in range(n+1):
        if(A[i]==a):
            A[i]=0
            r=i

    mf=modfact(n+1)
    for k in range(1,n+2):
        print((mf.comb(n+1,k)-mf.comb(l+n-r,k-1))%MOD)
resolve()

Measured memory_bytes: 73192
// 2011/07/12 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int days[12];
	days[0]  = 0;
	days[1]  = days[0] +31;
	days[2]  = days[1] +29;
	days[3]  = days[2] +31;
	days[4]  = days[3] +30;
	days[5]  = days[4] +31;
	days[6]  = days[5] +30;
	days[7]  = days[6] +31;
	days[8]  = days[7] +31;
	days[9]  = days[8] +30;
	days[10] = days[9] +31;
	days[11] = days[10]+30;

	while(true){
		int m, d;
		cin >> m >> d;
		if(m==0)
			break;

		switch((days[m-1]+d)%7){
			case 0:
				cout << "Wednesday" << endl;
				break;
			case 1:
				cout << "Thursday" << endl;
				break;
			case 2:
				cout << "Friday" << endl;
				break;
			case 3:
				cout << "Saturday" << endl;
				break;
			case 4:
				cout << "Sunday" << endl;
				break;
			case 5:
				cout << "Monday" << endl;
				break;
			case 6:
				cout << "Tuesday" << endl;
				break;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, S: str):
    # dp = [float('inf')]*(N+1)
    # dp[N] = 0
    # count = 1
    # for i in range(N,-1,-1):
    #     if S[i] == "1":
    #         continue
            
    #     for j in range()
    S = S[::-1]
    cur_index = 0
    answer = []
    while True:
        for i in range(M,0,-1):
            if cur_index+i >= N:
                answer.append(N-cur_index)
                answer.reverse()
                print(*answer)
                return

            if S[cur_index+i] == "1":
                continue
            else:
                cur_index += i
                answer.append(i)
                break
        else:
            print(-1)
            return
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = next(tokens)
    solve(N, M, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6552
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=5e6+10;
const int mod=1e9+7;
int arr[N],iarr[N];
int logi(int n){int p=0;while(n/2){n=n/2;p++;}return p;}
int poww(int x,int y){int pro=1;while(y){if(y&1)pro=((pro%mod)*(x%mod)%mod);y=y>>1;x=((x%mod)*(x%mod)%mod);}return pro;}
map<int,int> mp;
int arr1[1000001],arr2[1000001];

int solve()
{
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	int temp=1;
	for(int i=0;i<n;i++)
	{
		if(v[i]==temp)
		{
			temp++;
		}
	}
	if(temp==1)
	{
		return cout<<-1,0;
	}
	cout<<n-temp+1;
}
int32_t main()																																	
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

int main() {
    string X;
    cin>>X;
    int Snum = 0, ans = 0;
    for(int i=0;i<X.size();++i){
        if(X[i] == 'S'){
            Snum++;
        }
        else {
            if(Snum > 0) Snum--;
            else ans++;
        }
    }
    cout<<2*ans<<endl;
}


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

#define int long long

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

    int n;
    cin >> n;
    cout << (n/500) * 1000 + ((n%500)/5) *  5 << endl;  
}

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

dp = [0] * (N+1)

for i_A in A_list:
    dp[i_A] += 1

total = 0
for i_dp in dp:
    total += (i_dp*(i_dp-1)) // 2

for i_A in A_list:
    diff = (dp[i_A]*(dp[i_A]-1))//2 - ((dp[i_A]-1)*(dp[i_A]-2))//2
    print(total - diff)

Measured memory_bytes: 83788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int MAX = 100005;

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int taka_x = (b+c-1)/b;
    int aoki_y = (a+d-1)/d;
    if (aoki_y < taka_x) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<string>
#include<algorithm>
#include<string.h>
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<limits.h>
#include<iostream>
#include<functional>
#include<queue>
using namespace std;

int a[100000], b[100000];
signed main() {
	int c; cin >> c;
	for (int d = 0; d < c; d++) {
		scanf("%d", &a[d]);
		b[d] = a[d];
	}
	sort(b, b + c);
	unordered_map<int, int>U;
	for (int i = 0; i < c; i++) {
		U[b[i]] = i;
	}
	int ans = 0;
	for (int i = 0; i < c; i++) {
		if ((U[a[i]] - i) & 1)ans++;
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 5156
import java.util.Scanner;
public class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
     int a,b,c;
        for (;;) {
            a = sc.nextInt();
            b = sc.nextInt();
            if (a ==0 && b == 0)break;
            if (a > b){
                c = a;
                a = b;
                b = c;
            }
            System.out.println(a +" "+b);
        }


    }
}



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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

typedef long long ll;
typedef pair<int, int> pii;


int C2(int n) {
    return n * (n - 1) / 2;
}

int main()
{
    //freopen("input.txt", "r", stdin);


    int n, m;
    scanf("%d %d", &n, &m);
    printf("%d\n", C2(n) + C2(m));
}


Measured memory_bytes: 256
X = int(input())

if 400<=X<=599:
    print(8)
if 600<=X<=799:
    print(7)
if 800<=X<=999:
    print(6)
if 1000<=X<=1199:
    print(5)
if 1200<=X<=1399:
    print(4)
if 1400<=X<=1599:
    print(3)
if 1600<=X<=1799:
    print(2)
if 1800<=X<=1999:
    print(1)

Measured memory_bytes: 61652
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, k;
    cin >> a >> b >> k;
    if(a <= k) {
        if(b - k + a < 0)
            cout << 0 << " " << 0 << endl;
        else
            cout << 0 << " " << b - k + a << endl;
    } else {
        cout << a - k << " " << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
ans = 0
for x1, y1 in XY:
    for x2, y2 in XY:
        ans += ((x1 - x2)**2 + (y1 - y2)**2)**0.5
print(ans/N)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n , k;
	ios::sync_with_stdio(0);
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 1 ; i < s.length() ; i++) {
		if(s[i] == s[i - 1])ans++;
	}
	ans = min(2 * k + ans , n -1); 
	cout << ans << "\n";
	return 0;
}

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

vector<pair<int,long> > items;//{weight , value}

 
long memory[100001][101] = {0,};

long dp(int w,int i){
    if(w < 0){
        return INT_MIN;
    }
    if(i<0){
        return 0;
    }
    if(memory[w][i]>0){
        return memory[w][i];
    }
    return memory[w][i] = max(items[i].second + dp(w - items[i].first , i-1) , dp(w,i-1));
}

int main(){
    int n,w;
    cin>>n>>w;
    items.resize(n);
    for(int i=0;i<n;i++){
        cin>>items[i].first>>items[i].second;
    }
    cout<<dp(w,n-1);
}

Measured memory_bytes: 78848
#include <iostream>

using namespace std;

int main()
{
    string s1,s2,s3; cin>>s1>>s2;
    int n1,n2; cin>>n1>>n2;
    cin>>s3;
    if(s3==s1){n1--;}
    else{n2--;}
    cout<<n1<<" "<<n2;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  ll x, y;
  scanf("%lld %lld", &x, &y);
  ll r = 0;
  while(x <= y) {
    r++;
    x *= 2;
  }
  printf("%lld\n", r);
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main() {

	ll n;
	cin >> n;

	int ans = IINF;
	for(ll i = 1; i <= (ll)sqrt(n) + 1; i++){
		ll a = i;
		if(n % a != 0) continue;
		ll b = n / a;

		int cnt1 = 0, cnt2 = 0;
		while(a != 0){
			cnt1++;
			a /= 10;
		}
		while(b != 0){
			cnt2++;
			b /= 10;
		}
		ans = min(ans, max(cnt1, cnt2));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, a[100005] = {}, b[100005] = {}, c = 0;
    pii f[100005] = {};
    ll z = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= m; i++) cin >> f[i].second >> f[i].first;
    sort(f + 1, f + m + 1); reverse(f + 1, f + m + 1);
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j < f[i].second && c <= n; j++) b[++c] = f[i].first;
    }
    for (int i = 1; i <= n; i++) z += max(a[i], b[i]);
    cout << z;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define W 1
#define B 2

const int N=1e5+5;

int n, root;
int leaf[N];
int col[N];
vector<int> g[N];

int dfs(int u, int par)
{
	vector<pair<int, int> > childs;
	for(auto &it:g[u])
	{
		if(it==par)
			continue;
		childs.push_back({dfs(it, u), it});
	}
	for(auto &it:childs)
	{
		if(it.first==0)
		{
			col[u]=W;
			col[it.second]=B;
			break;
		}
	}
	for(auto &it:childs)
	{
		if(col[it.second]==0)
		{
			bool check=1;
			for(auto &it2:g[it.second])
				check&=(col[it2]!=2);
			if(check)
				col[it.second]=1;
		}
	}
	if(u==root)
	{
		bool check=1;
		for(auto &it:childs)
			check&=(it.first==W);
		if(check)
			col[u]=W;
	}
	return col[u];
}

int32_t main()
{
	IOS;
	cin>>n;
	if(n==2)
	{
		cout<<"Second";
		return 0;
	}
	for(int i=1;i<=n-1;i++)
	{
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	{
		if(g[i].size()>1)
		{
			root=i;
			dfs(i, i);
			break;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(col[i]==W)
		{
			bool check=1;
			for(auto &it:g[i])
				check&=(col[it]==W);
			if(check)
			{
				cout<<"First";
				return 0;
			}
		}
	}
	cout<<"Second";
	return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if ((N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else if ((N / 10) % 111 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  int a,b,c,k; cin >>a >>b >>c >>k;
  bool can = false;
  rep(i,k){
    if(a>=b) b*=2;
    else if(b>=c) c*=2;
    if(a<b && b<c) can = true;
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

map<int, int, greater<int> > cnt;

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

    for (int i = 1; i <= n; i++) {
        int tmp;
        cin >> tmp;

        cnt[tmp]++;
    }

    ll area = 1;
    int cc = 0;

    for (auto x : cnt) {
        if (x.second >= 2) {
            if (x.second >= 4 && !cc) {
                cout << (ll)x.first * x.first;
                return 0;
            }
            area *= x.first;
            cc++;
            if (cc == 2) {cout << area; return 0;}
        }
    }

    cout << 0;
}


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

string s1, s2;

int main() {
    cin >> s1;
    s2 = s1;
    reverse(s1.begin(), s1.end());
    
    if (s1 == s2)
    {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = gets(chomp:true).to_i

r = []
n.times do
  r << gets(chomp:true).to_i
end

maxv = r[1] - r[0]

minv = r[0]

for j in 1...n
  if maxv < r[j]-minv
    maxv = r[j]-minv
  end

  minv = r[j] if minv > r[j]

end

puts maxv


Measured memory_bytes: 9920
#include <stdio.h>
int tax(int p,int x){
	return p*(100+x)/100;
}
int main(void){
	int x,y,s,max,i,j,before,after;
	while(1){
		scanf("%d %d %d",&x,&y,&s);
		if(!x){
			break;
		}
		max=0;
		for(i=1;i<s;i++){
			for(j=1;j<s;j++){
				before=tax(i,x)+tax(j,x);
				after=tax(i,y)+tax(j,y);
				if(before==s&&after>max){
					max=after;
				}
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 600
K = int(input())
A = [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]
print(A[K-1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long long fac[200005];
long long mod = 1000000007;
long long F(int n){
	long long&ret = fac[n];
	if(~ret) return ret;
	if(n<=1) return 1;
	return ret = (n*F(n-1))%mod;
}
long long multi(long long a,long long b){
	if(b==0) return 1;
	if(b==1) return a;
	long long ret = multi(a,b/2);
	ret*=ret;
	ret%=mod;
	if(b%2) ret*=a;
	return ret%mod;
}
long long C(long long a,long long b){
	long long ret = 1;
	for(long long i=a; i>=a-b+1; i--){
		ret*=i;
		ret%=mod;
	}
	long long down = F(b);
	return (ret*multi(down,mod-2))%mod;
}
int main(){
	memset(fac,-1,sizeof(fac));
	long long n,a,b;
	cin>>n>>a>>b;
	long long ret = multi(2,n);
	ret--;
	ret-=(C(n,a)+C(n,b))%mod;
	if(ret<0) ret+=mod;
	cout<<ret;
}

Measured memory_bytes: 11392
n = int(input())
S = input()
l = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
     "Q","R","S","T","U","V","W","X","Y","Z"]
s1 = ""
for s in S:
  sind = l.index(s)
  s1 += l[(sind+n)%26]
print(s1)
  

Measured memory_bytes: 3064
t = input()
le = len(t)
tt = []
for i in range(le):
    c = t[i]
    if t[i] == '?':
        c = 'D'
        if i > 0 and tt[i - 1] == 'P':
            c = 'D'
        elif i == 0 and le > 1 and t[i + 1] == 'D' or i == 0 and le > 1 and t[i + 1] == '?':
            c = 'P'
        elif i < le - 1 and t[i + 1] == 'D' or i < le - 1 and t[i + 1] == '?':
            c = 'P'
    tt.append(c)
print(''.join(tt))

Measured memory_bytes: 11060
//
//  main.cpp
//  biggner20200419
//
//  Created by zer0 on 2020/04/19.
//  Copyright © 2020 zer0. All rights reserved.
//

#include <iostream>

const double PI=3.14159265358979323846;

int main(int argc, const char * argv[]) {
    double r,c;
    
    std::cin >> r;
    
    c=2*r*PI;
    
    // insert code here.std..
    std::cout << c;
    
    
    return 0;
}


Measured memory_bytes: 3808
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;
use std::collections::VecDeque;

fn main() {
    input! {
        h: usize,
        w: usize,
        s: [chars; h]
    }
    let mut ans = 0;

    for i in 0..h {
        for j in 0..w {
            if s[i][j] == '#' {
                continue;
            }
            ans = max(ans, bfs(&s, (i, j)));
        }
    }

    println!("{}", ans);
}

fn bfs(s: &Vec<Vec<char>>, from: (usize, usize)) -> usize {
    let s = s.clone();
    let mut s: Vec<Vec<isize>> = s
        .into_iter()
        .map(|si| {
            si.into_iter()
                .map(|sij| if sij == '.' { isize::max_value() } else { -1 })
                .collect()
        })
        .collect();
    s[from.0][from.1] = 0;
    let mut q = VecDeque::new();
    q.push_front(from);

    let mut d = 0;
    while !q.is_empty() {
        let (pi, pj) = q.pop_front().unwrap();
        d = max(d, s[pi][pj]);
        for &(x, y) in [
            (pi + 1, pj),
            (pi, pj + 1),
            (pi.wrapping_sub(1), pj),
            (pi, pj.wrapping_sub(1)),
        ]
        .iter()
        {
            if x > s.len() - 1
                || y > s[0].len() - 1
                || s[x][y] == -1
                || s[x][y] != isize::max_value()
            {
                continue;
            }
            s[x][y] = s[pi][pj] + 1;
            q.push_back((x, y));
        }
    }
    d as usize
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
/*
  l:テ・ツキツヲテァツォツッ
  r:テ・ツ渉ウテァツォツッ
  h:テァツ渉セテ・ツ慊ィテ」ツ?ョテヲツーツエテ、ツスツ?
  w:1テァツァツ津」ツ?づ」ツ?淌」ツつ甘」ツ?ョテヲツーツエテ」ツ?ョテゥツ??
  lkabe:テ・ツキツヲテ」ツ?ョテ・ツ」ツ?」ツ?ョテゥツォツ佚」ツ??
  rkabe:テ・ツキツヲテ」ツ?ョテ・ツ」ツ?」ツ?ョテゥツォツ佚」ツ??
*/
const double EPS = 1e-8; 
struct dat{double l,r,h,w,lkabe,rkabe;};
typedef pair<double,double> P;
typedef pair<P,int> PP;
vector<dat> A;

double getMinTime(){
  double res = 1e9;
  for(dat a:A){
    if(a.w==0)continue;
    double t = ((min(a.lkabe,a.rkabe) - a.h)*(a.r-a.l)*30)/a.w;
    res = min(res,t);
  }
  return res;
}

dat Merge(dat l,dat r){
  dat res;
  res.l = l.l;
  res.r = r.r;
  res.h = min(r.h,l.h);
  res.w = l.w + r.w;
  res.lkabe = l.lkabe;
  res.rkabe = r.rkabe;
  return res;
}

bool replace(int idx,int flg){
  A[idx+flg].w += A[idx].w;
  A[idx].w = 0;
  if(abs(A[idx+flg].h-A[idx].h)>EPS) return 0 ;
  if(flg == 1) A[idx] = Merge(A[idx],A[idx+1]);
  if(flg == -1)A[idx] = Merge(A[idx-1],A[idx]);
  A.erase(A.begin()+idx+flg);
  return 1;
}

void adTime(double sec){
  for(int i=0;i<(int)A.size();i++){
    if(A[i].w==0)continue;
    A[i].h += (sec*A[i].w)/(30*(A[i].r-A[i].l));
  }

  int update = 1;
  while(update){
    update = 0;
    for(int i=0;i<(int)A.size();i++){
      if(A[i].w==0)continue;
      
      if(A[i].lkabe<=A[i].h+EPS){ update=1,replace(i,-1);break;}
      else if(A[i].rkabe<=A[i].h+EPS) { update=1,replace(i,1);break;}
    } 
  }
}

void sim(double t){
  while(t){
    double sec = min(t,getMinTime());
    assert(sec>=0);
    adTime(sec);
    t -=sec;
  }
}


double getH(int x){
  for(int i=0;i<(int)A.size();i++) if(A[i].l<x && x<A[i].r) return A[i].h;
  return -1;
}

int main(){
  int q;
  cin>>q;
  while(q--){
    int n;
    cin>>n;
    A.resize(n+1);
    double l=0,r,lkabe=1e15,rkabe;
    for(int i=0;i<n; i++,l=r,lkabe = rkabe){
      cin>>r>>rkabe;
      A[i] = (dat){l,r,0,0,lkabe,rkabe};
      if(i==n-1) A[n] = (dat){r,100,0,0,rkabe,1e15};
    }
    
    int m;
    cin>>m;
    for(int i=0,x,w;i<m;i++){
      cin>>x>>w;
      for(dat &a:A) if(a.l<x&&x<a.r)a.w+=w;
    }
    int L;
    cin>>L;
    while(L--){
      vector<dat> tmp = A;
      double x,t;
      cin>>x>>t;
      sim(t);
      printf("%.8f\n",min(50.0,getH(x)));
      A = tmp;
    }

  }
  return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll ans = 0;
    if(b>n){
        ans = (a*n)/b - a*(n/b);
    }else{
        ans = (a*(b-1))/b - a*((b-1)/b);
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;
const int h1 = 1299827, h2 = 27617;

pll p[500005], sum[500005];
vector<int> g[500005];
char s[500005];
int n;
pll check2(int l, int r){
    pll ans;
    ans.fi = (sum[r].fi-sum[l-1].fi+mod)%mod*1ll*p[n-r].fi%mod;
    ans.se = (sum[r].se-sum[l-1].se+mod)%mod*1ll*p[n-r].se%mod;
    return ans;
}
bool check(int l, int r){
    if(r-l+1 == 1) return 1;
    int le = r-l+1;
    for(int j=0;j<sz(g[le]);j++){
        int d = g[le][j];
        if(check2(l, r-d) == check2(l+d, r)) return 0;
    }
    return 1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s+1;
    n = strlen(s+1);
    p[0] = mp(1, 1);
    for(int i=1;i<=n;i++) p[i] = mp(p[i-1].fi*1ll*h1%mod, p[i-1].se*1ll*h2%mod);
    for(int i=1;i<=n;i++) sum[i] = mp((sum[i-1].fi + s[i]*1ll*p[i].fi)%mod, (sum[i-1].se + s[i]*1ll*p[i].se)%mod);
    bool ok = 1;
    for(int i=2;i<=n;i++){
        if(s[i] != s[i-1]) ok = 0;
    }
    if(ok){
        printf("%d\n", n);
        printf("1\n");
        return 0;
    }
    for(int i=1;i<=n;i++){
        for(int j=i+i;j<=n;j+=i) g[j].eb(i);
    }
    if(check(1, n)){
        printf("1\n");
        printf("1\n");
        return 0;
    }
    int ans = 0;
    for(int i=1;i<=n-1;i++){
        if(check(1, i) && check(i+1, n)) ans++;
    }
    printf("2\n");
    printf("%d\n", ans);
}

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

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return

#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define repd(i,a,b) for (ll i = (a); i >= b; i--)
#define repdz(i,a) for (ll i = a; i >=0; i--)
#define trav(a, x) for (auto& a : x)

#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define llin(a) ll a; cin>>a;
#define llin2(a,b) ll a,b; cin >>a>>b;
#define llin3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define full(v) v.begin(),v.end()

const int N = 1e6+7;
int marked[N];

void solve()
{
    int n;
    cin >> n;
    vi a(n);

    int mx = -1;
    repz(i,n)
    {
        cin >> a[i];
        mx  = max(mx,a[i]);
    }


    for (int i = 0; i < n; i++)
    {
        for (int j = a[i]; j <= mx ; j += a[i])
        {
            marked[j]++;
        }
    }

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if (marked[a[i]] > 1)
            sum++;
    }

    cout << n-sum << endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //llin(t);
    //while (t--)
    //{
        solve();
    //}
}


Measured memory_bytes: 7796
/** author: __nishad__ **/

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


typedef long long ll ;
typedef vector<ll> vll ;

#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define uni(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979323


int main()
{
    IOS;

    ll n;
    string ff, ss;
    bool ans=true;
    vector<string> v;

    cin>>n;
    n=n-1;
    cin>>ff;

    v.pb(ff);

    while(n--){
        cin>>ss;
        if(ff[ff.size()-1] != ss[0])
            ans = false;

        ff = ss;


        if(find(v.begin(), v.end(), ss) != v.end()){
            ans = false;
        }
        v.pb(ss);

    }

    if(ans)
        cout<<"Yes";
    else
        cout<<"No";






}



Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	mp := map[int]int{}
	for i := 0; i < K; i++ {
		_ = sc.NextInt()
		A := sc.NextIntArray()
		for _, v := range A {
			mp[v]++
		}
	}
	fmt.Println(N - len(mp))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 2024
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
a=get_i
b=get_i
r=0
if a.inject(:+)<b.inject(:+)
    puts -1
    exit
end
dif=array(N)
N.times do|i|
    dif[i]=a[i]-b[i]
end
ans=0
neg=dif.select{|x| x<0}
ans+=neg.size
sum=neg.inject(0){|res,x| res-=x}
dif.sort{|x,y| y<=>x}.each do|d|
    if sum<=0
        break
    end
    sum-=d
    ans+=1
end
puts ans

Measured memory_bytes: 19844
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N;
    cin >> N;
    vector<int> a, b;
    for(int i = 0; i < N; i++){
        a.push_back(i + 1);
        b.push_back(N - i);
    }
    int rank[N];
    for(int i = 0; i < N; i++){
        int p;
        cin >> p;
        rank[p - 1] = i;
    }
    int a_sum = 0, b_sum = 0;
    for(int i = 0; i < N; i++){
        a_sum += rank[i];
        a[i] += a_sum;
        b_sum += rank[N - i - 1];
        b[N - i - 1] += b_sum;
    }
    array_output(all(a));
    array_output(all(b));
}


Measured memory_bytes: 1360
n, m, k = list(map(int, input().split()))
mod = 998244353
m_ = m - 1
n_ = n - 1
m_p = {0: 1}
ans = 0
fac = {0: 1, 1: 1}
finv = {0: 1, 1: 1}
inv = {1: 1}

def comb_init():
    for i in range(2, n + 1):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod
def pow_init(m):
    for i in range(1, m):
        m_p[i] = m_p[i - 1] * m_
        m_p[i] %= mod

comb_init()
pow_init(n_ - k)
for i in range(k, -1, -1):
    if n_ - i not in m_p:
        m_p[n_ - i] = m_p[n_ - i - 1] * m_ % mod
    d = m * comb(n_, i) % mod 
    d *= m_p[n_ - i]
    ans += d % mod
    ans %= mod
print(ans)

Measured memory_bytes: 98068
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	io;
	int a,b;
  cin>>a>>b;
  cout<<(a>=2*b?a-2*b:0);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N = 2005;
const int mod = 1e9 + 7;
using namespace std;

vector <int> G[N];
int n, dp[N][N][3], g[N][3], c[N], ans;

void add(int&a, int b){
    a += b; if (a >= mod) a -= mod; if (a < 0) a += mod;
}

void dfs(int u){
    c[u] = 0;
    dp[u][0][0] = 1;
    for (auto v : G[u]){
        dfs(v);
        for (int i = 0; i <= c[u]+c[v]+1; i++) g[i][0] = g[i][1] = g[i][2] = 0;
        for (int i = 0; i <= c[u]; i++) for (int j = 0; j <= c[v]; j++){
            add(g[i+j][0], 1LL * dp[u][i][0] * dp[v][j][0] % mod);
            add(g[i+j][1], 1LL * dp[u][i][1] * dp[v][j][0] % mod);
            add(g[i+j+1][1], 1LL * dp[u][i][0] * dp[v][j][1] % mod);
            add(g[i+j][2], 1LL * dp[u][i][2] * dp[v][j][0] % mod);
            add(g[i+j+1][2], 1LL * dp[u][i][1] * dp[v][j][1] % mod);
        }
        for (int i = 0; i <= c[u]+c[v]+1; i++) dp[u][i][0] = g[i][0], dp[u][i][1] = g[i][1], dp[u][i][2] = g[i][2];
        c[u] += c[v] + 1;
    }
    for (int i = 0; i <= c[u]; i++){
        int a = dp[u][i][0], b = dp[u][i][1], c = dp[u][i][2];
        dp[u][i][0] = a; add(dp[u][i][0], 2LL * b % mod); add(dp[u][i][0], 2LL * c % mod);
        dp[u][i][1] = a; add(dp[u][i][1], b);
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 2; i <= n; i++){
        int x; cin >> x;
        G[x].push_back(i);
    }
    dfs(1); int f = 1;
    for (int i = n-1; i >= 0; i--){
        f = 1LL * f * (n - i) % mod;
        if (i&1) add(ans, -1LL * f * dp[1][i][0] % mod);
        else add(ans, 1LL * f * dp[1][i][0] % mod);
    }
    cout << ans;
}


Measured memory_bytes: 47744
# -*- coding: utf-8 -*-
#D - Equals
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def union(x,y):
    x = find(x)
    y = find(y)
    if x != y:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return
# xとyが同じ集合に属するか
def same(x,y):
    return find(x) == find(y)
#xが属する集合の個数
def size(x):
    return -par[find(x)]

N,M = map(int,readline().split())
P = list(map(int,readline().split()))
# 0-index
par = [-1]*(N+1)

for _ in range(M):
    x,y = map(int,readline().split())
    union(x,y)

cnt = 0
for i,p in enumerate(P,1):
    if same(i,p):
        cnt += 1
print(cnt)

Measured memory_bytes: 18704
N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
tmp = A[0]
mn = abs(sum_A - tmp*2)
for i in range(1,N-1):
    tmp += A[i]
    # print(tmp, sum_A-tmp*2)
    if abs(sum_A-tmp*2) < mn:
        mn = abs(sum_A-tmp*2)
print(mn)

Measured memory_bytes: 23800