akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int ke[100] = { 0 };
int main() {
	int n;
	int ans = 0;
	string s, s1, s2, s3, s4;
	cin >> n;
	if (n < 10) {
		cout << n << endl;
		return 0;
	}
	string n1 = to_string(n), n2;
	for (int i = n; i > 0; i--) {
		s = to_string(i);
		s1 = s[0];
		s1 += s[s.size() - 1];
		s2 = s[s.size() - 1];
		s2 += s[0];
		if (n1.size() > s.size() || n >= atoi(s.c_str())) {
			if (s1[s1.size() - 1] != '0') {
				ke[atoi(s1.c_str())]++;
			}
		}
	}
	for (int j = 0; j < 100; j++) {
		s3 = to_string(j);
		if (s3[0] != s3[s3.size() - 1]) {
			s4 = s3;
			reverse(s4.begin(), s4.end());
			ans += ke[j] * ke[atoi(s4.c_str())];
		}
		else {
			ans += ke[j] * ke[j];
		}
	}
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    vector<double> E(n);
    rep(i,n) cin>>p[i];
    rep(i,n) E[i] = (p[i]*(p[i]+1)*0.5)/p[i];
    double sum=0;
    double ans=0;
    rep(i,k)sum+=E[i];
    ans=sum;
    for(int i = k; i < n; i++){
        sum = sum-E[i-k]+E[i];
        ans = max(ans,sum);
    }
    cout<<fixed<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <sstream>
using namespace std;
#define rep(i,n) for (int i=0; i<n; i++)
typedef long long ll;


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

    int n = s.length();

    rep(i,n){
        if (i%2 == 0){
            if (s[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if (s[i]=='R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a) cout<<k<<"\n";
  else if(k<=a+b) cout<<a<<"\n";
  else cout<<a-(k-a-b)<<"\n";
return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <functional>
 
using namespace std;

int main() {
    unsigned long long n;
    cin>>n;
    unsigned long long sum = 0;
    for (unsigned long long i = 1;i<=n;++i){
        if (i%3!=0&&i%5!=0){
            sum += i;
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3636
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  n,i:Integer;
  s,e:string;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(s);

    n:=1;
    for i := 1 to Length(s) do begin
      if s[i]='B' then begin
        if not(e='') then begin
          Delete(e, n-1, 1);
          n:=n-1;
        end;
      end else begin
        e:=e+s[i];
        inc(n);
      end;
    end;

    Writeln(e);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if ((a[0] % 2 == 0) || (a[1] % 2== 0) || (a[2] % 2== 0))
		cout << 0 << endl;
	else
		cout << a[0] * a[1] ;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int in(int y,int x,int n){
  return 0<=y&&y<n&&0<=x&&x<n;
}
signed main(){
  int n;
  while(cin>>n,n){
    string s[n];
    for(int i=0;i<n;i++) cin>>s[i];
    int st=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(s[i][j]=='@') st+=(i*n+j)<<(n*n);
	else if(s[i][j]=='#') st+=1<<(i*n+j);
    
    int ans=-1,mask=(1<<(n*n))-1;
    //cout<<mask<<endl;
    int ax[]={1,1,1,0,0,-1,-1,-1};
    int ay[]={-1,0,1,-1,1,-1,0,1};
    queue<P> q;
    
    q.push(P(st,0));
    set<int> si;
    while(!q.empty()){
      P p=q.front();q.pop();
      int b=p.first,d=p.second;
      if(si.count(b)) continue;
      si.insert(b);
      int c=b&mask;
      int z=b>>(n*n);
      int y=z/n,x=z%n;
      if(c==0){
	ans=d;
	break;
      }
      for(int k=0;k<8;k++){
	int ny=y+ay[k],nx=x+ax[k],nb=0;
	if(!in(ny,nx,n)) continue;
	if((c>>(ny*n+nx))&1) continue;
	for(int i=0;i<n;i++){
	  for(int j=0;j<n;j++){
	    if(ny==i&&nx==j) continue;
	    int v=0;
	    for(int a=0;a<8;a++){
	      if(!in(i+ay[a],j+ax[a],n)) continue;
	      if((c>>((i+ay[a])*n+(j+ax[a])))&1) v++;
	      else if(ny==i+ay[a]&&nx==j+ax[a]) v++;
	    }
	    if((c>>(i*n+j))&1){
	      if(v==2||v==3) nb+=1<<(i*n+j);
	    }else{
	      if(v==3) nb+=1<<(i*n+j);
	    }
	  }
	}
	nb+=(ny*n+nx)<<(n*n);
	q.push(P(nb,d+1));
      }
    }
    
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3616
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = map(int, readline().split())
    ans = [0] * (2 * n - 1)

    if x == 1 or x == (2 * n - 1):
        print("No")
        return

    for i in range(1, n + 1):
        if i % 2 == 1:
            ans[i - 1] = (x - 1 + abs(n - i)) % (2 * n - 1) + 1
        else:
            ans[i - 1] = (x - 1 - abs(n - i)) % (2 * n - 1) + 1
    ans[n] = x

    for i in range(n + 1, 2 * n):
        if i % 2 == 0:
            ans[i - 1] = (x - 1 + abs(n - i)) % (2 * n - 1) + 1
        else:
            ans[i - 1] = (x - 1 - abs(n - i)) % (2 * n - 1) + 1
    
    print("Yes")
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, x, t;
	cin >> n >> x >> t;
	cout << (n / x) * t + min(1, n % x) * t;
	return 0;
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    ll n;
    cin>>n;
    ll cur=1000;
    while(cur<n){
        cur+=1000;
    }
    cout<<cur-n<<"\n";
}

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
if s == 'hi' or s == 'hihi' or s == 'hihihi' or s == 'hihihihi' or s == 'hihihihihi':
    print('Yes')
else:
    print('No')


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

using namespace std;

void solve()
{
	string s, t1, t2;
	cin >> s;
	int l = s.size(), xcnt = 0;
	for (int i = 0; i < l; i++)
	{
		if (s[i]=='x')
		{
			xcnt++;
			continue;
		}
		t1.push_back(s[i]);
	}
	t2 = t1;
	reverse(t2.begin(), t2.end());
	if (t1 != t2)
	{
		cout << -1 << endl;
		return;
	}
	int ans = xcnt, j = 0;
	t1 = t2 = s;
	reverse(t2.begin(), t2.end());
	for (int i = 0; i < l && j < l && i+j < l; i++, j++)
	{
		if (t1[i] == 'x' && t2[j] == 'x')
		{
			ans -= 2 - (i+j == l-1);
		}
		else
		{
			while (t1[i] == 'x')
			{
				i++;
			}
			while (t2[j] == 'x')
			{
				j++;
			}
		}
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag){
    if (flag) cout << "Yes" << endl; else  cout << "No" << endl;
}

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

int nanko(string s,Int n,Int i){
    Int length = min(n - i - 1,i);
    Int ans = 0;
    for (int k = i-length;k < i;k++){
        if (s.at(k) == 'R' && s.at(i +  (i - k) == 'B')) ans++;
    }
    return ans;
}


int main() {
    Int a, b , k;
    cin >> k >> a >> b;
    for (int i = a ; i <= b; i++){
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3628
import sys
N, Y = map(int, input().split())
for i in range(0, min(N, Y//10000) + 1):
    for j in range(0, min(N-i, Y//5000) + 1):
        for k in range(N-i-j, min(N-i-j, Y//1000) + 1):
            if i*10000 + j*5000 + k*1000 == Y and i+j+k == N:
                print(i, j, k)
                sys.exit()
print(-1, -1, -1)


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

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

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

int main() {
  int n;
  cin >> n;
  vector<ll> t(n);
  rep(i, n) cin >> t[i];
  ll ans = t[0];
  for (int i = 1; i < n; ++i) ans = lcm(ans, t[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
#define ll lobg long;
#define f(i,n) for(int i=0;i<n;i++)
long long mod = 1000000007;
int main() {
	        int n,m;
	        cin>>n>>m;
	        char matrix[n][m];
	        f(i,n){
	            f(j,m){
	                cin>>matrix[i][j];
	            }
	        }
	        long long dp[n+1][m+1];
	        f(i,n+1)
                f(j,m+1)
	        dp[i][j]= 0;
	       
	        dp[1][1]=1;
	        for(int i =1;i<=n;i++){
	            for(int j=1;j<=m;j++){
	                
	                if(matrix[i-1][j-1]=='#')dp[i][j]=0;
	                else
	                dp[i][j] =(dp[i-1][j]+dp[i][j-1]+dp[i][j])%mod;
	            }
	        }
	        cout << dp[n][m] << endl;
	return 0;
}


Measured memory_bytes: 9088
import math

dog_count, monkey_count = map(int, input().rstrip().split())

pattern_count = 0

if dog_count == monkey_count:
    pattern_count = math.factorial(dog_count) * math.factorial(monkey_count) * 2
elif math.fabs(dog_count - monkey_count) == 1:
    pattern_count = math.factorial(dog_count) * math.factorial(monkey_count) 

if pattern_count >= 10**9 + 7:
    pattern_count = pattern_count % (10**9 + 7)

print(pattern_count)
    

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

long long getGcd(long long a, long long b){
    if(a < b){
        long long tmp = a;
        a = b;
        b = tmp;
    }
    
    if(b == 0)return a;
    
    return getGcd(b, a%b);
}

long long getLcm(long long a, long long b){
    long long gcd = getGcd(a, b);
    
    return a/gcd*b;
}

int main(){
    int N;
    cin >> N;
    
    long long T[N];
    for(int i=0; i < N; i++){
        cin >> T[i];
    }
    
    long long lcm=1;
    for(int i=0; i<N; i++){
        lcm = getLcm(T[i], lcm);
    }
    
    cout << lcm << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 170, task a, 2020/06/14
//ms,
/*
*/

int main(void){
  int x;
  int counter=1;

  for(counter=1;counter<=5;counter++){
    cin >>x;
    if(x==0) break;
  }

  cout <<counter <<endl;
  return 0;
}
/*
*/


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    int n; cin >> n;
    int k; cin >> k;
    vector<int> sweet(k);
    vector<vector<int>> holder(k);
    int a;
    rep(i, k){
        cin >> sweet.at(i);
        rep(j, sweet.at(i)){
            cin >> a;
            holder.at(i).push_back(a);
        }
    }

    int ans = 0;
    bool have = false;
    for(int person = 1; person<=n; person++){
        have = false;
        rep(j, k){
            rep(search, sweet.at(j)){
                if(holder.at(j).at(search) == person){
                    have = true;
                }
            }
        }
        if(!have) ans++;  
    }

    cout << ans << endl;

    return 0;
}

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

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  rep(i, 0, H) cin >> A[i];
  using tp = tuple<int, int, int>;
  queue<tp> Q;
  rep(i, 0, H) rep(j, 0, W) {
    if (A[i][j] == '#') Q.push(tp(i, j, 0));
  }
  int ans = 0;
  while (!Q.empty()) {
    tp cur = Q.front();
    Q.pop();
    int d = get<2>(cur);
    rep(i, 0, 4) {
      int ny = get<0>(cur) + dy[i];
      int nx = get<1>(cur) + dx[i];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W)
        continue;
      if (A[ny][nx] != '#') {
        A[ny][nx] = '#';
        Q.push(tp(ny, nx, d + 1));
        ans = max(ans, d + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13456
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; typedef long double ld ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define ALL(name) (name).begin(),(name).end()
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){ios::sync_with_stdio(0);cin.tie(nullptr); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  string s;
  cin>>s;
  int ans=MOD;
  REP(i,s.size()-2){
    if(abs(stoi(s.substr(i,3))-753) < ans){
      ans=abs(stoi(s.substr(i,3))-753);
    }
  }
  cout<<ans<<endl;
}


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

namespace AtTest.DP
{
    class CodeFestival2017Final_D
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[][] hps = new int[n][];
            for(int i = 0; i < n; i++)
            {
                hps[i] = ReadInts();
            }
            hps = hps.OrderBy(a => a[0]+a[1]).ToArray();
            int[] dp = new int[n + 1];
            for (int i = 0; i <= n; i++) dp[i] = int.MaxValue;
            dp[0] = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = n - 1; j >= 0; j--)
                {
                    if (dp[j] == int.MaxValue) continue;

                    if (dp[j] <= hps[i][0])
                    {
                        dp[j + 1] = Min(dp[j + 1], dp[j] + hps[i][1]);
                    }
                }
            }
            for(int i = n; i >= 0; i--)
            {
                if (dp[i] == int.MaxValue) continue;

                WriteLine(i);
                return;
            }
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
 int a[100],x[100],y[100],W,H,N,i,j,k;
 bool sht[100][100];
 cin>>W>>H>>N;
 for(i=0;i<N;i++){
 	cin>>x[i]>>y[i]>>a[i];
 }
 
 for(i=0;i<W;i++){
 	for(j=0;j<H;j++){
		sht[i][j]=1;
	}
 }
 
 for(i=0;i<N;i++){
 	if(a[i]==1){
		for(j=0;j<x[i];j++){
			for(k=0;k<H;k++){
				sht[j][k]=0;
			}
		}
	}else if(a[i]==2){
		for(j=x[i];j<W;j++){
			for(k=0;k<H;k++){
				sht[j][k]=0;
			}
		}
 	}else if(a[i]==3){
		for(j=0;j<y[i];j++){
			for(k=0;k<W;k++){
				sht[k][j]=0;
			}
		}
	}else if(a[i]==4){
		for(j=y[i];j<H;j++){
			for(k=0;k<W;k++){
				sht[k][j]=0;
			}
		}
	}
 }
 k=0;
 for(i=0;i<W;i++){
 	for(j=0;j<H;j++){
		k=k+sht[i][j];
	}
 }
 cout<<k<<endl;
}

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

int main() {
    int64 N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<int64> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    rep(i, N) A[i] += M;
    auto isOK = [&](int x) -> bool {
        if(x >= N - P) return true;
        // A[x] 以下の問題に M 人が投票
        int64 v = V - x - 1; // 残り v 問
        int64 r = M * (N - x - 1 - v);
        for(int i = x + 1; i < N - P + 1; ++i) {
            int64 d = A[i] - A[x];
            if(d > M) return false;
            if(r - d < 0) return false;
            r -= d;
        }
        return true;
    };
    int64 l = -1, r = N - 1;
    while(r - l > 1) {
        int mid = (l + r) / 2;
        if(isOK(mid)) r = mid;
        else l = mid;
    }
    cout << N - r << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int  a,b,f=0;
  cin>>a>>b;
  double e,d,g,h;
  int c[a][b];
  rep(i,a){
    rep(j,b)cin>>c[i][j];
  }
  rep(i,a-1){
    for(int j=i+1;j<a;j++){
      rep(o,b){
        d=c[i][o]-c[j][o];
        e+=d*d;
      }
      g=sqrt(e);
      h=modf(g,&e);
      if(h==0)f++;
      e=0;
    }
  }
  cout<<f;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                ans +=1


print(ans)

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

#define rep(i, n) for (int i = 0; i < n; i++)

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

    if (a == b && a != c) {
        cout << "Yes" << endl;
    } else if (a != b && a == c){
        cout << "Yes" << endl;
    } else if (b == c && a != c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
_ = gets.to_i
lr = []
rmax = 0
readlines.each do |line|
  l, r = line.split(" ").map(&:to_i)
  lr.push([l, r])
  rmax = [rmax, r].max
end

def is_prime(n)
  return false if n < 2
  return true if n == 2
  return false if n.even?

  3.step(Math.sqrt(n), 2) do |i|
    return false if n % i == 0
  end

  true
end

p = Array.new(rmax + 1, 0)
(0..(p.size + 1)).each do |i|
  p[i] = is_prime(i)
end

a = Array.new(rmax + 1, 0)
(0..a.size).each do |i|
  a[i + 1] = a[i]
  a[i + 1] += 1 if p[i + 1] && p[(i + 2) / 2]
end

lr.each do |_lr|
  l, r = _lr
  puts a[r] - a[l - 1]
end

Measured memory_bytes: 18668
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var x = int.Parse(_[0]);
            var y = int.Parse(_[1]);
            var z = int.Parse(_[2]);

            var t1 = x;
            x = y;
            y = t1;

            var t2 = x;
            x = z;
            z = t2;

            Console.WriteLine(string.Format("{0} {1} {2}", x, y, z));
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using P= pair<int,int>;
int main(){
  int x;
  cin >> x;
  if(x >= 30){
cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char m;
	cin>>m;
	if(m=='a'||m=='o'||m=='u'||m=='i'||m=='e')
	{
		cout<<"vowel"<<endl;
	}
	else
	{
		cout<<"consonant"<<endl;
    }
		return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int LIMIT = 45;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int limit;
int MDT[16][16];
struct Puzzle {
	int st[16];
	int space, MD;
} in, cur;
int getAllMD(Puzzle p) {
	int sum = 0;
	for (int i = 0; i < 16; i++) {
		if (p.st[i] == 16) continue;
		sum += MDT[i][p.st[i] - 1];
	}
	return sum;
}
bool dfs(int dep, int prev) {
	if (cur.MD == 0) return true;
	if (dep + cur.MD > limit) return false;
	int sx = cur.space / 4, sy = cur.space % 4;
	Puzzle tmp;
	for (int i = 0; i < 4; i++) {
		int tx = sx + dx[i], ty = sy + dy[i];
		if (tx < 0 || ty < 0 || tx >= 4 || ty >= 4) continue;
		if (abs(i - prev) == 2) continue;
		tmp = cur;
		cur.MD -= MDT[tx * 4 + ty][cur.st[tx * 4 + ty] - 1];
		cur.MD += MDT[sx * 4 + sy][cur.st[tx * 4 + ty] - 1];
		swap(cur.st[tx * 4 + ty], cur.st[sx * 4 + sy]);
		cur.space = tx * 4 + ty;
		if (dfs(dep + 1, i)) return true;
		cur = tmp;
	}
	return false;
}
int iterative_deepening() {
	in.MD = getAllMD(in);
	for (limit = in.MD; limit <= LIMIT; limit++) {
		cur = in;
		if (dfs(0, 10)) return limit;
	}
}
int main() {
	for (int i = 0; i < 16; i++) {
		for (int j = 0; j < 16; j++) {
			MDT[i][j] = abs(i / 4 - j / 4) + abs(i % 4 - j % 4);
		}
	}
    for (int i = 0; i < 16; i++) {
    	scanf("%d", &in.st[i]);
    	if (in.st[i] == 0) {
    		in.space = i;
    		in.st[i] = 16;
		}
	}
	printf("%d\n", iterative_deepening());
	return 0;
}


Measured memory_bytes: 2768
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<ll> w(n);
  for (int i = 0; i < n; i++){
    cin >> w[i];
  }


  ll m = 1e9;
  for (int t = 1; t < n; t++){
    ll l = 0, r = 0;

    for (int j = 0; j < n; j++){
      if (j <= t)
        l += w[j];
      else
        r += w[j];
    }

    m = min(m, abs(l - r));
  }


  cout << m << endl;



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,M; cin>>N>>M;
	int A[N][M];
	rep(i,0,N)rep(j,0,M){ cin>>A[i][j]; A[i][j]--; }
	int ans = N;
	int id[N] = {}; set<int> st;
	while(st.size() < M-1){
		int cnt[M] = {}; int res = 0; int k;
		rep(i,0,N) cnt[A[i][id[i]]]++;
		rep(i,0,M)if(res < cnt[i]){ res = cnt[i]; k = i; }
		ans = min(ans, res);
		st.insert(k);
		rep(i,0,N)if(A[i][id[i]] == k){
			while(st.count(A[i][id[i]])) id[i]++;
		}//print(id,,N);
	}cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

double pow2(double x) {
    return x * x;
}

int main() {
    int n; cin >> n;
    vector<pair<double, double>> p(n);
    for (int i = 0; i < n; ++i) {
        double x, y; cin>> x >> y;
        p[i] = make_pair(x, y);
    }
    sort(p.begin(), p.end());

    double sum = 0.0;
    double nn = 1;
    for (int i = 1; i <= n; ++i) {
        nn *= (double)i;
    }
    do {
        for (int i = 0; i < n - 1; ++i) {
            sum += sqrt(pow2(p[i].first - p[i + 1].first) + pow2(p[i].second - p[i + 1].second));
        }
    } while (next_permutation(p.begin(), p.end()));

    cout << fixed << setprecision(10) << sum / nn << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define MAX 200000
#define INF (ll)1e10
#define MOD 1000000007

void solve(void){
    int n, m;
    cin >> n >> m;
    int coins[m], counts[n+1];
    rep(m, i) cin >> coins[i];
    sort(coins, coins+m);
    rep(n+1, i) counts[i] = i;
    rep(n+1, i) {
        rep(m, j) {
            if (coins[j] > i) break;
            counts[i] = min(counts[i], counts[i-coins[j]]+1);
        }
    }
    cout << counts[n] << '\n';
}

int main(void){
  solve();
  return 0;
}



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vll a(n);
	REP(i, n) cin >> a[i];
	vll s(n + 1);
	REP(i, n) s[i + 1] = (s[i] + a[i]) % m;
	map<ll, ll> mp;
	REP(i, n + 1) mp[s[i]]++;
	ll res = 0;
	for(auto v : mp){
		ll p = v.second;
		res += p * (p - 1) / 2;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 5760
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#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(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main(void){
    string s;
    cin >> s;
    ll ans =0;
    ll tmplength=0;
    for (ll i = 0; i < s.size(); i++)
    {
        if( ! (s[i] == 'A' ||
            s[i] == 'C' ||
            s[i] == 'G' ||
            s[i] == 'T') ){
                CHMAX(ans, tmplength);
                tmplength = 0;
            }else{
                tmplength++;
            }
    }
    CHMAX(ans,tmplength);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
ll x;
ll dp[210000];
ll a[210000];
ll ps[210000];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> x;
	ps[0] = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		ps[i + 1] = ps[i] + a[i];
	}
	ll ans = 1e18;
	ll cur = 0;
	for (int i = 1; i <= n; ++i) {
		cur += 5 * a[n - i] + x;
		ll now = cur;
		int cc = 2;
		for (int j = n - 1 - i; j >= 0; j -= i, ++cc) {
			now += (ps[j + 1] - ps[max(0, j - i + 1)]) * (2 * cc + 1);
			if (now > ans)
				break;
		}
		ans = min(ans, now);
	}
	cout << ans + n * x << "\n";
	return 0;
}




Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main(){
	int n,a,b,c;
	cin>>n;
	c=n%10;
	n/=10;
	b=n%10;
	n/=10;
	a=n;
	if((b>a)||(b==a&&c>a))
		a++;
	cout<<a*100+a*10+a<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P);

P dequeue();
int min(int,int);


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
head=1;tail=n+1;
  for(i=0;;i++){
      if(head==tail)break;
  	u=dequeue();
  	c=min(q,u.t);
      u.t-=c;
      elaps+=c;
      if(u.t>0){
          enqueue(u);
      }else{
          printf("%s %d\n",u.name,elaps);
      }
  }
}
  
    void enqueue(P z){
        if(head==(tail+1)%LEN){
            printf("Overflow\n");
        }
        Q[tail]=z;
        if(tail+1==LEN){
            tail=0;
        }else{
            tail++;
        }
        
    }
    P dequeue(){
        P x;
        if(head==tail){
            printf("Underflow\n");
        }
        x=Q[head];
        if(head+1==LEN){
            head=0;
        }else{
            head++;
        }
        return x;
    }
    int min(int a,int b){
        if(a<b){
            return a;
        }else{
            return b;
        }
    }



Measured memory_bytes: 12752
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		string str;
		map<string, bool> pattern;
		cin >> str;

		for (int i = 1; i < str.size(); i++)
		{
			string front = str.substr(0, i);
			string back = str.substr(i, str.size() - i);

			pattern[front + back] = true;
			pattern[back + front] = true;

			reverse(front.begin(), front.end());
			pattern[front + back] = true;
			pattern[back + front] = true;

			reverse(back.begin(), back.end());
			pattern[front + back] = true;
			pattern[back + front] = true;

			reverse(front.begin(), front.end());
			pattern[front + back] = true;
			pattern[back + front] = true;
		}

		cout << pattern.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1300
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

struct Tree{
	vector<vector<int>>G;
	vector<int>doubling[20];
	vector<int>depth;
	void dfs(int x,int p){
		for(int i:G[x])if(i!=p){
			doubling[0][i]=x;
			depth[i]=depth[x]+1;
			dfs(i,x);
		}
	}
	int lca(int x,int y){
		if(depth[x]>depth[y])swap(x,y);
		rep(i,20){
			if((depth[y]-depth[x])>>i&1){
				y=doubling[i][y];
			}
		}
		if(x==y)return x;
		for(int i=19;i>=0;i--){
			if(doubling[i][x]!=doubling[i][y]){
				x=doubling[i][x];
				y=doubling[i][y];
			}
		}
		return doubling[0][x];
	}
	int dis(int x,int y){
		return depth[x]+depth[y]-depth[lca(x,y)]*2;
	}
	Tree(vector<vector<int>>&G):G(G){
		int N=G.size();
		rep(i,20)doubling[i].resize(N,-1);
		depth.resize(N);
		dfs(0,0);
		rep(i,19)rep(j,N){
			if(doubling[i][j]==-1)doubling[i+1][j]=-1;
			else doubling[i+1][j]=doubling[i][doubling[i][j]];
		}
	}
};

int N,Q;
vector<vector<int>>G;
int A[100005],B[100005],C[100005],D[100005];
int X[100005],Y[100005],U[100005],V[100005];
vector<int>req[100005];
int dist[100005];
map<int,P>cnt[100005];
struct Edge{
	int to,cost,color;
};
vector<vector<Edge>>G2;
P now[100005];
void dfs(int x,int p){
	for(int i:req[x])cnt[x][i]=now[i];
	for(Edge e:G2[x])if(e.to!=p){
		dist[e.to]=dist[x]+e.cost;
		now[e.color].first++;
		now[e.color].second+=e.cost;
		dfs(e.to,x);
		now[e.color].first--;
		now[e.color].second-=e.cost;
	}
}
signed main(){
	cin>>N>>Q;
	G.resize(N);
	G2.resize(N);
	rep(i,N-1){
		cin>>A[i]>>B[i]>>C[i]>>D[i];
		A[i]--;B[i]--;C[i]--;
		G[A[i]].pb(B[i]);G[B[i]].pb(A[i]);
		G2[A[i]].pb({B[i],D[i],C[i]});G2[B[i]].pb({A[i],D[i],C[i]});
	}
	Tree tree(G);
	rep(i,Q){
		cin>>X[i]>>Y[i]>>U[i]>>V[i];
		X[i]--;U[i]--;V[i]--;
		req[U[i]].pb(X[i]);req[V[i]].pb(X[i]);
		req[tree.lca(U[i],V[i])].pb(X[i]);
	}
	dfs(0,0);
	rep(i,Q){
		int lc=tree.lca(U[i],V[i]);
		int def=dist[U[i]]+dist[V[i]]-2*dist[lc];
		int sub=cnt[U[i]][X[i]].second+cnt[V[i]][X[i]].second-2*cnt[lc][X[i]].second;
		int plus=Y[i]*(cnt[U[i]][X[i]].first+cnt[V[i]][X[i]].first-2*cnt[lc][X[i]].first);
		cout<<def-sub+plus<<endl;
	}
}


Measured memory_bytes: 76716
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

ll n, a, b;
ll x[100000];

int main(){
  cin >> n >> a >> b;
  rep(i, n) cin >> x[i];
  ll res = 0;
  rep(i, n - 1) res += min(a * (x[i + 1] - x[i]), b);
  cout << res << endl;
}


Measured memory_bytes: 1152
'use strict'

function main(s) {
  s = s.split('\n');

  const city  = Number(s[0].split(' ')[0]);
  const roads = [];

  s.slice(1, -1).forEach((road) => {
    road = road.split(' ');
    roads.push(road[0]);
    roads.push(road[1]);
  });

  const ans = [...Array(city)].fill(0);
  for (const r of roads) {
    ans[Number(r) - 1] += 1;
  }

  console.log(ans.join('\n'));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
X, N = list(map(int,input().split()))
if N >0:
    P =  list(map(int,input().split()))
else:
    print(X)
    exit()
# 
# ans = 1000
# P.sort()
# ok = len(P)
# ng = 0
# 
# while (ok - ng)> 1:
#     mid = (ok + ng) //2
#     if P[mid] > X:
#         ok = mid
#     else:
#         ng = mid
# 
# threshold = P[ok]
ans = None
for n in range(100):
    plus = X +n
    if plus not in P:
        ans = plus
    minus = X -n
    if minus not in P:
        ans = minus
    if ans is not None:
        print(ans)
        exit()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

struct card {char suit;int num;};

void Acout(struct card A[],int N){
    rep(i,N){
        if(i)cout<<" ";
        cout<<A[i].suit<<A[i].num;
    }
    cout<<endl;
}

void bubblesort(struct card  A[],int N){
    int flag=1;
    int ns=0;
    int i=0;
    while(flag){
        flag=0;
        for(int j=N-1;j>=i+1;j--){
            if(A[j].num<A[j-1].num){
                swap(A[j],A[j-1]);flag=1;ns++;
            }
        }
        i++;
    }
}

void selectionsort(struct card A[],int N){
    int ns=0;
    rep(i,N-1){
        int min=i;
        for(int j=i;j<N-1;j++){
            for(int j=i;j<N;j++){
            if(A[min].num>A[j].num)min=j;
            }   
        swap(A[i],A[min]);
        if(i!=min)ns++;
        }
    }
}

int main(){
    int N;
    cin>>N;
    card a1[N],a2[N];

    rep(i,N)cin>>a1[i].suit>>a1[i].num;
    rep(i,N)a2[i]=a1[i];

    bubblesort(a1,N);
    selectionsort(a2,N);

    bool flag=true;
    rep(i,N)if(a1[i].suit!=a2[i].suit)flag=false;

    Acout(a1,N);
    cout<<"Stable"<<endl;
    Acout(a2,N);
    if(flag)cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1LL << 60;

int n;
vector<pair<int, int>> a[100100];
vector<pair<long long, int>> out[100100];

bool cmp(pair<int, int> u, pair<int, int> v)
{
  if (u.first != v.first)
    return u.first < v.first;
  return u.second > v.second;
}

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

  int m;
  cin >> n >> m;
  while (m--)
  {
    int l, r, c;
    cin >> l >> r >> c;
    a[l].push_back({c, r});
  }

  set<pair<long long, int>> s;
  for (int i = 1; i <= n; i++)
  {
    long long dist = oo;
    if (i == 1) dist = 0;
    else if (s.empty()) dist = oo;
    else dist = s.begin()->first;

    if (i == n)
    {
      cout << (dist == oo ? -1 : dist) << endl;
      return 0;
    }

    if (dist != oo)
    {
      sort(a[i].begin(), a[i].end(), cmp);
      int r = i;
      for (auto u : a[i])
        if (u.second > r)
        {
          s.insert({dist + u.first, i});
          out[u.second].push_back({dist + u.first, i});
          r = u.second;
        }
    }

    for (auto u : out[i])
      s.erase(u);
  }
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define ll long long

using namespace std;

// input
int n,m;
vector<vector<int> > rinsetu;
bool visited[200000];

void dfs(int now,int count){

    if(count == 3){
        return;
    }

    visited[now] = true;

    auto nexts = rinsetu[now];
    int next_size = nexts.size();

    for(int i = 0;i < next_size;i++){
        if(visited[nexts[i]]){
            continue;
        }

        dfs(nexts[i],count+1);
    }

}

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

    cin >> n >> m;

    for(int i = 0;i < n;i++){
        vector<int> row;
        rinsetu.push_back(row);
    }

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


    dfs(0,0);

    string ans = (visited[n-1])?"POSSIBLE":"IMPOSSIBLE";

    cout << ans << "\n";

    
}

Measured memory_bytes: 14188
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int sum = 0;
		for(int i = 0; i < s.length(); i++){
			sum += s.charAt(i)-'0';
		}
		System.out.println(sum);
	}
}

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

#define endl "\n"
#define ll long long
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define read(v) for(auto &it:v) cin>>it;
#define out(v) for(auto &it:v) cout<<it<<" ";
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<ll> vll;

#define deb(x) cout << ">" << #x << '=' << x << endl;
#define setbits(n) __builtin_popcountll(n)
#define done {cout<<"-1"<<endl; return;}

#define inf INT_MAX
#define ninf INT_MIN
//const ll N = 1e5 + 5;
#define MOD 1000000007
ll power(ll a, ll b)    //a is base, b is exponent
{
	if (b == 0)
		return 1;
	if (b == 1)
		return a;
	if (b % 2 == 1)
		return (power(a, b - 1) * a) % MOD;
	ll q = power(a, b / 2);
	return (q * q) % MOD;
}

void solve() {
	int n;
	cin >> n;
	ll ans = ((((((power(10, n) + 0LL) % MOD) - 2 * 1LL * power(9, n) ) % MOD + power(8, n)) % MOD) + MOD) % MOD;
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("inputc.txt", "r", stdin);
	freopen("outputc.txt", "w", stdout);
#endif
	int t = 1;
	//cin>>t;
	while (t--) solve();
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <string>

using namespace std;

string strS;
string strT;

int main()
{
	cin >> strS;
	cin >> strT;

	int nS = strS.length();
	int nT = strT.length();
	int ok = 0;

	int i = nS;
	while (i >= 0)
	{
		int j = i - 1;
		int iCount = 0;
		while (strS[j] == '?' && j >= 0)
		{
			--j;
			++iCount;

			if (iCount == nT)
			{
				ok = 1;
				++j;

				for (int k = 0; k < j; ++k)
					if (strS[k] == '?')
						strS[k] = 'a';

				for (int k = 0; k < nT; ++k)
					strS[j + k] = strT[k];

				for (int k = j + nT; k < nS; ++k)
					if (strS[k] == '?')
						strS[k] = 'a';

				break;
			}
		}

		if (ok == 1)
			break;
		i = j;
	}

	if (!ok)
	{
		for (int i = nS - nT; i >= 0; --i)
		{
			int iCount1 = 0;
			int iCount2 = 0;
			for (int j = 0; j < nT; ++j)
				if (strS[i + j] == strT[j])
					++iCount1;
				else
					if (strS[i + j] == '?')
						++iCount2;

			if (iCount1 + iCount2  == nT)
			{
				ok = 1;

				for (int k = 0; k < i; ++k)
					if (strS[k] == '?')
						strS[k] = 'a';

				for (int k = 0; k < nT; ++k)
					strS[i + k] = strT[k];

				for (int k = i + nT; k < nS; ++k)
					if (strS[k] == '?')
						strS[k] = 'a';

				break;
			}

			if (ok)
				break;
		}
	}

	if (ok)
		cout << strS << endl;
	else
		cout << "UNRESTORABLE" << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, m  = map(int, input().split())
h  = list(map(int, input().split()))
ab  = [tuple(map(int, input().split())) for i in range(m)]
#
# c = collections.Counter()

ans = 0
tenbo = [0] * n
for (a, b) in ab:
    #print(tenbo)
    if h[a-1] > h[b-1]:
        if tenbo[a-1] != -1:
            tenbo[a-1] = 1
        tenbo[b-1] = -1
    if h[a-1] < h[b-1]:
        if tenbo[b-1] != -1:
            tenbo[b-1] = 1
        tenbo[a-1] = -1
    if h[a-1] == h[b-1]:
        tenbo[a-1] = -1
        tenbo[b-1] = -1

for tenbo_ in tenbo:
    if tenbo_ == 1 or tenbo_ == 0:
        ans += 1

print(ans)


Measured memory_bytes: 27748