akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int formula(int &p,bool inper);
pair<int,bool> term1(int &p);
int term2(int &p);
int get_num(int &p);

int calc(int lhs,int rhs,char op){
  int res=-1;
  if(lhs==-1 || rhs==-1) return -1;
  if(op=='+') res=lhs+rhs;
  if(op=='-') res= lhs-rhs;
  if(op=='*') res= lhs*rhs;
  return (0<=res && res<1024) ? res : -1;
}

string s;
int formula(int &p,bool inper=false){
  bool isok=!inper;
  pair<int,bool> ret=term1(p);
  int res=ret.first;
  isok|=ret.second;
  while(p<s.size() && s[p]!=')'){
    char op=s[p];
    if(op!='+' && op!='-'){
      return -1;
    }
    isok=true;
    p++;
    int rhs=term1(p).first;
    res=calc(res,rhs,op);
  }
  if(!inper && s[p]==')') return -1;
  return isok ? res : -1;
}

pair<int,bool> term1(int &p){
  int res=term2(p);
  bool res2=false;
  while(p<s.size() && s[p]!=')' && s[p]!='+' && s[p]!='-'){
    char op=s[p];
    p++;
    if(op!='*'){
      return {-1,0};
    }
    res2=true;
    int rhs=term2(p);
    res=calc(res,rhs,op);
  }
  return {res,res2};
}

int term2(int &p){
  int res=-1;
  if(s[p]=='('){
    p++;
    res=formula(p,true);
    if(s[p]!=')') return -1;
    p++;
  }
  else if(isdigit(s[p])){
    res=get_num(p);
  }
  else{
    return -1;
  }
  return res;
}

int get_num(int &p){
  int res=-1;
  while(isdigit(s[p])){
    if(res==-1) res=0;
    res*=2;
    res+=(s[p]-'0');
    p++;
  }
  //cout<<res<<endl;
  if(res>=1024) return -1;
  return res;
}

string ch="01+-*()";

int dfs(int i){
  if(i==s.size()){
    int p=0;
    //cout<<s<<endl;
    int res=formula(p);
    //cout<<res<<endl;
    return res;
  }
  if(s[i]=='.'){
    int res=-1;
    for(int j=0;j<ch.size();j++){
      s[i]=ch[j];
      res=max(res,dfs(i+1));
      s[i]='.';
    }
    return res;
  }
  else{
    return dfs(i+1);
  }
}

int main(){
  cin>>s;
  cout<<dfs(0)<<endl;
  return 0;
}

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


int main(){
    int N, A, B, t;
    long ans=0;
    cin >> N >> A >> B;
    
    for(int i=1 ; i <=N ;i++){
        t =0;
        string s = std::to_string(i);
        for(int j=0; j < s.length(); j++){
            t += s[j] - '0';
        }
        if(A<=t && t<=B) ans +=i;
    }
    cout << ans << endl;

    return 0;
}
    

