akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

bool topologicalSort(const vector<vector<bool> >& graph, vector<int>& node)
{
    int n = graph.size();
    node.resize(n);

    vector<int> restEdges(n, 0);
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            if(graph[i][j])
                ++ restEdges[j];
        }
    }

    int restNodes = n;
    queue<int> q;
    for(int i=0; i<n; ++i){
        if(restEdges[i] == 0){
            node[n-restNodes] = i;
            q.push(i);
            -- restNodes;
        }
    }

    while(restNodes > 0){
        if(q.empty()){
            node.clear();
            return false;
        }
        int i = q.front();
        q.pop();

        for(int j=0; j<n; ++j){
            if(!graph[i][j])
                continue;
            -- restEdges[j];
            if(restEdges[j] == 0){
                node[n-restNodes] = j;
                q.push(j);
                -- restNodes;
            }
        }
    }

    return true;
}

int solve(vector<string>& s)
{
    int h = s.size();
    int w = s[0].size();

    vector<int> y1(26, INT_MAX), y2(26, INT_MIN), x1(26, INT_MAX), x2(26, INT_MIN);
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(isalpha(s[i][j])){
                int k = s[i][j] - 'A';
                y1[k] = min(y1[k], i);
                y2[k] = max(y2[k], i);
                x1[k] = min(x1[k], j);
                x2[k] = max(x2[k], j);
            }
        }
    }

    vector<vector<bool> > graph(26, vector<bool>(26, false));
    for(int i=0; i<26; ++i){
        for(int y=y1[i]; y<=y2[i]; ++y){
            for(int x=x1[i]; x<=x2[i]; ++x){
                if(s[y][x] == '.')
                    return false;
                int j = s[y][x] - 'A';
                if(j != i)
                    graph[i][j] = true;
            }
        }
    }

    vector<int> node;
    return topologicalSort(graph, node);
}

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

    while(--n >= 0){
        int h, w;
        cin >> h >> w;

        vector<string> s(h);
        for(int i=0; i<h; ++i)
            cin >> s[i];

        if(solve(s))
            cout << "SAFE" << endl;
        else
            cout << "SUSPICIOUS" << endl;
    }

    return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>

long long int cnt[5]={0};
long long int ans=0;

