akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
long H,W,a,b,c,h,hh,w,ww,ans;

inline void solve(){
  ans=1LL<<60;
  IN2(H,W);
  UP(h,1,H-1){
    a=h*W;
    hh=(H-h)/2;
    b=hh*W;
    c=(H-h-hh)*W;
    // printf("%ld %ld %ld\n",a,b,c);
    chmin(ans,max(a,max(b,c))-min(a,min(b,c)));
    ww=W/2;
    b=(H-h)*ww;
    c=(H-h)*(W-ww);
    // printf("%ld %ld %ld\n",a,b,c);
    chmin(ans,max(a,max(b,c))-min(a,min(b,c)));
  }
  UP(w,1,W-1){
    a=H*w;
    ww=(W-w)/2;
    b=H*ww;
    c=H*(W-w-ww);
    // printf("%ld %ld %ld\n",a,b,c);
    chmin(ans,max(a,max(b,c))-min(a,min(b,c)));
    hh=H/2;
    b=hh*(W-w);
    c=(H-hh)*(W-w);
    // printf("%ld %ld %ld\n",a,b,c);
    chmin(ans,max(a,max(b,c))-min(a,min(b,c)));
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

const int mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x = 0) : x(x % mod){}
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> broken(n+1);
    rep(i,m) {
        int a;
        cin >> a;
        broken[a] = 1;
    }
    vector<int> dp(n+2);
    const int mod = 1e9+7;
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--) {
        if (broken[i]) {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1]+dp[i+2]) % mod;
    }
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 1024
# returns the number of prime numbers less than or equal to n
def sieve(n):
    prime = [True] * (n+1)
    prime[0] = prime[1] = False
    count = 0
    for i in range(2, n+1):
        if prime[i]:
            count += 1
            for j in range(2*i, n+1, i):
                prime[j] = False
    return count


while True:
    try:
        n = int(input())
        print(sieve(n))
    except:
        break



Measured memory_bytes: 14320
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0520>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

ll rec(ll n,vector<ll>& p,vector<ll>& q,vector<ll>& r,vector<ll>& b){
    ll ret = 0;
    
    ll sumr = (r[n] == 0?1:rec(r[n],p,q,r,b));
    ll sumb = (b[n] == 0?1:rec(b[n],p,q,r,b));
    ll Tr = sumr*p[n];
    ll Tb = sumb*q[n];
    ll LCM = lcm(Tr,Tb);
    ret = sumr*(LCM/Tr) + sumb*(LCM/Tb);
    return ret;
}
ll solve(ll n){
    ll res = 0;
    vector<ll> p(n+1),q(n+1),r(n+1),b(n+1);
    for(int i = 1; i <= n;i++){
        cin >> p[i] >> q[i] >> r[i] >> b[i];
        ll GCD = gcd(p[i],q[i]);
        p[i] /= GCD;
        q[i] /= GCD;
    }
    vector<vector<ll>> G(n+1);
    for(int i = 1; i <= n;i++){
        if(r[i] != 0) G[r[i]].push_back(i);
        if(b[i] != 0) G[b[i]].push_back(i);
    }
    ll root = -1;
    for(int i = 1; i <= n;i++){
        if(G[i].empty()) root = i;
    }
    res = rec(root,p,q,r,b);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll n;
    while(cin >> n,n){
        cout << solve(n) << endl;
    }
    return 0;
}



Measured memory_bytes: 3140
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  string s,t;
  cin >> n >> s >> t;
  for(int i=0;i<n;i++) cout << s[i] << t[i];
  cout << endl;
  return 0;
}

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

