akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k, z, N;
string s, t, d, c;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	stack<char> ss;
	for(auto ch : s) {
		if(ch == 'B' ) {
			if(!ss.empty())ss.pop();
		}
		else {
			ss.push(ch);
		}
	}
	t = "";
	while(!ss.empty()) {
		t+=ss.top();
		ss.pop();
	}
	reverse(all(t));
	cout<<t;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(void){
    int N;
    string S;
    cin>>N>>S;
    int ans=0;
    for(int i=0;i<N-2;i++){
        if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C')ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long unsigned ll;
ll gcd(ll x, ll y){
    ll temp;
  	while(x!=0){
      temp = x;
      x = y%x;	
      y = temp;
    }
    return y;
}
ll lcm(ll x, ll y){
    return x * (y /gcd(x ,y));
}
int main(){
    ll n, ans=1;
    cin >> n;
    ll T[n];
    for(ll i=0;i<n;i++){
        cin >> T[i];
    }
    for(ll i=0;i<n;i++){
        ans = lcm(ans, T[i]);
    }
    cout << ans << endl;
    return 0;
 
}


Measured memory_bytes: 256
fn main()
{
    let n: i32 = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_end().to_owned().parse().unwrap()
    };
    
    match n % 10 {
        2 | 4 | 5 | 7 | 9 => println!("hon"),
        0 | 1 | 6 | 8 => println!("pon"),
        3 => println!("bon"),
        _ => {}
    }
}

Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n,q;
    cin>>n>>q;
    string s;
    cin >>s;
    int k[n];
    for(int i = 0;i<n;i++) k[i] = 0;
    for(int i = 0;i<n;i++){
     int aho  =0;
     if(s[i] == 'A'&&s[i+1] == 'C') aho = 1;
     k[i+1] = k[i]+aho;
    }
    for(int i = 0;i<q;i++){
      int l,r;cin>>l>>r;
      cout<<k[r-1]-k[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int l,r,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <math.h>
using namespace std;

void a()
{
    int k, n;
    cin >> n >> k;
    cout << n - k + 1;
}
void b()
{
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    int am = n / a;
    int bm = n / b;
    int cm = n / c;
    long long int num = 0;

    for (int i = 0; i <= am; i++)
    {
        if (a * i > n)
            break;
        for (int j = 0; j <= bm; j++)
        {
            if (a * i + b * j > n)
                break;
            if ((n - a * i - b * j) % c == 0)
                num++;
        }
    }
    cout << num;
}
void c()
{
    int n;
    cin >> n;
    int inc = 0;
    int outa = 0;
    int outb = 0;
    int bothc = 0;
    for (int i = 0; i < n; i++)
    {
        string tmp;
        cin >> tmp;
        int flag = 0;
        for (int i = 0; i < tmp.length() - 1; i++)
        {
            if (i == 0)
            {
                if (tmp[i] == 'B')
                {
                    outb++;
                    flag++;
                }
            }
            if (tmp.substr(i, 2) == "AB")
            {
                inc++;
            }
        }
        if (tmp[tmp.length() - 1] == 'A')
        {
            outa++;
            flag++;
        }
        if (flag == 2)
            bothc++;
    }
    int sum = 0;
    if (outa == 0 || outb == 0)
        sum = inc;
    else if (outa == bothc && outb == bothc)
        sum = inc + outa - 1;
    else
    {
        int min;
        if (outa < outb)
            min = outa;
        else
            min = outb;

        sum = min + inc;
    }
    cout << sum;
}
void d()
{
    long long int N = 0ll;
    cin >> N;
    long long int sum = 0ll;
    for (long long int i = 1ll; i < sqrt(N); i++)
    {
        if ((N % i) == 0)
        {
            sum += (long long int)((double)N / i) - 1ll;
            // cout << (long long int)((long double)N / i) - 1ll;
        }
    }
    cout << sum;
}
int main(void)
{
    //d();
    c();
    //b();
    //a();
}

Measured memory_bytes: 256
n=int(input())
l=sorted([int(i)for i in input().split()])
ans=0
for i in range(n-2):
    for j in range(i,n-1):
        for k in range(j,n):
            if (l[i]!=l[j]and l[j]!=l[k])and l[k]-l[i]<l[j]:
                ans+=1
print(ans)

Measured memory_bytes: 9188
N = int(input())
A = list(map(int, input().split()))

# 正負が混在するか判定
plus = False
minus = False
for a in A:
    if a > 0:
        plus = True
    elif a < 0:
        minus = True

ans = []

# 正負が混在する場合、符号を揃える
if plus == True and minus == True:
    max_a = max(A)
    min_a = min(A)
    max_idx = A.index(max_a)
    min_idx = A.index(min_a)
    # 正に揃える
    if abs(max_a) >= abs(min_a):
        for i in range(N):
            A[i] += max_a
            ans.append([max_idx + 1, i + 1])
    # 負に揃える
    if abs(max_a) < abs(min_a):
        for i in range(N):
            A[i] += min_a
            ans.append([min_idx + 1, i + 1])
# print(A)

# 正に揃っている場合
if min(A) >= 0:
    # 前から累積和
    for i in range(1, N):
        A[i] += A[i - 1]
        ans.append([i, i + 1])
# 負に揃っている場合
else:
    # 後ろから累積和
    for i in range(N - 2, -1, -1):
        A[i] += A[i + 1]
        ans.append([i + 2, i + 1])

print(len(ans))
for a in ans:
    print(*a)
# print(A)


Measured memory_bytes: 62524
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>
#include <set>

int ProjectA();

int main()
{

	ProjectA();
	return 0;
}

int ProjectA() 
{
	int i, j, k, m, n, a, b, c, tc, o, ans, q, x, y;
	
	scanf("%d", &n);
	scanf("%d", &a);

	printf("%d", (n*n - a));

}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)
	for i := 0; i < len(S); i++ {
		offset := (S[i] - 'A' + byte(N)) % 26
		fmt.Print(string('A' + offset))
	}
	fmt.Println()
}


Measured memory_bytes: 896
input_ = input()
length = int(len(input_))
if length%2==0:
  print('No')
  exit(0)

f,b = input_[:int((length-1)/2)],input_[int((length-1/2)):]
str_ = [input_,f,b]

for s in str_:
  #print(s)
  if s==''.join(list(reversed(s))): pass
  else:
    print('No')
    exit(0)
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int F[45];
    for(int i = 0; i <= n; i++)
    {
        if(i == 0)
        {
            F[i] = 1;
        }
        else if(i == 1)
        {
            F[i] = 1;
        }
        else
        {
            F[i] = F[i-1] + F[i-2];
        }
    }
    cout << F[n] << endl;
}


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

struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E') b=s[0] , s[0]=s[3] , s[3]=s[5] , s[5]=s[2] , s[2]=b;
    if(c=='W') b=s[0] , s[0]=s[2] , s[2]=s[5] , s[5]=s[3] , s[3]=b;
    if(c=='N') b=s[0] , s[0]=s[1] , s[1]=s[5] , s[5]=s[4] , s[4]=b;
    if(c=='S') b=s[0] , s[0]=s[4] , s[4]=s[5] , s[5]=s[1] , s[1]=b;
    s[5]--;
  }
  bool valid(){
    int a=s[0]+s[5];
    int b=s[1]+s[4];
    int c=s[2]+s[3];
    r(i,6)if(s[i]<0) return 0;
    return a<=b+c && b<=a+c && c<=a+b;
  }
  bool END(){
    int a=s[0]+s[5];
    int b=s[1]+s[4];
    int c=s[2]+s[3];
    return !(a+b+c);
  }
};

int a[6];
Dice D;

string S[]={"E","EE","EN","ES","EW","N","NE","NN","NS","NW","S","SE","SN","SS","SW","W","WE","WN","WS","WW",};
#define Ssz 20

string ch(){
  r(i,6) D.s[i]=a[i];
  string res="";
  
  while(1){
    Dice tmp;
    int flag = 0;
    
    r(i,Ssz){
      tmp=D;
      
      r(j,S[i].size()){
	tmp.roll(S[i][j]);
      }
      
      if(tmp.valid()){
	flag = 1;
	D=tmp;
	res += S[i];
	break;
      }
    }
    if(!flag)return "NG";
    if(D.END())break;
  }

  return res;
}

