akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int n, m;
vector<vi> graph;
vi used;

int dfs(int v, int depth){
    if(depth == n - 1){
        return 1;
    }

    int ret = 0;
    for(auto& nv : graph[v]){
        if(used[nv]) continue;

        used[nv] = true;
        ret += dfs(nv, depth + 1);
        used[nv] = false;
    }

    return ret;
}

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

    n, m; cin >> n >> m;
    graph = vector<vi>(n);
    rep(loop, m){
        int a, b; cin >> a >> b; a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    used = vi(n);

    used[0] = true;
    cout << dfs(0, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	string S; cin >> S;
	if ((S.length()%2 == 0)^ (S[0] == S[S.length() - 1])) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

char c[6][5] = {
	{'a', 'b', 'c', 'd', 'e'},
	{'f', 'g', 'h', 'i', 'j'},
	{'k', 'l', 'm', 'n', 'o'},
	{'p', 'q', 'r', 's', 't'},
	{'u', 'v', 'w', 'x', 'y'},
	{'z', '.', '?', '!', ' '},
};

int main(){
	
	bool checker;
	
	string str;
	
	while(true){
		cin >> str;
		if(cin.eof()){
			break;
		}
		
		checker = false;
		
		for(int i = 0; i < str.size(); i++){
			if(str[i] < '1' || str[i] > '6'){
				printf("NA\n");
				checker = true;
				break;
			}
		}
		
		if(checker){
			continue;
		}
		
		if(str.size() % 2 != 0){
			printf("NA\n");
			continue;
		}
		for(int i = 0; i < str.size(); i += 2){
			if(str[i + 1] - '0' - 1 >= 5){
				printf("NA\n");
				checker = true;
				break;
			}
		}
		
		if(checker){
			continue;
		}
		
		for(int i = 0; i < str.size(); i += 2){
			printf("%c", c[str[i] - '0' - 1][str[i + 1] - '0' - 1]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> c(n-1),s(n-1), f(n-1);
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
    vector<int> v(n,0);
    rep(i,n){
        int now = 0;
        for(int j = i ; j < n-1 ; j++){
            if(now < s[j]) now = s[j];
            else now = s[j] +((now - s[j] -1)/f[j]+1)*f[j];
            now += c[j];
        }
        v[i] = now;
    }
    rep(i,n) cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x,y,z;
    scanf("%d %d %d",&a,&b,&c);
    x = a;
    y = b;
    z = c;
    a= y;
    b = x;
    c = a;
    a = z;
    printf("%d %d %d\n",a,b,c);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    vector<vector<int> > matrix(10+1,vector<int>(10+1,0));
 
    int n;
    cin>> n;
    for(int i = 1; i <= n; i++)
    {
        matrix[to_string(i)[0]-'0'][i % 10]++;
    }
 
    long long int ans = 0;
    for(int i = 1; i < 10; i++)
        for(int j = 1; j < 10; j++)
         ans += (matrix[i][j] * matrix[j][i]);
 
 
    cout<<ans;
 
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int>a(11,-1);
	int x;
	for(int i=0;i<k;i++){
		cin>>x;
		a[x]++;
	}
	for(int i=n;i;i++){
		int temp=i;
		int flag=0;
		while(temp>0){
			int d=temp%10;
			temp/=10;
			if(a[d]==0){
				flag=1;
				break;
			}
		}
		if(flag)continue;
		cout<<i;
		break;
	}
  
	return 0;
}


Measured memory_bytes: 3564
import java.util.*;
public class Main {
       public static void main(String[] args){
              Scanner sc = new Scanner(System.in);
              int a = sc.nextInt();
              int b = sc.nextInt();
              if(a+b>=24){
              System.out.println(a+b-24);
              }else{
              System.out.println(a+b);
              }
       }
}

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

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

  vector<bool> f(n + 1, false);
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  bool ans = false;
  int cnt = 0;
  int i = 1;
  f[i] = true;
  while (true) {
    if (i == 2) {
      ans = true;
      break;
    }
    if (f[a[i]]) break;
    i = a[i];
    f[i] = true;
    cnt++;
  }
  cout << (ans ? cnt : -1) << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

const double PI = 3.1415926535897932384626433832795;

int main() {
  string s;
  cin >> s;
  int ans = count(ALL(s), '1');
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int a,b; cin>>a>>b;
    int height=(b-a)*(b-a+1)/2;
    cout<<height-b<<endl;
}


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

typedef long long ll;
const int MaxN = 212345;
const ll mod = 998244353;


void solve_case() {
	ll n, k;
	cin >> n >> k;
	
	ll h[n+1];
	h[0] = 0;
	for (int i = 0; i < n; i++) {
		cin >> h[i + 1];
	}
	
	ll dp[n + 1];
	dp[1] = 0;
	for (int i = 2; i <= n; i++)  {
		ll kk = 1;
		dp[i] = (int) 1e9;
		for (int j = i - 1; j > 0 && kk <= k ; j--) {
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
			kk++;
		}
	}
	
	cout << dp[n] << "\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll t=1;
    //cin >> t;
    while(t--) solve_case();
}


Measured memory_bytes: 5188
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] memo = new int[n + 1];
        memo[0] = 1;
        memo[1] = 1;
        for (int i = 2; i <= n; i++) {
            memo[i] = memo[i - 1] + memo[i - 2];
        }
        System.out.println(memo[n]);
    }
}

Measured memory_bytes: 26236
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e9
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    int n,m,x,y;
    cin >> n >> m >> x >> y;
    vector<int> a(n),b(m);

    REP(i,n){
        cin >> a[i];
    }
    VSORT(a);
    REP(i,m){
        cin >> b[i];
    }
    VSORT(b);

    bool exist = false;
    //cout << a[n-1] << b[0] << endl;
    for(int i = x;i <=y;i++){
        //cout << i << endl;
        if(a[n-1] < i && i <= b[0]){
            if(x< i && i <= y){
                exist = true;
            }
        }

    }
    if(exist){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }







  
  
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
es = [tuple(map(int, input().split())) for _ in range(n - 1)]
xs = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    xs[p - 1] += x

neighbors = {v: [] for v in range(n)}
for a, b in es:
    neighbors[a - 1] += [b - 1]
    neighbors[b - 1] += [a - 1]

queue = [(0, 0)]  # vertex, sum so far
counter = [None for _ in range(n)]

while queue:
    v, s = queue.pop()
    cv = s + xs[v]
    counter[v] = cv
    for n in neighbors[v]:
        if counter[n] is None:
            queue.append((n, cv))

print(' '.join(map(str, counter)))



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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int a, p;

bool read() {
    if (!(cin >> a >> p))
        return false;

    return true;
}

void solve() {
    cout << (a < 6 ? 0 : (a < 13 ? p / 2 : p)) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 87;
int po[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    for (int i = n - 1; i >= 0; --i)
        po[i] = (s[i] == 'E') + po[i+1];
    int cu = 0;
    int ans = 1e9;
    for (int i = 0; i < n; ++i) {
        ans = min(ans, cu + po[i+1]);
        cu += s[i] == 'W';
    }
    cout << ans << endl;
}


Measured memory_bytes: 1812
N = int(input())
A,B = map(int,input().split())
P = [int(x) for x in input().split()]

n1 = sum(1 if x <= A else 0 for x in P)
n2 = sum(1 if A < x <= B else 0 for x in P)
n3 = sum(1 if B < x else 0 for x in P)
answer = min(n1,n2,n3)
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF = (1LL<<60);
const int MOD = 1000000007;

bool dp[20010];

int main(){
    int n; cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];

    dp[0] = true;
    rep(i,n){
        for(int j=10010;j>=0;j--){
            if(dp[j]) dp[j+s[i]] = true;
        }
    }
    ll res = 0;
    rep(i,10010){
        if(dp[i] && i%10) res = i;
    }
    cout << res << endl;
}

Measured memory_bytes: 3588
import java.util.*;

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

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int ang = scan.nextInt();
		double S = 1.0 / 2.0 * a * b * Math.sin(Math.toRadians(ang));
		double L = a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(ang)));
		double h = b * Math.sin(Math.toRadians(ang));
		System.out.println(S);
		System.out.println(L);
		System.out.println(h);
	}
}

