akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
  int x,a;
  scanf("%d",&x);
  a=x%10;
  switch(a){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      printf("hon\n");
      break;
    case 3:
      printf("bon\n");
      break;
    default:
      printf("pon\n");
  }
}

Measured memory_bytes: 1660
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    a = [int(i) for i in input().split()]

    print("APPROVED" if all((i % 3 == 0) or (i % 5 == 0) for i in a if i % 2 == 0) else "DENIED")


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29804
//#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
const unsigned int m = 1000000007; 



int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	string str; cin >> str;
	if (str == "ARC") cout << "ABC";
	else  cout << "ARC";
	return 0;
}


Measured memory_bytes: 3116
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {
    static final int UNCALC = -1;
    static final long INF = (long) 1e18;
    static final int mod = (int) (1e9 + 7);
    static int n, m;
    static char[] s, t;
    static int memo[][];
    static StringBuilder ans;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        s = sc.next().toCharArray();
        t = sc.next().toCharArray();
        n = s.length;
        m = t.length;
        memo = new int[n][m];
        for (int[] a : memo)
            Arrays.fill(a, UNCALC);
        dp(0, 0);
        ans = new StringBuilder();
        trace(0, 0);
        out.println(ans);
        out.flush();
        out.close();

    }

    static int dp(int i, int j) {
        if (i == n || j == m) return 0;
        if (memo[i][j] != UNCALC) return memo[i][j];
        int max = Math.max(dp(i + 1, j), dp(i, j + 1));
        max = Math.max(max, (s[i] == t[j] ? 1 : 0) + dp(i + 1, j + 1));
        return memo[i][j] = max;
    }

    static void trace(int i, int j) {
        if (i == n || j == m) return;
        int opt = memo[i][j];
        if (s[i] == t[j] && dp(i + 1, j + 1) == opt - 1) {
            ans.append(s[i]);
            trace(i + 1, j + 1);
            return;
        }
        if (opt == dp(i + 1, j)) {
            trace(i + 1, j);
            return;
        }
        if (opt == dp(i, j + 1)) trace(i, j + 1);
    }


    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }


    }

}


Measured memory_bytes: 81932
//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (ll i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
const ll M=2e3+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

map<pll,ll> mp;

ll v[M];
ll dasti(ll a,ll b)
{
    v[0]=0;
    ll z=1;
    For(i,a,b+1)
    {
        For(j,0,z)
        {
            v[j+z]=v[j]|i;
        }
        z*=2;
    }
    sort(v,v+z);
    //ER(a);ER(b);For(i,0,z) ER(v[i]);
    return unique(v,v+z)-v-(a>0);
}

ll check(ll a,ll b)
{
    return (b&(b-1))+1>=a;
}//*/

ll calc(ll a,ll b)
{
    if (a>b) return 0;
    if (a==b) return 1;
    if (mp[{a,b}]) return mp[{a,b}];
    ll res=0;
    /*if (b-a<5)
    {
        res=dasti(a,b);
    }//*/
    if (a%2==0)
    {
        res=2*calc(a/2,b/2);
        //if (b%2==0) res-=!check(a/2,b/2-1,b/2);
    }
    else
    {
        res=calc(a/2,b/2)+calc(a/2+1,b/2);
        //if (b%2==0) res-=!check(a/2,b/2-1,b/2);
    } 
    if (b%2==0) res-=!check(a,b);
    mp[{a,b}]=res;
    return res;
}

int main()
{
	ios::sync_with_stdio(0);
	ll a,b;
	cin >> a >> b;
	cout << calc(a,b);
}    


Measured memory_bytes: 256
str = input()
ans = 'WA'
if str[0] == 'A':
    cPlc = str.find('C')
    if cPlc >= 2 and cPlc <= len(str) - 2 and str.find('C',cPlc + 1) == -1:
        AllLower = True
        for i in range(1, len(str)):
            if str[i].isupper() and i != cPlc: AllLower = False
        if AllLower: ans = 'AC'
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   int n;
   cin>>n;
   map<int,int> mp;
   for(int i=0;i<n;i++)
    {
        int h;
        cin>>h;
        mp[h]++;
    }

   if(n%2!=0)
   {
       for(int i=2;i<=n-1;i+=2)
       {
        if(mp[i]!=2)
        {
            cout<<0;
            return 0;
        }
       }   
       if(mp[0]==1)
        cout<<power(2,n/2);
       else
        cout<<0;
   }
   else
   {
       for(int i=1;i<=n-1;i+=2)
       {
        if(mp[i]!=2)
        {
            cout<<0;
            return 0;
        }
       }
       if(mp[0]==0)
       {
        cout<<power(2,n/2);
       }
       else
        cout<<0;
   }
   
    return 0;
}








