akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>; 



int main(){
    unsigned long long n; cin>>n;
    if(n%2 == 1)cout<<0<<endl;
    else{
        unsigned long long a = 0;
        if(n >= 10){
            for(ll i = 10; i <= n;i *= 5){
                a += n/i;
            }
        }
        cout<<a<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  double n, d, d2;
  cin >> n >> d;
  vector<double> vecXi(n);
  vector<double> vecYi(n);
  vector<double> vecDi2(n);
  int count;
  count = 0;
  d2 = d * d;

  for (int i = 0; i < n; i++) {
    cin >> vecXi.at(i) >> vecYi.at(i);
    vecDi2.at(i) = (vecXi.at(i)*vecXi.at(i))+(vecYi.at(i)*vecYi.at(i));
    if (d2 >= vecDi2.at(i)){
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 8020
h = Hash.new(0)
max_length = 0
max_str = ""
gets.chomp.split.each do |s|
    h[s] += 1
    if s.length > max_length
        max_length = s.length
        max_str = s
    end
end

print h.sort{|(k1, v1), (k2, v2)| v2 <=> v1}[0][0], " ", max_str, "\n"


Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;scanf("%d%d%d",&a,&b,&c);
    if(a>b)swap(a,b);if(b>c)swap(b,c);if(a>b)swap(a,b);
    int p=c-a+c-b;
    if(p%2)printf("%d\n",(p+3)/2);
    else printf("%d\n",p/2);
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 998244353;


int ones(int x) {
    int res = 0;
    while (x) {
        res += x & 1;
        x /= 2;
    }
    return res;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> x(n), y(n), p(n);
    for (int i = 0; i < n; ++i) 
        cin >> x[i] >> y[i] >> p[i];
    vector<ll> res(n + 1, 1LL * 10000 * 1000000 * 20 + 100);
    int up = 1;
    for (int i = 0; i < n; ++i) up *= 3;
    vector<int> a(n);
    vector<vector<ll> > resx(n);
    vector<vector<ll> > resy(n);
    for (int i = 0; i < n; ++i) {
        resx[i].assign(1 << n, abs(x[i]));
        resy[i].assign(1 << n, abs(y[i]));
    }
    for (int m = 0; m < (1 << n); ++m) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if ((m >> j) & 1) {
                    resx[i][m] = min(resx[i][m], abs(x[i] - x[j]));
                    resy[i][m] = min(resy[i][m], abs(y[i] - y[j]));

                }
            }
        }

    }

    for (int msk = 0; msk < up; ++msk) {
        int m = msk;

        for (int i = 0; i < n; ++i) {
            a[i] = m % 3;
            m /= 3;
        }
        int w = 0;
        int mx = 0, my = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] != 0) {
                ++w;
                if (a[i] == 1) {
                    mx += (1 << i);
                }
                else 
                    my += (1 << i);
            }
        }
        ll cur = 0;
        for (int i = 0; i < n; ++i) {
            cur += p[i] * min(resx[i][mx], resy[i][my]);
        }
        res[w] = min(res[w], cur);
    }
    for (int i = 0; i <= n; ++i) {
        cout << res[i] << "\n";
    }
}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 10792
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

int a[N];

int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i>k){
			if(a[i]>a[i-k]) cout<<"Yes\n";
			else cout<<"No\n";
		}
	}
	
	return 0;
}

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

#define X first
#define Y second
using namespace std;

struct UnionFindTree{
	UnionFindTree():pos(pair<int, int>(-1, -1)), root(NULL){}
	pair<int, int> pos;
	UnionFindTree *root;
};

void dfs(int x, int y, int &count, vector<vector<UnionFindTree> > &pos){
	int tmp = count;
	if(pos[pos[y][x].pos.Y][pos[y][x].pos.X].root==NULL){
		if(pos[y][x].root==NULL) pos[pos[y][x].pos.Y][pos[y][x].pos.X].root = &pos[y][x];
		else pos[pos[y][x].pos.Y][pos[y][x].pos.X].root = pos[y][x].root;
		dfs(pos[y][x].pos.X, pos[y][x].pos.Y, count, pos);
	}
	else if(pos[y][x].root == pos[pos[y][x].pos.Y][pos[y][x].pos.X].root){
		count++;
	}
	if(tmp == count) pos[y][x].root = NULL;
	return;
}

