akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define min(p,q)((p)<(q)?(p):(q))
/*
初期状態で数列が一致しているなら0。そうでないとする
（このときa[i]>b[i]となるもの、a[i]<b[i]となるものがそれぞれ少なくとも1つ存在する）
ターンをまとめて処理することを考える
「よさそう」な戦略として次のようなものがすぐに思いつく
===
・先攻はまずa[i]<b[i]であるa[i]を全て0にしてよい
　（途中で追いつかれることはないので）
・すると後攻は対応するb[i]を全て0にするしかない
・この時点ではまだaの和の方が大きいので、これがbの和と一致するまで先攻は操作ができる
　a[i],b[i]の少なくとも一方が0でないものが2つ以上あるなら
　a[i]>b[i]となるものを高々1つだけ残してそれ以外はa[i]≦b[i]となるようにしてよい
・これを繰り返すことで、「初期状態ではa[i]>b[i]だったもの」が1つだけ残るようにできる
　最後にb[i]残るので、そのような最小のものを残せば良い
===
*/

int main(){
	ll n;
	scanf("%lld",&n);
	ll ans=0,m=INF;
	rep(i,0,n){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		ans+=a;
		if(a>b)m=min(m,b);
	}
	if(m==INF)puts("0");
	else printf("%lld\n",ans-m);
}

Measured memory_bytes: 128
<?php
fscanf(STDIN, "%d", $n);
$count = 0;
for($i = 1; $i <= $n; $i++){
  for($j = $i+1; $j <= $n; $j++){
    $map[$i][$j] = true;
    $count++;
  }
}

if($n % 2 == 1){
  for($i = 1; $i <= floor($n/2); $i++){
    unset($map[$i][$n-$i]);
    $count--;
  }
}else{
  for($i = 1; $i <= floor($n/2); $i++){
    unset($map[$i][$n-$i+1]);
    $count--;
  }
}
echo $count,"\n";
foreach($map as $f => $toArray){
  foreach($toArray as $t => $_){
    echo $f." ".$t."\n";
  }
}

Measured memory_bytes: 4604
N=int(input())
mylist=[]
j=0
n=0
for i in range(N):
  mylist.append(int(input()))
  
for i in range(N):
  if n==1:
    print(j)
    break
  j=j+1
  n=mylist[n]-1
  if i==N-1:
  	print("-1") 
  
  

Measured memory_bytes: 7084
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(N-1):
	if A[i+1] - A[i] == 1:
		ans += C[A[i]-1]

print(ans)

Measured memory_bytes: 3064
// Aggressive Play

#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
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(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); 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 debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int N = 3e5 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    double n;
    cin >> n;
    cout << fixed << setprecision(10) << 2.0 * acos(-1) * n;
return 0;
}


Measured memory_bytes: 3816
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>v;
int x,k;
int main(){
	scanf("%d%d",&x,&k);
	for(register int i=k-x+1;i<k+x;i++)v.push_back(i);
	sort(v.begin(),v.end());
	for(register int i=0;i<v.size();i++)printf("%d ",v[i]);
}

Measured memory_bytes: 256
#include <stdio.h>


int main() {
    while (1) {
        int i;
        int n, k;
        int max, count_max;
        char has_delivered[100000];
        char has_white, is_white;
        int save_pos;
        int count;

        max = 0;
        for (i=0;i<100000;i++) has_delivered[i] = 0;
        is_white = has_white = 0;

        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) return 0;

        for (i=0;i<k;i++) {
            int d;

            scanf("%d", &d);
            if (max < d) {
                max = d;
            }

            if (d) {
                has_delivered[d-1] = 1;
            } else {
                is_white = has_white = 1;
            }
        }

        count = 0;
        count_max = 0;
        for (i=0;i<max+1;i++) {
            if (has_delivered[i]) {
                count++;
            } else if (is_white) {
                is_white = 0;
                save_pos = i;
                count++;
            } else {
                if (count_max < count) count_max = count;
                if (has_white && !is_white) {
                    is_white = 1;
                    i = save_pos;
                }
                count = 0;
            }
        }

        printf("%d\n", count_max);
    }
}

