akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

ll dp[1010][1010];
int main(){
    int n,m;
    cin>>n>>m;
    ll x[n],y[n],z[n];
    
    REP(i,n){
        cin>>x[i]>>y[i]>>z[i];
    

    };
    ll sum=0;
    vector<ll>v[8];
    int cnt=0;
    for (int i = -1; i < 2; i++)
    {
        for (int j = -1; j < 2; j++)
        {
            for (int k = -1; k < 2; k++)
            {
                if(i==0 || j==0 || k==0) continue;
               // sum=0;
                for (int l = 0; l < n; l++)
                {
                    v[cnt].push_back(i*x[l]+j*y[l]+k*z[l]);
                }
                cnt++;
                //cerr<<cnt<<endl;
            }
        }
        
    }
   // cerr<<sum<<endl;
  
    for (int i = 0; i < 8; i++)
    {
        sort(v[i].rbegin(),v[i].rend());
    }
    // show(v[5]);
    ll maxn=0;
   // cerr<<1<<endl;
    for (int i = 0; i < 8; i++)
    {   sum=0;
        for (int j = 0; j < m; j++)
        {
            sum+=v[i][j];
        }
       // cerr<<sum<<endl;
        maxn=max(maxn,sum);
        
    }
    cout<<maxn<<endl;
    
    
    


    return 0;
}

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

# define ll long long
# define mod 1000000007
# define MAX 100005
# define PI 3.141592653589793238                                                                                  //shortcut keys

# define pb push_back
# define mp make_pair
# define all(x) x.begin(),x.end()
# define fr(i,a,b) for(int i=a;i<=b;i++)

# define decimal(k) fixed<<setprecision(k)
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------
using namespace std;

int main()
{
	int n;cin>>n;
	ll a[n+1],b[n+1];
	fr(i,1,n)cin>>a[i];
	b[1]=a[1];
	fr(i,2,n){
		if(a[i]>=b[i-1]){
			b[i]=a[i];
		}
		else b[i]=b[i-1];
	}
	//fr(i,1,n)cout<<b[i]<<' ';
	ll ans=0;
	fr(i,1,n)ans+=b[i]-a[i];
	cout<<ans<<'\n';

	return 0;
}



Measured memory_bytes: 6712
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
    int n;
    scanf("%d",&n);
    int a = -1, b = -1;
    for(int i = 1; i <= n; i++)
    {
        int u;
        scanf("%d",&u);
        if(u < a || a == -1) a = u;
        if(u > b) b = u;
    }
    printf("%d\n",b-a);
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

char s[5010];
int main(){
	scanf("%s",s);
	if(strlen(s)<3){
		puts("No");
		return 0;
	}
	while(s[1]){
		char temp[5010]={};
		int cnt=0;
		int n=strlen(s);
		int flag=0;
		int check=0;
		rep(i,0,n){
			if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
				temp[cnt++]='X';
				i+=2;
				check=1;
			}else{
				temp[cnt++]=s[i];
				flag|=1<<(s[i]-'A');
			}
		}
		if(cnt==1){
			puts("Yes");
			return 0;
		}else if((check&&(flag==3||flag==5||flag==6))){
			rep(i,0,cnt)if(temp[i]=='X')temp[i]=flag==3?'C':flag==5?'B':'A';
			memcpy(s,temp,5000);
		}else{
			puts("No");
			return 0;
		}
	}
}


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

