akhauriyash/Code-Regression huggingface dataset:
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 200005
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> N >> M;
    fi(i, 0, N, 1) {
    	cin >> arr[i] >> arr1[i];
    }
    fi(i, 0, N, 1) {
    	V.push_back(arr[i] * arr[i] + arr1[i] * arr1[i]);
    }
    sort(all(V));
    ll ind = -1;
    fi(i, 0, V.size(), 1) {
    	if(V[i] <= M * M) {
    		ind = i;
    	}
    }
    cout << ind + 1 << "\n";
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

int main () {
  vector<char> line(6) ;
  
  for ( int i = 0 ; i < 6 ; i++ ) {
    cin >> line.at(i) ;
  }
  
  if ( line.at(0) == line.at(5) && line.at(1) == line.at(4) && line.at(2) == line.at(3) ) {
    cout << "YES" << endl ;
  } else {
    cout << "NO" << endl ;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D) {
		cout << "Left" << endl;
	} else if (A + B == C + D) {
		cout << "Balanced" << endl;
	} else {
		cout << "Right" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

// += すれば-vを考える必要がない


int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int n, m;
    cin >> n >> m;

    int a[n][m];
    int b[m];
    
    REP(i, n)
    {
        REP(j, m)
        {
            cin >> a[i][j];
        }
    }
    REP(j, m)
    {
        cin >> b[j];
    }

    REP(i,n)
    {
        int sum = 0;
        REP(j,m)
        {
            sum += a[i][j] * b[j];
        }

        cout << sum << endl;
    }

    //cout << endl;

    return 0;    
}




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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b; cin>>a>>b;
  rep(i,b+1){
    if(a*(i+1)%b==0){
      cout<<a*(i+1)<<endl;
      break;
    }
  }  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=1005;
//i_am_noob
int a,b,h,m;
ld x,y;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> a >> b >> h >> m;
	cout << fixed << setprecision(12);
	x=(ld)(h*60+m)/2.0;
	y=m*6;
	x=abs(x-y);
	print1(sqrt(a*a+b*b-2*a*b*cos(x/180*3.1415926535897932)));
	return 0;
}

Measured memory_bytes: 4168
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <climits>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
//const int mod=1e9+7;
//const ll inf = (ll)1e16 + 7;
//const int N=1e5+7;