int main(){
  while(1){
    Dice D;
    int sum=0;
    
    r(i,6)cin>>a[i],sum+=a[i];
    if(sum==0)break;

    int L,R;
    cin>>L>>R;
    
    string ans="Z";
    
    do{
      string s=ch();
      if(s=="NG")continue;
      ans = min( ans , s );
    }while(next_permutation(a,a+6));

    if(ans=="Z")cout<<"impossible"<<endl;
    else cout<<ans.substr(L-1,R-L+1)<<endl;
  }
}



Measured memory_bytes: 3280
n=int(input())
S=str(input())
r=S.count('R')
g=S.count('G')
b=S.count('B')
cnt=r*g*b

for j in range(2, n, 2):
    for i in range(0, n-j):
        k = (2 * i + j) // 2
        if S[i] != S[i+j] and S[i] != S[k] and S[k] != S[i+j]:
            cnt -= 1

print(cnt)

Measured memory_bytes: 9040
def main():
    from queue import Queue
    h,w=map(int,input().split())
    grid=[list(input())  for i in range(h)]
    dx=[-1,0,1,0]
    dy=[0,1,0,-1]

    q=Queue()
    q.put([0,0])
    inf=10**5
    ans=[[inf]*w for i in range(h)]
    ans[0][0]=1
    while q.qsize()!=0:
        p=q.get()
        ny,nx=p[0],p[1]
        for i in range(4):
            y=ny+dy[i]
            x=nx+dx[i]    
            if 0<=x<w and 0<=y<h and ans[y][x]>10**4:
                if grid[y][x]=='.':
                    ans[y][x]=ans[ny][nx]+1
                    q.put([y,x])
    if ans[h-1][w-1]>10**4:
        print(-1)
    else:
        cnt_white=sum([grid[i].count('.') for i in range(h)])
        print(cnt_white-ans[h-1][w-1])

if __name__=='__main__':
    main()

Measured memory_bytes: 3948
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
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<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll a, b, c;
    cin >> a >> b >> c;
    if (c - a - b <= 0){
        cout << "No" << endl;
        return 0;
    }
    ll x = 4 * a * b;
    ll y = (c - a - b) * (c - a - b);
    cout << (x < y ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
using ll = long long;

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

    int N;
    cin >> N;
    vector<double> V(N);

    for (int i = 0; i < N; i++)
        cin >> V[i];
    
    sort(V.begin(), V.end());

    for (int i = 1; i < N; i++) {
        V[i] = (V[i] + V[i-1]) / 2;
    }

    cout << V[N-1] << endl;
    
    return 0;
}

Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int b = 0; b < 4; b++) {
    char a[n];
    for (int i = 0; i < 2; i++) {
      if (b & (1 << i)) {
        a[i] = 'S';
      } else {
        a[i] = 'W';
      }
    }
    for (int i = 1; i < n - 1; i++) {
      if (s[i] == 'o' ^ a[i] == 'W') {
        a[i + 1] = a[i - 1];
      } else {
        if (a[i - 1] == 'W') a[i + 1] = 'S';
        else a[i + 1] = 'W';
      }
    }
    int ch, ch2;
    if (s[n - 1] == 'o' ^ a[n - 1] == 'W') {
      ch = a[n - 2];
    } else {
      if (a[n - 2] == 'W') ch = 'S';
      else ch = 'W';
    }

    if (s[0] == 'o' ^ a[0] == 'W') {
      ch2 = a[n - 1];
    } else {
      if (a[n - 1] == 'W') ch2 = 'S';
      else ch2 = 'W';
    }
    if (ch == a[0] && ch2 == a[1]) {
      for (int i = 0; i < n; i++) {
        cout << a[i];
      }
      cout << "\n";
      return 0;
    }
  }
  cout << "-1\n";
}



Measured memory_bytes: 720
#include<iostream>
using namespace std;
int main()
{
    int k,count_odd=0,count_even=0;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        if(i%2==0)
        {
            count_even++;
        }
        else if(i%2!=0)
        {
            count_odd++;
        }
    }
    cout << count_even*count_odd ;
    return 0;
}

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