using namespace std;


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

    string ans = "Yes";
    if(s == "AAA" || s == "BBB"){
        ans = "No";
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include "iostream"
#include "cstdio"
using namespace std;

int main(void)
{
    double a, b, c, d, e, f, x, y;

    while(cin >> a >> b >> c >> d >> e >> f) {
        y = (c*d - f*a) / (b*d - e*a);
        x = (c - b*y) / a;

        printf("%.3f %.3f\n", x, y);

    }
    
    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int n;
string s;

bool check(int len)
{
    map<string,int> m1;
    map<string,int> m2;
    for(int i=0;i+len-1<n;i++)
    {
        string aux;
        int k = len;
        int j = i;
        while(k--)
        {
            aux += s[j++];
        }
        m2[aux] = i;
        if(m1.count(aux)==false)
            m1[aux] = i;
        if(m1[aux] + len -1 < m2[aux])
        {
            // cout<<aux<<endl;
            return true;
        }
    }
    return false;
}

int main()
{
    si(n);
    cin>>s;
    int low = 1;
    int high = n/2;
    int ans = 0;
    while(low<=high)
    {
        int mid = (low+high)/2;
        if(check(mid)==true)
        {
            ans = mid;
            low = mid + 1;
        }
        else
            high = mid - 1;
    }
    pfi(ans);
    return 0;
}

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int q;
    cin >> q;
    vector<int> ans(q, 0);
    for(int ind=0; ind<q; ind++){
        string x, y;
        cin >> x >> y;
        // dp[i][j] は、x の i 文字目までの部分列のうち、y の j 文字目でちょうど終了するものの長さの最大
        // 最後には max_j dp[x.size()-1][j] を見れば ok
        vector<vector<int>> dp(x.size(), vector<int>(y.size(), 0));
        // i=0 だけ別処理
        for(int j=0; j<y.size(); j++){
            if(x[0] == y[j]) dp[0][j] = 1;
        }
        for(int i=1; i<x.size(); i++){
            int l = 0;
            for(int j=0; j<y.size(); j++){
                if(x[i] == y[j]){
                    dp[i][j] = max(dp[i-1][j], l+1);
                }
                else{
                    dp[i][j] = dp[i-1][j];
                }
                l = max(l, dp[i-1][j]);
            }
        }

        for(int j=0; j<y.size(); j++){
            ans[ind] = max(ans[ind], dp[x.size()-1][j]);
        }
    }

    for(int i=0; i<q; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6744
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main(){
  string s[3];
  for(int i = 0;i<3;i++){
    cin>>s[i];
  }
  int state = 0;
  int p[3];
  memset(p,0,sizeof(p));
  while(true){
    if(s[state].size() ==(p[state]))
      break;
    p[state]++;
    state = s[state][p[state]-1]-'a';
    // cout<<"s:"<<state<<endl;

  }
  string ans = "A";
  if(state == 1)
    ans = "B";
  else if(state == 2)
    ans = "C";
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
// 20:38
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  string a, b;
  cin >> a >> b;
  string work = a + b;
  int sum = stoi(work);
  int ans = sum;

  ans = sqrt(ans);
  if(ans*ans == sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int bu(int n,int a[],int b[],int c[])
{
   int dp[n+1][3];
   dp[1][0]=a[0];
   dp[1][1]=b[0];
   dp[1][2]=c[0];
   for(int i=2;i<=n;i++)
   {
       dp[i][0]=a[i-1]+max(dp[i-1][1],dp[i-1][2]);
       dp[i][1]=b[i-1]+max(dp[i-1][0],dp[i-1][2]);
       dp[i][2]=c[i-1]+max(dp[i-1][1],dp[i-1][0]);
   }
   return max(max(dp[n][0],dp[n][1]),dp[n][2]);

}
int main()
{
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<bu(n,a,b,c);
}


Measured memory_bytes: 5972
#include<stdio.h>
#include<string.h>

int main()
{
	char A[100];
	char B[100];
	int roop;
	int jubeat=0;
	
	scanf("%s", A);
	scanf("%s", B);

	int l_engthA = strlen(A);
	int l_engthB = strlen(B);
	
	if(l_engthA < l_engthB){
		jubeat--;
	}
	
	else if (l_engthA > l_engthB){
		jubeat++;
	}
	
	else{
		for(roop = 0; roop<l_engthA && jubeat==0 ; roop++){
			if(A[roop] < B[roop]){
				jubeat--;
			}
			else if (A[roop]>B[roop]){
				jubeat++;
			}
				
			}
	}
	
	if(jubeat>0)	printf("GREATER");
	else if(jubeat<0) printf("LESS");
	else printf("EQUAL");
	return 0;
}


Measured memory_bytes: 128
def count_same(first, last, digit):
    dig10 = 10**(digit-1)
    if n//dig10 > first:
        return dig10//10
    elif n//dig10 == first:
        return (n%dig10 - last) //10 + 1
    else:
        return 0

def count(first,last):
    count = 0
    if first == last and first <=n: count += 1
    if n <10:
        count += 0
    elif n < 100:
        if first*10+last <=n: count += 1
    elif n < 1000:
        count += 1 + count_same(first,last,3)
    elif n < 10000:
        count += 11 + count_same(first,last,4)
    elif n < 100000:
        count += 111 + count_same(first,last,5)
    else:
        count += 1111 + count_same(first,last,6)
    return count
    
n=int(input())
ans = 0
for i in range(1,10):
    for j in range(i,10):
        if i==j:
            ans += count(i,j)**2
        else:
            ans += count(i,j)*count(j,i) * 2
print(ans)

Measured memory_bytes: 3064
monster_num, attack_num = $stdin.gets.split(' ').map{|s| s.to_i}
monster_hp_list = $stdin.gets.split(' ').map{|s| s.to_i}

m_list = monster_hp_list.sort.reverse
attack_num.times do |i|
  m_list.shift
end

puts m_list.inject(0){|sum, h| sum += h}


Measured memory_bytes: 19312
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> v;
    for(int i=0;i<k&&a+i<=b;i++){
        v.push_back(a+i);
    }
    for(int i=k-1;i>=0&&a<=b-i;i--){
        v.push_back(b-i);
    }

    sort(v.begin(),v.end());
    auto uniq=std::unique(v.begin(),v.end());

    for(auto it=v.begin();it!=uniq;it++){
        cout << (*it) << endl;
    }
    return 0;
}



Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int N;
	int minu = 1001, maxi = -1;
	cin >> N;
	FOR(i, 0, N) {
		int a;
		cin >> a;
		minu = min(minu, a);
		maxi = max(maxi, a);
	}
	cout << maxi - minu << endl;
	return 0;
}

Measured memory_bytes: 256
data = input().split()
score = int(data[1])
tab = [score]*int(data[0])
n = int(data[2])
    
for i in range(n):
    value =int(input())
    tab[value - 1] += 1
    j =0
for i in tab:
    if (i > n):
        print ("Yes")
    else:
        print ("No")


Measured memory_bytes: 6596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, H, W; cin >> N >> H >> W;
	int res = 0;
	rep (i, N){
		int A, B; cin >> A >> B;
		res += (int)(A >= H && B >= W);
	} // end rep
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    vector<int> L(N);

    rep(i, N) cin >> L[i];

    sort(all(L));

    ll ans = 0;

    rep(i, N - 2) {
        repd(j, i + 1, N - 1) {
            /*
            auto position = lower_bound(all(L), (L[i] + L[j]));
            int index = distance(L.begin(), position);
            */
            int index = lower_bound(all(L), (L[i] + L[j])) - L.begin();
            ans += (index - j - 1);
        }
    }

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

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var hw = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var hor = string.Join("", Enumerable.Repeat("#", hw[1] + 2));
        var vert = "#";
        Console.WriteLine(hor);
        for (int i = 0; i < hw[0]; i++) Console.WriteLine(vert + Console.ReadLine() + vert);
        Console.WriteLine(hor);
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int n, m;
char s[15][15];
int cnt[15][26];
int mr[15], mc[15];

void prt() {
	// rep(i, n) printf("%d ", mr[i]);
	// puts("");
	// rep(i, m) printf("%d ", mc[i]);
	// puts("");
}

void c(int j, bool f = m & 1) {
	// printf("c(%d, %d)\n", j, f);
	if (j == m) prt(), exit(puts("YES") & 0);
	if (~mc[j]) return c(j + 1, f);
	if (f) {
		bool ok = 1;
		rep(i, n) ok &= s[mr[i]][j] == s[i][j];
		if (ok) mc[j] = j, c(j + 1, 0), mc[j] = -1;
	}
	rep(j0, m) if (j != j0 && !~mc[j0]) {
		bool ok = 1;
		rep(i, n) ok &= s[i][j] == s[mr[i]][j0];
		if (!ok) continue;
		mc[j] = j0; mc[j0] = j;
		c(j + 1, f);
		mc[j] = -1; mc[j0] = -1;
	}
}

void r(int i, bool f = n & 1) {
	// printf("r(%d, %d)\n", i, f);
	if (i == n) {memset(mc, -1, sizeof(mc)); return c(0);}
	if (~mr[i]) return r(i + 1, f);
	if (f) mr[i] = i, r(i + 1, 0), mr[i] = -1;
	rep(i0, n) if (i != i0 && !~mr[i0]) {
		bool ok = 1;
		rep(ch, 26) ok &= cnt[i][ch] == cnt[i0][ch];
		if (!ok) continue;
		mr[i] = i0; mr[i0] = i;
		r(i + 1, f);
		mr[i] = -1; mr[i0] = -1;
	}
}

int main() {
	scanf("%d %d", &n, &m);
	rep(i, n) scanf("%s", s[i]);
	rep(i, n) rep(j, m) cnt[i][s[i][j] - 'a'] ++;
	memset(mr, -1, sizeof(mr));
	r(0); puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

typedef tuple<ll, ll, ll, ll> T;
typedef pair<ll, ll> P;

const int INF = 1e6;

typedef int Weight;
typedef int Flow;

struct Edge {
	int src, dest, rev;
	Flow cap;
	Weight cost;
	bool operator < (const Edge &rhs) const {
		return cost > rhs.cost;
	}
	Edge(int s, int d) : src(s), dest(d) { ; }
	Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
	Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

//Veryfied AOJ 1163
typedef int Weight;
typedef int Flow;

void add_edge(Graph &g, int src, int dest, Flow cap) {
	g[src].push_back(Edge(src, dest, (int)g[dest].size(), cap, 0));
	g[dest].push_back(Edge(dest, src, (int)g[src].size() - 1, 0, 0));
}

Flow dfs(Graph &g, vector<bool> &used, int v, int t, Flow f) {
	if (v == t) return f;
	used[v] = true;
	for (Edge &e : g[v]) {
		if (!used[e.dest] && e.cap > 0) {
			Flow d = dfs(g, used, e.dest, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				g[e.dest][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

Flow ford_fulkerson(Graph &g, int s, int t) {
	Flow flow = 0;
	for (;;) {
		vector<bool> used(g.size(), false);
		Flow f = dfs(g, used, s, t, INF);
		if (f == 0) return flow;
		flow += f;
	}
}
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> area(H);
	for (int i = 0;i < H;i++)
		cin >> area[i];
	// in h+H*w  out H*W+h+H*w 
	// left:-H, right: +H, up: -1, down: 1
	const int sink = H * W * 2;
	const int tank = H * W * 2 + 1;
	Graph g(H * W * 2 + 2);
	int dx[] = {1,0,-1,0};
	int dy[] = {0,-1,0,1};
	for (int y = 0;y < H;y++)
		for (int x = 0;x < W;x++) {
			int in = y + H * x;
			int out = in + H * W;
			int cap;
			if (area[y][x] == '.')
				cap = 1;
			else {
				cap = INF;
				add_edge(g,sink,in,INF);
			}
			add_edge(g, in, out, cap); // in to out

			for (int i = 0;i < 4;i++) {
				int tx = x + dx[i];
				int ty = y + dy[i];
				int toin = ty + H * tx;
				int toout = toin + H * W;
				if (0 <= tx && tx < W && 0 <= ty && ty < H) {
					add_edge(g,out,toin,INF);
					add_edge(g, toout, in, INF);
				}
				else
					add_edge(g, out, tank, INF);
			}
		}
	int ans = ford_fulkerson(g, sink, tank);
	if (ans >= INF)
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7552
#include "bits/stdc++.h"
using namespace std;

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

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

    sort(A.begin(), A.end());
    vector<long long> leng = {0, 0};
    for (int i = 0; i < N;) {
        int res = 0;
        for (int k = 0; i + k < N; k++) {
            if (A[i] == A[i + k]) {
                res++;
            }
            else {
                break;
            }
        }
        if (res == 2 || res == 3) {
            leng.push_back(A[i]);
        }
        else if (res >= 4) {
            leng.push_back(A[i]);
            leng.push_back(A[i]);
        }
        i += res;
    }

    reverse(leng.begin(), leng.end());

    long long ans = leng[0] * leng[1];
    cout << ans << endl;
}

Measured memory_bytes: 1660
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, K;
ll A[1010];
ll B[1010];

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; ++i) cin >> A[i];
    B[0] = 0;
    for (int i = 1; i <= N; ++i) B[i] = A[i] + B[i-1];

    ll ans = 0;
    for (int b = 55; b >= 0; --b) {
        ans = ans | (1LL << b);

        int count = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = i+1; j <= N; ++j) {
                ll v = B[j] - B[i];
                if ((v & ans) == ans) { ++count; }
            }
        }

        if (count < K) ans = ans ^ (1LL << b);
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    string s;cin>>s;
    int n=s.size();
    int ans=n;
    rep(i,n-1)if(s[i]!=s[i+1])ans=min(ans,max(i+1,n-i-1));
    cout<<ans<<endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main(void){
  int n, T, now_time = 0, t; scanf("%d%d\n", &n, &T);
  lli res = T;
  REP(_, n){
    scanf("%d", &t);
    if(now_time + T >= t) res += t - now_time;
    else res += T;
    now_time = t;
  }
  printf("%lld\n", res);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5;

int main(){
	int n;
	cin>>n;
	lli a[MAX];
	rep(i,n)cin>>a[i];
	
	//初項正パターン
	lli pans=0;
	lli psum=0;
	rep(i,n){
		psum+=a[i];
		int f=i%2;
		//偶数番目なので正にしたいなー
		if(f==0){
			if(psum<=0){
				pans+=(1-psum);
				psum=1;
			}
		}
		//奇数番目なので負にしたいなー
		else {
			if(psum>=0){
				pans+=psum+1;
				psum=-1;
			}
		}
	}
	
	//初項負パターン
	lli nans=0;
	lli nsum=0;
	rep(i,n){
		nsum+=a[i];
		int f=i%2;
		//偶数番目なので負にしたいなー
		if(f==0){
			if(nsum>=0){
				nans+=nsum+1;
				nsum=-1;

			}
		}
		//奇数番目なので正にしたいなー
		else {
			if(nsum<=0){
				nans+=1-nsum;
				nsum=1;
			}
		}
	}
	cout<<min(pans,nans);
}

Measured memory_bytes: 1024
while line = gets do
	a, b = 0, 0							# 多項代入
	exit if line.to_i == 0	# 一行IF

	line.to_i.times do
		tmp_a, tmp_b = gets.split().map(&:to_i)

		if tmp_a > tmp_b
			a += tmp_a + tmp_b
		elsif tmp_a < tmp_b
			b += tmp_a + tmp_b
		else
			a += tmp_a
			b += tmp_b
		end
	end
	puts "#{a} #{b}"
end

Measured memory_bytes: 6112
a,b,c,x,y = map(int, input().split())
mina = min(a, 2*c)
minb = min(b, 2*c)
minab = min(a+b,2*c)

if x >= y:
	answer = (minab * y) + (mina * (x-y))
else:
	answer = (minab * x) + (minb * (y-x))
	
print(answer)


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

int main() {
  string s;
  cin >> s;
  
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def popcount(n):
    count = 0
    while n !=0:
        k = bin(n)[2:len(bin(n))].count("1")
        n = n%k
        count+=1
    return count


N = int(input())

X = list(map(int,list(input())))

c = X.count(1)

amari_c = 0#Xをcで割ったあまり
amari_c_dic = 0
amari_c_inc = 0

for i in range(0,N,1):
    if c > 0:
        amari_c = (amari_c + X[N-i-1]*pow(2,i,c))%c
    if c-1 > 0:
        amari_c_dic = (amari_c_dic + X[N-i-1]*pow(2,i,c-1))%(c-1)
    amari_c_inc = (amari_c_inc + X[N-i-1]*pow(2,i,c+1))%(c+1)

for i in range(0,N,1):
    if X[i]==0:#1にはんてんするので　
            tmp = (amari_c_inc + pow(2,N-i-1,c+1))%(c+1)
            print(1+popcount(tmp))

    elif X[i]==1:
        if c-1 >0:
            tmp = (amari_c_dic - pow(2,N-i-1,c-1))%(c-1)
            print(1+popcount(tmp))
        else:
            print(0)


Measured memory_bytes: 12024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
	      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	      String input[] = br.readLine().split(" ");
	      long a = Long.parseLong(input[0]);
	      long b = Long.parseLong(input[1]);
	      long c = Long.parseLong(input[2]);
	      if(c < a || c < b) {
	    	  System.out.println("No");
	    	  return;
	      }
	      long d = c - a - b;
	      
	      System.out.println((d > 0 && (d * d) > (4 * a * b))?"Yes":"No");
	}

}


Measured memory_bytes: 23248
#include<iostream>
#include<string.h>
#define rep(i,n) for(i = 0;i < n;i++)
#define MAX(a,b) (a>b?a:b)
using namespace std;

int N;
char stra[100000],strb[100000],*ans[10000];
int sum[10000][81];

int main(){
	int i,j;
	int a[80],b[80];
	cin >> N;
	rep(i,N){
		int la,lb;
		cin >> stra;
		cin >> strb;
		la = strlen(stra);
		lb = strlen(strb);
		if(la > 80 || lb > 80){
			ans[i] = "overflow";
			continue;
		}
		rep(j,80){
			a[j] = 0;b[j] = 0;
		}
		//小さい桁をインデックスの小さいほうに入れたい。
		for(j = la-1;j >= 0;j--)
			a[j] = stra[la-1-j]-48;
		for(j = lb-1;j >= 0;j--)
			b[j] = strb[lb-1-j]-48;
		//小さい桁から計算
		rep(j,MAX(la,lb)){
			sum[i][j] += a[j]+b[j];
			sum[i][j+1] += (sum[i][j])/10;
			sum[i][j] %= 10;
		}
		if(sum[i][80] > 0){
			ans[i] = "overflow";
			continue;
		}
		ans[i] = "j";
	}
	rep(i,N){
		if(*ans[i] == 'o'){
			cout << ans[i] << endl;
			continue;
		}
		for(j = 79;sum[i][j] == 0 && j>0;j--);
		for(;j>=0;j--)
			cout << sum[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct{
  char name[100];
  int time;
} PP;

PP Q[LEN];
int head,tail,n;

void enqueue(PP x);
PP dequeue();
int min(int a,int b);

int main(){
  int elaps=0,c;
  int i,q;
  PP z;

  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }

  head=1;
  tail =n+1;

  while(head!=tail){
    z=dequeue();
    c=min(q,z.time);
    z.time-=c;
    elaps+=c;
    if(z.time>0) enqueue(z);
    else printf("%s %d\n",z.name,elaps);
  }
  return 0;
}

void enqueue(PP x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

PP dequeue(){
  PP x;
  x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int a,int b){
  int min;
  if(a<b) min=a;
  else if(b<a) min=b;
  return min;
}


Measured memory_bytes: 11852
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
    int N,L;
    cin>>N>>L;
    string S[N];
    for(int i=0;i<N;i++)cin>>S[i];

    sort(S,S+N);
    for(int i=0;i<N;i++)cout<<S[i];
    cout<<endl;
}

Measured memory_bytes: 256
import math
import heapq
from bisect import bisect_right, bisect_left
from collections import defaultdict, Counter
import itertools
import sys
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7
INF = float("inf")


def main():
    S = list(input())
    flg = True
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == "R" or S[i] == "U" or S[i] == "D":
                pass
            else:
                print("No")
                exit()
        else:
            if S[i] == "L" or S[i] == "U" or S[i] == "D":
                pass
            else:
                print("No")
                exit()
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

typedef long long ll;

ll F(ll a, ll b)
{
    if( b % a == 0 ) return 2 * b - a;

    return 2 * a * ( b / a ) + F(b % a, a);
}

int main()
{
    ll n, x;
    cin >> n >> x;
    ll a = x, b = n - x;
    if(a > b)swap(a, b);
    cout << n + F(a, b) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll ans = 0,k,x,y,z;
int main()
{
    cin>>k;
    for (x=1; x<=k; x++)
        for (y=1; y<=k; y++)
            for (z=1; z<=k; z++)
                ans+=__gcd(x,__gcd(y,z));
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int linersearch(int [],int ,int );

int main(){
  int i,n,s[100000],q,t,count=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&t);
    if( linersearch(s,n,t) ) count++;
  }
  printf("%d\n",count);
  
  return 0;
}

int linersearch(int a[],int n,int key){
  int i=0;

  a[n]=key;
  
  while(a[i]!=key){
    i++;
  }
    return i!=n;
}
 



Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=2e5+10;
int a[N];
ll vis[N],ans;
int n;
ll cal(ll x)
{
    return x*(x-1)/2;
}
int main()
{
	cin>>n;
	rep(i,1,n)
	{
	    scanf("%d",&a[i]);
	    ans+=vis[a[i]];
	    vis[a[i]]++;
	}
	//printf("ans:%lld\n",ans);
	for(int k=1;k<=n;++k){
        ll t=ans;
        t-=cal(vis[a[k]]);
        vis[a[k]]--;
        t+=cal(vis[a[k]]);
        vis[a[k]]++;
        printf("%lld\n",t);
	}

}


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

int P(int p)
{
  int i;
    
  if(p < 2) return 0;
  
  if(p == 2) return 1;
  
  else if(p % 2 == 0) return 0;
  
  for(i = 3; i <= sqrt(p); i+=2){
    
    if(p % i == 0) return 0;
    
  }
  return 1;
}

int main()
{
  int n,a,c = 0;
  
  scanf("%d",&n);
  
  for(int i = 0; i < n; i++){
    
    scanf("%d",&a);
    
    if(P(a) == 1) c++;
    
  }
  
  printf("%d\n",c);
  
  return 0;
}






Measured memory_bytes: 2080
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    S = ins()
    a = int(S[:2])
    b = int(S[2:])
    am = 0 < a < 13
    bm = 0 < b < 13
    if am and bm:
        return "AMBIGUOUS"
    elif am:
        return "MMYY"
    elif bm:
        return "YYMM"
    else:
        return "NA"


print(solve())


Measured memory_bytes: 8988
import copy
X = input()
X = int(X)
A = copy.deepcopy(X)

i = 2

if 360 % X == 0:
    K = 360 / X
    K = int(K)
    print(K)
else:
    while True:
        X = copy.deepcopy(A)
        X *= i
        if X % 360 == 0:
            break
        i = i+1

    print(i)


Measured memory_bytes: 9336
N=int(input())
S=input()
cond=0
#print(S[0:3])

if N%2==0:
#  print(S[0:N//2],S[N//2:N])
  if S[0:N//2]==S[N//2:N]:
   print('Yes')
  else:
   print('No')
    
else:
  print('No')

      

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    long long M = 0, A = 0, R = 0, C = 0, H = 0;
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        if(S.at(0)=='M') M++;
        if(S.at(0)=='A') A++;
        if(S.at(0)=='R') R++;
        if(S.at(0)=='C') C++;
        if(S.at(0)=='H') H++;
    }
    
    cout << M*A*R + M*A*C + M*A*H + M*R*C+ M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H << endl;
   
}


Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int main()
{
  ll N, M;
  cin >> N >> M;
  vector<P> v;
  REP(i, N) {
    ll A, B;
    cin >> A >> B;
    v.PB(MP(A, B));
  }
  sort(ALL(v));

  ll ans = 0;
  REP(i, N) {
    if (v[i].SE < M) {
      ans += v[i].FI * v[i].SE;
      M -= v[i].SE;
    } else {
      ans += v[i].FI * M;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2420
n,m=map(int,input().split())
if n%4==0:
  l=m//2+1
else:
  l=m//2
if n%2==0:
  for i in range(l):
    print(i+1,n-i)

  for i in range(m-l):
    print(i+1+l,n-i-l-1)
else:
  for i in range(m):
    print(i+1,n-i)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
#define inf 1e15

int main(){
  
  long long n,tot,ans=0;
  cin>>n>>tot;
  vector<long long>dp(1e5+5,inf);
  dp[0]=0;
  for(int i=1;i<=n;i++){
    long long i1,i2;
    cin>>i1>>i2;
    for(int j=1e5;j>=0;j--){
      dp[j]=(j<i2)?dp[j]:min(dp[j],dp[j-i2]+i1);
    }
  }
  
 for(int i=0;i<=1e5;i++){
    if(dp[i]<=tot)
      ans=max(ans,1LL*i);
 }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int D;

ll eval(vector<int> last, int today, int contest, vector<vector<int>> s, vector<int> c)
{
	ll ret = s[today][contest];
	ret += c[contest]*(today+1-last[contest]);
	return ret;
}

vector<int> greedy_method(vector<vector<int>> s, vector<int> c)
{
	vector<int> last(26, 0);
	vector<int> ts(D);
	for(int i=0; i<D; i++){
		int sel=-1;
		ll evalmax = -INF;
		for(int t=0; t<26; t++){
			ll tmp = eval(last, i, t, s, c);
			if(tmp>evalmax){
				evalmax = tmp;
				sel = t;
			}
		}
		last[sel] = i+1;
		ts[i] = sel+1;
	}
	return ts;
}

signed main()
{
	cin >> D;
	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	vector<int> t(D);
	REP(i, 26){
		cin >> c[i];
	}
	REP(i, D){
		REP(k, 26){
			cin >> s[i][k];
		}
	}
	t = greedy_method(s, c);
	REP(i, D){
		cout << t[i] << endl;
	}
}


Measured memory_bytes: 3780
package main

import "fmt"

type dice struct {
	a [7]int
}

func (d *dice) init(a [6]int) {
	for i := range a {
		d.a[i+1] = a[i]
	}
}

func (d *dice) north() {
	d.a[1], d.a[2], d.a[5], d.a[6] = d.a[2], d.a[6], d.a[1], d.a[5]
}

func (d *dice) east() {
	d.a[1], d.a[4], d.a[6], d.a[3] = d.a[4], d.a[6], d.a[3], d.a[1]
}

func (d *dice) spin() {
	d.a[4], d.a[2], d.a[3], d.a[5] = d.a[2], d.a[3], d.a[5], d.a[4]
}

func (d *dice) eq(other *dice) bool {
	for i := range d.a {
		if d.a[i] != other.a[i] {
			return false
		}
	}
	return true
}

func (d *dice) rotate(other *dice) bool {
	for i := 0; i < 2; i++ {
		for j := 0; j < 4; j++ {
			for k := 0; k < 4; k++ {
				if d.eq(other) {
					return true
				}
				d.spin()
			}
			d.north()
		}
		d.east()
	}
	return false
}

func main() {
	var dices [100]dice

	var n int
	fmt.Scan(&n)
	var a [6]int
	for i := 0; i < n; i++ {
		for j := 0; j < 6; j++ {
			fmt.Scan(&a[j])
		}
		dices[i].init(a)
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if dices[i].rotate(&dices[j]) {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}



Measured memory_bytes: 1212
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    if(A%3==0||B%3==0) cout<<"Possible";
    else if((A+B)%3==0) cout<<"Possible";
    else cout<<"Impossible";
    return 0;
}


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

int main(){
  int N,count=0,a=0,b=0,ba=0;
  cin >> N;
  vector<string> S(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i);
    if(S.at(i).at(0)=='B'&&S.at(i).at(S.at(i).size()-1)=='A'){
      ba++;
    }
    else if(S.at(i).at(0)=='B'){
      b++;
    }
    else if(S.at(i).at(S.at(i).size()-1)=='A'){
      a++;
    }
    for(int j=0; j<S.at(i).size()-1; j++){
      if(S.at(i).at(j)=='A'&&S.at(i).at(j+1)=='B'){
        count++;
      }
    }
  }
  if(a==0&&b==0&&ba!=0){
    cout << count+min(a+ba,b+ba)-1 << endl;
  }
  else{
    cout << count+min(a+ba,b+ba) << endl;
  }
}

Measured memory_bytes: 768
s=input()
n = len(s)

ss =s[::-1]

sss =s[1:((n-1)//2)-1]
mmm = sss[::-1]

ssss = s[((n+3)//2)-1:n]
mmmm = ssss[::-1]


if s == ss and sss == mmm and ssss == mmmm:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int main()
{
        FastIO

        ll k,i,x;
        cin>>k;

        deque<long long> q;
        for(i=1;i<=9;i++)
        {
        	q.push_back(i);
        }
        for(i=1;i<=k;i++)
        {
        	x=q.front();
        	q.pop_front();
        	if(x%10!=0)
        		q.push_back(10*x + x%10- 1 );
        	
        		q.push_back(10*x + x%10);
        	if(x%10!=9)
        		q.push_back(10*x+ x%10+1);
        	

        }

        cout<<x<<"\n";
        return 0;
    }




Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e8;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=100005;

ldb dp[301][301][301];int n;

ldb solve(int i,int j,int k)
{
 if(i==0&&j==0&&k==0)
 return dp[i][j][k]=0;

if(dp[i][j][k]!= -1)
return dp[i][j][k];

dp[i][j][k]=1;
if(i)
{
    dp[i][j][k]+=((ldb)i/n)*solve(i-1,j,k);
}
if(j)
{
    dp[i][j][k]+=((ldb)j/n)*solve(i+1,j-1,k);
}
if(k)
{
    dp[i][j][k]+=((ldb)k/n)*solve(i,j+1,k-1);
}
dp[i][j][k]*=n;
dp[i][j][k]/=(i+j+k);
return dp[i][j][k];



}





void solve()
{

for(int i=0;i<=300;i++)
for(int j=0;j<=300;j++)
for(int k=0;k<=300;k++)
dp[i][j][k] = -1;
cin>>n;
int cnt[4]={0};
int x;
for(int i=0;i<n;i++)
{
    cin>>x;
    cnt[x]++;
}
cout<<setprecision(15);
cout<<solve(cnt[1],cnt[2],cnt[3])<<endl;
//cout<<dp[1][0][0]<<" "<<dp[2][0][0]<<endl;








}

int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}

Measured memory_bytes: 430748
#include <bits/stdc++.h>
int main() {
  	int n, a = 0, b = 0, c = 0, d = 0; std::cin >> n;
	std::map<std::string, int> cnt;
	std::string str;
	while (n--) {
		std::cin >> str;
		if (str == "AC") a++;
		if (str == "WA") b++;
		if (str == "TLE") c++;
		if (str == "RE") d++;
	}
	std::cout << "AC x " << a << std::endl <<
		"WA x " << b << std::endl <<
		"TLE x " << c << std::endl <<
	   	"RE x " << d << std::endl;
}

Measured memory_bytes: 3624