Measured memory_bytes: 256
N=int(input())
A=[int(input()) for i in range(N)]
t=1
ans=A[0]-1
A[0]=1
for i in range(1,N):
    if A[i]==t+1:
        t+=1
        continue
    if A[i]%(t+1)==0 and A[i]>(t+1):
        A[i]-=(t+2)
        ans+=1
    ans+=A[i]//(t+1)
    A[i]=A[i]-(A[i]//(t+1))*(t+1)
print(ans)


Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define forn(i, k, n) for (int i = k+1; i < int(n); i++)
typedef long long LL;
typedef pair<int, int> PII;

int pizza_value(int a,int b,int c,int a_num,int b_num, int c_num){
    if(a_num < 0)
        a_num = 0;
    if(b_num < 0)
        b_num = 0;    
    return a*a_num + b*b_num + c*c_num;
}

void f(int a,int b,int c,int x,int y) {
  int ans = 5000*2*1e5;
  int big = x > y? x:y;
  int temp;

  for(int i = 0; i <= big; i++){
      //temp = pizza_value(a,b,c,x - i, y - i, 2*i);
      //cout << "A " << x-i << " B " << y - i << " AB " << 2*i << endl;
      ans = min(ans, pizza_value(a,b,c,x - i, y - i, 2*i));
  }

  cout << ans << endl; 
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  f(a,b,c,x,y);
  return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>

int main(void)
{
    int x, y, s;
    int p[14][14] = {0};
    int q[3][5][5] = {
        {
            {0, 0, 0, 0, 0},
            {0, 0, 1, 0, 0},
            {0, 1, 1, 1, 0},
            {0, 0, 1, 0, 0},
            {0, 0, 0, 0, 0},
        },
        {
            {0, 0, 0, 0, 0},
            {0, 1, 1, 1, 0},
            {0, 1, 1, 1, 0},
            {0, 1, 1, 1, 0},
            {0, 0, 0, 0, 0},
        },
        {
            {0, 0, 1, 0, 0},
            {0, 1, 1, 1, 0},
            {1, 1, 1, 1, 1},
            {0, 1, 1, 1, 0},
            {0, 0, 1, 0, 0},
        }
    };
    int i, j;
    int c = 100, m = 0;

    while (scanf("%d,%d,%d", &x, &y, &s) != EOF)
        for (i = 0; i < 5; ++i)
            for (j = 0; j < 5; ++j)
                p[x + i][y + j] += q[s - 1][i][j];

    for (i = 0; i < 10; ++i) {
        for (j = 0; j < 10; ++j) {
            if (p[i + 2][j + 2] >= 1) {
                --c;
                if (p[i + 2][j + 2] > m)
                    m = p[i + 2][j + 2];
            }
        }
    }

    printf("%d\n%d\n", c, m);

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n,m,x,a[200],f = 0,b = 0;
  cin >> n >> m >> x;
  for(int i = 0; i < m; i++) {
    cin >> a[i];
    if(x > a[i]) f++;
    else b++;
  }
  if(f > b) cout << b << endl;
  else cout << f << endl;
}

Measured memory_bytes: 3600
while True:
	n = int(raw_input())
	if n == 0:
		break
	else:
		data = map(int, raw_input().split())

		all_sum = 0
		for i in range(n):
			all_sum += data[i]
		ave = all_sum * 1.0 / n

		bunsan_sum = 0
		for i in range(n):
			bunsan_sum += (data[i] - ave)**2
		bunsan = bunsan_sum / n

		alpha = bunsan ** 0.5

		print("{:.8f}".format(alpha))

Measured memory_bytes: 4764
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005
using namespace std;
typedef long long ll;
struct edge{
	int k,next;
}e[N<<1];
int n,home[N],cnt=-1,w[N],D=1;
ll f[N],a[N];
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
void dfs(int k,int F){
	if(w[k]==1){
		f[k]=a[k];return;
	}
	ll sum=0;
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		dfs(e[i].k,k);
		if(!D) return;
		if(f[e[i].k]>a[k]){
			D=0;return;
		}
		sum+=f[e[i].k];
	}
	if(sum<a[k]){
		D=0;return;
	}
	if(sum>a[k]+a[k]){
		D=0;return;
	}
	f[k]=a[k]+a[k]-sum;
}
int main(){
	memset(home,-1,sizeof(home));
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	if(n==2){
		if(a[1]!=a[2]) puts("NO");
		else puts("YES");
		return 0;
	}
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
		w[x]++;w[y]++;
	}
	int F;
	for(int i=1;i<=n;i++) if(w[i]>1){
		F=i;
		dfs(i,0);
		break;
	}
	if(D&&!f[F]) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 8192
//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =1;
string s,t;
int w;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>s>>w;
    rep(i,0,s.size())if(i%w==0)
    {
        t.pb(s[i]);
    }
    cout<<t;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 201

int main(void){
	int A[N];
	int tmp,max,i,n,m,z;
	char str[N];

	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d",&z);
	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d %d",&n,&m);
	A[n]=m; max=m; tmp=n;
	for(i=1;i<z;i++){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d %d",&n,&m);
		A[n]=m;
		if(m==max){
			if(tmp>n)
				tmp=n;
		}
		else if(m>max){
			tmp=n;
			max=m;
		}
	}
	printf("%d %d\n",tmp,A[tmp]);
	return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int a,b;
 
signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> a >> b;
	print1(a-b+1);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string x;
    cin>>x;
    
    if(x=="Sunny"){
       cout<<"Cloudy";
 
    }
    else if(x=="Cloudy"){
        cout<<"Rainy";
 
    }
    else if(x=="Rainy"){
        cout<<"Sunny";
 
    }
  else
  {cout<<"enter a vaild weather";}
  
return 0;}
 

Measured memory_bytes: 256
a = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]

flg = 0
for i in range(3):
    if (a[i][0] in b) and (a[i][1] in b) and (a[i][2] in b):
        print('Yes')
        flg = 1
        break
    elif (a[0][i] in b) and (a[1][i] in b) and (a[2][i] in b):
        print('Yes')
        flg = 1
        break
    
if flg == 1:
    pass
elif (a[0][0] in b) and (a[1][1] in b) and (a[2][2] in b):
    print('Yes')
elif (a[0][2] in b) and (a[1][1] in b) and (a[2][0] in b):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
n, y = map(int, input().split())

a, b, c = -1 ,-1, -1
for i in range(n + 1):
    for j in range(n +1 - i):
        k = n - i - j
        total = 10000 * i + 5000 * j + 1000 * k
        if total == y:
            a, b ,c = i, j, k
print('{} {} {}'.format(a, b, c))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fast() ios_base::sync_with_stdio (false); cin.tie (NULL)

using namespace std;
const unsigned int MOD = 1e9+7;

int N,K;

void solve () {
    cin >> N >> K;
    vector <int> height(N);
    for (int &x : height) cin >> x;
   
    vector <int> dp(N);
    for (int i=1;i<N;i++) {
        dp[i] = INT_MAX;
        for (int j=1;j<=K;j++) {
            dp[i] = min (dp[i], (i-j < 0 ? INT_MAX : dp[i-j] + abs (height[i] - height[i-j])));
        }
    }   
    
    cout << dp[N-1] << endl;
}