Measured memory_bytes: 6604
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"

#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define LINF ((ll)1 << 60)
#define INF (1 << 28)
template<typename T>
void chmax(T& a, T b) {
        if (a < b) a = b;
}
template<typename T>
void chmin(T& a,T b) {
        if (a > b) a = b;
}
bool debug = false;
//.....................
ull mod = (int)1e9 + 7;
const int MAX = (int)2e5 + 5;

ll N;
vector<ll> a;
ll res;

void solve() {
        cin >> N;
        a.resize(N);
        rep(i, N) cin >> a[i];
        rep(i, N) {
                res += a[i] / 2;
                a[i] %= 2;
                if (a[i] > 0 && i < N - 1 && a[i+1] > 0) {
                        res += 1;
                        a[i]--;
                        a[i+1]--;
                }
                if (debug) dump(res);
        }
        cout << res << endl;
}

signed main(int argc, char *argv[]) {
        int T = 1;
        cout << fixed << setprecision(20);
        rep(i, argc) {
                if (argv[i] == "-debug"s) {
                        debug = true;
                }
        }
        rep(i, T) {
                solve();
        }
        return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

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

	}

	public static void penInfo() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int cost;
		int costX = 0;
		int costY = 0;
		int numX = N / A;
		int numY = N / C;
		if (N % A != 0 ) {
			numX++;
		}
		costX = B * numX;
		if (N % C != 0 ) {
			numY++;
		}
		costY = D * numY;
		if (costX > costY) {
			cost = costY;
		} else {
			cost = costX;
		}
		System.out.println(cost);

	}
}



Measured memory_bytes: 26332
#include <iostream>
#include <cstdio>

using namespace std;

char a[4],b[4];

