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

const int N = (int) 1e5 + 5;
int dp[N][3];

int main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int aa,b,c;
    cin >> aa >> b >> c;
    dp[0][0] = aa;
    dp[0][1] = b;
    dp[0][2] = c;
    int a[3];
    for(int i = 1;i < n;++i)
    {
        cin >> a[0] >> a[1] >> a[2];
        for(int j = 0;j <= 2;++j)
        {
            for(int k = 0;k <= 2;++k)
            {
                if(j == k)
                    continue;
                dp[i][k] = max(dp[i][k],dp[i-1][j]+ a[k]);
            }
        }
    }
    int ans = max(dp[n-1][0],dp[n-1][1]);
    ans = max(ans,dp[n-1][2]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int socket = sc.nextInt();
        int goal = sc.nextInt();

        int layer = 1;
        int nowPlugs = 1;
        int usedSockets = 0;
        for(int i=0; goal > nowPlugs; i++){
           if(socket*layer==i){
               i=0;
               layer++;
           }
           nowPlugs += socket-1;
           usedSockets++;
        }
        System.out.println(usedSockets);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950L
int main()
{
        fast;

        int t=1;
        //cin>>t;
        while(t--)
        {
                string a,b;
                cin>>a>>b;
                char ch=b[b.length()-1];
                if((a+ch)==b)
                        cout<<"Yes"<<endl;
                else
                        cout<<"No"<<endl;

        }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n , x  ;
  int ans = 0;
  cin >> n >> x;
  vector<int> a(n);
  for(int i = 0 ; i< n ;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  for(int i = 0 ;i<n;i++){
    if( x >= a.at(i) ){
      ans += 1;
      x -= a.at(i);
    }
    else if( x < a.at(i)){
      break;
    }
    if( i == n - 1 && x > 0){
      ans -= 1;
    }
  }
  cout << ans <<endl;
}

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

int main(){
  int n;
  cin>>n;
  map<vi,int> f;
  vector<vi> pp;
  rep(i,n){
    int w;
    cin>>w;
    vi p(3);
    rep(j,3)p[j]=j;
    rep(j,w){
      int a;
      cin>>a;
      swap(p[a],p[a+1]);
    }
    f[p]++;
    pp.push_back(p);
  }
  if(n>=8){
    cout<<"yes"<<endl;
    return 0;
  }
  sort(pp.begin(),pp.end());
  do{
    vi acc(3);
    rep(i,3)acc[i]=i;
    rep(i,pp.size()){
      vi t(3);
      rep(j,3){
	t[j]=acc[pp[i][j]];
      }
      bool eq=1;
      rep(j,3)eq&=t[j]==j;
      if(eq){
	cout<<"yes"<<endl;
	return 0;
      }
      acc=t;
    }
  }while(next_permutation(pp.begin(),pp.end()));
  cout<<"no"<<endl;
}



Measured memory_bytes: 3168
program abc064_d
    use,intrinsic :: iso_fortran_env
    implicit none
    character(:), allocatable:: s
    character(200), allocatable:: ans
    integer(int32):: n,i
    integer(int32), allocatable:: cnt(:)

    read*, n
    allocate(character(n):: s)
    allocate(cnt(0:n))
    read*, s

    cnt(:) = 0
    do i=1,n
        if (s(i:i) == '(' ) then
            cnt(i)=cnt(i-1)+1
        else
            cnt(i)=cnt(i-1)-1
        end if
    end do

    ans = ''

    do i=1,abs(min(0,minval(cnt)))
        ans = '(' // trim(ans)
    end do

    ans = trim(ans) // s

    do i=1,cnt(n)-minval(cnt)
        ans = trim(ans) // ')'
    end do

    print'(a)', ans
end program abc064_d

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin >> a >> b;
	if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
s = input()
l = [s[0]]
d = len(s) - 1
if d == 0:
  print(s)
  exit()
def operate_1(string):
  return string
def operate_2(string):
  string += "+"
  return string
# l,d は未定義注意
def bfs(list_hoge = l,depth = 0,deepest = d):
    queue = []
    for e in list_hoge:
        for b in [0,1]:
            if b == 0:
                operated = operate_1(e)
                operated += s[depth + 1]
                queue.append(operated)
            elif b == 1:
                operated = operate_2(e)
                operated += s[depth + 1]
                queue.append(operated)
    list_hoge = queue[:]
    depth += 1
    if depth == deepest:
        return list_hoge
    else:
        return bfs(list_hoge,depth)
ans = 0
for e in bfs():
  ans += eval(e)
print(ans)

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

c_nums = set(50 * i for i in range(c + 1))
res = 0
for i in range(a + 1):
    for j in range(b + 1):
        tmp = x - 500 * i - 100 * j
        if tmp in c_nums:
            res += 1

print(res)


Measured memory_bytes: 9180
# include <iostream>

using namespace std;

//https://atcoder.jp/contests/abc076/tasks/abc076_b

int main(){
    int N,K;
    cin >> N >> K;

    int num=1;
    for(int i=0;i<N;i++){
        if(num + K < num*2){
            num += K;
        }else{
            num *= 2;
        }
    }
    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

n, m = gets.chomp.split(/ /).map(&:to_i)
array = []
n.times do
  array << gets.chomp.split(/ /).map(&:to_i)
end

ppp = []
ppm = []
pmp = []
pmm = []
mpp = []
mpm = []
mmp = []
mmm = []

array.each do |e|
  ppp << (e[0] + e[1] + e[2])
  ppm << (e[0] + e[1] - e[2])
  pmp << (e[0] - e[1] + e[2])
  pmm << (e[0] - e[1] - e[2])
  mpp << (- e[0] + e[1] + e[2])
  mpm << (- e[0] + e[1] - e[2])
  mmp << (- e[0] - e[1] + e[2])
  mmm << (- e[0] - e[1] - e[2])
end

ppp.sort!{|a, b| (b <=> a)}
ppm.sort!{|a, b| (b <=> a)}
pmp.sort!{|a, b| (b <=> a)}
pmm.sort!{|a, b| (b <=> a)}
mpp.sort!{|a, b| (b <=> a)}
mpm.sort!{|a, b| (b <=> a)}
mmp.sort!{|a, b| (b <=> a)}
mmm.sort!{|a, b| (b <=> a)}


pppv = 0
ppmv = 0
pmpv = 0
pmmv = 0
mppv = 0
mpmv = 0
mmpv = 0
mmmv = 0

(0..(m - 1)).each do |i|
  pppv += ppp[i]
  ppmv += ppm[i]
  pmpv += pmp[i]
  pmmv += pmm[i]
  mppv += mpp[i]
  mpmv += mpm[i]
  mmpv += mmp[i]
  mmmv += mmm[i]
end

puts [pppv, ppmv, pmpv, pmmv, mppv, mpmv, mmpv, mmmv].max


Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> c(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) { cin >> c[i][j]; }
  }

  int ans = 0;
  for (int bitH = 0; bitH < (1 << h); bitH++) {
    for (int bitW = 0; bitW < (1 << w); bitW++) {
      int black = 0;
      rep(i, h) {
        rep(j, w) {
          if (((((bitH >> i) & 1)) == 0) && ((((bitW >> j) & 1)) == 0) &&
              c[i][j] == '#')
            black++;
        }
      }
      if (black == k) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<bits//stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
int main(){
  string s,t;int n,m;char c;
  cin >> c;
  if(isupper(c)) cout << 'A' << endl;
  else cout<< "a"<<endl;
}

Measured memory_bytes: 3620
n = int(input())
nums = input().split()
a = {}
for i in nums:
    if int(i) in a:
        a[int(i)] += 1
    else:
        a[int(i)] = 1
b, l = list(a.keys()), len(a.keys())
res = 0
p = []
for i in range(l):
    for j in range(i + 1, l):
        for k in range(j + 1, l):
            t = [b[i], b[j], b[k]]
            t.sort()
            if t[0] + t[1] > t[2]:
                res += 1 * a[t[0]] * a[t[1]] * a[t[2]]
print(res)


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

int main() {
  string S;
  cin >> S;
  
  if(S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if(S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  else if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1

void solve() {
  int n;
  cin >> n;
  unordered_map<string, int> cnt;
  string s;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    ++cnt[s];
  }

  cout << "AC x " << cnt["AC"];
  cout << endl;
  cout << "WA x " << cnt["WA"];
  cout << endl;
  cout << "TLE x " << cnt["TLE"];
  cout << endl;
  cout << "RE x " << cnt["RE"];
  cout << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod=1e9+7;
const int N=2e5+100;
int a[N];
char s[10][10];
char ss[10][10];
int n,m,k;
bool check()
{
    int sum=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
          if(ss[i][j]=='#') sum++;
    if(sum==k) return true;
    return false;
}
void fix(int a,int b)
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) ss[i][j]=s[i][j];
    int k=1;
    while(a){
        if(a&1){
          for(int i=1;i<=m;i++) ss[k][i]='.';
        }
        k++;
        a>>=1;
    }
    k=1;
    while(b){
        if(b&1){
            for(int i=1;i<=n;i++) ss[i][k]='.';
        }
        k++;
        b>>=1;
    }
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>k;
    ll ans=0;
    for(int i=1;i<=n;i++) cin>>s[i]+1;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<m);j++){
           fix(i,j);
           if(check()) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    string s,t,u; cin >> s >> t >> u;
    s[0]-=32;
    t[0]-=32;
    u[0]-=32;
    cout << s[0] << t[0] << u[0] << endl;
    
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main(){
	var a , b int
	fmt.Scanf("%d %d", &a, &b)
	if (a < 10 && b < 10 && a > 0 && b > 0) {
		fmt.Print(a*b)
	}else{
		fmt.Print(-1)
	}
}

Measured memory_bytes: 512
#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++)
#define ALL(vec)  (vec).begin(),(vec).end()
int main() 
{
  vector<string> key(0);
  std::map<std::string,int> S;
  int N;
  cin >> N;
  string s;
  int criteria=0;
  rep(i, N)
  {
  cin >> s;
    S[s]++;
    if(S[s]==1){
    key.push_back(s);
    }
    if(S[s]>criteria)
      criteria=S[s];
  }
  sort(ALL(key));
  rep(i, S.size())
  {
    if(S[key[i]]==criteria)
      cout << key[i] << endl;
  }
}

Measured memory_bytes: 26736
#include <iostream>
#include <cstdio>
#include <vector>

void update(int64_t& old, int64_t new_)
{
	if (new_ > old)
		old = new_;
}

int64_t max(int64_t a, int64_t b)
{
	if (a > b)
		return a;
	return b;
}

int64_t max(int64_t a, int64_t b, int64_t c)
{
	return max(max(a, b), c);
}

int main()
{
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	std::ios::sync_with_stdio(false);

	int N;
	std::cin >> N;

	std::vector<int> happiness[3];
	std::vector<int64_t> DP[3];

	for (int i=0; i<3; i++)
	{
		happiness[i].resize(N);
		DP[i] = std::vector<int64_t>(N, -1);
	}

	for (int i=0; i<N; i++)
		std::cin >> happiness[0][i] >> happiness[1][i] >> happiness[2][i];

	DP[0][0] = happiness[0][0];
	DP[1][0] = happiness[1][0];
	DP[2][0] = happiness[2][0];
	
	for (int j=0; j<N-1; j++)
		for (int i=0; i<3; i++)
		{
			update(DP[(i+1)%3][j+1], DP[i][j] + happiness[(i+1)%3][j+1]);
			update(DP[(i+2)%3][j+1], DP[i][j] + happiness[(i+2)%3][j+1]);
		}

	/*std::cout << "DP[i] with last taken 0:\n";
	for (int i=0; i<N; i++)
		std::cout << DP[0][i] << ' ';
	std::cout << "\nDP[i] with last taken 1:\n";
	for (int i=0; i<N; i++)
		std::cout << DP[1][i] << ' ';
	std::cout << "\nDP[i] with last taken 2:\n";
	for (int i=0; i<N; i++)
		std::cout << DP[2][i] << ' ';
	std::cout << '\n';*/

	std::cout << max(DP[0][N-1], DP[1][N-1], DP[2][N-1]) << '\n';
}

Measured memory_bytes: 3840
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

x1, y1, x2, y2 = map(int, input().split())

y3 = y2 + (x2 - x1)
x3 = x2 - (y2 - y1)
y4 = y3 + (x3 - x2)
x4 = x3 - (y3 - y2)
print(x3, y3, x4, y4)



Measured memory_bytes: 7716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	static final int[] month = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int y1, m1, d1, y2, m2, d2;
			StringTokenizer st = new StringTokenizer(line);
			y1 = parseInt(st.nextToken()) - 1;
			m1 = parseInt(st.nextToken()) - 1;
			d1 = parseInt(st.nextToken());
			y2 = parseInt(st.nextToken()) - 1;
			m2 = parseInt(st.nextToken()) - 1;
			d2 = parseInt(st.nextToken());
			if ((y1 + 1 | m1 + 1 | d1 | y2 + 1 | m2 + 1 | d2) < 0) {
				break;
			}

			int days1, days2;
			//
			days1 = y1 * 365 + (y1 / 4 - y1 / 100 + y1 / 400);
			days1 += month[m1] + d1;
			if (m1 > 1 && isLeap(y1 + 1)) {
				days1++;
			}
			//
			days2 = y2 * 365 + (y2 / 4 - y2 / 100 + y2 / 400);
			days2 += month[m2] + d2;
			if (m2 > 1 && isLeap(y2 + 1)) {
				days2++;
			}
			System.out.println(days2 - days1);
		}
	}

	static boolean isLeap(int year) {
		return year % 4 == 0 ? (year % 100 == 0 ? (year % 400 == 0 ? true : false) : true) : false;
	}
}

Measured memory_bytes: 16892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;

// Modint
struct Mint {
	static const ll mod = (ll)(1e9 + 7);
	ll val;

	Mint() { val = 0; }
	Mint(ll a) { val = a; verify_value(); }

	void verify_value() {
		if (val >= mod) val %= mod;
		if (val < 0) val %= mod, val += mod;
	}

	Mint pow(ll p) const {
		Mint cur = Mint(val), ret = 1;
		while (p > 0) {
			if (p & 1) ret *= cur;
			cur *= cur;
			p >>= 1LL;
		}
		return ret;
	}
	Mint inv() const {
		if (val == 0) cerr << "CAUTION: inv() is called with 0." << endl;
		return pow(mod - 2);
	}

	Mint operator+() const { return *this; }
	Mint operator-() const { return Mint(mod - val); }

	Mint operator+=(const Mint &a) {
		val += a.val;
		if (val >= mod) val -= mod;
		return Mint(val);
	}
	Mint operator*=(const Mint &a) {
		val *= a.val;
		if (val >= mod) val %= mod;
		return Mint(val);
	}
	Mint operator-=(const Mint &a) { return *this += -a; }
	Mint operator/=(const Mint &a) { return *this *= a.inv(); }

	Mint operator++() { return *this += Mint(1); }
	Mint operator--() { return *this -= Mint(1); }
	Mint operator++(int) {
		Mint ret = *this;
		++(*this);
		return ret;
	}
	Mint operator--(int) {
		Mint ret = *this;
		--(*this);
		return ret;
	}

	operator ll() const { return val; }
};

Mint operator+(const Mint &a, const Mint &b) {
	ll ret = a.val + b.val;
	if (ret >= Mint::mod) ret -= Mint::mod;
	return Mint(ret);
}
Mint operator*(const Mint &a, const Mint &b) {
	ll ret = a.val * b.val;
	if (ret >= Mint::mod) ret %= Mint::mod;
	return Mint(ret);
}
Mint operator-(const Mint &a, const Mint &b) { return a + (-b); }
Mint operator/(const Mint &a, const Mint &b) { return a * b.inv(); }

ostream &operator<<(ostream &out, const Mint &a) { return out << a.val; }
istream &operator>>(istream &in, Mint &a) {
	in >> a.val;
	a.verify_value();
	return in;
}


int main() {
	int n; Mint k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	Mint ans = 0;
	for (int i = 0; i < n; i++) {
		Mint cnt = 0;
		for (int j = i + 1; j < n; j++) {
			cnt += a[i] > a[j];
		}
		ans += cnt * k*(k + Mint(1))/Mint(2);
		cnt = 0;
		for (int j = 0; j < i; j++) {
			cnt += a[i] > a[j];
		}
		ans += cnt * k*(k - Mint(1)) / Mint(2);
	}
	cout << ans << endl;
	return 0;
}



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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A)
{
  if (A.size() == n+1) {
    int now = 0;
    rep(i,q)
    {
      if (A[b[i]] - A[a[i]] == c[i])
        now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while (A.back() <= m)
  {
    dfs(A);
    A.back()++;
  }
}

int main()
{
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i, q)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1, 1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

N_SHOPS = attrs[0][0]
NEEDS = attrs[0][1]
attrs.shift
shops = attrs.sort

cost = 0
having = 0

while true do
  if shops[0][1] < (NEEDS - having) then
    cost   += shops[0][0] * shops[0][1]
    having += shops[0][1]
    shops.shift
  else
    cost   += shops[0][0] * (NEEDS - having)
    break
  end
end

puts cost


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

int main() {
  ll n;
  string s;
  cin >> n >> s;
  vector<int> e(n + 1);
  e[0]     = 0;
  int eCnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'E') {
      eCnt++;
      e[i + 1] = e[i] + 1;
    } else {
      e[i + 1] = e[i];
    }
  }

  int mn = INT_MAX;
  for (int i = 0; i <= n; i++) {
    mn = min(mn, eCnt - e[i] + (i - e[i]));
  }
  cout << mn << endl;
}

Measured memory_bytes: 1796
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        if(a <= 5) {
            System.out.println(0);
        }else if(a < 13) {
            System.out.println(b/2);
        }else {
            System.out.println(b);
        }
    }
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A){
    vector<int> cnt(N+1);
    rep(i,0,N) cnt[A[i]]++;
    int sum = 0;
    rep(i,1,N+1)
        if (cnt[i] >= 2)
            sum += cnt[i] * (cnt[i]-1) / 2;
    rep(i,0,N) {
        if (cnt[A[i]] < 2) {
            cout << sum << endl;
        } else {
            cout << (sum - cnt[A[i]] * (cnt[A[i]]-1) / 2 + (cnt[A[i]]-1) * (cnt[A[i]]-2) / 2) << endl;
        }
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int a, b; cin >> a >> b;
  cout << a * b << endl;

  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<iostream>

using namespace std;

int N;
int main(){
    cin >> N;
    int a[N],b[N];
    long long int ans = 0;
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];
    for(int i=N-1; i>=0; i--) {
         if( ( a[i] + ans ) % b[i] && b[i] != 1)ans += b[i] - ( a[i] + ans ) % b[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int A,B,C,X,Y;//A,B,AB's price, A,B wanted
    int PR;//answer
    int p,q,r;
    int damy;
    scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);//read input
    if(X > Y){//X<Y for all case
        damy = X;
        X = Y;
        Y = damy;
        damy = A;
        A = B;
        B = damy;
    }
    p = A * X + B * Y;
    q = 2 * C * X + B * (Y - X);
    r = 2 * C * Y;
    if(p<q) PR = p;
    else PR = q;
    if(r < PR) PR = r;
    printf("%d\n",PR);
    return 0;
}

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

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

    int A_index = -1;
    for(int i=0; i<S.size(); i++){
        if(S[i] == 'A'){
            A_index = i;
            break;
        }
    }

    int Z_index = -1;
    for(int i=S.size()-1; i>=0; i--){
        if(S[i] == 'Z'){
            Z_index = i;
            break;
        }
    }

    cout << Z_index - A_index + 1 << endl;
    return 0;
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define ll long long int
#define inf 999999999
#define maxn 200003
#define F first
#define S second
#define PB push_back
#define MP make_pair
const ll mod = 1e9+7;
using namespace std;
void code()
{
	string s;
	cin >> s;
	int rcount = 0, scount =0 ;
	for(auto i: s)
	{
		if(i=='S')
		{
			scount++;
		}
		else
		{
			rcount++;
		}
	}
	if(rcount==3)
	{
		cout << "3";
	}
	if(scount==3)
	{
		cout<<"0";
	}
	if(rcount==2)
	{
		if(s[1]=='S')
		{
			cout << "1";
		}
		else
		{
			cout << "2";
		}
	}
	if(rcount==1)
	{
		cout << "1";
	}
}
int main()
{
	SPEED
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	int t = 1;
	while(t--)
	{
		code();//DEBUG
	}
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef pair<int, int> pii;
typedef double Double;

inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
const Double EPS = 1e-9;

int N, M, L;
int P[110], T[110], V[110];

Double prob[110][55];
Double goal[110][55];

lint combination(int n, int m) {
	lint res = 1;
	if (2 * m > n) m = n - m;
	for_(i,0,m) res = res * (n - i) / (i + 1);
	return res;
}

Double calc_prob(int p, int s) {
	Double res = 1.0;
	
	Double time_p = goal[p][s];
	
	for_(i,0,N) {
		if (i == p) continue;
		Double sum = 0.0;
		int ind = upper_bound(goal[i], goal[i] + M + 1, time_p) - goal[i];
		for_(j,ind,M+1) sum += prob[i][j];
		res *= sum;
	}
	
	return res;
}

void solve() {
	for_(i,0,N) {
		Double f_goal = (Double)L / (Double)V[i];
		
		for_(j,0,M + 1) {
			prob[i][j] = (Double)combination(M, j) * pow((Double)P[i] / 100.0, j) * pow((Double)(100 - P[i]) / 100.0, M - j);
			goal[i][j] = f_goal + (Double)j * (Double)T[i];
		}
	}
	/*
	for_(i,0,N) {
		for_(j,0,M + 1) cout << prob[i][j] << " ";
		cout << endl;
	}
	*/
	
	for_(i,0,N) {
		Double ansi = 0.0;
		for_(j,0,M + 1) ansi += calc_prob(i, j) * prob[i][j];
		printf("%.9lf\n", ansi);
	}
}

int main() {
	cin >> N >> M >> L;
	for_(i,0,N) cin >> P[i] >> T[i] >> V[i];
	solve();
	return 0;
}

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

using namespace std;


int h, w;
int dp[10][10];
int temp;

int main()
{    
    cin >> h >> w;
    vector<vector<int>> v(h, vector<int>(w));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> dp[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> v[i][j];
        }
    }
    

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
            }
        }
    }


    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (v[i][j] != -1) {
                ans += dp[v[i][j]][1];
            }
        }
    }

    cout << ans;

    
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	int p[200020];
	for(int i=0; i<2*n; i++){
		cin>>p[i];
	}
	sort(p, p+2*n);
	double ans=0;
	for(int i=0; i<2*n; i++){
		ans+=(double)i/(2*n-1)*p[i];
	}
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string S;
    cin >> S;
    ll N = S.size() + 1;
    S.push_back('#');
    vector<ll> a(N, 0), l(N, 0), r(N, 0);
    ll L = 0, R = 1;
    while(R < N){
        if(S[L] == S[R]){
            R++;
        }else{
            if(S[L] == '<'){
                rep(i, L, R+1){
                    a[i] = max(a[i], i - L);
                }
            }else{
                for(ll i = R; i >= L; i--){
                    a[i] = max(R - i, a[i]);
                }
            }
            L = R;
            R = L + 1;
        }
    }

    ll ans = 0;
    rep(i, 0, N) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12548
