akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,k;
    cin >> n >> k;
    vector<pair<ll,ll>> x;
    for (ll i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        pairs s=make_pair(a,b);
        x.push_back(s);
    }
    sort(x.begin(),x.end());
    for (ll i=0;i<n;i++){
        k-=x[i].second;
        if (k<=0){
            cout << x[i].first << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 2420
/*ex3_3
    takafumi_ueki*/
#include <stdio.h>
int main(void){
    //N(:ある整数)がK進法で表したときM桁になる
    int N,K;
    int M = 0;
    //Nが0になるまで引き続け、その引いた回数が桁数になる
    scanf("%d %d",&N,&K);
    while(N != 0){
        N = N/K;
        M++;
    }
printf("%d\n",M);
    return 0;
}

Measured memory_bytes: 128
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifdef HOME
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef complex < double > com;

#define eb emplace_back
#define pb push_back
#define F first8
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test() {
    int h, w, n;
    cin >> h >> w >> n;
    cout << min((w + n - 1) / w, (h + n - 1) / h) << "\n";
}

int main() {
    fast_io();
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cout << fixed << setprecision(15);
    test();
    #ifdef HOME
        cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
    #endif
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        double[] a = new double[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

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

        System.out.println(a[n-1]);
    }
}

Measured memory_bytes: 25044
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <functional>
#include <iterator>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end());
#define PSort(x) sort(begin(x), end(x), pairCompare)
#define ll long long
#define INF 2000000000

using namespace std;

int main() {
	int n, m;
	cin >> n;
	vector<int> v(n);
	rep(i, 0, n)cin >> v[i];
	cin >> m;
	vector<int> vv(m);
	rep(i, 0, m)cin >> vv[i];

	Sort(v); Sort(vv);
	int pos = 0;
	rep(i, 0, m) {
		bool judge = true;
		rep(j, pos, n) {
			if (v[j] == vv[i]) {
				pos = j+1;
				judge = false;
				break;
			}
		}
		if (judge) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;
}



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

using namespace std;

typedef long long ll;
string A, B;
int n, m, d, i;

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> m;
    cin >> A >> B;

    d = __gcd(n, m);
    n /= d; m /= d;

    for(i=0; i<d; ++i)
        if(A[n*i] != B[m*i])
        {
            cout << -1 << '\n';
            return 0;
        }

    cout << (ll) n * m * d << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    map<string,int> mp;
    bool ok = 1;
    char las = 'A';
    REP(i,N){
        string S; cin >> S;
        if(i == 0) las = S[0];
        mp[S]++;
        if(mp[S] >= 2) ok = 0;
        if(S[0] != las){
            dump(S[0])
            dump(las)
            ok = 0;
        }
        dump(i)
        dump(ok)

        int len = S.length();
        las =  S[len-1];
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static long[][] dp;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		dp = new long[5][s.length() + 1];
		for (int i = 0; i < 5; i++) {
		    Arrays.fill(dp[i], -1L);
		}
		System.out.println(getCount(4, s));
	}
	
	static long getCount(int size, String s) {
	    if (dp[size][s.length()] != -1) {
	        return dp[size][s.length()];
	    }
	    if (size == 1) {
	        long ans = 0;
	        if (s.length() > 3 || s.length() <= 0) {
	        } else if (s.length() > 1 && s.charAt(0) == '0') {
	        } else {
    	        int x = Integer.parseInt(s);
    	        if (x > 255) {
    	            
    	        } else {
	                ans = 1;
    	        }
	        }
	        dp[size][s.length()] = ans;
	        return ans;
	    }
	    long ans = 0;
	    for (int i = 1; i <= 3 && i < s.length(); i++) {
	        if (i > 1 && s.charAt(0) == '0') {
	            break;
	        }
	        if (i == 3 && Integer.parseInt(s.substring(0, 3)) > 255) {
	            break;
	        }
	        ans += getCount(size - 1, s.substring(i, s.length()));
	    }
	    dp[size][s.length()] = ans;
	    return ans;
	}
}



Measured memory_bytes: 26184
n = int(input())
cards = [[False for i in range(13)]for j in range(4)]
pattern = ["S","H","C","D"]
for i in range(n):
    p,num = [x for x in input().split()]
    num = int(num)
    cards[pattern.index(p)][num-1] = True
for i in range(4):
    for j in range(13):
        if not cards[i][j]:
            print(pattern[i],j+1)



Measured memory_bytes: 5600
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 505;
const int mod = 1e9 + 7;
int h,w;
char mp[maxn][maxn];
int main() {
    cin>>h>>w;
    for (int i=0; i<h; i++) {
        cin>>mp[i];
    }
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (j == 0) putchar('.');
            else if (!(i & 1)) putchar('#');
            else if ((i & 1) && j == w-1) putchar('#');
            else if (mp[i][j] == '#') putchar('#');
            else putchar('.');
        }
        puts("");
    }
    puts("");
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (j == w-1) putchar('.');
            else if (i & 1) putchar('#');
            else if (!(i & 1) && j == 0) putchar('#');
            else if (mp[i][j] == '#') putchar('#');
            else putchar('.');
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[6];
    rep(i,4){
        cin >> A[i];
    }
    //sort(A,A+3);
    cout << max(A[0]*A[1],A[2]*A[3]) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

#define MOD 1000000007
#define INF INT_MAX
#define NINF INT_MIN
#define LLINF LLONG_MAX
using ll = long long;
using namespace std;


int main() {
    char a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "H" << endl;
    }
    else {
        cout << "D" << endl;
    }
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

int v[20][20], n;
ll dp[1<<16];
ll sum[1<<16];
bool mark[1<<16];

ll f(int i) {
    if(i == 0) return 0;
    if(mark[i]) return dp[i];
    mark[i] = true;

    ll ret = 0;
    for(int j = i; j ; j = (j - 1) & i) {
        ret = max(ret, f(i-j) + sum[j]);
    }

    return dp[i] = ret;
}

int main() {
	scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            scanf("%d", &v[i][j]);

    for(int i = 0; i < 1<<n; i++) {
        for(int j = 0; j < n; j++) {
            if(!(i&(1<<j))) continue;
            for(int k = j+1; k < n; k++) {
                if(i&(1<<k)) sum[i] += v[j][k];
            }
        }
        
    }

    printf("%lld\n", f((1<<n)-1));
	
    return 0;
}

Measured memory_bytes: 1280
class Node:
	def __init__(self, v):
		self.v = v
		self.l = self.r = None
		self.p = -1
	def __str__(self):
		return str(self.v)

def find_pos(a, v):
	for i in range(len(a)):
		if a[i] == v:
			return i
	return -1

def add_node(root, cur, ino):
	idx = find_pos(ino, cur.v)
	st = []
	st.append(root)
	while len(st) != 0:
		node = st.pop()
		if node.p == -1:
			node.p = find_pos(ino, node.v)
		if idx < node.p:
			if node.l == None:
				node.l = cur
				return
			else:
				st.append(node.l)
		else:
			if node.r == None:
				node.r = cur
				return
			else:
				st.append(node.r)		

def post_order(root):
	st = []
	cur = root
	last = None
	ret = ''
	while cur != None or len(st) != 0:
		if cur != None:
			st.append(cur)
			cur = cur.l
		else:
			peek = st[len(st)-1]
			if peek.r != None and peek.r != last:
				cur = peek.r
			else:
				if len(ret) != 0:
					ret += ' '
				ret += str(peek.v)
				last = st.pop()
	print(ret)

n = int(input())
preo = list(map(int, input().split()))
ino = list(map(int, input().split()))

r = preo[0]
root = Node(r)
for i in range(1, n):
	cur = Node(preo[i])
	add_node(root, cur, ino)

post_order(root)



Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main()
{
	int n;
	cin >> n;
	ll a[100000];
	ll c1 = 0;
	ll c2 = 0;

	for (int i = 0; i < n; i++) cin >> a[i];

	ll sum = 0;
	int c = 1;

	//odd number are over 0;
	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (sum * c <= 0)
		{
			c1 += abs(sum) + 1;
			sum = c;
		}

		c *= -1;
	}

	//even numbers are over 0
	c = -1;
	sum = 0;
	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (c * sum <= 0)
		{
			c2 += abs(sum) + 1;
			sum = c;
		}
		c *= -1;
	}

	cout << min(c1, c2) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll A, B;
  cin>>A>>B;
  ll a=0, b=0;
  ll tmpa, tmpb;
  ll ans = 0;
  for(ll i=0;i<40;++i) {
    if((A&(1ull<<i))!=0) {
      tmpa = (1ull<<i) - a;
      a += (1ull<<i);
    }
    else tmpa=0;
    if((B&(1ull<<i))!=0) {
      tmpb = b+1;
      b += (1ull<<i);
    }
    else tmpb=0;
    if(i==0) {
      if((B-A+1)%4==1 && ((A&1)!=0)) ans++; 
      if((B-A+1)%4==2) ans++;
      if((B-A+1)%4==3 && ((A&1)==0)) ans++;
    }
    if (i>0 && (tmpa+tmpb)%2==1) ans += (1ull<<i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, Res, D[501000][3];
char p[501000];
void Do(vector<int>&T){
    if(T.size() <= 1)return;
    int i;
    D[0][0]=0,D[0][1]=D[0][2]=-1e9;
    for(i=0;i<T.size();i++){
        D[i+1][2] = max(max(D[i][0],D[i][1]) + T[i], D[i][2] + T[i]-1);
        D[i+1][1] = max(D[i][1] + T[i]-1, D[i][0]);
        if(T[i]>1)D[i+1][1] = max(D[i+1][1],D[i][2]);
        D[i+1][0] = max(max(D[i][1]+T[i],D[i+1][1]),D[i][2]);
    }
    Res += max(D[i][0],D[i][1]);
}
int main(){
    int i, c = 0;
    scanf("%d",&n);
    scanf("%s",p);
    vector<int>T;
    for(i=0;p[i];i++){
        if(p[i]=='1')c++;
        else{
            if(i&&p[i-1]=='0'){
                Do(T);
                T.clear();
            }
            if(c)T.push_back(c);
            c=0;
        }
    }
    if(c)T.push_back(c);
    Do(T);
    printf("%d\n",Res);
}

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

int main() {
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
int c=0;
for(int i=0;i<n;i++){
	if(i%2==0 && a[i]%2==1) c++;
}
  cout<<c;       
}

Measured memory_bytes: 3592
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		for(int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}
		sc.close();
		
		long sumX =0;
		
		for(int i = 0; i < N; i++) {
			sumX += X[i];
		}
		
		double avg = (double)sumX / N;
		
		long p1 = (long)Math.floor(avg);
		long p2 = (long)Math.ceil(avg);
		
		long ans1 = 0, ans2 = 0;
		
		for(int i = 0; i < N; i++) {
			ans1 += (long)Math.pow(X[i] - p1, 2);
			ans2 += (long)Math.pow(X[i] - p2, 2);
		}
		
		System.out.println(Math.min(ans1, ans2));
		

	}
}




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