int main()
{
    scanf("%s",a);
    scanf("%s",b);
    for(int i = 2; i >= 0; i--)
    {
        if(a[i] != b[2-i]){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//B
int main(void) {
	int count = 0;
	string s;
	cin >> s;
	rep(0, s.size()) {
		char c = s[i];
		if (c == 'o')count++;
	}
	if ((15 - s.size()) + count >= 8)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define INF 1000000000
#define endl "\n"
#define all(s) s.begin(),s.end()
#define pb push_back
#define uno unordered_map
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define test(zz) int zz; cin>>zz; while(zz--)
#define foreach(var,i) for(auto i = var.begin();i!=var.end();i++)
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
ll power(ll a, ll n) {ll res = 1; while (n) {if (n % 2) {res *= a;} n >>= 1; a *= a;} return res;}
ll powerm(ll a, ll n, ll m) {ll res = 1; while (n) {if (n % 2) {res = (res * a) % m;} n >>= 1; a = (a * a) % m;} return res;}
using namespace std;

int main(){
	fast();
	//test(t){}
	int r,c,tar;
	cin>>r>>c>>tar;
	map<pair<int, int>, int> vis;
	map<int, int> row,col;
	int x,y,mx=0,my=0,pos_x,pos_y;
	for(int i=0;i<tar;i++){
		cin>>x>>y;
		vis[{x,y}] = 1;
		row[x]++; col[y]++;
		if(row[x]>mx){
			mx = row[x];
			pos_x = x;
		}
		if(col[y]>my){
			my = col[y];
			pos_y = y;
		}
	}
	int res, ma=0;
 	for(int i=1;i<=c;i++){
 		res = mx+col[i];
 		if(vis[{pos_x,i}]){
 			res--;
		}
		ma = max(ma,res);
		 
	}
	for(int i=1;i<=r;i++){
		res = my+row[i];
		if(vis[{i,pos_y}]){
			res--;
		}
		ma = max(res,ma);
	}
	cout<<ma<<endl;
	return 0;
}









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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int main() {
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3592
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline int read(){int r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e6+100;
const int MAXM = 1e5;
int main(){
	ll n,w,h;
	cin>>n>>w>>h;
	cout<<(n-h+1)*(n-w+1)<<endl;
	return 0;
}


Measured memory_bytes: 256
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn digit(num: u64) -> u64 {
    if num < 10 {
        1
    } else {
        digit(num / 10) + 1
    }
}

fn main() {
    let n = get_line().parse::<u64>().unwrap();
    println!("{}", (1..n + 1).map(|i| digit(i) % 2).sum::<u64>());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<"::"<<x<<endl;
using namespace std;
typedef long long ll;

void solve()
{
	ll n,w;
	cin>>n>>w;
	vector<ll>wt(n);
	vector<ll>val(n);
	for(ll i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	vector<vector<ll> >dp(n+1,vector<ll>(w+1));
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=w;j++)
		{
			if(j>=wt[i-1])
				dp[i][j]=max(dp[i-1][j-wt[i-1]]+val[i-1],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w]<<'\n';
}

int main()
{
	int t;
	t=1;
	while(t--)
		solve();
	return 0;
}

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

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

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
#define bit(n,k) ( (n>>k)&1 )

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end\n"<<endl;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));




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

    int H,W,K;
    cin>>H>>W>>K;
    char C[810][810];
    int d[810][810];
    for(int i=0;i<810;i++){
        for(int j=0;j<810;j++) d[i][j]=MAX;
    }
    int sh,sw;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>C[i][j];
            if(C[i][j]=='S') sh=i,sw=j;
        }
    }
    queue<pii> que;
    que.emplace(sh,sw);
    d[sh][sw]=0;
    while(!que.empty()){
        int h,w;
        tie(h,w)=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int nh=h+dx[i],nw=w+dy[i];
            if(nh<=H && nh>=1 && nw<=W && nw>=1 && d[nh][nw]==MAX && C[nh][nw]=='.'){
                d[nh][nw]=d[h][w]+1;
                que.emplace(nh,nw);
            }
        }
    }
    int ans=MAX;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(d[i][j]<=K){
                chmin(ans,i-1);
                chmin(ans,H-i);
                chmin(ans,j-1);
                chmin(ans,W-j);
            }
        }
    }
    cout<<(ans+K-1)/K+1<<endl;
}

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

int main() { /* ここに書く */
  
  long long N,K,A;
  int i = 0;
  cin >> N >> K ;
  
  if(N>K){
    A = N/K;
    N = N - K*A;}
  
  while (i<1){
    
    if(N>K){
      N = N-K;}
    
    else{
      if(N > K-N){
        N = K-N;}
      else if(N==K){
        N = 0;
        break;}
      else{
        break;} 
    }
  }
      cout << N << endl;
  
}

Measured memory_bytes: 256
K = int(input())
r = 7
ans = 1
s = set([])
while True:
    r %= K
    if r == 0:
        print(ans)
        break
    if r in s:
        print(-1)
        break
    s.add(r)
    r *= 10
    r += 7
    ans += 1


Measured memory_bytes: 77912
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64)::n,k,r,s,p,i,ans
    character(:),allocatable:: t
    logical,allocatable:: w(:)

    read*, n,k
    read*, r,s,p
    allocate(character(n):: t)
    read*, t
    allocate(w(n))

    ans=0
    do i=1,k
        ans=ans+win(t(i:i))
    end do
    w(1:k) = .true.
    w(k+1:) = .false.
    do i=k+1,n
        if (t(i:i)==t(i-k:i-k) .and. w(i-k)) cycle
        ans=ans+win(t(i:i))
        w(i) = .true.
    end do
    print'(i0)', ans

contains
    function win(ss) result(ret)
        character(1):: ss
        integer(int64):: ret

        if (ss=='r') then
            ret = p
        else if (ss=='p') then
            ret = s
        else
            ret = r
        end if
    end function
end program name

Measured memory_bytes: 1000
#include<iostream>
#include<set>
using namespace std;
int main()
{
  int n,t,sum,time;
  while(cin>>n){
    multiset<int>ms;
    multiset<int>::iterator it;
    while(n-->0){
      cin>>t;
      ms.insert(t);
    }
    sum=time=0;
    for(it=ms.begin();it!=ms.end();it++){
      time+=*it;
      sum+=time;
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
  int k,x;
  cin >> k>> x;
  k *= 500;
  if (k >= x)
    {
      cout << "Yes" <<endl;
    }
  else
    {
      cout << "No" << endl;
    }
}


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


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> v(n);
    FOR(i,0,n) cin>>v[i];
    sortAl(v);
    cout<<v[n/2] - v[n/2-1]<<endl;

}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a;
    cin>>b;
    if(a<b){
        
        cout<<"a < b"<<endl;
    }
    if(a>b){
        
        cout<<"a > b"<<endl;
    }
    if(a==b){
        
        cout<<"a == b"<<endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	ll sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
	ll dx=tx-sx,dy=ty-sy;
	rep(i,dy) cout<<"U";
	rep(i,dx) cout<<"R";
	rep(i,dy) cout<<"D";
	rep(i,dx) cout<<"L";
	cout<<"L";
	rep(i,dy+1) cout<<"U";
	rep(i,dx+1) cout<<"R";
	cout<<"D";
	cout<<"R";
	rep(i,dy+1) cout<<"D";
	rep(i,dx+1) cout<<"L";
	cout<<"U";
}

Measured memory_bytes: 256
t=[]
for _ in range(5):
    t.append(int(input()))
d=[0]*5
tt = [0]*5
for i in range(5):
    d[i] = t[i]%10 if t[i] %10!=0 else 10
    tt[i] =t[i]//10+1 if t[i]%10!=0 else t[i]//10
print(sum(tt)*10-10+min(d))


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A==B&&A!=C)printf("Yes");
  else if(A==C&&A!=B)printf("Yes");
  else if(B==C&&B!=A)printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,i,j,k,cm,count;
    bool flag;
    flag=false;
    cin >> N>>cm;
    count=0;
    long long int S[200010];

    for (i=0;i<N;i++){
        cin>>S[i];
        if (S[i]>=cm){
            count+=1;
        }
    }

    
        cout << count <<endl;
    
    return 0;
    
}


