akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int read()
{
	char ch=getchar();int h=0,t=1;
	while(ch>'9'||ch<'0') ch=getchar();
	while(ch>='0'&&ch<='9') h=h*10+ch-'0',ch=getchar();
	return h*t;
}
const int N=2e5+10,mod=1e9+7,inv=5e8+4;
int n,ans,tot=1,D[N],C[N],t1[N],t2[N],lst[N],A[N],cnt[N];
void add(int &x,int y) {x+=y;if(x>mod) x-=mod;}
void Add(int x,int k) {while(x<=n) add(t1[x],k),t2[x]++,x+=x&(-x);}
int Sum1(int x) {int s=0;while(x) add(s,t1[x]),x-=x&(-x);return s;}
int Sum2(int x) {int s=0;while(x) s+=t2[x],x-=x&(-x);return s;}
int ksm(int x,int k) {int s=1;for(;k;k>>=1,x=1ll*x*x%mod) if(k&1) s=1ll*s*x%mod;return s;}
int main()
{
	n=read();D[0]=1;
	for(int i=1;i<=n;i++) A[i]=read(),cnt[A[i]]++;
	for(int i=n;i>=1;i--) cnt[i]+=cnt[i+1];
	for(int i=1;i<=n;i++) cnt[i]-=(n-i),tot=1ll*tot*cnt[i]%mod;
	if(tot<=0) {puts("0");return 0;}
	for(int i=1;i<=n;i++)
	{
		int x=1ll*(cnt[i]-1)*ksm(cnt[i],mod-2)%mod;
		if(!x) lst[i]=i,D[i]=D[i-1];
		else lst[i]=lst[i-1],D[i]=1ll*D[i-1]*x%mod;
		C[i]=ksm(D[i],mod-2);
	}
	for(int i=1,s=A[1];i<=n;i++)
	{
		add(ans,1ll*(Sum1(s)-Sum1(lst[s]))%mod*tot%mod*inv%mod*D[s]%mod);
		Add(s,C[s]);s=A[i+1];ans=(ans+mod)%mod;
	}
	for(int i=1;i<=n;i++) t1[i]=t2[i]=0;
	for(int i=n,s=A[n];i;i--)
	{
		add(ans,1ll*Sum2(s-1)*tot%mod);
		add(ans,-1ll*(Sum1(s-1)-Sum1(lst[s]))%mod*tot%mod*inv%mod*D[s]%mod);
		Add(s,C[s]);s=A[i-1];(ans+=mod)%=mod;
	}
	printf("%d\n",(ans+mod)%mod);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll Q;
    cin >> Q;
    vc<set<ll>> ss(26);
    rep(i,N){
        ss[S[i] - 'a'].emplace(i);
    }
    rep(i, 26) ss[i].emplace(N);

    while(Q--){
        ll q;
        cin >> q;
        if(q==1){
            ll x;
            char c;
            cin >> x >> c;
            x--;
            if (S[x] == c) continue;
            ss[S[x] - 'a'].erase(x);
            ss[c - 'a'].emplace(x);

            S[x] = c;
            
        }else{
            ll l, r;
            cin >> l >> r;
            l--, r--;
            ll ans = 0;
            rep(i,26){
                ll t = *ss[i].lower_bound(l);
                if(l<=t&&t<=r)
                    ans++;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 24220
#include<stdio.h>
#include<math.h>
int main()
{
	int n,t,i;

	scanf("%d",&n);

	for(i=7;i>=0;i--){
		t=pow(2,i);
		if(t<=n){
			printf("%d",t);
			return 0;
		}
	}
}

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


int main()
{
	double a, b, c, d, e;
	cin >> a >> b >> c >> d;
	e = sqrt(pow(c-a, 2) + pow(d-b, 2));
	printf("%0.6f\n", e);
	return 0;
}



Measured memory_bytes: 3296
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const k = +input[0];
const [a, b] = input[1].split(" ").map((x: string): number => +x);

let result = false;
for (let i = a; i <= b; i++) {
	if (i % k === 0) result = true;
}

console.log(result ? "OK" : "NG");


Measured memory_bytes: 29576
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

void solve(long long K){
    if(K == 0){
        cout << 2 << endl;
        cout << "1 1" << endl;
    }
    else if( K <= 10){
        ll N = max(2LL, K+1);
        vll A(N, 0);
        A[0] = K * N;
        cout << N << endl;
        REP(i, N){
            cout << A[i] << " ";
        }
        cout<<endl;
    }
    else{
        ll N = min(50LL, K-1);
        
        ll num_big = K / N;
        ll num_res = K % N;
        vll A(N, N - 1 + num_big);
        
        REP(i, num_res){
            A[i] += N - num_res + 1;
        }
        for(ll i = num_res; i < N; i++){
            A[i] -= num_res;
        }
        cout << N << endl;
        REP(i, N){
            cout << A[i] << " ";
        }
        cout<<endl;
    }



}

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n;
    int k;
    int ans = 0;
    int f = 0;
    int i, j;

    scanf("%d", &n);

    while (n != 0) {
        ans = 0;
        f = 0;

        for (i = 0; i < n; i++) {
            scanf("%d", &k);
            
            if (k >= 2) f = 1;
            if (k != 0) ans++;
        }

        if (f) {
            printf("%d\n", ans + 1);
        } else {
            printf("NA\n");
        }

        scanf("%d", &n);
    }

    

    return 0;
}



Measured memory_bytes: 2704
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF 1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second
#define setprecision(d) cout << fixed << setprecision(d);

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

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





signed main(){
	ll n,a = 0,b = 0,cnt = 1;
	cin >> n;
	ll p[n],q[n],array[n];

	rep(i,0,n) cin >> p[i];
	rep(i,0,n) cin >> q[i];
	rep(i,0,n) array[i] = i+1;

	do{
		bool flag = true;
		
		rep(i,0,n){
			if(p[i] != array[i]){
				flag = false;
			}
			else if(i == n-1 && flag){
				a = cnt;
			}
		}

		flag = true;

		rep(i,0,n){
			if(q[i] != array[i]){
				flag = false;
			}
			else if(i == n-1 && flag){
				b = cnt;
			}
		}

		cnt++;
	}while(next_permutation(array,array+n));


	cout << abs(a-b) << endl;

    return 0;
}

Measured memory_bytes: 256
/*input
10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

*/

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

int add (int x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
  return x;
}

int mul (int x, int y) {
  return (long long)x * y % MOD;
}

int active[64];

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    for (int j = 0; j < 62; ++j) {
      active[j] += ((x & (1LL << j)) != 0);
    }
  }

  int ans = 0, i = 1;
  for (int j = 0; j < 62; ++j) {
    int count = mul(active[j], n - active[j]);
    int amount = mul(count, i);
    ans = add(ans, amount);
    i = mul(i, 2);
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int n;
    cin >> n;
    vl a(n+2);
    ll sum = 0;
    a[0] = 0;
    a[n+1] = 0;
    reps(i,1,n+1){ 
        cin >> a[i];
    }

    rep(i,n+1){
        sum += abs(a[i] - a[i+1]);
    }
    reps(i,1,n+1){
        cout << sum + abs(a[i-1]-a[i+1]) - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])) << endl;
    }


    return 0;
}

