akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
	int n,k,m,i,card[200],hold[200],j;
	scanf("%d",&n);
	scanf("%d",&m);
	for(i=0;i<n*2;i++){
		card[i]=i+1;
	}
	for(i=0;i<m;i++){
		scanf("%d",&k);
		for(j=0;j<n*2;j++){
			hold[j]=card[j];
		}
		if(k==0){
			for(j=0;j<n;j++){
				card[j*2]=hold[j];
				card[j*2+1]=hold[j+n];
			}
		}else{
			for(j=0;j<n*2;j++){
				card[j]=hold[(j+k)%(n*2)];
			}
		}
	}
	for(i=0;i<n*2;i++){
		printf("%d\n",card[i]);
	}
	return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').ToArray();
            var num = int.Parse(input[0] + input[1]);
            var sq = Math.Sqrt(num);

            Console.WriteLine(sq % 1 == 0 ? "Yes" : "No");
        }
    }
}

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

using namespace std;

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int p = 0, g = 0;
  rep(i, n) if (s[i] == 'p') p++;

  cout << n / 2 - p << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[10000];
bool V[10000];

int main(){
    int N, K;
    cin >> N >> K;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    sort(A, A+N);

    for(int i = N-1; i >= 0; i--){
        ll sum = 0;
        for(int j = i; j >= 0; j--){
            ll a = A[j];
            sum += a;
            if(sum >= K){
                V[j] = true;
                break;
            }
            ll diff = K - sum;
            int idx = lower_bound(A, A+j, diff) - A;
            if(idx < j){
                V[idx] = true;
            }
        }
    }

    ll ans = 0;
    ll last = -1;
    for(int i = N-1; i >= 0; i--){
        bool v = V[i];
        ll a = A[i];
        //if(a == last) v = true;
        if(v){
            ans = 0;
        }
        else{
            ans++;
        }
        last = a;
    }

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


Measured memory_bytes: 256
import java.io.*;

public class Main{
  public static void main(String[] args) {
    String line;
    int x;

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    try {
        line = reader.readLine();
        x = Integer.parseInt(line);
        System.out.println(x*x*x);
    } catch (NumberFormatException e) {
      System.out.println(e);
    } catch (IOException e) {
      System.out.println(e);
    }
  } 
}


Measured memory_bytes: 24244
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int men[] = new int[3];
		int nomi[] = new int[2];
		for(int i = 0; i < 3; i++){
			men[i] = sc.nextInt();
		}
		for(int j = 0; j < 2; j++){
			nomi[j] = sc.nextInt();
		}
		int taihi, taihi2;
		for(int i = 0; i < 3; i++){
			for(int k = i + 1; k < 3; k++){
				if(men[i] > men[k]){
					taihi = men[i];
					men[i] = men[k];
					men[k] = taihi;
				}
			}
		}
		for(int i = 0; i < 2; i++){
			for(int k = i + 1; k < 2; k++){
				if(nomi[i] > nomi[k]){
					taihi2 = nomi[i];
					nomi[i] = nomi[k];
					nomi[k] = taihi2;
				}
			}
		}
		int a = men[0] + nomi[0] - 50;
		System.out.println(a);
	}
}

Measured memory_bytes: 17164
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int s[SIZE], t[SIZE], x[SIZE], d[SIZE];

int main(){
  int N, Q;

  vector<pair<pair<int,int>,int> > timeline;

  scanf("%d%d", &N, &Q);

  for(int i=0; i<N; i++) {
    scanf("%d%d%d", s+i, t+i, x+i);
    timeline.push_back({{s[i]-x[i], i}, 0});
    timeline.push_back({{t[i]-x[i], i}, 1});
  }

  sort(timeline.begin(), timeline.end());

  int k = 0;

  set<pair<int,int> > ss;

  for(int i=0; i<Q; i++) {
    scanf("%d", d+i);

    while(k < timeline.size() && timeline[k].first.first <= d[i]) {
      int p = timeline[k].first.second;
      int q = timeline[k].second;

      debug(p);
      debug(q);

      if(q == 0)
        ss.insert({x[p], p});
      else
        ss.erase(ss.find({x[p], p}));

      k++;
    }

    if (ss.empty()) {
      printf("-1\n");
    } else {
      auto it = ss.begin();
      debug(it->first);
      printf("%d\n", it->first);
    }
  }


  return 0;
}


