akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ctime>
#include<deque>
using namespace std;

#define fr                first
#define se                second
#define int               long long
#define pb                push_back
#define mp                make_pair
#define pii               pair<int,int>
#define vi                vector<int>
#define vvi                vector<vector<int>>
#define mi                map<int,int>
#define pq                priority_queue<int>
#define set_bits(x)       __builtin_popcountll(x)
#define mod               1000000007
#define inf               1e18                        //Defining infinity the overflow of int
#define ps(x,y)           fixed<<setprecision(y)<<x   //for defining the precision of the decimal upto y places.
#define zrosetbits(x)     __builtin_ctzll(x)         //it will give no of 0's before the first 1 from the right.
#define mk(a,n,type)      type *a=new type[n];
#define test(t)           int t; cin>>t; while(t--)
#define no                cout<<"No\n";
#define yes               cout<<"Yes\n";
#define NO                cout<<"NO\n";
#define YES               cout<<"YES\n";
// #define for(i,n)          for(int i=0;i<n;i++)
// #define for(j,n)          for(int j=0;j<n;j++)
// #define forn(i,n)               for(int i=0;i<n;i--)



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

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

#define safemap               unordered_map<int,int,custom_hash>

//*********************************************************************************************************

void io()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}


int helper(int cap, int w[], int val[], int si, int n, vvi &dp)
{
//Base Case
  if (cap == 0)
    return 0;

  if (si == n)
    return 0;

  if (dp[si][cap] != -1)
    return dp[si][cap];

//Recursive Case
  int c1 = INT_MIN;

  if (w[si] <= cap)
    c1 = val[si] + helper(cap - w[si], w, val, si + 1, n, dp);

  int c2 = helper(cap, w, val, si + 1, n, dp);

  int ans = max(c1, c2);
  dp[si][cap] = ans;

  return ans;
}




int32_t main()
{

  io();
  clock_t begin = clock();

  int te = 1;

  // test(t)
  // {

  int n, cap;
  cin >> n >> cap;

  int w[n] = {0};
  int val[n] = {0};

  for (int i = 0; i < n; i++)
    cin >> w[i] >> val[i];

  vvi dp(n + 1, vi(cap + 1, -1));

  cout << helper(cap, w, val, 0, n, dp) << "\n";


// cout << "Case #" << te << ": " << res << "\n";
//te++;
// double c_time = (double) (clock() - begin) / CLOCKS_PER_SEC;
// cout << ps(c_time, 4) << " seconds\n";
  //}

  return 0;
}





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

using namespace std;
long long n, d, x, y, sol;
int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> d;

    d = d * d;

    while(n--)
    {
        cin >> x >> y;
        if(x * x + y * y <= d) ++sol;
    }

    cout << sol;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


ll floorl(ll num1, ll num2){
    if(num1%num2 == 0) return num1/num2;
    else return num1/num2+1;
}

int main(){
    ll n,x; cin >> n;
    ll sumA = 0, sumB = 0;
    ll countA = 0, countB = 0;
    vector<ll> a(n),b(n);

    rep(i,n) {
        cin >> a[i];
        sumA += a[i];
    }
    rep(i,n) {
        cin >> b[i];
        sumB += b[i];
    }

    if(sumB-sumA < 0) cout << "No";
    else {
        x = sumB-sumA;
        rep(i,n){
            if(a[i] > b[i]) {
                countB += a[i]-b[i];
            }else
            if(b[i] > a[i]){
                if((b[i]-a[i])%2 == 0) {
                    countA += (b[i]-a[i])/2;
                }else{
                    countB ++;
                    countA += (b[i]+1-a[i])/2;
                }
            }

        }

        if(max(countA,countB) <= x)  cout << "Yes";
        else cout << "No";
    }


}

Measured memory_bytes: 3732
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
#define SIZE 1005
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int n, m, k;
string s;
int main() {
	io(); cin >> n >> m >> k;
	swap(n, m);
	swap(n, k);
	cout << n << ' ' << m << ' ' << k;
}

Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string S,now,pre="";
int cnt;

int main(){
    cin>>S;
    rep(i,S.length()){
        now+=S[i];
        if(now==pre){
            if(i==S.length()-1)break;
            i++;
            now+=S[i];
        }
        pre=now;
        cnt++;
        now="";
        // cout<<now<<" : "<<pre<<endl;
    }
    out(cnt);
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N = 1e5 + 5;
int a[N], b[N];
int n, w;
ll dp[105][N];
ll oo = (ll)0x3f3f3f3f * (ll)0x3f3f3f3f;
ll iterative_dp(){
    for(int i=0; i<=n; i++){
        for(int j=0; j<=w; j++)
            if(i == n)
                dp[i][j] = 0;
            else
                dp[i][j] = -oo;
    }
    for(int i=n-1; i>=0; i--){
        for(int j=0; j<=w; j++){
            dp[i][j] = max(dp[i+1][j], (j>=a[i]?dp[i+1][j-a[i]] + b[i]:-oo));
        }
    }
    ll res = -oo;
    for(int i=0; i<=w; i++){
        res = max(res, dp[0][i]);
    }
    return res;
}

int main() {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false), cin.tie(0);
#endif
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin>>n>>w;
    for(int i=0; i<n; i++)
        cin>>a[i]>>b[i];
    cout<<iterative_dp()<<'\n';
}


Measured memory_bytes: 82500
/*AMETHYSTS*/
#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>
#include <unordered_map>
#include <random>
 
