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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  string s;
  cin>>s;
  sort(ALL(s));
  cout<<(s[0]!=s[2] ? "Yes" : "No")<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>


using namespace std;

int solve(int n, int m) {
    if (n <= m)
      return 1;

    return std::ceil((n - m) / (m - 1.0)) + 1;
}

int main () {
    int n, m;
    cin >> n >> m;
    
    cout << solve(n, m) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
int n,m,res,cnt,a[505][505],b[2500005][4];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]&1){
				if(i<n&&a[i+1][j]&1){
					a[i][j]--;
					a[i+1][j]++;
					b[++cnt][0]=i;
					b[cnt][1]=j;
					b[cnt][2]=i+1;
					b[cnt][3]=j;
				}else if(j<m&&a[i][j+1]&1){
					a[i][j]--;
					a[i][j+1]++;
					b[++cnt][0]=i;
					b[cnt][1]=j;
					b[cnt][2]=i;
					b[cnt][3]=j+1;
				}else if(i<n){
					a[i][j]--;
					a[i+1][j]++;
					b[++cnt][0]=i;
					b[cnt][1]=j;
					b[cnt][2]=i+1;
					b[cnt][3]=j;
				}else if(j<m){
					a[i][j]--;
					a[i][j+1]++;
					b[++cnt][0]=i;
					b[cnt][1]=j;
					b[cnt][2]=i;
					b[cnt][3]=j+1;
				}
			}
		}
	}
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;i++){
		printf("%d %d %d %d\n",b[i][0],b[i][1],b[i][2],b[i][3]);
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;
const int mod = (int)1e9 + 7;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

int fact[N];
int seen[N];
int inp[N];

int P(int a, int b){
    int ret = 1;
    while(b > 0){
        if(b & 1){
            ret = 1ll * ret * a % mod;
        }
        b /= 2;
        a = 1ll * a * a % mod;
    }
    return ret;
}

int nCr(int n, int r){
    if(r > n) return 0;
    int up = fact[n];
    int down = 1ll * fact[r] * fact[n - r] % mod;
    int ret = 1ll * up * P(down, mod - 2) % mod;
    return ret;
}

int main(){
    int n = in();
    for(int i = 1; i <= n + 1; i++){
        inp[i] = in();
    }
    fact[0] = 1;
    for(int i = 1; i <= n + 1; i++){
        fact[i] = 1ll * fact[i - 1] * i % mod;
    }
    int r = 1;
    for(int i = 1; i <= n + 1; i++){
        if(seen[inp[i]] == 1){
            r = i;
            break;
        }
        seen[inp[i]] = 1;
    }
    memset(seen, 0, sizeof seen);
    int l = n + 1;
    for(int i = n + 1; i >= 1; i--){
        if(seen[inp[i]] == 1){
            l = i;
            break;
        }
        seen[inp[i]] = 1;
    }
    //cout << l << " " << r << '\n';
    printf("%d\n", n);
    for(int i = 2; i <= n + 1; i++){
        int ans = nCr(n + 1, i) - nCr(n - (r - l), i - 1);
        ans %= mod; ans += mod; ans %= mod;
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,k;
  cin >> n >> k;
  vec a(n);
  ll x=inf;
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    x=min(x,a[i]);
  }
  ll cnt=0;
  ll ans=0;
  for(ll i=0;i<n;i++) {
    if(a[i]==x) {
      ans+=(cnt+k-2)/(k-1);
      if(i<(cnt+k-2)/(k-1)*(k-1)) {
        i=(cnt+k-2)/(k-1)*(k-1);
      }
      cnt=0;
    }
    else {
      cnt++;
    }
  }
  ans+=(cnt+k-2)/(k-1);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
 
using namespace std;
 
typedef long long ll;
 
int main() {
    ll n, sum = 0ll;
    
    cin >> n;
 
    for(ll x = 1; x <= n; x++) {
        if(x%3 && x%5)
            sum += x;
    }
    cout << sum;
}

Measured memory_bytes: 3192
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int length = arr.length;
		int[][] dp = new int[length + 1][13];
		dp[0][0] = 1;
		for (int i = 1; i <= length; i++) {
		    char c = arr[i - 1];
		    for (int j = 0; j < 10; j++) {
		        if (c == '?' || c - '0' == j) {
    		        for (int k = 0; k < 13; k++) {
    		            dp[i][(k * 10 + j) % 13] += dp[i - 1][k];
    		            dp[i][(k * 10 + j) % 13] %= MOD;
    		        }
		        }
		    }
		}
		System.out.println(dp[length][5]);
   }
}




Measured memory_bytes: 31224
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
ll a[600000], vs[6000000], vs1[4000000], fs[500][500];
map<int,int>mp;

int main()
{
    IO;
    ll j=0, n, m, k, m1, m2, a1=0, a2=0, l  = 1, t=3, mn, cnt=0, mx=0, h=0, mod=1e8+7, i; int tc=0;
    //cin>>t;
    //while(t--){
        cin>>n;
        for(i=1; i<=n; i++) {
            cin>>a[i]; a1=max(a1,a[i]);
            vs[a[i]]++;
        }
        sort(a+1,a+n+1);
        for(i=1; i<=n; i++){
            if(vs[a[i]]==1){
                cnt++;
            }
        if(!vs1[a[i]]){
            for(j=a[i]*2; j<=a1; j+=a[i]) { vs1[j]=1; vs[j]++; }
            vs1[a[i]]=1;
        }
        }
        cout<<cnt<<endl;
    //}
    return 0;
}



