akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define input(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int n, k, ans;
signed main() {
	cin >> n >> k;
	for (int i = k + 1; i <= n; i++) {
		ans += (n / i)*(i - k);
		if (n%i >= k)ans += (n%i) - k + 1;
		if (k == 0)ans--;
	}
	cout << ans << endl;
	endre;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);
    long A = scanner.nextLong();
    long V = scanner.nextLong();
    long B = scanner.nextLong();
    long W = scanner.nextLong();
    long T = scanner.nextLong();

    long speed = V - W;
    long dist = Math.abs(B - A);
    if(speed <= 0) {
      System.out.println("NO");
      return;
    }

    System.out.println((dist - speed * T <= 0) ? "YES" : "NO");

              
  }

}


Measured memory_bytes: 35696
#include <iostream>
#include <string>

int main() {
  std::string S, T;
  std::cin >> S >> T;

  int n = S.length();
  for (int i = 0; i < n; ++i) {
    if ( S[i] == T[i] ) continue;
    char c1 = S[i];
    char c2 = T[i];
    for (int j = 0; j < n; ++j) {
      if ( S[j] == c1 ) {
        S[j] = c2;
        continue;
      }
      if ( S[j] == c2 ) {
        S[j] = c1;
      }
      if ( j < i && S[j] != T[j] ) break;
    }
  }
  if ( S == T ) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 776
S=list(input())
n=len(S)

from itertools import product

PL=list(product(['+',''],repeat=n-1))

ans=0
for pl in PL:
    SS=S.copy()
    for i,p in enumerate(pl):
        SS.insert(i*2+1,p)
    ans+=eval(''.join(SS))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i,n){
    cin >> c.at(i);
    rep(j,m){
      cin >> a.at(i).at(j);
    }
  }
  
  
  int ans = inf;
  rep(i,1<<n){
    vector<int> skl(m,0);
    int cost=0;
    bool flag = 1;
    rep(j,n){
      if((i >> j)&1 == 1) {
        cost += c.at(j);
        rep(k,m) {
          skl.at(k) += a.at(j).at(k);
        }
      }
    }
    rep(j,m){if(skl.at(j) < x) flag = 0;}
    if(flag) ans = min(cost,ans);
  }
  
  if(ans == inf) cout << -1 << endl;
  else cout << ans << endl;
  
}

Measured memory_bytes: 3620
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long X = sc.nextLong();
        System.out.println(eatPatty(X, N));
    }

    static long layerTotal(int N) {
        if(N == 0) return 1;
        else return 2*layerTotal(N-1) + 3;
    }

    static long pattyTotal(int N) {
        if(N == 0) return 1;
        else return 2*pattyTotal(N-1) + 1;
    }

    static long eatPatty(long X, int N) {
        if(N == 0) 
            return 1;
        else {
            if(X == 1) 
                return 0;
            else if(1 < X && X <= layerTotal(N-1)+1) 
                return eatPatty(X-1, N-1);
            else if(X == 2+layerTotal(N-1)) 
                return pattyTotal(N-1) + 1;
            else if(2+layerTotal(N-1) < X && X <= 2*layerTotal(N-1)+2) 
                return pattyTotal(N-1) + 1 + eatPatty(X-2-layerTotal(N-1), N-1);
            else 
                return 2*pattyTotal(N-1) + 1;
        }
    }
}

Measured memory_bytes: 23380
#include<iostream>
#include<vector>

