akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}

int w, h, x, y;
double a;

signed main() {
	cin >> w >> h >> x >> y;
	a = (double)w * (double)h / 2;
	printf("%.10lf",a);
	cout << " ";
	if (x == (double)w / 2 && y == (double)h / 2) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define X 3
#define Y 3
#define THRESHOLD 2
int manhattan(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
int calc(vector<int>&v){
	int s=0;
	for(int coor=0;coor<X*Y;coor++){
		if(v[coor]!=0){
			s+=manhattan(coor%X,coor/X,(v[coor]-1)%X,(v[coor]-1)/X);
		}else{
			s+=manhattan(coor%X,coor/X,X-1,Y-1);
		}
			
	}
	return s;
}
int main(){
	int i=1,start_point;
	vector<int>start(X*Y),goal;
	for(;i<X*Y;i++)goal.push_back(i);goal.push_back(0);
	for(i=0;i<X*Y;i++){
		scanf("%d",&start[i]);
		if(start[i]==0)start_point=i;
	}
	if(start==goal){puts("0");return 0;}

	map<vector<int>,pair<int,int> >mstart;
	queue<vector<int> >q;
	mstart[start]=make_pair(start_point,0);
	q.push(start);
	for(;!q.empty();){
		vector<int> v=q.front();
		int val=calc(v);//,nxtval;
		//printf("[+] %d\n",val);
		q.pop();
		map<vector<int>,pair<int,int> >&m=mstart;
		int coor=m[v].first,x=coor%X,y=coor/X;
		int depth=m[v].second;
		if(0<x){
			swap(v[coor],v[coor-1]);
			if(m.find(v)==m.end() && calc(v)<=val+THRESHOLD)m[v]=make_pair(coor-1,depth+1),q.push(v);
			if(v==goal){printf("%d\n",depth+1);return 0;}
			swap(v[coor],v[coor-1]);
		}
		if(x<X-1){
			swap(v[coor],v[coor+1]);
			if(m.find(v)==m.end() && calc(v)<=val+THRESHOLD)m[v]=make_pair(coor+1,depth+1),q.push(v);
			if(v==goal){printf("%d\n",depth+1);return 0;}
			swap(v[coor],v[coor+1]);
		}
		if(0<y){
			swap(v[coor],v[coor-X]);
			if(m.find(v)==m.end() && calc(v)<=val+THRESHOLD)m[v]=make_pair(coor-X,depth+1),q.push(v);
			if(v==goal){printf("%d\n",depth+1);return 0;}
			swap(v[coor],v[coor-X]);
		}
		if(y<Y-1){
			swap(v[coor],v[coor+X]);
			if(m.find(v)==m.end() && calc(v)<=val+THRESHOLD)m[v]=make_pair(coor+X,depth+1),q.push(v);
			if(v==goal){printf("%d\n",depth+1);return 0;}
			swap(v[coor],v[coor+X]);
		}
	}
}

Measured memory_bytes: 24112
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iterator>
#include <sstream>

using namespace std;

int main()
{
	int n;
	while(cin>>n){
		cout << 1 + n * (n + 1) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#! /usr/bin/env ruby
# coding: utf-8
require 'date'
D = [144000, 7200, 360, 20, 1]

while s = gets do
  v = s.scan(/\d+/).map(&:to_i)
  if v.size == 3 then
    a = []
    d = Date.new(v[0], v[1], v[2]).jd - Date.new(2012, 12, 21).jd
    D.each do |n|
      a << d / n
      d %= n
    end
    a[0] %= 13
    puts a.join(".")
  elsif v.size == 5 then
    d = 0
    D.each.with_index do |n, i|
      d += n * v[i]
    end
    dt = Date.new(2012, 12, 21) + d
    puts [dt.year, dt.month, dt.day].join(".")
  end
end

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

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

    char c;
    cin >> c;
    int a = (int)c + 1;
    cout << (char)a << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
    int i = 0,cnt = 0;
    char W[10];
    char T[1000];
    char end[100] = "END_OF_TEXT";
    scanf("%s\n",W);
    scanf("%s\n",T);
    while(strcmp(T,end) != 0){
        i = 0;
        while(tolower(T[i]) == W[i]){
            i++;
            if(T[i] == '\0' && (i == 10 || W[i] == '\0') ) {
                cnt++;
                break;
            }
        }
        scanf("%s",T);
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 552
from collections import defaultdict
def solve():
  ans = 0
  mod = 10**9+7
  s = defaultdict(lambda: -1)
  t = defaultdict(lambda: -1)
  N, M = map(int, input().split())
  S = list(map(int, input().split()))
  T = list(map(int, input().split()))
  dp = [[0]*(M+1) for _ in range(N+1)]
  for j in range(M+1):
    dp[0][j] = 1
  for i in range(1,N+1):
    dp[i][0] = 1
  for i in range(1,N+1):
    for j in range(1,M+1):
      if S[i-1]==T[j-1]:
        dp[i][j] += dp[i-1][j]+dp[i][j-1]
      else:
        dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
      dp[i][j]%= mod
  ans = dp[-1][-1]%mod
  return ans
print(solve())

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

int n, m;
P p[100001], xy[100001];

int par[100001];

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

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

void unite(int x, int y){
	x = root(x);
	y = root(y);

	int dum;
	if(x < y){
		par[y] = x;
	}else{
		par[x] = y;
	}

	return;
}

int solve(){
	int ans = 0;
	for(int i = 1; i <= n; i++){
		par[i] = i;
	}

	sort(xy, xy+m);
	for(int i = 0; i < m; i++){
		unite(xy[i].first, xy[i].second);
	}
	for(int i = 1; i <= n; i++){
		if(same(p[i].first, p[i].second)) ans++;
	}

	return ans;
}

int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> p[i].first;
		p[i].second = i;
	}
	for(int i = 0; i < m; i++){
		cin >> xy[i].first >> xy[i].second;
		if(xy[i].first > xy[i].second){
			int dum = xy[i].first;
			xy[i].first = xy[i].second;
			xy[i].second = dum;
		}
	}

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
        int[] V=new int[N];
        int[] C=new int[N];
        for (int i=0; i<N; i++) {
        	V[i]=gi();
        }
        for (int i=0; i<N; i++) {
        	C[i]=gi();
        }
        int v=0;
        for (int i=0; i<N; i++) {
        	if(V[i]-C[i]>0)v+=(V[i]-C[i]);
        }
        
        


        System.out.print(v);

//        if (s>L[n-2]) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35708
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int n, m, q;
int a[51], b[51], c[51], d[51];
int v[11];
 
int main() {
    int dp[1000000] = {};
    dp[0] = 0;
    int N;
    cin >> N;
    rep(i, 1, 1000000) {
        dp[i] = 1000000;
        int num = 1;
        while (num <= i) {
            dp[i] = min(dp[i], dp[i-num]+1);
            num *= 6;
        }
        num = 1;
        while (num <= i) {
            dp[i] = min(dp[i], dp[i-num]+1);
            num *= 9;
        }
    }
    cout << dp[N] << endl;
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, 0, N) cin >> d[i];

    ll res = 0;
    rep(i, 0, N)
        rep(j, i+1, N)
            res += (ll)d[i] * d[j];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,C;
    cin >> N >> C;
    vector<vector<int>> D(C,vector<int>(C));
    for(int i = 0;i < C;i++) {
        for(int j = 0;j < C;j++) {
            cin >> D.at(i).at(j);
        }
    }
    vector<vector<int>> G(N,vector<int>(N));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < N;j++) {
            int A;
            cin >> A;
            A--;
            G.at(i).at(j) = A;
        }
    }
    vector<vector<int>> color(3,vector<int>(C));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < N;j++) {
            color.at((i + j) % 3).at(G.at(i).at(j))++;
        }
    }
    ll ret = INF;
    for(int i = 0;i < C;i++) {
        for(int j = 0;j < C;j++) {
            for(int k = 0;k < C;k++) {
                if(i != j && j != k && i != k) {
                    ll count = 0;
                    for(int l = 0;l < C;l++) {
                        count += color.at(0).at(l) * D.at(l).at(i);
                    }
                    for(int l = 0;l < C;l++) {
                        count += color.at(1).at(l) * D.at(l).at(j);
                    }
                    for(int l = 0;l < C;l++) {
                        count += color.at(2).at(l) * D.at(l).at(k);
                    }
                    ret = min(ret,count);
                }
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 1280
# 無理やり0.1度ずつ行先を回す。

import math
import numpy as np

n = int(input())

eng_list = []

for _ in range(n):
    a = np.array(list(map(int, input().split())))
    eng_list.append(a)

# 角度
angles = []

for i in range(n):
    cos = (np.dot(eng_list[i], np.array([0, 1]))/(np.linalg.norm(eng_list[i])))
    angle = math.degrees(math.acos(cos))
    if eng_list[i][0] < 0:
        angle = 360 - angle
    angles.append(angle)


def hantei(a, b):
    coss = np.dot(a, b)/(np.linalg.norm(a)*np.linalg.norm(b))
    if coss > 1:
        coss = 1.0
    elif coss < -1:
        coss = -1.0
    angg = math.degrees(math.acos(coss))
    if angg < 90.0001:
        return True
    else:
        return False


def distance(a):
    dis = np.linalg.norm(a)
    return dis

pitch = 1 # 角度
dist = []

for ikisaki in np.arange(0, 360, pitch):
    dist_location = np.array([0, 0])
    for j in eng_list:
        i = np.array([math.cos(math.radians(ikisaki)), math.sin(math.radians(ikisaki))])
        if hantei(i, j):
            dist_location = dist_location + j
    dist.append(distance(dist_location))

print(max(dist))


Measured memory_bytes: 14432
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

map<ll, ll>freq;

int main(){

	fastcin
	
	ll n, ans=0;
	cin >> n;
	
	ll v[n+1];
	
	for(int i=1; i<=n; i++) cin >> v[i];
	
	for(int i=1; i<=n; i++){
		freq[i+v[i]]++;
	}	
	
	for(int i=1; i<=n; i++){
		if(i-v[i] >= 0) ans+=freq[i-v[i]];
	}
	
	cout << ans << endl;
	      
	return 0;
}


Measured memory_bytes: 19048
#include<stdio.h>

int main(){

   char a[4],b[4];

   scanf("%s",a);
   scanf("%s",b);

   if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
      printf("YES\n");
   }else{
      printf("NO\n");
   }

   return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader
import java.io.InputStreamReader

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val line = jin.readLine().split(" ")
    val n = line[0].toInt()
    val xs = IntArray(3) { line[it + 1].toInt() }
    val s = "ABC"
    val strings = Array(n) { jin.readLine() }
    var possible = true
    val answer = mutableListOf<Char>()
    for (j in 0 until n) {
        val k1 = when (strings[j]) {
            "AB" -> 0
            "BC" -> 1
            else -> 2
        }
        val k2 = (k1 + 1) % 3
        if (xs[k1] == 0) {
            if (xs[k2] == 0) {
                possible = false
                break
            } else {
                answer.add(s[k1])
                xs[k1]++
                xs[k2]--
            }
        } else {
            if (xs[k2] == 0) {
                answer.add(s[k2])
                xs[k2]++
                xs[k1]--
            } else {
                if (j == n - 1 || s[k1] in strings[j + 1]) {
                    answer.add(s[k1])
                    xs[k1]++
                    xs[k2]--
                } else {
                    answer.add(s[k2])
                    xs[k2]++
                    xs[k1]--
                }
            }
        }
    }
    if (possible) {
        println("Yes")
        println(answer.joinToString("\n"))
    } else {
        println("No")
    }
}

Measured memory_bytes: 48676
#include <algorithm>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>


using namespace std;


class Solution {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n; 
    int ar[n];
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
      in >> ar[ctr1];
    int sum = accumulate(ar, ar + n, 0);
    int rez = 0;
    for (int ctr1 = 1; ctr1 < n; ++ctr1)
      if (fabs(ar[ctr1] - 1.0 * sum / n) < fabs(ar[rez] - 1.0 * sum / n))
        rez = ctr1;
    out << rez;
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
// Powered by caide (code generator, tester, and library code inliner)


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>


#define MOD 1000000007

using namespace std;
using ll=long long;


ll mod_pow(ll x, ll n, ll m)
{
	ll ret = 1LL;
	for(;n>0;n>>=1)
	{
		if(n&1) ret=(ret*x)%m;
		x=(x*x)%m;
	}
	return ret;
}


ll mod_inv(ll x, ll m)
{
	return mod_pow(x, m-2, m)%m;
}


int nCr(int n, int r)
{
	ll x=1LL;
	ll y=1LL;
	for(int i=0;i<r;i++)
	{
		x=(x*(n-i))%MOD;
		y=(y*(i+1))%MOD;
	}
	return (x*mod_inv(y, MOD))%MOD;
}


int solve(int x, int y)
{
	int n=(x+y)/3;
	int a=x-n; // jump to (i+2, j+1)
	int b=y-n; // jump to (i+1, j+2);

	if(a<0 || b<0) return 0;
	if(x!=a*2+b || y!=a+b*2) return 0;
	if(a>b) swap(a, b);

	return nCr(n, a);
}


int main(void)
{
	int x, y;

	while(scanf("%d%d", &x, &y)==2)
	{
		printf("%d\n", solve(x, y));
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static long mod = 1000000007;
	
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int N = s.nextInt();
	boolean is = false;
	int[][] D = new int[N][2];
	for(int i = 0; i < N; i++){
		D[i][0] = s.nextInt();
		D[i][1] = s.nextInt();
	}

	for(int i = 0; i < N-2; i++){
		if((D[i][0]==D[i][1]) && (D[i+1][0]==D[i+1][1]) && (D[i+2][0]==D[i+2][1])){
			is = true;
		}
	}
	if(is){
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}
	
    
  }
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const double eps = (double)(1e-6);

double a, b, x;

double calc_radian(double deg) {
  return (deg / 360.0) * 2 * M_PI;
}

bool should_change(double deg) {
  double target_radian = calc_radian(deg);

  double tanjent_b_over_a = b / a;
  double limit_radian = atanl(tanjent_b_over_a);

  return (limit_radian - eps) <= target_radian;
}

double calc_before_limit(double deg) {
  double c = a * tanl(calc_radian(deg));

  double whole = a * a * b;

  double subtract_part = a * c * 0.5 * a;

  double ret = whole - subtract_part;

  // printf("deg: %lf, body: %lf\n", deg, ret);

  return ret;
}

double calc_after_limit(double deg) {
  double gamma = b * tanl(calc_radian(90.0 - deg));

  double ret = b * gamma * 0.5 * a;

  // printf("deg: %lf, body: %lf\n", deg, ret);

  return ret;
}

bool check(double deg) {
  if (should_change(deg)) {
    // printf("after\n");
    return (x - eps) <= calc_after_limit(deg);
  } else {
    // printf("before\n");
    return (x - eps) <= calc_before_limit(deg);
  }
}

int main(void) {
  // Here your code !
  scanf("%lf %lf %lf", &a, &b, &x);

  // [0.0, 90.0)
  double ok = 0.0;
  double ng = 90.0;

  for (int i = 0; i <= 200; ++i) {
    double next = (ok + ng) / 2.0;

    if (check(next)) {
      ok = next;
    } else {
      ng = next;
    }
  }

  double ans = ok;

  printf("%lf\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;

double calc(string s) {
	int sm = 0;
	REP(i, s.size()) {
		sm += s[i] - '0';
	}
	return stod(s) / sm;
}
string LLtoS(ll x) {
	string res;
	while (x > 0) {
		res += '0' + x % 10;
		x /= 10;
	}
	VREVERSE(res);
	return res;
}

string func(string n) {
	int N = n.size();
	int s = N - 1;//s+1~N-1まで全部9
	for (int i = N - 1; i >= 0; i--) {
		if (n[i] == '9') {
			s--;
		}
		else break;
	}
	//999...9のとき
	if (s == -1) {
		string str = "1";
		REP(i, N) {
			str += '0';
		}
		return func(str);
	}
	if (N == 1) {
		if (n[0] != '9');
		n[0]++;
		return n;
	}
	//X99...9のとき
	else if (s == 0) {
		ll pos = (ll)stod(n);
		pos++;
		string str=LLtoS(pos);
		//print(str);
		/*str+=n[0];
		str[0] += 1;
		FOR(i, 1, N) {
			str += "0";
		}*/
		//print(str)
		return func(str);
	}
	
	map<double, string>mp;
	double mn = (double)INF;
	//i桁目以降を全部9にする
	for (int i = s+1; i > 0; i--) {
		if (i >= N)continue;
		string str = n;
		for (int j = N - 1; j >= i; j--) {
			str[j] = '9';
		}
		while (str[i - 1] <= '9') {
			if (str != n) {
				double res = calc(str);
				mn = min(mn, res);
				mp[res] = str;
			}
			
			if(str[i-1]<'9')str[i - 1]++;
			//print(str);
			double res = calc(str);
			//pe(str)print(res);
			mn = min(mn, res);
			mp[res] = str;
			
			if (str[i - 1] == '9')break;
			
		}
	}
	//print(mn);
	return mp[mn];
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string res = "0";
	//print(func(res));
	int K; cin >> K;
	REP(i, K) {
		res = func(res);
		print(res);
	}
}

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

int main(){
	while(1){
		int t,d,l;
		cin >> t >> d >> l;
		if(t==0) break;
		
		vector<int> imos(t+1, 0);
		for(int i=0; i<t; i++){
			int x;
			cin >> x;
			if(x >= l){
				imos[i]++;
				imos[min(i+d, t)]--;
			}
		}
		int ans = 0;
		for(int i=0; i<t; i++){
			imos[i+1] += imos[i];
			if(imos[i] > 0 && i<t-1) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3432
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 78736
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());

  int cant = 0;
  ll sum = a[0];
  rep1(i, n - 1) {
    if(a[i] > sum * 2) {
      cant = i;
    }
    sum += a[i];
  }

  cout << n - cant << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define re(i,n) for(i=0;i<n;i++)
#define bre(i,n) for(i=n;i>0;i--)
#define rep(i,l,r) for(i=l;i<r;i++)
#define brep(i,l,r) for(i=r;i>l;i--)
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
template<int H,int W>int wa(int x1,int y1,int x2,int y2,int(&p)[H][W]){
	return p[y2][x2]-p[y2][x1]-p[y1][x2]+p[y1][x1];
}
struct Unif{
	vector<int> e;
	vector<int> rank;
	Unif(int n):e(n,-1),rank(n,1){}
	void uni(int a,int b){
		if(e[a]!=-1)
			uni(e[a],b);
		else if(e[b]!=-1)
			uni(a,e[b]);
		else{
			if(a==b)
				return;
			int ra=rank[a],rb=rank[b];
			if(ra>=rb){
				e[b]=a;
				if(ra==rb)
					rank[a]++;
			}
			else
				e[a]=b;
		}
	}
	bool find(int a,int b){
		if(e[a]!=-1)
			return find(e[a],b);
		else if(e[b]!=-1)
			return find(a,e[b]);
		else
			return a==b;
	}
	int num(int a){
		if(e[a]!=-1)
			return num(e[a]);
		else
			return a;
	}
};
int A,B,C,D,N,M,K,S,T,H,W;
signed main(){
	int i,j,k;
	cin>>N>>M;
	if(N==1&&M==1)
		cout<<1<<endl;
	else if(N==1||M==1)
		cout<<N*M-2<<endl;
	else
		cout<<(N-2)*(M-2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    char ch=getchar();
    int f=1;
    for (x=0;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
    if (ch=='-') f=-1,ch=getchar();
    for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
    x*=f;
}
typedef long long ll;
int n,p,u;
ll t,f[2];
int main()
{
	read(n),read(p);
	f[0]=1;
	for (int i=1;i<=n;i++)
	{
		read(u);
		if (u&1)
		{
			t=f[0];
			f[0]+=f[1];
			f[1]+=t;
		}
		else
		{
			f[0]+=f[0];
			f[1]+=f[1];
		}
	}
	printf("%lld",f[p]);
	return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, M;
	vector<int> A;
	vector<pair<int,int>> ans;
	int minimum = -INF, maximum = INF;
	
	cin>>N;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	}
	
	sort(A.begin(), A.end());
	
	minimum = A[0];
	maximum = A[N-1];
	
	for(int i = 1; i < N-1; i++){
		if(A[i] < 0){
			ans.push_back(make_pair(maximum,A[i]));
			maximum -= A[i];
		} else {
			ans.push_back(make_pair(minimum,A[i]));
			minimum -= A[i];
		}
	}
	
	ans.push_back(make_pair(maximum,minimum));
	cout<<maximum-minimum<<endl;
	
	for(int i = 0; i < N-1; i++){
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	}
	

	
	
	return 0;
}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K, R, S, P;
    cin >> N >> K;
    cin >> R >> S >> P;
    string T;
    cin >> T;
    vector<vector<int> > M(K, vector<int>(3, 0));
    int ans = 0;
    for (int i = 0; i < (int)T.size(); ++i) {
        if (i >= K && T[i] == T[i-K]) {
            T[i] = '?';
        }
        if (T[i] == 'r') {
            ans += P;
        } else if (T[i] == 's') {
            ans += R;
        } else if (T[i] == 'p') {
            ans += S;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 5200
gray = []
brown = []
green = []
w_blue = []
blue = []
yellow = []
orange = []
red = []
seq = []
N = int(input())
a = list(map(int,input().split()))
for i in a:
    if 1 <= i < 400:
        gray.append(i)
    elif 400 <= i < 800:
        brown.append(i)
    elif 800 <= i < 1200:
        green.append(i)
    elif 1200 <= i < 1600:
        w_blue.append(i)
    elif 1600 <= i < 2000:
        blue.append(i)
    elif 2000 <= i < 2400:
        yellow.append(i)
    elif 2400 <= i < 2800:
        orange.append(i)
    elif 2800 <= i < 3200:
        red.append(i)
    else:
        seq.append(i)

L = [gray,brown,green,w_blue,blue,yellow,orange,red]
ans = 0
for i in L:
    if len(i) >= 1:
        ans += 1
if ans != 0:
    print(ans,ans+len(seq))
else:
    print(1,len(seq))

Measured memory_bytes: 3064
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)
def lcm(a, b):
    return abs(a*b)//gcd(a, b)

n = int(input())
ans = int(input())
for i in range(1, n):
    t = int(input())
    ans = lcm(ans, t)
print (ans)

Measured memory_bytes: 62544
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int c[]=new int[26];
		int s[][] = new int[D][26];
		int t[]=new int[D];
		for (int i = 0; i < 26; i++) {
			c[i]=sc.nextInt();
		}
		for (int i = 0; i < D; i++) {
			for (int j = 0; j < 26; j++) {
				s[i][j]=sc.nextInt();
			}
		}
		for (int i = 0; i < D; i++) {
			t[i]=sc.nextInt();
		}
		int mannzokudo = 0;
		int last[]=new int[26];
		for (int i = 0; i <26; i++) {
			last[i]=0;
		}
		for (int d = 1; d <D+1; d++) {
			mannzokudo=mannzokudo+s[d-1][t[d-1]-1];
			last[t[d-1]-1]=d;
			for (int j = 0; j < 26; j++) {
				mannzokudo=mannzokudo-c[j]*(d-last[j]);
			}
			System.out.println(""+mannzokudo);
		}
	}
}

Measured memory_bytes: 47980
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;

#define MAX (int)1e5

typedef tuple<int,int,int> t;

int a[MAX];
int b[MAX];
t dis[MAX];

int main(void){
  int A,B,M;
  cin >> A >> B >> M;
  int minA,minB;
  minA = MAX;
  minB = MAX;
  for(int i=0;i<A;i++){
    cin >> a[i];
    if(a[i] < minA)
      minA = a[i];
  }

  for(int i=0;i<B;i++){
    cin >> b[i];
    if(b[i] < minB)
      minB = b[i];
  }

  for(int i=0;i<M;i++){
    int x,y,c;
    cin >> x >> y >> c;
    t tmp(x,y,c);
    dis[i] = tmp;
  }
  int min = minA + minB;
  //cout << min << endl;
  for(int i=0;i<M;i++){
    int xval = a[get<0>(dis[i])-1];
    int yval = b[get<1>(dis[i])-1];
    int c = get<2>(dis[i]);
    //cout <<xval << " " << yval << "" << c << endl;
    int num = xval + yval - c;
    if(num < min)
      min = num;
  }

  cout << min << endl;
  return 0;
  
}


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

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

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			List<Edge>[] lists = new ArrayList[n];
			for (int i = 0; i < n; i++) {
				lists[i] = new ArrayList<Edge>();
			}
			for (int i = 0; i < m; i++) {
				int from = scanner.nextInt() - 1;
				int to = scanner.nextInt() - 1;
				int cost = scanner.nextInt();
				lists[from].add(new Edge(to, cost));
				lists[to].add(new Edge(from, cost));
			}
			int g = n - 1;
			PriorityQueue<Edge> pq = new PriorityQueue<Edge>();
			pq.offer(new Edge(0, 0, 2));
			int[][] cost = new int[3][n];
			for (int i = 0; i < 3; i++)
				Arrays.fill(cost[i], 1 << 20);
			cost[2][0] = 0;
			while (!pq.isEmpty()) {
				Edge edge = pq.poll();
				if (edge.to == g && edge.ticket != 1) {
					System.out.println(edge.cost);
					break;
				}

				for (Edge e : lists[edge.to]) {
					if (edge.ticket == 1) {
						if (cost[0][e.to] > edge.cost) {
							cost[0][e.to] = edge.cost;
							pq.offer(new Edge(e.to, edge.cost, 0));
						}
					} else {
						if (edge.ticket == 2) {
							if (cost[1][e.to] > edge.cost) {
								cost[1][e.to] = edge.cost;
							pq.offer(new Edge(e.to, edge.cost, 1));}
						}
						if (cost[edge.ticket][e.to] > edge.cost + e.cost) {
							cost[edge.ticket][e.to] = e.cost + edge.cost;
							pq.offer(new Edge(e.to, edge.cost + e.cost,
									edge.ticket));
						}
					}
				}
			}
		}
	}

	class Edge implements Comparable<Edge> {
		int to, cost, ticket;

		public Edge(int to, int cost, int ticket) {
			super();
			this.to = to;
			this.cost = cost;
			this.ticket = ticket;
		}

		public Edge(int to, int cost) {
			super();
			this.to = to;
			this.cost = cost;
		}

		@Override
		public String toString() {
			return "Edge [to=" + to + ", cost=" + cost + ", ticket=" + ticket
					+ "]";
		}

		@Override
		public int compareTo(Edge o) {
			if (this.cost == o.cost)
				return o.to - this.to;
			return this.cost - o.cost;
		}

	}
}

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

int main() {
  int N;
  cin >> N;
  
  int digitSum=0;
  int w=N;
  
  while (w>0){
    digitSum += w % 10;
    w /= 10;
  }
  if ( (N % digitSum)==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=40005,INF=1<<30;
vector<int> prime;//i番目の素数
bool is_prime[MAX+1];

void sieve(int n){
    int p=0;
    for(int i=0;i<=n;i++){
        is_prime[i]=true;
    }
    
    is_prime[0]=is_prime[1]=false;
    
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                is_prime[j] = false;
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    sieve(MAX-2);
    
    int l,r;cin>>l>>r;
    
    vector<int> now(r-l+1),cnt(r-l+1);
    
    for(int i=l;i<=r;i++){
        now[i-l]=i;
    }
    
    for(auto p:prime){
        int s=(l-1)/p*p+p;
        for(int i=s;i<=r;i+=p){
            while(now[i-l]%p==0){
                now[i-l]/=p;
                cnt[i-l]++;
            }
        }
    }
    
    int ans=0;
    
    for(int i=0;i<r-l+1;i++){
        if(now[i]!=1) cnt[i]++;
        
        if(is_prime[cnt[i]]) ans++;
    }
    
    cout<<ans<<endl;
    
}




Measured memory_bytes: 10796
#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
double EPS = 0.00001;
int main(){
  while (1){
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0){
      break;
    }
    vector<vector<char>> p(h + 2, vector<char>(w + 2, '.'));
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        cin >> p[i][j];
      }
    }
    vector<vector<bool>> used(h + 2, vector<bool>(w + 2, false));
    vector<vector<int>> id(h + 2, vector<int>(w + 2, -1));
    int cnt = 0;
    for (int i = h; i >= 1; i--){
      for (int j = 1; j <= w; j++){
        if (!used[i][j] && p[i][j] != '.'){
          used[i][j] = true;
          queue<pair<int, int>> Q;
          Q.push(make_pair(i, j));
          while (!Q.empty()){
            int y = Q.front().first;
            int x = Q.front().second;
            Q.pop();
            id[y][x] = cnt;
            for (int k = 0; k < 4; k++){
              int y2 = y + dy[k];
              int x2 = x + dx[k];
              if (!used[y2][x2] && p[y2][x2] == p[i][j]){
                used[y2][x2] = true;
                Q.push(make_pair(y2, x2));
              }
            }
          }
          cnt++;
        }
      }
    }
    for (int j = 0; j <= w + 1; j++){
      id[h + 1][j] = cnt;
    }
    vector<int> pr(cnt, -1);
    vector<int> xL(cnt, w + 1);
    vector<int> xR(cnt, 0);
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        if (id[i][j] != -1 && id[i + 1][j] != -1 && id[i][j] != id[i + 1][j]){
          if (id[i][j] > 0){
            pr[id[i][j]] = id[i + 1][j];
          }
          xL[id[i][j]] = min(xL[id[i][j]], j);
          xR[id[i][j]] = max(xR[id[i][j]], j + 1);
        }
      }
    }
    vector<int> weight(cnt, 0);
    vector<double> sum(cnt, 0);
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        if (id[i][j] != -1){
          int v = id[i][j];
          while (1){
            weight[v]++;
            sum[v] += (j + 0.5);
            if (v == 0){
              break;
            }
            v = pr[v];
          }
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < cnt; i++){
      if (sum[i] < xL[i] * weight[i] + EPS){
        ok = false;
      }
      if (sum[i] > xR[i] * weight[i] - EPS){
        ok = false;
      }
    }
    if (ok){
      cout << "STABLE" << endl;
    } else {
      cout << "UNSTABLE" << endl;
    }
  }
}


Measured memory_bytes: 3180
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0;
        long ins = 1;
        while (h>0){
            ans+=ins;
            h/=2;
            ins*=2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35852
/*
  Fuad Ashraful Islam
  University of Asia Pacific,Bangladesh
  Date:15 th March 2020
  Todo--
*/
#include<bits/stdc++.h>
#define all(o) (o).begin(),(o).end()
using namespace std;

int n,k,m,tc,cs=1,len;
const int N=1e5+5;
typedef long long ll;
void scan(int &x)
{
  scanf("%d",&x);
}

vector<int>v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(nullptr); cout.tie(nullptr);
  cin>>n;
  cout<<v[n-1]<<endl;
 return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    s = input()
    k = int(input())
    one_count = 0

    for si in s:
        if si == '1':
            one_count += 1
        else:
            break

    if s[0] == '1':
        if k == 1:
            print(s[0])
        elif one_count >= k:
            print(1)
        elif one_count < k:
            print(s[one_count])
        else:
            print(s[1])
    else:
        print(s[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>

using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define inrange(n, lb, ub) ((lb)<=(n) && (n) <=(ub))
int rec(vector<vector<int>> &mos, int k, int xl, int yl, int xr, int yr) {
	int left = inrange(xr, 0, 2 * k - 1) && inrange(yl - 1, 0, 2 * k - 1) ? mos[xr][yl - 1] : 0;
	int up = inrange(xl - 1, 0, 2 * k - 1) && inrange(yr, 0, 2 * k - 1) >= 0 ? mos[xl - 1][yr] : 0;
	int corner = inrange(xl - 1, 0, 2 * k - 1) && inrange(yl - 1, 0, 2 * k - 1) ? mos[xl - 1][yl - 1] : 0;
	int body = inrange(xr, 0, 2 * k - 1) && inrange(yr, 0, 2 * k - 1) ? mos[xr][yr] : 0;
	return body - left - up + corner;
}
int main() {
	int n, k;
	cin >> n >> k;
	auto t = mat(int, 2 * k, 2 * k, 0);
	rep(i, n) {
		ll x, y;
		string c;
		cin >> x >> y >> c;
		if (c == "B") t[x % (2 * k)][y % (2 * k)]++;
		else t[(x + k) % (2 * k)][y % (2 * k)]++;
	}
	auto mos = t;
	rep(i, 2 * k)rep(j, 2 * k - 1)mos[i][j + 1] += mos[i][j];
	rep(i, 2 * k)rep(j, 2 * k - 1)mos[j + 1][i] += mos[j][i];
	int ma = 0;
	rep(i, k)rep(j, k) {
		int xl = i;
		int xr = i + k - 1;
		int yl = j;
		int yr = j + k - 1;
		int center = rec(mos, k, xl, yl, xr, yr);
		int upleft = rec(mos, k, 0, 0, xl - 1, yl - 1);
		int upright = rec(mos, k, 0, yr + 1, xl - 1, 2 * k - 1);
		int lowleft = rec(mos, k, xr + 1, 0, 2 * k - 1, yl - 1);
		int lowright = rec(mos, k, xr + 1, yr + 1, 2 * k - 1, 2 * k - 1);
		int num = center + upleft + upright + lowleft + lowright;
		ma = max({ ma, num, n - num });
	}
	cout << ma;
	return 0;

}





Measured memory_bytes: 31616
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int n , m;

int main(){
    cin >> n >> m;
    cout << ((n - m) * 100 + m * 1900) * (1 << m) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char a[2];
  char b[]="ACGT";
  int i,j=0;
  scanf("%c",a);
  for(i=0;i<4;i++){
    if(a[0]==b[i]) j=i;
  }
  printf("%c\n",b[3-j]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s;
    cin>>s;
    if(s=="RRR"){
        cout<<3<<endl;
    }
    else if(s=="RRS"||s=="SRR"){
        cout<<2<<endl;
    }
    else if(s=="SSS"){
        cout<<0<<endl;
    }
    else cout<<1<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {


	string s;
	cin >> s;

	int ans = 100000;
	for (int i = 0; i < s.size() - 2; i++) {
		int a = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0') * 1;
		CHMIN(ans,abs(a - 753));
	}

	COUT(ans);

	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	while (n--) {
		int a[3] = { 0 };
		for (int i = 0; i < 3; i++)cin >> a[i];
		sort(a, a + 3);
		if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}

	}
    return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<int> apple_pie(N);
  for (int i = 0; i < N; ++i)
    apple_pie[i] = L + i;
  int ans = 0, min_abs = 1000000000, minus = 0;
  for (int i = 0; i < N; ++i) {
    ans += apple_pie[i];
    if (abs(apple_pie[i]) < min_abs) {
      min_abs = abs(apple_pie[i]);
      minus = apple_pie[i];
    }
  }
  ans -= minus;
  cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = n - 1; i >= 0; i--){
    if(i == 0)
      cout << a[i];
    else
      cout << a[i] << " ";
  }
  cout << endl;
}


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

ll a, b, c;
ll ans;

int main() {
	cin >> a >> b >> c;
	ans += min(b, c), c -= ans, b -= ans, ans *= 2;
	ans += min(a, c), c -= min(a, c);
	if (c) ans += 1;
	ans += b, cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    rep(i, H) rep(j, W) cin >> s[i][j];
    
    bool judge = true;
    vector<int> dx = {0, 1, 0, -1};
    vector<int> dy = {1, 0, -1, 0};
    rep(i, H) rep(j, W) {
        if (s[i][j] == '.') continue;
        bool n = false;
        rep(k, 4) {
            if (0 <= i + dy[k] && i + dy[k] < H && 0 <= j + dx[k] && j + dx[k] < W) {
                if (s[i + dy[k]][j + dx[k]] == '#') n = true;
            }
        }
        if (n) continue;
        judge = false;
    }
    if (judge) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long dp[1<<20][20] = {};
int a[20],b[20];
int main(){
	int i,j,k,n;
	long long inf = 10000000000000;
	cin >> n;
	for(i=0;i<n;i++) cin >> a[i];
	for(i=0;i<n;i++) cin >> b[i];
	for(i=0;i<(1<<n);i++){
		for(j=0;j<n;j++){
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	for(i=0;i<n;i++){
		dp[(1<<i)][i] = 0;
	}
	for(i=0;i<(1<<n);i++){
		for(j=0;j<n;j++){
			if(!((1<<j) & i)) continue;
			int pos = 0;
			for(k=0;k<n;k++){
				if((1<<k) & i) pos++;
			}
			pos--;
			int num,d = (j^pos);
			if(d&1) num = b[j];
			else num = a[j];
			long long cnt = 0;
			for(k=0;k<n;k++){
				if(k==j) continue;
				if(!((1<<k) & i)) continue;
				if(k>j) cnt++;
			}
			for(k=0;k<n;k++){
				if(k==j) continue;
				if(!((1<<k) & i)) continue;
				int num2,d = (pos + 1)^k;
				if(d&1) num2 = b[k];
				else num2 = a[k];
				if(num2<=num){
					dp[i][j] = min(dp[i][j],dp[i^(1<<j)][k] + cnt);
				}
			}
		}
	}
	long long ans = inf;
	for(i=0;i<n;i++){
		ans = min(ans,dp[(1<<n) - 1][i]);
	}
	if(ans==inf){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
}

Measured memory_bytes: 43264
#include <iostream>

using namespace std;

int main (void)
{
    string str;
    bool alph[26];

    for (int i = 0; i < 26; i++) {
        alph[i] = false;
    }

    cin >> str;
    for (int i = 0; i < str.size(); i++) {
        alph[str[i] - 'a'] = true;
    }

    for (int i = 0; i < 26; i++) {
        if (alph[i] == false) {
            cout << (char)('a' + i) << endl;
            return 0;;
        }
    }
    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512