#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (ll i = 0; i < (ll)n; i++)
#define mp make_pair
#define ui unsigned int
 
using namespace std;

const int maxn = 510;
char c[maxn][maxn];
int n, m;
char f[maxn][maxn];

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

	for (int i = 0; i < n; i++) {
		scanf(" ");
		for (int j = 0; j < m; j++) {
			scanf("%c", &c[i][j]);
		}
	}

	for (int i = 0; i < n; i++) {
		f[i][0] = 'r';
		f[i][m - 1] = 'g';
		if (i & 1) {
			for (int j = 1; j < m - 1; j++) {
				f[i][j] = 'g';
			}
		} else {
			for (int j = 1; j < m - 1; j++) {
				f[i][j] = 'r';
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (f[i][j] == 'r' || c[i][j] == '#') {
				printf("#");
			} else {
				printf(".");
			}
		}
		printf("\n");
	}

	printf("\n");

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (f[i][j] == 'g' || c[i][j] == '#') {
				printf("#");
			} else {
				printf(".");
			}
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll k;
  cin >> k;
  ll m = 0;
  m = max(m,a);
  m = max(m,b);
  m = max(m,c);
  if(a == m){
    ll sum = b+c;
    REP(i,k){
      m *= 2;
    }
    cout << sum+m << endl;
  }
  else if(b == m){
    ll sum = a+c;
    REP(i,k){
      m *= 2;
    }
    cout << sum+m << endl;
  }
  else if(c == m){
    ll sum = a+b;
    REP(i,k){
      m *= 2;
    }
    cout << sum+m << endl;
  }
  return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, L;
    cin >> N >> L;

    vector<ll> a(N);
    rep(i, N) {
        a[i] = L+i;
    }

    ll b = 500;
    ll tmp = 0;
    rep (i, N) {
        if (b > abs(a[i])) {
            b = abs(a[i]);
            tmp = a[i];
        }
    }

    ll ans = 0;
    rep (i, N) {
        ans += a[i];
    }

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef struct{
  char no[9];
  int en;
}P;
int main(){
  int a,b,en,k;
  char nanika[9],nanka[9];
  while(1){
    scanf("%d %d",&a,&b);
    if(a==0)break;
    P tmp[a];
    for(int i=0;i<a;i++){
      scanf("%s %d",tmp[i].no,&tmp[i].en);
    }
    int money=0;
    for(int i=0;i<b;i++){
      scanf("%s",nanika);
      for(int j=0;j<a;j++){
	for(k=0;k<8;k++){
	  if(tmp[j].no[k]!='*' && tmp[j].no[k]!=nanika[k]){
	    break;
	  }
	}
	if(k==8){
	  money+=tmp[j].en;
	  break;
	}
      }
    }
    cout << money << endl;
  }
}

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
int main(void){
    int n,i,j;
    
    cin >> n;
    int a[n];
    
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    

    
    for(j=n-1;j>=0;j--){
        if(j==0)
            cout << a[j] << endl;
        else
            cout << a[j] << " ";
    }
    
}



Measured memory_bytes: 3084
n = int(input())
a = list(map(int,input().split()))
lis = [40000 * i + 1 for i in range(n)]
li = [str(40000 * (n-i) + 1) for i in range(n)]
for i in range(n):
  lis[a[i]-1] += i
  lis[a[i]-1] = str(lis[a[i]-1])
print(" ".join(lis))
print(" ".join(li))

Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
bool ok(int d,int b,int c){
  int a[] = {d,b,c};
  int idx = 0;
  for(int i = 0; i < n; ++i){
    if(s[i]-'0' == a[idx])idx++;
    if(idx == 3) return true;
  }
  return false;
}
int main(){
  cin >> n;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < 10; ++i)
    for(int j = 0; j < 10; ++j)
      for(int k = 0; k < 10; ++k)
        if(ok(i,j,k))ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
  val input = readLine()!!.split(" ")
  val a = input[0].toLong()
  val b = input[1].toLong()

  val result = getCommonPrimeNumbers(a, b)

  println(result.keys.size+1)
}

fun primeFactorization(num: Long): Map<Long, Int>{
  val result = mutableMapOf<Long, Int>()

  var tmp = num
  var sqrt = Math.sqrt(tmp.toDouble())
  var i = 2L
  while( i <= sqrt ){
    if( tmp / i * i == tmp ){
      if( result.containsKey(i) )
        result.put(i, result.get(i)!!+1)
      else
        result.put(i, 1)
      tmp /= i
      sqrt = Math.sqrt(tmp.toDouble())
      i--
    }
    i++
  }
  if( tmp != 1L ){
    if( result.containsKey(tmp) )
      result.put(tmp, result.get(tmp)!!+1)
    else
      result.put(tmp, 1)
  }
  return result
}

fun getCommonPrimeNumbers(a: Long, b: Long): Map<Long, Int>{
  val primeNumbersA = primeFactorization(a)
  val primeNumbersB = primeFactorization(b)

  val result = mutableMapOf<Long, Int>()
  for( (k, v) in primeNumbersA )
    if( primeNumbersB.containsKey(k) )
      result.put(k, Math.min(v, primeNumbersB.get(k)!!))

  return result
}