Measured memory_bytes: 3992
n = int(input())

cnt_ac = 0
cnt_wa = 0
cnt_tle = 0
cnt_re = 0

for i in range(n):
    s = input()
    if s == 'AC':
        cnt_ac += 1
    elif s == 'WA':
        cnt_wa += 1
    elif s == 'TLE':
        cnt_tle += 1
    elif s == "RE":
        cnt_re += 1

print('AC x ', cnt_ac)
print('WA x ', cnt_wa)
print('TLE x ', cnt_tle)
print('RE x ', cnt_re)




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

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

    int64_t damage = 0;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        damage += a;
    }

    cout << (damage >= h ? "Yes" : "No")<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(){ }
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

//線分x線分交差判定
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}


class State{
public:
	double sum;
	int t,s;
	P cur;
	State(){}
	State(double c, int a, int b, P p):sum(c),t(a),s(b),cur(p){}
	bool operator < (const State &opp)const{
		return sum > opp.sum;
	}
};
//点pを中心としてr(radian)回転		p(0,0)で原点を中心として回転
P rotate(P t , P p , double r){
	double ta=cos(r)*real(t-p)-sin(r)*imag(t-p)+real(p);
	double tb=sin(r)*real(t-p)+cos(r)*imag(t-p)+imag(p);
	return P(ta , tb);
}


//単位ベクトルを求める
P unit_vector(P t){
	return t/fabs(abs(t));
}

//２円 |x-a|=raと|x-b|=rbの交点計算
L interpointCC(C a , C b){
	double di=fabs(abs(a.p-b.p));
	if(di > a.r+b.r || di < fabs(a.r-b.r)) return L(P(0, 0), P(0, 0));
	double t=(a.r*a.r-b.r*b.r+di*di)/(di+di);
	double rd=acos(t/a.r);

	P dv=unit_vector(b.p-a.p);
	P g1=rotate(dv , P(0,0) , rd);
	P g2=rotate(dv , P(0,0) , -rd);
	return L(a.p+g1*a.r, a.p+g2*a.r);
}

double dp[101][2];
int v[101][2];
vector <L> Lines;