int main() {
	int N, T;
	std::cin >> N >> T;

	// XXX: 命名
	std::vector<int> okC;
	for(int i = 0; i < N; i++) {
		int c, t;
		std::cin >> c >> t;
		if(t <= T) {
			okC.emplace_back(c);
		}
	}

	if(okC.empty()) {
		std::cout << "TLE" << std::endl;
	} else {
		const auto min = *std::min_element(okC.begin(), okC.end());
		std::cout << min << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
"use strict";

function main(input){
  let arr = input.trim().split(' ').sort();
  if(arr[0] == 5 && arr[1] == 5 && arr[2] == 7)
    console.log("YES");
  else
    console.log("NO");
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 21064
a,b = map(int, input().split())
if (a == 0 or b == 0):
    print('Zero')
elif (a > 0 and b > 0):
    print('Positive')
else:
    if (b < 0):
        if (abs(a - b) % 2 == 1):
            print('Positive')
        else:
            print('Negative')
    else:
        print('Zero')

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int md = 1e9+7;
const ll inf = 1e18;
const int maxn = 2e5+5;

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

int main()
{
	string s;
	cin >> s;
	int str = 0;
	int ans = 0;
	for(int i = 0; i< 3; i++)
	{
		if(s[i] == 'R') str++;
		else str = 0;
		ans = max(ans, str);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3620
N,K = map(int,input().split())
count = 0
for i in range(K,N+2):
    lb = 0.5*i*(i-1)
    ub = i*N-lb
    b = ub-lb+1
    #print(ub,lb,b)
    count += b
    count %= 10**9+7
print(int(count))

Measured memory_bytes: 9148
N, M, X, Y = map(int, input().split())

x_lst = list(map(int, input().split()))
y_lst = list(map(int, input().split()))

if min(y_lst) - max(x_lst) <= 0:
	print("War")
else:
	flg = 1
	for i in range(max(x_lst) + 1, min(y_lst) + 1):
		if X < i and i <= Y:
			flg = 0
			print("No War")
			break
	if flg:
		print("War")

Measured memory_bytes: 38472
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;

llint get(llint x)
{
	return x * (x+1) / 2;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	llint ans = 0;
	for(llint i = 1; i <= n; i++){
		ans += get(n/i) * i;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  vector<long>cost(n);
  vector<long>dp(n);
  for(int i=0;i<n;i++){
    cin >> cost[i];
  }
  dp[0]=0;
  dp[1]=abs(cost[1]-cost[0]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-2]+abs(cost[i]-cost[i-2]),dp[i-1]+abs(cost[i]-cost[i-1]));
  }
  printf("%lu",dp[n-1]);
  return 0;
}


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

    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846

    void solve(){
        ll total=0;
        int d;
        cin>>d;
        vector<int>a(d);
        for(int i=0;i<d;i++)
            cin>>a[i];
        for(int i=0;i<d;i++){
            for(int j=i+1;j<d;j++)
                total+=(ll)a[i]*(ll)a[j];
        }
        cout<<total;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3652
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long 
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
   // cout<<x<<' '<<y<<endl;
    if(y==0)
    return x;
    else
    return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
    if(m%2)
	r=(r*n)%p;
    n=(n*n)%p;
    m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
       return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
	z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	++z[i];
    if (i + z[i] - 1 > r)
	l = i, r = i + z[i] - 1;
    }
    return z;
}
int n;
int a[22][22];
int dp[22][2097153];
int solve(int i,int s)
{
	if(i==n)
		return (s==(1LL<<n)-1)?1:0;
	if(dp[i][s]!=-1)
		return dp[i][s];
	int ans=0;
	for(int j=0;j<n;j++)
	{
		if(a[i][j]==1&&(!(s&(1LL<<j))))
		{
			ans=(ans+solve(i+1,s+(1LL<<j)))%mod;
		}
	}
	dp[i][s]=ans;
	return ans;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   cin>>n;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<n;i++)
   {
   	for(int j=0;j<n;j++)
   	{
   		cin>>a[i][j];
   	}
   }
   cout<<solve(0,0)<<endl;
}        


Measured memory_bytes: 360704
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pb(s) push_back(s)
#define CST(x) cout<<fixed<<setprecision(x)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vvpl=vector<vector<pl>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }

ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

struct UF{
    vl par;
    UF(ll N):par(N){
        rep(i,N)par[i]=i;
    }
    ll root(ll x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }
    bool same(ll x,ll y){
        return root(x)==root(y);
    }
    void unite(ll x,ll y){
        x=root(x),y=root(y);
        if(x==y)return;
        par[x]=y;
        return;
    }
};

ll dp[1010][1010];

int main() {
ll N;
  cin >>N;
  ll c=(N+1000-1)/1000;
  cout<<c*1000-N<<endl;
}



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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int X;
    cin>>X;
    cout<<10-(X/200)<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;
/****************************** START ******************************/

signed main(){
  int N;
  cin >> N;
  int a,b;
  int cnt = 0;
  bool ans = false;
  rep(i,0,N){
    cin >> a >> b;
    if (a == b){
      cnt += 1;
    } else {
      cnt = 0;
    }
    if (cnt >= 3){
      ans = true;
    }
  }
  if (ans){
    cYes;
  } else {
    cNo;
  }
}

Measured memory_bytes: 3604
import java.util.*;
import java.io.*;
import java.math.*;
class Main{
	static int mod1 = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		long w = sc.nextLong();
		ArrayList<pair> al = new ArrayList<>();
		for(int i=1;i<=n;i++){
			pair p = new pair();
			p.l=sc.nextLong();
			p.r=sc.nextLong();
			al.add(p);
		}
		long dp[][] = new long[n+1][(int)w+1];
		long total = -1;
		for(int i=1;i<=n;i++){
			long val = al.get(i-1).l;
			long profit = al.get(i-1).r;
			for(int j=1;j<=w;j++){
				dp[i][j] = dp[i-1][j];
				dp[i][j] = Math.max(dp[i][j], dp[i][j-1]);
				if(j-(int)val>=0){
					dp[i][j] = Math.max(dp[i][j], dp[i-1][j-(int)val] + profit);
				}
			}
		}
		System.out.println(dp[n][(int)w]);
		
	}
	
	
	static boolean prime[] = new boolean[(int)1e6+1];
	public static void prime(){
		for(int i=2;i<=Math.sqrt((int)1e6);i++){
			if(prime[i]==false){
				for(int j=i*i;j<=(int)1e6;j+=i){
					prime[j]=true;
				}
			}
		}
	}
	
	
	

	public static char[] swap(int a, int b, char arr[]){
		for(int i=a, j=b; i<=j;i++, j--){
			char hold = arr[i];
			arr[i] = arr[j];
			arr[j] = hold;
		}
		return arr;
	}


	
	
	
	public static class pair{
		long l;
		long r;
	}
	

	
	public static long sum(long a, long d, long n){
		
		long total = ((n)*((2*a)+(n-1)*d))/2;
		return total;
	}
	
	public static class trie{
		char ch;
		HashMap<Character,trie> hm = new HashMap<>();
		int count;
		boolean isterminal;
	}
	
	
	public static int partition(int [] arr, int s, int e){
		
		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}
	
	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}
	
	
	public static long gcd(long a, long b){
		if(a==0)
			return b;
		
		return gcd(b%a,a);
	}
	
	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}
	
 
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
}