Measured memory_bytes: 37944
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nmax_def 110000
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	pair<int, int> dist[nmax_def];
	int N, a[nmax_def], b[nmax_def], c[nmax_def], Lcount[nmax_def], Lcountmax=0, Lcountmax_num, count = 0, M = 0, d[nmax_def];
	cin >> N;
	for (i = 0; i < N - 1; i++)
	{
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	for (i = 0; i < N; i++)
	{
		cin >> c[i];
		dist[i].second = i;
		dist[i].first = -1;
		Lcount[i] = 0;
	}
	for (i = 0; i < N - 1; i++)
	{
		Lcount[a[i]]++;
		Lcount[b[i]]++;
	}
	for (i = 0; i < N; i++)
	{
		if (Lcount[i] > Lcountmax)
		{
			Lcountmax_num = i;
			Lcountmax = Lcount[i];
		}
	}
	dist[Lcountmax_num].first = 0;
	count++;
	j = 0;
	while (count < N)
	{
		for (i = 0; i < N - 1; i++)
		{
			if ((dist[a[i]].first == j) && (dist[b[i]].first == -1))
			{
				dist[b[i]].first = j + 1;
				count++;
			}
			else if ((dist[a[i]].first == -1) && (dist[b[i]].first == j))
			{
				dist[a[i]].first = j + 1;
				count++;
			}
		}
		j++;
	}
	sort(dist, dist + N, greater <pair<int, int>>());
	sort(c, c + N, less<int>());
	for (i = 0; i < N; i++)
	{
		d[dist[i].second] = c[i];
	}
	for (i = 0; i < N - 1; i++)
	{
		M += min(d[a[i]], d[b[i]]);
	}
	cout << M << endl;
	for (i = 0; i < N; i++)
	{
		cout << d[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3200
from collections import deque

def main():
    N = int(input())
    A = deque(sorted((int(input()) for i in range(N))))
    dq = deque()
    dq.append(A.popleft())
    ans = 0
    for _ in range(N-1):
        a_first = A[0]
        a_last = A[-1]
        dq_first = dq[0]
        dq_last = dq[-1]

        ff = abs(a_first-dq_first)
        fl = abs(a_first-dq_last)
        lf = abs(a_last-dq_first)
        ll = abs(a_last-dq_last)

        comp_list = [ff, fl, lf, ll]
        max_idx = comp_list.index(max(comp_list))
        if max_idx == 0:
            ans += ff
            dq.appendleft(A.popleft())
        elif max_idx == 1:
            ans += fl
            dq.append(A.popleft())
        elif max_idx == 2:
            ans += lf
            dq.appendleft(A.pop())
        else:
            ans += ll
            dq.append(A.pop())

    print(ans)
if __name__ == "__main__":
    main()

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

int main(){
  string s,sub;
  cin>>s>>sub;
  for(int i=s.size()-sub.size();i>=0;--i){
    bool changeable=true;
    for(int j=0;j<sub.size();++j){
        if(s[i+j]=='?')continue;
        if(s[i+j]!=sub[j])changeable=false;
    }
    if(changeable){
        for(int j=0;j<sub.size();++j)s[i+j]=sub[j];
        for(int j=0;j<s.size();++j){
            if(s[j]=='?')s[j]='a';
        }
        cout << s << endl;
        return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#coding: UTF-8

from bisect import bisect_right

max_number = 1000000
prime_flag_list = [1] * max_number

prime_flag_list[0] = 0
prime_flag_list[1] = 0

prime_flag_list[4::2] = [0] * len(prime_flag_list[4::2])

for i in range(3, int(max_number**0.5) + 1, 2):
    prime_flag_list[i*i::i] = [0] * len(prime_flag_list[i*i::i])

prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]

while True:
    try:
        input = int(raw_input())
    except EOFError:
        break
    print bisect_right(prime_list, input)

Measured memory_bytes: 44452
N, x=map(int, input().split())
a=list(map(int, input().split()))
out=0
tmp=a[0]+a[1]
if tmp>x:
  if tmp-x>a[1]:
    out+=a[1]
    a[1]=0
    y=tmp-x-out
    out+=y
  else:
    out+=tmp-x
    a[1]-=tmp-x
    
for i in range(1, N-1):
  tmp=a[i]+a[i+1]
  if tmp>x:
    out+=tmp-x
    a[i+1]-=tmp-x
    
print(out)

Measured memory_bytes: 14068
#include <stdio.h>
#include <stdlib.h>

#define MAX 100000

typedef struct{
  char name[10];
  int time;
}process;


void enqueue(process);
process dequeue(void);
int isEmpty(void);
int isfull(void);

int head = 0, tail = 0;
process Q[MAX];

int main(){
  process input, processing;
  int n, q, x, y;
  int i, time = 0;

  scanf("%d%d", &n, &q);
  
  for(i = 0; i < n; i++){
    scanf("%s %d", input.name, &input.time);
    enqueue(input);
  }

  while(1){
    if(isEmpty() == 1)break;
    
    processing = dequeue();
    
    if(processing.time <= q){
      time += processing.time;
      printf("%s %d\n", processing.name, time);
    }
    
    else{
      processing.time -= q;
      time += q;
      enqueue(processing);
    }
  }
  

  return 0;
}


int isEmpty(){
  int sta = 0;

  if(head == tail) sta = 1;

  return sta;
}

int isFull(){
  int sta = 0;

  if(head == (tail + 1) % MAX) sta = 1;

  return sta;
}

void enqueue(process x){
  if(isFull() == 1) exit(1);

  Q[tail] = x;

  if(tail + 1 == MAX) tail = 0;

  else tail++;
}

process dequeue(){
  process x;
  
  if(isEmpty() == 1) exit(2);

  x = Q[head];

  if(head + 1 == MAX) head = 0;

  else head++;

  return x;
}



Measured memory_bytes: 3336
#include<stdio.h>
 int main()
 {
   int h, w, n ;
   scanf("%d%d%d",&h,&w,&n) ;

   int max, min ;
   if(h > w){
     min = w ;
     max = h ;
   }else{
     min = h ;
     max = w ;
   }

   int i ;
   for ( i = 0; i < min ; i++) {
     if( max * i >= n ){
       break ;
     }
   }
   printf("%d\n", i ) ;

   return 0 ;
 }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, P;
  int count=0;
  cin >> N;
  for(int i=1;i<=N;i++){
    cin>>P;
    if(P!=i){
      count+=1;
    }
  }
  if(count<3){
    cout << "YES";
  }else{
    cout << "NO";
  }
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main()
{
	int a[3];
	for(int i=0;i<3;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<3;i++){
		for(int j=i+1;j<3;j++){
			if(a[i]>a[j]){
				int b=a[i];
				a[i]=a[j];
				a[j]=b;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
	int A,B,mowchk,cnt,maxcnt;
	int carda[5000],cardb[5000];

	cin >> A >> B;
	
	for(int i = 0; i < A; i++){
		cin >> carda[i];
	}
	for(int i = 0; i < B; i++){
		cin >> cardb[i];
	}
	
	maxcnt = 0;
	for(int i = 0; i < B; i++){
		cnt = 0;
		for(int j = 0; j < A; j++){
			if(cardb[i + cnt] == carda[j]){
				cnt++;
			}
			maxcnt = max(maxcnt,cnt);
		}
	}

	cout << maxcnt << endl;

	return 0;
}

Measured memory_bytes: 1200
import java.util.*;
import static java.lang.Math.*;

public class Main {

	static int A, B, C, N;
	static List<Integer> lList;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		N= sc.nextInt();
		A= sc.nextInt();
		B= sc.nextInt();
		C= sc.nextInt();

		lList = new ArrayList<>();

		int i;

		for(i=0; i<N; i++){
			lList.add(sc.nextInt());
		}
		sc.close();

		System.out.println(dfs(0, 0, 0, 0));
	}

	static int dfs(int n, int a, int b, int c){
		if(n==N) {
			return  (min(min(a,b),c) > 0) ? abs(A-a) + abs(B-b) + abs(C-c) -30 : 9999999;
		}

		int mp0 = dfs(n+1, a, b, c);
		int mp1 = dfs(n+1, a+lList.get(n), b, c) + 10;
		int mp2 = dfs(n+1, a, b+lList.get(n), c) + 10;
		int mp3 = dfs(n+1, a, b, c+lList.get(n)) + 10;

		return min(min(mp0, mp1),min(mp2, mp3));
	}
}


Measured memory_bytes: 24504
#include<iostream>
#include<queue>
using namespace std;
int N,M;
main()
{
	cin>>N>>M;
	priority_queue<int>P;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;P.push(a);
	}
	for(;M--;)
	{
		int x=P.top();P.pop();P.push(x/2);
	}
	long ans=0;
	while(!P.empty())ans+=P.top(),P.pop();
	cout<<ans<<endl;
}


Measured memory_bytes: 892
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;


/// Info.
///****************************************************************************************************************************************///
/// Coder               : BAHAA El_DEEN OSAMA SAYED.
/// Problem name        : V - +-x
/// Method              : brute force
/// Date                : 19/2/2020
///****************************************************************************************************************************************///



#define rep(i,x1,x2)      for(int i=x1; i<=x2 ;++i)
#define rep0(i,x)         for(int i=0; i<x ;i++)
#define all(v)           ((v.begin()),((v.end())
#define mm(v,d)          memset(v,d,sizeof(v))
#define MP               make_pair
#define SZ(v)            ((int) ( (v).size() ) )
#define ull              unsigned long long
#define ll               long long
#define pi               3.1415926536
#define oo               1e9
#define OO               1e18
#define Fx(n)            fixed<<setprecision(n)
#define FasterIO           std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define RE0              return 0
#define RE1              return 1
#define mp(a,b)          make_pair(a,b)
#define X                first
#define Y                second
#define pii              pair(int a, int b)
#define RE               return
//#define LD               long double

const  int  N   = (int) 1e5+10;
const  int  M   = (int) 1e3+4;
const  int  INF = (int) 0x3f3f3f3f;
const double ESP = 1e77;
const ll MOD=1e9+7;

int a,b(0);


int main()
{

cin>>a>>b;
cout<<max(a*b,max(a+b,max(a-b,INT_MIN)));


RE0;}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
const long long mod = 998244353;
struct SegmentT{
    int l,r;
    long long d;
    long long c;
    SegmentT(){
        d = 0;
        c = 0;
    }
};
SegmentT t[800005];
long long f[200005];
long long sum[200005];

int max(int a,int b){ return a>b?a:b; }

SegmentT merge(SegmentT& u,SegmentT& v){
    SegmentT res;
    res.l = u.l, res.r = v.r; 
    res.c = 0;
    res.d = u.d+v.d; if(res.d>=mod) res.d -= mod;
    return res;
}

void doSpread(SegmentT& u,long long v,int n){
    long long add = sum[n-u.l];
    if(u.r!=n){ 
        add -= sum[n-u.r-1];
        if(add<0) add += mod;
    }
    u.d = v*add%mod;
    u.c = v;
}

void spread(int p,int n){
    if(t[p].c!=0){
        int c = t[p].c; t[p].c = 0;
        doSpread(t[2*p],c,n);
        doSpread(t[2*p+1],c,n);
    }
}

void build(int p,int l,int r,int n){
    t[p].l = l, t[p].r = r, t[p].c = 0;
    if(l==r){ 
        t[p].d = f[n-t[p].l];
    }
    else{
        int m = (l+r)/2;
        build(2*p,l,m,n);
        build(2*p+1,m+1,r,n);
        t[p] = merge(t[2*p],t[2*p+1]);
    }
}

void segChange(int p,int l,int r,int v,int n){
    if(l<=t[p].l && r>=t[p].r){
        doSpread(t[p],v,n);
    }
    else{
        spread(p,n);
        int m = (t[p].l+t[p].r)/2;
        if(l<=m) segChange(2*p,l,r,v,n);
        if(r>=m+1) segChange(2*p+1,l,r,v,n);
        t[p] = merge(t[2*p],t[2*p+1]);
    }
}

void preWork(int n){
    f[0] = sum[0] = 1;
    for(int i = 1; i <= n; i++){ 
        f[i] = f[i-1]*10ll%mod;
        sum[i] = (sum[i-1]+f[i])%mod;
    }
}

int main(){
    preWork(200000);
    int n,q;
    scanf("%d%d",&n,&q);
    build(1,1,n,n);
    for(int i = 1; i <= q; i++){
        int l,r,d;
        scanf("%d%d%d",&l,&r,&d);
        segChange(1,l,r,d,n);
        printf("%lld\n",t[1].d);
    }
    return 0;
}


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

int main() {
	int h, w;
	cin >> h >> w;
	char a[102][102] ;
	for (int i = 0;i < 102;i++) {
		for (int j = 0;j < 102;j++) {
			a[i][j] = '#';
		}
	}
	for (int i = 1;i < h + 1;i++) {
		for (int j = 1;j < w + 1;j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0;i < h + 2;i++) {
		for (int j = 0;j < w + 2;j++) {
			cout << a[i][j];
		}
		cout << endl;
	}
}


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

using namespace std;

int main() {
    int n;

    cin >> n;

    vector<double> p(n);

    for(int i = 0; i < n; ++i) {
        cin >> p.at(i);
    }

    vector<vector<double>> dp(n + 1, vector<double>(n + 1));

    dp.at(0).at(0) = 1.0;

    for(int i = 1; i <= n; ++i) {
        dp.at(i).at(0) = dp.at(i - 1).at(0) * (1.0 - p.at(i - 1));
        for(int j = 1; j <= i; ++j) {
            dp.at(i).at(j) = dp.at(i - 1).at(j - 1) * p.at(i - 1) + dp.at(i - 1).at(j) * (1.0 - p.at(i - 1));
        }
    }

    double ans = 0.0;
    for(int j = (n + 1) / 2; j <= n; ++j) {
        ans += dp.at(n).at(j);
    }
    
    printf("%12.10lf\n", ans);

    return 0;
}

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

typedef vector<int> vi;
#define ll long long
#define PI 3.14159265359
//#define x first
//#define y second
#define point pair<int,int>
#define clr(x, val)	memset((x), (val), sizeof(x))

//you don't know math, unless you can do math!
vector<vector<int> > adjList;
int n;

ll mod = 1e9 + 7;
ll dp[100000][3];
ll solve(int i, int last, int parent){
    if(adjList[i].size() == 1 && parent != -1){
        ll ret = 1 + (last != 1);
        return ret;
    }

    ll &ret = dp[i][last];
    if(ret != -1)
        return ret;
    ret = 0;
    //first coloring it white
    ll ways = 1;
    for(int k = 0; k  < adjList[i].size(); k++){
        int child = adjList[i][k];
        if(child == parent)
            continue;

        ways= (ways * solve(child, 0, i))%mod;
    }

    ret = ways;
    if(last == 1)
        return ret;

    ways = 1;
    for(int k =0; k < adjList[i].size(); k++){
        int child = adjList[i][k];
        if(child == parent)
            continue;

        ways= (ways * solve(child, 1, i))%mod;
    }

    return ret = (ret + ways)%mod;
}

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    cin>>n;
    adjList= vector<vector<int> > (n);
    clr(dp , -1);

    for(int  i = 0; i < n - 1; i++){
        int from,to;
        cin>>from>>to;

        adjList[from - 1].push_back(to - 1);
        adjList[to - 1].push_back(from - 1);
    }

    cout<<solve(0, 2, -1);

}


Measured memory_bytes: 15064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    ll S;
    vector<ll> v(N);
    for (int i = 0; i < N; ++i) {
        cin >> v[i];
        if (i == 0) S = v[i];
        else S ^= v[i];
    }

    for (int i = 0; i < N; ++i) {
        ll ans = S^v[i];
        cout << ans;
        if (i == N - 1) {
            cout << endl;
        } 
        else {
            cout << " ";
        }
    }
}

Measured memory_bytes: 4836
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int , input().split()))
    max_number = 10 ** 18
    result = 1
    if 0 in A:
        print(0)
        return
    for a in A:
        result = result * a
        if result > max_number:
            print(-1)
            return
    print(result)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 21844
#include <stdio.h>

int main(void){
    char line[201],line1[201];
    int t,i,num,h,o;
    for(;scanf("%s",line),line[0] != '-';){
        scanf("%d",&num);
        for(o=0;t=0,o<num;o++){
            scanf("%d",&h);
            for(i=0;i<h;i++)
                line1[i]=line[i];
            line1[i]=0;
            while(line[i])
                line[t++]=line[i++];
            i=0;
            while(line1[i])
                line[t++]=line1[i++];
            line[t]=0;
        }
        puts(line);
    }
}

Measured memory_bytes: 2600
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static BigInteger MOD = BigInteger.valueOf((long) 1e9 + 7);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i=0; i < n; i++)
            a[i] = in.nextInt();

        int[] maxl = new int[n];
        int[] maxr = new int[n];
        maxl[0] = a[0];
        maxr[0] = a[n-1];
        for (int i=1; i < n; i++) {
            maxl[i] = Math.max(maxl[i-1], a[i]);
            maxr[i] = Math.max(maxr[i-1], a[n-1-i]);
        }

        // out.println(Arrays.toString(maxl));
        // out.println(Arrays.toString(maxr));

        out.println(maxr[n-2]);
        for (int i=1; i < n-1; i++) {
            out.println(Math.max(maxl[i-1], maxr[n-2-i]));
        }
        out.println(maxl[n-2]);
    }

}