Measured memory_bytes: 18412
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
const int INF = 1e18;
const int MX = 1000001;


int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
  
     int a,b,c,d;
    cin>>a>>b>>c>>d;
    int mx = max({a*c,a*d,b*d,b*c});

    cout<<mx<<endl;    
    
 
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>

int main(void) {
  int a, b;
  int d, r;
  double f;

  scanf("%d %d", &a, &b);
  
  d = a / b;
  r = a % b;
  f = (double)a / (double)b;

  printf("%d %d %f\n", d, r, f);

  return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

Vec<int> a;
map<int, llong> dp;

llong score(int m)
{
  llong res = 0;
  pq<int> maxs(a.begin(), a.begin() + m);
  qp<int> mins(a.begin() + m, a.end());
  for (int i = 0; i < a.size() / 3; i++) {
    res += maxs.top() - mins.top();
    maxs.pop();
    mins.pop();
  }
  return dp[m] = res;
}

void hawawa()
{
  int n;
  cin >> n;
  a.resize(3 * n);
  for (auto&& i : a) {
    cin >> i;
  }
  int s = n, g = 2 * n;
  qp<int> check(a.begin(), a.begin() + n);
  Vec<llong> info(3 * n);
  llong num = accumulate(a.begin(), a.begin() + n, 0ll);
  info[n] = num;
  for (int i = n; i < n * 2; i++) {
    if (check.top() < a[i]) {
      num -= check.top();
      num += a[i];
      check.pop();
      check.push(a[i]);
    }
    info[i + 1] = num;
  }
  num = accumulate(a.begin() + 2 * n, a.end(), 0ll);
  pq<int> check2(a.begin() + 2 * n, a.end());
  llong ans = info[n * 2] - num;
  for (int i = n * 2 - 1; i >= n; i--) {
    if (check2.top() > a[i]) {
      num -= check2.top();
      num += a[i];
      check2.pop();
      check2.push(a[i]);
    }
    info[i] -= num;
    ans = max(ans, info[i]);
  }
  cout << ans << "\n";
}

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

struct RMQ {

};

Measured memory_bytes: 4608
from unittest.mock import patch
from math import sqrt, factorial
from itertools import permutations

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

total_sum = 0
for l in permutations(range(N)):
  total_sum += sum(sqrt((XY[l[i+1]][0] - XY[l[i]][0])**2 + (XY[l[i+1]][1]- XY[l[i]][1])**2) for i in range(N-1))
print(total_sum / factorial(N))


Measured memory_bytes: 6856
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N, M = MI()
    a = [0] * M
    b = [0] * M
    c = [0] * M
    dp = [IINF for i in range(2 ** N)]

    for i in range(M):
        a[i], b[i] = MI()
        tmp = LI()
        for v in tmp:
            c[i] |= 1 << (v-1)

    dp[0] = 0
    for i in range(M):
        for bit in range(2 ** N):
            dp[bit | c[i]] = min(dp[bit | c[i]], dp[bit] + a[i])

    if dp[2**N-1] == IINF:
        print(-1)
    else:
        print(dp[2**N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 45268
A, B, C, D = list(input())

for n in range(2 ** 3):
	identity = ""
	identity += A + ["+", "-"][(n >> 0 & 1)]
	identity += B + ["+", "-"][(n >> 1 & 1)]
	identity += C + ["+", "-"][(n >> 2 & 1)]
	identity += D
	if 7 == eval(identity):
		print(identity + "=7")
		break


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    string S; cin >> S;
    for(auto aaa: S){
        if(aaa=='?'){
            cout << 'D';
        }
        else cout << aaa;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3752
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b,c,x,y) = scan "%d %d %d %d %d" Tuple5.make

let () =
  [a*x + b*y; 2 * c * (max x y);
   2*c*(min x y) + a*(x- min x y) + b*(y- min x y)]
  |> List.min
  |> Printf.printf "%d\n"


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >>n;
  ll a[n],m=0,ans=0;
  for(ll i=0;i<n;i++) {
    cin >>a[i];
    if(a[i]<0) m++;
    ans+=abs(a[i]);
    a[i]=abs(a[i]);
  }
  sort(a,a+n);
  if(m%2==0) cout <<ans<<endl;
  else cout <<ans-2*abs(a[0])<<endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;
#define mp make_pair
#define pb push_back
#define FI first
#define SE second
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int main(){
    string S;
    cin >> S;
    int a=0,b=0;
    REP(i,S.size()){
        if(S[i] == '0') a++;
        else b++;
    }
    cout << min(a,b)*2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int n,i,j,h,w;
  n=1;
  while(n=1){
    scanf("%d",&h);
    scanf("%d",&w);
    if(h==0 && w==0) break;
    for(i=0;i<h;i++){
      for(j=0; j< w;j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");

  }
}



Measured memory_bytes: 1928
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX_V 2000000
#define INF 10000000000
ll d[MAX_V];
struct edge{ll to,cost;};
vector<edge> G[MAX_V];
void dij(ll s){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+MAX_V,INF);
  d[s]=0;
  que.push(make_pair(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    ll v=p.second;
    if(d[v]<p.first) continue;
    for(ll i=0;i<G[v].size();i++){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;  
        que.push(make_pair(d[e.to],e.to));
      }
    }
  }
}
signed main(){
  init_io();
  ll v,e,r;
  cin >> v >> e >> r;
  ll s,t,di;
  for(int i=0;i<e;i++){
    cin >> s >> t >> di;
    G[s].push_back({t,di});
  }
  dij(r);
  for(int i=0;i<v;i++){
    if(d[i] == INF) cout <<"INF\n";
    else cout <<d[i]<<endl;
  }
}



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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int h,n;
    cin>>h>>n;
    int s = 0;
    int a;
    REP(i,n){
        cin>>a; s += a;
    }
    puts(s>=h ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
x,n = map(int, input().split())
p = list(map(int, input().split()))
y1 = x
y2 = x
while y1 > 0 and y2 <= 100:
    if y1 in p:
        y1 += 1
    else: break
    if y2 in p:
        y2 -= 1
    else: break
ans = [100,100]
if y1 not in p:
    ans[0] = abs(x-y1)
if y2 not in p:
    ans[1] = abs(x-y2)
print(y2 if min(ans) == ans[1] else y1)

Measured memory_bytes: 9140
import itertools

N, M = list(map(int, input().split()))
L = [[] for i in range(N)]

for i in range(M):
	a, b = list(map(int, input().split()))
	L[a - 1].append(b - 1)
	L[b - 1].append(a - 1)

X = [i for i in range(1, N)]

ans = 0
for s in itertools.permutations(X, N - 1):
	judge = "Yes"
	x = 0
	for i in s:
		if L[i].count(x) == 1:
			pass
			x = i
		else:
			judge = "No"
			break
	if judge == "Yes":
		ans += 1

print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>
#include<iomanip>

/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
#define vll			vector<ll>
#define sll			set<ll>
const ll inf = 1000000000000000;
ll in = 1000000000000000000;
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

int main()
{
	FastIO;
	double t, a, i, j, k, q, c, d, b, r,n;
	cin >> a >> b >> c >> d;
	if(a/2.0==c && b/2.0==d)
		cout << setprecision(10) << fixed << .5 * a * b <<" 1"<< endl;
	else
		cout << setprecision(10) << fixed << .5 * a * b << " 0" << endl;
	return 0;
}


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

typedef long long ll;
const int N = 2010;
int n, k;
int a[N][N], b[N][N];
char ch[5];

int sum(int a[N][N], int i, int j, int x, int y) {
    return a[x][y] - a[x][j - 1] - a[i - 1][y] + a[i - 1][j - 1];
}

int calc(int a[N][N], int i, int j) {
    int ret = sum(a, i, j, i + k - 1, j + k - 1);
    ret += sum(a, 1, 1, i - 1, j - 1) + sum(a, i + k, j + k, k << 1, k << 1);
    ret += sum(a, i + k, 1, k << 1, j - 1) + sum(a, 1, j + k, i - 1, k << 1);
    return ret;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        int x, y; scanf("%d%d%s", &x, &y, ch);
        x %= (k << 1), y %= (k << 1);
        x++, y++;
        if (ch[0] == 'W') a[x][y]++;
        else b[x][y]++;
    }
    for (int i = 1; i <= k << 1; i++)
        for (int j = 1; j <= k << 1; j++) {
            a[i][j] += a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1];
            b[i][j] += b[i][j - 1] + b[i - 1][j] - b[i - 1][j - 1];
        }
    int ans = 0;
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++) {
            int tmpa = calc(a, i, j), tmpb = calc(b, i, j);
            tmpb = b[k << 1][k << 1] - tmpb;
            ans = max(tmpa + tmpb, ans);

            tmpa = calc(b, i, j), tmpb = calc(a, i, j);
            tmpb = a[k << 1][k << 1] - tmpb;
            ans = max(tmpa + tmpb, ans);
        }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 31872
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m;
    cin >> n >> m;
    int ans = (n * (n - 1) / 2) + (m * (m - 1) / 2);
    cout << ans << endl;
    return 0;
}

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

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    //input
    int d = sc.nextInt();
    /*
    int[] c = new int[26]; //array of decrease
    for(int i = 0; i < c.length; i++){
      c[i] = sc.nextInt();
    }
    */

    ArrayList<Integer> c = new ArrayList<Integer>();
    for(int i = 0; i < 26; i++){
      c.add(sc.nextInt());
    }

    int[][] s = new int[d][26]; //two dimensional array of increase
    for(int row = 0; row < s.length; row++){ //day
      for(int col = 0; col < s[row].length; col++){ //contest number
        s[row][col] = sc.nextInt();
      }
    }
    /*
    int[] t = new int[d]; //array of contest numbers of the day
    for(int i = 0; i < t.length; i++){
      t[i] = sc.nextInt();
    }
    */

    //output
    //based on increase
    int largestNum = s[0][0];
    int largestNumRow = 0;
    int largestNumCol = 0;
    for(int row = 0; row < s.length; row++){
      for(int col = 0; col < s[row].length; col++){
        if( s[row][col] > largestNum ){
          largestNum = s[row][col];
          largestNumRow = row;
          largestNumCol = col;
        }
      }
    }

    int largestNuM = c.get(0);
    int largestNumPos = 0;
    for(int j = 0; j < c.size(); j++){
      if( c.get(j) > largestNuM ){
        largestNuM = c.get(j);
        largestNumPos = j;
      }
    }

    for(int i = 0; i < d; i++){
      if( largestNum > largestNuM ){
        System.out.println(largestNumCol+1);
      }else{
        System.out.println(largestNumPos+1);
      }
    }


    /*

    for(int m = 0; m < d; m++){
      if( m%2 == 0 ){
        System.out.println(largestNumCol+1);
      }else{
        int largestNuM = c.get(0);
        int largestNumPos = 0;
        for(int j = 0; j < c.size(); j++){
          if( c.get(j) > largestNuM ){
            largestNuM = c.get(j);
            largestNumPos = j;
          }
        }
        c.remove(largestNumPos);
        System.out.println(largestNumPos+1);
      }
    }
    */



    //for(int i = 0; i < d; i++){
      //System.out.println((int)(Math.random()*26+1));
      //System.out.println(largestNumCol+1);
    //}




    /*
    int value = 0;
    for(int i = 0; i < t.length; i++){
      int contestNum = t[i]-1;
      int day = i+1;
      value += s[day-1][contestNum]; //increase
      for(int j = 0; j < c.length; j++){
        if( !(j == contestNum) ){
          int daySinceLast = day;
          for(int m = 0; m < i; m++){
            if( j == t[m]-1 ){
              daySinceLast = day-m-1;
            }
          }
          value -= c[j]*(daySinceLast); //decrease (amount of decrease * days since last one)
        }
      }
      System.out.println(value);
    }
    */

  }
}