int main(){
	int n = 0;
	while(cin >> n && n != 0){
		vector<vector<UnionFindTree> > pos(n, vector<UnionFindTree>(n, UnionFindTree()));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> pos[i][j].pos.X >> pos[i][j].pos.Y;
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(pos[i][j].root != NULL) continue;
				dfs(j, i, count, pos);
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1332
#include <stdio.h>
int n, s, count = 0, digits[10]; // n 個の整数の和がsになる
void dfs(int cur, int start) {              // cur = 0   {}
 if(cur == n) {               // cur = 1   {a}
     int sum = 0;             // cur = 2   {a, b}
     for(int i = 0; i < n; i++) { sum += digits[i]; }
     if(sum == s) { count++; }
     return;
 }
 for(int i = start; i < 10; i++) {
     digits[cur] = i; // FIXME: 重複を避ける
     dfs(cur+1, i+1);  
 }
}
int main(void){
   while(scanf("%d %d",&n,&s)!= EOF){
       if(n == 0 && s == 0){
           break;
       }
       count = 0;
       dfs(0, 0);
       printf("%d\n", count);
   }
 return 0;
}


Measured memory_bytes: 2040
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		//入力表示
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int count = 0;
		
       //配列を使用して身長を比べる
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(scanner.nextInt());
		}

		for (int i = 0; i < N; i++) {
          if (list.get(i) >= K) {
				count++;
			}
		}
		System.out.println(count);
	}
}

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

int main(){
  int n=0;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]!=s[s.size()-1-i]){
      n++;
    }
  }
  cout<<n/2<<endl;
}
    
    
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define inf 9e18
#define pii pair<int,int>
#define setp(x) fixed<<showpoint<<setprecision(x)
#define fastio ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
using namespace std;
long double n;
long double dp[303][303][303];
int a[303];
long double solve(int a1,int a2,int a3){
    if(a1+a2+a3==0)
        return 0;
    if(dp[a1][a2][a3]!=-1)
        return dp[a1][a2][a3];
    long double cur = n/(a1+a2+a3);
    long double q1,q2,q3;
    q1=q2=q3=0;
    long double n2 = a1+a2+a3;
  
    if(a1>0)
        q1 =  a1*solve(a1-1,a2,a3);
    if(a2>0)
        q2 = a2*solve(a1+1,a2-1,a3);
    if(a3>0)
        q3 = a3*solve(a1,a2+1,a3-1);
    cur = cur + (q1+q2+q3)/n2;
    return dp[a1][a2][a3] = cur;
}
int32_t main()
{
    
    fastio
  
    cin>>n;
    int a1,a3,a2;
    a1=a2=a3=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==1)
            a1++;
        else if(a[i]==2)
            a2++;
        else
            a3++;
    }
    for(int i=0;i<303;i++)
        for(int j=0;j<303;j++)
            for(int k=0;k<303;k++)
                dp[i][j][k] = -1;

    long double ans = solve(a1,a2,a3);
    
    cout<<setp(10)<<ans;
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

lli use[20];

lli n;

set<string> ans;
void func(string s,lli now,lli maxBefore){
	if(now==n){
		cout<<s<<endl;
		//ans.insert(s);
		return;
	}
	REP(i,0,maxBefore+1){
		func(s+(char)('a'+i),now+1,max(maxBefore,i+1));
	}
}