Measured memory_bytes: 70196
use proconio::input;

fn main() {
    input! {
        n: usize
    }

    let ans = {
        let mut count = 0;
        for a in 1..n {
            for b in 1..n {
                if a*b > n-1 {
                    break;
                }
                count += 1;
            }
        }
        count
    };

    println!("{}",ans)
}


Measured memory_bytes: 2172
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] chicket = new int[]{6000, 4000, 3000, 2000};
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()) {
			int t = stdIn.nextInt();
			int n = stdIn.nextInt();
			System.out.println(chicket[t - 1] * n);
		}
	}
}

Measured memory_bytes: 17364
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a,b,c;
    a=n/100;
    b=n%100/10;
    c=n%10;
    if(a==9) a=1;
    else a=9;
    if(b==9) b=1;
    else b=9;
    if(c==9) c=1;
    else c=9;
    printf("%d",a*100+b*10+c);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct state {
  int s;
  int x;
  int mark;
  int dis;
  state(int s, int x, int mark, int dis) :
    s(s), x(x), mark(mark), dis(dis) {}
};
// const bool operator<(const state &a, const state &b) {
//   return a.s!=b.s?a.s<b.s:a.x!=b.x?a.x<b.x:a.mark<b.mark;
// }

int dx[2] = {-1,1};
bool visited[1<<16][16][16];