int main(){
	long long int h,n,k=0;
	std::cin>>h>>n;

	std::vector<long long int> v;

	for (int i = 0; i < n; i++) {
		long long int x;
		std::cin >> x;
		v.push_back(x);
		k +=x;
	}

	if (k >= h) {
		std::cout<<"Yes"<<std::endl;
		exit(0);
	}else {
		std::cout << "No" << std::endl;
		exit(0);
	}

	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

ll GCD(ll n, ll m){
    return m ? GCD(m,n%m):n;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll g = GCD(n,m);
    ll res = n/g * m;
    n /= g;
    m /= g;
    bool ok = true;
    for(ll i=0;i<g;i++){
        if(s[i*n] != t[i*m]) ok=false;
    }
    if(ok) cout<<res<<endl;
    else cout<<-1<<endl;

}

Measured memory_bytes: 640
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = l()

co = []

co.append(a[0])

for i in range(n-1):
    if i == n-2:
        co.append(a[i])
    else:
        co.append(min(a[i],a[i+1]))
print(sum(co))

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

int N;
int V[105];

int main()
{
    cin >> N;
    for(int i = N; i >= 2; i--){
        int n = i;
        for(int j = 2; j * j <= n; j++){
            while(n % j == 0){
                V[j]++;
                n /= j;
            }
        }
        if(n != 1){
            V[n]++;
        }
    }
    int s = N + 1;
    int ans = 0;
    for(int i = 2; i < s; i++){
        if(V[i] == 0)continue;
        for(int j = i + 1; j < s; j++){
            if(V[j] == 0)continue;
            for(int k = j + 1; k < s; k++){
                if(V[k] == 0)continue;
                if(V[i] >= 4 && V[j] >= 4 && V[k] >= 2){
                    ans++;
                }
                if(V[i] >= 4 && V[j] >= 2 && V[k] >= 4){
                    ans++;
                }
                if(V[i] >= 2 && V[j] >= 4 && V[k] >= 4){
                    ans++;
                }

                //printf("%d %d %d\n", V[i], V[j], V[k]);
            }
            if(V[i] >= 24 && V[j] >= 2){
                ans++;
            }
            if(V[i] >= 14 && V[j] >= 4){
                ans++;
            }
            if(V[i] >= 2 && V[j] >= 24){
                ans++;
            }
            if(V[i] >= 4 && V[j] >= 14){
                ans++;
            }
            //printf("%d %d\n", V[i], V[j]);
        }
        if(V[i] >= 74){
            ans++;
        }
        //printf("%d\n", V[i]);
    }
    cout << ans << endl;

    return 0;
}


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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

int main() {
    for(int i = 0; i < 3; ++i) {
        int S, T;
        int h, m, s;
        cin >> h >> m >> s;
        S = h * 3600 + m * 60 + s;
        cin >> h >> m >> s;
        T = h * 3600 + m * 60 + s;
        int R = T - S;
        cout << R / 3600 << ' ';
        R %= 3600;
        cout << R / 60 << ' ' << R % 60 << endl;
    }
}


Measured memory_bytes: 3092
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (int A, B; cin >> A >> B; cout << A + B << endl);
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<ll>> a(3, vector<ll>(n));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[j][i];
        }
    }
    
    ll ans = 0;
    for (int bit = 0; bit < (1<<3); bit++) {
        vector<ll> b(n);
        for (int i = 0; i < n; i++)
        {
            ll c = 0;
            for (int j = 0; j < 3; j++)
            {
                if (bit & (1<<j)) c += a[j][i];
                else c -= a[j][i];
            }
            b[i] = c;
        }
        sort(b.begin(), b.end(), greater<ll>());
        ll tmp = 0;
        for (int i = 0; i < m; i++)
        {
            tmp += b[i];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    int a;
    cin>>a;
    int flag=0;
      for(int i=1;i<10;i++)
        {for(int j=i;j<10;j++)
            {if(i*j==a)
            {

          flag=1;
          break;
          }
            }
      if(flag==1)
        break;
}
    if(flag==1)
          cout<<"Yes";
    else if(flag==0)
          cout<<"No";
    return 0;
}


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

#define MAXN 100005
#define int long long
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

using namespace std;

int n;
int h[MAXN];
int dp[MAXN];

signed main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> h[i];
    memset(dp, 0x3f, sizeof(dp));
    dp[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (i - 2 >= 1) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        dp[i] = min(dp[i], dp[i-1] + abs(h[i-1] - h[i]));
    }
    cout << dp[n] << endl;
    return 0;
}

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

using namespace std;
using namespace atcoder;

typedef long long ll;

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

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

	int n, q;
	cin >> n >> q;

	dsu dsu(n);
	rep(i, q){
		int t, u, v;
		cin >> t >> u >> v;

		if(t == 0){
			dsu.merge(u, v);
		}else{
			cout << dsu.same(u, v) << endl;
		}
	}
}