Measured memory_bytes: 20808
#include <bits/stdc++.h>
using namespace std;
 
int main() { 
  
  int N, K, num;
  num = 1;
  cin >> N >> K;
  
  for(int i = 0;i < N;i++){
    if(num * 2 <= num + K){
    num = num * 2;
    }
    else{
    num = num + K; 
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int mArr[] = new int[n];
        int cnt = 0;

        for (int i = 0; i < mArr.length; i++) {
            mArr[i] = sc.nextInt();
        }

        Arrays.sort(mArr);

        for (int i : mArr) {
            x -= i;
            cnt ++;
        }
        cnt += x / mArr[0];
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
int main(){
	cin >> n;
	ll ans = 1000000000000;
	FOR(i,1,n) {
		ll a = i,b = n - i;

		ll aa = 0 ,bb = 0;

		while(a > 0 ) {
			aa += a % 10;
			a /= 10;
		}

		while(b > 0 ) {
			bb += b % 10;
			b /= 10;
		}

		ans = min (ans,aa + bb);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[M];
		
		for(int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}
		
		for(int i = 0; i < M; i++) {
			y[i] = sc.nextInt();
		}
		
		Arrays.sort(x);
		Arrays.sort(y);
		
		if((y[0] <= Y) && (y[0] > X) && (x[N - 1] < y[0])) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}
		
	}
}


Measured memory_bytes: 22736
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
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

def comb_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

N = INT()
S = ["".join(sorted(input())) for _ in range(N)]

dic = defaultdict(int)
for x in S:
	dic[x] += 1

wa = 0
for n in dic.values():
	wa += int(n*(n - 1)/2)

print(wa)

Measured memory_bytes: 21516
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;

int main() {
  int T, X;
  cin >> T >> X;
  double ans = (double)T / X;
  cout << setprecision(20) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    string s,t;
    cin >> s >> t;
    ll N = s.size();
    ll M = t.size();
    string ss = s + s;
    vector<ll> v[26];
    rep(i,N*2){
        v[ss[i]-'a'].push_back(i);
    }
    ll ans = 0;
    ll cur = 0;
    rep(i,M){
        ll c = t[i] - 'a';
        auto itr = lower_bound(v[c].begin(), v[c].end(), cur);
        if(itr == v[c].end()){
            cout << -1 << endl;
            return 0;
        }
        ll q = *itr - cur +1;
        ans += q;
        cur = *itr;
        cur++;
        if(cur > N){
            cur -= N;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5820
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);

  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      if (i * 4 + j * 7 == n) {
        writeln("Yes");
        return;
      }
    }
  }
  writeln("No");
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 310
#define MOD 1000000007

int dp[maxn][2][maxn][maxn];

int mn[4][maxn],mx[4][maxn];

int N,M;
vi vect;


int dpf(int idx,int prevC,int prev,int prev2){
	if (dp[idx][prevC][prev][prev2] != -1) return dp[idx][prevC][prev][prev2];
	

	if (idx > N) return 1;
	int R,G,B;
	if (prevC == 1){
		R = idx - 1;
		G = prev;
		B = prev2;
	}
	if (prevC == 2){
		R = prev;
		G = idx-1;
		B = prev2;
	}
	if (prevC == 3){
		R = prev;
		G = prev2;
		B = idx-1;
	}
	
	if (prevC == 0){
		R = G = B = 0;
	}
	vect.clear();
	vect.pb(R),vect.pb(G),vect.pb(B);

	vi poss;
	//cout<<idx<<' '<<R<<' '<<G<<' '<<B<<'\n';

	bool yes;
	FOR(i,1,3){
		yes = 1;
		FOR(j,1,3){
			if (mx[j][idx] == -1) continue;
			int num = 0;
			//num of colors from mx[j][idx] to idx-1
			
			aFOR(k,vect) if (k != 0 && mx[j][idx] <= k) num++;
			
			if (vect[i-1] != 0 && mx[j][idx] > vect[i-1]) num++;
			if (vect[i-1] == 0) num++;
			
			if (num != j) yes = 0;
			
			num = 0;
			//num of colors from mn[j][idx] to idx-1
			
			aFOR(k,vect) if (k != 0 && mn[j][idx] <= k) num++;
			
			if (vect[i-1] != 0 && mn[j][idx] > vect[i-1]) num++;
			if (vect[i-1] == 0) num++;
			
			if (num != j) yes = 0;
		}
		
		if (yes) poss.pb(i);
	}

	dp[idx][prevC][prev][prev2] = 0;
	aFOR(i,poss){
		if (i == 1){
			//~ cout<<idx+1<<' '<<i<<' '<<G<<' '<<B<<'\n';
			//~ continue;
			dp[idx][prevC][prev][prev2] += dpf(idx+1,1,G,B);
			dp[idx][prevC][prev][prev2] %= MOD;
		}
		if (i == 2){
			//~ cout<<idx+1<<' '<<i<<' '<<G<<' '<<B<<'\n';
			//~ continue;
			dp[idx][prevC][prev][prev2] += dpf(idx+1,1,R,B);
			dp[idx][prevC][prev][prev2] %= MOD;
		}
		if (i == 3){
			//~ cout<<idx+1<<' '<<i<<' '<<G<<' '<<B<<'\n';
			//~ continue;
			dp[idx][prevC][prev][prev2] += dpf(idx+1,1,R,G);
			dp[idx][prevC][prev][prev2] %= MOD;
		}
		
	}
	return dp[idx][prevC][prev][prev2];
			
	
}
	
int32_t main(){
	fast;
	
	cin>>N>>M;
	
	mem(mx,-1);
	mem(mn,-1);
	
	FOR(i,0,M-1){
		int a,b,c;
		cin>>a>>b>>c;
		
		if (mn[c][b] == -1) mn[c][b] = a;
		else mn[c][b] = min(mn[c][b],a);
		mx[c][b] = max(mx[c][b],a);

	}
	

	mem(dp,-1);
	cout<<dpf(1,0,0,0);
	

	

			
	
}



Measured memory_bytes: 233088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> adj[N];
    int r[K][3]{};
    for (int i = 0; i < K; i++) {
        cin >> r[i][0] >> r[i][1] >> r[i][2];
        if (r[i][0] == 1) {
            r[i][1]--;
            r[i][2]--;
        } else {
            r[i][1]--;
        }
    }
    int g[N]{};
    for (int i = 0; i < K; i++) {
        if (r[i][0] == 1) {
            int a = r[i][1];
            int b = r[i][2];
            if (g[a] != 0 && g[b] != 0 && g[a] != g[b]) {
                cout << i + 1 << "\n";
                return 0;
            }
            adj[r[i][1]].push_back(r[i][2]);
            adj[r[i][2]].push_back(r[i][1]);
            deque<int> q;
            if (g[a] != 0 && g[b] == 0) {
                g[b] = g[a];
                q.push_back(a);
            }
            if (g[b] != 0 && g[a] == 0) {
                g[a] = g[b];
                q.push_back(b);
            }
            int x = g[a];
            while (!q.empty()) {
                int u = q.front();
                q.pop_front();
                for (int j = 0; j < adj[u].size(); j++) {
                    int v = adj[u][j];
                    if (g[v] == 0) {
                        g[v] = x;
                        q.push_back(v);
                    } else if (g[v] != x) {
                        cout << i + 1 << "\n";
                        return 0;
                    }
                }
            }          

        } else {
            int c = r[i][1];
            int x = r[i][2];
            if (g[c] != 0 && g[c] != x) {
                cout << i + 1 << "\n";
                return 0;
            }
            g[c] = x;
            deque<int> q;
            q.push_back(c);
            while (!q.empty()) {
                int u = q.front();
                q.pop_front();
                for (int j = 0; j < adj[u].size(); j++) {
                    int v = adj[u][j];
                    if (g[v] == 0) {
                        g[v] = x;
                        q.push_back(v);
                    } else if (g[v] != x) {
                        cout << i + 1 << "\n";
                        return 0;
                    }
                }
            }
        }
    }
    cout << "0\n";
    return 0;
}


Measured memory_bytes: 10984
from collections import deque
N,Q = map(int,input().split())
edge = [[]for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
tree = [0]*N
for i in range(Q):
    p,x = map(int,input().split())
    tree[p-1] += x
flag = [0]*N
flag[0] = 1
queue = deque([0])
while queue != deque([]):
    p = queue.popleft()
    for i in edge[p]:
        if flag[i] == 0:
            flag[i] = 1
            tree[i] += tree[p]
            queue.append(i)

for i in tree:
    print(i,end=" ")


Measured memory_bytes: 52992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll n,k;
    ll a;
    double b=1,c=0;
    cin>>n>>k;
    for(int i=1;i<n+1;i++){
        a=i;
        while(a<k){
            a*=2;
            b/=2;
        }
        c+=b;
        b=1;
    }
    c/=n;
    cout<<setprecision(15)<<c;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,j,N;
  scanf("%d",&N);
  int sizeS=0;
  int temp=0;
  for(i=1;i<500;i++){
    temp=temp+i;
    if(temp>N){
      break;
    }
    if(temp==N){
      sizeS=i+1;
      break;
    }
  }
  if(sizeS==0){
    printf("No");
    return 0;
  }

  int S[sizeS+1][sizeS+1];
  int K=0;
  for(i=1;i<sizeS;i++){
    for(j=1;j<=i;j++){
      S[j][i]=K+j;
      S[i+1][j]=K+j;
    }
    K=K+i;
  }

  printf("Yes\n");
  printf("%d\n",sizeS);
  for(i=1;i<=sizeS;i++){
    printf("%d ",sizeS-1);
    for(j=1;j<=sizeS-1;j++){
      printf("%d ",S[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2048
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
class unionfind():
    def __init__(self,n):
        self.par = list(range(n))
        self.size = [1]*n
        self.rank = [0]*n
        self.n = n
        #self.ps=set(range(n)) #not tested
    def root(self,x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def same(self,x,y):
        return self.root(x) == self.root(y)

    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x==y:return
        else:
            if self.rank[x] < self.rank[y]:
                 x,y = y,x
            if self.rank[x] == self.rank[y]:
                self.rank[x]+=1
            self.par[y] = x
            #self.ps.discard(y)##親の集合からyを取り除く
            self.size[x] +=self.size[y]
    def get_size(self,x):
        x = self.root(x)
        return self.size[x]
    def parent_set(self):
        for x in range(self.n):
            self.root(x)
        s = set()
        for par in self.par:
            s.add(par)
        return s
n,m = ma()
uf=unionfind(n)
AB=[]
for i in range(m):
    a,b=ma();a-=1;b-=1
    uf.unite(a,b)
print(len(uf.parent_set())-1)


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
    }
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
    }
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;

ll rec(const vector<vector<ll>> &F, vector<bool> &ff, ll x) {
    if (ff[x] == true) return 0;
    ff[x] = true;
    ll ret = 1;
    for (auto &num : F[x]) {
        ret += rec(F, ff, num);
    }
    return ret;
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> F(N);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        --a;
        --b;
        F[a].emplace_back(b);
        F[b].emplace_back(a);
    }

    ll ans = 0;

    vector<bool> ff(N);
    rep(j, N) { ff[j] = false; }

    rep(i, N) { chmax(ans, rec(F, ff, i)); }
    cout << ans << endl;
}

Measured memory_bytes: 23500
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;

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


int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B << endl;

	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>


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

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;


lli mod197 = 1000000007LL;

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

int main(void) {

	lli A, B, C;
	cin >> A >> B >> C;

	COUT(B + min(A + B + 1, C));




	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	long long int n;
	cin >> n;
	long long int go = 5;
	long long int ans = 0;
	if (n % 2 == 1) {
		cout << 0;
		return 0;
	}
	ans = ans + n / 10;
	n = n / 10;
	while (n > 0) {
		ans = ans + n / 5;
		n = n / 5;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

const ll MOD = 1e9 + 7;

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) {
  // フェルマーの小定理
  return modpow(a, mod - 2, mod);
}

ll nCr(ll n, ll r, ll mod) {
  ll numerator = 1;
  ll denominator = 1;
  for (ll i = 0; i < r; i++) {
    numerator = numerator * (n - i) % mod;
    denominator = denominator * (i + 1) % mod;
  }
  ll tmp = modinv(denominator, mod);
  return numerator * tmp % mod;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll y = modpow(2, n, MOD);
  ll z = nCr(n, a, MOD);
  ll x = nCr(n, b, MOD);
  y = y - 1 - x - z;
  y = (y + MOD * 2) % MOD;
  cout << y << endl;
}

Measured memory_bytes: 256
def main():
    from itertools import combinations
    import bisect
    N, K = map(int, input().split())
    xy = [tuple(map(int, input().split())) for i in range(N)]
    xy.sort(key=lambda x: x[0])
    X = [x[0] for x in xy]

    ans = 40**18
    for a, b in combinations(range(N), 2):
        A, B = max(xy[a][0], xy[b][0]), min(xy[a][0], xy[b][0])
        r = bisect.bisect_right(X, A)
        l = bisect.bisect_left(X, B)
        for c, d in combinations(range(N), 2):
            tmp = 0
            C, D = max(xy[c][1], xy[d][1]), min(xy[c][1], xy[d][1])

            for i in range(l, r):
                if xy[i][1] <= C and xy[i][1] >= D:
                    tmp += 1
            #     print(xy[i][1], C, D)

            if tmp >= K and ans > (A-B) * (C - D):
                ans = (A-B) * (C - D)

    print(ans)
main()

Measured memory_bytes: 47452
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool gh[1100][1100];
int f[1100][1100];
bool vis[1100][1100];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
struct node{
	int x,y;
};
queue <node> q;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	int cnt=0;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			char c;
			cin>>c;
			if (c=='#') {
				gh[i][j]=true;
				q.push({i,j});
				cnt++;
				vis[i][j]=true;
			}
		}
	}
	while (!q.empty()){
		node now=q.front();
		q.pop();
		for (int i=0;i<4;i++){
			int tx=now.x+dx[i],ty=now.y+dy[i];
			if (tx<=0||tx>n||ty<=0||ty>m) continue;
			if (!vis[tx][ty]) {
				cnt++;
				f[tx][ty]=f[now.x][now.y]+1;
				vis[tx][ty]=true;
				q.push({tx,ty});
			}
		}
	}
	int ans=0;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			ans=max(ans,f[i][j]);	
		}
	}
	cout<<ans<<endl;
	return 0;
		
}