Measured memory_bytes: 4400
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace AtCoder
{
    enum Week
    {
        SAT = 1,
        FRI,
        THU,
        WED,
        TUE,
        MON,
        SUN
    }
    public class Program
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine();
            foreach (Week w in typeof(Week).GetEnumValues())
            {
                string day = Enum.GetName(typeof(Week), w);
                if (input == day) { Console.WriteLine((int)w); }
            }
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <sstream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
#include <list>

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")

using namespace std;

//ABC070B - Two Switches
int Main() {
	static const char EMPTY = '.';
	static const char BLACK = '#';
	int a, b, c, d, ans = 0;

	//input
	cin >> a >> b >> c >> d;

	//a b c d = 
	//a c b d = b-c
	//a c d b = d-c
	//c a b d = b-a
	//c a d b = d-a
	//c d a b = 
#define COND(a,b,c,d)	(a <= b && b <= c && c <=d)
	if (COND(a, b, c, d)) {
		ans = 0;
	}
	else if (COND(a, c, b, d)) {
		ans = b-c;
	}
	else if (COND(a,c,d,b)) {
		ans = d-c;
	}
	else if (COND(c,a, b,d )) {
		ans = b-a;
	}
	else if (COND(c, a, d, b)) {
		ans = d-a;
	}
	else if (COND(c, d, a, b)) {
		ans = 0;
	}

	cout << ans;

	return 0;
}


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=200010;

vector<vector<ll> > multiply(vector<vector<ll> > a,vector<vector<ll> > b)
{
    ll n=a.size();
    ll m=b[0].size();
    ll o=a[0].size();
    if(o!=b.size()){exit(1);}
    vector<vector<ll> > c(n,vector<ll>(m,0));
    for(ll i=0;i<n;++i)
    {
        for(ll j=0;j<m;++j)
        {
            c[i][j]=0;
            for(ll k=0;k<o;++k)
            {
                c[i][j]=(c[i][j] + (a[i][k]*b[k][j])%M)%M;
            }
        }
    }
    return c;
}

vector<vector<ll> > power(vector<vector<ll> > ar,ll n)
{
    if(n==1){return ar;}
    if(n%2==0)
    {
        return power( multiply(ar,ar) , n/2);
    }
    else
    {
        return multiply(ar,power(ar,n-1));
    }
}

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

    ll n,k;
    cin>>n>>k;
    vector<vector<ll> > ar;
    for(ll i=0;i<n;++i)
    {
        vector<ll> lol(n);
        for(ll j=0;j<n;++j)
        {
            cin>>lol[j];
        }
        ar.pb(lol);
    }

    ar=power(ar,k);

    ll ans=0;
    for(ll i=0;i<ar.size();++i){
        for(ll j=0;j<ar[i].size();++j)
        {
            ans=(ans+ar[i][j])%M;
        }
    }
    cout<<ans<<endl;

    return (0);
}


Measured memory_bytes: 5376
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;
 
