akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> a(N), b(N); rep(i, 0, N) { cin >> a[i] >> b[i]; }
	map<int, int>m;
	rep(i, 0, N) {
		m[a[i]] += b[i];
	}
	vector<pair<int, int>>w;
	for (int i = 0; (1 << i) <= K; i++) {
		if (K&(1 << i)) {
			int k = K;
			k ^= (1 << i);
			k |= (1 << i) - 1;
			w.emplace_back(make_pair(k, 0));
		}
	}
	int index(0);
	while (K >= (1 << index + 1))index++;
	pair<int, int> ans2(0, 0), ans3(K, 0);
	dump(1 << index);
	for (auto &z : m) {

		if (z.first < (1 << index)) {
			dump(z);
			ans2.second += z.second;
			ans2.first |= z.first;
		}

		auto x = ans3;
		x.second += z.second;
		x.first |= z.first;
		if (ans3.first == x.first)ans3 = x;

		rep(i, 0, w.size()) {
			auto x = w[i];

			x.second += z.second;
			x.first |= z.first;
			if (x.first<=K)w[i] = x;
		}
	}

	pair<int, int>ans(0, 0);
	vector<pair<int, int>>v;
	for (auto &z : m) {
		v.emplace_back(make_pair(z.second, z.first));
	}
	sort(all(v), greater<pair<int, int>>());
	rep(i, 0, v.size()) {
		auto x = ans;
		x.second |= v[i].second;
		x.first += v[i].first;

		if (x.second <= K) {
			ans = x;
		}
	}
	int ans4(0);
	rep(i, 0, w.size()) {
		if (w[i].first <= K)chmax(ans4, w[i].second);
	}
	cout << max(max(ans3.second, max(ans.first, ans2.second)),ans4) << endl;
	return 0;
}

Measured memory_bytes: 11764
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

	using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

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

}


const int EPS = (1e-10);

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) : x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a*x, a*y); }
	Point operator / (double a) { return Point(a / x, a / y); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y; }

	bool operator < (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const {
		return fabs(y - p.y) < EPS && fabs(x - p.x) < EPS;
	}

};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

bool ccw(Point p0, Point p1, Point p2) {
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if (cross(a, b) > EPS) {
		 return true;
	}
	return false;

}

typedef vector<Point> Polygon;

Polygon totsu(Polygon s) {

	Polygon u, l;
	if (s.size() < 3) return s;
	sort(s.begin(), s.end());

	u.push_back(s[0]);
	u.push_back(s[1]);
	for (int i = 2; i < s.size(); i++) {
		for (int j = u.size(); j >= 2 && ccw(u[j - 2], u[j - 1], s[i]); j--) {
			u.pop_back();
		}
		u.push_back(s[i]);
	}

	l.push_back(s[s.size() - 1]);
	l.push_back(s[s.size() - 2]);
	for (int i = s.size() - 3; i >= 0; i--) {
		for (int j = l.size(); j >= 2 && ccw(l[j - 2], l[j - 1], s[i]); j--) {
			l.pop_back();
		}
		l.push_back(s[i]);
	}

	reverse(l.begin(), l.end());
	for (int i = u.size() - 2; i >= 1; i--) l.push_back(u[i]);

	return l;
}


int main() {
	ll q;
	Polygon d, d2;
	cin >> q;

	if (q == 2) {
		cout << 0.5 << endl;
		cout << 0.5 << endl;
		return 0;
	}


	rep(i, q) {
		double x, y;
		cin >> x >> y;
		d.push_back(Point(x, y));
		d2.push_back(Point(x, y));
	}

	Polygon cands = totsu(d);

	double pi = acos(-1.0);

	map<Point, double> ans;
	rep(i, cands.size()) {
		Point a = cands[(i - 1 + cands.size()) % (cands.size())] - cands[i], b = cands[(i+1 + cands.size()) % cands.size()] - cands[i];
		
		double co = dot(a, b) / (a.abs()) / (b.abs());
		ans[cands[i]] = pi - acos(co);
		
	}

	rep(i, q) {
		printf("%.20f\n", ans[d2[i]] / pi / 2.0);
	}
	
	return 0;
}


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