Measured memory_bytes: 4000
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-6
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, a[SIZE], k, ans;
int main() {
	io(); cin >> n >> k;
	rep(i, 1, n) cin >> a[i];
	sort(a + 1, a + 1 + n);
	rep(i, 1, (n - k)) ans += a[i];
	cout << ans;
}

Measured memory_bytes: 1792
<?php

$default = array_flip(range(1, 13));
$trump   = array(
    'S' => array(),
    'H' => array(),
    'C' => array(),
    'D' => array(),
);

fscanf(STDIN, '%d', $n);

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%s %d', $suit, $rank);

    $trump[$suit][$rank] = true;
}

foreach ($trump as $suit => $ranks) {
    $diff = array_diff_key($default, $ranks);

    if (empty($diff)) { continue; }

    foreach ($diff as $rank => $_) {
        printf('%s %s%s', $suit, $rank, PHP_EOL);
    }
}

Measured memory_bytes: 6620
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll B_MAX = 1000000000000000000;
constexpr ll CD_MAX = 1000000000;

ll A, B, C, D;

void input() {
	scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
}

void solve() {
	ll g=lcm(C,D);

	ll ca=A%C==0?A/C:A/C+1;
	ll cb=B/C;//B%C==0?B/C:B/C+1;
	ll da=A%D==0?A/D:A/D+1;
	ll db=B/D;//B%D==0?B/D:B/D+1;
	ll cda=A%(g)==0?A/(g):A/(g)+1;
	ll cdb=B/(g);//B%(C*D)==0?B/(C*D):B/(C*D)+1;

	ll cnum=cb-ca+1;
	ll dnum=db-da+1;
	ll cdnum=cdb-cda+1;

	debug(cnum);
	debug(dnum);
	debug(cdnum);

	ll ans = B-A+1  -cnum-dnum  +cdnum;


	printf("%lld\n", ans);
}

signed main() {
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
def getmax(x,y):
    if x>y:
        return x
    else:
        return y
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b = [0],[0]
for i in range(N):   #a[i]にはAの本をi冊読んだ時の時間がそれぞれ保存されている．
    a.append(a[i]+A[i])  #計算量を減らすため，a[i]（1冊前までにかかる時間）を用いる
for i in range(M):
    b.append(b[i]+B[i])

ans,j = 0,M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j] > K-a[i]:    #Bの本を読んだ場合の処理はここで実行される．
        j -=1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 47444
(function main(){
  let lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  let n = Number(lines.shift());
  let arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  let n = arr.length;
  let maxHeapify = (i) => {
    let left = 2 * i + 1, right = 2 * i + 2;
    let largest = i;
    if (left < n && arr[left] > arr[largest]) largest = left;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140168
#include<bits/stdc++.h>
#define int long long
#define rep1(i,a,b) for(int i=a;i<b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000009
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r,int m){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%m)*(p%m))%m;
	 }
	 r=r>>1;
     p=((p%m)*(p%m))%m;
	}
	return ans;
}
signed main() {
	garou;
	int n;
	cin>>n;
	int min1=INT_MAX,min2=INT_MAX,max1=INT_MIN,max2=INT_MIN;
	rep1(i,0,n){
		int a,b;
		cin>>a>>b;
		 min1=min(min1,a+b);
      min2=min(min2,a-b);
      max1=max(max1,a+b);
      max2=max(max2,a-b);
	}
cout<<max(max2-min2,max1-min1);
}

Measured memory_bytes: 3648
import math
n,h = map(int, input().split())
a = []
b = []
for i in range(n):
  a1,b1 = map(int, input().split())
  a.append(a1)
  b.append(b1)
b.sort()
max_a = max(a)
ans = 0
for i in b[::-1]:
  if i > max_a:
    h -= i
    ans += 1
  else:
    break
  if h <= 0:
    print(ans)
    exit()
ans += math.ceil(h/max_a)
print(ans)


Measured memory_bytes: 11804
<?php /*atcoder.php*/

$t = new temp();
$t->main();
unset($t);

class temp{
	private function lineIn(){
		return fgets(STDIN);
	}