template<class T> T gcd(T a, T b) {
	return b ? gcd(b, a%b) : a;
}
template<class T> T lcm(T a, T b) {
	return a*b / gcd(a, b);
}

int main(int argc, char** argv) {
	unsigned long long a, b;
	while (cin >> a >> b) {
		cout << gcd(a, b) << " " << lcm(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
lis = [int(i) for i in input().split()]
N = lis[0]
X = lis[1]
m = []
for i in range(N):
    m.append(int(input()))

num = N
X -= sum(m)

while(X >= min(m)):
    X -= min(m)
    num += 1

print(num)


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

int main() {
	//O(k^2)
	int k, s, ans = 0;
	cin >> k >> s;
	for (int x = 0; x <= k; ++x)
		for(int y = 0; y <= k; ++y)
				ans += (s - x - y >= 0 && s - x - y <= k);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
 

int main(){
    int N,D; cin >> N >> D;
    int w = 2 * D + 1;
    int ans = 0;
    if(N % w == 0) ans = N/w;
    else ans = N/w + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
int main(void) 
{
	int m, f, r;
	m = 1, f = 1, r = 1;
	while (1)
	{
		scanf("%d %d %d", &m, &f, &r);
		if (m == -1 && f == -1 && r == -1)
		{
			break;
		}

		else if (m == -1 || f == -1)
		{
			printf("F\n");
		}
		else if (m + f >= 80)
		{
			printf("A\n");
		}
		else if (m + f >= 65 && m + f < 80)
		{
			printf("B\n");
		}
		else if (m + f >= 50 && m + f < 65)
		{
			printf("C\n");
		}
		else if (m + f >= 30 && m + f < 50 && r < 50)
		{
			printf("D\n");
		}
		else if (m + f >= 30 && m + f < 50 && r >= 50)
		{
			printf("C\n");
		}
		if (m + f < 30)
		{
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


x, n = invr()

mark = [0]*101
a = inlist()

lx = rx = res = x
while True:
    if lx not in a:
        res = lx
        break
    if rx not in a:
        res = rx
        break
    lx -= 1
    rx += 1
print(res)


Measured memory_bytes: 10556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <cstdio>
#include <stack>
#include <queue>
using namespace std;

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

	vector<int> v(n, 0);

	int num = 0;
	v[0] = 1;
	for(int i = 1; i < n; i++) {
		if(s[num] == s[i]) {
			//
		}
		else {
			num = i;
			v[i] = 1;
		}
	}

	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += v[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long ,long> ii; 	
typedef complex<long double> com;
 
const ll mod = 998244353;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll ans = (n/500)*1000;
	n %= 500;
	cout << ans + (n/5)*5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))

int main() {

    // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N; cin >> N;
    int res = 0;
    for (int i = 1; i <= N; i++) {
        if (to_string(i).length() % 2 == 1) {
            ++res;
        }
    }
    cout << res << endl;

	return 0;
}


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

using namespace std;

int main()
{
    int T;
    
    scanf("%d", &T);
    
    while (T--){
        int s, y, n;
        
        scanf("%d %d %d", &s, &y, &n);
        
        int ans = s;
        
        for (int i = 0; i < n; i++){
            int t, dec;
            double r;
            
            scanf("%d %lf %d", &t, &r, &dec);
            if (t == 0){
                int tmp = s, tmp2 = 0;
                for (int j = 0; j < y; j++){
                    tmp2 += tmp * r;
                    tmp -= dec;
                }
                ans = max(ans, tmp + tmp2);
            }
            else {
                int tmp = s;
                for (int j = 0; j < y; j++){
                    tmp *= (1 + r);
                    tmp -= dec;
                }
                ans = max(ans, tmp);
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
  int n,k;
  cin>>n>>k;
  int a[n],dp[n];
  for(int i=0;i<n;i++)cin>>a[i];
  dp[0]=0;
  for(int i=1;i<n;i++){
    int f=INT_MAX;
    for(int j=i-1;j>=max(1LL*0,i-k);j--){
      f=min(f,dp[j]+abs(a[i]-a[j]));
    }
    dp[i]=f;
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 1792
class BIT:
    def __init__(self, N):
        self.tree = [0] * (N + 1)  # 1-indexed
        self.N = N

    def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

    def sum(self, i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & (-i)
        return s

    def binary_search(self, x):
        """区間和 >=x となる最小のindex"""
        tree = self.tree
        N = self.N
        i = 0
        step = 1 << (N.bit_length() - 1)
        while step:
            if i + step <= N and tree[i + step] < x:
                i += step
                x -= tree[i]
            step >>= 1
        return i + 1


def main():
    from collections import deque, namedtuple
    from operator import attrgetter
    import sys

    input = sys.stdin.readline
    Event = namedtuple('Event', 'time position')

    N, Q = map(int, input().split())

    go = []
    stop = []
    xs = set()
    for _ in range(N):
        s, t, x = map(int, input().split())
        stop.append(Event(time=s - x, position=x))
        go.append(Event(time=t - x, position=x))
        xs.add(x)

    xs = sorted(xs)

    stop.sort(key=attrgetter('time'))
    go.sort(key=attrgetter('time'))

    stop = deque(stop)
    go = deque(go)

    compress = {x: i for i, x in enumerate(xs, 1)}
    decompress = {i: x for i, x in enumerate(xs, 1)}

    ans = []
    b = BIT(N)
    for _ in range(Q):
        d = int(input())
        while go and go[0].time <= d:
            e = go.popleft()
            p = compress[e.position]
            b.add(p, -1)
        while stop and stop[0].time <= d:
            e = stop.popleft()
            p = compress[e.position]
            b.add(p, 1)

        compressed_ind = b.binary_search(1)
        ind = decompress.get(compressed_ind, -1)
        ans.append(ind)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 142988
N = int(input())
S = input()
left = ""
right = ""
ans = []
for i in range(N):
    left = S[:i+1]
    right = S[i+1:]
    left_n = set(list(left))
    right_n = set(list(right))
    count = 0
    for l in left_n:
        if l in right_n:
            count += 1
    ans.append(count)
print(max(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    string S;
    cin >> S;
    
    int win_cnt = 0;
    
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'o'){
            win_cnt++;
        }
    }
    
    int remain = 15 - S.size();
    
    if(win_cnt + remain >= 8){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <cmath>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  vector<ll> dice(6);
  rep (i, 6) cin >> dice[i];
  map<ll, ll> mp;
  rep (i, 6) mp[dice[i]] = i;
  ll N;
  cin >> N;
  rep (i, N) {
    ll a, b;
    cin >> a >> b;
    a = mp[a] + 1;
    b = mp[b] + 1;
    ll c;
    if (a == 1 and b == 2) c = 3;
    if (a == 1 and b == 3) c = 5;
    if (a == 1 and b == 4) c = 2;
    if (a == 1 and b == 5) c = 4;
    if (a == 2 and b == 1) c = 4;
    if (a == 2 and b == 3) c = 1;
    if (a == 2 and b == 4) c = 6;
    if (a == 2 and b == 6) c = 3;
    if (a == 3 and b == 1) c = 2;
    if (a == 3 and b == 2) c = 6;
    if (a == 3 and b == 5) c = 1;
    if (a == 3 and b == 6) c = 5;
    if (a == 4 and b == 1) c = 5;
    if (a == 4 and b == 2) c = 1;
    if (a == 4 and b == 5) c = 6;
    if (a == 4 and b == 6) c = 2;
    if (a == 5 and b == 1) c = 3;
    if (a == 5 and b == 3) c = 6;
    if (a == 5 and b == 4) c = 1;
    if (a == 5 and b == 6) c = 4;
    if (a == 6 and b == 2) c = 4;
    if (a == 6 and b == 3) c = 2;
    if (a == 6 and b == 4) c = 5;
    if (a == 6 and b == 5) c = 3;
    c--;
    cout << dice[c] << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



Measured memory_bytes: 3168
#include <stdio.h>

int main(void)

{

int i,n;

long int a,min=1000000,max=-1000000,sum=0;

scanf("%d",&n);

for(i=1;i<=n;i++)

{

scanf("%ld",&a);

if(a<min)

min=a;

if(a>max)

max=a;

sum+=a;

}

printf("%ld %ld %ld\n",min,max,sum);

return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

std::queue<std::pair<int, int>> q;
std::vector<std::vector<int>> vec;
std::vector<int> distances;
int n, id, num, d;

void bfs_search(int start_id) {
    q.push(std::make_pair(start_id, 0));
    while (!q.empty()) {
        auto x = q.front();
        q.pop();
        distances[x.first-1] = x.second;
        for (int i = 1; i <= n; i++) {
            if (vec[x.first][i] == 1 && distances[i-1] == -1) {
                q.push(std::make_pair(i, x.second+1));
                distances[i-1] = x.second;
            }
        }
    }
}

int main() {
    std::cin >> n;
    vec.assign(n+1, std::vector<int>(n+1, -1));
    for (int i = 0; i < n; ++i) {
        std::cin >> id >> num;
        for (int p = 0; p < num; p++) {
            std::cin >> d;
            vec[id][d] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        distances.push_back(-1);
    }
    bfs_search(1);
    for (int i = 0; i < n; i++) {
        std::cout << i+1 << " " << distances[i] << std::endl;
    }
}




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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005

int main(){
sp;
ll n,k;
cin>>n>>k;
ll a[n];
ll x=0;
for(int i=0; i<n;++i)cin>>a[i];
for(ll i=50LL; i>=0; --i){
    ll temp=1LL<<i;
    int z=0;
    for(int j=0; j<n; ++j)
        if(a[j]&temp)++z;
    int z1=n-z;
    if(z1>z){
        if(x+temp<=k)x+=temp;
    }
}
ll ans=0;
for(int i=0; i<n; ++i)ans+=(x^a[i]);
cout<<ans;
return 0;}


Measured memory_bytes: 1024
read s
sn1=${#s}
s=${s/*C/}
sn2=${#s}
if [ ${sn1} -eq ${sn2} ]
then
	echo No
	exit
fi

sn2=${#s}
s=${s/*F/}
sn3=${#s}
if [ ${sn2} -eq ${sn3} ]
then
	echo No
	exit
fi
echo Yes


Measured memory_bytes: 1396
n,m = map(int,input().split())
# maxn = 10**n
a=[0 for i in range(m)]
b=[0 for i in range(m)]
for i in range(m):
    a[i],b[i] = map(int,input().split())

if n==1:
    minn =0
    maxn = 10
else:
    minn = 10**(n-1)
    maxn = 10**n

for i in range(minn, maxn):
    tmp = str(i)
    ok = True
    for aa, bb in zip(a,b):
        if int(tmp[aa-1]) == bb:
            pass
        else:
            ok = False
            break
    if ok:
        print(i)
        break
else:
    print(-1)



Measured memory_bytes: 38384
S = input()

N = len(S)
ans = [0] * N

rl = []
for i in range(N-1):
    if S[i] == "R" and S[i+1] == "L":
        rl.append(i)

step = 0

for i in range(N):
    if abs(i - rl[step]) % 2 == 0:
        ans[rl[step]] += 1
    else:
        ans[rl[step] + 1] += 1
    
    if i < N - 1 and S[i] == "L" and S[i + 1] == "R":
        step += 1
        
print(*ans)

Measured memory_bytes: 8304
/*相信玄学*/
#include<bits/stdc++.h>
using namespace std;
long long n,m;
int main()
{
	cin>>n>>m;
	long long ans=0;
	for(long long i=m;i<=n+1;i++)
	{
		ans+=((((i*(2*n-i+1)))/2+1-((i*(i-1)))/2)%1000000007);
		ans=ans%1000000007;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
 
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  int N,ans=0;
  int B[100];

  cin >> N;
  rep(i,N-1)
    cin >> B[i];


  rep(i,N){
    if(i==0)
      ans += B[0];
    else if(i==N-1)
      ans += B[N-2];
    else
      ans += min(B[i-1],B[i]);
  }

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

Measured memory_bytes: 256
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve2() -> Any:
    N = read_int()
    T = read_ints()
    A = read_ints()
    upper = [0]*N
    lower = [0]*N
    upper[0] = lower[0] = T[0]
    for i in range(1, N):
        if T[i] > T[i-1]:
            upper[i] = lower[i] = T[i]
        else:
            upper[i] = T[i]
            lower[i] = 1
    if A[N-1] > upper[N-1] or A[N-1] < lower[N-1]:
        return 0
    upper[N-1] = lower[N-1] = A[N-1]
    for i in range(N-2, -1, -1):
        if A[i] > A[i+1]:
            if A[i] > upper[i] or A[i] < lower[i]:
                return 0
            upper[i] = lower[i] = A[i]
        else:
            # 1..A[i]
            if lower[i] > A[i]:
                return 0
            upper[i] = min(upper[i], A[i])
            lower[i] = min(lower[i], A[i])
    answer = 1
    modulo = 10**9+7
    for i in range(N):
        answer = (answer*(upper[i]-lower[i]+1))%modulo
    return answer



if __name__ == '__main__':
    print(solve2())



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

void dfs(int ci, int cj, vector<string>& board, VVI& visited, int h,int w){
  visited[ci][cj] = 1;
  rep(dir,4){
    if((ci + dy[dir]) < h && (cj + dx[dir]) < w &&
       (ci + dy[dir]) >= 0 && (cj + dx[dir]) >= 0  &&
       visited[(ci + dy[dir])][(cj + dx[dir])] == 0 &&
       board[(ci + dy[dir])][(cj + dx[dir])] == '.'){
      dfs((ci + dy[dir]),(cj + dx[dir]),board,visited,h,w);
    }
  }
}

void solve(int h, int w){
  vector<string> board(h);
  rep(i,h) cin >> board[i];
  VVI visited(h,VI(w,0));
  int sy = 0;
  int sx = 0;

  rep(i,h)rep(j,w){
    if(board[i][j] == '@'){
      sx = j;
      sy = i;
      break;
    }
  }
  dfs(sy,sx,board,visited,h,w);

  int cnt = 0;
  rep(i,h)rep(j,w) if(visited[i][j]) cnt++;
  cout << cnt << endl;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h,w;
  while(true){
    cin >> w >> h;
    if(h == 0 &&  w == 0){
      break;
    }
    solve( h,  w);
  }
  return 0;
}



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


using namespace std;
typedef long long ll;
vector<vector<int> > mymap(100001,vector<int>());
int res[100001];
queue<pair<int,int> > q;

void dfs(int from, int i){
  if(res[i] != 0) return;


  res[i] = from; 

  for(auto& room : mymap[i]){
    if(res[room] != 0) continue;
    q.push(make_pair(i,room));
  }
}

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


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

  for(int i=0;i<n+1;i++) res[i] = 0;


  q.push(make_pair(0,1));

  while(q.size() != 0){
    pair<int,int> arg = q.front();
    q.pop();
    dfs(arg.first,arg.second);
  }

  cout << "Yes" << endl;
  for (int i=2;i<n+1;i++){
    cout << res[i] << endl;
  }



}

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

int main(){
    std::string s;
    std::cin>>s;
    int ans=0;
    for(int i=0;i<s.size()-1;++i){
        if(s[i]!=s[i+1])ans++;
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define REP(i,n) for(Long i = 0; i < (Long)n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

const int N = 2e5 + 5;
ll ac[N];
string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	int n = s.size();
	ac[n] = 0;
	for (int i = n - 1; i >= 0; i--) {
		ac[i] = ac[i + 1] + (s[i] == 'W'? 1 : 0);
	}
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'B') {
			sum += ac[i];
		}
	}
	cout << sum << endl;
	return 0;
}

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

struct Node{int key;
struct  Node *next,*prev;


};
struct Node *nil;

struct Node* listSearch(int);

void init();

void printList();
void deleteNode(struct Node *);

void deleteFirst();
void deleteLast();

void deleteKey(int);

void insert(int);

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i')
      {insert(key);
	np++;
	size++;
	
      }
    else if(com[0]=='d'){
      if(strlen(com)>6){
	if(com[6]=='F')
	  deleteFirst();
	else if(com[6]=='L')
	  deleteLast();}
      else{
	deleteKey(key);
	nd++;}
      size--;}}
  printList();
  return 0;}
struct Node* listSearch(int key){
struct Node *cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;}
  return cur;}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;}
void printList(){
 struct Node *cur =nil->next;
  int isf=0;
  while(1){
    if(cur==nil)
      break;
    if(isf++>0)
      printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");


}

void deleteNode(struct Node *t){
  if(t==nil)
    return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);}

void deleteFirst(){

  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);}

void deleteKey(int key){
  deleteNode(listSearch(key));}

void insert(int key){
struct  Node *x=(struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;}



Measured memory_bytes: 33848
n = int(input())
for i in range(n):
  a = input()
  b = input()
  if len(a) > 80 or len(b) > 80:
    print("overflow")
  else:
    aa = int(a)
    bb = int(b)
    c = str(aa + bb)
    if len(c) > 80:
      print("overflow")
    else:
      print(c)


Measured memory_bytes: 5588
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
XYU = []
from bisect import bisect_left
from collections import defaultdict
UR = defaultdict(list)
UL = defaultdict(list)
DR = defaultdict(list)
DL = defaultdict(list)
LR = defaultdict(list)
UD = defaultdict(list)
for _ in range(N):
    x, y, u = input().split()
    x, y = int(x), int(y)
    XYU.append((x, y, u))
XYU.sort()
for x, y, u in XYU:
    if u=='U':
        UL[(x-y)].append((x, y))
    if u=='R':
        LR[y].append((x, y))
    if u=='D':
        DL[(x+y)].append((x, y))
    if u=='U':
        UR[(x+y)].append((x, y))
        UD[x].append((x, y))
    if u=='R':
        DR[(x-y)].append((x, y))

ans = 10**18
def check(x, y, u):
    global ans
    if u=='R':
        leng = len(UR[x+y])
        if leng:
            idx = bisect_left(UR[x+y], (x, y, u))
            if idx<leng:
                ans = min(ans, UR[x+y][idx][0]-x)

    if u=='L':
        leng = len(UL[x-y])
        if leng:
            idx = bisect_left(UL[x-y], (x, y, u))
            if idx>0:
                ans = min(ans, x-UL[x-y][idx-1][0])
        
        leng = len(DL[x+y])
        if leng:
            idx = bisect_left(DL[x+y], (x, y, u))
            if idx>0:
                ans = min(ans, x-DL[x+y][idx-1][0])
        
        leng = len(LR[y])
        if leng:
            idx = bisect_left(LR[y], (x, y, u))
            if idx>0:
                ans = min(ans, (x-LR[y][idx-1][0])/2)

    if u=='D':
        leng = len(UD[x])
        if leng:
            idx = bisect_left(UD[x], (x, y, u))
            if idx>0:
                ans = min(ans, (y-UD[x][idx-1][1])/2)

        leng = len(DR[x-y])
        if leng:
            idx = bisect_left(DR[x-y], (x, y, u))
            if idx>0:
                ans = min(ans, x-DR[x-y][idx-1][0])

for x, y, u in XYU:
    check(x, y, u)

if ans>=10**16:
    print('SAFE')
else:
    print(int(ans*10))



Measured memory_bytes: 208352
#include<iostream>
using namespace std;
int main()
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
  
   if(a+b>c+d)
   cout<<"Left";
   
   else if(a+b==c+d)
    cout<<"Balanced";
  
   else if(a+b<c+d)
   cout<<"Right";
   
 
 
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        int N;

        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            N = in.Int();

            int ans = 0;
            for (int i = 1; i <= N; i++) {
                ans += (N - 1) / i;
            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 32968
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int mod = 1000000007;
const int INF = 1e9;

int main()
{
	int n;
	
	while (cin >> n && n){
		map<double, set<string>,greater<double>> ma;

		rep(i, n){
			string l;
			int p, a, b, c, d, e, f, s, m;
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			ma[double(s * f * m - p) / double(a + b + c + (d + e)*m)].insert(l);
		}
		for (auto i : ma){
			auto v = i.second;
			for(auto j : v)cout << j << endl;
		}
		cout << "#" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1228
<?php
    fscanf(STDIN,"%d %d",$n,$k);
    while(true){
        if(strlen($n) > strlen($k)){
            $n = $n - $k * pow(10,strlen($n)-strlen($k)-1);
        }else{
            $ans = abs($n-$k);
            if($n > $ans){
                $n = $ans;
                continue;
            }else{
                break;
            }
        }
    }
    echo $n.PHP_EOL;
?>

Measured memory_bytes: 4728
module UnionFind
    implicit none
    private
        type :: Union_Find
            integer,allocatable,dimension(:) :: par
        end type Union_Find
    
        interface init
            module procedure initpar
        end interface init
    
        interface root
            module procedure roott
        end interface root
    
        interface unite
            module procedure unite2
        end interface unite
        public :: Union_Find
        public :: init,root,unite
    contains
    
        subroutine initpar(p,n)
            implicit none
            type(Union_Find)  p
            integer n,i
            allocate( p%par(n) )
            do i=1,n
                p%par(i) = i
            enddo
        end subroutine initpar
    
        recursive function roott(p,n) result(ret)
            implicit none
            type(Union_Find) p
            integer ret,n
            if(p%par(n)==n)then
                ret = n
                return
            else
                p%par(n) = roott(p,p%par(n))
                ret = p%par(n)
                return
            endif
        end
    
        subroutine unite2(p,a,b)
            implicit none
            type(Union_Find) p
            integer a,b
            a = roott(p,a)
            b = roott(p,b)
            if(a/=b)then
                p%par(a) = b
            endif
        end
end module UnionFind


program atcoder_abc97d
    use UnionFind
    implicit none
    type(Union_Find) a
    integer n,m,i,x,y,ans
    integer,allocatable,dimension(:) :: p
    read*,n,m
    allocate( p(n) )
    call init(a,n)

    read(*,*)(p(i),i=1,n)
    do i = 1,m
        read*,x,y
        call unite(a,x,y)
    enddo

    ans = 0
    do i=1,n
        if(root(a,p(i))==root(a,i))then
            ans = ans+1
        endif
    enddo
    write(*,'(I0)')ans
!----------------------functions--------------------------
contains



end program atcoder_abc97d



Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;
#define en printf("\n");

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll a,b,c,k;
        cin>>a>>b>>c>>k;
        ll sum=0;
        while(b<=a)
        {
            b*=2;sum++;
        }
        while(c<=b){
            c*=2;sum++;
        }
        if(k>=sum)
        cout<<"Yes";
        else
        cout<<"No";
}


Measured memory_bytes: 3660
import sys

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()

n,m = na()
ba = []
for i in range(n):
    ba.append(ns())
bb = []
for i in range(m):
    bb.append(ns())

for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            if ba[i+k][j:j+m] != bb[k]:
                ok = False
                break
        if ok:
            print("Yes")
            sys.exit(0)
print("No")


Measured memory_bytes: 3064