akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
//const long long int pl=1000000;

long long int N,M,X,T,Q,res=0,sum=0;


int main(){
    cout << fixed << setprecision(18);
    cin>>N>>X>>T;
    cout<<(N+X-1)/X*T<<endl;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
#define lowbit(x) (x&-x)
#define F first
#define S second 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f; 
const int maxn=1e5+10;
int main()
{
	double a,b;
	cin>>a>>b;
	if(a>b){
		cout<<-1;
		return 0;
	}
	int la=a/0.08+0.5,ra=(a+1)/0.08+0.5;
	int lb=b/0.1+0.5,rb=(b+1)/0.1+0.5;
	
	if(max(la,lb)<min(ra,rb))
	cout<<max(la,lb);
	else cout<<-1;
}


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

int check(int a,int b,int c)
{
	a=a*a;
	b=b*b;
	c=c*c;
	if(a>=b&&a>=c&&a==b+c)
		return 1;
	if(b>=a&&b>=c&&b==c+a)
		return 1;
	if(c>=a&&c>=b&&c==b+a)
		return 1;
	return 0;
}
int main()
{
	int N,a,b,c;
	cin>>N;
	while(N--){
		cin>>a;
		cin>>b;
		cin>>c;
		if(check(a,b,c))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,L;
  cin >> N >> L;
  int minN = INF;
  int apple = 0;
  rep(i,N) {
    apple += L + i;
    if(abs(L+minN) > abs(L+i)) {
      minN = i;
    }
  }
  apple -= L + minN;
  cout << apple << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    int cmax=0,cmin=1e9;
    int n;
    cin>>n;
    while(n--)
    {
        cin>>a;
        cmax=max(a,cmax);
        cmin=min(a,cmin);
    }
    cout<<cmax-cmin<<endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 2000005
#define M 998244353
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"Yes\n";
#define N cout<<"No\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;

void solve()
{
     lli n;cin>>n;

     if(n%2==0) {cout<<-1;return;}

      lli sum=0,ten=10;
     for(lli i=1;i<S;i++)
     {
          

          sum=((sum%n*ten%n)%n+7)%n;
          sum=sum%n;
          if(sum==0)
          {
               cout<<i;
               return ;
          }

     }


     cout<<-1;

     


}
int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif    
     
     // test
     {
          solve();
          nl
     }
}
//a+b=a?b+2?(a&b)
//__builtin_popcount(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";




Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
int main(void){
  char s[3];
  scanf("%s", s);
  
  if(!strcmp(s, "AAA") || !strcmp(s, "BBB")){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int piv;
		String S_head,S_tail;
		int ans = 0;
		StringBuilder sb_head = new StringBuilder();
		StringBuilder sb_tail = new StringBuilder();

		if (S.length() % 2 == 0 ) {
			piv =  (int)Math.round(S.length()/2);
			S_head = S.substring(0,piv);
			S_tail = S.substring(piv,S.length());
		}else {
			piv =  (int)Math.round(S.length()/2) + 1;
			S_head = S.substring(0,piv - 1);
			S_tail = S.substring(piv,S.length());
		}
		sb_head.append(S_head);
		sb_tail.append(S_tail).reverse();
		for (int i = 0; i < sb_head.length(); i++) {
			if (sb_head.charAt(i) != sb_tail.charAt(i)) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35564
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007

using namespace std;

void solve()
{

    ll a, b, n;

    cin >> a >> b >> n;

    cout << (a * min(b - 1, n)) / b << endl;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}



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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string st;
    cin >> st;
    if(st == "Sunny") cout << "Cloudy";
    if(st == "Cloudy") cout << "Rainy";
    if(st == "Rainy")   cout << "Sunny";
    return 0;
}


Measured memory_bytes: 256
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
value=[]
for i in range(n):
    value.append(v[i]-c[i])
ans=0
for i in range(len(value)):
    if value[i]>0:
        ans+=value[i]
print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
const ll mod=1000000007,N=1e2+5,M=1e5+5,INF=0x3f3f3f3f3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head
struct node{
    int v,a,b;
    node(int _v,int _a,int _b):v(_v),a(_a),b(_b){

    }
};
int n,m,s;
VL c,d;

vector<node>e[N];
ll dp[N][2501],ans[N];
bool inq[N][2501];
void bfs(){
    queue<PII>q;
    dp[1][min(s,2500)]=0;
    q.push({1,min(s,2500)});
    inq[1][min(s,2500)]=1;
    while(!q.empty()){
        int po=q.front().fi,si=q.front().se;
        inq[po][si]=0;
        //cout<<"step "<<po<<' '<<si<<' '<<dp[po][si]<<endl;
        //getchar();
        q.pop();
        for(int i=1;i*c[po]+si<=2500;++i){
            if(dp[po][i*c[po]+si]>dp[po][si]+i*d[po]){
                dp[po][i*c[po]+si]=dp[po][si]+i*d[po];
                if(!inq[po][i*c[po]+si]){
                    inq[po][i*c[po]+si]=1;
                    q.push({po,i*c[po]+si});
                }
            }
        }
        for(auto nx:e[po]){
            if(si>=nx.a){
                if(dp[nx.v][si-nx.a]>dp[po][si]+nx.b){
                    dp[nx.v][si-nx.a]=dp[po][si]+nx.b;
                    if(!inq[nx.v][si-nx.a]){
                        inq[nx.v][si-nx.a]=1;
                        q.push({nx.v,si-nx.a});
                    }
                }
            }
        }
    }
}
int main(void){
    cin>>n>>m>>s;
    c.resize(n+1);
    d.resize(n+1);
    rep(i,1,m+1){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        e[u].pb({v,a,b});
        e[v].pb({u,a,b});
    }
    rep(i,1,n+1){
        cin>>c[i]>>d[i];
    }
    memset(dp,0x3f,sizeof(dp));
    bfs();
    MEM(ans,0x3f);
    rep(i,2,n+1){
        rep(j,0,2501){
            ans[i]=min(ans[i],dp[i][j]);
        }
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 6480
using System;

namespace AOJ
{
    class Program
    {
        static void Main()
        {
            string line = Console.ReadLine();
            int[] num = TypeConverter.arrayStrToInt(line.Split(' '));

            int d = num[0] / num[1];
            int r = num[0] % num[1];
            double f = num[0] / (double)num[1];

            Console.WriteLine(d.ToString() + " " + r.ToString() + " " + f.ToString("f5"));
        }
    }

    class TypeConverter
    {
        static public int[] arrayStrToInt(string[] str)
        {
            return Array.ConvertAll<string, int>(str,
                delegate(string value)
                {
                    return int.Parse(value);
                }
            );
        }

        static public string[] arrayIntToStr(int[] x)
        {
            return Array.ConvertAll<int, string>(x,
                delegate(int value)
                {
                    return value.ToString();
                }
            );
        }
    }
}

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



int main()
{
    // 整数の入力
    int a, b;
    // 文字列の入力
    string u,t,s;
 

    cin >> u >> t ;
    cin >> a >> b;
    cin >> s;

    if (u == s) {
        a = a - 1;

    }
    else {
        b = b - 1;

    }
    
    // 出力
    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
 
int n;
string s;
LL cnt[30];
const int mod = 1e9 + 7;
 
int main(){
    INIT;
    cin >> n >> s;
    REP(i, n){
        cnt[s[i] - 'a']++;
    }
    LL ans = 1;
    REP(i, 26){
        if(!cnt[i])continue;
        ans *= (cnt[i] + 1);
        ans %= mod;
    }
    cout << (ans - 1)%mod << endl;
}

Measured memory_bytes: 512
s =list(map(int,input().split()))

i = 1

while True:
    if s[0] <= 0:
        print("No")
        break
    elif s[2] <= 0:
        print("Yes")
        break
    s[(i%2)*2] -= s[((i+1)%2)*2+1]
    i += 1
        

Measured memory_bytes: 9156
#include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		bool hantei = true;
		int a;
		int count = 1;
		for (int i = 0; i < n; i++) {
			cin >> a;
			if (a > 1) {
				hantei = false;
			}
			if (a > 0) {
				count++;
			}
		}
		if (hantei) {
			cout << "NA" << endl;
		} else {
			cout << count << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define inf 20021225
#define ll long long
#define mxn 110
using namespace std;

int n,a[mxn],m;

int main()
{
	int cnt=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		cnt+=a[i]%2;
	}
	if(cnt>2)
	{
		printf("Impossible\n");
		return 0;
	}
	int fs=0;
	for(int i=1;i<=m;i++)
	{
		if(a[i]%2==1)
		{
			if(!fs)	swap(a[1],a[i]),fs=1;
			else	swap(a[m],a[i]);
		}
	}
	for(int i=1;i<=m;i++)	printf("%d ",a[i]);puts("");
	if(m==1)
	{
		if(a[1]==1)	printf("1\n1\n");
		else	printf("2\n1 %d\n",a[1]-1);
		return 0;
	}
	a[1]--; a[m]++; 
	if(a[1]==0)
	{
		printf("%d\n",m-1);
		for(int i=2;i<=m;i++)	printf("%d ",a[i]);
	}
	else
	{
		printf("%d\n",m);
		for(int i=1;i<=m;i++)	printf("%d ",a[i]);
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input().split()[0])
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

p = 0

for i in range(N):
    b_index = a_list[i] - 1
    p += b_list[b_index]
    if i != 0:
        if a_list[i] - 1 == a_list[i-1]:
            c_index = a_list[i] - 2
            p += c_list[c_index]
print(p)


Measured memory_bytes: 3064
import sys

def main():
    input = sys.stdin.readline
    N = [int(n) for n in input().strip()]

    if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
        print('Yes')
    else:
        print('No')

    


if __name__ == '__main__':
    main()


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

ll n, x;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> x;
	
	if(x == 1 || x == 2*n-1){print("No")}
	else{
		print("Yes")
		if(x == 2){
			rep(i, 4, n+1){print(i)}
			print(1)
			print(2)
			print(3)
			rep(i, n+2, 2*n-1){print(i)}
		}
		else{
			if(x == 2*n-2){
				rep(i, 1, n-2){print(i)}
				print(2*n-3)
				print(2*n-2)
				print(2*n-1)
				rep(i, n-1, 2*n-4){print(i)}
			}
			else{
				if(x-1 > n-2){
					rep(i, 1, n-2){print(i)}
					print(2*n-1)
					print(x)
					print(x-1)
					print(2*n-2)
					rep(i, n-1, x-2){print(i)}
					rep(i, x+1, 2*n-3){print(i)}
				}
				else{
					rep(i, 1, x-2){print(i)}
					rep(i, x+1, n){print(i)}
					print(2*n-1)
					print(x)
					print(x-1)
					print(2*n-2)
					rep(i, n+1, 2*n-3){print(i)}
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

int main() {
	int N, M;
	while(cin>> N >> M, N|M) {
		vector< pair<int, int> > v;
		REP(i, N) {
			pair<int, int> p;
			cin >> p.second >> p.first;
			v.push_back(p);
		}
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());

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

Measured memory_bytes: 1328
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  REP(i, A+1) REP(j, B+1) REP(k, C+1){
    if(i*500+j*100+k*50 == X) ans++;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fast std::ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
 
 //string ans="";
/*ll solve(ll n )
 {
     if(n<12)
        return n;
     if(mp[n]==0)
            mp[n]=max(solve(n/2)+solve(n/3)+solve(n/4),n);
     return mp[n];
        
 }
*/
 
int main()
{
   
    fast;
    ll t=1,x=1;
    //cin>>t;
    while(t--)
    {
        ll a,b,c,k;
        cin>>a>>b>>c>>k;
        ll x=0;
        while(b<=a)
        {
            b*=2;
            x++;
        }
        while(c<=b)
        {
            c*=2;
            x++;
        }
        if(x<=k)
        cout<<"Yes";
        else
            cout<<"No";
    }
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n;
	while (cin >> n, n) {
		vector< string > s(n);
		for_(i,0,n) cin >> s[i];
		
		for_(i,0,n) {
			int m = s[i].size();
			for_(j,0,m) {
				if (s[i][j] != '.') {
					s[i][j - 1] = '+';
					break;
				}
				s[i][j] = ' ';
			}
		}
		
		for_(i,1,n) {
			int m = s[i].size();
			for_(j,0,m) {
				if (s[i][j] != '+') continue;
				int k = i+1;
				while (k < n && (int)s[k].size() > j && s[k][j] == ' ') ++k;
				
				if (k < n && (int)s[k].size() > j && s[k][j] == '+') {
					--k;
					while (k > i) {
						assert(s[k][j] == ' ');
						s[k][j] = '|', --k;
					}
				}
			}
		}
		
		for_(i,0,n) cout << s[i] << endl;
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int x = 0;
  rep(i,n) x ^= a[i];
  rep(i,n) cout << (x ^ a[i]) << endl;
}

Measured memory_bytes: 4032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0033
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = RInt();

            for (int i = 0 ; i < n ; i++)
            {
                int[] items = RIntAr();
                LinkedList<int> cylinderB = new LinkedList<int>();
                LinkedList<int> cylinderC = new LinkedList<int>();

                cylinderB.AddFirst(0);
                cylinderC.AddFirst(0);

                bool CanPut = true;
                for (int j = 0 ; j < items.Count() ; j++)
                {
                    if (cylinderB.Last.Value < items[j] || cylinderC.Last.Value < items[j])
                    {
                        if (cylinderB.Last.Value < items[j] && cylinderC.Last.Value > items[j]) cylinderB.AddLast(items[j]);
                        else if (cylinderB.Last.Value > items[j] && cylinderC.Last.Value < items[j]) cylinderC.AddLast(items[j]);
                        else { if(cylinderB.Last.Value > cylinderC.Last.Value) cylinderB.AddLast(items[j]); else cylinderC.AddLast(items[j]); }
                    }
                    else
                    {
                        CanPut = false;
                        break;
                    }
                }
                Console.WriteLine(CanPut ? "YES" : "NO");
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  
  string s;
  cin >> s;
  int n = (int)s.length();
  int left = 0;
  ll sum = 0;
  REP(i,n){
    if(s[i] == 'W'){
      sum += i-left;
      left++;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3716
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	string s;
	cin >> s;
	if (s.size() == 2 && s[0] == s[1]) {
		cout << 1 << " " << 2 << endl;
		return 0;
	}
	rep(i, s.size() - 2) {
		if (s[i] == s[i + 1] || s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;

	return 0;
}


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

int main(){
	while(true){
		int h, w;
		cin >> h >> w;
		char ct[] = {'#', '.'};
		
		if(h == 0) break;
		
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				cout << ct[(i+j)%2];
			}
			cout << "\n";
		}
		cout << "\n";
	}
	cout << flush;
	
	return 0;
}


Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);


int main() {
  int h,n;
  cin >> h >> n;
  
  vector<int> p(n);
  
  rep(i,n) {
  cin >> p[i];
  h-=p[i];
  }
   
  cout << (h<=0?"Yes":"No") << endl;
  
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }




void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec (N,0);
  int SUM = 0;
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  int ANS = 0;
  for (int i = 0; i < 200000; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if(vec[j] >= N)
      {
        int d = vec[j]/N;
        ANS += d;
        vec[j] -= d*N;
        for (int k = 0; k < N; k++)
        {
          if(j != k)
          {
            vec[k] += d;
          }
        }
        
      }
    }
    
  }
  
    cout<<ANS<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
	x, y, z = map(int, input().split())
	a[i] = x
	b[i] = y
	c[i] = -z

INF = float('inf')
d = [INF]*N
d[0] = 0

for _ in range(N-1):
	for i in range(M):
		if d[a[i]-1]==INF:
			continue
		if d[b[i]-1]>d[a[i]-1]+c[i]:
			d[b[i]-1] = d[a[i]-1] + c[i]

ans = -d[N-1]

negative = [False]*N
for _ in range(N):
	for i in range(M):
		if d[a[i]-1]==INF:
			continue
		if d[b[i]-1]>d[a[i]-1]+c[i]:
			d[b[i]-1] = d[a[i]-1] + c[i]
			negative[b[i]-1] = True
		if negative[a[i]-1]==True:
			negative[b[i]-1] = True

if negative[N-1]==True:
	print('inf')
else:
	print(ans)

Measured memory_bytes: 48088
#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 <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int c,int d){
    return d ? gcd(d, c % d) : c;
}



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

    int a,b,c,d; cin >> a >> b >> c >> d;
    for(;;){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 3652
n,k=map(int,input().split())
snacks={}
for i in range(0,k):
  d=int(input())
  l=list(map(int,input().split()))
  for j in range(0,len(l)):
      snacks[l[j]]=1
count=0
for i in snacks.keys():
  count+=1
print(n-count)
  
  
  

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string a,b,c;
  	cin >> a >> b >> c;

    transform(a.begin(),a.end(),a.begin(),::toupper);
  	transform(b.begin(),b.end(),b.begin(),::toupper);
  	transform(c.begin(),c.end(),c.begin(),::toupper);
  	cout << a[0] << b[0] << c[0] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine().trim());
    List<Pair> pairs = new ArrayList<>(n);
    for (int i = 0; i < n; i++) {
      String[] line = sc.nextLine().trim().split(" ");
      int time = Integer.valueOf(line[0]);
      int limit = Integer.valueOf(line[1]);
      pairs.add(new Pair(time, limit));
    }
    Collections.sort(pairs);
    int currentTime = 0;
    for (Pair pair : pairs) {
      currentTime += pair.time;
      if (currentTime > pair.limit) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
  public static class Pair implements Comparable<Pair> {
    final int time;
    final int limit;

    Pair(int time, int limit) {
      this.time = time;
      this.limit = limit;
    }

    @Override
    public int compareTo(Pair o) {
      return limit - o.limit;
    }
  }
}

Measured memory_bytes: 177316
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int i;
    if(n%2==0){
        int c = n/2;
        int mg = (int)(m/2);
        int mk = (int)((m+1)/2);
        for(i=0;i<mk;i++){
            cout << i+1 << " " << c-i << endl;
        }
        for(i=0;i<mg;i++){
            cout << c+i+1 << " " << n-1-i << endl;
        }
    }else{      
        for(i=0; i<m;i++){
            cout << i+1 << " " << n-i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

ll MAX = 1000000000000000000;
ll X_Y_MAX = 1000000000;

void Main()
{
	ll S; cin >> S;
	ll res[10];
	if (S <= X_Y_MAX) {
		res[0] = 1;
		res[1] = 0;
		res[2] = 0;
		res[3] = S;
	} else {
		ll div = S / X_Y_MAX;
	    ll mod = S % X_Y_MAX;
		if (mod == 0) {
			res[0] = div;
			res[1] = 0;
			res[2] = 0;
			res[3] = X_Y_MAX;
		} else {
			for (ll i = 1; i * i <= mod; i++) {
		    	if (mod % i == 0) {
		    		if (div + i > X_Y_MAX) {
		    			continue;
		    		}
	        		res[0] = div;
	        		res[1] = mod / i;
	        		res[2] = -i;
	        		res[3] = X_Y_MAX;
                }
            }
		}
	}
	
	cout << 0 - res[2] << " 0" << " ";
	cout << res[0] - res[2] << " ";
	cout << res[1] << " ";
	cout << 0 << " ";
	cout << res[3] << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int[] ary=new int[n];
        for(int i=0;i<n;i++)ary[i]=sc.nextInt();
        sc.close();

        Arrays.sort(ary);
        for(int i=0;i<n;i++){
            if(ary[i]>=k){
                System.out.println(n-i);
                System.exit(0);
            }
        }
        System.out.println("0");
    }
}

Measured memory_bytes: 49736
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int t, p, r;
	static int[] ac, time;
	static int[][] wa;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}

	static boolean read(){
		t = sc.nextInt();
		p = sc.nextInt();
		r = sc.nextInt();
		if(t == 0 && p == 0 && r == 0)return false;
		wa = new int[t+1][p+1];
		ac = new int[t+1];
		time = new int[t+1];
		for(int i = 0; i < r; i++){
			int tId = sc.nextInt();
			int pId = sc.nextInt();
			int submitTime = sc.nextInt();
			String status = sc.next();
			if(status.equals("WRONG")){
				wa[tId][pId]++;
			}else{
				ac[tId]++;
				time[tId] += wa[tId][pId]*1200 + submitTime;
			}
		}
		return true;
	}
	
	static void solve(){
		PriorityQueue<Integer> q = new PriorityQueue<Integer>(t, new Comparator<Integer>(){
			public int compare(Integer obj1, Integer obj2){
				if(ac[obj1] != ac[obj2]){
					return ac[obj2] - ac[obj1];
				}else if(time[obj1] != time[obj2]){
					return time[obj1] - time[obj2];
				}else{
					return obj1 - obj2;
				}
			}
		});
		for(int i = 1; i <= t; i++){
			q.add(i);
		}
		while(!q.isEmpty()){
			int id = q.poll();
			System.out.println(id + " " + ac[id] + " " + time[id]);
		}
	}
}

Measured memory_bytes: 13000
n = int(input())
info = []
Base = []
Result = [['#' for i in range(10)] for k in range(15)]



for ia in range(n):
    val = list(map(int, input().split()))
    info.append(val)


for B in range(1,5):
    for F in range(1,4):
        for R in range(1,11):
            Base.append(list((B, F, R, 0)))

for ib in info:
    b, f, r, v = ib[0], ib[1], ib[2], ib[3]
    for ic in Base:
        if b == ic[0] and f == ic[1] and r == ic[2]:
            ic[3] += v

for ic in Base:
    b1, f1, r1, v1 = ic[0]-1, ic[1]-1, ic[2]-1, ic[3]
    Result[b1*4+f1][r1] = str(v1)
        
for ie, value in enumerate(Result):
    if ie == 3 or ie == 7 or ie == 11:
        print('#'*20, end='\n')
    else:
        print(' ' +' '.join(value),end='\n')


Measured memory_bytes: 5624
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
      int D = sc.nextInt();
      
      System.out.println((int)Math.ceil(N/(2.0*D+1)));
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

Measured memory_bytes: 23252
#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 <limits>
using namespace std;
using ll = long long;

int main(){
  int H,W;
  cin >> H >> W;
  vector< vector<int> > A(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> A[i][j];
    }
  }
  ll ans=0;
  queue< pair<int,int> > sol;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A[i][j]%2==0){
        continue;
      }
      if(i==H-1 &&  j==W-1){
        continue;
      }
      ans++;
      sol.push(make_pair(i+1,j+1));
      if(j!=W-1){
        A[i][j+1]++;
      }
      else{
        A[i+1][j]++;
      }
    }
  }
  cout << ans << endl;
  while(!sol.empty()){
    int y=sol.front().first;
    int x=sol.front().second;
    sol.pop();
    cout << y << " " << x << " ";
    if(x!=W){
      cout << y << " " << x+1 << endl;
    }
    else{
      cout << y+1 << " " << x << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5624
# AGC003B - Simplified mahjong
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, [input() for _ in range(N)])) + [0]
    ans = 0
    for i in range(N):  # make pairs greedily
        ans += A[i] // 2  # pairs with same cards
        if A[i] % 2 and A[i + 1]:  # pairs with a neighbor
            ans += 1
            A[i + 1] -= 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14240
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve(int test) {
	int a=0,b=0,c=0,d=0;
	int n ; cin >> n ;
	rep(i,0,n) {
		string s; cin >> s;
		if(s[0] == 'A') ++a;
		else if(s[0] == 'W') ++b;
		else if(s[0] == 'T') ++c;
		else ++d ;
	}
	cout << "AC x " << a << nl ;
	cout << "WA x " << b << nl ;
	cout <<"TLE x " << c << nl ;
	cout << "RE x " << d << nl ;
 }
 
int32_t main() {
  

    fast;
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

typedef struct {
    char mark;
    int value;
} Card;

void print(Card C[], int N) {
    int i;
    for (i = 0; i < N; i++) {
        printf("%c%d", C[i].mark, C[i].value);
        if (i != N-1)
            printf(" ");
        else
            printf("\n");
    }
}

void BubbleSort(Card C[], int N) {
    int i, j;
    Card num;

    for (i = 0; i < N; i++) {
        for (j = N-1; j > i; j--) {
            if (C[j].value < C[j-1].value) {
                num = C[j];
                C[j] = C[j-1];
                C[j-1] = num;
            }
        }
    }
    print(C, N);
    printf("Stable\n");
}

void SelectionSort(Card C[], int N) {
    int i, j;
    int minj;
    Card tmp;

    for (i = 0; i < N; i++) {
        minj = i;
        for (j = i; j < N; j++){
            if (C[j].value < C[minj].value)
                minj = j;
        }
        tmp = C[i];
        C[i] = C[minj];
        C[minj] = tmp;
    }
    print(C, N);
}

int main() {
    int N, flag = 1;
    int i;
    Card C1[36], C2[36];

    scanf("%d", &N);

    for (i = 0; i < N; i++) {
        scanf(" %c%d", &C1[i].mark, &C1[i].value);
        C2[i] = C1[i];
    }

    BubbleSort(C1, N);
    SelectionSort(C2, N);

    for(i = 0; i < N; i++) {
        if(C1[i].mark != C2[i].mark) {
            flag = 0;
            break;
        }
    }

    if (flag)
        printf("Stable\n");
    else
        printf("Not stable\n");

    return 0;
}



Measured memory_bytes: 2104
a,b,c,x,y = map(int,input().split())
ans = 0
if a + b > c*2:
    if x > y and a < c*2 :
        ans += 2*c*y + (x-y)*a
    elif y > x and b < c*2:
        ans += 2*c*x+(y-x)*b
    else:
        ans += 2*c*max(x,y)
else:
    ans += a*x+b*y
print(ans)

Measured memory_bytes: 3064
use std::io::*;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let token:String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n:usize = read();
    let mut w:Vec<usize> = (0..n).map(|_| read()).collect();
    for i in 1..n {
        w[i] += w[i-1];
    }
    let mut m:usize = w[n-1];
    for i in 0..n {
        m = cmp::min(m,cmp::min(w[n-1]-2*w[i],2*w[i]-w[n-1]));
   }
    println!("{}",m);
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph emplace
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n;
map <ll, bool> mp;
ll ans;
void tryy(ll x) {
	ll y = ((n-x)/x);
	if(mp[y]||y==0)return;
	if(n%y!=n/y)return;
	mp[y]=1; ans+=y;
}
int main()
{
	cin>>n;
	for(ll i=1;i*i<=n;i++){
		if(n%i) continue;
		tryy(i);
		tryy(n/i);
	}
	cout<<ans;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1e6+7;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(0.0) * 2;
int x,a,b;
int main() {
    while(~scanf("%d%d%d",&x,&a,&b)) {
        int c = max(x-a,a-x);
        int d = max(x-b,b-x);
        if(c>d)printf("B\n");
        else printf("A\n");
    }
    return 0;
}


Measured memory_bytes: 256