bool check(L l, int s, int t){
	for(;s<t;s++) if(!intersectSS(l, Lines[s]))return 0;
	return 1;
}

main(){
	int i,j,n;

	while(cin>>n, n){
		priority_queue<State> S;
		memset(v, 0, sizeof(v));
		for(i=0;i<=100;i++) dp[i][0] = dp[i][1] = INF;
		Lines.clear();
		C Prev, Now;
		double x, y, r;
		cin >> x >> y >> r;
		Now = C(P(x, y), r);
		P Start = Now.p;
		Lines.push_back(L(Start, Start));
		for(i=1;i<n;i++){
			Prev = Now;
			cin >> x >> y >> r;
			Now = C(P(x, y), r);
			Lines.push_back(interpointCC(Now, Prev));
		}
		Lines.push_back(L(Now.p, Now.p));
		S.push(State(0, 0, 0, Start));
		while(!S.empty()){
			State t = S.top();S.pop();
			if(v[t.t][t.s]) continue;
			v[t.t][t.s] = 1;
			if(t.t == n) break;
			for(i=t.t+1;i<=n;i++){
				for(j=0;j<2;j++){
					if(v[i][j]) continue;
					L l = L(t.cur, (j?Lines[i][1]:Lines[i][0]));
					if(!check(l, t.t+1, i)) continue;
					if(dp[i][j] < abs(l[1]-l[0]) + t.sum) continue;
					dp[i][j] = abs(l[1]-l[0]) + t.sum;
					S.push(State(dp[i][j], i, j, l[1]));
				}
			}
		}
		printf("%.4lf\n", dp[n][0]);
	}
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  string s,t;
  cin>>s>>t;

  int n=s.size();

  int ans=0;
  rep(i,n){
    if(s[i]!=t[i]) ans++;
  }

  cout << ans << endl;
}

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

#define llint long long int

using namespace std;

llint mod_pow(llint a, llint n, llint p){
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        llint d = mod_pow(a, n / 2, p);

        return (d * d) % p;
    } else {
        return (a * mod_pow(a, n - 1, p)) % p;
    }
}
llint mod_inv(llint a, llint p){
    return mod_pow(a, p - 2, p);
}
int main(){
    llint p = 1000000000 + 7;

    llint n, a, b;

    cin >> n >> a >> b;

    vector<llint> inv(b);

    for(llint i = 0; i < b; i ++){
        inv[i] = mod_inv(i + 1, p);
    }
    llint nCa = 1;

    for(llint i = 0; i < a; i ++){
        nCa = (nCa * (n - i)) % p;
        nCa = (nCa * inv[i]) % p;
    }
    // cout << nCa << endl;
    llint nCb = 1;

    for(llint i = 0; i < b; i ++){
        nCb = (nCb * (n - i)) % p;
        nCb = (nCb * inv[i]) % p;
    }
    // cout << nCb << endl;
    llint ans = (mod_pow(2, n, p) - 1 + p) % p;
    // cout << ans << endl;

    ans = (ans - nCa + p) % p;
    ans = (ans - nCb + p) % p;

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll K;
    cin >> K;
    if(K < 10){
        cout << K << endl;
        return 0;
    }
    ll cnt = 9;
    queue<string> que;
    for(char c = '1'; c <= '9'; c++){
        string t{c};
        que.push(t);
    }
    while(!que.empty()){
        auto t = que.front();
        que.pop();
        for(char c = '0'; c <= '9'; c++){
            if(abs(t[t.size()-1] - c) > 1) continue;
            que.push(t+c);
            cnt++;
            if(cnt == K){
                cout << t+c << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4864
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A1 = []
A2 = []

for i in range(1,N+1):
   A1.append(i + A[i-1])
   A2.append(i - A[i-1])
  
c1 = Counter(A1)
c2 = Counter(A2)

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)

Measured memory_bytes: 71760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
using namespace std;

int main() {
    int n,k; cin >> n >> k;
    double ans=0;
    for(int i = 1; i<=n; i++){
        int point = i;
        double num = 1.0;
        int count=0;
        while(point<k){
            point *= 2;
            num *= 0.5;
            count += 1;
        }
        if(count!=0){
            ans += num/n;
        }else{
            ans += 1.0/n;
        }
    }
    cout << setprecision(12) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

// ?????¢??¢?´¢
int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while ( A[i] != key ) i++;
  return i != n;
}

int main() {
  int i, n, A[10000+1], q, key, sum = 0;
  
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  
  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &key);
    if ( search(A, n, key) ) sum++;
  }
  printf("%d\n", sum);
  
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        String ans = (b - a == c - b)? "YES" : "NO";
        System.out.println(ans);
    }
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  vector<ll> a,b;
  rep(i,n) {
    ll x;
    R x;
    if(x>=0) a.pb(x);
    else b.pb(x);
  }
  sort(all(a));
  sort(all(b),greater<ll>());
  vector<P> v;
  if(a.size()&&b.size()) {
    rep(i,a.size()-1) {
      v.pb(P(b.back(),a[i]));
      b.back()-=a[i];
    }
    rep(i,b.size()-1) {
      v.pb(P(a.back(),b[i]));
      a.back()-=b[i];
    }
    v.pb(P(a.back(),b.back()));
    pr(a.back()-b.back());
    rep(i,v.size()) pr(v[i].F,v[i].S);
  } else if(b.size()) {
    REP(i,1,b.size()) {
      v.pb(P(b[0],b[i]));
      b[0]-=b[i];
    }
    pr(b[0]);
    rep(i,v.size()) pr(v[i].F,v[i].S);
  } else {
    REP(i,1,a.size()-1) {
      v.pb(P(a[0],a[i]));
      a[0]-=a[i];
    }
    v.pb(P(a.back(),a[0]));
    a.back()-=a[0];
    pr(a.back());
    rep(i,v.size()) pr(v[i].F,v[i].S);
  }
}

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


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  string s[3];
  int kaisu[3] = {0, -1, -1}, t = 0;

  for (int i = 0; i < 3; i++)
    cin >> s[i];

  // cout << kaisu[0] << kaisu[1] << kaisu[2] << endl;

  while (true) {
    if (kaisu[t] >= s[t].size()) {
      cout << (char)('A' + t) << endl;
      return 0;
    }

    // cout << "char is -- " << s[t][kaisu[t]] << endl;
    t = s[t][kaisu[t]] - 'a';
    kaisu[t]++;
    // cout << kaisu[0] << kaisu[1] << kaisu[2] << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(void) {
    int N;
    int buf[200];
    int ans = 0;

    std::cin >> N;
    
    for(int i = 0; i < N; i++) {
        std::cin >> buf[i];
    }

    while(true) {
        for(int i = 0; i < N; i++) {
            if(buf[i] % 2 != 0) {
                std::cout << ans << std::endl;
                return 0;
            }
            buf[i] /= 2;
        }
        ans++;
    }


    return 0;
}


