akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>

using namespace std;

void update(int** field, int n,int r,int c);

bool ch[500][500];

int main() {
	int n;
	cin >> n;
	int** field = new int*[n];
	for (int i = 0;i < n;i++) {
		field[i] = new int[n];
		for (int j = 0;j < n;j++) {
			field[i][j] = min(min(min(i,j),n-1-i),n-1-j);
			field[i][j] *= 2;
		}
	}
	pair<int, int>* p = new pair<int, int>[n * n];
	int tmp;
	for (int i = 0;i < n * n;i++) {
		cin >> tmp;
		tmp--;
		p[i] = make_pair(tmp / n, tmp % n);
	}
	long long ans = 0;
	for (int i = 0;i < n * n;i++) {
		ans += field[p[i].first][p[i].second]/2;
		update(field, n, p[i].first, p[i].second);
		field[p[i].first][p[i].second]++;
	}
	cout << ans << endl;
}


void update(int** field, int n,int r,int c) {
	bool flag = false;
	if (field[r][c] % 2 == 1) {
		flag = true;
		field[r][c]--;
	}
	if (r < n - 1) {
		if (field[r + 1][c] > field[r][c]) {
			update(field, n, r + 1, c);
		}	
	}
	if (c > 0) {

			if (field[r][c - 1] > field[r][c]) {
				update(field, n, r, c - 1);
			}
			
	}

	if (c < n - 1) {

			if (field[r][c + 1] > field[r][c]) {
				update(field, n, r, c + 1);
			}
			

	}
	if (r > 0) {

			if (field[r - 1][c] > field[r][c]) {
				update(field, n, r - 1, c);
			}
	}
	if (flag) {
		field[r][c]++;
	}
	field[r][c]-=2;
}


Measured memory_bytes: 25436
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char str[110];
char in[10];
int main(){
	for(int i=0;i<10;i++){
		int left=-1;
		if(i==0)left++;
		int right=10;
		while(left+1<right){
			int M=(left+right)/2;
			str[i]=M+'0';
			for(int j=i+1;j<13;j++)str[j]='9';
			str[13]=0;
			printf("? %s\n",str);fflush(stdout);scanf("%s",in);
			if(in[0]=='Y'){
				right=M;
			}else{
				left=M;
			}
		}
		str[i]=right+'0';
	}
	str[10]=0;
	long long b;
	sscanf(str,"%lld",&b);
	for(int i=9;i>=0;i--){
		if(b%10==9){
			b--;
			printf("? %lld\n",b*10);fflush(stdout);scanf("%s",in);
			if(in[0]=='Y'){
				printf("! ");
				for(int j=0;j<=i+1;j++)printf("%c",str[j]);
					printf("\n");
				return 0;
			}
			b++;
		}else{
			b++;
			printf("? %lld\n",b);fflush(stdout);scanf("%s",in);
			if(in[0]=='N'){
				printf("! ");
				for(int j=0;j<=i+1;j++)printf("%c",str[j]);
					printf("\n");
				return 0;
			}
			b--;
		}
		b/=10;
	}

	printf("! %c\n",str[0]);
}

Measured memory_bytes: 504
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

struct UnionFind{
    int size;
    std::vector<int> par;
    std::vector<int> rank;
    UnionFind(int x){
        size=x;
        par=std::vector<int> (x);
        rank=std::vector<int> (x,1);
        for (int i=0;i<x;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        else return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y) return;
        if(rank[x]<rank[y]) par[x]=y;
        else par[y]=x;
        if(rank[x]==rank[y]) rank[x]++;
    }
    bool check(int x,int y){
        return root(x)==root(y);
    }
    void initialize(){
        for (int i=0;i<size;i++){
            par[i]=i;rank[i]=1;
        }
    }
};

using namespace std;

long long gcd(ll x, ll y){
    if(x < y) swap(x,y);
    while(x%y){
        long long tmp = y;
        y = x%y; x = tmp;
    }
    return y;
}

bool em[1010000];

void setwise(vector<int> &da) {
    int now = da[0];
    rip(i,da.size(), 1) now = gcd(now, da[i]);
    if(now == 1) {
        cout << "setwise coprime\n";
    }
    else {
        cout <<"not coprime\n";
    }
}

int main() {
    int n; cin >> n;
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    rip(i,n,0) {
        if(da[i] != 1) {
            if(em[da[i]]) {
                setwise(da);
                return 0;
            }
            else{
                em[da[i]] = true;
            }
        }
    }
    rip(i,1001000, 2) {
        int now = i, cnt =  0;
        while(now < 1010000) {
            if(em[now]) cnt++;
            now += i;
        }
        if(cnt > 1) {
            setwise(da);
            return 0;
        }
    }
    cout << "pairwise coprime\n";
}