signed main(){

	cin>>n;

	string s="a";
	func(s,1,1);
	
	/*
	cout<<endl;
	for(auto e:ans){
		cout<<e<<endl;
	}
	*/
	

	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MAX 1005
#define MOD 1000000007
int dp[MAX][MAX];
signed main()
{
	int h,i,j,w;
	cin>>h>>w;
	string s[h];
	for(i=0;i<h;i++)
	cin>>s[i];
	dp[0][0]=1;
	for(i=0;i<h;i++)
	for(j=0;j<w;j++)
	{
		if(i>0&&s[i-1][j]=='.')
		dp[i][j]=(dp[i-1][j]+dp[i][j])%MOD;
		if(j>0&&s[i][j-1]=='.')
		dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD;	
    }
    cout<<dp[h-1][w-1]<<"\n";
}

Measured memory_bytes: 9088
#include<stdio.h>

int main() {
	int n,i,j,k,b,f,r,v,data[4][3][10] = {0};
	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b,&f,&r,&v);
		data[b-1][f-1][r-1] += v;
	}
	for(i = 0; i < 4; i++) {
		for(j = 0; j < 3; j++) {
			for(k = 0; k < 10; k++) {
				printf(" %d", data[i][j][k]);
			}
			printf("\n");
		}
		if(i != 3) {
			printf("####################\n");
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 612
#include <stdio.h>
int main(void) {

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

    int x, y, z;
    x = a + b;
    y = a - b;
    z = a * b;

    // printf("%d\n", a + b);
    if (x >= y && x >= z)
        printf("%d\n", x);
    if (y > x && y > z)
        printf("%d\n", y);
    if (z > x && z >= y)
        printf("%d\n", z);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const ll INF = 1LL<<60;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll H, n;
  cin>>H>>n;
  vector<P> A(n);
  rep(i,n) cin>>A[i].first>>A[i].second;
  sort(all(A));
  ll max_a = A[n-1].first;
  vector<vector<ll> > dp(n+5,vector<ll>(H+max_a+5, INF));
  rep(i,n) dp[i][0] = 0;
  rep(i,n) {
    ll a = A[i].first, b = A[i].second;
    for (ll h = 0; h < H+max_a+5; ++h) {
      chmin(dp[i+1][h], dp[i][h]);
      if (h - a >= 0) chmin(dp[i+1][h], dp[i+1][h-a] + b);
    }
  }
  ll ans = 1LL<<60;
  for (ll h = H; h < H+max_a+5; ++h) {
    chmin(ans, dp[n][h]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 88448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  double ans = 0;
  rep(i, n - 1) rep2(j, i + 1, n) ans +=
      sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
  ans *= 2 / double(n);
  printf("%.10f\n", ans);
}

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>;
const int INF = 1 << 29;
 
int main() {
	ll n;
	cin >> n;
	bool all9 = true;
	int cnt = 0;
	while (n >= 10)
	{
		if (n % 10 != 9) all9 = false;
		n /= 10;
		cnt++;
	}
	int ans = n + cnt * 9;
	if (all9) cout << ans << endl;
	else cout << ans -1 << endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define maxn 3003
using namespace std;
inline int read()
{
	char x = getchar();
	int lin = 0, f = 1;
	while(x < '0' || x > '9')
	{
		if(x == '-') f = -1;
		x = getchar();
	}
    while(x >= '0' && x <= '9')
	{
		lin = (lin << 1) + (lin << 3) + x - '0';
		x = getchar();
	}
	return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
#define db double
int n,s[maxn][maxn];
signed main(){
	n = read();
	int k = 1 + 8 * n;
	
	if(int(sqrt(k)) * int(sqrt(k)) != k || !(int(sqrt(k)) & 1))
	{
		cout << "No";
		return 0;
	}
	k = int(sqrt(k)) - 1 >> 1;
	printf("Yes\n%d\n",k + 1);
	int up = 0,now = 0;
	for(int i = 1; i <= k + 1; i++)
	{
		for(int j = i; j <= k; j++)
			s[i][j] = ++now;
		for(int j = i + 1; j <= k + 1; j++)
			s[j][i] = ++up;
	}
	for(int i = 1; i <= k + 1; i++)
	{
		printf("%d ",k);
		for(int j = 1; j <= k; j++)
		{
			printf("%d ",s[i][j]);
		}
		puts("");
	}
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a), _##i = (b); i < _##i; ++i)
#define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i)
#define pb push_back
typedef long long LL;

int n;
LL a[100004];

LL solve(LL sum){
	
	LL res = 0;	
	FOR(i,1,n){	
		if(sum < 0){
			if( sum + a[i] > 0){			
				sum += a[i];
				continue;		
			}		
			res+= 1 - (sum + a[i]);
			sum = 1;
		}else{
			if( sum + a[i] < 0) {			
				sum += a[i];
				continue;		
			}
			res+= (sum + a[i]) + 1;
			sum = -1;
		}
	}	
	return res;
}

int main(){
	//freopen("test.in","r",stdin);
	cin>> n;
	REP(i,n){
		cin >> a[i];
	}
	LL sum = a[0];
	if(sum){
		if( sum > 0){
			cout << min( solve(-1) + sum + 1, solve(sum) ) << endl;
		}else{
		
			cout << min( solve(1)  - sum + 1, solve(sum) ) << endl;
		}
		//cout << solve(sum) << endl;
	}else{
		cout << min( solve(1), solve(-1) ) + 1 << endl;
	}	
	return 0;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    static class ABC085B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 整数の入力
            int n = Integer.parseInt(in.next());
            Integer[] d = new Integer[n];
            for (int i = 0; i < n; i++) {
                d[i] = Integer.parseInt(in.next());
            }
            Set<Integer> ans = new HashSet();
            for (int i = 0; i < n; i++) {
                ans.add(d[i]);
            }


            // 出力
            out.println(ans.size());

        }

    }
}



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

int main() {
  
  int X, A, B;
  cin >> X >> A >> B;
  
  if(A >= B){
    cout << "delicious" << endl;
  }
  else if(A < B && B - A <= X){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
  
}


Measured memory_bytes: 384
#!/usr/bin/python3
#coding: utf-8

from collections import defaultdict

N, X = (int(x) for x in input().split())

memo = {}

def size_lv(lv):
    if lv == 0:
        return 1
    if lv not in memo:
        memo[lv] = size_lv(lv-1) * 2 + 3
    return memo[lv]

memo2 = {}
def num_pty(lv, X):
    if (lv, X) in memo2:
        return memo2[(lv, X)]
    if X == 0:
        return 0

    if lv == 0:
        memo2[(lv, X)] = 1
        return memo2[(lv, X)]

    prevSize = size_lv(lv-1)
    if X <= prevSize+1:
        memo2[(lv, X)] = num_pty(lv-1, X-1)
        return memo2[(lv, X)]
    
    if X == prevSize + 2:
        memo2[(lv, X)] = num_pty(lv-1, prevSize) + 1
        return memo2[(lv, X)]
    
    memo2[(lv, X)] = num_pty(lv-1, prevSize) + 1 + num_pty(lv-1, min(X-prevSize-2, prevSize))
    return memo2[(lv, X)]
    
print(num_pty(N, X))

# BBPPPBPBPPPBB
# BPPPB

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;


int main() {

double n;
cin>>n;
int ans;
ans=n/1.08;
int sum1=ans*1.08,sum2=(ans+1)*1.08,sum3=(ans-1)*1.08;

if(n==sum1){
    cout<<ans<<endl;
}
else if(n==sum2){
    cout<<ans+1<<endl;
}
else if(n==sum3){
    cout<<ans-1<<endl;
}
else{
    cout<<":("<<endl;
}
}

Measured memory_bytes: 256
def main
  _, total = gets.split.map(&:to_i)

  children = gets.split.map(&:to_i).sort

  acc = 0
  children.each_with_index do |n, i|
    acc += n

    if total < acc
      # 足りない
      puts i
      return
    end
  end

  if total == acc
    # ぴったり
    puts children.length
  else
    # あまり
    puts children.length - 1
  end
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (ll i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	string S, T;
	cin >> S >> T;
	string ans = "No";
	REP(i, S.size() + 1) {
		if (S == T) {
			ans = "Yes";
		}
		rotate(S.rbegin(), S.rbegin() + 1, S.rend());
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val reds, blues = List.fill(n)((sc.nextInt(), sc.nextInt()))
  val e = for {
    ((a, b), i) <- reds.zipWithIndex
    ((c, d), j) <- blues.zipWithIndex
    if a < c && b < d
  } yield (i, j)

  println(maximumMatching(n, n, e))

  def maximumMatching(n: Int, m: Int, e: Seq[(Int, Int)]): Int = {
    val adj = Array.fill(n)(List[Int]())
    for ((u, v) <- e) {
      adj(u) ::= v
    }

    val pair = Array.fill(m)(-1)

    def find(u: Int): Boolean = {
      val visited = Array.fill(m)(false)

      def dfs(u: Int): Boolean = {
        adj(u).find { v =>
          if (!visited(v)) {
            visited(v) = true
            pair(v) == -1 || dfs(pair(v))
          } else {
            false
          }
        } match {
          case Some(v) =>
            pair(v) = u
            true
          case None => false
        }
      }

      dfs(u)
    }

    (0 until n).count(find)
  }
}


Measured memory_bytes: 56180
#include <bits/stdc++.h>
#define f(a, n) for (int a=0; a<n; a++)
#define F(a, n) for (int a=1; a<=n; a++)
using namespace std;
/*
query 1, 10, 100, ... This will be YES up to the order of magnitude, then no. Check with 9s. Then bsearch.
*/

int digits=0;
string resp = "Y";

void query (long long x){
	cout<<"? "<<x<<endl;
	cin>>resp;
}
int main() {
	cin.tie(NULL);
	ios::sync_with_stdio(0);
	query (1e10);
	if (resp == "Y"){
		for (int i=9; i>=0; i--){
			query(2*pow(10, i));
			if (resp == "N") {
				cout<<"! "<<int(pow(10, i+1))<<endl;
				return 0;
			}
		}
		cout<<"! "<<1<<endl;
		return 0;
	}
	resp = "Y";
	while (resp == "Y"){
		digits++;
		query(pow(10, digits));
	}
	query(pow(10, digits)-1);
	if (resp == "N"){
		cout<<"! "<<int(pow(10, digits))<<endl;
		return 0;
	}
	else{
		long long high = pow(10, digits)-1, low = pow(10, digits-1)+1;
		while (high>low){
			long long guess = (high + low)/2;
			query(guess*10ll);
			if (resp == "Y") high = guess;
			else low = guess+1; 
		}
		cout<<"! "<<low<<endl;
	}
	
}




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

const int N = 100010;
int n, a[N];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	bool flag = true;
	if(n % 3 == 0) {
		if(a[1] != a[n / 3] || a[n / 3 + 1] != a[n / 3 * 2] || a[n / 3 * 2 + 1] != a[n])
			flag = false;
		if(a[1] ^ a[n / 3 + 1] ^ a[n]) flag = false;
	} else if(a[n] == 0) flag = true;
	else flag = false;
	if(flag) puts("Yes");
	else puts("No");
}

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

void prinv(vector<int> &a){
  for (int i=0; i<a.size(); i++){
    cout <<a[i];
    if (i == a.size()-1) cout <<endl;
    else cout <<" ";
  }
}

int main() {
  cin >>N;
  vector<int> A(N); rep(i, N) cin >>A[i];
  prinv(A);
  for (int i=1; i<N; i++){
    int v = A[i];
    int j = i-1;
    while (j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    prinv(A);
  }
}


Measured memory_bytes: 3148
#include <iostream>
using namespace std;
int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a == b && b == c && a % 2 == 0) { cout << -1 << endl; return 0; }
    int ans = 0;
    while (a%2 == 0 && b%2 == 0 && c%2 == 0) {
        ans++;
        int a1 = (b + c) / 2, b1 = (a + c) / 2, c1 = (a + b) / 2;
        a = a1; b = b1; c = c1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> anList = new ArrayList<Integer>();

		for(int i = 0; i < N; i++) {
			anList.add(sc.nextInt());
		}

		Collections.sort(anList, Comparator.naturalOrder());

		System.out.println(anList.get(N-1) - anList.get(0));
	}
}

Measured memory_bytes: 20948
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            ans = i*500+j*100+k*50
            if x == ans:
              cnt += 1


print(cnt)

Measured memory_bytes: 3060
package main

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

var (
	D int
	c [26]int
	s [365][26]int
)

func main() {
	readVariables()
	for row := 0; row < D; row++ {
		// fmt.Println(maxGreed(row))
		fmt.Println(row%26 + 1)
	}
}

func maxGreed(row int) int {
	max := 0
	result := 0
	for i, v := range s[row] {
		if v > max {
			result = i
			max = v
		}
	}
	return result + 1
}

func readVariables() {
	D = nextInt()
	for i := 0; i < 26; i++ {
		c[i] = nextInt()
	}
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			s[i][j] = nextInt()
		}
	}
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


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

vector<int*> dat;
int r, c;

int topow2(int a){
	while( a & (a - 1) ) {
		a += a & -a;
	}
	return a;
}


int query2(int c1, int c2, int kr, int k = 0, int left = 0, int right = c){
	if( right <= c1 || c2 <= left ) return INT_MAX;
	if( c1 <= left && right <= c2 ){
		return dat[kr][k];
	}
	
	int mid = (left + right) / 2;
	int vl = query2(c1, c2, kr, k * 2 + 1, left, mid);
	int vr = query2(c1, c2, kr, k * 2 + 2, mid, right);
	return min(vl, vr);
}

int query1(int r1, int r2, int c1, int c2, int k = 0, int left = 0, int right = r){
	if( right <= r1 || r2 <= left ) return INT_MAX;
	if( r1 <= left && right <= r2 ) return query2(c1, c2, k);
	
	int mid = (left + right) / 2;
	int vl = query1(r1, r2, c1, c2, k * 2 + 1, left, mid);
	int vr = query1(r1, r2, c1, c2, k * 2 + 2, mid, right);
	return min(vl, vr);
}


int main(){
	int r0, c0, q;
	int r1, c1, r2, c2;
	
	vector<int> buf(8388608);

	while( scanf("%d%d%d", &r0, &c0, &q), r0 != 0 ){
		r = topow2(r0);
		c = topow2(c0);

		dat.resize(r * 2 - 1);
		for(int i = r * 2 - 2; i >= 0; --i){
			dat[i] = &buf[i * (c * 2 - 1)];
			fill(dat[i], dat[i] + (c * 2 - 1), INT_MAX);
		}

		vector<int> datr(c * 2 - 1, INT_MAX);

		for(int i = 0; i < r0; ++i){
			for(int j = 0; j < c0; ++j){
				scanf("%d", &datr[j + c - 1]);
			}
			
			for(int j = c - 2; j >= 0; --j){
				datr[j] = min(datr[j * 2 + 1], datr[j * 2 + 2]);
			}
			copy(datr.begin(), datr.end(), dat[i + r - 1]);
		}

		for(int j = 0; j < c * 2 - 1; ++j){
			for(int i = r - 2; i >= 0; --i){
				dat[i][j] = min(dat[i * 2 + 1][j], dat[i * 2 + 2][j]);
			}
		}

		for(int i = 0; i < q; ++i){
			scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
			printf("%d\n", query1(r1, r2 + 1, c1, c2 + 1) );
		}
	}
}

Measured memory_bytes: 50200
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int min = 10000000;
        int max = -10000000;
        long sum = 0;

        for(int i = 0;i < n;i++){
            int x [] =new int[n];
            x[i]= sc.nextInt();

            if(min >  x[i]){
                min =  x[i];
            }
            if(max < x[i]){
                max = x[i];
            }
            sum += x[i];

        }
        System.out.println(min + " " + max + " " + sum);
        sc.close();
    }

}


Measured memory_bytes: 163172
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define sz 100000
typedef long long ll;
using namespace std;


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


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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
const int mod = (int)1e9 + 7;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}


