akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
import bisect


def solve(X: int, N: int, p: "List[int]"):
    sortp = sorted(p)
    if(N == 0):
        print(X)
        exit()

    for i in range(100):
        # 左側
        l = X - i
        index = bisect.bisect_left(sortp,l)
        if(index == N or sortp[index] != l):
            print(l)
            exit()

        # 右側
        r = X + i
        index = bisect.bisect_left(sortp,r)
        if(index == N or sortp[index] != r):
            print(r)
            exit()

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62316
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
ll n,s;
cin>>n>>s;

vll v;

for(ll i=1;i*i<=n;i++)
{
	if(i>=2)
	{
	ll sum=0;
	ll x=n;
	while(x)
	{
		sum+=x%i;
		x/=i;
	}
	if(sum==s)
	{
		v.pb(i);
	}
	}
	
	ll hi=n/i,lo=n/(i+1)+1,rem=n%i;
	if(i*i!=n)
	{
	if(s-i>=rem&&s-i<=n-i*lo)
	{
	
		if((s-i-rem)%i==0)
		{
			v.pb((n-s+i)/i);
		}
	}}
}
if(n==s)v.pb(n+1);
sort(all(v));
if(v.size()==0)
ol("-1");
else
ol(v[0]);
return 0;
}


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

long double x[100];
long double y[100];
int n;

#define POW(x) ((x)*(x))

long double len(int i, int j){
    return sqrtl(POW(x[i]-x[j]) + POW(y[i]-y[j]));
}

long double solve(long double cx, long double cy, long double r){

    for(int i = 0;i < n;i++){
        if(sqrtl(POW(x[i]-cx) + POW(y[i]-cy)) > r+0.00000001){
            return LDBL_MAX;
        }
    }
    return r;
}

