akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int a[200010];
vector<int> v[200010];
int ans[200010];
deque<int> dq;
void dfs(int now,int par){
    int m=(int)dq.size();
    int u=m,d=-1;
    while(u-d>1){
        int mid=(u+d)/2;
        if(dq[mid]>=a[now])u=mid;
        else d=mid;
    }
    int pre=-1;
    if(u==m){
        ans[now]=u+1;
        dq.push_back(a[now]);
    }
    else{
        ans[now]=m;
        pre=dq[u];
        dq[u]=a[now];
    }
    rep(i,0,v[now].size()){
        int ne=v[now][i];
        if(ne==par)continue;
        dfs(ne,now);
    }
    if(pre==-1)dq.pop_back();
    else dq[u]=pre;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    rep(i,0,n)cin>>a[i];
    rep(i,0,n-1){
        int f,g;cin>>f>>g;
        f--;
        g--;
        v[f].push_back(g);
        v[g].push_back(f);
    }
    dfs(0,-1);
    rep(i,0,n)cout<<ans[i]<<endl;
}



Measured memory_bytes: 30540
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll contr=0,contb=0,contg=0;
    rep(i,0,sz(s)){
        if(s[i]=='G')contg++;
        if(s[i]=='R')contr++;
        if(s[i]=='B')contb++;
    }
    ll ans = contr*contg*contb;
    rep(i,0,n){
        rep(j,i+1,n){
            if(s[i]==s[j])continue;
            if(j+j-i<n && s[j+j-i]!=s[i] && s[j+j-i]!=s[j])ans--;
        }
    }
    cout<<ans<<'\n';
    return 0;   
}   

Measured memory_bytes: 3660
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N= iRaw()
    if N%1000==0:
        print(0)
    else:
        print(1000-N%1000)

main()

Measured memory_bytes: 65732
extern crate proconio;
use proconio::{input, marker::Chars};
fn main() {
  input!{
    n: usize,
    s: Chars,
  };

  let mut ans = 0;
  for i in 0..n-2 {
    if cmp(&s[i..i+3]){
      ans += 1;
    }
  }
  println!("{}", ans);
}

fn cmp(l: &[char]) -> bool {
  let arr = "ABC".chars().collect::<Vec<char>>();
  for j in 0..3 {
    if arr[j] != l[j] {
      return false
    }
  }
  true
}


