akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(m), cnt(100010, 0), cnt2(100010, 0);
    vector<string> s(m);
    rep(i, m)cin >> p.at(i) >> s.at(i);
    ll ans1 = 0, ans2 = 0;
    rep(i, m){
        if(s.at(i) == "AC" && cnt.at(p.at(i)) == 0){
            ans1++;
            cnt.at(p.at(i)) = 1;
        }
        if(s.at(i) == "WA" && cnt.at(p.at(i)) == 0)cnt2.at(p.at(i))++;
    }
    REP(i, n)if(cnt.at(i) == 1)ans2 += cnt2.at(i);
    cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int r,d,x; cin>>r>>d>>x;
	For(i,1,10)
	{
		x=r*x-d;
		cout<<x<<"\n";
	}
	return 0;
}















Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;


vector<vector<pii> > G(N);
void print(int x,int y){
    cout<<x<<" "<<y<<endl;
}
main(){
    ll n=in(),k=lin();
    vector<int> v,pre(N,-1),next(N,-1);
    rep(i,n){
        int x=in();
        v.pb(x);
        if(pre[v[i]]==-1)pre[v[i]]=i;
    }
    rep3(i,n-1,0){
        next[i]=pre[v[i]]+1;
        pre[v[i]]=i;
    }
    next[n]=0;
    vector<ll> visited(N);
    visited[n]=1;
    vector<ll> tour={n};
    while(1){
        int pre=tour[tour.size()-1];
        int nx=next[pre];
        //cout<<pre<<nx<<endl;
        while(nx-1>pre){
            nx=next[nx];
        }
        pre=nx;
        //cout<<nx<<endl;
        while(next[nx]-1>pre){
            nx=next[nx];
            pre=nx;
        }
        //cout<<nx<<endl;
        if(visited[nx]){
            //for(auto e:tour)cout<<e<<" ";
            //return 0;
            ll int t=visited[nx]-1;
            ll s=tour.size()-t;
            //cout<<t<<" "<<s<<endl;
            //return 0;
            if(k>t)k=t+(k-t)%s;
                int c=tour[k];
                while(c<n){
                    int pre=c;
                    if(next[c]-1<=c){
                        cout<<v[c]<<" ";
                        c++;
                    }
                    else{
                        c=next[c];
                    }
                }
                return 0;
        }
        else{
            visited[nx]=tour.size()+1;
            tour.pb(nx);
        }
    }
}



Measured memory_bytes: 13808
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "T" : "F");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

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

  int n; cin >> n;
  vector< ld > a(n);
  for(auto &v:a)cin>>v;

  while( a.size() > 1 ) {
    sort(all(a));
    ld x = a[0], y = a[1];
    reverse(all(a)); a.pop_back(), a.pop_back();
    a.emplace_back((x+y)/2);
  }
  cout << a.front() << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int arr[100000];
int main(){
int h,n,sum=0; cin>>h>>n;
if(h<=1e9 && n<=1e5){
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
if(h>sum){
    cout<<"No";
}
else{
    cout<<"Yes";
}
}
}



Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
fumidai_list, A_after = [], 0

for count_a in range(len(A)):
    fumidai = 0

    if(A[count_a] >= A_after):
        A_after = A[count_a]
        fumidai_list.append(fumidai)

    elif(A[count_a] < A_after):
        fumidai = A_after - A[count_a]
        fumidai_list.append(fumidai)

print(sum(fumidai_list))


Measured memory_bytes: 32208
import java.util.Scanner;
 
class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int tmp = 0;
		sc.close();;
		if(a>b){tmp=a;a=b;b=tmp;}
		if(b>c){tmp=b;b=c;c=tmp;}
		if(a>b){tmp=a;a=b;b=tmp;}
		System.out.println(a+b);
	}
 
}


Measured memory_bytes: 21844
N = int(input())
restaurants = list()
for i in range(1, N+1) :
    S, P = input().split()
    r = {'i' : i, 'S' : S, 'P' : int(P)}
    restaurants.append(r)
restaurants.sort(key=lambda r : (r['S'], -r['P']))
for r in restaurants :
    print(r['i'])

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

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

const ll INF = 1e12;
const ll MOD = 1e9 + 7;

ll N, M;
vector<int> r;
vector<int> l;