Measured memory_bytes: 38032
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll acnt = 0, bcnt = 0;
    ll res = 0;
    F0R(i, s.sz() - 1)
    {
        if(s[i] == 'A')
        {
            acnt++;
        }
        else
        {
            if(s[i] == 'B' && s[i + 1] == 'C')
            {
                i++;
                res += acnt;
            }
            else
            {
                acnt = 0;
            }
        }
    }
    cout << res;
    return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b)cout << c << endl;
    if(a == c)cout << b << endl;
    if(b == c)cout << a << endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    string s;
    cin>>s;
    if(s=="ani"){
        cout<<"square1001"<<endl;
    }
    else{
        cout<<"e869120"<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3144
#include <iostream>

using namespace std;

int pro(long long x, long long y){
    long long num = x;
    int count = 0;
    while(num <= y){
        count += 1;
        num *= 2;
    }
    return count;
}

int main(){
    long long x, y, ans;
    cin >> x >> y;
    ans = pro(x, y);
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> v = a;
  sort(begin(a), end(a));
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != v[i]) {
      cnt++;
    }
  }
  if (cnt > 2) {
    puts("NO");
  } else {
    puts("YES");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String strLine = scan.nextLine();
        scan.close();
        String[] vowel = {"a", "i", "u", "e", "o"};
        boolean flag = false;

        for(int i=0;i<5; i++) {
            if(vowel[i].equals(strLine)){
                flag = true;
            }
        }

        if(flag) {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }
}


