akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
main(){
  double x1,y1,x2,y2,xq,yq;
  while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq)){
    if(x2==x1){
      printf("%lf %lf\n",(x2-xq)*2+xq,yq);
      continue;
    } else if(y2==y1){
      printf("%lf %lf\n",xq,(y2-yq)*2+yq);
      continue;
    }

    double a1 = (y2-y1)/(x2-x1);
    double b1 = y1 - a1*x1;
    double a2 = -(1/a1);
    double b2 = yq - a2*xq;
    //    printf("y=%lfx+%lf\n",a1,b1);
    //    printf("y=%lfx+%lf\n",a2,b2);
    //    y-a1x=b1;
    //    y-a2x=b2;
    a1*=-1;
    a2*=-1;
    double y0 = (a2*b1-a1*b2)/(1*a2-1*a1);
    double x0 = (1*b2 - 1*b1)/(1*a2-1*a1);
    //    printf("%lf %lf\n",x0,y0);
    double xr = (x0-xq)*2+xq;
    double yr = (y0-yq)*2+yq;
    printf("%lf %lf\n",xr,yr);
  } 
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int N = 51;
int dp[N][N * N] = {};
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x, ans = 0;
    cin >> n >> x;
    vector <int> a(n);
    for (auto &i : a) cin >> i;
    for (int t = 1; t <= n; t++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N * N; j++) dp[i][j] = 0;
        }
        dp[0][0] = 1;
        for (int j = 0; j < n; j++) {
            for (int i = t - 1; i >= 0; i--) {
                for (int k = 0; k < x * t; k++) {
                    dp[i + 1][k + a[j]] += dp[i][k];
                }
            }
        }
        ans += dp[t][x * t];
    }
    cout << ans << '\n';
}


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

typedef vector<int> V;
typedef vector<V> VV;
typedef pair<int, int> P;
typedef queue<P> Q;

int N, K;
VV t;