Measured memory_bytes: 26388
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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 void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    V<int> a(n),b(n);
    V<int> cnt(n+1,0);
    rep(i,n){
        cin>>a[i];
        cnt[a[i]]++;
    }
    rep(i,n){
        cin>>b[i];
        cnt[b[i]]++;
    }
    bool ok=1;
    for(int i=1;i<=n;i++){
        if(cnt[i]>n){
            ok=0;
        }
    }
    if(ok){
    reverse(all(b));
    int same=-1;
    rep(i,n){
        if(a[i]==b[i]) same=a[i];
    }
    int l=n+1,r=-1;
    rep(i,n){
        if(a[i]==same) chmin(l,i);
        if(b[i]==same) chmin(l,i);
    }
    for(int i=n-1;i>=0;i--){
        if(a[i]==same) chmax(r,i);
        if(b[i]==same) chmax(r,i);
    }
    int s=-1,t=-2;
    rep(i,n){
        if(a[i]==b[i]){
            s=i;
            break;
        }
    }
    for(int i=n-1;i>=0;i--){
        if(a[i]==b[i]){
            t=i;
            break;
        }
    }
    int pos=0;
    if(l==0) pos=r+1;
    for(int i=s;i<=t;i++){
        swap(b[i],b[pos]);
        if(pos==l-1) pos=r+1;
        else pos++;
    }
    }
    if(ok){
        cout<<"Yes"<<endl;
        rep(i,n) cout<<b[i]<<(i==n-1?"\n":" ");
    }else cout<<"No"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 5576
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
using namespace std;