Measured memory_bytes: 22740
#include<stdio.h>
int main(){
  int H, W, h, w;
  scanf("%d%d%d%d", &H,&W,&h,&w);
  if(H%h||W%w){
    puts("Yes");
    for(int i=1; i<=H; ++i,puts(""))
      for(int j=1; j<=W; ++j)
        if(i%h||j%w) printf("1000 ");
        else printf("%d ", -1000*(h*w-1)-1);
  }else puts("No");
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <array>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

#include <atcoder/string>

using namespace std;
using namespace atcoder;
#define rep(i,l,r) for(int i = l; i < r; ++i)

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

    long long n = s.size(), ans = n * (n + 1) / 2;

    auto sa = suffix_array(s);
    auto la = lcp_array(s, sa);

    for(auto e : la) ans -= e;
    cout << ans << endl;
}


Measured memory_bytes: 15380
n,m=map(int,input().split())

a=[[]for i in range(n)]

for i in range(n):
    a[i]=list(map(int,input().split()))

b=[[]for i in range(m)]

for i in range(m):
    b[i]=int(input())
    
for i in range(n):
    tmp=0
    for j in range(m):
        tmp+=a[i][j]*b[j]
    print(tmp)


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

using namespace std;
const long long mod=998244353;
const int N=3e3+10;
long long dp[N][N];
int a[N],n,s;
void add(long long &x,long long y)
{
    x=(x+y)%mod;
}
int main()
{
    cin>>n>>s; 
    for(int i=1;i<=n;i++)
    cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=s;++j) 
		dp[i][j]=dp[i-1][j]*2%mod;
 
        for(int j=s;j>=a[i];--j)
		{
            add(dp[i][j],dp[i-1][j-a[i]]);
        }
    }
    printf("%lld\n",dp[n][s]);
}