int main(){
    fast;
    const int inf = 100000000;
    int n,m;
    cin>>n>>m;
    int a[1000],b[1000],c[1000],dist[100][100];
    
    for(int i=0;i<m;i++){
        cin >> a[i] >>b[i]>>c[i];
        a[i]--,b[i]--;
    }
    for(int i=0;i<n;i++){
        for(int j = 0;j<n; ++j){
        if(i==j)
            dist[i][j]=0;
        else
            dist[i][j]=inf;
        }
    }
    for(int i=0;i<m;++i){
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
    }
    for(int k=0;k<n;++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    int ans=m;
    for(int i=0;i<m;++i){
        bool shortest=false;
        for(int j = 0; j < n; ++j) if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
        if(shortest==true) ans=ans-1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    }

    public static final long lcm(final long a, final long b) {
        return a * b / gcd(a, b);
    }

    public static final long gcd(long a, long b) {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
}

Measured memory_bytes: 35476
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
  while True:
    n = int(input())
    if(n == 0):
      break
    w = list(map(int, input().split()))
    dp = [[0] * (n+1) for _ in range(n+2)]
    for gap in range(2,n+1):
      for l in range(n-gap+1):
        r = l+gap
        if(dp[l+1][r-1] == gap-2):
          if(abs(w[l]-w[r-1]) <= 1):
            dp[l][r] = gap
            continue
        for k in range(l, r):
          if(dp[l][r] < dp[l][k]+dp[k][r]):
            dp[l][r] = dp[l][k]+dp[k][r]
    print(dp[0][n])
    
if __name__ == '__main__':
  main()


Measured memory_bytes: 7124
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, q;

void p(int & a) { a = (a - 1) / n; }

int d(int a) {
	int c = 0;
	while(a != 0) { p(a); c++; }
	return c;
}

int main() {
	cin >> n >> q;
	inc(qq, q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		
		if(n == 1) {
			cout << min(a, b) + 1 << "\n";
		} else {
			int aa = d(a);
			int bb = d(b);
			int c = abs(aa - bb);
			if(aa > bb) { inc(i, c) { p(a); } }
			if(bb > aa) { inc(i, c) { p(b); } }
			while(a != b) { p(a); p(b); }
			cout << a + 1 << "\n";
		}
	}
	
	return 0;
}


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

string S;
int main(){
    cin >> S;
    bool ok1 = false,ok2 = false;
    if(S.substr(0,2)>="13" || S.substr(0,2)=="00") ok1 = true;
    if(S.substr(2,2)>="13" || S.substr(2,2)=="00") ok2 = true;
    if(ok1 && ok2) cout << "NA" << endl;
    else if(ok1 && !ok2) cout << "YYMM" << endl;
    else if(!ok1 && ok2) cout << "MMYY" << endl;
    else cout << "AMBIGUOUS" << endl;    
}

Measured memory_bytes: 256
// ABC140B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector> //配列を使う
using namespace std;
int main()
{
	int N;
	cin >> N; // 料理の種類 2~20
	vector<int> A(N+1);
	for (int i = 1; i <= N; i++) // 食べた料理の番号
	{
		cin >> A.at(i);
	}
	vector<int>B(N+1);
	for (int j = 1; j <= N; j++) // 料理の満足度
	{
		cin >> B.at(j);
	}
	vector<int>C(N);
	for (int k = 1; k <= N-1; k++) // C.at(i-1)は、A.at(i)=A.at(i-1)+1の時に追加する満足度
	{
		cin >> C.at(k);
	}
	int happiness = 0;

	for (int m = 1; m <= N; m++)
	{
		happiness += B.at(A.at(m));
		if (m>1&&A.at(m)==A.at(m-1)+1)
		{
			happiness += C.at(A.at(m - 1));
		}
	}
	cout << happiness << endl;
}


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

int	main(void)
{
	int n , k;
	int count = 0;
  
  	cin >> n >> k;
	vector<int> judge(n, 0);

	for (int i = 0; i < k; i++)
	{
		int people;
		cin >> people;

		for (int j = 0; j < people; j++)
		{
			int num;
			cin >> num;
			judge[num - 1] += 1;
        }
	}
	//配列の中身が０の数を数える（お菓子もらえていない人）
	for (int l = 0; l < n; l++)
	{
		if (judge[l] == 0)
			count++;
	}

	cout << count << endl;

	return (0);
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String word = sc.next();
        String s[] = word.split("");
        int ret = word.length() / 2;
        String front = "",back = "";

      
        StringBuffer str = new StringBuffer(word);
        String reverse = str.reverse().toString();
        if(!word.equals(reverse)){
          System.out.println("No");
          return;
        }
              
        for(int i = 0;i < ret;i++){
          front += s[i];
        }
		str = new StringBuffer(front);
        reverse = str.reverse().toString();      
        if(!front.equals(reverse)){
          System.out.println("No");
          return;
        }        
      
        for(int i = ret + 1;i < word.length();i++){
          back += s[i];
        }
		str = new StringBuffer(back);
        reverse = str.reverse().toString();      
        if(!back.equals(reverse)){
          System.out.println("No");
          return;
        }       
        
        System.out.println("Yes");
    }
}

Measured memory_bytes: 39372
#include <bits/stdc++.h>
    #define ll long long
    #define sz(a) int((a).size())
    #define fr(i,n) for(int i=0;i<n;i++) 
    #define rf(i,n) for(int i=1;i<=n;i++)
    #define jdb(i,v) for(__typeof(v.begin())i=v.begin(); i!=v.end();i++)
    #define present(c,a) (find(all(c),a) != c.end())
    #define spresent(c,a) (c.find(a)!=c.end())
    #define no(s,c) s.count(c)  
    #define pb push_back 
    #define eb emplace_back
    #define mp make_pair
    #define all(c) (c).begin(),(c).end()
    #define MAX INT_MAX 
    using namespace std;
    #define f first
    #define s second         
    int main() 
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n;
        cin>>n;
        double j=0,b=0;
        fr(i,n)
        {
            double a;
            cin>>a;
            string s;
            cin>>s;
            if(s == "JPY")
                j+=a;
            else
                b+=a;
        }
        cout<<fixed;
        cout<<setprecision(10)<< j+b*380000.0<<endl;
        return 0;
    }
       

Measured memory_bytes: 256
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = LI()
h = LI()
dp = [float('INF')]*N
dp[0] = 0
for i,j in itertools.product(range(1,N),range(1,K+1)):
    if i-j>=0:
        dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])


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