Measured memory_bytes: 2136
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,b) for(int i=0;i<b;i++)
#define rrep(i,b) for(int i = b - 1; i >= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;
const int INF = 1e9 + 5;
//int dp[MAXN][2]; // dp[i][j] --> min cost to reach stone i with last leap of j+1
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i = 0; i < n; i++) cin>>h[i];
	vector<int> dp(n,INF);
	dp[0] = 0;
	for(int i = 0; i < n ; i++){
		for(int ki = 1; ki <= k; ki++){
				int j = i + ki;
				if( i + ki < n)
				dp[j] = min(dp[j],	dp[i] + abs(h[i] - h[j]));
		}
	}
	cout<<dp[n-1]<<nl;
	return 0;

}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MN 100001
int a[MN+5],s[MN+5],S[MN*3+5];
inline void add(int x){for(;x<=3*MN;x+=x&-x)++S[x];}
inline int sum(int x){int r=0;for(;x;x-=x&-x)r+=S[x];return r;}
int main()
{
	int n,i,l,r,mid,ans;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(l=1,r=1e9;l<=r;)
	{
		mid=l+r>>1;
		long long ss=0;
		memset(S,0,sizeof(S));add(MN);
		for(i=1;i<=n;++i)s[i]=s[i-1]+2*(a[i]<=mid)-1,ss+=sum(s[i]+MN-1),add(s[i]+MN);
		if(ss>=1LL*n*(n+1)/4+1)ans=mid,r=mid-1;else l=mid+1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main()
{ int h,w,i,j;
char c;
cin >> h>>w;
int a[h][w];
for(i=0;i<h;i++)
    for(j=0;j<w;j++)
        {   cin >>c;
            a[i][j]=c;
        }
for(i=0;i<w+2;i++)
    cout <<"#";
cout<<endl;
for(i=0;i<h;i++)
{
    cout<<"#";
    for(j=0;j<w;j++)
    {c=a[i][j];
    cout<<c;
    }
    cout<<"#"<<endl;
}
for(i=0;i<w+2;i++)
    cout <<"#";
    return 0;
}

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

int main(){
   long long int K,A,B;
   cin>>K>>A>>B;
    long long int n=1;
    int y=0;
    
   if(A+1>=B){
       cout<<1+K<<endl;
       return 0;
   }else 
   {
    
       for(int i=0;i<K;i++){
           if(y){
               n+=B;
               y=0;
           }else 
           if(n>=A&&i!=K-1){
               n-=A;
               y++;
           }else n++;
       }
   }
   cout<<max(n,1+K)<<endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ans = 'Yes'
#全探索して、黒色の隣接マスがすべて白色なら、Noとなる
for h, s in enumerate(S):
	for w, c in enumerate(s):
		if c == '#':
			if w-1 >= 0 and S[h][w-1] == '#':
				continue
			if w+1 < W and S[h][w+1] == '#':
				continue
			if h-1 >= 0 and S[h-1][w] == '#':
				continue
			if h+1 < H and S[h+1][w] == '#':
				continue
			ans = 'No'
			break
	else:
		continue
	break
	
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    vector <int> d(100000, 1);
    for (int i(0); i < s.size();)
    {
        while (i < s.size() - 1 && s[i + 1] != 'L')
        {
            d[i + 1] += d[i];
            d[i] = 0;
            i++;
        }
        i++;
        int p = i;
        i++;
        while (i < s.size() && s[i] == 'L')
        {
            d[i] = 0;
            d[p]++;
            i++;
        }
    }
    for (int i(0); i < s.size() - 1; i++)
        if (d[i] != 0 && d[i + 1] != 0)
        {
            int maxi = max(d[i], d[i + 1]), mini(min(d[i], d[i + 1]));
            if ((maxi - mini) % 2 == 0)
            {
                mini += (maxi - mini) / 2;
                d[i] = mini;
                d[i + 1] = d[i];
            } else {
                if (d[i] < d[i + 1])
                {
                    if ((mini - 1) % 2 == 0)
                    {
                        mini += (maxi - mini) / 2;
                        d[i] = mini + 1;
                        d[i + 1] = mini;
                    } else {
                        mini += (maxi - mini) / 2;
                        d[i] = mini;
                        d[i + 1] = mini + 1;
                    }
                } else {
                    if ((mini - 1) % 2 == 0)
                    {
                        mini += (maxi - mini) / 2;
                        d[i] = mini;
                        d[i + 1] = mini + 1;
                    } else {
                        mini += (maxi - mini) / 2;
                        d[i] = mini + 1;
                        d[i + 1] = mini;
                    }
                }
            }
            i++;
        }
    for (int i(0); i < s.size(); i++)
        cout << d[i] << ' ';
}


Measured memory_bytes: 1024
import sys

def sum_keta(num):
    tmp = num
    res = 0
    while tmp != 0:
        res += (tmp % 10)
        tmp = int(tmp/10)
    return res

n, a, b = list(map(int, sys.stdin.readline().strip().split(" ")))

r = 0
for i in range(1, n+1):
    s = sum_keta(i)
    if a <=  s and b >= s:
        r += i

print(r)


Measured memory_bytes: 3060
import java.util.*;

public class Main{
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long N = scan.nextInt();
    long A;
    long sum = 0;
    Map<Long,Long> map = new HashMap<>();
    for(long i=0;i<N;i++) {
        A = scan.nextInt();
        if (map.containsKey(A)) {
            map.put(A,map.get(A)+1);
        } else {
            map.put(A,(long)1);
        }
        sum += A;
    }

    long Q = scan.nextInt();
    long B;
    long C;
    StringBuilder sb = new StringBuilder();
    for(long i=0;i<Q;i++) {
        B = scan.nextInt();
        C = scan.nextInt();
        if (!map.containsKey(B)) {
            sb.append(String.valueOf(sum) + "\n");
            continue;
        }

        long diff = map.get(B);
        map.remove(B);
        sum += ((C - B) * diff);
//System.out.println("sum:" + sum + " C-B:" + String.valueOf(C-B) + " diff:" + String.valueOf(diff));

        if (map.containsKey(C)) {
            map.put(C, map.get(C) + diff);
        } else {
            map.put(C,diff);
        }
        sb.append(String.valueOf(sum) + "\n");
    }
    scan.close();

    System.out.print(sb);
}
}


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

typedef long long int ll;

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

	string str;
	cin >> str;

	int i=0;
	while(str[i]!='B' && str[i]!='\0') i++;

	if(str[i]=='\0'){
		cout << 0 << endl;
		return 0;
	}

	ll qt=0;
	for(int j=i+1;str[j]!='\0';j++){
		if(str[j]=='W'){
			qt+=j-i;
			i++;
		}
	}

	cout << qt << endl;

	return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int x=stdIn.nextInt(),y=stdIn.nextInt(),a=0,b=0;
		if(x==4||x==6||x==9||x==11) a++;
		else if(x==2) a+=2;
		if(y==4||y==6||y==9||y==11) b++;
		else if(y==2) b+=2;
		System.out.print(a==b?"Yes":"No");
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(5);
    REP(i,5){
        cin >> a[i];
    }
    ll m = *min_element(all(a));
    ll res = (n+m-1)/m;
    put(4+res);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
int A,B,C;

cin >> A>>B>>C;
if(A>=B&&A>=C){
cout << A*10+B+C<<endl;
return 0;
}
else if(B>=C){
cout << B*10+A+C<<endl;
}
else{
cout << C*10+B+A<<endl;
return 0;
}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a;
	cin >> b;
	cin >> c;
		if (a < b && b<c){
			cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
	return 0;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


int N, W[1010], S[1010], V[1010];
ll dp[1010][30101];
//---------------------------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, N) cin >> W[i] >> S[i] >> V[i];

    vector<int> ord(N);
    iota(all(ord), 0);
    sort(all(ord), [](int a, int b) { return min(S[a], S[b] - W[a]) > min(S[b], S[a] - W[b]); });

    rep(i, N) {
        rep(tot, 20101) {
            int a = ord[i];
            chmax(dp[i + 1][tot], dp[i][tot]);
            if (tot <= S[a]) chmax(dp[i + 1][tot + W[a]], dp[i][tot] + V[a]);
        }
    }

    ll ans = 0;
    rep(tot, 20101) chmax(ans, dp[N][tot]);
    cout << ans << endl;
}

Measured memory_bytes: 234368
#include <iostream>
using namespace std;
int n, p[200100], count, miiin;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    miiin = p[0];
    for (int i = 0; i < n; i++)
    {
        if (p[i] == 1)
        {
            count += 1;
            cout << count << endl;
            return 0;
        }
        if (p[i] <= miiin)
        {
            count += 1;
            miiin = p[i];
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    int heights[6] = {};
    for (int i = 0; i < n; i++) {
        double height;
        cin >> height;
        if (height < 165) {
            heights[0]++;
        } else if (height < 170) {
            heights[1]++;
        } else if (height < 175) {
            heights[2]++;
        } else if (height < 180) {
            heights[3]++;
        } else if (height < 185) {
            heights[4]++;
        } else {
            heights[5]++;
        }
    }
    for (int i = 0; i < 6; i++) {
        cout << i + 1 << ":";
        for (int j = 0; j < heights[i]; j++) {
            cout << "*";
        }
        cout << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll N;
    is >> N;
    if(!is) return;
    ll pre = 0;
    bool cant = false;
    ll can = true;
    for (int i = 0; i < N; ++i) {
        ll h;
        is >> h;
        if(pre < h) { h--; }
        if(pre > h) can = false;
        pre = h;
    } // end i
    cout << (can ? "Yes" : "No") << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_C.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		// 入力値の取得
		int a = sc.nextInt();
		
		// 結果の出力
		System.out.println(a + a*a + a*a*a);
		
		sc.close();
	}
}


Measured memory_bytes: 27012
import re

S = input()
S = S.replace('x', '*({0})')
S = S.replace('^', '**')
S = re.sub(r'([+-])\*', r'\1', S)[1:]
for i in range(2000, -2001, -1):
    if eval(S.format(i)) == 0:
        print('(x{:+})'.format(-i), end='')
else:
    print()



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

int main(){
  int H, W; cin >> H >> W;
  int masu[52][52]={};
  string s[51];
  for(int i=1; i<=H; i++){
    cin >> s[i];
    for(int j=1; j<=W; j++){
      if(s[i][j-1]=='#') masu[i][j]=1;
    }
  }
  
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(s[i][j-1]=='#') cout << '#';
      else cout << masu[i-1][j-1]+masu[i-1][j]+masu[i-1][j+1]+
        masu[i][j-1]+masu[i][j+1]+masu[i+1][j-1]+
        masu[i+1][j]+masu[i+1][j+1];
    }
    cout << endl;
  }
}

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

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

    int h, n;
    cin >> h >> n;
    vector<int> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
    }

    int H = 20010;
    vector<int> dp(H + 1, 1e9); // dp[i] ... 体力i減らす時の魔力の合計の最小値
    dp[0] = 0;

    for(int i = 0; i <= H; i++){
        for(int j = 0; j < n; j++){
            if(i - A[j] < 0) continue;
            dp[i] = min(dp[i], dp[i - A[j]] + B[j]);
        }
    }

    int ans = 1e9;
    for(int i = H; i >= h; i--){
        ans = min(ans, dp[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int cando = (a+b)==c || (a+c)==b || (b+c)==a;
    puts(cando==1 ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 128
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N+1)

for _ in range(M):
  A, B = map(int, input().split())
  uf.union(A, B)
  # print(uf)
  # print()

print(max([uf.size(r) for r in uf.roots()]))


Measured memory_bytes: 19856
#include<cstdio>
#include<cstdlib>
#include<cstring>

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

Node *nil;

Node* listSearch(int key){
  Node *cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;

  }

return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev =nil;
}

void printList(){
  Node *cur = nil->next;
  int isf = 0;
  while(1){

    if( cur == nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d",cur->key);

    cur = cur->next;

  }
  printf("\n");

}


void deleteNode(Node *t){

  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

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

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

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

}

int main(){
  int key,n,i;
  int size =0;
  char com[20];
  int np= 0,nd = 0;
  scanf("%d",&n);
  init();
  for(i = 0; i < n; i++){
    scanf("%s%d",com,&key);
    if(com[0] == 'i'){insert(key);np++;size++;}
    else if(com[0] == 'd') {
      if(strlen(com) > 6){
	if(com[6]=='F') deleteFirst();
     else if(com[6]=='L') deleteLast();
    }

  
  else{deleteKey(key);nd++;}
      size--;
  }
  }
  printList();

  return 0;
  
}






Measured memory_bytes: 34008
x = int(input())
m = x // 100
n = x % 100
# x = 100m+n
# 0~5までの数を合計m回使用して和をnにすることができるか
# nが5の倍数の時，n//5<=mであれば良い
# nが5の倍数でない時，n//5<=m-1であれば良い
import math
if math.ceil(n/5) <= m:
  print(1)
else:
  print(0)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    ll n,m;
    cin >> n >>m;
    ll cc=m/2;
    if(n>=cc) cout << cc <<endl;
    else cout << (n+cc)/2 <<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    //"Yes"  '\n'
    string s,t;
    cin>>s>>t;
    string m;
    for(int i=0;i<t.size()-1;i++)
    {
        m+=t[i];
    }
    if(s==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}          //Alhamdulilla..


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

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

  rep(n,1,3500){
    rep(w,1,3500){
      double h = double( (N*n*w)) / ((4*n*w) - (N*(n+w))); 
      int k = h;
      
      //printf("%.5f %d" , h , k);
      //cout << endl;
      if(h < 1)
        continue;

      if(h-k == 0.0){
        cout << k << " " << n <<" " << w << endl;
        ret 0;
      }

    }
  }
   
  ret 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int d; cin >> d;
  string ans;
  if(d == 22) ans = "Christmas Eve Eve Eve";
  if(d == 23) ans = "Christmas Eve Eve";
  if(d == 24) ans = "Christmas Eve";
  if(d == 25) ans = "Christmas";
  cout << ans;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i, b, e)	  for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ll h, a;
    cin >> h >> a;
    cout << h/a + (h%a > 0) << endl;
    return 0;
}
// PLUS ULTRA!

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

using namespace std;

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  int tmp = X;
  int minm = 100000;
  for(int i = 0; i < N; i++){
    cin >> m[i];
    tmp -= m[i];
    minm = min(minm, m[i]);
  }
  int ans = 0;
  if(tmp > 0){
  ans = m.size() + tmp / minm;
  }else if(tmp == 0){
  ans = m.size();
  }
  cout << ans;
}

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

