akhauriyash/Code-Regression huggingface dataset:
private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

fun getCost(a: Int, b: Int) = Math.abs(a - b)
fun computeMiddleOmitDiff(a: Int, b: Int, c: Int) = getCost(a, c) - (getCost(a, b) + getCost(b, c))

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readInts()

    val paths = listOf(0) + A + listOf(0)
    val totalCost = paths.fold(Pair(0, 0)) { cp, next ->
        val (cost, prev) = cp
        cost + getCost(prev, next) to next
    }.first

    (1 until N+1).forEach { index ->
        val (a, b, c) = listOf(index - 1, index, index + 1).map { paths[it] }
        println(totalCost + computeMiddleOmitDiff(a, b, c))
    }
}

Measured memory_bytes: 61452
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        long ans = (N / (A + B)) * A + Math.min(N % (A + B), A);
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const ll mod = 1e9 + 7;
int main()
{
	SPEED
	ll h;
	cin >> h;


	ll ptr = 1;
	ll ans = 0;

	while(h!=0)
	{
		ans += ptr;
		h = h>>1;
		ptr = ptr<<1;
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
//#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
//#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long


using namespace std;
typedef pair<int, int>P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


const int MAX = 500010;
const int MOD = 1000000007;
const ll INF = 10e17;

vector<P>vec
; signed main() {
	int N, M; cin >> N >> M;
	REP(i, N) {
		int a, b; cin >> a >> b;
		vec.pb(make_pair(a, b));
	}
	VSORT(vec);
	int cnt = M;
	ll ans = 0;
	REP(i, N) {
		if (cnt >=vec[i].second ) {
			ans += vec[i].first*vec[i].second;
			cnt -= vec[i].second;
		}
		else {
			ans += vec[i].first*cnt;
			cnt = 0;
		}
		if (cnt == 0)break;
	}
	print(ans);
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Graphi = vector<vi>;
using Graphe = vector<vector<edge> >;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){

    int n,m; cin >> n >> m;
    vi a(m),b(m);
    rep(i,m){
         int x,y; cin >> x >> y;
         x--;y--;
        a.at(i) = x;
        b.at(i) = y;
    }
    int cnt = 0;
    rep(i,m){
        UnionFind tree(n);
        rep(j,m){
            if(j == i) continue;
            tree.unite(a.at(j),b.at(j));
        }
        int k = 0;
        for(int l = 1; l < n; l++){
            if(!tree.same(0,l)){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    vector<int> a(n + 1);

    ll sum = 0;
    FOR(i, 1, n+1) {
        cin >> a[i];
        sum += a[i];
    }
    
    vector<ll> r(n + 1, 0);
    r[1] = sum;

    FOR(i, 1, n / 2 + 1) r[1] -= a[i * 2] * 2;
    
    FOR(i, 2, n + 1) {
        r[i] = 2 * a[i-1] - r[i-1];
    }

    FOR(i, 1, n + 1) {
        cout << r[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2432
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
  for i in range(4):
    t = list(last4)
    if i >= 1:
      t[i-1], t[i] = t[i], t[i-1]
    if ''.join(t).count('AGC') >= 1:
      return False
  return True
def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == N:
    return 1
  ret = 0
  for c in 'ACGT':
    if ok(last3 + c):
      ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
  return ret
print(dfs(0, 'TTT'))

Measured memory_bytes: 3872
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

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

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [usize;n],
    }
    let mut light = a[0];
    let mut cnt = 0;
    for i in 0..n {
        cnt += 1;
        if light==2 {
            println!("{}", cnt);
            return;
        }
        light = a[light-1];
    }
    println!("-1");
}


Measured memory_bytes: 3300
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;

bool comp(ll x, ll y){
	ll x1=x, y1=y;
	ll d1=0, d2=0;
	while(x1>0){
		d1+=(x1%10);
		x1/=10;
	}
	while(y1>0){
		d2+=(y1%10);
		y1/=10;		
	}
	if(x*d2!=y*d1){
		return x*d2<y*d1;
	}else{
		return x<y;
	}
}

int main()
{
	int k;
	scanf("%d", &k);
	vector<ll> v;
	ll p10=1;
	set<ll> st;
	for(ll d=1; d<=13; d++){
		for(ll i=1; i<1000; i++){
          if((i+1)*p10-1<=1e15){
			st.insert((i+1)*p10-1);
          }
		}
		p10*=10;
	}
	for(auto itr=st.begin(); itr!=st.end(); itr++){
		v.push_back(*itr);
	}
	bool e[200000]={};
  	ll m=v.back();
	for(int i=v.size()-2; i>=0; i--){
		if(!comp(v[i], m)){
          e[i]=1;
        }else{
          m=v[i];
        }
	}
	int t=0, i0=0;
	while(t<k){
		if(e[i0]==1){
			i0++;
			continue;
		}else{
			printf("%lld\n", v[i0]);
          i0++;
          t++;
        }
    }
	return 0;
}


Measured memory_bytes: 1280
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())

for i in range(n):
    b = int(input())
    if b in a1:
        a1[a1.index(b)] = 0
    elif b in a2:
        a2[a2.index(b)] = 0
    elif b in a3:
        a3[a3.index(b)] = 0

ans = "No"
bi = [0,0,0]
if a1 == bi or a2 == bi or a3 == bi:
    ans = "Yes"
elif a1[0] == 0 and a2[1] == 0 and a3[2] == 0:
    ans = "Yes"
elif a1[2] == 0 and a2[1] == 0 and a3[0] == 0:
    ans = "Yes"
else:
    for i in range(3):
        if a1[i] == 0 and a2[i] == 0 and a3[i] == 0:
            ans = "Yes"
            break
print(ans)    

Measured memory_bytes: 3064
//package AtCoder;
import java.util.*;
class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int a=sc.nextInt();
		int c=0;
		int ans=h/a;
		if(h%a==0)
			System.out.println(ans);
		else
		{
			ans=ans+1;
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 22732
#include<iostream>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>//min,max,swap,rand,reverse,sort,lower_bound
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<tuple>
#include<cmath>//abs, sin, cos
#include<bitset>
using namespace std;

int main()
{
	string X;
	string A;
	A = '0';
	int count = 1;
	while (1) {
		cin >> X;
		if (X == A) {
			cout << count << endl;
			break;
		}
		count++;
	}
	return 0;
}

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

typedef long long ll;
const ll INF = 1e18;

int main(int argc, char* argv[])
{
  std::string S, T;
  std::cin >> S >> T;

  std::vector< ll > vs(26, 0);
  std::vector< ll > vt(26, 0);
  for (std::string::iterator it = S.begin(); it != S.end(); it++) {
    vs[*it - 'a']++;
  }
  for (std::string::iterator it = T.begin(); it != T.end(); it++) {
    vt[*it - 'a']++;
  }

  std::sort(vs.begin(), vs.end());
  std::sort(vt.begin(), vt.end());  

  std::string judge = "Yes";
  for (ll i = 0; i < 26; i++) {
    if (vs[i] != vt[i]) {
      judge = "No";
    }
  }

  std::cout << judge << std::endl;

  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <set>
using namespace std;
using ll = long long;

int main(){
  int n; cin >> n;
  ll a[n+1], b[n+1];
  for(int i=1; i<=n; i++){
    cin >> a[i];
    b[a[i]] = i;
  }

  ll ans = 0;
  set<ll> s; 
  s.insert(0); s.insert(n+1);
  for(int i=1; i<=n; i++){
    auto itr = s.upper_bound(b[i]);
    ans += (*itr-b[i]) * (b[i]-*(--itr)) * i;
    s.insert(b[i]);
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	int n;cin>>n;
	if(n == 100000){
		cout << 99999 - 10000 + 1 + 999 - 100 + 1 + 9 << endl;
	}else if(n >= 10000){
		cout << n - 10000 + 1 + 999 - 100 + 1 + 9 << endl;
	}else if(n >= 1000){
		cout << 999 - 100 + 1 + 9 << endl;
	}else if(n >= 100){
		cout << n - 100 + 1 + 9 << endl;
	}else if(n >= 10){
		cout << 9 << endl;
	}else{
		cout << n << endl;
	}
}



Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n;
ll a[maxn], s[maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cin >> n;
	for(int i = 1; i <= n; ++i) 
		cin >> a[i], s[i] = (s[i - 1] + a[i]) % mod;
	ll ans = 0;
	for(int i = 1; i < n; ++i)
		ans = (ans + a[i] * (s[n] - s[i] + mod) % mod) % mod;
	cout << ans << endl;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  int acc = 0, answer = 0;
  for (const auto &c : S) {
    acc += (c == 'I') ? 1 : -1;
    answer = max(answer, acc);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long
#define cat(p) cout<<p<<endl
#define catA(p,n) for(int i=0;i<n;i++)cout<<p[i]<<((i==n-1)?"\n":" ")

ll a,b,c,d;
ll canC,canD,canCD;

ll gcd(ll a,ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  cin>>a>>b>>c>>d;
  ll aa=a-1;
  canC=b/c-aa/c;
  canD=b/d-aa/d;
  canCD=b/(c*d/gcd(c,d))-aa/(c*d/gcd(c,d));
  //cout<<canC<<" "<<canD<<" "<<canCD<<endl;
  cout<<(b-a+1)-(canC+canD-canCD)<<endl;
  return 0;
}


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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll n;
	cin>>n;
	ll a[n];
	ll i,j;
	rep(i,0,n)
	    cin>>a[i];
	 
	 ll k=1;
	 rep(i,0,n){
	     if(a[i]==k)
	        k++;
	 }if(k==1)
	    cout<<-1;
	    else if(k==n+1)
	        cout<<0<<endl;
	   else
	    cout<<n-k+1;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) //ループ変数は1ずつデクリ
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--) //ループ変数は1ずつデクリ
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

ll pcnt(ll x) { return __builtin_popcountll(x); }

ll f(ll x) {
    if (x == 0) {
        return 0;
    }
    return f(x % pcnt(x)) + 1;
}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> x(n);
    REP(i, n) { x[i] = s[i] - '0'; }
    ll pc = 0;
    vector<ll> ans(n);
    REP(i, n) pc += x[i]; // 最初のpopcount

    // popcountが1増える場合と減る場合
    REP(b, 2) {
        ll npc = pc;
        if (b == 0) {
            npc++;
        } else {
            npc--;
        }
        if (npc == 0) {
            continue;
        }

        // オリジナルの整数
        ll r0 = 0;
        REP(i, n) {
            r0 = (r0 * 2) % npc;
            r0 += x[i];
        }
        ll k = 1;
        REPD(i, n) {
            // 右からi桁目を変えたときのansを格納
            if (x[i] == b) {
                ll r = r0;
                if (b == 0) {
                    r = (r + k) % npc;
                } else {
                    r = (r - k + npc) % npc;
                }
                ans[i] = f(r) + 1;
            }
            k = (k * 2) % npc;
        }
    }
    REP(i, n) { cout << ans[i] << endl; }
}


Measured memory_bytes: 6840
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;
const int N = 100005;

int h, w, n, v[6][6], ans[N];
pii a[N];

map<pii, int> mp;
map<pii, bool> vis;

bool valid (int X, int Y) {
	if(X<2 || h<=X || Y<2 || w<=Y) return false;
	if(vis[pii(X, Y)]) return false;
	return true;
}

int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&a[i].X,&a[i].Y);
		mp[a[i]] = 1;
	}
	for(int i=1;i<=n;i++) {
		for(int j=0;j<=4;j++) for(int k=0;k<=4;k++) {
			v[j][k] = mp[pii(a[i].X-2+j, a[i].Y-2+k)];
		}
		for(int j=1;j<=3;j++) for(int k=1;k<=3;k++) {
			int cx = a[i].X-2+j, cy = a[i].Y-2+k, cc = 0;
			if(!valid(cx, cy)) continue;
			for(int A=-1;A<=1;A++) for(int B=-1;B<=1;B++) {
				cc += v[j+A][k+B];
			}
			ans[cc]++;
			vis[pii(cx,cy)] = true;
		}
	}
	long long z = 1ll * (h-2) * (w-2);
	for(int i=1;i<=9;i++) z -= ans[i];
	printf("%lld\n",z);
	for(int i=1;i<=9;i++) printf("%d\n",ans[i]);
}


Measured memory_bytes: 213504
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(C, B / A) << '\n';
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (r1, c1, r2, c2) = readLine()!!.split(" ").map(String::toInt)
    val combi = Combination(2000002)
    fun g(r: Int, c: Int) = combi(r + 1 + c + 1, c + 1)
    val ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
    println(ans)
}

class MInt {
    private val MOD = 1000000007L
    var v: Long

    constructor(v: Long) {
        this.v = v % MOD
    }

    constructor(v: Int) {
        this.v = v.toLong() % MOD
    }

    operator fun plus(b: MInt): MInt {
        val a = MInt(v)
        a += b
        return a
    }

    operator fun minus(b: MInt): MInt {
        val a = MInt(v)
        a -= b
        return a
    }

    operator fun times(b: MInt): MInt {
        val a = MInt(v)
        a *= b
        return a
    }

    operator fun div(b: MInt): MInt {
        val a = MInt(v)
        a /= b
        return a
    }

    operator fun plusAssign(b: MInt) {
        v += b.v
        if (v >= MOD) v -= MOD
    }

    operator fun minusAssign(b: MInt) {
        v -= b.v
        if (v < 0) v += MOD
    }

    operator fun timesAssign(b: MInt) {
        v *= b.v
        v %= MOD
    }

    operator fun divAssign(b: MInt) {
        this *= b.inv()
    }

    fun inv(): MInt {
        var a = v
        var b = MOD
        var u = 1L
        var w = 0L
        while (b != 0L) {
            val t = a / b
            a -= t * b
            u -= t * w
            var tmp = a
            a = b
            b = tmp
            tmp = u
            u = w
            w = tmp
        }
        u %= MOD
        if (u < 0) u += MOD
        return MInt(u)
    }

    fun pow(n: Int): MInt {
        var a = MInt(1)
        for (i in 1..n) a = a * this
        return a
    }

    override fun toString(): String {
        return v.toString()
    }
}

class Combination(n: Int) {
    private val fact = arrayOfNulls<MInt>(n + 1)
    private val ifact = arrayOfNulls<MInt>(n + 1)

    init {
        fact[0] = MInt(1)
        (1..n).forEach { i -> fact[i] = fact[i - 1]!! * MInt(i) }
        ifact[n] = fact[n]!!.inv()
        (n downTo 1).forEach { i -> ifact[i - 1] = ifact[i]!! * MInt(i) }
    }

    operator fun invoke(n: Int, k: Int): MInt {
        if (k < 0 || n < k) return MInt(0)
        return (fact[n]!! * ifact[k]!! * ifact[n - k]!!)
    }
}

Measured memory_bytes: 287764
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,D,E;
    cin>>A>>B>>C>>D>>E;
    if(A>0){
        cout<<(B-A)*E<<endl;
    }
    else if(A<0){
        cout<<C*(-A)+D+B*E<<endl;
    }
    
}    



Measured memory_bytes: 3060
'use strict'
function main(i) {
  i = i.trim().split('\n')
  const N = Number(i.shift())
  const A = i.shift().split(' ').map(n => Number(n))
  const B = i.shift().split(' ').map(n => Number(n))
  let ans = 0
  for (let i = 0; i < N; i++) {
    if (A[i] >= B[i]) {
      ans += B[i]
      A[i] -= B[i]
      B[i] = 0
    } else {
      ans += A[i]
      B[i] -= A[i]
      A[i] = 0
      if (A[i+1] >= B[i]) {
        ans += B[i]
        A[i+1] -= B[i]
        B[i] = 0
      } else {
        ans += A[i+1]
        B[i] -= A[i+1]
        A[i+1] = 0
      }
    } 
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 31764
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::fmt;
#[allow(unused_imports)]
use std::fmt::Debug;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let s = get_string_input().trim().to_string();
    let s = s.clone() + &s;
    let p = get_string_input();
    if s.contains(&p.trim()) {
        println!("Yes");
    } else {
        println!("No");
    }
}

#[allow(dead_code)]
fn sum_digit2(value: String) -> u32 {
    return value.chars().fold(0u32, |a, b| a + b.to_digit(10).unwrap());
}

#[allow(dead_code)]
fn sum_digit(value: i64) -> i64 {
    if value < 10 {
        return value;
    }
    return sum_digit(value / 10) + value % 10;
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn get_vec_input<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<T> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    vec
}

#[allow(dead_code)]
fn get_tuple_input() -> (u64, f32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: u64 = iter.next().unwrap().parse().unwrap();
    let n: f32 = iter.next().unwrap().parse().unwrap();
    (c, n)
}

#[allow(dead_code)]
fn get_string_input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    s
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int main(){

	int x = nxt(), y = nxt();
	int ans = 0;
	if (abs(x) == abs(y)) {
		if (x == y) {
			ans = 0;
		} else {
			ans = 1;
		}
	} else if (abs(x) < abs(y)) {
		if (x < 0) {
			ans += 1;
			x = -x;
		}
		ans += abs(y) - x;
		if (y < 0) {
			ans += 1;
		}
	} else {
		if (x > 0) {
			ans += 1;
			x = -x;
		}
		ans += abs(x) - abs(y);
		if (y > 0) {
			ans += 1;
		}
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
h = list(map(int, input().split()))

ans = 0

while sum(h) != 0:
    s = 0
    for i in range(N):
        if h[i] == 0 and s == 1:
            ans += 1
            break
        elif h[i] != 0:
            h[i] -= 1
            s = 1
        if i == N - 1:
            ans += 1
print(ans)

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

using namespace std;

int main()
{
    int b,n,sum=0,i;
    cin>>n;
    string a;
    cin>>a;
    for(i=0;i<n;i++){
        if(a[i]!=a[i+1]){
            sum++;
        }
    }
    cout<<sum<<endl;

}


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

#define ft first
#define sd second
#define sz(x) ((int)x.size())
#define int long long

using namespace std;

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






int dx[] = {-1, 0, 1}, dy[] = {-1, 0, 1};
map<pii, int> mp;
int n, r, c, ans[10];

int32_t main() {
	cin >> r >> c >> n;
	int a, b;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		a--, b--;
		for (auto j : dx)
			for (auto k : dy)
				if (a + j >= 1 && a + j < r - 1 && b + k >= 1 && b + k < c - 1)
					mp[{a + j, b + k}]++; 
	}
	for (auto i : mp)
		ans[i.sd]++;
	int sum = 0;
	for (auto i : ans)
		sum += i;
	cout << (r - 2) * (c - 2) - sum << '\n';
	for (int i = 1; i < 10; i++)
		cout << ans[i] << '\n';
	return 0;
}

Measured memory_bytes: 56448
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>

using namespace std;
using lint = long long;
using pii = pair<int, int>;
using vec = vector<int>;
using pq = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define mp(x, y) make_pair((x), (y))
#define space " "

constexpr lint MOD = 1e9 + 7;
constexpr int INF = 1<<(int)29;
int A, B, C, F, H, I, J, K, L, M, N, P, Q, R, S, T, U, V, W, X, Y;
// lint A, B, C, F, H, I, J, K, L, M, N, P, Q, R, S, T, U, V, W, X, Y;
int ans = INF;
// string ans;
vector<vec> d;
vec r;

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

	cin >> N >> M >> R;
    r.resize(R);
	rep(i, R) {
        cin >> r[i];
        r[i]--;
	}
    sort(all(r));

    d.assign(N, vec(N, INF));
    rep(i, M) {
        cin >> A >> B >> C;
        A--; B--;
        if (d[A][B] > C) {
            d[A][B] = d[B][A] = C;
        }
    }

    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
	
	do {
        int rst = 0;
        rep(i, R - 1) {
            rst += d[r[i]][r[i+1]];
        }
        ans = min(ans, rst);
    } while (next_permutation(all(r)));

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

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;

int main() {
	int n = 1;
	unsigned long long ans = 0;
	string s, t, buffer;
	cin >> s;
	for (int i = 0; i < (1 << s.length() - 1); ++i) {
		stringstream ss;
		t = s;
		n = 1;
		for (int j = 0; j <= s.length() - 1; ++j) {
			if (i&(1 << j)) {
				t.insert(t.begin() + j + n, '+');
				n++;
			}
		}
		ss << t;
		while (getline(ss, buffer, '+')) {
			ans += stoull(buffer);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,h,w;
struct ele{
	int X,Y,V;
	void set(int _X,int _Y,int _V){
		X=_X;Y=_Y;V=_V;
	}
	bool operator <(ele B) const{
		return V>B.V;
	}
}es[100005];
namespace DSU{
	int fa[200005],sz[200005],cnt[200005];
	void init(){
		int i;
		for(i=0;i<200005;++i) fa[i]=i,sz[i]=1;
		memset(cnt,0,sizeof(cnt));
	}
	int anc(int x){
		return (fa[x]==x?x:(fa[x]=anc(fa[x])));
	}
	void mrg(int x,int y){
		x=anc(x);y=anc(y);
		if(x!=y){
			fa[x]=y;
			sz[y]+=sz[x];
			cnt[y]+=cnt[x];
		}
	}
}
int main(){
	int i,j,k;
	scanf("%d%d%d",&n,&h,&w);
	for(i=0;i<n;++i){
		int R,C,A;
		scanf("%d%d%d",&R,&C,&A);
		es[i].set(R,C,A);
	}
	DSU::init();
	sort(es,es+n);
	LL res=0ll;
	for(i=0;i<n;++i){
		int x=es[i].X,y=h+es[i].Y,z=es[i].V;
		x=DSU::anc(x);
		y=DSU::anc(y);
		using namespace DSU;
		if(x==y && cnt[x]==sz[x]-1){
			++cnt[x];
			res+=(LL)z;
		}
		else if(x!=y && (cnt[x]<sz[x] || cnt[y]<sz[y])){
			mrg(x,y);
			++cnt[y];
			res+=(LL)z;
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

ll n,sum;
ll A[100001],dp[100001],d[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> A[i];
        if(i==0)
        {
            d[i] = A[i];
        }
        else
        {
            d[i] = A[i] - A[i-1];
        }
        sum += abs(d[i]);
    }
    d[n] = 0-A[n-1];
    sum += abs(d[n]);
    /*for(int i = 0; i <= n; i++)
    {
        cout << d[i] << " ";
    }
    cout << endl;*/
    for(int i = 0; i < n; i++)
    {
        if((d[i]>=0&&d[i+1]>=0)||(d[i]<0&&d[i+1]<0))
        {
            cout <<  sum << endl;
        }
        else
        {
            ll ori = abs(d[i]) + abs(d[i+1]);
            ll chg = d[i] + d[i+1];
            ll dif;
            if(ori>=0&&chg>=0)dif = abs(ori - chg);
            else dif = abs(ori + chg);
            //cout << ori << " " << chg << " " << dif << endl;
            cout << sum - dif << endl;
        }
    }

}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

bool checksum(string s){
    int sum = 0;
    int n=s.size();

    for(int i=0;i<n-1;i++){
        sum+=(s[i]-'0');
    }
    sum=sum%10;
    if(sum==(s[n-1]-'0')){
        return true;
    }else{
        return false;
    }
}
int stoi0(string s){
    int ind=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!='0'){
            return stoi(s.substr(i));
        }
    }
    return 0;
}

signed main(){ 
    int a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;

    if(w>=v) cout<<"NO"<<endl;
    else{
        int div=v-w;
        if(div*t>=abs(b-a)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}  

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[234567];
signed main(){
	int n;
	cin>>n;
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	int s=0;
	int Min=2e9+10;
	for(int i=0;i<n-1;i++){
		s+=a[i];
		sum-=a[i];
		Min=min(Min,abs(s-sum));
	}
	cout << Min <<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    if(N == 1){
        printf("First\n");
        return 0;
    }
    vector<vector<int>> G(N);
    int a, b;
    for (int i = 0; i < N-1; i++) {
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> q;
    vector<int> ds(N, inINF);
    ds[0] = 0;
    q.push(0);
    int tmp;
    while(!q.empty()){
        tmp = q.front();
        q.pop();
        for (int v : G[tmp]){
            if(ds[v] < inINF){
                continue;
            }
            ds[v] = ds[tmp] + 1;
            q.push(v);
        }
    }


    int m = 0;
    int ind;
    for (int i = 0; i < N; i++) {
        if(ds[i] > m){
            ind = i;
            m = ds[i];
        }
    }

    fill(ALL(ds), inINF);
    q.push(ind);
    ds[ind] = 0;
    while(!q.empty()){
        tmp = q.front();
        q.pop();
        for (int v : G[tmp]){
            if(ds[v] < inINF){
                continue;
            }
            ds[v] = ds[tmp] + 1;
            q.push(v);
        }
    }
    m = 0;    
    for (int i = 0; i < N; i++) {
        if(ds[i] > m){
            ind = i;
            m = ds[i];
        }
    }
    
    if(m % 3 == 1){
        printf("Second\n");
    }
    else{
        printf("First\n");
    }

}  

Measured memory_bytes: 16528
#include<iostream>
using namespace std;
long long a,b=0,c=0,d,e[1000001],f[1000001];
int main(){
	cin>>a;
	for(long long i=1;i<=a;i++){
		b=0;
		for(long long j=1;j<=i;j++){
			if(i%j==0&&i%2!=0){					
				b++;
			}
		}
		if(b==8){
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func cmb(n int) int {
	return (n * (n - 1)) / 2
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	s := make([]int, n)
	s[0] = a[0]
	for i := 1; i < n; i++ {
		s[i] = s[i-1] + a[i]
	}
	sort.Sort(sort.IntSlice(s))

	ans := 0
	for l := 0; l < n; l++ {
		r := l
		for r+1 < n && s[r+1] == s[l] {
			r++
		}
		ans += cmb(r - l + 1)
		if s[l] == 0 {
			ans += r - l + 1
		}
		l = r
	}

	puts(ans)
}


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

#define Bye return 0
#define ll long long

void solve(){
    int a, b; cin>>a>>b;

    a = a == 1 ? 14 : a;
    b = b == 1 ? 14 : b;

    if(a == b)
        cout<<"Draw"<<endl;
    else
        cout<<((a>b)?"Alice" : "Bob")<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
typedef long long ll;

// ax + by = gcd(a, b) なるx,yを計算する
// O(logN)
ll extGCD(ll a, ll b, ll &x, ll &y) {
    ll d = a;
    if (b == 0) {
        x = 1;
        y = 0;
    } else {
        d = extGCD(b, a % b, y, x);
        y -= (a / b) * x;
    }
    return d;
}


// verified
//   https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E
void AOJ_NTL_1_E() {
    ll a, b, x, y;
    cin >> a >> b;
    extGCD(a, b, x, y);
    cout << x << " " << y << "\n";
}

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


Measured memory_bytes: 3112
q,h,s,d = map(int,input().split())
n = int(input())*4
#小数点の挙動がよくわからなかったため，全部4倍して0.25を基準としたらうまく行った
k = [
    [q*8,q,1],
    [h*4,h,2],
    [s*2,s,4],
    [d,d,8]
    ]
k.sort() #単価の安い順にする．
cost = 0
for i in range(4):
    num = n // k[i][2] * k[i][1]
    cost += num
    n %= k[i][2]
print(int(cost))


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    if K <= A + B:
        print(min(A, K))
    else:
        print(A - (K - A - B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S, X, Y;
cin >> S;
bool rev = 0;
int N;
cin >> N;
for(int i = 0; i < N; i++){
int a, b;
string c;
cin >> a;
if (a == 2){
cin >> b >> c;
b--;
if(rev) b = 1 - b;
if(b == 0) X += c;
else Y += c;
}
else rev = 1 - rev;
}
reverse(X.begin(), X.end());
string ans = X + S + Y;
if(rev) reverse(ans.begin(), ans.end());
cout << ans << endl;
} 


Measured memory_bytes: 1348
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

template<class Type> Type ilcm(Type x,Type y){return x/__gcd(x,y)*y;}

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	
	int cnt=0;
	int now=1;
	REP(i,n){
		if(a[i]==now) now++;
		else cnt++;
	}
	
	if(cnt==n) cout<<-1<<endl;
	else cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
int num;
cin >> num;
if(num<600){
cout << 8<<endl;  
}else if(num<800){
  cout << 7<<endl;  
}else if(num<1000){
  cout << 6<<endl;  
}else if(num<1200){
  cout << 5<<endl;  
}else if(num<1400){
  cout << 4<<endl;  
}else if(num<1600){
  cout << 3<<endl;  
}else if(num<1800){
  cout << 2<<endl;  
}else if(num<2000){
  cout << 1<<endl;  
}
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




ll dp[303][303][303];
// 番号, 左隣のありうる高さ, 減らせる回数

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    
    const ll INF = 1e18;
    rep(i, 303) rep(j, 303) rep(l, 303) dp[i][j][l] = INF;
    dp[0][0][0] = h[0];
    dp[0][n][1] = 0;
    
    rep3(i, 1, n) {
        rep(l, k + 1) {
            rep(j, n) {
                if (dp[i - 1][j][l] == INF) continue;
                if (h[j] >= h[i]) {
                    // cout << i << " " << j << " " << l << endl;
                    chmin(dp[i][i][l], dp[i - 1][j][l]);
                } else {
                    chmin(dp[i][i][l], dp[i - 1][j][l] + h[i] - h[j]);
                }
                chmin(dp[i][j][l + 1], dp[i - 1][j][l]);
            }
            // 高さ0
            if (dp[i - 1][n][l] == INF) continue;
            // 加算
            chmin(dp[i][i][l], dp[i - 1][n][l] + h[i]);
            // 下げる
            chmin(dp[i][n][l + 1], dp[i - 1][n][l]);
        }
    }
    
    ll ans = 1e18;
    rep(j, n + 1) rep(l, k + 1) {
        if (dp[n - 1][j][l] == -1) continue;
        chmin(ans, dp[n - 1][j][l]);
    }
    cout << ans << endl;
    
    /*
    rep(i, n) {
        cout << endl;
        rep(j, n + 1) { rep(l, k + 1) cout << dp[i][j][l] << " "; cout << endl; }
    }
     */
}




Measured memory_bytes: 217600
S = input()
maxi = max(S.count("a"), S.count("b"), S.count("c"))
mini = min(S.count("a"), S.count("b"), S.count("c"))
mid = len(S)-maxi-mini
if maxi == mid and mid == mini:
    print("YES")
elif maxi == mid + 1 and mid == mini:
    print("YES")
elif maxi == mid and mid == mini + 1:
    print("YES")
else:
    print("NO")

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

keta = len(str(N))

n = N
ans = 0
while True:
    if keta == 0:
        break
    if keta % 2 == 0:
        keta = keta -1
        n = 10**keta - 1
    keta = keta - 1
    ans = ans + (n - 10**keta + 1)
    n = 10**keta - 1

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
class UnionFind {
  public:
    vector<int> parent;
    UnionFind(int n) {
        parent = vector<int>(n, -1);
    }
    int root(int a) {
        if (parent[a] < 0) return a;
        return parent[a] = root(parent[a]);
    }
    int size(int a) {
        return -parent[root(a)];
    }
    bool is_connected(int a, int b) {
        return root(a) == root(b);
    }
    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) {
            return false;
        }
        if (size(a)<size(b)) swap(a, b);
        parent[a] += parent[b];
        parent[b] = a;
        return true;
    }
};
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (auto & a : A) cin >> a;
    for (auto & b : B) cin >> b;
    vector<int> AS = A, BS = B;
    sort(AS.begin(), AS.end());
    sort(BS.begin(), BS.end());
    map<int, int> AB, BI;
    UnionFind UF(N);
    for (int i = 0; i < N; ++i) {
        if (BS[i] < AS[i]) {
            puts("No");
            return 0;
        }
        AB[AS[i]] = BS[i];
        BI[B[i]] = i;
    }
    for (int i = 0; i < N; ++i) {
        UF.connect(i, BI[AB[A[i]]]);
    }
    for (int i = 1; i < N; ++i) {
        if (BS[i-1] >= AS[i]) {
            puts("Yes");
            return 0;
        }
        if (UF.root(i) != UF.root(i-1)) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 13056
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

ll mod = 1e9 + 7;
ll dp[3005][3005], sum[3005];

int main() {
	int n; cin >> n;
	string s; cin >> s;
	s = "@" + s;
	for (int i = 0; i < n; i++) dp[0][i] = 1;
	for (int i = 1; i < n; i++) {
		sum[0] = dp[i - 1][0];
		for (int j = 1; j <= n; j++) sum[j] = (sum[j - 1] + dp[i - 1][j])%mod;
		for (int j = 0; j < n - i; j++) {
			if (s[i] == '<') dp[i][j] = sum[j];
			else dp[i][j] = (sum[n] - sum[j] + mod)%mod;
		}
	}
	cout << dp[n-1][0] << endl;
	return 0;
}

Measured memory_bytes: 70016
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n+1-i):
        if(10000*i+5000*j+1000*(n-i-j) == y):
            print(i, j, (n-i-j))
            exit()
print(-1, -1, -1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6+1;
vector<int> freq(N,1);
void solve()
{
	for(int i = 1; i < N;++i){
		for(int j = 2*i; j < N;j+=i)
			++freq[j];
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	solve();
	ll ans = 0;
	for(int i = 1; i <= n-1;++i){
		int num = n-i;
		ans += freq[num];
	}
	cout << ans << "\n";
}


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

using namespace std;

const int N = 1005, M = 2e5 + 5;
int n, m, a[M], b[M];
vector <int> adj[N], rev[N];
bool ans[M], mark[N], tmp[M];

void dfs1(int u, int ban) {
	mark[u] = 1;
	for (int ind : adj[u]) {
		int v = b[ind];
		if (v == ban || mark[v]) continue;
		dfs1(v, ban);
	}
}

void solve(int u) {
	for (int k = 0; k < adj[u].size(); ++k) {
		int ind = adj[u][k];
		int v = b[ind];
		tmp[ind] |= mark[v];
		dfs1(v, u);
	}
	memset(mark, 0, sizeof mark);
	for (int k = adj[u].size() - 1; k >= 0; --k) {
		int ind = adj[u][k];
		int v = b[ind];
		tmp[ind] |= mark[v];
		dfs1(v, u);
	}
	for (int ind : adj[u]) {
		ans[ind] ^= tmp[ind];
	}
}

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

	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> a[i] >> b[i];
		adj[a[i]].push_back(i);
		rev[b[i]].push_back(i);
	}
	for (int i = 1; i <= n; ++i) {
		memset(mark, 0, sizeof mark);
		dfs1(i, -1);
		for (int ind : rev[i]) {
			int u = a[ind];
			if (mark[u]) ans[ind] = 1;
		}
	}
	for (int i = 1; i <= n; ++i) {
		memset(mark, 0, sizeof mark);
		solve(i);
	}
	for (int i = 1; i <= m; ++i) if (ans[i] == 0) {
		cout << "same\n";
	} else cout << "diff\n";

	return 0;
}

Measured memory_bytes: 6272
class unionFind():
	def __init__(self,n):
		self.tree=[-1]*n
	def find(self,x):
		if self.tree[x]<0:
			return x
		else:
			self.tree[x]=self.find(self.tree[x])
			return self.tree[x]
	def union(self,x,y):
		xr=self.find(x)
		yr=self.find(y)
		if xr!=yr:
			if self.tree[xr]<self.tree[yr]:
				self.tree[yr]=xr
			elif self.tree[xr]>self.tree[yr]:
				self.tree[xr]=yr
			else:
				self.tree[xr]-=1
				self.tree[yr]=xr
			return True
		
		return False
def main():
	ans=0
	n,m=map(int,input().split())
	a=unionFind(n)
	li=[x-1 for x in list(map(int,input().split()))]
	for _ in range(m):
		x,y=map(int,input().split())
		a.union(x-1,y-1)
	for x in range(n):
		ans += a.find(x)==a.find(li[x])
	return ans
print(main())

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

const int INF = 0x3f3f3f3f;

typedef long long unsigned llu;
typedef long long lld;
typedef long ld;

#define N 100005
lld a[N], dp[N];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int i, n, k, j;
	cin >> n >> k;
	for(i = 1 ; i <= n ; i++) {
        cin >> a[i];
        dp[i] = INF;
    }
	dp[1] = 0;
	for(i = 1 ; i <= n ; i++) {
        j = i+1;
        while(j <= min(n, i+k)) {
            dp[j] = min(dp[j], dp[i] + abs(a[i]-a[j]));
            j++;
        }
    }
	cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1792