int main() {

  int A,B,M;
  cin>>A>>B>>M;

  vector<int> Ai(A);
  vector<int> Bi(B);
  for(int i=0;i<A;i++){
    cin>>Ai.at(i);
  }
  for(int i=0;i<B;i++){
    cin>>Bi.at(i);
  }
  
  vector<int> Xi(M);
  vector<int> Yi(M);
  vector<int> Ci(M);
  for(int i=0;i<M;i++){
    cin>>Xi.at(i)>>Yi.at(i)>>Ci.at(i);
  }
  
  /*割引券を使った最小値*/
  int minwk=500000;
  for(int i=0;i<M;i++){
    minwk=min(minwk,Ai.at(Xi.at(i)-1)+Bi.at(Yi.at(i)-1)-Ci.at(i));
  }
  /*割引券を使わない最小値*/
  sort(Ai.begin(),Ai.end());
  sort(Bi.begin(),Bi.end());
  minwk=min(minwk,Ai.at(0)+Bi.at(0));
  
  
  cout<<minwk;
  
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
int main(){
  long a,b,c,d;
  cin >> a >> b >> c >> d;

  long M = LONG_MIN;
  M = max(M, a * c);
  M = max(M, b * c);
  M = max(M, a * d);
  M = max(M, b * d);
  cout << M << "\n";
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
 int n; scanf("%d",&n); 
 int A[n];
 for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
 printf("%d\n",A[0]);     
    

return 0;
}



Measured memory_bytes: 2124
n = int(input(""))
a1 = input("").split(" ")
a2 = input("").split(" ")
sum = [0]*n
for i in range(n):
    for j in range(n):
        if j <= i:
            sum[i] += int(a1[j])
        if j >= i:
            sum[i] += int(a2[j])
print(max(sum))

Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc060/tasks/abc060_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    bool flag = false;
    FOR(i, 1, 101) {
        if ((a * i) % b == c) {
            flag = true;
            break;
        }
    }
    cout << (flag ? "YES\n" : "NO\n");
    return 0;
}


Measured memory_bytes: 256
def b j,k,l
k.any?{m,*n=k.rotate!
o=m.index j[l].swapcase
o&&([*0..5]-[o,5-o]).any?{|p|yield m,n,o,p}}end
def e a,b
a==b.swapcase
end
y=(0..5).map{[]}
(a=[*1..4,2,4,1,3]).zip(a.rotate(4),[0]*4+[5]*4).map{|b|b.map{i,j,k=b=b.rotate;y[i][j]=k}}
while gets[0]>?0
z=$<.take(7)<<$_
puts z.any?{a,*zz=z.rotate!
(0..5).any?{|c|b(a,zz,c){|d,o,f,i|b(d,o,i){|g,o,tt,j|b(g,o,j){|p,o,r,k|([*0..5]-[c,5-c]).any?{|l|e(p[k],a[l])&&b(a,o,y[l][c]){|s,o,u,m|b(s,o,m){|v,o,x,n|e(d[y[f][i]],v[n])&&b(v,o,y[x][n]){|h,o,cc,q|e(h[q],g[y[tt][j]])&&b(h,o,y[cc][q]){|w,_,o,t|e(w[t],p[y[r][k]])&&e(w[y[o][t]],s[y[u][m]])}}}}}}}}}}?:YES:"NO"end

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

/*
g++ -std=c++11 i-coins.cpp -o k
*/
int main() {
    int i, j, N;
    cin >> N;
    double p[N];
    // m[coins i][heads j]
    double m[N+1][N+1];
    for(i = 0; i < N; i++) {
        m[0][i] = 0.0;
        cin >> p[i];
    }
    m[0][0] = 1.0;
    m[0][N] = 0.0;
    for(i = 1; i <= N; i++) {
        // coin i is indexed i-1 in p
        m[i][0] = m[i-1][0]*(1.0-p[i-1]);
        //cout << m[i][0] << " ";
        for(j = 1; j <= N; j++) {
            // j heads
            m[i][j] = m[i-1][j-1]*p[i-1] + m[i-1][j]*(1.0-p[i-1]);
            //cout << m[i][j] << " ";
        }
        //cout << endl;
    }
    double o = 0.0;
    for(i = N; i > N/2; i--) {
        o += m[N][i];
    }
    cout.precision(numeric_limits<double>::max_digits10);
    cout << o << endl;

    return 0;
}