#define N 200000
#define EPS 1e-9
#define PI 3.14159265358979323846264338327950

int arr[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		cin >> m;
		arr[m - 1] ++;
	}
	for (int i = 0; i < n; ++i)
		cout << arr[i] << '\n';
}


Measured memory_bytes: 4312
#include <algorithm>
#include <iostream> //入出力
#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <cmath> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>

using namespace std;
typedef long long ll; //64bit型

const int INF = 1050000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int N_MAX = 2010;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() //input->compute->output
{
    double a, b, pi = 3.141592653589;
    cin >> a >> b;
    printf("%d %d %f\n", (int)a / (int)b, (int)a % (int)b, a / b);

    return 0;
}



Measured memory_bytes: 3204
#include<stdio.h>
#define N 100

int main(){
  int n,p[N+1],m[N+1][N+1],i,j,l,k,min,a;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=10000000;
      for(k=i;k<=j-1;k++){
	a = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(m[i][j]>=a)
	  m[i][j] = a;
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}
	
	



Measured memory_bytes: 2148
import sys
sys.setrecursionlimit(1000000)

n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)

edge=[[] for i in range(n)]
k=0

for i in range(n-1):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    edge[b[i]].append(a[i])
    edge[a[i]].append(b[i])

color_dict={}

def dfs(x, last=-1, ban_color=-1):
    global k
    color=1
    for to in edge[x]:
        if to==last:
            continue
        if color==ban_color:
            color+=1
        color_dict[(x,to)]=color
        k=max(k,color)
        dfs(to,x,color)
        color+=1
dfs(0)
print(k)

for i in range(n-1):
    if (a[i],b[i]) in color_dict:
        print(color_dict[(a[i],b[i])])
    else:
        print(color_dict[(b[i],a[i])])

Measured memory_bytes: 104860
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)

ll greedy(int x, int y, int a, int b, int c, ll p[], ll q[], ll r[])
{
    ll choose[x + y];
    rep(i, 0, x)
    {
        choose[i] = p[i];
    }
    rep(i, 0, y)
    {
        choose[i + x] = q[i];
    }
    sort(choose, choose + x + y);
    reverse(choose, choose + x + y);
    rep(i, 0, c)
    {
        if (choose[x + y - 1 - i] > r[i])
        {
            break;
        }
        choose[x + y - 1 - i] = r[i];
    }
    ll ans = 0;
    rep(i, 0, x + y)
    {
        ans += choose[i];
    }
    return ans;
}

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll p[a], q[b], r[c];
    rep(i, 0, a)
    {
        cin >> p[i];
    }
    rep(i, 0, b)
    {
        cin >> q[i];
    }
    rep(i, 0, c)
    {
        cin >> r[i];
    }
    sort(p, p + a);
    reverse(p, p + a);
    sort(q, q + b);
    reverse(q, q + b);
    sort(r, r + c);
    reverse(r, r + c);
    // rep(i, 0, a)
    // {
    //     cout << p[i] << ' ';
    // }
    // rep(i, 0, b)
    // {
    //     cout << q[i] << ' ';
    // }
    // rep(i, 0, c)
    // {
    //     cout << r[i] << ' ';
    // }
    cout << greedy(x, y, a, b, c, p, q, r);
}


Measured memory_bytes: 3968
s = input()

if s[-1]=='1':
    print(-1)
    exit()
if s[0]=='0':
    print(-1)
    exit()