int main(){
	string s,t;
	cin>>s>>t;
	for(int i=s.size()-1;i>0;i--){
		for(int j=0;j<i;j++){
			if(s[j]>s[j+1])
				swap(s[j],s[j+1]);
		}
	}
	for(int i=t.size()-1;i>0;i--){
		for(int j=0;j<i;j++){
			if(t[j]<t[j+1])
				swap(t[j],t[j+1]);
		}
	}
	if(s<t)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int r; cin >> r;
	cout << (r * r) << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  if (S[0] == T[0] && S[1] == T[1] && S[2] == T[2]) {
    cout << 3 << endl;
  } else if (S[0] == T[0] && S[1] == T[1] || S[1] == T[1] && S[2] == T[2] || S[0] == T[0] && S[2] == T[2]) {
    cout << 2 << endl;
  } else if (S[0] == T[0] || S[1] == T[1] || S[2] == T[2]) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  int C = 0;
  cin >> A >> B;
  for (int i=1;i<=1000;i++) {
    if (i*8/100 == A && i/10 == B) {
      C+=i;
      break;
    }
  }
  if (C == 0) {
    cout << "-1" << endl;
  }
  else {
    cout << C << endl;
  }
}
    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long long ll;
typedef pair<int,int> P;
ll mod=1e9+9;
int N,M,deg[100001];
int ans=0;
ll num=1;
vector<int> G[100001];	//id,to
bool done[100001]={};
bool comp(const int& x,const int& y){return deg[x]>deg[y];}
void add_edge(int x,int y){
	G[x].pb(y);
	G[y].pb(x);
	deg[x]++,deg[y]++;
}
int main(){
	cin>>N>>M;
	if((ll)N*(N-1)/2==M){
		cout<<1<<endl<<N<<endl;
		return 0;
	}
	rep(i,M){
		int x,y;
		cin>>x>>y;
		add_edge(x,y);
	}
	rep1(i,N) add_edge(0,i);
	vector<int> vc;
	rep(i,N+1) vc.pb(i);
	sort(all(vc),comp);
	for(int a:vc){
		if(done[a]) continue;
		done[a]=true;
		bool cl=true;
		for(int v:G[a]){
			if(done[v]) continue;
			if(deg[v]!=deg[a]) cl=false;
			deg[v]--;
		}
		if(cl){
			int cnt=1;
			done[a]=true;
			for(int v:G[a]){
				if(done[v]) continue;
				done[v]=true;
				cnt++;
			}
			ans++;
			num=num*cnt%mod;
		}
	}
	cout<<ans<<endl<<num<<endl;
}

Measured memory_bytes: 10624
import statistics
import math

N = int(input())

A = [0]*N
B = [0]*N
for i in range(N):
    A[i],B[i] = map(int,input().split())

AM = statistics.median(A)
BM = statistics.median(B)
if N % 2 == 1:
    ANS = (BM - AM) + 1
else:
    ANS = int((BM - AM) * 2 + 1)
print(ANS)

Measured memory_bytes: 28936
N = int(input())
A = []
B = []
for i in range(N):
  a, b = map(int,input().split())
  A.append(a)
  B.append(b)
  
A.sort()
B.sort()
  