int main(){

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

    ll n;
    cin >> n;

    ll res = n - 1;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res = min(res, i + n / i - 2);
    }

    cout << res << endl;

    return 0;
}

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

int main(){
    vector<int> H;
    vector<int> W;
    int h;
    int w;
    
    while(1){
      cin >> h >> w;
      if(h==0 && w==0) break;
      H.push_back(h);
      W.push_back(w);
    }

    
    for(int i=0;i<H.size();i++){
      if(H[i]==0 && W[i]==0) break;
      for(int j=0;j<H[i];j++){
	for(int k=0;k<W[i];k++){	  
	  if((j+k)%2!=0){
	    cout << ".";
	  }
	  else cout << "#";
	}
	cout << endl;
      }
      cout << endl;
    }
   
    return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define inf 1e12+1
typedef long long int ll;
typedef pair<ll,ll> mypair;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){

	ll v,e;
	cin>>v>>e;
	vector<vector<mypair> > g(v);
	vector<vector<ll> > dp(v,vector<ll>(v,inf) );
	ll s,t,d;
	rep(i,e){
	       	cin>>s>>t>>d,g[s].push_back(mypair(t,d) );
		dp[s][t]  = d;
	}
	rep(i,v)dp[i][i]=0;
	rep(k,v)rep(i,v)rep(j,v)if(dp[i][k]!=inf&dp[k][j]!=inf)dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
	bool flag =false;
	rep(i,v)if(dp[i][i]!=0)flag = true;
	if(flag){
	cout<<"NEGATIVE CYCLE"<<endl;
	}else{
	rep(i,v){
	rep(j,v){
	if(dp[i][j]==inf)cout<<"INF";
	else cout<<dp[i][j];
	if(j==v-1){}
	else cout<<' ';
	}
	cout<<endl;
	}
	}
		
	

	return 0;
}






