akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){

 	ios::sync_with_stdio(false);
	string Sa, Sb, Sc;	cin >> Sa >> Sb >> Sc;
	int count_a = 0, count_b = 0, count_c = 0;
	char next = 'a';
	while(count_a <= Sa.length() && count_b <= Sb.length() && count_c <= Sc.length()){
	 switch(next){
	  case 'a' :  next = Sa[count_a];  count_a += 1;	break;
	  case 'b' :  next = Sb[count_b];	count_b += 1;   break;
	  case 'c' :  next = Sc[count_c];  count_c += 1; 	break;
	 }
	}

	if(count_a == Sa.length() + 1)
	 	cout << "A" << endl;
	else if(count_b == Sb.length() + 1)
	 	cout << "B" << endl;
	else if(count_c == Sc.length() + 1)
	 	cout << "C" << endl;

 return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().strip().split())

A = []
B = []

for i in range(n):
    a = list(map(int,input().strip().split()))
    A.append(a)
    
for j in range(m):
    b = int(input())
    B.append(b)
 
for i in range(n):
    c = 0
    for j in range(m):
        x = A[i][j]
        y = B[j]
        c += x * y
    print(c)


Measured memory_bytes: 6016
#include<iostream>
#include<string>
#include<set>
#include<functional>

using namespace std;

int n;
size_t h[100];
string s[100];
set<size_t> t;

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

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		h[i] = hash<string>()(s[i]);
	}

	t.emplace(h[0]);
	for (int i = 1; i < n; i++) {
		if(t.count(h[i]) or s[i - 1].back() != s[i].front()){
			cout << "No" << '\n';
			return 0;
		}
		t.emplace(h[i]);
	}
	cout << "Yes" << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int x = 0;
	int y = 0;
	char op;

	while (1) {
		scanf("%d %c %d", &x, &op, &y);

		if (op == '?') { break; }

		if (op == '+') {
			printf("%d\n", x + y);
		}
		else if (op == '-') {
			printf("%d\n", x - y);
		}
		else if (op == '/') {
			printf("%d\n", x / y);
		}
		else {
			printf("%d\n", x * y);
		}
	}

	return 0;
}

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

signed main(){
	int q;
	multiset<int>s;
	cin>>q;
	while(q--){
		int x,y;
		cin>>x>>y;
		if(x==1)cout<<s.count(y)<<endl;
		else if(!x){
			s.insert(y);
			cout<<s.size()<<endl;
		}
		else if(x==2)s.erase(y);
		else{
			int l=y,r;
			cin>>r;
			set<int>::iterator end,it;
			it=s.lower_bound(l);
			end=s.upper_bound(r);
			for(;it!=end;it++){
				cout<<(*it)<<endl;
			}
		}
	}
}



Measured memory_bytes: 12260
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define SORRY FUL Accepted 
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define Toktama Kazakhstan 

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;                                          
const int PRI = 555557;
const int pri = 997;

int tests = 1;

bool check (int x) {
	vector < int > mm;
	while(x) {
		mm.pb(x % 10);
		x /= 10;
	}

	vector < int > Yeah = mm;
	reverse(all(mm));
	return Yeah == mm;
}

inline void Solve () {
	//easy
	int a, b;
	cin >> a >> b;
	int ans = 0;

	for (int i = a; i <= b; i ++) {
		if (check(i))
			++ ans;
	}

	cout << ans;
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}

	return Accepted; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n,m;
	cin >> n >> m;

	vector<set<int>> st(n);
	vector<P> py(m);
	for(int i = 0;i < m;i++){
		int p,y;
		cin >> p >> y;
		py[i] = P(p,y);
		st[p-1].insert(y);
	}

	map<P,int> id;
	for(int i = 0;i < n;i++){
		int idx = 1;
		for(auto itr = st[i].begin();itr!=st[i].end();itr++){
			id[P(i,*itr)] = idx;
			idx++;
		}
	}

	for(int i = 0;i < m;i++){
		printf("%06d%06d\n",py[i].first,id[P(py[i].first-1,py[i].second)]);
	}
}


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

using namespace std;

int main()
{
    int N, K, l, a;
    vector<int> v;

    cin >> N >> K;

    for (int i = 0; i < N; i++)
    {
        cin >> l;
        v.push_back(l);
    }

    sort(v.begin(), v.end(),greater<>());

    for (int i = 0; i < K; i++)
    {
        a = v[i] + a;
    }
    cout << a;
}

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

#define ll long long;
#define pi acos(-1);

