akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

#define MAX_N 2000

long long x[MAX_N][MAX_N];
long long dp[MAX_N][MAX_N];
int h, w, n, cx, cy;
int main() {
	while (true) {
		memset(dp, 0, sizeof(dp));
		cin >> h >> w >> n;
		if (h == 0 && w == 0 && n == 0) { break; }
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				scanf("%d", &x[i][j]);
			}
		}
		dp[1][1] = n - 1;
		for (int i = 2; i <= h + w; i++) {
			for (int j = 1; j <= h; j++) {
				int k = i - j;
				if (k >= 1 && k <= w) {
					if (x[j][k] == 0) {
						dp[j][k + 1] += dp[j][k] / 2;
						dp[j + 1][k] += (dp[j][k] + 1) / 2;
					}
					else {
						dp[j][k + 1] += (dp[j][k] + 1) / 2;
						dp[j + 1][k] += dp[j][k] / 2;
					}
				}
			}
		}
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				x[i][j] += dp[i][j];
				x[i][j] %= 2;
			}
		}
		cx = 1; cy = 1;
		while (cx <= w && cy <= h) {
			if (x[cy][cx] == 0) {
				cy++;
			}
			else {
				cx++;
			}
		}
		cout << cy << ' ' << cx << endl;
	}
	return 0;
}

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


int main() {
	int n, x;
	cin >> n >> x;
	vector<int> m(n);

	rep(i, n) {
		cin >> m[i];
		x -= m[i];
	}

	sort(m.begin(), m.end());
	int ans = n;
	ans += x / m[0];
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
	"sort"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type inInfo struct {
	in    int
	after int
}

type inInfoSorter []*inInfo

func (a inInfoSorter) Len() int      { return len(a) }
func (a inInfoSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a inInfoSorter) Less(i, j int) bool {
	me, you := a[i], a[j]
	switch {
	case me.in > you.in:
		return true
	case me.in < you.in:
		return false
	case me.after > you.after:
		return true
	default:
		return false
	}
}

func sum(w []int) int {
	s := 0
	for _, v := range w {
		s += v
	}
	return s
}

type ptr []int

func (x *ptr) top(i int) int {
	ptrs := []int(*x)
	var his []int
	cur := i
	for ; cur >= 0 && ptrs[cur] != cur; cur = ptrs[cur] {
		his = append(his, cur)
	}
	for _, v := range his {
		ptrs[v] = cur - 1
	}
	if cur >= 0 {
		ptrs[cur] = cur - 1
	}
	return cur
}

func solve(stdin io.Reader, stdout io.Writer) {
	var n, m int
	var infos []*inInfo

	fmt.Fscanln(stdin, &n, &m)

	for i := 0; i < n; i++ {
		var info inInfo
		fmt.Fscanln(stdin, &info.after, &info.in)
		infos = append(infos, &info)
	}

	sort.Sort(inInfoSorter(infos))

	var ans = make([]int, m)
	var p = make([]int, m)
	for i := range p {
		p[i] = i
	}
	ptrs := ptr(p)

	for _, w := range infos {
		i := ptrs.top(m - w.after)
		if i >= 0 {
			ans[i] = w.in
		}
	}

	fmt.Fprintln(stdout, sum(ans))

}



Measured memory_bytes: 8704
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	p := make([][2]int, n)
	for i := 0; i < n; i++ {
		p[i] = [2]int{i, intScanner()}
	}
	sort.Sort(SliceSort(p))
	ans := []int{1}
	for i := 1; i < n; i++ {
		if p[i-1][0] < p[i][0] {
			ans[len(ans)-1]++
		} else {
			ans = append(ans, 1)
		}
	}
	fmt.Println(n - max(ans))
}

type SliceSort [][2]int

func (x SliceSort) Len() int           { return len(x) }
func (x SliceSort) Less(i, j int) bool { return x[i][1] < x[j][1] }
func (x SliceSort) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }


Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

const string boin = "aiueo";
const string shiin = "kstnhmyrwgzdbp";
const string cho = "aiu";
const string museiinshi = "ksthp";

bool isBoin(char c) {
  return boin.find(c) != string::npos;
}

bool isShiin(char c) {
  return shiin.find(c) != string::npos;
}

bool isCho(char c) {
  return cho.find(c) != string::npos;
}

bool isMuseiinshi(char c) {
  return museiinshi.find(c) != string::npos;
}