for i in range(len(s)//2):
    if s[i]!=s[-i-2]:
        print(-1)
        exit()

print(1,2)
top = 2

for i in range(1,len(s)-1):
    print(top, i + 2)
    if s[i]=='1':
        top = i+2



Measured memory_bytes: 47704
use std::io::BufRead;

const P: u64 = 1_000_000_007;

fn main() {
    let stdin = std::io::stdin();
    let (n, c): (usize, usize) = stdin.lock().gets().split(' ').values();
    let a = stdin.lock().gets().split(' ').map(|x| x.parse().unwrap())
        .collect::<Vec<u64>>();
    let b = stdin.lock().gets().split(' ').map(|x| x.parse().unwrap())
        .collect::<Vec<u64>>();

    let mut cnt = vec![vec![0; c + 1]; n + 1];
    cnt[0][0] = 1;
    for ni in 1..n + 1 {
        for x in a[ni - 1]..b[ni - 1] + 1 {
            let mut cnt_ni = vec![0; c + 1];
            cnt_ni[0] = cnt[ni - 1][0];
            for ci in 1..c + 1 {
                cnt_ni[ci] = (x * cnt_ni[ci - 1] + cnt[ni - 1][ci]) % P;
            }
            for ci in 0..c + 1 {
                cnt[ni][ci] += cnt_ni[ci];
            }
        }
        for ci in 0..c + 1 {
            cnt[ni][ci] %= P;
        }
    }
    println!("{}", cnt[n][c]);
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(), x = sc.nextInt();
		boolean[] a = new boolean[n + 1];
		for (int i = 0; i < m; i++)
			a[sc.nextInt()] = true;

		int cost1 = 0, cost2 = 0;
		for (int i = x; i < a.length; i++) {
			if (a[i])
				cost1++;
		}
		for (int i = x; i > 0; i--) {
			if (a[i])
				cost2++;
		}

		System.out.println(Math.min(cost1, cost2));
	}

}

Measured memory_bytes: 27124
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;
int main(){

    int a,b,C;
    double S,L,h,D;

    cin >> a >> b >> C;
    D=(acos(-1.0)*C)/180.0;
    S=(a*b*sin(D))/2.0;
    L=a+b+sqrt(a*a+b*b-2*a*b*cos(D));
    h=b*sin(D);

    printf("%lf\n%lf\n%lf\n",S,L,h);

    return 0;


}


Measured memory_bytes: 3596
s = input()

n = len(s)
half = int((n-1)/2)
half_s = s[:half]
half_list = list(half_s)
for i in range(half):
    if half_list[i] != half_list[half-i-1]:
        print("No")
        exit()
if half_s != s[half+1:]:
    print("No")
    exit()
print("Yes")


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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
  long long N,X;
  cin >> N >> X;
  vector<long long> vec(N);
  
  for (long long i = 0; i < N; i++) {
    long long x;
    cin >> x;
    long long dist = x - X;
    if (dist < 0) dist = -dist;
    vec.at(i) = dist;
  }
  
  long long ans = vec.at(0);
  for (int i = 0; i < N; i++) {
    ans = GCD(ans,vec.at(i));
  } 
  cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())
D = map(int, input().split())

r = [None] * N
m = 0

for i, j in enumerate(D):
    if (i == 0 and j != 0) or (i != 0 and j == 0):
        print("0")
        exit()
    r[j] = 1 if r[j] is None else r[j] + 1
    if j > m:
        m = j

result = 1
pre = None

for i, x in enumerate(r):
    if x is None:
        if i != m + 1:
            print("0")
            exit()
        else:
            break
    if i < 2:
        pre = x
        continue
    result *= pre**x
    pre = x

print(result % 998244353)

Measured memory_bytes: 11324
def calc(x):
    ret = 0
    while x % 100 == 0:
        x /= 100
        ret += 1
    return ret

D, N = map(int, input().split())
cnt, val = 0, 0
while cnt < N:
    val += 1
    if calc(val) == D:
        cnt += 1
print(val)

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int ans[N] ;

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

  for(int i = 0 ;i<n ;i++){
    scanf("%d", &a) ;
    ans[a]++ ;
    if(a>0) ans[a-1]++ ;
    ans[a+1]++ ;
  }

  cout << *max_element(ans, ans+N) << endl ;

	
  return 0 ;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<list>
#include<cctype>
#include<utility>
#include<algorithm>
#include<cctype>
using namespace std;

int main()
{
	double x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	printf("%.7f\n",sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));

    return 0;
}

Measured memory_bytes: 1228
use std::collections::HashMap;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<usize> = s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let mut h: HashMap<usize, usize> = HashMap::new();
    for _ in 0..v[0] {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let u: Vec<usize> = s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
        let x = match h.get(&u[0]) {Some(x) => *x, None => 0};
        h.insert(u[0], x + u[1]);
    }
    let mut k = h.keys().collect::<Vec<&usize>>();
    k.sort();
    let mut x = 0;
    for i in &k {
        x += *h.get(*i).unwrap();
        if x >= v[1] {println!("{}", *i); return}
    }
}



