akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main(void)
{
  char s[200010],t[200010];
  long int len,count=0;
  int start[26],goal[26];
  int i;
  for(i=0;i<26;i++){
    start[i] = -1;
    goal[i] = -1;
  }
  scanf("%s %s",&s,&t);
  len = strlen(s);
  for(i=0;i<len;i++){
    int a = s[i] - 'a';
    int b = t[i] - 'a';
    if(start[a] != -1 || goal[b] != -1){
      if(start[a] != b || goal[b] != a){
        count = 1;
        break;
      }
    }else{
      start[a] = b;
      goal[b] = a;
    }
  }
  puts(count==0?"Yes":"No");
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int a[] = new int [3];
		int b[] = new int [3];
		int c[][] = new int [3][3];
		for ( int i = 0; i < 3; i++) {
			for ( int j= 0;j < 3; j++) {
				c[i][j] = scan.nextInt();
			}
		}

		int temp1 = c[0][1]-c[0][2];
		int temp2 = c[1][1]-c[1][2];
		int temp3 = c[2][1]-c[2][2];

		int temp4 = c[0][0]-c[0][1];
		int temp5 = c[1][0]-c[1][1];
		int temp6 = c[2][0]-c[2][1];

		boolean ans = true;
		if (temp1 != temp2) {
			ans = false;
		}
		if (temp1 != temp3) {
			ans = false;
		}

		if (temp4 != temp5) {
			ans = false;
		}
		if (temp4 != temp6) {
			ans = false;
		}



		if(ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 21972
import sys
import numpy as np
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    SP=['']*N
    for i in range(N):
        S,P=input().split()
        SP[i]=S+str((100-int(P))).zfill(3)
    SP_argsort=np.argsort(SP)
    for i in SP_argsort:
        print(i+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12492
#include <iostream>

using namespace std;

int main()
{
    int N;
    int a;
    bool aA[4001]={};
    cin>>N;
    
    for(int i=0;i<N;i++){
        cin>>a;
        for(int j=4000;j>0;j--){
            if(aA[j]&&j+a<4001){
                aA[j+a]=true;
            }
        }
        aA[a]=true;
    }
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a;
        if(aA[a]){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main(){
  char S1,S2,S3,T1,T2,T3;
  cin >> S1 >> S2 >> S3 >> T1 >> T2 >> T3;
  int count;
  if (S1==T1) count++;
  if (S2==T2) count++;
  if (S3==T3) count++;
  cout << count;
}

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

typedef long long ll;

int cmpnum(const void * n1, const void * n2)
{
  if (*(ll *)n1 > *(ll *)n2)
  {
    return 1;
  }
  else if (*(ll *)n1 < *(ll *)n2)
  {
    return -1;
  }
  else
  {
    return 0;
  }
}

int main(void)
{
  int n;
  scanf("%d",&n);
  ll x[200010];
  ll y[200010];
  for(int i=0;i<n;i++){
    scanf("%lld",&x[i]);
  }
  for(int i=0;i<n;i++){
    y[i]=x[i];
  }

  qsort(y, n, sizeof(ll), cmpnum);

  // for(int i=0;i<n;i++){
  //   printf("%lld ",y[i]);
  // }
  // puts("");

  for(int i=0;i<n;i++){
    if(x[i]<=y[n/2-1]){
      printf("%lld\n",y[n/2]);
    }else{
      printf("%lld\n",y[n/2-1]);
    }
  }

  return 0;
}


Measured memory_bytes: 6228
#include "bits/stdc++.h"
using namespace std;

int main()
{
  vector<int> input;
  int n;
  for(int i=0; i<3; i++){
    cin >> n;
    input.push_back(n);
  }
  sort(input.begin(), input.end());
  cout << input.at(0)+input.at(1);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define orta ((bas+son)/2)
#define N 805
using namespace std;

typedef pair < int , int > ii;

int n, m, k, x, y, a[N][N], u[N][N];
int o[] = {1, -1, 0, 0};
int p[] = {0, 0, -1, 1};
char orz;

bool git(int i, int j){
	return !(i < 1 or j < 1 or i > n or j > m or u[i][j] or a[i][j]);
}

bool dene(int z){
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			u[i][j] = 0;
	u[x][y] = 1;
	queue < pair < int , ii > > q;
	q.push(mp(k, mp(x, y)));
	int mn = N;
	while(!q.empty()){
		int kal = q.front().st;
		int i = q.front().nd.st;
		int j = q.front().nd.nd;
		q.pop();
		mn = min(mn, i - 1);
		mn = min(mn, j - 1);
		mn = min(mn, n - i);
		mn = min(mn, m - j);
		if(!kal)
			continue;
		for(int k = 0; k < 4; k++)
			if(git(i + o[k], j + p[k]) ){
				q.push(mp(kal - 1, mp(i + o[k], j + p[k])) );
				u[i + o[k]][j + p[k]] = 1;
			}
	}
	int gt = mn / k + (mn % k != 0) + 1;
	return (gt <= z);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d %d",&n ,&m ,&k);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			scanf(" %c" ,&orz);
			if(orz == 'S'){
				x = i;
				y = j;
			}
			if(orz == '#')
				a[i][j] = 1;
		}
	int bas = 1, son = n*m + 2;
	while(bas < son){
		if(dene(orta))
			son = orta;
		else
			bas = orta + 1;
	}
	printf("%d\n", orta);
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

int h,w;
char board[105][105];
int c[105][105];

int main() {
  cin >> h >> w;
  rep(i,h) {
    rep(j,w) {
      cin >> board[i][j];
      c[i][j]=123456789;
    }
  }

  rep(i,h){
    rep(j,w){
      if(i==0&&j==0){
            if(board[0][0]=='#')c[0][0]=1;
            else c[0][0]=0;}

      if(i>0)c[i][j]=min(c[i][j],c[i-1][j]+(board[i-1][j]=='.'&&board[i][j]=='#'));
      if(j>0)c[i][j]=min(c[i][j],c[i][j-1]+(board[i][j-1]=='.'&&board[i][j]=='#'));
    }
  }

  //rep(i,h){rep(j,w){cout << c[i][j];}cout << endl;}
  cout << c[h-1][w-1];
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto xa = readNums!int;

  if(xa[0] < xa[1]){
    writeln(0);
  } else {
    writeln(10);
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007
using namespace std;
 
#define MAXN 1000005
int spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
        spf[i] = i;
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;
 
    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
 
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
 
 
vector<int> gf(int x)
{
    vector<int> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
int BIT[100050]; //fenwick
void upd(int x) { ++x;  while(x<=MAXN)  {  BIT[x]++;  x+=(x&-x);  } }
int cal(int x) {  ++x;  int res=0;  while(x>0)  {  res+=BIT[x];  x-=(x&-x);  } return res; }
ll Com[1051][1051];
void pre()
{
 
    ll i,j,n=1051;
    rep(i,0,n) Com[i][0]=Com[i][i]=1;
    rep(i,2,n)
    {
        rep(j,1,i)
        {
            Com[i][j]=Com[i-1][j]+Com[i-1][j-1];
            Com[i][j]%=hell;
        }
    }
 
}
ll mod=998244353;
ll pr( ll x , ll y)
{
    ll ans=1;
    if(y==0) return ans;
    while(y>1)
    {
        if(y&1) ans*=x;
        x*=x;
        y/=2;
        x%=mod;
        ans%=mod;
    }
    ans*=x;
    ans%=mod;
    return ans;
}
ll inv(ll n)
{
    return pr(n,mod-2);
}
ll stoi(string s)
{
    int n=s.size();
    ll k=0; int i;
    rep(i,0,n)
    {
        k+=s[i]-'0';
        k*=10;
    }
    return k/10;
}
string to_string(ll n)
{  if(!n) return "0";
    string s=""; int a,b;
    while(n>0)
    {
        b=n%10;
        s+=(b+'0');
        n/=10;
    }
    reverse(all(s));
    return s;
}
 
 
void solve()
{
ll i,j=0,r=200,p,q,k=0,d,y=0,n,h=100000000000000,flag=0,m=0,a=hell,b=hell,id,h1,h2,a1,b1,a2,w,x,u,f,l,c=0,e,ans=0;
cin>>m;
rep(i,1,m+1)
{
    if(i%3==0 or i%5==0) continue;
    else y+=i;
    
}
cout<<y;
}
 
 
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //sieve();
    //cin>>t;
    while(t--)
    solve();
}

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

using ll = long long;

const int max_N = (int)1e5 + 21;

int N;

ll C, x[max_N], _x[max_N], v[max_N];

ll sv[max_N], _sv[max_N];

ll f[max_N], g[max_N];

int main(){
    scanf("%d%lld", &N, &C);
    for(int i=1;i<=N;++i){
        scanf("%lld%lld", x+i, v+i);
        sv[i] = sv[i-1] + v[i];
    }
    for(int i=1;i<=N;++i){
        _x[i] = C - x[N-i+1];
        _sv[i] = _sv[i-1] + v[N-i+1]; 
    }
    ll ans = 0;
    for(int i=1;i<=N;++i){
        ans = std::max(ans, sv[i] - x[i]);
        ans = std::max(ans, _sv[i] - _x[i]);
    }
    for(int i=1;i<=N;++i){
        f[i] = std::max(f[i-1], sv[i] - 2*x[i]);
        g[i] = std::max(g[i-1], _sv[i] - 2*_x[i]); 
    }
    for(int i=1;i<=N;++i){
        ans = std::max(ans, f[N-i] + _sv[i] - _x[i]);
        ans = std::max(ans, g[N-i] + sv[i] - x[i]);
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main()
{
    int n,d,x;
    cin >> n >> d >> x;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int a;
        cin >> a;
        if(d%a==0)
            sum+=d/a;
        else
            sum+=d/a+1;
    }
    cout << sum+x << endl;
    return 0;
}


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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define Sort(v) sort(all(v))


/* constant */
const int inf = 100100100100100100;
const int mod = 998244353;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
vector<int> cs(vector<int> arr){vector<int> tmp;if(arr.size() == 0) return tmp;tmp.push_back(arr[0]);rep(i,1,arr.size()){tmp.push_back(tmp.back() + arr[i]);}return tmp;}

/* math_library */
int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b);}
int lcm(int a, int b){ return a * b / gcd(a,b);}
int ceil(int a, int b){ if(a % b == 0) return a/b; else return a/b + 1;}
int digitlen(int n){int t = n;int cnt = 0;while(t){cnt++;t /= 10;}return cnt;}
bool isprime(int n){if(n < 2) return false;if(n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false;for(int i = 7; i * i < n + 1; i += 2){if(n % i == 0) return false;}return true;}
int mod_pow(int x, int n, int m){if(n== 0) return 1;int res = mod_pow(x*x%m,n/2,m);if(n&1) res = res*x%m;return res;}
int digitsum(int n){int ret = 0;while(n){ret += n % 10;n /= 10;}return ret;}



/* main */


signed main(){

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

    int arr[1001][1001];
    memset(arr, 0, sizeof(arr));

    int n = input();

    rep(i,0,n){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        arr[y1][x1]++;
        arr[y1][x2]--;
        arr[y2][x1]--;
        arr[y2][x2]++;

    }

    rep(i,1,1001){
        rep(j,0,1001){
            arr[i][j] += arr[i-1][j];
        }
    }

    rep(j,1,1001){
        rep(i,0,1001){
            arr[i][j] += arr[i][j-1];
        }
    }

    int ans = 0;
    rep(i,0,1001) rep(j,0,1001) chmax(ans, arr[i][j]);

    print(ans);



    








}   


Measured memory_bytes: 11052
package main

import (
	"fmt"
)

func main() {
	var N, Y int
	a, b, c, C := -1, -1, -1, 0
	fmt.Scanf("%d %d", &N, &Y)
	for i := 0; i <= N; i++ {
		for ii := 0; i+ii <= N; ii++ {
			C = N - i - ii
			if 10000*i+5000*ii+1000*C == Y {
				a = i
				b = ii
				c = C
			}
		}
	}
	fmt.Printf("%d %d %d", a, b, c)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;


int main(){
	ll n;
	cin>>n;
    string s[n];
    rep(i,0,n)cin>>s[i];
    bool p=false,w=false,g=false,y=false;
    rep(i,0,n){
        if(s[i][0]=='P')p=true;
        if(s[i][0]=='W')w=true;
        if(s[i][0]=='G')g=true;
        if(s[i][0]=='Y')y=true;
    }
    ll ans=0;
    if(p)ans++;
    if(w)ans++;
    if(g)ans++;
    if(y)ans++;

    if(ans==4)cout<<"Four";
    else cout<<"Three";


}


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

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("[\\s]+");
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            long max = Long.MIN_VALUE;
            int[] vars = new int[n];
            for (int i = 0; i < n; i++) {
                vars[i] = sc.nextInt();
            }
            for (int i = 0; i < n; i++) {
                long cur = 0;
                for (int j = i; j < n; j++) {
                    cur+=vars[j];
                    max = max >  cur ? max : cur;
                }
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 39804
import itertools

N = int(input())
# [[1番の人の証言], [2番の人の証言], ..., [N番の人の証言]]
l = [[-1 for _ in range(N)] for _ in range(N)]
# N人についてそれぞれ証言をまとめる
for i in range(N):
    # 証言の数
    a = int(input())
    # 各証言をlに格納
    for _ in range(a):
        x, y = map(int, input().split())
        l[i][x - 1] = y

ans = 0

# 全通りを列挙
perm = list(itertools.product([0, 1], repeat=N))
# それぞれの選び方について
for p in perm:
    flag = True
    # pの中身を左から順に見ていく
    for j in range(N):
        # 既に破綻していたら、以降は証言をチェックする必要はない
        if flag == False:
            break
        # jの全員に対する証言について
        for k in range(N):
            # 狂人(p[j]==0)の証言は意味がないので無視して良い
            if p[j] == 1:
                # l[j][k] == -1 なら、その人に対する証言は存在しない
                # kについての証言と、kの実情が異なる場合（矛盾）
                if l[j][k] != -1 and l[j][k] != p[k]:
                    flag = False
                    break

    # 一つも矛盾が存在しなかった場合
    # sum(d)は聖人の総数を表す
    if flag == True:
        ans = max(ans, sum(p))

print(ans)


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

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

    cin>>x>>a>>b;

    if(b<=a)
    {
        cout<<"delicious\n";
    }
    else if((b-a)<=x)
    {
        cout<<"safe\n";
    }
    else
    {
        cout<<"dangerous\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second

using namespace std;

ll gcd(ll n1,ll n2){
	if(!n1)return n2;
	if(!n2)return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	base%=mod;
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	ans%=mod;
	return ans;
}
ll arr[upperlimit+1];
int main()
{
	int n,i,j,k;
	ll x;
	cin>>n>>x;
	ll answer=0;
	for(i=1;i<=n;i++){
		slld(arr[i]);
		answer+=max(0LL,arr[i]-x);
		arr[i]=min(arr[i],x);
	}
	for(i=2;i<=n;i++)if(arr[i]+arr[i-1]>x){
        ll temp=(arr[i]+arr[i-1]-x);
        answer+=temp;
        arr[i]-=temp;
	}
	cout<<answer<<endl;
	return 0;
}


Measured memory_bytes: 1024
#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;
  vector<int> p(n), s(n+1); rep(i, n) cin >> p[i];
  s[0] = 0;
  rep(i, n) s[i+1] = s[i] + p[i];
  int mx = 0, f = 0;
  rep(i, n - (k - 1)) {
    if (mx < (s[i + k] - s[i])) {
      mx = s[i + k] - s[i];
      f = i;
    }
  }
  double ans = 0;
  for (int i = f; i < f + k; i++) {
    ans += p[i];
  }
  ans = (ans + k) / 2;
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
LL ans,x,pr[100005],sf[100005],co[100005],mul[100005];
int n;
int main()
{
    scanf("%d",&n);
    pr[0]=1,sf[n+1]=1,sf[n+2]=1;
    for(int i=1;i<=n;i++)pr[i]=pr[i-1]*i,pr[i]%=MOD;
    for(int i=n;i>0;i--)sf[i]=sf[i+1]*i,sf[i]%=MOD;
    for(int i=1;i<=n;i++)co[i]=co[i-1]+(pr[i]*sf[i+2]),co[i]%=MOD;
    for(int i=1;i<=(n+1)/2;i++)
    {
        mul[i]+=co[n-i];
        mul[i]+=co[i-1];
        mul[i]%=MOD;
    }
    for(int i=n;i>n/2;i--)mul[i]=mul[n-i+1];
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        ans+=x*pr[n];
        ans%=MOD;
        ans+=x*mul[i];
        ans%=MOD;
    }
    printf("%lld",(ans+MOD*50)%MOD);
}


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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

int main() {
	Boost();

	int n; cin >> n;
	vector < int > v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];

	map < int, int > Map[2];
	for (int i = 0; i < n; ++i) {
		++Map[i % 2][v[i]];
	}

	pair < int, int > mx[2][2];
	for (int i = 0; i < 2; ++i) {
		for (auto x : Map[i]) {
			pair < int, int > M = {x.second, x.first};
			if (M >= mx[i][0]) {
				mx[i][1] = mx[i][0];
				mx[i][0] = M;
			} else {
				if (M > mx[i][1]) {
					mx[i][1] = M;
				}
			}
		}
	}

	if (mx[0][0].second != mx[1][0].second) {
		cout << n - mx[0][0].first - mx[1][0].first;
	} else {
		cout << n - max(mx[0][0].first + mx[1][1].first, mx[0][1].first + mx[1][0].first);
	}
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int a,b;
   int d,r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = (double)a / b;
    printf("%d %d %f\n", d, r, f);
    
  
   
    
}



Measured memory_bytes: 3216
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if((a < c && b > c)||(b < c && a > c)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#define MAX 1000000

int A[MAX+1],H=0;

void insert(int);

int extract();
void increasekey(int,int);
void maxHeapify(int);

int main()
{
  int key;
  char com[20];
  while(1)
    {
      scanf("%s",com);
      if(com[0] == 'e' && com[1] == 'n')
	break;
      if(com[0] == 'i')
	{
	  scanf("%d",&key);
	  insert(key);
	}
      else
	printf("%d\n",extract());
    }
  return 0;
}

void insert(int key)
{
  H++;
  A[H] = -1;
  increasekey(H,key);
}

void increasekey(int i,int key)
{
  int k;
  if(key < A[H])
    return;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i])
    {
      k = A[i/2];
      A[i/2] = A[i];
      A[i] = k;
      i = i/2;
    }
}

int extract()
{
  int maxv;
  if( H < 1)
    return -1;
  maxv = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(1);
  return maxv;
}

void maxHeapify(int u)
{
  int l = 2 * u,r = 2 * u + 1,max,k;

  if(l <= H && A[l] > A[u])
    max = l;
  else
    max = u;
   if(r <= H && A[r] > A[max])
     max = r;


  if(max != u)
    {
      k=A[u];
      A[u] = A[max];
      A[max] = k;
      maxHeapify(max);
    }
}



Measured memory_bytes: 5688
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cctype>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(N), B(N), C(M), D(M);
    REP(i, N) cin >> A[i] >> B[i];
    REP(i, M) cin >> C[i] >> D[i];
    REP(i, N) {
        int ans = 0;
        ll d = INF;
        REP(j, M) {
            if (abs(A[i] - C[j]) + abs(B[i] - D[j]) < d) {
                ans = j + 1;
                d = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int A,Z;
  int i=0;
  int Flag=0;
  int L=s.size();

  for(int i=0;i<L;i++){
    if(s[i]=='A' && Flag==0){
      A=i;
      Flag=1;
    }
    if(s[i]=='Z')Z=i;
  }
  cout<<(Z-A)+1<<endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;

int main(){
  ll n,k;
  cin >> n >> k;
  n %= k;
  cout << min(n,k-n) << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    B.at(A.at(i)-1) = i+1;
  }
  if (N > 1) {
    for (int i = 0; i < N-1; i++) {
      cout << B.at(i) << " ";
    }
  }
    cout << B.at(N-1) << endl;
}



Measured memory_bytes: 1664
let () =
    let _ = read_int () in
    let x =
        read_line ()
        |> Str.split (Str.regexp " ")
        |> List.map int_of_string
    in
    let length = List.length x in
    let sorted_x = List.sort compare x in
    let lesser_median = List.nth sorted_x (length / 2 - 1) in
    let greater_median = List.nth sorted_x (length / 2) in
    List.map (fun n -> if n > lesser_median then lesser_median else greater_median) x
    |> List.iter (fun n -> print_endline (string_of_int n))


Measured memory_bytes: 33664
# ABC081B - Shift only
from functools import reduce
from operator import or_


def main():
    # bitwise or of sequence -> find rightmost 1-bit
    N, *A = map(int, open(0).read().split())
    x = reduce(or_, map(int, A))
    ans = bin(x)[::-1].find("1")
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
ll pow(int n,int sisu){
    ll res = 1;
    REP(i,sisu){
        res *= n;
    }
    return res;
}

int main()
{
    string S;
    ll ans = 0;
    ll temp=0;
    int a;
    cin >> S;
    REP(i,pow(2,S.length()-1)){
        temp = S[0]-'0';
        for(int j = 0; j < S.length()-1; j++){
            //a = i& (1 << j);
            //printf("%d & (1 << %d) = %d\n",i,j,a);
            if(i & (1 << j)){
                //cout << temp << "+";
                ans += temp;
                temp = S[j+1]-'0';
            }else{
                temp *= 10;
                temp += S[j+1]-'0';
            }
        }
        ans += temp;
        //cout << temp << endl;
    }
    fin(ans);
    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

const int INF = (1<<21);

int main(){
  int i,j,n,a[27],s,t,G[27][27],d[27];
  string str;
  bool f,v[27],fa[27];
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<27;i++){
      a[i] = 0;
      d[i] = INF;
      fa[i] = false;
      v[i] = false;
      for(j=0;j<27;j++) G[i][j] = INF;
    }

    for(i=0;i<n;i++){
      cin >> str;
      s = str[0]-'a';
      t = str[str.size()-1]-'a';
      a[s]++;
      a[t]--;
      v[s] = true;
      v[t] = true;
      G[s][t] = G[t][s] = 1;
    }

    d[s] = 0;
    while(1){
    int min = INF;
     int p;
      for(i=0;i<27;i++){
	if(!fa[i] && d[i] < min){
	  min = d[i];
	  p = i;
	}
      }
      if(min == INF) break;
      fa[p] = true;
      for(i=0;i<27;i++){
	if(fa[i] || !v[i]) continue;
   	if(G[p][i] < d[i]) d[i] = G[p][i];
      }
    }

    f = true;

    for(i=0;i<27;i++){
      if(a[i] || (v[i] && !fa[i])){
	f = false;
	break;
      }
    }
    if(f) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
// Justice will be served
// شهید حاج قاسم سلیمانی

#include <bits/stdc++.h>
using namespace std ;

#define all(x) x.begin() , x.end()

#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()

#define debug(x) cerr << #x << " = " << x << endl

typedef long long ll ;
typedef pair<int , int> pii ;

const int MAX_N = -1 ;
const int inf = 2e9 + 19 ;

string s[] = {"SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT"} ;

int main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        string t ;
        cin >> t ;
        for (int i = 0 ; i < 7 ; i ++)
                if (s[i] == t)
                        cout << 7 - i ;
        return (0) ;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

int main()
{
    ll A, B;
    cin >> A >> B;

    // A * n + 1
    cout << (B - 1 + A - 2) / (A - 1) << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, a, b = list(map(int, readline().split()))
ans = 0
for i in range(n+1):
    y = list(str(i))
    y = [int(z) for z in y]
    if a <= sum(y) <= b:
        ans += i
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String[] card1 = new String[36];
		String[] card2 = new String[36];
		
		int n = stdIn.nextInt();
		for (int i = 0; i < n; i++) {
			card1[i] = stdIn.next();
		}
		
		for (int i = 0; i < n; i++)
			card2[i] = card1[i];
		
		
		BubbleSort(card1, n);
		SelectionSort(card2, n);
		
		System.out.print(card1[0]);
		for (int i = 1; i < n; i++)
			System.out.print(" " +card1[i]);
		System.out.println();
		System.out.println("Stable");
		
		System.out.print(card2[0]);
		for (int i = 1; i < n; i++)
			System.out.print(" " +card2[i]);
		System.out.println();
		
		if (isStable(card1, card2, n))
			System.out.println("Stable");
		else
			System.out.println("Not stable");
	}
	
	public static void BubbleSort(String[] a, int n) {
		int flag = 1, i;
		String t;
		while (flag != 0) {
			flag = 0;
			for (i = n - 1; i > 0; i--) {
				if (a[i].charAt(1) < a[i-1].charAt(1)) {
					t = a[i];
					a[i] = a[i-1];
					a[i-1] = t;
					flag = 1;
				}
			}
		}
	}
	
	public static void SelectionSort(String[] a, int n) {
		int i, j, minat;
		String t;
		for (i = 0; i < n; i++) {
			minat = i;
			for (j = i + 1; j < n; j++)
				if (a[j].charAt(1) < a[minat].charAt(1))
					minat = j;
			if (i != minat) {
				t = a[i];
				a[i] = a[minat];
				a[minat] = t;
			}
		}
	}
	
	public static boolean isStable(String[] a, String[] b, int n) {
		for (int i = 0; i < n; i++)
			if (a[i].charAt(0) != b[i].charAt(0))
				return false;
		return true;
	}
}

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

using namespace std;


//全ての約数リストO(√n)
vector<int> allDivisors(int x) {
	int sx = (int) sqrt(x);

	vector<int> v;
	for (int n = 1; n <= sx; n++) {
		if (x % n == 0) {
			int m = x / n;
			v.push_back(n);
			if (n != m) v.push_back(m);
		}
	}
	sort(v.begin(), v.end());
	return v;
}



//最大公約数
//ベクトルの中で最大の数を取り、その約数を他のベクトルの要素でも割れるかを各自チェック
//O(nm+√k) m:約数の数, k:最大数の値
int greatestCommonFactor(vector<int> v) {
	sort(v.begin(), v.end());
	int maxval = v[v.size() - 1];
	vector<int> divisors = allDivisors(maxval);
	int n = divisors.size();
	int gcf = 1;
	for (int i = 0; i < n; i++) {
		int cf = divisors[n - 1 - i];
		int counter = 0;
		for (int val : v) {
			if (val % cf != 0) break;
			counter++;
		}
		if (counter == v.size()) {
			gcf = cf;
			break;
		}
	}
	return gcf;
}


int main() {
	int N, X;
	cin >> N >> X;
	vector<int> x;
	for (int i = 0; i < N; i++)
	{
		int z; cin >> z; x.push_back(abs(z - X));
	}

	int gcf = greatestCommonFactor(x);
	cout << gcf << endl;

	return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <cstdio>
using namespace std;
 
int main() {
    double a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f) {
        double y = (c*d - a * f) / (b*d - a * e);
        double x = c / a - b * y / a;
        x *= 1000;
        x = (int)(x + 0.5 - (x < 0));
        x /= 1000;
        y *= 1000;
        y = (int)(y + 0.5 - (y < 0));
        y /= 1000;
        printf("%.3f %.3f\n", x, y);
    }
}


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



int main() {
	int H, N;
	cin >> H >> N;
	int A[100010];
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		total += A[i];
	}


	if(total>=H)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 640
#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; cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++) cin>>vec[i];
  sort(vec.begin(),vec.end());
  cout << vec[N-1]-vec[0] << endl;
}


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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int rec = 0;
    int cum = 0;
    for (auto c : S){
        if (c == 'I'){
            ++cum;
            rec = max(rec, cum);
        }else{
            --cum;
        }
    }
    cout << rec << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000

int size, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= size && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= size && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if ( size < 1 ) return;
  maxv = A[1];
  A[1] = A[size--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  int tmp;
  if ( key < A[i] ) return;
  A[i] = key;
  while ( i > 1 && A[i/2] < A[i] ){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int key){
  size++;
  A[size] = -1000000001;
  increaseKey(size, key);
}

int main(){
  int k;
  char com[20];
  while(1){
    scanf("%s",com);
    if ( com[0] == 'i' ){
      scanf("%d",&k);
      insert(k);
    } else if ( strcmp(com,"extract") == 0  ){
      printf("%d\n",extract());
    } else break;
  }

  return 0;
}


Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
int main(){
	double x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	double ans;
	if(x2==x1/2&&y2==y1/2)
	{
		ans=x1*y1/2;
		cout<<fixed<<setprecision(6)<<ans<<' '<<1;
	return 0;	
	}
	else
	{
		ans=x1*y1/2;
		cout<<fixed<<setprecision(6)<<ans<<' '<<0;
		return 0;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vecInt = vector<int>;
using vecLong = vector<long long>;
#define rep(i,l,n) for(int i=l;i<n;i++)

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    int n;
    cin >> n;
    vecInt a(n);
    rep(i,0,n) cin >> a[i];
    vecInt div(1000010);
    rep(i,0,n){
        if (div[a[i]]>=2) continue;
        int x = a[i];
        while (x<1000010){
            div[x] += 1;
            x += a[i];
        }
    }
    int ans = 0;
    rep(i,0,n){
        if (div[a[i]]==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7912
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    out(max(0LL, min(b, d) - max(a, c)));
    re0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var mod = 1000000007;

        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(long.Parse).ToArray();

        var sum = 0L;
        for (int i = 0; i < N; i++)
        {
            sum += A[i];
            sum %= mod;
        }

        var result = 0L;
        for (int i = 0; i < N; i++)
        {
            sum -= A[i];
            if (sum < 0)
            {
                sum += mod;
            }
            result += A[i] * sum;
            result %= mod;
        }

        Console.WriteLine(result);
    }
}


Measured memory_bytes: 47908
#include <bits/stdc++.h>
#define rep( i, n ) for( int ( i ) = 0; ( i ) < ( n ); ( i )++ )
#define repr( i, n ) for( int ( i ) = ( n ); ( i ) >= 0; ( i )-- )
#define FOR( i, m, n ) for( int ( i ) = ( m ); ( i ) < ( n ); ( i )++ )
#define all( x ) ( x ).begin(), ( x ).end()
typedef long long lint;
using namespace std;

int main( void ){
	
	int n;
	string str[100];
	char last;
	char mae;
	mae = '0';
	
	cin >> n;
	
	rep(i,n){
		cin >> str[i];
	}
	
	last = str[0][str[0].size()-1];
	
	FOR( i, 1, n){
		
		if( last != str[i][0] ){
			cout << "No" << endl;
			return 0;
		}
		
		rep( j, n ){
			if( str[i] == str[j] and i != j ){
			cout << "No" << endl;
			return 0;
			}
		
		}
		
		last = str[i][str[i].size()-1];
		
	}
	
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;


int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


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

	vector<int> a(n);

	rep(i, n) {
		a[i] = i + 1;
	}
	int res = -1;
	int findID = -1;
	rep(i, n) {
		int count = 0;
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			count++;
		}
		if (res < count) {
			res = count;
			findID = i;
		}
	}
	cout <<  findID+1 << endl;
}

Measured memory_bytes: 384
n=int(input())
f=[]
p=[]
for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))
pmax=0
cnt=1024
for i in range(1023):
    cnt+=1
    tmpp=[]
    oc=str(bin(cnt))[3:]
    for j in range(n):
        c=0
        for k in range(10):
            if f[j][k]==1 and oc[k]=="1":
                c+=1
        tmpp.append(p[j][c])
    if i==0:
        pmax=sum(tmpp)
    else:
        if sum(tmpp)>pmax:
            pmax=sum(tmpp)
print(pmax)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  ll m = *min_element(A.begin(), A.end());

  vector<vector<ll>> dp(K + 1, vector<ll>(2));
  REP(i, 0, m) {
    dp[i][0] = false;
    dp[i][1] = false;
  }

  REP(i, m, K + 1) {
    REP(k, 0, N) if (A[k] <= i) {
      dp[i][0] = dp[i][0] || !dp[i - A[k]][1];
      dp[i][1] = dp[i][1] || !dp[i - A[k]][0];
    }
  }

  cout << (dp[K][0] ? "First" : "Second") << endl;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
int mb[2001][2001];
int mw[2001][2001];
int sb[2001][2001];
int sw[2001][2001];

signed main(){
    int n,k;
    cin >> n >> k;

    
    rep(i,2*k+1) rep(j,2*k+1) mb[i][j] = mw[i][j] = 0;

    rep(i,n){
        int x,y;
        char c;
        cin >> x >> y >> c;

        if(c == 'B') mb[x%(2*k)][y%(2*k)]++;
        if(c == 'W') mw[x%(2*k)][y%(2*k)]++;
    }
    
    rep(i,2*k+1) rep(j,2*k+1) sb[i][j] = sw[i][j] = 0;

    for(int i = 1; i <= 2*k; i++){
        for(int j = 1; j <= 2*k;j++){
            sb[i][j] = sb[i-1][j] + sb[i][j-1] - sb[i-1][j-1] + mb[i-1][j-1];
            sw[i][j] = sw[i-1][j] + sw[i][j-1] - sw[i-1][j-1] + mw[i-1][j-1];
        }   
    }
    int ans = 0;
    cerr << "wei" << endl;

    rep(i,k){
        rep(j,k){
            int x[4] = {0,i,i+k,2*k};
            int y[4] = {0,j,j+k,2*k};
            int b = 2*sb[x[1]][y[1]] - 2*sb[x[1]][y[2]] + sb[x[1]][y[3]]
                    -2*sb[x[2]][y[1]] + 2*sb[x[2]][y[2]] - sb[x[2]][y[3]]
                    +sb[x[3]][y[1]] - sb[x[3]][y[2]] + sb[x[3]][y[3]];
            int w = -2*sw[x[1]][y[1]] + 2*sw[x[1]][y[2]] - sw[x[1]][y[3]]
                    +2*sw[x[2]][y[1]] - 2*sw[x[2]][y[2]] + sw[x[2]][y[3]]
                    -sw[x[3]][y[1]] + sw[x[3]][y[2]];
            ans = max(ans,b+w);

            w = 2*sw[x[1]][y[1]] - 2*sw[x[1]][y[2]] + sw[x[1]][y[3]]
                    -2*sw[x[2]][y[1]] + 2*sw[x[2]][y[2]] - sw[x[2]][y[3]]
                    +sw[x[3]][y[1]] - sw[x[3]][y[2]] + sw[x[3]][y[3]];
            b = -2*sb[x[1]][y[1]] + 2*sb[x[1]][y[2]] - sb[x[1]][y[3]]
                    +2*sb[x[2]][y[1]] - 2*sb[x[2]][y[2]] + sb[x[2]][y[3]]
                    -sb[x[3]][y[1]] + sb[x[3]][y[2]];
            ans = max(ans,b+w);
        }
    }
    cout << ans << endl;
    
    
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 125312
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int a[101];
int main() {
	int n; cin >> n;
	int sum = 0;
	rep(i, n) {
		cin >> a[i]; sum += a[i];
	}
	int mi = 1000000; int out = n;
	rep(i, n) {
		int dif = abs(a[i] * n - sum);
		if (dif < mi) {
			mi = dif; out = i;
		}
	}
	cout << out << endl;
	return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll N = (ll)5e5 + 2;
const ll MOD = (ll)1e9 + 7;
const ll MOD1 = (ll)998244353;
const ll inf = (ll)1e18 + 6;

template <class T>
bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T>
bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll add(ll x, ll y)
{
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}

ll sub(ll x, ll y)
{
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}

ll mult(ll x, ll y)
{
    return (x * y) % MOD;
}

ll bin_pow(ll x, ll p)
{
    if (p == 0)
        return 1;
    if (p & 1)
        return mult(x, bin_pow(x, p - 1));
    return bin_pow(mult(x, x), p / 2);
}

ll rev(ll x)
{
    return bin_pow(x, MOD - 2);
}

int main()
{

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(20);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif
    ld n;
    cin >> n;
    cout << (44 * n) / 7 << "\n";
}


Measured memory_bytes: 3784
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int d = sc.nextInt();
		int nd = n - d;
		for (int i = 0; i < n; i++) {
		    if (arr[i] == '1') {
		        if (nd > 0) {
		            nd--;
		        } else {
		            arr[i] = '0';
		            d--;
		        }
		    } else {
		        if (d > 0) {
		            d--;
		            arr[i] = '1';
		        } else {
		            nd--;
		        }
		    }
		}
		System.out.println(arr);
	}
}



Measured memory_bytes: 26416
#include<iostream>
#include<string>
#include<vector>

#define P (1000000000 + 7)

using namespace std;

int main(){
        string str;
        cin >> str;

        long n = str.size();
        long long * threes = new long long[n];
        threes[0] = 1;
        for(long i=1;i<n;i++){
                threes[i] = (threes[i-1] * 3)%P;
        }

        long long ans = 0;
        long long rem = 1;
        for(long i=0;i<str.size();i++){
                char c = str[i];
                if(str[i] == '1'){
                        ans += rem * threes[n-1-i];
                        ans %= P;

                        rem *= 2;
                        rem %= P;
                }
                else
                {
                }
        }

        //cout << ans << "," << rem << endl;
        cout << (ans + rem) % P << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cmath>

using namespace std;
using ll = long long int;

int main() {
	ll N, P;
	cin >> N >> P;
	if (N == 1) cout << P << endl;
	else {
		ll ans = 1;
		ll p = P;
		for (ll i = 2; i <= (ll)pow(p + 1, 1.0 / N); i++) {
			ll cnt = 0;
			while (p % i == 0) {
				p /= i;
				cnt++;
			}
			ll n = cnt / N;
			for (ll j = 0; j < n; j++) {
				ans *= i;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
while   True:
    H,W=map(int,input().split())
    if (H==0 and W==0):
        break

    for i in range(H):
        for j in range(W):
            if (j%2==1):
                if (i%2==0):
                    print(".", end="")
                else:
                    print("#", end="")
            else:
                if (i%2==1):
                    print(".", end="")
                else:
                    print("#", end="")
        print()
    print()


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

N,K = map(int, input().split())
Dk = list(map(str, input().split()))

for i in range(N, 100000):
    i = str(i)
    for j in range(K):
        if i.find(Dk[j]) != -1:
            break
        if j == K-1:
            print(i)
            exit()

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
    cin>>a>>b;//KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
    if(a>0&&b>0)
	{
        cout<<"Positive"<<endl;//SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
    }
	else
	if(max(a,b)>=0&&min(a,b)<=0||a==0||b==0)
	{//RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
        cout << "Zero" << endl;
    }
	else
	{
        if((abs(min(a,b))-abs(max(a,b)))%2==0)//MMP
		{
            cout<<"Negative"<<endl;//PPM
        }
		else
		{
            cout<<"Positive"<<endl;//COUT
        }
    }
    return 0;//cu
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    final int counter = sc.nextInt();
    int subject = sc.nextInt();
    int[] children = new int[counter];
    for(int i = 0;i<counter;i++){
      children[i] = sc.nextInt();
    }
    Arrays.sort(children);
    int result = 0;
    while(result < counter && subject >= children[result]){
      if(result == counter -1 && subject > children[result]){
        break;
      }
      subject -= children[result];
      result ++;
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 23892
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<math.h>
#include<string>
#include<utility>
#include<queue>
#include<stdlib.h>
int main() {
	using namespace std;
	int sum, h, m, s;
	cin >> sum;
	h = sum / 3600;
	sum -= h * 3600;
	m = sum / 60;
	s = sum % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3108