int main()
{
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;
        int max = -1, min = 10000, sum = 0, score = 0, ans = 0;
        for(int i = 0; i < n; i++){
            cin >> score;
            sum += score;
            if(score > max) max = score;
            if(score < min) min = score;
        }
        sum -= max + min;
        ans = sum / (n - 2);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

ll MOD = 1000000007;

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

    ll a[n];

    ll ans = 0;

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

    for (ll i = 1; i < n; i++)
    {
        if (a[i - 1] > a[i])
        {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5156
import java.util.Scanner;
 
class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);  
        int a = scanner.nextInt();  
        int b = scanner.nextInt();
        int ans = (a - 1) * (b - 1);
        System.out.println(ans);
    }
}


Measured memory_bytes: 20820
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		int C=stdIn.nextInt();
		int D=stdIn.nextInt();
		int E=stdIn.nextInt();
		int a=(A/10+1)*10-A,b=(B/10+1)*10-B,c=(C/10+1)*10-C,d=(D/10+1)*10-D,e=(E/10+1)*10-E;
		int max=0;
		if(a>max&&a!=10)
			max=a;
		if(a==10)
			a=0;
		if(b>max&&b!=10)
			max=b;
		if(b==10)
			b=0;
		if(c>max&&c!=10)
			max=c;
		if(c==10)
			c=0;
		if(d>max&&d!=10)
			max=d;
		if(d==10)
			d=0;
		if(e>max&&e!=10)
			max=e;
		if(e==10)
			e=0;
		System.out.println(A+B+C+D+E+a+b+c+d+e-max);
	}
}

Measured memory_bytes: 21588
n=input()
n=int(n)
c=0
l=[]
h=list(map(int,input().split()))
for i in range(n-1):
  if h[i+1]<=h[i]:
    c+=1
  else:
    l.append(c)
    c=0
l.append(c)
print(max(l))

Measured memory_bytes: 14228
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;


#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>

void work() {
    int n;
    cin >> n;
    int odd = 0, even = 0;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        if (x & 1) odd++;
        else even++;
    }
    if (odd & 1) {
        cout << "NO" << endl;
        return;
    }
    cout << "YES" << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


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

static const int N = 100000;
static const int NIL = -1;

int n;
vector<int> g[N];
int color[N];

void dfs(int r,int c){
    stack<int> s;
    s.push(r);
    color[r] = c;
    while(!s.empty()){
        int u = s.top();
        s.pop();
        for(int i=0;i<g[u].size();i++){
            int v = g[u][i];
            if(color[v] == NIL){
                color[v] = c;
                s.push(v);
            }
        }
    }
}

void assign_color(){
    int id = 1;
    for(int i=0;i<n;i++) color[i] = NIL;
    for(int u=0;u<n;u++)
        if(color[u] == NIL) dfs(u,id++);
}

int main(){
    int m,s,t,q;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> s >> t;
        g[s].push_back(t);
        g[t].push_back(s);
    }

    assign_color();

    cin >> q;
    for(int i=0;i<q;i++){
        cin >> s >> t;
        if(color[s] == color[t])
            cout << "yes" << endl;
        else
            cout << "no"  << endl;
    }

}