import sys
import collections

n = int(input())
s=[]
for i in range(n):
  s.append(input())


c = collections.Counter(s)
#N = len(count)


ans_list = list(c.values())
ans=0
for i in range(len(ans_list)):
  if ans_list[i]>=2:
    ans+=1
  else:
    ans+=1
    
print(ans)


Measured memory_bytes: 38760
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for i in range(n)]
#wv[i][0]:i番目の品物の重さ
#wv[i][1]:i番目の品物の価値

dp = [0]+[float("inf")]*(10**5)#dp[k]:価値kにおける最小重さ
for i in range(n):#あるi番目の品物について
    for j in range(10**5,wv[i][1]-1, -1):#ある価値jについて
        dp[j] = min( dp[j], dp[j-wv[i][1]]+wv[i][0] )
        #重さwv[i][0]であるi番目の品物を使うほうが価値jでの最小重さdp[j]が小さい場合は値を更新

res = 0
for v,e in enumerate(dp):#インデックスv(=ある価値j)における最小重さeについて
    if e <= w:
        res = v#最小重さが重さ制限を超えないならres更新
print(res)

Measured memory_bytes: 93256
import sys

input = sys.stdin.readline

N, X, M = map(int, input().split())
LIST = [X]
SET = {X}

a = X

while True:
    if a * a % M in SET:
        break
    else:
        a = a * a % M
        LIST.append(a)
        SET.add(a)

