akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(void)
{
    int n;
    int p[21];
    int count = 0;
    
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> p[i];
    }

    for (int i= 1; i < n-1; i++) {
        if (p[i-1] < p[i] && p[i] < p[i+1]) {
            count++;
        } else if (p[i+1] < p[i] && p[i] < p[i-1]) {
            count ++;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	long long r = 0, g = 0, b = 0;
	for (int i = 0; i < N; i++) {
		if (S.at(i) == 'R') r++;
		if (S.at(i) == 'G') g++;
		if (S.at(i) == 'B') b++;
	}

	long long ans = r * g * b; // 順を考えずにR,G,Bから1つずつ選ぶ。
	// cout << ans << endl;

	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			int k = j + (j - i);
			// printf("%d %d %d\n",i,j,k);
			if (k >= N) continue;
			if (S.at(i) != S.at(j) && S.at(j) != S.at(k) && S.at(k) != S.at(i)) {
				ans -= 1;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 200005
using namespace std;
using P = pair<int,int>;
int n;
P in[M];
int main()
{
    while (~scanf("%d", &n)) {
        REP(i,1,n) scanf("%d %d",&in[i].second,&in[i].first);
        sort(in+1, in+n+1);

        int cur = 0;
        bool flg = false;
        REP(i,1,n) {
            cur += in[i].second;
            if (cur > in[i].first) flg = true;
        }
        puts(flg ? "No" : "Yes");
    }
    return 0;
}


Measured memory_bytes: 1792
from collections import deque
n, m = map(int, input().split())
edge = [[] for i in range(n)]
cnt = [0] * n
ans = [0] * n
for i in range(n + m - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    cnt[b - 1] += 1
Q = deque([cnt.index(0)])
while Q:
    p = Q.popleft()
    for u in edge[p]:
        cnt[u] -= 1
        if cnt[u] == 0:
            ans[u] = p + 1
            Q.append(u)
for i in range(n):
    print(ans[i])

Measured memory_bytes: 27672
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct{
  int p,l,r,h,flag;
}Node;
Node T[MAX];

int depth(int);
int sub(int);
int deg(int);
int height(int);

int main(){

  int n,i,j,node,degree,child,left;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
    T[i].h = 0;
    T[i].flag = 0;
  }
  for(i = 0; i < n; i++){
    scanf("%d",&node);
    for(j = 0; j < 2; j++){
      scanf("%d",&child);
      if(child != -1){
        T[child].p = node;
        if(j == 0)
          T[node].l = child;
        else
          T[node].r = child;


      }
    }
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth\
 = %d, height = %d, ",i,T[i].p,sib(i),deg(i),depth(i),height(i));
    if(T[i].p == NIL)
      printf("root\n");
    else if(T[i].l == NIL && T[i].r == NIL)
      printf("leaf\n");
    else
      printf("internal node\n");
    //    print_degree(T[i].l);
  }
  return 0;
}

int depth(int node){

  int count=0;

  while(T[node].p != NIL){
    count++;
    node = T[node].p;
  }
  return count;
}

int sib(int i){

  int parent,right,left;

  parent = T[i].p;
  left = T[parent].l;
  right = T[parent].r;

  if(parent == -1)
    return -1;
  if(i == left)
    return right;
  else
    return left;
}

int deg(int i){

  int parent,count=0;

  if(T[i].l != NIL)
    count++;
  if(T[i].r != NIL)
    count++;
  return count;
}

int height(int i){

  int left = 0,right = 0;

  if(T[i].l != NIL){
    left = height(T[i].l) + 1;
  }
  if(T[i].r != NIL){
    right = height(T[i].r) + 1;
  }
  if(right > left)
    return right;
  else
    return left;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

unordered_map<ll,double> mp;
double cal(ll n) {
    if(mp.find(n)!=mp.end()){
        return mp[n];
    }
    int s = 0;
    ll a = n;
    while(n){
        s+=n%10;
        n/=10;
    }
    double ans=(double)a/s;
    mp[n]=ans;
    return (double)a/s;
}

int main() {
    ios::sync_with_stdio(false);
    ll K, ans = 0;
    cin >> K;
    vector<ll> anss;
    for (ll i = 0; i <= 15; ++i)
	{
		for (ll j = 1; j <= 1000; ++j)
		{
			if (i == 0 && j == 1) continue;
			ll tmp = j * pow(10LL, i);
			--tmp;
			anss.push_back(tmp);
		}
	}
    sort(anss.begin(),anss.end());
    anss.erase(std::unique(anss.begin(), anss.end()), anss.end());
    REP(i,0,anss.size()) {
        REP(j,i+1,anss.size()){
            if(cal(anss[i]) > cal(anss[j])) {
                anss.erase(anss.begin() + i);
                --i;
                break;
            }
        }
    }
    REP(i,0,K){
        cout<<anss[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define M 1000000007
#define N 100005
int u[N*2],v[N*2],p[N],r[N*2],w[N*2],n,m,i,j,k=0;

struct zb{
    int x, y,id,prx,pry;
}a[N];
int cmp(const int i, const int j){return w[i]<w[j];}
int cmp1(struct zb i, struct zb j){return i.x<j.x;}
int cmp2(struct zb i, struct zb j){return i.y<j.y;}
int fin(int x){return p[x]==x?x:p[x]=fin(p[x]);}
LL kru()
{
    LL ans=0;
    for(int i=0;i<n;i++)
        p[i]=i;
    for(int i=0;i<m;i++)
        r[i]=i;
    sort(r,r+m,cmp);
    for(int i=0;i<m;i++)
    {
        int e=r[i];
        int x=fin(u[e]);
        int y=fin(v[e]);
        if(x!=y){ans+=w[e];p[x]=y;}
    }
    return ans;
}

int main()
{
    scanf("%d",&n);
    m=(n-1)*2;
    for(i=0;i<n;i++)
        {scanf("%d%d",&a[i].x,&a[i].y);a[i].id=i;}
    sort(a,a+n,cmp1);
    for(i=n-1;i>0;i--)
        {a[i].x=a[i].x-a[i-1].x;a[i].prx=a[i-1].id;}
    for(i=1;i<=n-1;i++)
    {
        u[k]=a[i].id;v[k]=a[i].prx;w[k++]=a[i].x;
    }
    sort(a,a+n,cmp2);
    for(i=n-1;i>0;i--)
        {a[i].y=a[i].y-a[i-1].y; a[i].pry=a[i-1].id;}
    for(i=1;i<=n-1;i++)
    {
        u[k]=a[i].id;v[k]=a[i].pry;w[k++]=a[i].y;
    }
    printf("%lld",kru());
    return 0;
}


Measured memory_bytes: 6140
#include<bits/stdc++.h>
using namespace std;
//#define debug 1

const int mod=2019;

int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int l,r;
	cin>>l>>r;
	if(r-l >=2018) {cout<<"0"<<endl;return 0;}
	l%=2019;r%=2019;
	if(r<=l) r+=2019;
	
	int ans=2020;
	for(int i=l;i<r;i++)
		for(int j=i+1;j<=r;j++) {
#ifndef debug
			ans=min(ans,((i*j)%2019));
#else
			if(((i*j)%2019) < ans) {
				ans=(i*j)%2019;
				cout<<"Change!"<<endl;
				cout<<i<<" "<<j<<endl;
			}
#endif
		}
	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import math
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
 
x = Ii()
ans = 0
k = 100
while x > k:
  tax = k//100
  k += tax  
  ans += 1
  
print(ans)

Measured memory_bytes: 9112
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int X[100];

int main()
{
	int N, ans = 10000000;

	cin >> N;
	rep(i, N) cin >> X[i];

	repc(x, 1, 100) {
		int sum = 0;
		rep(i, N) sum += (X[i] - x) * (X[i] - x);
		ans = min(ans, sum);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
S = input()
MOD = 2019
# L = [0 for _ in range(2019)]
L = []
N = len(S)
t = 0
k = 1
for i in range(N - 1, -1, -1):
    t = (t + int(S[i]) * k) % MOD
    L.append(t)
    k *= 10
    k %= MOD
R = [0 for _ in range(2019)]
R[0] = 1
for l in L:
    R[l] += 1
res = 0
for r in R:
    res += (r * (r - 1)) // 2
print(res)


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

using namespace std;

int main()
{
  long long int n,w,s;
  cin>>n>>w>>s;
	for(int i=0;i<w;i++)
		cout<<s<<" ";
	if(s!=1000000000)
		for(int i=0;i<n-w;i++)
		cout<<1000000000<<" ";
	if(s==1000000000)
		for(int i=0;i<n-w;i++)
		cout<<1<<" ";
}

Measured memory_bytes: 1280
def rensa(s,i):
    a=["A","C","G","T"]
    num=i+1 
    l=len(s)
    check=0
    combo=1
    while check==0 and num<=l-1:
        if any(s[num]==a[j] for j in range(4)):
            combo+=1
            num+=1
        else:
            check=1
    return combo

s=input()
l=len(s)
a=["A","C","G","T"]
max=0
for i in range(l):
    if any(s[i]==a[j] for j in range(4)):
        combo=rensa(s,i)
        if combo>max:
            max=combo
print(max)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	ll N, H, W;
	cin >> N >> H >> W;
	ll ans = 0;
	for(ll i = 0; i < N; i ++){
		ll a, b;
		cin >> a >> b;
		if(a >= H && b >= W)ans ++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <stack>
//#include <atcoder/dsu>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
//using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void)
{
    lli N, A, B;
    cin >> N >> A >> B;
    lli mxsum = (N - 1) * B + A;
    lli mnsum = (N - 1) * A + B;
    if (mxsum - mnsum >= 0)
    {
        cout << mxsum - mnsum + 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3580
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	string s;
	cin >> s;
	reverse(ALL(s));
	cout << s << endl;
	
}



}
int main() try{
	mainmain();
}
catch(...){}

Measured memory_bytes: 1172
A,B,Q=gets.split.map(&:to_i)
INF = 10**22
s,t=[-INF],[-INF]
ans = []
A.times do
  s << gets.to_i
end
B.times do
  t << gets.to_i
end
s << INF
t << INF
Q.times do
  x = gets.to_i
  a = s.bsearch_index{|si| x <= si}.to_i
  b = t.bsearch_index{|ti| x <= ti}.to_i
  res = INF
  [s[a-1], s[a]].each do |si|
    [t[b-1], t[b]].each do |ti|
      d1 = (si-x).abs + (si-ti).abs
      d2 = (ti-x).abs + (si-ti).abs
      res = [res, d1, d2].min
    end
  end
  ans << res
end
puts ans


Measured memory_bytes: 5812
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	
	ll x,y;
	cin>>x>>y;
	int ans=1;
	while(1){
		x*=2;
		if(x>y){
			break;
		}
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

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



int main(){
	int N; cin >> N;
	vector<Pi> P(N);
	rep(i,N) cin >> P[i].first,P[i].second = i;
	sort(P.rbegin(),P.rend());
	multiset<int> s;
	s.insert(-1);
	s.insert(-1);
	s.insert(N);
	s.insert(N);
	s.insert(P[0].second);
	ll ans = 0;
	repr(i,1,N){
		auto p1 = s.lower_bound(P[i].second);
		p1++;
		int n1 = *p1;
		p1--;
		int n2 = *p1;
		p1--;
		int n3 = *p1;
		p1--;
		int n4 = *p1;
		ans += (ll)(n1-n2)*(P[i].second-n3)*P[i].first;
		ans += (ll)(n2-P[i].second)*(n3-n4)*P[i].first;
		s.insert(P[i].second);
	}
	cout << ans << endl;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 1000030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
map<pair<int,int> ,int> mp;
int h,w,n;
int dx[9]={-1,0,1,-1,0,1,-1,0,1};
int dy[9]={-1,-1,-1,0,0,0,1,1,1};
ll cnt[10];
int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>h>>w>>n;
  cnt[0]={(ll)(h-2)*(w-2)};
	rep(i,0,n)
	{
		int x,y;
		cin>>x>>y;
		rep(j,0,9)
		{
			int a,b;
			a=x+dx[j];
			b=y+dy[j];
			if(a<=1||a>=h||b<=1||b>=w)
			continue;
			cnt[mp[{a,b}]++]--;
			cnt[mp[{a,b}]]++;
		}
	}
	rep(i,0,10)
	cout<<cnt[i]<<endl;
}

Measured memory_bytes: 56576
R, C, N = gets.split.map(&:to_i)
left, right, top, bottom = [], [], [], []
(1..N).each do |i|
    x1, y1, x2, y2 = gets.split.map(&:to_i)
    arrs = [[x1, y1], [x2, y2]]
    next unless arrs.all?{|x, y|
        x == 0 || x == R || y == 0 || y == C
    }
    [[x1, y1], [x2, y2]].each do |x, y|
        if x == 0
            top.push([i, y])
        elsif x == R
            bottom.push([i, y])
        elsif y == 0
            left.push([i, x])
        elsif y == C
            right.push([i, x])
        end
    end
end

order = top.sort_by{|arr|arr[1]}.map{|arr|arr[0]}
order.concat(right.sort_by{|arr|arr[1]}.map{|arr|arr[0]})
order.concat(bottom.sort_by{|arr|-arr[1]}.map{|arr|arr[0]})
order.concat(left.sort_by{|arr|-arr[1]}.map{|arr|arr[0]})

stack = []
order.each do |i|
    if stack.length > 0 && stack[-1] == i
        stack.pop
    else
        stack.push(i)
    end
end

puts stack.length == 0 ? 'YES' : 'NO'

Measured memory_bytes: 25156
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

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

	int a,b,c;
	cin >> a >> b >> c;

	int num[10];
	rep(i,10) num[i] = 0;
	num[a]++;
	num[b]++;
	num[c]++;

	if(num[5] == 2 && num[7] == 1) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[1001];
int main()
{
	int w,n,i;
	scanf("%s",s);
	getchar();
	scanf("%d",&w);
	n=strlen(s);
	for(i=0;i<n;i++)
	{
		if(i%w==0)
		{
			printf("%c",s[i]);
		}
	}
	return 0;
}

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

int main() {
    int N;
    char S;
    set<char> t;
    cin >> N;

    rep(i,N) {
        cin >> S;
        t.insert(S);
    }

    if(t.size() == 3)
        cout << "Three";
    else
        cout << "Four";
    cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,m,d,i,j,k,flg,cnt;
	char nm[101][101];
	scanf("%d %d %d",&n,&m,&d);
	for(i=0;i<n;i++) scanf("%s",nm[i]);
	cnt=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			flg=1;
			for(k=i;k<i+d;k++){
				if(k>=n){
					flg=0;
					break;
				}
				if(nm[k][j]=='#'){
					flg=0;
					break;
				}
			}
			if(flg==1) cnt++;
			flg=1;
			for(k=j;k<j+d;k++){
				if(k>=m){
					flg=0;
					break;
				}
				if(nm[i][k]=='#'){
					flg=0;
					break;
				}
			}
			if(flg==1) cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define ll long long 
#define N 3005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define piii pair<int, pii>
#define print(x) cout << #x << "=" << x << "\t";
#define endl "\n"
#define newline cout << endl;

int n;
ll a[N];
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); 
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=1;i<=n;i++) {
        dp[i][i] = a[i];
        a[i] += a[i - 1];
    }
    for(int len=2;len<=n;len++)
        for(int j=1;j+len-1<=n;j++)
            dp[j][j+len-1] = a[j+len-1] - a[j-1] - min(dp[j][j+len-2], dp[j+1][j+len-1]);
    cout << 2 * dp[1][n] - a[n];
    return 0;
}


Measured memory_bytes: 70016
def f(v,e):
  for x in v:
    if len(e[x]) == 1:
      y = e[x][0]
      v.remove(x)
      e[x] = []
      e[y].remove(x)
      return f(v,e)+1
  return 0

n,m = map(int,input().split())
v = list(range(1,n+1))
e = [[]]*(n+1)
for _ in [0]*m:
  x,y = map(int,input().split())
  e[x] = e[x] + [y]
  e[y] = e[y] + [x]
print(f(v,e))
  

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    int tmp = 1;
    imfor(i, n) {
        if (tmp * 2 < tmp + k) {
            tmp *= 2;
        }
        else {
            tmp += k;
        }
    }
    cout << tmp << endl;
}

Measured memory_bytes: 256
import math
N = int(input())
t = a = 1
for i in range(N):
  T, A = map(int, input().split())
  qT = (t+T-1)//T
  qA = (a+A-1)//A
  q = max(qT, qA)
  t = T*q
  a = A*q
r = t+a
print(r)


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

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

  string U;
  for(int i=0;i<2*N;++i){
    if(i%2==0){
      U.push_back(S.at(i/2));
    }
    else{
      U.push_back(T.at((i-1)/2));
    }
  }

  cout<<U<<endl;
}


Measured memory_bytes: 256
def gcd(n, m):
    x = max(n, m)
    y = min(n, m)

    while y != 0:
        x, y = y, x % y

    return x


def main():
    a, b, c, d = list(map(int, input().split()))

    # count of factors of c which are less than or equal to b
    fclb = b // c
    # count of factors of d which are less than or equal to b
    fdlb = b // d

    # least common multiple
    lcm = c * d // gcd(c, d)  # greatest common divisor

    duplicated_b = b // lcm
    count_b = b - fclb - fdlb + duplicated_b

    fcla = (a - 1) // c
    fdla = (a - 1) // d
    duplicated_a = (a - 1) // lcm
    count_a = (a - 1) - fcla - fdla + duplicated_a

    score = count_b - count_a
    print(score)


main()

Measured memory_bytes: 3064
#include <iostream>

int fr[11];

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

    fr[a]++;
    fr[b]++;
    fr[c]++;

    if((fr[5]==2)&&(fr[7]==1)) std::cout <<"YES\n";
    else std::cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,r;
string s,s1,s2;
vl v,a;
//vl vis,d;
ll dp[101][100001],f[101][100001];

int main() {
    IOS;
    cin>>n>>k;
    v.resize(n);cin>>v;
    fo(i,v[0]+1)dp[0][i]=1,f[0][i]=i+1;
    for(int i=v[0]+1;i<=k;i++)f[0][i]=v[0]+1;
    for(int i=1;i<n;i++){
        fo(j,k+1){
            dp[i][j]=(f[i-1][j]-(j-v[i]-1>=0?f[i-1][j-v[i]-1]:0)+mod)%mod;
            f[i][j]=(j>0?f[i][j-1]:0)+dp[i][j];
            f[i][j]%=mod;
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<el;
        }
    }
    cout<<dp[n-1][k];
    return 0;
}



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

int main() {
  int a,b;
  cin >> a >>b;
  vector<int>vec1(2*b);
  for(int i=0; i<2*b;i++)
    cin >> vec1.at(i);
  for(int i=0;i<a;i++){
    int sum =0;
    for(int j=0;j<2*b;j++){
      if(i+1 == vec1.at(j))
        sum++;
    }
    cout << sum <<endl;
  }      
    
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    c:usize,
    }
    println!("{}",if a<=c&&a+b>=c{"YES"}else {"NO"})
}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=500010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b,c;
    a=read(), b=read(), c=read();
    printf("%lld\n",min(a*b,c));
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

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

    //またいだ時
    if(a*b<0 || c*d<0){
        cout << max(a*c,b*d) << endl;
        return 0;
    }

    //またがないとき
    //両方正もしくは負
    if(a >= 0 && c>= 0){
        cout << b*d << endl;
        return 0;
    }
    if(b<=0 && d<=0){
        cout << a*c << endl;
        return 0;
    }
    //

    cout << max(a*d,b*c) << endl;


    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;

const ll mod = 1000000007;

int main() {
	ll x;
	cin >> x;

	ll cur = 100;
	ll year = 0;
	while(cur < x) {
		year++;
		
		cur = cur + cur / 100;
	}
	cout << year << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<bool,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}

//a,b x
int main(){
	ll N,M; cin>>N>>M;
	vector<P> yes(N+1,mp(false,1));
	ll ans=0;
	yes[1].a=true;
	rep1(i,M){
		ll A,B; cin>>A>>B;
		if(yes[A].a==true){
			if(yes[A].b==1){
				yes[A].a=false;
				yes[B].a=true;
			}
			else{
				yes[B].a=true;
			}
		}
		yes[A].b--;
		yes[B].b++;
	}
	rep1(i,N){
		if(yes[i].a==true) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 1792
import math

A, B, H, M = [int(i) for i in input().split()]

alpha = (H + M/60)/12 * 2*math.pi
beta = M/60 * 2*math.pi

X = A*math.cos(alpha) - B*math.cos(beta)
Y = A*math.sin(alpha) - B*math.sin(beta)

print(math.sqrt(X*X + Y*Y))


Measured memory_bytes: 9440
# coding: utf-8
from operator import itemgetter

n = int(input())
s = []
p = []
for i in range(n):
    x, l = map(int, input().split())
    s.append(x - l)
    p.append(x + l)
c = zip(s, p)
c = sorted(c, key=itemgetter(1))
s, p = zip(*c)

arm = p[0]
ans = 1
for i in range(1, n):
    if arm <= s[i]:
        ans += 1
        arm = p[i]
print(ans)


Measured memory_bytes: 26784
# encoding: utf-8
# N = int(input())
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# AB = [list(map(int, input().split())) for i in range(N)]

S = input()

if len(S) == 2: print(S)
else: print(S[::-1])

Measured memory_bytes: 2940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String[] s = new String[3];
            for (int i = 0; i < 3; i++)
                s[i] = in.next();
            int[] p = new int[3];
            int cp = 0;
            while (p[cp] < s[cp].length())
                cp = s[cp].charAt(p[cp]++) - 'a';
            out.println((char) ('A' + cp));
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return c >= 33 && c <= 126;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();

            int b = readByte();
            while (!isPrintableChar(b))
                b = readByte();

            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }

            return sb.toString();
        }

    }
}



Measured memory_bytes: 21460
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N1 1000
#define N2 100
int get,A[N1];

void push(int x){
  A[++get]=x;
}
 
int pop(){
  get--;
 
  return A[get+1];
}
 
int main()
{

  char a[N2];
  int x=0,y=0;
  get=0;
 
 
  while(scanf("%s",a)!=EOF){
    if(a[0]=='+'){
      x=pop();
      y=pop();
      push(y+x);
    }
    else if(a[0]=='-'){
      x=pop();
      y=pop();
      push(y-x);
    }
    else if(a[0]=='*'){
      x=pop();
      y=pop();
      push(x*y);
    }
    else {
      push(atoi(a)); 
    }
  }
 
  printf("%d\n",pop());
 
  return 0;
}



Measured memory_bytes: 2076
#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
int main() {
    
    char str1[500], str2[501], str3[501];

    scanf("%s %s", str1, str2);
    
    strcpy(str3, str1);
    
    strcat(str1, str3);

    if (strstr(str1, str2) == NULL ) {
        
        printf("No\n");

    } else {
        
        printf("Yes\n");
    
    }
}




Measured memory_bytes: 3152
import bisect
from math import ceil

N,H,*abf = map(int, open(0).read().split())
ab = [abf[i:i+2] for i in range(0, len(abf), 2)]
a = sorted([x[0] for x in ab],reverse=True)
b = sorted([x[1] for x in ab],reverse=True)
br = list(reversed(b))
bs = bisect.bisect_right(br,a[0])
ans = 0
rem = H
for i in range(N-bs):
    rem -= b[i] 
    ans += 1
    if rem <= 0:
        print(ans)
        break
else:
    ans += ceil(rem/a[0])
    print(ans)

Measured memory_bytes: 26020
#include<bits/stdc++.h>
using namespace std;
main()
{
  int n;
  cin>>n;
  string a[10];
  a[0]="pon";
    a[1]="pon";
    a[2]="hon";
    a[3]="bon";
    a[4]="hon";
    a[5]="hon";
    a[6]="pon";
    a[7]="hon";
    a[8]="pon";
    a[9]="hon";
  cout<<a[n%10];
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
vector<int>vec[2];
int x, y;

int wid(){
    set<int>st[2];
    st[0].insert(0);
    for(int i=0;i<vec[0].size();i++){
        for(auto it = st[i%2].begin();it!=st[i%2].end();it++){
            st[(i+1)%2].insert((*it)+vec[0][i]);
            st[(i+1)%2].insert((*it)-vec[0][i]);
        }
        st[i%2].clear();
    }
    for(auto it = st[vec[0].size()%2].begin(); it!=st[vec[0].size()%2].end();it++){
        if((*it)==x)return 1;
    }
    return 0;
}
int hei(){
    set<int>st[2];
    st[0].insert(0);
    for(int i=0;i<vec[1].size();i++){
        for(auto it = st[i%2].begin();it!=st[i%2].end();it++){
            st[(i+1)%2].insert((*it)+vec[1][i]);
            st[(i+1)%2].insert((*it)-vec[1][i]);
        }
        st[i%2].clear();
    }
    for(auto it = st[vec[1].size()%2].begin(); it!=st[vec[1].size()%2].end();it++){
        if((*it)==y)return 1;
    }
    return 0;
}

int main(){
    string s;
    cin>>s;    
    cin>>x>>y;
    for(int i=0, flg = 1, p = 0;i<s.size();i++){
        if(flg && s[i]=='F'){
            x--;
            continue;
        }
        else flg = 0;
        if(s[i]=='T'){
            p = (p+1)%2;
            vec[p].push_back(0);
        }
        else{
            vec[p][vec[p].size()-1]++;
        }
    }
    if(wid()&&hei()){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)

int main() { 
  double a,n;cin>>a>>n;
  cout << ceil((a+n)/2);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  if(a >= 3 && b <= 20){
    for(int i = 0; i <2; i++){
      if(a > b){
        ans += a;
        a = a -1;
          }else{
        ans += b;
        b = b - 1;
      }
    }
    cout << ans << endl;
  }else{
    return 0;
  }
}


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

using namespace std;

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

    int N; cin>>N;
    vector<int> A(N);
    for (auto& a : A) cin>>a;
    sort(A.begin(), A.end());
    vector<pair<int, int>> mem;
    int l = 0, r = N-1;
    while (l < r) {
        auto dif = A[r] - A[l];
        if (r-l==1) {
            mem.emplace_back(A[r], A[l]);
            A[l] = dif;
            r--;
        } else {
            if (dif - A[r - 1] >= A[l + 1] + dif) {
                mem.emplace_back(A[r], A[l]);
                A[r] = dif;
                l++;
            } else {
                mem.emplace_back(A[l], A[r]);
                A[l] = -dif;
                r--;
            }
        }
    }
    cout << A[l] << endl;
    for (auto p : mem)
        cout << p.first << ' ' << p.second << endl;

    return 0;
}



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  string s;
  int last;
  int mn;
};

vector<ST> v1, v2;

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

  rep(i,N){
    ST st;
    cin >> st.s;
    int mn = 0;
    int now = 0;
    rep(j,st.s.size()){
      if(st.s[j] == ')') now--;
      else now++;
      mn = min(mn, now);
    }
    st.last = now;
    st.mn = mn;

    if(st.last >= 0){
      v1.push_back(st);
    }
    else {
      reverse(ALLOF(st.s));
      mn = 0;
      now = 0;
      rep(j,st.s.size()){
        if(st.s[j] == ')') now++;
        else now--;
        mn = min(mn, now);
      }
      st.last = now;
      st.mn = mn;
      v2.push_back(st);
    }
  }

  sort(ALLOF(v1), [](const ST& a, const ST& b){
    return a.mn > b.mn;
  });
  sort(ALLOF(v2), [](const ST& a, const ST& b){
    return a.mn > b.mn;
  });

  int lnow = 0, rnow = 0;
  int lmn = 0, rmn = 0;
  rep(i,v1.size()){
    lmn = min(lmn, lnow + v1[i].mn);
    lnow += v1[i].last;
  }
  rep(i,v2.size()){
    rmn = min(rmn, rnow + v2[i].mn);
    rnow += v2[i].last;
  }

  //cout << lmn << " " << rmn << " " << lnow << " " << rnow << endl;
    
  if(lmn >= 0 && rmn >= 0 && lnow == rnow){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;

int main()
{
      int l, r, ans = inf;
      bool f = false;
      cin >> l >> r;
      for (int i = l; i <= l + 2019; i ++) {
            for (int j = i + 1; j <= l + 2019; j ++) {
                  if (l <= i && i <= r && l <= j && j <= r) {
                        ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
                  }
            }
      }
      cout << ans << endl;
      return 0;
}











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

using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> vec(N,0);

    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        vec[a]++;
        vec[b]++;
    }
    string ans="YES";
    for(int i=0; i<N; i++){
        if(vec[i]%2==1){
            ans="NO";
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
		int syaink = sc.nextInt();
        if(syaink%10==3){
          System.out.println("bon");
        }else if(syaink%10==0||syaink%10==1||syaink%10==6||syaink%10==8){
          System.out.println("pon");
        }else{
          System.out.println("hon");
        }
}
}

Measured memory_bytes: 35708
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

int A[200010];
int main()
{
	int K, N;
	cin >> K >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	int ans = mod;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans = min(ans, K - (K - (A[N - 1] - A[i])));
			ans = min(ans, K - (A[i + 1] - A[i]));
		}
		else if (i == N - 1) {
			ans = min(ans, K - (A[i] - A[i - 1]));
			ans = min(ans, K - (K - (A[N - 1] - A[0])));
		}
		else {
			ans = min(ans, K - (A[i] - A[i - 1]));
			ans = min(ans, K - (A[i + 1] - A[i]));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e18;
ll mod=998244353;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M)%M;
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

void solve()
{
  ll a,b,c;
  cin>>a>>b>>c;
  if(a>=c || b>=c || (a+b)>=c)
   {cout<<"No"<<endl;return ;}
  ll t=c-(a+b);
  t=t*t;
  if(a*b>=(t))
    cout<<"No"<<endl;
  else if((a*b)>=(MAX/4))
    cout<<"No"<<endl;
  else
  {
      if(4*a*b<(t))
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
  }

}

int main(){
    boost;
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int>> v(n);
  for(int i=0;i<n;++i)cin>>v[i].first>>v[i].second;
  sort(v.begin(),v.end());
  cout<<v[n-1].first+v[n-1].second<<"\n";
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int zo[2][4010]={};
int dp[2][4010];
char ar1[4010],ar2[4010];
int main(){
	int l1,l2,I,O,hog,cnt;
	while(true){
		cin>>ar1;
		if(cin.eof()) break;
		cin>>ar2;
		l1=strlen(ar1);
		l2=strlen(ar2);
		I=1;O=0;
		memset(zo[I],0,sizeof(zo[I]));
		memset(dp[I],0,sizeof(dp[I]));
		cnt=0;
		for(int i=0;i<l1;i++){
			for(int j=0;j<l2;j++){
				if(ar1[i]==ar2[j]){
					if(i!=0&&j!=0){
						zo[O][j]=zo[I][j-1]+1;
					}
					else{
						zo[O][j]=1;
					}
				}
				else{
					zo[O][j]=0;
				}
			}
			for(int j=0;j<l2;j++){
				cnt=max(cnt,zo[O][j]);
			}
			swap(I,O);
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n--;
    int ans = 0;
    for(int i=1;i<=n;i++){
        int num = n / i;
        ans += num;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3532
N = int(input())
A = list(map(int, input().split()))

sortA = sorted(set(A)) + [float('inf')]

def isOk(n):
    x = sortA[n]
    count = [0 for _ in range(2 * N + 1)]
    count[N + 1] = 1

    i = N + 1
    s = 1
    result = 0

    for a in A:
        if a >= x:
            i += 1
            s += count[i]
        else:
            s -= count[i]
            i -= 1
        result += s
        count[i] += 1
        s += 1

    if result >= N * (N + 1) // 4:
        return False
    else:
        return True


left = 0
right = len(sortA) - 1

while right - left > 1:
    mid = (left + right ) // 2

    if isOk(mid):
        right = mid
    else:
        left = mid

print(sortA[left])

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 2e6 + 10;
const int Mod = 1e9 + 7;

int mul(long long x, int y){
	return x * y % Mod;
}

void add(int &x, int y){
	x += y;
	if(x >= Mod) x -= Mod;
}

int Pow(int x, int e){
	int ret = 1;
	while(e){
		if(e & 1) ret = mul(ret, x);
		x = mul(x, x);
		e >>= 1;
	}
	return ret;
}

int rfac[N], fac[N];

void init(int n){
	fac[0] = 1;
	For(i, 1, n) fac[i] = mul(fac[i - 1], i);
	rfac[n] = Pow(fac[n], Mod - 2);
	Forr(i, n, 1) rfac[i - 1] = mul(rfac[i], i);
}

int X[7], Y[7];

int go(int x1, int y1, int x2, int y2){
	int d = y2 - y1 + x2 - x1, s = x2 - x1;
	return mul(fac[d], mul(rfac[s], rfac[d - s]));
}

int calc(int lx, int ly, int rx, int ry){
	int ret = 0;
	For(i, X[3], X[4]) add(ret, mul(Mod - i - Y[3], mul(go(lx, ly, i, Y[3] - 1), go(i, Y[3], rx, ry))));
	For(i, Y[3], Y[4]) add(ret, mul(Mod - i - X[3], mul(go(lx, ly, X[3] - 1, i), go(X[3], i, rx, ry))));
	For(i, X[3], X[4]) add(ret, mul(Y[4] + i + 1, mul(go(lx, ly, i, Y[4]), go(i, Y[4] + 1, rx, ry))));
	For(i, Y[3], Y[4]) add(ret, mul(X[4] + i + 1, mul(go(lx, ly, X[4], i), go(X[4] + 1, i, rx, ry))));
	return ret;
}

int main(){
	init(N - 5);
	For(i, 1, 6) scanf("%d", &X[i]);
	For(i, 1, 6) scanf("%d", &Y[i]);
	
	int Sx[4] = {X[1] - 1, X[2], X[1] - 1, X[2]}, 
		Sy[4] = {Y[1] - 1, Y[1] - 1, Y[2], Y[2]},
		Tx[4] = {X[6] + 1, X[5], X[6] + 1, X[5]},
		Ty[4] = {Y[6] + 1, Y[6] + 1, Y[5], Y[5]},
		coe[4] = {1, -1, -1, 1};

	int ans = 0;
	For(i, 0, 3) For(j, 0, 3) add(ans, mul(coe[i] * coe[j] + Mod, calc(Sx[i], Sy[i], Tx[j], Ty[j])));
	printf("%d\n", ans);

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int H, W, N, sr, sc;
    string S, T;
    cin >> H >> W >> N >> sr >> sc >> S >> T;
    int l = 1, r = W, u = 1, d = H;
    for (int i = N - 1; i >= 0; i--) {
        if (T[i] == 'L') r = min(W, r + 1);
        if (T[i] == 'R') l = max(1, l - 1);
        if (T[i] == 'U') d = min(H, d + 1);
        if (T[i] == 'D') u = max(1, u - 1);
        if (S[i] == 'L') l = min(W + 1, l + 1);
        if (S[i] == 'R') r = max(0, r - 1);
        if (S[i] == 'U') u = min(H + 1, u + 1);
        if (S[i] == 'D') d = max(0, d - 1);
        //cout << "l=" << l << " r=" << r << " u=" << u << " d=" << d << "\n";
        if (l > r || u > d) {
            cout << "NO\n";
            return 0;
        }
    }
    if (u <= sr && sr <= d && l <= sc && sc <= r) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 776
// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
const ll INF = 1e18; // LONG_LONG_MAX;
// const int INF = INT_MAX;
const ll MOD = 1000000007; // 998244353;

// using namespace atcoder;

// struct Point {
// 	int x, y;
// }

int main() {
	int N; cin >> N;
	vi x(N), y(N); rep(i, N) cin >> x[i] >> y[i];
	
	// vector<Point> v;
	// rep(i, N) {
	// 	v.push_back(Point{ x - y, x + y });
	// }

	vi X; rep(i, N) X.push_back(x[i] - y[i]); sort(all(X));
	vi Y; rep(i, N) Y.push_back(x[i] + y[i]); sort(all(Y));
	int dX = X[N - 1] - X[0], dY = Y[N - 1] - Y[0];
	// dbl(X); dbl(Y);
	// dbs(dX, dY);
	cout << max(dX, dY) << endl;
}

Measured memory_bytes: 7124