Measured memory_bytes: 126164
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  long long a,b,c;
  cin>>a>>b>>c;
  if(abs(b-a)<=abs(c-a)){
    cout<<"A"<<endl;
  }
  else{
    cout<<"B"<<endl;
  }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;

  vll three={2,5,63};
  vll odd={6,2,10,3,9,4,8,12};
  vll even={2,10,3,9,4,8,6,12};
  vll ans;
  if(n==3)
    ans=three;
  else if(n%2==0){
    ll cnt=0;
    ll cycle=0;
    while(cnt<n){
      REP(i,8){
        if(cnt>=n)
          break;
        ans.push_back(even[i]+cycle*12);
        cnt++;
      }
      cycle++;
    }

  }
  else{
    ll cnt=0;
    ll cycle=0;
    while(cnt<n){
      REP(i,8){
        if(cnt>=n)
          break;
        ans.push_back(odd[i]+cycle*12);
        cnt++;
      }
      cycle++;
    }
  }

  REP(i,ans.size()){
    if(i!=0)
      cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;

}



Measured memory_bytes: 3776
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#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 = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
ll dp[110][110000],w[110],v[110],ans = INF;

int main() {
	ll N, W;
	cin >> N >> W;
	REP(i, N) cin >> w[i] >> v[i];
	REP(i, 101) REPO(j, 100001) dp[i][j] = INF;
	REP(i, N) {
		REP(j, 100000) {
			dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
			dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
		}
	}
	REP(i, 100001) if (dp[N][i] <= W) ans = i;
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;
    
    ll cnt = 0;
    REP(i,K+1,N+1) {
        ll q = (N + 1) / i;
        ll r = (N + 1) % i;
        cnt += MAX((i-K)*q,0) + MAX(r-K,0);
    }
    if(K == 0) cnt -= N;
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 3608
def gcd(a, b):
    if a < b:
        b, a = a, b
    while b:
        a, b = b, a % b
    return a


def calc():
    a, b, c, d = map(int, raw_input().split())
    if a < b:
        return 'No'
    if d < b:
        return 'No'
    if c >= b:
        return 'Yes'
    g = gcd(b, d)
    a %= b
    n = (b - a) / g
    if a + g * n == b:
        n -= 1
    if a + g * n > c:
        return 'No'
    else:
        return 'Yes'


def main():
    t = input()
    for _ in range(t):
        print calc()


if __name__ == '__main__':
    main()


Measured memory_bytes: 30828
#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;

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

template<typename T, typename Compare = greater<T> >
inline void chmax(T& t, T f, Compare comp = Compare()){if(!comp(t, f))t = f;}

int W, H;

string solve(vector<string>& Cs){
    vector<vector<string> > mem(H, vector<string>(W));
    string res = "";
    auto comp = [](string& s, string& t){return s.size() == t.size()? t < s: t.size() < s.size();};
    rep(i, H)rep(j, W)if(isdigit(Cs[i][j])){
        if(mem[i][j].empty())mem[i][j] = Cs[i][j];
        if(i && mem[i-1][j] != "0")chmax(mem[i][j], mem[i-1][j] + Cs[i][j], comp);
        if(j && mem[i][j-1] != "0")chmax(mem[i][j], mem[i][j-1] + Cs[i][j], comp);
        chmax(res, mem[i][j], comp);
    }
    return res;
}

int main(){
    while(cin >> W >> H, W|H){
        vector<string> Cs(H);
        rep(i, H)cin >> Cs[i];
        cout << solve(Cs) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var num = GetLongs(5);
		var min = num.Min();
		var neck = Array.FindIndex(num, x => x == min);
		WriteLine(4 + (N + num[neck] - 1) / num[neck]);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 13524
N = int(input())
L = list(map(int, input().split()))
if N < 3:
  ans = 0
else:
  ans_list = []
  for i in range(N - 2):
    for j in range(i+1, N - 1):
      if L[i] == L[j]:
        pass
      else:
        for k in range(j + 1, N):
          if L[i] != L[k] and L[j] != L[k]:
            l_list = [L[i], L[j], L[k]]
            L_max = max(l_list)
            L_other = [l for l in l_list if l != L_max]
            if L_max < sum(L_other):
              ans_list.append(i)
  ans = len(ans_list)
print(ans)

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

#ifdef  DEBUG
#include "../common/inc/input.h"
#else
#define debuginput()
#endif

using namespace std;

int main() {
  debuginput();
  int a;
  string s;
  string x, y, ans;

  cin >> a >> s;
  x = s.substr(0, a/2);
  y = s.substr(a/2, a/2);
  if ((a & 0x1) == 1 || x != y) {
    ans = "No";
  } else {
    ans = "Yes";
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
H,W,K=map(int,input().split())
x = [input() for i in range(H)]

ans =0
for h in range(2**H):
    for w in range(2**W):
        cnt =0
        for i in range(H):
            for j in range(W):
                if (h >> i) & 1:
                    continue
                if (w >> j) & 1:
                    continue
                if x[i][j] == '#':#1つ1つマスが黒か見ていくが、そのマスが含まれている行と列が消えていない場合にのみ行う
                    cnt +=1
        if K== cnt:
            ans +=1
            
print(ans)

Measured memory_bytes: 9096
def solve():
    s = list(input())
    if s[0] == "A" and s[2:-1].count("C") == 1:
        s.remove("A")
        s.remove("C")

        if "".join(s).islower():
            print("AC")
            exit()

    print("WA")


if __name__ == "__main__":
    solve()


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

int main(){
    int N;
    cin >> N;
    vector<int> Wi(N);
    for (int i=0;i<N;i++){
        cin >> Wi[i];
    }
    int S1 = 0, S2 = 0;
    int ans = 100000000;
    for (int t=0;t<N-1;t++){
        S1 = 0;
        S2 = 0;
        for (int i=0;i<=t;i++){
            S1 += Wi[i];
        }
        for (int i=t+1;i<N;i++){
            S2 += Wi[i];
        }
        ans = min(ans, abs(S1-S2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int r, c;
    int t[101][101];
    cin >> r >> c;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> t[i][j];
        }
    }
    for (int i = 0; i < r; i++) {
        t[i][c] = 0;
        for (int j = 0; j < c; j++) {
            t[i][c] += t[i][j];
        }
    }
    for (int i = 0; i < c; i++) {
        t[r][i] = 0;
        for (int j = 0; j < r; j++) {
            t[r][i] += t[j][i];
        }
    }
    t[r][c] = 0;
    for (int i = 0; i < r; i++) {
        t[r][c] += t[i][c];
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cout << t[i][j] << " ";
        }
        cout << t[i][c] << endl;
    }
    for (int j = 0; j < c; j++) {
        cout << t[r][j] << " ";
    }
    cout << t[r][c] << endl;
}


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

int main(){

    int n,a;
    cin >> n >> a;

    vector<int> x(n);
    int ma=0;

    rep(i,n){
        cin >> x[i];
        x[i]-=a;
        ma=max(abs(x[i]),ma);
    }

    vector<vector<ll> > dp(n+1,vector<ll>(2*n*ma+1,0));

    dp[0][n*ma]=1;

    for(int i=1;i<=n;i++){
        for(int j=0;j<=2*n*ma;j++){
            if(j-x[i-1]<0||j-x[i-1]>2*n*ma){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=dp[i-1][j]+dp[i-1][j-x[i-1]];
            }
        }
    }

    cout << dp[n][n*ma]-1 << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

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

  long N, M;
  cin >> N >> M;
  vector<vector<long>> A(N, vector<long>(2));
  rep(i, 0, N) {
    cin >> A[i][0] >> A[i][1];
  }
  sort_(A);
  long n;
  ll ans = 0;
  int i = 0;
  while (M > 0) {
    n = min(M, A[i][1]);
    ans += n * A[i][0];
    M -= n;
    ++i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <numeric>
#include <cmath>



#define rep(i, n) for(int i = 0;i < (int)(n); i++)
#define pb push_back
typedef long long ll;

using namespace std;


int main() {
    double min1 = 99999999;
    double n,t,a;
    int ans = 0;
    cin >> n >> t >> a;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    rep(i, n){
        double temp = t - v[i] * 0.006;
        if(min1 > abs(temp - a)){
            min1 = abs(temp - a);
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
#include<cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,pii> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}

bool warp[5][5];
int maze[3010][3010];
int cnt[3010][3010];
int h,w;
vector<string> s;
int c;
void dfs(int y,int x){
    cnt[y][x]=c;
    for(int i=0;i<4;++i){
        int ny=y+dy[i],nx=x+dx[i];
        if(!(ny>=0&&ny<h&&nx>=0&&ny<w)) continue;
        if(s[ny][nx]=='#') continue;
        if(cnt[y][x]>0) continue;
        dfs(ny,nx);
    }
}
int main(){
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;++i) cin>>a[i];
    vector<int> d(1e6+1,0);
    for(int i=2;i<=1e6;++i){
        if(d[i]==0){
            for(int j=i;j<=1e6;j+=i){
                if(d[j]==0) d[j]=i;
            }
        }
    }
    vector<bool> prime(1e6,false);
    bool pc=true;
    for(int i=0;i<n;++i){
        int t=a[i];
        while(t>1){
            int p=d[t];
            while(t%p==0) t/=p;
            if(prime[p]){
                pc=false;break;
            }else prime[p]=true;
        }
    }
    if(pc){
        cout<<"pairwise coprime"<<endl;
        return 0;
    }
    int g=a[0];
    for(int i=1;i<n;++i) g=gcd(g,a[i]);
    if(g==1) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
    return 0;
}



Measured memory_bytes: 11140
// 2016/05/23 Tazoe

#include <iostream>
using namespace std;

// Node?????????
class Node{
public:
	Node* prev;	// ?????????????????????????????????
	Node* next;	// ?¬???????????????????????????????
	int data;	// ?????????
	Node(){prev = 0; next = 0; data = 0;}		// ????????????????????????????????????
};

// List?????????
class List{
private:
	Node head;	// ?????????????????????????????????
public:
	List(){head.prev = &head; head.next = &head;}	// ????????????????????????????????????
	int insert(int x);		// ?????\
	int del(int x);			// ??????
	int deleteFirst();		// ???????????????
	int deleteLast();		// ????°??????????
	void print();			// ??¨???
};

// insert????????????????????\???
int List::insert(int x)
{
	Node* p = new Node();

	if(p==0)
		return -1;		// ?????¢????¢??????¨??????

	Node* q = &head;
	Node* r = head.next;

	p->prev = q;
	p->next = r;
	p->data = x;

	q->next = p;
	r->prev = p;

	return 0;			// ??£?????????
}

// del????????????????????????
int List::del(int x)
{
	Node* p;

	for(p=head.next; p!=&head; p=p->next){
		if(p->data==x)
			break;
	}

	if(p==&head)
		return -2;		// ??¢?´¢??¨??????

	Node* q = p->prev;
	Node* r = p->next;

	q->next = r;
	r->prev = q;

	delete p;

	return 0;			// ??£?????????
}

// deleteFirst?????????????????????????????????
int List::deleteFirst()
{
	Node* p = head.next;

	if(p==&head)
		return -2;		// ??¨??????

	Node* q = p->prev;
	Node* r = p->next;

	q->next = r;
	r->prev = q;

	delete p;

	return 0;			// ??£?????????
}

// deleteLast???????????????????°?????????????
int List::deleteLast()
{
	Node* p = head.prev;

	if(p==&head)
		return -2;		// ??¨??????

	Node* q = p->prev;
	Node* r = p->next;

	q->next = r;
	r->prev = q;

	delete p;

	return 0;			// ??£?????????
}

// print?????????????????¨??????
void List::print()
{
	for(Node* p=head.next; p!=&head; p=p->next){
		cout << p->data;

		if(p->next!=&head){
			cout << ' ';
		}
		else{
			cout << endl;
		}
	}
}


// main??¢??°
int main()
{
	List L;

	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		char com[20];		// C?????????
		cin >> com;

		if(com[0]=='i'){
			int x;
			cin >> x;

			L.insert(x);
		}
		else if(com[6]=='F'){
			L.deleteFirst();
		}
		else if(com[6]=='L'){
			L.deleteLast();
		}
		else{
			int x;
			cin >> x;

			L.del(x);
		}
	}

	L.print();

	return 0;
}

Measured memory_bytes: 32444
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
	using T = int;
	const T def = 0;
	T f(T a, T b) { return a + b; }
	//==========================================
    vector<int> par; 
	vector<T> value;
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
	void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
	int operator[](int x) {
		if (par[x] == x) return x;
		else {
			int res = operator[](par[x]);
			if (res != par[x]) {
				value[res] = f(value[res], value[par[x]]);
				value[par[x]] = def;
			}
			return par[x] = res;
		}
	}
	// uf(x,y)->y
    void operator()(int x, int y) {
		x = operator[](x); y = operator[](y); 
		if (x != y) {
			value[y] += value[par[x]];
			value[par[x]] = def;
			par[x] = y;
		}
	}
	T getValues(int x) { return value[operator[](x)]; };
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, K, A[101010], B[101010], C[101010], D[101010];
int ans[101010];
set<int> friends[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> K;
	rep(i, 0, M) cin >> A[i] >> B[i], A[i]--, B[i]--;
	rep(i, 0, K) cin >> C[i] >> D[i], C[i]--, D[i]--;

	UnionFind uf(N);
	rep(i, 0, M) uf(A[i], B[i]);

	rep(i, 0, N) ans[i] = uf.getValues(i) - 1;
	rep(i, 0, M) {
		ans[A[i]]--;
		ans[B[i]]--;
		friends[A[i]].insert(B[i]);
		friends[B[i]].insert(A[i]);
	}
	rep(i, 0, K) if (!friends[C[i]].count(D[i]) && uf[C[i]] == uf[D[i]]) {
		ans[C[i]]--;
		ans[D[i]]--;
	}

	rep(i, 0, N) {
		if(i) printf(" ");
		printf("%d", ans[i]);
	}
	printf("\n");
}







Measured memory_bytes: 18168