akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int inf = 0x3f3f3f3f;
typedef long long ll;
const int maxn = 1e5+10;
const ll mod=1e9+7;
#define MAXN 40100
ll gcd(ll T, ll b) { return b == 0 ? T : gcd(b, T % b); }
ll lcm(ll T, ll b) { return T / gcd(T, b) * b; }
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
 
ll mul(ll a,ll b, ll c) {
    ll ans = 0;
    while(b) {
        if(b&1) {
            ans= (ans+a)%c;
            b--;
        }
        b>>=1;
        a=(a+a)%c;
    }
    return ans;
}
 
ll powmod(ll a,ll b,ll c) {
    ll ans = 1;
    while(b) {
        if(b&1) {
            ans = mul(ans,a,c);
            b--;
        }
        b>>=1;
        a=mul(a,a,c);
    }
    return ans ;
}
 
ll exgcd(ll a,ll b,ll &x,ll &y) {
    if(b==0)
    {
        x=1;y=0;
        return a; 
    }
    ll r=exgcd(b,a%b,x,y);
    ll temp=y;
    y=x-(a/b)*y;
    x=temp;
    return r;
}

int main() {
    IO;
    ll n,m;
    while(cin>>n>>m)
    	cout<<n*m<<endl;


    return 0;
}

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

const int INF = 1<<30;