Measured memory_bytes: 1124
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n, k = list(map(int,sys.stdin.readline().split()))
    p = list(map(int,sys.stdin.readline().split()))
    sum_l = [0] * (n - k + 1)
    for i in range(k):
        sum_l[0] += p[i]
    for i in range(1,n - k + 1):
        sum_l[i] = sum_l[i - 1] - p[i - 1] + p[i + k - 1]
    #print(sum_l)
    max_idx = sum_l.index(max(sum_l))
    #print(max_idx)
    ans = 0
    for i in range(max_idx, max_idx + k):
        ans += ((p[i] * (p[i] + 1)) / 2) / p[i]
    print("{:.12f}".format(ans))
    return 0
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 24880
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, sum = 0;
  cin >> N;  
  vector<ll> A(N);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
    if(i == 0) sum += abs(A.at(0));
    else sum += abs(A.at(i) - A.at(i - 1));
  }
  sum += abs(A.at(N - 1));
  for(ll i = 0; i < N; i++) {
    if(i == 0) {
      if(A.at(0) * (A.at(1) - A.at(0)) < 0) cout << sum - 2 * min(abs(A.at(1) - A.at(0)), abs(A.at(0))) << endl;
      else cout << sum << endl;
    }
    else if(i == N - 1) {
      if((A.at(N - 1) - A.at(N - 2)) * (-A.at(N - 1)) < 0) cout << sum - 2 * min(abs(A.at(N - 1) - A.at(N - 2)), abs(A.at(N - 1))) << endl;
      else cout << sum << endl;
    }
    else {
      if((A.at(i) - A.at(i - 1)) * (A.at(i + 1) - A.at(i)) < 0) cout << sum - 2 * min(abs(A.at(i) - A.at(i - 1)), abs(A.at(i + 1) - A.at(i))) << endl;
      else cout << sum << endl;
    }
  }
}

Measured memory_bytes: 4020
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var S = Console.ReadLine();
        static bool IsACGT(char l) => l == 'A' || l == 'C' || l == 'G' || l == 'T';
        var answer = 0;
        var count = 0;
        foreach (var l in S){
            if (!IsACGT(l)){
                if (answer < count) answer = count;
                count = 0;
                continue;}
            count++;}
        if (answer < count) answer = count;
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 25904
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include<bitset>
#include <utility>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const int MAX=1e5+5;
const int MAX_N=MAX;
const ll MOD=998244353;
const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
    freopen("1009.in","r",stdin);
    freopen("out.txt","w",stdout);
}
int n;
int a[MAX],an,cnt;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    int i,j;i=j=1;
    while(i<=n)
    {
        cnt=0;j=i;
        while(j<=n&&a[j]==j)
            ++j,++cnt;
        an+=(cnt+1)/2;if(a[j]!=j)++j;i=j;
    }
    printf("%d\n",an);
    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define For(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
// const ll MOD=1000000007ll;
const ll MOD=998244353ll;
const int MAX=510000;



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

    int n500 = x/500;
    x = x % 500;

    int n5 = x/5;

    cout << n500*1000 + n5*5 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll N;
	cin >> N;
	vector<ll> V;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			if (i * i != N) V.push_back(i - 1);
			if (i * i != N) V.push_back(N / i - 1);
		}
	}
	ll ans = 0;
	for (ll num : V) {
		if (num == 0) continue;
		if (N / num == N % num) ans += num;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
#define EPS 1e-15
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,q;cin>>n>>q;
  vector<pair<ll,ll>> ma(n);
  for(int i=0;i<n;i++){
    ma[i] = mp(-1,-(i+1));
  }
  for(int i=0;i<q;i++){
    ll a;cin>>a;
    ma[a-1].F = i;
  }
  sort(ALL(ma),greater<pair<ll,ll>>());
  for(auto a:ma)
    cout<<-a.S<<endl;
  return 0;
}