int main() {
  int n;
  while(cin>>n,n) {
    string ss,tt;
    cin >> ss >> tt;
    int s=0, t=0;
    REP(i, n) {
      if (ss[i]=='W') s |= 1<<i;
      if (tt[i]=='W') t |= 1<<i;
    }
    
    queue<state> Q;
    REP(i, n) Q.push(state(s, i, -1, 0));
    int res;
    memset(visited,0,sizeof(visited));
    while(!Q.empty()) {
      state now = Q.front();
      Q.pop();

      if (visited[now.s][now.x][now.mark]) continue;
      visited[now.s][now.x][now.mark] = 1;

      //cout << now.s << " " << now.x << " " << now.mark << " " << now.dis << endl;
      if (now.s == t) {
        res = now.dis - 1;
        break;
      }

      int nd = now.dis + 1;
      REP(i, 2) {
        int nx = now.x + dx[i];
        if (nx<0||nx>=n) continue;
        
        if (now.mark == -1) {
          Q.push(state(now.s, nx, now.x, nd));
          Q.push(state(now.s, nx, -1, nd));
        } else {
          Q.push(state(now.s, nx, now.mark, nd));
          int tmp = now.s;
          if (now.s >> now.mark & 1) {
            tmp |= 1<<now.x;
          } else {
            if (now.s >> now.x & 1) tmp ^= 1<<now.x;
          }
          if (now.s >> now.x & 1) {
            tmp |= 1<<now.mark;
          } else {
            if (now.s >> now.mark & 1) tmp ^= 1<<now.mark;
          }
          Q.push(state(tmp, nx, -1, nd));
        }
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 30000
while True:
    m,f,r=map(int,input().split())
    grade = ''
    regular = m + f
    
    if m==-1 and f==-1 and r==-1:
        break
    
    if m==-1 or f==-1 or regular < 30:
        grade = 'F'
    
    elif regular >= 80:
        grade='A'
        
    elif regular >= 65 and regular < 80:
        grade = 'B'
    
    elif regular >= 50 and regular < 65:
        grade = 'C'
    
    elif regular >= 30 and regular < 50:
        if r >= 50:
            grade = 'C'
        else:
            grade = 'D'
    
    print(grade)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define tr(container , s ) for(auto x : container ){cout << x << s;} cout<<endl;
#define one(x) cerr<<#x<<" : "<<x<<endl;
#define two(x,y) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;

signed main()
{
    int a , b ,k;
    cin >> a >> b >> k;
    int x = a - k;
    if(a - k > 0 ){
        cout << x << " "<< b << endl;
    }
    else {
        b+=x;
        if(b > 0){
            cout << 0 << " " << b << endl;
        }
        else {
            cout << 0 << " " << 0 << endl;
        }
    }
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:268435456")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifndef _MSC_VER
#pragma GCC target ("sse4.2")
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <random>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;



int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	const int maxn = 1e6 + 5;
	vector<bool> ok(maxn, true);
	vi cnt(maxn);
	int n;
	cin >> n;
	set<int> a;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		cnt[x]++;
		a.insert(x);
	}
	int res = 0;
	if (*a.begin() == 1)
	{
		if (cnt[1] == 1)
			cout << 1;
		else
			cout << 0;
		return 0;
	}
	for (auto& x : a)
	{
		if (ok[x] && cnt[x] <= 1)
			res++;
		for (int i = 1; i * x < sz(ok); i++)
			ok[i * x] = false;
	}
	cout << res;
	
	return 0;
}

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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    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;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

x1, y1, r1 = map(int, raw_input().split())
x2, y2, r2 = map(int, raw_input().split())

dist = (x1 - x2) ** 2 + (y1 - y2) ** 2

if (r1 + r2) ** 2 < dist:
    print 4
elif (r1 + r2) ** 2 == dist:
    print 3
elif (r1 - r2) ** 2 < dist:
    print 2
elif (r1 - r2) ** 2 == dist:
    print 1
else:
    print 0


Measured memory_bytes: 5028
#include <stdio.h>
#include <stdlib.h>
#define NIL -1

typedef struct{
  //lは、left,rは、right,pは、parent//
  int p;
  int l;
  int r;
} T;
T t[1000005];

int main()
{
  int i,node,j,n,k,c[100005],depth=0,num;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    t[i].p=NIL;
    t[i].l=NIL;
    t[i].r=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&node,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c[j]);
      if(j==0){
	      t[c[0]].p=node;
        t[node].l=c[0];
      }
      else{
        t[c[j]].p=node;
        t[c[j-1]].r=c[j];
      }
    }
  }

  for(i=0;i<n;i++){
    
    num=i;
    while(t[num].p!=NIL){
      depth++;
      num=t[num].p;
    }

    printf("node %d: parent = %d, depth = %d,",i,t[i].p,depth);
    depth=0;
    if(t[i].p==NIL && t[i].l==NIL){
       printf(" root, []\n");
    }

    else if(t[i].p==NIL && t[i].l!=NIL){
      printf(" root, [%d",t[i].l);
      for(j=t[t[i].l].r;j!=NIL;j=t[j].r){
        printf(", %d",j);
      }
      printf("]\n");
    }

    else if(t[i].l!=NIL){
      printf(" internal node, [%d",t[i].l);
      for(j=t[t[i].l].r;j!=NIL;j=t[j].r){
        printf(", %d",j);
      }
      printf("]\n");
    }
    
    else{
      printf(" leaf, []\n");
    }
    
  }
  return 0;
}


  
    

      
          