Measured memory_bytes: 3276
import math


a, b, x = map(int, input().split())

if x >= a ** 2 * b:
    print(0)
else:
    if 2 * x >= b * a ** 2:
        c = 2 * (b * a ** 2 - x) / a ** 2
        print(math.degrees(math.atan(c/a)))
    else:
        c = 2 * x / (a * b)
        print(math.degrees(math.atan(b/c)))

Measured memory_bytes: 3188
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x;
		for(int i = 1; (x = scan.nextInt()) != 0; i++){
			System.out.println("Case " + i + ": " + x);
		}
	}

}

Measured memory_bytes: 41920
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int P = 998244353;
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0)
    a += P;
}
int mul(int a,int b){
  return a * b % P;
}

string s;
int k;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> s >> k;
  s += '0';
  int n = SZ(s);
  vector<vector<int>> dp(n + 1,vector<int>(n+1));
  dp[0][0] = 1;
  int il1 = 0;
  R(i,n){
    if(s[i] == '1'){
      il1++;
    }else{
      auto ak = dp;
      R(j,n+1)R(l,n){
        add(dp[j][l+1], dp[j][l]);
      }
      R(ii,il1+1)if(ii)R(j,n-ii)R(l,n+1){
        if(j+ii <= l)
          add(dp[j+ii][l], ak[j][l]);
      }
      il1 = 0;
    }
    R(jj,3){
      R(kk,3){
        cerr << dp[jj][kk] << " ";
      }
      cerr << "\n";
    }
    cerr << "\n";
  }
  int res = 0;
  R(i,min(n+1,k+1)){
    debug(dp[i][i]);
    add(res, dp[i][i]);
  }
  cout << res << "\n";
}