Measured memory_bytes: 5964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=3005;
int n,m;
int a[max_n],b[max_n],c[max_n],d[max_n],e[max_n],f[max_n];
vector<int> x,y;
int gx(int ox){
    return lower_bound(x.begin(),x.end(),ox)-x.begin()+1;
}
int gy(int oy){
    return lower_bound(y.begin(),y.end(),oy)-y.begin()+1;
}
bool vis[max_n][max_n],dwn[max_n][max_n],lef[max_n][max_n];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",a+i,b+i,c+i);
        x.push_back(a[i]),x.push_back(b[i]),y.push_back(c[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",d+i,e+i,f+i);
        x.push_back(d[i]),y.push_back(e[i]),y.push_back(f[i]);
    }
    x.push_back(0),y.push_back(0);
    sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end());
    sort(y.begin(),y.end());y.erase(unique(y.begin(),y.end()),y.end());
    for(int i=1;i<=n;i++){
        a[i]=gx(a[i]),b[i]=gx(b[i]),c[i]=gy(c[i]);
        for(int j=a[i];j<b[i];j++)dwn[j][c[i]]=true;
    }
    for(int i=1;i<=m;i++){
        d[i]=gx(d[i]),e[i]=gy(e[i]),f[i]=gy(f[i]);
        for(int j=e[i];j<f[i];j++)lef[d[i]][j]=true;
    }
    int ox=0,oy=0;
    ox=gx(ox),oy=gy(oy);
    #define P pair<int,int> 
    queue<P> que;
    que.push(P(ox,oy));
    vis[ox][oy]=true;
    ll ans=0;
    while(!que.empty()){
        P p=que.front();que.pop();
        ox=p.first,oy=p.second;
        if(ox==0||ox==x.size()||oy==0||oy==y.size())return printf("INF\n"),0;
        ans+=1ll*(x[ox]-x[ox-1])*(y[oy]-y[oy-1]);
        //left
        if(ox&&!lef[ox][oy]&&!vis[ox-1][oy]){
            vis[ox-1][oy]=true;
            que.push(P(ox-1,oy));
        }
        //right
        if(ox+1<=x.size()&&!lef[ox+1][oy]&&!vis[ox+1][oy]){
            vis[ox+1][oy]=true;
            que.push(P(ox+1,oy));
        }
        //up
        if(oy+1<=y.size()&&!dwn[ox][oy+1]&&!vis[ox][oy+1]){
            vis[ox][oy+1]=true;
            que.push(P(ox,oy+1));
        }
        //down
        if(oy&&!dwn[ox][oy]&&!vis[ox][oy-1]){
            vis[ox][oy-1]=true;
            que.push(P(ox,oy-1));
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 26816
#include<iostream>

using namespace std;

int main(){

  int n;
  cin >> n;

  int p = 0;
  bool f = true;
  while(n--){
    char c;
    int x;
    cin >> c >> x;
    if(c == '(') p+=x;
    else p-=x;
    if(p<0) f = false;
  }

  if(f&&p==0) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 1160
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn a() {
    let s: String = read!(String);

    if &s == "Sunny" {
        println!("Cloudy");
        return;
    }
    if &s == "Cloudy" {
        println!("Rainy");
        return;
    }
    if &s == "Rainy" {
        println!("Sunny");
        return;
    }
}

fn b() {
    let s: String = read!(String);
    let c: Vec<char> = s.chars().collect();

    for i in 0..c.len() {
        let j = i + 1;
        if j % 2 == 0 {
            if c[i] == 'R' {
                println!("No");
                return;
            }
        } else {
            if c[i] == 'L' {
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}

fn c() {
    unimplemented!();
}

fn d() {
    unimplemented!();
}

fn e() {
    unimplemented!();
}

fn f() {
    unimplemented!();
}

fn main() {
    b();
}


Measured memory_bytes: 4352
import math

X, Y = map(int, input().split())
MOD = 10**9 + 7

def pow_mod(a, b, p):
    if b == 0:
        return 1
    elif b % 2 == 0:
        d = pow_mod(a, b//2, p)
        return (d**2) % p
    else:
        return (a*pow_mod(a, b-1, p)) % p


def factorial_mod(n, p):
    tmp = 1
    for i in range(1, n+1):
        tmp *= i
        tmp %= p
    return tmp

X, Y = max(X,Y), min(X,Y)

j = -1
for i in range(X//2 +1):
    x = X - i*2
    y = Y - i
    if y == x*2:
        j = x
        break

if j == -1:
    print(0)
else:
    ans = factorial_mod(i+j, MOD)
    ans *= pow_mod(factorial_mod(i, MOD), MOD-2, MOD)
    ans *= pow_mod(factorial_mod(j, MOD), MOD-2, MOD)
    ans %= MOD
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<list>

using namespace std;


/*
//1
int main(){
	for(int i=0; i<7;i++){
		int a, b;
		cin >> a >> b;
		cout << a- b << endl;

	}

	return 0;
}
*/

/*
//2
int main(){
	int t[4] = {6000, 4000, 3000, 2000};
	for(int i=0; i<4; i++){
		int T,n;
		cin >> T >> n;
		T--;
		cout << t[T]*n << endl;
	}

	return 0;
}
*/

/*
//3
int main(){
	int N;
	cin >> N;
	for(int i=0; i<N; i++){
		int x, y, b, p;
		cin >> x >> y >> b >> p;
		
		if(b >= 5 && p >= 2){
			int ans = (b*x + p*y)*0.8 + (b-5)*x + (p-2)*y;
			cout << ans << endl;
		}
		else if(b >= 5 && p < 2){
			int ans = (5*x + 2*y)*0.8 + (b-5)*x;
			ans = min( b*x + p*y, ans );
			cout << ans << endl;
		}
		else if(b < 5 && p >= 2){
			int ans = (5*x + 2*y)*0.8 + (p-2)*y;
			ans = min( b*x + p*y, ans );
			cout << ans << endl;
		}
		else{
			int ans = (5*x + 2*y)*0.8;
			ans = min( b*x + p*y, ans );
			cout << ans << endl;
		}
	}

	return 0;
}
*/

/*
//4
int main(){


	return 0;
}
*/

/*
//5
int main(){


	return 0;
}
*/


//6
int main(){
	int Q;
	cin >> Q;
	for(int i=0; i<Q; i++){
		int c,a,n;
		cin >> c >> a >> n;
		int ans = 0;
		while(c != 0 && a != 0 && n != 0){
			c--;
			a--;
			n--;
			ans++;
		}
		while(c >= 2 && a >= 1){
			c -= 2;
			a--;
			ans++;
		}
		while(c >= 3){
			c -= 3;
			ans++;
		}
		cout << ans << endl;
	}

	return 0;
}


/*
//7
int main(){


	return 0;
}
*/

/*
//8
int main(){


	return 0;
}
*/

/*
//9
int main(){


	return 0;
}
*/

/*
//10
int main(){


	return 0;
}
*/




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


int main (void)
{ 
  long long int ans,a,b,c,d,gcd,lcm;
  
  cin>>a>>b>>c>>d;
  long long int cc=c,dd=d;
  while(1){
  gcd=cc%dd;
  if(gcd==0){gcd=dd;break;}
  else{cc=dd;dd=gcd;}
  }
  lcm=c*d/gcd;
  
  ans=b-a+1;
  ans=ans-b/c-b/d+a/c+a/d;
  if(a%c==0)ans--;
  if(a%d==0&&a%c!=0)ans--;
  ans=ans+b/lcm-a/lcm;
  
  
  cout<<ans<<endl;
  
  return 0;
}

 

Measured memory_bytes: 3612
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};
use std::collections::BTreeMap;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

struct FenwickTree {
    buf: Vec<i64>,
    size: usize,
}

impl FenwickTree {
    pub fn new(n: usize) -> FenwickTree {
        FenwickTree {
            buf: vec![0; n + 1],
            size: n,
        }
    }

    pub fn add(&mut self, i: usize, v: i64) {
        let mut i = i + 1;
        while i <= self.size {
            self.buf[i] += v;
            i += i & i.wrapping_neg();
        }
    }

    pub fn sum(&self, i: usize) -> i64 {
        let mut i = i + 1;
        let mut sum = 0;
        while i > 0 {
            sum += self.buf[i];
            i -= i & i.wrapping_neg();
        }
        sum
    }
}

fn main() {
    let mut sc = Scanner::default();
    let out = &mut BufWriter::new(stdout());

    let n = sc.next();
    let mut a = vec![0; n];
    let mut map = BTreeMap::<i64, usize>::new();
    for i in 0..n {
        a[i] = sc.next();
        map.insert(a[i], 0);
    }
    for (i, (_, v)) in map.iter_mut().enumerate() {
        *v = i;
    }

    let mut ft = FenwickTree::new(n);
    let mut ans = 0;
    for x in a.iter().rev() {
        let i = map[&x];
        ans += ft.sum(i);
        // writeln!(out, "{} {}: {}", x, i, ans ).ok();
        ft.add(i, 1);
    }
    writeln!(out, "{}", ans).ok();
}



Measured memory_bytes: 25508
n, a, b, c=map(int, input().split())
l=[0]*n
ch=0
ans=0

for i in range(n):
    l[i]=int(input())

ans+=abs(l[0]-a)
ans+=abs(l[1]-b)
ans+=abs(l[2]-c)

    
for i in range(4**n):
    ch=0
    mp=0
    s=[0]*4
    for j in range(n):
        for k in range(3):
            if (i>>2*j) % 2**2 ==k:
                if s[k]==0:
                    0
                else:
                    mp+=10
                s[k]+=l[j]
                    
    for p in range(3):
        if s[p]==0:
            #invalid
            ch=1
    if ch==1:
        0
        #invalid
    else:
        mp+=abs(int(s[0]-a))
        mp+=abs(int(s[1]-b))
        mp+=abs(int(s[2]-c))
        if mp<ans:
            ans=mp
            s_ans=s
            j_ans=j
    #print('bin(j),ch,s,mp',bin(i),ch,s,mp,abs(int(s[0]-a)),abs(int(s[1]-b)),abs(int(s[2]-c)))
    
print(ans)
#print(bin(j_ans),s_ans)
    
    


Measured memory_bytes: 55004
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1)*a%MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1)*a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size()>n) return kaijo_memo[n];
  if(kaijo_memo.size()==0) kaijo_memo.push_back(1);
  while(kaijo_memo.size()<=n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1]*kaijo_memo.size()%MOD);
  return kaijo_memo[n];
}

signed main(){
	string s; cin>>s;
	bool t[26]; CLR(t);
	rep(i,s.size()){
		if(t[s[i]-'a']) return cout<<"no"<<endl,0;
		else t[s[i]-'a']=true;
	}
	cout<<"yes"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x = sx, y = sy;
	while(x!=tx) {
		while(y!=ty) {
			if (y < ty) {
				cout << 'U';
				y++;
			}
			else if (y >ty) {
				cout << 'D';
				y--;
			}
		}
		if (x < tx) {
			cout << 'R';
			x++;
		}
		else if (x > tx) {
			cout << 'L';
			x--;
		}
	}
	while (x != sx) {
		while (y != sy) {
			if (y < sy) {
				cout << 'U';
				y++;
			}
			else if (y > sy) {
				cout << 'D';
				y--;
			}
		}
		if (x < sx) {
			cout << 'R';
			x++;
		}
		else if (x > sx) {
			cout << 'L';
			x--;
		}
	}
	cout << 'L' << string(ty - sy + 1, 'U') << string(tx - sx + 1, 'R') << 'D' ;
	cout << 'R' << string(ty - sy + 1, 'D') << string(tx - sx + 1, 'L') << 'U' << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int c[101][3];
bool f=true;
int main()
{
 int n,sum=0,summ=0,ans,oo=0;
 cin>>n;
 for(int i=1;i<=2;i++)
 for(int j=1;j<=n;j++)
 cin>>c[j][i];
 for(int i=1;i<=n;i++)
 for(int j=1;j<=2;j++)
 {
  if(c[i][j]!=c[i+1][j])
  f=false;
 }
 if(f==true) ans=c[2][1]*5;
 for(int i=1;i<=n;i++)
 {
  oo+=c[i][1];
  for(int j=i;j<=n;j++)
  {
   sum+=c[j+1][1];
   summ+=c[j][2];
  }
  if(sum<summ)
  {ans=max(summ+oo,ans);sum=0;summ=0;}
  else
  {sum=0;summ=0;}
 }
 cout<<ans;
 return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int x, y;
  int a[] = {1, 3, 5, 7, 8, 10, 12};
  int b[] = {4, 6, 9, 11};
  int flag_xa, flag_ya, flag_xb, flag_yb;

  scanf("%d%d", &x, &y);

  flag_xa = 0; flag_ya = 0;
  for(int i = 0; i < 7; i++){
    if(a[i] == x){
      flag_xa++;
    }
    if(a[i] == y){
      flag_ya++;
    }
  }

  flag_xb = 0; flag_yb = 0;
  for(int i = 0; i < 4; i++){
    if(b[i] == x){
      flag_xb++;
    }
    if(b[i] == y){
      flag_yb++;
    }
  }

  if(flag_xa*flag_ya > 0 || flag_xb*flag_yb > 0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}
  


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

struct edge {lnt to, money, time;};

int main(){
	summon_tourist;

	lnt N, M, S; cin >> N >> M >> S;
	chmin(S, 5000ll);
	vector<vector<edge>> G(N);

	REP(i, M){
		lnt u, v, a, b; cin >> u >> v >> a >> b;
		u--; v--;
		G[u].pb({v, -a, b});
		G[v].pb({u, -a, b});
	}
	REP(i, N){
		lnt c, d; cin >> c >> d;
		G[i].pb({i, c, d});
	}

	lnt dp[55][5010];
	REP(i, 55) REP(j, 5010) dp[i][j] = BBIG;
	dp[0][S] = 0;

	using state = vector<lnt>; // {time, idx, money}
	pque<state, vector<state>, greater<state>> que;
	que.push({0, 0, S});
	
	while(!que.empty()){
		state st = que.top(); que.pop();
		lnt pos = st[1], money = st[2], time = st[0];
		if(dp[pos][money] < time) continue;
		for(auto e: G[pos]){
			lnt nxmoney = money + e.money;
			if(nxmoney < 0) continue;
			if(nxmoney > 5000) nxmoney = 5000;
			if(chmin(dp[e.to][nxmoney], time + e.time)){
				que.push({time+e.time, e.to, nxmoney});
			}
		}
	}

	RANGE(i, 1, N){
		lnt ans = BBIG;
		REP(j, 5010){
			chmin(ans, dp[i][j]);
		}
		cout << ans << ln;
	}
}

Measured memory_bytes: 15608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;

    double x[11];
    string u[11];

    cin >> n;

    REP(i, n)
    cin >> x[i] >> u[i];

    double res = 0;

    REP(i, n)
    {
        if (u[i] == "JPY")
        {
            res += (double)x[i];
        }
        else
        {
            res += (double)x[i] * 380000.0;
        }
    }

    cout << setprecision(20) << res << endl;

    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

struct edge
{
    int a, b;
    double w;
};

class BellmanFord
{
    int n;
    vector<edge> edges;
    vector<double> d;

public:
    bool is_negative_loop = false;
    BellmanFord(int n) : n(n), edges(n), d(n, numeric_limits<double>::infinity()) {}
    void add_edge(int a, int b, double w)
    {
        assert(0 <= a && a < n && 0 <= b && b < n);
        edges.push_back({a, b, w});
        edges.push_back({b, a, w});
    }

    void add_arc(int a, int b, double w)
    {
        assert(0 <= a && a < n && 0 <= b && b < n);
        edges.push_back({a, b, w});
    }

    // return true if has negative loop
    void build(int a)
    {
        d[a] = 0;
        for (int i = 0; i < n; i++)
        {
            bool change = false;
            for (edge e : edges)
            {
                if (d[e.a] != numeric_limits<double>::infinity())
                {
                    if (d[e.b] > d[e.a] + e.w)
                    {
                        d[e.b] = d[e.a] + e.w;
                        change = true;
                    }
                }
            }
            if (!change)
            {
                return;
            }
        }
        is_negative_loop = true;
    }

    double dist(int a)
    {
        return d[a];
    }
};

int main()
{
    int v, e, r;
    cin >> v >> e >> r;
    BellmanFord g(v);
    for (int i = 0; i < e; i++)
    {
        int a, b, w;
        cin >> a >> b >> w;
        g.add_arc(a, b, w);
    }
    g.build(r);
    if (g.is_negative_loop)
    {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    for (int i = 0; i < v; i++)
    {
        if (g.dist(i) == numeric_limits<double>::infinity())
        {
            cout << "INF" << endl;
        }
        else
        {
            cout << (long long)g.dist(i) << endl;
        }
    }
}



Measured memory_bytes: 3228
#include <iostream>

#include <algorithm>

const int MAXN = 3e5 + 19;

int root, ind;

struct Node{
	int ls, rs;
	int max;
}tr[MAXN << 1];

inline void push_up(int node){
	tr[node].max = std::max(tr[tr[node].ls].max, tr[tr[node].rs].max);
}

void modify(int &node, int L, int R, int x, const int &val){
	if(!node) node = ++ind;
	if(L == R){
		tr[node].max = std::max(tr[node].max, val);
		return;
	}
	int mid = (L + R) >> 1;
	if(x <= mid) modify(tr[node].ls, L, mid, x, val);
	else modify(tr[node].rs, mid + 1, R, x, val);
	push_up(node);
}

int query(int node, int L, int R, int l, int r){
	if(!node) return 0;
	if(l <= L && R <= r) return tr[node].max;
	int mid = (L + R) >> 1, res = 0;
	if(l <= mid) res = std::max(res, query(tr[node].ls, L, mid, l, r));
	if(r > mid) res = std::max(res, query(tr[node].rs, mid + 1, R, l, r));
	return res;
}

int n, k, a[MAXN];
int lim;

int main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	std::cin >> n >> k;
	for(int i = 1; i <= n; ++i) std::cin >> a[i];
	for(int i = 1; i <= n; ++i) lim = std::max(lim, a[i]);
	
	for(int i = 1; i <= n; ++i)
		modify(root, 1, lim, a[i], query(root, 1, lim, a[i] - k, a[i] + k) + 1);
	
	std::cout << query(root, 1, lim, 1, lim) << std::endl;
}

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

int N,A;
//int A[100010];

int main(){
	cin >> N;
	long long ans = 0;
	long long check = 0;
	for(int i=0;i<N;i++){
		cin >> A;
		check += A;
		if(A==0){
			ans += check/2;
			check = 0;
		}
	}
	ans += check/2;
	cout << ans << endl;
}

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int counts=0;
  int countt=0;
  for(int i=0;i<N;i++){
    if(S[i]=='S')counts++;
    else if(counts>0)counts--;
    else countt++;
  }
  cout<<counts+countt<<endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define scl(x) scanf("%lld",x);
map<ll,ll>vis;
vector<string>length[109];
ll len[109];
map<string,ll>cnt;
vector<ll>ans;
vector<ll>ans2;
ll colour[50009];
map<ll,ll>distinct;
vector<ll>not_used;
map<ll,string>name;
int main()
{
  ll i=0,j=1,k,l,p=1,q=1,r,s,t=-1,u=1,v=2,w,x,y=5,z=0,n,m=1,sum=0;
  name[1]="Sheldon",name[2]="Leonard",name[3]="Penny",name[4]="Rajesh",name[5]="Howard";
  string str1,str2,str3;
  cin>>str1>>str2;
  for(i=0;i<str2.size()-1;i++)
    str3=str3+str2[i];
    if(str3==str1)
      cout<<"Yes"<<'\n';
      else
      cout<<"No"<<'\n';
  
  	
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int turn = 0;
    while (A > 0 and C > 0) {
        if (turn & 1) A -= D;
        else C -= B;
        turn = 1 - turn;
    }

    puts(turn == 0 ? "No" : "Yes");
}

Measured memory_bytes: 3632
N,Y = input().split()
N,Y = map(int,(N,Y))
Z = Y
for i in range(N+1):
  Y = Y-10000*i
  for j in range(N+1-i):
    Y = Y-5000*j
    Y = Y-1000*(N-i-j)
    if Y == 0:
      print(i,end = " ")
      print(j,end = " ")
      print(N-i-j,end = " ")
      break
    else :
      Y=Z-i*10000
  else:
    Y = Z
    continue
  break
else :
  print(-1,end=" ")
  print(-1,end=" ")
  print(-1,end=" ")

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  string s; cin >> s;
  cout << (s[2]==s[3] && s[4]==s[5] ? "Yes" : "No");
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    bool f = true;
    rep(i, len(s)) {
        if (i % 2 == 1) {
            if (s[i] == 'R') {
                f = false;
            }
        }
        else {
            if (s[i] == 'L') {
                f = false;
            }
        }
    }
    cout << (f ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int J, Y;

void rec(int j, int y, std::string s){
    if(j == J && y == Y){
        std::cout << s << std::endl;
        return;
    }

    if(j == 5 && y == 5){return;}
    if(j <= 3 && y == 5){return;}
    if(j == 5 && y <= 3){return;}

    if(j+1 <= J){rec(j+1, y, s+'A');}
    if(y+1 <= Y){rec(j, y+1, s+'B');}
}

int main(){
    std::cin >> J >> Y;

    rec(0, 0, "");
}

Measured memory_bytes: 1200
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	ans := make([]int, n+12345)
	left, right := n/2, n/2+1
	for i := 0; i < n; i++ {
		if i%2 == (n-1)%2 {
			ans[left] = a[i]
			left--
		} else {
			ans[right] = a[i]
			right++
		}
	}
	for i := left + 1; i < right; i++ {
		fmt.Print(ans[i], " ")
	}
	fmt.Println()
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535
 
int main() 
{
  FAST;
  ll n;
  cin>>n;
  ll a[n],b[n+1];
  memset(b,0,sizeof(b));
  set<ll> s;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    s.insert(a[i]);
    b[a[i]]++;
  }
  ll ans=1;
  for(auto i=s.begin();i!=s.end();i++)
    ans+=(b[(*i)]*(b[(*i)]-1))/2;
  for(int i=0;i<n;i++)
    cout<<ans-b[a[i]]<<'\n';
  return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto& x:a) cin >> x;
  
  int cnt = 0;
  if(n == 2){
    cnt = (a[0] == a[1] ? 1 : 0);
  }else{
    for(int i = 1; i < n-1; ++i){
      if(a[i] == a[i-1]){
        cnt += 1;
        if(a[i+1] != 10000){
          a[i] = a[i+1] + 1;
        }else{ // a[i+1] == 10000
          if(a[i] != 1){
            a[i] = 1;
          }else{
            a[i] = 2;
          }
        }
      }
    }
    if(a[n-2] == a[n-1]) cnt += 1;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;cin>>s>>t;
  ll sl=s.length(),tl=t.length();
  vector<vector<ll>>dp(sl+1,vector<ll>(tl+1));
  vector<vector<pair<ll,ll>>>par(sl+1,vector<pair<ll,ll>>(tl+1,{-1,-1}));
  repi(i,1,sl+1)repi(j,1,tl+1){
    if(chmax(dp[i][j],dp[i-1][j]))par[i][j]={i-1,j};
    if(chmax(dp[i][j],dp[i][j-1]))par[i][j]={i,j-1};
    if(s[i-1]==t[j-1])if(chmax(dp[i][j],dp[i-1][j-1]+1))par[i][j]={i-1,j-1};
  }
  pair<ll,ll>tp=par[sl][tl];
  string res="";
  while(tp!=(pair<ll,ll>){-1,-1}){
    if(tp.first<sl&&tp.second<tl&&s[tp.first]==t[tp.second])res=s[tp.first]+res;
    tp=par[tp.first][tp.second];
  }
  cout<<res<<endl;

  return 0;

}


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

using namespace std;
bool check(string s){
	for(int i = 0; i < s.length() / 2; ++i){
		if(s[i] != s[s.length() - 1 - i])
			return false;
	}
	return true;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	string s;
	cin >> s;
	int n = s.length();
	string l, r;
	for(int i = 0; i < (n - 1)/2; ++i)
		l+= s[i];
	for(int i = (n + 3)/2 - 1; i < s.length(); ++i){
		r += s[i];
	}
	if(!check(s) || !check(l) || !check(r))
		return cout <<"No", 0;
	cout <<"Yes";
}




Measured memory_bytes: 256
#define N 500005
#define INF 2000000000
#include <stdio.h>

int A[N];
int L[N / 2 + 2];
int R[N / 2 + 2];
int cnt;

void showArray(int A[], int n) {
    for (int i = 0; i < n; i++) {
        printf(" %d" + !i, A[i]);
    }
    printf("\n");
}

void merge(int A[], int left, int mid, int right) {
    // 此为数组中实际元素的个数
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1] = INF;
    R[n2] = INF;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        }
        else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int A[], int left, int right) {
    // 如果当前子数组还有两个以上元素
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left ,mid, right);
    }
} 

