akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

int main() {
    int q;
    cin >> q;
    for (int i=0; i<q; i++) {
        long a, b;
        cin >> a >> b;
        long r   = (long)sqrt(a * b),
             ans = r * 2;
        if (a != b) ans--;
        if (a * b <= r * r) ans--;
        if (a * b <= r * (r+1)) ans--;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,x,min,i,w;
	scanf("%d %d %d",&a,&b,&c);
	min=2147483640;
	for(i=1;i*i<=a*b;i++){
		if((a*b)%(i*i)==0&&a%i==0&&b%i==0){
			x=(a*b/(i*i))*c;
			if(min>x) min=x;
		}	
	}
	printf("%d\n",min);
	return 0;
}

Measured memory_bytes: 2732
import java.util.Scanner;
class Main{
    public static void main (String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int count=0;
        for(int i=1;i<10;i++)
        {
            for(int j=1;j<10;j++){
                if(i*j==a){
                    count=1;
                }
                
            }
        }
        if(count==1){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        
    }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200005
#define LOG         20
#define mod         1000000007
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w,i,j,ans=0,total_value=0;
    cin>>n>>w;
    ll weight[n],value[n];
    for(i=0;i<n;i++){
        cin>>weight[i]>>value[i];
        total_value+=value[i];
    }
    ll dp[n+1][total_value+1];
    for(i=0;i<=n;i++){
        for(j=0;j<=total_value;j++){
            dp[i][j]=MAX;
        }
    }
    dp[0][0]=0;
    for(i=1;i<=n;i++){
        for(j=0;j<=total_value;j++){
            if(j>=value[i-1]){
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-value[i-1]]+weight[i-1]);
            } 
            else{
                dp[i][j]=dp[i-1][j];
            }
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    for(j=0;j<=total_value;j++){
        if(dp[n][j]<=w){
            ans=max(ans,j); 
        }
    }
    cout<<ans;
}

Measured memory_bytes: 79232
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>

using namespace std;

int P[100000];
int S[100000];

int U[100000];
int V[100000];

long long curr;
long long ans[100000];

int find(int u) {
    if (P[u] == u) return u;
    return P[u] = find(P[u]);
}

void unite(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return;
    curr -= (long long)S[u] * S[v];
    S[u] += S[v];
    P[v] = u;
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        P[i] = i;
        S[i] = 1;
    }
    curr = (long long)n * (n - 1) / 2;
    for (int i = 0; i < m; i++) {
        cin >> U[i] >> V[i];
        U[i]--;
        V[i]--;
    }
    for (int i = m - 1; i >= 0; i--) {
        ans[i] = curr;
        unite(U[i], V[i]);
    }
    for (int i = 0; i < m; i++) {
        cout << ans[i] << '\n';
    }
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i=i+2){
        string palabra = s.substr(i,2);
        if(palabra != "hi"){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main() {
    string s;
    cin>>s;
    if(s=="AAA"||s=="BBB"){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int ncr(int n,int r)
{
	static int memo[2001][2001];
	int& res=memo[n][r];
	if(res==0){
		if(r==0||r==n)
			res=1;
		else
			res=(ncr(n-1,r-1)+ncr(n-1,r))%MOD;
	}
	return res;
}

int ncrsum(int n,int r)
{
	static int memo[2001][2001];
	int& res=memo[n][r];
	if(res==0){
		if(r>0)
			res=ncrsum(n,r-1);
		(res+=ncr(n,r))%=MOD;
	}
	return res;
}

int calc(int p,int q,vvi& memo)
{
	int& res=memo[p][q];
	if(res==-1){
		if(p==0||q==0)
			res=1;
		else
			res=(calc(p-1,q,memo)+ncrsum(q-1,min(p,q-1)))%MOD;
	}
	return res;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int a,b;cin>>a>>b&&a|b;){
		ll res=0;
		vvi memo(a+1,vi(b+1,-1));
		for(int t=0;t<=a;t++){
			for(int p=0;p<=t;p++){
				int q=t-p;
				if(b<=q) continue;
				assert(0<=p&&p<=a&&0<=q&&q<b);
				(res+=(ll)ncr(b-1,t-p)*calc(p,q,memo))%=MOD;
			}
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 46464
//verma_ankit484

#include<bits/stdc++.h>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const ll mod = (ll) 1e9+7;

using namespace std;

bool chk(const pair<ll, ll> & p1, const pair<ll, ll> & p2) {
  if(p1.first == p2.first) {
    return p1.second >= p2.second;
  }
  return p1.first >= p2.first;
}

int main()
{
  IOS
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll> > vc(n);
  for(ll i = 0; i < n; i++) {
    cin >> vc[i].second >> vc[i].first;
  }
  sort(vc.begin(), vc.end(), chk);
  ll s, c;
  s = c = 0;
  set<ll> st;
  for(ll i = 0; i < n; i++) st.insert(i);
  for(ll i = 0; i < n; i++) {
    if(st.size() == 0) break;
    if(vc[i].second <= m) {
      auto it = st.lower_bound(m-vc[i].second+1);
      if(it == st.begin()) continue;
      it--;
      st.erase(it);
      s += vc[i].first;
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n) cin >> c[i];
    sort(a, a+n);
    sort(c, c+n);
    ll ans = 0;
    REP(i,n) {
        ll a_piece = lower_bound(a, a+n, b[i]) - a;
        ll c_piece = (c+n) - upper_bound(c, c+n, b[i]);
        ans += a_piece * c_piece;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,m;
int adj[20],cnt1[1<<15];
ll tab[1<<15];
ll dp[1<<15];
int main()
{
	for(int i=1;i<(1<<15);i++)cnt1[i]=cnt1[i-(i&(-i))]+1;
	getii(n,m);
	ll ans=1;
	for(int i=1;i<=m;i++)
	{
		ans=ans*2%mod;
		int x,y;
		getii(x,y);x--;y--;
		adj[x]|=1<<y;
	}
	dp[0]=1;
	for(int i=1;i<(1<<n);i++)
	{
		if((i&3)!=0&&(i&3)!=3)continue;
		int msk=i;
		while(true)
		{
			int tmsk=i&(~msk);
			if(dp[tmsk])
			{
				ll coef=1;
				for(int j=0;j<n&&coef;j++)
				{
					if((tmsk>>j)&1)
					{
						coef=coef*((1ll<<cnt1[adj[j]&msk])-1)%mod;
					}
					else if(!((i>>j)&1))
					{
						coef=coef*(1ll<<cnt1[adj[j]&msk])%mod;
					}
				}
				dp[i]+=coef*dp[tmsk]%mod;
			}
			if(msk==0)break;
			msk=(msk-1)&i;
		}
		dp[i]%=mod;
//		cerr<<i<<":"<<dp[i]<<endl;
	}
	cout<<(ans-dp[(1<<n)-1]+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 640
def S(a,N,M):
    m=0
    for i in range(N):
        m+=(a[i]-M)**2
    return m
    

N=int(input())
a=[int(x) for x in input().split()]

m=S(a,N,-100)

for i in range(-99,101):
    if m > S(a,N,i):
        m=S(a,N,i)
        
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  string s;cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]==s[i+1]){
      puts("Bad");return 0;
    }
  }
  
      puts("Good");return 0;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(void)
{
    int n, v[20] = {0}, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int c, d;
    for (int i = 0; i < n; i++)
    {
        cin >> c;
        d = v[i] - c;
        if (d > 0)
        {
            sum += d;
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main(){
  //入力値を受け取る
  int N,A,B,C,D;
  cin >> N;
  vector<int> vec(4);
  vec.at(0) = N / 1000; //A
  vec.at(1) = (N / 100) % 10;//B
  vec.at(2) = (N / 10 ) % 10;//C
  vec.at(3) = N % 10;//D
  string ans;
  for(int tmp = 0;tmp < (1 << 3);tmp++){
    bitset<3> b(tmp);
    ans = "";
    int sum = vec.at(0);//Aをsumに加算する
    ans = to_string(vec.at(0));
    //B~Dの値を加算または減算する
    for(int i = 1; i < 4; i++){
      //1の場合は加算、それ以外は減算
      if(b.test(i-1)){
        sum += vec.at(i);
        ans += "+" + to_string(vec.at(i));
      }else{
        sum -= vec.at(i); 
        ans += "-" + to_string(vec.at(i));
      }
    }
    if(sum == 7){
      break;
    }   
  }
  cout << ans << "=7" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define dd double
using namespace std;
const ll MOD = 1e9 + 7; 
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s;
  cin>>s;
  int i,j;
  vector<int> v;
  int count;
  for(i=0;i<s.length();i++){
  	count=0;
  	if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
  	{ 
  	  count++;
  	  for(j=i+1;j<s.length();j++){
  	  	if(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T'){
  	  		  count++;
			}
		 else{
		 	v.push_back(count);
		 	break;
		 }
		 	
		}
		 
		if(j==s.length()){
			v.push_back(count);
		} 
	    	
	  }
  }
  
  if(v.size()==0){
  	cout<<"0"<<endl;
  }
  else{
  	cout<<*max_element(v.begin(),v.end())<<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(void){
  int a=0;
  int h=0;
  int m=0;
  int s=0;
  scanf("%d\n", &a);
  while(a>=3600){
    a -=3600;
    h++;
  }
  while(a>=60){
    a -=60;
    m++;
  }

  s = a;

  printf("%d:%d:%d\n", h, m, s);
  return 0;
}



Measured memory_bytes: 2740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{int H, W; cin >> H >> W;
 vector<vector<char>> B ( H, vector<char>(W));//H*W配列
 for(int i = 0; i < H; i++){
   for(int j = 0 ; j < W; j++){
     cin >> B.at(i).at(j);}}//
 int dx[] = {1,0,-1,0};
 int dy[] = {0,1,0,-1};
 
 bool flag0 = true;
 
 for(int i = 0; i < H; i++){
   for(int j = 0; j < W; j++){
     if(B.at(i).at(j) == '#'){
      bool flag = false;
     for(int k = 0; k < 4;k++){
       int a = i + dx[k]; int b = j + dy[k];
       if(0 <= a && a <= H-1 && 0 <= b && b <= W-1 && B.at(a).at(b) == '#'){
         flag = true;}}
     if(!flag){flag0 = false;
               break;}}
  }}
 
 if(flag0){cout << "Yes" <<endl;}
 else{cout << "No" <<endl;}
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; 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(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const ll MOD = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> odd(10e5, 0);
    vector<int> even(10e5, 0);
    REP(i,n) {
        int v; cin >> v;
        if(i%2==0) even[v] ++;
        else odd[v] ++;
    }
    int ans = n;
    vector<p> oddChange;
    vector<p> evenChange;
    REPP(i,(int)10e5) {
        if(odd[i]!=0) oddChange.push_back(make_pair(odd[i],i));
        if(even[i]!=0) evenChange.push_back(make_pair(even[i],i));
    }
    sort(oddChange.begin(), oddChange.end(), greater<pair<int,int>>());
    sort(evenChange.begin(), evenChange.end(), greater<pair<int,int>>());
    if(oddChange[0].second==evenChange[0].second) {
        ans -= max(oddChange[0].first, evenChange[0].first);
        if(oddChange[0].first == evenChange[0].first) ans -= max(oddChange[1].first, evenChange[1].first);
        else if(oddChange[0].first > evenChange[0].first) ans -= evenChange[1].first;
        else ans -= oddChange[1].first;
    }
    else ans -= oddChange[0].first + evenChange[0].first;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9084
/* ex2_3
   pandacodeb */

#include <stdio.h>

int main(void){
  int N, white, black;
  scanf("%d %d", &N, &white);	//input square size and white squares
  black = N*N - white;			//calculate number of black squares
  printf("%d\n", black);		//output
  return 0;
}

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

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

            var list = new List<string>();

            var flag = 0;
            char tail = ',';

            for (var x=0; x<N; ++x)
            {
                var str = Console.ReadLine();

                if (list.Contains(str))
                {
                    flag = 1;
                }

                if(x > 0 && str[0] != tail)
                {
                    flag = 1;
                }

                list.Add(str);
                tail = str[str.Length - 1];
            }

            if (flag == 1)
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 11104
N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[len(str(N)) - 1])
ans = 0
#print(str(100)[len(str(100)) - 1])
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[len(str(i)) - 1])
  # 一桁
  if lead == end:
    ans += 1
  #2桁以上ループ lead + 中間 + end　
  for j in range((len(str(N)) - 2) + 1):
    if end == 0:
      #末尾が0
      continue
    elif end > lead_N and j == (len(str(N)) - 2) :
      #生成する整数がNに収まらない場合
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      #生成する整数の一部がNに収まらない場合
      #中間の数字
      if len(str(N)) >= 3:
        ans += int(str(N)[1:len(str(N)) - 1])

      if lead <= end_N:
        ans += 1
      #print("b")
      pass
    else:
      #何も気にしないときは組み合わせの分だけたす
      ans += 10 ** j

print(ans)

Measured memory_bytes: 3064
<?php

//文字列の入力
fscanf(STDIN,"%s",$weather);

//条件分岐
if ($weather == 'Sunny'){
    echo 'Cloudy';
}elseif ($weather == 'Cloudy'){
    echo 'Rainy';
}elseif ($weather == 'Rainy'){
    echo 'Sunny';
}

Measured memory_bytes: 3576
import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                sys.exit()
        t += 1

main()

Measured memory_bytes: 2940
from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += c * (c-1) // 2
print(t)

Measured memory_bytes: 62040
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

char s[52][52], d[52][52];
int H, W;

int main() {
	int a = 700;
	char s[3];
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
		if (s[i] == 'o')a += 100;
	}
	cout << a;


}

Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))
dist=0
ans=10**9
for i in range(n-k+1):
    l=x[i]
    r=x[i+k-1]
    dist=r-l
    ans=min(ans,dist+min(abs(l),abs(r)))
print(ans)

Measured memory_bytes: 14252
def appearance_frequency(seq)
	h = Hash.new(0)
	seq.each {|i| h[i] += 1}
	return seq.map{|i| h[i]}
end

loop do
	n = $<.gets.to_i
	break if n.zero?

	seq = $<.gets.split.map(&:to_i)
	count = 0
	loop do
		s = appearance_frequency(seq)
		if s == seq
			p count
			puts s.join(' ')
			break
		end

		seq = s
		count += 1
	end
end

Measured memory_bytes: 6148
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9;

int A,B,C,K;
int main(){
    cin>>A>>B>>C>>K;
    int ans = A+B+C;
    int tmp = max({A,B,C});
    REP(i,0,K){
        tmp = tmp*2;
    }
    p(ans+tmp-max({A,B,C}));

}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  int ans = 0;
  int t = n / 500;
  ans += 1000 * t;
  n = n % 500;
  int tmp = n / 5;
  ans += 5 * tmp;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, a, b;
vector<int>v[100000];
bool vis[100000];

int dfs(int x) {
	vis[x] = true;
	int cnt0, cnt1;
	cnt0 = cnt1 = 0;
	for (int i : v[x]) {
		if (!vis[i]) {
			int t = dfs(i);
			if (t == 0xE869120)return 0xE869120;
			if (t) {
				++cnt1;
			}
			else {
				++cnt0;
			}
		}
	}
	if (cnt1 >= 2) {
		return 0xE869120;
	}
	else if (cnt1 == 1) {
		return 0;
	}
	else {
		return 1;
	}
}

int main() {
	cin >> N;
	for (int i = 1; i < N; ++i) {
		cin >> a >> b;
		--a;
		--b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int t = dfs(0);
	if (t == 0xE869120 || (t == 1 && N % 2 == 1)) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H + 2, vector<char> (W + 2));
    for (int i = 0; i < W + 2; i++){
        S[0][i] = '.';
    }
    for (int i = 0; i < H; i++){
        S[i][0] = '.';
        for (int j = 1; j < W + 1; j++){
            cin >> S[i][j];
        }
        S[i][W + 1] = '.';
    }
    for (int i = 0; i < W + 2; i++){
        S[H + 1][i] = '.';
    }
    vector<int> dx = {-1, 0, 1, 0};
    vector<int> dy = {0, -1, 0, 1};
    bool flag = true;
    for (int i = 1; i < H + 1; i++){
        for (int j = 1; j < W + 1; j++){
            if (S[i][j] == '#') {
                for (int k = 0; k < 4; k++){
                    if (S[i + dx[k]][j + dy[k]] == '#') {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    cout << "No" << endl;
                    return 0;
                }
                else{
                        flag = true;
                    }
            }
        }
    }
    cout << "Yes" << endl;
}


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

#define ll long long

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans;
    ans = max(a*c, b*d);
    ans = max(ans, b*c);
    ans = max(ans, a*d);

    cout << ans << endl;

    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        string s1 = Console.ReadLine();
        int n = int.Parse(s1);
        char suit;
        int number;
        char[] suit2 = new char[4] { 'S', 'H', 'C', 'D' };
        bool[,] cards = new bool[4, 13];
        for (int i = 0; i < n; i++)
        {
            string[] s2 = Console.ReadLine().Split(' ');
            suit = char.Parse(s2[0]);
            number = int.Parse(s2[1]);
            switch (suit)
            {
                case 'S':
                    cards[0, number - 1] = true;
                    break;
                case 'H':
                    cards[1, number - 1] = true;
                    break;
                case 'C':
                    cards[2, number - 1] = true;
                    break;
                case 'D':
                    cards[3, number - 1] = true;
                    break;
            }
        }

        for (int j = 0; j < 4; j++)
        {
            for (int k = 0; k < 13; k++)
            {
                if (cards[j, k] == false)
                {
                    Console.WriteLine(suit2[j] + " " + (k + 1));
                }
            }
        }
    }
    
}

Measured memory_bytes: 9196
import numpy as np
import math

if __name__ == "__main__":
  _a, _b = map(str,input().split())
  a_int, b_int = int(_a), int(_b)

  a_b = _a*b_int
  b_a = _b*a_int
  if a_b <= b_a:
    print(a_b)
  else:
    print(b_a)


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

int main(void) {
    int a, b;
    char op;
    
    while(true) {
        cin >> a >> op >> b;
        if(op == '?') break;
        switch(op) {
            case '+' : cout << a + b << endl;   break;
            case '-' : cout << a - b << endl;   break;
            case '*' : cout << a * b << endl;   break;
            case '/' : cout << a / b << endl;   break;
        }
    }
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define out(a) cout<<a<<endl;

struct node {
	forward_list<node*> c;
	ll count = 0;
    ll sum = 0;
};

void addNum(node* c ){
	c->sum += c->count;
    for(const auto& no : c->c){
        no->sum = c->sum;
        addNum(no);
    }
}

int main()
{
	in(n);
	in(q);
	vector<node*> nodes(n);
	rep(i, n) {
		nodes[i] = new node();
	}
	rep(i, n - 1) {
		int a;
		int b;
		cin >> a; cin >> b;
		nodes[a - 1]->c.push_front(nodes[b - 1]);
	}
	rep(i, q) {
		int p;
		int x;
		cin >> p; cin >> x;
        nodes[p - 1]->count += x;
	}
    addNum(nodes[0]);
	rep(i, n) {
        out(nodes[i]->sum);
	}
}

Measured memory_bytes: 22656
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
 
if max(x)<min(y) and X<Y:
  if len(set(range(max(x)+1,min(y)+1))&set(range(X+1,Y+1)))>=1:
  	print('No War')
  else:
    print('War')
else:
  print('War')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
    int a,b,flag=0;
    cin >> a >> b;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='-'){
            if(i==a){
                flag++;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }
    }
    if(s.size() == a+b+1){
        flag+=1;
    }
    if(flag==2){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}

#define REP(i,s,n) for(int i=s; i!=n; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1'000'000'000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

double dp[300][300][300];

double ex(int s0, int s1, int s2, int s3) {
    int M = s0+s1+s2+s3;
    if (s0 == M) return 0.0;
    if (dp[s1][s2][s3] > 0.0) {
        return dp[s1][s2][s3];
    }
    
    double e = 0.0;
    if (s3 > 0) {
        e += ex(s0, s1, s2+1, s3-1)*s3/M;
    }
    if (s2 > 0) {
        e += ex(s0, s1+1, s2-1, s3)*s2/M;
    }
    if (s1 > 0) {
        e += ex(s0+1, s1-1, s2, s3)*s1/M;
    }
    dp[s1][s2][s3] = (e+1) / (s1+s2+s3) * M;
    
    return dp[s1][s2][s3];
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> cnt(4);
    REP(i, 0, N) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    cout << setprecision(10) << ex(0, cnt[1], cnt[2], cnt[3]) << endl;
    
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/11  Problem: ABC 088 B / Link: http://abc088.contest.atcoder.jp/tasks/abc088_b  ----- */


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

	LL N; 
	cin >> N;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	LL ans = 0LL;
	RSORT(a);
	FOR(i, 0, N) {
		if (i%2==0)ans += a[i];
		else ans -= a[i];
	}
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
class Dijkstra():
    """ ダイクストラ法
    重み付きグラフにおける単一始点最短路アルゴリズム

    * 使用条件
        - 負のコストがないこと
        - 有向グラフ、無向グラフともにOK
    
    * 計算量はO(E*log(V))

    * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
    """
    class Edge():
        """ 重み付き有向辺 """
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        """ 重み付き有向辺
        無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい

        Args:
            V(int): 頂点の数
        """
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数

    @property
    def E(self):
        """ 辺数
        無向グラフのときは、辺数は有向グラフの倍になる
        """
        return self._E
    
    @property
    def V(self):
        """ 頂点数 """
        return self._V
    
    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加する """
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1
        
    def shortest_path(self, s):
        """ 始点sから頂点iまでの最短路を格納したリストを返す 
        Args:
            s(int): 始点s
        Returns:
            d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。
                     到達不可の場合、値はfloat("inf")
        """
        import heapq
        que = []  # プライオリティキュー（ヒープ木）
        d = [float("inf")] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))  # 始点の(最短距離, 頂点番号)をヒープに追加する

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
                e = self.G[v][i]  # vのi個目の隣接辺e
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost  # dの更新
                    heapq.heappush(que, (d[e.to], e.to))  # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
        return d

n = int(input())
djk = Dijkstra(n)
for i in range(n - 1):
    a, b, c = map(int, input().split())
    djk.add(a-1, b - 1, c)
    djk.add(b - 1, a - 1, c)

q, k = map(int, input().split())
d = djk.shortest_path(k-1)

for i in range(q):
    x, y = map(int, input().split())
    print(d[x-1] + d[y-1])

Measured memory_bytes: 105888
using System;
using System.Linq;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            int nums = int.Parse(Console.ReadLine());
            string[] item = new string[nums];

            for(var i = 0; i < nums; i++) {
                item[i] = Console.ReadLine();
            }

            Console.Write(item.Distinct().Count());
        }
    }
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<llP> point(n);
  rep(i, n) cin >> point[i].first >> point[i].second;
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }
  sort(ALL(point));

  vector<ll> p, q;

  rep(i, n) rep(j, n) {
    if(i == j) continue;
    p.push_back(point[i].first - point[j].first);
    q.push_back(point[i].second - point[j].second);
  }

  int m = p.size();
  int ans = INF;
  rep(k, m) {
    int tmp = n;
    rep(i, n) {
      if(binary_search(ALL(point), make_pair(point[i].first-p[k], point[i].second-q[k]))) --tmp;
    }
    chmin(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int ,int> pi;
typedef pair<ll ,ll> pl;
typedef map<ll ,ll> ml;
#define modulo 1000000007
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N=1e7+1;
int arr[N];

void solve()
{
    for(int i=1;i<N;i++)
        for(int j=0;(j+=i)<N;)arr[j]++;
    ll n,d;
    cin >> n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans+=i*arr[i];
    }
    cout <<  ans << endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fast;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 42692
n=int(input())
A=list(map(int,input().split()))

D={}
for i in A:
    if i in D:
        D[i]+=1
    else:
        D[i]=1
T=0
for i in D:
    T+=D[i]*(D[i]-1)//2

for i in range(n):
    print(T-(D[A[i]]-1))
    

Measured memory_bytes: 86604
def main():
    N, Q = map(int, input().split())
    s = input()
    l = []
    for _ in range(Q):
        t, d = input().split()
        l.append((t, d))
    lmax = N + 1
    lmin = 0
    rmax = N + 1
    rmin = 0
    # find most left R
    t = N
    for i in range(Q):
        if s[t-1] == l[i][0]:
            if l[i][1] == 'L':
                t -= 1
            else:
                t += 1
        if t == N+1:
            break
        if t == 0:
            print('0')
            return 0
    else:
        rmin = N + 1
    while rmax != rmin:
        m = t = (rmax + rmin) // 2
        for i in range(Q):
            if s[t-1] == l[i][0]:
                if l[i][1] == 'L':
                    t -= 1
                else:
                    t += 1
            if t == N+1:
                rmax = m
                break
            if t == 0:
                rmin = m + 1
                break
        else:
            rmin = m + 1
    t = 1
    for i in range(Q):
        if s[t-1] == l[i][0]:
            if l[i][1] == 'L':
                t -= 1
            else:
                t += 1
        if t == 0:
            break
        if t == N + 1:
            print('0')
            return 0
    else:
        lmax = 0
 
    # find most right L
    while lmax != lmin:
        m = t = (lmax + lmin + 1) // 2
        for i in range(Q):
            if s[t-1] == l[i][0]:
                if l[i][1] == 'L':
                    t -= 1
                else:
                    t += 1
            if t == 0:
                lmin = m
                break
            if t == N + 1:
                lmax = m - 1
                break
        else:
            lmax = m - 1
    print(rmax-lmax-1)
main()


Measured memory_bytes: 90628
N = int(input())
S = input().strip()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag = 0
            for n in range(N):
                if flag==0 and S[n]==str(i):
                    flag = 1
                elif flag==1 and S[n]==str(j):
                    flag = 2
                elif flag==2 and S[n]==str(k):
                    flag = 3
                    break
            if flag==3:
                cnt += 1
print(cnt)

Measured memory_bytes: 45532
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int hantei(int x) {
  int ret_val=0;
  if      (x< 400) ret_val=1;
  else if (x< 800) ret_val=2;
  else if (x<1200) ret_val=3;
  else if (x<1600) ret_val=4;
  else if (x<2000) ret_val=5;
  else if (x<2400) ret_val=6;
  else if (x<2800) ret_val=7;
  else if (x<3200) ret_val=8;
  return ret_val;
}

int main(){
  int N; cin >>N;
  vector<int> check(9);
  rep(i,0,N) {
    int a; cin >>a;
    check[hantei(a)]++;
  }
  int min_val=0,max_val=0;
  rep(i,0,9) {
    if (check[i]) min_val++;
  }
  if (check[0]==0) max_val=min_val;
  else if (min_val==1) max_val=check[0];
  else {
    min_val--;
    max_val=min_val+check[0];
  }
  cout <<min_val <<' ' <<max_val <<endl;
  return 0;
}


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

static class Program
{
    static long Solve(int N, string S)
    {
        if (S[0] == 'W') { return 0; }
        const int M = 1000000007;
        long ans = 1;
        int cnt = 0;
        foreach (char c in S)
        {
            switch (c)
            {
            case 'B':
                if (cnt % 2 == 0)
                {
                    ++cnt;
                }
                else
                {
                    ans *= cnt;
                    ans %= M;
                    --cnt;
                }
                break;
            case 'W':
                if (cnt % 2 == 0)
                {
                    ans *= cnt;
                    ans %= M;
                    --cnt;
                }
                else
                {
                    ++cnt;
                }
                break;
            }
        }
        if (cnt == 0)
        {
            for (int i = N; i > 1; --i)
            {
                ans *= i;
                ans %= M;
            }
            return ans;
        }
        else
        {
            return 0;
        }
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var S = Console.ReadLine();
        Console.WriteLine(Solve(N, S));
    }
}


Measured memory_bytes: 13240
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 500 + 5;
int n, m, d;
int a[kN][kN];

int main()
{
    scanf("%d%d%d", &n, &m, &d);
    int mod = d + d;
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < m; ++ j) {
            int x = (i + j) % mod;
            int y = ((i - j) % mod + mod) % mod;
            putchar("RGBY"[(x < d) * 2 + (y < d)]);
        }
        puts("");
    }

}

Measured memory_bytes: 384
N = int(input())
S = input()
e,w= [0]*N,[0]*N
for i in range(N-1):      e[i+1] = e[i] + (1 if S[i]=='W' else 0)
for i in range(N-1,0,-1): w[i-1] = w[i] + (1 if S[i]=='E' else 0)
print(min([w[i]+e[i] for i in range(N)]))


Measured memory_bytes: 39160
#include <stdio.h>
#include <math.h>


double eps = 1e-10 ;
int main()
{
  double x1, x2, x3, y1, y2, y3, xp, yp;
  double s, s1, s2, s3;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp) != EOF){
    //?????§????¢??????¢???
    s  = ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2; 
    s1 = ((xp - x1) * (y2 - y1) - (yp - y1) * (x2 - x1)) / 2;
    s2 = ((xp - x1) * (y3 - y1) - (yp - y1) * (x3 - x1)) / 2;
    s3 = ((xp - x2) * (y3 - y2) - (yp - y2) * (x3 - x2)) / 2;

    s  = fabs(s);
    s1 = fabs(s1);
    s2 = fabs(s2);
    s3 = fabs(s3);

    if (fabs(s - (s1 + s2 + s3)) <= eps) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 612
from collections import deque
import copy

def BFS(h,w,sy,sx,xy_list):
 dist=[[-1]*w for i in range(h)]
 dist[sy][sx]=0
 xy_list[sy][sx]='#'

 dq=deque()
 dq.append((sy,sx))

 while dq:
  y,x=dq.popleft()
  for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
   ny=y+dy
   nx=x+dx
   if 0<=ny<h and 0<=nx<w and xy_list[ny][nx]!='#':
    dq.append((ny,nx))
    xy_list[ny][nx]='#'
    dist[ny][nx]=dist[y][x]+1

 return dist

def main():
 h,w=map(int,input().split())
 s=[list(input()) for i in range(h)]

 ans=0
 for hh in range(h):
  for ww in range(w):
   if s[hh][ww]=='#':
    continue
   xy_list=copy.deepcopy(s)
   dist=BFS(h,w,hh,ww,xy_list)
   for d in dist:
    ans=max(ans,max(d))

 print(ans)

if __name__=="__main__":
  main()

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

#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define watch(x) cout<<#x<<" = "<<x<<endl;
#define V(x) vector<x>
#define P(x,y) pair<x,y>
#define UMP(x,y) unordered_map<x,y>
#define MP(x,y) map<x,y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define coutd(n) cout << fixed << setprecision(n)
typedef long long ll;
typedef double db;
typedef long double ld;
const ll mod = 1000000007;

using namespace std;

int main(){
	fast

	int t;
	cin>>t;
	unordered_set<string> st;
	rep(_,0,t){
		string str;
		cin>>str;
		st.insert(str);
	}
	cout<<st.size();
	
	return 0;
}


Measured memory_bytes: 17748
#include <bits/stdc++.h>
int main()
{
    int N;
    std::cin >> N;
    std::vector<std::string> S(N);
    std::vector<int> P(N);
    for(int i = 0; i< N; i++){std::cin >> S[i] >> P[i]; }
    std::vector<int> ind(N);
    std::iota(ind.begin(),ind.end(),0);
    std::sort(ind.begin(),ind.end(),[&](const int i, const int j){return S[i]==S[j]?P[i]>P[j]:S[i]<S[j];});
    for(const int i: ind){std::cout << i+1 << std::endl;}
    return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = map(int, readline().split())
    a = list(map(int, readline().split()))

    ans = 0

    for i in range(n - 1):
        diff = (a[i] + a[i + 1]) - x
        if diff > 0:
            ans += diff
            if diff > a[i + 1]:
                a[i] = a[i] - (diff - a[i + 1])
                a[i + 1] = 0
            else:
                a[i + 1] = a[i + 1] - diff

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
 char X,Y;
  cin >> X >> Y;
  if( X == Y){
  cout << '=' << endl;
  }
  else if (X =='A'){
  cout << '<' << endl;
  }
  else if (X == 'B'){
     if (Y == 'A'){
     cout << '>' << endl;
     }
     else{
     cout << '<' << endl;
     }
  }
  else if (X == 'C'){
     if (Y =='A' || Y =='B'){
     cout << '>' << endl;
     }
     else{
     cout << '<' << endl;
     }
  }
  else if(X == 'D'){
     if (Y =='E' || Y =='F'){
     cout << '<' << endl;
     }
     else{
     cout << '>' << endl;
     }
  }
  else if(X == 'E'){
     if (Y == 'F'){
     cout << '<' << endl;
     }
     else{
     cout << '>' << endl;
     }
  }
  else if(X == 'F'){
  cout << '>' << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int main(){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    if(x < r || w < x+r || y < r || h < y+r) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<vector>

int main(void){
    int i,n,sum=0,tmp,out=0;
    scanf("%d",&n);
    std::vector<int> vd(n);
    for(i=0;i<n;i++){
        scanf("%d",&tmp);
        vd.at(i)=tmp;
        sum+=tmp;
    }
    for(i=0;i<n;i++){
        out+=(sum-vd.at(i))*vd.at(i);
    }
    out/=2;
    printf("%d\n",out);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int s[2000];

int main() {
	int H, W, h, w; cin >> H >> W >> h >> w;
	if (H%h == 0 && W%w == 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	if (W%w != 0) {
		for (int i = 1; i <= W; ++i) s[i] = 1000;
		for (int i = 0; i < W; ++i) s[i + w] = s[i] - 1;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cout << s[j + 1] - s[j] << (j < W - 1 ? " " : "\n");
			}
		}
	}
	else {
		for (int i = 1; i <= H; ++i) s[i] = 1000;
		for (int i = 0; i < H; ++i) s[i + h] = s[i] - 1;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cout << s[i + 1] - s[i] << (j < W - 1 ? " " : "\n");
			}
		}
	}
	return 0;
}

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

int main(){
    int K, N, ans = 0;
    cin >> N >> K;
    vector<int>p(N);
    for (int i = 0; i < N; i++) {
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    for (int i = 0; i < K; i++) {
        ans += p.at(i);
    }
    cout << ans;
} 

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

int main() {
	int N , K;
  	cin >> N >> K;
  	int total = 1;
  	for(int i = 0; i < N; i++){
      	if(total * 2 < total + K){
        	total *= 2;
        }else{
        	total += K;
        }
    }
  	cout << total << endl;
}


Measured memory_bytes: 3592