int main(void){

    int a, b;

    scanf("%d%d", &a, &b);

    if(a <= b){
        printf("%d\n", a);
    }else{
        printf("%d\n", a-1);
    }

    return 0;
}

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

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

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

int main()
{

    std::vector<int> a(11);

    rep(i, 11)
        a[i] = i * (i + 1) / 2;

    ll n;
    std::cin >> n;

    ll p = 2;

    int ans = 0;

    while (n > 1 && n >= p * p)
    {
        if (n % p == 0)
        {
            int cnt = 0;
            while (n % p == 0)
            {
                ++cnt;
                n /= p;
            }
            int t = (std::upper_bound(std::begin(a), std::end(a), cnt)) - std::begin(a) - 1;
            //std::cerr << t << std::endl;
            ans += t;
        }
        ++p;
    }

    if (n != 1)
    {
        ans += 1;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3628
import math

inputdata=list(map(int,input().split()))

A = int(inputdata[0])
B = int(inputdata[1])
H = int(inputdata[2])
M = int(inputdata[3])

dig = abs(360.0 * ( ( M / 60.0 ) - ( ( H * 60.0 + M )/ 720 ) ) )

C = math.sqrt((A*A) + (B*B) -2 * A * B * math.cos(math.radians(dig)))

print(C)


Measured memory_bytes: 9580
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const long long INF = 1LL << 60;
typedef pair<int, int> P;





int main() {
    /*
    int A, B; cin >> A >> B;
    if (A > B) swap(A,B);
    if (A == 1 && B == 2) {
        cout << 3 << endl; 
    } 
    if (A == 2 && B == 3) {
        cout << 1 << endl; 
    } 
    if (A == 1 && B == 3) {
        cout << 2 << endl; 
    } */
    int N; cin >> N;
    string S, T;
    cin >> S >> T;
    string res;
    for (int i = 0; i < N; i++) {
        res.push_back(S[i]);
        res.push_back(T[i]);
    }
    cout << res << endl;



}


Measured memory_bytes: 256
N,X,Y = list(map(int,input().split()))

X,Y = X-1,Y-1

from collections import defaultdict
res = defaultdict(int)
for i in range(N):
  for j in range(N):
    ans = min(abs(j-i),
        abs(X-i)+1+abs(j-Y),
        abs(Y-i)+1+abs(j-X))
    res[ans]+=1
    
for i in range(1,N):
  print(res[i]//2)

Measured memory_bytes: 56412
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
int main(){
        int n;
        cin>>n;
        vector<long>ar(n);
        for(auto&e:ar){
                scanf("%ld",&e);
        }
        long long sum1=0;
        for(int i=0;i<n;i++){
                sum1+=ar[i];
        }
    sort(ar.begin(),ar.end());
    printf("%ld %ld %lld\n",ar[0],ar[n-1],sum1);
        return 0;
}

Measured memory_bytes: 1300
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    cnt = 0
    for i in range (1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    cnt += 1
    print(cnt)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int d;cin>>d;
    ll g;cin>>g;
    vector<int> p(d),c(d);
    rep(i,d){
        cin>>p[i]>>c[i];
    }
    ll res=1e18;
    for(int tmp=0;tmp<(1<<d);tmp++){
        ll sum=0,tot=0;
        rep(i,d){
            if(tmp&(1<<i)){
                tot+=((i+1)*100)*p[i]+c[i];
                sum+=p[i];
            }
        }
        if(tot>=g){
            chmin(res,sum);
            continue;
        }
        bool ok=false;
        for(int i=d-1;i>=0;i--){
            if(tmp&(1<<i))continue;
            int x=100*(i+1);
            if((g-tot+x-1)/x<p[i]){
                sum+=(g-tot+x-1)/x;
                chmin(res,sum);
                ok=true;
                break;
            }else{
                sum+=p[i]-1;
                tot+=(p[i]-1)*x;
            }
        }
        if(ok)chmin(res,sum);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3596
def calc():
    summ  = sum(A)
    low = summ / (4*M)
    newlist = [i for i in A if i >= low]
    num = len(newlist)
    
    if M <= num:
        print ("Yes")
    else:
        print ("No")

N, M = map(int,input().split())
A = list(map(int,input().split()))

#N, M = 5, 2
#A = [110, 2, 20, 10, 0]
calc()

Measured memory_bytes: 2940
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        int needStrip = 0;
        int startOutlet =1;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int arr[] = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        while(startOutlet<arr[1]) {
            startOutlet--;
            startOutlet+=arr[0];
            needStrip++;
        }
        System.out.println(needStrip);                                     
    }
}


Measured memory_bytes: 31320
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
	static long[] list = new long[10001];
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()) {
			char[] tmp = stdIn.next().toCharArray();
			solv(tmp);
		}
	}
	public static void solv(char[] a) {
		int tmp = 0;
		tmp += check(a[0]);
		for(int i = 1; i < a.length; i++) {
			int ax = check(a[i]);
			int bx = check(a[i-1]);
			if(ax <= bx) {
				tmp += ax;
			}
			else {
				tmp -= bx;
				tmp += ax - bx;
			}
		}
		System.out.println(tmp);
	}
	public static int check(char a) {
		if(a == 'M') return 1000;
		if(a == 'D') return 500;
		if(a == 'C') return 100;
		if(a == 'L') return 50;
		if(a == 'X') return 10;
		if(a == 'V') return 5;
		if(a == 'I') return 1;
		return 0;
	}
}