int main() {
    int n = 0;
    cnt = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }    
    mergeSort(A, 0, n);
    showArray(A, n);
    printf("%d\n", cnt);
    return 0;
}


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

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, Capacity cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef int Capacity;
struct Dinic {
    int n, s, t;
    vector<int> level, iter, que;
    vector<vector<Capacity>> cap, flow;
    vector<vector<int>> g;
    Capacity inf;
    Dinic(int n)
        : n(n), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
          g(n, vector<int>()), inf(numeric_limits<Capacity>::max()/8){}
    Dinic(const Graph &graph){
        *this = Dinic(graph.size());
        for(int i = 0; i < n; i++) for(auto &e : graph[i]) addEdge(e.src, e.dst, e.cap);
    }
    void addEdge(int u, int v, Capacity c){
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        g[u].push_back(v); g[v].push_back(u);
    }
    inline Capacity residue(int u, int v){ return cap[u][v] - flow[u][v]; }
    Capacity solve(int s, int t){
        this->t = t, this->s = s;
        que.resize(n+1);
        Capacity res = 0;
        while(levelize()){
            iter.assign(n, 0);
            res += augment(s, inf);
        }
        return res;
    }
    bool levelize(){
        int l = 0, r = 0;
        level.assign(n, -1); level[s] = 0;
        que[r++] = s;
        while(l != r){
            int v = que[l++];
            for(const int &d : g[v]){
                if((level[d] != -1 && level[d] <= level[v] + 1) || residue(v,d) == 0) continue;
                level[d] = level[v] + 1; que[r++] = d;
            }
        }
        return level[t] != -1;
    }
    Capacity augment(int v, Capacity lim){
        Capacity res = 0;
        if(v == t) return lim;
        for(int &i = iter[v]; i < (int)g[v].size(); i++){
            const int &d = g[v][i];
            if(residue(v,d) == 0 || level[v] >= level[d]) continue;
            const Capacity aug = augment(d, min(lim, residue(v,d)));
            flow[v][d] += aug; flow[d][v] -= aug;
            res += aug; lim -= aug;
            if(lim == 0) break;
        }
        return res;
    }
};

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

