akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL (long long)
#define IT iterator
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
//map<int,int> M;
int main(){
	int n,x,OK=0;
	scanf("%d %d",&n,&x);
	if(n==2){
		if(x==2){
			printf("Yes\n");
			printf("1\n2\n3\n");return 0;
			}
		else{
			printf("No\n");return 0;
		}
	}
	if(x-1>=1&&x+1<=2*n-1&&x+2<=2*n-1){
		printf("Yes\n");
		OK=1;
		int res[300001];
		int NUM=x;
		rl(i,n,1){
			res[i]=NUM;
			NUM--;
			if(NUM==0){
				NUM=2*n-1;
			}
		}
		NUM=x+1;
		rb(i,n+1,2*n-1){
			res[i]=NUM;
			NUM++;
			if(NUM==2*n){
				NUM=1;
			}
		}
		swap(res[n+2],res[n-2]);
		rb(i,1,2*n-1){
			printf("%d\n",res[i]);
		}
	}
	else
	if(x-1>=1&&x-2>=1&&x+1<=2*n-1){
		OK=1;
		printf("Yes\n");
		int res[300001];
		int NUM=x;
		rl(i,n,1){
			res[i]=NUM;
			NUM--;
			if(NUM==0){
				NUM=2*n-1;
			}
		}
		NUM=x+1;
		rb(i,n+1,2*n-1){
			res[i]=NUM;
			NUM++;
			if(NUM==2*n){
				NUM=1;
			}
		}
		swap(res[n-1],res[n+1]);
		rb(i,1,2*n-1){
			printf("%d\n",res[i]);
		}
	}
	if(!OK){
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<cmath>
#include<string>

using namespace std;
int main(){
	

	

	int m,h;

	while (1)
	{
		string n;
		cin >> n;
		
		if (n == "-")break;

		cin >> m;

		for (int i = 0; i < m; i++)
		{
			cin >> h;

			string sub = n.substr(0, h);
	
			n += sub;
	
			
				n.erase(n.begin() , n.begin() + h);

			

		}


		cout << n << endl;





	}

return 0;
}

Measured memory_bytes: 3224
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l+r) >> 1)
#define ll long long
using namespace std;

int main()
{
     char s[10];
     int f1=0,f2=0;
     cin>>s;
     for(int i=0;i<3;i++) 
       {
       	  if(s[i]=='A') f1=1;
       	  if(s[i]=='B') f2=1;
	   }
	 if(f1==1&&f2==1) cout<<"Yes"<<endl;
	   else cout<<"No"<<endl;  
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
//#include <unordered_map>
#include <numeric>
 
using namespace std;
 
const int mod = 1e9 + 7;
 

int n;
int a[123], ans;
int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i = 1; i <= n; i++) {
		int r = i;
		while(a[r + 1] == a[r] && r + 1 <= n) r++;
		ans += (r - i + 1) / 2;
		i = r;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#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 RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M;
  cin >> N;
  vector<int> D(N);
  REP(i,N)cin >> D[i];
  cin >> M;
  vector<int> T(M);
  REP(i,M)cin >> T[i];
  sort(D.begin(), D.end());
  sort(T.begin(), T.end());
  int di = 0, ti = 0;
  while(ti < T.size() && di < D.size()){
    if(D[di] < T[ti]){
      di++;
    }else if(D[di] > T[ti]){
      break;
    }else{
      di++;
      ti++;
    }
  }
  if(ti == T.size()) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<uint64_t> A(N+1), B(N);
    int i;
    for(i=0; i<N+1; i++) cin >> A.at(i);
    for(i=0; i<N; i++) cin >> B.at(i);


    //uint64_t ans = accumulate(A.begin(), A.end(), 0);
    uint64_t ans = 0;
    uint64_t diff;
    for(i=0; i<N; i++){
        
        if(A.at(i) >= B.at(i)){
            A.at(i) -= B.at(i);
            ans += B.at(i);
        }
        else{
            B.at(i) -= A.at(i);
            ans += A.at(i);
                        
            if(A.at(i+1) >= B.at(i)){
                A.at(i+1) -= B.at(i);
                ans += B.at(i);
            }
            else{
                ans += A.at(i+1);
                A.at(i+1) = 0;
            }
        }
    }


    cout << ans << endl;

    return 0;
}



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