Measured memory_bytes: 3300
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;

int h, w, m;
int h1[300005], w1[300005];
int H[300005], W[300005], maxH, maxW;
vector<int> dotH, dotW;
map<int, int> mp[300005];

int main() {
	scanf("%d%d%d", &h, &w, &m);
	for(int i=1;i<=m;i++) {
		scanf("%d%d", &h1[i], &w1[i]);
		++mp[h1[i]][w1[i]];
		if(++H[h1[i]] > maxH) {
			maxH = H[h1[i]];
			dotH.clear();
			dotH.push_back(h1[i]);
		}
		else if(H[h1[i]] == maxH) dotH.push_back(h1[i]);
		if(++W[w1[i]] > maxW) {
			maxW = W[w1[i]];
			dotW.clear();
			dotW.push_back(w1[i]);
		}
		else if(W[w1[i]] == maxW) dotW.push_back(w1[i]);
	}
	int ans = maxH + maxW;
	int l1 = dotH.size(), l2 = dotW.size();
	for(int i=0;i<l1;i++) {
		for(int j=0;j<l2;j++) {
			if(!mp[dotH[i]][dotW[j]]) {
				printf("%d\n", ans);
				return 0;
			}
		}
	}
	printf("%d\n", ans-1);
	return 0;
}

Measured memory_bytes: 38304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