int dp[500][500];
int gcd(int a, int b){
    return a < 500 && b < 500 ? dp[a][b] : b == 0 ? a : gcd(b, a%b);
}


int main(){
    rep(i,500)rep(j,i+1) dp[i][j] = dp[j][i] = __gcd(i,j);
    ios::sync_with_stdio(0);
    cin.tie(0);
    #define endl "\n"
    int n,m;
    while(cin >> n >> m && n|m){
        vector<int> a(n), b(m);
        rep(i,n) cin >> a[i];
        rep(i,m) cin >> b[i];
        Dinic d(n+m+2);
        int s = n+m, t = n+m+1;
        rep(i,m) d.addEdge(i+n,t,1);
        rep(i,n){
            d.addEdge(s,i,1);
            rep(j,m) if(gcd(a[i],b[j]) != 1) d.addEdge(i,n+j,1);
        }
        cout << d.solve(s,t) << endl;
    }
}

// int main(){
//     int N,M;
//     cin >> N >> M;
//     Graph g(N);
//     rep(i,M){
//         int a,b,c;
//         cin >> a >> b >> c;
//         g[a].emplace_back(a,b,c);
//     }
//     Dinic dinic(g);
//     cout << dinic.solve(0,N-1) << endl;
// }

Measured memory_bytes: 11564
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
string ss;
ll ans;
void dfs(string s,int i)
{
	if(i==0)
	{
		dfs(s+ss[i],i+1);
		return;
	}
	if(i==ss.size())
	{
		istringstream sss(s);
		ll x;
		while(sss>>x)
			ans+=x;
		return;
	}
	dfs(s+' '+ss[i],i+1);
	dfs(s+ss[i],i+1);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>ss;
	dfs("",0);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int N;
  int A[200010]={0};
  int result[200010]={0};
  int sum=0;
  scanf("%d",&N);
  for(int i=2;i<=N;i++){
    scanf("%d",&A[i]);
    result[A[i]]++;
  }
  for(int i=1;i<=N;i++){
    printf("%d\n",result[i]);
  }
}

Measured memory_bytes: 3272
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long res = 0;
	long N , D , X; cin >> N >> D >> X ;
	long A[1000]; for (int i = 1; i <= N; i++) cin >> A[i];
	
	for (int i = 1; i <= N; i++){ res += (D / A[i] + 1); if( D % A[i] == 0) res-- ;}

	res += X;

	cout << res << endl;

}

Measured memory_bytes: 256
import sys

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())

x = ni()

c = 1
ans = 1
while(True):
    if(x <= c):
        print(ans)
        break
    else:
        ans += 1
        c += ans


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

using namespace std;

typedef long long ll;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << w * h / 2 << " " << (2 * x == w && 2 * y == h) << endl;
  return 0;
}


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

using namespace std;

int main(){
   string astring;
   cin >> astring;
   for(int i = 0; i<19; i++){
   		if(astring[i] == ','){
   			printf(" ");
   		} else {
   			printf("%c", astring[i]);
   		}
   }
   printf("\n");
}


Measured memory_bytes: 3612