using namespace std;
using ll = long long;

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

	set<int> st;
	st.insert(s);
	int a = s;
	int idx = 1;
	while (idx++ < 1e8) {
		if (a % 2) { a = a * 3 + 1; }
		else { a = a / 2; }

		if (st.count(a)) {
			cout << idx << endl;
			return 0;
		}
		st.insert(a);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, d;
	cin >> n >> d;
	
	vector< vector<int> > x(n, vector<int>(d));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < d; ++j) {
			cin >> x[i][j];
		}
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			int sum = 0;
			
			for(int k = 0; k < d; ++k) { 
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			
			bool yes = false;
			for(int k = 1; k <= sum; ++k) {
				if( k * k == sum ) yes = true;
			}
			
			if( yes ) ans++;
		}
	}

	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif



void solve()
{
    long long a,b;
    cin>>a>>b;

    if(a>b)
    {
        swap(a,b);
    }

    long long diff=(b-a)/2;

    if(a+diff==b-diff){
        cout<<a+diff<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }

}

int main()
{
    int t=1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,k,cnt=0;
    cin>>a>>b>>k;
    for(int i=min(a,b);i;i--){
        if(a%i==0&&b%i==0){
            ++cnt;
            if(cnt==k){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long count = 1;
		boolean flag = true;
		long ans = 0;

		if(h == 1){
			System.out.println("1");
		}else{
			if(!(h%2 == 0)){
				h = h-1;
			}
			while (flag) {
				if(h/2 == 1){
					flag = false;
				}else{
					h = h/2;
					count++;
				}
			}
			long tmp = 1;
			for(int i = 0;i<count;i++){
				ans = tmp*2+1;
				tmp = ans;
			}
	System.out.println(ans);
		}
		}
}

Measured memory_bytes: 23124
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#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=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e9 - 10;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    if (h % a == 0 && w % b == 0){
        cout << "No" << endl;
        return 0;
    }

    VVI ans(h, VI(w));
    for (int i = a-1; i < h; i += a){
        for (int j = b-1; j < w; j += b){
            ans[i-a+1][j-b+1] = INF - 1;
            ans[i][j] = -INF;
        }
    }

    int s = (h/a) * (w/b);
    int x = s / (h * w - (h/a*a) * (w/b*b)) + 2;

    REP(i, h % a) REP(j,w) ans[h-i-1][j] = x;
    REP(i,h) REP(j, w % b) ans[i][w-j-1] = x;

    ll sum = 0;
    REP(i,h) REP(j,w) sum += ans[i][j];

    cout << "Yes" << endl;
    REP(i,h){
        REP(j,w){
            printf("%d ", ans[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 3840
using System;

namespace ITP1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0 || i % 10 == 3 || i.ToString().Contains("3")) Console.Write(" " + i);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8360
import java.util.function.*;
import java.util.*;
import java.io.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1234567;
    static int inf = 0x7ffffff;

    public static void main(String[]$) throws Exception {
        char[] s = scanner.next().toCharArray();
        int n = s.length;
        int[] a = new int[n + 1];
        for (int i = 0; i < n; i++) {
            if (s[i] == '<') {
                a[i + 1] = a[i] + 1;
            }
        }
        for (int i = n; i > 0; i--) {
            if (s[i - 1] == '>') {
                a[i - 1] = Math.max(a[i - 1], a[i] + 1);
            }
        }
        long sum = 0;
        for (int i = 0; i <= n; i++) {
            sum += a[i];
        }
        System.out.println(sum);
    }

    static class System {
        static PrintWriter out = new PrintWriter(java.lang.System.out);

        static {
            Runtime.getRuntime().addShutdownHook(new Thread(System.out::flush));
        }

        static void exit() {
            java.lang.System.exit(0);
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        char[][] nextCharArray(int n, int m) {
            char[][] a = new char[n][m];
            for (int i = 0; i < n; i++) {
                a[i] = next().toCharArray();
            }
            return a;
        }
        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        int[] nextIntArray(int n, IntUnaryOperator op) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = op.applyAsInt(nextInt());
            }
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        long[] nextLongArray(int n, LongUnaryOperator op) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = op.applyAsLong(nextLong());
            }
            return a;
        }
    }
}


Measured memory_bytes: 35932
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	VI d;
	for (int i = 1; i <= c; i++) {
		if (c%i == 0)d.PB(i);
	}
	int cnt = 0;
	for (auto n : d) {
		if (a <= n && n <= b)cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int n, m, l;
using P = pair<int, ll>;
vector<vector<P> > v(303);
int s, t;
using ppll = pair<P, int>;
P d[303][303];

void dijkstra() {
    priority_queue<ppll, vector<ppll>, greater<ppll> > que; // 回数, 使った燃料, id
    
    
    que.push(mp(P(0, 0), s));
    d[s][s] = P(0, 0);
    while (!que.empty()) {
        ppll p = que.top();
        que.pop();
        // cout << p.F.F << " " << p.F.S << " " << p.S << endl;
        if (p.F > d[s][p.S]) continue;
        
        for (P nxt : v[p.S]) {
            ppll np = p; // pに+=とかしたら次のloopで事故
            np.F.S += nxt.S;
            if (np.F.S > l) {
                np.F.S = nxt.S; // 使った量がさらになって次のcostがそのまま
                np.F.F++;
            }
            
            if (chmin(d[s][nxt.F], np.F)) {
                que.push(mp(np.F, nxt.F));
            }
        }
    }
    // cout << endl; rep(i, n) cout << d[s][i].F << " " << d[s][i].S << endl;
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin >> n >> m >> l;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        if (c > l) continue;
        a--; b--;
        v[a].eb(P(b, c));
        v[b].eb(P(a, c));
    }
    rep(i, n) rep(j, n) d[i][j].F = inf;
    
    rep(i, n) {
        s = i;
        dijkstra();
    }
    int q;
    cin >> q;
    rep(i, q) {
        cin >> s >> t;
        s--; t--;
        if (d[s][t].F == inf) cout << -1 << endl;
        else cout << d[s][t].F << endl;
    }
}



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

bool p(int n){
  return ((n/10000) == (n%10) && (n/1000 - (n/10000*10)) == ((n%100-n%10)/10));
}

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; i++){
    if(p(i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
renzoku =0
ans ="No"
for _ in range(N):
    d1,d2 = map(int, input().split())
    if d1 ==d2:
        renzoku +=1
        if renzoku ==3:
            print("Yes")
            sys.exit()
    else:
        renzoku =0
print(ans)
    

Measured memory_bytes: 9164
def main():
    N, K, C = map( int, input().split())
    S = input()
    T = [False]*N
    ANS = [1]*N
    for i in range(N):
        if S[i] == "o":
            T[i] = True
        else:
            ANS[i] = 0
    F = []
    i = 0
    now = 0
    D = [False]*N
    k = 0
    while i < N and k < K:
        if T[i]:
            F.append(i)
            D[i] = True
            i += C+1
            k += 1
        else:
            i += 1
    for i in range(N):
        if not D[i]:
            ANS[i] = 0
    # print(ANS, F)
    end = N-1
    for i in range(N-1,-1,-1):
        if T[i]:
            end = i
            break
    for m in F[::-1]:
        # print(m, end)
        if m < end:
            ANS[m] = 0
        if end == 0:
            break
        for j in range(end-C-1,-1,-1):
            # print(j,T[j])
            if T[j]:
                end = j
                break

    print("\n".join( map( str, [ i+1 for i in range(N) if ANS[i] == 1])))
            
    
if __name__ == '__main__':
    main()


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

int main(){
  long a,b,c;
  cin >> a >> b >> c;
  long ans = 0;
  if(c >= a + b + 1){
    ans += a + b + 1 + b;
  }else{
    ans += b + c;
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string s;
int ans;
int main() {
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '1')
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,m;
vector<int> each[100000+10];
priority_queue<int> Q;
LL res=0;
int main(){
	scanf("%d %d",&n,&m);
	rep(i,n){
		int ai,bi;
		cin>>ai>>bi;
		if(ai>m) continue;
		each[ai].PB(bi);
	}
	rb(i,1,m){
		int IT=0;
		rep(j,each[i].size())
		Q.push(each[i][IT++]);
		if(!Q.empty()){
			res+=Q.top();
			Q.pop();
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n,Q;cin>>n>>Q;
  vector<int> v[n];
  REP(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    v[a].pb(b);
    v[b].pb(a);
  }

  int x[n];
  REP(i,n){
    x[i] = 0;
  }
  REP(i,Q){
    int p,y;
    cin>>p>>y;
    p--;
    x[p] += y;
  }

  ll score[n];
  REP(i,n){
    score[i] = -1;
  }

  queue<int> q;
  score[0] = x[0];

  q.push(0);
  while(!q.empty()){
    int i = q.front();
    q.pop();
    REP(j,v[i].size()){
      int next = v[i][j];
      if(score[next] == -1){
        score[next] = score[i] + x[next];
        q.push(next);
      }
    }
  }

  REP(i,n){
    cout<<score[i]<<" ";
  }
  cout<<endl;


 

  return 0;
}

Measured memory_bytes: 17140
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    int n=in();
    vec d(n);
    rep(i,n)d[i]=in();
    ll ans=0;
    rep(i,n)rep(j,n)if(i<j)ans+=d[i]*d[j];
    cout<<ans<<endl;
}


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

string s;
char c;
bool f;
int m, m_max;

bool isACGT(const char& c) {
    return (c == 'A' || c == 'C' || c == 'G' || c == 'T');
}

int main(){
    cin >> s;
    m = m_max = 0;
    for (size_t i = 0; i < s.size(); ++i){
        f = true;
        m = 0;
        for (size_t j = i; j < s.size(); ++j){
            c = s[j];
            f = (c == 'A' || c == 'C' || c == 'G' || c == 'T');
            if (!f) break;
            else m++;
        }
        if (m_max < m) m_max = m;
    }
    cout << m_max;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> v(h,vector<char>(w));
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> v[i][j];
    }
  }
  for(int i = 0; i < w+2; i++) cout << "#";
  cout << "\n";
  for(int i = 0; i < h; i++) {
    cout << "#";
    for(int j = 0; j < w; j++) {
      cout << v[i][j];
    }
    cout << "#\n";
  }
  for(int i = 0; i < w+2; i++) cout << "#";
  cout << "\n";
}

Measured memory_bytes: 3640
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int [] B = nextIntArray(N-1);
		int [] unknownA = new int [N];

		unknownA[0] = B[0];
		unknownA[N-1] = B[N-2];
		for(int i=1;i<N-1;i++) {
			unknownA[i] = Math.min(B[i-1],B[i]);
		}
		long res = 0;
		for(int i : unknownA) {
			res += i;
		}

		out.println(res);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 23636
//It doesn't matter as long as you rise to the top - Katsuki Bakugo
#include<bits/stdc++.h>
using namespace std;
     
     
#define Fast_as_duck ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define rev(i,st,n) for(int i = st; i >= n ; i--)
#define ss second
#define ff first
#define ll long long 

typedef pair <int , int> pii;

const int N = 1e5 + 10 , mod =  1000000007;

void solve(){

    int n; cin >> n;
    std::vector<int> arr(n);
    forn(i,0,n){
        cin >> arr[i];
        
    }
    
    ll ans = 0;

    forn(i,1,n){
        if(arr[i] < arr[i-1] ){
            ans += (arr[i-1] - arr[i]);
            arr[i] = arr[i-1];
        }
    }

    cout << ans << "\n";
    
    

    
    
        


}

int main(){
    Fast_as_duck;

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    int t = 1; 
    
    // cin >> t;
    

    while(t--){
        solve();
    }




    return 0;
}
      
       


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N, A, B; cin >> N >> A >> B;
  string result = abs(A-B)%2 ? "Borys" : "Alice";
  cout << result << endl;
  return 0;
}

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

int main() {
  int N, Q;
  string s;
  cin >> N >> Q >> s;
  vector<int> A;
  for (int i = 0; i < N-1; i++) {
    if (s[i] == 'A' && s[i+1] == 'C') A.push_back(i);
  }
  
  for (int i = 0; i < Q; i++) {
    int L, R;
    cin >> L >> R;
    L--; R--;
    auto itrl = lower_bound(A.begin(), A.end(), L);
    auto itrr = lower_bound(A.begin(), A.end(), R);
    cout << distance(itrl,itrr) << endl;
  }
}

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


int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    int ans = 0;
    rep(i,n) cin >> d[i];
    rep(i,n){
        for(int j=i+1; j<n; j++){
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		String o=sc.next();
		String e=sc.next();
		int lo=o.length();
		int le=e.length();
		String ans="";
		int a=0;
		int b=0;
		while(a!=lo) {
			ans+=o.substring(a,a+1);
			a++;
			if(b!=le) {
				ans+=e.substring(b,b+1);	
				b++;
			}
		}
		System.out.println(ans);
		
	}
	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





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

int N;
int A[200010],B[200010];
int ans;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);
    for(int i = 0; i < N; i++)scanf("%d",B + i);

    int mem = 1;
    for(int i = 0; i < 29; i++)
    {
        mem *= 2;
        vector<int> AA,BB;
        for(int j = 0; j < N; j++)
        {
            AA.push_back(A[j] % mem);
            BB.push_back(B[j] % mem);
        }
        sort(BB.begin(),BB.end());
        int cnt = 0;
        for(int j = 0; j < N; j++)
        {
            cnt += lower_bound(BB.begin(),BB.end(),mem - AA[j]) -
                   lower_bound(BB.begin(),BB.end(),mem / 2 - AA[j]);
            cnt += lower_bound(BB.begin(),BB.end(),2 * mem - AA[j]) -
                   lower_bound(BB.begin(),BB.end(),3 * (mem / 2) - AA[j]);
        }
        if(cnt % 2)ans += mem / 2;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    int ans = 1;
    for(int i = 1; i < n; i++)
    {
        bool ok = true;
        for(int j = 0; j < i; j++)
        {
            if (h.at(i) < h.at(j)) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve(A, B, X):
    if X < A:
        return "NO"
    if X > A + B:
        return "NO"
    return "YES"
if __name__ == "__main__":
    s = input()
    A, B, X = map(lambda x: int(x), s.split())
    print(solve(A, B, X))


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <string>

#include <vector>
#include <cmath>
#include <limits>
#include <functional>
using namespace std;

int main()
{
    int N, M;
    char s[105][105], t[105][105];
    int ans = 0, max = 0;

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

    cin >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> t[i];
    }

    for (int k = 0; k < N; k++)
    {
        for (int l = 0; l < N; l++)
        {
            if (strcmp(s[k], s[l]) == 0)
            {

                ans++;
            }
        }
        for (int l = 0; l < M; l++)
        {
            if (strcmp(s[k], t[l]) == 0)
            {
                ans--;
            }
        }
        if (max < ans)
        {
            max = ans;
        }

        ans = 0;
    }

    if (max <= 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << max << endl;
    }

    return 0;
}

Measured memory_bytes: 3216
#include <stdio.h>

int main()
{
    while(1) {

            int i, j, h, w;

            scanf("%d %d", &h, &w);

            if(h == 0 && w == 0) {

                break;
            }

            for(i = 1; i <= h; i++) {

                for(j = 1; j <= w; j++) {

                    if(i != 1 && i != h && j != 1 && j != w) {
                        printf(".");
                    }

                    else {

                        printf("#");
                    }
                }

                printf("\n");
            }

            printf("\n");
    }

    return 0;
}




Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> e[111111];
int sg[111111];
void dfs(int x,int fat){
	sg[x] = 0;
	for(vector<int>::iterator it = e[x].begin(); it!=e[x].end(); it++)
		if(*it != fat){
			dfs(*it, x);
			sg[x] ^= (sg[*it]+1);
		}
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1,1);
	puts(sg[1]?"Alice":"Bob");
	return 0;
}


Measured memory_bytes: 11008
/*
      @author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

const int Max_N=1e5+1;

int arr[Max_N];
int n, k;
int dp[Max_N][2]; 
//dp[i][0] = winner if i stones are present and 0th player starts the game
//dp[i][1] = winner if i stones are present and 1st player starts the game

// turn = 0 (Taro) , 1 (Jiro)
// O(K*2*N) time & space
int Top_Down(int stones = k, int turn = 0) {
    // Base Case
    if(stones == 0) return (dp[stones][turn]=!turn);

    if(dp[stones][turn] != -1) return dp[stones][turn];

    // Choice
    for(int i = 1; i <= n; ++i) {
        if(arr[i] <= stones) 
            if(Top_Down(stones-arr[i], !turn) == turn)  return (dp[stones][turn]=turn);
    }
    return (dp[stones][turn]=!turn);
}

//

int Bottom_Up() {
    vector<int> winner(k+1); // winner[i] = winner if we have i stones and 0th player starts
    winner[0] = 1;
    for(int stones = 1; stones <= k; ++stones) {
        for(int i = 1; i <= n; ++i) {
            if(arr[i] <= stones) {
                if(winner[stones-arr[i]] == 1) {
                    winner[stones]=0;
                    break;
                }
                else winner[stones]=1;
            }
            else
                winner[stones]=1;
        }
    }
    // for(int num:winner
    //     ) cout << num <<" ";
    return winner[k];
}


int32_t main() {
    IOS;
    int t=1; 
    // cin >> t;
    while(t--){
        memset(dp, -1, sizeof(dp));
        cin >> n >> k;
        for(int i = 1; i <= n; ++i) cin >> arr[i];
        if(Bottom_Up() == 0) cout << "First" << endl;
        else cout << "Second" << endl;
    }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
long long MAX = 1e18;
//区間和
struct S{
    long long zero;
    long long one;
    long long ten;
};
S op(S a, S b){
    return S{a.zero + b.zero, a.one + b.one, a.one * b.zero + a.ten + b.ten};
}
S e(){
    return S{0, 0, 0};
}
using F = bool;
S mapping(F f, S x){
    if(!f) return x;
    return S{x.one, x.zero, x.zero * x.one - x.ten};
}
F composition(F f, F g){
    return (!f && g) || (f && !g);
}
F id(){
    return false;
}
int main(){
    int N, Q;
    cin >> N >> Q;
    vector<S> A(N);
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(a == 1) A[i] = S{0, 1, 0};
        else A[i] = S{1, 0, 0};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> segt(A);
    for(int i = 0; i < Q; i++){
        int t, l, r;
        cin >> t >> l >> r;
        l--;
        if(t == 1) segt.apply(l, r, true);
        else cout << segt.prod(l, r).ten << endl;
    }
}

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

int main(){
    int n ;
    cin >> n ;
    vector<int> a(n);

    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    double harmony = 0 ;
    for (size_t i = 0; i < n; i++)
    {
        harmony += 1.0 / a.at(i) ;
    }
    cout << 1.0 / harmony << endl ;
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	
	string s;
	cin >> s;
	if(s=="Sunny")
		cout << "Cloudy" << endl;
	if(s=="Cloudy")
		cout << "Rainy" << endl;
	if(s=="Rainy")
		cout << "Sunny" << endl;




}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x = A[r]; // partition number
  int i = p - 1;

  for (size_t j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i + 1], A[r]);
  return i + 1;
}

int main(int argc, char const *argv[]) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int partition_number = partition(0, n - 1);

  for (int i = 0; i < n; i++) {
    if (i)
      cout << " ";
    if (i == partition_number) {
      cout << "[" << A[i] << "]";
    } else {
      std::cout << A[i];
    }
  }
  std::cout << '\n';

  return 0;
}



Measured memory_bytes: 3356
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

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

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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() {
  	//解説
    ll n;
    cin >> n;
    ll sum = 1;
    while(sum*(sum+1)/2 <= n)sum++;
    ll o = sum*(sum+1)/2 - n;
    vector<ll> res;
    for(ll i = 1;i <= sum;i++)if(i!=o)res.push_back(i);
    rep(i,res.size()) cout << (i ? " " : "") << res[i];
    return 0;
}

Measured memory_bytes: 384
/*
平面上に N 個の点があり、それぞれ 0 から N−1 までの番号が付けられており、
それぞれの点について x 座標と y 座標が与えられています。
その N 点のうち 2 点を選び結んで得られる線分のうち、最も長くなる線分の長さを求めてください。
*/
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
    int K, S;
    cin >> K >> S;
	
    int res = 0;
    for (int i = 0; i <= K; ++i) {
        for (int k = 0; k <= K; ++k) {
        	if (i+k<=S & S-i-k<=K) ++res;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
readline = sys.stdin.readline
N = int(readline())
P = defaultdict(list); Q = defaultdict(list)
for i in range(N):
    x, y = map(int, readline().split())
    P[x].append(y)
    Q[y].append(x)
X = set(); Y = set()

res = 0
que = deque()
for x in P:
    que.append((0, x))
    X.add(x)
    cx = 1; cy = 0
    while que:
        t, v = que.popleft()
        if t:
            for x in Q[v]:
                if x in X:
                    continue
                X.add(x)
                que.append((0, x))
                cx += 1
        else:
            for y in P[v]:
                if y in Y:
                    continue
                Y.add(y)
                que.append((1, y))
                cy += 1
    res += cx * cy
print(res - N)

Measured memory_bytes: 32480
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
#define N 100005
int n,m;
struct node{
	ll a,b;
}d[N];
bool cmp(node a,node b){
	return a.a<b.a;
}
int main(){
	int cnt=0;
	ll ans=0;
	in2(n,m);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&d[i].a,&d[i].b);
	sort(d+1,d+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(cnt>m) break;
		ans+=(ll)(min(d[i].b,(ll)m-cnt)*d[i].a);
		cnt+=d[i].b;
	}
	printf("%lld",ans);
	return 0;
}

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

words = []
for i in range(n):
    words.append(input())

ret = "Yes"
if len(set(words)) != n:
    ret = "No"
else:
    for i in range(n-1):
        if words[i][-1] != words[i+1][0]:
            ret = "No"
            break

print(ret)

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



int main() {
  int a,b,c;
  cin >> a>> b>> c;
  if(a-b<=c){cout << c-(a-b) << endl;}else{cout << 0 << endl;}
}

Measured memory_bytes: 256
a = []
b = []
gets.to_i.times do
    t = gets.split.map &:to_i
    a << t[0]
    b << t[1]
end

br = b.reverse
res = 0
a.reverse.each_with_index do |e,i|
    t = (res+e)%br[i]
    res += br[i]-t if t != 0
    
end
p res

Measured memory_bytes: 5120
n,l = map(int, raw_input().split(' '))
m = (+float('inf'), -1)
cumul = 0
for a in range(1, n + 1):
  	cumul += l + a -1 
	m = min(m, (abs(l + a - 1), a))
print cumul - (l + m[1] - 1)


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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define LL           long long
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define MAX 400005
#define Val first
#define lazy second
#define F first
#define S second

typedef pair<LL,LL> pii;

const LL INF = (LL)10000000000000000;
pii tree[4*MAX];

void update_node(int idx, int b, int e,LL v)
{
    cnd.Val += v;
    cnd.lazy += v;
}

void lazy_update(int idx, int b, int e)
{
    int m = (b+e)>>1;

    update_node(lnd, b, m, cnd.lazy);
    update_node(rnd, m + 1, e, cnd.lazy);

    cnd.lazy = 0;
}

LL query(int idx, int b, int e, int st, int en)
{
    if(st > e || en < b ) return INF;
    if(st <= b && en >= e) return tree[idx].Val;

    lazy_update(idx, b, e);

    int m = (b+e)>>1;

    return min(query(lnd, b, m, st, en), query(rnd, m + 1, e, st, en));
}

void update(int idx, int b, int e, int st, int en,LL v)
{
    if(st > e || en < b ) return;
    if(st <= b && en >= e)
    {
        update_node(idx, b, e, v);
        return;
    }

    lazy_update(idx, b, e);

    int m = (b+e)>>1;
    update(lnd, b, m, st, en, v); update(rnd, m + 1, e, st, en, v);
    cnd.Val = min(tree[lnd].Val, tree[rnd].Val);
}

LL dp[MAX], prin, lolo;
vector<pii> mat[MAX];

int main()
{
    ios::sync_with_stdio(false);
    //inf;
    int n, m, l, r, c;

    cin >> n >> m;
    FOR(i,0,m-1)
    {
        cin >> l >> r >> c; prin += c;
        mat[r].push_back( {l, c} );
    }

    int base = 1;
    while(base <= n) {base *= 2;}

    FOR(i,1,n + 1)
    {
        dp[i] = query(1, 0, base, 0, i - 1);

        for(auto x : mat[i])
             update(1, 0, base, 0, x.F - 1, x.S);

        update(1, 0, base, i, i, dp[i]);
    }

    cout << prin - dp[n + 1] << endl;

    return 0;
}


Measured memory_bytes: 29056
// ConsoleApplication7.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<iomanip>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a, b;
	while (cin>>a>>b)
	{
		if (a >= b)
		{
			for (int i = 0; i < a; i++)
			{
				cout << b;
			}
		}
		else
		{
			for (int i = 0; i < b; i++)
			{
				cout << a;
			}
		}
		cout << "\n";
	}
}



Measured memory_bytes: 256
s=input()
n=len(s)
for i in range(1,n):
  if s[i-1]==s[i]:
    print(i,i+1)
    exit()
for i in range(2,n):
  if s[i-2]==s[i]:
    print(i-1,i+1)
    exit()
print(-1,-1)

Measured memory_bytes: 39408
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5 + 1 # N >= n
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n = int(input())
A = list(map(int,input().split()))

val = sum(A) - sum(set(A))
i = -1
j = -1
for k in range(n+1):
    if A[k] == val:
        if i == -1:
            i = k
        elif j == -1:
            j = k
            break
for k in range(1,n+2):
    print((cmb(n+1, k, mod) - cmb(n + i - j, k - 1, mod)) % mod)

Measured memory_bytes: 27792
#include<iostream>
#include<cmath>
#include<cstdio>
#define EPS (1e-7)
#define N 50
using namespace std;
int n,x[N],y[N],flag=1;
double gx,gy;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    gx+=x[i]; gy+=y[i];
  }
  gx/=n; gy/=n;
  for(int i=0;i<n;i++){
    double px=gx+(gx-x[i]),py=gy+(gy-y[i]);
    int f=0;
    for(int j=0;j<n;j++)
      if(abs(px-x[j])<EPS&&abs(py-y[j])<EPS)f=1;
    if(!f)flag=0;
  }
  if(flag)printf("%.8f %.8f\n",gx,gy);
  else cout<<"NA"<<endl;
  return 0;
}

Measured memory_bytes: 3220
/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
int n;
int a[maxn];
ll pw(ll x, ll y) {
    ll r = 1;
    x %= mod;
    while(y) {
        if(y & 1)
            r = (r * x) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return r;
}
void solve() {
    while(cin >> n) {
        memset(a, 0, sizeof a);
        int x;
        bool f = 1;
        for (int i = 0; i < n; i++) {
            cin >> x;
            a[x]++;
        }
        if(n & 1) {
            if(a[0] != 1) {
                f = 0;
            } else {
                for (int i = 2; i <= n - 1; i+=2) {
                    if(a[i] != 2) {
                        f = 0;
                        break;
                    }
                }
            }
        } else {
            for (int i = 1; i <= n - 1; i+=2) {
                if(a[i] != 2) {
                    f = 0;
                    break;
                }
            }
        }
        if(!f) cout << 0 << endl;
        else cout << pw(2, n / 2) << endl;

    }
}
int main() {
   // freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 640