int main()
{
    int N, p[110], ans = 0;
    cin >> N;
    REP(i, N) cin >> p[i];
    sort(&p[0], &p[N]);
    p[N - 1] /= 2;
    REP(i, N) ans += p[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void al(){
  cout <<"Alice"<<endl ;
}
void bo(){
  cout <<"Borys"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, b ;
  cin >> n >> a >> b ;
  if((b-a)%2==1){
    bo() ;
  }
  else{
    al() ;
  }
  
  
  
  
  return 0 ;
}




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

void get_next_str(char* s){
    int i;
    bool a[30];
    for(i = 0; i < 30; i++){
        a[i] = false;
    }
    
    i = 0;
    char last_c;
    while(s[i]){
        a[s[i] - 'a'] = true;
        last_c = s[i];
        i++;
    }

    int len = strlen(s);

    int j;
    for(j = 0; j < 30; j++){
        if(a[j] == false){
            break;
        }
    }

    s[len] = char(j + int('a'));
    s[len + 1] = '\0';

    return;
}

int main(void){
    char s[30];

    scanf("%s", s);

    if(strlen(s) != 26){
        get_next_str(s);
        printf("%s\n", s);
        return 0;
    }

    int i = 24;
    while(i + 1){
        if(s[i] > s[i + 1]){
            i--;
            continue;
        }
        s[i + 1] = '\0';
        break;
    }
    
    if(i == -1){
        printf("%d\n", -1);
        return 0;
    }

    int len = strlen(s);
    bool b[30];
    for(i = 0; i < 30; i++){
        b[i] = false;
    }

    i = 0;
    while(s[i + 1]){
        b[s[i] - 'a'] = true;
        i++;
    }
    char last_word = s[len - 1];
    int k = 1;

    while(1){
        if(b[last_word - 'a' + k]){
            k++;
            continue; 
        }
        s[len - 1] = char(int(last_word) + k);
        break;
    }

    printf("%s\n", s);

    return 0;

}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = input()

tmp = 0
for n in N:
	tmp += int(n)

print("Yes" if tmp%9 == 0 else "No")

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    Int ma = *max_element(all(a));
    vector<Int> prime(ma + 1);
    iota(all(prime), 0);
    for (Int i = 2; i <= ma; i++) {
        if (prime[i] < i) continue;
        for (Int j = 2; j * i <= ma; j++) {
            prime[i * j] = i;
        }
    }
    unordered_map<Int, Int> mp;
    mp.reserve(n);
    for (Int i = 0; i < n; i++) {
        Int x = a[i];
        while (x > 1) {   
            if (mp.find(prime[x]) != mp.end()) {
                Int b = a[0];
                for (Int j = 1; j < n; j++) {
                    b = gcd(b, a[j]);
                }
                if (b == 1) {
                    print("setwise coprime");
                } else {
                    print("not coprime");
                }
                return 0;
            }         
            mp[prime[x]]++;
            Int p = prime[x];
            while (x % p == 0) {
                x /= p;
            }
        }
    }
    print("pairwise coprime");
    return 0;
}


Measured memory_bytes: 27260
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0 || n==1)
    return dp[n]=1;

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

  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;

  for(i=0;i<50;i++)
    dp[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  std::cin >> N;
  long long sum = 0;
  long long x =0;
  long long ans = 0;
  std::vector<int> A(N,0);
  std::vector<int> X(N,0);
  for (size_t i = 0; i < N; i++) {
    int a;
    std::cin >> a;
    A[a-1]++;
    X[i] = a;
  }
  for (size_t i = 0; i < N; i++) {
    x = A.at(i);
    sum += x*(x-1)/2;
  }
  for (size_t i = 0; i < N; i++) {
     x = A[X[i]-1];
     if (x == 0) {
            ans = sum;
     }
     else{
       ans = sum -x+1;
     }
    std::cout <<ans << '\n';
  }
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>

using namespace std;

int dfs(string s);

inline int toInt(std::string s) {int v; std::istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {std::ostringstream sout;sout<<x;return sout.str();}


int main(int argc, char const *argv[])
{
	string s;
	int n;

	cin>>n;
	for(int i1=0;i1<n;i1++){
		cin>>s;
		cout<<dfs(s)<<endl;
	}

	return 0;
}

int dfs(string s)
{
	if(s[0]!='['){
		return toInt(s)/2+1;
	}
	else{
		int i1=0;
		int stc=0;
		vector<int> v;
		string tmp="";

		while(i1<s.size()){

			if(s[i1]==']') stc--;
			else if(s[i1]=='[') stc++;
			
			tmp+=s[i1];
			
			if(stc==0){
				v.push_back(dfs(tmp.substr(1,tmp.size()-2)));
				tmp="";
			}

			i1++;
		}

		sort(v.begin(),v.end());
		int sum=0;
		for(i1=0;i1<v.size()/2+1;i1++){
			sum+=v[i1];
		}

		return sum;
	}

}

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

int main(void){
  int n, x, i, m;
  scanf("%d", &n);
  char s[n-1];
  scanf("%s", &s);
  x = 0;
  i = 0;
  m = 0;
  while (i <= n) {
  	if (s[i] == 'I') {
    	x = x + 1;
    	if (x > m) m = x;
  	} else {
      x = x - 1;
    }
    i = i + 1;
  }
  printf("%d", m);
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str[8];
    for(int i=0;i<8;i++)cin>>str[i];
    cout<<"90\n";
    for(int i=0;i<8;i++){
        for(int j=7;j>-1;j--)cout<<str[j][i];
        cout<<endl;
    }
    cout<<"180\n";
    for(int i=7;i>-1;i--){
        for(int j=7;j>-1;j--)cout<<str[i][j];
        cout<<endl;
    }
    cout<<"270\n";
    for(int i=7;i>-1;i--){
        for(int j=0;j<8;j++)cout<<str[j][i];
        cout<<endl;
    }
}

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

using namespace std;

#define lli long long
#define ld long double
#define mod 1000000007 
#define set(n) cout << fixed << setprecision(n)    
#define fi first
#define se second
#define mp make_pair
#define pll pair<lli, lli>
#define endl '\n'

const double PI = acos(-1);
const double epsilon = 1e-7;  // floating point precision

signed main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x, t;
    cin >> n >> x >> t;
    int cnt = (n / x) * t + min(1, n % x) * t;
    cout << cnt << endl; 
}


Measured memory_bytes: 3648
import sys
input = sys.stdin.readline

def main():
    s=list(input())
    a,b=0,0
    for i in range(3):
        if s[i]=='A':
            a+=1
        else:
            b+=1
    if a*b==0:
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.math.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  }
}