int main(){
    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> x[i] >> y[i];
    }

    long double ans = LDBL_MAX;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(i != j){
                ans = min(ans, solve((x[i]+x[j])/2, (y[i]+y[j])/2, len(i, j)/2));

                for(int k = 0;k < n;k++){
                    if(i != k && j != k){
                        long double ox, oy, a, b, c, d;
                        long double r1, r2, r3;
                        long double stat;
                        long double cx, cy, r;

                        a = x[j] - x[i];
                        b = y[j] - y[i];
                        c = x[k] - x[i];
                        d = y[k] - y[i];

                        if((a != 0 && d != 0) || (b != 0 && c != 0)){
                            ox = x[i] + (d * (a * a + b * b) - b * (c * c + d * d)) / (a * d - b * c) / 2;
                            if(b > LDBL_EPSILON){
                                oy = (a * (x[i] + x[j] - ox - ox) + b * (y[i] + y[j])) / b / 2;
                            }else{
                                oy = (c * (x[i] + x[k] - ox - ox) + d * (y[i] + y[k])) / d / 2;
                            }
                            r1 = sqrtl(POW(ox-x[i]) + POW(oy-y[i]));
                            r2 = sqrtl(POW(ox-x[j]) + POW(oy-y[j]));
                            r3 = sqrtl(POW(ox-x[k]) + POW(oy-y[k]));

                            cx = ox;
                            cy = oy;
                            r = (r1 + r2 + r3) / 3;
                            ans = min(ans, solve(cx, cy, r));
                        }
                    }
                }
            }
        }
    }

    if(ans == LDBL_MAX){
        abort();
    }else{
        printf("%.12Lf\n", ans);
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int i,j;
    vector<int> t(n);
    for(i = 0;i < n;++i){
        cin >> t.at(i);
    }
    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    for(i = 0;i < m;++i){
        cin >> p.at(i) >> x.at(i);
    }
    int ans = 0;
    for(i = 0;i < m;++i){
        for(j = 0;j < n;++j){
            if(j == p.at(i)-1){
                ans += x.at(i);
            }else{
                ans += t.at(j);
            }
        }
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}

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

using namespace std;

#define ll long long
#define ar array


ll n;
ll ans = 0;


ll combis(int x){
    
    ll ret = 0;

    ll i = 1;
    ll b = 2;
    while (i <= x)
    {
        i = i+b;
        b++;
        ret++;
    }
    
    return ret;
}

void solve(){

    cin >> n;

    
    ll tmp = sqrt(n)+1;

    ll pow = 0;

    while(n % 2 == 0){
        n /=2;
        pow +=1;
    }
    ans += combis(pow);

    for (int i = 3; i < tmp; i = i+2)
    {
        pow = 0;
        while(n % i == 0){
            n /=i;
            pow +=1;
            //cout << "i :" << i << "  pow = " << pow << endl;
        }
        
        if(pow >0){
            //cout << "combis : " << combis(pow) << endl;
            ans += combis(pow);
        } 

        if(n == 1){
            break;
        } 
    }
    if(n != 1){
        ans ++;
    }
        cout << ans << endl;

    
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 3664
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int l, r;
    vector<pair<int, int>> gate(M);
    for (int i = 0; i < M; i++) {
        cin >> l >> r;
        gate[i].first = l;
        gate[i].second = r;
    }

    l = 0, r = N + 1;
    for (int i = 0; i < M; i++) {
        l = max(gate[i].first, l);
        r = min(gate[i].second, r);
    }
    if (r >= l) {
        cout << (r - l + 1) << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,s,a;
  while(1){
    scanf("%d",&n);
    if(!n)break;
    s=0;
    for(a=5;a<20000;a*=5){
      s+=n/a;
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 600
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
ans=0
for n in range(N):
    A=list(map(int,input().split()))
    s=sum([A[i]*B[i] for i in range(M)])+C
    if s>0:
        ans+=1
print(ans)


Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if(N%2==1){
      System.out.println(((N/2)+1)/(double)N);
    }
    else{
      System.out.println(0.50000000000);
    }
  }
}

Measured memory_bytes: 23380
<?php   
fscanf(STDIN,"%s",$s);


       
 $s_modi=$s;
       
for($i=0;$i<strlen($s);$i++){
  $s_modi = substr($s_modi, 0, -1);
  $len = (int)(strlen($s_modi)/2);
  $front = substr($s_modi,0,(strlen($s_modi)-$len));
  $back = substr($s_modi,$len,$len);
  //echo "front ${front} back ${back} \n";
  if($front==$back){
    echo strlen($s_modi)."\n";
    break;
  }
}

Measured memory_bytes: 4604
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
/// 最小公倍数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }
int main(){
  vector<int> N(4);
  for(int i = 0; i < 4; i++){
      cin >> N[i];

  }
bool ok_1 = false;
bool ok_9 = false; 
bool ok_4 = false;
bool ok_7 = false;
for(int i = 0;i < 4; i++){
    if(N[i] == 1)ok_1 = true;
    else if(N[i] == 7)ok_7 = true;
    else if(N[i] == 9)ok_9 = true;
    else if(N[i] == 4)ok_4 = true;
}
if(ok_1 && ok_7 && ok_4 && ok_9)cout << "YES" << endl;
else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char **argv)
{
    int N;
    long long H;
    std::cin >> N >> H;
    std::vector<long long> a(N), b(N);

    long long max_a = 0;
    for(int i = 0; i < N; i++){
        std::cin >> a.at(i) >> b.at(i);
        max_a = std::max(a.at(i), max_a);
    }

    std::vector<long long> bb;
    long long bb_sum = 0;
    for(int i = 0; i < N; i++){
        if(b.at(i) >= max_a){
            bb.push_back(b.at(i));
            bb_sum += b.at(i);
        }
    }
    std::sort(bb.begin(), bb.end(), std::greater<long long>());

    if(bb_sum >= H){
        long long i = 0;
        for(;;){
            H -= bb.at(i);
            i++;
            if(H <= 0){
                std::cout << i << std::endl;
                return 0;
            }
        }
    }else{
        long long h = H - bb_sum;
        long long k = (h + (max_a-1)) / max_a;
        std::cout << (k + bb.size()) << std::endl;
    }
    
}


Measured memory_bytes: 2936
s = input()
a = []
for i in range(len(s)):
  a.append(s[i])
a.pop(5)
a.pop(-6)

a1 = a[0]+a[1]+a[2]+a[3]+a[4]
a2 = a[5]+a[6]+a[7]+a[8]+a[9]+a[10]+a[11]
a3 = a[12]+a[13]+a[14]+a[15]+a[16]

print(a1 +" "+ a2 +" "+ a3)

Measured memory_bytes: 3064
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const ll MAX = 1e15 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


#define int ll

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


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int a, b, c;
main() {
    file("rmq");
    ios;
    cin >> a >> b >> c;
    int d = a + b;
    cout << min(d + 1, c) + b;
    return 0;
}
/**
caca
*/


Measured memory_bytes: 256
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=3e5+5;

ll dp[N][21];

int main()
{ 

IOS;

ll n;cin>>n;

vl a(n+1);

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

sort(a.begin()+1,a.end());


ll ans1=0;

for(int i=1;i<=n;i++)
{
  ans1+=abs(a[(n+1)/2]-a[i]);
 // ans2+=abs(a[n/2+1]-a[i]);
}

cout<<ans1<<endl;

return 0;
 
}



Measured memory_bytes: 4728
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void){

  int A, B;  cin >> A >> B;
  if(A >= 1 && 9 >= A && B >= 1 && 9 >= B)
    cout << A * B << endl;
  else
    cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.function.BiConsumer;


//幅優先探査（BFS）による解法
//Breadth-first search
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();    
        int X = sc.nextInt();    
        int Y = sc.nextInt();    
        sc.close();
        X--; Y--;
        int INF = 1001001001;
        int[] dist = new int[N];
        int[] count = new int[N];
        for (int sv = 0; sv < N; sv++) {
            Arrays.fill(dist, INF);
            Queue<Integer> queue = new ArrayDeque<>();
            BiConsumer<Integer, Integer> push = (v, d) -> { 
                if (dist[v] != INF) return;
                dist[v] = d;
                queue.add(v);
            };
            push.accept(sv, 0);
            while(queue.peek() != null) {
                int v = queue.poll();
                int d = dist[v];
                if (v - 1 >= 0) push.accept(v - 1, d + 1);
                if (v + 1 < N) push.accept(v + 1, d + 1);
                if (v == X) push.accept(Y, d + 1);
                if (v == Y) push.accept(X, d + 1);
            }
            for (int i = 0; i < N; i++) {
                count[dist[i]]++;
            }
        }
        
        for (int i = 1; i < N; i++){
            System.out.println(count[i]/2);        
        }
    }
}


Measured memory_bytes: 96328
import sys
N = int(input())

b = 1

a = sorted(list(map(int, input().split())), reverse=True)
if a[-1] == 0:
    print("0")
    sys.exit()
for i in a:
    b *= i
    if b > pow(10, 18):
        print("-1")
        sys.exit()
print(b)

        


Measured memory_bytes: 21664
#include<iostream>
#include<algorithm>
#include<vector>
int N,M;
int D[100010];
int main(){
    std::cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;
        std::cin>>a>>b;
        D[a]++;
        D[b]++;
    }
    for(int i=1;i<=N;i++){
        if(D[i]%2){
            std::cout<<"NO"<<std::endl;
            return 0;
        }
    }
    std::cout<<"YES"<<std::endl;
    return 0;

}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    string N;
    cin >> N;

    int ans = 0;
    rep(i, N.length()) {
        ans = (ans + (N[i]-'0')) % 9;
    }

    cout << (ans ? "No" : "Yes") << endl;

    return 0;
}