int main()
{
	
    fast();
    solve ();
    return 0;
}





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

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

    int x;
    cin >> x;
    
    set<int> st;
    st.insert(1);
    for(int i = 2; i <= 31; i++){
        int tmp = i;
        while(true){
            tmp *= i;
            if(tmp > x) break;
            st.insert(tmp);
        }
    }
    vector<int> A;
    for(auto y : st){
        A.push_back(y);
    }
    cout << A[A.size() - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
S=input()
c0=0
c1=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='0':
      c0+=1
  else:
    if S[i]=='1':
      c0+=1
for i in range(len(S)):
  if i%2==0:
    if S[i]=='1':
      c1+=1
  else:
    if S[i]=='0':
      c1+=1
print(min(c0,c1))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,i,c=0;
    cin>>n;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='W')
        {
            x=i+1;
            break;
        }
    }
    for(i=x;i<s.size();i++)
    {
        if(s[i]=='R')
        {
            c++;
        }
    }
    int w=c;
    c=0;
    int ll=0,rr=n-1;
    while(ll<rr)
    {
        if(s[ll]=='W'&&s[rr]=='R')
        {
            c++;
            swap(s[ll],s[rr]);
        }
        else
        {
            if(s[ll]=='R')
                ll++;
            if(s[rr]=='W')
                rr--;
        }
    }
    cout<<min(w,c);
}


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

#define pb push_back
#define pbk pop_back
#define mk_pr make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<string> vss;
typedef queue<int> qi;

const int MX = 123456;

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

        int a, b, c;
        cin >> a >> b >> c;
        a = a*100 + b*10 + c;

        if( a%4 == 0 ) cout << "YES" << endl;
        else cout << "NO" << endl;

        return 0;
}


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

static class LIS {
    struct D : IComparable<D> {
        public int value;
        public int index;
        public int CompareTo(D o) {
            return value.CompareTo(o.value);
        }
    }

    public static List<int> Do(List<int> xs) {
        var lis = new List<D>();
        lis.Add(new D { value=xs[0], index=0 });

        var prev = new int[xs.Count];
        prev[0] = -1;
        for (int i = 1; i < xs.Count; i++) {
            var d = new D { value=xs[i], index=i };
            int p = lis.BinarySearch(d);
            if (p < 0) {
                int m = ~p;
                if (m == lis.Count) lis.Add(d);
                else lis[m] = d;

                if (m == 0) prev[i] = -1;
                else prev[i] = lis[m-1].index;
            }
        }

        var ret = new List<int>();
        int index = lis.Last().index;
        while (index != -1) {
            ret.Add(xs[index]);
            index = prev[index];
        }
        ret.Reverse();
        return ret;
    }
}

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Main() {
        int n = ReadInt();
        var xs = new List<int>();
        for (int i = 0; i < n; i++) {
            xs.Add(ReadInt());
        }


        var ans = LIS.Do(xs);
        Console.WriteLine(ans.Count);
    }
}

Measured memory_bytes: 14052
import java.util.Scanner;
class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();
        if (K <= A) {
        		System.out.println(A-K + " " + B);
        } else if(K > A+B){
        		System.out.println("0 0");
        } else {
        		System.out.println("0 " + (A+B-K));
        }
    }
} 

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
const int MAX_S = 1005;
using namespace std;

