akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int field[6][6];
int dp[6][6][1<<12];
int n;
const int INF=1000000000;
int seiseki[4];

// óÔsÌidxÔÚÌlðæèo·
int getValue(int s,int idx){
    int b1=((s>>idx*2)&1);
    int b2=((s>>idx*2+1)&1);
    return b1+2*b2;
}
// óÔsÌidxÔÚÉlxðZbg
void setValue(int &s,int idx,int x){
    int b1=((x>>0)&1);
    int b2=((x>>1)&1);
    if(b1==0)
        s&=~(1<<idx*2);
    else
        s|=(1<<idx*2);
    if(b2==0)
        s&=~(1<<(idx*2+1));
    else
        s|=(1<<(idx*2+1));
}

// (»Ýn_ÌxÀW,»Ýn_ÌyÀW,êÔµ½5}XÌóÔ
int rec(int x,int y,int s){
    if(x==4){
        x=0;
        y++;
        if(y==4){
            int res=0;
            // ¡ÌsÌlð0-4Ìn_ÌàÌð·×Ä«µí¹A»êðÔ·
            for(int i = 0; i < 5; i++)
                if(field[y][i]!=-1)
                    res+=seiseki[getValue(s,i)];
            return res;
        }
    }
    if(dp[y][x][s]!=INF)
        return dp[y][x][s];
    int maxCost=0;
    // »Ýn_ð½ñ·©
    for(int i = 0; i <= 3; i++){
        if(x==0){
            int ns=0;
            setValue(ns,5,getValue(s,4));
            setValue(ns,4,getValue(s,3));
            setValue(ns,3,getValue(s,2));
            setValue(ns,2,(getValue(s,1)+i)%4);
            setValue(ns,1,(max(0,field[y+1][x+1])+i)%4);
            setValue(ns,0,(max(0,field[y+1][x])+i)%4);
            // ¶ãÌêÌXRAðmè³¹é
            int res=0;
            if(field[y][x]!=-1)
                res+=seiseki[(getValue(s,x)+i)%4];
            // rec
            maxCost=max(maxCost,res+rec(x+1,y,ns));
        }
        else{
            int ns=0;
            for(int j = 0; j < 6; j++){
                if(j==x||j==x+2)
                    setValue(ns,j,(getValue(s,j)+i)%4);
                else
                    setValue(ns,j,getValue(s,j));
            }
            setValue(ns,x+1,(max(0,field[y+1][x+1])+i)%4);
            // ¶ãÌêÌXRAðmè³¹é
            int res=0;
            if(field[y][x]!=-1)
                res+=seiseki[(getValue(s,x+1)+i)%4];
            // EãÌXRAàmè³¹é
            if(x==3){
                if(field[y][x+1]!=-1)
                    res+=seiseki[(getValue(s,x+2)+i)%4];
            }
            maxCost=max(maxCost,res+rec(x+1,y,ns));
        }
    }
    return dp[y][x][s]=maxCost;
}