Measured memory_bytes: 12432
N, M =map(int, input().split())
L = []

for i in range(N):
    A, B =map(int, input().split())
    L.append((A, B))

L.sort()
value = 0
num = 0
for i in range(N):
    if num + L[i][1] > M:
        value += (M - num) * L[i][0]
        num = M
    else:
        value += L[i][0] * L[i][1]
        num += L[i][1]
    if num == M:
        break

print(value)

Measured memory_bytes: 16904
#include <stdio.h>

int main(void) {
int a,b,x;

	int asdf=0;
	
	scanf("%d",&x);
	scanf("%d",&a);
	scanf("%d",&b);

	
	asdf=x-a;
	
	//asdf=asdf/b;
	
	
	
    do{asdf=asdf-b;}while(asdf>=0);
	asdf=asdf+b;
	printf("%d",asdf);
	
	return 0;
}



Measured memory_bytes: 128
getInt = do
  x <- getLine
  let intValue = read x :: Int
  return intValue

main = do
  inNum <- getInt
  let hours = inNum `div` 3600 :: Int
  let minutes = (inNum `mod` 3600) `div` 60
  let seconds = (inNum `mod` 60)
  putStrLn ((show hours) ++ [':'] ++ (show minutes) ++ [':'] ++ (show seconds))