if N % 2:
  A_median = A[N // 2]
  B_median = B[N // 2]
  print(abs(B_median - A_median) + 1)
else:
  A_median = (A[N // 2 - 1] + A[N // 2]) / 2
  B_median = (B[N // 2 - 1] + B[N // 2]) / 2
  print(int(abs(B_median - A_median) * 2) + 1)

Measured memory_bytes: 25412
import javax.sound.midi.Soundbank;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Long N, A, B;
        Scanner sc = new Scanner(System.in);
        N = sc.nextLong();
        A = sc.nextLong();
        B = sc.nextLong();
        Long N2 = N%(A+B);
        Long N1 = N/(A+B);
        System.out.println(A*N1 + (N2 >= A ? A : N2) );
    }
}


Measured memory_bytes: 35772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int ans = 0;
		for(int i = 2 ; i <= x ;  i++) {
			for(int j = 2 ; (int)Math.pow(i, j) <= x ; j++) {
				ans = Math.max(ans, (int)Math.pow(i, j));
			}
		}
		if(ans == 0) {
			System.out.println(1);
		} else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21460
S = input()
n = len(S)
ans = [0 for i in range(n)]
for i in range(n):
    if S[i:i+2] == "RL":
        for j in range(i,-1,-1):
            if S[j] == "R":
                ans[i + (i-j) % 2] += 1
            else:
                break
        for j in range(i+1,n):
            if S[j] == "L":
                ans[i + (j-i) % 2] += 1
            else:
                break

print(*ans)

Measured memory_bytes: 48956
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    double sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum += (1.0/a[i]);
    }
    printf("%.10lf", 1.0/sum);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll num=1e9+7;
ll mod(ll n)
{
    return (n%num+num)%num;
}
ll add(ll x,ll y)
{
    return mod(mod(x)+mod(y));
}
ll mult(ll x,ll y)
{
    return mod(mod(x)*mod(y));
}
ll sub(ll x,ll y)
 {
     return mod(mod(x)-mod(y));
 }
 ll pt(ll n,ll p)
 {
      if(p==0)
       return 1;
       if(p==1)
        return n%num;
        ll t=pt(n,p/2);
        if(p%2==0)
         return mult(t,t);
         else
          return mult(n,mult(t,t));
 }
 void solve()
 {
     string str;
     cin>>str;
     if(str[str.size()-1]=='s')
      cout<<str+"es"<<endl;
      else
      cout<<str+"s"<<endl;
      
 }
int main(){
   ll t;
   t=1;
   while(t--)
   {
       solve();
   }
    
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(void){
  string S;
  cin >> S;

  for(int i=0; i<S.length(); i+=2){
    if(S[i] == 'h' && S[i+1] == 'i')
      continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define FOR(i,n) for(int i = 0;i<n ;i++)
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define mii map<int,int>
#define uii unordered_map<int,int>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f
#define print(x) cout<<x<<"\n";

//#include<boost/multiprecision/cpp_int.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//(Uncomment when needed and be sure it not give TLE bcoz it requires time)
//#pragma GCC optimize "trapv"//to check integer overflow and gives RE.
//typedef tree<pair<int,int>,null_type, 
//less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)\
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("O3")
//uncoment for large int requirement
//using boost::multiprecision::cpp_int;
//using namespace _gnu_pbds;

using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//use it with unordered_map<T,T,custom_hash> safe_map

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

int main()
{fast_io

int t;
//cin>>t;
t = 1;
while(t--)
{
ll n;
cin>>n;
vi v(n);
 ll cnt = 0 ; 
 for(int i = 0 ;i<n ;i++){
     cin>>v[i];
 }
 for(int i = 0 ;i<n ;i ++){
     for(int j = i+1;j<n ;j++){
         for(int k = j+1;k<n ;k++){
             if((v[i]+v[j]>v[k]) and (v[j]+v[k]>v[i]) and (v[k]+v[i]>v[j]) and v[i]!=v[j] and v[j]!=v[k] and v[k]!=v[i])
             cnt++;
         }
     }
 }
 cout<<cnt<<endl;
}
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ll,N);
  AIN(ll,W,N);
  ll A1 = 0, A2 = 0;
  REP(i,N){
    A2 += W[i];
  }
  ll ans = A2;
  REP(i,N){
    A1 += W[i];
    A2 -= W[i];
    chmin(ans,abs(A1 - A2));
  }
  OUT(ans);
}

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

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int count = 0;
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            while (tmp % 2 == 0) {
                tmp /= 2;
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 34428
#include<string>
#include<iostream>
#include<cstdio>

using namespace std;

int f[26];
int main(){
string s;
cin >> s;
for(char x:s)f[x-'a']++;

for(int i=0;i<26;i++){
	if(f[i]%2==1){
		puts("No");
		return 0;
	}
}
puts("Yes");
return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 200005;
const int mod = 998244353;

string str;
int dp[MAXN][3][4][2];

int f(int x, int y, int z, int ok){
	if(x == 0) return y == 0 && ok;
	if(~dp[x][y][z][ok]) return dp[x][y][z][ok];
	lint ret = 0;
	for(int i='a'; i<='c'; i++){
		bool nok = ok || (z + 'a' == i);
		ret += f(x - 1, (y + i - 'a') % 3, i - 'a', nok);
	}
	return dp[x][y][z][ok] = ret % mod;
}

set<string> s;

void dfs(string x){
	if(s.find(x) != s.end()) return;
	s.insert(x);
	for(int i=0; i+1<x.size(); i++){
		if(x[i] != x[i+1]){
			char t = 'a';
			while(t == x[i] || t == x[i+1]) t++;
			string n = x;;
			n[i] = n[i+1] = t;
			dfs(n);
		}
	}
}

int main(){
	cin >> str;
	if(count(str.begin(), str.end(), str[0]) == str.size()){
		cout << 1 << endl;
		return 0;
	}
	if(str.size() <= 3){
		dfs(str);
		cout << s.size() << endl;
		return 0;
	}
	int dap = 0;
	for(auto &i : str) dap += i - 'a';
	int tmp = 1;
	for(int i=1; i<str.size(); i++) if(str[i] == str[i-1]) tmp = 0;
	memset(dp, -1, sizeof(dp));
	cout << (tmp + f(str.size(), (3 * 696969 - dap) % 3, 3, 0)) % mod << endl;
}


Measured memory_bytes: 34948
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long C(long long x,long long y)
{
	long long ans=1;
	for(int i = x ; i >= x-y+1 ; i--)
	{
		ans*=i;
	}
	ans/=2;
	return ans;
}
int main()
{
	int n;
	scanf("%d",&n);
	long long sum[200005];
	sum[0]=0;
	scanf("%lld",&sum[1]);
	for(int i = 2 ; i <= n ; i++)
	{
		long long x;
		scanf("%lld",&x);
		sum[i]=sum[i-1]+x;
	}
	sort(sum,sum+n+1);
	int tot=1;
	long long  ssum=0;
	for(int i = 0 ; i < n ;i++)
	{
		if(sum[i]==sum[i+1])
		{
			tot++;
		}
		else if(sum[i]!=sum[i+1]&&tot>=2)
		{
			ssum+=C(tot,2);
			tot=1;
		}
	}
	if(tot)
	ssum+=C(tot,2);
	cout <<ssum <<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin>>n;
	int ans = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				int a = __gcd(i,j);
				a = __gcd(a,k);
				//cout<<i<<" "<<j<<" "<<k<<" "<<a<<"\n";
				ans+=a;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(){
  int year,month,day;
  scanf("%d/%d/%d",&year,&month,&day);
  if(year<2019) printf("Heisei");
  else if(year>2019) printf("TBD");
  else{
    if(month<=4) printf("Heisei");
    else printf("TBD");
  }
  return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/03  Problem: tenka1-procon-2017_d / Link: https://tenka1-2017-beginner.contest.atcoder.jp/tasks/tenka1_2017_d?lang=en  ----- */
/* ------問題------

非負整数専門店「せいすうや」には、N 個の非負整数が売られています。i 個目の非負整数は Ai で、その価値は Bi です。 価値の異なる同じ非負整数が複数売られていることもあります。
高橋君は、「せいすうや」でいくつかの整数を買うことにしました。高橋君は、買う整数たちの bitwise or が K 以下になるような 任意の組み合わせで、整数を買うことができます。高橋君は、買った整数たちの価値の総和をできるだけ大きくしたいです。
高橋君が達成できる、価値の総和の最大値を求めてください。ただし、bitwise or とは、ビットごとの論理和を表します。

-----問題ここまで----- */
/* -----解説等-----

あるbitを使用しないとしたとき、それ以下のbitは1にしてもいいよ、としたほうが嬉しい。
したがってこれらを全探索

----解説ここまで---- */

LL N,K;

LL ans = 0LL;



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

	cin >> N>>K;
	VL val(N), cost(N);
	FOR(i, 0, N) {
		cin >> val[i] >> cost[i];
	}


	// K 以下の bin, 000010/11111をつくる
	FOR(i, 0, 30) {
		LL num = 0;
		LL ret = 0;
		if ((K&(1 << i)) == 0) {
			continue;
		}
		// Kのあるビットをへし折ったときはK以下になる
		FOR(j, 0, i) {
			num |= (1 << j);
		}
		FOR(j, i + 1, 31) {
			if (K&(1 << j))num |= (1 << j);
		}
		//print_bin(num);
		FOR(j, 0, N) {
			if ((num | val[j]) == num) {
				ret += cost[j];
			}
		}
		ans = max(ans, ret);
	}
	{ // Kのとき
		LL ret = 0;
		LL num = K;
		FOR(j, 0, N) {
			if ((num | val[j]) == num) {
				ret += cost[j];
			}
		}
		ans = max(ans, ret);

	}
	cout << ans << "\n";

	return 0;
}


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

int main() {
  int N;
  cin >>N;
  int i=N%10;
  if(i==2||i==4||i==5||i==7||i==9){cout<<"hon"<<endl;}
  else if(i==0||i==1||i==6||i==8){cout<<"pon"<<endl;}
  else {cout<<"bon"<<endl;}
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 998244353
#define F first
#define S second

int A[1<<20], num, N, Q, B, C;
int sum = 0;

int main() {

 //freopen("input.in","r",stdin);
 //freopen("output.out","w",stdout);

 cin>>N;
 rep(i, N) {cin>>A[i];sum ^= A[i];}
 for(int i = 0;i < N;i++) {
   cout << (A[i]^sum) << " ";
 }

  return 0;
}


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

using namespace std;

constexpr int MOD = 998244353, MAXN = 200000;

int comp[MAXN + 2], aux[MAXN + 2], dp[MAXN + 2], robot[MAXN + 2][2], bit[MAXN + 2];

int cl = 0;
int getidx(int x) {
	return lower_bound(comp, comp + cl, x) - comp;
}

int reduce(int x) {
	return x >= MOD ? x - MOD : x;
}

int main() {
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> robot[i][0] >> robot[i][1];
		comp[cl++] = robot[i][0];
	}
	sort(comp, comp + cl);
	cl = unique(comp, comp + cl) - comp;
	for(int i = 0; i < N; i++)
		aux[getidx(robot[i][0])] = getidx(robot[i][0] + robot[i][1]);
	for(int i = N - 1; i >= 0; i--) {
		for(int j = i + 1; j <= N; j += j &- j)
			bit[j] = max(bit[j], aux[i + 1]);
		int res = aux[i];
		for(int j = aux[i] - 1; j > 0; j ^= j &- j)
			res = max(res, bit[j]);
		aux[i] = res;
	}
	dp[N] = 1;
	for(int i = N - 1; i >= 0; i--)
		dp[i] = reduce(dp[i + 1] + dp[aux[i]]);
	cout << dp[0] << '\n';
}


Measured memory_bytes: 4992
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 100000


int main(){
	int a[N + 2];
	int b[N + 1];
	int c[N];
	f(i, N + 2)a[i] = 0;
	f(i, N + 1)b[i] = 0;
	f(i, N)c[i] = 0;
	int n, s;
	scanf("%d", &n);
	f(i,n){
		scanf("%d", &a[i + 1]);
	}
	s = 0;
	f(i,n+1){
		b[i] = a[i + 1] - a[i];
		if (b[i] < 0)b[i] = -b[i];
		s += b[i];
	}
	f(i,n){
		c[i] = a[i + 2] - a[i];
		if (c[i] < 0)c[i] = -c[i];
	}

	f(i, n)printf("%d\n", s + c[i] - b[i] - b[i + 1]);


	return 0;
}

Measured memory_bytes: 2304
/*
    Rem is cute :D
*/

# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second

#define y0 asjdlksajldjals
#define y1 ajsldjalksdkjlk

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = (int)1e9 + 7;
const int maxn = (int)4e5 + 7;
const int lmaxn = (int)6e5 + 7;
const ll linf = (ll)1e18 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll k, a[111], n, m;
string s;

int main(){
  cin >> n >> m;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  for(int i = 1; i <= n; i++){
    if(m - a[i] >= 0){
      m -= a[i];
    }
    else{
      cout << i - 1;
      return 0;
    }
  }
  if(m > 0){
    cout << n - 1;
    return 0;
  }
  cout << n;
  return 0;
}



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

using namespace std;

int main (){

  int n, x;

  cin>>n;
  
  int m =(int)( n / 1.08 );
  
  if( (int)(m * 1.08) == n ) cout<<(int)m<<endl;
  else if((int)( ( m+1 ) * 1.08) == n ) cout<<(int)m+1<<endl;
  else cout<<":("<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll s[2][800001], l[2][800001];
void upd(ll t, ll id, ll v){
	l[t][id] = min(l[t][id], v);
	s[t][id] = min(s[t][id], v);
}
void prop(ll t, ll id){
	upd(t, id * 2, l[t][id]);
	upd(t, id * 2 + 1, l[t][id]);
	l[t][id] = 2147483647;
}
ll query(ll t, ll id, ll l, ll r, ll p){
	if (l == r) return s[t][id];
	prop(t, id);
	ll mid = (l + r) / 2;
	if (p <= mid) return query(t, id * 2, l, mid, p);
	return query(t, id * 2 + 1, mid + 1, r, p);
}
void update(ll t, ll id, ll l, ll r, ll L, ll R, ll v){
	if (r < L || R < l) return;
	if (L <= l && r <= R){
		upd(t, id, v);
		return;
	}
	prop(t, id);
	ll mid = (l + r) / 2;
	update(t, id * 2, l, mid, L, R, v);
	update(t, id * 2 + 1, mid + 1, r, L, R, v);
	s[t][id] = min(s[t][id * 2], s[t][id * 2 + 1]);
}
int main(){
	ll n, q, a, b, ans = 0;
	cin >> n >> q, n--;
	for (int i = 0; i <= n * 4; i++){
		s[0][i] = s[1][i] = n - 1;
		l[0][i] = l[1][i] = 2147483647;
	}
	for (int i = 0; i < q; i++){
		cin >> a >> b, b--;
		if (a == 1){
			ll temp = query(1, 1, 0, n - 1, b);
			ans += temp;
			update(0, 1, 0, n - 1, 1, temp, b - 1);
			update(1, 1, 0, n - 1, b, b, 0);
		}else{
			ll temp = query(0, 1, 0, n - 1, b);
			ans += temp;
			update(1, 1, 0, n - 1, 1, temp, b - 1);
			update(0, 1, 0, n - 1, b, b, 0);
		}
	}
	printf("%lld\n", (n - 1) * (n - 1) - ans);
}

Measured memory_bytes: 28552
N = int(input())
n = N//2

def get_val(num1, num2):
  num1 = sum([int(i) for i in str(num1)])
  num2 = sum([int(i) for i in str(num2)])
  return num1 + num2
  
ans = 10**9
for i in range(1, n+2):
  pool = get_val(i, N-i)
  if ans > pool:
    ans = pool
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<map>
using namespace std;
typedef long long LL;
int xx[9]={-1,-1,-1,0,0,0,1,1,1},yy[9]={-1,0,1,-1,0,1,-1,0,1};
LL c[15];

struct data
{
    int x,y;
    data(){};
    data(int x, int y):x(x),y(y){};
    bool operator<(const data &r)const{
        if(x==r.x)return y<r.y;
        return x<r.x;
    }
};

map<data,int> m;
map<data,int>::iterator it;

int main()
{
    int n,i,j,x,y;
    LL S=0,h,w;
    data t;
    scanf("%lld %lld %d",&h, &w, &n);
    for(i=1;i<=n;i++){
        scanf("%d %d", &x, &y);
        for(j=0;j<9;j++){
            t=data(x+xx[j],y+yy[j]);
            if(t.x<2||t.x>h-1||t.y<2||t.y>w-1)continue;
            //if(m.find(t)==m.end())m.insert(pair<data,int>(t,0));
            m[t]++;
        }
    }
    for(it=m.begin();it!=m.end();it++){
        //  printf("%d %d %d\n", (it->first).x,(it->first).y,(it->second));
        c[it->second]++;
        S++;
    }
    c[0]=(h-2)*(w-2)-S;
    for(i=0;i<10;i++){
        printf("%lld\n", c[i]);
    }
    return 0;
}


Measured memory_bytes: 56448
inp = input().split()
a = int(inp[0])
b = int(inp[1])

def check(a, b):
    for i in range(1,1001):
        if (a<=i*0.08) and (a+1>i*0.08):
            if (b<=i*0.1) and (b+1>i*0.1):
                return i
    return -1

print(check(a, b))

Measured memory_bytes: 3060
N, A, B = [int(_) for _ in input().split()]
d = B - A
if d % 2:
    t1 = N - B + 1
    ans = t1 + (N - (A + t1)) // 2
    t2 = A
    ans = min(ans, t2 + (B - t2 - 1) // 2)
    print(ans)
else:
    print(d // 2)


Measured memory_bytes: 9072
// defines
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define casti static_cast<int>
#define cast static_cast
#define ll long long int
#define vi vector<int>
#define vpi vector<pair<int,int >>

// includes
#include <bits/stdc++.h>

using namespace std;

ll modF=1e9+7;

// topcoder



//codechef and codeforces and atcoder

int main(){
    boost_io;
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=a[i];
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;


class B {
	int N;
	unordered_map<string, int> um;
	int ans{ 0 };
	string s;

public:
	void solve()
	{
		unordered_map<string, int>::iterator found;
		cin >> N;
		for (int i{ 0 }; i < N; i++)
		{
			cin >> s;
			if ((found = um.find(s)) == um.end())
				um.insert(make_pair(s, 1));
			else found->second += 1;
		}

		cin >> N;
		for (int i{ 0 }; i < N; i++)
		{
			cin >> s;
			if ((found = um.find(s)) != um.end())
				found->second -= 1;
		}

		for (found = um.begin(); found != um.end(); found++)
			ans = max(ans, found->second);

		cout << ans << endl;

	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;++i) cin>>A[i];
  ll ans = A[0]-1;
  ll maxnum = 1;
  for(int i=1;i<N;++i) {
    if(A[i]==maxnum+1) maxnum++;
    else {
      if(A[i]%(maxnum+1)==0) ans += A[i]/(maxnum+1)-1;
      else ans += A[i]/(maxnum+1);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4028
import sys
import collections

b=[]
n = map(int, raw_input().split())
a = map(int, raw_input().split())

while True:
    a.sort()
    b=[]
    if a[0]==1:
        print(1)
        break
    elif a[0]==a[-1]:
        print(a[0])
        break
    else:
        for n in a:
            n=n%a[0]
            if n!=0:
                b.append(n)
        a=[a[0]]
        a.extend(b)


Measured memory_bytes: 11500
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll>::iterator IT;
const int M = 1024;

ll a[4][M];

int main()
{
	int n; ll w, ans = 0;
	scanf("%d %lld", &n, &w);
	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < n; ++j)
			scanf("%lld", &a[i][j]);
	
	vector<ll> b, c;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			b.push_back(a[0][i] + a[1][j]);
			c.push_back(a[2][i] + a[3][j]);
		}
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	
	
	for (IT it= b.begin(); it != b.end(); ++it)// 加的长度为 大于 - 正好等于的第一个 
		ans += upper_bound(c.begin(), c.end(), w-(*it)) - lower_bound(c.begin(), c.end(), w-(*it));
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 18336
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int a, b;
	cin >> a >> b;
	int ans = a+b;
	if(ans >= 10) cout << "error" << endl;
	else cout << ans << endl;
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)

signed main(){

	lli n;
	cin>>n;

	string s;
	cin>>s;

	REP(start,0,2)REP(side,0,2){
		lli ans[100100];
		REP(i,0,100100)ans[i]=-1;
		ans[0]=start;
		ans[1]=side;
		ans[n+2] = (ans[0]+ans[1]+(s.at(0)!='o'))%2;

		REP(i,1,n){
			ans[i+1] = (ans[i-1]+ans[i]+(s.at(i)!='o'))%2;
		}
		if(ans[0]==ans[n] && ans[n-1] == ans[n+2]){
			REP(i,0,n){
				if(ans[i]==0)cout<<"S";
				else cout<<"W";
			}
			cout<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
#include <cstdlib>
using namespace std;

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

	if (s.at(0) != s.at(1) && s.at(0) != s.at(2) && s.at(1) != s.at(2))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(n: int, a: "List[int]"):
    ret = []
    if n % 2 == 0:
        for i in range(n - 1, 0, -2):
            ret.append(a[i])
        for i in range(0, n - 1, 2):
            ret.append(a[i])
    else:
        for i in range(n - 1, -1, -2):
            ret.append(a[i])
        for i in range(1, n - 1, 2):
            ret.append(a[i])
    print(' '.join([str(r) for r in ret]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 45756
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

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

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )


int main()
{
	ll N, M;
	cin >> N >> M;

	vector<Pll> v( N );
	rep( i, N )
	{
		ll a, b;
		cin >> a >> b;
		v[i] = { a, b };
	}

	sort( ALL( v ), []( Pll a, Pll b ) {
			return( a.F < b.F );
		} );

	ll num = 0;
	ll cost = 0;
	rep( i, N )
	{
		if ( num + v[i].S < M )
		{
			cost += v[i].F * v[i].S;
			num += v[i].S;
		}
		else
		{
			cost += v[i].F * ( M - num );
			break;
		}
	}

	cout << cost << endl;

	return ( 0 );
}


Measured memory_bytes: 1792
S = str(input())

front = int(S[:2])
back = int(S[2:4])

if (front == 0 or front > 12) and back > 0 and back <= 12:
    print('YYMM')
elif front <= 12 and front > 0 and (back == 0 or back > 12):
    print('MMYY')
elif (front <= 12 and front > 0) and (back > 0 and back <= 12):
    print('AMBIGUOUS')
else:
    print('NA')

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	unsigned int n, tmp, t;
	int *array;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		array = (int *)calloc(n, sizeof(int));
		
		for(int i = 0; i < n; i++){
			cin >> array[i];
		}
		sort(array, array+n);
		
		tmp = 0;
		t = 0;
		for(int i = 1; i < n; i++){
			t += array[i-1];
			tmp += t;
		}
		
		cout << tmp << endl;
		free(array);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
FO

vector<int> v[100];
int p[100];
void solve(){
    int n;
    string s;
    cin>>n>>s;
    int a=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') a++;
        else b++;
    }
    string p="";
    for(int i=0;i<a;i++) p+='R';
    for(int i=0;i<b;i++) p+='W';
    int cnt=0;
    for(int i=0;i<n;i++) if(s[i]!=p[i]) cnt++;
    cout<<cnt/2;


    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}


Measured memory_bytes: 3884
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

//#define P 1000000007
#define P 998244353

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int a[3001];
long d[3001][3001];
int main(void){
	int n=nextpint();
	int s=nextpint();
	for(int i=1; i<=n; i++){
		a[i]=nextpint();
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=s; j++){
			long D=0;
			if(a[i]==j){
				D=i;
			}else if(a[i]<j){
				D=d[i-1][j-a[i]];
			}
			if(j==s){
				D*=(n-i+1);
			}
			d[i][j]=(d[i-1][j]+D)%P;
			//printf("%d %d %ld\n", i, j, d[i][j]);
		}
	}
	printf("%ld\n", d[n][s]);
}


Measured memory_bytes: 70528
//Solution By SlavicG
#include <bits/stdc++.h>
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
#define mp                          make_pair
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	string s;
	cin >> s;
	ll num = 0;
	for(int i = 0;i<sz(s);i++)
		num += s[i] - '0';
	if(num%9==0)
	{
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;



void solve(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, a, b;
    cin >> n >> a >> b;
    string s; cin >> s;

    ll su = a + b;
    rep(i, 0, n){
        if(s[i] == 'c') cout << "No" << "\n";
        if(s[i] == 'a'){
            if(su) cout << "Yes" << "\n";
            else cout << "No" << "\n";
            if(su) su--;
        }
        if(s[i] == 'b'){
            if(su && b) cout << "Yes" << "\n";
            else cout << "No" << "\n";
            if(b){
                if(su) su--;
                b--;
            }
        }
    }
}

int main() {
    solve();
}


Measured memory_bytes: 848
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s | a `mod` 3 == 0 || b `mod` 3 == 0 || c `mod` 3 == 0 = "Possible"
        | otherwise = "Impossible"
 where
  [a, b] = fmap read (words s) :: [Int]
  c      = a + b

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;
 
 
public class  Main{
	static int adj[][];
	static boolean[]v;
	static int ans=-1;
	static void bfs(int i) {
		int[]color=new int[adj.length];
		v[i]=true;
		color[i]=0;
		LinkedList<Integer>l=new LinkedList<Integer>();
		l.add(i);
		int max=0;
		while(!l.isEmpty()) {
			int u=l.poll();
			for(int j=0;j<adj.length;j++) {
				if(adj[u][j]==1) {
					if(!v[j]) {
						l.add(j);v[j]=true;color[j]=color[u]+1;
						max=Math.max(color[j], max);
					}
					else {
						if(Math.abs(color[u]-color[j])!=1) {
							return;
						}
					}
				}
			}
		}
		ans=Math.max(ans, max+1);
	}
	public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();
        adj=new int[n][n];
        for(int i=0;i<n;i++) {
        	char[]in=sc.nextLine().toCharArray();
        	for(int j=0;j<n;j++) {
        		if(in[j]=='1') {
        			adj[i][j]=1;
        		}
        	}
        }
        for(int i=0;i<n;i++) {
        	v=new boolean[n];
        	bfs(i);
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 25008
s=gets.to_s
if (0 <s[0,2].to_i and s[0,2].to_i<13) and(0 <s[2,2].to_i and s[2,2].to_i<13)
  puts 'AMBIGUOUS'
elsif 0 <s[2,2].to_i and s[2,2].to_i<13
  puts 'YYMM'
elsif 0 <s[0,2].to_i and s[0,2].to_i<13
  puts 'MMYY'
else
  puts 'NA'
end

Measured memory_bytes: 1788