akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define sz 100100
int val[sz];
vector<int>adj[sz];
int ret(int a)
{
    if (val[a] != -1)  return val[a];
    int &mx = val[a];
    for (auto it : adj[a])
        mx = max(mx, 1 + ret(it));
    return mx;
}
int main()
{
    int n, m, a, b, mx;
    scanf("%d", &n); scanf("%d", &m);
    for (int i = 0; i < m; ++i)
    {
        scanf("%d", &a);
        scanf("%d", &b);
        adj[a].push_back(b);
        val[a] = -1;
    }
    mx = 0;
    for (int i = 1; i <= n; ++i)
    {
        mx = max(mx, ret(i));
    }
    cout << mx;
    return 0;
}

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

using namespace std;

int N, A, B, C;
int L[9];

int f(int i, int a, int b, int c) {
    if (i > N) {
        if (a < A && b < B && c < C) return abs(a) + abs(b) + abs(c) - 30;
        else return 1 << 30;
    }

    int ret = f(i + 1, a, b, c);
    ret = min(ret, f(i + 1, a - L[i], b, c) + 10);
    ret = min(ret, f(i + 1, a, b - L[i], c) + 10);
    ret = min(ret, f(i + 1, a, b, c - L[i]) + 10);

    return ret;
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 1; i <= N; ++i) {
        cin >> L[i];
    }

    cout << f(1, A, B, C) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int N = 100010;

int n, k;
int w[N];