Measured memory_bytes: 8932
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    double x,sum=0.0;
    string u;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>x>>u;
        if (u=="JPY") {
            sum+=x;
        } else {
            sum+=380000.0*x;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9
/*
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    In the blazing sun I saw you
    In the shadows hiding from yourself
    When the lights are on I know you
    See you're grey from all the lies you tell 
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin>>n;
    string s; cin>>s;
    ll ans=INF;
    vector<ll> w_beg(n,0),r_end(n,0);
    for(int i=0;i<n;i++){
        if(i){
            w_beg[i]=w_beg[i-1]+(s[i]=='W');
        }
        else{
            w_beg[i]=(s[i]=='W');
        }
    }
    for(int i=n-1;i>=0;i--){
        if(i==n-1){
            r_end[i]=(s[i]=='R');
        }
        else{
            r_end[i]=r_end[i+1]+(s[i]=='R');
        }
    }
    ans=min(w_beg[n-1],r_end[0]);
    for(int i=0;i<n-1;i++){
        ans=min(ans,max(r_end[i+1],w_beg[i]));
    }
    cout<<ans<<endl;
    return 0;
}



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

int main() {
    int s = 0;
    int h = 0, m = 0;
    cin >> s;

    h = s / 3600;
    s -= h * 3600;
    m = s / 60;
    s -= m * 60;

    cout << h << ":" << m << ":" << s << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  int ans = 0;
  rep2(i, 1, n+1){
    string s = to_string(i);
    if(s.size() % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int mod=1e9+7;
int32_t main()
{
	int n,m;
	cin>>n>>m;
	int x[n+1];
	int y[m+1];
	for(int i=1;i<=n;i++)cin>>x[i];
	for(int j=1;j<=m;j++)cin>>y[j];
	
	//ith element added i-1 times
	//subtracted n-i times
	int xs=0,ys=0;
	for(int i=1;i<=n;i++)
	{
		xs+=(((i-1)*x[i])%mod - ((n-i)*x[i])%mod + 2*mod)%mod;
		xs%=mod;
	}
	for(int i=1;i<=m;i++)
	{
		ys+=(((i-1)*y[i])%mod - ((m-i)*y[i])%mod + 2*mod)%mod;
		ys%=mod;
	}
	
	cout<<(ys*xs)%mod;
	
	
	
}

Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    if(n>=2*k-1){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
#East[north][top] -> E
class Dice():
 East = [ [0,3,5,2,4,0]
		 ,[4,0,1,6,0,3]
		 ,[2,6,0,0,1,5]
		 ,[5,1,0,0,6,2]
		 ,[3,0,6,1,0,4]
		 ,[0,4,2,5,3,0]
		 ]
 def __init__(self,N):
  self.label = N
  self.top = 1
  self.north = 5
 def move(self,ori):
  if ori=='S':
   t = self.top
   self.top = self.north
   self.north = 7-t
  elif ori=='N':
   t = self.top
   self.top = 7-self.north
   self.north = t
  elif ori=='E':
   east = self.East[self.north-1][self.top-1]
   self.top = 7-east
  elif ori=='W':
   east = self.East[self.north-1][self.top-1]
   self.top = east
 def gettop(self):
  return( self.label[self.top-1] )

label = list(map(int, input().split() ))
D = Dice(label)
command = input()
for ci in range(len(command)):
 D.move(command[ci])
 #print(D.top,D.north)
print(D.gettop())



Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    unsigned long long s;
    cin >> s;
    cout << 0 << " " << 0 << " " << (ll)1e9 << " " << 1 << " " << (s%(ll)1e9 == 0 ? 0 : (ll)1e9 - s%(ll)1e9) << " " << (s%(ll)1e9 == 0 ? s / (ll)(1e9) : (s / (ll)(1e9)) + 1 )  << endl;

//    cout << (ll)1e9*((s / (ll)(1e9)) + 1) - (ll)1e9 + s%(ll)1e9 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
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;}
const ll INF = 1e18+1;

/*
あるb(>= K+1)を固定すると
a % b >= K
なのは 
bn + b-1 , b-2,...., K なる数

このような数の範囲は

[K,.,b-1], [b+K,..,b+b-1], [2b+K,..,2b+b-1], ..[,N]

Nをbで割った商 * (b-K)個はぶち込める
残りはあまりの分

Nをbで割った商qとして
q*b+K ... N はぶち込める
*/

int main() {
    ll N, K; cin >> N >> K;
    if (K == 0) {
    cout << N * N << endl;
    return 0;
    }
    ll res = 0;
    for (int b = K+1; b <= N; b++) {
        ll q = N/b;
        res += q * (b-K);
        if (N % b >= K) {
            res += N % b - K + 1;
        }
        //cout << b <<" "<<  q << " " << q * (b-K) << " " << N - (q*b + K  - 1) << endl;
    }
    cout << res << endl;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
  ll x;      \
  cin >> x;  \
  while (x--) 

void cpc()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){ 
   
  ll a,b,c,k,sum=0;
  cin>>a>>b>>c>>k;
    if(k<=a){
      sum=k;
    }
    else if(k>a && k<=b+a){
      sum = a;
    }
    else{
      sum = a + (k-(a+b))*-1;
    }
    cout<<sum<<"\n";
  }


Measured memory_bytes: 3632
X, Y = map(int, input().split())
T = 0

if X == 1:
    T += 300000
elif X == 2:
    T += 200000
elif X == 3:
    T += 100000

if Y == 1:
    T += 300000
elif Y == 2:
    T += 200000
elif Y == 3:
    T += 100000

if X == 1 and Y == 1:
    T += 400000

print(T)

Measured memory_bytes: 3060
import heapq
n = int(input())
a = list(map(int, input().split()))

l = a[:n]
heapq.heapify(l)
memo_l = [0 for _ in range(n+1)]
memo_l[0] = sum(a[:n])

for i in range(1, n+1):
    memo_l[i] = memo_l[i-1]
    if l[0] < a[n+i-1]:
        x = heapq.heappop(l)
        heapq.heappush(l, a[n+i-1])
        memo_l[i] += a[n+i-1] - x


r = [-a[-i] for i in range(1, n+1)]
heapq.heapify(r)
memo_r = [0 for _ in range(n+1)]
memo_r[0] = sum(a[-n:])

for i in range(1, n+1):
    memo_r[i] = memo_r[i-1]
    if abs(r[0]) > a[-n-i]:
        x = heapq.heappop(r)
        heapq.heappush(r, -a[-n-i])
        memo_r[i] += x + a[-n-i]


ans = - 10 ** 20
for i in range(n+1):
    ans = max(ans, memo_l[i] - memo_r[n-i])

print(ans)

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

int main(){
	string s;
	cin >> s;
	int count = 0;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	for (int i=1; i<s.size(); i++){
		if ((i >=2 && i < s.size() - 1) && s[i] == 'C') count++;
		else if(s[i] < 'a' || s[i] > 'z') {
			cout << "WA" << endl;
			return 0;
		} 
	}
	if (count == 1)
		cout << "AC" << endl;
	else
		cout << "WA" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --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)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int N, M;
	cin >> N >> M;
	ll K;
	cin >> K;
	vector<ll> sumA(N + 1), sumB(M + 1);
	REP(i, N) {
		int a;
		cin >> a;
		sumA[i + 1] = sumA[i] + a;
	}
	REP(i, M) {
		int b;
		cin >> b;
		sumB[i + 1] = sumB[i] + b;
	}
	int res = 0;
	REP(a, N + 1) {
		ll t = sumA[a];
		if (t > K) break;
		int b = UB(sumB, K - t) - 1;
		if (b >= 0) {
			res = max(res, a + b);
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 6296
// https://www.youtube.com/watch?v=jQjnQJ9NPOY&list=PLn8m49B2OVF4kVTE0TK1PT-R0R9QhTVyS&index=1
#include<bits/stdc++.h>
using namespace std;
#define inf 1e18
#define int long long
#define ll long long
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define input(v) for(auto &i:v) cin>>i;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define forr(i , l , r) for(int i = int(l) ; i >= int(r); i--)
#define vi vector<int>
#define vii vector<vector<int>>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0);
void print(ll a)                  {              cout<<a<<'\t'<<'\n';}
void print(ll a,ll b)                {          cout<<a<<'\t'<<b<<'\t'<<'\n';}
void print(ll a,ll b,ll  c)             {      cout<<a<<'\t'<<b<<'\t'<<c<<'\n';}
void print(ll a,ll  b,ll  c,ll  d)         {   cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\n';}
void print(ll a,ll  b,ll  c,ll  d,ll  e)      { cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\t'<<e<<'\n';}
void print(vector<int> &a)  {for(auto i:a)  cout<<i<<" ";   nl;}
void print(string s)   {cout<<s, nl;}
void print(string s , ll a) { cout<<s<<"\t"<<a; nl;};
void print(string s , ll a , string ss , ll b) { cout<<s<<'\t'<<a<<'\t'<<ss<<'\t'<<b; nl;};


void sub(vector<int> &wt , vector<int> val , int idx , int tsum)
{

}


int32_t main()
{
    int n,weight,ans = 0;
    cin>>n>>weight;

    vi wt(n);
    vi val(n);

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

    vector<vector<int>> dp(n+1 , vector<int> (weight+1));

    dp[0][0] = 0;
    dp[0][wt[0]] = val[0];

    for(int i=1 ; i<n ; i++)
    {
        dp[i][0] = 0;
        for(int j=1 ; j<= weight ; j++)
        {
            // selected
            if(j >= wt[i])
                dp[i][j] = max(
                               dp[i][j],
                               dp[i-1][j-wt[i]] + val[i]
                               );

            // not selected;
            dp[i][j] = max(dp[i-1][j] , dp[i][j]);
        }
    }
    for(int i=0 ; i<= weight ; i++)
        ans = max(ans , dp[n-1][i]);

//    for(auto i : dp)
//    {
//        for(auto j : i)
//            cout<<j<<" ";
//        cout<<endl;
//    }
    cout<<ans;
}










// Connected Sum

/*

nodes edges
f   t   w

8 14
0 1 4
0 7 8
1 7 11
7 6 1
7 8 7
8 6 6
8 2 2
1 2 8
2 3 7
2 5 4
6 5 2
3 5 14
3 4 9
5 10 4

4   4
1	2	3
1	3	2
2	1	3
1	4	5

ans = 3;

*/






















Measured memory_bytes: 83004
import sys
sys.setrecursionlimit(10 ** 6)
N=int(input())
tree=[[] for _ in range(N)]
ans=[-1]*(N-1)
for i in range(N-1):
    a,b=map(int,input().split())
    tree[a-1].append((b-1,i))
    tree[b-1].append((a-1,i))
    
def dfs(now,prev=-1,color=0):
    color_num=1
    for i,j in tree[now]:
        if i==prev:
            continue
        if color_num==color:
            color_num=color_num+1
        ans[j]=color_num
        dfs(i,now,color_num)
        color_num=color_num+1

dfs(0)
print(max(ans))
for i in range(N-1):
    print(ans[i])

Measured memory_bytes: 85700
#include<bits/stdc++.h>
using namespace std;
int yy(int x,int y)
{
	if(x>=0) return x;
	return x+y;
}
int main()
{
	string a,b;
	cin>>a>>b;
	int L=a.length(),t;
	for(int i=0;i<L;i++)
	{
		t=0;
		for(int j=0;j<L;j++)
		{
			if(a[yy(j-i,L)]==b[j])
			{t++;}
		}
		if(t==L)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define RIGHT 1
#define LEFT -1
#define abs(n) ((n>0)?n:-n)
int x=0,cur=0,len,i,temp,xs[100001];
char s[100001],rem_x[100001];
void print(){
	for(int i=0;i<cur;i++){
		printf(" %c ",rem_x[i]);
	}
}
int next(int cur,int dir){
	int shift=1;
	cur+=dir;
	while(s[cur]=='x'){
		cur+=dir;
		shift++;
	}
	return shift;
}
int main(){
	scanf("%s",s);
	len=strlen(s);
	for(i=0;i<len;i++){
		if(s[i]!='x'){
			rem_x[cur]=s[i];
			cur++;
		}else{
			xs[cur]++;
		}
	}
	//print();
	for(i=0;i<cur/2;i++){
		if(rem_x[i]!=rem_x[cur-i-1]){
			printf("-1\n");
			return 0;
		}
	}
	for(i=(cur-1)/2;i>=0;i--){
		if(xs[i]>xs[cur-i])
			x+=(xs[i]-xs[cur-i]);
		else
			x-=(xs[i]-xs[cur-i]);
	}
	printf("%d\n",x);
	//print();
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#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=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 3){
        string s;
        cin >> s;
        cout << s[0];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int h, w;
  std::cin >> h >> w;

  std::vector<char> s(h * w);
  for (int i = 0; i < h; ++i) {
    std::string si;
    std::cin >> si;
    for (int j = 0; j < w; ++j) s[w * i + j] = si[j];
  }

  std::vector<int> l(h * w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      const auto k = w * i + j;
      if (s[k] == '#')
        l[k] = 0;
      else if (j == 0)
        l[k] = 1;
      else
        l[k] = l[k - 1] + 1;
    }
  }

  std::vector<int> r(h * w);
  for (int i = 0; i < h; ++i) {
    for (int j = w - 1; j >= 0; --j) {
      const auto k = w * i + j;
      if (s[k] == '#')
        r[k] = 0;
      else if (j == w - 1)
        r[k] = 1;
      else
        r[k] = r[k + 1] + 1;
    }
  }

  std::vector<int> u(h * w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      const auto k = w * i + j;
      if (s[k] == '#')
        u[k] = 0;
      else if (i == 0)
        u[k] = 1;
      else
        u[k] = u[k - w] + 1;
    }
  }

  std::vector<int> d(h * w);
  for (int i = h - 1; i >= 0; --i) {
    for (int j = 0; j < w; ++j) {
      const auto k = w * i + j;
      if (s[k] == '#')
        d[k] = 0;
      else if (i == h - 1)
        d[k] = 1;
      else
        d[k] = d[k + w] + 1;
    }
  }

  std::vector<int> count(h * w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      const auto k = w * i + j;
      count[k] = l[k] + r[k] + u[k] + d[k] - 3;
    }
  }

  const auto it = std::max_element(count.begin(), count.end());
  std::cout << *it << std::endl;
}


Measured memory_bytes: 82304