Measured memory_bytes: 4764
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 1000000007
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int inv(int x) {return qpow(x,maxd-2);}

	int c(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	int math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;
int n,A,B,C,D,f[1010][1010];

int main()
{
	n=read();A=read();B=read();C=read();D=read();
	math_init();
	f[0][0]=1;
	rep(i,1,B-A+1)
	{
		int t=i+A-1;
		rep(j,0,n)
		{
			f[i][j]=f[i-1][j];
			rep(k,C,D)
			{
				if (k*t>j) continue;
				int tmp=mul(f[i-1][j-k*t],c(n-j+k*t,k*t));
				tmp=mul(mul(tmp,invfac[k]),mul(qpow(invfac[t],k),fac[k*t]));
				f[i][j]=add(f[i][j],tmp);
			}
		}
	}
	printf("%d",f[B-A+1][n]);
	return 0;
}
		



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
	int n; cin >> n;
    vector<string> s(n);

	rep(i,n) cin >> s[i];

	string ans;

	for (char c = 'a'; c <= 'z'; c++){
		int small = 1002003004;

		rep(i,n){
			int cnt = 0;

			for (int j = 0; j < s[i].size(); j++){
				if (s[i][j] == c)cnt++;

			}
			small = min(small, cnt);
		}

		rep(i,small){
			ans += c;
		}

	}

    cout << ans << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,max=0;
  string s;
  cin>>n>>s;
  vector<int> w(n),e(n);
  
  w.at(0)=0;
  for(int i=0; i<n-1; i++){
    w.at(i+1)=w.at(i);
    if(s.at(i)=='E')w.at(i+1)++;
  }
  reverse(s.begin(),s.end());
  e.at(0)=0;
  for(int i=0; i<n-1; i++){
    e.at(i+1)=e.at(i);
    if(s.at(i)=='W')e.at(i+1)++;
  }
  reverse(e.begin(),e.end());
  
  for(int i=0; i<n; i++){
    int a=w.at(i)+e.at(i);
    if(max<a)max=a;
  }
  cout<<n-max-1<<endl;
}

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