Measured memory_bytes: 256
# a, b = map(int, input().split())
# k = list(map(int, input().split(",")))
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: 3060
use std::io;
use std::f64::consts::PI;

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

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

fn main() {
    from_line!(r: f64);
    println!("{:.6} {:.6}", r*r*PI, r*PI*2.0);
}



Measured memory_bytes: 5060
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n;
	cin >> n;
	cout << 3 * n * n << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <set>
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
#define fi first
#define se second
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    set<string>s;
    int n;
    cin>> n;
    string str;
    while(n--){
        cin>>str;
        s.insert(str);
    }
    cout<<s.size()<<endl;
    return 0;
}



Measured memory_bytes: 15652
package main

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

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	mm := make(map[int]bool)
	am := make(map[int]bool)
	om := make(map[int]bool)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		mm[a] = true
		om[a] = true
	}
	for i := 0; i < m; i++ {
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		if bl, ok := mm[b]; ok && bl {
			am[b] = true
		}
		om[b] = true
	}
	fmt.Printf("%d %d\n", len(am), len(om))
	as := make([]int, 0)
	for k := range am {
		as = append(as, k)
	}
	sort.Sort(sort.IntSlice(as))
	os := make([]int, 0)
	for k := range om {
		os = append(os, k)
	}
	sort.Sort(sort.IntSlice(os))
	for i := range as {
		fmt.Println(as[i])
	}
	for i := range os {
		fmt.Println(os[i])
	}
}



Measured memory_bytes: 25160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int X = sc.nextInt();
		sc.close();
		if(K*500>=X) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 21716
import java.util.Scanner;

//Time Manipulation
public class Main{