Measured memory_bytes: 3580
#![allow(non_snake_case)]

use std::collections::VecDeque;
use std::io::Read;


const ALPHA_SIZE: usize = 26;

struct State<'a> {
    D: usize,
    C: &'a Vec<i32>,
    S: &'a Vec<Vec<i32>>,
    actions: Vec<usize>
}

impl<'a> State<'a> {
    fn create(D: usize, C: &'a Vec<i32>, S: &'a Vec<Vec<i32>>, actions: Vec<usize>) -> State<'a> {
        assert_eq!(D, actions.len());
        assert_eq!(S[0].len(), ALPHA_SIZE);
        return State { D, C, S, actions };
    }

    fn scores(self: &Self) -> Vec<i32> {
        let mut score = 0;
        let mut scores = vec![];
        let mut last: Vec<i32> = vec![-1; ALPHA_SIZE];
        for d in 0..self.D {
            score += self.S[d][self.actions[d]];
            last[self.actions[d]] = d as i32;
            for c in 0..ALPHA_SIZE {
                score -= (d as i32 - last[c]) * self.C[c];
            }
            scores.push(score);
        }
        return scores;
    }

    fn last_score(self: &Self) -> i32 {
        let mut score = 0;
        let mut last: Vec<i32> = vec![-1; ALPHA_SIZE];
        for d in 0..self.D {
            let diff = d as i32 - last[self.actions[d]];
            score += self.S[d][self.actions[d]];
            score -= diff * (diff - 1) / 2 * self.C[self.actions[d]];
            last[self.actions[d]] = d as i32;
        }
        for c in 0..ALPHA_SIZE {
            let diff = self.D as i32 - last[c];
            score -= diff * (diff - 1)/ 2 * self.C[c]
        }
        score
    }

    fn change(self: &mut Self, d: usize, action: usize) {
        self.actions[d] = action;
    }


}