Measured memory_bytes: 74280
W=gets.split[~c=0].to_i+1
s=$<.read.tr'#
','10'
b,w=[?0,?1].map{|t|s.tr(?.,t).to_i 2}
(b|=b*2|b/2|b>>W|b<<W
c+=1)while w>b&=w
p c

Measured memory_bytes: 91096
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
#define MOD 1000000007
 
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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}

typedef std::pair<ll, ll> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}
 
using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<P> a(n);

    rep(i, n){
        cin >> a[i].second;
        a[i].first = i+1;
    }

    sort(all(a), pairCompare);

    rep(i, n-1) cout << a[i].first << " ";
    cout << a[n-1].first;
}

Measured memory_bytes: 2432
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    ans = float('inf')
    for h in range(1, H):
        dh = H-h
        Sa = h*W
        Sb = dh*(W//2)
        Sc = dh*(W//2+W%2)
        tmp = sorted([Sa, Sb, Sc])
        ans = min(tmp[-1]-tmp[0], ans)
        Sb = dh//2*W
        Sc = (dh//2+dh%2)*W
        tmp = sorted([Sa, Sb, Sc])
        ans = min(tmp[-1]-tmp[0], ans)
    
    for w in range(1, W):
        dw = W-w
        Sa = w*H
        Sb = dw*(H//2)
        Sc = dw*(H//2+H%2)
        tmp = sorted([Sa, Sb, Sc])
        ans = min(tmp[-1]-tmp[0], ans)
        Sb = dw//2*H
        Sc = (dw//2+dw%2)*H
        tmp = sorted([Sa, Sb, Sc])
        ans = min(tmp[-1]-tmp[0], ans)
    print(ans)

Measured memory_bytes: 44008
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s,tp="";
   cin>>s;
   int l=s.length();
   for(int i=0;i<l;i++)
   {
   	if(i%2==0)
   	tp+=s[i];
   }
   cout<<tp;
   return 0;
}

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

int main(){
  int h,w;
  cin>>h>>w;
  
  char lis[h+2][w+2];
  memset(lis,'#',sizeof(lis));
  rep(i,1,h+1){
    rep(j,1,w+1){
      cin>>lis[i][j];
    }
  }
  
  int cnt;


  rep(i,0,h+2){
    rep(j,0,w+2){
      cout<<lis[i][j];
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
H,W = [int(i) for i in input().split(' ')]
C = [[int(i) for i in input().split(' ')]for _ in range(10)]
 
prev = [-1]*10
row = [int(i) for i in range(10)]
ansewrDict = {}
total = 0

for v in row:
    ansewr = {str(i): 1000 for i in range(10)}
    d = {str(i) : 1000 for i in range(10)}
    if v == -1:
        continue
    s = v
    d[str(s)] = 0
    
    while d:
        u = min(d, key=d.get)
        ansewr[u] = d.pop(u)

        for i in range(10):
            if ansewr[str(i)] > ansewr[u] + C[int(u)][i]:
                d[str(i)] = ansewr[u] + C[int(u)][i]
                ansewr[str(i)] = ansewr[u] + C[int(u)][i]
    
    ansewrDict[str(v)] = ansewr

for _ in range(H):
    row = input().split(' ')
    for v in row:
        if v == '1' or v == '-1':
            continue
        
        total += ansewrDict[v]['1']
print(total)

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pii> x(n);
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        x[i].first = a;
        x[i].second = b;
    }
    ll ans = 0;
    sort(x.begin(),x.end());
    ll i = 0;
    while(m > 0 && i < n){
        if(m-x[i].second >= 0){ 
            ans += x[i].first*x[i].second;
            m -= x[i].second;
        }
        else{
            ans += x[i].first*m;
            break;
        }
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
// In The Name Of God
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()


int32_t main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int a,b,c; cin >> a >> b >> c;
    int x,y; cin >> x >> y;
    int ans = 0;
    if(a+b > 2*c){
        int t = min(x,y);
        ans += 2*t*c;
        x -= t;
        y -= t;
    }
    ans += min(y*b+x*a,(x+y)*2*c);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	REP(i,N){
		cin>>A[i];
	}
	int ans=powint(3,N);
	int dame=1;
	REP(i,N){
		if(A[i]%2==0){
			dame*=2;
		}
	}
	ans-=dame;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N,L;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> L;
  vector<int> v(N);
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    v[i-1] = L + i - 1;
    sum += v[i-1];
  }
  int ans = INF;
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    for (int j = 0; j < N; j++) {
      if (j == i) continue;
      tmp += v[j];
    }
    if (abs(sum-tmp) < abs(sum-ans)) {
      ans = tmp;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
nums = []
for i in range(n):
    nums.append(list(input().split())+[i+1])
sort_num = sorted(nums, key=lambda x: (x[0], -int(x[1])))
for i, j in enumerate(sort_num):
    j.append(i+1)
for i in sort_num:
    print(i[2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    char a,b;
    cin>>a>>b;
    if(a>b) puts(">");
    else if(a<b) puts("<");
    else puts("=");
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        int curMin = INT32_MAX;
        for(int j = 1; j <= k; j++) {
            if (i - j < 0) break;
            curMin = min(curMin, dp[i-j] + abs(a[i-j] - a[i]));
        }
        dp[i] = curMin;
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io::Read;

fn check(a: String, b: String) -> String {
    if a == "unko" {
        b
    } else if a.len() > b.len() {
        a
    } else if a.len() < b.len() {
        b
    } else {
        let c: Vec<char> = a.chars().collect();
        let d: Vec<char> = b.chars().collect();
        for i in 0..a.len() {
            if c[i] > d[i] {
                return a;
            } else if c[i] < d[i] {
                return b;
            }
        }
        b
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..m)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let need: Vec<usize> = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6].to_vec();
    let mut dp: Vec<String> = vec!["unko".to_string(); n + 9];
    dp[0] = "".to_string();
    for i in 0..n {
        for &j in a.iter() {
            if dp[i] == "unko" {
                continue;
            }
            dp[i + need[j]] = check(dp[i + need[j]].clone(), dp[i].clone() + &j.to_string());
        }
    }
    println!("{}", dp[n]);
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int cal(int x1, int y1, int x2, int y2, vector<vector<int>>& grid)
{
  return grid[y2][x2] - grid[y2][x1] - grid[y1][x2] + grid[y1][x1];
}

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  vector<vector<int> > grid(2 * K + 5, vector<int>(2 * K + 5, 0));
  int x, y;
  char ch;
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %c", &x, &y, &ch);
    if (ch == 'W') { x += K; }
    x %= 2 * K;
    y %= 2 * K;
    ++grid[y + 1][x + 1];
  }

  int K2 = 2 * K;
  for (int i = 1; i <= K2; ++i) {
    for (int j = 1; j <= K2; ++j) {
      grid[i][j] += grid[i][j - 1];
    }
  }
  for (int i = 1; i <= K2; ++i) {
    for (int j = 1; j <= K2; ++j) {
      grid[i][j] += grid[i - 1][j];
    }
  }
  int ans = 0;
  for (int y = 1; y <= K2; ++y) {
    for (int x = 1; x <= K2; ++x) {
      // (x, y) is on the right-bottom cell of the target squre
      int x1 = 0, x2 = max(0, x - K), x3 = x, x4 = min(K2, x + K), x5 = K2;
      int y1 = 0, y2 = max(0, y - K), y3 = y, y4 = min(K2, y + K), y5 = K2;
      int cnt = cal(x1, y1, x2, y2, grid) + cal(x3, y1, x4, y2, grid) +
        cal(x2, y2, x3, y3, grid) + cal(x4, y2, x5, y3, grid) +
        cal(x1, y3, x2, y4, grid) + cal(x3, y3, x4, y4, grid) +
        cal(x2, y4, x3, y5, grid) + cal(x4, y4, x5, y5, grid);
      ans = max(ans, cnt);
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main(){
  int n,l;
  cin>>n>>l;
  string s[n];
  for(int i=0;i<n;i++)
    cin>>s[i];
  sort(s,s+n);
  for(int i=0;i<n;i++)
    cout<<s[i];
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d",&a, &b, &c);
    if(a==5 && b==5 && c==7) printf("YES\n");
    else if(a==5 && b==7 && c==5) printf("YES\n");
    else if(a==7 && b==5 && c==5) printf("YES\n");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main (void)
{
    int a, b, c, d, e;
    int min = 10, time = 0;

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);

    if ((a % 10) && ((a % 10) < min)) min = a % 10;
    if ((b % 10) && ((b % 10) < min)) min = b % 10;
    if ((c % 10) && ((c % 10) < min)) min = c % 10;
    if ((d % 10) && ((d % 10) < min)) min = d % 10;
    if ((b % 10) && ((e % 10) < min)) min = e % 10;

    time += ((a + 9) / 10) * 10;
    time += ((b + 9) / 10) * 10;
    time += ((c + 9) / 10) * 10;
    time += ((d + 9) / 10) * 10;
    time += ((e + 9) / 10) * 10;

    printf("%d\n", time - 10 + min);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<int,int> P;

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

	string S;
	cin >> S;

	if(S[K-1]=='A') S[K-1]='a';
	else if(S[K-1]=='B') S[K-1]='b';
	else S[K-1]='c';

	cout << S << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;

int main() {
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int n, m, a[2000][2000] = {}, b, x, y, z, k, sum = 0, d = 1, w, h, typ = 0;
	long long dp[200005] = {}, memo[200005] = {};
	string str, str2;
	cin >> x >> y >> z;
	cout << (x - z) / (y + z);

}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi x(n), y(n), p(n);
    rep(i, n) cin >> x[i] >> y[i] >> p[i];
    vector<vll> xd(1<<n, vll(n)), yd(1<<n, vll(n));
    rep(i, 1<<n) {
        vll valx(n, INF), valy(n, INF);
        rep(k, n) {
            valx[k] = (ll)abs(x[k]) * p[k];
            valy[k] = (ll)abs(y[k]) * p[k];
        }
        rep(j, n) if ((i>>j)&1) {
            rep(k, n) {
                valx[k] = min(valx[k], (ll)abs(x[k]-x[j])*p[k]);
                valy[k] = min(valy[k], (ll)abs(y[k]-y[j])*p[k]);
            }
        }
        xd[i] = valx; yd[i] = valy;
    }
    vll ans(n+1, INF);
    int t = 1;
    rep(i, n) t *= 3;
    rep(i, t) {
        int t2 = i, xi = 0, yi = 0, bcnt = 0;
        rep(j, n) {
            if (t2%3==1) xi |= (1<<j);
            if (t2%3==2) yi |= (1<<j);
            if (t2%3!=0) ++bcnt;
            t2 /= 3;
        }
        ll sum = 0;
        rep(j, n) sum += min(xd[xi][j], yd[yi][j]);
        ans[bcnt] = min(ans[bcnt], sum);
    }
    rep(i, n+1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 13004
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, T;

    cin >> N >> T;

    int ary[N];

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

    int diff_ary[N-1];
    bool tf_ary[N-1];

    for (int i = 0; i < N-1; ++i)
    {
        diff_ary[i] = ary[i+1] - ary[i];
        tf_ary[i] = diff_ary[i] < T;
    }

    int total = 0;
    for (int i = 0; i < N-1; ++i)
    {
        if (tf_ary[i])
        {
            total += diff_ary[i];
        } else {
            total += T;
        }
    }

    total += T;

    cout << total << endl;

    return 0;
}

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

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

int main() {
    int N;
    cin >> N;
    int h[N];
    for (int i=0; i<N; i++){
        cin >> h[i];
    }
    
    int DP[N];
    for (int i=0; i<N; i++){
        DP[i] = INF;
    }
    DP[0] = 0;

    for (int i=0; i<N-1; i++){
        DP[i+1] = min(DP[i] + abs(h[i+1]-h[i]), DP[i+1]);
        if (i != N-2) {
            DP[i+2] = min(DP[i] + abs(h[i+2]-h[i]), DP[i+2]);
        }
    }

    cout << DP[N-1];

}

Measured memory_bytes: 1024
import sys
from itertools import combinations
l, r = [int(i) for i in sys.stdin.readline().split()]
flg = r - l >= 2019
l %= 2019
r %= 2019
res = 1e9
if l >= r or flg:
    print(0)
else:
    for (_l, _r) in combinations(list(range(l,r+1)), 2):
        if _l == _r:
            continue
        res = _l * _r % 2019 if _l * _r % 2019 < res else res
    print(res)

Measured memory_bytes: 3064