akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S;
    cin >> S;
    int n = S.size();
    vint l(n + 1), r(n + 1);
    for (int i = 0; i < n; i++)
    {
        if (S[i] == '<')
            l[i + 1] = l[i] + 1;
        else
        {
            l[i + 1] = 0;
        }
    }
    for (int i = n - 1; i >= 0; i--)
    {
        if (S[i] == '>')
            r[i] = r[i + 1] + 1;
        else
        {
            r[i] = 0;
        }
    }
    ll sum = 0;
    for (int i = 0; i <= n; i++)
    {
        sum += max(l[i], r[i]);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 4764
import heapq

N = int(input())
V = list(map(int,input().split()))

heapq.heapify(V)

for _ in range(N-1):
    x = heapq.heappop(V)
    y = heapq.heappop(V)
    heapq.heappush(V,(x+y)/2)

print(V[0])

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

int main(){
    string s; cin >> s;
    int cnt1 = 0;
    int cnt2 = 0;

    for(int i=0; i<s.size(); i++){
        if(i%2 == 0){
            if(s[i] == '0') cnt1++;
            else cnt2++;
        }else{
            if(s[i] == '1') cnt1++;
            else cnt2++;
        }
    }

    cout << min(cnt1,cnt2) << endl;
}

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

result = 'No'
for i in range(1,10):
    q1, mod1 = divmod(N, i)
    if mod1 == 0:
        for j in range(i, 10):
           q2, mod2 = divmod(q1, j)
           if (q2 == 1) & (mod2 == 0):
                result = 'Yes'

print(result)

Measured memory_bytes: 3060
#

import sys
from copy import deepcopy
input=sys.stdin.readline

def main():
    N=int(input())
    P=list(map(int,input().split()))
    minn=max(P)
    cnt=0
    for i in range(N):
        if minn >= P[i]:
            cnt+=1
            minn=P[i]
    print(cnt)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 26228
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingDeque;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			int b_nums[] = new int[N];
			int x_nums[] = new int[N];
			int y_nums[] = new int[N];
			
			for(int i = 0; i < N; i++){
				b_nums[i] = sc.nextInt();
				x_nums[i] = sc.nextInt();
				y_nums[i] = sc.nextInt();
			}
			
			double adj[][] = new double[N][N];
			
			for(int i = 0; i < N; i++){
				for(int j = i+1; j < N; j++){
					if((x_nums[i] - x_nums[j])*(x_nums[i] - x_nums[j]) + (y_nums[i] - y_nums[j])*(y_nums[i] - y_nums[j]) <= 2500){
						adj[i][j] = adj[j][i] = Math.sqrt((x_nums[i] - x_nums[j])*(x_nums[i] - x_nums[j]) + (y_nums[i] - y_nums[j])*(y_nums[i] - y_nums[j]));
					}else{
						adj[i][j] = adj[j][i] = Integer.MAX_VALUE;
					}
				}
			}
			
			int M = sc.nextInt();
			for(int i = 0; i < M; i++){
				int start = sc.nextInt();
				int end = sc.nextInt();
				
				for(int j = 0; j < N; j++){
					if(b_nums[j] == start){
						start = j;
						break;
					} 
				}
				
				for(int j = 0; j < N; j++){
					if(b_nums[j] == end){
						end = j;
						break;
					} 
				}
				
				double costs[] = new double[N];
				boolean visited[] = new boolean[N];
				Arrays.fill(costs, Integer.MAX_VALUE);
				
				int prev[] = new int[N];
				
				costs[start] = 0;
				prev[start] = -1;
				
				for(int j = 0; j < N; j++){
					double min = Integer.MAX_VALUE;
					int min_num = -1;
					
					for(int k = 0; k < N; k++){
						if(!visited[k] && costs[k] < Integer.MAX_VALUE && min > costs[k]){
							min = costs[k];
							min_num = k;
						}
					}
					
					if(min_num == -1){
						break;
					}
					
					visited[min_num] = true;
					
					for(int k = 0; k < N; k++){
						if(!visited[k] && adj[min_num][k] + costs[min_num] < costs[k]){
							costs[k] = adj[min_num][k] + costs[min_num];
							prev[k] = min_num;
						}
					}
				}
				
				if(costs[end] < Integer.MAX_VALUE){
					StringBuilder b = new StringBuilder();
					int pos = end;
					b.append(b_nums[end]);
					while(prev[pos] != -1){
						b.insert(0," ");
						b.insert(0,b_nums[prev[pos]]);
						pos = prev[pos];
					}
					
					System.out.println(b);
				}else{
					System.out.println("NA");
				}
				
			}
			
		}
		
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