Measured memory_bytes: 17232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	long long w, h, x, y;
    cin >> w >> h >> x >> y;

    double s;
    long long subS;
    subS = w*h;
    if(subS&1) s = (subS >> 1) + 0.5;
    else s = subS >> 1;

    if(x*2 == w && y*2 == h) cout << s << " " << 1 << endl;
    else cout << s << " " << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,k;
    cin>>a;cin>>b;cin>>k;
    if((b-a+1)>(2*k))
    {
        for(int i=0;i<=k-1;i++)
        {
            cout<<a+i<<" ";
        }

    for(int j=k-1;j>=0;j--)
        {
            cout<<b-j<<" ";
        }
    }
    else{
            for(int o=0;o<=(b-a);o++)
            {
                cout<<a+o<<" ";
            }
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, a[100000], ta, mu;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	rep(i, n) {
		if (i == 0 || a[i - 1] != a[i]) {
			ta = upper_bound(a, a + n, a[i]) - lower_bound(a, a + n, a[i]);
			if (a[i] > ta)mu += ta;
			else mu += ta - a[i];
		}
	}
	cout << mu << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 1024
value = input().split()
rows = int(value[0])
colmuns = int(value[1])

#valid
if colmuns == 1:
  rows = 1
elif rows == 1:
  colmuns = 1

OddColNum = colmuns // 2 
EvenColNum = OddColNum
if (colmuns % 2) != 0:
  OddColNum = OddColNum + 1
if (colmuns == 1):
  OddColNum = 1

OddRowCount = 0
EvenRowCount = rows // 2
if (rows % 2) == 0:
  OddRowCount = rows // 2
else:
  OddRowCount = (rows // 2) + 1
if (rows == 1):
  OddRowCount = 1

counts = OddRowCount * OddColNum + EvenColNum * EvenRowCount
print(counts)

Measured memory_bytes: 3064
N = int(input())
nump = input().split()
nump = [int(i) for i in nump]

count = 0
for i in range(1,N-1):
  p = nump[i]
  tmp = nump[i-1:i+2]
  tmp.sort()
  if tmp[1] == p:
    count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int toi(string s){
    int t = ((s[0] - '0')*10 + s[1] - '0') * 3600 + ((s[3] - '0') * 10 + s[4] - '0') * 60 + (s[6] - '0')*10 + s[7] - '0';
    return t;
}
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> sum(24*60*60 + 1, 0);
        for(int i =0; i < n; i++){
            string go, arrive;
            cin >> go >> arrive;
            int gos = toi(go);
            int as = toi(arrive);
            sum[gos]++;
            sum[as]--;
        }
        for(int i = 1; i < 24*60*60 + 1; i++) sum[i] += sum[i - 1];
        int ans = 0;
        for(int i = 0; i < 24*60*60 + 1; i++) ans = max(ans, sum[i]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
int square(int n){
    return n*n;
}
int main(){
    int N,D;
    cin >> N >> D;
    int X[N][D];
    int ans=0;
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            cin >> X[i][j];
        }
    }
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            double dist2jou=0;
            for(int k=0; k<D; k++){
                dist2jou += square(X[i][k]-X[j][k]);
            }
            int dist = sqrt(dist2jou);
            if(dist*dist==dist2jou){
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N, a, b;
	cin >> N >> a >> b;

	if (abs(a - b) % 2 == 0) {
		cout << abs(a - b) / 2 << "\n";
	}
	else {
		cout << min({ max(a - 1, b - 1), max(N - a, N - b),
			 min(abs(a - b) / 2 + a, abs(a - b) / 2 + N - a + 1),
			 min(abs(a - b) / 2 + b, abs(a - b) / 2 + N - b + 1) }) << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import itertools
import numpy as np
from numba import njit

def main():
#入力
    readline=stdin.readline
    N,M,Q=map(int,readline().split())
    a=np.zeros(Q,dtype=np.int64)
    b=np.zeros(Q,dtype=np.int64)
    c=np.zeros(Q,dtype=np.int64)
    d=np.zeros(Q,dtype=np.int64)
    for i in range(Q):
        a[i],b[i],c[i],d[i]=map(int,readline().split())

    arrays=np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)),dtype=np.int64)
    l=len(arrays)

    print(f(l,Q,a,b,c,d,arrays))
    
@njit("i8(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:,:])",cache=True)
def f(l,Q,a,b,c,d,arrays):
    max_res=0
    for i in range(l):
        res=0
        for j in range(Q):
            if arrays[i][b[j]-1]-arrays[i][a[j]-1]==c[j]:
                res+=d[j]
        max_res=max(max_res,res)
    return max_res

if __name__=="__main__":
	main()

Measured memory_bytes: 125468
n = int(input())
s = list(map(int, input()))


def is_Lucky(x):
    x = tuple(map(int, '{:03d}'.format(x)))
    idx = 0
    for c in s:
        if x[idx] == c:
            idx += 1
            if idx == 3:
                return True
    else:
        return False


ans = 0
for i in range(1000):
    if is_Lucky(i):
        ans += 1
print(ans)


Measured memory_bytes: 75012
(h, n), *m = [[*map(int, i.split())] for i in open(0)]
dp = [0] + [10**9] * h
for i in range(1, h + 1):
    for a, b in m:
        dp[i] = min(dp[i], dp[max(i-a,0)]+b)
print(dp[-1])


Measured memory_bytes: 74064
#include <cstdio>
#include <cstring>
int main() {
	char x[100005];
	scanf("%s",x);
	bool c=false,f=false;
	for(int i=0;i<strlen(x);i++)
	{
		if(x[i]=='C') c=1;
		if(c&&x[i]=='F') f=1;
	}
	if(c&&f) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stack>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
 
int main()
{
  stack<int> S;
  char c[10];
  int x,y;
  while((scanf("%s",&c))!=EOF){
    if(c[0]=='+'){
      x=S.top();S.pop();
      y=S.top();S.pop();
      S.push(x+y);
    }
    else if(c[0]=='-'){
      x=S.top();S.pop();
      y=S.top();S.pop();
      S.push(y-x);
    }
    else if(c[0]=='*'){
      x=S.top();S.pop();
      y=S.top();S.pop();
      S.push(x*y);
    }
    else{
      S.push(atoi(c));
    }
  }
  cout<<S.top()<<endl;
  return 0;
}


Measured memory_bytes: 3236
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	string s;
	while (cin >> s){
		int n[3];
		REP(i,s.length()){
			if (s[i] == '+')
				n[0] = i;
			if (s[i] == '='){
				n[1] = i - n[0] - 1;
				n[2] = s.length() - n[0] - n[1] - 2;
				break;
			}
		}
		int ans = -1;
		REP(i, 10){
			string s2 = s;
			REP(j, s2.length()){
				if (s2[j] == 'X')
					s2[j] = i + '0';
			}
			if ((s2[0] == '0'&&n[0]>1) ||( s2[n[0] + 1] == '0'&&n[1]>1) || (s2[n[0] + n[1] + 2] == '0'&&n[2]>1))
				continue;
			int num[128] = {0};
			for (int j = 0; j < 128; j++){
				if (j < n[0])
					num[j]+=s2[n[0]-j-1]-'0';
				if (j < n[1])
					num[j] += s2[n[0]+n[1] - j] - '0';
				if (j < n[2])
					num[j] -= s2[s2.length()-1-j] - '0';
				if (num[j] != 0 && num[j] != 10)
					break;
				else{
					if (num[j] == 10)
						num[j + 1]++;
					num[j] = 0;
				}
			}
			bool b = true;
			REP(j, 128){
				if (num[j] != 0)
					b = false;
			}
			if (b){
				ans = i;
				break;
			}
		}
		if (ans != -1)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 3116
from collections import defaultdict

N = int(input())
E = defaultdict(list)
W = dict()

for i in range(N-1):
  a,b,c = map(int,input().split())
  E[a].append(b)
  E[b].append(a)
  W[(a,b)] = c
  W[(b,a)] = c

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

costs = [float('inf')]*(N+1)
costs[K] = 0

stack = [K]

while stack:
  s = stack.pop()
  for t in E[s]:
    if costs[t] > costs[s] + W[(s,t)]:
      costs[t] = costs[s] + W[(s,t)]
      stack.append(t)

for i in range(Q):
  x,y = map(int,input().split())
  print(costs[x]+costs[y])

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

int main()
{
  string s;
  cin >> s;
  
  int l = s.size();
  
  char first, second;
  if (s.at(0) == '0')
  {
    first = '0';
    second = '1';
  }
  else
  {
    first = '1';
    second = '0';
  } 
  
  int count = 0;
  for (int i = 0; i < l; i ++)
  {
    if (i % 2 == 0)
    {
      if (s.at(i) != first)
        count ++;
    }
    else
    {
      if (s.at(i) != second)
        count ++;
    }
  }
  
  cout << count;
  return 0;
}

Measured memory_bytes: 512
n,m,c=map(int, input().split())
blist=list(map(int, input().split()))
ans=0
for i in range(n):
  alist=list(map(int, input().split()))
  cnt=0
  for i in range(m):
    cnt+=alist[i]*blist[i]
  if cnt>-c:
    ans+=1
print(ans)

Measured memory_bytes: 9048
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let s: Vec<u8> = read::<String>().into_bytes();
    if s[2] == s[3] && s[4] == s[5] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>

using namespace std;

int len;
char S[205], T[105];

bool equal(int pos){
	for(int i = pos; i <= len+pos-1; i++)
		if(S[i] != T[i-pos+1])
			return false;
	return true;
}

int main(){
	scanf("%s%s", S+1, T+1);
	len = strlen(T+1);
	for(int i = 1; i <= len; i++)
		S[i+len] = S[i];
	for(int i = 1; i <= len; i++)
		if(equal(i))
			return puts("Yes"), 0;
	puts("No");
	return 0;
}


Measured memory_bytes: 128