Measured memory_bytes: 104604
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		int blue_count = sc.nextInt();
		for (int i = 0; i < blue_count; i++) {
			String line = sc.next();
			if (map.containsKey(line)) {
				map.put(line, map.get(line) + 1);
			} else {
				map.put(line, 1);
			}
		}
		
		int red_count = sc.nextInt();
		for (int i = 0; i < red_count; i++) {
			String line = sc.next();
			if (map.containsKey(line)) {
				map.put(line, map.get(line) - 1);
			} else {
				map.put(line, -1);
			}
		}
		
		int maxValue = 0;
		for (String key : map.keySet()) {
			if (map.get(key) > maxValue) {
				maxValue = map.get(key);
			}
		}
		
		System.out.println(maxValue);
	}
}

Measured memory_bytes: 21588
from collections import deque

n, m = map(int, input().split())
l = [[] for _ in range(n + 1)]

for i in range(1, m + 1):
    a, b = map(int, input().split())
    l[a].append(b)
    l[b].append(a)

q = deque([1])
s = [1] + [0] * n

while q:
    u = q.popleft()
    for v in l[u]:
        if not s[v]:
            s[v] = u
            q.append(v)
print('Yes')

for i in range(2, n + 1):
    print(s[i])

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

using namespace std;

typedef long long ll;

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

	int p, q, r;
	cin >> p >> q >> r;
	cout << min({p + q, q + r, r + p}) << endl;

}


Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_D

def reverse(s, a, b):
    s1 = s[0:a]
    s2 = s[a:b+1]
    s2 = s2[::-1]
    s3 = s[b+1:len(string)]
    return s1 + s2 + s3
def replace(s, a, b, p):
    s1 = s[0:a]
    s2 = p
    s3 = s[b+1:len(string)]
    return s1 + s2 + s3

string = input()
q = int(input())

for _ in range(q):
    c = input().split()

    if c[0] == "print":
        print(string[int(c[1]):int(c[2])+1])
    if c[0] == "reverse":
        string = reverse(string, int(c[1]), int(c[2]))
    if c[0] == "replace":
        string = replace(string, int(c[1]), int(c[2]), c[3])

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

struct State {
  int i, j, f;
};

const int MAXH = 21;
const int MAXW = 21;
const int MAXF = 1<<10;
int w, h, n;
vector<string> G;
int cost[MAXH][MAXW][MAXF];