typedef long long LL;

const int N=100000,INF=(1<<30)-1,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

char s[N*3+9];
int n;

void into(){
  scanf("%d%s",&n,s+1);
}

int a[N*3+9],ans;

void Get_ans(){
  for (int i=1;i<=n*3;++i) a[i]=s[i]=='R'?0:s[i]=='G'?1:2;
  int c[3]={0,0,0};
  ans=1;
  for (int i=1;i<=3*n;++i){
	int t=INF;
	if (c[0]>c[a[i]]) t=min(t,c[0]-c[a[i]]);
	if (c[1]>c[a[i]]) t=min(t,c[1]-c[a[i]]);
	if (c[2]>c[a[i]]) t=min(t,c[2]-c[a[i]]);
	if (t<INF) smul(ans,t);
    ++c[a[i]];
	t=min(c[0],min(c[1],c[2]));
	c[0]-=t;c[1]-=t;c[2]-=t;
  }
  for (int i=1;i<=n;++i) smul(ans,i);
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

string to_small(string str){
	string rst = "";
	REP(i,str.size()){
		if('A'<=str[i]&&str[i]<='Z') rst += str[i] + ('a'-'A');
		else rst += str[i];
	}
	return rst;
}
int main(){
	string word;
	cin >> word;
	word = to_small(word);
	ll int cnt = 0;
	while(1){
		string s;
		cin >> s;
		if(s=="END_OF_TEXT") break;
		s = to_small(s);
		if(s==word) cnt++;
	}
	cout << cnt << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	string s;
	cin >> s;

	string str[3] = {"Sunny","Cloudy","Rainy"};
	for(int i = 0; i < 3; i++){
		if(s == str[i]) cout << str[(i+1)%3] << endl;
	}
	return 0;
}

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

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

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

    printf("%d %d %d\n", c, a, b);

    return 0;
}


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

long long k,a[210],b,b1,c,n;
string s;
char pre;