Measured memory_bytes: 70528
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);
  int cnt=1, s;
  foreach (i; 1..n) {
    if (s == 1) {
      if (a[i-1] > a[i]) {
        cnt++;
        s = 0;
      }
    } else if (s == -1) {
      if (a[i-1] < a[i]) {
        cnt++;
        s = 0;
      }
    } else {
      if (a[i - 1] < a[i]) {
        s = 1;
      } else if (a[i-1] > a[i]) {
        s = -1;
      }
    }
  }
  cnt.writeln;
}


Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, l, r;
  cin >> n;
  int ans = 0;
  rep(i, 0, n) {
    cin >> l >> r;
    ans += r-l +1;
  }
  
  cout << ans << "\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <string>

#define N 26
using namespace std;

main(){
  int n;
  string data[150];
  string tmp[150];
  cin >> n;
  for(int i=0;i<n;i++){
    int size;
    for(size=0;;size++){
      cin >> data[size];
      char c;
      scanf("%c", &c);
      if(c=='\n'){
	break;
      }
    }
    size++;
    for(int i=3;i<N;i+=2){
      if(i%13==0) continue;
      for(int j=0;j<N;j++){
	for(int k=0;k<size;k++){
	  tmp[k]="";
	}
	for(int a=0, b=0;a<size;b++){
	  if(data[a].size()<=b){
	    a++;
	    b=-1;
	    continue;
	  }
	  char c=(char)((i*(int)(data[a][b]-'a')+j)%26);
	  c+='a';
	  tmp[a]+=c;
	}
	for(int k=0;k<size;k++){
	  if(tmp[k]=="that" || tmp[k]=="this"){
	    for(int l=0;l<size;l++){
	      cout << tmp[l];
	      if(l==size-1) cout << endl;
	      else cout << ' ';
	    }
	  }
	}
      }
    }
  }
  return 0;
}


    

Measured memory_bytes: 0
use std::io;
use std::str::FromStr;

fn main(){
    let mut buf = String::new();
    let _ = io::stdin().read_line(&mut buf);

    let mut num : Vec<i64> = buf.split_whitespace().map(|x| i64::from_str(x).unwrap()).collect();
    num.sort();

    let arr : Vec<String> = num.iter().map(|x| x.to_string()).collect();
    println!("{}", arr.join(" "));
}



Measured memory_bytes: 5036
#include<iostream>
using namespace std;
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//#define READ freopen("in.txt","r",stdin)
//#define WRITE() freopen("out.txt","w",stdout);
//#define pb push_back
//#define mem(arr,val) memset(arr,val,sizeof(arr))
//#define sf(x) scanf("%d",&x)
//#define sf2(x,y) scanf("%d %d",&x,&y)
//#define sl(x) scanf("%lld",&x)
//#define sl2(x,y) scanf("%lld %lld",&x,&y)
//#define pii pair<int,int>
//#define sl2(x,y) scanf("%lld %lld",&x,&y)
//#define ff first
//#define sd second
typedef long long ll;
//typedef long long lld;
//const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};