int count_node(V s, int r) {
  Q q;
  V u;
  u.resize(N);
  for (int i = 0; i < N; ++i) {
    u[i] = 0;
  }
  for (auto n : s) {
    q.push(P(n, 0));
  }
  int count = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    auto n = p.first;
    auto d = p.second;
    if (u[n]) continue;
    u[n] = 1;
    ++count;
    if (d >= r) continue;
    for (auto a : t[n]) {
      if (u[a]) continue;
      q.push(P(a, d + 1));
    }
  }
  return count;
}

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

  t.resize(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    t[a].push_back(b);
    t[b].push_back(a);
  }

  V s;
  int m = 0;
  if (K % 2 == 0) {
    s.resize(1);
    for (int i = 0; i < N; ++i) {
      s[0] = i;
      m = max(m, count_node(s, K / 2));
    }
  } else {
    s.resize(2);
    for (int i = 0; i < N; ++i) {
      s[0] = i;
      for (auto a : t[i]) {
        if (a <= i) continue;
        s[1] = a;
        m = max(m, count_node(s, K / 2));
      }
    }
  }
  cout << N - m << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int INF=1e9;

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

  int N; cin>>N;
  vector<string> s(N);
  for(int i=0;i<N;i++) cin>>s[i];

  vector<vector<int>> G(N);
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++) if(s[i][j]=='1'){
      G[i].push_back(j);
    }
  }

  bool bipartite=true;
  vector<int> color(N);
  function<void(int,int)> dfs=[&](int v,int c){
    color[v]=c;
    for(int u:G[v]){
      if(color[u]==0) dfs(u,-c);
      if(color[u]==c) bipartite=false;
    }
  };
  
  dfs(0,1);
  if(!bipartite){
    cout<<-1<<endl;
    return 0;
  }

  vector<vector<int>> dist(N,vector<int>(N,INF));
  for(int i=0;i<N;i++) for(int j=0;j<N;j++){
    if(s[i][j]=='1') dist[i][j]=1;
    if(i==j) dist[i][j]=0;
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++) for(int j=0;j<N;j++){
      chmin(dist[i][j],dist[i][k]+dist[k][j]);
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++) chmax(ans,dist[i][j]+1);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();
            int iX = int.Parse(sS);
            sS = Console.ReadLine().Trim();
            int iA = int.Parse(sS);
            sS = Console.ReadLine().Trim();
            int iB = int.Parse(sS);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = (iX - iA) % iB;

            // 出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

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

  ll ans=0;

  for(int i=1;i<=n;i++){
      if(i%3!=0 && i%5!=0){
          ans += i;
      }
  }

  cout << ans << endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli a, b, m;
    cin >> a >> b >> m;
    vector<lli> v1;
    vector<lli> v2;
    lli m1 = 1000000, m2 = 1000000;
    for1(i, 0, a)
    {
        lli k;
        cin >> k;
        v1.pb(k);
        if (k < m1)
            m1 = k;
    }
    for1(i, 0, b)
    {
        lli k;
        cin >> k;
        v2.pb(k);
        if (k < m2)
            m2 = k;
    }
    lli sum = m1 + m2;
    for1(i, 0, m)
    {
        lli x, y, c;
        cin >> x >> y >> c;
        if (v1[x - 1] + v2[y - 1] - c < sum)
        {
            sum = v1[x - 1] + v2[y - 1] - c;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 2548
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

ll n, m;

int main() {
	scanf("%lld %lld",&n,&m);
	ll ans = 0;
	ll sol = min(n, m / 2);
	m -= sol * 2;
	ans = max(ans, sol + m / 4);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
n, k = gets.split(' ').map(&:to_i)
v = gets.split(' ').map(&:to_i)

q = [k, n].min
answer = (0..q).map do |j|
    (0..j).map do |shift|
        stone = v.slice(0, j - shift) + v.slice(n - shift, shift)
        minus_stone, plus_stone = stone.partition {|i| i < 0}
        (minus_stone.sort.drop(k - j) + plus_stone).reduce(0, :+)
    end
end.flatten(1).max

puts answer


Measured memory_bytes: 2300
from bisect import bisect_left
import random
import time
time_start = time.perf_counter()


#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
#初期解
T = []
for _ in range(D):
    t = random.randrange(26)
    T.append(t)


last_day = [[-1] for _ in range(26)]
for d in range(D):
    test = T[d]
    last_day[test].append(d)
for i in range(26):
    last_day[i].append(D)

while True:
    time_now = time.perf_counter()
    if time_now - time_start > 1.8:
        break
    d = random.randrange(365)
    q = random.randrange(26)
    old = T[d]
    T[d] = q
    #日程dでの元のテストold
    l = last_day[old]
    ind_old = l.index(d)
    dd_left = l[ind_old] - l[ind_old-1] - 1
    dd_right = l[ind_old+1] - l[ind_old] - 1
    dd = l[ind_old+1] - l[ind_old-1] - 1
    dif_old = C[old] * (((dd_left * (dd_left + 1)) // 2) + ((dd_right * (dd_right + 1)) // 2) - ((dd * (dd + 1)) // 2))
    #日程dでのテストq
    l = last_day[q]
    ind_q = bisect_left(last_day[q],d)
    dd_left = d - l[ind_q-1] - 1
    dd_right = l[ind_q] - d - 1
    dd = l[ind_q] - l[ind_q-1] - 1
    dif_q = C[q] * (((dd * (dd + 1)) // 2) - ((dd_left * (dd_left + 1)) // 2) - ((dd_right * (dd_right + 1)) // 2))
    #変更による差
    dif_s = (dif_old + dif_q - S[d][old] + S[d][q])
    if dif_s > 0:
        del last_day[old][ind_old]
        last_day[q].insert(ind_q,d)
    else:
        T[d] = old
for d in range(365):
    print(T[d] + 1)



Measured memory_bytes: 86804
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    vector<ll>a(3);
    ll d;
    cin>>a[0]>>a[1]>>a[2]>>d;
    if(abs(a[0]-a[2])<=d){
        cout<<"Yes"<<endl;
        exit(0);
    }
    sort(a.begin(),a.end());
    if(abs(a[0]-a[1])<=d&&abs(a[1]-a[2])<=d){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  int count=0,count_max=0,pt=0;
  for(int i=0;i<n;++i){
    if(s[i]=='E') count++;
    else count--;
    if(count_max < count){
      count_max = count;
      pt = i;
    }
  }
  int ans=0;
  for(int i=0;i<pt;++i){
    if(s[i]=='W') ans++;
  }
  for(int i=pt+1;i<n;++i){
    if(s[i]=='E') ans++;
  }
  //cout << "pt = " << pt << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 900
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = input()
    K = I()

    dp1 = [[0] * len(N) for _ in range(K + 2)] #未確定
    dp2 = [[0] * len(N) for _ in range(K + 2)] #確定

    dp1[1][0] = 1
    dp2[0][0] = 1
    dp2[1][0] = int(N[0]) - 1

    for i in range(1, len(N)):
        num = int(N[i])
        for k in range(K+1):
            if num == 0:
                dp1[k][i] += dp1[k][i - 1]
                dp2[k][i] += dp2[k][i - 1]
                dp2[k+1][i] = dp2[k][i - 1] * 9
            else:
                dp1[k + 1][i] += dp1[k][i - 1]
                dp2[k][i] += dp2[k][i - 1] + dp1[k][i - 1]
                dp2[k + 1][i] = dp2[k][i - 1] * 9 + dp1[k][i - 1] * (num - 1)

    print(dp1[K][-1] + dp2[K][-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 76824
def solve
  n, a, b = gets.split.map!(&:to_i)
  a_add_b = a + b
  x = n % a_add_b
  y = n / a_add_b
  ans = 0
  if x <= a
    ans = (a * y) + x
  else
    ans = (a * y) + a
  end
  
  print ans
end
solve


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b;
  cin>>a>>b;
  if(a%b==0){
    cout<<-1<<endl;
    return 0;
  }
  for(long long i=1;;i++){
    if(a*i>1000000000000000001){
      cout<<-1<<endl;
      return 0;
    }
    else if(a*i%b!=0){
      cout<<a*i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()
ans = min(h,w)
if w%3 == 1:
    a = w//3
else:
    a = w//3+1
c = max(h*a,(h//2)*(w-a),h*(w-a)-(h//2)*(w-a))-min(h*a,(h//2)*(w-a),h*(w-a)-(h//2)*(w-a))
if h % 3== 1:
    b = h//3
else:
    b = h//3+1
d = max(w*b,(w//2)*(h-b),w*(h-b)-(w//2)*(h-b))-min(w*b,(w//2)*(h-b),w*(h-b)-(w//2)*(h-b))
print(min(ans,c,d))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
struct tree {
  int key;
  int priority;
  struct tree *left;
  struct tree *right;
};
struct tree *root = NULL;
int Search(struct tree *p, int key);
struct tree *Lrotation(struct tree *p);
struct tree *Rrotation(struct tree *p);
struct tree *Insert(struct tree **p, int key, int priority);
struct tree *Delete(struct tree **p, int key);
struct tree *delete(struct tree **p, int key);
void Dispm(struct tree *p);
void Dispp(struct tree *p);
int main(void)
{
  int i, count, key, priority;
  char command[7];
  scanf("%d", &count);
  for (i = 0; i < count; i++) {
    scanf("%*c%s", command);
    switch (command[0]) {
    case 'f':
      scanf("%d", &key);
      if (Search(root, key)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
      break;
    case 'i':
      scanf("%d %d", &key, &priority);
      root = Insert(&root, key, priority);
      break;
    case 'd':
      scanf("%d", &key);
      Delete(&root, key);
      break;
    case 'p':
      Dispm(root);
      putchar('\n');
      Dispp(root);
      putchar('\n');
      break;
    }
  }
  return 0;
}
int Search(struct tree *p, int key)
{
  if (p == NULL) {
    return 0;
  } else if (p->key == key) {
    return 1;
  } else if (p->key > key) {
    return Search(p->left, key);
  } else {
    return Search(p->right, key);
  }
}
struct tree *Lrotation(struct tree *p)
{
  struct tree *q = p->right;
  p->right = q->left;
  q->left = p;
  return q;
}
struct tree *Rrotation(struct tree *p)
{
  struct tree *q = p->left;
  p->left = q->right;
  q->right = p;
  return q;
}
struct tree *Insert(struct tree **p, int key, int priority)
{
  if (*p == NULL) {
    *p = (struct tree*)malloc(sizeof(struct tree));
    (*p)->key = key;
    (*p)->priority = priority;
    (*p)->left = NULL;
    (*p)->right = NULL;
  } else if ((*p)->key > key) {
    (*p)->left = Insert(&(*p)->left, key, priority);
    if ((*p)->priority <  (*p)->left->priority) *p = Rrotation(*p);
  } else if ((*p)->key < key) {
    (*p)->right = Insert(&(*p)->right, key, priority);
    if ((*p)->priority <  (*p)->right->priority) *p = Lrotation(*p);
  }
  return *p;
}
struct tree *Delete(struct tree **p, int key)
{
  if ((*p) == NULL) return NULL;
  if ((*p)->key > key) (*p)->left = Delete(&(*p)->left, key);
  else if ((*p)->key < key) (*p)->right = Delete(&(*p)->right, key);
  else delete(p, key);
  return *p;
}
struct tree *delete(struct tree **p, int key)
{
  if ((*p)->left == NULL && (*p)->right == NULL) return *p = NULL;
  else if ((*p)->left == NULL) *p = Lrotation(*p);
  else if ((*p)->right == NULL) *p = Rrotation(*p);
  else {
    if ((*p)->left->priority > (*p)->right->priority) *p = Rrotation(*p);
    else *p = Lrotation(*p);
  }
  return Delete(p, key);
}
void Dispm(struct tree *p)
{
  if (p != NULL) {
    Dispm(p->left);
    printf(" %d", p->key);
    Dispm(p->right);
  }
}
void Dispp(struct tree *p)
{
  if (p != NULL) {
    printf(" %d", p->key);
    Dispp(p->left);
    Dispp(p->right);
  }
}


Measured memory_bytes: 7988
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
char buff[1 << 22];
template <int size>
struct Buffer{
    int idx = 0;
    Buffer(){ read(0, buff, size); }
    int next(){
        int ret = 0;
        while(!isdigit(buff[idx])){ idx++; }
        while(isdigit(buff[idx])){ ret = ret * 10 + buff[idx++] - '0'; }
        return ret;
    }
};
struct FastInput {
    Buffer<1 << 22> buf;
    template <class T>
    FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

enum { SIZE = 1 << 20 };
char buf[SIZE];
int accs[512][512];
pair<int, int> pqs[100000];
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        accs[0][r]++;
        accs[l + 1][r]--;
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            accs[i + 1][j] += accs[i][j];
            accs[i][j] += accs[i][j - 1];
        }
    }
    int idx = SIZE;
    for(int i = 0; i < q; i++){
        cin >> pqs[i].first >> pqs[i].second;
    }
    for(int i = q - 1; i >= 0; i--){
        int p = pqs[i].first, q = pqs[i].second;
        buf[--idx] = '\n';
        div_t num2;
        num2.quot = accs[p][q];
        do{
            num2 = div(num2.quot, 10);
            buf[--idx] = num2.rem + '0';
        }while(num2.quot);
    }
    write(1, buf + idx, SIZE - idx);
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> line(n);
    for(auto&i:line){
        cin>>i;
    }
    sort(line.begin(), line.end());
    line.erase(unique(line.begin(), line.end()), line.end());
    if(n==line.size()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using ll = long long;
using ull = unsigned long long;

struct Edge{
	int to; //where to go to
	int weight; //weight of this edge
	Edge(int arg_t, int arg_w) : to(arg_t), weight(arg_w){};
};


using Graph = std::vector<std::vector<Edge>>;


void dfs(int v, int p, ull d, const Graph &G, std::vector<ull> &depth){
	depth[v] = d;
	for(auto &nv : G[v]){
		if(nv.to == p)continue;
		dfs(nv.to, v, d + nv.weight, G, depth);
	}
}


int main(){


	int N; std::cin >> N;
	Graph G(N);
	std::vector<ull> depth(N);
	rep(i, N - 1){
		int a, b, c; std::cin >> a >> b >> c;
		a--; b--;
		G[a].push_back(Edge(b, c));
		G[b].push_back(Edge(a, c));
	}
	int Q, K; std::cin >> Q >> K;
	K--;

	dfs(K, -1, 0, G, depth);

	rep(i, Q){
		int x, y; std::cin >> x >> y;
		x--; y--;
		std::cout << depth[x] + depth[y] << std::endl;
	}



	return 0;
}

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




int main()
{	
	ll n,ans=0;
	cin>>n;
 string s;
  map<string,ll>m;


for(ll i=0;i<n;i++)
{
  cin>>s;
  sort(s.begin(),s.end());
	m[s]++;
}
for(auto u:m)
{
  ans+=(u.second*(u.second-1))/2;
}
  cout<<ans;

}


Measured memory_bytes: 11136
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
    cout << "hon" << endl;
  } else if (n == 3) {
    cout << "bon" << endl;
  } else {
    cout << "pon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool comp1(pair<int,int> &a,pair<int,int> &b)
{
    return a.second>b.second;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    ll sum=0;
    for(int i=0;i<n-k;i++){
        sum+=a[i];
    }
    cout<<sum;
}

Measured memory_bytes: 5180
#include <stdio.h>
int main(void){
    int a[100][100]={{0}};
    int b[100]={0};
    int c[100]={0};
    int i,j,n,m;
    
    scanf("%d %d",&n,&m);
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(i=0; i<m; i++){
        scanf("%d",&b[i]);
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            c[i] += a[i][j]*b[j];
        }
    }
    
    for(i=0; i<n; i++){
        printf("%d\n",c[i]);
    }
    
    return 0;
}

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

int main() {
    string s;
    cin >> s;

    int result1 = 0;
    int result2 = 0;
    for (int i = 0; i < s.length(); i++) {
        int si = s[i];
        int rem = i % 2;
        if (rem == 1) {
            if (si == '0') {
                result1++;
            } else {
                result2++;
            }
        } else {
            if (si == '0') {
                result2++;
            } else {
                result1++;
            }
        }
    }
    int result;
    if (result1 > result2) {
        result = result2;
    } else {
        result = result1;
    }
    cout << result << endl;

	return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
bool plus_minus(int x){
    if(x == 0)return true;
    else return false;
}
int main(void){
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    int ia = a - 48;
    int ib = b - 48;
    int ic = c - 48;
    int id = d - 48;
    bool finish(false);
    for(int i(0);i<2;i++){
        for(int j(0);j<2;j++){
            for(int k(0);k<2;k++){
                int num(ia);
                if(plus_minus(i))num += ib;
                else num -=ib;
                if(plus_minus(j))num += ic;
                else num -=ic;
                if(plus_minus(k))num += id;
                else num -=id;
                if(num == 7){
                    cout<<ia;
                    if(plus_minus(i))cout<<'+';
                    else cout<<'-';
                    cout<<ib;
                    if(plus_minus(j))cout<<'+';
                    else cout<<'-';
                    cout<<ic;
                    if(plus_minus(k))cout<<'+';
                    else cout<<'-';
                    cout<<id<<"=7"<<endl; 
                    finish = true;
                }
                if(finish)break;
            }
            if(finish)break;
        }
        if(finish)break;
    }
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x; cin>>x;
	int ans=1;
	for(int i=2;i*i<=x;++i){
		int j=i*i;
		while(j<=x)j*=i;
		ans=max(ans,j/i);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define mer make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;
typedef pair<int,pair<int,int> > ipii;
typedef pair<pii,pii> pi4;
const int vbi=999999999;

int main(){
	//my new name is Veex
	//clock_t start1=clock();
	int n,t,minn=vbi;
	cin>>n>>t;
	for(int i=1;i<=n;i++){
		int c,s;
		cin>>c>>s;
		if(s<=t)
			minn=min(minn,c);
	}
	if(minn==vbi)
		cout<<"TLE";
	else
		cout<<minn;
	//cout<<endl<<((double)(clock()-start1)/CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    int n,m;
    cin >> n >> m;
    vector<Pll> drinks(n);
    for(int i=0;i<n;++i) {
        cin >> drinks[i].first >> drinks[i].second;
    }
    sort(all(drinks));

    ll ans = 0LL;
    int count = 0;
    for(int i=0;i<n;++i) {
        ans += drinks[i].first * min(drinks[i].second, ll(m-count));
        count += min(drinks[i].second, ll(m-count));
        if(count == m) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

map <ll, ll> dp;

ll n, a[3], d;
ll val[3] = {2, 3, 5};

ll f(ll x) {
	if (x == 0) {
		return 0;
	}
	if (x == 1) {
		return d;
	}
	if (dp.count(x)) {
		return dp[x];
	}
	ll res = 9e18;
	if (x < res / d) {
		res = min(res, x * d);
	}
	for (int i = 0; i < 3; i++) {
		if (x % val[i] == 0) {
			res = min(res, a[i] + f(x / val[i]));
		}	else {
			ll A = x / val[i];
			ll B = (x + val[i] - 1) / val[i];
			A *= val[i], B *= val[i];
			res = min(res, d * abs(x - A) + a[i] + f(A / val[i]));
			res = min(res, d * abs(x - B) + a[i] + f(B / val[i]));
		}
	}
	return dp[x] = res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	int tc;
	cin >> tc;
	while (tc--) {
		dp.clear();
		cin >> n >> a[0] >> a[1] >> a[2] >> d;
		cout << f(n) << '\n';
	}
}


Measured memory_bytes: 4380
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u8 = read();
    let s: String = read();

    for i in 0..s.len() {
        print!("{}", ((s.chars().nth(i).unwrap() as u8 + n) % 65 % 26 + 65) as char);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<45;
ll Sum[100];
ll n,m,a,b,p,q;


ll calc(ll k){
  ll A = 1,B = 1,res=p+q;
  while(res>0&&res<=INF&&k--)A*=a,B*=b,res=p*A+q*B;
  if(res<0) res = INF;
  return min(INF,res);
}

ll ans = INF;
set<ll> used[101];
void dfs(ll pos,ll sum){
  ans = min(ans,(ll)abs(m-sum));
  if(m<sum||pos==-1||sum>INF||used[pos].count(sum)) return;
  if(Sum[pos]+sum<m){ans=min(ans,m-(Sum[pos]+sum));return;}
  used[pos].insert(sum);
  dfs(pos-1,sum+calc(pos));  
  dfs(pos-1,sum);
}

int main(){
  cin>>n>>m>>a>>b>>p>>q;
  Sum[0] = calc(0);
  for(int i=1;i<60;i++)Sum[i]=min(INF,calc(i)+Sum[i-1]);
    if(max(a,b)==1) {
    ll s = abs(m - (m/(p+q))*(p+q));
    ll t = abs(m - (m/(p+q))*(p+q) - (p+q));
    if(m/(p+q)==n) t = INF;
    if(m/(p+q)<=n) cout<<min(s,t)<<endl;
    else cout<< m-(p+q)*n <<endl;
    return 0;
    }
  
  dfs(min(n-1,50LL),0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        sc.nextLine();

        char[][] s = new char[h][w];
        for(int i=0; i<h; i++) {
            s[i] = sc.nextLine().toCharArray();
        }
        sc.close();

        //right, up, left, down
        int[] x = {0, -1, 0, 1};
        int[] y = {1, 0, -1, 0};

        boolean[][] isVisited = new boolean[h][w];
        int cnt = 0;
        int foundCnt = 0;

        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                if(s[i][j] == '#') {
                    cnt++;
                    for(int k=0; k<4; k++) {
                        int nx = i+x[k];
                        int ny = j+y[k];
                        if( nx >= 0 && nx < h && ny >= 0 && ny < w &&
                            s[nx][ny] == '#' && !isVisited[nx][ny]) {
                            isVisited[nx][ny] = true;
                            foundCnt++;
                        }
                    }
                }
            }
        }
        if(cnt == foundCnt) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  
  int p1 = a * n;
  int p2 = b;
  
  if (p1 <= p2) {
  	  cout << p1 << endl;
  }
  else {
      cout << p2 << 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<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<ll, string> a, pair<ll, string> b) {
    if(a.first != b.first){
        return a.first > b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N;
    cin >>N;
    vector<string> S(N);
    vector<pair<ll,string>> lis;
    map<string,ll> m;
    ll kind = 1;
    rep(i,N){
        cin >>S[i];
        if(m[S[i]] == 0){
            lis.pb(make_pair(1,S[i]));
            m[S[i]] = kind;
            kind++;
        }else{
            lis[m[S[i]]-1].first++;
        }
    }

    sort(all(lis),compare);
    //reverse(all(lis));
    ll mx = lis[0].first;
    cout << lis[0].second << endl;
    rep2(i,N-1){
        if(lis[i].first == mx){
            cout << lis[i].second << endl;
        }else{
            break;
        }
    }
    //cout << N << endl;


    return 0;
    

}

Measured memory_bytes: 32884
#include <stdio.h>
#include <stdlib.h>
#define N 100010
int min(int a,int b);
int main(){
	char sn[N];
	int an[N]={0};
	int cour,coul,i,k,p,d,flag,first,m;
	cour=coul=0;
	i=k=0;
	flag=0;
	first=1;
	scanf("%s",sn);
	/*search*/
	while(sn[i]){
		if(sn[i]=='R'){
			if(flag==0){
				cour++;
		}else if(flag==1){
			/*集計処理ポイント*/
			if(first==1){
				//coul--;
				cour--;
				first=0;
			}
			d=abs(coul-cour);
			//printf("%d %d %d\n",cour,coul,d);
			if(d%2==0){
				an[p-1]=an[p]=(1+min(coul,cour)+(d/2));
			}else{
				if(min(coul,cour)%2==0){
					an[p]=(2+min(coul,cour)+(d/2));
					an[p-1]=(1+min(coul,cour)+(d/2));
				}else{
					an[p]=(1+min(coul,cour)+(d/2));
					an[p-1]=(2+min(coul,cour)+(d/2));
				}
			}
			if(coul>cour){
				m=an[p];
				an[p]=an[p-1];
				an[p-1]=m;
			}
			cour=coul=0;
			
		}
		flag=0;
	}else if(sn[i]=='L'){
		if(flag==0){
			/*集合場所のL座標*/
			p=i;
		}else if(flag==1){
			coul++;
		}
		flag=1;
	}
	i++;
	}
	/*end集計処理ポイント*/
			if(first==1){
				//coul--;
				cour--;
				first=0;
			}
			d=abs(coul-cour);
			//printf("%d %d %d\n",cour,coul,d);
			if(d%2==0){
				an[p-1]=an[p]=(1+min(coul,cour)+(d/2));
			}else{
				if(min(coul,cour)%2==0){
					an[p]=(2+min(coul,cour)+(d/2));
					an[p-1]=(1+min(coul,cour)+(d/2));
				}else{
					an[p]=(1+min(coul,cour)+(d/2));
					an[p-1]=(2+min(coul,cour)+(d/2));
				}
			}
			if(coul>cour){
				m=an[p];
				an[p]=an[p-1];
				an[p-1]=m;
			}
			cour=coul=0;
			
	for(k;k<i;k++){
		printf("%d ",an[k]);
	}
	printf("\n");
}
int min(int a,int b){
	if(a>=b){
		return b;
	}else if(a<b){
		return a;
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int main(){
  string s; cin>>s;
  int N = s.size();
  int s_buf = 0;
  int r = N;
  REP(i,N){
    if(s[i]=='T'){
      if(s_buf>0){
        r -= 2;
        --s_buf;
      }
    }else{
      ++s_buf;
    }
  }
  cout << r <<"\n";
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, K = MI()

    i = 1
    while K ** i <= N:
        i += 1
    print(i)


main()


Measured memory_bytes: 64720
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool ans = (abs(a - b) <= d && abs(b - c) <= d || abs(a - c) <= d);
  puts(ans ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector as V
a#b = abs$a-b

main = B.interact$B.pack.show.g.unfoldr(B.readInt.B.dropWhile isSpace)

g (n:k:hr)=dp V.! (n-1)
    where
        hv = UV.fromListN n hr
        dp = V.generate n $ \i -> if i==0 then 0 else
            let bg = max 0 (i-k)
            in
            UV.minimum $ UV.zipWith (+) (UV.map (# (hv UV.! i)) $ UV.slice bg (i-bg) hv) $ UV.convert $ V.slice bg (i-bg) dp


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

string to_string(string s) {
    return '"' + s + '"';
}
string to_string(char ch) {
    string s(1, ch);
    return '\'' + s + '\'';
}
string to_string(const char *s) {
    return to_string((string)s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int ll;
#define int ll
#define pb          push_back
#define pll         pair<int,int>
#define mll	        map<int,int>
#define F           first
#define S           second
#define lbnd(v,val) lower_bound(v.begin(),v.end(),val)
#define ubnd(v,val) upper_bound(v.begin(),v.end(),val)
#define bs(v,val)   binary_search(v.begin(),v.end(),val)
#define mp          make_pair
#define f(i,x,n)    for(int i=x;i<n;i++)
#define isup		isupper
#define islow 		islower
#define max3(a,b,c)	max(a,max(b,c))
#define endl        "\n"
#define countbits(n)	 __builtin_popcountll(n)
#define all(ar) ar.begin(), ar.end()
#define rall(ar) (ar).rbegin(), (ar).rend()
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 2e5 + 10;

typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;

double dp[301][301][301];
double calc(int o,int t,int th,int n){
	if(o<0 || t<0 || th<0){
		return 0;
	}else if(o==0 and t==0 and th==0){
		return 0;
	}
	if(dp[o][t][th]>0){
		return dp[o][t][th];
	}
	double ans;
	ans = n + o*calc(o-1,t,th,n) + t*calc(o+1,t-1,th,n) + th*calc(o,t+1,th-1,n);
	return dp[o][t][th] = ans/(double)(o+t+th);
}

void solve(){
	int n;
	cin>>n;
	int one=0,two=0,three=0;
	f(i,0,n){
		int x;
		cin>>x;
		if(x==1){
			one++;
		}else if(x==2){
			two++;
		}else{
			three++;
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<fixed<<setprecision(9)<<calc(one,two,three,n)<<endl;
}

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

    

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


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

int main() {
	
	string s; cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'x') cnt++;
	}
	if (8 <= cnt) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

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

using namespace std;

int n,k,i,j;
int a[200005];


int possible(int w){
	
	long long int c=0,d=k;
	for(i=1;i<=n;i++){
		d-=(a[i]+w-1)/w-1;
	}
	return d>=0;
}

int main( ){
	int low,mid,high;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	low=1,high=1e9+100;
	while(low<high){
		mid=low+(high-low)/2;
		if(possible(mid)){
			high=mid;
		}
		else{
			low=mid+1;
		}
	}
	cout<<low<<endl;
	return 0;
}

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

int card[255][14]={{0}};

int main(void){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        char c;
        int num;
        cin>>c>>num;
        card[(int)c][num]=1;
    }
    
    for(int i=1; i<=13; i++){
        if(card[(int)'S'][i]==0){
            cout<<"S "<<i<<endl;
        }
    }
    
    for(int i=1; i<=13; i++){
        if(card[(int)'H'][i]==0){
            cout<<"H "<<i<<endl;
        }
    }
    
    for(int i=1; i<=13; i++){
        if(card[(int)'C'][i]==0){
            cout<<"C "<<i<<endl;
        }
    }
    
    for(int i=1; i<=13; i++){
        if(card[(int)'D'][i]==0){
            cout<<"D "<<i<<endl;
        }
    }
}



Measured memory_bytes: 3084
while 1:
    n=int(input())
    k=int(input())
    if n==k==0:break
    card=[]
    ans=[]
    for i in range(n):
        card.append(str(input()))
    if k==2:
        for i in range(n):
            for j in range(n):
                if i==j:continue
                ans.append(card[i]+card[j])
    elif k==3:
        for i in range(n):
            for j in range(n):
                if i==j:continue
                for k in range(n):
                    if i==k or j==k:continue
                    ans.append(card[i]+card[j]+card[k])
    elif k==4:
        for i in range(n):
            for j in range(n):
                if i==j:continue
                for k in range(n):
                    if i==k or j==k:continue
                    for l in range(n):
                        if i==l or j==l or k==l:continue
                        ans.append(card[i]+card[j]+card[k]+card[l])    
    ans=list(set(ans))
    print(len(ans))


Measured memory_bytes: 6056
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 5121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	long long ret=0;
	init_C(1100000);
	for(int i=0;i<=b;i++){
		if(i>a)continue;
		long long ks=Comb(b,i)*Comb(a,i)%mod;
		ks=ks*fact[i]%mod;
		ks=ks*pw(a+1,b-i)%mod*pw(b+1,a-i)%mod;
		if(i%2)ret=(ret+mod-ks)%mod;
		else ret=(ret+ks)%mod;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 30848