int main() {
  while(cin >> w >> h && (w|h)) {
    G.resize(h);
    for(int i = 0; i < h; ++i) cin >> G[i];

    int si, sj;
    n = 0;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        if(G[i][j] == 'o') {
          si = i; sj = j;
        } else if(G[i][j] == '*') {
          G[i][j] = '0' + n++;
        }
      }
    }

    try {
      queue<State> que;
      que.push((State){si, sj, 0});
      memset(cost, -1, sizeof(cost));
      cost[si][sj][0] = 0;
      while(que.size()) {
        const State s = que.front();
        que.pop();
        for(int k = 0; k < 4; ++k) {
          int di = (2 - k) % 2;
          int dj = (1 - k) % 2;
          int ni = s.i + di;
          int nj = s.j + dj;
          if(ni < 0 || ni >= h) continue;
          if(nj < 0 || nj >= w) continue;
          int nf = s.f;
          if(G[ni][nj] == 'x') continue;
          if(isdigit(G[ni][nj])) {
            nf |= 1 << (G[ni][nj] - '0');
          }
          if(~cost[ni][nj][nf]) continue;
          que.push((State){ni, nj, nf});
          cost[ni][nj][nf] = cost[s.i][s.j][s.f] + 1;
          if(nf == (1 << n) - 1) {
            throw cost[ni][nj][nf];
          }
        }
      }
      throw -1;
    } catch(int res) {
      cout << res << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3156
N, K = map(int, input().split(" "))
list_num = ["0","1","2","3","4","5","6","7","8","9"]
D =  input().split(" ")

use_num = list(set(list_num) - set(D))
ok = []

for a in use_num:
    ok.append(a)
    for b in use_num:
        ok.append(a+b)
        for c in use_num:
            ok.append(a+b+c)
            for d in use_num:
                ok.append(a+b+c+d)
                for e in use_num:
                    ok.append(a+b+c+d+e)
ans = []
for i in ok:
    if int(i) >= N:
        ans.append(int(i))

print(min(ans))

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

int main()
{
    int l,r,d;
    cin >> l >> r >> d;
    
    int cnt = 0;
    for (int i =r; i >= l; i--){
        if((i % d) == 0){
            cnt++;
        }
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vi;
struct edge { int v; ll w; };

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
ll INF = INT_MAX;

struct skew_heap {
	skew_heap *lch, *rch;
	int val;
	skew_heap(int _val) : lch(NULL), rch(NULL), val(_val) {}
};

skew_heap* meld(skew_heap* x, skew_heap* y) {
	if (!x) return y;
	if (!y) return x;
	if (x->val < y->val) swap(x, y);
	x->rch = meld(x->rch, y);
	swap(x->lch, x->rch);
	return x;
}

skew_heap* push(skew_heap* x, int val) {
	return meld(x, new skew_heap(val));
}

skew_heap* pop(skew_heap* x) {
	return meld(x->lch, x->rch);
	skew_heap* y = meld(x->lch, x->rch);
	delete x;
	return y;
}

int main() {
	skew_heap* pq = NULL;
	for (;;) {
		char s[10]; scanf("%s", s);
		if (s[2] == 's') {
			int x; scanf("%d", &x);
			pq = push(pq, x);
		}
		if (s[2] == 't') {
			printf("%d\n", pq->val);
			pq = pop(pq);
		}
		if (s[2] == 'd') break;
	}
}

Measured memory_bytes: 50044
#include <bits/stdc++.h>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  string s; cin >> s;

  if(s[2] == s[3] && s[4] == s[5]){cout << "Yes" << "\n";}
  else{cout << "No" << "\n";}
  return 0;
}


Measured memory_bytes: 256
h,w=[int(i) for i in input().split()]
l=['n'*(w+2),'n'*(w+2)]
for _ in range(h):
	a=input()
	l.insert(1,'n'+a+'n')
l.reverse()
ans=['#'*w for i in range(h)]
for i in range(1,h+1):
	for j in range(1,w+1):
		cnt=0
		if l[i][j]=='#':continue
		if l[i][j+1]=='#':cnt+=1
		if l[i][j-1]=='#':cnt+=1
		if l[i-1][j-1]=='#':cnt+=1
		if l[i-1][j]=='#':cnt+=1
		if l[i-1][j+1]=='#':cnt+=1
		if l[i+1][j-1]=='#':cnt+=1
		if l[i+1][j]=='#':cnt+=1
		if l[i+1][j+1]=='#':cnt+=1
		ans_=list(ans[i-1])
		ans_[j-1]=str(cnt)
		ans_="".join(ans_)
		ans[i-1]=ans_
print('\n'.join(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define vll vector<ll>
#define here cout<<"I'm here\n";
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele;
}

int main() {
    SPEED;
    cout.precision(8);
    cout << fixed;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

#define COMMENT

int N, D, A, x, h;
vector<pair<ll, int> > X;
int H[1 << 20];

int main() {

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

  cin >> N >> D >> A;
  for(int i = 0;i < N;i++) {
    cin >> x >> h;
    int num_bombs = ceil(h * 1.0 / A);
    X.push_back(make_pair(x, num_bombs));
  }

  ll ans = 0;
  sort(X.begin(), X.end());
  for(int i = 0;i < N;i++) {
    if(i) H[i] += H[i-1];

    if(X[i].second + H[i] <= 0) continue;
    ans += X[i].second + H[i];
    int l = upper_bound(X.begin(), X.end(), make_pair(X[i].first + 2 * D, INT_MAX)) - X.begin() - 1;

    H[l+1] += X[i].second + H[i];
    H[i] += -(X[i].second + H[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6512
#include <iostream>

using namespace std;
int main()
{   int N,M;
    cin >>N>>M;
    if ( N==M ){ cout<<"Yes"<<endl;
        }
    else if (M>N){
        cout<<"error"<<endl;

    }
    else {
    cout << "No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i ,a, n) for (long long int i=a;i<=n;i++)
#define pb  push_back
#define mp make_pair
#define fp first
#define sp second
#define be(v) v.begin(),v.end()
typedef long long ll;
typedef vector<ll> vi ;
typedef vector<pair<ll , ll > >  vpi ;
const int ma1=3e5+5;
string no="NO",yes="YES";
#define MOD 1000000007
int max_char=26;
ll max1=1e15;
vector<ll> v[100005];
bool visited[100005];
ll dp[100005];



int main()
{
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    while(t--)
    {
         string s,s1;
         cin>>s>>s1;
         ll n,m;
         n=s.size();
         m=s1.size();
         ll dp[n+1][m+1];
         for(int i=0;i<=n;i++)
         {
             for(int j=0;j<=m;j++)
             {
                if(i==0 || j==0)
                    dp[i][j]=0;
             }
         }
         for(int i=1;i<=n;i++)
         {
             for(int j=1;j<=m;j++)
             {
                 if(s[i-1]==s1[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                 else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
             }
         }

         ll x=dp[n][m];
         string s2="";
         ll i=n,j=m;
         while(i>0 && j>0)
         {
             if(s[i-1]==s1[j-1] )
            {

               s2+=s[i-1];

                i--;j--;

             }
             else if(dp[i-1][j]>dp[i][j-1])
             {
                 i--;

             }
             else
             {

                 j--;
             }
         }
         reverse(be(s2));
         cout<<s2;
    }
    return 0;
}
















Measured memory_bytes: 76348
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  int ka[a];
  int kb[b];
  int kc[c];
  rep(i,a){
    cin >> ka[i];
  }
  rep(i,b){
    cin >> kb[i];
  }
  rep(i,c){
    cin >> kc[i];
  }
  sort(ka,ka+a);
  sort(kb,kb+b);
  sort(kc,kc+c);
  vector<int64_t> kcc(a+b,0);
  rep(i,c){
    kcc[i+1]=kcc[i]+kc[c-1-i];
  }
  vector<int64_t> f(x+y+1,0);
  queue<int> aa;
  queue<int> bb;
  rep(i,x){
    aa.push(ka[a-1-i]);
  }
  rep(i,y){
    bb.push(kb[b-1-i]);
  }
  rep(i,x+y){
    int r=i+1;
    int e=0;
    if(aa.front()>=bb.front()){
      e=aa.front();
      aa.pop();
    }
    else{
      e=bb.front();
      bb.pop();
    }
    f[r]=f[i]+e;
  }
  int64_t ans=0;
  rep(i,x+y+1){
    int p=x+y-i;
    ans=max(ans,kcc[i]+f[p]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
typedef pair<ll,ll> P;


int main(){
    ll n,m,k;cin>>n>>m>>k;
    ll a[200020],b[200020];
    rep(i,0,n)cin>>a[i];
    rep(i,0,m)cin>>b[i];
    ll M=m,an=0;
    rep(i,1,n)a[i]+=a[i-1];
    rep(i,1,m)b[i]+=b[i-1];
    for(int j=m-1;j>=0;j--){
        if(k>=b[j]){
            M=j+1;
            an=M;
            break;
        }
    }
    rep(i,0,n){
        if(a[i]>k)continue;
        for(int j=M-1;j>=0;j--){
            ll K=k-a[i];
            if(K>=b[j]){
                M=j+1;
                break;
            }
            if(j==0&&K<b[j]){
                M=0;
            }
        }
        an=max(an,M+i+1);
    }
    cout<<an<<endl;
}

    









Measured memory_bytes: 6756
#include <stdio.h>

int main(){
	int i,j,k;
	int a,b,c;
	int n[200]={0};
	while(1){
		scanf("%d",&a);
		if(a==0){
			break;
		}
		b=0;
		while(a){
			n[b]=a%8;
			a/=8;
			b++;
		}
		
		
		n[b]=0;
		c=0;
		i=0;
		while(i<=b){
			
			if(n[i]>3){
				n[i]++;
			}
			if(n[i]>5){
				n[i]++;
			}
			i++;
		}
		for(i=b-1;i>=0;i--){
			printf("%d",n[i]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char s[10];
int main(){
	scanf("%s",s);
	for(int i=1;i>=-1;i-=2)
		for(int j=1;j>=-1;j-=2)
			for(int k=1;k>=-1;k-=2){
				if(s[0]-'0'+i*(s[1]-'0')+j*(s[2]-'0')+k*(s[3]-'0')==7){
					printf("%c%c",s[0],i==1 ? '+' : '-');
					printf("%c%c",s[1],j==1 ? '+' : '-');
					printf("%c%c",s[2],k==1 ? '+' : '-');
					printf("%c=7",s[3]);
					return 0;
				}
			}
	return 0;	
}

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

int main() {
	int n,m,k;
	cin>>n>>m>>k;
	ll a[n+5],b[m+5];
	ll ans=0;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	    if(i>0)a[i]+=a[i-1];
        if(a[i]<=k) ans=i+1;
	}
	
    ll temp=0;
    for(ll i=0; i<m; i++){
        cin>>b[i];
        temp+=b[i];
        if (temp>k) break;
        ll resto=k-temp;
        ll  in= upper_bound(a,a+n,resto)-a;
        ans=max(ans,in+i+1LL);
    }
    
    cout<<ans<<"\n";
	return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")

template<typename T> T DUP(T x, T y) { return (x + y - 1) / y; };

using ll = std::int64_t;
using vint = std::vector<std::int32_t>;
using vll = std::vector<ll>;
using vstr = std::vector<std::string>;
using pint = std::pair<std::int32_t, std::int32_t>;
using usetint = std::unordered_set<std::int32_t>;
using usetstr = std::unordered_set<std::string>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int k;
    cin >> k;
    cout << DUP(k, 2) * (k / 2) << endl;
}

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


Measured memory_bytes: 256
N = input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0

for i, b in enumerate(B):
    if(A[i] > b):
        count += b
    else:
        sum_monster = A[i] + A[i+1]
        killed_monster = min(b, A[i] + A[i+1])
        count += killed_monster
        A[i+1] = sum_monster - killed_monster
        
print(count)

Measured memory_bytes: 19116
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <numeric>
#include <tuple>

// さんこう :https://beta.atcoder.jp/contests/abc109/submissions/3153889
using namespace std;

typedef long long ll;

int H, W;
int a[510][510];

int main() {
   cin >> H >> W;
   int N = 0;
   for (int i=0;i<H;i++) {
      for (int j=0;j<W;j++) {
         cin >> a[i][j];
      }
   }

   vector< tuple< int, int, int, int > > tt;

   for (int i=H-1;i>=0;i--) {
      if (i % 2 == 0) {
         for (int j=0;j<W;j++) {
            if (a[i][j] % 2 == 1) {
               a[i][j]--;
               if (j+1 == W) {
                  // W にあるときの処理
                  if (i>0) {
                     tt.emplace_back(i, j, i-1, j);
                     a[i-1][j]++;
                  }
               } else {
                  //下の行から右に行って上に行って
                  tt.emplace_back(i, j, i, j+1);
                  a[i][j+1]++;
               }
            }
         }
      } else {
         for (int j=W-1;j>=0;j--) {
            if (a[i][j] % 2 == 1) {
               a[i][j]--;
               if (j == 0) {
                  if (i > 0) {
                     tt.emplace_back(i, j, i-1, j);
                     a[i-1][j]++;
                  }
               } else {
                  // ←に行く行
                  tt.emplace_back(i, j, i, j-1);
                  a[i][j-1]++;
               }
            }
         }
      }
   }
   cout << tt.size() << endl;
   for (auto &p : tt) {
      int a, b, c, d;
      tie(a, b, c, d) = p;
      cout << a+1 << " " << b+1 << " " << c+1 << " " << d+1 << endl;
   }
   
   return 0;
}


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


int main(){
    long long h, w;
    cin >> h >> w;

    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }

    long long m, n;
    if(h % 2 == 0){
        m = h / 2;
        n = h / 2;
    }else{
        m = h / 2 + 1;
        n = h / 2;
    }

    long long ans;
    if(w % 2 == 0){
        ans = (m + n) * (w / 2);
    }else{
        ans = (m + n) * (w / 2) + m;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

vector<int> eratosthenes(int n) {
	vector<int> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;

	for (int i = 2; i <= n; i++) {
		if (!isPrime[i]) {
			continue;
		}

		for (int j = 2 * i; j <= n; j += i) {
			isPrime[j] = false;
		}
	}

	return isPrime;
}

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

	vector<int> isPrime = eratosthenes(60000);

	int n;
	cin >> n;

	vector<int> ans;
	for (int i = 2; ans.size() != n; i++) {
		if (!isPrime[i]) {
			continue;
		}

		if (i % 5 == 1) {
			ans.emplace_back(i);
		}
	}

	for (int i = 0; i < ans.size(); i++) {
		if (i) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 512
#最初に置いておくもの
import copy
import sys
sys.setrecursionlimit(50000000) 

#入出力関係
N, M = map(int, input().split())
l = []

for i in range(M):
    l.append(list(map(lambda x: int(x)-1 , input().split())))

lis = [[] for i in range(N)]

for i in range(M):
    lis[l[i][0]].append(l[i][1])
    lis[l[i][1]].append(l[i][0])

def dfs():
    re=0
    q1 =[[0]*N]
    q2=[0]
    while len(q1) != 0:
         
        visited=q1.pop()
        v=q2.pop()
        visited[v]=1
        if all(visited[c]==1 for c in range(N)):
            re += 1
        elif len(lis[v]) != 0:
            for i in lis[v]:
                if visited[i] == 0:
                    hoge=copy.deepcopy(visited)                    
                    q1.append(hoge)
                    q2.append(i)
    return re

print(dfs())


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

int main() {
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    map<int,int> pw,ps;
    for (int i = 0; i < f/a; ++i) {
        for (int j = 0; j < f/b; ++j) {
            int t=a*100*i+b*100*j;
            if(t<=f&&t!=0)pw[t]=1;
        }
    }
    for (int i = 0; i < f/c; ++i) {
        for (int j = 0; j < f/d; ++j) {
            int t=c*i+d*j;
            if(t<=f)ps[t]=1;
        }
    }
    double m=-1;
    pair<int,int> ans;
    for (auto s : ps) {
        for (auto w:pw){
            if(s.first*(100+e)<=e*(w.first+s.first)&&w.first+s.first<=f){
                if(m<double(s.first)/double((w.first+s.first))){
                    m=double(s.first)/double((w.first+s.first));
                    pair<int,int> t(w.first+s.first,s.first);
                    ans = move(t);
                }
            }
        }
    }
    cout<<ans.first<<" "<<ans.second<<endl;
    return 0;
}

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

int n;

int ans;
vector<pair<int, int>> seq;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    vector<int> a(n);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end());
    
    if (a[n - 1] <= 0) {
		ans = a[n - 1];
		for (int i = 0; i < n - 1; i++) {
			seq.push_back({ans, a[i]});
			ans -= a[i];
		}
	} else {
		ans = a[0];
		for (int i = 1; i < n - 1; i++) {
			if (a[i] >= 0) {
				seq.push_back({ans, a[i]});
				ans -= a[i];
			}
		}
		seq.push_back({a[n - 1], ans});
		ans = a[n - 1] - ans;
		for (int i = 1; i < n - 1; i++) {
			if (a[i] < 0) {
				seq.push_back({ans, a[i]});
				ans -= a[i];
			}
		}
	}
	
	cout << ans << "\n";
	for (auto& i : seq) cout << i.first << " " << i.second << "\n";
    return 0;
}


Measured memory_bytes: 3316
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 ABCD = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var answer = Math.Min(ABCD[1], ABCD[3]) - Math.Max(ABCD[0], ABCD[2]);
            Console.WriteLine(Math.Max(0, answer));
        }
    }
}


Measured memory_bytes: 28288
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = 0

before = None
for a in A:
    ans += B[a-1]
    if before is not None:
        if a - before == 1:
            ans += C[a-2]
    before = a

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll a[100000], n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll s = 0;
  FOR(i, 0, n){
    cin >> a[i];
    s += a[i];
  }
  if(s%((n+1)*n/2)){
    cout << "NO" << endl;
    return 0;
  }
  s /= (n+1)*n/2;
  FOR(i, 0, n){
    ll d = a[i] + s - a[(i+1)%n];
    if(d<0 || d%n){
      cout << "NO"<<endl;
      return 0;
    }
  }
  cout << "YES"<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll d, t, s;
  cin >> d >> t >> s;
  if(d>t*s){
    cout << "No";
  }else{
    cout << "Yes";
  }
  return 0;
}


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

typedef struct range
{
  int a;
  int z;
  struct range *next;
} range;


range *rangenew(int r1, int r2, range *nx)
{
  range *rng;
  rng = (range *)malloc(sizeof(range));
  rng->a = r1;
  rng->z = r2;
  rng->next = nx;
  return rng;
}

range *insert(range *line, int r1, int r2)
{
  range *rng;
  int z2;
  if(line == NULL){
    return rangenew(r1, r2, NULL);
  }
  if(line->z < r1){
    line->next = insert(line->next, r1, r2);
    return line;
  }
  if(r2 < line->a){
    return rangenew(r1, r2, line);
  }
  line->a = (r1 < line->a ? r1 : line->a);
  z2 = line->z;
  rng = line->next;
  while(rng != NULL && rng->a <= r2) {
    z2 = rng->z;
    free(rng);
    rng = rng->next;
  }
  line->z = (r2 > z2 ? r2 : z2);
  line->next = rng;
  return line;
}

void linefree(range *line)
{
  if(line){
    free(line);
    linefree(line->next);
  }
}

int counts(range *line)
{
  return line ? counts(line->next)+(line->z-line->a) : 0;
}

int count(range *line)
{
  return line ? count(line->next)+1 : 0;
}
 
int main()
{
  int n, t;
  range *sheetx[10000]; // x~x+1??§?????¨?????\??£?????????y?????????
  range *sheety[10000];
  int i;
  int x, y;
  int x1, y1, x2, y2;
  int s, l;
  
  scanf("%d %d", &n, &t);
  while(n!=0 && t!=0){
    s = l = 0;
    for(i=0; i<10000; i++){
      sheetx[i] = sheety[i] = NULL;
    }
    for(i=0; i<n; i++){
      scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
      for(x=x1; x<x2; x++){
        sheetx[x] = insert(sheetx[x], y1, y2);
      }
      for(y=y1; y<y2; y++){
        sheety[y] = insert(sheety[y], x1, x2);
      }
    }
  
    for(i=0; i<10000; i++){
      s += counts(sheetx[i]);
    }
    printf("%d\n", s);
    if(t == 2){
      for(i=0; i<10000; i++){
        l += count(sheetx[i]);
        l += count(sheety[i]);
      }
      printf("%d\n", l*2);
    }
    for(i=0; i<10000; i++){
      linefree(sheetx[i]);
      linefree(sheety[i]);
    }
    scanf("%d %d", &n, &t);
  }
  return 0;
}

Measured memory_bytes: 1632
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main(){

    string s;

    cin >> s;    

    int n;

    n=s.size();

    string t,u,v,w,x;

    v=s;
    u=s.substr(0,(n-1)/2);
    t=s.substr(0,(n-1)/2);
    w=s.substr((n+1)/2,n-1);
    x=s.substr((n+1)/2,n-1);

    
    for(int i=0;i<n;i++){
        v[i]=s[n-i-1];
    }

    for(int i=0;i<(n-1)/2;i++){
        t[i]=u[(n-1)/2-1-i];
    }


    for(int i=0;i<(n-1)/2;i++){
        x[i]=w[(n-1)/2-i-1];
    }

    if(s == v && t == u && w == x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    

    /*
    for(int i=1;i<(n-1)/2;i++){
        t[i]=s[i];
    }

    for(int i=(n+3)/2;i<=n;i++){
        u[i-(n+3)/2+1]=s[i];
    }

    if(s == reverse(s.begin(),s.end()) && u == reverse(u.begin(),u.end()) && t == reverse(t.begin(),t.end())){
        cout << "Yes" << endl;
    }
    else 
        cout << "No" << endl;
    

*/


}

Measured memory_bytes: 256
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(N)]
 
res = 0
 
for i in range(8): # x, y, z を正にするか負にするか8通り試す
    D = [0 for _ in range(N)]
    for j in range(N):
        x, y, z = C[j]
        if (i >> 0) & 1:
            D[j] += x
        else:
            D[j] -= x
        if (i >> 1) & 1:
            D[j] += y
        else:
            D[j] -= y
        if (i >> 2) & 1:
            D[j] += z
        else:
            D[j] -= z
    D.sort(reverse=True)
    res = max(res, sum(D[:M])) # その中で一番大きいものM個をとる
 
print(res)

Measured memory_bytes: 9272
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using GraphI = vector<vector<int>>;
using GraphC = vector<vector<char>>;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  int m = 0, tot = 0;
  rep(i, 0, N) {
    cin >> p[i];
    tot += p[i];
    m = max(m, p[i]);
  }
  tot -= (m / 2);
  cout << tot << endl;
  return 0;
}


Measured memory_bytes: 3632
import copy
import itertools
import sys

if sys.version[0] == '2':
    range, input = xrange, raw_input

drc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
C_NUM = 6

def dfs(r, c, now_c, next_c):
    tmp_board[r][c] = next_c
    for dr, dc in drc:
        nr, nc = r + dr, c + dc
        if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c:
            dfs(nr, nc, now_c, next_c)


while True:
    H, W, C = map(int, input().split())
    if not (H | W | C):
        break
    board = [[int(x) - 1 for x in input().split()] for _ in range(H)]
    ans = 0
    for ope in itertools.product(range(C_NUM), repeat=5):
        # print(ope)
        if ope[0] == board[0][0] or ope[-1] != C - 1 or any(ope[i] == ope[i + 1] for i in range(4)):
            continue
        tmp_board = copy.deepcopy(board)
        for color in ope:
            dfs(0, 0, tmp_board[0][0], color)
        dfs(0, 0, tmp_board[0][0], -1)
        cand = sum(row.count(-1) for row in tmp_board)
        if cand > ans:
            ans = cand
    print(ans)

Measured memory_bytes: 8216
N, L = list(map(int, input().split()))
T = [L + i for i in range(N)]
sum_T = sum(T)
if T[0] < 0 and T[-1] >= 0:
  print(sum_T)
  exit()
elif T[-1] < 0:
  print(sum_T - T[-1])
  exit()
else:
  print(sum_T - T[0])

Measured memory_bytes: 3060