	public function main(){
		$s = $this->lineIn();
		
		if(3 > $s){
			echo 0;
		}else{
			if(3 > ( $s % 3 ) ){
				echo (floor($s / 3));
			}else{
				echo ($s / 3);
			}
		}
	}
}
?>


Measured memory_bytes: 3828
from typing import List


if __name__ == "__main__":
    num_vector, num_query = map(lambda x: int(x), input().split())
    int_vector: List[List[int]] = [[] for _ in range(num_vector)]
    for _ in range(num_query):
        op, *value = map(lambda x: int(x), input().split())
        if (0 == op):
            int_vector[value[0]].append(value[1])
        elif (1 == op):
            print(" ".join([str(elem) for elem in int_vector[value[0]]]))
        elif (2 == op):
            int_vector[value[0]] = []
        else:
            pass



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

//flagを用いたバブルソート
int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0;flag;i++) {
		flag = 0;
		for (int j = N - 1;j >= i + 1;j--) {
			if (A[j] < A[j - 1]) {
				//隣接要素を交換する
				swap(A[j], A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}
int main() {
	int A[100],N,sw;
	cin >> N;
	for (int i = 0;i < N;i++)cin >> A[i];

	sw = bubbleSort(A, N);

	for (int i = 0;i < N;i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
	
	
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  char c;
  cin >> c;
  
  string s;
  s = "abcdefghijklmnopqrstuvwxyz";
    
  int i;
  for(i=0;i<s.size();i++) {
    if(s.at(i)==c){
      i++;
      cout << s.at(i) << endl;
      break;
    }
  }  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main(){
  int N;
  cin>>N;
  for (int i(0);i<N;i++){
    for (int j(0);j<N;j++){
      if (4*i + j*7 == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];

        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;i < n;i++){
            b[i] = sc.nextInt();
        }
        for(int i = 0;i < n-1;i++){
            c[i] = sc.nextInt();
        }

        int sum = 0;
        for(int i = 0;i < n;i++){
            sum += b[a[i]-1];
            if(i != 0 && a[i] == a[i-1] + 1){
                sum += c[a[i-1]-1];
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    map<char, char> m {
        {'A', 'T'},
        {'C', 'G'},
        {'G', 'C'},
        {'T', 'A'}
    };
    char b;
    cin >> b;
    cout << m[b] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> l(n + 1);
    vector<int> r(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());

    long s = 0;
    for (int i = 0; i < n + 1; i++) {
        if (r[i] < l[n - i]) {
            s += 2 * (l[n - i] - r[i]);
        } else {
            break;
        }
    }
    cout << s << "\n";


    return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

/**
 *
 *
 * 考虑把绿色视为红色加蓝色
 * 那么题目就转化成了给每一层涂两种颜色，可以全涂红色（贡献为 A）、蓝色（贡献为 B）、涂红色和蓝色（贡献为 C = A + B）、不涂颜色（贡献为 0）
 * 设 a 层涂了红色，b 层涂了蓝色，则答案为 sum{ C(a, N) * C(b, N) | (0 <= a, b <= N, A * a + B * b = K) }
 *
 */

const int MAXN = 3 * 1e6 + 10;
const int HA = 998244353;

long long int fac[MAXN], inv[MAXN], N, A, B, K;

long long int fastPow(long long int a, long long int b) {
    if (b == 0) return 1;
    if (b == 1) return a % HA;
    long long int ret = 1;
    while (b) {
        if (b & 1) ret = (ret * a) % HA;
        a = a * a % HA;
        b >>= 1;
    }
    return ret;
}

long long int C(long long int m, long long int n) {
    return fac[n] * inv[m] % HA * inv[n - m] % HA;
}

int main() {
    std::ios::sync_with_stdio(false);
    cin >> N >> A >> B >> K;
    fac[0] = 1; inv[0] = 1;
    for (long long int i = 1; i <= N; ++i) {
        fac[i] = fac[i - 1] * i % HA;
        inv[i] = fastPow(fac[i], HA - 2);
    }
    long long int ans = 0;
    for (long long int a = 0; a <= N; ++a) {
        // A * a + B * b = K
        //cout << "((K - A * a) % B + B) % B = " << ((K - A * a) % B + B) % B << endl;
        if (((K - A * a) % B + B) % B != 0) continue;
        long long int b = (K - A * a) / B;
        (ans += (C(a, N) * C(b, N)) % HA) %= HA;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N, K;
  scanf("%d", &N);
  scanf("%d", &K);
  if (K>(N-1)*(N-2)/2){
    printf("-1\n");
    return 0;
  }
  std::vector<std::pair<int, int > > ans;
  int diff = (N-1)*(N-2)/2-K;
  for (int i=2; i<=N; i++){
    ans.push_back(std::make_pair(1, i));
  }
  bool end=false;
  for (int i=2; i<N; i++){
    if (end) break;
    for (int j=i+1; j<=N; j++){
      if (diff==0){
	end=true;
	break;
      }
      ans.push_back(std::make_pair(i, j));
      diff--;
    }
  }
  printf("%d\n", ans.size());
  for (int i=0; i<ans.size(); i++){
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}


Measured memory_bytes: 384
using System;

namespace Ex160506_1{
    public class Program{
        public static void Main(string[] args){
            while(true){
                var input = Console.ReadLine().Split(' ');
                var a = int.Parse(input[0]);
                var op = input[1];
                var b = int.Parse(input[2]);

                switch(op){
                    case "+":
                        Console.WriteLine(a + b);
                        break;
                    case "-":
                        Console.WriteLine(a - b);
                        break;
                    case "*":
                        Console.WriteLine(a * b);
                        break;
                    case "/":
                        Console.WriteLine(a / b);
                        break;
                    default:
                        return;
                }
            }
        }
    }
}

Measured memory_bytes: 9308
# Levenshtein Distance algorithm
def levenshtein(s1, s2):
    prev = range(len(s1) + 1)
    for i, c2 in enumerate(s2, start=1):
        cur = [i] + [0] * len(s1)
        for j, tpl in enumerate(zip(s1, prev[1:], cur, prev), start=1):
            c1, p1, p2, p3 = tpl
            cur[j] = min(p1 + 1, p2 + 1, p3 + (c2 != c1))
        prev = cur
    return cur[len(s1)]

# solve
s1 = input()
s2 = input()

ans = levenshtein(s1, s2)

print(ans)

Measured memory_bytes: 7576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;
    cin >> n;
    int a[n],b[n];
    rep(i,n)cin >> a[i] >> b[i];
    sort(a,a+n);
    sort(b,b+n);
    if(n%2 == 1){
        int ma = a[n/2];
        int mb = b[n/2];
        cout << mb - ma +1 << endl;

    }
    else {
        int ma = (a[n/2]+ a[n/2-1]);
        int mb = (b[n/2]+ b[n/2-1]);
        cout << mb - ma +1 << endl;

    }
    return 0;
}

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

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

  vector<bool> mn(n, false);
  vector<bool> mx(n, false);
  bool down;
  if ( a[0] > a[1] ) {
    down = true;
    mx[0] = true;
  } else {
    down = false;
    mn[0] = true;
  }
  for ( int i = 1; i < n-1; i++ ) {
    if ( a[i] > a[i+1] ) {
      if ( !down ) { mx[i] = true; }
      down = true;
    } else {
      if ( down ) { mn[i] = true; }
      down = false;
    }
  }
  if ( !down ) { mx[n-1] = true; }

  long long ans = 1000;
  long long kabu = 0;
  for ( int i = 0; i < n; i++ ) {
    if ( mn[i] ) {
      long long buy = ans / a[i];
      kabu += buy;
      ans -= (buy*a[i]);
    }
    if ( mx[i] ) {
      ans += (kabu*a[i]);
      kabu = 0;
    }
  }

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


Measured memory_bytes: 3624
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

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

/* see https://github.com/pllk/cphb/
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;
 **/

typedef long long ll;
#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

//typedef __int128 lll;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(k);
    cini(x);
    for(int i=x-k+1; i<x+k; i++)
        cout<<i<<" ";
    cout<<endl;

}



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

int main() {
  int n;
  cin >> n;
  vector <int> p(n);
  for (int i=0 ; i<n ; i++){
    cin >> p.at(i) ;
  }
  int min_dis =100000000 ;
  for (int i= 1 ; i<=100 ; i++){
    int sum_dis = 0;
    for (int j=0 ; j<n ; j++){
    sum_dis += (p.at(j)-i)*(p.at(j)-i) ;
   }
    min_dis = min ( min_dis , sum_dis) ;
  }
  cout << min_dis << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

ll go(vl a) {
	ll n = sz(a);

	FOR(i,0,n) if (a[i] > i) return -1;
	FOR(i,1,n) if (a[i] > a[i-1]+1) return -1;

	ll res = 0;
	FOR(i,0,n) res += (a[i] == a[i-1]+1) ? 1 : a[i];
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n);
	FOR(i,0,n) cin >> a[i];
	
	cout << go(a) << endl;

}



Measured memory_bytes: 3456
/*
 AtCoder AXC 000
 */
 
#include <stdio.h>

int main(void){
	
	int x,a,b;
	
	scanf("%d",&x);
	scanf("%d",&a);
	scanf("%d",&b);
	
	printf("%d",(x-a)%b);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int opt[200005],n,num,t = -1;
int main(){
	cin >> n;
	opt[0] = true;
	for(int i = 1;i <= n;i++){
		cin >> num;
		opt[num] = opt[num - 1];			
	}
	for(int i = n;i >= 1;i--)
		if (opt[i])
			t = max(t,i);
	int ans = n - t;
	if (t == -1) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;
int main(void){
    // Your code here!
    double x1,y1,x2,y2,x,y,ans;
    cin>>x1>>y1>>x2>>y2;
    x=fabs(x1-x2);
    y=fabs(y1-y2);
    ans=pow(x,2)+pow(y,2);
    cout<<fixed << setprecision(10)<<sqrt(ans)<<endl;
}



Measured memory_bytes: 3284
N=parse(Int,readline())
A=map(x->parse(Int,x),split(readline()))
B=map(x->parse(Int,x),split(readline()))
now=sum(A)+B[N]
ans=now
for i=N-1:-1:1
	now-=A[i+1]
	now+=B[i]
	ans=max(ans,now)
end
println(ans)


Measured memory_bytes: 111828
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;



int main(){
    double a,l,x;
    while(cin>>a>>l>>x){
        double ans=0.5*a*sqrt(l*l-(a*a)*0.25) + 0.5*l*sqrt(x*x+2*l*x) ;
        printf("%15.10lf\n",ans);
    }
    
 return 0;
}

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

using namespace std;

long long candles[100010];

int main()
{

    long long res = 1e18;
    int n, k, p, q;
    cin >> n >> k;

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

    for (int i = 1; i + k - 1 <= n; i++)
    {
        p = i;
        q = i + k - 1;
        res = min(res, candles[q] - candles[p] + min(abs(candles[p]), abs(candles[q])));
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;

  int x = 0;
  for(int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    x += r - l + 1;
  }
  cout << x << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;
    vint m_x, m_y;
    int flag = 1;
    int ct = 0;
    rep(i,s.size()) {
        if (s[i] == 'F') ct++;
        if (s[i] == 'T' || i == s.size()-1) {
            if (flag == 1 && ct != 0) m_x.push_back(ct);
            else if (flag != 1 && ct != 0) m_y.push_back(ct);
            flag *= -1;
            ct = 0;
        }
    }
    bool ok_x = false;
    if (m_x.size() == 0) {
        if (x == 0) ok_x = true;
    }
    else {
        vector<vector<bool>> dp_x(m_x.size(),vector<bool>(17000));
        if (s[0] != 'T') dp_x[0][8000+m_x[0]] = 1;
        else dp_x[0][8000+m_x[0]] = dp_x[0][8000-m_x[0]] = 1;
        REP(i,m_x.size()) {
            rep(j,16000) {
                if (j-m_x[i] >= 0) {
                    dp_x[i][j] = dp_x[i-1][j-m_x[i]] || dp_x[i-1][j+m_x[i]];
                }
                else dp_x[i][j] = dp_x[i-1][j+m_x[i]];
            }
        }
        ok_x = dp_x[m_x.size()-1][8000+x];
    }

    bool ok_y = false;
    if (m_y.size() == 0) {
        if (y == 0) ok_y = true;
    }
    else {
        vector<vector<bool>> dp_y(m_y.size(),vector<bool>(17000));
        dp_y[0][8000+m_y[0]] = dp_y[0][8000-m_y[0]] = 1;
        REP(i,m_y.size()) {
            rep(j,16000) {
                if (j-m_y[i] >= 0) {
                    dp_y[i][j] = dp_y[i-1][j-m_y[i]] || dp_y[i-1][j+m_y[i]];
                }
                else dp_y[i][j] = dp_y[i-1][j+m_y[i]];
            }
        }
        ok_y = dp_y[m_y.size()-1][y+8000];
    }
    if (ok_x && ok_y) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main(){

    string s;

    cin >> s;

    for (int i=0 ; i<50;i++) 
        if ((s[2*i+1] == 'R') || (s[2*i] == 'L'))
            {
            cout << "No" << endl;
            return 0;
            }

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

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: int, B: int):
    if A > B :
        print(0)
    
    elif N == 1 and A == B:
        print(1)
    
    elif N == 1 and A < B:
        print(0)

    else:
        ans = (B*(N-2)-A*(N-2)+1)
        print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

int N,Q;
string s;
vector<int> c(200000,0);
vector<vector<int> > td(200000,vector<int>(2,0));

int bsL(int l, int r){
    //cout << 'L' << ' ' << l << ' ' << r << endl;
    int mid = (l+r)/2;
    if(mid==l || r==0){
        return l;
    }
    int now=mid;
    for(int i =0; i<Q; i++){
        //cout << now << endl;
        if(c[now]==td[i][0]){
            now+=td[i][1];
        }
        if(now<0){
            return bsL(mid,r);
        }else if(now>=N){
            break;
        }
    }
    return bsL(l,mid);
}

int bsR(int l, int r){
    //cout << 'R' << ' ' << l << ' ' << r << endl;
    int mid = (l+r)/2;
    if(mid==l || r==0){
        return r;
    }
    int now = mid;
    for(int i=0; i<Q; i++){
        //cout << now << endl;
        if(c[now]==td[i][0]){
            now+=td[i][1];
        }
        if(now>=N){
            return bsR(l,mid);
        }else if(now<0){
            break;
        }
    }
    return bsR(mid,r);
}

int main(){
    cin >> N >> Q;
    cin >> s;
    for (int i=0; i<N;i++){
        c[i]=s[i]-'A';
    }
    for(int i=0; i<Q; i++){
        char t, d;
        cin >> t >> d;
        td[i][0]=t-'A';
        if(d=='L'){
            td[i][1]=-1;
        }else{
            td[i][1]=1;
        }
    }
    int ans=N;
    ans-=bsL(-1,N)+1;
    ans-=N-bsR(-1,N);
    cout << ans << endl;
}

Measured memory_bytes: 12292
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	input = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
	var c = parseInt(input[2], 10);
	
	
    var total = a + b + c;
    //console.log(a,b,c,total)
    if (total >21){console.log('bust');}else{console.log('win');}
	

	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  string ans="";
  int N;
  cin>>N;
  int a=N%10;
  if (a==2||a==4||a==5||a==7||a==9) ans="hon";
  else if(a==0||a==1||a==6||a==8) ans="pon";
  else ans="bon";
  
  cout<<ans<<endl;
}
    

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <deque>
#include <queue>
#include <vector>

using namespace std;

int main() {
    int n, k1;
    cin >> n >> k1;
    int v[n], best = -100000000;
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int k = 0; k <= k1; k++) {
        for (int i = 0; i <= k / 2; i++) {  // iは戻す宝石の数
            if (k - i > n) continue;
            for (int j = 0; j <= k - i; j++) {
                int front = 0, back = n - 1;
                priority_queue<int> pq;
                for (int l = 0; l < j; l++) {// jはfrontからとる宝石の数
                    pq.push(v[front]);
                    front++;
                }
                for (int l = 0; l < k - i - j; l++){
                    pq.push(v[back]);
                    back--;
                }
                int sum = 0;
                for (int l = 0; l < k - 2 * i; l++) {
                    //cerr << pq.top() << '\n';
                    sum += pq.top();
                    pq.pop();
                }
                best = max(best, sum);
                // cerr << i << ' ' << j << ' ' <<  sum << '\n';
            }
            
        }
    }
    cout << best << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T>
struct Stack{
private:
    T* begin;
    int size;
    int end;
    
public:
    Stack(){
        begin=(T*)malloc(sizeof(T));
        size=1;
        end=0;
    }
    
    ~Stack(){free(begin);}
    
    void push(const T &data){
        if(end==size){
            T* New=(T*)realloc(begin,sizeof(T)*(size<<=1));
            if(New==NULL){
                free(begin);
                assert(false);
            }
            begin=New;
        }
        *(begin+(end++))=data;
    }
    
    T top() const {
        assert(end>0);
        return *(begin+(end-1));
    }
    
    void pop(){
        assert(end>0);
        --end;
    }
};




int main(){
    Stack<ll> S;
    string s;
    while(cin>>s){
        if(s=="+"){
            ll a=S.top(); S.pop();
            ll b=S.top(); S.pop();
            S.push(a+b);
        }
        else if(s=="-"){
            ll a=S.top(); S.pop();
            ll b=S.top(); S.pop();
            S.push(b-a);
        }
        else if(s=="*"){
            ll a=S.top(); S.pop();
            ll b=S.top(); S.pop();
            S.push(a*b);
        }
        else{
            ll a=atoi(s.c_str());
            S.push(a);
        }
    }
    cout<<(ll)S.top()<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 3156
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
#print(a)
s=a[:n]
m=a[n:2*n]
f=a[2*n:]

ssum=sum(s)
fsum=sum(f)
#print(fsum)
import heapq

heapq.heapify(s)
ms=[0]*n
mf=[0]*n

for i in range(n):
    heapq.heappush(s,m[i])
    mn=heapq.heappop(s)
    ms[i]=mn
#print(ms)
for i in range(n):
    f[i]*=-1
heapq.heapify(f)
#print(f)
for i in range(n-1,-1,-1):
    heapq.heappush(f,-m[i])
    mx=-heapq.heappop(f)
    mf[i]=mx
#print(mf)
#print(m)
srui=[0]*(n+1)
srui[0]=ssum
for i in range(n):
    srui[i+1]=srui[i]-ms[i]+m[i]
#print(srui)
frui=[0]*(n+1)
frui[-1]=fsum
#print(frui)
for i in range(n,0,-1):
    frui[i-1]=frui[i]-mf[i-1]+m[i-1]
#print(srui)
#print(frui)
ans=-float("inf")
for i in range(n+1):
    ans=max(ans,srui[i]-frui[i])
print(ans)


Measured memory_bytes: 120744
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL << 50;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
 
struct edge{
    int from, to; ll cost;
};

int main(){
    int n;
    vector<ll> a;
    cin >> n;
    ll xsum = 0, ysum = 0;
    REP(i, n){
        ll tmp;
        cin >> tmp;
        a.pb(tmp);
        ysum += tmp;
    }
    ll ans = INF;
    REP(i, n - 1){
        xsum += a[i];
        ysum -= a[i];
        ans = min(abs(xsum - ysum), ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	string s;
	cin >> s;
	if (s.size() == 3)reverse(s.begin(), s.end());
	cout << s << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string S;
  std::cin >> S;

  ll N = S.size();

  std::string s = S;

  bool judge = true;
  ll i = 0;
  while (i < N) {
    if (s.substr(i, 10) == "dreamerase") {
      i += 5;
      continue;
    }
    if (s.substr(i, 6) == "eraser") {
      i += 6;
      continue;
    }
    if (s.substr(i, 7) == "dreamer") {
      i += 7;
      continue;
    }
    if (s.substr(i, 5) == "dream" || s.substr(i, 5) == "erase") {
      i += 5;
      continue;
    }

    judge = false;
    break;
  }

  if (judge) print("YES");
  else print("NO");

  return 0;
}


Measured memory_bytes: 512