	long gcd(long a, long b){
		if(a < b){
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}
	
	long sum(long a, long k){
		return (k*(a+a*k))/2;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			long n = sc.nextLong();
			int m = sc.nextInt();
			if((n|m)==0)break;
			long[] a = new long[m];
			long[] subsum = new long[m];
			for(int i=0;i<m;i++){
				a[i] = sc.nextLong();
				subsum[i] = sum(a[i], n/a[i]);
			}
			long sum = n*(n+1)/2;
			long res = 0;
			for(int i=1;i<(1<<m);i++){
				int num = 0;
				for(int j=0;j<m;j++)if(((i>>j)&1)>0)num++;
				long LCM = 1;
				for(int j=0;j<m;j++){
					if(((i>>j)&1)>0){
						LCM = LCM/gcd(LCM, a[j])*a[j];
						if(LCM>n)break;
					}
				}
				if(num%2==0)sum += sum(LCM, n/LCM);
				else sum -= sum(LCM, n/LCM);
				if(num%2==0)res -= n/LCM;
				else res += n/LCM;
			}
			long N = n-res;
			System.out.printf("%.6f\n", N==0?0.0:(1.0*sum/N));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;
#define int long long
long long total, a[15];
int n;
int h, w, x[100005], y[100005];

map<pair<int, int>, bool> mymap;
map<pair<int, int>, bool> mymap1;
signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> h >> w >> n;
    total = (h - 2) * (w - 2);
    for(int i = 1; i <= n; i++){
        cin >> y[i] >> x[i];
        mymap1[{x[i], y[i]}] = 1;
    }
    for(int i = 1; i <= n; i++){
        for(int l = max(x[i] - 2, 1LL); l <= min(x[i], w); l++){
            for(int j = max(y[i] - 2,1LL); j <= min(y[i], h); j++){
                if(l + 2 <= w && j + 2 <= h && mymap.count({l, j})==0){
                    int count1 = 0;
                    for(int l1 = l; l1 <= l + 2; l1++){
                        for(int l2 = j; l2 <= j + 2; l2++){
                            if(mymap1.count({l1, l2}))
                                count1++;
                            //if(l == 3 && j == 1)
                                //cout << l1 << " " << l2 << "\n";
                        }
                    }
                    a[count1]++;
                    mymap[{l, j}] = 1;
                }
            }
        }
    }
    for(int i = 1; i <= 9; i++)
        total-=a[i];
    a[0] = total;
    for(int i =0;i <= 9;i ++)
        cout << a[i] << "\n";
}

Measured memory_bytes: 64384
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int w, n;
  cin >> w >> n;
  vi v(w);
  iota(all(v), 1);
  rep(i, n) {
    int a, b;
    char gomi;
    cin >> a >> gomi >> b;
    a--;
    b--;
    swap(v[a], v[b]);
  }
  rep(i, w) cout << v[i] << endl;
}

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

string s, t;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> s >> t;
    string newt;
    for (int i = 0; i < t.size() - 1; i++)
    {
        newt += t[i];
    }
    if (newt == s)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    cin >> s;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	ll l[2*n];
	rep(i, 0, 2*n-1){
		cin >> l[i];
	}
	sort(l, l+2*n);
	ll ans = 0;
	rep(i, 0, n-1){
		ans += l[2*i];
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define reg register
#define MAXN 101
#define MAXI 11
using namespace std;

int dis[MAXI][MAXI];
int f[MAXN][MAXN];
int n,m;

inline int max(int a,int b)
{return(a>b?a:b);}

inline int min(int a,int b)
{return(a<b?a:b);}

int main()
{
	scanf("%d %d",&n,&m);
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=m;j++)
			scanf("%d",&dis[i][j]);
	for(reg int i=0;i<=100;i++)
		for(reg int j=0;j<=100;j++)
			for(reg int px=1;px<=n;px++)
				for(reg int py=1;py<=m;py++)
					f[i][j]=max(f[i][j],dis[px][py]-i*px-j*py);
	for(reg int px=1;px<=n;px++)
		for(reg int py=1;py<=m;py++)
		{
			int tmp=2147483647;
			for(reg int i=0;i<=100;i++)
				for(reg int j=0;j<=100;j++)
					tmp=min(tmp,f[i][j]+i*px+j*py);
			if(tmp!=dis[px][py])
			{
				printf("Impossible");
				return(0);
			}
		}
	puts("Possible\n202 10401");
	for(reg int i=1;i<=100;i++)
		printf("%d %d X\n",i,i+1);
	for(reg int i=102;i<=201;i++)
		printf("%d %d Y\n",i,i+1);
	for(reg int i=0;i<=100;i++)
		for(reg int j=0;j<=100;j++)
			printf("%d %d %d\n",1+i,202-j,f[i][j]);
	printf("1 202");
	return(0);
}

Measured memory_bytes: 256
N,K=map(int,input().split())
S=input()

p=S[0]
l=[]

prev_c0=0
prev_c1=0
c=0
order=0
ind=0
ans=[]
val=0

for s in S:
    if s==p:
        c+=1
    else:
        if p=='0':
            prev_c0=c
        if p=='1':
            order+=1
            val+=prev_c0+c
            l.append(prev_c0+prev_c1)
            if order>K:
                val-=l[ind]
                ind+=1
            ans.append(val)
            prev_c1=c
        c=1
        p=s
if c>=2:
    if p=='0':
        if order<K:
            ans.append(val+c)
        else:
            ans.append(val+c-l[ind])
    if p=='1':
        order+=1
        val+=prev_c0+c
        if order>K:
            val-=l[ind]
        ans.append(val)
if len(ans)>0:
    print(max(ans))
else:
    print(len(S))




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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int a[200100];
int main() {
  int n;
  cin >> n;
  repi(n) cin >> a[i];
  int m = -1;
  ll res = 0;
  repi(n) {
    updatemax(m, a[i]);
    res += m - a[i];
  }
  cout << res << endl;
}


Measured memory_bytes: 4408
#include <iostream>
using namespace std;
int main(){
	int W , H , x , y , r;
	bool in=true;
	cin >> W >> H >> x >> y >> r;
	if((x+r)>W || (x-r)<0){
		in=false;
	} 
	if((y+r)>H || (y-r)<0){
		in=false;
	}
	if(in){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
 
int calc(string ex)
{
    if(ex[0]=='(')  ex=ex.substr(1,ex.length()-2);
 
    for(int i=0,depth=0;i<ex.length();i++){
        if     (ex[i]=='(') depth++;
        else if(ex[i]==')') depth--;
        else{
            if(depth==0 && (ex[i]=='+'||ex[i]=='-'||ex[i]=='*')){
                switch(ex[i]){
                    case '+':   return calc(ex.substr(0,i-1))+calc(ex.substr(i+2));
                    case '-':   return calc(ex.substr(0,i-1))-calc(ex.substr(i+2));
                    case '*':   return calc(ex.substr(0,i-1))*calc(ex.substr(i+2));
                }
            }
        }
    }
 
    return ex[0]-'0';
}
 
int main()
{
    char op[]={'+','-','*'};
    char *fmt[]={"(((%d %c %d) %c %d) %c %d)",
                 "((%d %c (%d %c %d)) %c %d)",
                 "((%d %c %d) %c (%d %c %d))",
                 "(%d %c ((%d %c %d) %c %d))",
                 "(%d %c (%d %c (%d %c %d)))"};
 
     for(int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d),a|b|c|d;){
        int n[]={a,b,c,d};
        sort(n,n+4);
        do{
            for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++){
                for(int l=0;l<5;l++){
                    char ex[20];
                    sprintf(ex,fmt[l],n[0],op[i],n[1],op[j],n[2],op[k],n[3]);
                    if(calc(ex)==10){
                        puts(ex);
                        goto FOUND;
                    }
                }
            }
        }while(next_permutation(n,n+4));
        puts("0");
        FOUND:;
    }
 
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); }
 size_t operator()(uint64_t x) const {
  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, W;
    cin >> n >> W;
    V<ll> w(n), v(n);
    rep(i,0,n) cin >> w[i] >> v[i];
    int k = 0;
    rep(i,0,n) k += v[i];
    V<ll> dp(k+1, LLONG_MAX/2);
    dp[0] = 0;
    rep(i,0,n) rep(j,k-v[i]+1,0) dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
    rep(j,k+1,0) {
        if (dp[j] <= W) {
            cout << j << endl;
            exit(0);
        }
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n;
  cin>>n;
  vector<ll> a;
   
  for(int i = 0; i < n; i++){
    int x;
    cin>>x;
    a.push_back(x);
  }

  int right = 0;
  int sum = 0;
  ll ans = 0;
  vector<int> v;
  for(int left = 0; left<n; left++){
    while(right<n&&(sum^a[right])==sum+a[right]){
      sum+=a[right];
      right++;
    }
    ans+=right-left;
    if(right==left) right++;
    else sum-=a[left];
  }
 cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>

int main()
{
	int n;
	int dat;
	int odd = 0, even = 0;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &dat);

		if (dat & 1) {
			odd++;
		} else {
			even++;
		}
	}

	if (odd & 1) {
		puts("NO");
	} else {
		puts("YES");
	}

	return 0;
}


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