# 繰り返しがaから始まる
# SETには順番が記録されていないのでLISTを使う
start = LIST.index(a * a % M)
LEN = len(LIST)

if N <= LEN:
    print(sum(LIST[:N]))
else:
    LoopTimes, Excess = divmod(N-LEN, LEN-start)
    LoopSum = sum(LIST[start:]) * LoopTimes
    ExSum = sum(LIST[start:start+Excess])
    print(sum(LIST[:]) + LoopSum + ExSum)

Measured memory_bytes: 13168
#include<stdio.h>
 
int main(void){
    int i,j,h,n,a[5000],max=0,sum;
    scanf("%d",&n);
    while(n!=0){
        for(i=0; i<n; i++){
            scanf("%d",&a[i]);
        }
        for(i=0; i<n; i++){
            sum=0;
            for(j=i; j<n; j++){
                sum+=a[j];
                if((i==0 && j==0) || max<sum){
                    max=sum;
                }
            }
        }
        printf("%d\n",max);
        scanf("%d",&n);
    }
    return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  
  	int n,m;
  	cin >> n >> m;
  	if(n==m) Yes
    No
    return 0;
}

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

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var w = cin.ReadInt;
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            double ha = a + (double)w / 2;
            double hb = b + (double)w / 2;
            if(Abs(ha - hb) <= w)
            {
                WriteLine(0);
                return;
            }
            else
            {
                WriteLine(Abs(ha - hb) - w);
            }
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