Measured memory_bytes: 3776
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

#define MAX_V 201
#define INF 1000000000

typedef pair<int, int> P;
struct edge{int to, cap, cost, rev;};
int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V];
int preve[MAX_V];

void ae(int from, int to, int cap, int cost){
  G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
  G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}

int minCostFlow(int s, int t, int f){
  int res = 0;
  memset(h,0,sizeof(h));
  while(f > 0){
    priority_queue<P, vector<P>, greater<P> > que;
    for(int i = 0; i < V; i++){
      dist[i] = INF;
    }
    dist[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      int v = p.second;
      if(dist[v] < p.first)continue;
      for(int i = 0; i < (int)G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.push(P(dist[e.to], e.to));
        }
      }
    }
    if(dist[t] == INF){
      return -1;
    }
    for(int v = 0; v < V; v++){
      h[v] += dist[v];
    }
    int d = f;
    for(int v = t; v != s; v = prevv[v]){
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for(int v = t; v != s; v = prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int main(){
  int v,e,f;
  cin>>v>>e>>f;
  V=v;
  edge z;
  for(int i=0;i<e;i++){
    cin>>z.to>>z.cap>>z.cost>>z.rev;
    ae(z.to,z.cap,z.cost,z.rev);
  }
  cout << minCostFlow(0,v-1,f) << endl;
  return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>

int main(){
	int m=100000;
	int weeks, w;

	scanf("%d", &weeks);

	for( w=0; w<weeks ; w++ ){
		m = m + m*0.05;
		m = (int)((m + 999)/1000.0)*1000;
	}

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

	return 0;
}
	

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

int main() {
  int x;
  cin >> x;
  int ans = 0;
  int y = 0;
  while (true) {
    if (y != 0 && y % 360 == 0) {
      cout << ans << endl;
      return 0;
    }
    y += x;
    ++ans;
  }
}


Measured memory_bytes: 3596
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	string ans = "No";
	if((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d){
		ans = "Yes";
	}
	
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
  int sum=0;
  	cin>>a>>b;
  	for(int i=0;i<3;i++){
    if(a.at(i)==b.at(i)){
    sum++;
    }
    }
  	cout<<sum<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    import re

    A, B = list(map(str, input().split()))
    S = str(input())

    text = r'\d{' + A + '}\-\d{' + B + '}'
    result = re.match(text, S)

    if result:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3188
n,m=map(int,input().split())
ps=[list(input().split()) for i in range(m)]

wa=[0]*n
ac=[0]*n

for i in range(m):
    if ps[i][1]=='WA' and ac[int(ps[i][0])-1]==0:
        wa[int(ps[i][0])-1]+=1
    else:
        if ac[int(ps[i][0])-1]==0:
            ac[int(ps[i][0])-1]+=1
        else:
            pass

ac_num=0
wa_num=0

for i in range(n):
    if ac[i]==1:
        ac_num+=1
        wa_num+=int(wa[i])

print(ac_num,wa_num)

Measured memory_bytes: 27480
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;

    int c_min = 1001;
    for (int i = 0; i < N; i++) {
        int c, t;
        cin >> c >> t;
        if (t <= T && c < c_min) {
            c_min = c;
        }
    }

    if (c_min == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << c_min << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int n, k;
  cin >> n >> k;
  vector<int> v;
  int t;
  for (int i = 0; i < n; i++){
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = n - 1; n - k <= i; i--){
    t = v[i];
    ans += t;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import itertools
import math

def def1(l):
    
    res = []
    for i in range(len(l)):
        for j in range(i):
            res.append(abs(l[j] - l[i]) ** 2)
    return res

def main():
    input = sys.stdin.readline
    N, D = map(int, input().split())
    
    L = []
    L = [list(map(int, input().split())) for i in range(N)]
    
    L = list(zip(*L))
    
    l = [def1(v) for v in L]
    
    cnt = 0
    for v in list(zip(*l)):
        if float.is_integer(math.sqrt(sum(v))) : cnt = cnt + 1
            
    print (cnt)
        
if __name__ == '__main__':
    main()

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

int main(void) {
    int N;
    long long sum =0;
    
    cin >> N;
    
    long long a[N];
    
    for(int i=0; i<N; i++) {
        cin >> a[i];
        sum += a[i];
    }

    cout << *min_element(a, a+N) << " " << *max_element(a, a+N) << " " << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3152
/**
 *    author:  tourist
 *    created: 23.09.2017 16:27:00       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    bool flag = (x & (x - 1)) > 0;
    int v = 0;
    while (x > 1) {
      x /= 2;
      v++;
    }
    if (flag) {
      v++;
      // v - 1 and v
      if (a.empty() || a.back() <= v - 1) {
        a.push_back(v - 1);
        a.push_back(v);
      } else {
        a.push_back(v);
        a.push_back(v - 1);
      }
    } else {
      // only v
      a.push_back(v);
    }
  }
  int ans = 0;
  vector<int> s;
  for (int x : a) {
    if (!s.empty() && s.back() > x) {
      ans += s.back() - x;
      while (!s.empty() && s.back() > x) {
        s.pop_back();
      }
    }
    s.push_back(x);
  }
  if (!s.empty()) {
    ans += s.back();
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1908
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if(s[i]==s[i+1])
        {
            cnt++;
        }
    }
    int ans = min(cnt + 2 * k, n - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import bisect

n = int(input())
X = list(map(int, input().split()))
l = int(input())
U = 17
dp = [[0]*n for _ in range(U+1)]
for i, x in enumerate(X):
  t = bisect.bisect_left(X, x+l)
  dp[0][i] = bisect.bisect_right(X, x+l) - 1
for k in range(U):
  for i in range(n):
    dp[k+1][i] = dp[k][dp[k][i]]
def test(x, a, b):
  for i in range(U, -1, -1):
    if x >> i & 1:
      a = dp[i][a]
  return a >= b
def solve(a, b):
  if a > b:
    a, b = b, a
  ng = 0
  ok = n-1
  while ok - ng > 1:
    mid = (ng + ok) // 2
    if test(mid, a, b):
      ok = mid
    else:
      ng = mid
  print(ok)
q = int(input())
for _ in range(q):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  solve(a, b)

Measured memory_bytes: 90144
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;
const int mod = 1e9+7;

long long fast_pw(long long x, long long y) {
	long long ret = 1;

	for(;y;y>>=1) {
		if(y & 1) ret = (ret * x) % mod;
		x = (x * x) % mod;
	}
	return ret;
}

long long dp[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;

	for(int i = k; i >= 1; i--) {
		dp[i] = fast_pw(k / i, n);
		for(int j = i + i; j <= k; j += i) {
			dp[i] = (dp[i] - dp[j] + mod) % mod;
		}
	}

	long long ans = 0;

	for(int i = 1; i <= k; i++) {
		ans += i * dp[i];
		ans %= mod;
	}

	cout << ans;
		

	return 0;
}


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

// input
ll N, X, M;

vector<ll> w;


void input() {
    cin >> N >> X >> M;
}


int main() {
    input();
    map<int, int> m;
    w = vector<ll>(2 * M + 2);
    w[0] = 0;
    m[0] = 0;
    w[1] = X;
    m[X] = 1;
    int n = 1;
    ll v = X;
    rep(i, 2 * M + 1) {
        v = v * v % M;
        if (m.count(v)) break;
        m[v] = n + 1;
        w[n + 1] = w[n] + v;
        n++;
        if (n == N) {
            cout << w[n] << endl;
            return 0;
        }
    }
    ll ans = w[n];
    ll dn = N - n;
    int i = m[v];
    if (i == 0) {
        cout << ans << endl;
        return 0;
    }
    vector<ll> l;
    for (int j = i; j <= n; j++) {
        l.push_back(w[j] - w[i - 1]);
    }
    int ln = l.size();
    ans += l.back() * (dn / ln);
    if (dn % ln != 0) ans += l[dn % ln - 1];
    cout << ans << endl;
}


Measured memory_bytes: 7716
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)

int main(void){
	int m,l,r,p[222],ans,mx,i;
	cin >> m >> l >> r;
	while(m || l || r){
		mx = 0;
		for(i=0; i<m; ++i){
			cin >> p[i];
		}
		for(i=l; i<=r; ++i){
			if(mx <= p[i-1] - p[i]){
				mx = p[i-1] - p[i];
				ans = i;
			}
		}
		cout << ans << endl;
		cin >> m >> l >> r;
	}
}


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

using namespace std;
typedef long long int ll;
ll N1097 = 1000000007LL;

int main(){
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if(S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

c = []

for i in range(a):
	c.append(list(map(int,input().split())))

ans = float('inf')

for i in range(1<<a):
	sc = 0
	co = 0
	for j in range(a):
		if i & (1<<j):
			sc += c[j][0]*(j+1)*100 + c[j][1]
			co += c[j][0]
	if sc >= b:
		ans = min(ans,co)
	else:
		for j in range(a)[::-1]:
			if i &(1<<j):
				continue
			else:
				for k in range(c[j][0]):
					sc += 100*(j+1)
					co += 1
					if sc >= b:
						break
				if sc >= b:
					break
		ans = min(ans,co)

print(ans)


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  vector<P> v(n);
  map<P,int> seen;
  rep(i,n)cin >> v[i].first >> v[i].second,seen[v[i]] = 1;
  map<P,int> mp;
  rep(i,n){
    for(ll j = i+1;j < n;j++){
      mp[make_pair(v[i].first-v[j].first,v[i].second-v[j].second)]++;
      mp[make_pair(v[j].first-v[i].first,v[j].second-v[i].second)]++;
    }
  }
  pair<ll,ll> k;int cnt = 0;
  for(auto au : mp)if(au.second > cnt)k = au.first,cnt = au.second;
  ll res = 0;
  rep(i,n){
    P ov = v[i];
    if(seen[ov] != 1)continue;
    seen[ov] = 2;
    res++;
    for(ll j = 1;;j++){
      pair<ll,ll> nv = make_pair(ov.first+k.first*j,ov.second+k.second*j);
      if(seen[nv] == 1)seen[nv] = 2;
      else break;
    }
    for(ll j = 1;;j++){
      pair<ll,ll> nv = make_pair(ov.first-k.first*j,ov.second-k.second*j);
      if(seen[nv] == 1)seen[nv] = 2;
      else break;
    }
  }
  cout << res << endl;



  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#define rep(i, n) for (i = 0; i < n; i++)
#define int long long
using namespace std;

const int M = 1 << 20;
int mod = 1000000007;
int n;
int a[500000];
int ra[500001];
int cnt0[500002];
int dp[2][M];
int lastPos[M];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) ra[i + 1] = ra[i] ^ a[i];
	rep(i, n + 1) cnt0[i + 1] = cnt0[i] + (ra[i] == 0);
	
	rep(i, M) dp[1][i] = 1;
	rep(i, n + 1) {
		if (ra[i] != 0) {
			(dp[1][ra[i]] += (cnt0[i] - cnt0[lastPos[ra[i]]]) * dp[0][ra[i]]) %= mod;
			(dp[0][ra[i]] += dp[1][ra[i]]) %= mod;
			lastPos[ra[i]] = i;
		}
	}
	
	if (ra[n] != 0) { cout << dp[1][ra[n]] << endl; return 0; }
	
	int ans = 1;
	rep(i, cnt0[n + 1] - 2) (ans *= 2) %= mod;
	rep(i, M) if (i > 0) (ans += dp[0][i]) %= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 36608
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,res=0;
    cin>>n>>m;
    vector<vector<ll>> v(n);
    ll p[m];
    for(ll i=0;i<m;i++){
        ll len;
        cin>>len;
        for(ll j=0;j<len;j++){
            ll x;
            cin>>x;
            v[x-1].push_back(i);
        }
    }
    for(ll i=0;i<m;i++)
    cin>>p[i];
    for(ll i=0;i<pow(2,n);i++){
        ll k=i,cnt=0;
        vector<ll> st(m);
        while(k>0){
            if(k&1){
                for(ll j=0;j<v[cnt].size();j++)
                st[v[cnt][j]]++;
            }
            k>>=1;
            cnt++;
        }
        ll f=0;
        for(ll j=0;j<m;j++)
        if(st[j]%2!=p[j])
        f=1;
        if(!f)
        res++;
    }
    cout<<res;
}


Measured memory_bytes: 256
//Code by ASIM FOIZE AIMON
//CSE'19;CUET
//avoid copy paste//Hit the frined button
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define endl "\n"
#define int int64_t
#define ll long long
#define yes printf("YES\n")
#define no printf("NO\n")

int32_t main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/input.txt", "r", stdin);
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/output.txt", "w", stdout);
    #endif*/
    int a,b,c,d,e,s,f,m,n,p,t,i,j,k;
    vector<int>v;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#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
const ll INF = 1LL << 60;
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()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S;
    cin >>S;
    ll ans = 700;
    rep(i,3){
        if(S[i]=='o'){
            ans+=100;
        }
    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3568
'use strict';

(function() {
    var fs = require('fs');
    var contents = fs.readFileSync('/dev/stdin', 'utf-8');

    var ab = function(contents) {
        var line = contents.trim().split(" ");
        var a = parseInt(line[0]);
        var b = parseInt(line[1]);

        var d = Math.floor(a / b);
        var r = a % b;
        var f = a / b;
        console.log(d + " " + r + " " + f.toFixed(15));
    }

    ab(contents);
}());

Measured memory_bytes: 15636
n, m = map(int, input().split())
ab = [list(map(int, input().split()))for i in range(m)]
ans = [0] * n
edge = [[]for _ in range(n)]
for a, b in ab:
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
visited = {0}
stack = [0]
for i in stack:
    for j in edge[i]:
        if j in visited:
            continue
        stack.append(j)
        visited.add(j)
        ans[j] = i + 1
print("Yes")
print(*ans[1:])


Measured memory_bytes: 78892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"



  int a,b,c,sum;
  int main(){
	ios::sync_with_stdio(true);
	cin.tie(0);
	cin >> a >> c;
	for(int i = 0; i<a; i++){
		cin >> b;
		if(b >= c){
			sum++;
		}
	}
	
	cout << sum;
	
	
	}

	
	


	



Measured memory_bytes: 3620
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    h,w = map(int, input().split())
    d = []
    for _ in range(h):
        d.append(list(map(int, input().split())))
    
    res = []
    for i in range(h):
        for j in range(w):
            if j == w-1 and i < h-1:
                if d[i][j]%2 == 1:
                    res.append([i+1, j+1, i+2, j+1])
                    d[i+1][j] += 1
                continue
            if d[i][j]%2 == 1 and j < w-1:
                res.append([i+1, j+1, i+1, j+2])
                d[i][j+1] += 1
    print(len(res))
    for i in res:
        print(*i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 30644
#include "bits/stdc++.h"
using namespace std;
#define lint long long
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
#define P pair<int, int>
#define D pair<double, double>
#define DI pair<double, int>
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

lint gcd(lint a, lint b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

set<int>st;
int n, a;
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a;
		st.insert(a);
	}
	cout << st.size() << endl;
}


Measured memory_bytes: 7744
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000
#define MAXN 100010

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}

void GI_fast(int& x) {
#if defined(_WIN32) || defined(_WIN64)
  char t = _getchar_nolock();
  while (t < '0' || '9' < t) {
    t = _getchar_nolock();
  }
  x = t - '0';
  t = _getchar_nolock();
  while ('0' <= t && t <= '9') {
    x *= 10; x += t - '0';
    t = _getchar_nolock();
  }
#else
  char t = getchar_unlocked();
  while (t < '0' || '9' < t) {
    t = getchar_unlocked();
  }
  x = t - '0';
  t = getchar_unlocked();
  while ('0' <= t && t <= '9') {
    x *= 10; x += t - '0';
    t = getchar_unlocked();
  }
#endif
}

void GS_fast(char* x) {
#if defined(_WIN32) || defined(_WIN64)
  char t = _getchar_nolock();
  while (t == ' ') {
    t = _getchar_nolock();
  }
  while (t != ' ') {
    *x = t;
    x++;
    t = _getchar_nolock();
  }
#else
  char t = getchar_unlocked();
  while (t == ' ') {
    t = getchar_unlocked();
  }
  while (t != ' ') {
    *x = t;
    x++;
    t = getchar_unlocked();
  }
#endif
}

void print_buf_fast(char* buf, int len) {
  FORN(i, len) {
#if defined(_WIN32) || defined(_WIN64)
    _putchar_nolock(buf[i]);
#else
    putchar_unlocked(buf[i]);
#endif
  }
}

void print_int_fast(int d) {
  int sz = 1;
  for (; sz <= d && sz < 1e9; sz*=10);
  sz /= 10;
  for (; sz > 0; sz /= 10) {
    char c = '0' + d/sz;
    d %= sz;
#if defined(_WIN32) || defined(_WIN64)
    _putchar_nolock(c);
#else
    putchar_unlocked(c);
#endif
  }
#if defined(_WIN32) || defined(_WIN64)
  _putchar_nolock('\n');
#else
  putchar_unlocked('\n');
#endif
}

int calcAns(string n) {
  int sum = 0;
  for (auto d : n) {
    int digit = d - '0';
    sum += digit;
  }
  return sum;
}

int main() {
  srand(time(NULL));
  string n; cin >> n;
  int sum = calcAns(n);

  string m = n;
  for (int pos = n.size()-1; pos >= 0; pos--) {
    if (m[pos] == '0') continue;

    m[pos]--;
    for (int i = pos+1; i < n.size(); i++)
      m[i] = '9';

//    cout << m << endl;
    sum = max(sum, calcAns(m));
  }

  cout << sum << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    string s;cin>>s;
    if(s=="RRR")cout<<3<<endl;
    else if(s=="RRS" || s=="SRR")cout<<2<<endl;
    else if(s=="SSR" || s=="SRS"||s=="RSS")cout<<1<<endl;
    else if(s=="RSR")cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 3620
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String w = sc.next();
		sc.close();
		Map<String, Integer> map = new HashMap<String, Integer> ();
		for(int i = 0; i < w.length(); i++) {
			String tmp = w.substring(i, i + 1);
			if(map.containsKey(tmp)) {
				int count = map.get(tmp) + 1;
				map.put(tmp, Integer.valueOf(count));
			}else {
				map.put(tmp, 1);
			}
		}
		boolean check = true;
		for(String key : map.keySet()) {
			if(map.get(key) % 2 != 0) {
				check = false;
			}
		}
		System.out.println(check ? "Yes" : "No");

	}
}

Measured memory_bytes: 23252
// a template for main.cpp
#include <bits/stdc++.h>
#define ll long long
using namespace std;

#define f(x) (x)*(x)*(x)*(x)*(x)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X;
    cin >> X;
    int mx = 500;
    for (ll i = -mx; i <= mx; i++) {
        for (ll j = 0; j <= mx; j++) {
            ll now = f(j) - f(i);
            if (now == X) {
                cout << j << ' ' << i << endl;
                exit(0);
            }
        }
    }
}

Measured memory_bytes: 3624
def triangle(a,b,c):
    return cross(b - a, c - a) / 2
def cos(a, b):
    return dot(a, b) / (abs(a) * abs(b))
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def solve(xyi, xy):
    # anti_clockwise_sort:sort(key=cos((1,0)(0,0)(xyk-xyi)),reverse=True)
    xy = sorted(xy, key=lambda a:(a.real - xyi.real) / abs(a - xyi), reverse=True)

    area = [[[(float('inf'),) for i in range(len(xy))] for j in range(len(xy))] for k in range(max(q) + 1)]
    # triangle
    for j in range(len(xy) - 1):
        for k in range(j + 1, len(xy)):
            area[3][j][k] = triangle(xyi, xy[j], xy[k]), (xyi, xy[j], xy[k])

    # square,pentagon,,,, 
    for i in range(4, max(q) + 1):
        for j in range(len(xy)):
            for k in range(j + 1, len(xy)):
                for s in range(k + 1, len(xy)):                                
                    if math.isinf(area[i - 1][j][k][0]):
                        continue                
                    if triangle(xy[j], xy[k], xy[s]) <= 0:
                        continue #skip not convex polygon
                    tmp = area[3][k][s][0] + area[i - 1][j][k][0]
                    if not math.isnan(area[i][k][s][0]) and area[i][k][s][0] < tmp:
                        continue
                    area[i][k][s] = tmp, area[i - 1][j][k][1] + (xy[s],)
                
    min_space = [(float('inf'),)] * (max(q) + 1)
    for i in range(3, max(q) + 1):
        min_space[i] = min([y for x in area[i] for y in x], key=operator.itemgetter(0))
    
    return min_space

import sys
import operator
import math

f = sys.stdin

xy =[[int(i) for i in f.readline().split()] for _ in range(int(f.readline()))]
q = [int(f.readline()) for _ in range(int(f.readline()))]

xy = [x + y * 1j for x, y in xy]
id = {xyi:i+1 for i, xyi in enumerate(xy)}

xy.sort(key=operator.attrgetter('imag', 'real'))

min_space = [(float('inf'),) for i in range(max(q) + 1)]
while 2 < len(xy):
    xyi = xy.pop(0)
    min_space = [min(i, j, key=operator.itemgetter(0)) for i,j in zip(min_space,solve(xyi, xy))]

for qi in q:
    if math.isinf(min_space[qi][0]):
        print('NA')
    else:
        print(*[id[i] for i in min_space[qi][1]])

Measured memory_bytes: 10584
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<tuple>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	vector<tuple<string, int, int>> v;

	int N;

	cin >> N;

	REP(i, N) {
		string a;
		int b;

		cin >> a >> b;

		v.emplace_back(a, 100-b, i + 1);
	}

	sort(ALL(v));

	REP(i, N) {
		cout << get<2>(v[i]) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
struct edge { int to, cost; };

typedef pair<int,int> P;

const int VMAX = 100100, INF = 1e7;
int V;
vector<edge> G[VMAX];
int d[VMAX];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V + 1, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
/*  REP(i, V + 1) {
    cout << d[i] << " ";
  }
  cout << endl;*/
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  cin >> V;
  for (int x = 1; x <= V; x++) {
    int p; cin >> p;
    if (p != 0) {
      G[x].push_back((edge){x + p, 0});
    } else {
      for (int dx = 1; dx <= 6; dx++) {
        G[x].push_back((edge){x + dx, 1});
      }
    }
  }
  dijkstra(1);
/*  REP(i, V + 1) {
    cout << d[i] << " ";
  }
  cout << endl;*/
  cout << d[V] << endl;
}

Measured memory_bytes: 8660