typedef long long ll;

vector<vector<ll>> dp((1 << 15),vector<ll>(15,-1));
vector<vector<pair<ll, ll>>> graph(15);
ll n;

ll solve(ll bit, ll v)
{
    if(dp.at(bit).at(v) != -1){
        return dp.at(bit).at(v);
    }
    if(bit == (1 << n) -1 && v == 0){
        return dp.at(bit).at(v) = 0;
    }
    ll ans = 1e9+7;
    ll i,j;
    for(i = 0;i < graph.at(v).size();++i){
        ll s = graph.at(v).at(i).first;
        if(bit & (1 << s)) continue;
        ll d = graph.at(v).at(i).second;
        ans = min(ans, solve(bit | 1 << s, s) + d);
    }
    return dp.at(bit).at(v) = ans;
}

int main()
{
    ll i,j;
    ll e;
    cin >> n >> e;
    for(i = 0;i < e;++i){
        ll s,t,d;
        cin >> s >> t >> d;
        graph.at(s).emplace_back(t, d);
    }
    ll ans = min((ll)1e9+7, solve(0LL, 0LL));
    if(ans == 1e9+7){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 7460
def main13():

    strbuf = input('');
    chars = list(strbuf);
    num = 0;
    for i in range(4):
        if(chars[i] == '+'):
            num = num + 1;
        else:
            num = num - 1;
    print(num);


if __name__ == '__main__':
    main13()

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

int main(){
  int N,K;
  int ans=1;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    if(ans>=K)
      ans+=K;
    else
      ans*=2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
package main

import "fmt"

func calc(c []int, a []int, n int, m int, x int, i int, temp []int) int {
	if i == n {
		var cost int
		for j:= 0 ; j<len(temp) ; j++ {
			cost += c[temp[j]]
		}
		for k:=0 ; k<m ; k++ {
			var tt int
			for j:=0 ; j<len(temp) ; j++ {
				tt += a[temp[j]*m+k]
			}
			if tt < x {
				return -1
			}
		}
		return cost
	}



	//入れる
	take := calc(c,a,n,m,x,i+1,append(temp,i))

	//入れない
	non := calc(c,a,n,m,x,i+1,temp)
	if take != -1 {
		if non != -1 {
			if take < non {
				return take
			} else {
				return non
			}
		} else {
			return take
		}
	} else {
		if non != -1 {
			return non
		} else {
			return -1
		}
	}
}

func main(){
	var n,m,x int
	var temp []int
	fmt.Scan(&n,&m,&x)
	c := make([]int,n)
	a := make([]int,n*m)
	sat := make([]int,m)
	for i:=0 ; i<n ; i++ {
		fmt.Scan(&c[i])
		for j:=0 ; j<m ; j++ {
			fmt.Scan(&a[i*m+j])
			sat[j] += a[i*m+j]
		}
//fmt.Println(a[i*m:(i+1)*m])
	}
	flag := true
	for i:=0 ; i<m ; i++ {
		if sat[i] < x {
			flag = false
			break
		}
	}
	if !flag {
		fmt.Println("-1")
	} else {
		fmt.Println(calc(c,a,n,m,x,0,temp))
	}
}


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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int gcd_3(int x, int y, int z){
  int d = gcd(x,y);
  return gcd(d, z);
}
int main() {
  int N;
  cin >> N;
  int a = 0;
  for (int i=1;i<=N;i++){
    for (int j= 1;j<=N;j++){
      for (int k=1;k<=N;k++){
        a += gcd_3(i, j, k);
      }
    }
  }
  cout << a << endl;
  return 0;
}


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

using namespace std;

int main(void)
{
    int N;
    int min = 0;
    cin >> N; 
    vector<int> W(N);
    for(int i = 0; i < N; i++){
        cin >> W[i];
        min += W[i];
    }

    min -= W[0];
    for(int i = 1; i < N; i++){
        int s1 = 0;
        for(int j = 0; j < i; j++){
            s1 += W[j];
        }
        int s2 = 0;
        for(int j = i; j < N; j++){
            s2 += W[j];
        }
        if(abs(s1 - s2) < min){
            min = abs(s1 - s2);
        } 
    }

    cout << min << endl;

    return 0;
}

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

typedef long long LL;

const LL MOD = 1e9 + 7;
const int N = 405;

LL dp[N][N];
int a[N], b[N];
LL sumOfPow[N][N];
int n, c;

LL modPow(LL base,int po) {
	LL ret = 1;
	while(po) {
		if(po & 1) ret =(ret * base) % MOD;
		base = (base * base) % MOD;
		po >>= 1;
	}
	return ret;
}

void prec() {
	for(int po = 0 ; po < N ; po++)
		for(int i = 1 ; i < N ; i++) {
			sumOfPow[po][i] = (sumOfPow[po][i-1] + modPow(i,po)) % MOD;
		}
}

LL getSum(int x,int y,int z) {
	return (sumOfPow[z][y] - sumOfPow[z][x-1] + MOD) % MOD;
}

void read() {
	cin >> n >> c;
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	for(int i = 0 ; i < n ; i++) {
		cin >> b[i];
	}
}

LL solve(int pos,int sisa) {
	if(pos == n) {
		if(sisa) return 0;
		return 1;
	}
	LL &ret = dp[pos][sisa];
	if(ret != -1) return ret;
	ret = 0;

	for(int i = 0 ; i <= sisa ; i++)
		ret = (ret + getSum(a[pos],b[pos],i) * solve(pos+1,sisa - i)) % MOD;

	return ret;
}

int main() {
	prec();
	read();
	memset(dp,-1,sizeof dp);
	cout << solve(0,c) << endl;
	return 0;
}

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

const int MAXN = 3e5;
int N;
const int MAXM = 3e5;
int M;

bool alive[MAXN];
bool type[MAXN];
vector<int> adj[MAXN];
int cnt[MAXN][2];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(nullptr);
	cin >> N >> M;
	{
		string s; cin >> s;
		assert(int(s.size()) == N);
		for (int i = 0; i < N; i++) {
			char c = s[size_t(i)];
			assert(c == 'A' || c == 'B');
			type[i] = c - 'A';
		}
	}
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		a--, b--;

		adj[a].push_back(b);
		cnt[b][type[a]] ++;

		adj[b].push_back(a);
		cnt[a][type[b]] ++;
	}

	for (int i = 0; i < N; i++) {
		alive[i] = true;
	}

	vector<int> rem;
	for (int i = 0; i < N; i++) {
		if (cnt[i][0] == 0 || cnt[i][1] == 0) {
			alive[i] = false;
			rem.push_back(i);
		}
	}
	for (int z = 0; z < int(rem.size()); z++) {
		int cur = rem[z];
		assert(!alive[cur]);
		for (int nxt : adj[cur]) {
			if (!alive[nxt]) continue;
			if ((--cnt[nxt][type[cur]]) == 0) {
				alive[nxt] = false;
				rem.push_back(nxt);
			}
		}
	}
	if (int(rem.size()) == N) {
		cout << "No" << '\n';
	} else {
		cout << "Yes" << '\n';
	}


	return 0;
}


Measured memory_bytes: 16016
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s1,s2;
	cin >> s1 >> s2;
	for(int i=0;i<n;i++){
		cout << s1[i] << s2[i];
	}
	cout << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    vector<int> s(n);
    for(int i=0;i<n;i++){
        cin>>s.at(i);
        m-=s.at(i);
    }
    sort(s.begin(),s.end());
    cout<<m/s.at(0)+n<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(in.nextInt() - 1);
		}
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (list.get(i) == i) {
				if (i == 0) {
					Collections.swap(list, i, i + 1);
					ans++;
				} else {
					if (i + 1 < N && list.get(i + 1) == i + 1) {
						Collections.swap(list, i, i + 1);
					} else {
						Collections.swap(list, i, i - 1);
					}
					ans++;
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
}

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

int main() {
  int N; cin >> N;
  int ans = 0;
  vector<long long> l(N), r(N); for(int i = 0; i < N; i++) cin >> l[i] >> r[i];
  sort(l.begin(), l.end()); sort(r.begin(), r.end());
  for(int i = 0; i < l.size(); i++) {
    ans += r[i] - l[i] + 1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
tk_hp, tk_atk, ao_hp, ao_atk = map(int,input().split())


while(1):
    ao_hp -= tk_atk

    if(ao_hp <= 0):
        print("Yes")
        exit()

    tk_hp -=  ao_atk

    if(tk_hp <= 0):
        print("No")
        exit()


Measured memory_bytes: 9168
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)
#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)
#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int main() {
    int N, sum=0;
    cin>>N;
    
    int nums[109];
    rep(i,N){
        cin>>nums[i];
        sum += nums[i];
    }
    
    int ave = round(1.0*sum/N);
    
    ll cnt=0;
    rep(i,N){
        cnt += pow(abs(nums[i]-ave),2);
    }
    
    cout1(cnt);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int sum = 0;

		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				for (int c = 1; c <= K; c++) {
					sum += gcd(gcd(a, b), c);
				}
			}
		}
		System.out.println(sum);
	}

	public static int gcd(int num1, int num2) {
		if (num2 == 0)
			return num1;
		else
			return gcd(num2, num1 % num2);
	}
}


Measured memory_bytes: 35576
while 1:
	W, H = map(int, input().split())
	field = [input().split() for i in range(H)]
	if W == 0 and H == 0:
		break
	
	searched = [[0]*W for i in range(H)]
	stack = []
	count = 0
	for y in range(H):
		for x in range(W):
			if searched[y][x] == 0:
				searched[y][x] = 1
				if field[y][x] == '1':
					stack += [[x, y]]
					count += 1
					while (stack):
						sx, sy = stack.pop()
						for m in range(8):
							ny = sy + [0,1,1,1,0,-1,-1,-1][m]
							nx = sx + [1,1,0,-1,-1,-1,0,1][m]
							if (ny >= 0 and ny < H) and (nx >= 0 and nx < W):
								if (searched[ny][nx] == 0) and (field[ny][nx] == '1'):
									searched[ny][nx] = 1
									stack += [[nx, ny]]
	else:
		print(count)


Measured memory_bytes: 5624