Measured memory_bytes: 8084
import java.util.Scanner;

class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        int total = 0;

        for ( int i = 1; i <= N; i++ ){
            int n = digits_sum(i);
            if ( n >= A && n <= B ){
                total += i;
            }
        }
        System.out.println(total);
    }
    private static int digits_sum(int n){
        int sum = 0;
        for(char c: Integer.toString(n).toCharArray()){
            
            sum  += Character.getNumericValue(c);
        }
        return sum;
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int fact(int n){
    int factn=1;
    for (int i = 1; i <= n; ++i)
        factn *= i;
    return factn;
}

int main(){
    int n;
    cin >> n;
    vector<double> x(n),y(n);
    for(int i=0;i<n;++i){
        cin >> x[i] >> y[i];
    }
    
    double sum=0;
    for(int i=0; i<n;++i){
        for(int j=0;j<n;++j){
            if(i==j) break;

            double l = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
            l = sqrt(l);
            
            if(n==2) sum = l*2;
            else{
                int a = fact(n-2);
                sum +=  l*(a + a*(n-2))*2;
            }
        }
    }
    printf("%.10lf\n", sum / fact(n));
    //cout << fixed << setprecision(15) << sum / fact(n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x;
    cin>>n>>x;
    vector<ll>v;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        v.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
        v[i]=abs(v[i]-x);
    }
    ll g=0;
    for(int i=0;i<n;i++)
        g=__gcd(g,v[i]);
    cout<<g<<endl;
    return 0;
}

Measured memory_bytes: 4232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	string a, b;
	cin >> a >> b;
	if(a.size() > b.size()) puts("GREATER");
	else if (a.size() < b.size())puts("LESS");
	else{
		for(int i = 0; i < a.size(); ++i){
			if(a[i] > b[i]){
				puts("GREATER");
				return 0;
			}
			else if(a[i] < b[i]){
				puts("LESS");
				return 0;
			}
		}
		puts("EQUAL");
	}
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
a_start = a[0]
a_last = a[k - 1]
for i in range(1, n - k + 1):
    next_start = a[i]
    next_last = a[k + i - 1]
    if next_last > a_start:
        print('Yes')
    else:
        print('No')
    a_start, a_last = next_start, next_last

Measured memory_bytes: 94256
#include <stdio.h>