fn main() {
    let mut buffer = String::new();
    std::io::stdin().read_to_string(&mut buffer).unwrap();
    let mut iter = buffer.split_whitespace();
    let D = iter.next().unwrap().parse::<usize>().unwrap();

    let C: Vec<i32> = (0..ALPHA_SIZE)
        .map(|_| iter.next().unwrap().parse::<i32>().unwrap())
        .collect();
    let S: Vec<Vec<i32>> = (0..D)
        .map(|_| {
            (0..ALPHA_SIZE)
                .map(|_| iter.next().unwrap().parse::<i32>().unwrap())
                .collect()
        })
        .collect();

    let T = (0..D).map(|_| iter.next().unwrap().parse::<usize>().unwrap() - 1).collect();
    let mut state = State::create(D, &C, &S, T);

    let M = iter.next().unwrap().parse::<usize>().unwrap();
    for _ in 0..M {
        let d = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        let a = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        state.change(d, a);
        println!("{}", state.last_score());
    }
    // for score in state.scores() {
    //     println!("{}", score)
    // }

    // for d in 0..D {
    //     let mut best_c = 0;
    //     for c in 0..ALPHA_SIZE {
    //         if S[d][c] > S[d][best_c] {
    //             best_c = c;
    //         }
    //
    //         for
    //     }
    //     println!("{}", best_c + 1);
    // }
}


Measured memory_bytes: 2652
while True:
  n, r = map(int, input().split())
  if n == 0:
    break
  lst = [n - i for i in range(n)]
  for _ in range(r):
    p, c = map(int, input().split())
    lst = lst[p - 1:p - 1 + c] + lst[:p - 1] + lst[p - 1 + c:]
  print(lst[0])




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