template<class T> inline bool chmax(T& a, T b) {
    // chmax: change maximum
    // a より b の方が大きかったら，a の値を b の値に置き換える．
    // 書き換えた場合，true を返す
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N;
    cin >> N;
    vector<vector<ll>> vec(N+1, vector<ll>(3));
    REP(i, N) {
        REP(j, 3) {
            cin >> vec[i+1][j];
        }
    }
    
    // calculation
    // init dp table
    vector<vector<ll>> dp(N+1, vector<ll>(3, 0));
    const ll A = 0, B = 1, C = 2;
    
    for (ll i = 0; i < N; ++i) {
        ll day = i+1;
        
        // dp[i][A]: i 日目に A を選んだ場合の幸福度の max
        // dp[i+1][B]: i+1 日目に B を選んだ場合の幸福度の max
        
        // i 日目に A を選んだとき
        chmax(dp[i+1][B], dp[i][A] + vec[day][B]);
        chmax(dp[i+1][C], dp[i][A] + vec[day][C]);
        
        // i 日目に B を選んだとき
        chmax(dp[i+1][A], dp[i][B] + vec[day][A]);
        chmax(dp[i+1][C], dp[i][B] + vec[day][C]);

        // i 日目に C を選んだとき
        chmax(dp[i+1][A], dp[i][C] + vec[day][A]);
        chmax(dp[i+1][B], dp[i][C] + vec[day][B]);


    }
    
    ll res = 0;
    REP(i, 3) chmax(res, dp[N][i]);
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 11136
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N,four=0,two=0,cur;
    cin >> N;
    REP(i,0,N){
        cin >> cur;
        if(cur%4==0){
            four++;
        }else if(cur%2==0){
            two++;
        }
    }
    //cout << four << " " << two << endl;
    if(two==0||two==1){
        two=0;
    }else{
        two=two-1;
    }
    if((N-two)/2<=four){
        P("Yes");
    }else{
        P("No");
    }    
}

Measured memory_bytes: 256
import re

s = input()

ans = [0] * len(s) 

t = -1

while len(s) > 0:
    r = re.search('R*', s)

    r_e = r.end()

    s = s[r_e:]

    l = re.search('L*', s)

    l_e = l.end()

    s = s[l_e:]

    r_ind = r_e + t

    l_ind = r_ind + 1

    ans[r_ind] = (r_e + 1) // 2 + l_e // 2
    ans[l_ind] = r_e // 2 + (l_e + 1)// 2

    t += r_e + l_e 

print(*ans)

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = input().split()
N = ''.join(N)
if '1' in N and '9' in N and '7' in N and '4' in N:
    print('YES')
else:
    print('NO')


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

bool flags[10];
int solved[1024][331];

int trans(){
  int a=0;
  for(int i=0;i<10;i++)
    a+= ( int(flags[i])<<i );
  return a;
}

int solve(int index,int sum,int max){
  int a=trans();
  if(sum < 0 || sum>330 || index > max){ return 0; } 
  if(index == max && sum == 0){
    return solved[a][0]=1;
  }

  if(solved[a][sum]!=-1) return solved[a][sum];
  int count=0;
  for(int i=0;i<10;i++){
    if(!flags[i]){
      flags[i]=true;
      int s=solve(index+1,sum-index*i,max);
      count+=s;
      flags[i]=false;
    }
  }
  return solved[a][sum]=count;
}

int main(){
  int n,s;
  while(cin>>n>>s){
    for(int i=0;i<1024;i++)
      for(int j=0;j<331;j++)
	solved[i][j]=-1;
    cout<<solve(1,s,n+1)<<endl;
  }
  return 0;
}

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