int main(){
    cin>>s>>k;
    n=s.size();
    pre=s[0];
    for(int i=1;i<n;i++){
        if(s[i]==pre){
            if(!a[i-1]){
                b++;
                a[i]=1;
            }
        }
        pre=s[i];
    }
    if((s[0]!=s[n-1]) || a[n-1]){
        cout<<b*k<<endl;
        return 0;
    }
    for(int i=n;i<2*n;i++){
        if(s[i-n]==pre){
            if(!a[i-1]){
                b1++;
                a[i]=1;
            }
        }
        pre=s[i-n];
    }
    if(a[n*2-1])cout<<(k+1)/2*b+k/2*b1<<endl;
    else cout<<b+(k-1)*b1<<endl;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n;
	while (1) {
		cin >> n;
		if (n == 0) break;
		VS ss;
		bool l = false, r = false;
		rep (i, n) {
			string s;
			cin >> s;
			ss.pb(s);
		}
		int ans = 0;
		bool flag = false;
		for (string s : ss) {
			if (s == "lu") l = true;
			else if (s == "ru") r = true;
			else if (s == "ld") l = false;
			else r = false;
			if (l && r && !flag) {
				flag = true;
				ans++;
			}
			if (!l && !r && flag) {
				flag = false;
				ans++;
			}
		}
		cout << ans << endl;

	}
	return 0;
}

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

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> p(n);
  for(int i = 0; i<n-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    p.at(a).push_back(b);
    p.at(b).push_back(a);
  }
  queue<int> que;
  que.push(v);
  vector<int> ku(n, -1), kv(n, -1);
  kv.at(v) = 0;
  ku.at(u) = 0;
  while(!que.empty()){
    int w = que.front();
    que.pop();
    for(int i : p.at(w)){
      if(kv.at(i) != -1) continue;
      kv.at(i) = kv.at(w) + 1;
      que.push(i);
    }
  }
  que.push(u);
  while(!que.empty()){
    int w = que.front();
    que.pop();
    for(int i : p.at(w)){
      if(ku.at(i) != -1) continue;
      ku.at(i) = ku.at(w) + 1;
      que.push(i);
    }
  }
  int out = 0;
  for(int i = 0; i< n; i++){
    if(ku.at(i) <= kv.at(i)){
      if(kv.at(i) > out) out = kv.at(i);
    }
  }
  if(out == 0) out = 1;
  cout << out - 1;
}

Measured memory_bytes: 6656
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	int a, b;
	cin >> a >> b;

	cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 3628
n, l = [int(item) for item in input().split()]
apples = [item + l for item in range(n)]
if apples[0] <= 0 and apples[-1] >= 0:
    print(sum(apples))
elif apples[0] > 0:
    print(sum(apples[1:]))
else:
    print(sum(apples[:-1]))

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

int main() {
	ios::sync_with_stdio(false);
	int N, Q;
	string S;
	cin >> N >> Q >> S;

	vector<int> l(Q), r(Q);

	for (int i = 0; i < Q; i++) {
		cin >> l.at(i) >> r.at(i);
	}

	vector<int> indexs;
	for (int i = 0; i < N - 1; i++) {
		if (S.at(i) == 'A' && S.at(i + 1) == 'C') {
			indexs.push_back(i);
		}
	}


	indexs.push_back(N-1);

	/////////////////////////////////////////////////
	/*cout << "indexs\n";
	for (auto&i:indexs) {
		cout << i<< " ";
	}*/

	vector<int> sum(N);
	int cnt=0, now=0;
	for (auto&i:indexs) {
		for (;now <= i;now++) {
			sum.at(now)=cnt;
		}
		cnt++;
	}
	///////////////////////////////////////////////
	//cout << "cnt:" << cnt;
	//cout << "\nsum\n";
	//for (auto&i:sum) {
	//	cout << i << " ";
	//}

	for (int i = 0; i < Q; i++) {
		cout << (sum[r[i] - 1] - sum[l[i] - 1]) << "\n";
	}

	return 0;
}

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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a+b > c+d)
    cout << "Left" << endl;
  if(a+b == c+d)
    cout << "Balanced" << endl;
  if(a+b < c+d)
    cout << "Right" << endl;
}

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 1e5 + 5;

int C[N], D[N];
vector<int> G[N];

void DFS(int v, int p, int &x) {
	for (int u : G[v]) if (u != p) DFS(u, v, x);
	D[v] = C[x++];
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n; cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u; cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) cin >> C[i], sum += C[i];
	sort(C, C + n); sum -= C[n - 1];
	int x = 0;
	DFS(1, 0, x);
	cout << sum << endl;
	for (int i = 1; i <= n; i++) cout << D[i] << ends;
	cout << endl;

	return 0;
}


Measured memory_bytes: 3712