int main(){
    seiseki[0]=0;
    seiseki[1]=60;
    seiseki[2]=70;
    seiseki[3]=80;
    cin>>n;
    for(int q=0;q<n;q++){
        for(int i = 0; i < 6; i++)
            for(int j = 0; j < 6; j++)
                for(int k = 0; k < (1<<12); k++)
                    dp[i][j][k]=INF;
        for(int i = 0; i < 5; i++){
            for(int j = 0; j < 5; j++){
                cin>>field[i][j];
                field[i][j]--;
            }
        }
        int s=0;
        for(int i = 0; i < 5; i++)
            setValue(s,i,max(0,field[0][i]));
        int res=rec(0,0,s);
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 1440
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair, tuple

int main(){
      int a,b,c;cin >> a >> b >> c;
      if(a == 1)cout << "YES";
      else if(a == 77)cout << "NO";
      else if((a & 1))cout << "YES";
      else if(!(a & 1) && !(c & 1))cout << "YES";
      else cout << "NO";
}

Measured memory_bytes: 256
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
#define IO ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);
typedef long long ll;
typedef long double ld;
 

 
ll MOD=1e9 + 7;
ll OO=1e10;
const int N=3e3 + 5;
int arr[N];
int dp[N][N];

ll n,m,k,cnt,SU,idx,len,MN,MX,T;
int l,r,mid;
int a,b,c;
string s,t,ans;
int Solve(int l,int r){
	
	if(l == SZ(s) || r == SZ(t))
		return 0;
	
	int &ret = dp[l][r];
	if(~ret)
		return ret;
	
	if(s[l] == t[r])
		return ret = 1 + Solve(l+1,r+1);

	
	return ret = max(Solve(l+1,r) , Solve(l,r+1));
}


void Bulid(int l,int r){
	if(l == SZ(s) || r == SZ(t))
		return;
	
	
	if(s[l] == t[r]){
		ans+=s[l];
		Bulid(l+1,r+1);
		return;
	}

	int val = Solve(l,r);
	int x = Solve(l+1,r);
	int y = Solve(l,r+1);
	if(val == x)
		Bulid(l+1,r);
	else
		Bulid(l,r+1);
}


int main(){
	memset(dp,-1,sizeof dp);
	
	IO
	
	cin>>s>>t;

	Solve(0,0);
	Bulid(0,0);
	cout<<ans<<endl;
	


	
	

}




Measured memory_bytes: 35840
# Combination
MOD = 10**9+7
MAX = 2*10**5
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

H, W, A, B = map(int, input().split())
ans = 0
for i in range(1, H-A+1):
    cnt = comb(i-1+B-1, i-1)
    #print(i, cnt)
    cnt *= comb(H-i+W-B-1, H-i)
    ans += cnt
    ans %= MOD
print(ans)


Measured memory_bytes: 29784
h,w,k = map(int,input().split())
matrix = [list(input()) for n in range(h)]
ans = 0

for fill_h in range(2**h):
  for fill_w in range(2**w):
    cnt = 0
    for i in range(h):
      for j in range(w):
        if (fill_h >> i)&1 == 0 and (fill_w >> j)&1 == 0:
          if matrix[i][j] == '#':
            cnt += 1
    if cnt == k:
      ans += 1
      
print(ans)

Measured memory_bytes: 9152
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
    double a, b, A, B, N, M, K;
    int i;
    cin >> N >> M >> K;
    A = min(N, M);
    B = max(N, M);
    for(i = 0; i <= A; i++){
        a = i;
        if(2*a != B){
            b = (K -a*B) / (A -2*a);
            if(ceil(b) == floor(b) && b <= B && b >= 0){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        Arrays.sort(s);
        for (int i = 0; i < n; i++) {
            System.out.print(s[i]);
        }
    }
}

Measured memory_bytes: 23252
def main():
    n, w = map(int, input().split())
    wv = [list(map(int, input().split())) for _ in range(n)]

    dp = [0] * (w + 1)
    for wi, vi in wv:
        for sum_w in range(w, wi - 1, -1):
            v = dp[sum_w - wi] + vi
            if dp[sum_w] < v:
                dp[sum_w] = v

    print(dp[w])


if __name__ == '__main__':
    main()


Measured memory_bytes: 14348
#include <iostream>
#include <stdio.h>

using namespace std;

int H, N, P, M, K;
int bar[505];
double dp[505][505][105];

int main(void)
{
	cin >> H >> N >> P >> M >> K;
	int a, b;
	for(int i = 1; i <= M; i++){
		cin >> a >> b;
		bar[H+1-a] = b;
	}
	
	double x = 1;
	for(int i = 0; i < K; i++){
		x *= (H-M-i);
		x /= (i+1);
	}
	for(int i = 0; i < K; i++) x *= (N-1);
	
	dp[0][0][P] = 1.0 / x;
	for(int i = 0; i < H; i++){
		for(int j = 0; j <= K; j++){
			for(int k = 1; k <= N; k++){
				int pt = N-1;
				if(bar[i+1] == 0){
					if(k > 1) dp[i+1][j+1][k-1] += dp[i][j][k], pt--;
					if(k < N) dp[i+1][j+1][k+1] += dp[i][j][k], pt--;
					dp[i+1][j+1][k] += pt * dp[i][j][k];
					dp[i+1][j][k] += dp[i][j][k];
				}else{
					if(k == bar[i+1]) dp[i+1][j][k+1] += dp[i][j][k];
					else if(k == bar[i+1]+1) dp[i+1][j][k-1] += dp[i][j][k];
					else dp[i+1][j][k] += dp[i][j][k];
				}
			}
		}
	}
	
	double ans = 0.0;
	for(int i = 1; i <= N; i++){
		ans = max(ans, dp[H][K][i]);
	}
	printf("%.11f\n", ans);
	
	return 0;
}


Measured memory_bytes: 46932
/**
 * @Author:      G_bg
 * @DateTime:    2019-05-19 20:18:24
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn = 1e5+10;
int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(0);cin.tie(0);
	int n,k;cin >> n >> k;
	double p = 1.0/n;
	double ans = 0.0;
	for(int i = 1;i <= n;i++){
		double y = k*1.0/i;
		int xx = (int)(log(y)/log(2.0));
		if(k <= i) {
			ans += p;
		}else{
			if(pow(2,xx*1.0) < y) xx++;
			ans += p*pow(0.5,xx);
		}
	}
	cout << fixed << setprecision(12) << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>

int main() {

    int A, B, C;

    std::cin >> A >> B >> C;
    std::vector<int> components{A, B, C};
    std::sort(components.begin(), components.end());

    if (components[0] == 5 && components[1] == 5 && components[2] == 7){
        std::cout << "YES\n";
    }else{
        std::cout << "NO\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    string s;
    cin >> s;
    long long int k;
    cin >> k;
    rep(i,k){
        if(s[i]=='1') continue;
        else{
            cout<<s[i]<<endl;
            return 0;
        }
    }
    cout<<'1'<<endl;
    return  0;
}

Measured memory_bytes: 256
#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() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> c[i];
  rep(i, n) p[i]--;

  ll ans = -1e18;
  rep(si, n) {
    int x = si;  // current position
    vector<int> s;
    ll tot = 0;
    while (true) {
      x = p[x];
      s.push_back(c[x]);
      tot += c[x];
      if (x == si) break;
    }
    int l = s.size();  // length of cycle
    ll t = 0;
    rep(i, l) {
      t += s[i];
      if (i + 1> k) break;
      ll now = t;
      if (tot > 0) {
        ll e = (k - i - 1) / l;
        now += tot * e;
      }
      ans = max(ans, now);
    }
  }

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


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define irp(i,s,e) for(int i=(int)(s);i>(int)(e);--i)
// #define NMAX 1000000000
int K;
string S;

string solve(){
	string ans = "";
	if((int)S.size() <= K){
		return S;
	}
	else{
		ans = S.substr(0,K);
		return ans+"...";
	}
}

int main(){
	cin>>K>>S;
	cout<< solve() <<endl;

	// printf("%f\n",solve());
	// cout<<cout<<setprecision(10)<<ans<<endl;
	// solve();
}


Measured memory_bytes: 3624
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

n = int(input())
if n % 2 == 0:
    print(0.5)
else:
    print((n - n // 2) / n)

Measured memory_bytes: 5240
// YOU THINK YOU KNOW ME.//


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int                      long long
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define countbit                __builtin_popcount
#define loop(i,a,n)				for(int i=a;i<n;i++)
#define pb                      push_back
#define pf                      push_front
#define mp                      make_pair
#define f                       first
#define s                       second
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define boost                   ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
#define cases                   int tests;cin>>tests;while(tests--)
#define all(s)                  s.begin(),s.end()
#define line                    cout<<endl;
#define watch(x)                cout<<(#x)<<" is "<<x<<endl
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rich_set;
bool isprime(int n){if(n==1)return false;if(n==2)return true;for(int i=2;i<=sqrt(n);i++){if(n%i==0){ return false;}}return true;}
int poww(int b,int e){if(e==0)return 1;else if(e%2==0){int a=pow(b,e/2);return a*a;}else {int a=pow(b,e/2);return b*a*a;}}
int powm(int x,int y,int m=MOD){x=x%m;int res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
int modInverse(int a, int m=MOD) { return powm(a, m-2, m);}
void print(vector<int>v){for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}}
void print(int arr[]){int size = *(&arr + 1) - arr; for(int i=0;i<size;i++){cout<<arr[i]<<" ";}}
string to_bin(int n){string res="";int i=0;while(n>0){if(n%2==1){res=res+'1';}else{res=res+'0';}n/=2;i++;}reverse(all(res));return res;}
int to_dec(string s){int n=s.size(),ans=0,temp=1;for(int i=n-1; i>=0; i--){int x=s[i]-'0';ans+=x*temp;temp*=2;}return ans;}
void result(bool f){if(f)cout<<"YES"<<endl;else cout<<"NO"<<endl;}



void solve(){
	string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    int dp[n+2][m+2]={0};
    dp[0][0]=0;
    
    loop(i,0,n+1){
        loop(j,0,m+1){
            if(i==0 || j==0){
                dp[i][j]=0;
                continue;
            }
            if(s[i-1]==t[j-1]){
                dp[i][j]= dp[i-1][j-1]+1;
            }
            else dp[i][j]= max(dp[i-1][j] , dp[i][j-1]);
        }
    }
    string ans="";
    int ind=n,jind=m;
    while(ind>0 && jind>0){
        if(s[ind-1] == t[jind-1]){
            ans+=s[ind-1];
            ind--;
            jind--;
        }
        else if(dp[ind][jind-1]>dp[ind-1][jind]){
            jind--;
        }
        else{
            ind--;
        }
    }
    reverse(all(ans));
    cout<<ans<<endl;



}
int32_t main(){
	boost
  //cases
	solve();	
	
	//return 0;
}

Measured memory_bytes: 70656
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    Integer c[][] = new Integer[3][3];
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        c[i][j] = sc.nextInt();
      }
    }
    int a,b;
    a = c[0][0] - c[0][1];
    b = c[0][1] - c[0][2];
    String ans = "Yes";
    for(int i=1; i<3; i++){
      if(a != c[i][0] - c[i][1] || b != c[i][1] - c[i][2]){
        ans = "No";
        break;
      }
    }
    for(int j=1; j<3; j++){
      if(c[0][0] - c[1][0] != c[0][j] - c[1][j] || c[1][0] - c[2][0] != c[1][j] - c[2][j]){
        ans = "No";
        break;
      }
    }
    out.println(ans);
          
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

typedef long long ll;

int a, b, c, d;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b >> c >> d;
    if (a + b > c + d) {
        cout << "Left" << endl;
    } else if (a + b < c + d) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }

    return 0;
}



Measured memory_bytes: 3652
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    Arrays.sort(a);
    double ans=(double)a[0];
    for(int i=1;i<n;i++){
      ans=(double)(ans+a[i])/2.0;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22740
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	if(n%10==9||n/10==9) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

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

	cout << N - i + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
#define ll long long
const int mod = 998244353, maxn = 1e5+10;
int N, M, K;
int w[maxn], v[maxn], dp[maxn];

int main()
{
    scanf("%d %d", &N, &M);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d %d", &w[i], &v[i]);
        K += v[i];
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for(int i = 1; i <= N; i++)
        for(int j = K; j >= v[i]; j--)
        {
            dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
        }
    for(int j = K; j >= 0; j--)
        if(dp[j] <= M)
        {
            printf("%d\n", j);
            return 0;
        }
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(){
  int i,j,n,count=0,mini;
  scanf("%d",&n);
  int a[n];

  for(i=0; i<n; i++)
    scanf("%d",&a[i]);
  
  for(i=0; i<n; i++){
    mini = i;
    for(j=i; j<n; j++)
      if(a[j] < a[mini])
	mini = j;
    if(mini != i){    
      int tmp = a[i];
      a[i] = a[mini];
      a[mini] = tmp;
      count++;
    }
  }
  
  for(i=0; i<n-1; i++)
    printf("%d ",a[i]);
  
  printf("%d\n%d\n",a[n-1],count);
  return 0;
}



Measured memory_bytes: 2100
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let d = read::<i64>();
    let mut dseq = vec![0; n];
    for i in 0..n {
        dseq[i] = read::<i64>();
    }
    let q = read::<usize>();
    let mut qseq = vec![0; q];
    for i in 0..q {
        qseq[i] = read::<usize>() - 1;
    }
    let mut poss = vec![0; n];
    let mut pos = d;
    for i in 0..n {
        poss[i] = pos;
        pos = std::cmp::min(pos, (pos - dseq[i]).abs());
    }
    if pos != 0 {
        for _ in 0..q {
            println!("YES");
        }
        return;
    }
    let mut all_ok = vec![true; n];
    let mut movable = 0;
    // println!("{:?}", poss);
    for i in (0..n).rev() {
        all_ok[i] = poss[i] <= movable;
        if (movable + 1) * 2 > dseq[i] {
            movable += dseq[i];
        }
        // println!("{} {}", movable, poss[i]);
    }
    // println!("{:?}", all_ok);
    for i in 0..q {
        println!("{}", if all_ok[qseq[i]] { "NO" } else { "YES" });
    }
}


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

int main() {
	int n,i,j,k,ans=0;
	cin >> n;
	
	vector<int> l(n);
	for(i=0; i<n; i++){
		cin >> l[i];
	}
	sort(l.begin(),l.end());
	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			if(l[i]==l[j]){
				continue;
			}
			for(k=j+1; k<n; k++){
				if(l[i]==l[k] || l[j]==l[k]){
					continue;
				}
				if(l[i]+l[j]>l[k]){
					ans++;
				}
			}
		}
	}
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << a * b << " " << a * 2 + b * 2 << endl;
	return 0;
}


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

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>


using namespace std;

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

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

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

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

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

	string S;
	cin >> S;

	int sum = 0;
	for (auto c : S)
	{
		sum += (int)(c - '0');
	}

	if (sum % 9 == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


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

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

    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        ans += (s[i] == '+' ? 1 : -1);
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int a,worktime=0,offtime=0;
    for(int i = 0;i < m;i++){
        cin >> a;
        worktime += a;
    }
    offtime = n - worktime;
    if(offtime < 0)cout << -1 << endl;
    else cout << offtime << endl;
}

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

int main(){
int X,Y;

cin >> X >> Y ;

int reX,reY,re;
reX = 0;
reY = 0;
if(X==1) reX = 300000;
    
else if(X==2) reX = 200000;
else if(X==3) reX = 100000;

if(Y==1) reY = 300000;
else if(Y==2) reY = 200000;
else if(Y==3) reY = 100000;

if(X==1 && Y==1) re = 1000000;
else re = reX + reY;

cout << re <<endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static System.Math;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static long a, b, x;
        


        public static void Input()
        {
            var cin = new Solve();

            var input = cin.SplitReaderL();
            a = input[0];
            b = input[1];
            x = input[2];
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            if (a == 0) { Console.WriteLine((b / x) + 1); }
            else { Console.WriteLine((b / x) - ((a - 1) / x)); }

            //Console.Out.Flush();
        }

        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }
}

    



Measured memory_bytes: 13396
mn = input()
mn = mn.split()
m, n = int(mn[0]), int(mn[1])
A_array = list()
for i in range(m):
    A = input()
    A = A.split()
    A_array.append(A)
B_array = list()
for j in range(n):
    b = input()
    B_array.append(int(b))
for i in A_array:
    result = 0
    for A,B in zip(i,B_array):
        result += int(A)*int(B)
    else:
        print(result)
        


Measured memory_bytes: 6252
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, long long> memo;
long long nCr(int n, int r) {
    if (r > n-r) return nCr(n, n-r);
    if (memo.find(make_pair(n, r)) != memo.end()) {
        return memo[make_pair(n, r)];
    }
    long long res = 1;
    for (int i = 1; i <= r; i++) {
        res *= (n-i+1);
        res /= i;
    }
    return memo[make_pair(n, r)] = res;
}
int main () {
    long long N, P;
    long long o = 0, e = 0;
    cin >> N >> P;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        if (A % 2) o++;
        else e++;
    }
    long long k = 0;
    for (int i = 0; i <= e; i++) {
        k += nCr(e, i);
    }
    long long ans = 0;
    for (int i = P; i <= o; i+=2) {
        ans += k * nCr(o, i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S,T;
    cin >> S >> T;
    int N = S.size();
    rep(i,0,N-1){
        S += S[i];
    }
    if(S.find(T) != -1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.exceptions(cin.failbit)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const int mod=1000000007;
const int inf=1e9+100;
const int N=2e6+10;

int main()
{
	boost;
	int h,w,k;
	cin>>h>>w>>k;
	vector<vector<bool > > a(h,vector<bool> (w,0));
	vector<vector<int > > ans(h,vector<int> (w,0));
	int now=1;
	std::vector< int >  v[h];
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) 
	{
		char c;
		cin>>c;
		//check(c);
		if(c=='#') a[i][j]=1,ans[i][j]=now++,v[i].pb(j);
		else a[i][j]=0;
	}
	std::vector<bool> done(h,0);
	for(int i=0;i<h;i++)
	{
		sort(all(v[i]));
		if(int(v[i].size())==0)
		{
			if(i>0)
			{
				//check(i);
				

				ans[i]=ans[i-1];
				//show(ans[i]);
				//show(ans[i-1]);
				done[i]=done[i-1];
				continue;
			}
			else continue;
		}
		int prev=0;
		int last=0;
		for(auto j:v[i])
		{
			while(prev<=j)
			{
				ans[i][prev]=ans[i][j];
				prev++;
			}
			last=j;
		}
		while(prev<w)
		{
			ans[i][prev]=ans[i][last];
			prev++;
		}		
		done[i]=1;

	}

	for(int j=h-2;j>=0;j--)
	{
		if(done[j]==0) ans[j]=ans[j+1];
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++) cout<<ans[i][j]<<" ";cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main() {

	long int n;
	cin >> n;
	vector<long int> friends;
	friends.resize(n);

	for(long int i = 0 ; i < n ; i++) {
			friends[i] = 0;
	}

	for(long int i = 0 ; i < n ; i++) {
		long int place;
		cin >> place;
		friends[i] = place-1;
	}

	long int counter = 0;
	for(long int j = 0 ; j < n ; j++) {
			if(friends[friends[j]] == j) {
				counter++;
			}
	}

	cout << counter/2;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
double maxvolume(double s)
{
    double length = s / 3;
 
    s -= length;
    double breadth = s / 2;
    double height = s - breadth;
    return length * breadth * height;
}
int main()
{
    double s;
    cin>>s;
    cout<<fixed<<setprecision(12)<< maxvolume(s) << endl;
    return 0;
} 


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <climits>
#include <vector>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int n = 0, c = gcu();
	// bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	return n; }
	// return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

template <typename T>
struct heap{
	vector<T> h = {T()};

	void insert(T x) {
		h.push_back(x);
		int c = h.size() - 1;
		for (int p = c / 2; p; c = p, p /= 2)
			if (h[p] < x)
				h[c] = move(h[p]);
			else
				break;
		h[c] = move(x);
	}
	T extract() {
		T res = move(h[1]);
		h[1] = h.back();
		T v = move(h[1]);
		h.pop_back();

		int p = 1, H = h.size();
		for (int c = 2; c < H; p = c, c = p * 2) {
			if (c + 1 < H && h[c] < h[c + 1])
				c++;
			if (h[c] < v)
				break;
			h[p] = move(h[c]);
		}
		h[p] = move(v);

		return move(res);
	}

	bool empty() {
		return h.size() == 1;
	}
};

#define v vector
struct graph {
	struct node {int n, w;};
	v<v<node>> nodes;

	void read(int n) {
		nodes.resize(n);
		for (auto &x: nodes) {
			in();
			for (int k = in(); k--;) {
				int c = in();
				x.push_back({c, in()});
			}
		}
	}

	v<node> dks() {
		v<node> w(nodes.size(), {0, INT_MAX});
		w[0].w = 0;
		heap<node> q;
		q.insert({0, 0});
		while (!q.empty()) {
			node n = q.extract();
			if (w[n.n].n)
				continue;
			w[n.n].n = 1;
			for (node &x: nodes[n.n]) {
				int a = n.w + x.w;
				if (w[x.n].w > a) {
					w[x.n].w = a;
					q.insert({x.n, a});
				}
			}
		}
		return move(w);
	}
};

bool operator < (const graph::node &a, const graph::node &b) {
	return a.w > b.w;
}

int main() {
	graph g;
	g.read(in());
	int i = 0;
	for (auto &x: g.dks())
		out(i++, ' ', x.w, '\n');
}


Measured memory_bytes: 7284
S=input().strip()
N=len(S)
snum=1
ns=S[0]
def solve(S):
    global ns,snum
    for i in range(N):
        #print(ns)
        if ns!=S[i]:
            snum+=1
            ns=S[i]
    #if snum==1 and S[0]=='B':
    #    snum=3
    #    return snum
    return snum

print(solve(S)-1)

Measured memory_bytes: 3188
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();

        char[] u = new char[n * 2];
        int i = 0;
        for (int j = 0; j < n; j++) {
            u[i++] = s[j];
            u[i++] = t[j];
        }

        System.out.println(String.valueOf(u));
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        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());
        }
    }
}

Measured memory_bytes: 20692
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<typeinfo>
#include<cstdlib>
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> d;
  for(int i=0;i<k;i++){
    int tmp;
    cin >> tmp;
    d.push_back(tmp);
  }
  sort(d.begin(),d.end());
  
  vector<int> d2;
  int k2=0;
  for(int i=0;i<10;i++){
    if(i!=d[i-k2]){
      d2.push_back(i);
      k2++;
    }
  }
  
  int ntmp=n;
  int cnt=0;
  int flag=1;
  int ret=0;
  while(ntmp>0){
    int dig = ntmp%10;
    if(!flag){
      dig++;
    }
    flag=0;
    for(int i=0;i<k2;i++){
      if(dig==d2[i]){
	flag=1;
	break;
      }
      if(!flag &&  dig< d2[i]){
	dig=d2[i];
	flag=1;
	ret=0;
	for(int k=1;k<=cnt;k++){
	  ret+=d2[0]*pow(10,k);
	}
      }
    }
    if(!flag)
      dig=d2[0];
    cnt++;
    ntmp/=10;
    ret+=dig*pow(10,cnt);
  }
  if(!flag){
    cnt++;
    if(d2[0]!=0)
      ret+=d2[0]*pow(10,cnt);
    else
      ret+=d2[1]*pow(10,cnt);
  }
  cout <<ret/10<<endl;
}



Measured memory_bytes: 384
import numpy as np

N,D = list(map(int, input().split()))
x = [[0.0]*D]*N
for i in range(N):
    x[i] = list(map(int, input().split()))

def norm(y,z,D):
    nrm = 0.0
    for i in range(D):
        nrm = nrm + (y[i] - z[i])*(y[i] - z[i])
    return np.sqrt(nrm)

count = 0
for i in range(N):
    for j in range(i+1,N):
        dis = norm(x[i],x[j],D)
        if dis.is_integer():
            count = count + 1
print(count)

Measured memory_bytes: 12504
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,100*N):
    if use >= set(str(i)):
        print(i)
        break


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

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

int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    cin >> n;
    ll ans = 1;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        ans = a / gcd(ans, a) * ans;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> L(N);
    rep (i, N) {
        cin >> L[i];
    }

    sort(L.begin(), L.end());

    ll ans = 0;
    rep (i, N) {
        for (ll j = i+1; j < N; j++) {
            auto it = lower_bound(L.begin(), L.end(), L[i]+L[j]);
            ans += N-(j+1)-(L.end()-it);
        }
    }

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

Measured memory_bytes: 256
n=int(input())
b=input().split()

a=[0]*n
a[0]=b[0]
a[n-1]=b[n-2]
ans=0

for i in range(n-2):
  a[i+1]=min(int(b[i]),int(b[i+1]))

for j in range(n):
  ans+=int(a[j])

print(ans)


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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int turn = 0;

    while (A > 0 && C > 0) {
        if (turn == 0)
            C -= B;
        else
            A -= D;

        turn = !turn;
    }

    cout << (turn == 1 ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
int n,q;
P a[214514];
vector<int> t[214514];
int sum[214514]={};
bool reached[214514]={};
void tansaku(int s){
    for(int i=0;i<t[s].size();i++){
        if(reached[t[s][i]]==false){
            sum[t[s][i]]+=sum[s];
            reached[t[s][i]]=true;
            tansaku(t[s][i]);
        }
    }
    return;
}
signed main(){
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        cin>>a[i].first>>a[i].second;
        if(a[i].second<a[i].first)swap(a[i].first,a[i].second);
        a[i].first--;
        a[i].second--;
        t[a[i].first].push_back(a[i].second);
        t[a[i].second].push_back(a[i].first);
    }
    for(int i=0;i<q;i++){
        int p,x;
        cin>>p>>x;
        sum[p-1]+=x;
    }
    reached[0]=true;
    tansaku(0);
    for(int i=0;i<n-1;i++){
        cout<<sum[i]<<" ";
    }
    cout<<sum[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 28160
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll k;
  cin >> k;
  vector<ll> ans(50, k / 50 + 49);
  int num = k % 50;
  for(int i = num; i < 50; i++) ans[i] -= num;
  rep(i, num) ans[i] += 50 - num + 1;
  cout << 50 << endl;
  rep(i, 49) cout << ans[i] << " ";
  cout << ans[49] << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,M;
ll ans;
P AB[100005];

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>M;
rep(i,N) cin>>AB[i].first>>AB[i].second;
sort(AB,AB+N);

rep(i,N){
	if(AB[i].second<M){
		ans+=AB[i].second*AB[i].first;
		M-=AB[i].second;
	}
	else{
		ans+=M*AB[i].first;
		M=0;
	}
	if(M==0){
		cout<<ans<<endl; return 0;
	}
}

}
	


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <algorithm>

#define rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define print(x) cout << (x) << endl 
#define min2(a, b) ((a) < (b)) ? (a) : (b)
#define max2(a, b) ((a) > (b)) ? (a) : (b)
#define count counting_variable

using namespace std;

int mintime = INT16_MAX;
int A[5];

int main(){
    int sum = 0;
    rep(i, 0, 5){
        cin >> A[i];
    }
    sort(A, A + 5, [](int x, int y) -> bool{return ( (x - 1) % 10 > (y - 1) % 10);});
    rep(i, 0, 4){
        sum += (A[i] + (10 - 1)) / 10 * 10;
    }
    sum += A[4];
    print(sum);
    return 0;
}

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

const int maxn = 1010;

vector<int> g[maxn];
int n;
int d[maxn], father[maxn], maxson[maxn], son[maxn];
int s,t,len;

void link(int u, int v) { g[u].push_back(v); g[v].push_back(u); }

void del(int u, int v)
{
	for (int i=0;i<g[u].size();i++)
		if (g[u][i] == v) g[u].erase(g[u].begin()+i);
	for (int i=0;i<g[v].size();i++)
		if (g[v][i] == u) g[v].erase(g[v].begin()+i);
}

int find(int ss)
{
	queue<int> que;
	int maxd = 0, maxu;
	while (!que.empty()) que.pop();
	for (int i=0;i<=n;i++) d[i] = 0, son[i] = 0;
	que.push(ss);
	while (!que.empty())
	{
		int u = que.front();
		if (d[u] > maxd) { maxd = d[u]; maxu = u; }
		que.pop();
		for (auto v:g[u])
		{
			if (d[v] || v == ss) continue;
			son[u]++;
			d[v] = d[u] + 1;
			father[v] = u;
			que.push(v);
		}
	}
	return maxu;
}


int findd()
{
	s = find(1);
	t = find(s);
	return d[t];
}

ll solve1(int c1, int c2)
{
	del(c1,c2);
	find(c1);
	memset(maxson,0,sizeof(maxson));
	for (int i=1;i<=n;i++)
	{
		if (!d[i] && i != c1) continue;
		maxson[d[i]] = max(maxson[d[i]],son[i]);
	}
	find(c2);
	for (int i=1;i<=n;i++)
	{
		if (!d[i] && i != c2) continue;
		maxson[d[i]] = max(maxson[d[i]],son[i]);
	}
	ll ret = 1;
	for (int i=0;i<=len/2;i++)
		if (maxson[i]) ret = ret * (ll)maxson[i];
	link(c1,c2);
	return ret * 2LL;
}

ll solve2(int c)
{
	find(c);
	memset(maxson,0,sizeof(maxson));
	for (int i=1;i<=n;i++)
	{
		if (!d[i] && i != c) continue;
		maxson[d[i]] = max(maxson[d[i]],son[i]);
	}
	ll ret = 1;
	for (int i=0;i<=len/2;i++) 
		if (maxson[i]) ret = ret * (ll)maxson[i];
	return ret;
}

int main()
{
	//freopen("D.in","r",stdin);
	cin >> n;
	for (int i=1;i<n;i++)
	{
		int u,v;
		cin >> u >> v;
		link(u,v);
	}
	len = findd();
	ll ans;
	if (len % 2 == 1)
	{
		for (int i=1;i<=len/2;i++) t = father[t];
		ans = solve1(t,father[t]);
	}
	else
	{
		for (int i=1;i<=len/2;i++) t = father[t];
		ans = solve2(t);
		len++;
		vector<int> list; list.clear();
		for (auto v : g[t]) list.push_back(v);
		for (auto v : list)
		{
			ans = min(ans,solve1(t,v));
		}
	}

	cout << len/2 + 1 << " " << ans << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()

	if N%f(N) == 0 {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
	wtr.Flush()
}

func f(n int) int {
	ans := 0
	for n > 0 {
		ans += n % 10
		n /= 10
	}
	return ans
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> h(n), dp(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++) {
        int cost1 = dp[i - 1] + abs(h[i] - h[i - 1]);
        int cost2 = dp[i - 2] + abs(h[i] - h[i - 2]);
        dp[i] = min(cost1, cost2);
    }

    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

	public void Proc()
	{
        
        string ans = "Impossible";
        int[] num = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        if(num.Sum()%3==0||num.Any(a=>a%3==0)) {
			ans = "Possible";
		}
        Console.WriteLine(ans);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"




4 5



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13780
n = int(input())
ls = [list(map(str,input().split())) for _ in range(n)]
nums = [e for e in range(1,n+1)]
for i in range(n):
    ls[i][1] = 100-int(ls[i][1])
    ls[i] = ls[i] + [nums[i]] 
ls = sorted(ls)
for i in range(n):
    print(ls[i][2])

Measured memory_bytes: 3060
#include <iostream>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

  int r,g;
  cin >> r >> g;

  cout << g*2 - r << endl;
    
  return 0;
}


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

using namespace std;

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

int main() {

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    while (true) {
        c -= b;
        if (c <= 0) {
            puts("Yes");
            return 0;
        }
        a -= d;
        if (a <= 0) {
            puts("No");
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>

int main(){
  long x;
  scanf("%ld",&x);
  
  for(int a=0;a<=200;a++){
    for(int b=-200;b<=200;b++){
      if(a*a*a*a*a-b*b*b*b*b==x){printf("%d %d",a,b);return 0;}
    }
  }
}

Measured memory_bytes: 1720