akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    H1, M1, H2, M2, K = Scanner.map_int()
    ans = (H2 - H1) * 60
    ans += (M2 - M1)
    ans = max(0, ans - K)
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    # print('YNEOS'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


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

int main(){
  int X, Y;
  cin >> X >> Y;
  int Ans=0;
  for(int i=0; i<=X; i++){
    if(2*i+4*(X-i)==Y){
      Ans=1;
    }
  }
  if(Ans==0){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second


int main(){
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
   int n, d;
   cin>>n>>d;
   int a[n][d];
   for(int i = 0;i<n;i++){
    for(int j = 0;j<d;j++){
        cin>>a[i][j];
    }
   }
   ll count = 0;
   float t = 0;
   for(int i = 0;i<n;i++){
    for(int j = i+1;j<n;j++){
        t = 0;
        for(int k = 0;k<d;k++){
          t += (a[i][k] - a[j][k])*(a[i][k]-a[j][k]);  
        }
        //cout<<()sqrt(t)<<" ";
        if((float)sqrt(t)*1.0 + 1 == (ll)sqrt(t) + 1){
            count++;
        }
    }
   }
   cout<<count;
	return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/arc087/tasks/arc087_a
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};

int main(){
    int N;
    cin>>N;
    map<int,int> m;

    for(int i:range(N)){
        int a;
        cin>>a;
        m[a]++;
    }
    int ret=0;
    for(auto &it:m){
        if(it.first<=it.second)ret+=it.second-it.first;
        else ret+=it.second;
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

double dist(double x, double y){
    return sqrt(x * x + y * y);
}

int main(){
    double R, X, Y;
    int N;
    while(cin >> R >> X >> Y >> N){
        vector<double> P(N + 1, 0);
        for(int i = 0; i < N; i++){
            cin >> P[i + 1];
            P[i + 1] = P[i + 1] / 100 * 2 * M_PI;
            P[i + 1] += P[i];
        }
        const int LOOP = 10000;
        for(int i = 0; i < N; i++){
            double ARG = P[i + 1] - P[i];
            double S = ARG * R * R / 2.0;
            double newS = 0;
            for(double p = P[i]; p < P[i + 1]; p += ARG / LOOP){
                double x1 = R * cos(M_PI/2.0 - p);
                double y1 = R * sin(M_PI/2.0 - p);
                double x2 = R * cos(M_PI/2.0 - (p + ARG/LOOP));
                double y2 = R * sin(M_PI/2.0 - (p + ARG/LOOP));
                newS += abs( (x1 - X) * (y2 - Y) - (x2 - X) * (y1 - Y) ) / 2.0;
            }
            printf("%d", int(newS/S*100 + EPS));
            if(i == N - 1) putchar('\n');
            else putchar(' ');
        }
    }
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> cnt(N + 1);
    for (int i = 1; i * i <= N; ++i) {
        for (int j = 1; j * j <= N; ++j) {
            for (int k = 1; k * k <= N; ++k) {
                int tmp = i * i + j * j + k * k;
                tmp += i * j + j * k + k * i;
                if (tmp <= N)
                    cnt[tmp]++;
            }
        }
    }

    for (int i = 1; i <= N; ++i)
        cout << cnt[i] << '\n';

    return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();

            int[] a = new int[M];
            int[] b = new int[M];

            for (int i = 0; i < M; i++) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
            }

            int[] count = new int[N + 1];
            for (int i = 0; i < M; i++) {
                count[a[i]]++;
                count[b[i]]++;
            }

            for (int i = 0; i < count.length; i++) {
                if (count[i] % 2 != 0) {
                    System.out.println("NO");
                    return;
                }
            }

            System.out.println("YES");

        }
    }
}


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

ll n, k;
vector<ll> T(MAX);

ll check(ll P) {
    ll i = 0;
    for( ll j = 0; j < k; j++) {
        ll s = 0;
        while( s + T.at(i) <= P) {
            s +=  T.at(i);
            i++;
            if( i == n ) return n;
        }
    }
    return i;
}

ll solve() {
    ll left = 0;
    ll right = 100000 * 10000;
    while(right - left > 1) {
        ll mid = (right + left) / 2;
        ll v = check(mid);
        if( v >= n ) right = mid;
        else left = mid;
    }

    return right;
}
int main() {
    cin >> n >> k;
    for(ll i = 0; i < n; i++) cin >> T.at(i);

    cout << solve() << endl;
    
    return 0;
}




Measured memory_bytes: 3468
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

const ll MOD = 1000000007;

ll imos[202020];
ll d[202020];

int main(){

    ll N;
    cin >> N;
    ll ans = 1;
    for(ll i = 1; i <= N; i++){
        ans = (ans * i) % MOD;
    }
    string S;
    cin >> S;
    S = "#" + S;
    for(ll i = 1; i < S.size(); i++){
        if(S[i] == 'W'){
            if(abs(imos[i]) % 2){
                d[i] = 1;
                imos[i] += 1;
                imos[i + 1] = imos[i];
            }
            else{
                d[i] = -1;
                imos[i] += 0;
                imos[i + 1] = imos[i] - 1;
            }
        }
        else{
            if(abs(imos[i]) % 2){
                d[i] = -1;
                imos[i] += 0;
                imos[i + 1] = imos[i] - 1;
            }
            else{
                d[i] = 1;
                imos[i] += 1;
                imos[i + 1] = imos[i];
            }
        }
    }
    ll tmp = 1;
    ll cnt = 0;
    for(ll i = 1; i < S.size(); i++){
        if(d[i] == 1){
            cnt++;
        }
        else{
            if(cnt <= 0)tmp = 0;
            tmp = (tmp * cnt) % MOD;
            cnt--;
        }
    }
    if(cnt != 0)tmp = 0;
    ans = (ans * tmp) % MOD;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n,k,c;
char s[200005];
set<int> st;
set<int> st2;
set<int> st3;
int main(){
	//freopen("in.txt","r",stdin);
	scanf("%d%d%d%s",&n,&k,&c,s);
	
	int cnt=0;
	for(int i=0;i<n;i++){
		if(s[i]=='o') {
			st.insert(i+1);
			cnt++;
			i+=c;
		}
		if(cnt>k) return 0;  //一定不存在必须工作的一天 
	}
	
	cnt=0;
	for(int i=n-1;i>=0;i--){
		if(s[i]=='o'){
			st2.insert(i+1);
			cnt++;
			i-=c;
		}
		if(cnt>k) return 0;  //一定不存在必须工作的一天 
	}
	set_intersection(st.begin(),st.end(),st2.begin(),st2.end(),ostream_iterator<int>(cout,"\n"));
	
	return 0;
}

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

bool ee[1001][1001] = {};

int main() {

    long long int n, m;
    cin >> n >> m;

    vector< vector< long long int > > e;
    for ( long long int i = 0; i < n; i++ ) {
        vector< long long int > ee;
        e.push_back( ee );
    }

    for ( long long int i = 0; i < m; i++ ) {
        long long int a, b;
        cin >> a >> b;
        a--;
        b--;
        e[a].push_back( b );
//        e[b].push_back( a );
        ee[a][b] = true;
        ee[b][a] = true;
    }

    for ( long long int i = 0; i < n; i++ ) {
        bool f[1001] = {};
        queue< vector< long long int > > q;
        vector< long long int > v;
        v.push_back( i );
        q.push( v );
        while( q.size() > 0 ) {
            vector< long long int > vv = q.front();
            q.pop();
            long long int k = vv.back();
            for ( long long int j = 0; j < e[k].size(); j++ ) {
                long long int p = e[k][j];
                if ( f[p] == true ) continue;
                if ( p == i ) {
                    bool ff = true;
                    for ( long long int x = 0; x < vv.size(); x++ ) {
                        long long int xx = vv[x];
                        for ( long long int y = 0; y < vv.size(); y++ ) {
                            if ( x - 1 <= y && y <= x + 1 ) continue;
                            if ( x == 0 && y == vv.size() - 1 ) continue;
                            if ( x == vv.size() - 1 && y == 0 ) continue;
                            long long int yy = vv[y];
//                            cout << "   " << xx << " " << yy << endl;
                            if ( ee[xx][yy] == true || ee[yy][xx] == true ) {
                                ff = false;
                                break;
                            }
                        }
                        if ( ff == false ) break;
                    }
                    if ( ff == true ) {
                        cout << vv.size() << endl;
                        for ( long long int x = 0; x < vv.size(); x++ ) {
                            cout << vv[x] + 1 << endl;
                        }
                        return 0;
                    }
                }
                f[p] = true;
                vv.push_back( p );
                q.push( vv );
                vv.pop_back();
            }
        }
    }

    cout << -1 << endl;

    return 0;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string S;
  cin >> S;
  int ans = 0;
  for (auto a : S) {
    if (a == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//B
		int x[] = new int[4];
		int y[] = new int[4];

		x[0] = sc.nextInt();
		y[0] = sc.nextInt();
		x[1] = sc.nextInt();
		y[1] = sc.nextInt();

		int disx = x[1] - x[0];
		int disy = y[1] - y[0];
		x[2] = x[1] - disy;
		y[2] = y[1] + disx;
		x[3] = x[2] - disx;
		y[3] = y[2] - disy;
		System.out.println(x[2] + " " + y[2] + " " + x[3] + " " + y[3]);
	}
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
from collections import deque
import copy

N, M, K = map(int, input().split())
friend = [deque() for _ in range(N)]
status = [-1]*N
numList = [0]*N
ans = [0]*N

for _ in range(M):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
    ans[a-1] -= 1
    ans[b-1] -= 1

def DFS(graph, v, num):
    cnt = 0
    stack = [v]
    status[v] = num
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if status[w] == -1:
                status[w] = num
                cnt += 1
                stack.append(w) 
        else:
            stack.pop() 
    numList[num] = cnt

cnt = 0
for i in range(N):
    if status[i] == -1:
        DFS(friend, i, cnt)
        cnt += 1

for i in range(N):
    ans[i] += numList[status[i]]

for i in range(K):
    a, b = map(int, input().split())
    if status[a-1] == status[b-1]:
        ans[a-1] -= 1
        ans[b-1] -= 1

print(" ".join(map(str, ans)))


Measured memory_bytes: 129628
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int W, H, N, x, y, xi, yi, distx, disty, sum, i;
	cin >> W >> H >> N;
	cin >> x >> y;
	sum = 0;
	for(i = 1; i < N; i++) {
		cin >> xi >> yi;
		distx = x - xi;
		disty = y - yi;
		if(distx >= 0 && disty >= 0) {
			sum += max( abs(distx), abs(disty) );
		} else if(distx < 0 && disty < 0) {
			sum += max( abs(distx), abs(disty) );
		} else {
			sum += abs(distx);
			sum += abs(disty);
		}
		x = xi;
		y = yi;
	}

	cout << sum << endl;

	return 0;

}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var Ai = new string[N];
            for (var i = 0; i < N; ++i)
                Ai[i] = ReadLine();
            var Bi = new string[M];
            for (var i = 0; i < M; ++i)
                Bi[i] = ReadLine();
            for (var h = 0; h <= N - M; ++h)
            {
                for (var w = 0; w <= N - M; ++w)
                {
                    var yes = true;
                    for (var m = 0; m < M; ++m)
                    {
                        if (Ai[h + m].Substring(w, (int)M) != Bi[m])
                        {
                            yes = false;
                            break;
                        }
                    }
                    if(yes)
                    {
                        WriteLine("Yes");
                        return;
                    }
                }
            }
            WriteLine("No");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <stdio.h>

int main()
{
    int number;
    scanf("%d", &number);
    int count = 0;
    while(number != 0)
        {
            int temp = number % 10;
            number = number/10;
            if(temp == 7)
            {
                printf("Yes\n") ;
                count = 1;
                break;
            }
        }
            if(count == 0)
            {
                printf("No\n") ;
            }
            return 0;
}


Measured memory_bytes: 1616
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    static const ll INF=0x3f3f3f3f3f3f3f3f;
    int A,B,Q;
    ll s[MAXN];
    ll t[MAXN];
    void test(){
        int a[]={2,3,4,5,6};
        int p=upper_bound(a,a+5,7)-a;
        DEBUG2(p,a[p]);
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>A>>B>>Q;
        for(int u=0;u<A;u++)cin>>s[u];
        for(int u=0;u<B;u++)cin>>t[u];
        while(Q--){
            ll x;
            cin>>x;
            ll ans=INF;
            int ps=lower_bound(s,s+A,x)-s;
            int pt=lower_bound(t,t+B,x)-t;
            if(ps<A&&pt<B)ans=min(ans,max(s[ps],t[pt])-x);
            if(ps>0&&pt>0)ans=min(ans,x-min(s[ps-1],t[pt-1]));
            if(ps>0&&pt<B)ans=min(ans,min(x-s[ps-1]+t[pt]-s[ps-1],t[pt]-x+t[pt]-s[ps-1]));
            if(ps<A&&pt>0)ans=min(ans,min(x-t[pt-1]+s[ps]-t[pt-1],s[ps]-x+s[ps]-t[pt-1]));
            cout<<ans<<"\n";
        }
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, n - 2)
	{
		rep2(j,i+1,n-1){
			rep2(k, j + 1, n) {
				if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k])
				{
					if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i])
					{
						ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}

struct UnionFindTree{
    vec par,size,rank,height;//par[i]:iの親,size[i]:iの属する木の要素数,rank[i]:iが、自分の属する木の何階層目にあるか,height[i]:iを根とする部分木の高さ
    int setNum;//木が何本あるか
    UnionFindTree(int n):par(n),size(n),rank(n),height(n){
        rep(i,n){
            par[i]=i;
            size[i]=1;
            rank[i]=-1;
            height[i]=1;
        }
        setNum=n;
    }
    int root(int x){
        if(par[x]==x)return x;
        return root(par[x]);
    }
    void unite(int x, int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry)return;
        if(height[rx]<height[ry]){
            par[rx]=ry;
            size[ry]+=size[rx];
        }else{
            par[ry]=rx;
            size[rx]+=size[ry];
            if(height[rx]==height[y]){
                height[rx]++;
            }
        }
        setNum--;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int getSize(int x){//xの属する木の要素数
        return size[root(x)];
    }
    int getSetNum(){//木の本数
        return setNum;
    }
    int getRank(int x){//xが何階層目にあるか
        if(par[x]==x)return 0;
        return getRank(par[x])+1;
    }
    int getHeight(int x){//xの属する木の高さ
        return height[root(x)];
    }
};
int main(){
    int n=in(),m=in();
    UnionFindTree uf(n);
    rep(i,m){
        int a=in(),b=in(),c=in();
        uf.unite(a-1,b-1);
    }
    int ans=0;
    rep(i,n)if(!uf.getRank(i))ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

long long cnt;
int l = 0;
int a[1000000];
int n;
int g[1000000];

void insertionSort(int a[],int n,int g);
void shellSort(int a[],int n);

int main(void)
{
	int n;
	scanf("%d",&n);
	
	int a[n];
	int i;
	for( i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	cnt = 0;
	shellSort(a,n);
	
	printf("%d\n",l);
	for( int i = l-1; i >= 0; i--)
	{
		printf("%d",g[i]);
		if(i)printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for( int i = 0; i < n; i++)printf("%d\n",a[i]);
	
	
	return 0;
}

void insertionSort(int a[], int n , int g)
{
	for( int i = g; i < n; i++)
	{
		int v = a[i];
		int j = i - g;
		while(j >= 0 && a[j] > v)
		{
			a[j+g] = a[j];
			j -= g;
			cnt++;
		}
		a[j+g] = v;
	}
}

void shellSort(int a[], int n)
{
	int i = 0;
	for( int h = 1;;)
	{
		if( h > n) break;
		g[i] = h;
		h = 3*h+1;
		i++;
		l++;
	}
	for( int j = i -1; j >= 0; j--)
	{
		insertionSort(a,n,g[j]);
	}
}



Measured memory_bytes: 5636
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct node {
  int key;
  struct node *parent,*left,*right;
}Node;
  
Node *root,*NIL;

void insert(int);
void inorder(Node *);
void preorder(Node *);
void delete(Node *);
Node * find(Node *,int);
Node * treeMinimum(Node *);
Node * treeSuccessor(Node *);

Node * treeMinimum(Node *x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node * treeSuccessor(Node *x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node *y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void delete(Node *z){
  Node *y;
  Node *x;

  if(z->left==NIL||z->right==NIL) y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }

  if(x!=NIL){
    x->parent=y->parent;
  }

  if(y->parent==NIL){
    root=x;
  }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }

  if(y!=z){
    z->key=y->key;
  }

  free(y);
}

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }

  z->parent=y;

  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node * find(Node *u,int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key){
      u=u->left;
    }else{
      u=u->right;
    }
  }
  return u; 
}

int main(){
  int m,i,x;
  char com[10];
  
  scanf("%d",&m);
  
  for(i=0;i<m;i++){
    scanf("%s",com);
    if(strcmp(com,"find")==0){
      scanf("%d",&x);
      Node *t=find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(strcmp(com,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }else if(strcmp(com,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(strcmp(com,"delete")==0){
	scanf("%d",&x);
	delete(find(root,x));
      }
  } 
  return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	int count = 0;
	rep(i, N-2) if(S.substr(i,3)=="ABC") count++;
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int A,B;
	cin >> A >> B;
	if (B % A == 0){
		cout << A + B << endl;
	}
	else{
		cout << B - A << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a;
    cin >> a;
    int ans = 3*a*a;
    cout << ans <<endl;
    return 0;

}

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

signed main() {
  int X; cin >> X;
  //vector<int> vec(N);

  int ans = 0;
  int x = 100;
  
  while(x<X) {
    x *= 1.01;
    ans++;
  }

  cout << ans << endl;

}

Measured memory_bytes: 3636
N = ARGF.gets.chomp.to_i
aa = ARGF.gets.chomp.split.collect {|el| el.to_i}

if aa.min <= 0
  mm = 0
else
  mm = 1
  aa.each do |ai|
    mm *= ai
    if 1000000000000000000 < mm
      mm = -1
      break
    end
  end
end
puts mm


Measured memory_bytes: 23504
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    h = get_li()
    highest = 0
    ans = 0
    for hi in h:
        if hi >= highest:
            ans += 1
            highest = hi
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5332
// finish date: 2018/03/10

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    vi a(N);
    ll ans = 0;
    map<int, int> indice, use;
    rep(i, N) {
        cin >> a[i];
        indice[a[i]] = i + 1;
    }
    use[0] = 0;
    use[N + 1] = 0;

    FOR(i, 1, N + 1) {
        auto itr = use.upper_bound(indice[i]);
        int right = itr->first;
        itr--;
        int left = itr->first;
        ans += (ll) i * (ll) (indice[i] - left) * (right - indice[i]);
        use[indice[i]] = 0;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 19840
import Data.Traversable
import Data.List


main = do
  ps <- for [1..3] $ \x -> do
    map read . words <$> getLine
  putStrLn $ if solve'' ps == True then "YES" else "NO"

solve'' :: [[Int]] -> Bool
solve'' ps =
  let ss = sort $ concat ps
      counts =  map (\x -> count x ss) [1..4]
  in count 2 counts == 2 && count 1 counts == 2

count _ [] = 0
count p (x:xs) = if p == x then 1 + (count p xs) else count p xs


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<int> v;
void fact(ll n)
{
    for(int i=1; i<=sqrt(n); i++)
    {
        if(n%i == 0)
        {
            v.push_back(i);
            if(n/i != i)
                v.push_back(n/i);
        }
    }
}
int main()
{

    ll n;
    cin>>n;
    int c = 0;
//    105 135 165 189 195

    if(n>=105)
        c++;
    if(n>=135)
        c++;
    if(n>=165)
        c++;
    if(n>=189)
        c++;
    if(n>=195)
        c++;

        cout<<c<<endl;
    return 0;
}




Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        string[] inputList = input.Split(' ');

        //string strA = inputList[0];
        //string strB = inputList[1];

        int A = int.Parse(inputList[0]);
        int B = int.Parse(inputList[1]);

        int ans = A - 2 * B;
        if (ans > 0)
        {
            Console.Write(ans);
        }
        else
        {
            Console.Write("0");
        }
            }
}

Measured memory_bytes: 13140
// インクルード
#include <bits/stdc++.h>

// 名前空間省略
using namespace std;

// メイン関数
int main()
{
	// 標準入出力　高速化
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;
	vector<int> a(n+1,0);

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

	for(int i=1;i<=n;i++){
		cout << a[i] << endl;
	}
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int i,s;
char a[500000],b;
int main(){
    while((b=getchar())!='\n'){
        s++;
        if(b=='S')
            a[i++]=b;
        if(b=='T')
            a[i++]=b;
        if(a[i-2]=='S'&&a[i-1]=='T'){
            s-=2;
            i-=2;
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 384
ans = []
while True:
    try:
        n = input()
    except EOFError:
        break
    if n == 0 or n >= 37:
        ans.append(0)
    else:
        count = 0
        for a in range(0,10):
            for b in range(0,10):
                for c in range(0,10):
                    for d in range(0,10):
                        if a+b+c+d == n:
                            count += 1
        ans.append(count)

for i in ans:
    print i

Measured memory_bytes: 4236
N=int(input())
pre_t=0
pre_x=0
pre_y=0
flg="Yes"
for i in range(N):
    t,x,y=map(int,input().split())
    dt=t-pre_t
    dist=abs(x-pre_x) + abs(y-pre_y)
    pre_t=t
    pre_x=x
    pre_y=y
    if(dist > dt ):
        flg="No"
        break
    if((dist)%2 != dt%2):
        flg="No"
        break
print(flg)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>

int main() {

	int a, b, c, d;
	std::cin >> a >> b >> c >> d;

	std::vector<int> alice(101, 0);
	std::vector<int> bob(101, 0);
	std::vector<int> res(101, 0);
	for (int i = a; i <= b; i++)alice[i]++;
	for (int i = c; i <= d; i++)bob[i]++;

	for (int i = 0; i < 101; i++) res[i] = alice[i] * bob[i];
	
	int ans = 0;
	for (int i = 0; i < 101; i++) ans += res[i];
	ans--;


	if (ans>0)std::cout << ans << std::endl;
	else std::cout << 0 << std::endl;


}

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

ll maxu(ll a,ll b)
{
    if(a>b)
    return a;
    else
    return b;
}

int main()
{
    ll t,i,j,k,n,W;
    cin>>n>>W;
    vector <ll> w(n);
    vector <ll> v(n);
    for(i=0;i<n;i++)
    cin>>w[i]>>v[i];
    
    ll ans[n+1][W+1];
    for(i=0;i<=n;i++)
    ans[i][0]=0;
    for(i=0;i<=W;i++)
    ans[0][i]=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=W;j++)
        {
            if(j-w[i-1]>=0)
            ans[i][j]=maxu(v[i-1]+ans[i-1][j-w[i-1]],ans[i-1][j]);
            else
            ans[i][j]=ans[i-1][j];
        }
    }
    cout<<ans[n][W]<<endl;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    string s;
    long long ans = 0;
    long long count = 0;
    long long r, g, b;
    r = g = b = 0;
    cin >> N  >> s;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') {
            r++;
        }else if (s[i] == 'G'){
            g++;
        }else if (s[i] == 'B'){
            b++;
        }
    }
    for (int i = 1; i <= N/2; i++){
        for (int j = 0; j + 2*i < N; j++) {
            if ((s[j] != s[j+i]) && (s[j+2*i] != s[j+i]) && (s[j] != s[j+2*i])) {
                count ++;
            }
        }
    }
    cout << r*g*b - count << endl;

}


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

using namespace std;

int main(void)
{
    int n, su = 0;
    scanf("%d", &n);
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
        su = su ^ arr[i];
    }
    printf("%d", arr[0] ^ su);
    for (int i = 1; i < n; i++)
    {
        printf(" %d", arr[i] ^ su);
    }
    printf("\n");
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			if((d-i*500-j*100>=0)&&(d-i*500-j*100<=c*50)){
				e++;
			}
		}
	}
	cout<<e<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
using namespace std;
inline int read(){int tot=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')tot=-1,c=getchar();
int sum=0;while(c<='9'&&c>='0')sum=sum*10+c-'0',c=getchar();return sum*tot;}
int fa[100005];
set<int> s[100005];
set<int>::iterator it;
map<pair<int,int>,int> mp;
queue<pair<int,int> > q;
int find(int x){
	if(fa[x]!=x)return fa[x]=find(fa[x]);
	return fa[x];
}
int main()
{
	int n=read();
	for(int i=1;i<=(n-1)*2;i++){
		int x=read(),y=read();
		s[x].insert(y);s[y].insert(x);
		mp[make_pair(x,y)]++;mp[make_pair(y,x)]++;
		if(mp[make_pair(x,y)]==2)q.push(make_pair(x,y));
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;q.pop();
//		cout<<x<<" "<<y<<endl;
		x=find(x),y=find(y);
		s[x].erase(y);s[y].erase(x);
		if(s[x].size()<s[y].size())swap(x,y);
		for(it=s[y].begin();it!=s[y].end();it++){
//			cout<<"aa";
			int j=(*it);
			s[j].erase(y);//s[y].earse(j)这样子写GG
			mp[make_pair(y,j)]=0;mp[make_pair(j,y)]=0;
			s[j].insert(x);s[x].insert(j);
			mp[make_pair(x,j)]++;mp[make_pair(j,x)]++;
			if(mp[make_pair(j,x)]==2)q.push(make_pair(j,x));
		}
		fa[y]=x;
        s[y].clear();//
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(fa[i]==i)sum++;
//		cout<<fa[i]<<" ";
	}
	if(sum==1)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 56576
n, p = map(int, input().split())
x = p
so = []
for i in range(2, int(p**(1/2))+1):
    c = 0
    while x%i==0:
        c += 1
        x //= i
    if c:
        so.append([c, i])
if x:
    so.append([1, x])
result = 1
for s, t in so:
    result *= t**(s//n)
print(result)

Measured memory_bytes: 3188
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

struct Dice{
  vector<int> D;
  string dir;
  int roll(int a, int b){
    int top = D.at(0);
    int front = D.at(1);
    for(auto c : dir){
      if(c == 'N'){
        top = D.at(1);
        D.at(1) = D.at(5);
        D.at(5) = D.at(4);
        D.at(4) = D.at(0);
        D.at(0) = top;
      }
      else if(c == 'E'){
        top = D.at(3);
        D.at(3) = D.at(5);
        D.at(5) = D.at(2);
        D.at(2) = D.at(0);
        D.at(0) = top;
      }
      else if(c == 'W'){
        top = D.at(2);
        D.at(2) = D.at(5);
        D.at(5) = D.at(3);
        D.at(3) = D.at(0);
        D.at(0) = top;
      }
      else if(c == 'S'){
        top = D.at(4);
        D.at(4) = D.at(5);
        D.at(5) = D.at(1);
        D.at(1) = D.at(0);
        D.at(0) = top;
      }
      else if(c == 'L'){
        front = D.at(2);
        D.at(2) = D.at(4);
        D.at(4) = D.at(3);
        D.at(3) = D.at(1);
        D.at(1) = front;
      }
      else if(c == 'R'){
        front = D.at(3);
        D.at(3) = D.at(4);
        D.at(2) = D.at(1);
        D.at(4) = D.at(2);
        D.at(1) = front;
      }
      if(D.at(0) == a && D.at(1) == b) return D.at(2);
    }
    return 0;
  }
};

int main(){
  Dice x;
  for(int i = 0; i < 6; i++){
    int a;
    cin >> a;
    x.D.push_back(a);
  }
  int q;
  cin >> q;
  x.dir = "LLLLNLLLLSWLLLLEELLLLWSLLLLNNNLLLL";
  for(int i = 0; i < q; i++){
    int a, b, c;
    cin >> a >> b;
    c = x.roll(a, b);
    cout << c << endl;
  }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int N, K; cin >> N >> K;
  int K2 = 2 * K;

  vector<vi32> sums(K2 + 1, vi32(K2 + 1));
  rep(i, N) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    x %= K2, y %= K2;
    if (c == 'W') x += K, x %= K2;
    sums[x + 1][y + 1]++;
  }
  repc(i, K2) rep(j, K2) sums[i][j + 1] += sums[i][j];
  rep(i, K2) repc(j, K2) sums[i + 1][j] += sums[i][j];

  int ans = 0;
  reps(i, K) reps(j, K) {
    int b = 0, w = 0;
    rep(k, 3) rep(l, 3) {
      int x0 = max(0, min(K2, i + (k - 1) * K - 1));
      int y0 = max(0, min(K2, j + (l - 1) * K - 1));
      int x1 = max(0, min(K2, i + (k - 0) * K - 1));
      int y1 = max(0, min(K2, j + (l - 0) * K - 1));

      if ((k + l) % 2 == 0) {
        b += sums[x1][y1] - sums[x1][y0] - sums[x0][y1] + sums[x0][y0];
      } else {
        w += sums[x1][y1] - sums[x1][y0] - sums[x0][y1] + sums[x0][y0];
      }
    }
    amax(ans, max(b, w));
  }
  cout << ans << '\n';
}


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

using namespace std;

#define ll long long
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NUint);
#define MAX 401

void start(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifndef ONLINE_JUDGE
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif

}

const ll INF = 1e18L + 5; // 10^18+5
ll dp[MAX][MAX];
// dp[i][j] - the minimum total cost of combining interval [i,j] into one vertex

int main() {
    // start();
    int n;
    cin>>n;
    vector<int> a(n);
    for(int& x : a) {
        cin>>x;
    }
    auto sum = [&](int L, int R) {
        ll s = 0;
        for(int i = L; i <= R; ++i) {
            s += a[i];
        }
        return s;
    };
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = 0;
            }
            else {
                dp[L][R] = INF;
                ll s = sum(L, R);
                for(int i = L; i <= R - 1; ++i) {
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + s);
                }
            }
        }
    }
    
    cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 1536
A, B=map(int, input().split())

def make_divisors(n):
  divisors = []
  for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n // i)
  #divisors.sort()
  return divisors

C = list(set(make_divisors(A)) & set(make_divisors(B)))
C.sort()

for i in range(1, len(C) - 1):
  a = C[i]
  for j in range(len(C) - 1, i, -1):
    if C[j] % a == 0:
      del C[j]
  if i + 1 >= len(C):
    break
    
print(len(C))

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

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef vector<ll> vll;

string s;
int main() {
	cin >> s;
	if(s[0] == s[1] && s[1] == s[2]) {
		puts("Yes");
		return 0;
	} else if(s[1] == s[2] && s[2] == s[3]) {
		puts("Yes");
		return 0;
	} else puts("No");
	return 0;
}

Measured memory_bytes: 256
c_1_1, c_1_2, c_1_3 = map(int, input().split())
c_2_1, c_2_2, c_2_3 = map(int, input().split())
c_3_1, c_3_2, c_3_3 = map(int, input().split())

ans = "No"
for a_1 in range(101):
  b_1 = c_1_1 - a_1
  b_2 = c_1_2 - a_1
  b_3 = c_1_3 - a_1
  for a_2 in range(101):
    if c_2_1 != a_2 + b_1:
      continue
    if c_2_2 != a_2 + b_2:
      continue
    if c_2_3 != a_2 + b_3:
      continue
    for a_3 in range(101):
      if c_3_1 != a_3 + b_1:
        continue
      if c_3_2 != a_3 + b_2:
        continue
      if c_3_3 != a_3 + b_3:
        continue
      ans = "Yes"
      break
    if ans == "Yes":
      break
  if ans == "Yes":
    break

print(ans)

Measured memory_bytes: 9128