int main(){
    int N;
    char s[11]={0};

    scanf("%d",&N);
    for (int i=0;i<N;i++){
	scanf("%s",s);
	if (s[0] == 'M') cnt[0]++;
	else if (s[0] == 'A') cnt[1]++;
	else if (s[0] == 'R') cnt[2]++;
	else if (s[0] == 'C') cnt[3]++;
	else if (s[0] == 'H') cnt[4]++;
    }

    for (int i=0;i<=2;i++){
	for (int j=i+1;j<=3;j++){
	    for (int k=j+1;k<=4;k++){
		ans+=cnt[i]*cnt[j]*cnt[k];
	    }
	}
    }

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 128
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = s()

cn,cs,ce,cw = 0,0,0,0
for i in range(len(s)):
	if s[i] == "N":
		cn = 1
	elif s[i] == "S":
		cs = 1
	elif s[i] == "E":
		ce = 1
	else:
		cw = 1

if (cn and cs) and (ce and cw):
	print("Yes")
elif (cn and cs) and not(ce or cw):
	print("Yes")
elif not(cn or cs) and (ce and cw):
	print("Yes")
else:
	print("No")

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

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int num = 100 * r + 10 * g + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    int x=log2(n);
    cout<<pow(2,x)<<endl;
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M, Q = map(int, input().split())
    abcd = [tuple(map(int, input().split())) for _ in range(Q)]

    data = [[1]]
    for _ in range(N):
        tmp = []
        for d in data:
            v = d[-1]
            for m in range(M):
                if v + m > M:
                    break
                tmp.append(d + [v + m])
        data = tmp

    ans = 0
    for val in data:
        tmp_ans = 0
        for a, b, c, d in abcd:
            if val[b - 1] - val[a - 1] == c:
                tmp_ans += d
        if tmp_ans > ans:
            ans = tmp_ans
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 108208
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*9
for i in a:
  k=i//400
  if k>=8:
    cnt[8]+=1
  else:
    cnt[k]+=1
z=0
for i in range(8):
  if cnt[i]>=1:
    z+=1
print(1 if z==0 else z,z+cnt[8])

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

  bool zero = false;
  unsigned long long ans = 1;
  for(int i = 0; i < n; i++){
    long long a;
    cin >> a;

    if(a == 0){
      zero = true;
    }

    ans *= a;
  }

  if(ans > 1000000000000000000){
    cout << "-1" << endl;
  }
  else if(ans == 0){
    if(zero){
      cout << "0" << endl;
    }
    else{
      cout << "-1" << endl;
    }
  }
  else{
    cout << ans << endl;
  }

  return 0;

}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
//10:10-10:18
bool cmp(ll a,ll b){
    return llabs(a)<llabs(b);
}
const ll MAX_N=1e5;
ll N,A[MAX_N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    REP(i,N)cin>>A[i];
    sort(A,A+N,cmp);
    ll c=0,ans=0;
    REP(i,N-1){
        ans+=llabs(A[N-1-i]);
        if(A[N-i-1]<0){
            c++;
        }
    }
    if(c%2==0){
        ans+=A[0];
    }else{
        ans-=A[0];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
n , a , b = map(int, input().strip().split())
s = input()
count = 0
foreigner = 0

for i in range(n):
  j = s[i]
  if j == 'a' and count < a + b:
    print('Yes')
    count += 1
  elif j == 'b' and count < a + b and foreigner < b:
    print('Yes')
    count += 1
    foreigner += 1
  else:
    print('No')


Measured memory_bytes: 4016
from collections import Counter

N = int(input())
V = [int(x) for x in input().split()]
if all(v == V[0] for v in V):
    print(N // 2)
    quit()
even = Counter([v for i, v in enumerate(V) if i % 2 == 0])
odd = Counter([v for i, v in enumerate(V) if i % 2 != 0])
evens = even.most_common()
odds = odd.most_common()
if evens[0][0] != odds[0][0]:
    print(N - evens[0][1] - odds[0][1])
elif len(evens) == len(odds) == 1:
    print(N // 2)
elif len(evens) == 1:
    print(min(N - odds[0][1], N - len(evens) - odds[1][1]))
elif len(odds) == 1:
    print(min(N - evens[0][1], N - len(odds) - evens[1][1]))
else:
    print(min(N - evens[0][1] - odds[1][1], N - evens[1][1] - odds[0][1]))


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

const int N = 1e5 + 100;

int n, h, a[N], sum;

int main() {
	cin >> h >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	cout << (sum >= h? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

signed main()
{
    int d, c; cin >> d >> c;

    cout << d * c << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

string s[110], t[110];

int main () {
  int n;
  cin >> n;
  rep(i,n) cin >> s[i];
  int m;
  cin >> m;
  rep(i,m) cin >> t[i];
  int ans = 0;
  rep(i,n) {
    int score = 0;
    rep(j,n) if (s[j] == s[i]) score++;
    rep(j,m) if (t[j] == s[i]) score--;
    ans = max(ans, score);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,k,c;
    cin>>n>>k>>c;

    string s;
    cin>>s;

    vector <int> v,vv;
    int ans = k;
    int len = s.size();
    for(int i=0; i<len; i++){
        if(s[i]=='o'){
            ans--;
            v.push_back(i+1);
            i += c;

            if(ans == 0) break;
        }
    }

    ans = k;
    for(int i=len-1; i>=0; i--){
        if(s[i]=='o'){
            ans--;
            vv.push_back(i+1);
            i -= c;

            if(ans == 0) break;
        }
    }

    sort(vv.begin(), vv.end());
    for(int i=0; i<k; i++){
        if(v[i]==vv[i]) printf("%d\n",v[i]);
    }

    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int indexA, indexZ;
    for(int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A') {
            indexA = i;
            break;
        }
    }
    for(int i = s.size() - 1; i >= 0; i--)
    {
        if (s[i] == 'Z') {
            indexZ = i;
            break;
        }
    }
    cout << indexZ - indexA + 1 << "\n";
}

Measured memory_bytes: 640
package main

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

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	A, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	B, _ := strconv.Atoi(sc.Text())

	C := 0

	if A+B > A-B {
		C = A + B

	} else {
		C = A - B
	}

	if C > A*B {
		fmt.Println(C)
	} else {
		fmt.Println(A * B)

	}

}

Measured memory_bytes: 640
def getDivisableCount(min_bound, max_bound, div):
    return max_bound // div - (min_bound - 1) // div

def LCM(a, b):
    return a * b // GCD(a, b)

def GCD(a, b):
    if a > b:
        a, b = b, a
    while b % a != 0:
        a, b = b % a, a
    return a

if __name__ == '__main__':
    A, B, C, D = [int(i) for i in input().split()]
    ret = (B - A + 1) - getDivisableCount(A, B, C) - getDivisableCount(A, B, D) + getDivisableCount(A, B, LCM(C, D))
    print(ret)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int maxn=1e5+5;
int a[105],b[105];
int main()
{
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int max1=0;
    int min1=0;
    for(int i=0;i<n;i++)
        {
        	cin>>a[i];
        	if(i==0) max1=a[i];
        	if(a[i]>max1) max1=a[i];
		}
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
        if(i==0) min1=b[i];
        if(b[i]<min1) min1=b[i];
	}
    int min2=max(max1,x);
    int max2=min(min1,y);
    if(max2>min2) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define deb(a) cout << #a << ": " << ENDL
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

int main()
{   _
    lli n; cin >> n;
    vi v(n); fore(i, 0, n) cin >> v[i];
    sort(all(v));
    lli ans = 0;
    fore(i, 0, n - 2) {
        fore(j, i + 1, n - 1) {
            fore(k, j + 1, n) {
                if(v[i] == v[j] or v[j] == v[k]) continue;
                if((v[i] + v[j] > v[k]) and (v[i] + v[k] > v[j]) and (v[k] + v[j] > v[i])) ++ans;
            }
        }
    }
    cout << ans << ENDL;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n;
	vector<long long> a;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	long long int h = 0, w = 0;
	for (int i = n - 1;i > 0;i--) {
		if (a[i] == a[i - 1]) {
			h = a[i];
			a[i] = 0;
			a[i - 1] = -1;
			break;
		}
	}
	for (int i = n - 1;i > 0;i--) {
		if (a[i] == a[i - 1]) {
			w = a[i];
			a[i] = 0;
			a[i - 1] = -1;
			break;
		}
	}
	cout << h*w << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
vector<ll> A;

void Gauss(vector<ll> &B){//binary
    int rank=0;
    for(int d=59;d>=0;d--){
        int pivot=-1;
        for(int i=rank;i<(int)B.size();i++){
            if(B[i]&(1ll<<d)){
                pivot=i;
                break;
            }
        }
        if(pivot==-1) continue;
        swap(B[rank],B[pivot]);
        for(int j=0;j<(int)B.size();j++){
            if(j<=rank) continue;
            if(!(B[j]&(1ll<<d))) continue;
            B[j]^=B[rank];
        }
        rank++;
    }
}

int main(){
  cin>>N;
  A.resize(N);
  rep(i,N) cin>>A[i];

  ll sum=0;
  for(int i=0;i<N;i++) sum^=A[i];

  vector<ll> B=A;
  for(int i=0;i<N;i++){
      B[i]&=(~sum);
  }

  Gauss(B);

  ll ans=0;
  for(int i=0;i<N;i++){
      ans=max(ans,ans^B[i]);
  }

  ans*=2;
  ans+=sum;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc133/tasks/abc133_c
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var L, R int

	fmt.Scan(&L, &R)

	ans := 2019

	for i := L; i < min(R, L+2019); i++ {
		for j := i + 1; j <= min(R, L+2019); j++ {
			ans = min(ans, ((i%2019)*(j%2019))%2019)
			//fmt.Printf("ans = %v\n", ans)
			// 割り切れたのなら、これ以上小さくならない
			if ans == 0 {
				break
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
S = input()
N = len(S)

if N % 2 == 0:
    s1 = "10"*int(N/2)
    s2 = "01"*int(N/2)
    c1 = 0
    c2 = 0
    for i,j,k in zip(S,s1,s2):
        if i != j:
            c1 += 1
        elif i != k:
            c2 += 1
        else:
            continue

    print(min(c1,c2)) 

else:
    s1 = "10"*int(N//2) + "1" 
    s2 = "01"*int(N//2) + "0"
    c1 = 0
    c2 = 0

    for i,j,k in zip(S,s1,s2):
        if i != j:
            c1 += 1
        elif i != k:
            c2 += 1
        else:
            continue

    print(min(c1,c2))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 1e16+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;

int main(){
    int n;
    cin>>n;
    if(n==1){
        cout<<1<<endl;

    }
    else{
        if(n%2==1){
            cout<<(float)((n/2)+1)/n<<endl;
        }
        else{
            cout<<0.5<<endl;
        }
    }
}

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

template <typename T>
struct segtree {

  vector<T> seg, lazy;

  segtree(int n = 1e5) {
    n += 5;
    seg.assign(4*n, 1e16);
    lazy.assign(4*n, 1e16);
  }

  T join(T x, T y) {
    return min(x, y);
  }

  void lazy_update(int x, int s, int e) {
    if (lazy[x] == 1e16)  return ;
    seg[x] = min(seg[x], lazy[x]);

    if (s != e)
      lazy[2*x] = min(lazy[2*x], lazy[x]), lazy[2*x+1] = min(lazy[2*x+1], lazy[x]);
    lazy[x] = 1e16;
  }

  void build(int x, int s, int e) {
    if (s == e) {
      seg[x] = 0;
      return; 
    }

    int mid = (s + e) >> 1;
    build(2 * x, s, mid);
    build(2 * x + 1, mid + 1, e);

    seg[x] = join(seg[2*x], seg[2*x+1]);
  }

  void update(int x, int s, int e, int l, int r, T val) {
    lazy_update(x, s, e);
    if (s > r || e < l)  return ;

    if (s >= l && e <= r) {
      lazy[x] = min(lazy[x], val);
      lazy_update(x, s, e);
      return;
    }

    int mid = (s + e) >> 1;
    update(2 * x, s, mid, l, r, val);
    update(2 * x + 1, mid + 1, e, l, r, val);

    seg[x] = join(seg[2 * x], seg[2 * x + 1]);
  }

  T query(int x, int s, int e, int l, int r) {
    lazy_update(x, s, e);
    if (e < l || s > r)  return 1e16;
    if (s >= l && e <= r){
      return seg[x];
    }

    int mid = (s + e) >> 1;
    return join(query(2 * x, s, mid, l, r), query(2 * x + 1, mid + 1, e, l, r));
  }
};

int main() {

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

  int n, m;
  cin >> n >> m;

  vector<pair<pair<int, int>, int>> p;
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;

    p.push_back({{l, r}, c});
  }

  sort(p.begin(), p.end(), [&](auto la, auto lb) {
    return la.first.first > lb.first.first;
  });

  segtree<long long> seg(n);
  seg.update(1, 1, n, n, n, 0);

  for (int i = 0; i < m; ++i) {
    int l = p[i].first.first, r = p[i].first.second, c = p[i].second;
    long long mn = seg.query(1, 1, n, l, r);
    seg.update(1, 1, n, l, l, c + mn);
  }

  long long ans = seg.query(1, 1, n, 1, 1);
  if (ans > 1e15) ans = -1;
  cout << ans << '\n';
}

Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    ll max;
    max = a[0];
    REP(i, n)
    {
        if(max<a[i])
            max = a[i];
        if(max+2<=a[i]||max-2>=a[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
static const int N=100;
int main(){
    int M[N][N];
    int n,u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j)cout<<" ";
            cout<<M[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n,i;
  scanf("%lld",&n);
  ll s1=1,s2=1,p=0,s3=1;
  for(i=1;i<=n;i++)
  {
      s1*=9;
      s2*=10;
      s3*=8; s3=s3%1000000007;
      s1=s1%1000000007;
      s2=s2%1000000007;
  }
  s1=2*s1;
  s1=s1%1000000007;
  p=s2-s1+s3;
  if(p>0)
  {
    printf("%lld",p);
  }
  else
  {
      printf("%lld",(p+1000000007)%1000000007);
  }
  return 0;
}

Measured memory_bytes: 3828
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int counter = 0;
		char[] a;
		Deque<Character> deq = new LinkedList<Character>();
		boolean isABA = true;
		while (in.hasNext()) {
			deq.clear();
			a = in.next().toCharArray();
			for (int i = 0; i < a.length; i++) {
				deq.add(Character.valueOf(a[i]));
			}
			isABA = true;
			while (deq.size() >= 2 && isABA) {
				isABA = deq.pollFirst() == deq.pollLast();
			}
			if (isABA) {
				counter++;
			}
		}
		System.out.println(counter);
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <math.h>
#define pi 3.141592
#define rad(x) ((x)*pi/180)
int main(void){
  double x=0,y=0,d,a,t=90;
  while(1){
    scanf("%lf,%lf",&d,&a);
    if(d==0&&a==0)break; 
    x+=d*cos(rad(t));
    y+=d*sin(rad(t));
    t-=a;
  }
  printf("%d\n%d\n",(int)x,(int)y);
  return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    string s;	cin >> s;
    //solve
    bool ok = false;
    s.pop_back();
    s.pop_back();
    for(int i = s.size(); i && !ok; i-=2){ //2文字づつ減らす
	int l=0, r=i/2;
	int count = 0;
	for(; r<s.size() && s[l] == s[r]; ++l, ++r, ++count);
	if(count==i/2)ok=true;
	else{
	    s.pop_back();
	    s.pop_back();
	}
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 256
using System;

public class Problem {
  public static void Main(string[] args) {
    var str = Console.ReadLine().Split();
    int n = int.Parse(str[0]);
    int k = int.Parse(str[1]);
    int count = 0;
    int num = n;
    
    while (num > 0) {
      num /= k;
      count++;
    }
    
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 11092
/*input
10 8
5 3 6 8 7 10 9 1 2 4
3 1
4 1
5 9
2 5
6 5
3 5
8 9
7 9
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int a[maxn];
int DSU[maxn];
int sz[maxn];

int find(int u){
	if(DSU[u]==u) return u;
	return DSU[u]=find(DSU[u]);
}
void mrg(int u,int v){
	u=find(u),v=find(v);
	if(sz[u]<sz[v]) swap(u,v);
	DSU[v]=u;
	sz[v]+=sz[u];
}
int main()
{
	IOS;
	int n,q;
	cin>>n>>q;
	REP(i,n) DSU[i]=i;
	REP(i,n) sz[i]=1;
	REP(i,n) cin>>a[i];
	REP(i,n) a[i]--;
	while(q--){
		int u,v;
		cin>>u>>v;
		u--;v--;
		mrg(u,v);
	}
	int ans=0;
	REP(i,n) if(find(i)==find(a[i])) ans++;
	cout<<ans<<'\n';
}



Measured memory_bytes: 1408
//
// Created by yoshihito.hotta on 2018/06/10.
//
#include <iostream>
using namespace std;

int main() {
    int i;
    cin >> i;
    int h  = i / 3600;
    int m = (i % 3600) / 60;
    int s = i - 3600 * h - 60 * m;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}



Measured memory_bytes: 3112
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("4");
            //5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("19");
            WillReturn.Add("100");
            //261
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("10");
            WillReturn.Add("0");
            //100
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);
        int A = int.Parse(InputList[1]);
        Console.WriteLine(N * N - A);
    }
}


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

ll X, Y, Z, K;
vector<ll> A, B, C;

void solve() {
  vector<ll> AB;

  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      AB.push_back(A[i] + B[j]);
    }
  }

  sort(C.rbegin(), C.rend());
  sort(AB.rbegin(), AB.rend());

  vector<ll> ABC;
  for (int i = 0; i < min(K, X * Y); i++) {
    for (int j = 0; j < Z; j++) {
      ABC.push_back(AB[i] + C[j]);
    }
  }

  sort(ABC.rbegin(), ABC.rend());
  for (int i = 0; i < K; i++) {
    cout << ABC[i] << "\n";
  }
}

int main() {
  cin >> X >> Y >> Z >> K;
  A.resize(X);
  B.resize(Y);
  C.resize(Z);
  for (int i = 0; i < X; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < Y; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < Z; i++) {
    cin >> C[i];
  }
  solve();
  return 0;
}


Measured memory_bytes: 43240
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin>>s>>t;
  int len = s.length();
  int cnt = 0;
  for(int i=0; i<len; i++)
  {
    if(s[i] != t[i]) cnt++;
  }
  cout<<cnt;
  return 0;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A), q(B), r(C);
  for (auto &it : p)
    cin >> it;
  for (auto &it : q)
    cin >> it;
  for (auto &it : r)
    cin >> it;
  sort(p.begin(), p.end(), greater<ll>());
  sort(q.begin(), q.end(), greater<ll>());
  vector<ll> RGC;
  for (int i = 0; i < X; i++)
    RGC.push_back(p[i]);
  for (int i = 0; i < Y; i++)
    RGC.push_back(q[i]);
  for (int i = 0; i < C; i++)
    RGC.push_back(r[i]);
  sort(RGC.begin(), RGC.end(), greater<ll>());
  ll ans = 0;
  for (int i = 0; i < X + Y; i++)
  {
    ans += RGC[i];
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

void Main()
{
    int x;
    cin >> x;
    if (x == 3 || x == 5 || x == 7)
        cout << "YES";
    else
        cout << "NO";
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;
int H, W;
vector<string> fi;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    cin >> H >> W;
    fi.resize(H);
    for(int i = 0; i < H; ++i) cin >> fi[i];

    vector<vector<int> > dist(H, vector<int>(W, -1));
    using pint = pair<int, int>;
    queue<pint> que;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            if (fi[i][j] == '#') {
                dist[i][j] = 0;
                que.push(pint(i, j));
            }
        }
    }

    while(!que.empty()){
        auto cur = que.front();
        que.pop();
        for(int dir = 0; dir < 4; ++dir){
            int nx = cur.first + dx[dir];
            int ny = cur.second + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (dist[nx][ny] == -1){
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
                que.push(pint(nx, ny));
            }
        }
    }

    int res = 0;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            res = max(res, dist[i][j]);
        }
    }

    cout << res << endl;



}

Measured memory_bytes: 13456
#include <iostream>

using namespace std;

int main(){
    int cnt, h, Max = 0, ans = 0;
    cin >> cnt;
    if(cnt){
        cin >> h;
        Max = h;
        ans++;
    }
    for(int i = 1; i<cnt; i++){
        cin >> h;
        if(h>=Max){
            ans++;
            Max = h;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main(void){
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<"Hello World";
    }
    if(n==2)
    {
        int a,b;
        cin>>a>>b;
        cout<<(a+b);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    long long ans = 0;
    long long useq = (n - n % 2) * 4 * q;
    long long useh = (n - n % 2) * 2 * h;
    long long uses = (n - n % 2) * s;
    long long used = (n - n % 2) / 2 * d;
    ans += min(min(useq, useh), min(uses, used));
    n = n % 2;
    if(n != 0) {
        ans += min(4 * q, min(2 * h, s));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int pangkat[200],ans,n;
bool isprime[200];
vector<int> prime;
vector<int> power;
void sieve (int x){
    for(int i=2;i<=x;i++){
        isprime[i]=true;
    }
    for(int i=2;i<=x;i++){
        if(isprime[i]){
            prime.pb(i);
            for(int j=i*2;j<=x;j+=i){
                isprime[j]=false;
            }
        }
    }
}
void factorize(int x){
    while(x>1){
        for(int i=0;i<prime.size();i++){
            if(x%prime[i]==0){
                x/=prime[i];
                pangkat[prime[i]]++;
                break;
            }
        }
    }

}
void calculate (){
    // product3
    for(int i=0;i<power.size();i++){
        if(power[i]>=5){
            for(int j=i+1;j<power.size();j++){
                if(power[j]>=5){
                    for(int k=0;k<power.size();k++){
                        if(k==i || k==j){continue;}
                        else{
                            if(power[k]>=3){
                                ans++;
                            }
                        }
                    }
                }
            }
        }
    }

    //product2
    for(int i=0;i<power.size();i++){
        for(int j=0;j<power.size();j++){
            if(j==i)continue;
            if(power[i]>=3 && power[j]>=25){ans++;}
            if(power[i]>=5 && power[j]>=15){ans++;}
        }
    }

    //product1
    for(int i=0;i<power.size();i++){
        if(power[i]>=75){ans++;}
    }
}
int main(){
    sieve(150);
    cin>>n;
    for(int i=2;i<=n;i++){
        factorize(i);
    }
    for(int i=1;i<=100;i++){
        if(pangkat[i]>0){
            power.pb(pangkat[i]+1);
        }
    }
    calculate();
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int m, f, b;
	cin >> m >> f >> b;

	if (m >= b){
		cout << 0 << endl;
		return 0;
	}

	if (b - m > f){
		cout << "NA" << endl;
		return 0;
	}

	cout << b - m << endl;
}



Measured memory_bytes: 3100
<?php
$whn = explode(' ', trim(fgets(STDIN)));

$w          = (int)$whn[0];
$h          = (int)$whn[1];
$n          = (int)$whn[2];
$coordinate = [];
$sequence   = [];

while (count($sequence) < $n) {
    $xya          = explode(' ', trim(fgets(STDIN)));
    $coordinate[] = [(int)$xya[0], (int)$xya[1]];
    $sequence[]   = (int)$xya[2];
}

$map = [];
for ($x = 0; $x < $w; $x++) {
    for ($y = 0; $y < $h; $y++) {
        $map[$x][$y] = 1;
    }
}

for ($i = 0; $i < count($sequence); $i++) {
    switch ($sequence[$i]) {
        case 1:
            for ($x = 0; $x < $coordinate[$i][0]; $x++) {
                for ($y = 0; $y < $h; $y++) {
                    $map[$x][$y] = 0;
                }
            }
            break;
        case 2:
            for ($x = $w - 1; $x >= $coordinate[$i][0]; $x--) {
                for ($y = 0; $y < $h; $y++) {
                    $map[$x][$y] = 0;
                }
            }
            break;
        case 3:
            for ($x = 0; $x < $w; $x++) {
                for ($y = 0; $y < $coordinate[$i][1]; $y++) {
                    $map[$x][$y] = 0;
                }
            }
            break;
        case 4:
            for ($x = 0; $x < $w; $x++) {
                for ($y = $h - 1; $y >= $coordinate[$i][1]; $y--) {
                    $map[$x][$y] = 0;
                }
            }
            break;
    }
}

$ans = 0;
foreach ($map as $value) {
    $ans = $ans + array_sum($value);
}
echo $ans;


Measured memory_bytes: 16600
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cctype>
#include <ctime>
#include <set>
#include <algorithm>

namespace LegitStream
{
char bufdatum[BUFSIZ];
char *buf = bufdatum, *endbuf = bufdatum;

inline bool eof(void)
{
    if (endbuf == buf)
    {
        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);
        return endbuf == buf;
    }
    else
        return false;
}

inline int nextch(void)
{
    return eof() ? EOF : *buf++;
}

void legit(void) {}

template<typename Car, typename ...Cdr>
void legit(Car &var, Cdr &...Rest)
{
    int peek;
    while (!isdigit(peek = nextch())
#ifdef LEGIT_NEGI
        && peek != '-'
#endif  // LEGIT_NEGI
        )
        ;
#ifdef LEGIT_NEGI
    bool negi;
    if (peek == '-')
        negi = true;
    else
        negi = false;
#endif  // LEGIT_NEGI
    var = 0;
    do
        var = (((var << 2) + var) << 1) + (peek ^ '0');
    while (isdigit(peek = nextch()));
#ifdef LEGIT_NEGI
    if (negi)
        var = -var;
#endif  // LEGIT_NEGI
    legit(Rest...);
}
}
using LegitStream::nextch;
using LegitStream::eof;
using LegitStream::legit;

void solve(void);

int main(void)
{
#ifdef redirect
    freopen("check/data.in", "r", stdin);
    freopen("check/prog.out", "w", stdout);
    freopen("check/log.out", "w", stderr);
#endif  // redirect
#ifdef chrono
    auto begtm = clock();
#endif  // chrono
    solve();
#ifdef chrono
    auto endtm = clock();
    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);
#endif  // chrono
    return 0;
}

enum class Direction
{
    Left,
    Right,
};

const size_t MaxN = size_t(3e5 + 7);

size_t n;
Direction queue[MaxN];
size_t tol[MaxN], tor[MaxN];

void solve(void)
{
    legit(n);
    for (int i = 0; i < n; ++i)
        queue[i] = nextch() == 'W' ? Direction::Left : Direction::Right;
    tor[0] = (queue[0] == Direction::Right);
    for (int i = 1; i < n; ++i)
        tor[i] = tor[i - 1] + (queue[i] == Direction::Right);
    tol[n - 1] = (queue[n - 1] == Direction::Left);
    for (int i = n - 2; i >= 0; --i)
        tol[i] = tol[i + 1] + (queue[i] == Direction::Left);

    size_t ans = 19260817;
    for (int i = 1; i < n - 1; ++i)
        ans = std::min(ans, n - 1 - tor[i - 1] - tol[i + 1]);
    ans = std::min(ans, n - 1 - tol[1]);
    ans = std::min(ans, n - 1 - tor[n - 2]);
    printf("%llu\n", ans);
}



Measured memory_bytes: 6144
n=int(input())
string_list=[input() for i in range(n)]
list = [x.split() for x in string_list]

count = 0
for s in list:
    if s[0] == s[1]:
        count+=1
        if count == 3:
            break
    else:
        count = 0

if count == 3:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 9172
Module _20190422

    Sub Main()

        Dim iLineCount As Integer = Console.ReadLine()

        Dim iLength() As String = Console.ReadLine().Split(" ")

        '大きい順に並べるバブルソート
        For i As Integer = 0 To iLineCount - 1

            For j As Integer = iLineCount - 1 To i + 1 Step -1

                If CInt(iLength(j)) > CInt(iLength(j - 1)) Then

                    Dim iTemp As String = iLength(j)
                    iLength(j) = iLength(j - 1)
                    iLength(j - 1) = iTemp

                End If

            Next

        Next

        Dim iLongest As Integer = iLength(0)

        Dim iTotal As Integer = 0

        For k As Integer = 1 To iLineCount - 1

            iTotal = iTotal + CInt(iLength(k))

        Next

        If iLongest < iTotal Then

            Console.WriteLine("Yes")

        Else

            Console.WriteLine("No")

        End If

    End Sub

End Module

Measured memory_bytes: 11220
#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>;
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; }
const ll INF = 1LL << 60;

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

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  string s,t;
  cin >> s >> t;
  string ans = "No";
  for(int i = 0 ; i < s.size(); i++){
    if(s == t) ans = "Yes";
    s = s.back() + s.substr(0,s.size()-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

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

            var aaa = str.Replace("2017", "2018");

            Console.WriteLine(aaa);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
vector<vll> S;
//vector<pii> dp;
vector<bool> vis;
pii ways(lli index){
	vis[index] = true;
	lli sz = S[index].size();
	if(sz == 1){
		if(vis[S[index][0]]){
			return  {1, 1};
		}
	}
	lli w = 1;
	lli b = 1;
	loop(i, 0, sz){
		if(vis[S[index][i]] == true)
			continue;
		pii temp = ways(S[index][i]);
		w = (w * (temp.fi + temp.se)%M )%M;
		b = (b * temp.fi) % M;
	}
//	cout<<index<<" "<<w<<" "<<b<<"\n";
	return {w, b};
}
lli solve(){
	lli n;
	cin>>n;
	S.clear();
	S.resize(n+1);
	lli u, v;
	loop(i, 1, n){
		cin>>u>>v;
		S[u].pb(v);
		S[v].pb(u);	
	}
//	dp.clear();
//	dp.resize(n+1, {0, 0});
	vis.clear();
	vis.resize(n+1, false);
	pii temp = ways(1);
	cout<<(temp.fi + temp.se)%M<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 11264