ll number_of_divisors(ll n)
{
    ll ans = 1;

	for (ll i=2; i*i <= n; i++){
		if (n%i != 0) continue;
		ll cnt = 0;
		while (n%i == 0){
			n /= i;
			cnt++;
		}
		ans *= (cnt+1);
	}
	if (n > 1){
		ans *= 2;
	}
	return ans;
}
ll aa[1000004]; ll bb[200004];
ll ara[200][200];
int main()
{
    io;
    ll a,b,c,d,m,n,i,j,k,l,t,x,y,z;
    ll ans=0;
    ll maxi=INT_MIN; ll mini=INT_MAX,sum=0,mul=1;
    cin>>n;
    for(i=0;i<n;i++)
    {
        for(j=0;j<2;j++) cin>>ara[i][j];
    }
    ans=0;
    for(i=0;i<n;i++)
    {

            if(ara[i][0]==ara[i][1]) sum++;
            else sum=0;
            if(sum==3) ans=1;
    }
    
    if(ans==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}






Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
static const ll INF = 1000000000000000000ll;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		--a[i];
	}
	const int k = n - 1;
	vector<pii> b(k);
	for(int i = 0; i < k; ++i){
		if(a[i + 1] < a[i]){
			b[i] = pii(a[i], a[i + 1] + m);
		}else{
			b[i] = pii(a[i], a[i + 1]);
		}
	}
	sort(b.begin(), b.end());
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	ll current = 0;
	for(int i = 0; i < k; ++i){
		if(b[i].second >= m){
			pq.push(pii(b[i].second - m, i));
			current += b[i].second - m + 1;
		}else{
			current += b[i].second - b[i].first;
		}
	}
	ll best = current;
	for(int i = 1, j = 0; i < m; ++i){
		while(!pq.empty() && pq.top().first < i){
			const int t = pq.top().second;
			pq.pop();
			current -= 1;
			current += b[t].second - b[t].first;
		}
		current -= pq.size();
		best = min(best, current);
		while(j < k && b[j].first < i){
			pq.push(pii(b[j].second, j));
			++j;
		}
	}
	cout << best << endl;
	return 0;
}



Measured memory_bytes: 2552
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))

int N, K;
string S;

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

	S[K - 1] += 32;

	cout << S << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;


signed main()
{
    int n;
    cin >> n;
    
    vi a(n);
    rep(i, n) cin >> a[i];
    
    vi pos(n+1);
    rep(i, n) pos[a[i]] = i;
    
    set<int> finished = {-1, n};
    
    ll ans = 0;
    reps(v, 1, n+1){
        int p = pos[v];
        auto itr = finished.lower_bound(p);
        int r = *itr;
        --itr;
        int l = *itr;
        
        ans += v*(ll(p-l)*(r-p));
        
        finished.insert(p);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 11136
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();

function main(){
  var waitTime = calc();
  for(var i = 0, len = input.length - 1; i < len;i++){
    console.log(waitTime[parseInt(input[i], 10)]);
  }
}

function calc(){
  var seats = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var groupMembers = [2,5,2,2,2];
  var eatTimes = [19,39,25,36,22,42];
  
  var headGroup = -1;
  var pastMinutes = 0;
  var waitTime = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var lastMembers = 100;
  
  while(true){
    // たべおわる
    var i;
    for(i = 17; i--;){
      seats[i] = max(--seats[i], 0);
    }
    
    // 来店
    if(headGroup == -1 && pastMinutes % 5 == 0){
      headGroup = pastMinutes / 5;
    }
    
    // ちゃくせき
    while(headGroup != -1 && i != 17){
      var needsSequencialSeats = groupMembers[headGroup % 5];
      var sequencialSeats = 0;
      var startIndex = -1;
      
      for(i = 0; i < seats.length; i++){
        sequencialSeats = seats[i] == 0 ? sequencialSeats + 1 : 0;
        
        if(sequencialSeats == needsSequencialSeats){
          startIndex = i - (needsSequencialSeats - 1);
          // すわれるみたい
          waitTime[headGroup] = pastMinutes - (headGroup * 5);
          for(var j = startIndex; j < (needsSequencialSeats + startIndex); j++){
            seats[j] = eatTimes[headGroup % 6];
          }
          
          headGroup = (((headGroup + 1) * 5) <= pastMinutes) ? headGroup + 1 : -1;
          if(!(--lastMembers)){
            // 100グループ着席
            return waitTime;
          }
          break;
        }
      }
    }
    
    pastMinutes++;
  }
  
}

function max(a, b){
  var t = (a - b);
  return a - (t & (t >> 31));
}

Measured memory_bytes: 8440
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val p = sc.nextInt()
    val q = sc.nextInt()
    val r = sc.nextInt()

    abc129a(p, q, r)
}

fun abc129a(p: Int, q: Int, r: Int) {
    var list: MutableList<Int> = mutableListOf()
    list.add(p)
    list.add(q)
    list.add(r)
    var ans = list.sorted().take(2).sum()

    println(ans)
}


Measured memory_bytes: 36052
#include <cstdio>
using namespace std;
const long long mod=1000000007;
const int N=200005;
const int M=2005;
const int S=2005;
const int T=4010;
const int G=8010;
int n,i,j;
int a[N],b[N];
int h[T][T],ans;
int frac[G],inv[G];
long long getinv(long long b,int e=mod-2)
{
	if (e==0)
		return 1ll;
	long long ret=getinv(b,e>>1);
	ret=ret*ret%mod;
	if (e&1)
		ret=ret*b%mod;
	return ret;
}
int main()
{
	scanf("%d",&n);
	frac[0]=1;
	for (i=1;i<G;i++)
		frac[i]=1ll*i*frac[i-1]%mod;
	inv[G-1]=getinv(frac[G-1]);
	for (i=G-2;i>=0;i--)
		inv[i]=1ll*(i+1)*inv[i+1]%mod;
	for (i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		h[S-a[i]][S-b[i]]++;
	}
	for (i=1;i<T;i++)
		for (j=1;j<T;j++)
			h[i][j]=(1ll*h[i][j]+1ll*h[i-1][j]+1ll*h[i][j-1])%mod;
	for (i=1;i<=n;i++)
	{
		ans=(ans+h[S+a[i]][S+b[i]])%mod;
		ans=(1ll*ans+mod-1ll*frac[2*(a[i]+b[i])]*inv[2*a[i]]%mod*inv[2*b[i]]%mod)%mod;
	}
	printf("%lld\n",ans*getinv(2)%mod);
	return 0;
}

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

using namespace std;

unsigned short dp[20][50010];

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<int> c(M);
    for (auto &i : c) cin >> i;
    sort(c.begin(), c.end());
    for (int j = 0; j <= N; j++) dp[0][j] = j;
    int m;
    for (int i = 1; i < M; i++)
    {
        for (int j = 0; j <= N; j++)
        {
            m = dp[i - 1][j];
            for (int k = j / c[i]; j / c[i] - k < 10 && k > 0; k--) m = min(m, dp[i - 1][j - k * c[i]] + k);
            dp[i][j] = m;
        }
    }
    cout << dp[M - 1][N] << endl;
    return 0;
}



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

