akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) <<"\n"


int main() {
	ll h, w, m;
	cin >> h >> w >> m;

	vl y(m), x(m);
	rep(i, m) cin >> y[i] >> x[i], y[i]--, x[i]--;

	set<pii> s;
	rep(i, m) s.insert(mp(y[i], x[i]));

	vector<pii> ky(h), kx(w);
	rep(i, h)
	ky[i] = mp(0, i);

	rep(i, w)
	kx[i] = mp(0, i);

	rep(i, m) {
		ky[y[i]].fi++;
		kx[x[i]].fi++;
	}

	sort(rrng(ky)); sort(rrng(kx));

	rep(i, h) {
		if (ky[i].fi != ky[0].fi) break;
		rep(j, w) {
			if (kx[j].fi != kx[0].fi) break;

			if (s.find(mp(ky[i].se, kx[j].se)) == s.end()) {
				prt(ky[0].fi + kx[0].fi);
				return 0;
			}
		}
	}

	prt(ky[0].fi + kx[0].fi - 1);

	return 0;
}

Measured memory_bytes: 26736
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='S' && s[2]=='N')
        cout<<7-0;
    else if(s[2]=='T')
        cout<<7-6;
    else if(s[0]=='F')
        cout<<7-5;
    else if(s[2]=='U')
        cout<<7-4;
    else if(s[0]=='W')
        cout<<7-3;
    else if(s[2]=='E')
        cout<<7-2;
    else if(s[0]=='M')
        cout<<7-1;

   return 0;
}


Measured memory_bytes: 3604
#include<string.h>
#include<stdio.h>
int main()
{
    char s[1200];
    int t,i;
    scanf("%[^\n]",s);
    t=strlen(s);
    for(i=0;i<t;i++)
    {
        if(s[i]>='A' && s[i]<='Z')
        {
            s[i]=s[i]+32;
        }
        else if(s[i]>='a' && s[i]<='z')
        {
            s[i]=s[i]-32;
        }
        else
        {
            s[i]=s[i];
        }
    }
    printf("%s\n",s);
}



Measured memory_bytes: 2120
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
//#define int long long int

vi len((int)3e5);
int n;
bool check(int x){
 //   debug(x);
    unordered_map<int, int> s;
    int prev = len[0];
    priority_queue<int> q;
    FOR1(i, n-1){
        if(len[i] <= prev){
            if(x == 1)return false;
            s[len[i]] += 1; 
            q.push(len[i]);
            int j = len[i];
            while(j >= 1 && s[j] == x){
                if(j == 1)return false;
                s[j] = 0;
                j--;
                q.push(j);
                s[j]++;
            }
        }else{
            // do nothing here
            // everything after prev should be 0
            while(!q.empty() && q.top() > prev){
                s[q.top()] = 0;
                q.pop();
            }
        }
        //update prev at the end
        prev = len[i];
    }
    return true;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

  //  freopen("in16.txt", "r" , stdin);
    cin >> n;
    FOR(i, n)cin >> len[i];
    int s = 1, e= n;
    int ans =n;
    while(s <= e){
        int mid = (s + e) >> 1;
        if(check(mid)){
            e = mid -1;
            ans = mid;
        }else{
            s = mid + 1;
        }
    }
    cout << ans;
}




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