Measured memory_bytes: 12540
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
        int a = 0, b, p, i, t;
		for(b = 1;b <= x;b++) {
			t = b;
			for(p = 2;p <= x;p++) {
				t *= b;
				if(t <=x && a < t) a = t;
			}
		}
		if(x == 1) a = 1;
		System.out.print(a);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main() {
	int d[9] = { 0, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200 };
	int n;
	cin >> n;
	vector<int> dd(n);
	for (int i = 0; i < n; i++) {
		cin >> dd[i];
	}
	sort(dd.begin(), dd.end());
	set<int> st;
	int ans = 0;
	int cc = 0;
	for (int i = 0; i < n; i++) {
		bool h = true;
		for (int j = 0; j < 8; j++) {
			if (d[j] <= dd[i] && dd[i] < d[j+1]) {
				st.insert(j);
				h = false;
			}
		}
		if (h) {
			cc++;
		}
	}
	ans = st.size();
	ans += cc;
	
	int bb = st.size();
	if (bb == 0) {
		bb = 1;
	}
	cout << bb << ' ' << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
    string s; cin >> s;
    int ans1=-1, ans2=-1;
    REP(i,s.size()-2){
        if(s[i]==s[i+1]){
            ans1 = i+1;
            ans2 = i+2;
            break;
        }else if(s[i]==s[i+2]){
            ans1 = i+1;
            ans2 = i+3;
            break;
        }else if(s[i+1] == s[i+2]){
            ans1 = i+2;
            ans2 = i+3;
            break;
        }
    }
    if(s.size()==2){
        if(s[0] == s[1]){
            ans1 = 1;
            ans2 = 2;
        }
    }
    cout << ans1 << " " << ans2 << endl;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N,M,L;
  cin>>N>>M>>L;
  string ans="NG";
  rep(i,1001){
    int T=i*N;
    if(T>=M&&T<=L){
      ans="OK";
      break;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    int aa = 0, bb = 0;
    for (int i = 0; i < b; i++) {
        aa *= 10;
        aa += a;
    }
    for (int i = 0; i < a; i++) {
        bb *= 10;
        bb += b;
    }
    cout << max(aa,bb) << endl;
    return 0;
}

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

int main() {
	string S, K;
	cin >> S >> K;
	int n;
	if (K.size() == 1) n = K[0] - '1';
	else if (K.size() == 2) n = (K[0] - '0') * 10 + K[1] - '1';
	else n = 100;
	n = S.size() <= n ? S.size() - 1 : n;
	for (int i = 0;i < n;++ i) if (S[i] > '1') n = i;
	cout << S[n];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

ポイントは、ある数字はその数字から変化することはない
例えば3は333になって333333333になって……と3のみに変化するので、それぞれ独立に数えられる

ところで、5000兆日だと2ですら2^5000兆の長さになる
ということはだ、単純に左から見てK番目まで全部1なら1が、そうでないなら最初に1でなかった数がK番目だろう
*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
 
 
int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < a + 1; i++) {
        int turtles = a - i;
        if (2 * i + 4 * turtles == b) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3624
#include <stdio.h>
int main(void){
  int a[100]={0};
  int n,c=0;
  while(scanf("%d",&n)!=EOF){
    if(n){
      a[c]=n;
      c++;
    }
    else{
      c--;
      printf("%d\n",a[c]);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <bitset>

using namespace std;

int main() {
  int H, W, K;
  cin >> H;
  cin >> W;
  cin >> K;
  
  // black 1, else 0
  vector <vector <int> > table(H, vector <int> (W, 0));
  for (int i = 0; i < H; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < W; ++j) {
      if (s[j] == '#') table[i][j] = 1;
    }
  }
  
  int cnt = 0;
  for (int state = 0; state < (1 << (H + W)); ++state) {
    vector <vector <int> > t(table);
    for (int w = 0; w < W; ++w) {
      if ((1 & (state >> w)) == 1) {
        for (int i = 0; i < H; ++i) {
          t[i][w] = 0;
        }
      }
    }

    for (int h = 0; h < H; ++h) {
      if ((1 & (state >> (W + h))) == 1) {
        for (int i = 0; i < W; ++i) {
          t[h][i] = 0;
        }
      }
    }
    int k = 0;
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        if (t[i][j] == 1) {
          k++;
        }
      }
    }
    if (k == K) {
      cerr << state << endl;
      cnt++;
    }
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int a, b,c,d;
	cin >> a >> b >> c>> d;
	int f = 0;

	while (a > 0 && c > 0) {
		if (f == 0) {
			c = c - b;
			f = 1;
		}
		else {
			a = a - d;
			f = 0;
		}
	}

	if (f == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	

}

Measured memory_bytes: 3636
import std.stdio;
import std.string;

void main()
{
	auto n = readln;
	auto s = readln.strip;
	
	writeln( solve( s ) );
}

int solve( in string s )
{
	auto lc = new int[ s.length ];
	lc[ 0 ] = 0;
	foreach( i; 1 .. s.length )
	{
		lc[ i ] = lc[ i - 1 ] + ( s[ i - 1 ] == 'E' ? 0 : 1 );
	}
	
	auto rc = new int[ s.length ];
	rc[ $-1 ] = 0;
	foreach_reverse( i; 0 .. s.length-1 )
	{
		rc[ i ] = rc[ i + 1 ] + ( s[ i + 1 ] == 'W' ? 0 : 1 );
	}
	
	auto result = lc[ 0 ] + rc[ 0 ];
	foreach( i; 1 .. s.length )
	{
		auto lrc = lc[ i ] + rc[ i ];
		if( lrc < result ) result = lrc;
	}
	
	return result;
}

unittest
{
	assert( solve( "WEEWW" ) == 1 );
	assert( solve( "WEWEWEEEWWWE" ) == 4 );
	assert( solve( "WWWWWEEE" ) == 3 );
}


Measured memory_bytes: 4328
#include<stdio.h>
#include<ctype.h>
int main(void){
	char c;
	while(1){
		c=getchar();
		if(c=='\n'){
			printf("\n");
			break;
		}
		else if(isalpha(c)){
			if(isupper(c)) printf("%c",tolower(c));
			else printf("%c",toupper(c));
		}
		else printf("%c",c);
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int K {0}, A {0}, B {0};
	vector<int> nums;
	cin >> K >> A >> B;
	for (int i = A; i <= B; ++i) {
		nums.push_back(i);
		}
	int j = count_if(begin(nums), end(nums), [K] (int x) {return (x % K) == 0;});
	if (j == 0) {cout << "NG";}
	else {cout << "OK";}
	return 0;
	}


Measured memory_bytes: 3632
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N; cin >> N;
    vl x(N), y(N); REP(i, N) cin >> x[i] >> y[i];
    map<pair<ll, ll>, ll> m;
    REP(i, N)
    {
        REP(j, N)
        {
            if(i == j) continue;
            m[make_pair(x[i]-x[j], y[i]-y[j])]++;
        }
    }
    ll e = 0;
    for(auto itr = m.begin(); itr != m.end(); itr++) e = max(e, itr->second);
    cout << N - e << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,m=0;
  cin>>N;
  vector<int> A(N+1);
  vector<int> B(N+1);
  vector<int> C(N);
  for(int i=1;i<=N;i++)cin>>A[i];
  for(int i=1;i<=N;i++)cin>>B[i];
  for(int i=1;i<=N-1;i++)cin>>C[i];
  for(int i=1;i<=N;i++){
    int p=0;
    if(i>1&&A[i-1]+1==A[i])p=C[A[i-1]];
    m+=B[A[i]]+p;
  }
  cout <<m <<endl;
  
}

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

const int maxn = 109;
char s[maxn]; int n, ans, sum;

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1); 
	for (int i=1; i<=n; i++) {
		if (s[i] >= 1)
			ans = max(ans, sum + s[i] - '0' - 1 + 9 * (n - i));
		sum += s[i] - '0';
	}
	ans = max(ans, sum);
	printf("%d\n", ans);
	return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> s(M),c(M);
  for(int i=0;i<M;i++){
    cin>>s.at(i)>>c.at(i);
  }
  vector<int> number(N,-1);
  bool flag=true;
  for(int i=0;i<M;i++){
    if(number.at(s.at(i)-1)==-1){
      number.at(s.at(i)-1)=c.at(i);
    }else{
      if(number.at(s.at(i)-1)!=c.at(i)){
        flag=false;
        break;
      }
    }
  }

  if(number.at(0)==0){
    if(N!=1){
      flag=false;
    }
  }


  if(flag){
    for(int i=0;i<N;i++){
      if(number.at(i)==-1){
        if(i==0&&N!=1){
          number.at(i)=1;
        }else{
          number.at(i)=0;
        }
      }
      cout<<number.at(i);
    }
    cout<<endl;
  }else{
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  cout << (N+1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

class union_find {
public:
vector<int> par,rank,lsize;
union_find(int n): par(n),rank(n),lsize(n){
   for (int i=0;i < n;i++){
      par[i]=i;
      rank[i]=0;
      lsize[i]=1;
   }
}

int find(int x){
   if (par[x]==x){
      return x;
   }
   else{
      return par[x] = find(par[x]); 
   }
}

void unite(int x ,int y){
   x=find(x);
   y=find(y);
   if (x==y) return;
   if (rank[x] < rank[y]){
      lsize[y] += lsize[x];
      lsize[x] = -1;
      par[x] = y;
   }else{
      lsize[x] += lsize[y];
      lsize[y] = -1;
      par[y]=x;
      if (rank[x]==rank[y]) rank[x]++;
   }   
}

bool same(int x, int y){
   return find(x) == find(y);
}

int size(int x){
   if (lsize[x] == -1){
      x=find(x);
   }
   return lsize[x];
}
};

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    union_find tree(n);
    vector<int> b(n,0);
    vector<int> f(n,0);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--; y--;
        tree.unite(x,y);
        f[x]++;
        f[y]++;
    }
    rep(i,k){
        int x,y;
        cin >> x >> y;
        x--;y--;
        if (tree.same(x,y)){
            b[x]++;
            b[y]++;
        }
    }
    rep(i,n){
        cout << tree.size(i)-b[i]-f[i]-1 << " ";
    }
    cout << endl;
    

    return 0;
}

Measured memory_bytes: 2816
from itertools import product
from functools import reduce
import operator
def prod(iterable):
    return reduce(operator.mul, iterable, 1)
def cnt_samelen(b,e,n_str):
  n0=int(n_str[0])
  if b>n0 or len(n_str)==1:
    return 0
  if b<n0:
    return b*int(10**(len(n_str)-2))
  
  return (int(n_str[1:-1])+1 if len(n_str)>2 else 1)-(1 if e>int(n_str[-1]) else 0)
def cnt(b,e,n_str):
  res=0
  l=len(n_str)
  if b==e and int(n_str)>=b:
    res+=1
  for i in range(l-2):
    res+=10**(i)
  res+=cnt_samelen(b,e,n_str)
  return res
def sol():
  n_str=input()
  return sum(cnt(b,e,n_str)*cnt(e,b,n_str) 
             for b,e in product(range(1,10),repeat=2))

print(sol())  

Measured memory_bytes: 3572
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    while True:
        n, k = list(map(int, input().strip().split()))
        if n == 0 and k == 0:
            return
        v = [0] * n
        a = [0] * (n+1)
        for i in range(n):
            v[i] = int(input().strip())
        for i in range(n):
            a[i+1] = v[i] + a[i]

        ans = -INF
        for i in range(n-k+1):
            ans = max(ans, a[i+k] - a[i])
        print(ans)

if __name__ == '__main__':
    main()



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

using namespace std;

int preW[1000000], sufE[1000000];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  for(int i=1; i<n; i++){
    preW[i] = preW[i-1] + (s[i-1] == 'W');
  }
  for(int i=n-2; i>=0; i--){
    sufE[i] = sufE[i+1] + (s[i+1] == 'E');
  }
  int ans = 1e9;
  for(int i=0; i<n; i++){
    int tmp;
    tmp = preW[i] + sufE[i];
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5908
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  map<string,int> mp;
  int n; cin >> n;
  string s;
  rep(i,n){
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 3628
N = int(input())
A = []
XY = []
for i in range(N):
    a = int(input())
    A.append(a)

    xy = [list(map(int, input().split())) for _ in range(a)]
    XY.append(xy)

V = [False] * N
ans = 0
for i in range(1, 2**N):
    tmp_i = i
    isOK = True
    cnt = 0
    H = [False] * N
    for j in range(N):
        if tmp_i & 1 == 1:
            cnt += 1
            H[j] = True
        tmp_i = tmp_i >> 1
    for j in range(N):
        if H[j] == True:
            for k in range(A[j]):
                status = XY[j][k][1]
                if status != H[XY[j][k][0]-1]:
                    isOK = False
                    break
        if isOK == False:
            break
    if isOK == True:
        ans = max(cnt, ans)
print(ans)



    





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

int main(){

    int X, N;
    cin >> X >> N;
    set<int> P;
    rep (i, N){
        int p;
        cin >> p;
        P.insert(p);
    }

    rep(i, 10000){
        if (P.find(X-i) == P.end()){
            cout <<  X-i << endl;
            return 0;
        }

        if (P.find(X+i) == P.end()){
            cout <<  X+i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 8;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define Graph vector<vector<int>>
#define rng(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rnr(i, a, b) for(ll i = ll(a); i >= ll(b); i--)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int maxv = 0;
int maxv_i = 0;
Graph tree;

void dfs(int from, int now, int dist) {
    for(int next : tree[now]) {
        if(next == from) continue;
        dfs(now, next, dist + 1);
    }
    if(dist > maxv) maxv_i = now, maxv = dist;
    return;
}

int main() {
    int n; cin >> n;
    int a[n - 1], b[n - 1];
    tree.resize(n);
    rep(i, n - 1) {
        cin >> a[i] >> b[i]; --a[i], --b[i];
        tree[a[i]].pb(b[i]); tree[b[i]].pb(a[i]);
    }
    dfs(0, 0, 0);
    dfs(maxv_i, maxv_i, 0);
    cout << (((maxv - 1) % 3 == 0) ? "Second" : "First") << endl;
}


Measured memory_bytes: 28116
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
   cin>>A.at(i);
    
  }
  int count=0;
  for(int i=0;i<N;i++){
  if(A.at(i)!=i+1){
  count++;
  }
  }
  if(count<=2){
  cout<<"YES"<<endl;
  }
  else{
  cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

ll gcd(ll a,ll b){
  if(a==0||b==0) return a+b;
  return gcd(b,a%b);
}

int main(){
  ll a,b;
  cin>>a>>b;
  a=gcd(a,b);
  b=1;
  for(ll i=2;i*i<=a;++i){
    if(a%i==0) ++b;
    while(a%i==0) a/=i;
  }
  if(a>1) ++b;
  cout<<b<<endl;
}


Measured memory_bytes: 256
import math
a,b,n = map(int,input().split())
if b > n:
    print(math.floor(a * n / b) - a * math.floor(n / b))
elif b == n:
    print(math.floor(a * (n-1) / b) - a * math.floor((n-1) / b))
else:
    print(math.floor(a * (b-1) / b) - a * math.floor((b-1) / b))

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int i;
    for(i = 0; i * i <= n; i++) {
    }
    i--;
    print(i * i);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;

  string ans = t;
  for (int i = 0; i < n; ++i)
  {
    if (t[i] == 'r')
    {
      ans[i] = 'p';
    }
    else if (t[i] == 's')
    {
      ans[i] = 'r';
    }
    else
    {
      ans[i] = 's';
    }
  }
  for (int i = k; i < n; ++i)
  {
    if (ans[i] == ans[i - k])
    {
      if (ans[i] == 'r')
      {
        if (i + k < n && ans[i + k] == 'r')
        {
          ans[i] = 's';
        }
        else if (i + k < n && ans[i + k] == 's')
        {
          ans[i] = 'p';
        }
        else if (i + k < n && ans[i + k] == 'p')
        {
          ans[i] = 's';
        }
        else
        {
          ans[i] = 's';
        }
      }
      else if (ans[i] == 's')
      {
        if (i + k < n && ans[i + k] == 'r')
        {
          ans[i] = 'p';
        }
        else if (i + k < n && ans[i + k] == 's')
        {
          ans[i] = 'p';
        }
        else if (i + k < n && ans[i + k] == 'p')
        {
          ans[i] = 'r';
        }
        else
        {
          ans[i] = 'p';
        }
      }
      else if (ans[i] == 'p')
      {
        if (i + k < n && ans[i + k] == 'r')
        {
          ans[i] = 's';
        }
        else if (i + k < n && ans[i + k] == 's')
        {
          ans[i] = 'r';
        }
        else if (i + k < n && ans[i + k] == 'p')
        {
          ans[i] = 's';
        }
        else
        {
          ans[i] = 's';
        }
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < n; ++i)
  {
    if (ans[i] - t[i] == -1)
    {
      sum += r;
    }
    else if (ans[i] - t[i] == 3)
    {
      sum += s;
    }
    else if (ans[i] - t[i] == -2)
    {
      sum += p;
    }
  }
  cout << sum << endl;

  return 0;
}


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

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC123_B();
        }


        static void ABC123_B()
        {
            var inputs = new List<int>();
            for (var i = 0; i < 5; i++)
            {
                inputs.Add(int.Parse(Console.ReadLine()));
            }
            var k = int.Parse(Console.ReadLine());

            var list = new List<int>();
            for (var i = 0; i < 4; i++)
            {
                for (var j = i+1; j < 5; j++)
                    list.Add(inputs[j] - inputs[i]);
            }

            Console.WriteLine(list.All(x => x <= k) ? "Yay!" : ":(");
        }
    }
}

Measured memory_bytes: 13268
n = input()

min_num = 1000001
max_num = -1000001
sum = 0

tmp = map(int, raw_input().split())
for i in xrange(n):
    min_num = min(min_num, tmp[i])
    max_num = max(max_num, tmp[i])
    sum += tmp[i]
    
print "%d %d %d" % (min_num, max_num, sum)

Measured memory_bytes: 6984