int main(void){
    // Your code here!
   string a, b, c;
   cin >> a >> b >> c;
   if(a.back() == b[0] && b.back() == c[0]){
       cout << "YES" << endl;
   } else {
       cout << "NO" << endl;
   }
}


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

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;
int main(){
    int n,k;
    cin>>n>>k;
    vector<tuple<ll,ll,char>> v(n);
    vector<vector<ll>> sum(2*k+1,vector<ll>(2*k+1));
    ll black = 0,white=0;
    for(auto &a : v){
        ll x,y;char c;
        cin>>x>>y>>c;
        x%=2*k;
        y%=2*k;
        if(c == 'B') sum[x+1][y+1]++,black++;
        if(c == 'W') sum[x+1][y+1]--,black--,white++;
        a = make_tuple(x,y,c);
    }
    for(int i=1;i<=2*k;++i){
        for(int j=1;j<=2*k;++j){
            sum[i][j] += sum[i][j-1];
        }
    }
    for(int i=1;i<=2*k;++i){
        for(int j=1;j<=2*k;++j){
            sum[i][j] += sum[i-1][j];
        }
    }
    ll ma = -inf;
    for(int i=0;i<=k;++i){
        for(int j=0;j<=k;++j){
            ll bsum = sum[i][j];
            bsum += sum[i+k][j+k] - sum[i+k][j] - sum[i][j+k] + sum[i][j];
            bsum += sum[2*k][j] - sum[i+k][j];
            bsum += sum[i][2*k] - sum[i][j+k];
            bsum += sum[2*k][2*k] - sum[i+k][2*k] - sum[2*k][j+k] + sum[i+k][j+k];
            ma = max({ma,bsum,black-bsum});
        }
    }
    ma += white;
    cout << ma << endl;
    return 0;
}



Measured memory_bytes: 33920
#include <bits/stdc++.h>
#include <stdio.h>
#include <string>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

int n,m,r;
int rr[10];
ll d[205][205];
ll ans;
ll pmt[10][400000];
ll fc[10];
ll pw(int x,int y){
  ll ret=1;
  for(int i=0; i<y; i++){
    ret*=x;
  }
  return ret;
}
ll calc(ll x){
  ll ret=0;
  int dv=1;
  while(1){
    int n1=(x/dv)%10;
    int n2=(x/(dv*10))%10;
    if(x/dv<10){
      break;
    }
    n1--;
    n2--;
    ret+=d[rr[n1]][rr[n2]];
    dv*=10;
  }
  return ret;
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>n>>m>>r;

for(int i=0; i<r; i++){
  cin>>rr[i];
  rr[i]--;
}

for(int i=0; i<203; i++){
  for(int j=0;j<203; j++){
    if(i==j) continue;
    d[i][j]=mod;
  }
}

for(int i=0; i<m; i++){
  ll a,b,c;
  cin>>a>>b>>c;
  a--; b--;
  d[a][b]=min(d[a][b],c);
  d[b][a]=min(d[b][a],c);
}

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

fc[0]=1;
for(int i=1; i<10; i++){
  fc[i]=fc[i-1]*i;
}

pmt[1][0]=1;
for(int i=2; i<10; i++){
  int c=0;
  for(int j=0; j<fc[i-1]; j++){
    for(int k=0; k<i; k++){
      int n1=pmt[i-1][j]/pw(10,k);
      int n2=pmt[i-1][j]%pw(10,k);
      pmt[i][c]=n1*pw(10,k+1)+i*pw(10,k)+n2;
      c++;
    }
  }
}

ans=mod;
for(int i=0; i<fc[r]; i++){
  ans=min(ans,calc(pmt[r][i]));
}

cout<<ans<<endl;

}



Measured memory_bytes: 21376
#include<stdio.h>

