akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
   public:
    i64 a[maxn], b[maxn], cc;
    i64 ac = 0, bc = 0;
    void solve() {
        i64 n, k;
        cin >> n >> k;
        for (int i = 0; i < n; ++i) {
            i64 t;
            cin >> t;
            if (t < 0)
                a[ac++] = -t;
            else if (t > 0)
                b[bc++] = t;
            else
                cc++;
        }
        sort(a, a + ac);
        sort(b, b + bc);
        i64 L = -1e18, R = 1e18;
        while (L < R) {
            i64 mid = (L + R) >> 1;
            if (count(mid) >= k) {
                R = mid;
            } else {
                L = mid + 1;
            }
        }
        cout << L << '\n';
    }
    i64 count(i64 N) {
        debug(N);
        i64 res = 0;
        if (N >= 0)
            res += cc * (ac + bc) + (cc - 1) * cc / 2;
        if (N > 0) {
            res += ac * bc;
            for (int i = 0; i < ac; ++i) {
                i64 q = N / a[i];
                int cnt = upper_bound(a + i + 1, a + ac, q) - a - i - 1;
                res += cnt;
            }
            for (int i = 0; i < bc; ++i) {
                i64 q = N / b[i];
                int cnt = upper_bound(b + i + 1, b + bc, q) - b - i - 1;
                res += cnt;
            }
        } else {
            N *= -1;
            for (int i = 0; i < ac; ++i) {
                i64 q = N / a[i];
                if (N % a[i] == 0)
                    q--;
                int cnt = upper_bound(b, b + bc, q) - b;
                res += bc - cnt;
            }
            // for (int i = 0; i < bc; ++i) {
            //     i64 q = N / b[i];
            //     if (N % b[i] == 0)
            //         q--;
            //     int cnt = upper_bound(a, a + ac, q) - a;
            //     res += ac - cnt;
            // }
        }
        debug(res);
        return res;
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

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

int main () {
  string S, R;
  cin >> S >> R;

  int ans = 0;
  rep(i, 3) {
    if (S.at(i) == R.at(i)) ans++;
  }

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

Measured memory_bytes: 256
H, W, K = map(int, input().split())
C = ["" for _ in range(H)]
for h in range(H):
    C[h] = [s for s in input()]

cnt = 0
for h in range(1 << H):
    for w in range(1 << W):
        black = 0
        for i in range(H):
            if (h >> i & 1) == 1:
                continue
            for j in range(W):
                if (w >> j & 1) == 1:
                    continue
                if C[i][j] == "#":
                    black += 1
        if black == K:
            cnt += 1
print(cnt)


Measured memory_bytes: 73892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
//cout<<fixed<<setprecision(20);



signed main(){
   cout<<fixed<<setprecision(20);

   int n;cin>>n;

   long double sum=0;
   vector<pair<double,double>> x(n);
   rep(i,0,n)cin>>x[i].fs>>x[i].sc;

   sort(all(x));
   do{
      //cout<<"DE"<<endl;
      rep(i,1,n)sum+=pow(pow(x[i].fs-x[i-1].fs,2)+pow(x[i].sc-x[i-1].sc,2),0.5);
   }while(next_permutation(all(x)));


   double fact=1;
   rep(i,1,n+1)fact*=i;
   cout<<sum/fact<<endl;

}


//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,output_format?

Measured memory_bytes: 512
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [[INT()] for _ in range(N)]

for i in range(N):
	A[i].append(i+1)

A.sort(key = lambda x: x[0], reverse = True)

for i in range(N):
	if A[0][1] == i+1:
		print(A[1][0])
	else:
		print(A[0][0])

Measured memory_bytes: 44912
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,ans=1,num=0,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        num+=x;
        if(num<=k)
            ans++;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>A(3);
  int K;
  cin>>A.at(0)>>A.at(1)>>A.at(2)>>K;
  sort(A.begin(),A.end());
  for(int i=0;i<K;i++){
    A.at(2)=2*A.at(2);
  }
  cout<<A.at(0)+A.at(1)+A.at(2)<<endl;
}

  

Measured memory_bytes: 256
N = gets.to_i
a = gets.chomp.split.map(&:to_i)
sum = 0
asum = a.sum
for i in 0..N-1 do
    asum = asum - a[i]
    sum = sum + (((asum) * a[i]) % 1000000007)
end
puts sum % 1000000007

Measured memory_bytes: 35944
import Data.Graph
import qualified Data.Vector.Unboxed as U
import qualified Data.Set as S
import qualified Data.Foldable as F
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as B

solve n m p e = sum $ map count $ cmps where
  count cmp = S.size $ S.intersection (S.fromList cmp) $
    S.fromList [ p U.! (i-1) | i <- cmp ]
  cmps = map F.toList $ components $ buildG (1,n) e

main = do
  [n, m] <- readInts
  p <- U.fromList <$> readInts
  e <- replicateM m $ (\[a,b]->(a,b)) <$> readInts
  print $ solve n m p e

readInts = unfoldr (B.readInt . B.dropWhile (== ' '))
  <$> B.getLine 

Measured memory_bytes: 44412
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

const int MAX = 100005;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
                fac[i] = fac[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
        }
}