ll solve() {
    ll N;
    cin >> N;
    ll NN = 1LL << N;
    vector<ll> A(NN);
    for ( int i = 0; i < NN; i++ ) {
        cin >> A[i];
    }
    vector<pii> tmp(5);
    vector<int> ix1(NN, -1), ix2(NN, -1); // ix1[k] (k|i)==kとなるiでA[i]が最大となるi
    ix1[0] = 0;
    for ( int k = 0; k < NN; k++ ) {
        for ( int i = 0; i < N; i++ ) {
            int h = k | (1 << i);
            if ( h == k ) continue;
            priority_queue<pii> q;
            q.push(pii(A[h],h));
            q.push(pii(ix1[h] >= 0 ? A[ix1[h]] : -1, ix1[h]));
            q.push(pii(ix1[k] >= 0 ? A[ix1[k]] : -1, ix1[k]));
            q.push(pii(ix2[h] >= 0 ? A[ix2[h]] : -1, ix2[h]));
            q.push(pii(ix2[k] >= 0 ? A[ix2[k]] : -1, ix2[k]));
            ix1[h] = q.top().second;
            while( q.top().second != -1 && ix1[h] == q.top().second ) q.pop();
            ix2[h] = q.top().second;
        }
    }

    ll m = 0;
    vector<ll> ans(NN);
    for ( int i = 1; i < NN; i++ ) {
        m = max(m, A[ix1[i]] + A[ix2[i]]);
        ans[i] = m;
    }

    for ( int i = 1; i < NN; i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <stack>


using namespace std;


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

    int n;
    cin >> n;
    long long res = 0;
    unordered_map<string, int> m;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (m.count(s)) {
            res += m[s];
            m[s]++;
        } else {
            m[s] = 1;
        }
    }

    cout << res;
    return 0;
}