int main(void)
{
	int n,i,p,max=0,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p);
		if(p>max)
			max=p;
		sum+=p;
	}
	sum-=max/2;
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
using System.Linq;using System.Collections.Generic;using static System.Console;class Z{static void Main()=>new K();}class K{long M=1000000007;int[]G=>ReadLine().Split().Select(int.Parse).ToArray();long N,A,D;long[]j,k,l,m;bool[]z;List<E>[]g;public K(){var I=G;N=I[0];int Q=I[1],s=(I=G)[0]-1,t=I[1]-1;g=new List<E>[N];for(var i=0;i<N;i++)g[i]=new List<E>();for(var i=0;i<Q;i++){I=G;int a=I[0]-1,b=I[1]-1,c=I[2];g[a].Add(new E(b,c));g[b].Add(new E(a,c));}C(s,ref j,ref l);C(t,ref k,ref m);A=S(l[t]);D=j[t];z=new bool[N];B(t);WriteLine((A%=M)<0?A+M:A);}long S(long x)=>x*x%M;void B(long u){if(!z[u]){z[u]=true;if(2*j[u]==D)A-=S(l[u]*m[u]%M);foreach(var e in g[u])if(j[e.V]+e.D==j[u]){if(2*j[u]>D&&2*j[e.V]<D)A-=S(m[u]*l[e.V]%M);B(e.V);}}}void C(int u,ref long[]d,ref long[]c){d=new long[N];c=new long[N];for(var v=0;v<N;v++)d[v]=(long)4e18;var q=new Q();d[u]=0;c[u]=1;q.E(new E(u,0));while(q.C>0){var p=q.D();var v=p.V;if(d[v]<p.D)continue;foreach(var e in g[v]){var t=d[v]+e.D;if(d[e.V]>t){q.E(new E(e.V,d[e.V]=t));c[e.V]=c[v];}else if(d[e.V]==t)c[e.V]=(c[e.V]+c[v])%M;}}}}struct E{public long V,D;public E(long v,long d){V=v;D=d;}public long C(E e)=>D-e.D;}class Q{List<E>a=new List<E>();public int C;public void E(E x){var i=C++;a.Add(x);while(i>0){var p=(i-1)/2;if(a[p].C(x)<=0)break;a[i]=a[p];i=p;}a[i]=x;}public E D(){var v=a[0];var x=a[--C];a.RemoveAt(C);if(C==0)return v;var i=0;while(i*2+1<C){int l=2*i+1,r=l+1;if(r<C&&a[r].C(a[l])<0)l=r;if(a[l].C(x)>=0)break;a[i]=a[l];i=l;}a[i]=x;return v;}}

Measured memory_bytes: 53764
#include <iostream>
#include <algorithm>
#define mod 1000000007
using namespace std;

int main()
{
    int n, a[100010], ans=1;
    bool ok=true;
    cin>>n;
    for (int i=0; i<n; i++) cin>>a[i];
    sort(a, a+n);
    if (n%2==1)
    {
        if (a[0]!=0) ok=false;
        for (int i=1; i<n; i++)
        {
            if (i%2==1) { if (a[i]!=a[i-1]+2) ok=false; }
            else { if (a[i]!=a[i-1]) ok=false; }
        }
    }
    else
    {
        if (a[0]!=1 || a[1]!=1) ok=false;
        for (int i=2; i<n; i++)
        {
            if (i%2==0) { if (a[i]!=a[i-1]+2) ok=false; }
            else { if (a[i]!=a[i-1]) ok=false; }
        }
    }
    if (ok)
    {
        if (n%2==0) for (int i=0; i<n/2; i++) ans=ans*2%mod;
        else for (int i=0; i<(n-1)/2; i++) ans=ans*2%mod;
    }
    else ans=0;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, m, a;
bool b[101010];
int sei, pen[101010];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		string s;
		int a;
		cin >> a >> s;
		if(s == "AC" && !b[a]){
			b[a] = 1;
			sei++;
		}
		else if(!b[a]){
			pen[a]++;
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(b[i]) ans += pen[i];
	}
	
	cout << sei << " " << ans << endl;
	
	return 0;
}

Measured memory_bytes: 768
// AOJ DSL_3_A The Smallest Window I
// 2018.5.5 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int s[100002];

int main()
{
	int N, S, i, j, ans;

	N = in(), S = in();
	for (i = 1; i <= N; i++) s[i] = s[i-1] + in();
	if (s[N] < S)  { puts("0"); return 0; }
	if (s[N] == S) { printf("%d\n", N); return 0; }

	for (j = 1; s[j] < S; j++);
	i = 0, ans = j;
	while (1) {
		while (s[j]-s[i] >= S) i++;
		if (j-i+1 < ans) ans = j-i+1;
		while (j <= N && s[j]-s[i] < S) j++;
		if (j > N) break;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 2236
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string a,b;
  cin >> a >> b;
  ll A=a.size();
  ll B=b.size();
  ll x;
  if(A>B){
    x=1;
  }
  else if(A<B){
    x=-1;
  }
  else{
    if(a>b){
      x=1;
    }
    else if(b>a){
      x=-1;
    }
    else
      x=0;
  }
  if(x==0){
    cout << "EQUAL" << endl;
  }
  else if(x==1){
    cout << "GREATER" << endl;
  }
  else{
    cout << "LESS" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int n, k;
	char* s;

	scanf("%d", &n);
	scanf("%d", &k);

	s = (char*)malloc(sizeof(char) * n);

	scanf("%s", s);

	if(s[k-1] == 'A') s[k-1] ='a';
	if(s[k-1] == 'B') s[k-1] ='b';
	if(s[k-1] == 'C') s[k-1] ='c';
	
	printf("%s", s);
	
	return 0;
}

Measured memory_bytes: 128