// 二項係数計算　n kどちらも10**5程度
long long COM(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long PER(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return (fac[n] * finv[n-k]) % MOD;
}


int n = 100005;
int k ;
vector<vector<int>> graph(n,vector<int>());
ll ans = 1;

void dfs(int i,int par){
        if(par == -1) {ans *= PER(k-1,(int)(graph.at(i).size())); }
        else ans *= PER(k-2,(int)(graph.at(i).size())-1);
        
        if(ans >= MOD) ans %= MOD;    
        
        for(int p:graph.at(i)){
                if(p == par) continue;
                dfs(p,i);
        }
}

int main() {
        COMinit();
        cin >> n >> k;
        rep(i,n-1){
                   int a,b;
                cin >> a >> b;
                --a;--b;
                graph.at(a).push_back(b);
                graph.at(b).push_back(a);
        }
        
        if(n==1 && k==1) cout << 1 << endl;
        else if(k == 1) cout << 0 << endl;
        else{
                ans *= k;
                dfs(0,-1);
                cout << ans << endl;
        }
        
        
        return 0;
}




Measured memory_bytes: 11520
n,m = map(int,input().split())
b = []
a = []
for i in range(n):
    a1 = list(map(int,input().split()))
    a.append(a1)
for k in range(m):
    b1 = int(input())
    b.append(b1)
for i in range(n):
    c = 0
    for j in range(m):
        c1 = a[i][j] * b[j]
        c += c1
    print(c)


Measured memory_bytes: 6012
#include <iostream>

using namespace std;
const int MAXN = 100000;
int arr[MAXN], N;

int main() {
	cin >> N;

	for (int i = 0; i < N; ++i) {
		cin >> arr[i];
	}
	
	bool hl;
	int result = 0;
	if (N == 1) {
		cout << "1";
		return 0;
	}
	
	for (int i = 1; i < N; ++i) {		
		if (arr[i] == arr[i-1]) {
			if (i == N-1) {
				result += 1;
				break;
			}	
			continue;
		} else if (arr[i] >= arr[i-1]) {
			result += 1;
			while (arr[i] >= arr[i-1] && i != N) {
				i++;
			}
			if (i == N-1) {
				result += 1;
				break;
			}
			continue;
		} else if (arr[i] <= arr[i-1]) {
			result += 1;
			while (arr[i] <= arr[i-1] && i != N) {
				i++;
			}
			if (i == N-1) {
				result += 1;
				break;
			}
			continue;
		}
	}
	cout << result;
	return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    int H, W;
    char c;
    cin >> W >> H >> c;
    rep(h, H) {
        rep(w, W) {
            if (w == W / 2 && h == H / 2) {
                cout << c;
            } else if ((h == 0 && w == 0) || (h == 0 && w == W - 1) || (h == H - 1 && w == 0) ||
                       (h == H - 1 && w == W - 1)) {
                cout << "+";
            } else if (h == 0 || h == H - 1) {
                cout << "-";
            } else if (w == 0 || w == W - 1) {
                cout << "|";
            } else {
                cout << ".";
            }
        }
        cout << "\n";
    }
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N,K;
    cin >> N >> K;
    
    vector<vector<int>> G(N);
    
    REP(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> q;
    
    ll ans = K;
    q.push(0);

    vector<bool> seen(N,false);

    while(!q.empty()){
        auto pos = q.front();
        q.pop();
        seen[pos] = true;

        int count;
        if(pos == 0){
            count = K-1;
        }else{
            count = K-2;
        }
        
        for(auto next: G[pos]){
            if(seen[next]){
                continue;
            }else{
                q.push(next);
                if(count <= 0){
                    cout << 0 << endl;
                    return 0;
                }
                ans *= count;
                ans %= MOD;
                count--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9592
using System;

class Program {
  static readonly int MAX = 200010;
  static void Main(string[] args) {
    string[] val1 = Console.ReadLine().Split();
    string[] val2 = Console.ReadLine().Split();
    int N = int.Parse(val1[0]);
    int K = int.Parse(val1[1]);
    
    int[] A = new int[MAX];
    int size = 0;
    for (int i = 0; i < N; ++i) {
      int a = int.Parse(val2[i]);
      if (A[a] == 0) ++size;
      ++A[a];
    }

    Array.Sort(A);
    int ans = 0;
    for (int i = MAX - size; i < MAX - K; ++i) {
      ans += A[i];
    }

    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 31388
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int a[25][25],b[25];
int32_t main(){
	int n,m,c;cin>>n>>m>>c;
	for(int i=1;i<=m;i++){
		cin>>b[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int sum=c;
		for(int j=1;j<=m;j++){
			sum+=(a[i][j]*b[j]);
			//cout<<a[i][j]*b[j]<<"\n";
		}
		//cout<<sum<<"\n";
		//cout<<"\n";
		ans+=(sum>0);
	}
	cout<<ans;
}


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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

int main() {
    int a,b;
    cin >> a >> b;
    int hati,zyuu;
    int ans;
    int k = 0;

    for(int i = 1;i<=1000;i++) {
        int hati = i * 0.08;
        int zyuu = i * 0.10;
        if(hati == a && zyuu == b) {
            cout << i << '\n';
            k++;
            break;
        }
    }

    if(k!=1) {
        cout << -1 << '\n';
    }
    
}

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

const int64_t INF = 1e16;

template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

int64_t dp[200005][6][2];

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    rep(i, N + 1) rep(j, 6) rep(k, 2) dp[i][j][k] = -INF;
    dp[0][2][0] = 0;
    rep(i, N) rep(j, 6) rep(k, 2) {
        if(!k && j + 1 < 6) chmax(dp[i + 1][j + 1][1], dp[i][j][k] + A[i]);
        if(j - 1 >= 0) chmax(dp[i + 1][j - 1][0], dp[i][j][k]);
    }
    if(N % 2) cout << max(dp[N][1][0], dp[N][1][1]) << '\n';
    else cout << max(dp[N][2][0], dp[N][2][1]) << '\n';
    return 0;
}


Measured memory_bytes: 22784
N,M = map(int,input().split())
ab_list = [tuple(map(int,input().split())) for _ in range(M)]

def create_dict(ab_list):
    d = {}
    for a,b in ab_list:
        if a in d:
            d[a].append(b)
        else:
            d[a] = [b]
        if b in d:
            d[b].append(a)
        else:
            d[b] = [a]
            
    return d

# def check():
cnt = 0

for i in range(M):
#     print("i:",i)
    tmp_ab_list = ab_list[:i] + ab_list[i+1:]

    d = create_dict(tmp_ab_list)
#     print("d:",d)
    connected = [0 for _ in range(N+1)]

    def write_connected(a):
#         print(a)
        if connected[a] == 0:
            connected[a] = 1
            if a in d:
                for next_a in d[a]:
                    write_connected(next_a)

    write_connected(1)

#     print(connected)
    if sum(connected) < N:
        cnt += 1
#     return cnt

print(cnt)

Measured memory_bytes: 43888
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int x;
    while(scanf("%d",&x)!=EOF)
    {
    if(x>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    }
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w;
	int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	cin >> h >> w;
	vector<string> a(h);
	rep(i, h) cin >> a.at(i);
	vector<vector<bool>> c(h, vector<bool>(w, false));
	int x, y;
	x = y = 0;
	while(1){
		int n_ = 10;
		rep(i, 4){
			int nx, ny;
			nx = x + dx[i];
			ny = y + dy[i];
			if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if(a.at(ny)[nx] == '#' && c.at(ny).at(nx) == false){
				if(i == 2 || i == 3 || n_ != 10){
					// cerr << "1tst" << endl;
					cout << "Impossible" << endl;
					return 0;
				}
				n_ = i;
			}
		}
		c.at(y).at(x) = true;
		// cerr << x << " " << y << endl;
		if(x == w-1 && y == h-1) break;
		x = x + dx[n_];
		y = y + dy[n_];
	}
	cout << "Possible" << endl;
	return 0;
}


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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()

int main(){
  int n;
  cin >> n;
  vector<int> a;
  REP(i, n){
    int d;
    cin >> d;
    auto it = upper_bound(ALL(a), -d);
    if(it == a.end()){
      a.push_back(-d);
    }else{
      *it = -d;
    }
  }
  cout << a.size() << endl;
  return 0;
}

Measured memory_bytes: 892
#include<math.h>
#include <stdio.h>
int main(void)
{
	int n, i,ten[1000] = { 0 };
	while (1)
	{
		double x=0,x_heikin=0, hensa = 0, bunsan=0, hyohensa=0;
		scanf("%d", &n);
		if (n == 0)
		{
			break;
		}
		for (i = 0; i < n; i++)
		{
			scanf("%d", &ten[i]);
			x = x+ten[i];
		}
		x_heikin=x/n;

		for (i = 0; i < n; i++)
		{
			hensa=hensa+pow(ten[i]-x_heikin,2);
		}
		bunsan = hensa / n;
		hyohensa = sqrt(bunsan);
		printf("%f\n", hyohensa);
	}
	return 0;
}

Measured memory_bytes: 636
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll rui(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n&1) ans=ans*a%mod;
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

int main(){
  ll n; cin >> n;
  mint ans=rui(10,n);
  ans-=2*rui(9,n);
  ans+=rui(8,n);
  cout << ans << endl;
}

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

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> Ls(M), Rs(M);
    for(int i = 0; i < M; ++i){
        cin >> Ls[i] >> Rs[i];
    }

    int Lmax = *max_element(Ls.begin(), Ls.end());
    int Rmin = *min_element(Rs.begin(), Rs.end());
    int ans = Rmin - Lmax + 1;
    ans = max(ans, 0);
    cout << ans << endl;

    



    return 0;
}


Measured memory_bytes: 1024
# F - Silver Fox vs Monster
N,D,A = map(int,input().split())
XH = [0]*N
for i in range(N):
    X,H = map(int,input().split())
    XH[i] = (X,(H-1)//A+1)
XH = sorted(XH, key=lambda x:x[0])
X = [xh[0] for xh in XH]
M = [XH[0][1]]+[XH[i][1]-XH[i-1][1] for i in range(1,N)]
Y = [0]*N
r = 0
for l in range(N):
    r = max(r,l+1)
    while r<N and X[r]<=X[l]+2*D:
        r += 1
    Y[l] = r-1
ans = 0
tmp = 0
for i in range(N):
    tmp += M[i]
    if tmp>0:
        ans += tmp
        r = Y[i]+1
        if r<N:
            M[r] += tmp
        tmp = 0
print(ans)

Measured memory_bytes: 126128
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int main(){
	string s;
	cin >> s;

	int i,j;
	for (i=0; i<s.length(); i++) {
		if (s.substr(i,2)=="BC"){
			s.replace(i,2,"D");
		}
	}

	vector<ll> va,vd;
	ll count=0;
	for (i=0; i<s.length(); i++) {
		if (s[i]=='A'){
			for (j=i; j<s.length(); j++){
				if(s[j]=='A'){
					count++;
				}else{
					break;
				}
			}
			s.replace(i,count,"E");
			va.push_back(count);
			count=0;
		}else if(s[i]=='D'){
			for (j=i; j<s.length(); j++){
				if(s[j]=='D'){
					count++;
				}else{
					break;
				}
			}
			s.replace(i,count,"F");
			vd.push_back(count);
			count=0;
		}
	}

	ll ans=0;
	int indexa=0,indexd=0;
	int tmp;
	for (i=0; i<s.length()-1; i++){
		if (s[i]=='E') {
			tmp=indexd;
			for (j=i+1; j<s.length(); j++) {
				if (s[j]=='B' || s[j]=='C') {
					break;
				} else if (s[j]=='F') {
					ans+=va[indexa]*vd[tmp];
					tmp++;
				}
			}
			indexa++;
		}else if(s[i]=='F'){
			indexd++;
		}
	}

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

Measured memory_bytes: 1408
#include <iostream>
#include <map>
#include <vector>

using namespace std;

long gcd(long a, long b)
{
    if(a < b) return gcd(b, a);
    long r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    long A, B, C, D;
    cin >> A >> B >> C >> D;

    long common = gcd(C, D);
    long lcm = (C/common) * D;


    long a =  B/C - (A-1)/C;
    long b = B/D - (A-1)/D;
    long c = B/lcm - (A-1)/lcm;
    long total = a + b - c;
    long points = B - A + 1;
    cout << points - total << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(ll i = b; i < e; i++)
#define forg(i, b, e, m)	for(ll i = b; i < e; i+=m)

using namespace std;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const ll tam = 10000010;

int dp[11][20000];
bool ac[11];
int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("asd.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, m;
	cin>>n>>m;
	int a;
	while(m--)
	{
		cin>>a;
		ac[a] = 1;
	}
	int pal[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
	fore(i, 0, 11)
		fore(j, 0, n+1)
			dp[i][j] = -50000;
	fore(i, 0, 11)
		dp[i][0] = 0;

	fore(i, 1, 10)
	{
		fore(j, 1, n+1)
		{
			if(j - pal[i-1] >= 0 && ac[i])
				dp[i][j] = 1 + dp[i][j - pal[i-1]];
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
			//cout<<i<<' '<<j<<" -> "<<dp[i][j]<<'\n';
		}
	}
	int i = 10, j = n;
	while(j > 0)
	{
		if(j - pal[i-1] >=0 && ac[i])
		{
			if(dp[i][j - pal[i-1]] + 1 < dp[i-1][j])
			{
				i--;
			}
			else
			{
				j -= pal[i-1];
				cout<<i;
			}
		}
		else
			i--;
	}
	cout<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constralls?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs ll?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 768
n = gets.to_i
ans = Float::INFINITY
divide = []
(n**(0.5)).ceil.times do |i|
    if n%(i+1)==0
        divide << i+1
    end
end

divide.each do |d|
    temp = (d-1)+(n/d)-1
    if ans > temp
        ans = temp
    end
end
puts ans

Measured memory_bytes: 14728
n=int(input())
a_list_sum = []
for i in range(n):
    a_tmp=int(input())
    a_list_tmp=[list(map(int,input().split())) for _ in range(a_tmp)]
    a_list_sum_tmp=[]
    a_list_sum_tmp.append(a_tmp)
    a_list_sum_tmp.append(a_list_tmp)
    a_list_sum.append(a_list_sum_tmp)
    
import itertools
L = [0, 1] #生成する数字
bit_list = list(itertools.product([0, 1], repeat=n))

#bit全探索
for i in range(len(bit_list)):
    count = 0
    #証言者
    for j in range(len(a_list_sum)):
        #正直者について
        if bit_list[i][j] == 1:
            #証言数
            for k in range(len(a_list_sum[j][1])):
                #対象者
                person_id = a_list_sum[j][1][k][0] - 1
                #審議
                is_honest = a_list_sum[j][1][k][1]
                #countが増えることが食い違いを生む
                if bit_list[i][person_id] != is_honest:
                    count += 1
    if count == 0:
        ans = sum(bit_list[i])
print(ans)

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

const double eps = 1e-10;

int n;
//math.hライブラリでy1, y2...とかって変数名が使われてるらしい
double ix1, ix2, ix3, ix4;
double iy1, iy2, iy3, iy4;

//増加率を見る方法
int solve() {
    double Ax = ix2 - ix1;
    double Ay = iy2 - iy1;
    double Bx = ix4 - ix3;
    double By = iy4 - iy3;

    double val = Ax * By - Ay * Bx;
    return (fabs(val) < eps);
}

int main() {
    scanf("%d", &n);
    for(int i=0; i<n; ++i) {
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &ix1, &iy1, &ix2, &iy2, &ix3, &iy3, &ix4, &iy4);

        if(solve()) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
}


Measured memory_bytes: 2040
MAX = 2*10**6+100
fact = [0]*MAX
inv = [0]*MAX
finv = [0]*MAX

def C_init():
    fact[0] = 1
    fact[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    
    for i in range(2, MAX):
        fact[i] = fact[i-1]*i%MOD
        inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
    
def g(r, c):
    res = 0
    
    for i in range(1, r+2):
        res += C(i+c, c)
        res %= MOD
    
    return res
 
r1, c1, r2, c2 = map(int, input().split())
MOD = 10**9+7
C_init()

print((g(r2, c2)-g(r2, c1-1)-g(r1-1, c2)+g(r1-1, c1-1))%MOD)

Measured memory_bytes: 86000
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int i;
        i=n%10;
        n=n/10;
        if(n==9||i==9)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
//#include "Header.h"
struct Drink {
	long long int a, b;
}drink[100000 + 10];
int compdrink(const void*a, const void*b)
{
	return (*(Drink*)a).a - (*(Drink*)b).a;
}
int main()
{
	long long static int n, m, a[100000 + 10], b[100000 + 10],i,j,ans=0;
	cin >> n >> m;
	for (i = 1; i <= n; i++)
	{
		cin >> drink[i].a >> drink[i].b;
	}
	qsort(drink+1, n, sizeof(Drink), compdrink);
	for (i = 1; i <= n; i++)
	{
		//printf("a%db%dans%d\n", drink[i].a, drink[i].b,ans);
		if (m > drink[i].b)
		{
			ans += drink[i].a*drink[i].b;
			m -= drink[i].b;
		}
		else {
			ans += drink[i].a*m;
			break;
		}
	}
	cout << ans << endl;
}


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

#define N 1000000007

using namespace std;

typedef unsigned long long int BigInt;

int s2d(string s, int d) {
    if (d < (int)s.length()) {
        char c = s[s.length()-d-1];
        if (c == '?') {
            return -1;
        }
        return c-'0';
    }
    return 0;
}

BigInt count_ways(string a, string b, string c) {
    BigInt dp[2][61];
    dp[0][0] = 1;
    dp[1][0] = 0;
    for (unsigned int i=1; i<=60; i++) {
        int x = s2d(a, i-1);
        int y = s2d(b, i-1);
        int z = s2d(c, i-1);
        dp[0][i] = 0;
        dp[1][i] = 0;
        for (int xi=0; xi<10; xi++) {
            if (x >= 0 && xi != x) {
                continue;
            }
            if (a.length() == i && xi == 0) {
                continue;
            }
            for (int yi=0; yi<10; yi++) {
                if (y >= 0 && yi != y) {
                    continue;
                }
                if (b.length() == i && yi == 0) {
                    continue;
                }
                for (int zi=0; zi<10; zi++) {
                    if (z >= 0 && zi != z) {
                        continue;
                    }
                    if (c.length() == i && zi == 0) {
                        continue;
                    }
                    switch (xi+yi-zi) {
                        case 0:
                            dp[0][i] += dp[0][i-1];
                            break;
                        case -1:
                            dp[0][i] += dp[1][i-1];
                            break;
                        case 10:
                            dp[1][i] += dp[0][i-1];
                            break;
                        case 9:
                            dp[1][i] += dp[1][i-1];
                            break;
                    }
                    dp[0][i] = dp[0][i]%N;
                    dp[1][i] = dp[1][i]%N;
                }
            }
        }
    }
    return dp[0][60];
}

int main() {
    string a, b, c;
    while (true) {
        cin >> a;
        if (a == "0") {
            return 0;
        }
        cin >> b >> c;
        cout << count_ways(a, b, c) << endl;
    }
}

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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LINF = 4e18;
const ll delta = 96181;

const int M = 4e6 + 5;
const int N = 2e3 + 20;
bitset<M> B;
vector<int> ans;
int n, S;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	B[0] = 1;
	for (int i = 0, x; i < n; i++) {
		cin >> x;
		B = B | (B << x);
		S += x;
	}
	for (int i = 0; i < M; i++)
		if (B[i])
			ans.push_back(i);
	cout << ans[ans.size() / 2] << endl;
}



Measured memory_bytes: 12268
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
using namespace std;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
int main() {
	bitset<3> b;
	cin >> b;
	cout << b.count() << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////

int main() {
	int x; cin >> x;
	if (x >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long LL;

#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define LEN(a) int((a).size())
#define SORT(a) sort((a).begin(), (a).end())
#define CLR(a) memset((a), 0, sizeof(a))

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
    int a, p;
    cin >> a >> p;
    p += a * 3;
    cout << p / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
		return false;
	}
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

signed main(){
    int n=read(),x=read(),t=read();
    
    int T=ceil(n*1.0/x);
    writeln(T*t);
    return 0;
}

Measured memory_bytes: 3712
#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <cassert>
#include <complex>
#include <time.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define DBG1(a) cerr<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;


int main()
{
	//freopen("in.txt","r",stdin);
	string s;
	cin >> s;
	FOR(i, 0, 4) cout << s[i];
	cout << " ";
	FOR(i, 4, 12) cout << s[i];
	cout << endl;

	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

string fie[20]={};


void dfs(int y,int x){
    fie[y][x]='0';
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    rep(i,4){
        if( 0<=y+dy[i] && y+dy[i]<12  &&  0<=x+dx[i] && x+dx[i]<12  &&  fie[y+dy[i]][x+dx[i]]=='1' ){
            dfs(y+dy[i],x+dx[i]);
        }
    }
}

int main(){
    string s;
    while(cin>>s){
        fie[0]=s;
        for(int i=1;i<12;i++) cin>>fie[i];
        
        int c=0;
        rep(i,12){
            rep(j,12){
                if(fie[i][j]=='1'){
                    dfs(i,j);
                    c++;
                }
            }
        }
        cout<<c<<endl;
    }
}

Measured memory_bytes: 1200
#include <stdio.h>
int main(void){
    int n, x, m[1000], ms, a=0, i;
    
    scanf("%d%d",&n,&x);
    for(i=0;i<n;i++) scanf("%d",&m[i]);
    
    ms=m[0];
    for(i=1;i<n;i++){
        if(ms>m[i]) ms=m[i];
    }
    for(i=0;i<n;i++){
        a=a+m[i];
    }
    int b=(x-a)/ms;
    printf("%d\n",b+n);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

string rotate(string s){
	string ans;
	FOR(i,1,s.size())ans += s[i];
	ans += s[0];
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	FOR(i,0,s.size()){
		if(s==t){
			cout << "Yes" << endl;
			return 0;
		}
		s = rotate(s);
	}
	cout << "No" << endl;
}


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

bool check(string s,string t){
    for(int i = 0;i < s.size();++i){
        if(s[i] != t[i] && s[i] != '?'){
            return false;
        }
    }
    return true;
}

int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    string ss;
    bool f = false;
    for(int i = s.size() - t.size(); i >= 0; --i){
        ss = s.substr(i,t.size());

        if(check(ss,t)){
            for(int j = 0; j < t.size(); ++j){
                s[i + j] = t[j];
            }
            f = true;
            break;
        }
    }
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == '?'){
            s[i] = 'a';
        }
    }

    if(f){
        cout << s << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;

    if(n == 4) {
        cout << "Yes" << endl;
        return 0;
    }

    if(c < d) {
        for(int i = a; i <= d-2; i++) {
            if(s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }

    for(int i = b-2; i <= d-2; i++) {
        if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') {
            cout << "Yes" << endl;
            return 0; 
        }
    }

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

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String[] s = scanner.next().split("");
		ArrayList<String> ans = new ArrayList();

		for (String typing : s ) {
			switch (typing) {
			case "0":
			case "1":
				ans.add(typing);
				break;
			case "B":
				if (ans.size() > 0) {
					ans.remove(ans.size() - 1);
				}
				break;
			default:
				break;
			}
		}

		ans.stream().forEach(System.out::print);
		scanner.close();
	}
}


Measured memory_bytes: 27216
n = int(input())
V = [[] for _ in range(n)]
for i in range(n):
    data = list(map(int, input().split(" ")))
    V[i] = data[2:]

answer = [[None, None] for _ in range(n)]

counter = 1


def dfs(v):
    global counter
    if answer[v][0] == None:
        answer[v][0] = counter
        counter += 1
        # ノードの子供の管理
        for e in V[v]:
            dfs(e-1)
        answer[v][1] = counter
        counter += 1


for i in range(len(answer)):
    if answer[i][0] == None:
        dfs(i)

for i in range(len(answer)):
    print(str(i+1) + " " + " ".join(map(str, answer[i])))



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

int64_t comb(int a, int b){
  if(a < b) return 0;

  int64_t res = 1;
  for(int i=0; i<b; i++) res *= a-i;
  for(int i=0; i<b; i++) res /= b-i;
  return res;
}

int main(){
  string S; int K;
  cin >> S >> K;
  int L = S.length();

  // dp1[i][j][0] : 上からiケタ目までで0でない数がj個，かつそこまではNと一致
  // dp1[i][j][1] : 上からiケタ目までで0でない数がj個，かつN未満であることが確定
  vector<vector<vector<int>>> dp(110, vector<vector<int>>(4, vector<int>(2)));

  dp[0][0][0] = 1;

  for(int i=0; i<L; i++){
    for(int j=0; j<4; j++){
      for(int k=0; k<2; k++){
        int nd = S[i] - '0'; // 元の数のiケタ目
        for(int d=0; d<=9; d++){ // iケタ目の候補
          int ni = i+1, nj = j, nk = k;
          if(d != 0) nj++;
          if(nj > K) continue;
          if(nk == 0){
            if(d > nd) continue;
            if(d < nd) nk = 1;
          }
          dp[ni][nj][nk] += dp[i][j][k];
        }
      }
    }
  }

  cout << dp[L][K][0] + dp[L][K][1] << endl;
  

}

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

using namespace std;

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int n,m;
    cin>>n>>m;
    UnionFind tree(n+1);
    int a[n+1];
    rep(i,n){
        cin>>a[i+1];
    }
    rep(i,m){
        int x,y;
        cin>>x>>y;
        tree.merge(x,y);
    }
    int ans=0;
    for (int i=1;i<n+1;i++){
        if (tree.issame(i,a[i])){
            ans+=1;
        }
    }
  cout<<ans<<endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static ll n,x;
	static ll a[100010];
	scanf("%lld%lld",&n,&x);
	rep(i,n)scanf("%lld",&a[i]);
	
	static ll ret = 0;
	rep(i,n){
		if(a[i] > x){
			ret += a[i]-x;
			a[i] = x;
		}
	}
	for(int i = 1 ; i < n ; i ++){
		if(a[i]+a[i-1] > x){
			ret += a[i]+a[i-1]-x;
			a[i] = x-a[i-1];
		}
	}
	cout << ret << endl;

}



Measured memory_bytes: 1024
S = input()
S_ar = S[::-1]
S_len = len(S)
a = (S_len-1)//2
b = (S_len+3)//2-1
S_a = S[0:a]
S_b = S[b:S_len]

if S == S_ar:
    if S_a == S_a[::-1]:
        if S_b == S_b[::-1]:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
<?php
fscanf(STDIN, '%d %d %d', $a, $b, $c);
fscanf(STDIN, '%d', $k);
for($i = 0; $i < $k; $i++) {
    $mx2 = max($a, $b, $c) * 2;
    if($a > $b && $a > $c) {
        $a = $mx2;
    } elseif($b > $a && $b > $c) {
        $b = $mx2;
    } else {
        $c = $mx2;
    }
}
echo $a + $b + $c;

Measured memory_bytes: 4732
package main

import "fmt"

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	if b <= a {
		fmt.Println("delicious")
	} else if b <= a+x {
		fmt.Println("safe")
	} else {
		fmt.Println("dangerous")
	}
}


Measured memory_bytes: 512
<?php
    fscanf(STDIN,"%d%d",$N,$M);
    
    for($i=1;$i<=$M;$i++){
        list($l,$r) = array_map('intval',explode(" ",trim(fgets(STDIN))));
        
        $L[$i] = $l;
        $R[$i] = $r;
    }
    if(min($R) - max($L) + 1<0){
        echo "0";
        exit;
    }
    echo min($R) - max($L) + 1;

    
?>

Measured memory_bytes: 24672
/*
    Vishal Raj
    IIT Kharagpur
*/

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,l,r) for( int (i) = (l); (i) < (r); (i)++ )

void upd( int & a, int b, int c, int d ) {
    a = max(a,b+d);
    a = max(a,c+d);
}

int main() {
    int n; cin>>n;
    vector<vector<int>> dp(2,vector<int>(3,0));
    FOR(i,0,n) {
        int a,b,c;
        cin>>a>>b>>c;
        int u = i%2;
        upd(dp[u][0],dp[1-u][1],dp[1-u][2],a);
        upd(dp[u][1],dp[1-u][0],dp[1-u][2],b);
        upd(dp[u][2],dp[1-u][1],dp[1-u][0],c);
        // cout<<dp[u][0]<<" "<<dp[u][1]<<" "<<dp[u][2]<<"\n";
    }
    cout<<max({dp[(n-1)%2][0],dp[(n-1)%2][1],dp[(n-1)%2][2]})<<"\n";
}

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


int main() {
    string  a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2];
    
    cout << endl;
}


Measured memory_bytes: 256