Measured memory_bytes: 10660
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    r = 0
    for _ in range(n):
        a,b = LI()
        r += b-a+1

    return r

print(main())





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


int main(){
    int a,b,h;
    cin >> a >> b >> h;
    if(a+b==h)cout << "Yes" << endl;
    else if(a+h==b)cout << "Yes" << endl;
    else if(b+h==a)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int n, a, b, c;
int l[10];

int dfs(int i, int aa, int bb, int cc){
    if(i == n){
        if(aa == 0 || bb == 0 || cc == 0){
            return 1000000000;
        }else{
            return abs(a-aa) + abs(b-bb) + abs(c-cc);
        }
    }

    return min(dfs(i+1, aa, bb, cc),
            min(dfs(i+1, aa+l[i], bb, cc) + (aa == 0 ? 0 : 10),
                min(dfs(i+1, aa, bb+l[i], cc) + (bb == 0 ? 0 : 10),
                    dfs(i+1, aa, bb, cc+l[i]) + (cc == 0 ? 0 : 10))));
}



int main(){
    cin >> n >> a >> b >> c;

    for(int i = 0;i < n;i++){
        cin >> l[i];
    }

    cout << dfs(0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

const int maxn = 1e5+5;
char str[maxn];
int arr[127];
int main(){
    while(scanf("%s",str+1)!=EOF){
        bool sta = true;
        memset(arr,-1,sizeof(arr));
        for(int i=1;str[i];i++)
        if(arr[str[i]]==-1)
            arr[str[i]] = i;
        else if(i - arr[str[i]]<3){
            sta = 0;
            printf("%d %d\n",arr[str[i]],i);
            break;
        }else arr[str[i]] = i;


        if(sta)
            puts("-1 -1");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int calcb(double a, int q[]) {
  int i;
  for (i = 0; i < 4; i++) {
    a *= 2;
    if (a >= 1.0) {
      q[i] = 1;
      a -= 1.0;
    }
  }
  if (-0.000001 <= a && a <= 0.000001) return 1;
  return 0;
}

int calca(int a, int p[]) {
  if (a > 256) return 0;
  if (a >= 128) {
    p[0] = 1;
    a -= 128;
  }
  if (a >= 64) {
    p[1] = 1;
    a -= 64;
  }
  if (a >= 32) {
    p[2] = 1;
    a -= 32;
  }
  if (a >= 16) {
    p[3] = 1;
    a -= 16;
  }
  if (a >= 8) {
    p[4] = 1;
    a -= 8;
  }
  if (a >= 4) {
    p[5] = 1;
    a -= 4;
  }
  if (a >= 2) {
    p[6] = 1;
    a -= 2;
  }
  if (a == 1)
    p[7] = 1;
  return 1;
}

int main(void) {
  double n, b;
  int a, p[8], q[4], i, pos;

  while (1) {
    scanf("%lf", &n);
    if (n == -1.0) break;

    a = (int)n;
    b = n - (double)a;

    for (i = 0; i < 8; i++)
      p[i] = 0;
    for (i = 0; i < 8; i++)
      q[i] = 0;
    
    pos = 1;
    pos = calca(a, p);
    pos = calcb(b, q);

    if (pos == 0) {
      printf("NA\n");
    } else {
      for (i = 0; i < 8; i++)
	printf("%d", p[i]);
      putchar('.');
      for (i = 0; i < 4; i++)
	printf("%d", q[i]);
      putchar('\n');
    }
  }
  return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int a = ri();
	int b = ri();
	int c = ri();
	bool res = false;
	if (a == b && b != c) res = true;
	if (b == c && a != b) res = true;
	if (a == c && b != c) res = true;
	puts(res ? "Yes" : "No");
	return 0;
}


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

int main() {
	cin >> a;
	int n = a.length();
	int cnt = 0;
	if (n % 2 == 0) {
		int l;
		char m;
		l = n / 2;
		m = a[l-1];
		while (l-1-cnt>=0 && m == a[l-1 - cnt] && m == a[l + cnt]) {
			cnt += 1;
		}
		cout << l + cnt << endl;
	}
	else {
		int l;
		char m;
		l = n / 2;
		m = a[l];
		cnt = 1;
		while (l-cnt >= 0 && m == a[l - cnt] && m == a[l + cnt]) {
			cnt += 1;
		}
		cout << l + cnt << endl;
	}
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << (a[2] * 10 + a[1]) + a[0] << endl;
    return 0;
}



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

int Y[4]={-1,0,1,0};
int X[4]={0,1,0,-1};

bool in(int a,int b){
  if(a<0 || b<0 || 3<=a || 3<=b)return false;
  return true;
}

int main()
{
  int a;
  string start="",goal="123456780";

  for(int i=0;i<9;i++){
    cin>>a;
    start+=(a+'0');
  }
  
  queue<string> q;
  map<string,int> mp;
  mp[start]=0;
  q.push(start);
  while(!q.empty()){
    string u=q.front();
    q.pop();
    int s=-1,cost=mp[u];
    if(u==goal){
      cout<<mp[u]<<endl;
      break;
    }

    for(int i=0;i<u.length();i++){
      if(u[i]=='0')s=i;
    }

    int y=s/3,x=s%3;

    for(int i=0;i<4;i++){
      int ny=y+Y[i],nx=x+X[i];
      if(!in(ny,nx))continue;
      int index=ny*3+nx;
      string t=u;
      swap(t[s],t[index]);
      if(mp.find(t)==mp.end()){
	mp[t]=cost+1;
	q.push(t);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 21348