int main() 
{
  ll N; cin>>N;
  if(N==1) {cout<<0<<endl; return 0;}
  vector<ll> sosu(0);
  vector<ll> kosu(0);
  for(ll i=2;i<=(ll)sqrt(N)||i<=1000000;i++)
  {
    if(N%i==0)
    {
      sosu.push_back(i);
      kosu.push_back(0);
      while(N%i==0)
      {
        N/=i;
        kosu.at(kosu.size()-1)++;
      }
    }
  }
  if(kosu.size()==0) {cout<<1<<endl; return 0;}
  if(N>1){sosu.push_back(N); kosu.push_back(1);}
  ll ans=0;
  rep(i,kosu.size())
  {
    for(ll j=1;;j++)
    {
      kosu.at(i)-=j;
      if(kosu.at(i)>=0) {ans++; continue;}
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3732
#include<stdio.h>

int main(void){

int x,min,max,a,i;

long int sum;

scanf("%d",&x);

scanf("%d",&a);

max=a;

min=a;

sum=a;

for(i=1;i<x;i++){

scanf("%d",&a);

sum+=a; 

if(a<min){

min=a;

}

if(a>max){

max=a;

}

}

printf("%d %d %ld\n",min,max,sum);

return 0 ; 

}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>

using namespace std;

struct restaurant
{
	string city;
	int score;
	int no;
	
	inline bool operator < (const restaurant &other) const
	{
		return city!=other.city?city<other.city:score>other.score;
	}
};

int N;
restaurant rec[105];

int main()
{
	cin >> N;
	for (int i=1; i<=N; i++)
	{
		cin >> rec[i].city >> rec[i].score;
		rec[i].no=i;
	}
	sort(rec+1,rec+N+1);
	for (int i=1; i<=N; i++) cout << rec[i].no << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NK = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];
            var L = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var answer = L.OrderByDescending(x => x).Take(K).Sum();
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28100
#include <iostream>

using namespace std;

int main(){
  int n;
  int c[6]={500,100,50,10,5,1};
  while(cin>>n,n){
    int m=1000-n,a=0;
    for(int i=0;i<6;++i){
      a+=m/c[i];
      m%=c[i];
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
int main(){
  int a,b;
  char s[200010];
  scanf("%s",s);
  for(int i=0;i<strlen(s);i++)
    if(s[i]=='A'){
      a=i;
      break;
    }
  for(int i=strlen(s);i>=0;i--)
    if(s[i]=='Z'){
      b=i;
      break;
    }
  printf("%d\n",b-a+1);
}

Measured memory_bytes: 384
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
def ConvexHullScan(P) :
 P = sorted(P)
 phU = []
 phU.append(P[0])
 phU.append(P[1])
 for p in P[2:] :
  phU.append(p)
  if isCLKWISE(phU) : continue
  while(True) :
   del phU[-2]
   try:
    if isCLKWISE(phU) : break
   except IndexError : break
 phL = []
 phL.append(P[-1])
 phL.append(P[-2])
 for p in P[-3::-1] :
  phL.append(p)
  if isCLKWISE(phL) : continue
  while(True) :
   del phL[-2]
   try:
    if isCLKWISE(phL) : break
   except IndexError : break
 ph = phU + phL[1:-1]
 return ph
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
P = P[idx:] + P[:idx]
for p in P : print(p[0],p[1])

Measured memory_bytes: 33232
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var kosuu = new int[100001];
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                ans += a[i];
                kosuu[a[i]]++;
            }
            var q = int.Parse(ReadLine());

            for (int i = 0; i < q; i++)
            {
                var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                ans += kosuu[s[0]] * (s[1] - s[0]);
                kosuu[s[1]] += kosuu[s[0]];
                kosuu[s[0]] = 0;
                WriteLine(ans);
                Out.Flush();
            }
        }
    }
}

Measured memory_bytes: 50884
#include <iostream>
using namespace std;
int main(void){
    
    string S;
    cin >> S;
    
    if(S == "SUN") cout << 7 << endl;
    if(S == "MON") cout << 6 << endl;
    if(S == "TUE") cout << 5 << endl;
    if(S == "WED") cout << 4 << endl;
    if(S == "THU") cout << 3 << endl;
    if(S == "FRI") cout << 2 << endl;
    if(S == "SAT") cout << 1 << endl;
    
}

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


void solve(long long A, long double B){
    long long iB = B * 100 + 0.1;
    A *= iB;
    A /= 100;
    cout << A << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    double B;
    scanf("%lf",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3792
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=max(p-j-1,0)
print(cnt)


Measured memory_bytes: 44508
//                                                  '-.-'
   //                                         ()      __.'.__
   //                                      .-:--:-.  |_______|
   //                               ()      \____/    \=====/
   //                               /\      {====}     )___(
   //                    (\=,      //\\      )__(     /_____\
   //    __    |'-'-'|  //  .\    (    )    /____\     |   |
   //   /  \   |_____| (( \_  \    )__(      |  |      |   |
   //   \__/    |===|   ))  `\_)  /____\     |  |      |   |
   //  /____\   |   |  (/     \    |  |      |  |      |   |
   //   |  |    |   |   | _.-'|    |  |      |  |      |   |
   //   |__|    )___(    )___(    /____\    /____\    /_____\
   //  (====)  (=====)  (=====)  (======)  (======)  (=======)
   //  }===={  }====={  }====={  }======{  }======{  }======={
   // (______)(_______)(_______)(________)(________)(_________)
   //
   // Credits :- Joan G. Stark
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
   //|                      AUTHOR - KASPAROVIAN                                     |
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define frr(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define int long long
#define mk make_pair
#define endl '\n'
#define MOD 1000000007
#define in insert
#define sz(x) (ll)(x).size()
#define mem(a,b) memset(a,b,sizeof(a))
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef vector<vi> graph;
template<class T> void mxi(T & a, const T & b) { a = max(a, b); }
template<class T> void mni(T & a, const T & b) { a = min(a, b); }
ld EPS=1e-9;
int n;
int mat[22][22];
int dp[21][1<<21];
int go(int id,int mask)
{
	if(id==n)
	{
		if(mask==(1<<n)-1)
			return 1;
		else
			return 0;
	}
	if(dp[id][mask]!=-1)
		return dp[id][mask];
	int &s=dp[id][mask];
	s=0;
	for(int i=0;i<n;i++)
	{
		if(mat[id][i]==1&&(mask&(1<<i))==0)
		{
			s=(s+go(id+1,mask|(1<<i)))%MOD;
		}
	}
	return s;
}
void solve()
{
	mem(dp,-1);
	cin>>n;
	frr(i,n)
	frr(j,n)cin>>mat[i][j];
	cout<<go(0,0)<<endl;

}
signed main()
{
  fast;
  int t,tab;
  t=1;
  tab=t;
  while(t--)
  {
    //cout<<"Case #"<<(tab-t)<<": ";
    solve();
  }
}

Measured memory_bytes: 347688
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <cstdio>
#include <float.h>
#include <ctype.h>
 using namespace std;
 int main(void) {
	 int a, b, c, d, e, total, avg;
	 scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
	 if (a < 40) {
		 a = 40;
	 }
	 if (b < 40) {
		 b = 40;
	 }
	 if (c < 40) {
		 c = 40;
	 }
	 if (d < 40) {
		 d = 40;
	 }
	 if (e < 40) {
		 e = 40;
	 }
	 total = a + b + c + d + e;
	 avg = total / 5;
	 printf("%d\n", avg);
	 return 0;
 }


Measured memory_bytes: 3188
#include <iostream>
#include <set>
#include <vector>
#include <map>
using namespace std;
const int MAX = 1500000;
int check(vector<int> h,vector<int> w,int x,int y,int b){
  if(h[y]&&w[x]&&h[y+b]&&w[x+b])return 1;
  return 0;
}
int main(){
  int n,m;
  while(cin >> n >> m,n || m){
    vector<int> h(n+1,0);
    vector<int> w(m+1,0);
    h[0] = 0;w[0] = 0;
    for(int i = 1;i <= n;i++){
      int tmp;
      cin >> tmp;
      h[i] = h[i-1] + tmp;
    }
    for(int i = 1;i <= m;i++){
      int tmp;
      cin >> tmp;
      w[i] = w[i-1] + tmp;
    }
    map<int,int> cnt;
    for(int i = 0;i <= n;i++){
      for(int j = 0;j <= m;j++){
	cnt[h[i]-w[j]]++;
      }
    }
    int ans = 0;
    map<int,int>::iterator it = cnt.begin();
    while(it != cnt.end()){
      ans += (*it).second*((*it).second-1)/2;
      it++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 28004
#include <iostream>

using namespace std;

int main()
{
  /******input******/
  int N;
  int D,X;
  cin >> N >> D >> X;
  int A[N];
  for(int i = 0; i < N; i++) cin >> A[i];
  /******input******/


  int E[N];
  for(int i = 0; i < N; i++){
    E[i] = 1;
    E[i] += (D-1)/A[i];
  }

  int ans = X;
  for(int i = 0; i < N; i++){
    ans += E[i];
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#include<algorithm>
#define maxn 105
#define maxm 100005
using namespace std;
int x[maxn];
ll dp[maxn][maxm];
int main()
{
    int n,a;
    scanf("%d%d",&n,&a);

   dp[0][0]=1;
   int sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x[i]);
        sum+=x[i];
        for(int j=i;j>=1;j--)
        {
            for(int l=sum;l>=x[i];l--)
                dp[j][l]+=dp[j-1][l-x[i]];
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        ans=(ans+dp[i][i*a]);
        printf("%lld\n",ans);

        return 0;
}


Measured memory_bytes: 39168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static long long combination2(int num) {
    if ( num == 0 )
        return 0;
    return (long long)num * (num-1) / 2;
}

static void print_ans (int n, int a[]) {
    int i;
    int cnt[n];
    long long total=0;

    memset(cnt, 0, n*sizeof(int));
    for ( i=0; i<n; i++ )
        cnt[(a[i]-1)]++;

    for ( i=0; i<n; i++ )
        total += combination2(cnt[i]);

    for ( i=0; i<n; i++ ) {
        printf("%lld\n", total - (cnt[a[i]-1] -1));
    }
}

int main (void) {
    int i;
    int n;
    scanf("%d", &n);
    int a[n];
    for ( i=0; i<n; i++ )
        scanf("%d", &a[i]);

    print_ans(n, a);

    return EXIT_SUCCESS;
}


Measured memory_bytes: 4096
<?php
$cnt = array_fill(0,26,0);
$a = range("a","z");
while ($s = fgets(STDIN)) {
    $s = strtolower(trim($s));
    foreach($a as $k => $v){
        $cnt[$k] += substr_count($s,$v);
    }
}
foreach($a as $k => $v){
    echo "$v : ".$cnt[$k]."\n";
}

Measured memory_bytes: 15404
X,N = list(map(int,input().split()))
p = list(map(int,input().split()))
s = 1
t = 1
for i in range(100):
    for j in range(N):
        if p[j] == X-i:
            s *= 0
        else:
            s *= 1
        if p[j] == X+i:
            t *= 0
        else:
            t *= 1
    if s == 1:
        print(X-i)
        break
    elif t == 1:
        print(X+i)
        break
    else:
        s = 1
        t = 1

Measured memory_bytes: 9212
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

int main(){
	int N;
	int a[100];

	scanf("%d",&N);
	for(int i=0;i<N;i++) scanf("%d",&a[i]);

	int min = 100*100*100;
	int ans;
	for(int i=-100;i<=100;i++){
		int tmp = 0;
		for(int j=0;j<N;j++) tmp += (i-a[j])*(i-a[j]);
		if(min>tmp){
			ans = i;
			min = tmp;
		}
	}

	printf("%d\n",min);

	return 0;
}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;

    int n;
    cin >> n;

    vector<int> iot;
    for(int i = 1; i <= n; i++) iot.pb(i);

    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];

    int i = 0, j = 0;
    int k = 0;
    do{
        if(iot == a) i = k;
        if(iot == b) j = k;
        k++;
    } while(next_permutation(all(iot)));

    cout << abs(i - j) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
    int Q;cin>>Q;
    priority_queue<ll> pre;
    priority_queue<ll,vector<ll>,greater<ll>> lat;
    ll pre_sum = 0, lat_sum = 0, sum = 0;
    rep(i,Q) {
        int typ;
        cin>>typ;
        if(typ==1) {
            ll a,b;
            cin>>a>>b;
            sum += b;
            if(pre.size()==0) {
                pre.push(a);
                pre_sum += a;
                continue;
            }
            if(pre.size()>lat.size()) {
                ll mx = pre.top();
                if(mx>a) {
                    pre.pop();
                    pre.push(a);
                    lat.push(mx);
                    pre_sum += a - mx;
                    lat_sum += mx;
                } else {
                    lat.push(a);
                    lat_sum += a;
                }
            } else {
                ll mn = lat.top();
                if(mn < a) {
                    lat.pop();
                    lat.push(a);
                    pre.push(mn);
                    lat_sum += a - mn;
                    pre_sum += mn;
                } else {
                    pre.push(a);
                    pre_sum += a;
                }
            }
        } else {
            ll res = sum + (pre.top()*(int)pre.size() - pre_sum) + (lat_sum - pre.top()*(int)lat.size());
            cout<<pre.top()<<" "<<res<<endl;
        }
    }
}

Measured memory_bytes: 5004
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 123456789;
const int maxx = 1005;
ll q, t, n, m, T, k, ans, a[maxn], b[maxn];
priority_queue<ll> pr;
string s, str;
char ss[maxx][maxx];

struct dang
{
    ll val, sl;
};
dang st[maxn];
bool lt(const dang &x, const dang &y)
{
    return x.val < y.val;
}


void test()
{
    cin >> m >> n;
    t = (n + 1) / 2;
    k = (m + 1) / 2;
    ans = t * k + (n / 2) * (m / 2);
    if(m == 1 || n == 1)ans = 1;
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    test();
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    while(true) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;

        if(M == 0 && T==0 && P == 0 && R == 0) return 0;

        int m, t, p, j;
        int result[T];
        fill(result, result + T, 0);
        int time[T];
        fill(time, time + T, 0);
        int failure[T][P];
        fill(failure[0], failure[T] + P, 0);
        for (int submit = 0; submit < R; submit++) {
            cin >> m >> t >> p >> j;
            if (j == 0) {
                result[t - 1] += 1;
                time[t - 1] += m + failure[t - 1][p-1] * 20;
            } else {
                ++failure[t - 1][p-1];
            }
        }

        bool done[T];
        fill(done, done + T, false);
        int prevPoint, prevTime;
        for (int count = 0; count < T; count++) {
            int maxPoint = -1;
            int maxTeam = 0;
            int minTime = 100000;
            for (int i = T - 1; i >= 0; i--) {
                if (done[i]) continue;
                if (maxPoint < result[i]) {
                    maxPoint = result[i];
                    maxTeam = i + 1;
                    minTime = time[i];
                } else if (maxPoint == result[i]) {
                    if (minTime > time[i]) {
                        minTime = time[i];
                        maxTeam = i + 1;
                    }
                }
            }
            minTime = time[maxTeam - 1];
            if (count != 0) {
                if (maxPoint == prevPoint && minTime == prevTime) cout << "=";
                else cout << ",";
            }
            cout << maxTeam;
            done[maxTeam - 1] = true;
            prevPoint = maxPoint;
            prevTime = minTime;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3076
S = int(input())
def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1
a = S
al = [a]
for i in range(2,1000001):
    na = f(a)
    if na in al:
        print(i)
        break
    a = na
    al.append(na)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		String s = sc.next();
		sc.close();
		String tmp = s.substring(5,  7);
		String tmp2 = s.substring(8, 10);
		int month = Integer.parseInt(tmp);
		int day = Integer.parseInt(tmp2);
		String ans[] = {"Heisei", "TBD"};
		int a = 0;
		if(month > 4)a = 1;
		System.out.println(ans[a]);
	}

}


Measured memory_bytes: 22740
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
source=[]
for i in range(n):
  source_a=list(map(int,input().split()))
  source.append(source_a)
ans=0
for i in source:
  sum=c
  for k in range(m):
    sum+= i[k]*b[k]
  if sum > 0:
    ans+=1
print(ans)

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
#define MOD 1000000007
  
using ll = long long;
using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  ll N; cin>>N;
  Graph G(N+1);
  rep(i,N-1){
    ll a,b,c; cin>>a>>b>>c;
    G.at(a).push_back(make_pair(b,c));
    G.at(b).push_back(make_pair(a,c));
  }
  ll Q,K; cin>>Q>>K;
  vector<ll> dist(N+1,-1);
  dist.at(K)=0;
  queue<ll> Que;
  Que.push(K);
  while(!Que.empty()){
    ll v = Que.front();
    Que.pop();
    for(auto p: G.at(v)){
      ll nv = p.first;
      ll cost = p.second;
      if(dist.at(nv)!=-1)continue;//訪問済み
      dist.at(nv) = dist.at(v)+cost;
      Que.push(nv);
    }
  }
  rep(i,Q){
    ll x,y; cin>>x>>y;
    cout<<dist.at(x)+dist.at(y)<<endl;
  }
}

Measured memory_bytes: 9984
#曜日を表す関数Sを使う
#input()という命令を使い、入力待機状態にする
#つまり、曜日ｓを入力したら、答えを出してくれるようプログラムする

s = input()
if s =='SUN':
    print('7')
elif s == 'MON':
    print('6')
elif s == ('TUE'):
    print('5')
elif s == 'WED':
    print('4')
elif s == 'THU':
    print('3')
elif s == 'FRI':
    print('2')
elif s == 'SAT':
    print('1')

Measured memory_bytes: 9056
N = int(input())
list_of_a = list(map(int, input().split()))

ng = max(0, sum(list_of_a)-(N-1)*N) - 1
ok = max(0, (max(list_of_a) - (N-1)) * N)
while ok - ng > 1:
    mid = (ok + ng) // 2
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count <= mid:
        ok = mid
    else:
        ng = mid

#'ok'-i (i=1..N) may be better

for i in range(0, 30 * N + 1):
    mid = ok - i
    if mid < 0:
        break
    count = 0
    for a in list_of_a:
        count += (a + mid + 1) // (N+1)
    if count == mid:
        ans = mid

print(ans)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int m[10] = {0,2,5,5,4,5,6,3,7,6};
int main(){
  int N,M;
  cin>> N >> M;
  vector<int> A(M);
  for(int i = 0;i < M;i++)cin >> A[i];
  sort(A.begin(),A.end(),greater<int>());
  vector<int> DP(N+1,-10000000);
  DP[0] = 0;
  for(int i = 1;i <= N;i++){
    for(int j = 0;j < M;j++){
      if(i-m[A[j]] >= 0)DP[i] = max(DP[i],DP[i-m[A[j]]]+1);
    }
  }
  while(N > 0){
    for(int i = 0;i < M;i++){
      if(N-m[A[i]] >= 0){
        if(DP[N-m[A[i]]]+1 == DP[N]){
        	cout << A[i];
        	N -= m[A[i]];
        	break;
        }
      }
    }
  }
}

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

int n,m;
int a[5]={0},rt[5],num[5];

signed main()
{
	cin>>n>>m;
	for (int i=1;i<=m;i++)  cin>>rt[i]>>num[i];
	for (int i=1;i<=m;i++)
	{
		if (rt[i]==1&&num[i]==0&&n!=1)
		{
			cout<<-1<<endl;
			return 0;
		}
		for (int j=min(i+1,m);j<=m;j++)
		{
			if (rt[i]==rt[j]&&num[i]!=num[j])
			{
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	if (n==1)
	{
		for (int i=1;i<=n;i++)
		{
			if (rt[i]==1)
			{
				cout<<num[i]<<endl;
				return 0;
			}
		}
		cout<<0<<endl;
	}
	if (n==2)
	{
		for (a[1]=1;a[1]<=9;a[1]++)
		{
			int flag=1;
			for (a[2]=0;a[2]<=9;a[2]++)
			{
				flag=1;
				for (int k=1;k<=m;k++)
				{
					if (a[rt[k]]!=num[k])
					{
						flag=0;
						break;
					}
				}
				if (flag==1)  break;
			}
			if (flag==1)  break;
		}
		for (int i=1;i<=2;i++)  cout<<a[i];
		cout<<endl;
		return 0;
	}
	
	if (n==3)
	{
		for (a[1]=1;a[1]<=9;a[1]++)
		{
			int flag=1;
			for (a[2]=0;a[2]<=9;a[2]++)
			{
				for (a[3]=0;a[3]<=9;a[3]++)
				{
					for (int k=1;k<=m;k++)
					{
						flag=1;
						if (a[rt[k]]!=num[k])
						{
							flag=0;
							break;
						}
					}
					if (flag==1)  break;
				}
				if (flag==1)  break;
			}
			if (flag==1)  break;
		}
		for (int i=1;i<=3;i++)  cout<<a[i];
		cout<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	char c;
	cin >> c;
	cout << (char)(c+1) << endl;

	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vint NUM(n);
  rep(i,n) cin >> NUM[i];
  vbool BOAL(n);
  int ans = 0;
  for(int i = n-1;i >= 0;i--){
    int count = 0;
    int tmp = i;
    while(tmp + (i+1) < n){
      tmp += (i+1);
      if(BOAL[tmp]) count++;
    } 
    if(count % 2 == 0){
      if(NUM[i] == 1){
        BOAL[i] = true;
        ans++;
      }    
    }
    else{
      if(NUM[i] == 0){
        BOAL[i] = true;
        ans++;
      }
    }
  }
  cout << ans << endl;
  rep(i,n){
    if(BOAL[i]) cout << i+1 << " ";
  }
}

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

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(System.Console.ReadLine().Trim());
        int[] line = Array.ConvertAll(System.Console.ReadLine().Trim().Split(' '),int.Parse);

        Dictionary<int, int> s = new Dictionary<int, int>();
        Dictionary<int, int> t = new Dictionary<int, int>();
        Dictionary<int, int> tmp;

        for (int i = 0; i < n ; i++)
        {
           
            tmp = (i % 2 == 0) ? s: t;

            if(tmp.ContainsKey(line[i]))
            {
                tmp[line[i]]++;
            }
            else
            {
                tmp.Add(line[i], 1);
            }
        }

        int s1 = 0, s2 = 0, t1 = 0, t2 = 0;

        s = s.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        t = t.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

        List <int> sSortedKeys = s.Keys.ToList();
        List <int> tSortedKeys = t.Keys.ToList();

        s1 = s[sSortedKeys[0]];
        t1 = t[tSortedKeys[0]];

        if(sSortedKeys[0] != tSortedKeys[0])
        {
            //最頻値が異なればsもtも最頻値で置換
            System.Console.WriteLine("{0}", (n - s1 - t1));

        }
        else{

            //最頻値が同じならいずれかを2番目の頻度の値で置換
            if (s.Count > 1) s2 = s[sSortedKeys[1]];
            if (t.Count > 1) t2 = t[tSortedKeys[1]];

            //sを最頻値で、tを二番目で書き換え
            //tを最頻値で、sを二番目で書き換え
            int sRlt = n - s1 - t2;
            int tRlt = n - s2 - t1;

            System.Console.WriteLine("{0}", Math.Min(sRlt, tRlt));

        }


    }

    


}


Measured memory_bytes: 26848
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll N, T;
	cin >> N>>T;

	vector<ll> t(N + 2);
	repn(i, N) cin >> t[i];
	t[N + 1] = INF;

	ll ans = 0;
	repn(i, N) ans += min(T, t[i + 1] - t[i]);

	cout << ans;
	
	system("PAUSE");
}


Measured memory_bytes: 2040
def is_prime(num):
  i = 5
  while (i * i <= num):
      if num % i == 0 or num % (i+2) ==0:
          return False
      i+=6
  return True if num > 1 and num <=3 else False if num % 2 == 0 or num % 3 == 0 or num <=1 else True

k = int(input())
if is_prime(k):
  print(k)
else:
  while(not is_prime(k)):
    k +=1
  print(k)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,last=0,cnt=0;
  int a[100009];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(i==a[i])cnt++;
  }
  for(int i=1;i<=n-1;i++){
    if(a[i]==i&&a[i+1]==i+1&&last==0){
      cnt--;
      last=1;
    }
    else last=0;
  }
  cout<<cnt<<endl;
  return(0);
}


Measured memory_bytes: 640
//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
#pragma comment(linker,"/STACK:33554432") /*32Mb*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <set>
#include <map>
#include <sstream>
using namespace std;

typedef  long long LL;
typedef  unsigned long long ULL;
typedef  long double LD;
typedef  pair<int, int> PII;
typedef vector<int> VI;
#define For(i,a,b) for(int (i)=(a);i<(b);++(i))
#define FoR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i)) 
#define MP make_pair
#define MOD 1000000007
#define INF 1000000000
#define PB push_back
#define y0 kihrbdb
#define y1 ugvrrtgtrg
#define eps 1e-5
#define X first
#define Y second

int n, c, k;
int arr[100010];

int main()
{
	///freopen("distance4.in", "r", stdin);
	///freopen("distance4", "w", stdout);
	//cout.setf(ios::fixed, ios::floatfield);
	//cout.precision(4);

	cin >> n >> c >> k;
	For(i, 0, n) cin >> arr[i];
	sort(arr, arr + n);

	int ans = 0;
	int curr = 1;
	int wait = arr[0];
	For(i, 1, n)
	{
		if (arr[i] - wait > k || curr == c)
		{
			ans++;
			wait = arr[i];
			curr = 0;
		}
		curr++;
	}
	if (curr)
	{
		ans++;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 640
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

signed main()
{
  int n = in();
  vi a(n); REP(i, n) a[i] = in();
  int ans = INF;
  REPS(i, -100, 101) {
    int t = 0;
    for (int v : a) t += (v - i) * (v - i);
    ans = min(ans, t);
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
 char S[10], T[10];
 scanf("%s",S);scanf("%s",T);
 
 int i,cnt=0;
 for(i=0;i<3;i++){
   if(S[i]==T[i])cnt++;
 }
 printf("%d\n",cnt);
 return 0; 
}

Measured memory_bytes: 128
void main()
{
    long n, m;
    ipElems(n, m);

    long[] burger = new long[n+1], patty = new long[n+1];
    burger[0] = patty[0] = 1;
    foreach (i; 0 .. n)
    {
        burger[i+1] = 2 * burger[i] + 3;
        patty[i+1] = 2 * patty[i] + 1;
    }

    long countPatty(long l, long y)
    {
        if (l == 0) return 1;
        if (y <= 1) return 0;
        if (y == burger[l-1] + 2) return patty[l-1] + 1;
        if (y < burger[l-1] + 2) return countPatty(l-1, y-1);
        return patty[l-1] + 1 + countPatty(l-1, y-2-burger[l-1]);
    }

    countPatty(n, m).writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void ipElems(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 2000100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll r1,r2,c1,c2;
  cin>>r1>>c1>>r2>>c2;
  ll ans = 0;
  for(ll i=1;i<=r2+1;i++){
    ans += combination(c2+i,i);
    //cout<<combination(c2+i,i)<<" "<<i<<" "<<c2<<endl;
    ans%=MOD;
  }
  // cout<<ans<<endl;
  for(ll i=1;i<=r1;i++){
    ans -= combination(c2+i,i);
    ans += MOD;
    ans%=MOD;
  }
  for(ll i=1;i<=c1;i++){
    ans -= combination(r2+i,i);
    ans += MOD;
    ans%=MOD;
  }
  //cout<<ans<<endl;
  for(ll i=1;i<=r1;i++){
    ans += combination(c1+i-1,i);
  }
  cout<<ans%MOD<<endl;
  return 0;
}


Measured memory_bytes: 15872
def solve(n):
  a=str(n)
  b=len(a)
  for i in range(b//2):
    if a[i]!=a[b-1-i]:
      return False
  return True

A,B=map(int,input().split())
ans=0
for j in range(A,B+1):
  if solve(j):
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
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; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL A,B;cin >> A >> B;
    LL ans = A+B;
    if((A+B) % 2 == 0){
        cout << (A+B)/2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    int n,m;
    cin >> n >> m;
    ll S = 0;
    for (int i=0; i<m; i++) {
        int ai;
        cin >> ai;
        S += ai;
    }
    if (S > n) cout << -1 << endl;
    else cout << (n - S) << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    cout << ((n + 1000 - 1) / 1000 * 1000) - n << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   int a,b,c;
   cin >> a >> b >> c;  
   cout << (a+b>=c ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int c = sc.nextInt();
      Map<Integer, ArrayList<int[]>> channels = new HashMap<>();
      for(int i = 1;  i <= c; i++) {
          channels.put(i, new ArrayList<>());
      }
      for(int i = 0; i < n; i++) {
          int[] itv = new int[]{sc.nextInt(), sc.nextInt()};
          channels.get(sc.nextInt()).add(itv);
      }

      ArrayList<int[]> allItvs = new ArrayList<>();
      for(int i = 1;  i <= c; i++) {
          ArrayList<int[]> itvs = channels.get(i);
          if(itvs.size() == 0) continue;
          Collections.sort(itvs, (itv1, itv2) -> itv1[0] - itv2[0]);
          int start = itvs.get(0)[0];
          int end = itvs.get(0)[1];
          for(int j = 1; j < itvs.size(); j++) {
            int[] itv = itvs.get(j);
            if(itv[0] == end || itv[0] + 1 == end) {
              end = itv[1];
            } else {
              allItvs.add(new int[] { start - 1, end});
              start = itv[0];
              end = itv[1];
            }
          }
          allItvs.add(new int[] { start - 1, end});
      }

      Collections.sort(allItvs, (itv1, itv2) -> itv1[0] == itv2[0] ? itv1[1] - itv2[1] : itv1[0] - itv2[0]);
      PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[1] == b[1] ? a[0] - b[0] : a[1] - b[1]);

      int min = 0;
      for(int[] itv : allItvs) {
          while(!pq.isEmpty() && itv[0] >= pq.peek()[1])
            pq.poll();
          pq.offer(itv);
          min = Math.max(min, pq.size());
      }
      System.out.println(min);
  }
}



Measured memory_bytes: 97136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int a,b;cin>>a>>b;
    if(a%2==0||b%2==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;

ll p[N], q[N], r[N], sum;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for(int i = 0; i < a; i++){
        cin >> p[i];
    }
    for(int i = 0; i < b; i++){
        cin >> q[i];
    }
    for(int i = 0; i < c; i++){
        cin >> r[i];
    }
    sort(p, p + a);
    sort(q, q + b);
    sort(r, r + c);
    vector<int>red, green;
    for(int i = a - 1; i >= a - x; i--){
        sum += p[i];
        red.push_back(p[i]);
    }
    for(int i = b - 1; i >= b - y; i--){
        sum += q[i];
        green.push_back(q[i]);
    }
    for(int i = c - 1; i >= 0; i--){
        if(red.size() && green.size()){
            if(green.back() <= red.back() && green.back() < r[i]){
                sum += r[i] - green.back();
                green.pop_back();
            }
            else if(red.back() <= green.back() && red.back() < r[i]){
                sum += r[i] - red.back();
                red.pop_back();
            }
            else break;
        }
        else if(green.size()){
            if(green.back() < r[i]){
                sum += r[i] - green.back();
                green.pop_back();
            }
        }
        else if(red.size()){
            if(red.back() < r[i]){
                sum += r[i] - red.back();
                red.pop_back();
            }
        }
        else break;
    }
    cout << sum;


    return 0;
}


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

#define MAXN 100010

typedef long long ll;

using namespace std;

inline ll rd(){
	ll x=0,y=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')y=-y;c=getchar();}
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x*y;
}

char c[MAXN];
int len,ans1=MAXN,ans2=MAXN,ans=MAXN;

int main(){
	scanf("%s",c);
	len=strlen(c);
	bool f1=0,f2=0;
	for(int i=0; i<len; i++){
		if(c[i]=='1')f1=1;
		else f2=1;
	}
	if(f1^f2){
		printf("%d\n",len);
		return 0;
	}
	for(int i=0; i<len; i++){
		if(c[i]=='1')ans1=min(ans1,max(i,len-i-1));
		if(c[i]=='0')ans2=min(ans2,max(i,len-i-1));
	}
	printf("%d\n",max(ans1,ans2));
	
	return 0;
}

Measured memory_bytes: 384