//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
int main()
{
    int a,b;
//    sf2(a,b);
    cin>>a>>b;
    if(a==b)
        cout<<"Draw"<<endl;
    else if(a==1)
        cout<<"Alice"<<endl;
    else if(b==1)
        cout<<"Bob"<<endl;
    else if(a>b)
        cout<<"Alice"<<endl;
    else if(a<b)
        cout<<"Bob"<<endl;
    else
    cout<<"Draw"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef deque<bool> db;
template <class T>
using vv = vector<vector<T>>;

struct UnionFind
{
  vector<int> par;
  vector<int> sizes;
  int N;

  UnionFind(int n) : par(n), sizes(n, 1)
  {
    for (int i = 0; i < n; i++)
      par[i] = i;
    N = n;
  }

  int find(int x)
  {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
      return;

    if (sizes[x] < sizes[y])
    {
      par[x] = y;
      sizes[y] += sizes[x];
    }
    else
    {
      par[y] = x;
      sizes[x] += sizes[y];
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return sizes[find(x)]; }
};

int main()
{
  int n, m;
  cin >> n >> m;

  vi p(n);

  rep(i, n)
  {
    cin >> p[i];
    p[i]--;
  }

  UnionFind uf(n);

  rep(i, m)
  {
    int x, y;
    cin >> x >> y;
    uf.unite(x - 1, y - 1);
  }

  int count = 0;

  rep(i, n)
  {
    if (uf.same(p[i], i))
      count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
from operator import itemgetter
from heapq import heappop, heappush
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7

N = int(input())
A = inpl()
ans = 0
x = 1
for a in A:
    if x == a:
        x += 1
    else:
        ans += 1
if (ans == N):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 26780
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 200003;
int n, a[N], b[N];
inline bool check(int x){
	for(Rint i = 1;i < (n << 1);i ++) b[i] = (a[i] >= x);
	for(Rint i = 0;i < n - 1;i ++){
		if(b[n + i] == b[n + i + 1]) return b[n + i];
		if(b[n - i] == b[n - i - 1]) return b[n - i];
	}
	return b[1];
}
int main(){
	scanf("%d", &n);
	for(Rint i = 1;i < (n << 1);i ++) scanf("%d", a + i);
	int l = 1, r = 2 * n - 1, mid, ans = 0;
	while(l <= r){
		mid = l + r >> 1;
		if(check(mid)) l = mid + 1, ans = mid;
		else r = mid - 1;
	}
	printf("%d", ans);
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;

using P = pair<int, int>;
const ll INF = 4e18;
int n;
V<P> a;
ll amin, amax;

ll solve1() {
    ll bmin = INF, bmax = 0;
    for (auto &p : a) {
        bmin = min<ll>(bmin, p.second);
        bmax = max<ll>(bmax, p.first);
    }
    return (amax-bmin)*(bmax-amin);
}

ll solve2() {
    set<P> st;
    for (int i = 0; i < n; i++) {
        st.emplace(a[i].first, i);
    }
    int last = -1;
    ll ans = INF;
    while (true) {
        int id, v; tie(v, id) = *st.begin();
        st.erase(st.begin());
        ans = min<ll>(ans, st.rbegin()->first-v);
        if (id == last) break;
        st.emplace(a[id].second, id);
        last = id;
    }
    return ans*(amax-amin);
}

int main() {
    scanf("%d", &n);
    amin = INF; amax = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x > y) swap(x, y);
        a.emplace_back(x, y);
        amin = min<ll>(amin, x);
        amax = max<ll>(amax, y);
    }

    ll ans = min(solve1(), solve2());
    printf("%lld\n", ans);
    return 0;
}

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

const int N = 500 + 10;

int a[N][N], h[N][N], n;

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

void dfs(int x, int y) {
    int cost = h[x][y] + a[x][y];
    for (int k = 0; k < 4; k++) {
        int tx = x + dx[k], ty = y + dy[k];
        if (h[tx][ty] > cost) {
            h[tx][ty] = cost;
            dfs(tx, ty);
        }
    }
}

int main() {
    scanf("%d", &n);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            h[i][j] = min(min(i - 1, n - i), min(j - 1, n - j));
            a[i][j] = 1;
        }
    }
    for (int i = 1; i <= n * n; i++) {
        int pos;  scanf("%d", &pos);
        int row = (pos - 1) / n + 1, col = (pos - 1) % n + 1;
        ans += h[row][col];
        a[row][col] = 0;
        dfs(row, col);
    }
    printf("%d\n", ans);
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

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

int main()
{
  string str;
  int n;
  long long head[5] = {};
  long long ans = 0;

  cin >> n;
  for ( int i = 0; i < n; i++) {
    cin >> str;
    if ( str[0] == 'M' ){
      head[0]++;
    } else if ( str[0] == 'A' ) {
      head[1]++;
    } else if ( str[0] == 'R' ) {
      head[2]++;
    } else if ( str[0] == 'C' ) {
      head[3]++;
    } else if ( str[0] == 'H' ) {
      head[4]++;
    }
  }

  for ( int i = 0; i < 5; i++ ) {
    for ( int j = i + 1; j < 5; j++) {
      long long temp = 1;
      for ( int k = 0; k < 5; k++) {
        if ( k != i && k != j ) {
          temp *= head[k];
        }
      }

      ans += temp;
    }
  }

  cout << ans << endl;

  return (0);
}

Measured memory_bytes: 384
s = input()
odd = [s[i] for i in range(len(s)) if (i+1) % 2 == 1]
even = [s[i] for i in range(len(s)) if (i+1) % 2 == 0]
if "L" in odd or "R" in even:
    print("No")
else:
    print("Yes")

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

int main() {
  int n, m;
  cin >> n >> m;
  int coun = 0;
  coun = n * (n - 1) + m * (m - 1);
  coun /= 2;
  cout << coun << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(b-a>k || c-a>k||d-a>k||e-a>k||c-b>k||d-b>k||e-b>k||d-c>k||e-c>k||e-d>k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int N; cin >> N;
	vector<ll> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	if(N == 2) {
		cout << abs(A[0] + A[1]) << endl;
		return 0;
	}
	int plus = 0, minus = 0, zero = 0;
	for(int i = 0; i < N; i++) {
		if(A[i] > 0) plus++;
		else if(A[i] == 0) zero++;
		else minus++;
	}
	sort(A.begin(), A.end());
	ll ans = 0;
	if(minus % 2 == 0) for(int i = 0; i < N; i++) ans += abs(A[i]);
	else if(minus == N) {
		for(int i = 0; i < N - 1; i++) ans += abs(A[i]);
		ans += A[N - 1];
	} 
	else {
		if(zero > 0) for(int i = 0; i < N; i++) ans += abs(A[i]);
		else {
			for(int i = 0; i < N; i++) {
				if(i < minus - 1) ans += abs(A[i]);
				else if(i == minus - 1) {
					if(abs(A[i]) > abs(A[i + 1])) ans += abs(A[i]) - abs(A[i + 1]);
					else ans += abs(A[i + 1]) - abs(A[i]);
				}
				else if(i == minus) continue;
				else ans += abs(A[i]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
int main()
{
  string S;
  cin >> S;
  ll ans=0;
  rep(i,S.size()/2){
      if(S[i]!=S[S.size()-1-i])ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

// Greatest Common Divisor 最大公約数
int GCD( int a, int b) {
	int bi, sm, r;
	if(a>b) {bi = a; sm = b;} else {bi = b; sm = a;}
	r = bi % sm;
	if(r==0) return sm;
	return GCD( sm, r);
}

// Least Common Multiple 最小公倍数
// gcd( a, b) * lcm( a, b) = a * b

int main() {
	int a, b;
	int gcd;
	while( std::cin >> a >> b) {
		gcd = GCD( a, b);
		std::cout << gcd << " " << ( a / gcd * b) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int[] n = new int[N];
        int curr = 1;
        for (int i = 0; i < N; i++) {
            n[i] = Integer.parseInt(scanner.next());
            if (n[i] == curr) {
                curr++;
            }
        }
        if (curr == 1) {
            System.out.println(-1);
        } else {
            System.out.println(N - curr + 1);
        }
    }

}


Measured memory_bytes: 50968
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    if (s[0] != '1'){
        cout << s[0] << endl;
        return 0;
    }else{
        for (int i = 0; i < min((ll)s.size(), k); i++){
            if (s[i] != '1'){
                cout << s[i] << endl;
                return 0;
            }
        }

        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def dfs(num):
    global used, G
    used.add(num)
    for t in G[num]:
        if t not in used:
            dfs(t)

N, M = map(int, input().split())
es = []
G = [[] for i in range(N)]
for i in range(M):
    a, b = [int(i) - 1 for i in input().split()]
    G[a].append(b)
    G[b].append(a)
    es.append([a, b])

ans = 0
for a, b in es:
    G[a].remove(b)
    G[b].remove(a)
    used = set()
    dfs(0)
    if len(used) != N:
        ans += 1
    G[a].append(b)
    G[b].append(a)

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

long long find( long long x, long long y ) {
    
    long long s1, s2, s3;
    long long s_min, s_max;
    long long diff_min = LLONG_MAX;
    
    for ( long long i = 1; i < x; i++ ) {
        s1 = i * y;
        
        if ( x-i > 1 ) {
            if ( ( x-i ) %2 == 0 ) {
                s2 = s3 = ( ( x-i )/2 ) * y;
            }
            else {
                s2 = ( ( x-i )/2 ) * y;
                s3 = ( (( x-i )/2) + 1 ) * y;
            }
            
            s_min = min(s1, s2);
            s_min = min(s_min, s3);
            
            s_max = max(s1,s2);
            s_max = max(s_max,s3);
            
            diff_min = min( diff_min, s_max-s_min );
        }
        
        if ( y > 1 ) {
            if ( y%2 == 0 ) {
                s2 = s3 = ( x-i ) *  (y/2);
            }
            else {
                s2 =  ( x-i ) *  (y/2);
                s3 =  ( x-i ) * ( (y/2) +1);
            }
            
            s_min = min(s1, s2);
            s_min = min(s_min, s3);
            
            s_max = max(s1,s2);
            s_max = max(s_max,s3);
            
            diff_min = min( diff_min, s_max-s_min );
        }
        
        
    }
    
    return diff_min;
}


int main() {
    
    long long H, W;
    
    cin >> H;
    cin >> W;
    
    if ( H%3 == 0 || W%3 == 0 ) {
        cout << "0" << endl;
        return 0;
    }
    
    cout << min( find(H,W), find(W,H) ) << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
int a=0,b=0,i=0,j=0,k=0,f=0,sum=0;
scanf ("%d%d",&a,&b);
int c[32] = {0};
for (i=0;i<a;i++){
scanf ("%d",&f);
  for (j=0;j<f;j++){
  scanf ("%d",&k);
  c[k-1]=c[k-1]+1;
  }
}
for (i=0;i<b;i++){
if(c[i]==a){
sum=sum+1;
}
}
  printf ("%d",sum);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define CON 1000000000000
#define SIX 1000000
using namespace std;

int main() {
  int n;
  string s = "No";
  cin >> n;
  if(n == 25) {
    s = "Christmas";
  } else if (n == 24) {
    s = "Christmas Eve";
  } else if (n == 23) {
    s = "Christmas Eve Eve";
  } else if (n == 22){
    s = "Christmas Eve Eve Eve";
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PB push_back
ll n,s;
bool ok(ll b){
	ll p=0,a=n;
	while(a){
		p+=(a%b);
		a/=b;
	}
	return p==s;
}
vector<ll>o;
int main(void){
	cin>>n>>s;
	ll v=abs(n-s);
	if(v==0){
		printf("%lld\n",n+1);
		return 0;
	}
	for(ll i=1;i*i<=v;i++){
		if(v%i==0){
			o.PB(i);
			o.PB(v/i);
		}
	}
	sort(o.begin(),o.end());
	for(int i=0;i<o.size();i++){
		if(ok(o[i]+1)){
			printf("%lld\n",o[i]+1);
			return 0;
		}
	}
	printf("-1\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
vector<ll> memo(1000010,-1);

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    ll ans1,ans2;
    if(x>=0){
        ans1 = x%d;
        ans2 = x%d-d;
        
        if((x-ans1)/d>=k){       
            cout<<abs(x-k*d)<<endl;
            return 0;
        }else{
            if((k%2==(x/d)%2)){
               cout<<abs(ans1)<<endl;
               return 0; 
            }else{
                cout<<abs(ans2)<<endl;
               return 0; 
            }
        }

    }else{
        ans1 = x%d;
        ans2 = x%d+d;
        int ok = 1;
        ll cx = x;
        
        if(k<=(ans1-x)/d){
            cout<<abs(x+k*d)<<endl;
            return 0;
        }else{
            if(k%2==(-x/d)%2){
               cout<<abs(ans1)<<endl;
               return 0; 
            }else{
                cout<<abs(ans2)<<endl;
               return 0; 
            }
        }

    }
       
    return 0;
}

Measured memory_bytes: 11032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define __fd cout.setf(ios::fixed); cout.precision(18)
#define preturn(X) cout<<X<<endl; return 0
typedef long long ll;




ll a[300000+1];

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);
	int n; cin>>n;
	rep(i,1,(3*n)+1){
		cin>>a[i];
	}
	sort(a+1,a+(3*n)+1);
	int i =1;
	int j = 3*n;
	ll ans =0;
	while(i<j){
		j--;
		ans+=(a[j]);
		i++;
		j--;
	}
	preturn(ans);
}

Measured memory_bytes: 2560
N,M=map(int,input().split())
A=[0]*N

for i in range(N):
    a,b=map(int,input().split())
    A[i]=(a,b)
A=sorted(A)

t=0
c=0
for i in range(N):
    if(M<=t+A[i][1]):
        print(c+A[i][0]*(M-t))
        exit()
    else:
        t+=A[i][1]
        c+=A[i][0]*A[i][1]

print(c)

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());
  
  int Bob,Alice;
  Bob =0;
  Alice =0;
  
 if(N%2 ==0){
  for (int i = 0; i < N; i++) {
    if(i%2 == 0){
      Bob += vec.at(i);
    }
    else{
      Alice += vec.at(i);
    }
  }
 }
 else{
  for (int i = 0; i < N; i++) {
    if(i%2 == 0){
      Alice += vec.at(i);
    }
    else{
      Bob += vec.at(i);
    }
  }
 }
      
  
  cout << Alice - Bob << endl;
              
 }

Measured memory_bytes: 256
import sys
from math import ceil
from operator import itemgetter as get

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nod(a, b):
    while b: 
        a, b = b, a % b
    return a
 
def calc(n, c, d):
    return n - n // c - n // d + n // (c * d // nod(c, d))   


def main():
    l, r = rinput()
    q = []
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            res = i * j % 2019
            q.append(res)
            if res == 0:
                print(0)
                return 0
    print(min(q))
main() 

Measured memory_bytes: 6948
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Queue<Integer> queue = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            queue.add(sc.nextInt());
        }
        Comp cmp = new Comp();
        cmp.set_index(1);
        int[][] bc = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                bc[i][j] = sc.nextInt();
            }
        }
        Arrays.sort(bc, cmp);
        int done;
        long ans = 0;

        for (int i = 0; i < m; i++) {
            done=0;
            while(queue.peek()<bc[m-i-1][1]&&done<bc[m-i-1][0]){
                queue.add(queue.poll()*0+bc[m-1-i][1]);
                done++;
            }
        }
        for(int i=0;i<n;i++){
            ans+=queue.poll();
        }
        System.out.println(ans);
    }
}

    class Comp implements Comparator {

        int index = 0;

        void set_index(int i) {
            index = i;
        }

        public int compare(Object a, Object b) {
            int[] int_a = (int[]) a;
            int[] int_b = (int[]) b;
            return (int_a[index] - int_b[index]);
        }

    }


Measured memory_bytes: 99936
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  if (s == "RRR") {
    cout << 3 << endl;
    return 0;
  }
  if (s == "SRR") {
    cout << 2 << endl;
    return 0;
  }
  if (s == "RRS") {
    cout << 2 << endl;
    return 0;
  }
  if (s == "RSS") {
    cout << 1 << endl;
    return 0;
  }
  if (s == "SRS") {
    cout << 1 << endl;
    return 0;
  }
  if (s == "SSR") {
    cout << 1 << endl;
    return 0;
  }
  if (s == "RSR") {
    cout << 1 << endl;
    return 0;
  }
  cout << 0 << endl;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

class UnionFind {
public:
  vector<int> par;

  UnionFind(int N) {
    par = vector<int>(N, -1);
  }

  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }

  int size(int x) {
    return -par[root(x)];
  }

  bool same(int x, int y) {
    if (root(x) == root(y))
      return true;
    else
      return false;
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (size(x) < size(y)) swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  UnionFind uf(N);
  vector<ll> res(M);
  res[M - 1] = 1LL * N * (N - 1) / 2;
  for (int i = M - 1; i >= 1; i--) {
    res[i - 1] = res[i];
    if (uf.same(A[i], B[i])) continue;
    res[i - 1] -= 1LL * uf.size(A[i]) * uf.size(B[i]);
    uf.unite(A[i], B[i]);
  }
  for (int i = 0; i < M; i++)
    cout << res[i] << '\n';
  return 0;
}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

def main():
# 整数の入力
    
    s = [int(x) for x in input().split(' ')]
    n = s[0]
    k = s[1]

    # 文字列の入力
    
    id_list = []
    for i in range(k):
        d = int(input())
        s = [int(x) for x in input().split(' ')]
        id_list.extend(s)
    l = list(set(id_list))
    # 出力
    print(n - len(l))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int N=1e5+5, INF=1e9;
using namespace std;
int n, ans = 0;
vector<int> v;
signed main()
{
    bool flag=false;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        if(a!=b) flag=true;
        if(a<=b) ans+=b;
        else
        {
            v.pb(b);
        }
        
    }
    if(!flag)
    {
        cout << 0;
        return 0;
    }
    sort(v.begin(), v.end());
    for(int i = 1; i < v.size(); i++)
    {
        ans+=v[i];
    }
    cout << ans;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

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

int showAll(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector< vector <int> > v(10, vector<int>(10, 0));
  for (int i = 1; i <= n; ++i) {
    int tmp = stoi(to_string(i).substr(0, 1));
    v[tmp][i % 10]++;
  }

  int count = 0;
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v[i].size(); j++) {

      if (i == j) {
        count += (v[i][j] * v[i][j]);
      } else {
        count += (v[i][j] * v[j][i]);
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-06-13 20:05:00
 * @LastEditTime: 2020-06-13 20:12:07
 * @FilePath: \VSC\C++\Public\tokiomarine2020 B.cpp
 */ 
#include<bits/stdc++.h>
using namespace std;
#define int long long

int a,v,b,w,t;
signed main(){
    scanf("%lld%lld%lld%lld%lld",&a,&v,&b,&w,&t);
    if(v<=w) return puts("NO"),0;

    int dis=llabs(b-a);
    if(dis<=t*(v-w)) puts("YES");
    else puts("NO");
    
    return 0;
}

Measured memory_bytes: 3764