int main()
{
    cin >> N >> M;
    r.resize(M);
    l.resize(M);
    for (int i = 0; i < M; ++i)
    {
        cin >> l[i] >> r[i];
        --l[i];
        --r[i];
    }
    int left = *max_element(l.begin(), l.end());
    int right = *min_element(r.begin(), r.end());
    cout << max(right - left + 1, 0) << endl;
}


Measured memory_bytes: 1024
from itertools import permutations
N, M, R, *L = map(int, open(0).read().split())
city = L[:R]
inf = L[R:]
dist = [[10**10]*N for i in range(N)]
for x,y,c in zip(*[iter(inf)]*3):
  dist[x-1][y-1] = c
  dist[y-1][x-1] = c
for i in range(N):
  dist[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      dist[i][j] = min(dist[i][k]+dist[k][j], dist[i][j])

ans = 10**10
for m in permutations(city):
  n = 0
  for i in range(R-1):
    n += dist[m[i]-1][m[i+1]-1]
  ans = min(ans,n)
print(ans)  
  


Measured memory_bytes: 49264
from numpy.linalg import solve

#制約
MOD = 10**9 +7
MAX = 10**6

#　組み合わせ計算
def COM(n, r):
    fac = [1, 1]
    finv = [1, 1]
    inv = [0, 1]
    for i in range(2, MAX):
        fac.append(fac[i - 1] * i % MOD)
        inv.append(-inv[MOD % i] * (MOD // i))
        finv.append(finv[i - 1] * inv[i] % MOD)
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

x,y = map(int,input().split())

if (x+y)%3 != 0:
    print(0)
    exit()

l = solve([[2, 1], [1, 2]], [x, y])
if l[0] < 0 or l[1] < 0: #n,m <0の時0
    print(0)
    exit()
# n+m回のうち，どのn回で移動するか n+mCOMnを計算
print(COM(int(l[0]+l[1]), int(l[0])))


Measured memory_bytes: 172692
n = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
a = A[0]/2
num = 100000000000
for i in range(1, n):
  if abs(a-A[i]) < num:
    ans = A[i]
    num = abs(a-A[i])
print(A[0], ans)

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

vector<bool> memo(100005, false);

int main(void) {
  int n, m;
  cin >> n >> m;
  int p[m];
  string s[m];
  rep (i, m) cin >> p[i] >> s[i];

  map<int, int> wawa;

  int ac = 0, wa = 0;
  
  rep (i, m) {
    if (s[i] == "AC") memo[p[i]] = true;

    if (!memo[p[i]] && s[i] == "WA") wawa[p[i]]++;
  }

  for (auto x : wawa) {
    if (memo[x.first]) wa += x.second;
  }
  
  rep (i, n + 1) if (memo[i]) ac++;
  
  cout << ac << " " << wa << endl;
  
  return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int x=0;
	int res=0;
	for (int i=0;i<n;i++){
		if (s[i]=='I') x++;
		else x--;
		res=max(res,x);
	}
	cout<<res<<endl;
	return 0;
}

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

using namespace std;

int main() {
	int N, K; cin >> N >> K;
	int* x = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	int m = 1000000000;
	int a;
	for (int i = 0; i <= N - K; i++) {
		a = min(abs(x[i]), abs(x[i + K - 1]));
		m = min(m, x[i + K - 1] - x[i] + a);
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)















int main(){
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i, h){
        cin >> s[i];
    }
    ll ans = INF;
    REP(bit, (1LL << (h - 1))){
        vector<ll> idx = {-1};
        ll line = 0;
        REP(i, h - 1){
            if(bit & (1LL << i)){
                idx.push_back(i);
                line++;
            }
        }
        idx.push_back(h - 1);
        vector<ll> cnt(line + 1);
        bool ok = true;
        ll res = line;
        REP(j, w && ok){
            bool f = false;
            vector<ll> c(line + 1);
            REP(t, line + 1 && ok){
                for(ll i = idx[t] + 1; i <= idx[t + 1]; i++){
                    if(s[i][j] == '1') c[t]++;
                }
                if(c[t] > k){
                    ok = false;
                    break;
                }
                cnt[t] += c[t];
                if(cnt[t] > k){
                    if(!f){
                        res++;
                    }
                    f = true;
                    cnt[t] = c[t];
                }
            }
            if(f){
                REP(t, line + 1){
                    cnt[t] = c[t];
                }
            }
        }
        if(ok){
            ans = min(ans, res);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){

    int x=0;
    int d;
    while(scanf("%d",&d)!=EOF){
        int s=0;
        while(x<600){
            s+=x*x*d;
            x+=d;
        }
        printf("%d\n",s);
        x=0;
    }
    
}

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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int gcd(int a,int b);

int main(void)
{
  int i;
  int ans=0;
  REP(i,4)
  {
    char str;
    scanf("%c",&str);
    if(str=='+') ans++;
    else ans--;
  }
  printf("%d",ans);
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

ll mod = 1e9 + 7;


int n;
char s[100005];
ll dp[100005][13];

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

	int k=0;
	for(int i=1;i<=n;i+=2) k++;

	double ans = 1.0*k / n;
	cout << ans << endl;

	return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<string>s(n);
  for(int i=0;i<n;i++) cin>>s[i];
  int m;
  cin>>m;
  vector<string>t(m);
  for(int i=0;i<m;i++) cin>>t[i];
  sort(s.begin(),s.end());
  int ans=0;
  int kari=1;
  string u=s[0];
  int i=1;
  while(i<n){
    if(s[i]==u){
      kari++;
      if(i==n-1){
        for(int j=0;j<m;j++){
          if(t[j]==u) kari--;
        }
        ans=max(ans,kari);
      }
    }
    else{
      for(int j=0;j<m;j++){
        if(t[j]==u) kari--;
      }
      ans=max(ans,kari);
      kari=1;
      u=s[i];
      if(i==n-1){
        for(int j=0;j<m;j++){
          if(t[j]==u) kari--;
        }
        ans=max(ans,kari);
      }
    }
    i++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#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>;

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

    int H, W;
    while (1) {
        cin>>H>>W;
        if (H == 0 && W == 0) break;

        rep(i, H) {
            rep(j, W) cout<<"#";
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3128
#include<stdio.h>
int main()
{
    int n, i;
    scanf("%d", &n);
    int a[100000] = {0}, k[100000] = {0};
    for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
    for(i=0;i<n;i++){
        k[a[i]-1] = i+1;
    }
    for(i=0;i<n;i++){
        printf("%d",k[i]);
        if(i!=n-1){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1536
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD 1000000007;

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

    int abs_NM = abs(N - M);
    unsigned long long answer;
    if (abs(N - M) > 1) {
        cout << 0 << endl;
        return 0;
    } else if (abs_NM == 0) {
        answer = 2;
    } else {
        answer = 1;
    }
    while (N > 1) {
        answer *= N;
        answer %= MOD;
        N--;
    }
    while (M > 1) {
        answer *= M;
        answer %= MOD;
        M--;
    }
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
# your code goes here
import numpy as np

def main():
	s = input()
	ans = 0
	w = 0
	for i in range(len(s)):
		c = s[len(s)-1-i]
		if(c == 'B'):
			if(w > 0):
				ans += w
		else:
			w += 1
	
	print(ans)
	
main()

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

using namespace std;

int tab[3][100005];

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;

    long long w=0;

    for(int i=1; i<=n; i++)
    {
        cin>>tab[0][i]>>tab[1][i]>>tab[2][i];
    }

    for(int i=2; i<=n; i++)
    {
        tab[0][i]=max(tab[1][i-1], tab[2][i-1])+tab[0][i];
        tab[1][i]=max(tab[0][i-1], tab[2][i-1])+tab[1][i];
        tab[2][i]=max(tab[0][i-1], tab[1][i-1])+tab[2][i];
    }

    cout<<max(max(tab[0][n], tab[1][n]), tab[2][n]);

    return 0;
}


Measured memory_bytes: 1408
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 200002;
#define endl '\n'
#define ld long double
#define int ll
#define all(x) (x).begin(),(x).end()
#define biton(x, y) (((x>>y)&1ll) == 1)
#define bitoff(x, y) (((x>>y)&1ll) == 0)

int32_t main()
{ 
   IOS
  
  int a, b, c, k;
  cin >> a>>b >> c >> k;
  for(int i = 0;i<=k;i++){
    int A = a;
    int B = b*(1ll<<i);
    int C = c*(1ll<<(k-i));
    if(B>A and C>B){
      cout << "Yes" << endl;
      return 0;
    }
  } 
  cout << "No"<<endl;


 
}

Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string str = Console.ReadLine ();

            int N = int.Parse (str);
            List<int> M = new List<int> ();

            for (int i = 0; i < N; i++)
            {
                int d = int.Parse (Console.ReadLine ());
                if (!M.Contains (d)) M.Add (d);
            }

            Console.WriteLine (M.Count);
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int t(int h, int m) {
  if (11 <= h && h <= 14) return 0;
  if (18 <= h && h < 21) return 1;
  if (21 <= h || h <= 1) return 2;
  return 3;
}

int main() {

  for (int n; cin >> n, n; ) {
    pair<int, int> c[4] = { {0, 0} };
    rep (i, n) {
      int h, m, m2; char colon;
      cin >> h >> colon >> m >> m2;
      if ((m2 - m + 60) % 60 <= 8) {
        car(c[t(h, m)])++;
      }
      cdr(c[t(h, m)])++;
    }

    cout << "lunch ";
    if (cdr(c[0]) == 0) cout << "no guest" << endl;
    else cout << int(car(c[0]) * 100 / cdr(c[0])) << endl;

    cout << "dinner ";
    if (cdr(c[1]) == 0) cout << "no guest" << endl;
    else cout << int(car(c[1]) * 100 / cdr(c[1])) << endl;


    cout << "midnight ";
    if (cdr(c[2]) == 0) cout << "no guest" << endl;
    else cout << int(car(c[2]) * 100 / cdr(c[2])) << endl;

  }

  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=200005;
int n,cnt;
struct ex{int num,next;}map[N*2];
int head[N],d[N],len;bool del[N];
inline void link(int x,int y)
{
  len++;map[len].num=y;map[len].next=head[x];head[x]=len;d[x]++;
  len++;map[len].num=x;map[len].next=head[y];head[y]=len;d[y]++;
}
queue<int>q;
int main( )
{
  int i,x,y,k;
  n=read( );
  if(n&1) {puts("First");return 0;}
  for(i=1;i<n;i++) x=read( ),y=read( ),link(x,y);
  for(i=1;i<=n;i++) if(d[i]==1) q.push(i);
  while(!q.empty( ))
    {
      x=q.front( );q.pop( );y=0;
      if(del[x]) continue;
      for(i=head[x];i;i=map[i].next)
	if(!del[k=map[i].num]) {y=k;break;}
      if(!y) {puts("First");return 0;}
      del[x]=1;del[y]=1;
      for(i=head[y];i;i=map[i].next)
	if((--d[k=map[i].num])==1) q.push(k);
    }
  puts("Second");
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

typedef long long int64;
typedef pair<int64,int64> P;

int64 dx[4]={1,0,-1,0};
int64 dy[4]={0,1,0,-1};

int64 bfs(int64 i, int64 j, const int64& h, const int64& w, const vector<string>& s) {
    int64 res = 0;
    vector<vector<int64>> d(h, vector<int64>(w,-1));
    queue<pair<P,int64>> q;
    q.emplace(P(i,j), 0);

    while(!q.empty()) {
        int64 x,y,c;
        P p;
        tie(p,c) = q.front(); q.pop();
        tie(y,x) = p;

        if (x<0 || w<=x) continue;
        if (y<0 || h<=y) continue;
        if (d[y][x] != -1) continue;
        if (s[y][x] != '.') continue;

        d[y][x] = c;
        res = max(res, c);
        for (int64 k=0; k < 4; k++) {
            int xi,yi;
            xi = x + dx[k];
            yi = y + dy[k];
            if (xi<0 || w<=xi) continue;
            if (yi<0 || h<=yi) continue;
            if (s[yi][xi] != '.') continue;
            q.emplace(P(yi,xi),c+1);
        }
    }
    return res;
}

int main() {
    int64 h,w;
    int64 ans = 0;
    cin >> h >> w;
    vector<string> s(h);
    for (int64 i=0; i<h; i++) cin >> s[i];

    for (int64 i=0; i<h; i++) {
        for (int64 j=0; j<w; j++) {
            if (s[i][j] == '.') {
                ans = max(ans, bfs(i, j, h, w, s));
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    int N;
    scan(N);
    map<string, int> s;
    int mx = 0;
    rep(i, N) {
        string x;
        scan(x);
        if (s.count(x) == 0) {
            s[x] = 1;
        } else {
            s[x]++;
        }
        chmax(mx, s[x]);
    }

    vector<string> ans;
    for (auto &&i : s) {
        if (i.second == mx) {
            ans.emplace_back(i.first);
        }
    }
    sort_(ans);
    vprint(ans);

    return 0;
}

Measured memory_bytes: 25584
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================
	

	ll N, M;
	cin >> N >> M;
	vll X(N), Y(N), Z(N);
	for (int i = 0; i < N; i++) cin >> X[i] >> Y[i] >> Z[i];

	ll ans = 0;
	for (int bit = 0; bit < 8; bit++)
	{
		vbool is_plus = {bool(bit & 1), bool(bit >> 1 & 1), bool(bit>>2 & 1)};

		vll sum(N);
		for (int i = 0; i < N; i++)
		{
			sum[i] = 0;
			if (is_plus[0])
			{
				sum[i] += X[i];
			}
			else
			{
				sum[i] -= X[i];
			}

			if (is_plus[1])
			{
				sum[i] += Y[i];
			}
			else
			{
				sum[i] -= Y[i];
			}		

			if (is_plus[2])
			{
				sum[i] += Z[i];
			}
			else
			{
				sum[i] -= Z[i];
			}
		}

		sort(sum.begin(), sum.end(), greater<ll>());

		ll la = 0;
		for (int i = 0; i < M; i++)
		{
			la += sum[i];
		}

		ans = max(ans, la);



	}



	cout << ans << endl;


}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

	Int W, H, x, y;
	cin >> W >> H >> x >> y;

	long double ans = 0;
	Int flag = 0;

	ans = (long double)W * H / 2;
	
	if (2 * x == W && 2 * y == H)flag = 1;

	cout << ans << " " << flag << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[1010][1010] = {0};
int main()
{
    ll h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for (int i = 0; i < h; i++)
        cin >> grid[i];
    dp[0][0] = 1LL;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (i + 1 < h && grid[i + 1][j] == '.')
            {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= 1000000007;
            }
            if (j + 1 < w && grid[i][j + 1] == '.')
            {
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= 1000000007;
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;



int main(){
    long long x;
    cin >> x;
    for(long long i=-1000; i<1000; i++){
        for(long long j=-1000; j<1000; j++){
            long long a = (i*i*i*i*i);
            long long b = (j*j*j*j*j);
            if(a - b == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n|m){
        vector<int> v(n), u(m);
        int s1 = 0, s2 = 0;
        for (auto &&i : v) scanf("%d", &i), s1 += i;
        for (auto &&j : u) scanf("%d", &j), s2 += j;
        int ans1 = INF<int>, ans2 = INF<int>;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if(s1+u[j]-v[i] == s2 + v[i]-u[j]){
                    if(ans1 + ans2 > u[j] + v[i]){
                        ans1 = v[i], ans2 = u[j];
                    }
                }
            }
        }
        if(ans1 != INF<int>){
            cout << ans1 << " " << ans2 << "\n";
        } else puts("-1");

    }
    return 0;
}



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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i += 2)
	{
		int tmp = 0;
		for (int j = 1; j <= n; j++)
			if (i % j == 0)
				tmp++;
		if (tmp == 8)
			ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main(){
  int mod=1e9+7;
  int n;
  cin>>n;
  int a[n+1];
  for(int i=1;i<=n;i++)
  {
      cin>>a[i];
  }
  bitset<61> b[n+1];
  int c[n+2][61];
  for(int i=1;i<=n;i++)
  {
      for(int j=0;j<=60;j++)
      {
          b[i][j]=a[i]&(1l<<j);
      }
      //std::cout << b[i] << std::endl;
  }
  
  for(int i=n;i>=1;i--)
  {
      for(int j=0;j<=60;j++)
      {
          if(i==n)
          c[i][j]=0;
          c[i-1][j]=(b[i][j]+c[i][j]);
          
          //cout<<c[i][j]<<" ";
      }
      //cout<<endl;
  }
  int res=0;
  for(int i=1;i<=n;i++)
  {
      for(int j=0;j<=60;j++)
      {
          if(b[i][j]==1)
          res=(res+((n-c[i][j]-i)*((1l<<j)%mod))%mod)%mod;
          else
          res=(res+(c[i][j]*((1l<<j)%mod))%mod)%mod;
          res%=mod;
      }
     //  cout<<res<<endl;
  }
  cout<<res%mod<<endl;
  
}

Measured memory_bytes: 147840
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first

#define aLL(str) (str).begin(), (str).end()
#define IOs                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define flu(i, a, b) for (ll i = a; i < b; i++)
#define blu(i, a, b) for (ll i = a; i >= b; i--)
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define Unique(X) (X).erase(unique(all(X)), (X).end())
#define all(v) v.begin(), v.end()
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\n';
ll i, j, le;

int main()
{
	IOs;
	int t;
	t=1;
	while (t--)
	{ ll n,c;
		 cin>>n;
    string s;
    cin>>s;
    ll pre[n+1];
    ll post[n+1];
c=0;
pre[0]=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='W')
            c++;
        if(s[i]=='R')
            pre[i+1]=0;
        else pre[i+1]=1;

      pre[i+1]+= pre[i];
 
    }

    ll ans=min(c,n-c);
    ll temp=0;

    for(i=0;i<n;i++)
    {
        temp= (n-i)-(c-pre[i]);
          

        if(pre[i]>temp)
        {
            ans=min(ans,pre[i]);
        }
        else 
        {
             ans=min(ans,temp);
        }


    }

    cout<<ans;
		
	}

return 0;
}

Measured memory_bytes: 5320
def main():
    S = input()
    Q = int(input())
    reverse = False
    front = []
    back = []
    for _ in range(Q):
        TFC = list(input().split())
        if len(TFC) == 1:
            reverse = not(reverse)
        else:
            t,f,c = TFC
            if reverse:
                if f == "2":
                    front.append(c)
                else:
                    back.append(c)

            else:
                if f == "1":
                    front.append(c)
                else:
                    back.append(c)
    if reverse:
        print("".join(back[::-1]) + S[::-1] + "".join(front))
    else:
        print("".join(front[::-1]) + S + "".join(back))
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 74968
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

cost_0 = 0
cost_last = 0

for n in A:
  if n > X:
    cost_last += 1
  elif n < X:
    cost_0 += 1


if cost_0 >= cost_last:
  print(cost_last)
elif cost_0 < cost_last:
  print(cost_0)

Measured memory_bytes: 9104
#include <iostream>

using namespace std;

int find(string s){
  int ans = 0,flag = 0;
  for(int i = 0 ; i < s.size(); i++){
    if(flag){
      if(s[i] == 'B')
         ans++;
      flag = 0;
    }
    if(s[i] == 'A') flag = 1;
  }
  return ans;
}

int main(){
  int n,ans = 0,a=0,b=0,c=0;
  string s;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    ans+= find(s);
    if(s[s.size()-1] == 'A') a++;
    if(s[0] == 'B') b++;
    if(s[0] == 'B' && s[s.size()-1] == 'A') c++;
  }
  ans += min(a,b);
  if(c == a && c == b && c > 0)
    ans-=1;
  cout << ans;
  return 0;
}


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

int main() {
  ll h, w;
  cin >> h >> w;
  ll ans = 0;
  if (h == 1 || w == 1) {
    ans = 1;
  } else if (h % 2 == 0 && w % 2 == 0) {
    ans = h * w / 2;
  } else {
    if (h % 2 == 0) {
      ans = (h / 2) * w;
    } else if (w % 2 == 0) {
      ans = (w / 2) * h;
    } else {
      ans = (h * w + 1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;

int n;
char s[101];
vector<int> v;

int main() {
    scanf("%d", &n);
    scanf("%s", s);
    
    if (s[0] == ')') v.push_back(0);
    char cnt = 1;
    for (char i = 0; i < n - 1; i++) {
        if (s[i] == s[i + 1]) cnt++;
        else {
            v.push_back(cnt);
            cnt = 1;
        }
    }
    v.push_back(cnt);
    if (s[n - 1] == '(') v.push_back(0);
    
    int a = 0, b = 0;
    for (int i = 0, m = v.size(); i < m; i += 2) {
        if (v[i] < v[i + 1]) {
            int c = v[i + 1] - v[i];
            a += max(0, c - b);
            b = max(b - c, 0);
        }
        else b += v[i] - v[i + 1];
    }
    for (int i = 0; i < a; i++) printf("(");
    for (int i = 0, m = v.size(); i < m; i += 2) {
        for(int j = 0; j < v[i]; j++) printf("(");
        for(int j = 0; j < v[i + 1]; j++) printf(")");
    }
    for (int i = 0; i < b; i++) printf(")");
    printf("\n");

    return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repe(i, n) REPN(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
template <typename T>
void coVec(const Vec1<T> &v){for(T i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	n--;
	b -= a;
	a = 0;
	b = abs(b);
	ll tb = b, tn = n;
	while(b > d){
		n--;
		b -= d;
	}

	if(n%2 == 0){
		if(b <= (d-c)*n/2){
			puts("YES");
			return 0;
		}
	}else{
		ll mini = LINF;
		if(b >= c && b <= d) mini = 0;
		chmin(mini, abs(b-c));
		chmin(mini, abs(b-d));
		if(mini <= (d-c)*(n/2)){
			puts("YES");
			return 0;
		}
	}

	b = tb, n = tn;
	while(b > c){
		n--;
		b -= c;
	}

	if(n%2 == 0){
		if(b <= (d-c)*n/2){
			puts("YES");
			return 0;
		}
	}else{
		ll mini = LINF;
		if(b >= c && b <= d) mini = 0;
		chmin(mini, abs(b-c));
		chmin(mini, abs(b-d));
		if(mini <= (d-c)*(n/2)){
			puts("YES");
			return 0;
		}
	}

	puts("NO");
	return 0;
}


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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import sys
from itertools import combinations, chain
from operator import itemgetter
from functools import reduce

n, m, x = map(int, next(sys.stdin).split())
books = [tuple(map(int, s.split())) for s in sys.stdin]

book_combinations = chain.from_iterable(combinations(books, i)
                                        # because X >= 1
                                        # for i in range(n + 1))
                                        for i in range(1, n + 1))

def total_price(book_list, _price_getter=itemgetter(0)):
  return sum(map(_price_getter, book_list))
def min_score(book_list, _score_getter=itemgetter(slice(1, None))):
  book_scores = map(_score_getter, book_list)
  scores = [0] * m
  for book_score in book_scores:
    for i, score in enumerate(book_score):
      scores[i] += score
  return min(scores)

price_score_list = ((total_price(book_list), min_score(book_list))
                    for book_list in book_combinations)
prices = (price for price, score in price_score_list if score >= x)
answer = min(prices, default=-1)
print(answer)

Measured memory_bytes: 9608
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;

int main() {
  cin >>N;
  vector<int> A(N); rep(i, N) cin >>A[i];
  reverse(all(A));
  rep(i, N){
    cout <<A[i];
    if (i == N-1) cout <<endl;
    else cout <<" ";
  }
}



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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define int long long

template<typename T> constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int N, K;
	cin >> N >> K;

	VI A(N);
	map<int, VI> index;
	int i = 0;
	for (auto& a : A) {
		cin >> a;
		index[a].push_back(i++);
	}

	const int LOG_NK = static_cast<int>(log2(N * K)) + 1;
	VVI w(LOG_NK+1, VI(N));
	for (auto idx : index) {
		int size = idx.second.size();
		idx.second.push_back(idx.second[0] + N);
		rep(i, size) w[0][idx.second[i]] = idx.second[i + 1] - idx.second[i] + 1;
	}

	rep(k, LOG_NK) {
		rep(i, N) {
			w[k + 1][i] = w[k][i] + w[k][(i + w[k][i]) % N];
		}
	}

	int start = 0;
	i = 0;
	while (start + w[0][i] < N * K) {
		int k = 1;
		while (start + w[k][i] < N * K) k++;
		start += w[k-1][i];
		i = (i + w[k-1][i]) % N;
	}
	start = start % N;


	VI s, exist(200001, 0);
	rng(i, start, N) {
		if (exist[A[i]] == 0) {
			s.push_back(A[i]);
			exist[A[i]]++;
		}
		else {
			while (exist[A[i]] > 0) {
				exist[s.back()]--;
				s.pop_back();
			}
		}
	}

	if (s.empty()) cout << endl;
	else {
		for (auto& ans : s) cout << ans << ' ';
		cout << endl;
	}


	return 0;
}


Measured memory_bytes: 121700
def countDiv(x):
  count = 0
  for i in range(1,x+1):
    if x % i == 0:
      count += 1
  return count
 
n = int(input())
ans = 0
for i in range(1,n+1,2):
  #print(i, countDiv(i))
  if countDiv(i) == 8:
    ans += 1
 
print(ans)

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n, m; cin >> n >> m;
    int ans = 0;
    vector<P> v(m);
    rep(i, m) {
        int a, b; cin >> a >> b;
        v[i] = {a, b};
    }
    sort(v.begin(), v.end());
    REP(i, 1, m) {
        if(v[i].first < n) ans += n - v[i].first;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3136