vector<int> adj[100005];

int main(){

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m, a, b, s, t; cin >> n >> m;

    for(int i = 0; i < m; ++i){
        cin >> a >> b;
        adj[a].push_back(b);
    }

    cin >> s >> t;

    bitset<100005> vis[3];
    vis[0][s] = 1;

    queue<pair<int, int>> q;
    q.push(make_pair(0, s));

    while(!q.empty()){

        pair<int, int> state = q.front(); q.pop();

        if(state.second == t && state.first % 3 == 0){
            cout << state.first / 3 << "\n";
            return 0;
        }

        for(int nx : adj[state.second]){
            if(vis[(state.first + 1) % 3][nx]) continue;
            vis[(state.first + 1) % 3][nx] = 1;
            q.push(make_pair(state.first + 1, nx));
        }

    }

    cout << "-1\n";

    return 0;

}


Measured memory_bytes: 5760
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
 


int main(){
     
    int n;
    long power=1;
    
    cin>>n;
    for(int i=1;i<=n;i++){
        power*=i;
        power%=(10*10*10*10*10*10*10*10*10+7);
    }
    cout<<power<<endl;
     
    return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int W[110];
    rep(i, N) cin >> W[i];
    int ans = INF;
    rep(i, N) {
        int sum1 = 0, sum2 = 0;
        rep(j, N) {
            if(j <= i) sum1 += W[j];
            else sum2 += W[j];
        }
        ans = min(ans, abs(sum1 - sum2));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3560
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
#define vi vector<int>
#define vpii vector<pair<int,int>> 
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>> 
#define pii pair<int,int> 
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>

ld pie=3.141592653589793238462643383279;
int mod=1e9+7;

vvi mat_mul(vvi mat1,vvi mat2){
  vvi ret;
  f(i,0,2){
    vi xx;
    f(j,0,2){
      int r=0;
      f(k,0,2) r=(r+(mat1[i][k]*mat2[k][j])%mod)%mod;
      xx.pb(r%mod);
    }
    ret.pb(xx);\
  }
  return ret;
}

vvi mat_exp(vvi mat,int p){
  vvi iden={{1,0},{0,1}};
  while(p!=0){
    if(p&1) iden=mat_mul(iden,mat);
    p/=2; 
    mat=mat_mul(mat,mat);
  }
  return iden;
}


int32_t main(){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  int n,k;  cin>>n>>k;
  vi vt;
  f(i,0,n){
    int x; cin>>x;
    vt.pb(x);
  }
  f(i,0,n){
    if(i>=k)
    if(vt[i]>vt[i-k]) cout<<"Yes\n";
    else cout<<"No\n";  
  }
  return 0; 
}

Measured memory_bytes: 5344
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, A[112345], C[112345];

int main() {

	cin >> N;
	rep(i, N) cin >> A[i];

	ll ans = 1;
	rep(i, N) {
		ans *= (A[i] ? C[A[i] - 1] : 3) - C[A[i]];
		ans %= 1000000007;
		C[A[i]]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int h,w;
	cin>>h>>w;
	vector<vector<int>> a=vector<vector<int>> (h+3,vector<int>(w+3,0));
	vector<vector<int>> b=vector<vector<int>> (h+3,vector<int>(w+3,0));
	vector<vector<int>> r=vector<vector<int>> (h+3,vector<int>(w+3,0));
	FOR(i,0,h){
		FOR(j,0,w){
			char c;
			cin>>c;
			if(c=='#'){
				r[i][j]=1;
			}else{

			}
		}
	}
	FOR(i,0,h){
		a[i][0]=b[i][w-1]=1;
		FOR(j,1,w-1){
			if(i&1){
				a[i][j]=1;
				if(r[i][j]==1){
					b[i][j]=1;
				}
			}else{
				b[i][j]=1;
				if(r[i][j]==1){
					a[i][j]=1;
				}
			}
		}
	}
	FOR(i,0,h){
		FOR(j,0,w){
			if(a[i][j]){
				cout<<'#';
			}else{
				cout<<'.';
			}
		}
		cout<<endl;
	}
	cout<<endl;
	FOR(i,0,h){
		FOR(j,0,w){
			if(b[i][j]){
				cout<<'#';
			}else{
				cout<<'.';
			}
		}
		cout<<endl;
	}
    return 0;
}


Measured memory_bytes: 3840
import fractions
A,B,C,D=map(int, input().split())
def ans_mthd(i, j, k):
    return (i - i // j - i // k + i * fractions.gcd(j, k) // j // k )
ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
print(ans)

Measured memory_bytes: 5432
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  
  cin >> a >> b;
  
  c = a + b;
  
  if(c == 3)c = 3;
  else if(c == 4)c = 2;
  else c = 1;
  
  cout << c << endl;
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int total = in();
  int ans = LLONG_MAX;
  REP(i,total+1) {
    int counter = 0;
    int balance_4_6 = i;
    while(balance_4_6 > 0) {
      counter += balance_4_6 % 6;
      balance_4_6 /= 6;
    }
    int balance_4_9 = total - i;
    while(balance_4_9 > 0) {
      counter += balance_4_9 % 9;
      balance_4_9 /= 9;
    }
    ans = min(ans, counter);
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n,n){
		vector<int> data(n);
		rep(i,n)cin >> data[i];
		int ret = 0;
		rep(i,n)ret = min(ret,data[i]);
		rep(i,n){
			int sum = 0;
			for(int j=i;j<n;j++){
				sum += data[j];
				ret = max(sum,ret);
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
   int n;
   cin>>n;
   int temp=n;
   int reverse=0;
   while(temp!=0)
   {
       reverse=reverse*10+(temp%10);
       temp/=10;
   }
   if(reverse==n)
    cout<<"Yes";
   else
   cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vi a(n); 
    li x=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    li totalxor = 0;
    for(int i=0;i<n;i++)
        totalxor ^= a[i]^a[++i];

    for(int i=0;i<n;i++)
        cout<<(totalxor^a[i])<<" ";
    cout<<endl;
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 3988
#include <iostream>
#include <set>
using namespace std;
int mx[(1<<18)];
multiset<int> s[(1<<18)];
void add(int a,int b)
{
	s[a].insert(b);
	if (s[a].size()>2)
	s[a].erase(s[a].begin());
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<(1<<n);i++)
	{
		int a;
		scanf("%d",&a);
		s[i].insert(a);
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<(1<<n);j++)
		{
			if (!(j&(1<<i)))
			{
				for (int k:s[j])
				add((j|(1<<i)),k);
			}
		}
	}
	for (int i=1;i<(1<<n);i++)
	{
		mx[i]=max(mx[i-1],*s[i].begin()+*next(s[i].begin()));
		printf("%d\n",mx[i]);
	}
}

Measured memory_bytes: 40960
#include<bits/stdc++.h>
using namespace std;
char p[200010];
char a[200010];
int main()
{
	int i=0;
	char ps;
	while(scanf("%c",&ps)!=EOF)
	{
		if(ps=='?')
		{
			a[i++]='D';
		}
		else
		a[i++]=ps;
	}
	printf("%s",a);
}

Measured memory_bytes: 3944
N = int(input())

s = input()
l = [1 if i=="W" else 0 for i in s]
ac = [0]*(N+1)

for i in range(1, N+1):
    ac[i] = ac[i-1]+l[i-1]
ans = N
for i in range(1, N+1):
    lw = ac[i-1]
    le = i-1-lw
    rw = ac[N]-ac[i]
    re = N-i-rw
    ans = min(ans, lw+re)

print(ans)

Measured memory_bytes: 17824
//

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  int N;
  vector<int> v;
  int cnt = 1;

  cin >> N;
  for(int i = 0; i < N; i++){
    int work;
    cin >> work;
    v.push_back(work);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  int len = v.size();
  // debug
/*  for(int i = 0; i < len; i++){
    cout << v[i] << " ";
  }
  cout << endl;*/
  cout << len << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N, K; cin >> N >> K;
  map<int, int> A;
  rep(i, N) {
   int num; cin>>num;
   if(A.count(num)) A.at(num)++;
   else A.insert(make_pair(num, 1));
  }
  vector<int> num;
  for(auto a:A) num.push_back(a.second);
  sort(num.begin(), num.end());
  ll ans = 0;
  if(num.size() > K) {
    for(int i=0; i<num.size()-K; ++i) ans += num[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 10748