int check(int p)
{
    int cnt = k;
    int i = 0;
    while (cnt--) {
        int v = p;
        while (w[i] <= v) {
            v -= w[i];
            i++;
            if (i == n)
                return n;
        }
    }
    return i;
}

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", &w[i]);
        
    int l = 0, r = 1e9;
    while (l < r) {
        int mid = l + r >> 1;
        if (check(mid) >= n)
            r = mid;
        else
            l = mid + 1;
    }
    
    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve(void)
{
  string str;cin>>str;
  map<char,int> mp;
  if(str.size() == 1)
  {
    cout<<"YES"<<endl;
    return;
  }
  else if(str.size() == 2)
  {
    if(str[0] == str[1])
    {
      cout<<"NO"<<endl;
    }
    else
    {
      cout<<"YES"<<endl;
    }
    return;
  }

  for (int i = 0; i < str.size(); i++)
  {
    mp[str[i]]++;
  }
  int MIN =min(mp['a'],min(mp['b'],mp['c']));
  int check = 1;
  for (auto &&i : mp)
  {
    if(i.second - MIN >1)check = 0;
  }
  if(check ==1)
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  
  
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 512
<?php

function input() {
    return trim(fgets(STDIN));
}

$N = (int)input();
$s1 = str_split((string)input());
$s2 = str_split((string)input());

$units = [];

for ($i = 0; $i < $N; $i++) {
    if ($s1[$i] === $s2[$i]) {
        $units[] = 'v';
    } else {
        $units[] = 'h';
        $i++;
    }
}

$product = 1;

for ($j = 0, $count = count($units); $j < $count; $j++) {
    if ($units[$j] === 'v') {
        if ($j === 0) {
            $product *= 3;
        } else if ($units[$j - 1] === 'v') {
            $product *= 2;
        } else if ($units[$j - 1] === 'h') {
            $product *= 1;
        }
    } else if ($units[$j] === 'h') {
        if ($j === 0) {
            $product *= 6;
        } else if ($units[$j - 1] === 'v') {
            $product *= 2;
        } else if ($units[$j - 1] === 'h') {
            $product *= 3;
        }
    }
    $product %= 1000000007;
}

echo "{$product}\n";

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

struct UnionFind {
	vector<int> p;
	vector<int> s;
	
	UnionFind(int n) : p(n), s(n) {
		rep(i, n) p[i] = i;
		rep(i, n) s[i] = 1;
	}
	
	int root(int x) {
		return (p[x] == x) ? x : p[x] = root(p[x]);
	}
	
	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (s[x] < s[y]) swap(x, y);
		s[x] += s[y];
		p[y] = x;
	}
	
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	
	int size(int x) {
		return s[root(x)];
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		uf.unite(a, b);
	}
	int ans = 0;
	rep(i, n) ans = max(ans, uf.size(i));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4784
#include<stdio.h>
#include<math.h>
int main(){
  int n,m,a,b,c,d,x[100],y[100],r[100],f,ty,tx,ox,oy,i;
  double td,od,cd,px,py;
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d %d %d",&x[i],&y[i],&r[i]);
    scanf("%d",&m);
    while(m--){
      scanf("%d %d %d %d",&tx,&ty,&ox,&oy);
      for(i=f=0;i<n;i++){
	td=hypot(tx-x[i],ty-y[i]);
	od=hypot(ox-x[i],oy-y[i]);
	a=ox-tx;
	b=ty-oy;
	c=ty*a+tx*b;
	d=a*x[i]-b*y[i];
	cd=abs(a*y[i]+b*x[i]-c)/hypot(a,b);
	px=1.0*(b*c+a*d)/(a*a+b*b);
	py=1.0*(a*c-b*d)/(a*a+b*b);
	if(td<r[i]&&od<r[i])continue;
	if((tx<=px&&px<=ox||tx>=px&&px>=ox)&&(ty<=py&&py<=oy||ty>=py&&py>=oy)){
	  if((double)r[i]+0.000000001>cd)f=1;
	}
	if(td<r[i]&&r[i]<od)f=1;
	if(td>r[i]&&r[i]>od)f=1;//printf("%f %f %f %f %f\n",td,od,cd,px,py);
	if(f)break;
      }
      if(f)printf("Safe\n");
      else printf("Danger\n");
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

string s;

int main()
{
    string a,c;

    cin >> a >> s >> c;

    cout << "A" << (char)(s.front()) << "C" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;

int main() {
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
}


Measured memory_bytes: 3576
N,M=map(int,input().split())
H=list(map(int,input().split()))
good=[1 for _ in range(N)]

for i in range(M):
    A,B=map(int,input().split())
    if H[A-1]==H[B-1]:
        good[A-1]=0
        good[B-1]=0
    elif H[A-1]>H[B-1]:
        good[B-1]=0
    else:
        good[A-1]=0 

print(sum(good))

Measured memory_bytes: 19984
// std::set を用いた解
#include <iostream>
#include <set>
#include <map>
#include <string>
using namespace std;

int main() {
    int N;
    cin >> N;
    string s[N];
    for (int i = 0; i < N; ++i) cin >> s[i];
    int M;
    cin >> M;
    string t[M];
    for (int i = 0; i < M; ++i) cin >> t[i];

    map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
    for (int i = 0; i < N; ++i) {
        auto itr = mp.find(s[i]);        // s[i] が設定されているか？
        if(itr != mp.end() ) {
             mp[s[i]] += 1;
        }
        else {
             mp[s[i]] += 1 ;
        }
    }
    for (int i = 0; i < M; ++i) mp[t[i]] -= 1;

    int max = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) { //itr: (key, item)
        if (max<(itr->second)) max = (itr->second);
        //cout << "key = " << itr->first           // キーを表示
        //    << ", val = " << itr->second << endl;    // 値を表示
    }
    // set のサイズを出力します
    cout << max << endl;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> l(2 * n);
    rep(i, 2 * n) cin >> l[i];
    sort(all(l), greater<int>());
    int ans = 0;
    
    for (int i = 1; i < (2 * n); i += 2) {
        ans += l[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n;
int main(){
	cin>>n;
	string ans="";
	while(n){
		int r=(n-1)%26+1;
		n=(n-r)/26;
		char c=('a'+r-1);
		ans=c+ans;
	}
	cout<<ans<<'\n'; 
	return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"

typedef long long ll;

using namespace std;

int main() {
	int N, M, x = 0, y = 999999999, L, P,res;
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		cin >> L >> P;
		x = max(L, x);
		y = min(P, y);
	}
	if(y>=x){ res = (y - x) + 1; }
	else { res = 0; }
	
	if (res<=N) {
		cout << res << endl;
	}
	else {
		cout << N << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
R = [0]*N
C = [0]*N
for i in range(N):
    R[i], C[i] = map(int, input().split())

INF = 10**18
dp = [[INF]*N for i in range(N)]
for i in range(N):
    dp[i][i] = 0
for l in range(1, N):
    for i in range(N-l):
        a0 = R[i]
        c0 = C[i+l]
        dp[i][i+l] = min(a0*C[j]*c0 + dp[i][j] + dp[j+1][i+l] for j in range(i, i+l))
print(dp[0][N-1])


Measured memory_bytes: 5656
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vl a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  a.push_back(1e18);
  vii res;
  for (int pos = 0; pos < a.size(); ++pos) if (a[pos] >= 0) {
    bool ok = 1;
    ll ma = a[pos];
    for (int i = pos + 1; i < a.size(); ++i) {
      if (a[i] + ma < 0) ok = 0;
      ma = max(ma, a[i]);
    }
    if (ok) {
      for (int i = pos + 1; i < n; ++i) while (a[i] < a[i-1]) {
        assert(a[i] + 2 * a[i-1] >= a[i-1]);
        a[i] += a[i-1];
        res.emplace_back(i-1, i);
      }
      for (int i = pos-2; i >= 0; --i) while (a[i] > a[i+1]) {
        assert(a[i] + 2 * a[i+1] <= a[i+1]);
        a[i] += a[i+1];
        res.emplace_back(i+1, i);
      }
    }
  }
  cout << res.size() << endl;
  for (pii p : res) cout << p.first+1 << ' ' << p.second+1 << endl;
  return 0;
}

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

using namespace std;
using ll = long long int;

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

    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for(auto &e: p) cin >> e;
    for(auto &e: q) cin >> e;
    for(auto &e: r) cin >> e;

    sort(p.begin(), p.end(), greater<>());
    sort(q.begin(), q.end(), greater<>());
    sort(r.begin(), r.end(), greater<>());

    ll res = 0;
    res += accumulate(p.begin(), p.begin()+x, 0ll);
    res += accumulate(q.begin(), q.begin()+y, 0ll);

    ll i = x, j = y, s = res;
    for(ll k=0; k<c; k++) {
        if(i == 0 && j == 0) {
            break;
        }
        if(i == 0) {
la:
            s += r[k];
            s -= q[--j];
            res = max(res, s);
            continue;
        }
        if(j == 0) {
lb:
            s += r[k];
            s -= p[--i];
            res = max(res, s);
            continue;
        }
        if(p[i-1] >= q[j-1]) {
            goto la;
        }
        if(p[i-1] <  q[j-1]) {
            goto lb;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 2560
'use strict';
(function(stdin) {
  //declare function

  //declare variable
  var inputs = stdin.toString().trim().split('\n');
  var cols = inputs.splice(0, inputs.indexOf('0 0')).map(function(v) {
    return v.split(' ').map(Number);
  });
  //main
  cols = cols.map(function(array) {
    return array.sort(function(a, b) {
      return a - b;
    }).join(' ');
  }).join('\n');

  //display
  console.log(cols);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 18492
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cmath>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> p;
typedef vector<p> vp;
const int INF=1e9;
int n;
ll x[105];
ll y[105];
ll h[105];
ll tmpHlist[105l];
ll sabun[105];
int main(int argc,char const* argv[])
{
  cin >> n;
  for(int i=0;i<n;i++)
    {
      cin >> x[i] >> y[i] >> h[i];
    }
  for(ll cx=0;cx<=100;cx++)
    {
      for(ll cy=0;cy<=100;cy++)
	{
	  ll tmpH;
	  for(int j=0;j<n;j++)
	    {
	      bool ok=true;
	      tmpH=h[j]+abs(x[j]-cx)+abs(y[j]-cy);
		for(int i=0;i<n;i++)
		  {
		    if(h[i]==0)
		      {
			if((tmpH-abs(x[i]-cx)-abs(y[i]-cy))>0)ok=false;
		      }
		    else
		      {
			if((tmpH-abs(x[i]-cx)-abs(y[i]-cy))!=h[i]) ok=false;
		      }
		  }
	      if(ok) 
		{
		  cout << cx << ' ' << cy << ' ' << tmpH << endl;
		  return 0;
		}
	    }
	}
    }
  return 0;
  
}


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

using ll = long long;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int l, r, d;
    cin >> l >> r >> d;
    cout << (r / d) - (l - 1) /d ;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll h,w,ans=-1;cin>>h>>w;
  VV<char> v(h,V<char>(w));
  rep(i,0,h)rep(j,0,w)cin>>v[i][j];

  rep(i,0,h)rep(j,0,w){
    if(v[i][j]=='.'){
      VV<bool> used(h,V<bool>(w,false));
      queue<int> q;
      int mx=-1;
      q.push(i);
      q.push(j);
      q.push(0);
      used[i][j]=true;

      while(q.size()){
        int g=q.front();q.pop();
        int r=q.front();q.pop();
        int ng,nr,dis;
        dis=q.front();q.pop();
        chmax(mx,dis);

        rep(k,0,4){
          ng=g+dx[k];
          nr=r+dy[k];
          if(0<=ng && 0<=nr && ng<h && nr<w && v[ng][nr]=='.' && !used[ng][nr]){
            used[ng][nr]=true;
            q.push(ng);
            q.push(nr);
            q.push(dis+1);
          }
        }
      }

      chmax(ans,mx);
    }
  }
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int NIL = -1;
	static int MAX = 100005;
	static Node[] T = new Node[MAX];
	static int n;
	static int[] D = new int[MAX];
	static int[] H = new int[MAX];
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int v = 0;
		int l = 0;
		int r = 0;
		int root = 0;
		int n = sc.nextInt();
		
		for(int i=0; i<n; i++){
			T[i] = new Node(NIL, NIL, NIL);
		}
		for(int i=0; i<n; i++){
			v = sc.nextInt();
			l = sc.nextInt();
			r = sc.nextInt();
			T[v].setL(l);
			T[v].setR(r);
			if (l != NIL) T[l].setP(v);
			if (r != NIL) T[r].setP(v);
		}
		sc.close();
		
		for(int i=0; i<n; i++) {
			if(T[i].getP() == NIL) root = i;
		}
		
		setDepth(root, 0);
		setHeight(root);
		
		for(int i=0; i<n; i++){
			print(i);
		}
	}
	
	static void setDepth(int u, int d){
		if(u == NIL) return;
		D[u] = d;
		setDepth(T[u].getL(), d + 1);
		setDepth(T[u].getR(), d + 1);
	}
	
	static int setHeight(int u){
		int h1 = 0;
		int h2 = 0;
		if (T[u].getL() != NIL) h1 = setHeight(T[u].getL()) + 1;
		if (T[u].getR() != NIL) h2 = setHeight(T[u].getR()) + 1;
		if(h1>h2){
			return H[u] = h1;
		}else{
			return H[u] = h2;
		}
	}
	
	static int getSibling(int u) {
		if (T[u].getP() == NIL) return NIL;
		if (T[T[u].getP()].getL() != u && T[T[u].getP()].getL() != NIL)
			return T[T[u].getP()].getL();
		if (T[T[u].getP()].getR() != u && T[T[u].getP()].getR() != NIL)
			return T[T[u].getP()].getR();
		return NIL;
	}
	
	static void print (int u){
		System.out.print("node " + u);
		System.out.print(": parent = " + T[u].getP());
		System.out.print(", sibling = " +getSibling(u));
		int deg = 0;
		if (T[u].getL() != NIL) deg++;
		if (T[u].getR() != NIL) deg++;
		System.out.print(", degree = " + deg);
		System.out.print(", depth = " + D[u]);
		System.out.print(", height = " + H[u]);
		
		if (T[u].getP() == NIL) {
			System.out.println(", root");
		} else if (T[u].getL() == NIL && T[u].getR() ==NIL){
			System.out.println(", leaf");
		} else {
			System.out.println(", internal node");
		}
	}
}

class Node {
    private int p, l ,r;
    public Node(int p, int l, int r) {
        this.p = p;
        this.l = l;
        this.r = r;
    }
    int getP() {
        return p;
    }
    int getL() {
        return l;
    }
    int getR() {
        return r;
    }
    void setR(int r) {
        this.r = r;
    }
    void setL(int l) {
        this.l = l;
    }
    void setP(int p) {
        this.p = p;
    }
}


Measured memory_bytes: 27588
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,t;
int a[100001];
int dp[100001];
const int inf=999999999;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
    cin>>n>>t;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    int l=0,r=0;
    int nowmax=0;
    int ans=0;
    for(int r=0;r<n;r++){
    	if(a[r]<a[l]){
    		l=r;
    	}else{
    		if(nowmax<a[r]-a[l]){
    			nowmax=a[r]-a[l];
    			ans=1;
    		}else if(nowmax==a[r]-a[l]){
    			ans++;
    		}
    	}
    }
    cout<<ans<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
	int n; cin >> n;
	ll a=1;
	ll t=1;
	repi(i,0,n){
		ll ttmp, atmp;
		cin >> ttmp >> atmp;
		ll xt = t/ttmp;
		if(t%ttmp != 0) xt++;
		ll xa = a/atmp;
		if(a%atmp != 0) xa++;
		ll x = max(xt,xa);
		t = ttmp*x;
		a = atmp*x;
		//cout << t << " " << a << endl;
	}
	cout << t+a << endl;
	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

void solve()
{
	ll x;
	cin >> x;
	ll sum = 1000 * (x / 500);
	x = x - 500 * (x / 500);
	sum += 5 * (x / 5);
	cout << sum << "\n";
}

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



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,a,b,ans=0;
    cin>>k>>a>>b;
    if(a+1>=b || k-a+1<=0){
        ans=k+1;
    }
    else{
        ans=a+(k-a+1)/2*(b-a)+(k-a+1)%2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
from itertools import permutations

def main():
    N, C = map(int, input().split())
    D = [tuple(map(int, input().split())) for _ in range(C)]

    cnt = [Counter() for _ in range(3)]

    for i in range(N):
        c = [int(x)-1 for x in input().split()]
        for j in range(3):
            cnt[j].update(c[(3-(i+2)+j)%3::3])

    ans = 1000*500*500+5
    for p in permutations(range(C), 3):
        s = 0
        for j in range(3):
            s += sum(D[k][p[j]] * v for k, v in cnt[j].items())
        if s < ans: ans = s
    print(ans)

main()


Measured memory_bytes: 3436
class RightTriangle:
	def __init__(self,ab,bc,ca):
		self.ab = ab
		self.bc = bc
		self.ca = ca
	def calc_area(self):
		return self.ab*self.bc/2

ab,bc,ca = map(int,raw_input().strip().split())
val = RightTriangle(ab,bc,ca)
print(val.calc_area())


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
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;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int K;
  string S;
  cin >> K >> S;

  if(K>=sz(S)){
    cout << S << endl;
    return 0;
  }
  S=S.substr(0,K);
  S+="...";
  cout << S << endl;

  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	string sp, T;
	cin >> sp >> T;

	bool ok = false;
	int idx = 0;
	rep(i, 0, sp.size()) {
		if(i + T.size() - 1 >= sp.size()) break;
		bool flag = true;
		rep(j, 0, T.size()) {
			if(T[j] != sp[i + j] && sp[i + j] != '?') {
				flag = false;
				break;
			}
		}
		if(flag) {
			idx = i;
			ok = true;
		}
	}

	if(!ok) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	string ans = "";
	int i = 0;
	while(i < sp.size()) {
		if(i == idx) {
			rep(j, 0, T.size()) ans += T[j];
			i += T.size();
		} else if(sp[i] != '?') {
			ans += sp[i]; 
			i++;
		} else {
			ans += "a";
			i++;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.
 
int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LLI n,i,w=0;cin>>n;
      LLI arr[n];
      std::map<LI, LI> m;
      fo(i,0,n) {cin>>arr[i];m[arr[i]]++;}
      for(auto x:m){
        if(x.ss<2) continue;
        w+=x.ss*(x.ss-1)/2;
      }
      fo(i,0,n){
        LLI x=w;
        if(m[arr[i]]<2) {cout<<x<<endl;continue;}
        x-=(m[arr[i]])*(m[arr[i]]-1)/2;
        if(m[arr[i]]==2) {cout<<x<<endl;continue;}
        x+=(m[arr[i]]-1)*(m[arr[i]]-2)/2;
        cout<<x<<endl;
      }
    }
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

void balance(multiset<int>& s1, multiset<int>& s2, int half) {
    //
    while (s1.size() > half) {
        auto it = prev(s1.end());
        int mid = *it;
        s1.erase(it);
        s2.insert(mid);
        // cout << "move s1 to s2" << endl;
    }
    while (s2.size() > half+1) {
        auto it = s2.begin();
        int mid = *it;
        s2.erase(it);
        s1.insert(mid);
        // cout << "move s2 to s1" << endl;
    }
}

int main() {
    int n; cin >> n;
    multiset<int> s1, s2;
    vector<int> arr(n, 0);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for(int i = 1; i < n; i++)
        s1.insert(arr[i]);
    balance(s1, s2, (n-1)/2);
    cout << *s2.begin() << endl;
    for(int i = 1; i < n; i++) {
        if (arr[i] >= *s2.begin()) {
            auto it = s2.find(arr[i]);
            s2.erase(it);
        } else {
            auto it = s1.find(arr[i]);
            s1.erase(it);
        }

        balance(s1, s2, n/2);
        if (arr[i-1] >= *s2.begin())
            s2.insert(arr[i-1]);
        else
            s1.insert(arr[i-1]);
        balance(s1, s2, (n-1)/2);
        cout << *s2.begin() << endl;
        // cout << s1.size() << ", " << s2.size() << endl;
        // for(auto t2: s2) {
        //    cout << t2 << " ";
        //  }
    }
    return 0;
}




Measured memory_bytes: 12416
def solve
  n, m = gets.split.map!(&:to_i)
  h = gets.split.map!(&:to_i)
  ab = []
  ma = []
  ans = 0

  (0..(m - 1)).each do |i|
    ab[i] = gets.split.map!(&:to_i)
  end

  (0..(n - 1)).each do |i|
    ma[i] = 0
  end

  (0..(m - 1)).each do |i|
    ma[ab[i][0] - 1] = h[ab[i][1] - 1] if ma[ab[i][0] - 1] <= h[ab[i][1] - 1]
    ma[ab[i][1] - 1] = h[ab[i][0] - 1] if ma[ab[i][1] - 1] <= h[ab[i][0] - 1]
  end

  (0..(n - 1)).each do |i|
    ans += 1 if h[i] > ma[i]
  end

  print ans
end
solve

Measured memory_bytes: 22436
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n; cin >> n;
    vl v(n,0);
    rep(i,n-1){
        ll a; cin >> a; a--;
        v[a]++;
    }
    rep(i,n) cout << v[i] << "\n";
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int H,W;
    cin >> H >> W;
    vector<string> V(H),A(H),B(H);
    rep(i,0,H)cin >> V[i];
    rep(i,0,H){
        A[i] = string(W,'.');
        B[i] = string(W,'.');
    }
    rep(i,0,H)rep(j,0,W){
        if(i % 2 == 0 && j < W-1 || j == 0)A[i][j] = '#';
        else                               B[i][j] = '#';
    }
    rep(i,0,H)rep(j,0,W){
        if(V[i][j] == '#'){
            A[i][j] = '#';
            B[i][j] = '#';
        }
    }

    rep(i,0,H)cout << A[i] << endl;
    cout << endl;
    rep(i,0,H)cout << B[i] << endl;
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>
int main()
{
    int i,n; scanf("%d",&n);
    int in[n];
    for(i=1;i<=n;i++)
    {
        scanf("%d",&in[i]);
    }
    for(i=n;i>1;i--)
    {
        printf("%d ",in[i]);
    }
    printf("%d",in[1]); printf("\n");
    


}








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

int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;

  int ans=0;
  for (int i = 0; i <= a; i++)
  {
    for (int j = 0; j <= b; j++)
    {
      for (int k = 0; k <= c; k++)
      {
        if(500*i+100*j+50*k==x) ans++;
      }
    }
  }
  cout << ans << endl;
  
}

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

#define int long long int

const int mod = 1000000007;


int32_t main()
{
    int n;
    cin>>n;
    vector< vector<int> > arr(10, vector<int> (10, 0));

    for(int i=1;i<n+1;i++)
    {
        int first = i/pow(10, floor(log10(i)));
        int last = i%10;
        arr[first][last]++;
    }
    int sum = 0;
    for(int i=1;i<10;i++)
    {
        for(int j=1;j<10;j++)
        {
            sum = sum + arr[i][j] * arr[j][i];
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int, input().split())

s = 0


def dsum(n):
	res = 0
	while n!= 0:
		res += n%10
		n = n//10

	return res


for i in range(1,n+1):
	if (dsum(i)>=a and dsum(i)<=b):
		s +=i

print(s)

Measured memory_bytes: 2940
// d

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    // 単発入力
    int N, K;
    cin >> N >> K;

    vector<int> P(N);
    rep(i,N) cin >> P[i];

    queue<double> kitai;

    double kitai_max = 0;
    double kitai_cur = 0;

    for (int i = 0; i < N; ++i)
    {
        // 期待値出す
        // double kita = (double)(P[i] + 1) / 2.0;

        double kita = 0;
        for (int j = 1; j <= P[i]; ++j)
        { 
            kita += (double)j / (double)P[i];
        }
        
        // 末尾に足す
        kitai.push(kita);
        kitai_cur += kita;

        if (kitai.size() > K)
        {
            //Kより多かったら先頭を引く
            kitai_cur -= kitai.front();
            kitai.pop();
        }

        if (kitai.size() == K)
        {
            if (kitai_cur > kitai_max) kitai_max = kitai_cur;
        }
    }

    // cout << kitai_max << endl;
    printf("%.10f\n", kitai_max);
    return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define INF 0x7fffffff

int n;
vector<int> v;
vector<int> v2;

inline int size(int t) {
    int cnt = 1;

    while (t) {
        t /= 10;
        cnt *= 10;
    }

    return cnt;
}

int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        int a;
        scanf("%d", &a);
        v.push_back(a);
    }
    sort(v.begin(), v.end());

    for (int i=0; i < min(100, n); i++) {
        for (int j=0; j < min(100, n); j++) {
            if (i != j) v2.push_back(v[i] * size(v[j]) + v[j]);
        }
    }
    sort(v2.begin(), v2.end());
    printf("%d\n", v2[2]);
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    while(N != 0){
        vector<int> sum(200000,0);
        for(int i=0; i<N; i++){
            string S;
            cin >> S;
            int h,w,s;
            h = (S[0]-'0')*10+S[1]-'0';
            w = (S[3]-'0')*10+S[4]-'0';
            s = (S[6]-'0')*10+S[7]-'0';
            s += h*60*60+w*60;
            int s2;
            cin >> S;            
            h = (S[0]-'0')*10+S[1]-'0';
            w = (S[3]-'0')*10+S[4]-'0';
            s2 = (S[6]-'0')*10+S[7]-'0';
            s2 += h*60*60+w*60;
            sum[s]++;
            sum[s2]--;
        }
        int mx = 0;
        for(int i=0; i<100000; i++){
            sum[i+1] += sum[i];
            chmax(mx,sum[i+1]);
        }
        cout << mx << enld;
        cin >> N;
    }
    return 0;
}



Measured memory_bytes: 4012
import sys

cin = sys.stdin
# cin = open("in.txt", "r")

def line2N():
    return map(int, cin.readline().split())

A = cin.readline().strip()

a = [0] * 26
for ch in A:
    a[ord(ch)-ord('a')] += 1

cnt = 1
for i in range(0,26):
    for j in range(i+1,26):
        cnt += a[i]*a[j]

print(cnt)


Measured memory_bytes: 3500
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int in[100][100];

int main(int argc, char *argv[])
{
  int n;
  cin >> n;
  ll ans=0;
  rep(i,n)rep(j,n) cin >> in[i][j];
  rep(i,n)rep(j,n) ans += min(in[i][j],in[j][i]);
  cout << ans/2 << endl;
  return 0;
}

Measured memory_bytes: 1200
import java.io.IOException;

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

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        int num = Integer.parseInt(builder.toString()) % 1000;
        if (num > 0) System.out.print(1000 - num);
        else System.out.print(0);
    }
}


Measured memory_bytes: 32220
#include <stdio.h>
#include <string.h>

char A[11], B[11], C[11];

int main()
{
	scanf("%s %s %s", A, B, C);
	
	if(A[strlen(A)-1] == B[0] && B[strlen(B)-1] == C[0]) printf("YES");
	else printf("NO");
	
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string S;
  cin >> S;
  int N = S.size();
  int flag = 1; 
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    int n = S[i] - '0';
    if (n < 4) {
      if (flag == -1) {
        ans += n + 1;
      } else {
        ans += n;
      }
      flag = 1;
    }
    else if (n > 5) {
      if (flag == 1) {
        ans += 10 - n;
      }
      else {
        ans += 9 - n;
      }
      flag = -1;
    } else if(n == 4) {
      if (flag == -1) {
        flag = 0;
        ans += 5;
      }
      else {
        flag = 1;
        ans += 4;
      }
    } else if (n == 5) {
      if (flag == 1) {
        flag = 0;
        ans += 5;
      } else {
        flag = -1;
        ans += 4;
      }
    }
  }
  int last = S[N - 1] - '0';
  if(last <= 4) {
    if(flag == -1) {
      ans += last + 1;
    } else {
      ans += last;
    }
  } else if (last == 5) {
    ans += 5;
  } else {
    if(flag == 1) {
      ans += 11 - last;
    } else {
      ans += 10 - last;
    }
  }
  printf("%d\n", ans);
  return 0;
}
 

Measured memory_bytes: 1948
import scala.io.StdIn.{readInt, readLine}
import scala.annotation.tailrec

object Main extends App {

  val n     = readInt()
  val lines = Iterator.fill(n)(readLine())

  val result = for {
    line <- lines
    balls = line.split(" ").map { _.toInt }
  } yield if (solve(balls)) "YES" else "NO"

  result.foreach(println)

  def solve(balls: Seq[Int]): Boolean = {

    @tailrec
    def go(xs: List[Int], accum: (List[Int], List[Int])): Boolean = {
      xs match {
        case Nil     => true
        case y :: ys =>
          val nextLists = accum match {
            case (Nil, Nil) => Some((List(y), Nil))

            case (Nil, right @ rh :: _)            =>
              if (y > rh) Some((Nil, y :: right))
              else Some((List(y), right))

            case (left @ lh :: _, Nil)             =>
              if (y > lh) Some((y :: left, Nil))
              else Some((left, List(y)))

            case (left @ lh :: _, right @ rh :: _) =>
              if (lh > rh) {
                if (y > lh) Some((y :: left, right))
                else if (y > rh) Some((left, y :: right))
                else None
              } else {
                if (y > rh) Some((left, y :: right))
                else if (y > lh) Some((y :: left, right))
                else None
              }
          }

          nextLists match {
            case Some(z) => go(ys, z)
            case None    => false
          }
      }
    }

    go(balls.toList, (Nil, Nil))
  }

}



Measured memory_bytes: 43836
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define MOD 1000000007LL

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
  
int main()
{
	int r;
  cin>>r;
  if(r<1200){
    cout<<"ABC"<<endl;
  }else if(r<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [['.']*(W+2)]
for i in range(H):
    S.append(['.'] + list(input()) + ['.'])
S.append(['.']*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '#':
            if S[i+1][j] == '.' and S[i-1][j] == '.' and S[i][j+1] == '.' and S[i][j-1] == '.':
                print('No')
                break
    else:
        continue
    break
else:
    print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
          char str1[15],str2[15];
          cin >> str1 >> str2;
          int x,y;
          cin >> x >> y;
          char str3[15];
          cin >> str3;
          if(strcmp(str1,str3) == 0)
                    x = x - 1;
          else
                    y = y - 1;
          cout << x << " " << y << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; x++)
  {
    for (int y = 0; y <= K; y++)
    {
      int z = S - x - y;
      if (0 <= z && z <= K)
      {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define rp(i, N) for(int i=0; i<N; i++);
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
const int INF = 100000000;
// " ", ' '

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

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

	string s; cin >> s;
	string odd_s;
	for(int i=0; i<s.size(); i++) {
		if(i%2==0) odd_s.push_back(s.at(i));
	}

	cout << odd_s << endl;
	
}


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

vector<vector<int> > num;

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  s += s;

  bool can = true;
  int n = s.size();
  int next_ch[n][26];
  for ( int ci = 0; ci < 26; ci++ ) {
    char c = 'a'+ci;
    if ( t.find(c) == string::npos ) { continue; }
    int si = 0;
    string::size_type p = s.find(c);
    if ( p == string::npos ) { can = false; break; }
    int first_pos = p;
    while ( p != string::npos ) {
      for ( ; si < p; si++ ) { next_ch[si][ci] = p; }
      p = s.find(c, p+1);
    }
    for ( ; si < n; si++ ) { next_ch[si][ci] = first_pos; }
  }

  long long ans;
  if ( can ) {
    ans = s.find(t[0]);
    for ( int i = 1; i < t.size(); i++ ) {
      int c = t[i]-'a';
      int spos = ans%n;
      if ( spos < next_ch[spos][c] ) {
        ans += next_ch[spos][c] - spos;
      } else {
        ans += (n-spos) + next_ch[spos][c];
      }
    }
    ans++;
  } else {
    ans = -1;
  }

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


Measured memory_bytes: 24120
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define dup(x, y) (((x) + (y)-1) / (y))
#define PI 3.14159265359
typedef long long LL;
typedef vector<vector<int>> Graph;
const LL MOD = 1e9 + 7;
const LL LLINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline void chmax(T &a, T b) {
    if(a < b) {
        a = b;
    }
}
template <class T> inline void chmin(T &a, T b) {
    if(a > b) {
        a = b;
    }
}
template <class T> inline T gcd(T x, T y) {
    if(y == 0) {
        return x;
    } else if(x == 0) {
        return y;
    }
    return gcd(y, x % y);
}
template <class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template <class T> inline void print_vector(vector<T> vec) {
    for(int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    cout << endl;
}
template <class T> inline T mpower(T x, T n) {
    if(n == 0) {
        return 1;
    } else if(n % 2 == 0) {
        return mpower(x * x % MOD, n / 2);
    } else {
        return x * mpower(x, n - 1) % MOD;
    }
}
LL mfrac(LL x) {
    LL res = 1;
    for(LL i = x; i >= 1; i--) {
        res *= i;
        res %= MOD;
    }
    return res;
}
LL mcomb(LL n, LL r) {

    if(n == 0 and r == 0) {
        return 1;
    } else if(n < r || n < 0) {
        return 0;
    }

    LL res = mfrac(n) * mpower(mfrac(r), MOD - 2) % MOD;
    res *= mpower(mfrac(n - r), MOD - 2) % MOD;

    return res;
}

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

    vector<pair<int, int>> X(N);
    rep(i, N) {
        int tmp;
        cin >> tmp;
        X[i] = make_pair(tmp, i);
    }
    sort(RALL(X));

    vector<pair<int, int>> ans(N);
    rep(i, N) {
        if(i < N / 2) {
            ans[i] = make_pair(X[i].second, X[N / 2].first);
        }else{
            ans[i] = make_pair(X[i].second, X[N / 2 - 1].first);
        }
    }
    sort(ALL(ans));

    rep(i, N){
        cout << ans[i].second << endl;
    }
    return 0;
}


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

int main(){
    int n, a, j;
    int trump[4][13];
    string c;

    for(int i=0;i<4;i++){
        for(int k=0;k<13;k++){
            trump[i][k]=1;
        }
    }


    cin >> n;
    for(int i=0;i<n;i++){
        cin >> c >> j;
        if(c == "S"){
            a = 0;
        }else if(c == "H"){
            a = 1;
        }else if(c == "C"){
            a = 2;
        }else if(c == "D"){
            a = 3;
        }
        trump[a][j - 1] = 0;
    }

    for(int i=0;i<4;i++){
        if(i==0){
            c="S";
        }else if(i==1){
            c="H";
        }else if(i==2){
            c="C";
        }else if(i==3){
            c="D";
        }
        for(int k=0;k<13;k++){
            if(trump[i][k]){
                cout << c << " " << k + 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3120
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n;cin>>n;
    vector<int> v(9,0);
    for(int i=0;i<n;i++){
        int a;cin>>a;
        if(a<400) v[0]++;
        else if(a<800) v[1]++;
        else if(a<1200) v[2]++;
        else if(a<1600) v[3]++;
        else if(a<2000) v[4]++;
        else if(a<2400) v[5]++;
        else if(a<2800) v[6]++;
        else if(a<3200) v[7]++;
        else v[8]++;
    }
    int mi=0,ma=0;
    for(int i=0;i<8;i++){
        if(v[i]){
            mi++;
            ma++;
        }
    }
    ma=mi+v[8];
    if(mi==0) mi=1;
    cout<<mi<<" "<<ma<<endl;
}


Measured memory_bytes: 256