int isPrime(int a)
{
   if (a < 2)
      return 0;
   if (a == 2)
      return 1;
   if (a % 2 == 0)
      return 0;
   int root = sqrt(a);
   for (int i = 2; i <= root; i++)
   {
      if (a % i == 0)
      {
         return 0;
      }
   }
   return 1;
}

int main()
{
   int n,res = 0;
   cin >> n;
   int data[n];
   for (int i = 0; i < n; i++)
   {
      cin >> data[i];
   }

   for (int i = 0; i < n; i++)
   {
      if (isPrime(data[i]) == 1)
      {
        //cout<<'*'<< data[i];
        res++;
      }
   }

  cout << res << endl;
   return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int a, b;
   cin >> a >> b;
   if(a>b) {
       for(int i = 0;i < a;i++) {
           cout << b;
       }
       cout << '\n';
   }else {
       for(int i = 0;i < b;i++) {
           cout << a;
       }
       cout << '\n';
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>

#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

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

	vector<ll> vec(n);
	ll ans = 0,sum = 0;
	rep(i,n){
		cin >> vec[i];
		ans += vec[i];
	}

	sort(vec.rbegin(),vec.rend());

	priority_queue<ll> que;
	ll tmp;

	rep(i,m){
		if(i < n){
			que.push(vec[i]);
		}
		tmp = que.top();
		que.pop();
		if(tmp%2 == 0){
			sum += tmp/2;
		}
		else{
			sum += tmp/2 + 1;
		}
		que.push(tmp/2);
		
	}

	cout << ans - sum << endl;

	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(void){
  string S;
  cin >> S;
  //入力終了

  int N = S.size();

  //文字列の長さが1なら操作はしなくてOK
  if(N == 1){
    cout << 0 << endl;
    return 0;
  }
  
  int ans = 0;
  rep(i, N){
    //次が同じ色なら変換する
    if(S[i] == S[i+1]){
      S[i+1] = (char)('1'-S[i+1] + '0');
      ans++;
    }
  }

  //解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;;


int main() {
    ios_base::sync_with_stdio(false); 
    
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i]; 
    vector<vector<int>> cnt(h,vector<int>(w,INF));
    priority_queue<pair<int,P>,vector<pair<int,P>>,greater<pair<int,P>>> pq;
    
    cnt[0][0]=0;
    pq.push({0,{0,0}});
    vector<int> di={0,1},dj={1,0};
    while (!pq.empty()) {
        pair<int,P> now=pq.top();
        int i=now.second.first,j=now.second.second;
        pq.pop();
        rep(k,2) {
            int ni=i+di[k],nj=j+dj[k];
            if (ni<h && nj<w) {
                int cost=cnt[i][j];
                if (s[ni][nj]=='#' && s[i][j]=='.') ++cost;
                if (cnt[ni][nj]>cost) {
                    cnt[ni][nj]=cost;
                    pq.push({cnt[ni][nj],{ni,nj}});
                }
            }
        }
    }
    int sc=(s[0][0]=='.')?0:1;
    cout << cnt[h-1][w-1]+sc << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    vector<int> v(4);
    for(int i = 0; i < 4; i++) cin >> v[i];

    map<int, int> mp;
    mp[1] = 0;
    mp[9] = 0;
    mp[7] = 0;
    mp[4] = 0;
    for(int i = 0; i < 4; i++) {
        mp[v[i]]++;
    }

    if(mp[1] > 0 && mp[9] > 0 && mp[7] > 0 && mp[4] > 0) {
        cout << "YES" << endl;
        return 0;
    }

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


Measured memory_bytes: 256
//2020-06-02
#include <bits/stdc++.h>
using namespace std;
#define loop(v, st, en) for (int v = st; v < en; v++)
#define loopdesc(v, st, en) for (int v = st; v >= en; v--)
#define INF 1E9
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define MP make_pair
#define P(x) cout << #x << " = { " << x << " }\n"
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<pll> vll;
const int M = 2e5 + 5;

vi prime_fact(ll n)
{
    vi ans;
    ll y = n;

    for (ll i = 2; i * i <= n; i++)
    {
        if (y % i == 0)
        {
            int cnt = 0;
            while (y % i == 0)
            {
                cnt++;
                y /= i; 
            }
            ans.push_back(cnt);
        }
    }
    if (ans.size() == 0)
        ans.pb(0);
    if(y>1)ans.pb(1);
    return ans;
}

ll calc(ll n)
{
    double x = sqrt(1 + 8 * n) - 1;
    return floor(x / 2.0);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    ll x;
    cin >> x;
    if (x == 1)
    {
        cout << "0";
        return 0;
    }
    vi a = prime_fact(x);
    if (a[0] == 0)
    {
        cout << "1";
        return 0;
    }
    ll ans = 0;
    loop(i, 0, a.size()) ans += calc(a[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3688
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

map <LL,LL> mp;
LL n,a,b,c,d,T;

LL solve(LL x){
	if(mp.find(x) != mp.end()) return mp[x];
	LL tmp = (INF / d < x ? INF : x * d);
	for(LL i = -4;i <= 4;i ++){
		if(x + i < 0) continue;
		if(i >= -1 && i <= 1) if((x + i) % 2 == 0) tmp = min(tmp,solve((x + i) / 2) + a + (i < 0 ? -i : i) * d);
		if(i >= -2 && i <= 2) if((x + i) % 3 == 0) tmp = min(tmp,solve((x + i) / 3) + b + (i < 0 ? -i : i) * d);
		if(i >= -4 && i <= 4) if((x + i) % 5 == 0) tmp = min(tmp,solve((x + i) / 5) + c + (i < 0 ? -i : i) * d);
	}
	mp[x] = tmp; return tmp;
}

int main(){
	cin >> T;
	while(T --){
		mp.clear();
		cin >> n >> a >> b >> c >> d;
		mp[0] = 0; mp[1] = d;
		cout << solve(n) << '\n';
	}
	return 0;
}

Measured memory_bytes: 4436
/*
 * RD
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
#define pii pair<int,int>
#define sz(x) ((int)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const ll inf=1e18;
const int mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//12367769,266916112,123798211
ll powm(ll a, ll b, ll m);

int n;
vector<int> pos;
int neg=0;
int a[100005];
int b[100005];
void solve()
{
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++)
		cin>>b[i];
	int ct=0;
	for(int i=1; i<=n; i++)
		if(a[i]>=b[i])
			pos.pb(a[i]-b[i]);
		else
		{
			ct++;
			neg+=b[i]-a[i];
		}
	sort(all(pos));
	reverse(all(pos));
	for(int i=0; i<pos.size(); i++)
	{
		if(neg<=0)
			break;
		ct++;
		neg-=pos[i];
	}
	if(neg>0)
		cout<<-1<<endl;
	else
		cout<<ct<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	auto clk=clock();
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}
ll powm(ll a,ll b, ll m) {
	ll te=1;
	while(b) {
		if(b&1) te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


Measured memory_bytes: 2936
def bubble(A):
    flag = True
    n = len(A)
    i = 0
    while flag:
        flag = False
        for j in range(n-1,i,-1):
            if A[j][1] < A[j-1][1]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = True
        i += 1

def selection(A):
    n = len(A)
    for i in range(n):
        minj = i
        for j in range(i,n):
            if A[j][1] < A[minj][1]:
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]

n = int(input())
ss = [ x for x in input().split()]
ss2 = ss.copy()

bubble(ss)
for i in range(len(ss)-1):
    print(ss[i],end=' ')
print(ss[-1])
print('Stable')

selection(ss2)
for i in range(len(ss2)-1):
    print(ss2[i],end=' ')
print(ss2[-1])
if ss == ss2:
    print('Stable')
else:
    print('Not stable')
    


Measured memory_bytes: 5620
#include<stdio.h>
int main(){
  int n, S[10000], q, T[10000], i, j, cnt = 0;

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

  scanf("%d", &q);
  for(j = 0; j < q; j++)
    scanf("%d", &T[j]);
  

  
  for(i = 0; i < q; i++)
    for(j = 0; j < n; j++)
      if(T[i] == S[j])   {
	cnt++;
	break;
      }

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();

		int result = 0;

		if (n >= k) {
			result += x * k + y * (n - k);
		} else {
			result += x * n;
		}
		System.out.println(result);
		sc.close();
	}
}


Measured memory_bytes: 9940
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

const int INF = 1e+9 + 7;
const int MAX_N = 2005;

int N, K;
int ans = INF;

vector<int> edge[MAX_N];
vector<PII> edge_list;
int depth[2005];

void dfs(int cur, int prev, int d) {
	depth[cur] = d;
	for (int i = 0; i < edge[cur].size(); i++) {
		int adj = edge[cur][i];
		if (adj == prev) continue;
		dfs(adj, cur, d + 1);
	}
}

int calc(int t) {
	int res = 0;
	for (int i = 0; i < N; i++) {
		if (depth[i] > t) {
			res++;
		}
	}
	return res;
}

void solve() {
	if (K % 2 == 0) {
		for (int i = 0; i < N; i++) {
			memset(depth, -1, sizeof(depth));
			dfs(i, -1, 0);
			ans = min(ans, calc(K / 2));
		}
	} else {
		for (int i = 0; i < edge_list.size(); i++) {
			memset(depth, -1, sizeof(depth));
			int u = edge_list[i].first;
			int v = edge_list[i].second;
			dfs(u, v, 0);
			dfs(v, u, 0);
			ans = min(ans, calc((K - 1) / 2));
		}
	}
	cout << ans << endl;
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
		edge_list.push_back(PII(a, b));
	}
#if 0
	for (int i = 0; i < N; i++) {
		printf("%d: ", i);
		for (int j = 0; j < edge[i].size(); j++) {
			cout << edge[i][j] << " ";
		}
		cout << endl;
	}
#endif
	solve();
	return 0;
}




Measured memory_bytes: 512
using System.Collections.Generic;
using System;

public class Hello
{
	public static void Main()
	{
		string[] line = Console.ReadLine().Trim().Split(' ');
		var n = int.Parse(line[0]);
		var m = int.Parse(line[1]);
		var a = new List<int>[m];
		for (int i = 0; i < m; i++) a[i] = new List<int>();
		for (int i = 0; i < m; i++)
		{
			line = Console.ReadLine().Trim().Split(' ');
			var jmax = int.Parse(line[0]);
			for (int j = 0; j < jmax; j++)
				a[i].Add(int.Parse(line[j + 1]) - 1);
		}
		line = Console.ReadLine().Trim().Split(' ');
		var p = Array.ConvertAll(line, int.Parse);
		var ans = getAns(a, n, m, p);
		Console.WriteLine(ans);
	}
	static int getAns(List<int>[] a, int n, int m, int[] p)
	{
		var ans = 0;
		for (int i = 0; i < 1 << n; i++)
		{
			var ok = true;
			for (int j = 0; j < m; j++)
			{
				var count = 0;
				foreach (var x in a[j])
					if (((i >> (n - x - 1)) & 1) == 1) count++;
				if (count % 2 != p[j]) { ok = false; break; }
			}
			if (ok) ans++;
		}
		return ans;
	}
}

Measured memory_bytes: 13268
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 2e5 + 20;

void solve() {

    int x, y;
    cin >> x >> y;

    for (int i = 0; i <= x; ++ i){
        if (2 * i + 4 * (x - i) == y){
            cout << "Yes";
            return;
        }
    }

    cout << "No";
}

#else

void solve() {

}

#endif


void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Mission #" << (i++) << ": \n";

        solve();
        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
    //    gen();
#endif

}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;

        int[] count = new int[26];

        while((input = br.readLine()) != null){
            if(input.equals("")){
                break;
            }
//          ??¨????°????????????????
            input = input.toLowerCase();

//          ????????????????????????????´?
            char[] ch = input.toCharArray();

            for(char alpha : ch ){
                if('a' <= alpha && alpha <= 'z'){
//                  a????????°??????alpha???????????????1?????????a??????????????°=?????????????????????alpha?????°
                    count[alpha - 'a']++;
                }
            }
        }
        for(int i = 0; i < count.length; i++){
            System.out.println((char)('a' + i) + " : " + count[i]);
        }
    }
}

Measured memory_bytes: 24180
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << ":" << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

template<typename Monoid, typename Operand>
class SegTree {
public:
	Monoid* tree;
	size_t size;
	int32 i;
	//?????????????????????
	SegTree(size_t length) {
		--length;
		size = length;
		if (size & 0xffff0000) { size = size & 0xffff0000; }
		if (size & 0xff00ff00) { size = size & 0xff00ff00; }
		if (size & 0xf0f0f0f0) { size = size & 0xf0f0f0f0; }
		if (size & 0xcccccccc) { size = size & 0xcccccccc; }
		if (size & 0xaaaaaaaa) { size = size & 0xaaaaaaaa; }
		if (length) { size <<= 1; }
		else { size = 1; }
		tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
	}
	//?????????
	void set(bool merge) {
		i = size << 1;
		while (--i) { tree[i].set(); }
		if (merge) {
			i = size;
			while (--i) { tree[i] = tree[i << 1] + tree[i << 1 | 1]; }
		}
	}
	//tree[index]???data????§????´????°
	void update(size_t index, Operand &data) {
		index += size;
		tree[index] = tree[index] * data;
		while (index >>= 1) tree[index] = tree[index << 1] + tree[index << 1 | 1];
	}
	//[begin,end)??????????????????
	Monoid range(size_t begin, size_t end) {
		Monoid retL, retR;
		for (begin += size, end += size; begin < end; begin >>= 1, end >>= 1) {
			if (begin & 1) retL = retL + tree[begin++];
			if (end & 1)  retR = tree[end - 1] + retR;
		}
		return retL + retR;
	}
};
struct SUB {
	int32 e;
	SUB() { set(); }
	SUB(int32 x) { e = x; }
	void set() { e = 1000000000; }
	SUB operator*(const SUB &other) {
		return other;
	}
};
struct MIN {
	int32 e;
	MIN() { set(); }
	MIN(int32 x) { e = x; }
	void set() { e = 2147483647; }
	MIN operator+(const MIN &other) {
		if (e < other.e) return *this;
		return MIN(other.e);
	};
	MIN operator*(const SUB &other) {
		return MIN(other.e);
	}
};

int main() {
	int32 n, l;
	cin >> n >> l;
	if (n > 1000000) { return 0; }
	SUB a;
	SegTree<MIN, SUB> t(n);
	rep(i, 0, n) {
		cin >> a.e;
		t.update(i, a);
	}
	printf("%d", t.range(0, l).e);
	rep(i, 1, n - l + 1)
		printf(" %d", t.range(i, i + l).e);
	printf("\n");
	return 0;
}

Measured memory_bytes: 18868
#include <stdio.h>
#include <string.h>
#include <ctype.h>
 
int strcmp_custom(char* s1, char* s2);
 
 
int main(int argc, const char * argv[]) {
    // insert code here...
     
    char w[11];
    char s[1000];
     
    scanf("%s",w);
     
    int count = 0;
    while(1){
        scanf("%s",s);
         
        if(strcmp(s, "END_OF_TEXT") == 0){
            break;
        }
        else if(strcmp_custom(s, w)){
            count++;
        }
         
    }
 
     
    printf("%d\n",count);
     
    return 0;
}
 
int strcmp_custom(char* s1, char* s2){
     
    int i=0;
    while(1){
         
        if(s1[i] == '\0' && s2[i] == '\0'){
            return 1;
        }
        if(s1[i] == '\0' || s2[i] == '\0'){
            return 0;
        }
        else if(toupper(s1[i]) == toupper(s2[i])){
            i++;
        }
        else{
            return 0;
        }
         
    }
 
}


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

int digit(long long x){
  if(x<10) return 1;
  else return digit(x/10)+1;
}

int main(){
  long long N;
  cin>>N;
  int ans=100;
  for(long long i=1;i<sqrt(N)+1;i++){
    if(N%i==0){
      long long a=i,b=N/i;
      ans=min(ans,max(digit(a),digit(b)));
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
"use strict";
// import bigInt from 'big-integer'

const Main = input => {
  input = input.trim().split("\n");
  const n = input[0]
  input = input[1].split(" ")
  const s = input[0]
  const t = input[1]

  let str = ""
  for (let i = 0; i < n; i++) {
    str += s.charAt(i) + t.charAt(i)
  }

  console.log(str);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
  int w;
  int kei;
  cin >> w;
  while(w!=-1){
	if(w<=10)
		kei=1150;
	else if(w>10&&w<=20)
		kei=1150+((10-(20-w))*125);
	else if(w>20&&w<=30)
		kei=1150+1250+((10-(30-w))*140);
	else
		kei=1150+1250+1400+((10-(40-w))*160);
	
	cout << 4280-kei << endl;

	cin >> w;
  }

  return 0;
}


Measured memory_bytes: 1160
a = []
5.times do
	a << gets.to_i
end
a.sort!
sum = 1000
a.permutation(5).each do |per|
  tmp = 0
  per.each do |i|
    if tmp % 10 == 0
      tmp += i
    else
      while tmp % 10 != 0
        tmp += 1
      end
      tmp += i
    end
  end
  sum = tmp if tmp < sum
end
puts sum


Measured memory_bytes: 1788
//******\\
**udc321**	 
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mpr make_pair
#define db  double
using namespace std;

ll mod=1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*pair(sort and all) implementation and upper bound implementation*/
vector<vector<ll>> v;
vector<ll> h;
ll ps=0;
void dfs1(ll a,ll p)
{

	fr(j,0,v[a].size())
	{
		if(v[a][j]==p){continue;}
		dfs1(v[a][j],a);
		h[a]+=h[v[a][j]];
	}
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string n;
	cin>>n;
	ll s=0;
	bc(j,n.length()-1,-1)
	{
		s+=(ll)(n[j]-'0');
	}
	if(s%9==0){cout<<"Yes"<<endl;}
	else{cout<<"No"<<endl;}

}









Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

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

struct result {
	int pena, corr, tid;
	result(int t, int c, int p) {
		tid = t;
		corr = c;
		pena = p;
	}
};
bool operator<(const result& lhs, const result& rhs) {
	if( lhs.corr == rhs.corr ) {
		return lhs.pena < rhs.pena;
	}
	return lhs.corr > rhs.corr;
}

int main() {
	int t, p, r;
	while(cin >> t >> p >> r, t||p||r) {
		int pena[51] = {};
		int solved[51] = {};
		int wrong[51][11] = {};
		rep(i, r) {
			int tid, pid, time;
			string judge;
			cin >> tid >> pid >> time;
			cin >> judge;
			if(judge == "CORRECT") {
				solved[tid]++;
				pena[tid] += wrong[tid][pid] * 1200 + time;
			} else {
				wrong[tid][pid]++;
			}
		}
		vector<result> res;
		for(int id=1; id<=t; id++) {
			res.push_back(result(id, solved[id], pena[id]));
		}
		stable_sort( res.begin(), res.end() );
		rep(i, res.size()) {
			cout << res[i].tid << ' ' << res[i].corr << ' ' << res[i].pena << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,n,k;
    cin>>n>>k;
    long long  ar[n+1],fsum[n+1],rsum[n+1],ans=1;
    memset(ar,0,sizeof ar);
    for(i=0;i<=n;i++)
    {
        ar[i]=i;
        fsum[i]=0;
        rsum[i]=0;
    }
    fsum[0]=ar[0];
    rsum[n]=ar[n];
    for(i=1;i<=n;i++)
    {
        fsum[i] = ar[i] + fsum[i-1];
    }
    for(i=n-1;i>=0;i--)
    {
        rsum[i] = ar[i] + rsum[i+1];
    }
    
    
    for(i=k;i<=n;i++)
    {
        ans = (ans + 1 + rsum[n+1-i] - fsum[i-1])%1000000007;
        //cout<<rsum[n+1-i] <<" "<<fsum[i-1]<<"\n";
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 8276
#include<bits/stdc++.h>
#define PB push_back
using namespace std;
typedef vector<int>V;
int main(void){
	int n,m;
	int sum;
	int i,j;
	int low,high,mid,flg,key;
	int box[1001];
	V v;
	int MAX;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)	break;
		v.clear();
		box[0]=0;
		for(i=1;i<=n;i++)	cin>>box[i];
		sort(box,box+n+1);
		for(i=0;i<=n;i++){
			for(j=i;j<=n;j++){
				if(box[i]+box[j]<=m)	v.PB(box[i]+box[j]);
			}
		}
		sort(v.begin(),v.end());
		//for(i=0;i<v.size();i++)	cout<<v[i]<<endl;
		MAX=-1;
		for(i=0;i<v.size();i++){
			sum=v[i];
			if(sum<=m){
				key=m-sum;
				//cout<<key<<endl;
				flg=0;
				low=0;
				high=v.size()-1;
				while(low<=high){
					mid=(low+high)/2;
					if(key<v[mid]){
						high=mid-1;
					}
					else if(key>v[mid]){
						low=mid+1;
					}
					else{
						flg=1;
						break;
					}
				}
				if(flg==1){
					sum+=key;
				}
				else{
					sum+=v[high];
				}
				//cout<<sum<<endl;
				MAX=max(MAX,sum);
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}
	


Measured memory_bytes: 4848
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut a: [u64; n],
    }
    a.sort();
    let mut sum_ = 0;
    let mut idx = 0;
    for i in 0..n - 1 {
        sum_ += a[i];
        if sum_ * 2 < a[i + 1] {
            idx = i + 1;
        }
    }
    println!("{}", n - idx);
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H1, M1, H2, M2, k;
    cin >> H1 >> M1 >> H2 >> M2 >> k;
    cout << (H2 * 60 + M2) - (H1 * 60 + M1) - k << '\n';
    return 0;
}

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

int main() {
    long long l, r, ans = 0;
    cin>>l>>r;
    for(long long i = l; i <= l + 3 - (l % 4); ++i) {
        ans ^= i;
    }
    for(long long i = r; i >= r - (r % 4); --i) {
        ans ^= i;
    }
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n, a, b, c, d;
string s;

bool check_reach(int start, int end) {
  for (int i = start; i <= end - 1; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') {
      return false;
    }
  }

  return true;
}

bool check_triple() {
  bool ret = false;
  for (int i = b; i <= d; ++i) {
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') ret = true;
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);

  cin >> s;

  s = '.' + s + '.';

  if (!check_reach(a, c) || !check_reach(b, d)) {
    printf("No\n");
    return 0;
  }

  if (c < d) {
    printf("Yes\n");
    return 0;
  }

  if (check_triple()) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }

  return 0;
}


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

int main(){
string t;
cin >> t;
rep(i,t.size()){
    if(t[i]=='?')
        t[i] = 'D';
}
    cout << t<< endl;

}

Measured memory_bytes: 3724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);
			int c = Integer.parseInt(chr[2]);
			int d = Integer.parseInt(chr[3]);
			 System.out.println(Math.abs(c-a)<=d
					 || (Math.abs(b-a)<=d && Math.abs(b-c)<=d)?"Yes":"No");
		}
	}
}

Measured memory_bytes: 25432
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
 
int func(int A, int B, int C, int D){
    if(A <= C && D <= B) return D - C;
    else if(C <= B && B <= D) return B - C;
    else return 0;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans;
    if(A <= C) ans = func(A, B, C, D);
    else ans = func(C, D, A, B);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    ll pre=0,ans=1e18;
    for(int i=0;i<n-1;i++){
        pre+=a[i];
        ans=min(ans,abs(2*pre-sum));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			long n = sc.nextLong();
			long k = sc.nextLong();
			TreeMap<Long,Long> m = new TreeMap<Long,Long>();
			
			for(int i=0;i<n;i++) {
				long a = sc.nextLong();
				long b = sc.nextLong();
				
				m.merge(a, b, Long::sum);
			}
			
			long ret = 0;
			
			for(Map.Entry<Long, Long> e: m.entrySet()) {
				k -= e.getValue();
				if(k<=0) {
					ret = e.getKey();
					break;
				}
			}
			
			//System.out.println(m);
			System.out.println(ret);
			
	    }
		
	}
	


Measured memory_bytes: 65092
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  for (int h = 1; h <= 3500; ++h) {
    for (int n = 1; n <= 3500; ++n) {
      ll div = 4 * h * n - N * h - N * n, num = N * (ll)h * n;
      if (div >= 1 && num % div == 0 && num / div <= 3500) {
        cout << h << " " << n << " " << (num / div) << endl;
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;

vector<vector<int>>lst;
map<pair<int,int>,pair<int,int>>m;

pair<int,int> dfs(int d,int cur){
	if(m.find({d,cur})!=m.end())return m[{d,cur}];
	pair<int,int> r={cur,cur};
	if(cur>0){
		auto it=upper_bound(lst[cur].begin(),lst[cur].end(),d);
		if(it!=lst[cur].end()){
			r.first=dfs(*it,cur-1).first;
		}
	}
	if(cur<lst.size()-1){
		auto it=upper_bound(lst[cur+1].begin(),lst[cur+1].end(),d);
		if(it!=lst[cur+1].end()){
			r.second=dfs(*it,cur+1).second;
		}
	}
	return m[{d,cur}]=r;
}

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	vector<pair<int,int>>v(k);
	for(int i=0;i<k;i++){
		scanf("%d%d",&v[i].first,&v[i].second);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	lst.resize(n);
	for(int i=0;i<k;i++){
		lst[v[i].second].push_back(i);
	}
	for(int i=0;i<n;i++){
		auto p=dfs(-1,i);
		printf(i<n-1 ? "%d " : "%d\n",p.second-p.first+1);
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
   cin >> a.at(i);
  }
  
  int count = 0;
  rep(i,n) {
   if(a.at(i) % 2 == 0) {
    count++;
   }
  }
  
  int check = 0;
  rep(i,n) {
   if(a.at(i) % 2 == 0 ) {
     if(a.at(i) % 3 == 0 || a.at(i) % 5 == 0) {
     check++;
    }
   }
  }
  
  if (count == check) {
  cout << "APPROVED";
  }
  else {
   cout << "DENIED";
  }
  
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



inline li calc(li from, li to) {
    li n = to - from + 1;
    li base = from * n % MOD;
    li up = n * (n - 1) / 2 % MOD;
    return (base + up) % MOD;
}

int main() {

    li n;
    li k;
    cin >> n >> k;
    li res = 0;
    repp(i, k, n + 2) {
        // i子取る場合
        li mi = calc(0, i - 1);
        li ma = calc(n - i + 1, n);
        res = (res + ma - mi + 1 + MOD) % MOD;
    }
    cout << res << endl;


    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<stdlib.h>
#include<vector>
//##..##
using namespace std;

int main() {

	int N, V[100], C[100],Z=0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	for (int i = 0; i < N; i++) {
		if (V[i] - C[i] > 0) {
			Z += V[i] - C[i];
		}
	}
	cout << Z << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

n = int(input())
days = []
for _ in range(n):
    day = list(map(int, input().split()))
    days.append(day)
dp = [[10000] * 3 for _ in range(n)]

# 1日目
dp[0][0] = days[0][0]
dp[0][1] = days[0][1]
dp[0][2] = days[0][2]


for d in range(1,n):
    for i in range(3):
        mx = 0
        for j in range(3):
            if i != j:
                mx = max(dp[d-1][j] + days[d][i],mx)
                # mx = max(dp[d][i], dp[d-1][j]+ days[d][i])
        dp[d][i] = mx
print(max(dp[-1]))


Measured memory_bytes: 56420
//  Bug Party.cpp
//  2013/01/17.

#if 1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct Bug
{	ll a, b; Bug(ll a=0, ll b=0) : a(a), b(b) {} }; // a=放出量 b=許容量

bool cmpb(const Bug& l, const Bug& r)
{	return l.b > r.b; }

bool check(const vector<Bug>& bugs, ll n)
{
	ll foo = 0;
	priority_queue<ll> que;
	
	rep(i, n)
	{
		foo += bugs[i].a;
		que.push(bugs[i].a);
	}
	
	bool flag = (foo <= bugs[n-1].b * n) || (foo <= bugs[bugs.size()-1].b * n);
	
	REP(i, n, bugs.size())
	{
		if(que.top() > bugs[i].a)
		{
			foo -= que.top() - bugs[i].a;
			que.pop();
			que.push(bugs[i].a);
		}
		
		flag |= foo <= bugs[i].b * n;
	}

	return flag;
}

int main()
{
	int N;
	cin >> N;
	
	vector<Bug> bugs(N);
	rep(i, N) cin >> bugs[i].a >> bugs[i].b;
	
	sort(ALL(bugs), cmpb);

	ll ok = 0;
	for(ll ub = N+1; ub - ok > 1; )
	{
		ll mid = (ok + ub) / 2;
		
		if(check(bugs, mid)) ok = mid;
		else ub = mid;
	}
	
	cout << ok << endl;
}

#endif

Measured memory_bytes: 13036
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  long long int a = 0,b = 0,c = 0,d = 0;
  cin >> a >> b >> c >> d;
  long long int ans = -1000000000000000000;
  ans = max(a*c,ans);
  ans = max(a*d,ans);
  ans = max(b*c,ans);
  ans = max(b*d,ans);
  cout << ans << endl;
}


Measured memory_bytes: 3632
def solve(n, a, b):
    if a > b: return 0
    if n == 1: return 1 if a == b else 0

    x = n - 2
    return b * x - a * x + 1

if __name__ == '__main__':
    n, a, b = map(int, input().split())
    print(solve(n, a, b))


Measured memory_bytes: 2940
import math

def eratosthenes():
    erat = [0 for _ in range(max_a+1)]
    #lim = int(math.sqrt(max_a))
    pair = True
    #for i in range(2, lim+1):
    for i in range(2, max_a+1):
        cnt = 0
        if not erat[i]:
            for res in range(i, max_a+1, i):
                if res in set_a:
                    cnt += 1
                erat[res] = i
                if cnt > 1:
                    pair = False
                    break
        if not pair:
            break
    return pair


n = int(input())
a = [int(x) for x in input().split()]
max_a = max(a)
set_a = set(a)

if eratosthenes() and len(set_a) == n - max(0, a.count(1)-1):
    print('pairwise coprime')
else:
    res = a[0]
    for i in range(n):
        res = math.gcd(res, a[i])
    if res == 1:
        print('setwise coprime')
    else:
        print('not coprime')


Measured memory_bytes: 133268
local n = io.read("n")
-- local n = 999999999
local total = 0
local stack = {{0,0}}
while true do
	local len = #stack
	local one = stack[len]
	if not one then
		break
	end
	local value, mark = one[1], one[2]
	table.remove(stack, len)
	if value <= n then
		if mark == 7 then
			total = total + 1
		end
		table.insert(stack, {value * 10 + 3, mark | 1})
		table.insert(stack, {value * 10 + 5, mark | 2})
		table.insert(stack, {value * 10 + 7, mark | 4})
	end
end
print(total)

Measured memory_bytes: 760
W,H,N = map(int,input().split())

xmin,xmax = 0,W
ymin,ymax = 0,H
for n in range(N):
  x,y,a = map(int,input().split())
  if a==1:
    xmin = max(xmin,x)
  elif a==2:
    xmax = min(xmax,x)
  elif a==3:
    ymin = max(ymin,y)
  elif a==4:
    ymax = min(ymax,y)
#print('{}-{} {}-{}'.format(xmin,xmax,ymin,ymax))

print((xmax-xmin)*(ymax-ymin) if xmin<xmax and ymin<ymax else 0)


Measured memory_bytes: 38256