akhauriyash/Code-Regression huggingface dataset:
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long long int> VLL;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    io;
    int n;
    cin >> n;
    VLL a(n+1);
    for (auto &x : a) {
        cin >> x;
    }

    vector<PLL> r(n+1);
    if (a[0] > 1) {
        cout << -1 << "\n";
        return 0;
    }
    if (a[0] == 1) {
        if (SZ(a) > 1) {
            cout << -1 << "\n";
        } else {
            cout << 1 << "\n";
        }
        return 0;
    }

    r[0] = {1, 1};
    for (int i = 1; i <= n; i++) {
        r[i] = {r[i-1].fi, min(LLONG_MAX/4, (ll)2ll*r[i-1].se)};
        if (a[i] > r[i].se) {
            cout << -1 << "\n";
            return 0;
        }
        if (i < n and a[i] == r[i].se) { // check
            cout << -1 << "\n";
            return 0;
        }
        if (i != n)
            assert(r[i].fi > 0 and r[i].se > 0);
        r[i].se -= a[i];
        r[i].fi -= a[i];
        r[i].fi = max(r[i].fi, 1ll);
        if (i != n)
        assert(r[i].fi > 0 and r[i].se > 0);

    }

    ll ans = a[n];
    ll below = a[n];
    for (int i = n-1; i >= 0; i--) {
        ll nl = min(r[i].se, below);
        below = nl + a[i];
        ans += below;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 5576
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (1000)
#define MOD (998244353)


//グラフ
#define MAXV (MAXN*MAXN)
int Gv;
typedef struct edge
{
    int to;
    struct edge* next;
}edge;

edge* Ge[MAXV]; //vから出てる有向辺
int Gd[MAXV]; //vの次数

// vは頂点数、指定するときは0～(v-1)
void Ginit(int v)
{
    Gv = v;
}

void Gadd(int v, int to)
{
    edge* e = malloc(sizeof(edge));
    e->to = to;
    e->next = Ge[v];
    Ge[v] = e;
    Gd[v]++;
}

// 最長経路
// 閉路があれば-1
bool GLPvisit[MAXV];
bool GLPfixed[MAXV];
int GLP[MAXV];
int GLP_DFS(int v)
{
    if(GLPvisit[v])
    {
        return GLPfixed[v] ? GLP[v] : -1;
    }
    GLPvisit[v] = true;
    GLP[v] = 0;
    edge* e = Ge[v];
    while(e!=NULL)
    {
        int l = GLP_DFS(e->to);
        if(l == -1) return -1;
        GLP[v] = max(GLP[v], l+1);
        e = e->next;
    }
    GLPfixed[v] = true;
    return GLP[v];
}
int GLongestPath(void)
{
    int lmax = 0;
    for(int i=0;i<Gv;i++)
    {
        int l = GLP_DFS(i);
        if(l==-1)
        {
            return -1;
        }
        lmax = max(lmax, l);
    }
    return lmax;
}

int sid[MAXN][MAXN];
int a[MAXN][MAXN-1];

int main(void)
{
    int n;
    scanf("%d",&n);

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

    for(int i=0;i<n;i++)for(int j=0;j<n-1;j++)
    {
        scanf("%d",&(a[i][j]));
        a[i][j]--;
    }

    Ginit(s);
    for(int i=0;i<n;i++)for(int j=0;j<n-2;j++)
    {
        Gadd(sid[i][a[i][j]], sid[i][a[i][j+1]]);
    }

    int ans = GLongestPath();
    if(ans == -1)
    {
        printf("-1\n");
        return 0;
    }
    
    printf("%d\n", ans+1);
    return 0;
}







Measured memory_bytes: 54144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N;
int A[MAXN];

int main() {
	register int i;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i)
		scanf("%d", A + i);
	long long l = 2, r = 2;
	for(i = N; i >= 1; --i) {
		l = ((l - 1) / A[i] + 1) * A[i];
		r = r / A[i] * A[i] + A[i] - 1;
	}
	if(l > r) puts("-1");
	else printf("%lld %lld\n", l, r);
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> cnt(m, 0);
  rep(i, n) {
    int k;
    cin >> k;
    rep(j, k) {
      int a;
      cin >> a;
      a--;
      cnt[a]++;
    }
  }
  int ans = 0;
  rep(i, m) {
    if (cnt[i] == n) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
#define minn(x,y) x=min(x,y)
#define maxx(x,y) x=max(x,y)
using namespace std;
int a[100010];
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	a[0]--;
	for(i=1;i<n;i++)
	{
		if(a[i]-1>=a[i-1])
		{
			a[i]--;
		}
		if(a[i]<a[i-1])
		{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdint>

int const MAXN = 1e5;
int N;
int64_t M, A[MAXN], sum[MAXN+1];

int64_t count(int th) {
  int64_t c = 0;
  int j = N-1;
  for(int i = 0; i < N; ++i) {
    if(A[i]*2 < th) break;
    while(j > i && A[i]+A[j] < th) --j;
    ++j;
    c += (int64_t)(j-i)*2-1;
    j = std::min(j, N-1);
  }
  return c;
}

int64_t calc(int th) {
  int64_t res = 0;
  int j = N-1;
  for(int i = 0; i < N; ++i) {
    if(A[i]*2 < th) break;
    while(j > i && A[i]+A[j] < th) --j;
    ++j;
    res += (sum[j-1] - sum[i] + (j-i)*A[i])*2;
    j = std::min(j, N-1);
  }
  return res;
}

int main() {
  std::cin >> N >> M;
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  std::sort(A, A+N, [](int l, int r){ return l > r; });
  // 
  int thH = A[0]*2, thL = A[N-1]*2;
  while(thH > thL + 1) {
    int thM = (thH+thL)/2;
    if(count(thM) >= M) thL = thM;
    else thH = thM-1;
  }
  while(count(thH) < M) --thH;
  sum[0] = A[0];
  for(int i = 1; i < N; ++i) sum[i] = sum[i-1]+A[i];
  int64_t ans =  calc(thH) - (count(thH) - M)*thH;
  std::cout << ans << std::endl;
  return 0;
}



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

int main(){
  int x,y ;
  cin >> x >> y ;
  if(x==y&&x==1){
    cout << 1000000 << endl ;
    return 0 ;
  }
 cout << 100000*(max(0,4-x))+100000*(max(0,4-y)) << endl ;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
int main()
{
	char a[105];
	scanf("%s",&a);
	int n=strlen(a);
	for (int i=0;i<n;i++)
	{
		if (a[i]=='C')
		{
			for (int j=i+1;j<n;j++)
			{
				if (a[j]=='F')
				{
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC163
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_C();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var r = Ex.ReadInt;
            Ex.Cw(r * 2 * Math.PI);
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            // i番目の宿題をやるにはAi日間

            var l1 = Ex.ReadLongArray();
            var l2 = Ex.ReadLongArray();

            // 夏休みはN日間
            var n = l1[0];
            // 宿題がM個
            var m = l1[1];

            for (int i = 0; i < m; i++) n -= l2[i];

            Math.Max(-1, n).Cw();

        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
            // N人の社員
            var n = Ex.ReadLong;
            var l2 = Ex.ReadLongArray();
            var ans = new long[n + 2];
            for (int i = 1; i < n; i++) ans[l2[i - 1]]++;
            for (int i = 1; i <= n; i++) ans[i].Cw();
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 41816
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10);


int main() {

	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	a[0] = 0;
	for (int i = 1;i < n;i++) {
		cin >> a[i];
		b[a[i]-1] = b[a[i]-1] + 1;
	}

	for (int i = 0;i < n;i++) {
		cout << b[i] << endl;
	}

	

	return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,p;
	cin>>a>>p;
	puta((a*3+p)/2);
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
map<char,int> mp;
int main(){
int n,k;
cin>>n>>k;
vector<ll> v(n+1,0);
for(int i=0;i<n;i++)cin>>v[i];
int m=n+1;
int ma=min(k,m);
if(ma==m)ma--;//kより区間の方が小さかった場合、下の実行コードだと同じものを２回足してしまう
ll ans=0;
for(int i=ma;i>=1;i--){//iは区間
for(int j=m-i-1;j<m;j++){
    ll res=0;
    priority_queue<ll,vector<ll>,greater<ll>> pq;
    int l=0;
while(l!=i+1){res+=v[(l+j)%m];pq.push(v[(l+j)%m]);l++;}
    int times=k-i;
   while(times--){
       if(pq.empty())break;
        ll tmp=pq.top();
        pq.pop();
        if(tmp>=0)break;
        res-=tmp;
    }
ans=max(ans,res);
}
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		try (Scanner sc = new Scanner(System.in)) {
			while (sc.hasNextDouble()) {

				double v = sc.nextDouble();
				double t = v / 9.8;
				double y = t * t * 4.9;
				double n = Math.ceil((y + 5) / 5);

				System.out.println((int) n);
			}
		}
	}
}

Measured memory_bytes: 27584
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: usize,
      p: usize,
      aa: [u64; n]
    }

    let mut dp = vec![vec![0u64;2]; n+1];

    dp[0][0] = 1;
    for i in 0..n {
        if aa[i] % 2 == 0 {
            dp[i+1][0] = dp[i][0]*2;
            dp[i+1][1] = dp[i][1]*2;
        } else {
            dp[i+1][0] = dp[i][1] + dp[i][0];
            dp[i+1][1] = dp[i][0] + dp[i][1];
        }
    }
    println!("{}", dp[n][p]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>=13){
        cout<<b<<endl;
    }else if(a<=5){
        cout<<0<<endl;
    }else{
        cout<<b/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define NUMBER 100

int main(){

    int i,n;
    int count = 0;
    int flag,stock;
    int A[NUMBER];

    scanf("%d",&n);

    for(i=0;i<n;i++){

        scanf("%d",&A[i]);
        
    }

    flag = 1;

    while(flag>0){

        flag = 0;

        for(i=n-1;i>=1;i--){

            if(A[i]<A[i-1]){

                stock = A[i];
                A[i] = A[i-1];
                A[i-1] = stock;
                count++;

                flag = 1;
            }
        }
    }

    for(i=0;i<n;i++){

        if(i != n && i != 0){
            printf(" ");
        }

        printf("%d",A[i]);

    }

    printf("\n");
    printf("%d\n",count);

    return 0;
}


Measured memory_bytes: 2128
from collections import defaultdict
H,W,M = map(int,input().split())
bomb = [set() for _ in range(H+1)]
hdic = [0]*(H+1)
wdic = [0]*(W+1)
for i in range(M):
    hi,wi = map(int,input().split())
    hdic[hi] += 1
    wdic[wi] += 1
    bomb[hi].add(wi)
hmax = 0
hlist = []
wmax = 0
wlist = []
for i in range(1,H+1):
    if hdic[i] > hmax:
        hlist = [i]
        hmax = hdic[i]
    elif hdic[i] == hmax:
        hlist.append(i)
for i in range(1,W+1):
    if wdic[i] > wmax:
        wlist = [i]
        wmax = wdic[i]
    elif wdic[i] == wmax:
        wlist.append(i)
for i in hlist:
    for j in wlist:
        if j not in bomb[i]:
            print(hmax+wmax)
            exit()
print(hmax+wmax-1)


Measured memory_bytes: 174340
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int sum=0,count1=0;
	for(int j=1;j<=n;j+=2)
	{
		sum=0;
		for(int i=1;i<=sqrt(j);i++)
			if(j%i==0)
				sum++;
		if(sum==4) 
			count1++;
	}
	 cout<<count1;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <climits>
#include <utility>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rep1(i,n) for(int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int N,X,Y;
int d[2010][2010];
vector<int> G[2010];
int ans[2010];

signed main()
{
	cin>>N>>X>>Y;
	--X,--Y;
	
	rep(i,N-1){
		G[i].push_back(i+1);
		G[i+1].push_back(i);
	}
	G[X].push_back(Y);
	G[Y].push_back(X);

	queue<int> q;

	rep(i, N) rep(j, N) d[i][j] = 1e9;

	rep(i, N) {
		q.push(i);

		d[i][i] = 0;

		while (not q.empty()) {
			int cur = q.front(); q.pop();

			ans[d[i][cur]]++;

			for (int &nxt : G[cur]) {
				if (d[i][nxt] != 1e9) continue;
				d[i][nxt] = d[i][cur] + 1;

				q.push(nxt);
			}
		}
	}

	for (int i = 1; i <= N - 1; ++i) printf("%lld\n", ans[i]/2);
}


Measured memory_bytes: 31744
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    
    cin>>a>>b;
    
    if(a%2 != b%2){
        cout<<"IMPOSSIBLE"<<endl;
    }
    
    else{
        cout<<(a+b)/2<<endl;
        
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#define ll long long
#define uint unsigned
#define MOD 1000000007
using namespace std;

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

    // #ifndef _DEBUG
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    // --------------------------------
    vector<int> arr (3);
    int n = 2;
    while (n--) {
    	int num {};
    	cin >> num;
    	arr.at(num-1) = 1;
    }
    for (size_t i {}; i < 3; ++i)
    	if (arr.at(i) == 0) cout<<i+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;


int main(){
    int cost_l=0, cost_r=0;
    int n,m,x;
    cin >> n >> m >> x;
    
    for(int i=0; i<m; i++){
        int a;
        cin >> a;
        if(a<x){
            cost_l++;
        }else{
            cost_r++;
        }
    }
    cout<<min(cost_l,cost_r)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  string S;
  cin>>S;
  bool ans=true;
  for(int i=0;i<A+B+1;i++){
    if(i==A&&S.at(i)!='-'){
        ans=false;
      break;
    }
    if(i!=A){
      if(S.at(i)-'0'<0||9<S.at(i)-'0'){
        ans=false;
        break;
      }
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  
  int count = 0;
  
  int h[N];
  for(int i = 0; i < N; i++){
    cin >> h[i];
    if(h[i] >= K){
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
 
#define MAX 10000000
#define n_MAX 101
#define c_MAX 11

typedef pair<int, pair<int, int> > edge;

int get_cost(const edge& e){
  return e.first;
}

int get_tickets(const edge& e){
  return -(e.second.first);
}

int get_station(const edge& e){
  return e.second.second;
}

inline edge make_edge(int cost, int tickets, int station){
  return make_pair(cost, make_pair(-tickets, station));
}

int main() {
 
  while( true ) {
    
    long long int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if ( n == 0 ) break;
    
    long long int l[n_MAX][n_MAX] = {0};
    
    for ( long long int i = 0; i < m; i++ ) {
      long long int a, b, f;
      cin >> a >> b >> f;
      l[a][b] = l[b][a] = f;
    }
 
    long long int t[c_MAX][n_MAX];
    for ( long long int j = 0; j <= c; j++ ) {
      for ( long long int i = 1; i <= n; i++ ) {
	t[j][i] = MAX;
      }
    }
    
    priority_queue<edge, vector<edge>, less<edge> > queue;
    queue.push(make_edge(0, c, s));
    t[c][s] = 0;

    int ans = MAX;
    while(!queue.empty()){
      edge e = queue.top(); queue.pop();

      const int cost = get_cost(e);
      const int tickets = get_tickets(e);
      const int station = get_station(e);
      if(t[tickets][station] > cost){
	continue;
      }else if(station == d){
	ans = min(ans, cost);
      }

      for(long long int next = 1; next <= n; next++){
	if(l[station][next] == 0){
	  continue;
	}
	
	const int next_non_use_cost = cost + l[station][next];
	const int next_use_cost     = cost + l[station][next] / 2;
 
	if(tickets > 0 && t[tickets - 1][next] > next_use_cost){
	  t[tickets - 1][next] = next_use_cost;
	  queue.push(make_edge(next_use_cost, tickets - 1, next));
	}
	
	if(t[tickets][next] > next_non_use_cost){
	  t[tickets][next] = next_non_use_cost;
	  queue.push(make_edge(next_non_use_cost, tickets, next));
	}
      }
    }
 
    cout << ans << endl;
  }
 
  return 0;
 
}

Measured memory_bytes: 1308
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    ABC = [list(map(int, input().split())) for i in range(N)]

    dp = [[0]*3 for i in range(N)]
    dp[0] = ABC[0]

    for i in range(N-1):
        a, b, c = ABC[i+1]

        dp[i+1][0] = a + max(dp[i][1], dp[i][2])
        dp[i+1][1] = b + max(dp[i][0], dp[i][2])
        dp[i+1][2] = c + max(dp[i][0], dp[i][1])

    print(max(dp[-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 69468
#include <stdio.h>
int main(){
	int n,m,ans=0;
	scanf("%d%d",&n,&m);
	if(n>=2)ans+=n*(n-1)/2;//偶数里任选2个
	if(m>=2)ans+=m*(m-1)/2;//奇数里任选2个
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
using namespace std;
int main()
{
	char a, b;
	int at, to;
	while(scanf("%c %c", &a, &b) != EOF)
	{
		getchar();
		if(a == 'H') at = 1;
		else at = 0;
		if(b == 'H') 
		{
			if(at == 1) to = 1;
			else to = 0;
		}
		else 
		{
			if(at == 1) to = 0;
			else to = 1;
		}
		printf("%c\n", to == 1 ?'H':'D');
	}
	return 0;
}

Measured memory_bytes: 256
K,N = map(int, input().split())

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

dists = []
for i in range(N):
    if i == 0:
        dists.append(K - (A[i+1] - A[i]))
        dists.append(A[-1] - A[i])

    elif i == N-1:
        dists.append((K-A[i]) + A[i-1])
        dists.append(A[i] - A[0])

    else:
        dists.append((K - A[i]) + A[i-1])
        dists.append(A[i] + (K - A[i+1]))
    
print(min(dists))

Measured memory_bytes: 31024
/*
      author  : nishi5451
      created : 14.08.2020 23:46:05
*/

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


int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int i=min(a,b);
    int now=0;
    while(i){
        if(a%i==0 && b%i==0){
            now++;
            if(now == k){
                cout << i << endl;
                return 0;
            }
        } 
        i--;  
    }
    return 0;
}

Measured memory_bytes: 3672
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N, K, S;

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

    rep(i, 0, N)
    {
        if (i < K)
        {
            cout << S;
        }
        else
        {
            if (S == 1000000000)
            {
                cout << 999999999;
            }
            else
            {
                cout << 1000000000;
            }
        }

        if (i != N - 1)
        {
            cout << " ";
        }
    }
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    vector<int> dp(k, 2);
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (v[j] > i)continue;
            if (dp[i - v[j]] == 2)dp[i] = 1;
        }
    }
    cout << (dp[k] == 1 ? "First" : "Second") << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3976
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int inf = 2e9;
const int mod = 1e9+7;

int main() {
	int n;

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

	vector<bool> t_known(n, false), a_known(n, false);
	t_known[0] = true;
	a_known[n-1] = true;
	for (int i = 1; i < n; i++) {
		if (t[i] != t[i-1]) {
			t_known[i] = true;
		}
	}
	for (int i = n - 2; i >= 0; i--) {
		if (a[i] != a[i+1]) {
			a_known[i] = true;
		}
	}

	long long ans = 1;
	for (int i = 0; i < n; i++) {
		if (t_known[i] && a_known[i]) {
			if (t[i] != a[i]) {
				ans = 0;
				break;
			} else {
				continue;
			}
		}

		if (!t_known[i] && !a_known[i]) {
			ans = ans * min(t[i], a[i]) % mod;
		} else if (t_known[i]) {
			if (t[i] > a[i]) {
				ans = 0;
				break;
			}
		} else {
			if (a[i] > t[i]) {
				ans = 0;
				break;
			}
		}
	}

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


Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
const int maxnn = 1e5+5;
int ac[maxnn], wa[maxnn];

int calstonum(char *p)
{
    int i;
    int res = 0;
    for(i = 0;p[i] != '\0';i++)
    {
        res = res*10 + (p[i]-'0');
    }
    return res;
}

int main()
{
    int n,m;
    int i;
    char p[15], s[15];

    scanf("%d%d",&n,&m);
    for(i = 0;i < m;i++)
    {
        scanf("%s",p);
        scanf("%s",s);
        int num = calstonum(p);
        if(strcmp(s, "AC") == 0)
        {
            ac[num] = 1;
        }
        else if(ac[num] != 1)
        {
            wa[num]++;
        }
    }
    int acsum = 0, wasum = 0;
    for(i = 1;i <= n;i++)
    {
        if(ac[i] == 1)
        {
            acsum++;
            wasum += wa[i];
        }
    }
    printf("%d %d\n", acsum, wasum);

    return 0;
}


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

#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << endl;

using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define scl1(a)             scanf("%lld", &a)
#define scl2(a, b)          scanf("%lld %lld", &a, &b)

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
const int N=(int)3e3+5;
int n;
ll dp[N][N],a[N];
ll f(ll i,ll j){
	 if (i<1 or j<1 or j>n or i>n) return 0;
    if (i==j) return a[i];
    if (i>j) return 0;
    if (dp[i][j]!=(-1)) return dp[i][j];
    dp[i][j] = max(a[i]+min(f(i+2,j),f(i+1,j-1)),a[j]+min(f(i,j-2),f(i+1,j-1)));
	return dp[i][j];
}

int32_t main(){

ios_base::sync_with_stdio(false);
cin.tie(NULL);

ll t,i,j,z,k,s=0;

memset(dp,-1,sizeof(dp));
cin>>n;
rep(i,1,n+1,1){
	cin>>a[i];
	s+=a[i];
}
cout<<(2*f(1,n)-s)<<endl;
}


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

const int MAX_N = 2e5 + 10;
int n, q, ans;
int Arr[MAX_N];
int cnt[MAX_N];
int val[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> Arr[i];
		cnt[Arr[i]]++;
	}

	for (int i = 1; i <= n; i++)
		for (int j = max(0, i - cnt[i]); j < i; j++)
			val[j]++;

	for (int i = 0; i < n; i++)
		ans += !val[i];

	while (q--) {
		int x, y;
		cin >> x >> y;
		x--;

		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 1)
				ans++;

			val[Arr[x] - cnt[Arr[x]]]--;
		}

		cnt[Arr[x]]--;

		Arr[x] = y;
		cnt[Arr[x]]++;
		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 0)
				ans--;
			
			val[Arr[x] - cnt[Arr[x]]]++;
		}

		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 3840
fn main() {
    let mo:u64 = 10u64.pow(9)+7;
    let s:Vec<char> = get_line().chars().collect();
    let mut p= vec![0u64;13]; p[0] = 1;
    for c in s.iter() {
        let mut v = vec![0u64;13];
        let candy = match c.to_digit(10) {
            Some(n) => {let u= n as usize; u..u+1} ,
            None => 0..10
        };
        for n in candy {
            for i in 0..13 {
                v[(i*10+n)%13] += p[i];
            }
        }
        p = v.iter().map(|e| e%mo).collect();
    }
    println!("{}",p[5]);
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
//this code is written by Itst
using namespace std;

const int _ = 1e5 + 7;
struct Edge{
	int end , upEd , col , w;
}Ed[_ << 1];
int N , Q , head[_] , val[_] , ind[_] , col[_] , top[_] , dfn[_] , sz[_] , son[_] , fa[_] , dep[_] , cntEd , ts;

void addEd(int a , int b , int c , int d){
	Ed[++cntEd] = (Edge){b , head[a] , c , d};
	head[a] = cntEd;
}

void dfs1(int x , int p){
	sz[x] = 1; fa[x] = p; dep[x] = dep[p] + 1;
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != p){
			col[Ed[i].end] = Ed[i].col; val[Ed[i].end] = Ed[i].w;
			dfs1(Ed[i].end , x); sz[x] += sz[Ed[i].end];
			if(sz[Ed[i].end] > sz[son[x]]) son[x] = Ed[i].end;
		}
}

void dfs2(int x , int t){
	top[x] = t; dfn[x] = ++ts; ind[ts] = x;
	if(!son[x]) return;
	dfs2(son[x] , t);
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != fa[x] && Ed[i].end != son[x]) dfs2(Ed[i].end , Ed[i].end);
}

namespace segTree{
	int sum[_ * 70] , lch[_ * 70] , rch[_ * 70] , cnt;

#define mid ((l + r) >> 1)
	
	void modify(int &x , int l , int r , int tar , int val){
		int t = ++cnt; sum[t] = sum[x] + val; lch[t] = lch[x]; rch[t] = rch[x]; x = t;
		if(l == r) return;
		mid >= tar ? modify(lch[x] , l , mid , tar , val) : modify(rch[x] , mid + 1 , r , tar , val);
		sum[x] = sum[lch[x]] + sum[rch[x]];
	}

	int qry(int x , int l , int r , int L , int R){
		if(l >= L && r <= R) return sum[x];
		int sum = 0;
		if(mid >= L) sum = qry(lch[x] , l , mid , L , R);
		if(mid < R) sum += qry(rch[x] , mid + 1 , r , L , R);
		return sum;
	}
}
using segTree::modify; using segTree::qry;
int rt1 , rt2[_] , rt3[_];

void init(){
	for(int i = 1 ; i <= N ; ++i){
		modify(rt1 , 1 , N , i , val[ind[i]]);
		modify(rt2[col[ind[i]]] , 1 , N , i , 1);
		modify(rt3[col[ind[i]]] , 1 , N , i , val[ind[i]]);
	}
}

int work(int x , int y , int c , int val){
	int tx = top[x] , ty = top[y] , sum = 0;
	while(tx != ty){
		if(dep[tx] < dep[ty]){swap(x , y); swap(tx , ty);}
		int p = dfn[tx] , q = dfn[x];
		sum = sum + qry(rt1 , 1 , N , p , q) + qry(rt2[c] , 1 , N , p , q) * val - qry(rt3[c] , 1 , N , p , q);
		x = fa[tx]; tx = top[x];
	}
	if(dfn[x] != dfn[y]){
		if(dfn[x] < dfn[y]) swap(x , y);
		int p = dfn[y] + 1 , q = dfn[x];
		sum = sum + qry(rt1 , 1 , N , p , q) + qry(rt2[c] , 1 , N , p , q) * val - qry(rt3[c] , 1 , N , p , q);
	}
	return sum;
}

signed main(){
	ios::sync_with_stdio(0);
	cin >> N >> Q;
	for(int i = 1 ; i < N ; ++i){
		int a , b , c , d; cin >> a >> b >> c >> d;
		addEd(a , b , c , d); addEd(b , a , c , d);
	}
	dfs1(1 , 0); dfs2(1 , 1); init();
	for(int i = 1 ; i <= Q ; ++i){
		int u , v , c , val; cin >> c >> val >> u >> v;
		cout << work(u , v , c , val) << endl;
	}
	return 0;
}


Measured memory_bytes: 79872
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void){
    int i, T[10], p1[10], MIN=100, MINT=10, ANS=0;
    for(i=0; i<5; i++){
        scanf("%d", T+i);
        p1[i] = T[i] % 10;
    }
    for(i=0; i<5; i++){
        if(p1[i]!=0 && p1[i]<MIN){
            MIN = p1[i];
            MINT = i;
        }
    }
    for(i=0; i<5; i++){
        if(i==MINT || p1[i] == 0) ANS += T[i];
        else ANS += T[i] + 10 - p1[i];
    }
    printf("%d\n", ANS);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	long[] A, B;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		A = new long[N];
		B = new long[N];
		for (int i = 0; i < N; ++i) {
			String[] t = in.readLine().split(" ");
			A[i] = Long.parseLong(t[0]);
			B[i] = Long.parseLong(t[1]);
		}
		Arrays.sort(A);
		Arrays.sort(B);
	}

	void calc() {
		if (N % 2 == 0) {
			long aSmallMiddle = A[N / 2 - 1] * 2;
			long aLargeMiddle = A[N / 2] * 2;
			long bSmallMiddle = B[N / 2 - 1] * 2;
			long bLargeMiddle = B[N / 2] * 2;
			long small = (aLargeMiddle + aSmallMiddle) / 2;
			long large = (bLargeMiddle + bSmallMiddle) / 2;
			long result = large - small + 1;
			System.out.println(result);
		} else {
			long aMiddle = A[N / 2];
			long bMiddle = B[N / 2];
			long result = bMiddle - aMiddle + 1;
			System.out.println(result);
		}
	}

	void showResult() {
	}
}

Measured memory_bytes: 59644
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read.ToCharArray();

            Array.Sort(S);
            for (int i = 0; i < S.Length - 1; i++)
            {
                if (S[i] == S[i + 1])
                {
                    WriteLine("no");
                    return;
                }
            }

            WriteLine("yes");

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
using Data = vector<long long>;
using pll = pair<long long, long long>;
const long long INF = (1LL<<60);

pll Binary_Search(const Data& v, long long x) {
    int l = 0, r = (int)v.size() - 1;
    while (abs(l - r) > 1) {
        int m = (l + r) / 2;
        if (v[m] < x) l = m;
        else r = m;
    }
    return make_pair(v[l], v[r]);
}

void solve(const Data& s, Data& t, long long x) {
    long long a[2]; tie(a[0], a[1]) = Binary_Search(s, x);
    long long b[2]; tie(b[0], b[1]) = Binary_Search(t, x);
    long long ans = INF;
    for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) {
        long long cost1 = abs(x - a[i]) + abs(a[i] - b[j]);
        long long cost2 = abs(x - b[i]) + abs(b[i] - a[j]);
        ans = min({ans, cost1, cost2});
    }
    cout << ans << endl;
    return;
}

int main() {
    int n, m, q;
    long long x;
    cin >> n >> m >> q;
    vector<long long> s(n), t(m);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < m; i++) cin >> t[i];
    sort(s.begin(), s.end()); sort(t.begin(), t.end());
    while (q--) { cin >> x; solve(s, t, x); }
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <map>


static constexpr int multiple = 2019;

int main() {
    std::string c;
    std::cin >> c;

    int len = c.length();
    std::vector<int> str(len);
    for (auto i = 0; i < len; i++) {
        str[i] = c[i] - '0';
    }

    std::vector<int> mods(len);
    mods[0] = 1;
    for (auto i = 1; i < len; i++) {
        mods[i] = mods[i - 1] * 10 % multiple;
    }

    std::vector<int> sum_mods(len + 1);
    std::map<int, std::vector<int>> same_mod;
    sum_mods[len] = 0;
    same_mod[0].emplace_back(len);
    for (auto i = len - 1; i >= 0; i--) {
        sum_mods[i] = (sum_mods[i + 1] + str[i] * mods[len - i - 1]) % multiple;
        same_mod[sum_mods[i]].emplace_back(i);
    }

    int count = 0;
    for (auto vec : same_mod) {
        int len = vec.second.size();
        count += len * (len - 1) / 2;
    }

    std::cout << count << std::endl;
}


Measured memory_bytes: 7576
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  int aa, L;
  while(cin >> aa >> L, aa || L) {
    map<int, int> MAP;
    MAP[aa] = 0;
    string a = to_string(aa);
    string A(L, '0');
    FOR(i,0,a.length()) A[i] = a[i];
    FOR(i,1,21) {
      while(A.length() < L) A += '0';
      string mx = A, mn = A;
      sort(mx.rbegin(), mx.rend());
      sort(mn.begin(), mn.end());
      int sa = stoi(mx) - stoi(mn);
      A = to_string(sa);
      if(MAP.count(sa)) {
        cout << MAP[sa] << " " << sa << " " << i - MAP[sa] << endl;
        break;
      } else MAP[sa] = i;
    }
  }
  return 0;
}

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

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

class kruskal
{
  static const int MAX_V = 200010;

  int par[MAX_V];
  int rank_[MAX_V];

  inline int root(int x)
  {
    return par[x] == x ? x : par[x] = root(par[x]); //経路圧縮
  }

  inline bool same(int x, int y)
  {
    return root(x) == root(y);
  }

  void unite(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return;

    if (rank_[x] < rank_[y])
    {
      par[x] = y;
    }
    else
    {
      par[y] = x;
      if (rank_[x] == rank_[y])
        rank_[x]++;
    }
  }

  struct edge
  {
    ll u, v, cost;
  };

  vector<edge> E;

  static bool comp(edge &e1, edge &e2)
  {
    return e1.cost < e2.cost;
  }

public:
  kruskal(int n)
  {
    for (int i = 0; i < n; ++i)
      par[i] = i, rank_[i] = 0;
  }

  inline void setE(int s, int t, ll w)
  {
    E.push_back({s, t, w});
  }

  ll calc()
  {
    sort(E.begin(), E.end(), comp);
    ll res = 0;
    for (auto e : E)
    {
      if (!same(e.u, e.v))
      {
        unite(e.u, e.v);
        res += e.cost;
      }
    }
    return res;
  }
};

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

  ll v, e;
  cin >> v >> e;
  kruskal ks(v);

  rep(i, e)
  {
    ll s, t, w;
    cin >> s >> t >> w;
    ks.setE(s, t, w);
  }
  cout << ks.calc() << endl;
  return 0;
}



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

long long rec(int n, long long x) {
    if (n == 0) return 1;
    long long len = (1LL<<(n+1)) - 3;
    long long num = (1LL<<n) - 1;
    if (x == 1) return 0;
    else if (x <= len + 1) return rec(n-1, x-1);
    else if (x == len + 2) return num + 1;
    else if (x <= (len + 1) * 2) return num + 1 + rec(n-1, x-len-2);
    else return num * 2 + 1;
}

int main() {
    int N; long long X;
    cin >> N >> X;
    cout << rec(N, X) << endl;
}

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

int main()
{
  int s[400];
  int l[400];
  int p[400];
  int w[400];

  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> s[i] >> l[i] >> p[i];
  }

  int m;
  cin >> m;
  for (int i = 0; i < m; i++)
  {
    cin >> w[i];
  }

  int dp[400];
  dp[0] = 0;
  for (int i = 1; i < 400; i++)
  {
    dp[i] = -1;
  }

  for (int i = 1; i < 400; i++)
  {
    for (int j = 0; j < n; j++)
    {
      for (int k = s[j]; k <= l[j]; k++)
      {
        if (i - k >= 0)
        {
          dp[i] = max(dp[i], dp[i-k] + p[j]);
        }
      }
    }
  }

  for (int i = 0; i < m; i++)
  {
    if (dp[w[i]] < 0) { cout << -1 << endl; return 0; }
  }

  for (int i = 0; i < m; i++)
  {
    cout << dp[w[i]] << endl;
  }


}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#include <variant>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecll p(n), q(n);
  REP(i,n) {
    ll x,y;
    cin>>x>>y;
    p[i] = x+y;
    q[i] = x-y+1e9;
  }
  ll dp = *max_element(ALL(p)) - *min_element(ALL(p));
  ll dq = *max_element(ALL(q)) - *min_element(ALL(q));
  cout << max(dp, dq) << endl;
  return 0;
}


Measured memory_bytes: 6268
import java.util.Scanner;

public class Main {
	final int INF = Integer.MAX_VALUE;
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][] cost = new int[n][n];
		int[] minCost = new int[n];
		boolean[] isUsed = new boolean[n];
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int a = scan.nextInt();
				cost[i][j] = a != -1 ? a : INF;
			}
		}
		for (int i = 0; i < n; i++)
			minCost[i] = INF;
		
		minCost[0] = 0;
		int res = 0;
		
		while (true) {
			int v = -1;
			for (int u = 0; u < n; u++)
				if (!isUsed[u] && (v == -1 || minCost[u] < minCost[v]))
					v = u;
			
			if (v == -1)
				break;
			isUsed[v] = true;
			res += minCost[v];
			
			for (int u = 0; u < n; u++)
				minCost[u] = Math.min(minCost[u], cost[v][u]);
		}
		System.out.println(res);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 40380