int main(void) {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        string x, y;
        cin >> x >> y;
        x = ' ' + x;
        y = ' ' + y;

        int dp[MAX_S][MAX_S];
        for (auto j = 1; j < x.size(); j++) {
            dp[j][0] = 0;
        }
        for (auto k = 1; k < y.size(); k++) {
            dp[0][k] = 0;
        }

        int maxlength = 0;
        for (auto j = 1; j < x.size(); j++) {
            for (auto k = 1; k < y.size(); k++) {
                if (x[j] == y[k]) {
                    dp[j][k] = dp[j-1][k-1] + 1;
                } else {
                    dp[j][k] = max(dp[j-1][k], dp[j][k-1]);
                }
                maxlength = max(maxlength, dp[j][k]);
            }
        }

        cout << maxlength << endl;
    }

    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    long long n, m;
    cin >> n >> m;
    vll a(n);

    rep(i, m) cin >> a[i];

    long long sum = 0;

    rep(i, m) sum += a[i];

    if(n-sum>=0){
        cout << n - sum << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 11128
import java.util.Arrays;
import java.util.Scanner;

//Lupin The 4th
public class Main{

	int n, INF = 1<<29;
	int[] dist, num;
	double[][] dp;
	int[][][] next;
	
	double get(int state, int v, int w){
		if(state==(1<<n)-1){
			next[state][v] = new int[]{-1, -1};
			return 0;
		}
		if(dp[state][v]!=INF)return dp[state][v];
		double min = INF;
		for(int i=0;i<n;i++){
			if(((state>>i)&1)>0)continue;
			double t = Math.abs(dist[v]-dist[i])/(2000.0/(70+w)) + get(state+(1<<i), i, w+20*num[i]);
			if(t<min){
				min = t;
				next[state][v] = new int[]{state+(1<<i), i};
			}
		}
		return dp[state][v] = min;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] ref = new int[n];
		dist = new int[n];
		num = new int[n];
		for(int i=0;i<n;i++){
			ref[i] = sc.nextInt();
			dist[i] = sc.nextInt();
			num[i] = sc.nextInt();
		}
		dp = new double[1<<n][n];
		for(double[]a:dp)Arrays.fill(a, INF);
		next = new int[1<<n][n][2];
		double min = INF;
		int id = -1;
		for(int i=0;i<n;i++){
			double t = get(1<<i, i, 20*num[i]);
			if(t<min){
				min = t; id = i;
			}
		}
		int[] s = new int[]{1<<id, id};
		System.out.print(ref[id]);
		for(;;){
			s = next[s[0]][s[1]];
			if(s[0]==-1)break;
			System.out.print(" "+ref[s[1]]);
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	int N, K;
	int A[505], r[505];
	set<ll> candi;
	ll sum = 0;

	cin >> N >> K;

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

	for (int i = 1; i * i <= sum; i++) {
		if (sum % i == 0) {
			candi.insert(i);
			candi.insert(sum / i);
		}
	}

	ll ans = 1;
	for (ll x : candi) {
		ll need;
		for (int i = 0; i < N; i++) {
			r[i] = A[i] % x;
		}
		sort(r, r + N);
		ll B = 0;
		for (int i = 0; i < N; i++) {
			B += x - r[i];
		}
		ll A = 0;
		need = 1e18;
		for (int i = 0; i < N; i++) {
			A += r[i];
			B -= x - r[i];
			need = min(need, max(A, B));
		}
		if(need <= K) {
			ans = max(ans, x);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val inputs = readInputLine().split(" ").map { Integer.parseInt(it) }
    val n = inputs[0]
    val k = inputs[1]
    
    if (k == 1) {
        println("0")
    } else {
        println("${n - k}")
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


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

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 998244353


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 	int n;
 	cin>>n;
 	string s;
 	cin>>s;
 	int w = 0;
 	for (auto j:s)
 	{
 		if (j=='W')
 			w++;
 	}
 	string t = "";
 	for (int i=0;i<n-w;++i)
 		t += "R";
 	for (int i=0;i<w;++i)
 		t += "W";
 	int ans = 0;
 	for (int i=0;i<n;++i)
 	{
 		if (s[i]!=t[i])
 			ans++;
 	}
 	cout << ans/2 << "\n";
    
    return 0;
}



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

int main() {
  string s;
  long k,ans,a=1,b=1;
  ans=0;
  cin >> s >> k;

  for(int i=0;i<s.size()-1;i++) {
    if(s.at(i)==s.at(i+1)) i++,ans++;
  };
  ans*=k;
  if(s.at(0)==s.at(s.size()-1)) {
    for(int i=0;i<s.size()-1;i++) {
      if(s.at(i)==s.at(i+1)) a++;
      else break;
    };
    for(int i=s.size()-1;i>0;i--) {
      if(s.at(i)==s.at(i-1)) b++;
      else break;
    };
    if(a==s.size()) {
      ans=s.size()*k/2;
    } else {
      if(a%2==1&&b%2==1) ans+=k-1;
    };
  };

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



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


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n;
  cin>>n;
  if(n>=30)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}
    

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};
ll ccalc(ll a) {
    ll tmp = a;
    ll ttmp = 0;
    rep(i, 2) {
        if (tmp % 2) ttmp += pow(2, i);
        tmp /= 2;
    }
    tmp = a;
    tmp -= ttmp; //下位2bitを除く
    ll tttmp = ttmp;
    //下位2bit変換
    if (ttmp == 2) ttmp = 3;
    else if (ttmp == 3) ttmp = 0;
    if (tttmp % 2 == 0) {
        ttmp += tmp;
    }
    return ttmp;
}

int main() {
    
    ll a, b; cin >> a >> b;
    cout << ((a == 0 ? 0 : ccalc(a - 1)) ^ ccalc(b)) << endl; //a, 0やとまずくないか
    
}



Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n,m,c;
    cin>>n>>m>>c;
    
    int b[m];
    forn(i,m)   cin>>b[i];
    
    int a[n][m];
    forn(i,n)
        forn(j,m)
            cin>>a[i][j];
    
    int cnt=0;
    forn(i,n){
        int sum=0;
        forn(j,m)   sum += (a[i][j]*b[j]);
        if (sum+c>0)    cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
S = input()
#dp[i][j] S[i-x:i+1]==S[j-x:j+1]となる最大のx
dp = [[0] * (N + 1) for _ in range(N + 1)]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i - 1][j - 1] + 1, j - i)
    ans = max(dp[i] + [ans])
print(ans)


Measured memory_bytes: 271324
#https://atcoder.jp/contests/abc129/tasks/abc129_c
N,M = map(int,input().split())
Danger_List = []
Route_List = [[] for i in range(N+1)]
for i in range(M):
    Route_List[int(input())] = 0
        
Route_List[0] = 1

for i in range(1,N+1):
    if Route_List[i] != 0:
        if i == 1:
            Route_List[i] = 1
        else:
            Route_List[i] = Route_List[i-1] + Route_List[i-2]

    
    
        
print(Route_List[-1] % 1000000007)

Measured memory_bytes: 466092
H, W = map(int, input().split())

if W % 2 == 0:
    x = W // 2
    y = W // 2
else:
    x = W // 2 + 1
    y = W // 2

if H % 2 == 0:
    ans = (x + y) * (H // 2)
else:
    ans = (x + y) * (H // 2) + x

if H == 1 or W == 1:
    print(1)
else:
    print(ans)


Measured memory_bytes: 3060
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

a,b,h,m = map(int,input().split())
d1 = h*30 + m*0.5
d2 = m*6
kakudo = abs(d2-d1)
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo)))
print(ans)

Measured memory_bytes: 68444
#include <stdio.h>
#include <string.h>

#define N 50

int main(void)
{
    int n;
    char s[N + 1];
    const char t[] = "ABC";

    scanf("%d", &n);
    scanf("%s", s);

    int ans = 0;
    for (int i = 0; i < N - 2; i++) {
        if (memcmp(&s[i], t, 3) == 0) {
            ans++;
        }
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  string s,t;
  cin>>s>>t;
  swap(s[0],s[2]);
  if (s==t) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,flag=1;
  cin >> n;
  string tmp;
  map<string,int> mp;
  rep(i,n){
    cin >> tmp;
    if(!mp.count(tmp)){
      mp[tmp]=1;
    }
    else{
      flag=0;
      break;
    }
  }
  if(flag)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 24832
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  int n = readln.chomp.to!int;
  string s = readln.chomp;
  int[] rcs = new int[n+1];
  int[] gcs = new int[n+1];
  int[] bcs = new int[n+1];

  long sum = 0;

  for(int i=0; i<s.length; i++) {
    if(s[$-1-i]=='R') rcs[n-1-i]=rcs[n-i]+1;
    else rcs[n-1-i]=rcs[n-i];
    if(s[$-1-i]=='G') gcs[n-1-i]=gcs[n-i]+1;
    else gcs[n-1-i]=gcs[n-i];
    if(s[$-1-i]=='B') bcs[n-1-i]=bcs[n-i]+1;
    else bcs[n-1-i]=bcs[n-i];
  }

  for(int i=0; i<s.length; i++) {
    for(int j=i+1; j<s.length; j++) {
      if(s[i]=='R') {
        if(s[j]=='G') sum += bcs[j+1];
        if(s[j]=='B') sum += gcs[j+1];
      }
      if(s[i]=='G') {
        if(s[j]=='R') sum += bcs[j+1];
        if(s[j]=='B') sum += rcs[j+1];
      }
      if(s[i]=='B') {
        if(s[j]=='R') sum += gcs[j+1];
        if(s[j]=='G') sum += rcs[j+1];
      }
    }
  }

  for(int span=1; span<n; span++) {
    for(int i=0; i+span*2<n; i++) {
      if(s[i]!=s[i+span] &&
         s[i+span]!=s[i+span*2] &&
         s[i]!=s[i+span*2]) sum--;
    }
  }
  writeln(sum);
}



Measured memory_bytes: 2732
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint mo=1000000007;
lint zyo[1001001],rz[1001001],tz[1001001];
lint dp[1001001][2];
lint co(int a,int b){
	if(a<0 || b<0 || a<b) return 0;
	return (zyo[a]*rz[b])%mo*rz[a-b]%mo;
}
int main()
{
	int n;cin>>n;
	zyo[0]=1;rep(i,1000100) zyo[i+1]=(zyo[i]*(i+1))%mo;
	rep(i,1000100) rz[i]=invMod(zyo[i],mo);
	tz[0]=1;rep(i,1000100) tz[i+1]=(tz[i]*3)%mo;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	rep(i,1000100){
		dp[i][0]%=mo;dp[i][1]%=mo;
		dp[i+1][0]+=dp[i][1];
		dp[i+1][1]+=dp[i][0]*2+dp[i][1];
	}
	lint out=0;
	REP(i,1,n+1){
		lint t=dp[i][2];t*=invMod(2,mo);t%=mo;
		//cout<<t<<endl;
		t*=co(n,n-i);t%=mo;
		//cout<<i<<' '<<t<<endl;
		t*=invMod(tz[n],mo);t%=mo;
		t*=i;t%=mo;
		t*=invMod(n,mo);t%=mo;
		t*=invMod(i,mo);t%=mo;
		t*=invMod(i,mo);t%=mo;
		out+=t;out%=mo;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 39296
n = int(input())

a = list(map(int, input().split()))
ngcounter = 0
a.sort()
for i in range(n-1):
  if a[i] == a[i+1]:
    ngcounter += 1
    break
  
if ngcounter > 0:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 26804
N = int(input())
S = []
for _ in range(N):
  s = input()
  S.append(s)
kekka = [0,0,0,0]
for s in S:
  if s=='AC':
    kekka[0] += 1
  if s=='WA':
    kekka[1] += 1
  if s=='TLE':
    kekka[2] += 1
  if s=='RE':
    kekka[3] += 1
judge = ['AC','WA','TLE','RE']
for i in range(4):
  print(judge[i],'x',kekka[i])

Measured memory_bytes: 16288
#include<iostream>
#include<vector>
#include<complex>
#include<algorithm>
#include<map>
using namespace std;
#define EPS (1e-9)
typedef complex < double > P; // P:点
struct C{ //C:円
  P p; double r;
  C():p(0),r(0){}
  C(const P& p, double r):p(p),r(r){};
};
bool interectCC(const C& c,const C& d){
  return (norm(c.p - d.p) - (c.r + d.r)*(c.r + d.r) < EPS) &&
    (norm(c.p - d.p) - (c.r - d.r)*(c.r - d.r) > -EPS);
}
pair< P , P > crosspointCC(const C& c,const C& q){
  P a = conj(q.p - c.p);
  P b = q.r  * q.r - c.r * c.r - (q.p - c.p) * a;
  P C = c.r * c.r * (q.p - c.p);
  P d = b * b - 4.0 * a * C;
  P z1 = (-b * sqrt(d)) / (2.0 * a) + c.p;
  P z2 = (-b - sqrt(d)) / (2.0 * a) + c.p;
  return pair< P , P >( z1, z2);
}
int main(){
  int n;
  while(cin >> n , n){
    vector < P > pts(n);
    int ans = 1;
    for(int i = 0 ; i < n ; i++ ){
    cin >> pts[i].real() >> pts[i].imag();
    }
    for(int i = 0 ; i < n ; i++ ){
      C c1 = C( pts[i], 1);
      for(int j = 0 ; j < i ; j++ ){
        C c2 = C( pts[j], 1);
        if(interectCC(c1,c2)){
          pair< P , P > nnr = crosspointCC( c1, c2);
          int ret = 0, rec = 0;
          for(int k = 0 ; k < n ; k++ ){
            if(abs(nnr.first - pts[k]) <= 1 + EPS) ret++;
            if(abs(nnr.second - pts[k]) <= 1 + EPS) rec++;
          }
          ans = max( ans, max( ret, rec));
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1272
//Author:Barry Wang
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
#define X first
#define Y second
/*---define types---*/
typedef long long ll;
typedef list<int> li;
typedef queue<int> qi;
typedef deque<int> dqi;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef unsigned int uint;
/*---define variables---*/
const int inf=(1<<29);
int n;
vi E[100005];
int dis[100005],all[100005],mid;
dqi m;
bool f;
/*---define function---*/

void DFS(int x,const int& pre)
{
	m.push_back(x);
	all[x]=1;
	if(x==n)
	{
		mid=m[(m.size()+1)/2] ;
	}
	EACH(E[x],it)
	{
		int y=*it;
		if(y!=pre)
		{
			dis[y]=dis[x]+1;
			DFS(y,x);
			all[x]+=all[y];
		}
	}
	m.pop_back();
}

/*---main code---*/
int main()
{
	FIO;
	cin>>n;
	for(int i=1;i<n;++i)
	{
		int x,y;
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	DFS(1,-1);
	int snuke=all[mid];
	bool fewin=snuke*2<n;
	string ans=fewin?"Fennec":"Snuke";
	puts(ans.c_str());
	return 0;
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N;
  cin >> N;
  vector<pair<string, pair<int, int>>> vec(N);
  rep(i, N) {
    cin >> vec.at(i).first >> vec.at(i).second.first;
    vec.at(i).second.second = i + 1;
    vec.at(i).second.first *= -1;
  }
  sort(vec.begin(), vec.end());
  rep(i, N) {
    cout << vec.at(i).second.second << endl;
  }
}

Measured memory_bytes: 3604
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printmultiplerow(a):
    for i in a:
        print(i)
def printrow(a):
    for i in range(len(a)-1):
        print(a[i],end = " ")
    print(a[-1])


a,b = ips()
if max(a,b) > 9:
    print(-1)
else:
    print(a*b)
    


Measured memory_bytes: 5344
N=int(input())
H=list(map(int,input().split()))
c=0
d=H[0]

for i in range(N):
	if d<=H[i]:
		d=H[i]
	else:
		if d-H[i]>=2:
			c=c+1
if c>=1:
	print('No')
else:
	print('Yes')

Measured memory_bytes: 14396
var a,b,k,i,j,h:integer; s,t:array[1..100] of integer;
begin
  read(a,b,k);
  j:=1;
  for i:=1 to 100 do 
    if a mod i =0 then begin s[j]:=i; j:=j+1 end;
  h:=1;
  for i:=1 to j-1 do 
    if b mod s[i] =0 then begin t[h]:=s[i]; h:=h+1 end;
  write(t[h-k])
end.


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool ans = false;
    for(int i=1; i<=101; i++){
        if(a * i % b == c) ans = true;
    }
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int dp[1001][1001];
const int mod = 1e9 + 7;
char A[1001][1001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H, W;
	scanf("%d", &H);
	scanf("%d", &W);
	rep(i, H) scanf("%s", A[i]);

	dp[0][0] = 1;
	rep(i, H + W - 2) {
		for (int h = max(0, i - W + 1); h < min(H, i + 1); h++) {
			int w = i - h;
			if (A[h + 1][w] == '.') dp[h + 1][w] = (dp[h + 1][w] + dp[h][w]) % mod;
			if (A[h][w + 1] == '.') dp[h][w + 1] = (dp[h][w + 1] + dp[h][w]) % mod;
		}
	}
	printf("%d", dp[H - 1][W - 1]);

	Would you please return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
long long n,dp[2005]={0,0,0,1,1,1};
const long long mod=1000000007;
int main()
{
	scanf("%d",&n);
	for(int i=6;i<=n;i++)
	{
		for(int j=0;j<=i-3;j++)
		{
			dp[i]=(dp[i]+dp[j])%mod;
		}
		dp[i]+=1;
		dp[i]%=mod;
	}
	printf("%lld\n",dp[n]);
 	return 0;
}


Measured memory_bytes: 3820
// 補助関数
template<typename T> T modpow(T x, T p, T M) {
  if(!p) return 1;
  if(p & 1) return (x * modpow(x, p - 1, M)) % M;
  return modpow((x * x) % M, p >> 1, M);
}
// 剰余類
template<typename T, T M = T(1e9 + 7)>
struct ModInt {
  T number;
  ModInt(T n = 0) : number(n % M) {while(number < 0) number += M;}
  // 代入演算
  ModInt& operator+=(const ModInt& m) {return *this = *this + m;}
  ModInt& operator-=(const ModInt& m) {return *this = *this - m;}
  ModInt& operator*=(const ModInt& m) {return *this = *this * m;}
  ModInt& operator/=(const ModInt& m) {return *this = *this / m;}
  ModInt& operator%=(const ModInt& m) {return *this = *this % m;}
  // 二項演算
  friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return lhs.number + rhs.number;}
  friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return lhs.number - rhs.number;}
  friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return lhs.number * rhs.number;}
  friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return lhs.number * modpow(rhs.number, M - 2, M);}
  friend const ModInt operator%(const ModInt& lhs, const ModInt& rhs) {return lhs.number % rhs.number;}
  // 関係演算
  friend bool operator==(const ModInt& lhs, const ModInt& rhs) {return lhs.number == rhs.number;}
  friend bool operator!=(const ModInt& lhs, const ModInt& rhs) {return lhs.number != rhs.number;}
  friend bool operator<=(const ModInt& lhs, const ModInt& rhs) {return lhs.number <= rhs.number;}
  friend bool operator>=(const ModInt& lhs, const ModInt& rhs) {return lhs.number >= rhs.number;}
  friend bool operator<(const ModInt& lhs, const ModInt& rhs) {return lhs.number < rhs.number;}
  friend bool operator>(const ModInt& lhs, const ModInt& rhs) {return lhs.number > rhs.number;}
};
// 入出力ストリーム
#include<iostream>
template<typename T, T M> inline std::istream& operator>>(std::istream& is, ModInt<T, M>& m) {return is >> m.number;}
template<typename T, T M> inline std::ostream& operator<<(std::ostream& os, const ModInt<T, M>& m) {return os << m.number;}

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

using I = ModInt<long long>;
const int C = 3;

int N;
string S1, S2;

using Memo=tuple<int,int,int>;
map<Memo, I> memo;
I dfs(int i, int u, int d) {
  if(i==N) return 1;
  auto m=Memo(i,u,d);
  if(memo.count(m)) return memo[m];
  I res;
  if(S1[i]==S2[i]) {
    set<int> ng;
    ng.emplace(u);
    ng.emplace(d);
    for(auto c=0; c<C; ++c) if(!ng.count(c)) res += dfs(i+1, c, c);
  } else {
    if(S1[i-1]==S1[i]) res += dfs(i+1, u, d);
    else
      for(auto u2=0; u2<C; ++u2) if(u2!=u)
        for(auto d2=0; d2<C; ++d2) if(d2!=d)
          if(u2!=d2) res += dfs(i+1, u2, d2);
  }
  return memo[m] = res;
}

int main() {
  cin >> N;
  cin >> S1 >> S2;
  I res;
  if(S1[0]==S2[0]) {
    for(auto c=0; c<C; ++c) res += dfs(1, c, c);
  } else {
    for(auto d=0; d<C; ++d) for(auto u=0; u<d; ++u) res += dfs(1, u, d) + dfs(1, d, u);
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
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; }

const int MOD=1000000007;
int INF=100100100100100;
int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}

int beki(int a,int b)
{
	if(b==0)return 1;
	int x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

int inv(int a)
{
	return beki(a,MOD-2);
}

int kaijou(int a)
{
	int ans=1;
	for(int i=1;i<=a;i++)
	{
		ans=(ans*i)%MOD;
	}			
	return ans;
}

/*int combi(int a,int b)
{
	int ret=1;
	for(int i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}*/
/*
const int MAX_a=200010;
int cb[MAX_a+1]
void combi(int a,int b)
{
    int ret=1;
    cb[0]=1;
    for(int i=1;i<=b;i++)
    {
	ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
        cb[i]=ret;
    }
	
}*/

vector<P> prime_factorize(int N)
{
	vector<P> res;
	for(int a=2;a*a<=N;a++)
	{
		if(N%a!=0)continue;
		int ex=0;
		while(N%a==0)
		{
			ex++;N/=a;
		}
		res.push_back(P(a,ex));
	}
	if(N!=1)res.push_back(P(N,1));
	return res;
}

//ここから書く
signed main(){
  int n;cin>>n;
  string s;cin>>s;
  int ans=0,cnt=0;
  for(int i=1;i<n;i++){
    if(s[i]=='E')cnt++;
  }
  ans=cnt;
  for(int i=1;i<n;i++){
    if(s[i-1]=='W')cnt++;
    if(s[i]=='E')cnt--;
    chmin(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3788
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>

using namespace std;

class DSumOfDivisors {
public:
    long long sum(int x) {
        return 1LL * x * (x + 1) / 2;
    }
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        long long ans = 0;
        for (int i = 1; i <= n; ++i) {
            ans += 1LL * i * sum(n / i);
        }
        out << ans << '\n';
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    DSumOfDivisors solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 3660
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] array = sc.next().toCharArray();
        int max = 0;

        for(int i=0; i<array.length; i++){
            Map<String, Integer> left = new HashMap<>();
            Map<String, Integer> right = new HashMap<>();
            Map<String, Integer> ans = new HashMap<>();
            for(int j=0; j<array.length; j++){
                String s = String.valueOf(array[j]);
                if(j<=i){
                    if(left.containsKey(s)){
                        left.put(s, left.get(s) + 1);
                    } else {
                        left.put(s, 1);
                    }
                } else {
                    if(right.containsKey(s)){
                        right.put(s, right.get(s) + 1);
                    } else {
                        right.put(s, 1);
                    }
                }
            }

            for(String strLeft: left.keySet()){
                for(String strRight: right.keySet()){
                    if(strLeft.equals(strRight)){
                        if(ans.containsKey(strLeft)){
                            ans.put(strLeft, ans.get(strLeft)+1);
                        } else {
                            ans.put(strLeft, 1);
                        }
                    }
                }
            }

            if(max < ans.keySet().size()){
                max = ans.keySet().size();
            }
        }

        System.out.println(max);
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }

    public static int gcd(int a, int b){
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static int lcm(int a, int b){
        return a * b / gcd(a, b);
    }
}


Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main(){
    int n;
    int x;
    
    cin >> n;
    
    int array[n];
    
    for (int i = 1; i <= n; i ++) {
        
        cin >> x;
        
        array[n-i] = x;
        
    }
    
    for (int i = 0; i < n; i ++) {
        
        if (i == n-1) {
            
            cout << array[i] << endl;
        
        } else {
            
            cout << array[i] << ' ';
            
        }
        
    }
    
    return 0;
    
}



Measured memory_bytes: 3080
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n;
    cin >> n;
    int a[n];

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

    int sum = 0;
    while(1){
        for (int i = 0; i < n; i++){
            if (a[i] % 2 != 0){
                cout << sum << endl;
                exit(0);
            }
            else {
                a[i] /= 2;
            }
        }
        sum++;
    }
}


Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
map<int,bool> m;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int x,n;
	cin>>x>>n;
	for(int i=1;i<=n;i++){
		int G;
		cin>>G;
		m[G]=1;
	}
	for(int i=0;i<=1000;i++){
		if(!m[x-i]){
			cout<<x-i;
			return 0;
		}
		if(!m[x+i]){
			cout<<x+i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

#define LL long long

const int MAXN = 500000 + 5;

LL a[3002][3002];

LL dp[3002][3002][4];

int main()
{
    int R, C, K, r, c, v;
    cin >> R >> C >> K;
    for (int i = 0; i < K; i ++){
        cin >> r >> c;
        cin >> a[r][c];
    }
    for (int i = 1; i <= R ; i ++){
        for (int j = 1; j <= C; j ++){
            LL cnt = 0;
            for (int k = 0; k <= 3; k ++){
                cnt = max(cnt, dp[i - 1][j][k]);
            }
            dp[i][j][0] = max(cnt, dp[i][j - 1][0]);
            for (int k = 1; k <= 3; k ++){
                dp[i][j][k] = max(cnt + a[i][j], max(dp[i][j - 1][k], dp[i][j - 1][k - 1] + a[i][j]));
            }
        }
    }
    LL cnt = 0;
    for (int k = 0; k <= 3; k ++){
        cnt = max(cnt, dp[R][C][k]);
    }
    cout << cnt;
    system("pause");
    return 0;
}

Measured memory_bytes: 355332