int main(void){
    int W,H;
    string dp[2][70];
    string line,ans;
    while(cin >> W >> H, W){
        /*
        for(int i=0;i<70;i++){
            dp[0][i].clear();dp[1][i].clear();
        }*/
        for(auto& i : dp[1]) i.clear();
        ans.clear();
        for(int i=0;i<H;i++){
            cin >> line;
            for(int j=0;j<W;j++){
                dp[i&1][j].clear();
                if(isdigit(line[j])){
                    if(dp[(i&1)^1][j]!="0"){
                        dp[i&1][j]=dp[(i&1)^1][j]+line[j];
                    }else{
                        dp[i&1][j].push_back(line[j]);
                    }
                    if(j!=0&&dp[i&1][j-1]!="0") dp[i&1][j]=max(dp[i&1][j],dp[i&1][j-1]+line[j],[](const string& a, const string& b){return a.size()==b.size()? a < b : a.size() < b.size();});
                    ans=max(dp[i&1][j],ans,[](const string& a, const string& b){return a.size()==b.size()? a < b : a.size() < b.size();});
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2980
from collections import Counter
import math
n,a,b = map(int,input().split())
v = sorted(list(map(int,input().split())))[::-1]
l = Counter(v)
su = 0
ko = 0

def C(a,b):
  return math.factorial(a)//(math.factorial(b)*math.factorial(a-b))
for i in range(a,b+1):
  v1 = v[:i]
  s = sum(v1)/i
  if su<s:
    su = s
    ko = C(l[v[a]],v1.count(v1[-1]))
  elif su==s:
    ko += C(l[v[a]],v1.count(v1[-1]))
 # print(s,ko)
print(su)
print(ko)

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

int main(){
    int n,m,c,ans=0;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0;i < m;i ++){
        cin >> b[i];
    }
    for(int i = 0;i < n;i ++){
        int s=0;
        for(int j = 0;j < m;j ++){
            int a;
            cin >> a;
            s += a*b[j];
        }
        if(s+c>0) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
//#define int          long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define mod      1000000007
#define MOD      998244353
#define mp       make_pair
#define pb       push_back
#define F        first
#define S        second
#define t()      int test;cin>>test;while(test--)
#define ii       pair<int,int>
#define endl     "\n"
#define que_max  priority_queue <int>
#define IOS      ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef tree < int ,  null_type ,  greater <int> ,  rb_tree_tag ,  tree_order_statistics_node_update > pbds;

int pw(int b, int p) { int r = 1; while (p > 0) { if (p & 1) r = r * b;
        p = p >> 1; b = b * b; } return r; }


int n,k;
vector <int> arr(1e5);
vector <int> dp(1e5 , -1);

int solve(int id)
{
    if(id == n-1)
        return 0;

    if(dp[id]!=-1)
    {
        return dp[id];
    }
    int ans = INT_MAX;

    for(int i = 1; i <= k; i++) {
        if(id + i >= n) break;
        ans = min(ans, solve(id + i) + abs(arr[id + i] - arr[id]));
    }

        return dp[id] = ans;
}
int main()
{
    cin>>n>>k;

    arr.resize(n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cout<<solve(0)<<endl;
}


Measured memory_bytes: 10308
#include<stdio.h>

int main(){
  char str[2];
  scanf("%s",&str);
  if(str[0]=='B' && str[1]=='B' && str[2]=='B'){
  printf("No");
  return 0;
  }
  if(str[0]=='A' && str[1]=='A' && str[2]=='A'){
  printf("No");
  return 0;
  }
  
  printf("Yes");
  return 0;


}

Measured memory_bytes: 128
#define d for(x=0;x<N;x++){for(y=0;y<N;y++
c,m[10][10],x,N;main(y){for(;scanf("%d",&N),N;){d)m[x][y]=(x+y)*(x+y+1)/2+1+(x+y&1?x:y);}printf("Case %d:\n",++c);d)printf("%3d",x+y<N?m[x][y]:N*N+1-m[N-1-x][N-1-y]);puts("");}}return 0;}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int m_x[4] = { 0, 0,-1, 1};
int m_y[4] = {-1, 1, 0, 0};

int main()
{
  string ans;
  cin >> ans;
  int c = ans.length()-1;
  if(ans[c]=='s')cout << ans << "es" << endl;
  else cout << ans << "s" << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){
    int i,j,k,l,n,m[100][100],p[100],a,q;
    
    scanf("%d",&n);
    for(i=0; i<n; i++) {
        if(i<n-1) scanf("%d%d",&p[i],&a);
        else scanf("%d%d",&p[i],&p[i+1]);
    }
    
    for(i=1; i<=n; i++) {
        for(j=1; j<=n; j++) m[i][j] = 0;
    }
    
    for(i=2; i<=n; i++) {
        for(k=1; k<=n-i+1; k++) {
            j = k+i-1;
            m[k][j] = 100000;
            for(l=k; l<j; l++) {
                q = m[k][l]+m[l+1][j]+p[k-1]*p[l]*p[j];
                if(m[k][j]>q) m[k][j] = q;
            }
        }
    }
    
    printf("%d\n",m[1][n]);
    
    return 0;
}

Measured memory_bytes: 636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;
double EPS = 1e-11;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

ll n, q;
ll s[200010], t[200010], x[200010];
ll d[200010];

void solve(){
  cin >> n >> q;
  rep(i, n) cin >> s[i] >> t[i] >> x[i];
  rep(i, q) cin >> d[i];
  set<pair<ll, ll>> F, S;
  rep(i, n){
    F.insert({s[i] - x[i], i});
    S.insert({t[i] - x[i], i});
  }
  set<pair<ll, ll>> now;
  rep(i, q){
    while(F.size() && F.begin()->f <= d[i]){
      pair<ll, ll> p = *F.begin();
      F.erase(p);
      now.insert({x[p.s], p.s});
    }
    while(S.size() && S.begin()->f <= d[i]){
      pair<ll, ll> p = *S.begin();
      S.erase(p);
      now.erase({x[p.s], p.s});
    }
    if(now.size() == 0) cout << -1 << endl;
    else cout << now.begin()->f << endl;
  }
}

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


Measured memory_bytes: 35072
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int height = sc.nextInt();
        int width = sc.nextInt();
        while(width != 0 || height != 0){
            StringBuilder sb = new StringBuilder();
            for(int w = 0; w < width; w++){
                sb.append('#');
            }
            for(int h = 0; h < height; h++){
                System.out.println(sb.toString());
            }
            System.out.println();
            height = sc.nextInt();
            width = sc.nextInt();
        }
    }
}



Measured memory_bytes: 27456
#include<iostream>
 
using namespace std;
int main()
{
	int N,a[210],ans=-1;
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> a[i];
	}
	bool flag = true;
	while(flag){
		for(int i=0; i<N; i++){
			if(a[i] % 2 != 0){
				 flag = false;
				break;
			}else{
				a[i] /= 2;
			}
		}
		ans++;
	}
	cout << ans << endl;
	
	
	return 0;
}

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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
#define x first
#define y second
#define point pair<double,double>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}