template<class T> inline bool chmin(T &a, T b)
{
    if(a > b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    vector<int> dp(H+1, INF); // dp[削った体力] = かかった魔力
    dp[0] = 0;
    for(int i=0; i<H; i++)
    {
        for(int j=0; j<N; j++)
        {
            if(i + A[j] < H) chmin(dp[i+A[j]], dp[i] + B[j]);
            else chmin(dp[H], dp[i] + B[j]);
        }
    }

    cout << dp[H] << endl;

    return 0;
}


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

int selectionSort(int* A, int N){

  int count = 0;
  int minj;

  for(int i = 0; i < N; i++){
    minj = i;
    for(int j = i; j < N; j++){
      if(A[j] < A[minj])
        minj = j;
    }

    if(minj != i){
      int tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      count++;
    }
  }

  return count;

}

void showA(int *A, int N){

  for(int i = 0; i < N; i++){
    if(i < N-1)
      std::cout << A[i] << ' ';
    else
      std::cout << A[i] << std::endl;
  }

  return;

}


int main(){
  int* A;
  int N;

  std::cin >> N;

  A = (int*)malloc(sizeof(int) * N);

  for(int i = 0; i < N; i++){
    std::cin >> A[i];
  }

  int c = selectionSort(A, N);

  showA(A, N);
  std::cout << c << std::endl;

  return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    ll k;
    cin >> s >> k;
    rep(i,s.size()) {
        if((s[i] == '1' && i+1 >= k) || s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;

bool isPrime(int x) {
  int s = sqrt(x);
  for (int i = 2; i <= s; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int X;
  cin >> X;
  if (X == 2) {
    cout << X << endl;
    return 0;
  }
  for (int i = X;; i++) {
    if (isPrime(i)) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define Max INT_MAX
#define Inf INT_MIN


#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i,l,n) for(int (i)=(int)(l);(i)<(int)(n);(i)++)
// s <= x < g ?
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
// 0 <= x < w && 0 <= y < h ?
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

int par[1000*1000];
int rank[1000*1000];

int W,H;


int p(int x, int y){
    return y*1000 + x;
}

void initTree(int W, int H){
    rep(i,H) { 
        rep(j,W){
            par[p(j,i)] = p(j,i); 
            rank[p(j,i)] = 0;
        }
    }
    return;
}

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]){
        par[x] = y;
    }else if( rank[y] < rank[x] ){
        par[y] = x;
    } else {
        par[y] = x;
        rank[x]++;
    }
    return;
}

bool same(int x,int y) {
    //cout << "first line in same "<< endl;
    x = find(x);
    y = find(y);
    //cout << "find x" << find(x) << endl;
    //cout << "find y" << find(y) << endl;
    return find(x) == find(y);
}


char grid[1000][1000];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
void around_unite(int x,int y){
    rep(i,4){
        if( grid[ y+dy[i] ][ x+dx[i] ] != '#' ) {
            if( IN(x+dx[i] , 0 , W) && IN(y+dy[i], 0, H ) ) 
            //if( 0 <= x+dx[i] && x+dx[i] < W &&
            //    0 <= y+dy[i] && y+dy[i] < H ) 
            { 
                unite( p(x,y), p(x+dx[i], y+dy[i]) );
            }
        }
    }
    return;
}
    




int main()
{
    char tmp;
    cin >> W >> H;
    int gx,gy;
    initTree(W,H);


    rep(i,H){
        rep(j,W){
            char tmp;
            cin >> tmp;
            grid[i][j] = tmp;
            if(tmp == 't'){ 
                gy = i;
                gx = j;
            }
        }
    }

    
    rep(i,H){
        rep(j,W){
            if(grid[i][j] != '#'){
                around_unite(j, i);
            }
        }
    }
    //rep(i,H){
    //    rep(j,W){
    //        cout << find(p(j,i)) << " ";
    //    }
    //    cout << endl;
    //}

    if( same( p(gx,gy), p(0,0) )){
        cout << 0 << endl;
        return 0;
    }

    int n_time;
    cin >> n_time;
    rep(i,n_time){
        int a,b;
        cin >> a >> b;
        if ( grid[b][a] == '#' ){
            grid[b][a] = '.';
            around_unite(a,b);
        } 

        if( same( p(gx,gy), p(0,0) )){
                cout << i + 1 << endl;
                return 0;
                //break;
        }
        //if( i + 1  == n_time ) { cout << -1 << endl; }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 9948
#include <iostream>
#include <string>

#define MAXN 17000
#define MAXS 8001

using namespace std;

bool X[MAXS][MAXN];
bool Y[MAXS][MAXN];

int main()
{
  string s;
  int fcnt = 0;
  int tcnt = 0;
  int x, y;

  cin >> s;
  s += 'T';
  cin >> x >> y;

  for ( int i = 0; i < s.size(); ++i ) {
    if ( s[i] == 'F' ) {
      ++fcnt;
      continue;
    }


    if ( tcnt % 2 == 0 ) {
      if ( tcnt == 0 ) {
         X[0][0+MAXS+fcnt] = true;
      } else {
        for ( int i = 0; i < MAXN; ++i ) {
          if ( X[tcnt/2-1][i] ) {
            X[tcnt/2][i-fcnt] = X[tcnt/2][i+fcnt] = true;
          }
        }
      }
    } else {
      if ( tcnt == 1 ) {
        Y[0][MAXS-fcnt] = Y[0][MAXS+fcnt] = true;
      } else {
        for ( int i = 0; i < MAXN; ++i ) {
          if ( Y[tcnt/2-1][i] ) {
            Y[tcnt/2][i-fcnt] = Y[tcnt/2][i+fcnt] = true;
          }
        }
      }
    }

    fcnt = 0;
    ++tcnt;
  }

  --tcnt;

  if ( tcnt == 0 ) {
    if ( X[0][MAXS+x] && y == 0 ) cout << "Yes\n";
    else cout << "No\n";
  } else if ( tcnt % 2 == 0 ) {
    if ( X[tcnt/2][x+MAXS] && Y[tcnt/2-1][y+MAXS] ) cout << "Yes\n";
    else cout << "No\n";
  } else {
    if ( X[tcnt/2][x+MAXS] && Y[tcnt/2][y+MAXS] ) cout << "Yes\n";
    else cout << "No\n";
  }
}


Measured memory_bytes: 135936
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := len(a) - 1; i >= 0; i-- {
		if i < len(a)-1 {
			fmt.Print(" ")
		}
		fmt.Print(a[i])
	}
	fmt.Println()
}



Measured memory_bytes: 1128
import scala.io.StdIn

object Main extends App {
  
  val r = StdIn.readLine().toDouble
  val s: Double = scala.math.Pi * r * r
  val v: Double = scala.math.Pi * r * 2
  
  print(f"$s%.6f" + " " + f"$v%.6f")

}


Measured memory_bytes: 44012
var
	N,A,x,y,i,j,out,ans,nowt,nowf,ccc:Longint;
	F,T,gF,gT:Array[1..15]of Longint;
begin
	read(N);
	for i:=1 to N do begin
		read(A);
		for j:=1 to A do begin
			read(x,y);
			dec(x);
			if y=0 then F[i]:=F[i] or (1<<x)else T[i]:=T[i] or (1<<x);
		end;
	end;
	for i:=1 to N do begin
		nowt:=1<<(i-1);
		nowf:=0;
		for ccc:=1 to N do begin
			for j:=1 to N do begin
				if ((nowt>>(j-1))and 1)=1 then begin
					nowt:=nowt or T[j];
					nowf:=nowf or F[j];
				end;
			end;
		end;
		gF[i]:=nowf;
		gT[i]:=nowt;
		if((out and nowt)<>0)or((nowt and nowf)<>0)then out:=out or(1<<(i-1));
	end;
	i:=((1<<N)-1)and not out;
	ans:=0;
	while i>0 do begin
		ccc:=0;
		nowt:=i;
		nowf:=0;
		for j:=1 to N do begin
			if ((nowt>>(j-1))and 1)=1 then begin
				inc(ccc);
				nowt:=nowt or gT[j];
				nowf:=nowf or gF[j];
			end;
		end;
		if((nowt and nowf)=0)and(ans<ccc)then ans:=ccc;
		i:=(i-1)and not out;
	end;
	writeln(ans);
end.


Measured memory_bytes: 128
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

S = LI2()
N = len(S)

def f(n):  # n個ずつ反転するとき、左n個を同じ数字にできるか
    for i in range(N-n,n):
        if S[i] != S[n-1]:
            return False
    return True

left,right = (len(S)+1)//2,len(S)+1
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        left = mid
    else:
        right = mid
print(left)


Measured memory_bytes: 94204
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N>>S;
    ll u9 = 0, u8 = 0;
    rep(i,N){
        if(S[i] == ')'){
            u8 == 0 ? ++u9 : --u8;
        }else{
            ++u8;
        }
    }
    rep(i,u9) cout<<'(';
    cout<<S;
    rep(i,u8) cout<<')';
    cout<<endl;
}

Measured memory_bytes: 256
haves = []
n = 0

line = gets
line.chomp!
n, k = line.split(' ')
k.to_i.times do
  d = gets
  d.chomp!
  as = gets
  as = as.chomp!.split(' ').map(&:to_i)

  haves = haves | as
end

puts n.to_i - haves.length


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int flag[20] = {0};

int main(){
  REP(i,3){
    int a;
    cin >> a;
    flag[a]++;
  }
  if(flag[5]==2 && flag[7] == 1){
    cout << "YES" <<endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
    string S; cin >> S;
    int ans = 0;
    for(int i=0;i<S.size();i++)
    {
        if(S[i] == '+')
            ans++;
        else if(S[i] == '-')
            ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
mods=10**9+7

N, K = map(int,input().split(' '))

cnt = 0
for k in range(K,N+1+1):
    minsum = k*(k+1)/2 -k
    maxsum = k*(k+1)/2 + (N-k)*(k)

    cnt+=(maxsum-minsum+1)
    cnt=cnt%mods

print(int(cnt))

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int h,w,d[400][400];
string s[20];

signed main() {
    rep(i,400) rep(j,400) if (i^j) d[i][j] = INF/100;
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    rep(i,h) rep(j,w) {
        if (s[i][j] == '#') continue;
        if (i+1 < h && s[i+1][j] == '.') {
            d[i*w+j][(i+1)*w+j] = 1;
            d[(i+1)*w+j][i*w+j] = 1;
        }
        if (j+1 < w && s[i][j+1] == '.') {
            d[i*w+j][i*w+j+1] = 1;
            d[i*w+j+1][i*w+j] = 1;
        }
    }
    rep(k,h*w) rep(i,h*w) rep(j,h*w) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    int ans = 0;
    rep(i,h*w) rep(j,h*w) if (d[i][j] == INF/100) d[i][j] = -1;
    rep(i,h*w) rep(j,h*w) ans = max(ans, d[i][j]);
    cout << ans << endl;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
int count = 1;
  
  for(int j = 0; j < (N - 1); j++) {
    if (vec.at(j) != vec.at(j + 1)) {
        count ++;
  }
  }
      cout << count << endl;
      
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 01:58:46 2020

@author: liang
"""

from math import gcd

N, X = map(int, input().split())
A = [abs(int(x)-X) for x in input().split()]

ans = A[0]
for i in range(N):
    ans = gcd(ans,A[i])
print(ans)

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

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());

	cout << ((s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int E[2],A[2],B[9][2],i,j,k,m=1<<30,R,M=100000007,P[1005][1005]={0};
int d(int a[2],int b[2]){return abs(a[0]-b[0])+abs(a[1]-b[1]);}
int min(int a,int b){return a<b?a:b;}
int C(int p,int q)
{
	int i,j;
	P[0][0]=1;
	for(i=0;i<=p;i++)
		for(j=0;j<=q;j++)
		{
			if(i==0||j==0)P[i][j]=1;
			else P[i][j]=(P[i][j-1]+P[i-1][j])%M;
		}
	return P[p-q][q];
}

int main()
{
	scanf("%d%d%d%d%d%d",&E[0],&E[1],&A[0],&A[1],&B[0][0],&B[0][1]);
	for(i=-1,k=1;i<2;i++)
		for(j=-1;j<2;j++)
			if(i!=0||j!=0)
			{
				B[k][0]=B[0][0]+E[0]*i;
				B[k][1]=B[0][1]+E[1]*j;
				k++;
			}
	for(i=0;i<9;i++)
		m=min(m,d(B[i],A));
	for(i=R=0;i<9;i++)
		if(d(B[i],A)==m)
			R=(R+C(m,abs(B[i][0]-A[0])))%M;
	printf("%d\n",R);
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a,b,c;
		a = 1e9;
		b = pow(n,0.34);
		c = pow(n,0.5);
		for(int i = 0; i <= b; i++){
			for(int j = 0; j <= c*2; j++){
				int t =(n-i*i*i-j*j);
				if(t >= 0)a= min( i+j+t, a);
			}
		}
		cout << a<<endl;
		cin >> n;
	}
	return 0;
}


Measured memory_bytes: 3264
n = int(input())
a = [int(x) for x in input().split()]

result = 0

for a_i in range(n):
  for b_i in range(a_i+1, n):
    for c_i in range(b_i+1, n):
      l_a = a[a_i]
      l_b = a[b_i]
      l_c = a[c_i]
      
      if l_a == l_b or l_b == l_c or l_a == l_c:
        continue

      if l_a + l_b > l_c and l_b + l_c > l_a and l_c + l_a > l_b:
        result += 1
print(result)

Measured memory_bytes: 9208
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	
	string t;
	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	
	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int  main()
{
	int N; cin >> N;
	vector<int> h(N);
	int cnt = 1;
	priority_queue<int> q;
	rep(i, N)
		cin >> h[i];
	q.push(h[0]);
	rep1(i, N)
	{
		if (q.top() <= h[i] && h[i-1] <= h[i])
		{
			cnt++;
		}
		q.push(h[i]);
	}
	cout << cnt << endl;
	return (0);
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;


int main() {

	int N;

	cin >> N;

	vector<long long> a(N), b(N), c(N);

	REP(i, N)cin >> a[i] >> b[i] >> c[i];

	vector<vector<long long>> dp(N,vector<long long>(3));

	REP(i, N)REP(j, 3)dp[i][j] = -1;

	REP(i, N) {
		if (i == 0) {
			dp[0][0] = a[0];
			dp[0][1] = b[0];
			dp[0][2] = c[0];
			continue;
		}
		dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i - 1][1] + c[i], dp[i - 1][0] + c[i]);
	}

	cout << max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2])) << endl;

	return 0;
}

Measured memory_bytes: 8064
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

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

	ll cnt = 0;
	ll mx = -1;
	int flag = 0;
	for (int i = 0; i < s.size(); i++) {
		flag = 0;

		if (s[i] != 'A' && s[i] != 'T' && s[i] != 'G' && s[i] != 'C') {
			mx = max(mx, cnt);
			cnt = 0;
			flag = 1;
		}

		if(flag == 0) cnt++;
	}

	if (cnt != 0) mx = max(mx, cnt);

	cout << mx << endl;
}

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

int main()
{
    int mn=754;
    char a[20];
    scanf("%s",a);
    for(int i=0;i<strlen(a)-2;i++)
    {
       int k=abs(753-(a[i]-'0')*100-(a[i+1]-'0')*10-a[i+2]+'0');
       if(mn>k)
        mn=k;
    }
    printf("%d\n",mn);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	while (1) {
		int n;
		scanf("%d", &n);
		
		if (n == 0) {
			break;
		}
		
		int a_score = 0;
		int b_score = 0;
		
		int i;
		for (i = 0; i < n; i++) {
			int a;
			int b;
			scanf("%d %d", &a, &b);
			
			*(a >= b ? &a_score : &b_score) += a;
			*(b >= a ? &b_score : &a_score) += b;
		}
		
		printf("%d %d\n", a_score, b_score);
	}
	
	return 0;
}

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

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n, m;
    while(cin >> n >> m, n){
        vector<int> a(n);
        rep(i, n){
            cin >> a[i];
        }
        SORT(a);
        if(a[0] + a[1] > m){
            cout << "NONE" << endl;
            continue;
        }
        int ans = 0;
        rep(i, n){
            int k = upper_bound(a.begin(), a.end(), m - a[i]) - a.begin();
            k--;
            if(i == k){
                k--;
            }
            if(k < 0){
                continue;
            }
            ans = max(ans, a[i] + a[k]);
        }
        cout << ans << endl;
    }
    return 0;
}


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

///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
// #define f(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b,c) for(ll i=a;i<b;i+=c)
#define fo(i,a,b) for(ll i = a; i<=b;i++)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define MOD 1000000007
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define MS(x,y) memset(x,y,sizeof(x))
#define INF 1000000000000000000

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

    //tests(){}
    //v/ll fis;
    //cout<<fis.size();
    ll n;
    cin>>n;
    // bool ans = true;
    std::vector<string> a(n);
    std::map<string , ll > m;
    std::multimap<ll , string, greater<ll> > mp;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    	m[a[i]]++;
    }
    for(auto x:m){
    	ll temp = x.second;
    	mp.insert(make_pair(temp,x.first));
    }
    // for(auto y:mp){
    // 	deb(y.first);
    // 	deb(y.second);
    // }
    ll pre= -1;
    for(auto x:mp){
    	// deb(x.first)
    	
    	// deb(x.second)
    	if ((pre==-1)||(pre==x.first))
    	{
    		cout<<x.second<<endl;
    	}
    	else break;
    	pre = x.first;

    }
    return 0;
}




Measured memory_bytes: 37888
"use strict";
function main(input) {
    const line = input.split("\n");
    const N = parseInt(line[0]);
    const p = line[1].split(" ").map(Number);
    let cnt = 0;
    for (let i = 0; i < N; i++) if (p[i] !== i + 1) cnt++;
    if (cnt <= 2) console.log("YES");
    else console.log("NO");
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29612
while 1:
    n,m=map(int,raw_input().split())
    if n+m==0:
        break
    a = dict(zip(range(m),[0]*m))
    for i in range(n):
        c=map(int,raw_input().split())
        for j in range(m):
            a[j]+=c[j]
    for k,v in sorted(a.items(),key=lambda x:x[1],reverse=1):
        print k+1,
    print

Measured memory_bytes: 6360
// +/- Rectangle
// * frank_c1
// * 2017 / 11 / 09

#include <bits/stdc++.h>
using namespace std;

const int maxn = 505;
const int base = 23333;
int a[maxn][maxn];

int main() {
	int H, W, h, w, sgn = 0;
	scanf("%d%d%d%d", &H, &W, &h, &w);
	if (H % h == 0 && W % w == 0) return printf("No\n"), 0;
	printf("Yes\n");
	if (H % h == 0) {
		for (int i = 1; i <= H; ++i) {
			for (int j = 1; j <= W; ++j) printf("%d ", j % w == 0 ? -base * (w - 1) - 1 : base); putchar('\n');
		}
	} else {
		for (int i = 1; i <= H; ++i) {
			for (int j = 1; j <= W; ++j) printf("%d ", i % h == 0 ? -base * (h - 1) - 1 : base); putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
	char s;
	int n;
	cin>>n;
	int r=0,b=0;
	for(int i = 0; i<n;i++)
	{
		cin>>s;
		if(s=='R')r++;
		else b++;
	}
	
	if(r <= b)
	{
		cout<< "No" <<endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
# PyPy3

N, W = map(int, input().split())

dp = [[0]*(W+1) for _ in range(N+1)]
    
def npsk_1(N, W):
    for i in range(N):
        w, v = map(int, input().split())
        for j in range(W+1):
            if j  >= w:
                dp[i+1][j] = max(dp[i][j], dp[i][j - w] + v)
            else:
                dp[i+1][j] = dp[i][j]
    
    print(dp[N][W])

npsk_1(N, W)

Measured memory_bytes: 118512
s = list(input())
t = list(input())
from collections import defaultdict

def s2i(z):
    ret = []
    nz = defaultdict(int)
    for i in range(len(z)):
        if z[i] in nz:
            ret.append(nz[z[i]])
        else:
            x = len(nz) + 1
            ret.append(x)
            nz[z[i]] = x
    return ret

ss = s2i(s)
tt = s2i(t)
if ss == tt:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 10024
#include<stdio.h>

void pass(int x,int y,int a,int b,int n,int *map){
	int i;
}

int main(){
	int a,b,n,map[16][16],i,j,x,y;
	scanf("%d %d",&a,&b);
	while(a){
		for(i=0;i<a;i++){
			for(j=0;j<b;j++){
				map[i][j]=0;
			}
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&x,&y);
			map[x-1][y-1]=-1;
		}
		for(i=0;i<b;i++){
			for(j=0;j<a;j++){
				if(i==0){
					if(j==0){
						map[0][0]=1;
					}else{
						if(map[j][0]==-1) map[j][0]=0;
						else{
							map[j][i]=map[j-1][0];
						}
					}
				}else{
					if(j==0){
						if(map[0][i]==-1) map[0][i]=0;
						else{
							map[0][i]=map[0][i-1];
						}
					}else{
						if(map[j][i]==-1) map[j][i]=0;
						else{
							map[j][i]=map[j-1][i]+map[j][i-1];
						}
					}
				}
			}
		}
		printf("%d\n",map[a-1][b-1]);
		scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
bool compare(pair<ll,string> p1,pair<ll,string> p2){
return p2.fi>p1.fi;
}
void solve(){
string s;
cin>>s;
if(s[1]=='R') s[1]='B';
    else s[1]='R';
cout<<s<<endl;
}
int main()
{   fast;
    ll t=1;
    //cin>>t;
    fr(zz,1,t+1){
    solve();
    }
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define re register
#define SIZE 100005
using namespace std;
template <typename T>
inline void read(T &x)
{
	int f;char c;
	x=0,f=0,c=getchar();
	while(c<'0' && '9'<c)	f|=(c=='-'),c=getchar();
	while('0'<=c && c<='9')	x=(x<<3)+(x<<1)+c-48,c=getchar();
	x=f?-x:x;
}
int n;
int h[SIZE];
int dp[SIZE];
int main()
{
	read(n);
	for(re int i=1;i<=n;++i)
		read(h[i]);
	if(n==1)
	{
		printf("0\n");
		return 0;
	}
	dp[2]=abs(h[2]-h[1]);
	for(re int i=3;i<=n;++i)
	{
		int f1,f2;
		f1=dp[i-1]+abs(h[i]-h[i-1]);
		f2=dp[i-2]+abs(h[i]-h[i-2]);
		dp[i]=min(f1,f2);
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	k := getNextInt(scanner)

	g := make([][]int, n)
	m := 0
	for i := 0; i < n-1; i++ {
		g[i] = make([]int, n)
		for ii := i + 1; ii < n; ii++ {
			g[i][ii] = 1
			m++
		}
	}
	if k == 0 {
		fmt.Fprintln(writer, m)
		ans := answer(m, n, g)
		for k := 0; k < m; k++ {
			fmt.Fprintln(writer, ans[k])
		}
		writer.Flush()
		return
	}

	for i := 1; i < n-1; i++ {
		for ii := i + 1; ii < n; ii++ {
			if g[i][ii] == 1 {
				k--
				m--
				g[i][ii] = 0
				if k == 0 {
					fmt.Fprintln(writer, m)
					ans := answer(m, n, g)
					for k := 0; k < m; k++ {
						fmt.Fprintln(writer, ans[k])
					}
					writer.Flush()
					return
				}
			}
		}
	}

	fmt.Fprintln(writer, -1)
	writer.Flush()
}

func answer(m, n int, g [][]int) []string {
	ans := make([]string, m)
	a := 0
	for i := 0; i < n-1; i++ {
		for ii := i + 1; ii < n; ii++ {
			if g[i][ii] == 1 {
				ans[a] = fmt.Sprintf("%d %d", i+1, ii+1)
				a++
			}
		}
	}
	return ans
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e3 + 7;
int n, m, ans;
char s[maxx][maxx];
int res[maxx][maxx];
vector <int> vec1[maxx]; //每行#坐标
vector <int> vec2[maxx]; //每列#坐标

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 0; i <= n + 1; i++) {
		for(int j = 0; j <= m + 1; j++) s[i][j] = '#';
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) scanf(" %c", &s[i][j]);
	}
	for(int i = 0; i <= n + 1; i++) {
		for(int j = 0; j <= m + 1; j++) {
			if(s[i][j] == '#') {
				vec1[i].push_back(j);
				vec2[j].push_back(i);
			}
		}
	}
	int pos = 0;
	for(int i = 1; i <= n; i++) {
		pos = 0;
		for(int j = 1; j <= m; j++) {
			if(s[i][j] == '.') {
				res[i][j] += vec1[i][pos + 1] - vec1[i][pos];
			}
			else pos++;
		}
	}
	pos = 0;
	for(int j = 1; j <= m; j++) {
		pos = 0;
		for(int i = 1; i <= n; i++) {
			if(s[i][j] == '.') {
				res[i][j] += vec2[j][pos + 1] - vec2[j][pos];
			}
			else pos++;
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) ans = max(ans, res[i][j] - 3);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 54144
d = int(input())
cl = list(map(int, input().split()))
sl = []
for _ in range(d):
    sl.append(list(map(int, input().split())))

tl = []
# for _ in range(d):
#     tl.append(int(input()))

last_di = [-1]*26
ans = 0
for day in range(d):
    # if day <= 100:
    #     coef = 1.0*day/36.0 + 3.0
    # else:
    #     coef = 10.0 - 1.0*day/36.0 + 3.0
    coef = 7.0 - day/90.0
    best_t = 0
    best_t_val = -999999999999
    for t in range(26):
        curr_val = sl[day][t]*1
        for i in range(26):
            if i == t: continue
            curr_val -= (day-last_di[i])*cl[i]*coef
        if curr_val >= best_t_val:
            best_t = t
            best_t_val = curr_val
    tl.append(best_t+1)
    last_di[best_t] = day
    ans += best_t_val
    # print(ans)
    # print('-- {}---'.format(day))
    # print(best_t)
    # print(last_di)

for t in tl:
    print(t)

# for day, t in enumerate(tl):
#     ans += sl[day][t-1]
#     last_di[t-1] = day
#     for ld, c in zip(last_di, cl):
#         # if ld == -1: continue
#         ans -= (day-ld)*c
#     print(ans)

Measured memory_bytes: 9400
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ARC075C
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var N = NN;
            var sList = NNList(N);
            var total = sList.Sum();
            var ans = 0L;
            if (total % 10 != 0) ans = total;
            foreach (var item in sList)
            {
                if ((total - item) % 10 != 0) ans = Max(ans, total - item);
            }
            Console.WriteLine(ans);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 14944
#include <iostream>
#include <cstring>
using namespace std;
int r,c,data[12][10010],start[10010],rowcnt[12],tmp[10010];
int main()
{
	ios::sync_with_stdio(false);
	while(true)
	{
		cin>>r>>c;
		if(r==0)
			return 0;
		int ans=0;
		memset(start,0,sizeof(start));
		memset(rowcnt,0,sizeof(rowcnt));
		for(int i=0;i<r;i++)
		for(int j=0;j<c;j++)
		{
			cin>>data[i][j];
			if(data[i][j])
			{
				++start[j];
				++rowcnt[i];
			}
		}
		for(int x=0;x<(1<<r);x++)
		{
			int smallans=0;
			for(int col=0;col<c;col++)
				tmp[col]=start[col];
			for(int dig=0;dig<r;dig++)
			{
				if((x>>dig)&1)
				{
					for(int col=0;col<c;col++)
					{
						if(data[dig][col])
							--tmp[col];
						else
							++tmp[col];
					}
				}
			}
			for(int col=0;col<c;col++)
				smallans+=max(r-tmp[col],tmp[col]);
			ans=max(ans,smallans);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

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

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

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    vector<ll> ans(n);
    ans[0] = accumulate(v.begin(),v.end(), 0LL);
    for (int j = 1; j < n; j += 2) {
        ans[0] -= 2*v[j];
    }
    for (int j = 1; j < n; ++j) {
        ans[j] = 2*v[j-1]-ans[j-1];
    }
    for (int i = 0; i < n; ++i) {
        if(i) printf(" ");
        printf("%lld", ans[i]);
    }
    puts("");
    return 0;
}

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

int main(void)
{
  int a, b;
  cin >> a >> b;
  if(a + b == 15){
    cout << "+" << endl;
  }else if(a * b == 15){
    cout << "*" << endl;
  }else{
    cout << "x" << endl;
  }
  return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int a, b, h, m;
	double ans, diff;
	double pi = asin(1.0)*2;
	cin >> a >> b >> h >> m;
	double hd = 30 * h + (double)m/2;
	double md = 6 * m;
	if (hd >= md){
		diff = hd - md;
	}
	else {
		diff = md - hd;
	}
	ans = sqrt(a * a + b * b - 2 * a * b * cos(diff*pi/180));

	cout << fixed << setprecision(9) << ans << endl;
}

Measured memory_bytes: 4252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll west[300007];
  ll east[300007];
  west[0] = 0;
  east[0] = 0;
  for (ll i = 1; i <= n; i++){
    west[i] = west[i - 1];
    east[i] = east[i - 1];
    if (s[i-1] == 'W'){
      west[i]++;
    }
    else{
      east[i]++;
    }
  }
  ll mini = INF;
  for (ll i = 1; i <= n; i++){
    ll count = 0;
    count += west[i - 1];
    count += east[n] - east[i];
    chmin(mini, count);
  }
  print(mini);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long  ull;

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define sz(x) int (x.size());
//typedef pair<int,int> P;

using namespace std;
const int MOD=1000000007;
const int INF=1001001001;

int main(){
  ull n,a,b,c,d,e;
  cin>>n>>a>>b;
  c=a+b;
  d=n/c;
  e=n%c;
  ull ans=0;
  ans+=a*d;
  if (e>a)ans+=a;
  else ans+=e;
  cout<<ans;


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

const int CN = 1e5 + 5;

int read(){
    int s = 0,ne = 1; char c = getchar();
    while(c < '0' || c > '9') ne = c == '-' ? -1 : 1, c = getchar();
    while(c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - '0', c = getchar();
    return s * ne;
}

int n, a[CN], sum = 0, ans = 0; map<int, bool> ext;

int main()
{
    // freopen("_in.in", "r", stdin);

    n = read(); for(int i = 1; i <= n; i++) a[i] = read(), sum ^= a[i];
    for(int i = 1; i <= n; i++) ext[ a[i] ^ (a[i] - 1) ] = true;

    bool flag = true;
    for(int k = 29; k + 1; k--)
        if(sum & (1 << k)){
            int u = (1 << (k + 1)) - 1;
            if(!ext.count(u)) {flag = false; break;}
            sum ^= u, ans++;
        }
    if(!flag) puts("-1");
    else printf("%d ", ans);
}

Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; i64 A, B; scanf("%d%lld%lld", &n, &A, &B); std::vector<i64> x(n);
	for(int i = 0; i < n; i++) scanf("%lld", &x[i]);
	
	std::vector<i64> dp(n + 1, 1LL << 60); dp[0] = 0;
	for(int i = 0; i < n - 1; i++) {
		i64 d = x[i + 1] - x[i];

		dp[i + 1] = std::min({dp[i + 1], dp[i] + d * A, dp[i] + B});
	}
	printf("%lld\n", dp[n - 1]);
	return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

    ll N; cin >> N;
    vector<ll> L;

    L.pb(2);
    L.pb(1);
    REPS(i, 2, N) {
        L.pb(L[i-1] + L[i-2]);
    }
    cout << L[N] << endl;
    return 0;
}

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

int main()
{
    int a,b,c,i,j,t;
    cin>>a ;cin>>b;
    cout<<a*b;
    // for (int z = 0; z < t; i++)
    // { vector<int> v ;

    //     /* code */
    // }
    
}

Measured memory_bytes: 3568
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
	 Scanner reader  =new Scanner(System.in);	
	 int a=reader.nextInt();
	 int b=reader.nextInt();
	 int c=reader.nextInt();
	 int s1=a+b;
	 int s2=b+c;
	 int s3=a+c;
	 if(s1<s2 && s1<s3) {
		 System.out.println(s1);
		 
	 }
	 else if (s2<s1 && s2<s3){
		 System.out.println(s2);
	 }
	 else  {
		 System.out.println(s3);
	 }
	}

}


Measured memory_bytes: 23252
n,m=map(int,input().split())
p=1
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    if m//i>=n:
      if i>=n:
        p=max(i,m//i,p)
      else:
        p=max(p,i)
print(p)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        int start = s.indexOf("A");
        int end = s.lastIndexOf("Z");
        System.out.println(end - start + 1);
    }
}


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

int main() {
  string N;
  cin >> N;
  int NA = 0, ans = 0;
  for(int i = 0; i < N.size(); i++){ 
    NA = N.at(i) -'0';
    ans += NA;
  }
  if(ans % 9 == 0) cout << "Yes" << endl;
  else cout << "No" <<endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main() {
	VI x(5); rep(i,5) cin>>x[i];
	rep(i,5){
		if(x[i]==0) cout<<i+1<<endl;
	}


	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
#define ipair pair<int,int>
#define mod 1000000007


int main()
{
   int n,a;
   cin>>n>>a;
   cout<<n*n-a<<endl;
}



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

namespace abc168_v{
    class Program{
        static void Main(string[] args){
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if(s.Length <= k){
                System.Console.WriteLine(s);
            }else{
                Console.WriteLine(s.Substring(0, k) + "...");
            }
        }
    }
}


Measured memory_bytes: 27524
#include<iostream>
#include<string>
using namespace std;
long long int a[100005];
long long int b[100005]={};
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    long long int N;
    long long int maxv=0;
    
    cin >> N;
    for(long long int i=0;i<N;i++){
        cin >> a[i];
    }
    for(long long int i=0;i<N;i++){
        if(a[i]>0) b[a[i]-1]++;
        if(a[i]<100000) b[a[i]+1]++;
        b[a[i]]++;
    }
    for(long long int i=0; i<100000;i++) {
        if( b[i] > maxv )
            maxv = b[i];
    }
        
	cout << maxv << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    string s;cin>>s;
    rep(i,0,3)cout<<s[i];
 
return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    q = []
    heappush(q, (-(A[0]+B[0]+C[0]),0,0,0))
    count = 0
    used = set()

    while count < K:
        num, s,t,u = heappop(q)
        print(-num)
        used.add((s,t,u))

        if s+1 < X and (s+1,t,u) not in used:
            heappush(q, (-(A[s+1]+B[t]+C[u]),s+1,t,u))
            used.add((s+1,t,u))
        if t+1 < Y and (s,t+1,u) not in used:
            heappush(q, (-(A[s]+B[t+1]+C[u]),s,t+1,u))
            used.add((s,t+1,u))
        if u+1 < Z and (s,t,u+1) not in used:
            heappush(q, (-(A[s]+B[t]+C[u+1]),s,t,u+1))
            used.add((s,t,u+1))
        count += 1

if __name__ == "__main__":
    main()


Measured memory_bytes: 10920
#include <cstdio>
using namespace std;
int main(void){
    double a, b, p, q, r, d1, d2, res;
    scanf("%lf %lf", &a, &b);
    scanf("%lf %lf %lf", &p, &q, &r);
    d1 = b * p;
    d2 = (b-a)*q;
    res = (d1-d2) / (q+r);
    printf("%.12lf\n", res+b);
    return 0;
}



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

int main(){
  string n;
  cin>>n;
  for(int i=0;i<3;i++){
    if(n[i]=='9'){
      n[i]='1';
    }
    else if(n[i]=='1'){
      n[i]='9';
    }
  }
  cout<<n<<endl;
}

Measured memory_bytes: 256