akhauriyash/Code-Regression huggingface dataset:
def main():
    N, M = map(int, input().split())
    g = [[] for _ in range(N + 1)]
    d = [float('INF')] * (N + 1)
    d[1] = 0
    for _ in range(M):
        a, b, c = map(int, input().split())
        c = -c
        g[a].append((b, c))
    for i in range(2 * N):
        for x, r in enumerate(g):
            for y, c in r:
                if d[x] != float('INF') and d[y] > d[x] + c:
                    d[y] = d[x] + c
                    if y == N and i > N:
                        print("inf")
                        exit()

    print(-d[-1])


main()


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll a,b,c;

int main(){
  cin>>a>>b>>c;
  ll ans = 1e18;
  CHMIN(ans,a*b*(c%2));
  CHMIN(ans,a*c*(b%2));
  CHMIN(ans,c*b*(a%2));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define sz(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int ch(string s){
    int a=sz(s);
    
    if(a%2){
        return 0;
    }else{
        string b,c;
        b="";c="";
        rep(i,a/2){
            b+=s[i];
        }
        FOR(i,a/2,a-1){
            c+=s[i];
        }
        if(b==c){
            return a;
        }else{
            return 0;
        }
    }
}
int main() {
    string s;cin>>s;
    while(1){
        s.pop_back();
        int t=ch(s);
        if(t!=0){
            cout<<t<<endl;
            return 0;
            break;
        }
            
    }
    return 0;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int a, b, c, x, y;

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

  cin >> a >> b >> c >> x >> y;

  ll tmp1 = a * x + b * y;
  ll tmp2 = a * max(x - y, 0) + c * 2 * y;
  ll tmp3 = c * 2 * x + b * max(y - x, 0);
  ll rsl = min(tmp1, min(tmp2, tmp3));
  cout << rsl << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>

#define p1 "dream"
#define p2 "dreamer"
#define p3 "erase"
#define p4 "eraser"

using namespace std;

int main() {
    string p[4]{p1,p2,p3,p4};
    char buf[100*1000];
    string input;
    scanf("%s",buf);
    input = buf;
    int n = input.size();
    while (n > 0) {
        //printf("%d\n",n);
        int flag = 0;

        for (int i=0; i<4; i++) {

            if ((int)(n-p[i].size()) < 0) {
                continue;
            }
            //printf("*%d\n",n-p[i].size());

            if (input.substr(n-p[i].size(),p[i].size()) == p[i]) {
                n -= p[i].size();
                flag = 1;
                break;
            }
        }

        if (flag == 0) {
            printf("NO\n"); 
            return 0;
        }     
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(max(0,(M-2)))
elif M == 1:
    print(max(0,(N-2)))
else:
    print(max(0,(N-2)) * max(0,(M-2)))


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


int main(){

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

int eat=a+b;
if(eat>c){
cout<<b+c<<endl;
}
if(eat<c){
cout<<b+eat+1<<endl;

}

if(eat==c){
cout<<b+c<<endl;


}
return 0;


}

 




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

int solve(int a, int b, int t);

int main(){
    int a, b, t;
    cin >> a >> b >> t;
    cout << solve(a, b, t) << endl;
    return 0;
}

int solve(int a, int b, int t){
    a = (t+0.5)/a;
    return a*b;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

char cate_print(int i)
{
	switch(i){
		case 0:	
			return 'S';
		case 1:
			return 'H';
		case 2:
			return 'C';
		case 3:
			return 'D';
	}
}

int main()
{
	int cards[4][13] = {false};
	char cate;
	int num;
	int n;
	
	cin >> n;
				
	for(int i=0; i<n; i++){
		cin >> cate >> num;
		if(cate == 'S')
			cards[0][num-1] = true;
		if(cate == 'H')
			cards[1][num-1] = true;
		if(cate == 'C')
			cards[2][num-1] = true;
		if(cate == 'D')
			cards[3][num-1] = true;
	}
	
	//cout << endl;
	
	for(int i=0; i<4; i++)
		for(int j=0; j<13; j++)
			if(cards[i][j] == false)
				cout << cate_print(i) << ' ' << j+1 << endl;
	
	return 0;
}



Measured memory_bytes: 3084
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,x,y;
    cin >> n >> x >>y;
    
    x--, y--;
    vector<vector<int>> g(n);
    for (int i = 0; i < n-1; i++){
        int a = i, b = i+1;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    g[x].push_back(y);
    g[y].push_back(x);
    
    vector<int> cnt(n, 0);

    
    for (int i = 0; i < n; i++){
        set<int> vis;
        vector<int> d(n);
        d[i] = 0;
        vis.insert(i);
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (auto v: g[u]) {
                if(vis.count(v))continue;
                d[v] = d[u] + 1;
                cnt[d[v]] ++;
                vis.insert(v);
                q.push(v);
            }
        }
    }
    
    for (int i = 1; i < n; i++){
        cout << cnt[i]/2 << "\n";
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
const int inf=0x3f3f3f3f;
using namespace std;
template <typename T> void read(T &t) {
    t=0; char ch=getchar(); long long f=1;
    while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int main(){
	long long n;
	read(n);
	cout<<n*(n-1)/2;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>



int main() {
	int r, c;
	int T[101][101];
	int buff = 0;

	scanf("%d %d", &r, &c);
	for (int i = 0; i < r; i++) {
		buff = 0;
		for (int j = 0; j < c; j++) {
			scanf("%d", &T[i][j]);
			buff += T[i][j];
		}
		T[i][c] = buff;
	}

	for (int j = 0; j <= c; j++) {
		T[r][j] = 0;
		for (int i = 0; i < r; i++) {
			T[r][j] += T[i][j];
		}
	}

	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			printf("%d", T[i][j]);
			if (j != c)printf(" ");
		}
		printf("\n");
	}


	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb1(x) cout<<#x<<" :: "<<x<<"\n";
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define lli long long int
#define pii pair<lli,lli>
#define f first
#define sE second
lli n,x,y,t,mod=1e9+7,ans=0;
int main() { 
    fast
    cin>>n>>x;
    vector<lli>w(n+1),p(n+1);
    lli dp[n+1][x+1];
     for(int i=0;i<=n;i++){
        for(int j=0;j<=x;j++){
            dp[i][j]=0;
        }
     }
    for(int i=1;i<=n;i++)
        cin>>w[i]>>p[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=x;j++){
            if(w[i]>j){ 
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=max(p[i]+dp[i-1][j-w[i]],dp[i-1][j]);
            }
        }
    }
    cout<<dp[n][x]<<endl;
    
} 

Measured memory_bytes: 79232
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  vlist = list(map(int, input().split()))
  vlist = list(sorted(vlist, key=lambda x: -x))
  ans = 0
  for i, v in enumerate(vlist):
    ans += v / pow(2, i+1)
  ans += vlist[-1] / pow(2, len(vlist))
  print('%.10f' % ans)

if __name__ == '__main__':
  main()


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){
  string S,ans,R,L;
  ans = "Yes";
  cin>>S;
  rep(i,(S.size()-1)/2){
    R.push_back(S.at(i));
    L.push_back(S.at(1+i+(S.size()-1)/2));
    if(S.at(i)!=S.at(S.size()-1-i)){
      ans = "No";
      cout<<ans<<endl;
      return 0;
    }
  }
  if(R.size()%2==1){
    rep(i,(R.size()-1)/2){
      if(R.at(i)!=R.at(R.size()-1-i)){
        ans = "No";
        cout<<ans<<endl;
        return 0;
      }
      if(L.at(i)!=L.at(L.size()-1-i)){
        ans = "No";
        cout<<ans<<endl;
        return 0;
      }
    }
  }else{
    rep(i,(R.size())/2){
      if(R.at(i)!=R.at(R.size()-1-i)){
        ans = "No";
        cout<<ans<<endl;
        return 0;
      }
      if(L.at(i)!=L.at(L.size()-1-i)){
        ans = "No";
        cout<<ans<<endl;
        return 0;
      }
    }
    }



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


Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
if n==2:
    print(a[0])
elif n%2==0:
    print(2*sum(a[:n//2])-a[0])
else:
    print(2*sum(a[:(n+1)//2])-a[0]-a[(n+1)//2-1])

Measured memory_bytes: 31452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,X,T;
  cin >> N >> X >> T;
  int a=0;
  if(N%X) a=1;
  cout << (N/X+a)*T << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 10000000007
#define ff first
#define ss second
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5 + 5;

int main()
{
    IOS
    int n,k;
    cin>>n>>k;
    lli dp[n],a[n];
    for(int i=0;i<n;i++) dp[i] = 1e16;
    cin>>a[0];
    dp[0] = 0;
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
        for(int j=1;j<=k;j++)
        if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        else break;
        
        
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll  a,b,c,d,maxm;
   cin>>a>>b>>c>>d;
    maxm=max((a*c),max((a*d),max((b*c),(b*d))));
    cout<<maxm;
  return 0;
}
   
         
         

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

bool f(double mid, vector<int> a, int k){
  
  ll t{};
  for(int i=0; i<a.size(); i++){
    t += ceil(a.at(i)/mid)-1;
  }
  return t<=k;
}

int main(){
  
  int n,k; cin>>n>>k;
  vector<int> a(n);
  for(auto &i:a) cin>>i;
  int j = 100;
  double ok = 1e9, ng = 0;
  while(--j){
    auto mid = (ok+ng)/2;
    (f(mid,a,k)?ok:ng) = mid;
  }
  cout << (ll)ceil(ok) << endl;
  
}


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

int main() {
  string S;
  cin >> S;
  
  bool ans = true;
  
  for (int i = 0; i < 3; i++) {
    if ( S.at(i) == S.at (i+1) ) {
      ans = false;
    }
  }    
   
  if (ans) {
    cout << "Good" << endl;
  }
  else {
    cout << "Bad" << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int seq[n];
    for(int i = 0; i < n; i++){
        cin >> seq[i];
    }
    
    for(int i = n-1; i >= 0; i--){
        if(i == 0){
            cout << seq[i] << endl;
        }else{
            cout << seq[i] << " ";
        }
    }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int  main (){
  string a, b, c;
  cin  >> a >> b >> c;
  char  dif='A' - 'a';
  printf ("%c%c%c\n", a[0] + dif , b[0] + dif , c[0] + dif);
  return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll M=1e9+7;
 
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	float r;cin>>r;
	float pi=3.141592;
	pi=2.0*pi*r;
	cout<<pi;
 
	
	return 0;
} 

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

// good and short method....
	string s, t; int q, i, k, f; char c;
	cin >> s >> q;
	zip(i, 0, q)
	{
		cin >> k;
		if (k == 1)
		{
			swap(s, t);
		}
		else
		{
			cin >> f >> c;
			if (f == 1)
				t = t + c;
			else
				s = s + c;
		}
	}
	reverse(all(t));
	t = t + s;
	cout << t << en;

	// string s;
	// cin >> s;
	// string a = "12";
	// int q;
	// cin >> q;
	// int t;
	// int f;
	// char c;
	// string x;
	// int var = 0;
	// //a = s;
	// zip(i, 0, q)
	// {
	// 	cin >> t;
	// 	if (t == 1)
	// 	{
	// 		var++;
	// 	}
	// 	else
	// 	{
	// 		cin >> f >> c;
	// 		if (f == 1)
	// 		{
	// 			x = c;
	// 			if (var % 2)
	// 			{
	// 				a =  a + x;
	// 			}
	// 			else
	// 			{
	// 				a = x + a;
	// 			}
	// 		}
	// 		else
	// 		{
	// 			x = c;
	// 			if (var % 2)
	// 			{
	// 				a = x + a;
	// 			}
	// 			else
	// 			{
	// 				a = a + x;
	// 			}
	// 		}
	// 	}
	// }
	// if (var % 2)
	// {
	// 	reverse(all(a));
	// }
	// //cout << a << en;
	// //return 0;
	// string y = s;
	// reverse(all(y));
	// for (int i = 0; i < a.size(); i++)
	// {
	// 	if (a[i] == '1' || a[i] == '2')
	// 	{
	// 		if (a[i] == '1')
	// 		{
	// 			cout << s;
	// 			i++;
	// 		}
	// 		else
	// 		{
	// 			cout << y;
	// 			i++;
	// 		}
	// 	}
	// 	else
	// 	{
	// 		cout << a[i];
	// 	}
	// }
	// cout << en;


	return 0;
}



Measured memory_bytes: 1764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		boolean checkS = false;
		boolean checkN = false;
		boolean checkW = false;
		boolean checkE = false;
		for(int i=0;i<s.length();i++){
			if(s.charAt(i) == 'S'){
				checkS = true;
			}else if(s.charAt(i) == 'N'){
				checkN = true;
			}else if(s.charAt(i) == 'W'){
				checkW = true;
			}else if(s.charAt(i) == 'E'){
				checkE = true;
			}
		}
		if(checkS == checkN && checkW == checkE){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21200
S = input()
data_list = S.split()
ab_distance = abs(int(data_list[0])-int(data_list[1]))
ac_distance = abs(int(data_list[0])-int(data_list[2]))
bc_distance = abs(int(data_list[1])-int(data_list[2]))
d = int(data_list[3])
if ac_distance <= d:
    print('Yes')
elif ab_distance <= d and bc_distance <= d:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9092
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int n;
	int a,b,c,d;
	int i;
	int mindist=0x7fffffff;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	scanf("%d%d",&c,&d);
	a--;b--;c--;d--;
	for(i=1;i<=n;i++) {
		int ax,ay,bx,by,cx,cy,dx,dy;
		int nowdist;
		ax=a%i;ay=a/i;
		bx=b%i;by=b/i;
		cx=c%i;cy=c/i;
		dx=d%i;dy=d/i;
		nowdist=abs(ax-bx)+abs(ay-by)+abs(cx-dx)+abs(cy-dy);
		if(nowdist<mindist)mindist=nowdist;
	}
	printf("%d\n",mindist);
	return 0;
}

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

using namespace std;

typedef long long ll;
const int N=1e5+9;

int n;
ll l,ans;
char s[N];
int ch[N<<1][2],tot;

inline ll calc(ll depth)
{
	ll dlt=l-depth;
	ll ret=1;
	while(dlt && !(dlt&1))
		ret<<=1,dlt>>=1;
	return ret;
}

inline void insert(char *str)
{
	int len=strlen(str+1);
	int now=0;
	for(int i=1;i<=len;i++)
	{
		if(!ch[now][str[i]-'0'])
			ch[now][str[i]-'0']=++tot;
		now=ch[now][str[i]-'0'];
	}
}

inline void dfs(int u,int depth)
{
	if(depth==l)return;
	if(ch[u][0])
		dfs(ch[u][0],depth+1);
	else
		ans^=calc(depth);
	if(ch[u][1])
		dfs(ch[u][1],depth+1);
	else
		ans^=calc(depth);
}

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	scanf("%d%lld",&n,&l);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		insert(s);
	}
	dfs(0,0);

	puts(ans?"Alice":"Bob");
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define push_back pb
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<ll> A(N);
	int cntminus = 0;
	ll ans = 0;
	ll minabsA = INF;
	rep(i,N){
		cin>>A[i];
		ans +=abs(A[i]);
		minabsA = min(minabsA, abs(A[i]));
		if(A[i]<0)cntminus++;
		//cout<<ans<<endl;
	}
	//print(A);
	if(cntminus%2 == 1){
		ans -= 2*minabsA;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int n;
unsigned long long dp[101][21];

int main () {
	int a;
	cin >> n;
	cin >> a;
	dp[0][a]++;
	for (int i = 1; i < n - 1; i++) {
		cin >> a;
		for (int j = 0; j <= 20; j++) {
			if (j - a >= 0) {
				dp[i][j - a] += dp[i - 1][j];
			}
			if (j + a <= 20) {
				dp[i][j + a] += dp[i - 1][j];
			}
		}
	}
	cin >> a;
	cout << dp[n - 2][a] << endl;
	return 0;
}

Measured memory_bytes: 1172
import java.util.Scanner;
class Main {
public static void main(String[] args) {

try (Scanner sc = new Scanner(System.in)) {
while (true) {
int n = sc.nextInt();
double sum=0.0;
double ssum=0.0;
if (n == 0) { break; }
int[] scores = new int[n];
for (int i = 0; i < scores.length; i++) {
scores[i] = sc.nextInt();
}
double average = 0, variance = 0;
for(int j=0;j<scores.length;j++){
    sum +=scores[j];
}
average=sum/scores.length;
for(int k=0;k<scores.length;k++){
    ssum+=(scores[k]-average)*(scores[k]-average);
}
variance =ssum/scores.length;
System.out.println(Math.sqrt(variance));
}
}
}
}


Measured memory_bytes: 31584
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  int tot = H * W;
  tot -= h * W;
  tot -= w * (H - h);
  cout << tot << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
    int p;
    int left;
    int right;
}Tree;

void preparse(int);
void inparse(int);
void postparse(int);

Tree tree[100];
int n;

int main(){
    int i,root,p,left,right;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        tree[i].p = -1;
    }
    for(i=0;i<n;i++){
        scanf("%d%d%d",&p,&left,&right);
        tree[p].left = left;
        tree[p].right = right;
        if(left != -1) tree[left].p = p;
        if(right != -1) tree[right].p = p;
    }
    
    for(i=0;i<n;i++){
        if(tree[i].p == -1) root = i;
    }
    
    printf("Preorder\n");
    preparse(root);
    printf("\nInorder\n");
    inparse(root);
    printf("\nPostorder\n");
    postparse(root);
    printf("\n");
    return 0;
}

void preparse(int u){
    if(u== -1) return ;
    printf(" %d", u);
    preparse(tree[u].left);
    preparse(tree[u].right);
}

void inparse(int u){
    if(u==-1) return ;
    inparse(tree[u].left);
    printf(" %d",u);
    inparse(tree[u].right);
}

void postparse(int u){
    if(u==-1) return ;
    
    postparse(tree[u].left);
    postparse(tree[u].right);
    printf(" %d", u);
    
}

Measured memory_bytes: 616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

int main(){
    string s; cin >> s;
    int n=s.size();
    int ans=n;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            ans=min(ans,max(i+1,n-i-1));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
from bisect import bisect_left
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))

cumsum = list(accumulate(A))
cumsum.insert(0, 0)

ans = float('inf')
for m in range(2, N-1):
    # 左
    Lmid = cumsum[m] / 2
    Lx = bisect_left(cumsum, Lmid)
    if abs(Lmid-cumsum[Lx]) > abs(Lmid-cumsum[Lx-1]):
        Lx -= 1

    # 右
    Rmid = (cumsum[m] + cumsum[N]) / 2
    Rx = bisect_left(cumsum, Rmid)
    if abs(Rmid-cumsum[Rx]) > abs(Rmid-cumsum[Rx-1]):
        Rx -= 1

    P, Q, R, S = cumsum[Lx], cumsum[m]-cumsum[Lx], cumsum[Rx]-cumsum[m], cumsum[N]-cumsum[Rx]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)


Measured memory_bytes: 90488
X,A,B = map(int,input().split())
N = int(input())
S = [input() for i in range(N)]

for s in S:
  if s=='nobiro':
    X += A
  elif s=='tidime':
    X += B
  else:
    X = 0
  if X < 0: X = 0
print(X)


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;

int main(){
  ll x;
  cin >> x;
  rep(a,200){
    rep(b,200){
      if(pow(a,5)-pow(b,5)==x){cout << a << " "<< b;return 0;}
      if(pow(a,5)+pow(b,5)==x){cout << a << " "<< -b;return 0;}
    }
  }
}


Measured memory_bytes: 4028
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        while (true) {
            c -= b;
            if (c <= 0) {
                System.out.println("Yes");
                return;
            }
            a -= d;
            if (a <= 0) {
                System.out.println("No");
                return;
            }
        }
    }
}

Measured memory_bytes: 35852
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner keyboard = new Scanner(System.in);

		int N = keyboard.nextInt();
		int A1[] = new int[N];
		int A2[] = new int[N];
		
		int a1 = 0;
		for(int n1=0; n1<N; n1++) {
			a1 += keyboard.nextInt();
			A1[n1] = a1;
		}
		
		int a2sum = 0;
		for(int n2=0; n2<N; n2++) {
			A2[n2] = keyboard.nextInt();
			a2sum += A2[n2];
		}
		int ans = a2sum+A1[0];
		
		for(int n=1; n<N; n++) {
			a2sum -= A2[n-1];
			if(ans < A1[n]+ a2sum) {
				ans = A1[n]+ a2sum;
			}
		}
		
		System.out.println(ans);
		keyboard.close();
	}
}


Measured memory_bytes: 36084
import numpy as np
n = int(input())
x = list(map(int, input().strip().split()))

X = np.zeros((100,n))
Y = np.zeros((100,n))
for i in range(100):
    X[i,:] = x
    Y[i,:] = np.full(n,i+1)
#print(X)
#print(Y)

Z = X - Y
#print(Z)
Z = np.power(Z,2)
W = np.sum(Z,axis=1)
print(int(np.min(W)))


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

int main() {
  int N,i,k=0;
  cin >> N;
  vector<int> a(N);
  for(i=0;i<N;++i)
    cin >> a.at(i);
  i=0;
  do{
    ++k;
    i=a.at(i)-1;
    if(i==1)
      break;
  }while(--N);
  if(N==0)
    cout << -1 << endl;
  else
    cout << k << endl;
    
}


Measured memory_bytes: 3796
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        mut k: usize,
    }
    let mut q: VecDeque<usize> = VecDeque::new();
    for i in 1..=9 {
        q.push_back(i);
    }

    while let Some(i) = q.pop_front() {
        k -= 1;
        if k == 0 {
            println!("{}", i);
            return;
        }

        let l = i % 10;
        let n = i * 10 + l;
        if l != 0 {
            q.push_back(n - 1);
        }
        q.push_back(n);
        if l != 9 {
            q.push_back(n + 1);
        }
    }
}


Measured memory_bytes: 4052
N = int(input())
hoge = True
fuga = True
count = 0

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

for i in range(N - 1):
    if l[i] % 2 == 1:
        hoge = False
        break

while True:
    if hoge == False:
        break
    for j in range(N):
        if l[j] % 2 == 1:
            fuga = False
            break
        l[j] = l[j] / 2
    if fuga == False:
        break
    count += 1

if hoge == False:
    print(0)
else:
    print(count)


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


int main(){

  char a, b;
  cin >> a >> b;
  string aa = string(b-'0', a), bb = string(a-'0', b);
  if(aa < bb)
    cout << aa << endl;
  else
    cout << bb << endl;
  
  return 0;
}

Measured memory_bytes: 256
import math
n,k=map(int,input().split())
log=list(map(int,input().split()))
a=0
b=max(log)
if b==1:
  print(1)
  exit()
c=(a+b)//2
while True:
  div=0
  for i in range(n):
    div+=math.ceil(log[i]/c)-1
  if div<=k:
    b=c
    c=(a+b)//2
  else:
    a=c
    c=(a+b)//2
    
  if c==a or c==b:
    break
print(b)

Measured memory_bytes: 104588
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n;
string s;
stack<char> st;
int main() {
    DAU
    cin >> n >> s;
    for (const char& c : s) {
        while (!st.empty() && st.top() == c)
            st.pop();
        st.emplace(c);
    }
    cout << st.size();
    PLEC
}


Measured memory_bytes: 3776
from bisect import bisect_left

s = input()
n = len(s)

ans = [0] * n
p = []
for i in range(n - 1):
    if s[i] == 'R' and s[i + 1] == 'L':
        p.append(i)
        ans[i] += 1
        ans[i + 1] += 1

for i in range(n):
    if ans[i] > 0:
        continue
    if s[i] == 'L':
        to = bisect_left(p, i) - 1
    else:
        to = bisect_left(p, i)
    dist = abs(i - p[to])
    # print(p[to], dist)
    if dist % 2 == 0:
        ans[p[to]] += 1
    else:
        ans[p[to] + 1] += 1
print(*ans)


Measured memory_bytes: 8312
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long

#define INF 999999999

using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
// input
int n;
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;

    int east = 0;

    REP(i, n) if (s[i] == 'E') east++;
    
    int total = east;

    REP(i,n){
        if(s[i] == 'E') east--;
        else east++;
        total = min(east,total);
    }
    cout << total << "\n";
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  string s; cin >> s;
  int n = s.size();
  int ans = 1;
  for (int len = n - 2; len > 0; len -= 2) {
    if (s.substr(0, len / 2) == s.substr(len / 2, len / 2)) {
      ans = len;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp.chars
ans = 110
s.uniq.each do |char|
    count = 0
    str = s.dup
    while str.uniq.size != 1 && count < 110
        count += 1
        for i in 0..str.size-1
            str[i] = (str[i+1] == char ? str[i+1] : str[i])
        end
        str.delete_at(-1)
    end
    ans = [ans, count].min
end
puts ans

Measured memory_bytes: 1788
n, k = map(int, input().split())
v = list(map(int, input().split()))
ret = 0
for l in range(min(n, k) + 1):
    for r in range(min(n, k) - l + 1):
        d = k - l - r
        g = sorted(v[:l] + v[n - r:])
        for i in range(min(d, len(g))):
            g[i] = max(0, g[i])
        ret = max(ret, sum(g))
print(ret)


Measured memory_bytes: 41456
#include<bits/stdc++.h>
#define ll long long
#define all(s0) s0.begin(),s0.end()
#define ins(s0) inserter(s0,s0.begin())
using namespace std;
ll read()
{
    char ch=getchar();
    ll x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
const ll mod=1e9+7;
ll ksm(ll a,ll n)
{
    a%=mod;
    ll ans=1,base=a;
    while(n)
    {
        if(n&1)
            ans=(ans*base)%mod;
        base=(base*base)%mod;
        n>>=1;
    }
    return ans%mod;
}


int main()
{
    ll a,b,n;
    ll ans;
    cin>>a>>b>>n;
    if(n>=b-1)
        ans=(floor)(a*1.0*(b-1)/b);
    else
        ans=(floor)(a*1.0*n/b);
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

//#define MD 100010

int main(){
    int a,b,x;
    cin>>a>>b>>x;
    if(a+b>=x && a<=x){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
    
}

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


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

  int N, ans = 0;
  string S;
  cin >> N >> S;
  int x = 0;
  rep(i, N){
    if(S[i] == 'I'){
      x++;
    }
    else x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
int cnt[1000];
int main(void){    
    IOS;
    int x, n; cin >> x >> n;
    for (int i = 1; i <= n; ++i){
    	int y; cin >> y;
    	cnt[y] = 1;
    }
    for (int i = 0; ; ++i){
    	if (!cnt[x-i]){
    		cout << x-i << endl; return 0;
    	}else if (!cnt[x+i]){
    		cout << x+i << endl; return 0;
    	}
    }
    return 0;
}


Measured memory_bytes: 3648
# include <bits/stdc++.h>
  typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
#define all v.begin(),v.end()
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef unsigned long long ulll;
 
using namespace std ;
int main () {

  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  int x=a+b;
  int y = c+d;
  
  if(x>y)
  cout<<"Left";
  
  else if(x==y)
    cout<<"Balanced";
    
    else
    cout<<"Right";
  return 0;
}

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

int main()
{
  long long N;
  cin >> N;
  string ans;
  while(N)
  {
    N--;
    ans += 'a' + N % 26;
    N /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 3624
n,*a=map(int,open(0).read().split())
d=[0]*-~n
for h,a in zip(a,a[n:]):
    i,s=h,0
    while i:
        s=max(s,d[i])
        i-=i&-i
    s+=a
    i=h
    while i<=n:
        d[i]=max(d[i],s)
        i+=i&-i
print(max(d))

Measured memory_bytes: 125048
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

int main(){
	int h,w,n;
	cin >> h >> w >> n;
	int mx=max(h,w);
	int mi=min(h,w);
	
	int sum=0;
	int cnt=0;;
	for(int i=0;i<mi;i++){
		sum+=mx;
		cnt++;
		if(sum>=n)break;
	}
	cout << cnt << endl;
	
	return 0;
}



Measured memory_bytes: 256
<?php
  list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));

  // $cで割り切れるもの
  $x = intdiv($a-1, $c);
  $y = intdiv($b, $c);
  $c_div_cnt = $y - $x;

  // $dで割り切れるもの
  $x = intdiv($a-1, $d);
  $y = intdiv($b, $d);
  $d_div_cnt = $y - $x;

  // $cと$dの両方で割り切れるもの
  $e = lcm($c, $d);
  $x = intdiv($a-1, $e);
  $y = intdiv($b, $e);
  $e_div_cnt = $y - $x;

//  echo $c_div_cnt." ". $d_div_cnt ." ". $e_div_cnt.PHP_EOL;
  echo ($b - $a + 1) - ($c_div_cnt + $d_div_cnt - $e_div_cnt);

function lcm($a, $b){
  return $a*$b/gcd($a, $b);
}
function gcd($a, $b){
  if($b===0){
    return $a;
  }
  return gcd($b, $a%$b);
}

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

int main(){
  int A, B; cin >> A >> B;
  if (A <= 9 and B <= 9) cout << A * B << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 256
a, b, h, m = input().split()

a = int(a)
b = int(b)
h = int(h)
m = int(m)

#長針は60分で一周、短針は720分で一周
#長針は1分で6、短針は1分で0.5 合わせて5.5度離れる

min = (60 * h) + m
ang0 = (min * 5.5) % 360

if ang0 <= 180:
    ang = ang0
else:
    ang = 360 - ang0

import math
cos_ang = math.cos(math.radians(ang))

x = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * cos_ang))

print(x)


Measured memory_bytes: 9372
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int s, w;

    cin >> s >> w;

    if (s <= w)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
}


Measured memory_bytes: 3636
#include <iostream>

int main() {
    std::string s;
    std::cin >> s;
    int c = 0;
    int length = s.size();
    std::string pattern;
    if (s[0] == '1') {
        pattern = "10";
    }
    else {
        pattern = "01";
    }
    for (int i = 0; i < length; ++i) {
        if (i % 2 == 0 && s[i] != pattern[0]) {
            c++;
        }
        else if (i % 2 == 1 && s[i] != pattern[1]) {
            c++;
        }
    }    
    std::cout << c << std::endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	ff 				first
#define 	ss				second
#define 	pb 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vvll            vector<vll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
 
// vll pwx(22);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 22)pwx[i] = x*(pwx[i-1]); }
 
/* ################################################################ */

#define space 200005

void solve(){ 
    ll n, ans = 0;
    cin >> n;

    string s;
    cin >> s;

    ll w = 0, r = n-1;

    while(w < n && s[w] != 'W')
        w++;

    if(w==n){
        cout << 0 << nl; return;
    }

    while(r >= 0 && s[r] != 'R')
        r--;
    
    if(r == -1){
        cout << 0 << nl; return;
    }

    while(w < r){
        if(s[w] == 'W' && s[r] == 'R'){
            ans++;
            w++;
            r--;

            while(w < n && s[w] != 'W')
                w++;

            while(r >= 0 && s[r] != 'R')
                r--;
        }
    }

    cout << ans << nl;
}

int main(){
    boost;
    // cal(2);

    // For getting input from input.txt file 
    // freopen("running_on_fumes_chapter_1_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);

    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    ll c = 0;
    ll ans = 0;
    for(ll i=1; i<=N; i++){
        ll p;
        cin >> p;
        if(i == p){
            c++;
        }
        else
        {
            ans += (c+1)/2;
            c = 0;
        }
    }
    ans += (c+1)/2;
    c = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int main(){
	int a=read(),b=read(),c=read(),minn=0x3f3f3f3f;
	minn=min(minn,abs(a-b)+abs(b-c));
	minn=min(minn,abs(a-c)+abs(b-c));
	minn=min(minn,abs(c-a)+abs(a-b));
	minn=min(minn,abs(c-b)+abs(a-b));
	minn=min(minn,abs(b-a)+abs(a-c));
	minn=min(minn,abs(c-b)+abs(a-b));
	minn=min(minn,abs(a-b)+abs(a-c));
	minn=min(minn,abs(b-c)+abs(b-a));
	minn=min(minn,abs(c-a)+abs(c-b));
	printf("%d",minn);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n,v[20]={},c[20]={},ans=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &v[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &c[i]);
	for (int i = 0; i < n; i++) {
		if(v[i]>c[i]){
			ans+=v[i]-c[i];
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

#define ull unsigned long long int
#define ll long long int
#define vll vector<ll>
#define vi vector<int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define itr vll::iterator
#define all(c) c.begin(),c.end()
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define inf 1000000000000000001

#define rep(i, n)      for(ll i = 0; i <  n; ++i)
#define repA(i, a, n)  for(ll i = a; i <= n; ++i)
#define repD(i, a, n)  for(ll i = a; i >= n; --i)

using namespace std;

bool func(const pll &a, const pll &b){
    return a.s < b.s;
}

ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}

void solve(){
    ll n;
    cin >> n;
    vll v(n); rep(i, n) cin >> v[i];
    map<ll, ll> cnt;
    cnt[v[0]+1] = 1;
    ll dp[n] = {0};
    dp[0] = 0;
    repA(i, 1, n-1){
        dp[i] = dp[i-1]+cnt[i+1-v[i]];
        // cout << dp[i] << '\n';
        cnt[i+1+v[i]]++;
    }
    cout << dp[n-1];
}

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

    int t, tmp = 0;
    // cin >> t;
    t = 1;
    while(t--){
        // cout << "Case #" << ++tmp << ": ";
        solve();
        if(t) cout << "\n";
    }
    cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 29032
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	k := getInt()
	x := getInt()

	ans := "No"
	if k*500 >= x {
		ans = "Yes"
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1<<18)+10;
int n,N,x,mx;
multiset<int> s;
multiset<int>::iterator it;
int d[maxn],tot;
void del(int x) {
	x=-x;
	it=s.lower_bound(x);
	s.erase(it);
}
int main() {
//	freopen("1.txt","r",stdin);
	read(n); N=1<<n;
	for (int i=1;i<=N;i++) {
		read(x); s.insert(-x);
		mx=max(mx,x);
	}
	tot=1; d[1]=-mx;
	del(mx);
	for (int i=0;i<n;i++) {
		for (int j=1;j<=(1<<i);j++) {
			x=d[j];
			it=s.upper_bound(x);
			if (it==s.end()) { printf("No\n"); return 0; }
			d[++tot]=*it;
			s.erase(it);
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 13568