akhauriyash/Code-Regression huggingface dataset:
read_string(Str) :-
  current_input(Input),
  read_string(Input, '\n', '', _, Str).

head([X | _], X).

solve(S, Ret) :-
  string_chars(S, Cs),
  length(Cs, Count),
  Num is Count -2,
  number_string(Num, NumStr),
  head(Cs, S1),
  last(Cs, S2),
  concat_atom([S1, NumStr, S2], '', Ret).

main :-
  read_string(S),
  solve(S, Ret),
  write(Ret).

:- main.


Measured memory_bytes: 8144
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    ll H, N;
    input(H, N);

    ll sum = 0;
    rep(i, 0, N)
    {
        ll A;
        input(A);
        sum += A;
    }

    cout << (sum >= H ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;
using PP = pair<P, llong>;


#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main(){
	llong N, M;
	llong X, Y, Z;
	vector<vector<P> > edge;
	vector<llong> use;

	cin >> N >> M;
	edge.resize(N+1);
	use.resize(N+1, 0);
	for (int i = 0; i < M; i++) {
		cin >> X >> Y >> Z;
		use[X]++;
		use[Y]++;
		edge[X].push_back(P(Y,Z));
		edge[Y].push_back(P(X,Z));
	}

	vector<llong> dis(N+1, -1);
	vector<P> v;
	for (int i = 1; i <= N; i++) {
		v.push_back(P(use[i], i));
	}
	sort(ALL(v), greater<>());
	llong ans = 0;
	queue<llong> q;
	for (auto &p : v) {
		p.second;
		if (dis[p.second] != -1) continue;
		ans++;
		dis[p.second] = 1;
		for (auto i : edge[p.second]) {
			if (dis[i.first] != -1) continue;
			dis[i.first] = (i.second - dis[p.second])&1;
			q.push(i.first);
		}
		while(q.size()) {
			for (auto i : edge[q.front()]) {
				if (dis[i.first] != -1) continue;
				dis[i.first] = (i.second - dis[q.front()])&1;
				q.push(i.first);
			}
			q.pop();
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

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

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	int N; cin >> N;
	vector<int> a(N);
	set<int> S;
	REP(i,N){
		cin >> a[i];
		S.insert(a[i]);
	}

	int Ss = S.size();
	bool ans = false;

	if (Ss == 1){
		if (a[0] == 0) ans = true;
	}else if (Ss == 2){
		if (N % 3 == 0){
			int cnt = 0;
			REP(j,N){
			    if (a[j] == 0) cnt++;
			}

			if (cnt == N/3) ans = true;

		}
	}else if ((Ss == 3) and (N % 3 == 0)){
		int x,y,z;
		auto it = S.begin();
		x = *it;
		it++;
		y = *it;
		it++;
		z = *it;

		int Acnt = 0;
		int Bcnt = 0;
		int Ccnt = 0;

		REP(i,N){
		    if (a[i] == x) Acnt++;
			if (a[i] == y) Bcnt++;
			if (a[i] == z) Ccnt++;
		}

		ans = true;
		if (Acnt != N/3) ans = false;
		if (Bcnt != N/3) ans = false;
		if (Ccnt != N/3) ans = false;

		if (((x xor y) xor z) != 0) ans = false;
	}

	if (ans) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define FRU                                  freopen("out.txt","w",stdout);
#define FRO                                  freopen("in.txt","r",stdin);
#define pb                                   push_back
#define pf                                   push_front
#define ppb                                  pop_back()
#define ppf                                  pop_front()
#define mp                                   make_pair
#define ff                                   first
#define ss                                   second
#define flash                                ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mem(ara,n)                           memset(ara,n,sizeof ara)
#define fr(i,j,n)                            for(i=j;i<n;i++)
#define rf(i,j,n)                            for(i=n;i>=j;i--)
#define inf                                  2147483647
#define ll                                   long long
#define ull                                  unsigned long long
#define pii                                  pair<int,int>
#define vi                                   vector<int>
#define vll                                  vector <long long>
#define vch                                  vector <char>
#define itr                                  ::iterator
#define msi                                  map<string,int>
#define psi                                  pair <string,int>
#define vii                                  vector <pair<int,int> >
#define all(n)                               n.begin(),n.end()
#define INF                                  10000000000000000LL
#define pi                                   3.1415926535897932384626434
#define sii                                  set <int>
#define max3(a,b,c)                          max(a,max(b,c))
#define min3(a,b,c)                          min(a,min(b,c))
#define mid3(a,b,c)                          min(max(a,b),max(b,c),max(a,b))
#define max4(a,b,c,d)                        max(max(a,b),max(c,d))
#define min4(a,b,c,d)                        min(min(a,b),min(c,d))
#define endl                                 '\n'
#define endll                                cout<<"\n";
#define spc                                  ' '
#define ld                                   long double

using namespace std;
ll p=1000000007;
int main()
{
    flash
    string s,st;
    ll n,t,T,i,j,J,I,k,m;
    char ch;
    cin>>n>>k;
    n++;
    t=0;
    for(m=k;m<=n;m++)
    {
        i=(n-m)*m+1;
        t+=i;
        t=t%p;
    }
    cout<<t;
    return 0;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll r=0,g=0,b=0;
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i,n){
        if(s[i]=='R')r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    ll m=0;
    ll ans = r*g*b;
    for(int i=1;i<=n;i++){
        for(int j=0;(j+2*i)<n;j++){
            if(s[j]!=s[j+i]&&s[j]!=s[j+2*i]&&s[j+i]!=s[j+2*i]){
                ans--;
            }
        }
    }
    
    
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

void kekek()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef EBUCHKA
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
}

int main() {
    kekek();
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> b(n);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    // cout << "HERE" << endl;
    long long ans = 0;
    for (int i = 0; i < n + 1; i++) {
        if (i != 0) {
            int tt = min(a[i], b[i - 1]);
            a[i] -= tt;
            ans += tt;
        }
        if (i == n)
            break;
        int t = min(a[i], b[i]);
        ans += t;
        b[i] -= t;
    }
    cout << ans;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

// A

void solve() {

}

int main() {
  //int 
  ll N,X,T;
  cin >> N >> X >> T;
  ll ans = 0;
  ll cur = 0;
  while( cur < N ) {
    cur += X;
    ans += T;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    OUT(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0] ? "YES" : "NO");
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,A[1000],i,j,v,h;
  scanf("%d",&N);
  for(i = 0 ; i < N  ; i++)scanf("%d",&A[i]);
  for(i = 0 ; i < N  ; i++){
    v = A[i];
    j = i-1;
    while(j >=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    for(h = 0 ; h < N  ; h++) {
      if(h==N-1)printf("%d", A[h]);
      else printf("%d ", A[h]);
  }
  
    printf("\n");
  }
  return 0;
}



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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

i32 n, k;
vector<i32> a;

bool validate(i32 d) {
    vector<i32> r(n+1);
    transform(begin(a), end(a), begin(r)+1, [&](i32 i) { return i % d; });
    sort(begin(r)+1, end(r));
    partial_sum(begin(r), end(r), begin(r));
    
    for (i32 i = 0; i <= n && r[i] <= k; i++) {
        if (r[i] == (n-i) * d - (r[n] - r[i])) return true;
    }
    return false;
}

int main() {
    cin >> n >> k;
    a.assign(n, 0);
    for (auto& e : a) cin >> e;
    i64 s = accumulate(begin(a), end(a), 0l);
    
    i32 ans = 0;
    for (i32 i = 1; i <= sqrt(s); i++) {
        if (s % i != 0) continue;
        if (ans < i && validate(i)) ans = i;
        if (ans < s / i && validate(s / i)) ans = s / i; 
    }
    cout << ans << endl;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int table[MAX];

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

    vector<int> A(N);
    for (auto &i : A) cin >> i;

    rep(k, K) {
        bool flg = true;
        rep(i, N) flg = A[i] >= N;
        if (flg) break;

        rep(i, N) table[i] = 0;
        rep(i, N) {
            table[max(i - A[i], 0)]++;
            table[min(i + A[i] + 1, N)]--;
        }

        rep(i, N) {
            if (0 < i) table[i] += table[i - 1];
        }

        rep(i, N) {
            int res = table[i];
            A[i] = res;
        }
    }

    for (auto &i : A) cout << i << " ";
    cout << endl;
}

Measured memory_bytes: 4844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>

#define ll long long
#define R register
#define IL inline
#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))
#define MP make_pair
#define PA pair<int,int>
#define MES(a,b) memset((a),(b),sizeof((a)))
#define MEC(a,b) memcpy((a),(b),sizeof((b)))
#define D double

using namespace std;

char str[10]; 

IL int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}
IL void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

signed main()
{
	scanf("%s",str);
	if(str[1]=='B') puts("ARC");
	else puts("ABC");


    return 0;
}


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

const long md=1000000007;
const long f[10]={0, 1, 1, 2, 3, 5, 8, 13, 21, 34};

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<long>>dp(h+1, vector<long>(w+2, 0));
  dp[0][1]=1;
  for(int n=1; n<=h; n++){
    for(int k=1; k<=w; k++){
      dp[n][k] = f[k-1]*f[w-k+1]*dp[n-1][k-1] + f[k]*f[w-k+1]*dp[n-1][k]+f[k]*f[w-k]*dp[n-1][k+1];
      dp[n][k]%=md;
    }
  }
  cout << dp[h][k];
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;



int main(){FIN

    ll a,b,t;cin>>a>>b>>t;
    cout<<b*(t/a)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e8;

int main(){
	while(1){
		int n,m;
		cin >> n >> m;
		if(n==0) break;
		
		vector<vector<int> > adjL(n, vector<int>(n, inf)), adjS(n, vector<int>(n, inf));
		for(int i=0; i<m; i++){
			int x,y,t;
			char sl;
			cin >> x >> y >> t >> sl;
			x--; y--;
			if(sl=='L'){
				adjL[x][y] = adjL[y][x] = min(adjL[x][y], t);
			}else{
				adjS[x][y] = adjS[y][x] = min(adjS[x][y], t);
			}
		}
		for(int i=0; i<n; i++){
			adjL[i][i]=0;
			adjS[i][i]=0;
		}
		
		int r;
		cin >> r;
		vector<int> z(r);
		for(int i=0; i<r; i++){
			cin >> z[i];
			z[i]--;
		}
		
		for(int k=0; k<n; k++){
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					adjL[i][j] = min(adjL[i][j], adjL[i][k]+adjL[k][j]);
					adjS[i][j] = min(adjS[i][j], adjS[i][k]+adjS[k][j]);
				}
			}
		}
		
		vector<vector<int> > dp(r, vector<int>(n, inf));
		dp[0][z[0]] = 0;
		for(int i=0; i<r-1; i++){
			for(int j=0; j<n; j++){
				for(int k=0; k<n; k++){
					if(k==j){
						dp[i+1][k] = min(dp[i+1][k], dp[i][j]+adjL[z[i]][z[i+1]]);
					}else{
						dp[i+1][k] = min(dp[i+1][k], dp[i][j]+adjL[z[i]][j]+adjS[j][k]+adjL[k][z[i+1]]);
					}
				}
			}
		}
		
		int ans=inf;
		for(int i=0; i<n; i++){
			ans = min(ans, dp[r-1][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3864
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next()),b=Integer.parseInt(sc.next()),c=Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next()),y=Integer.parseInt(sc.next());
        long ans = a*x+b*y;
        for(int i=2;i<=Math.max(x,y)*2;i=i+2){
            ans = Math.min(ans,a*Math.max(0,(x-i/2))+b*Math.max(0,(y-i/2))+c*i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

//input
int main(void)
{
    lli L, R;
    cin >> L >> R;
    map<lli, lli> x;
    lli minvalue = 20000;
    for (int i = L; i < R; i++)
    {
        for (int j = i + 1; j <= R; j++)
        {
            if (i % 2019 == 0 || j % 2019 == 0)
            {
                cout << 0 << endl;
                return 0;
            }
            else
            {
                lli tmp = (i % 2019) * (j % 2019) % 2019;
                minvalue = min(minvalue, tmp);
            }
        }
    }
    cout << minvalue << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<vector>
#include<string>
#define int long long
using namespace std;

int p[100000], r[100000];
int find(int a) {
	if (p[a] == a)return a;
	return p[a] = find(p[a]);
}
void unite(int a, int b) {
	a = find(a), b = find(b);
	if (a == b)return;
	if (r[a] > r[b]) {
		p[b] = a;
	}
	else if (r[a] < r[b]) {
		p[a] = b;
	}
	else {
		p[a] = b;
		r[b]++;
	}
}
signed main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) {
		p[i] = i;
	}
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b; a--; b--;
		unite(a, b);
	}
	int ans = 0;
	int x = 0, y = 0, z = 0;
	for (int i = 0; i < n; i++) {
		if (find(i) == find(0))x++;
		else if (find(i) == find(1))y++;
		else z++;
	}
	if (x > y)x += z;
	else y += z;
	cout << x*(x - 1) / 2 + y*(y - 1) / 2 -m<< endl;
}

Measured memory_bytes: 1792
n=gets.to_i
array=[]
def sum_of_digits(c)
   c.to_s.split("").map { |s| s.to_i }.inject(:+)
end
 n.times do |a|
 b=n-a
 array.push(sum_of_digits(b)+sum_of_digits(a))
 a+=1
 end
array.delete(1)
p array.min


Measured memory_bytes: 2936
def main():

  n = int(input())

  a = list(map(int, input().split()))
  b = list(map(int, input().split()))

  d = 0
  for i in range(n):
    if a[i] >= b[i]:
      d += b[i]

    else:
      d += a[i]
      b[i] = b[i] - a[i]

      if a[i+1] - b[i] >= 0:
        d += b[i]
        a[i+1] = a[i+1] - b[i]

      else:
        d += a[i+1]
        a[i+1] = 0


  print(d)


if __name__ == '__main__':
    main()

Measured memory_bytes: 81892
#include<stdio.h>
int main()
{
    int a,b,c,d;
    int sum1,sum2;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    sum1=a*b;
    sum2=c*d;
    if(sum1>=sum2)
    {
        printf("%d",sum1);
    }
    else
        printf("%d",sum2);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	int N, M;
	cin >> N >> M;

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

	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		sum += A[i];
	}

	int ans = 0;
	for (int i = 0; i < N; i++)

	{

		if (A[i] * 4 * M >= sum)
		{
			ans++;
		}

	}

	if (ans >= M)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

}





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

int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  
  if((e-a)<=k){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
  return 0;
}


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

ll MOD = 1e9+7;


int main(){
    string S, ans = "";
    ll w;
    cin >> S >> w;
    for(int i = 0; i < S.size(); i++){
        if(i*w >= S.size()) break;
        ans += S[i*w];        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
    fastio;
    int n;
    cin >> n;
    vector<int> a(n+1),b(n);
    for(int i=0;i<=n;i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        cin >> b[i];
        int k = min(b[i],a[i]);
        ans += k;
        b[i] -= k;
        a[i] -= k;
        k = min(b[i],a[i+1]);
        ans += k;
        b[i] -= k;
        a[i+1] -= k;

    }
    cout << ans << endl;
}

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

int main() {
    ll a, b, c, ans = 0;
    cin >> a >> b >> c;

    if (a + b + 1 >= c)
    {
        ans = b + c;
    } else {
        ans = a + 1 + b + b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
from collections import deque


def main():
    n = int(input())
    s = input()
    left = 0
    stack = deque([])
    for ss in s:
        if ss == "(":
            stack.append("(")
        elif not stack:
            left += 1
        else:
            stack.pop()
    print(left * "(" + s + len(stack) * ")")


if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

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

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  int n,k,i,j; cin >> n >> k;
  int a[n], b[n]; rep(i,n){cin >> a[i]; b[i] = 0;}
  k = min(k,50);  

  rep(i,k){
      rep(j,n){b[j]=0;}
      rep(j,n){
      if(a[j]>j){b[0]++;}else{b[j-a[j]]++;}
      if(a[j]+j+1<=n){b[a[j]+j+1]--;}
      }
      rep(j,n){
          if(j>0){b[j]+=+b[j-1];a[j]=min(b[j],n);}else{a[0]=b[0];}
      }
  }

    rep(i,n){cout << a[i]; if(i<n-1){cout << " ";}else{cout << endl;};}

  return 0;
}


Measured memory_bytes: 5156
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def is_prime(n):
	for i in range(2, int(-(-n**0.5//1))+1):
		if n % i == 0:
			return False
	return True

def comb(n, r):
	return fact(n) // fact(n-r) // fact(r)

fact_memo = [1, 1]
def fact(n):
	if len(fact_memo) > n:
		return fact_memo[n]
	else:
		for i in range(len(fact_memo), n+1):
			fact_memo.append(fact_memo[i-1] * i)
		return fact_memo[n]


def main():
	log = Logger(1)
	n, k = map(int, sys.stdin.readline().split())
	ans = 0
	mod = 10 ** 9 + 7
	a = [0]*(k+1)
	for i in range(1, k+1):
		a[i-1] = pow(k//i, n, mod)
	ans = 0
	for i in list(range(1, k+1))[::-1]:
		for j in range(1, k//i):
			a[i-1] -= a[i-1 + i * j]
		ans += a[i-1] * i
		ans %= mod
	print(ans)



main()

Measured memory_bytes: 72332
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    vector<vector<int>> pos(h + w, vi(h + w, 0)), post(h + w, vi(h + w, 0));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') {
                pos[i + j][i - j + w]++;
                post[i - j + w][i + j]++;
            }
        }
    }
    vvi acc(h + w, vi(h + w, 0)), acct(h + w, vi(h + w, 0));
    for (int i = 0; i < h + w; ++i) {
        acc[i][0]  = pos[i][0];
        acct[i][0] = post[i][0];
        for (int j = 1; j < h + w; ++j) {
            acc[i][j]  = acc[i][j - 1] + pos[i][j];
            acct[i][j] = acct[i][j - 1] + post[i][j];
        }
    }
    ll ret = 0;
    for (int i = 0; i < h + w; ++i) {
        for (int j = 0; j < h + w - 1; ++j) {
            for (int k = j + 1; k < h + w; ++k) {
                if (pos[i][j] == 1 && pos[i][k] == 1) {
                    int dist = k - j;
                    if (i - dist >= 0) {
                        ret += acc[i - dist][k];
                        if (j)
                            ret -= acc[i - dist][j - 1];
                    }
                    if (i + dist < h + w) {
                        ret += acc[i + dist][k];
                        if (j)
                            ret -= acc[i + dist][j - 1];
                    }
                }
            }
        }
    }
    for (int i = 0; i < h + w; ++i) {
        for (int j = 0; j < h + w - 1; ++j) {
            for (int k = j + 1; k < h + w; ++k) {
                if (post[i][j] == 1 && post[i][k] == 1) {
                    int dist = k - j;
                    if (i - dist >= 0) {
                        ret += acct[i - dist][k - 1];
                        ret -= acct[i - dist][j];
                    }
                    if (i + dist < h + w) {
                        ret += acct[i + dist][k - 1];
                        ret -= acct[i + dist][j];
                    }
                }
            }
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 6144
#include<iostream>
#include<string>
using namespace std;
     
int main(){
  double h;
  double max=0,min=1000000;
  while(cin>>h){
    if(h>max)max=h;
    if(h<min)min=h;
  }
  cout<<max-min<<endl;

  return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 1e5 + 512;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
 

int x, k, d;

main () {
	cin >> x >> k >> d;
	x = abs(x);
	int y = min(x / d, k);
	k -= y;
	x -= d*y;
	int ans = INF * 3;

	if (k % 2 == 1) {
		ans = min(ans, abs(x - d)); 
		ans = min(ans, x + d);
	}

	if (k % 2 == 0) {
		ans = x; 
		if (k)
			ans = min(ans, abs(x - 2*d));
	}

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	double x, y, z, r;
} Coord;

typedef struct {
	int parent, rank;
} Node;

typedef struct {
	int from, to;
	double weight;
} Edge;

Coord coord[ 100 ];
Node node[ 100 ];
Edge edge[ 4950 ];

int compare( const void *a, const void *b ) {
	double at = (*(Edge *)a).weight, bt = (*(Edge *)b).weight;

	if ( at < bt )
		return -1;
	if ( at > bt )
		return 1;
	return 0;
}

int find( int x ) {
	if ( node[ x ].parent == x )
		return x;
	else
		return node[ x ].parent = find( node[ x ].parent );
}

int main( void ) {
	int i, j;
	int n;

	while ( scanf( "%d", &n ), n ) {
		int cnt;
		double sum;

		for ( i = 0; i < n; i++ )
			scanf( "%lf %lf %lf %lf", &coord[ i ].x, &coord[ i ].y, &coord[ i ].z, &coord[ i ].r );

		cnt = 0;
		for ( i = 0; i < n; i++ )
			for ( j = i + 1; j < n; j++ ) {
				edge[ cnt ].from = i;
				edge[ cnt ].to = j;
				edge[ cnt ].weight = fmax( sqrt( ( coord[ i ].x - coord[ j ].x ) * ( coord[ i ].x - coord[ j ].x ) + ( coord[ i ].y - coord[ j ].y ) * ( coord[ i ].y - coord[ j ].y ) + ( coord[ i ].z - coord[ j ].z ) * ( coord[ i ].z - coord[ j ].z ) ) - coord[ i ].r - coord[ j ].r, 0.0 );
				cnt++;
			}
		qsort( edge, cnt, sizeof(Edge), &compare );

		for ( i = 0; i < n; i++ ) {
			node[ i ].parent = i;
			node[ i ].rank = 0;
		}

		sum = 0.0;
		for ( i = 0; i < cnt; i++ ) {
			int set1 = find( edge[ i ].from ), set2 = find( edge[ i ].to );

			if ( set1 != set2 ) {
				if ( node[ set1 ].rank < node[ set2 ].rank )
					node[ set1 ].parent = set2;
				else {
					node[ set2 ].parent = set1;
					if ( node[ set1 ].rank == node[ set2 ].rank )
						node[ set1 ].rank++;
				}

				sum += edge[ i ].weight;
			}
		}

		printf( "%.3f\n", sum );
	}

	return 0;
}

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

int main() {
    int t = 0;
    string s;
    while(getline(cin, s, ' ')){
        int num = stoi(s);
        t += num;
    }
    if(t < 22) cout << "win" << endl;
    else cout << "bust" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		Map<Long, Long> map = new HashMap<Long,Long>();

		for(int i = 0; i < n; i++) {

			Long tmp = Long.parseLong(temp[i]);

			if(!map.containsKey(tmp)) {

				map.put(tmp, (long) 1);

			}else {

				System.out.println("NO");
				return;

			}

		}

		System.out.println("YES");

	}
}

Measured memory_bytes: 88924
fun main(args: Array<String>){
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }

    var sum = 0.0
    for(i in 1..N){
        var j = i
        var prob = 1 / N.toDouble()
        while(j < K){
            j *= 2
            prob /= 2
        }
        sum += prob
    }
    println(sum)
}

Measured memory_bytes: 37932
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	int x,y,n,m;
  	scanf("%d %d %d %d",&n,&m,&x,&y);
  	long long p=1ll*n*m/2;
  	printf("%lld.",p);
  	if(p+p==1ll*n*m)printf("000000 ");else printf("500000 ");
  	if(x+x==n&&y+y==m)printf("1");else printf("0");
}

Measured memory_bytes: 128
N, A, B = map(int, input().split())
v = [int(i) for i in input().split()]

v.sort()
v.reverse()

print("{:.7f}".format(sum(v[0: A]) / A))

cnt = 0
target = v[A - 1]
first = -1

for i, vv in enumerate(v):
    if vv == target:
        if first == -1:
            first = i
        cnt += 1

def comb(n, r):
    import math
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)

if first == 0:
    # cnt C A + ... + cnt C min(cnt, B)
    ans = 0
    for i in range(A, min(cnt, B) + 1):
        ans += comb(cnt, i)
    print(ans)
else:
    print(comb(cnt, A - first))

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

using namespace std;

int main()
{
  int s; cin >> s;
  vector<int> a = {s};

  for (int i = 1; i <= 1000000; ++i) {
    int v = a[i-1] % 2 == 0 ? a[i-1] / 2 : 3 * a[i-1] + 1;
    for (int j = 0; j < a.size(); ++j) {
      if (a[j] == v) {
        cout << i + 1 << endl;
        return 0;
      }
    }

    a.push_back(v);
  }
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};


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

    vector<int> ds(n);
    rep(i, n) cin >> ds[i];
    int ma = *max_element(ds.begin(), ds.end());
    vector<int> cs(ma + 1, 0);
    for (int d : ds) cs[d]++;

    if (cs[0] != 1 || ds[0] != 0) {
        cout << 0 << endl;
        ret();
    }

    mint ans = 1;
    for (int i = 1; i <= ma; i++)ans *= mint(cs[i - 1]).pow(cs[i]);
    ofstream outfile("log.txt");
    for(int c : cs) outfile << c << endl;

    cout << ans << endl;


}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  int n=(int)s.length();
  vector<vector<int>> dp(n+1,vector<int>(2,0));
  dp[0][0]=1;
  dp[0][1]=2;
  rep1(i,n-1){
    if(s[i]=='1'){
      dp[i][0]=dp[i-1][0]*3;
      dp[i][0]+=dp[i-1][1];
      dp[i][1]=dp[i-1][1]*2;
    }
    else{
      dp[i][0]=dp[i-1][0]*3;
      dp[i][1]=dp[i-1][1];
    }
    dp[i][0]%=MOD;
    dp[i][1]%=MOD;
  }
  //cout<<n<<endl;
  //cout<<dp[n-1][0]<<endl;
  cout<<(dp[n-1][0]+dp[n-1][1])%MOD<<endl;
  return 0;
}

Measured memory_bytes: 5760
n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
ans = [0] * n
b = [set() for _ in range(n)]
for (s, c) in sc:
    b[s - 1].add(c)
    if s == 1 and c == 0 and n >= 2:
        print(-1)
        exit()
for i in b:
    if len(i) >= 2:
        print(-1)
        exit()
    else:
        continue
b = list(map(list, b))
for i in range(n):
    if len(b[i]) != 0:
        ans[i] = b[i][0]
if n >= 2 and ans[0] == 0:
    ans[0] = 1
print(''.join(list(map(str, ans))))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int mod = 1e9 +7;


int main(){
    int n, m;
    cin>>n>>m;
    vector<string>vec(n);
    for(int i =0 ; i <n ;i++){
        cin>>vec[i];
    }
    vector<vector<int>>ans(n, vector<int>(m, -1));
    for(int i = 0 ; i < n; i++){
        if(vec[i][0]=='#')
            break;
        else ans[i][0]=1;
    }
    for(int j = 0 ; j < m; j++){
        if(vec[0][j]=='#')
            break;
        else ans[0][j]=1;
    }
    for(int i = 1 ; i < n ; i++){
        for(int j = 1; j < m ; j++){
            if(vec[i][j]!='#'){
                if(ans[i][j-1]!=-1 && ans[i-1][j]!=-1){
                    ans[i][j] = (ans[i-1][j]+ans[i][j-1])%mod;
                }
                else if(ans[i-1][j]!=-1){
                    ans[i][j]=ans[i-1][j]%mod;
                }
                else if(ans[i][j-1]!=-1){
                    ans[i][j]= ans[i][j-1]%mod;
                }
            }
        }
    }
    if(ans[n-1][m-1]!=-1){
        cout<<ans[n-1][m-1]%mod;
    }
    else{
        cout<<0;
    }
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

const double PI = 3.1415926535897932384;

// 1次元vectorの出力
template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}

// 2次元vectorの出力
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

int main(void){
	ll x; cin >> x;
	ll n = 100;
	ll ans = 0;
	while(n < x){
		n *= 1.01;
		cerr << n << endl;
		ans++;
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const int INF = 1e9;

void enumerate(std::vector<std::pair<int, int>> &items, std::vector<std::pair<int, int>> &ps) {
  int L = items.size();
  REP(j, 1 << L) {
    int w = 0, v = 0;
    REP(k, L) {
      if (j >> k & 1) v += items[k].first, w += items[k].second;
    }
    ps.emplace_back(w, v);
  }
  sort(ALL(ps));
  int M = 1;
  REP(j, 1 << L) {
    if (ps[M-1].second < ps[j].second) {
      ps[M++] = ps[j];
    }
  }
  ps.resize(M);
}


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  std::cin >> N;
  std::vector<int> V(N), W(N);
  REP(i, N) std::cin >> V[i] >> W[i];

  int n_perm = std::min(N, (1 << 12) - 1);
  std::vector<std::vector<std::pair<int, int>>> permed(n_perm);

  REP(i, n_perm) {
    std::vector<std::pair<int, int>> items;
    int v = i;
    while (true) {
      items.emplace_back(V[v], W[v]);
      if (v == 0) {
        break;
      }
      v = (v - 1) / 2;
    }

    std::vector<std::pair<int, int>> ps;
    enumerate(items, ps);
    permed[i] = ps;
  }
  /*
  for (auto ps : permed) {
    for (auto p : ps) std::cout << '(' << p.first << ',' << p.second << ')' << ' ';
    std::cout << std::endl;
  }
  */

  int Q;
  std::cin >> Q;
  REP(_, Q) {
    int v, L;
    std::cin >> v >> L;
    v--;
    if (v < n_perm) {
      auto ans = std::lower_bound(ALL(permed[v]), std::make_pair(L, INF)) - 1;
      std::cout << ans->second << '\n';
    } else {
      std::vector<std::pair<int, int>> items;
      while (v >= n_perm) {
        items.emplace_back(V[v], W[v]);
        v = (v - 1) / 2;
      }
      int M = items.size();
      int ans = 0;
      REP(i, 1 << M) {
        int vv = 0, w = 0;
        REP(j, M) if (i >> j & 1) vv += items[j].first, w += items[j].second;
        if (w <= L) {
          auto cand = std::lower_bound(ALL(permed[v]), std::make_pair(L - w, INF)) - 1;
          ans = std::max(vv + cand->second, ans);
        }
      }
      std::cout << ans << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 78136
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

using namespace std;

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++)

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int> > VVi;
typedef vector<vector<ll> > VVl;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 28;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int n;
string s;

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

	char last = 'A';

	int ans = 0;
	for (char c : s)
	{
		if (c == last)
			continue;

		last = c;
		++ans;
	}

	cout << ans << endl;
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);  freopen(Task".out", "w", stdout);
  int n; cin >> n;
  int mi = n + 1;
  int ans = 0;
  for (int i = 0; i < n; ++i){
    int x; cin >> x;
    if (mi > x) ++ans;
    mi = min(mi, x);
  }
  cout << ans;
}




Measured memory_bytes: 256
import sys


def main():
    n, a, b = map(int, sys.stdin.readline().strip().split(" "))
    if a > b:
        print(0)
    elif a == b:
        print(1)
    else:
        if n == 1:
            print(0)
            return
        x = (n - 1) * a + b
        y = a + (n - 1) * b
        print(y - x + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568