vector<pair<string,int> > parse(const string &s) {
  vector<pair<string,int> > v;
  string t = "";
  for(int i = 0; i < s.size(); ++i) {
    t += s[i];
    if(isBoin(s[i])) {
      int type = 0;
      if(t.size() == 1) {
	if(i >= 1 && isBoin(s[i-1]) && isCho(s[i])) {
	  type = 6;
	} else {
	  type = 1;
	}
      } else if(t.size() == 2) {
	type = 2;
      } else if(t.size() == 3) {
	type = 3;
      }
      v.push_back(make_pair(t, type));
      t = "";
    } else if(i+1 < s.size() && isShiin(s[i]) && s[i+1] == s[i] &&
	      s[i] != 'n' && s[i] != 'y' && s[i] != 'w') {
      v.push_back(make_pair(t, 4));
      t = "";
    } else if(s[i] == 'n' &&
	      (i+1 == s.size() || (i+1 < s.size() && isShiin(s[i+1]))) ) {
      v.push_back(make_pair(t, 5));
      t = "";
    } else if(s[i] == '\'') {
      v.push_back(make_pair(t, 5));
      t = "";
    }
  }
  return v;
}

char getBoin(const string &s) {
  return *s.rbegin();
}

int main() {
  string s;
  while(cin >> s && s != "#") {
    vector<pair<string, int> > v = parse(s);
    int n = v.size();
    bool isMusei[n];
    fill(isMusei, isMusei+n, false);

    // i or u
    for(int i = 0; i < n; ++i) {
      if((v[i].second == 2 || v[i].second == 3) &&
	 isMuseiinshi(v[i].first[0]) && 
	 (getBoin(v[i].first) == 'i' || getBoin(v[i].first) == 'u') &&
	 (i+1 == n || isMuseiinshi(v[i+1].first[0]))) {
	isMusei[i] = true;
      }
    }
    
    // a or o
    for(int i = 0, cnt = 0; i+1 < n; ++i) {
      if((getBoin(v[i].first) == 'a' || getBoin(v[i].first) == 'o') &&
	 getBoin(v[i].first) == getBoin(v[i+1].first)); else continue;
      bool flag = true;
      for(int j = 0; j < 2; ++j) {
	const string &t = v[i+j].first;
	const int &type = v[i+j].second;
	if((type == 2 || type == 3) &&
	   isMuseiinshi(t[0])) ; else {
	  flag = false;
	  break;
	}
      }
      if(flag) {
	isMusei[i] = true;
      }
    }

    for(int i = 0, pre = 0; i < n; ++i) {
      if(isBoin(getBoin(v[i].first))) {
	bool musei = !pre && isMusei[i];
	cout << v[i].first.substr(0, v[i].first.size()-1);
	if(musei) cout << "(";
	cout << getBoin(v[i].first);
	if(musei) cout << ")";
	pre = musei;
      } else {
	cout << v[i].first;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int cnt;
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){
  cnt=0;
  int r=1;
  vector<int> G;
  while(r<=n){
    G.push_back(r);
    r*=2;
  }
  int m=G.size();
  reverse(G.begin(),G.end());
  cout<<m<<endl;
  for(int i=0;i<m;i++) cout<<G[i]<<" \n"[i==m-1];
  for(int i=0;i<m;i++) insertionSort(A,n,G[i]);
  cout<<cnt<<endl;
}
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  shellSort(A,n);
  for(int k=0;k<n;k++) cout<<A[k]<<endl;
  return 0;
}


Measured memory_bytes: 7032
#include<stdio.h>

unsigned long x;
unsigned long i = 0;

int main()
{
    int tmp = 0;

    scanf("%ld", &x);

    i = (x / 11) * 2;
    x = x % 11;

    while(1){
        if(tmp >= x){
            break;
        }
        i++;
        (i % 2) ? (tmp += 6) : (tmp += 5);
    }

    printf("%lu\n", i);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

typedef struct {
  int X;
  int Y;
} st_nums;

int main(void) {
  int N;
  scanf("%d", &N);

  st_nums nums[50];
  for(int i = 0; i < N; i++) {
    scanf("%d %d", &nums[i].X, &nums[i].Y);
  }
  int minCost = N;
  for(int i = 0; i < N-1; i++) {
    for(int j = i+1; j < N; j++) {
      int p = nums[i].X - nums[j].X;
      int q = nums[i].Y - nums[j].Y;
      int cost = N;
      for(int m = 0; m < N-1; m++) {
	for(int n = m+1; n < N; n++) {
	  if(((nums[m].X-p) == (nums[n].X) &&
	      (nums[m].Y-q) == (nums[n].Y)) ||
	     ((nums[m].X+p) == (nums[n].X) &&
	      (nums[m].Y+q) == (nums[n].Y)))
	    cost--;
	}
      }
      minCost = MIN(minCost, cost);
    }
  }
  printf("%d\n", minCost);
  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re
import bisect

BIGNUM = 10 ** 9 + 7

def main():
    A, B = map(int, input().split())
    #N = int(input())
    #Hs = list(map(int, input().split()))

    maxnum = max([A+B, A-B, A*B])
    print(maxnum)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;

int main(){
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x;
cin>>n>>x;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);

long long dis=0;
int i=0;
for(;i<n-1;i++)
{
  if(dis+arr[i]<=x)
    dis+=arr[i];
  else break;
}
if(dis+arr[n-1]==x)
    i++;    
cout<<i<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
static const int MAX_N = 100000;

int N;
P p[MAX_N];
ll res[MAX_N];

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%lld", &p[i].first);
		p[i].second = i;
	}
	sort(p, p + N);
	reverse(p, p + N);
	int min_index = MAX_N;
	for(int i = 0; i < N; i++){
		min_index = min(min_index, p[i].second);
		if(i == N - 1) res[min_index] += p[i].first * (ll)(i + 1);
		else res[min_index] += (p[i].first - p[i + 1].first) * (ll)(i + 1);
	}
	
	for(int i = 0; i < N; i++) printf("%lld\n", res[i]);
	return 0;
}

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

long long a[100010];
long long b[100010];
int main(){
  int n;
  cin >> n;

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

  long long ans = 0;
  for(int i = n-1;i >= 0;i--){
    a[i] += ans;
    if(a[i] % b[i] != 0){
      long long tmp = (a[i]+b[i]-1) / b[i];
      ans += b[i] * tmp - a[i];
    }
  }

  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int n=0,l=-1,r=-1;
int main()
{
	scanf("%s",s+1);
	for(int i=1;s[i];i++)
	{
		++n;
	}
	for(int i=1;i<n;i++)
	{
		if(s[i]==s[i+1])
		{
			l=i;
			r=i+1;
		}
	}
	for(int i=1;i<n-1;i++)
	{
		if(s[i]==s[i+2])
		{
			l=i;
			r=i+2;
		}
	}
	printf("%d %d\n",l,r);
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



int n,m;
vector<pii> vec;
vector<int> ans;//i,i+1の橋を取り除くときiが入る

int main(){
  cin >> n >> m;
  REP(i,m){
    int a,b;
    cin >> a>> b;
    vec.push_back(pii(b,a));
  }
  sort(vec.begin(),vec.end());
  REP(i,vec.size()){
    bool flag = false;
    REP(j,ans.size()){
      if(ans[j]>=vec[i].second) flag = true;
    }
    if(!flag){
      ans.push_back(vec[i].first-1);
    }
  }
  cout << ans.size() <<endl;
}


/*
int n,m;
vector<pii> vec;

int main(){
  cin >> n >> m;
  REP(i,m){
    int a,b;
    bool flag = false;
    cin >> a >>b;
    REP(j,vec.size()){
      if(max(vec[j].first,a)<min(vec[j].second,b)){
        vec[j].first = max(vec[j].first,a);
        vec[j].second = min(vec[j].second,b);
        flag = true;
        break;
      }
    }
    if(!flag){
      vec.push_back(pii(a,b));
    }
  }
  cout << vec.size() <<endl;
}
*/


Measured memory_bytes: 1400
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	S := sc.nextStr()
	N := len(S)
	R := make([]int, N)
	count := 0
	for i := 0; i < N; i++ {
		if S[i] == 'R' {
			count++
		} else {
			if count%2 == 0 {
				R[i-1] += count / 2
				R[i] += count / 2
			} else {
				R[i-1] += count/2 + 1
				R[i] += count / 2
			}
			count = 0
		}
	}
	count = 0
	for i := N - 1; i >= 0; i-- {
		if S[i] == 'L' {
			count++
		} else {
			if count%2 == 0 {
				R[i] += count / 2
				R[i+1] += count / 2
			} else {
				R[i] += count / 2
				R[i+1] += count/2 + 1
			}
			count = 0
		}
	}

	for i := 0; i < N; i++ {
		if i != 0 {
			fmt.Fprint(wtr, " ")
		}
		fmt.Fprint(wtr, R[i])
	}
	fmt.Fprintln(wtr)
	wtr.Flush()
}


Measured memory_bytes: 4480
#include <algorithm>
#include <iostream>

using namespace std;

constexpr static int MAXN = 1e6;

int n;
int a[MAXN];

int main() {
    cin >> n;
    for (int i = 0; i < 3 * n; i++)
        cin >> a[i];
    sort(a, a + (3 * n));
    reverse(a, a + (3 * n));

    int64_t sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[2 * i + 1];
    cout << sum << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(int i = 0; i <N; i++)
using namespace std;


const int MOD = pow(10,9)+7;
const int MAX = 2047483647;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}




int main() {
    
    ll N = lin();
    ll M = lin();
    
    vector<ll> X;
    
    if (M == 1){
        cout << 0 << endl;
        return 0;
    }
    
    if ( N >= M){
        cout << 0 << endl;
        return 0;
    }
    
    for(auto i = 0; i<M;i++){
        X.push_back(in());
    }
    
    sort(X.begin(),X.end());
    
    ll totallen = *max_element(X.begin(),X.end()) - *min_element(X.begin(),X.end());
    
    vector<ll> pre;
    
    
    for(auto i = 1; i<M; i++){
        pre.push_back(X[i]-X[i-1]);
    }
    
    sort(pre.begin(),pre.end(),greater<int>());
    
    for(auto i = 0; i<N-1;i++){
        totallen -=pre[i];
    }
    
    cout << totallen << endl;
    
    return 0;
}




Measured memory_bytes: 2548
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    Int r,d,x;
    cin>>r>>d>>x;

    for(int i = 1;i <= 10;i++) {
        x = r*x-d;
        cout<<x<<endl;
    }

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int X,Y,A,B,C;cin>>X>>Y>>A>>B>>C;
    ll ans=0,mu=0;
    
    priority_queue<pair<ll,int>> PQ;
    
    for(int i=0;i<A;i++){
        int a;cin>>a;
        PQ.push({a,1});
    }
    for(int i=0;i<B;i++){
        int a;cin>>a;
        PQ.push({a,2});
    }
    for(int i=0;i<C;i++){
        int a;cin>>a;
        PQ.push({a,3});
    }
    
    while((X+Y-mu>0)){
        pair<ll,int> p=PQ.top();PQ.pop();
        if(p.second==1&&X){
            ans+=p.first;
            X--;
        }
        if(p.second==2&&Y){
            ans+=p.first;
            Y--;
        }
        if(p.second==3){
            ans+=p.first;
            mu++;
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 10604
n = int(input())
a = [int(i) for i in input().split()]
num,num2 = 0,0
for i in range(n):
	if abs(a[i])>abs(num): num,num2=a[i],i
print(2*n-2)
for i in range(n):
	if i!=num2: print(num2+1,i+1)
if num<0:
	for i in range(n-1,0,-1): print(i+1,i)
else:
	for i in range(n-1): print(i+1,i+2)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	int rec = 0;
	for (int i = A; i <= B; i++) {
		string S = to_string(i);
		if (S[0] != S[4] || S[1] != S[3]) {
			rec++;
		}
	}
	cout <<  B - A - rec + 1 << endl;
	return 0;
}

Measured memory_bytes: 3740
#include<stdio.h>
int main(){
    int N,A,B,mul;
    scanf("%d %d %d",&N,&A,&B);
    mul=N*A;
    if(mul<B){
        printf("%d\n",mul);

    }
    else if(B<mul){
        printf("%d\n",B);
    }
    else {
        printf("%d",B);
    }




return 0;
}



Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N =sc.nextInt();
    Map<Integer,Integer> button = new HashMap<>();
    for(int i=1; i<=N; i++){
      button.put(i,sc.nextInt());
    }
    int key=1;
    long cnt=1L;
    for(long i=1; i<=100001L; i++){
      if(button.get(key)==2){
        break;
      }else if(i==100001L){
        cnt=-1L;
      }else{
        cnt++;
        key=button.get(key);
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 66492
#include<stdio.h>
int main(void)
{
	int n,x,y,z,i,j,flg,fh[101][4],cnt;
	int a[101],b[101],c[101];
	scanf("%d %d",&n,&x);
	for(i=0;i<x;i++) scanf("%d",&a[i]);
	scanf("%d",&y);
	for(i=0;i<y;i++) scanf("%d",&b[i]);
	scanf("%d",&z);
	for(i=0;i<z;i++) scanf("%d",&c[i]);
	for(i=1;i<=n;i++){
		for(j=0;j<3;j++) fh[i][j]=0;
	}
	for(i=0;i<x;i++){
		for(j=1;j<=n;j++){
			if(a[i]==j) fh[j][0]=1;
		}
	}
	for(i=0;i<y;i++){
		for(j=1;j<=n;j++){
			if(b[i]==j) fh[j][1]=1;
		}
	}
	for(i=0;i<z;i++){
		for(j=1;j<=n;j++){
			if(c[i]==j) fh[j][2]=1;
		}
	}
	cnt=0;
	for(i=1;i<=n;i++){
		if((fh[i][0]==0&&fh[i][2]==1)||(fh[i][1]==1&&fh[i][2]==1)){
			cnt++;
		}	
	}
	printf("%d\n",cnt);
	return 0;
}	

Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,p;
	cin>>a>>p;

	p=p+(3*a);
	cout<<(p/2);
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int change(int x)
{
	if(x==1)
	return 0;
	else
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    string s1,s2;
    int i;
    for(i=0;i<m;i++)
    {
    	s1.push_back(n+'0');
	}
	for(i=0;i<n;i++)
	{
		s2.push_back(m+'0');
		
	}
	if(s1>s2)
	cout<<s2;
	else
	cout<<s1;
    
}


Measured memory_bytes: 256
n = int(input())
cnt = [0] * n

for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            num = (i + j + k) ** 2 - (i * j + j * k + k * i)
            if num <= n:
                cnt[num - 1] += 1

for i in range(n):
    print(cnt[i])

Measured memory_bytes: 69212
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: u32 = 1_000_000_007;
const INF: i64 = std::i64::MAX;

pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

fn solve() {
	let n = read!(i32);
	let val = (1..n+1).filter(|x| x%2==1).count();
	println!("{}", (val as f32)/(n as f32));
}

fn run() {
    solve();
}

Measured memory_bytes: 8572
def solve():
  x1, y1, x2, y2 = map(int, input().split())

  dx = abs(x2 - x1)
  dy = abs(y2 - y1)
  x3, y3, x4, y4 = 0, 0, 0, 0

  if (x1 <= x2) and (y1 <= y2):
    x3, y3 = x2 - dy, y2 + dx
    x4, y4 = x1 - dy, y1 + dx
  elif (x1 <= x2) and (y1 >= y2):
    x3, y3 = x2 + dy, y2 + dx
    x4, y4 = x1 + dy, y1 + dx

  elif (x1 >= x2) and (y1 <= y2):
    x3, y3 = x2 - dy, y2 - dx
    x4, y4 = x1 - dy, y1 - dx

  elif (x1 >= x2) and (y1 >= y2):
    x3, y3 = x2 + dy, y2 - dx
    x4, y4 = x1 + dy, y1 - dx
  
  print(x3, y3, x4, y4)

solve()

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>
#include <map>

using namespace std;

class BTwoColorsCardGame {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N, M;
        in >> N;
        string s[N];
        for (int i = 0; i < N; ++i) {
            in >> s[i];
        }
        in >> M;
        string t[M];
        for (int i = 0; i < M; ++i) {
            in >> t[i];
        }

        map<string, int> scores;
        for (int i = 0; i < N; ++i) {
            ++scores[s[i]];
        }
        for (int i = 0; i < M; ++i) {
            --scores[t[i]];
        }

        int max = 0;
        for (const auto& score : scores) {
            if (score.second > max) {
                max = score.second;
            }
        }
        int ret = max;
        if (max < 0) {
            ret = 0;
        }
        out << ret;
    }
};


int main() {
	BTwoColorsCardGame solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>

using namespace std;
typedef long long int lli;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long int> llv;
typedef vector<double> dv;

#define sor_(vec) sort(vec.begin(),vec.end())
#define rev_(vec) reverse(vec.begin(),vec.end())
#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
const long long mod = 1000000007;

template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    std::reverse(ret.begin(), ret.end());

    return ret;
}

int upf(double num){
    if(num-(int)num>0)return (int)num+1;
    else return num;
}

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}

struct Chara{
    int hp;
    int sp;
};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,a,b;
    cin>>k>>a>>b;
    if(a/k==0){
        if(k<=b)cout<<"OK";
        else cout<<"NG";
    }
    else if(b%k<=b-a)cout<<"OK";
    else cout<<"NG";
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const int N=440000;
int a[N];
int k,n,ans;
int main(){
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	
	for(int i=1;i<n;++i)a[n+i]=a[i]+k;
	ans=k;
	
	for(int i=n;i<2*n;++i)ans=min(ans,a[i]-a[i-n+1]);
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
int a,b,c,d,e,f,g,n,m,j;
int nm[100][100]={0},mj[100][100]={0};
long int C[100][100];
scanf("%d %d %d",&n,&m,&j);
for(a=0;a<n;a++){
for(b=0;b<m;b++){
scanf("%d",&nm[a][b]);
}
}
for(a=0;a<m;a++){
for(b=0;b<j;b++){
scanf("%d",&mj[a][b]);
}
}
for(a=0;a<n;a++){
for(b=0;b<j;b++){
for(c=0;c<m;c++){
C[a][b]+=nm[a][c]*mj[c][b];
}
printf("%ld",C[a][b]);
if(b<j-1)
printf(" ");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 764
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
    int n;
    int m;
    int a[1001];
    int s;



    cin>>n;
    cin>>m;

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

   for(int k=1; k<m+1; k++){
	   for(int i=1; i<n; i++){
		  if(a[i]%k>a[i+1]%k){
			  s=a[i];
			  a[i]=a[i+1];
			  a[i+1]=s;
		  }
	   }
   }
   for(int j=1; j<n+1; j++){
 	  cout<<a[j]<<endl;
   }
}

Measured memory_bytes: 3100
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[][] a = new int[n][m];
		int[] b = new int[m];
		
		for(int i1 = 0; i1 < n; i1++) {
			for(int i2 = 0; i2 < m; i2++) {
				a[i1][i2] = sc.nextInt();
			}
		}
		
		for(int i3 = 0; i3 < m; i3++) {
			b[i3] = sc.nextInt();
		}
		
		for(int i4 = 0; i4 < n; i4++) {
			int c = 0;
			
			for(int i5 = 0; i5 < m; i5++) {
				c += a[i4][i5] * b[i5];
			}
			
			System.out.println(c);
		}
	}
}



Measured memory_bytes: 40164
//Author: master19
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ulli unsigned long long int
#define lli long long int 
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define f first 
#define s second 
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define mod 1000000007
int main(){
    ll num, a, b, temp;
    cin >> num;
    ll lessA = 0, greaterA = 0, greaterB = 0;
    cin >> a >> b;
    for(int i=0;i<num; i++){
        cin >> temp;
        if(temp <= a)
            lessA++;
        else if(temp <= b)
            greaterA++;
        else    
            greaterB++;
    }
    cout << min(lessA, min(greaterA, greaterB)) << endl;
}


Measured memory_bytes: 256
object Main extends App{
  import scala.io.StdIn._

  val (min::mid::max::_) =  readLine().trim().split(' ').map(_.toInt).sorted.toList
  def solve(min:Int, mid:Int, max:Int):Int = {
    if (min == mid && mid == max)
      0
    else if (max - min == 1) {
      if (max == mid) 2
      else 1
    }else{
      if (mid - min >= 2){
        solve(min + 2, mid, max) + 1
      }else{
        solve(mid, min + 2, max) + 1
      }
    }
  }
  println(solve(min, mid, max))
}

Measured memory_bytes: 27332
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

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

  string S[110];
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }

  sort(S, S+N);

  stringstream ss;
  for (int i = 0; i < N; ++i) {
    ss << S[i];
  }

  cout << ss.str() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char **argv)
{
    char w[128];
    scanf("%s", w);

    int c[26] = {};
    for (int i = 0; w[i] != '\0'; ++i) {
        c[w[i]-'a']++;
    }
    for (int i = 0; i < 26; ++i) {
        if (c[i] % 2 == 1) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int32_t main(){
	int n, k; cin>>n>>k;
	vector<int>v(n);
	for(int i=0; i<n; i++) cin>>v[i];
	sort(v.begin(), v.end());
	int ans=0;
	for(int i=0; i<k; i++) ans+=v[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long int
#define cin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define ull unsigned long long
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rf1(i,a,n) for(int i=a;i>n;i--)
#define cases() int q;cin>>q;while(q--)
#define ld long double
#define cout(a,n) for(i=0;i<n;i++)cout<<a[i]<<" ";
#define inf 1e9;
#define mod 1000000007;
#define PI 3.14159265358979323846264338327950L
using namespace std;

int main(){
    ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int a,b;
cin>>a>>b;
string ans ="No";
for(int i=0;i<a+1;i++){
    if((2*i+4*(a-i))==b){
        ans = "Yes";
        break;
}
}
cout<<ans;
 return 0;
 }


Measured memory_bytes: 3620
import java.io.*;

public class Main{
    public static void main(String args[]) throws Exception{
    	final int PRICE= 100;
    	int num_hrs, win_hrs, edge;
    	int vote_tot,vote_win, div;
    	
    	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    	String str;
        while( !( (str= br.readLine()).equals("0 0 0") ) ){
        	String[] buf= str.split(" ");  
        	num_hrs= Integer.parseInt(buf[0]);
            win_hrs= Integer.parseInt(buf[1])-1;
        	   edge= Integer.parseInt(buf[2]);
            vote_tot= vote_win= 0;
            for(int i=0;i<num_hrs;i++){
            	if( i==win_hrs ){
            		vote_win= Integer.parseInt(br.readLine());
            		vote_tot+= vote_win;
            	} else{
                	vote_tot+= Integer.parseInt(br.readLine());
            	}
            }
            
            if( vote_win !=0 ){
            	div= (100-edge)*vote_tot/vote_win;
            	System.out.println(div);
            } 
            else{ System.out.println(0); }
        }
    }
}

Measured memory_bytes: 22492
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int h,n,s,x,i;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>h>>n;
	for(i=1;i<=n;i++)cin>>x,s+=x;
	h-=s;
	if(h<=0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
N,M =list(map(int,input().split()))

if N >=2 and M >=2:
    ans = N*(N-1)/2 + M*(M-1)/2
elif  N >=2 and M <2:
    ans = N*(N-1)/2
elif  N <2 and M >=2:
    ans =  M*(M-1)/2
else:
    ans = 0
print(int(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M;
    vector<int> L(M),R(M); rep(m,0,M) cin>>L.at(m)>>R.at(m);

    sort(ToEnd(L));
    sort(ToEnd(R));

    cout<<max(0,R.at(0)-L.at(M-1)+1)<<endl;
}

Measured memory_bytes: 1024
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const Arr = (input.trim()).split("\n");
const N1 = Number(Arr[0]);
const arr1 = Arr[1].split(" ").map(Number);
const arr2 = Arr[3].split(" ").map(Number);

const summing = (a, b) => a + b;
console.log(arr2.map(key => {   
  let mid;
  let left = 0;
  let right = N1;
  if (key < arr1[0] || arr1[N1-1] < key) return 0;
  while (left < right) {
    mid = Math.floor((left + right) / 2);
    if (key < arr1[mid]) right = mid;
    else if (key > arr1[mid]) left = mid + 1;
    else return 1;
  }
  return 0;
}).reduce((a, b) => a + b, 0));



Measured memory_bytes: 34936
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 
#define MAXN 1010*4
using namespace std;

int n,m,k,suf[MAXN][MAXN];

inline int f(int XA,int YA,int XB,int YB)
{
	return suf[XA][YA]-suf[XB+1][YA]-suf[XA][YB+1]+suf[XB+1][YB+1];
}

int main()
{
	scanf("%d%d",&n,&k);m=k*2;
	for(int i=0;i<n;i++)
	{
		int x,y;char ch;
		scanf("%d%d %c",&x,&y,&ch);
		suf[x%m][(y+((ch=='B')?k:0))%m]++;	
	}
	
	for(int i=0;i<m;i++)
		for(int j=0;j<m;j++)
			suf[i+m][j]=suf[i][j+m]=suf[i+m][j+m]=suf[i][j];
			
	int res=0;
	
	for(int i=2*m-1;i>=0;i--)
		for(int j=2*m-1;j>=0;j--)
			suf[i][j]=suf[i][j]+suf[i+1][j]+suf[i][j+1]-suf[i+1][j+1];
			
	for(int i=0;i<m;i++)
		for(int j=0;j<m;j++)
			res=max(res,f(i,j,i+k-1,j+k-1)+f(i+k,j+k,i+m-1,j+m-1));
			
	printf("%d\n",res);						
	

	return 0;	
} 

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

int main(){
    int x,t;	cin >> x >> t;
    if(x >= t){
	cout << x-t << endl;
    }else{
	cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//    ____       ____                 _           
//   |  _ \ _ __|  _ \  ___ _ __   __| |_ __ ___  
//   | | | | '__| | | |/ _ \ '_ \ / _` | '__/ _ \ 
//   | |_| | |_ | |_| |  __/ | | | (_| | | | (_) |
//   |____/|_(_)|____/ \___|_| |_|\__,_|_|  \___/ 
//                                                

 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;


#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define f first
#define s second
#define pb push_back
#define ll long long

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll LLOO = 1e18+7;
const ll OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;



int main()
{
	
	int n,m;
	scanf("%d %d",&n,&m);
	ll sum = 0;
	rep(i,m)
	{
		int x;
		scanf("%d",&x);
		sum += x;
	}
	ll ans = n-sum;
	if (ans < 0) printf("-1\n");
	else printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define frr(j,i,n) for(int i=j;i<=n;++i)
using namespace std;
int n;
ll w[101],v[101];
ll W;
ll dp[101][100001];
ll go(int index,int we)
{
    if(index>n || we<=0)
        return 0;
    if(dp[index][we]!=-1)
        return dp[index][we];

    if(w[index]>we)
        return dp[index][we] = go(index+1,we);
    else
    {
        ll x=v[index]+go(index+1,we-w[index]);
        ll y=go(index+1,we);
        return dp[index][we] =  max(x,y);
    }
    
}
void solve()
{
	memset(dp,-1,sizeof(dp));
    cin>>n>>W;
    frr(1,i,n)
    {
        cin>>w[i];
        cin>>v[i];
    }
    cout<<go(1,W)<<"\n";


}
int main() 
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--)
	solve();
	return 0;
}



Measured memory_bytes: 82536
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  vector<ll> vec;
  for(int i=0; i<N; i++){
    ll sum = A[i];
    vec.push_back(sum);
    for(int j=i+1; j<N; j++){
      sum += A[j];
      vec.push_back(sum);
    }
  }
  ll ans = 0;
  vector<bool> use(vec.size(),true);
  for(int i=50; i>=0; i--){
    int cnt = 0;
    for(int j=0; j<vec.size(); j++){
      if(!use[j]) continue;
      if(vec[j] & (1LL<<i)) cnt++;
    }
    if(cnt >= K){
      for(int j=0; j<vec.size(); j++){
        if(!(vec[j] & (1LL<<i))) use[j] = false;
      }
      ans += (1LL<<i);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6516
/**
 *    author:  yoseph
 *    created: 02.08.2020 17:22:10      
**/
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n ;
	cin >> n;
	vector<string> st(n);
	for (int i = 0; i < n; ++i)
		cin >> st[i];
	int a = 0, w = 0, r = 0, t = 0;
	for (auto &x : st) {
		if (x == "AC")
			++a;
		else if (x == "WA")
			++w;
		else if (x == "TLE")
			++t;
		else if (x == "RE")
			++r;
	}
	cout << "AC x " << a << "\nWA x " << w
		<< "\nTLE x " << t << "\nRE x " << r << "\n";
	return 0;
}


Measured memory_bytes: 6376
#include <iostream>

using namespace std;

class Array
{
	int* dataArray;
	int arraySize;

public:

	Array(int arraySize)
	{
		this->arraySize = arraySize;

		dataArray = new int[arraySize];
	}

	Array(const Array& ob);
	
	~Array()
	{
		delete[] dataArray;
	}


	int& operator [](int index)
	{
		return dataArray[index];
	}


	int BubbleSort();

	void ShowArray();

};

Array::Array(const Array& ob)
{
	this->arraySize = ob.arraySize;

	for (int i = 0; i < arraySize; i++)
	{
		this->dataArray[i] = ob.dataArray[i];
	}
}

int Array::BubbleSort()
{
	int count = 0;

	for (int i = 0; i < arraySize - 1; i++)
	{
		for (int j = arraySize - 1; i < j ; j--)
		{
			if (dataArray[j -1] > dataArray[j])
			{
				int temp = dataArray[j - 1];

				dataArray[j - 1] = dataArray[j];
				dataArray[j] = temp;

				count++;
			}
		}
	}

	return count;
}

void Array::ShowArray()
{
	for (int i = 0; i < arraySize; i++)
	{
		if (i > 0)
		{
			cout << " ";
		}
		cout << dataArray[i];
	}

	cout << endl;
}

int main()
{
	int dataSize;
	cin >> dataSize;

	Array data(dataSize);

	for (int i = 0; i < dataSize; i++)
	{
		cin >> data[i];
	}

	int count = data.BubbleSort();

	data.ShowArray();

	cout << count << endl;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define pqueue priority_queue
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    typedef pair<int,int> P;
    int N;
    cin>>N;
    vector<string> S(N);
    rep(0,N){
        cin>>S.at(i);
    }
    sort(S.begin(),S.end());
    vector<string> result(0);
    vin num(0);
    result.push_back(S.at(0));
    num.push_back(1);
    int cnt=0;
    rep(0,N-1){
        if(S.at(i)==S.at(i+1)){
            num.at(cnt)++;
        }
        else{
            result.push_back(S.at(i+1));
            num.push_back(1);
            cnt++;
        }
    }
    int maxn=*max_element(num.begin(),num.end());
    rep(0,num.size()){
        if(num.at(i)==maxn) cout<<result.at(i)<<endl;
    }
    return 0;
}

Measured memory_bytes: 17636
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

constexpr int INF{1001001001};
constexpr lint LINF{1001001001001001001ll};
constexpr int MOD{(int)1e9 + 7};
constexpr double EPS{1e-9};
const double PI{acos(-1)};
constexpr int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)(v.size() - 1) ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int a, b;
  cin >> a >> b;
  if (b > a) print(0);
  else print(a - b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n, k; cin >> n >> k;
    int ans = 0;
    rep(i, n) {
        int x; cin >> x;
        ans += 2*min(abs(x-0), abs(x-k));
    }
    cout << ans;
}


Measured memory_bytes: 256