int main(void) {

	int a[10][10];
	int i, j, x, y;
	int size;
	int max = 0, cnt = 0;

	for(i = 0; i < 10; i++) {
		for(j = 0; j < 10; j++) {
			a[i][j] = 0;
		}
	}

	//while(scanf("%d,%d,%d", &x, &y, &size) && size != 0 ) {
	while(scanf("%d,%d,%d", &x, &y, &size) == 3 ) {
		switch(size) {
		case 3:
			if(x >= 2) a[x - 2][y]++;
			if(y >= 2) a[x][y - 2]++;
			if(x <= 7) a[x + 2][y]++;
			if(y <= 7) a[x][y + 2]++;
		case 2:
			if((x >= 1) && (y >= 1)) a[x - 1][y - 1]++;
			if((x >= 1) && (y <= 8)) a[x - 1][y + 1]++;
			if((x <= 8) && (y >= 1)) a[x + 1][y - 1]++;
			if((x <= 8) && (y <= 8)) a[x + 1][y + 1]++;
		case 1:
			if(x >= 1) a[x - 1][y]++;
			if(y >= 1) a[x][y - 1]++;
			if(x <= 8) a[x + 1][y]++;
			if(y <= 8) a[x][y + 1]++;
			a[x][y]++;
		}
	}

	for(i = 0; i < 10; i++) {
		for(j = 0; j < 10; j++) {
			if(a[i][j] == 0) {
				cnt++;
			} else {
				if(a[i][j] > max) max = a[i][j];
			}
		}
	}
	printf("%d\n", cnt);
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 600
@n=glob<>;
@x=glob<>;
@y=glob<>;
$ym=100;
$xm=-100;
$xm=($_>$xm)?$_:$xm foreach @x;
$ym=($_<$ym)?$_:$ym foreach @y;
$j="No " if($xm<$n[3]&&$xm<$ym&&$n[2]<$ym);
print $j."War"


Measured memory_bytes: 768
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys
S = sys.stdin.readline().rstrip()
A,B,C,D = [int(c) for c in S]

def calc(s,i,ops):
    #print(i,s,ops)
    if i == 4:
        if s == 7:
            print(S[0]+ops[0]+S[1]+ops[1]+S[2]+ops[2]+S[3]+"=7")
            exit(0)
        else:
            return
    calc(s+int(S[i]),i+1,ops+["+"])
    calc(s-int(S[i]),i+1,ops+["-"])

calc(int(S[0]),1,[])

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

using namespace std;

const int maxn = 1e4+10, maxs = 110, mod = 1e9+7;

vector<int> digit;

int n, d, dp[maxn][maxs][2];

void add_self(int &a, int b){
    a += b;
    if(a>=mod){
        a -= mod;
    }
}

inline int solve(int pos, int sum, bool flag){
    if(dp[pos][sum][flag] != -1) return dp[pos][sum][flag];
    if(pos == n) return (sum%d == 0 ? 1 : 0);

    if(flag){
        int tot = 0;

        for(int i=0; i<=digit[pos]; i++){
            add_self(tot, solve(pos+1, (sum+i)%d, (i == digit[pos])));
        }

        return dp[pos][sum][flag] = tot;
    }
    else{
        int tot = 0;

        for(int i=0; i<=9; i++){
            add_self(tot, solve(pos+1, (sum+i)%d, 0));
        }

        return dp[pos][sum][flag] = tot;
    }
}

int calc(string k){
    n = (int)k.size();

    digit.resize(n);

    for(int i=0; i<n; i++) digit[i] = k[i] - '0';

    memset(dp, -1, sizeof dp);

    int ans = solve(0, 0, 1) - 1;

    if(ans == -1) ans += mod;

    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    string k;

    cin >> k >> d;

    cout << calc(k) << endl;

    return 0;
}


Measured memory_bytes: 13952
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>
 
#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;
 
 
ll dp[100];
 
int main()
{
	dp[0] = 2;
	dp[1] = 1;
	
	for(int i = 2;i < 87;i++)
	{
		dp[i] = dp[i-1] + dp[i-2];
	}
	
	int n;cin >> n;
	
	cout << dp[n] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif
 
	string s;
	cin>>s;
	
	if(s=="RRR")
	{
	    cout << 3 << endl;
	    return 0;
	}
	
	if(s=="RRS" || s=="SRR")
	{
	    cout << 2 << endl;
	    return 0;
	}
	
	if(s=="SSS")
	{
	    cout << 0 << endl;
	    return 0;
	}
	
	cout << 1 << endl;
}


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

int main()
{
  string todayWeather;
  cin >> todayWeather;
  
  if( todayWeather == "Sunny" )
  {
    cout << "Cloudy" << endl;
  }
  else if ( todayWeather == "Cloudy" )
  {
    cout << "Rainy" << endl;
  }
  else if ( todayWeather == "Rainy" )
  {
    cout << "Sunny" << endl;
  }
  
  return 0;
}

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

int main() {
	
	int A, B;
	cin >>A >>B;
	
	if(A>=13){
		
		cout <<B <<endl;
		
	}
	else if(A>=6&&A<=12){
		
		cout <<B/2 <<endl;
		
	}
	else{
		
		cout <<0 <<endl;
		
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;

vi adj[210000];
vi val(210000,0);
void dfs(int cur, int par, int Val){
    val[cur]=val[cur]+Val;
    for(auto g:adj[cur]){
        if(g!=par){
            dfs(g,cur,val[cur]);
        }
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    int n, q;
    cin>>n>>q;    
    REP(i,0,n-1){
        int A, B;
        cin>>A>>B;
        adj[A].PB(B);
        adj[B].PB(A);
    }
    while(q--){
        int A, B;
        cin>>A>>B;
        val[A]=val[A]+B;
    }
    dfs(1,0,val[0]);
    for(int i=1;i<=n;i++){
        cout<<val[i]<<" "; 
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 24576
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  long long k; cin >> k;
  if (k%2 == 0 || k%5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  int a;
  if (k%7 == 0) {
    a = 9*k / 7;
  } else {
    a = 9*k;
  }

  long long tmp = 10;
  for(int i=1; ; i++) {
    if((tmp - 1)%a == 0) {
      cout << i << endl;
      return 0;
    }
    tmp = tmp%a * 10;
  }


  return 0;
}

// EOF

Measured memory_bytes: 3616
import java.util.*;

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

    int N = sc.nextInt();
    int x = sc.nextInt();
    int[] a = new int[N];

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

    Arrays.sort(a);
    int ans = 0;

    for (int i = 0; i < N; i++) {
      x -= a[i];

      if (x < 0) {
        ans = i;
        break;
      } else if (x == 0) {
        ans = i+1;
      }
    }

    if (x > 0) {
      ans = N - 1;
    }

    System.out.println(ans);
  }
}


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

int main() {
	string ans;
	int r, g,b;
	cin >> r >> g>>b;
	r = r*100;
	g = g * 10;
	int rgb;
	rgb = r + g + b;
	if (rgb%4==0) {
		ans = "YES";
	}
	else {
		ans = "NO";
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int n,p,i,j,a[55];
long long dp[2];

int main(){
	scanf("%d%d", &n, &p);
	
	dp[0] = 1LL;
	
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
		a[i] %= 2;
	}
	
	for(i = 0; i < n; i++){
		long long tmp, tmp1;
		if(a[i] == 0){
			dp[0] += dp[0];
			dp[1] += dp[1];
		}
		else{
			tmp = dp[1];
			tmp1 = dp[0];
			dp[0] += tmp;
			dp[1] += tmp1;
		}
	}
	
	printf("%lld\n", dp[p]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
using vi = vector<int>; using vvi = vector<vi>;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0}; vi d4y = {0, 1, 0, -1};
//---------------------------------------

int main(){
    ll n; cin>>n;
    cout<<n*(n-1)/2<<endl;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

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

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;

    vector< pair<s64, s64> > v(n);
    s64 x, l;
    rep (i, n)
    {
        cin >> x >> l;
        v[i] = make_pair(x + l, l);
    }

    sort(v.begin(), v.end());
    int ans = 1;
    int idx = 0;
    rep (i, n)
    {
        if (v[idx].first <= v[i].first - 2 * v[i].second)
        {
            idx = i;
            ++ans;
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1792
local mmi, mma = math.min, math.max
local n, m = io.read("*n", "*n")
local edge = {}
local v = {}
local len = {}
for i = 1, n do
  edge[i] = {}
  v[i] = false
  len[i] = false
end
v[1] = 0
len[1] = 0
local evmin = 0
local oddmin = false
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  edge[a][b] = c
  edge[b][a] = c
  if a == 1 then
    oddmin = c
  end
end
local rem_edge = {}
local tasks = {1}
for i = 1, n do
  local src = tasks[i]
  for dst, sum in pairs(edge[src]) do
    if not v[dst] then
      edge[dst][src] = nil
      v[dst] = sum - v[src]
      len[dst] = 1 - len[src]
      if len[dst] == 1 then
        oddmin = mmi(oddmin, v[dst])
      else
        evmin = mmi(evmin, v[dst])
      end
      table.insert(tasks, dst)
    else
      table.insert(rem_edge, {src, dst, sum})
      edge[dst][src] = nil
    end
  end
end
if #rem_edge == 0 then
  print(mma(0, oddmin + evmin - 1))
else
  local valid = true
  local offset = false
  for i = 1, #rem_edge do
    local p1, p2, sum = rem_edge[i][1], rem_edge[i][2], rem_edge[i][3]
    if len[p1] + len[p2] == 1 then
      if v[p1] + v[p2] ~= sum then
        valid = false break
      end
    else
      if len[p1] + len[p2] == 0 then
        if not offset then
          offset = sum - v[p1] - v[p2]
          if offset % 2 == 1 then valid = false break end
          offset = math.floor(offset / 2)
        else
          if v[p1] + v[p2] + offset * 2 ~= sum then
            valid = false break
          end
        end
      else
        if not offset then
          offset = v[p1] + v[p2] - sum
          if offset % 2 == 1 then valid = false break end
          offset = math.floor(offset / 2)
        else
          if v[p1] + v[p2] - offset * 2 ~= sum then
            valid = false break
          end
        end
      end
    end
    if offset then
      if evmin + offset < 1 then valid = false end
      if oddmin - offset < 1 then valid = false end
    end
  end
  if offset then
    print(valid and 1 or 0)
  else
    print(valid and mma(0, oddmin + evmin - 1) or 0)
  end
end


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

int main(){
    long int a,b,x;
    cin>>a>>b>>x;
    if(a!=0){
        cout<<(b/x)-((a-1)/x)<<endl;
    }else{
        cout<<((b/x)+1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    int n[4];
    for(int i=0;i<4;++i){
        n[i] = s[i] - '0';
    }
    for(int i=0;i<8;++i){
        int ans = n[0];
        for(int j=0;j<3;++j){
            if((i>>j)&1){
                ans += n[j+1];
            }else{
                ans -= n[j+1];
            }
        }
        if(ans == 7){
            cout << n[0];
            for(int j=0;j<3;++j){
                if((i>>j)&1){
                    cout << '+';
                }else{
                    cout << '-';
                }
                cout << n[j+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int maxn = 1e7 + 5;
const int MAX = 10000000;
 
ll d,n;
int main()
{
   cin>>d>>n;
   int temp=1;
   int ans=0;
   if(d==0)
   {
    if(n==100)
       ans=101;
    else
        ans=temp*n;
   }
   else if(d==1)
   { 
    temp=100;
    if(n==100)
       ans=10100;
    else
        ans=temp*n;

   }
   else 
  {
    temp=10000;
    if(n==100)
       ans=10000*100+10000;
    else
        ans=temp*n;
  }
  cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


template< typename T >
struct SparseTable {
  vector< vector< T > > st;
  vector< int > lookup;

  SparseTable(const vector< T > &v) {
    int b = 0;
    while((1 << b) <= v.size()) ++b;
    st.assign(b, vector< T >(1 << b));
    for(int i = 0; i < v.size(); i++) {
      st[0][i] = v[i];
    }
    for(int i = 1; i < b; i++) {
      for(int j = 0; j + (1 << i) <= (1 << b); j++) {
        st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
    lookup.resize(v.size() + 1);
    for(int i = 2; i < lookup.size(); i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  inline T rmq(int l, int r) {
    int b = lookup[r - l];
    return min(st[b][l], st[b][r - (1 << b)]);
  }
};

int n;
bool f(int k,SparseTable<int> &st,vector<int> &a){
    unordered_map<int,P> ma;
    int bf = 0;
    for (int i = 0; i < n; i++) {
        int t = a[i];
        if(ma.find(t) != ma.end()){
            if(st.rmq(ma[t].sc,i) < t) ma[t] = mp(0,i);
        }
        if(t < bf && ma[t].fs == 0) ma[t] = mp(1,i); 
        ma[t].fs++;
        ma[t].sc=i;
        while(ma[t].fs == k + 1){
            ma[t].fs = 1;
            if(ma.find(t-1) != ma.end()){
                if(st.rmq(ma[t-1].sc,i) < t - 1) ma[t - 1] = mp(1,i);
                else ma[t - 1].sc = i;
            }
            else ma[t - 1] = mp(1,i);
            ma[t-1].fs++;
            t--;
            if(t<=0||k==1) return false;
        }
        bf = a[i];
    }
    return true;
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SparseTable<int> st(a);
    int l = 0, r = INF;
    while(abs(r - l) > 1){
        int m =  l + (r - l) / 2;
        if(f(m,st,a)) r = m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}


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

int main()
{
    using namespace std;
    
    long int a, b, x;
    cin >> a >> b >> x;

    auto solver = [](long a, long b, long x){
        long int cnt = b/x;
        if(a==0)
            cnt += 1;
        else
            cnt -= (a-1)/x;
        return cnt;
    };

    cout << solver(a,b,x) << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n;
int ans=0,active=0;
cin >> n;
vector<int> a(n);
for(int i=0;i<n;i++)cin >> a[i];

for(int i=0;i<n;i++){
if(active >= a[i]){
active = a[i];
}else{
ans += a[i] - active;
active = a[i];
}
}
cout << ans << endl;
return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void Dijkstra(Graph& G, ll s, Array& d) {//O(|E|log|V|)
	d.resize(G.size());
	REP(i, d.size())d[i] = INF;
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(make_pair(0, s));
	while (!q.empty()) {
		P a = q.top();
		q.pop();
		if (d[a.second] < a.first)continue;
		REP(i, G[a.second].size()) {
			Edge e = G[a.second][i];
			if (d[e.to] > d[a.second] + e.cap) {
				d[e.to] = d[a.second] + e.cap;
				q.push(make_pair(d[e.to], e.to));
			}
		}
	}
}

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

	ll n, m;
	cin >> n >> m;

	Graph g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		add_edge(g, a, b, c, true, c);
	}


	ll con = 0;
	REP(i, n) {
		Array d;
		Dijkstra(g,i,d);
		for (auto e : g[i]) {
			if (e.cap > d[e.to]) {
				con++;
			}
		}
	}

	cout << con / 2 << endl;

	return 0;
}

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

int main() {
    ll n;
    cin>>n;
    ll ans = 0;
    map<int,int> mp;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        int sa = i - a[i];
        ans += mp[sa];
        int wa = i + a[i];
        mp[wa]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 21124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int s;
  cin >> s;
  int a=s;
  
  for(int i=1;i<=1000000;i++){
    if(a==4||a==2||a==1){
      cout << i+3 << endl;
      return 0;
    }
    
    if(a%2==0){
      a /= 2;
    }else{
      a = 3*a+1;
    }
  }
}

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

using namespace std;

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

using vi = vector<int>;


int main() {

	int N;

	cin >> N;

	long long int ans = 0;

	for (long long int i = 1; i < N+1; i++)
	{
		if ((i % 3) == 0 || (i % 5) == 0) {
			continue;
		}
		ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n;
    cin >> n;
    vec a(n),b(n);
    vector<pair<ll,pair<ll,ll>>> c(n);
    rep(i,n){
        cin >> a[i]>> b[i];
        c[i]=mp(a[i]+b[i],mp(a[i],b[i]));
    }
    sort(ALL(c),greater<pair<ll,pair<ll,ll>>>());
    ll ans=0;
    rep(i,n){
        if(i%2==0){
            ans+=c[i].se.fi;
        }else{
            ans-=c[i].se.se;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7220
#define f(I)(p[I]+h[I]*(h[I]-2*h[i]))
long C,h[2<<17],p[2<<17],X,a;
P[2<<17];
s,t=-1,i,x,y;
main(){
	for(scanf("%*d%ld",&C);~scanf("%ld",&a);){
		h[i]=a;
		for(;X=f(P[s]),s<t&&X>=f(P[s+1]);s++);
		X=p[i]=i?a*a+C+X:0;i++;
		for(;s<t&&(h[y=P[t]]-h[x=P[t-1]])*(f(y)-f(i-1))>=(a-h[y])*(f(x)-f(y));t--);
		P[++t]=i-1;
	}
	printf("%ld",X);
}

Measured memory_bytes: 4608
#include <stdio.h>

int func(int x) {
  int num;
  if(x % 2 == 0) {
    num = x / 2;
  } else {
    num = 3 * x + 1;
  }
  return num;
}

int main() {
  int s, i, j;
  int a[1000000];
  scanf("%d", &s);
  a[0] = s;
  for(i = 1; ; i++) {
    a[i] = func(a[i-1]);
    for(j = 0; j < i; j++) {
      if(a[i] == a[j]) {
        printf("%d\n", i + 1);
        return 0;
      }
    }
  }
}


Measured memory_bytes: 128
from collections import deque
n=int(input())
s=input()
black=0
write=s.count(".")
koho=deque([write,s.count("#")])
for i in s:
    if i==".":
        write-=1
    else:
        black+=1
    koho.append(write+black)
print(min(koho))

Measured memory_bytes: 11492
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        // out.println("AMAN");
        int n = sc.nextInt(), s = sc.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        int max = 0;
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
            max+=v[i];
        }
        long dp[] = new long[max+1]; 
        Arrays.fill(dp,(long)10e17);
        dp[0]=0;
        for(int i=0;i<n;i++) {
            for(int j=max;j>=0;j--) {
                if(j-v[i]>=0)
                    dp[j] = Math.min(dp[j],dp[j-v[i]]+w[i]);
            }
        }
        int res = 0;
        for(int i=0;i<max+1;i++) {
            if(dp[i]<=s)
                res=i;
        }
        out.print(res);

        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

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

int main() {
  int a, b, ans;
  char op;
  cin >> a >> op >> b;
  ans = 0;
  
  if (op == '+') ans = a + b;
  else if (op == '-') ans = a - b;
  
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <bits/stl_numeric.h>
#include <queue>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

static const int MAX = 510000;

int main() {

    ll n,res;
    cin >> n;
    res = 0;

    for(ll i = 1; i <= n; ++i)
    {
        if(i % 3 == 0 || i % 5 == 0)continue;
        res += i;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }

int main() {
    string s;
    cin >> s;
    bool ok = true;
    if (s[3] != s[2] || s[4] != s[5]) {
        cout << "No";
        return 0;
    } else {
        if (s[0] == s[1])
            cout << "No";
        else
            cout << "Yes";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int cnt5(ll x){
    int res = 0;
    ll tmp = 1;
    while(tmp<x){
        tmp*=5;
        res++;
    }
    return res;
}

ll pow5(int k){
    ll res = 1;
    REP(i,k) res *= 5;
    return res;
}

int main(){
    ll N; cin >> N;
    ll ans = 0;
    FOR(i,1,cnt5(N)+1){
        ans += N/2/pow5(i);
    }
    cout << (N%2==0?ans:0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<deque>
using namespace std;
const int maxn=300000+10;
char a[maxn];
deque<char> que;

int main(){
	int q;
	cin>>a>>q;
	int len=strlen(a);
	for(int i=0;i<len;i++){
		que.push_back(a[i]);	
	}
	int nowt=1;
	while(q--){
		int x;cin>>x;
		if(x==1){
			if(nowt==1){
				nowt=2;	
			}
			else nowt=1;
		}
		else if(x==2){
			int vis;char ch;
			cin>>vis>>ch;
			if(vis==1){
				if(nowt==1){
					que.push_front(ch);	
				}
				else{
					que.push_back(ch);	
				}
			}
			else{
				if(nowt==2){
					que.push_front(ch);	
				}
				else{
					que.push_back(ch);	
				}
			} 
		}
	}
	if(nowt==1){
		while(!que.empty()){
			cout<<que.front();
			que.pop_front();
		}
	} 
	else{
		while(!que.empty()){
			cout<<que.back();
			que.pop_back();
		}	
	}
}

Measured memory_bytes: 896
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

l = [i for i in range(1,13)]
l = [str(i) if len(str(i))==2 else '0'+str(i) for i in l]

if s[:2] not in l and s[2:] not in l:
    print('NA')
elif s[:2] not in l and s[2:] in l:
    print('YYMM')
elif s[:2] in l and s[2:] not in l:
    print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 61824
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>

using namespace std;

int main(){
    string S;
    cin >> S;
    int n = S.size();
    vector<int> list;
    char f;
    int cnt = 0;
    for (int i = 0; i < n; i++){
        char c = S[i];
        if (i == 0 && c == '>'){
            list.emplace_back(1);
            cnt++;
            f = '>';
            continue;
        }
        else if (i == 0 && c == '<'){
            cnt++;
            f = '<';
            continue;
        }
        if (c == f)
            cnt++;
        else{
            list.emplace_back(cnt);
            cnt = 1;
            f = c;
        }
    }
    list.emplace_back(cnt);
    if (S[n - 1] == '<')
        list.emplace_back(1);
    

    long ans = 0;
    for (int i = 0; i < list.size() / 2; i++){
        int up = list[i * 2];
        int down = list[i * 2 + 1];
        long big = max(up, down);
        long sml = min(up, down);
        long sum = (1 + big) * big / 2;
        sum += sml * (sml - 1) / 2;
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2296
n = int(input())
if n < 10:
    print(n)
elif n < 100:
    print(9)
elif n < 1000:
    print(9 + n - 99)
elif n < 10000:
    print(909)
elif n < 100000:
    print(909 + n - 9999)
elif n == 100000:
    print(90909)


Measured memory_bytes: 2940
ABK = input().split()
A = int(ABK[0])
B = int(ABK[1])
K = int(ABK[2])

if (K >= A):
    K -= A
    B -= K
    A = 0

    if (B <= 0):
        B = 0
else:
    A -= K

print(str(A) + " " + str(B))

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

vector< pair<long long, long long> > X;
set< pair<long long, long long> > A, B;

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

    int N, d, a;
    cin >> N >> d >> a;

    for(int i=0; i<N; i++)
    {
        int x, h;
        cin >> x >> h;
        X.push_back({x, h});
    }

    d *= 2;
    sort(X.begin(), X.end());
    long long ans = 0, shift = 0;
    
    for(int i=0; i<X.size(); i++)
    {
        while(!A.empty() && X[i].first > A.begin()->first + d)
        {
            int h = max(0LL, B.begin()->first - shift * a);
            ans += (h + a - 1) / a;
            shift += (h + a - 1) / a;
            
            A.erase({B.begin()->second, B.begin()->first});
            B.erase(B.begin());
        }

        A.insert({X[i].first, X[i].second + shift * a});
        B.insert({X[i].second + shift * a, X[i].first});
    }

    while(!A.empty())
    {
        int h = max(0LL, B.begin()->first - shift * a);
        ans += (h + a - 1) / a;
        shift += (h + a - 1) / a;
        
        A.erase({B.begin()->second, B.begin()->first});
        B.erase(B.begin());
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 29036
using System;

class MainClass
{
	public static void Main (string[] args)
	{
		while (true) {
			string str = Console.ReadLine ();
			string[] spStr = str.Split (' ');

			int a = int.Parse (spStr [0]);
			int b = int.Parse (spStr [1]);

			if (a == 0 && b == 0) {break;}

			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					if (i % 2 ==0) 
					{
						if (j % 2 == 0) 
						{
							Console.Write ("#");
						}
						else 
						{
							Console.Write (".");
						}
					} 
					else 
					{
						if (j % 2 == 1) 
						{
							Console.Write ("#");
						}
						else 
						{
							Console.Write (".");
						}
					}
				}
				Console.WriteLine ("");
			}
			Console.WriteLine ("");
		}
	}
}

Measured memory_bytes: 8772
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
if x not in p:
    print(x)
    exit()
    
for i in range(1, 51):
    ok1 = False
    ok2 = False
    if x-i not in p:
        ok1 = True
    if x+i not in p:
        ok2 = True
    if ok1 or ok2:
        if not ok2:
            print(x-i)
        elif not ok1:
            print(x+i)
        else:
            print(x-i)
        exit()

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n; cin >> n;

	int t = n / 10;
	int k = n % 10;

	if (t == 9 || k == 9)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
		List<long>[] nextList = new List<long>[n];//頂点番号ごとの隣接リスト
    long[] unionVertexes = new long[n];//まとめた頂点数
    long scoreFirst = 0;//先手の得点。同点は負け
    long scoreSecond = 0;//後手の得点

    for(long i = 0; i < n; i++)
    {
      nextList[i] = new List<long>();
    }

    for(long i = 0; i < n-1; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      nextList[nums[0]-1].Add(nums[1]-1);
      nextList[nums[1]-1].Add(nums[0]-1);//木の作成
    }

    while(true)
    {
      bool isChanged = false;
      for(long i = 1; i < n-1; i++)
      {
        if(nextList[i].Count() == 1)
        {
          unionVertexes[nextList[i][0]] += unionVertexes[i] + 1;//先端の頂点の結合
          nextList[nextList[i][0]].Remove(i);
          nextList[i].RemoveAt(0);
          isChanged = true; 
        }
      }
      if(!(isChanged)) break;
    }

    scoreFirst = unionVertexes[0];
    scoreSecond = unionVertexes[n-1];

    while(true)
    {
      if(nextList[0][0] == n-1) break;
      else
      {
        scoreFirst += unionVertexes[nextList[0][0]] + 1;//先手のスコア加算
        nextList[nextList[0][0]].Remove(0);//0の先から0を除く
        long memo = nextList[nextList[0][0]][0];//0の先をメモ
        nextList[nextList[nextList[0][0]][0]].Remove(nextList[0][0]);//0の先からもう一方も除く
        nextList[nextList[0][0]].RemoveAt(0);
        nextList[0].RemoveAt(0);
        nextList[0].Add(memo);
        nextList[memo].Add(0);
      }

      if(nextList[n-1][0] == 0) break;
      else
      {
        scoreSecond += unionVertexes[nextList[n-1][0]] + 1;
        nextList[nextList[n-1][0]].Remove(n-1);
        long memo = nextList[nextList[n-1][0]][0];
        nextList[nextList[nextList[n-1][0]][0]].Remove(nextList[n-1][0]);
        nextList[nextList[n-1][0]].RemoveAt(0);
        nextList[n-1].RemoveAt(0);
        nextList[n-1].Add(memo);
        nextList[memo].Add(n-1);
      }
    }
    
    Console.WriteLine((scoreFirst > scoreSecond) ? "Fennec" : "Snuke");
	}
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    int i;
    int ans = 1;
    for(i = 0;i < n;++i){
        if(ans*2 < ans+k){
            ans *= 2;
        }else{
            ans += k;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
S = [list(input()) for i in range(n)]

S.sort(key=lambda x: len(x))
table = collections.defaultdict(int)

len_s = len(S[0])
for i in range(1, n):
    for x in S[0]:
        if x in S[i]:
            S[i].pop(S[i].index(x))
        else:
            S[0].pop(S[0].index(x))

S[0].sort()
print("".join(S[0]))


Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[200];
bool solve() {
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) return 0;
	}
	return 1;
}
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (solve()) {
		cout << "YES\n";
		return 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			swap(a[i], a[j]);
			if (solve()) {
				cout << "YES\n";
				return 0;
			}
			swap(a[i], a[j]);
		}
	}
	cout << "NO\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
  long double result = 0;
  long int a, b, c, d;
  scanf("%ld %ld %ld", &a, &b, &c);
  d = c-a-b;
  result = (4*a*b) - d*d;
  if( d > 0 && result < 0 ){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  //printf("%Lf\n", result);
  return 0;
}

Measured memory_bytes: 128