//you don't know math, unless you can do math!
ll OO= 1e15;
int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

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

    int n,w; cin>>n>>w;
    vector<int> weight(n), value(n);

    loop(i,n) cin>>weight[i]>>value[i];
    ll maxSum=0;

    loop(i,n) maxSum+= value[i];
    vector<ll> dp (maxSum+1, OO);

    dp[0]=0;
    for(int i=0; i < n; i++){
        for(int val = maxSum - value[i]; val >= 0; val--){
            dp[val + value[i]]= min(dp[val + value[i]], dp[val]+ weight[i]);
        }
    }

    ll mx=0;
    loop(i, sz(dp)){
        if(dp[i] <= w){
            mx= max(mx, (ll)i);
        }
    }

    cout<<mx;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;

ll gcd(ll a, ll b){ return b ? gcd(b, a%b) : a; }

int main()
{
	string s;

	while (cin >> s && s != "#"){

		vector<char> v;
		for (int i = 0; i < s.size();){
			if (s.substr(i, 4) == "west"){
				v.push_back('w'); i += 4;
			}
			if (s.substr(i, 5) == "north"){
				v.push_back('n'); i += 5;
			}
		}
		reverse(all(v));
		ll m = 0;
		rep(i, v.size()){
			if (v[i] == 'w'){
				m += 90LL * pow(2,(v.size() - i - 1));
			}
			else{
				m -= 90LL * pow(2,(v.size() - i - 1));
				if (m < 0)m = 0;
			}
		}
		
		int d = pow(2,v.size() - 1);
		int g = gcd(m, d);
		if (d / g == 1)cout << m / g << endl;
		else
		{
			cout << m / g << "/" << d / g << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1264
// 解き直し.
// https://img.atcoder.jp/agc010/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[101010], d[101010];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    LL k = 0, one = (LL)(N + 1) * (LL)N / 2;
    rep(i, N){
        scanf("%lld", &a[i]);
        k += a[i];
    }
    
    // 2. 操作回数を計算.
    if(k % one){
        puts("NO");
        return 0;
    }
    k /= one;
    
    // 3. 差分を計算.
    a[N] = a[0];
    rep(i, N) d[i] = a[i + 1] - a[i];
    
    // 4. (d[i] - k) を チェック.
    bool ans = true;
    rep(i, N){
        LL t = d[i] - k;
        if(t > 0 || t % N != 0){
            ans = false;
            break;
        }
    }
    
    // 4. 出力.
    printf("%s\n", ans ? "YES" : "NO");
    return 0;
    
}

Measured memory_bytes: 5296
using System;

class Test
{
    public static void Main()
    {
        string s = Console.ReadLine();
        string[] ss = s.Split(' ');
        
        int d;
        int r;
        double f;
        
        int a = int.Parse(ss[0]);
        int b = int.Parse(ss[1]);
        
        d = a / b;
        r = a % b;
        f = (double)a / (double)b;
        
        Console.WriteLine(d + " " + r + " " + Math.Round(f,5,MidpointRounding.AwayFromZero));
        
        
    }
}


Measured memory_bytes: 17972
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
bool pr[1000007];
void sieve(){pr[0]=1;pr[1]=1;for(int i=2;i<sqrt(1000007);i++){for(int j=2*i;j<=1000007;j+=i){pr[j]=1;}}}
ll fashtpower(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ull lopow(ll x,ll y){ull res=1ULL;while(y){if(y&1)res*=(ull)x;y>>=1;x*=x;}return res;}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string n;
	cin>>n;
	for(int i=0;i<n.length();i++){
		if(n[i]=='9'){
			cout<<"Yes";
			return 0;
		}
	}cout<<"No";
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;



int main(){
    int n;
        cin >> n;
    int cnt = 0;
        for(int i=1; i<=n; i+=2){
            int tmp = 1;
            for(int j=1; j<=i/2; j++)
                if(i%j==0) tmp += 1;
            if(tmp==8) cnt += 1;
        }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const int INF = 100100100;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl

int main(){
  string S; cin >> S;
  bool flag = true;
  int N = S.size();
  for(int i = 0; i < N; i += 2){
    if(S[i] == 'L') flag = false;
  }
  for(int i = 1; i < N; i += 2){
    if(S[i] == 'R') flag = false;
  }

  cout << (flag ? "Yes" : "No") << endl;

}

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

int main() {
	int byou, h, m, s;
	cin >> byou;
	h = byou / 3600;
	s = byou % 60;
	m = byou / 60 % 60;
	cout << h << ":" << m << ":" << s << endl;
	

}


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

const int N = 2e5 + 5;

int n, k, m, f[N], cnt[N], pos, mf, ans, y[N], tot, d[N], vis[N];
char a[N];

int main() {
	cin>>n>>k>>m>>(a + 1);
	for(int i = 1; i <= n; i++) {
		if(a[i] == 'x') continue;
		while(i - pos - 1 >= m && pos < i) {
			mf = max(mf, f[pos]);
			pos++;
		}
		f[i] = mf + 1;
		cnt[f[i]]++; 
		ans = max(ans, f[i]);
	}
	for(int i = 1; i <= n; i++)
	    if(a[i] == 'o') d[++tot] = i, y[i] = tot;
 	if(ans <= k) {
		for(int i = n; i; i--){
			if(a[i] == 'x') continue;
			int l = y[i] + 1, r = tot;
			while(l < r) {
				int mid = (l + r)/2;
				if(d[mid] - i - 1 >= m) r = mid;
				else l = mid + 1;
			}
			if(d[l] - i - 1 < m) {
				if(f[i] != ans) cnt[f[i]]--, vis[i] = 1;
			}
			else {
				if(f[d[l]] != f[i] + 1 || vis[d[l]]) cnt[f[i]]--, vis[i] = 1;
			}
		}
		for(int i = 1; i <= n; i++)
		    if(a[i] != 'x' && cnt[f[i]] == 1 && !vis[i]) cout<<i<<endl;
	}
}

Measured memory_bytes: 4864
n = list(input())

if n[0] == '1':
    n[0] = '9'
else:
    n[0] = '1'

if n[1] == '1':
    n[1] = '9'
else:
    n[1] = '1'

if n[2] == '1':
    n[2] = '9'
else:
    n[2] = '1'

print(n[0] + n[1] + n[2])

Measured memory_bytes: 3060
#include <stdio.h>
    int main(void){  
        
    int x,a,b,c,count;
    scanf("%d %d %d",&a,&b,&c);
    
    count = 0;
    
    for (  x =a; x <= b; x++){
    if(c%x == 0 ) {
        count++;
    }
    }
    
    
    printf("%d\n",count);
    
    
    
    
    return 0;
    
}




Measured memory_bytes: 2108
#include<stdio.h>
int main()
{	int a,b,c,i,sum,k,j,sum2,n;
	sum2=0;
	scanf("%d%d%d",&a,&b,&c);
	for(i=1;i<=a;i++)
	{	sum=0;
		j=i;
	while(j>=1)
	{
	 k=j%10;
	 sum=sum+k;
	 j=j/10;
	}
	if(sum>=b&&sum<=c) sum2=sum2+i;
	}
	printf("%d",sum2);
	return 0;
	
}

Measured memory_bytes: 128
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


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

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)

#n = ip()                                     #入力整数1つ
h,w= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
## a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
a=[input() for i in range(h)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
for i in range(h):
    for k in range(w):
        if a[i][k] == '#':
            fail = 1
            if i:
                if a[i - 1][k] == '#': fail = 0
            if i != h-1:
                if a[i + 1][k] == '#': fail = 0

            if k:
                if a[i][k - 1] == '#': fail = 0
            if k != w-1:
                if a[i][k + 1] == '#': fail = 0
            if fail:j(0)
j(1)



Measured memory_bytes: 13380
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll INF=1e9+7;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=1;
    rep(i,n-1){
        if(s[i+1]!=s[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){

  ll n;cin>>n;
  vector<vector<ll>> f(n,vector<ll>(10));
  vector<vector<ll>> p(n,vector<ll>(10));
  rep(i,n){
    rep(j,10){
      cin>>f[i][j];
    }
  }
  rep(i,n){
    rep(j,11){
      cin>>p[i][j];
    }
  }
  ll cnt=0;
  string s;
  ll ans=-INF,temp_ans=0;
  FOR(i,1,1024){
    temp_ans=0;
    s=(bitset<10>(i)).to_string();
    rep(j,n){
      cnt=0;
      rep(k,10){
        if(s[k]=='1'&&f[j][k]){
          cnt++;
        }
      }
      temp_ans+=p[j][cnt];
    }
    ans=max(temp_ans,ans);
  }

  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

#define WHATS(var)//cout<<__LINE__<<' '<<#var<<"="<<var<<endl;

template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
int i=0;
for(auto it:v){
	if(i > 0){os << ' ';}
	os << it;
	i++;
} 
return os;
}
/*
1 2 3 4 5 6 7 8 9 10 11 12 13 14

12 1 11
13 3 10
14 5 9
15 7 8
16 2 14
17 4 13
18 6 12

1-12

11 1 10
12 3 9
13 5 8
13 6 7
14 2 12
15 4 11
*/

using ll=long long ;




using Value=ll;
const Value ini =ll(1e18);
// Value operator +(const Value&al,const Value&ar){
// 	return al+ar;
// }
Value connect(Value al,const Value ar){
	return min(al,ar);
}
Value dat[400001];
struct segtree {
	int N;

	segtree() {}
	
	segtree(int n)  {
		N = 1;
		while (N < n) N *= 2;
		
		for(int x=0;x<N;++x){
			
			dat[x+N-1] = ini;
			
		}
		for(int x=N-2;x>=0;--x){
			dat[x]=connect(dat[x*2+1],dat[x*2+2]);
		}
	}
	// update k th element
	void update(int k,const Value& a) {
		 k += N - 1;
		dat[k] = a;
		
		while (k > 0) {
			k = (k - 1) >>1;
			dat[k]=connect(dat[k * 2 + 1],dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		return connect(query(a, b, k * 2 + 1, l, m),query(a, b, k * 2 + 2, m, r));
	}

	
};

int main() {
	ios::sync_with_stdio(false);
	int N,M;cin>>N>>M;
	vector<pair<int,pair<int,ll>>>qs;
	for(int i=0;i<M;++i){
		int l,r;ll c;
		cin>>l>>r>>c;
		qs.push_back(make_pair(l-1,make_pair(r,c)));
	}
	sort(qs.begin(),qs.end());
	segtree seg(N);
	seg.update(0,0);
	for(int i=0;i<M;++i){
		int l=qs[i].first;
		int r=qs[i].second.first;
		ll c=qs[i].second.second;
		ll amin=seg.query(l,r-1);
		seg.update(r-1,min(seg.query(r-1,r),amin+c));
	}
	ll answer=seg.query(N-1,N);
	if(answer>=ll(1e17))answer=-1;
	cout<<answer<<endl;
	return 0;
}

Measured memory_bytes: 5360
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

const int MAX_N = (int)1e5 + 5;
int parent[MAX_N], r[MAX_N];

void init(int n){
    for(int i=0;i<n;i++){
        parent[i] = i;
        r[i] = 0;
    }
}

int find(int x){
    if(parent[x] == x) return x;
    else return parent[x] = find(parent[x]);
}

void unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return;
    if(r[x]<r[y]) parent[x] = y;
    else{
        parent[y] = x;
        if(r[x] == r[y]) r[x]++;
    }
}


int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, M; cin >> N >> M;
    init(N);
    for(int i=0;i<M;i++){
        int x, y, z; cin >> x >> y >> z, x--, y--;
        unite(x, y);
    }

    unordered_set<int> S;
    for(int i=0;i<N;i++) S.emplace(find(i));
    cout << S.size() << endl;
    return 0;
}

Measured memory_bytes: 5156
N = int(input())
cnt = 0
tmp = ''
M = list(map(int,input().split()))
L = []
for x in M:
    if x == tmp:
        pass
    else:
        L.append(x)
    tmp = x
    

    
while True:
    try: 
        if L[0] <L[1]>L[2] or L[0] > L[1] <L[2]:
            a0=L.pop(0)
            a1=L.pop(0)
            cnt += 1
        else:
            L.pop(0)
    except:
        break
#    print(L)
print(1+cnt)



Measured memory_bytes: 14252
package main

import (
	"fmt"
	"sort"
)

func main() {
  
  Poll()
 
}

//Poll tedt
//Poll tedt
func Poll() {

	var N int

	fmt.Scan(&N)

	S := make([]string, N)

	m := make(map[string]int)

	for i := 0; i < N; i++ {

		fmt.Scan(&S[i])
	}

	for j := 0; j < len(S); j++ {

		count, ok := m[S[j]]

		if ok == true {

			m[S[j]] = count + 1

		} else {

			m[S[j]] = 0
		}

	}

	var list []string

	max := 0

	for _,value := range m{

		if max < value{
		   max = value
		}

	}

	for key,value := range m{

		if value ==max{

			list = append(list,key)
		}

	}
  
	sort.Sort(sort.StringSlice(list))

	for i := 0; i < len(list); i++ {

		fmt.Println(list[i])
	}
}

Measured memory_bytes: 35328
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


template<class T>
struct Sum2D{
    ll H,W;
    vector<vector<T>> f;
    Sum2D(ll h, ll w) : H(h), W(w), f(h+10,vector<T>(w+10,0)){}
    void add(ll x, ll y, T a){
        f[x+1][y+1]+=a;
    }
    void sum(){
        rep(x,H+1)rep(y,W+1) f[x][y+1]+=f[x][y];
        rep(x,H+1)rep(y,W+1) f[x+1][y]+=f[x][y];
    }

    T get(ll sx, ll sy, ll gx, ll gy){
        return f[gx][gy]-f[sx][gy]-f[gx][sy]+f[sx][sy];
    }

    void print(){
        rep(i,H+1){
            rep(j,W+1){
                cerr<<f[i][j]<<" ";
            }
            cerr<<endl;
        }
    }

};



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,k;
    cin>>n>>k;
    Sum2D<ll> sum(4*k,4*k);
    rep(i,n){
        ll x,y;
        char c;
        cin>>x>>y>>c;
        if(c=='W') y+=k;
        x%=2*k;y%=2*k;
        sum.add(x,y,1);
        sum.add(x+2*k,y,1);
        sum.add(x,y+2*k,1);
        sum.add(x+2*k,y+2*k,1);
    }
    // sum.print();
    sum.sum();
    cout<<endl;
    // sum.print();
    ll ans=0;
    rep(i,2*k){
        rep(j,2*k){
            ans=max(ans,sum.get(i,j,i+k,j+k)+sum.get(i+k,j+k,i+2*k,j+2*k));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 128128
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
    int x;
    cin>> x;
    if(x >= 30)
        cout<< "Yes\n";
    else
        cout<< "No\n";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3668
#include<stdio.h>

int A[2000], n;

int solve(int, int);

int main(){

  int q, i, m;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    scanf("%d",&A[i]);

  scanf("%d", &q);

  for(i = 0; i < q; i++){
    scanf("%d", &m);

  if(solve(0, m))
    printf("yes\n");
  else printf("no\n");
  }

  return 0;
}

int solve(int i, int m){

  int res;

  if(m == 0)
    return 1;

  if(i >= n)
    return 0;

  res = solve(i + 1, m) || solve(i + 1, m - A[i]);

  return res;
}



Measured memory_bytes: 2108
import numpy as np
n,m = map(int,input().split())
k = np.zeros(n,dtype=int)
a = np.zeros((n,m),dtype=int)
for i in range(n):
    p = list(map(int, input().split()))
    k[i] = p[0]
    for j in range(1,len(p)):
        a[i][j-1] = p[j]
ans = np.zeros(n+m,dtype=int)
for i in range(n):
    for j in range(m):
        if a[i][j] != 0:
            s = a[i][j]-1
            ans[s] += 1
an = 0
for i in range(n+m):
    if ans[i] == n:
        an += 1
print(an)

Measured memory_bytes: 26988
#include "bits/stdc++.h"
using namespace std;
int main(){
	string s;cin>>s;
	int k;cin>>k;--k;
	for (int i=0; i<=k; ++i)if (s[i]!='1'){
		cout<<s[i];
		return 0;
	}
	cout<<1;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i, j, k, n, m, l;
        while(true) {
        	String d = sc.next();
	        char[] a = d.toCharArray();
	        if(d.equals("-"))break;
	        n = a.length;
	        char[] c = new char[n];
	        m = sc.nextInt();
	        for(i = 0; i < m; i++) {
	        	k = 0;
	        	l = sc.nextInt();
		        char[] b = new char[l];
	        	for(j = 0; j < l; j++) {
		        	b[j] = a[j];
		        }
		        for(j = l; j < n; j++) {
			    	c[k] = a[j];
			    	k++;
			    }
		        for(j = 0; j < l; j++) {
			        c[k] = b[j];
			        k++;
			    }
		        for(j = 0; j < n; j++) {
		        	a[j] = c[j];
		        }
	        }
	        for(i = 0; i < n; i++) {
	        	System.out.print(a[i]);
	        }
        	System.out.println();
        }
        sc.close();
    }
}


Measured memory_bytes: 26292
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    LL X;
    cin >> X;

    LL N = (LL)(-1 + round(sqrt(1+8*X))) / 2;

    while(true){
        if(N*(N+1) == 2*X){
            cout << N << endl;
            return 0;
        }

        if(N*(N+1) < 2*X && (N+1)*(N+2) > 2*X){
            cout << N + 1 << endl;
            return 0;
        }

        if(N*(N+1) < 2*X){
            N++;
        }

        if(N*(N+1) > 2*X){
            N--;
        }
    }

    return 0;


}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[114514];
ll b[114514];
ll dp[114514];
signed main() {
	ll n, m;
	cin >> n >> m;
	rep(i, m)cin >> a[i];
	rep(i, n+1)dp[i] = inf;
	rep(i, m) {
		dp[a[i]] = 0;
	}
	dp[0] = 1;
	if (dp[1] != 0)dp[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (dp[i] == inf) {
			dp[i] = dp[i - 2] + dp[i - 1];
			dp[i] %= 1000000007;
		}
	}
	cout << dp[n] << endl;
	ggr
}


Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    t = S()
    cnt = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            cnt += 1
    print(cnt)

main()



Measured memory_bytes: 78976
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		while(true){
			String in=s.next();
			if(in.equals("#"))System.exit(0);
			String[]str=in.split("\\|");
			boolean ok=false;
			for(int i=0;i<str.length;i++){
				String now=str[i].substring(1,str[i].length()-1);
				String tmp[]=now.split("\\&");
				boolean OK=true;
				for(int j=0;j<tmp.length;j++)for(int k=0;k<tmp.length;k++){
					if(tmp[k].equals("~"+tmp[j]))OK=false;
				}
				if(OK)ok=true;
			}
			if(ok)System.out.println("yes");
			else System.out.println("no");
		}
	}
}

Measured memory_bytes: 71608
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int gcd(int a,int b){
	if(!b) return a;
	return gcd(b,a%b);
}

int n;
vi a;

vi f(){
	vi b(n);
	int x=0;
	for(int i=1;i<n;i++){
		x=gcd(x,a[i-1]);
		b[i]=x;
	}
	reverse(a.begin(),a.end());
	return b;
}

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	vi b=f(),c=f();
	int res=0;
	for(int i=0;i<n;i++) res=max(res,gcd(b[i],c[n-i-1]));
	cout<<res<<endl;
}

Measured memory_bytes: 1408