akhauriyash/Code-Regression huggingface dataset:
fn main() {
    println!("{}", read::<usize>() * read::<usize>());
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2108
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var big, small int
	if a > b {
		big, small = a, b
	} else {
		big, small = b, a
	}
	for i := 1; ; i++ {
		if big*i%small == 0 {
			fmt.Println(big * i)
			return
		}
	}
}


Measured memory_bytes: 512
#include<cstdio>
int n,m,i,j,k,k2,t,x,y,z,a[2505],v[2505],st[5005],en[5005],len[5005],last[2505],nxt[5005],st2[5005],en2[5005],last2[2505],nxt2[5005],find[10000005];
bool b[2505],f[2505];
void build(int x,int y,int z)
{
	k++,st[k]=x,en[k]=y,len[k]=z,nxt[k]=last[x],last[x]=k;
}
void build2(int x,int y)
{
	k2++,st2[k2]=x,en2[k2]=y,nxt2[k2]=last2[x],last2[x]=k2;
}
void go(int x)
{
	for (int i=last2[x];i;i=nxt2[i])
	if (!f[en2[i]])
	{
		f[en2[i]]=true;
		go(en2[i]);
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		build(x,y,z);
		build2(y,x);
	}
	f[n]=true;
	go(n);
	for (i=1;i<=n;i++)
	a[i]=-2e9;
	a[1]=0,x=y=find[1]=1,b[1]=true;
	while (x<=y)
	{
		b[find[x]]=false;
		for (i=last[find[x]];i;i=nxt[i])
		if (a[en[i]]<a[st[i]]+len[i]-t&&f[en[i]])
		{
			a[en[i]]=a[st[i]]+len[i]-t;
			if (!b[en[i]])
			b[en[i]]=true,y++,find[y]=en[i],v[en[i]]++;
			if (v[en[i]]==n)
			return printf("-1\n")&&0;
		}
		x++;
	}
	printf("%d\n",a[n]>0?a[n]:0);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Enum various numbers
//-------------------------------------------------
namespace Enum
{
    using fint = ::std::int_fast64_t;
    //素因数分解(素因数列挙)
    ::std::map<fint,int> factor(fint n)
    {
        ::std::map<fint,int> ret;
        for(fint i=2; i*i<=n; i++){
            while(n%i==0){
                ret[i]++;
                n/=i;
            }
        }
        if (n!=1) ret[n]++;
        return ret;
    }
    //約数列挙
    ::std::vector<fint> divisor(fint n)
    {
        ::std::vector<fint> ret;
        for(fint i=1; i*i<=n; i++){
            if (n%i==0){
                ret.push_back(i);
                if (i*i!=n) ret.push_back(n/i);
            }
        }
        return ret;
    }
    //商列挙(割る最小の数と商のペア)
    ::std::vector<::std::pair<fint,fint> > quotient(fint n)
    {
        ::std::vector<::std::pair<fint,fint> > ret;
        fint i=0;
        for(i=1; i*i<=n; i++){
            ret.emplace_back(i,n/i);
        }
        for(; i<=n; i++){
            fint d = n/i;
            ret.emplace_back(i,d);
            i+=(n-d*i)/d;
        }
        return ret;
    }
    //素数判定(おまけ)
    bool isprime(fint n)
    {
        for(fint i=2; i*i<=n; i++){
            if (n%i==0) return false;
        }
        return true;
    }
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi a(N);
    rep(i,N) cin>>a[i];
    bool ng=false;
    vector<bool> table(1000001);
    rep(i,N){
        if (table[a[i]]){
            ng=true;
            break;
        }
        auto fac = Enum::factor(a[i]);
        for(auto f:fac){
            int c = f.fi;
            for(int j=c; j<=1000001; j+=c){
                table[j] = true;
            }
        }
    }
    if (ng){
        int g = a[0];
        rep(i,N-1){
            g = __gcd(g,a[i+1]);
        }
        if (g==1){
            cout<<"setwise coprime\n";
        }else{
            cout<<"not coprime\n";
        }
    }else{
        cout<<"pairwise coprime\n";
    }
    return 0;
}


Measured memory_bytes: 7388
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;
int a[100010];
int b[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    rep(i,0,M){
        cin >> a[i] >> b[i];
    }
    vector<pair<int, int> > pairs(M);
    rep(i,0,M){
        pairs[i] = make_pair(b[i],a[i]);
    }
    sort(pairs.begin(), pairs.end());
    int bb = -1;
    int ans = 0;
    rep(i,0,M){
        int i_left = pairs[i].second;
        int i_right = pairs[i].first;
        if(i_left <= bb && bb < i_right){
            continue;
        }else{
            ans++;
            bb = i_right - 1;
        }
    }
    print(ans);





}


Measured memory_bytes: 1792
"use strict";
function Main(input) {
    let lines = input.split("\n");
    const nums = lines.shift().split(/\s/).map((v) => v - 0);
    const N = nums[0], Q = nums[1];
    let S = lines.shift().split(/\s/)[0] + 'x';
    let lr = new Array(Q);
    let ans = new Array(Q).fill(0);
    for (let n = 0; n < Q; n++) {
        lr[n] = lines.shift().split(/\s/).map((v) => v - 0 - 1);
    }
    let T = new Array(N).fill(0);
    for (let m = 0; m < S.length-1; m++) {
        T[m + 1] = T[m] + ((S.substr(m, 2) == 'AC') ? 1 : 0);
    }
    lr.forEach(function(v, i, a) {
        ans[i] = T[v[1]] - T[v[0]];
    });
    console.log(ans.join('\n'));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 57264
//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

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

#define int long long

using namespace std;
using namespace __gnu_pbds;

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

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int a[N];

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= 2 * n; ++i)
    cin >> a[i];
  sort(a + 1, a + 1 + n * 2);
  int ret = 0;
  for (int i = 1; i <= n * 2; i += 2)
    ret += a[i];
  cout << ret;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
H,W  = (int(X) for X in input().split())
Grid = np.ones((H+2,W+2),dtype=bool)
for TH in range(0,H):
    Grid[TH+1,1:W+1] = [False if X=='#' else True for X in input()] 

Flag = True
for TH in range(0,H):
    for TW in range(0,W):
        if Grid[TH+1,TW+1]==False:
            Check = np.all([Grid[TH+1,TW],Grid[TH+1,TW+2],Grid[TH,TW+1],Grid[TH+2,TW+1]])
            if Check==True:
                Flag = False
                break
    if Flag==False:
        break
if Flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27212
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

string d[4] = {"SS", "SW", "WS", "WW"};

signed main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    REP(i,4){
        string ans = d[i];
        for(int i = 1; i < n - 1; i++){
            if(s[i] == 'o'){
                if(ans[i] == 'S'){
                    ans.push_back(ans[i - 1]);
                }else{
                    if(ans[i - 1] == 'S'){
                        ans.push_back('W');
                    }else{
                        ans.push_back('S');
                    }
                }
            }else{
                if(ans[i] == 'S'){
                    if(ans[i - 1] == 'S'){
                        ans.push_back('W');
                    }else{
                        ans.push_back('S');
                    }
                }else{
                    ans.push_back(ans[i - 1]);
                }
            }
        }
        bool isok = true;
        if(s[n - 1] == 'o'){
            if(ans[n - 1] == 'S'){
                if(ans[0] != ans[n - 2]){
                    isok = false;
                }
            }else{
                if(ans[0] == ans[n - 2]){
                    isok = false;
                }
            }
        }else{
            if(ans[n - 1] == 'S'){
                if(ans[0] == ans[n - 2]){
                    isok = false;
                }
            }else{
                if(ans[0] != ans[n - 2]){
                    isok = false;
                }
            }
        }
        if(s[0] == 'o'){
            if(ans[0] == 'S'){
                if(ans[1] != ans[n - 1]){
                    isok = false;
                }
            }else{
                if(ans[1] == ans[n - 1]){
                    isok = false;
                }
            }
        }else{
            if(ans[0] == 'S'){
                if(ans[1] == ans[n - 1]){
                    isok = false;
                }
            }else{
                if(ans[1] != ans[n - 1]){
                    isok = false;
                }
            }
        }
        if(isok == true){
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define inf 1000000000007;
typedef long long ll;
int main(){
	fast;
	ll a,b; cin>>a>>b;
	bool f=0;
	for(auto i=1;i<1009;++i){
		if(floor(i*0.08)==a&&floor(i*0.1)==b || floor(i*0.8)==a&&floor(i*0.1)==b){
			f=1; cout<<i<<'\n'; break;
		}
	}
	if(!f)cout<<"-1\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2000005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin >> h >> w;
    vector<string> grid(h+2);
    string s = "";
    rep(i,w+2) s += '.';
    grid[0] = s;
    grid[h+1] = s;
    rep(i,h){
        cin >> grid[i+1];
        grid[i+1] = '.'+grid[i+1]+'.';
    }
    rep(i,1,h+1){
        rep(j,1,w+1){
            bool out = 1;
            if (grid[i][j] == '#'){
                rep(k,4){
                    ll xn = i+nx[k];
                    ll yn = j+ny[k];
                    if (grid[xn][yn] == '#') out = 0; 
                }
                if (out){
                    PRINT("No");
                    return 0;
                }
            }
        }
    }
    PRINT("Yes");
}


Measured memory_bytes: 3624
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline split-ints-into-vector))
(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))
  (declare (string string)
           (function key)
           ((array * (*)) dest-vector)
           ((integer 0 #.most-positive-fixnum) offset))
  (loop with position = 0
        for idx from offset below (length dest-vector)
        do (setf (values (aref dest-vector idx) position)
                 (parse-integer string :start position :junk-allowed t))
           (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))
        finally (return dest-vector)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil
;; ap0+bp0=10^9-20000
;; ap1+bp1=10^9-19999,...
;; ap(n-1)+bp(n-1)=10^9-1
;; (p0, ..., pn-1 is a permutation of 0, ..., n-1)
;; ap0 = [(p0+1)/(1+N) * (ap0+bp0)],...
(defun main ()
  (let* ((n (read))
         (ps (make-array n :element-type 'uint15))
         (as (make-array n :element-type 'uint32))
         (bs (make-array n :element-type 'uint32)))
    (split-ints-into-vector (read-line) ps :key #'1-)
    (loop for i from 0 below n
          for a+b = (- (expt 10 9) 20000) then (1+ a+b)
          do (let* ((p (aref ps i))
                    (a (floor (* a+b (1+ p)) (1+ n))))
               (setf (aref as p) a
                     (aref bs p) (- a+b a))))
    (dotimes (i n (terpri))
      (unless (zerop i)
        (princ #\ ))
      (princ (aref as i)))
    (dotimes (i n (terpri))
      (unless (zerop i)
        (princ #\ ))
      (princ (aref bs i)))))

#-swank(main)


Measured memory_bytes: 24036
a=int(input())
N=[0 for i in range(a)]
b=input()
#print(b)
N=b.split()
for i in range(a):
  N[i]=int(N[i])

#print(N)
  
a2ans=0
a2ans2=0
for i in range(a-1):
  if N[i]==N[i+1]:
    a2ans2+=1
    #print(a2ans2)
  else :
    if a2ans2%2==1 :
      a2ans2+=1
    
    a2ans+=a2ans2/2
    a2ans2=0


if a2ans2%2==1 :
  a2ans2+=1
#print(a2ans2)
a2ans+=a2ans2/2
a2ans2=0



print(int(a2ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){

	int n,target,cost; cin>>n;
	vector<int>v(n,0);
	vector<int>ans;
	for(int i=0;i<n;i++)
		cin>>v[i];
	
	sort(v.begin(),v.end());

    for(int i=v[0];i<=v[n-1];i++)
    { 
     // cerr<<"target= "<<i<<endl;
       for(int j=0;j<n;j++)
       	cost=cost+(v[j]-i)*(v[j]-i);
       	
        ans.push_back(cost);
        //cout<<"cost= "<<cost<<" ";
        cost=0;
    }
    
    sort(ans.begin(),ans.end());

    cout<<ans[0]<<" ";
	return 0;	
}

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


int main() {
  const double PI = 3.141593;
  long double a,b,x;
  cin >> a >> b >> x;
  long double ans = 0;
  if(x >= a*a*b/2) ans = atan(2*(a*a*b-x)/(a*a*a));
  else ans = atan((a*b*b)/(2*x));

  cout << fixed << setprecision(10);
  cout << ans*180.0/PI << endl;
}


Measured memory_bytes: 256
S = str(input())

# セキュリティコードは 4桁 の数字列です。
# セキュリティコードが「入力しづらい」とは、同じ数字が連続する箇所が存在することを言います。
# セキュリティコード S が「入力しづらい」なら Bad を、そうでなければ Good を出力してください。

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
    print("Bad")
else:
    print("Good")

Measured memory_bytes: 8864
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll a;
    ll all=0;
    ll all2=0;
    ll mod=1e9+7;
    rep(i,n){
        cin>>a;
        all+=a;
        all2+=a*a;
        all%=mod;
        all2%=mod;
    }
    all=(all*all)%mod;
    cout<<((all-all2+mod)%mod*500000004)%mod<<endl;
}


Measured memory_bytes: 3644
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}

ll N;
vl L;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    L = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> L[i];
    }
    solve();
}

// 1 <= N <= 100
// 1 <= L_i <= 10^9
// 入力は全て整数である

// ll N, vl L
// 三角形を作ることのできるような、長さの異なる 3 本の棒を選ぶ方法の個数を出力せよ。
void solve(){
    ll ans=0;
    rep(i,N)rep(j,i+1,N)rep(k,j+1,N){
        vl a={L[i],L[j],L[k]};
        sort(all(a));
        if(a[0]==a[1]||a[1]==a[2])continue;
        if(a[0]+a[1]>a[2])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3656
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 100010;

int n;
string s[MAXN];
ll cnt[5];

void solve() {
  for (int i=0;i<n;i++) {
    int index = 0;
    switch (s[i][0]) {
      case 'M':
        index = 0;
        break;
      case 'A':
        index = 1;
        break;
      case 'R':
        index = 2;
        break;
      case 'C':
        index = 3;
        break;
      case 'H':
        index = 4;
        break;
      default:
        index = -1;
    }
    if (index >= 0) {
      cnt[index]++;
    }
  }
  ll ans = 0;
  for (int i=0;i<5;i++) {
    for (int j=i+1;j<5;j++) {
      for (int k=j+1;k<5;k++) {
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> s[i];
  }
  solve();
}


Measured memory_bytes: 6144
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    S = input().strip()
    import string
    a = string.ascii_uppercase
    a = a*2
    s = ""
    for c in S:
        s = s + a[a.index(c)+N]
    print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41196
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
import bisect

n, d, a = [int(item) for item in input().split()]
places = []
xh = []
for i in range(n):
    x, h = [int(item) for item in input().split()]
    xh.append((x, h))
    places.append(x)
xh.sort()
places.sort()

N = 2**((n - 1).bit_length())
data0 = [0]*(N+1)
data1 = [0]*(N+1)
# 区間[l, r)に x を加算
def _add(data, k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def add(l, r, x):
    _add(data0, l, -x*(l-1))
    _add(data0, r, x*(r-1))
    _add(data1, l, x)
    _add(data1, r, -x)

# 区間[l, r)の和を求める
def _get(data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
def query(l, r):
    return _get(data1, r-1) * (r-1) + _get(data0, r-1) - _get(data1, l-1) * (l-1) - _get(data0, l-1)

ans = 0
for i, (x, h) in enumerate(xh):
    init_damage = (query(1, i+2) - query(1, i+1)) * a
    if init_damage >= h:
        continue
    bomb = (h - init_damage + a - 1) // a
    ans += bomb
    r_lim = bisect.bisect_right(places, x+2*d)
    add(1, r_lim+1, bomb)
print(ans)

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

using ll = long long;
#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 INF 1e9

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  REP(i, N){
    cin >> p[i];
    p[i]--;
  }
  UnionFind uf(N);
  REP(i, M){
    int x, y;
    cin >> x >> y;
    x--, y--;
    uf.unite(x, y);
  }
  int ans = 0;
  REP(i, N){
    if(uf.same(i, p[i])){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
n=int(input())
x=list(int(s) for s in input().split())
y=list(int(s) for s in input().split())
d=[(s-t,t-s)[s<t]for s,t in zip(x,y)]
f=lambda n:sum([s**n for s in d])**(1/n)
print(f(1),f(2),f(3),max(d),sep='\n')

Measured memory_bytes: 5652
#include <iostream>
#include <numeric>
#include <queue>
#include <cstring>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
const int inf=10000000;
int H,W,startx,starty,goalx,goaly;
string board[105];
int cost[105][105];
int d[105][105];
bool visited[150][105];
int dx8[]={-1,-1,0,1,1,1,0,-1};
int dy8[]={0,1,1,1,0,-1,-1,-1};
int dy[]={0,1,0,-1};
int dx[]={-1,0,1,0};
int student[105][105];
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
bool lefthand[105][105];
bool righthand[105][105];
int main(int argc,char const* argv[])
{
  int n;
  while(cin >> n &&  n)
    {
      int ans=-1;
      memset(lefthand,false,sizeof(lefthand));
      memset(righthand,false,sizeof(righthand));
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      cin >> student[i][j];
	    }
	}
      for(int i=0;i<n;i++)
	{
	  int mnl=1e9;
	  int lindex=-1;
	  for(int j=0;j<n;j++)
	    {
	      if(student[i][j]<mnl)
		{
		  mnl=student[i][j];
		  lindex=j;
		}
	    }
	   for(int j=0;j<n;j++)
	    {
	      if(student[i][j]==mnl)
		{
		  lefthand[i][j]=true;
		}
	    }
	}
      for(int i=0;i<n;i++)
	{
	  int mxr=-1;
	  int rindex=-1;
	  for(int j=0;j<n;j++)
	    {
	      if(student[j][i]>mxr)
		{
		  mxr=student[j][i];
		  rindex=j;
		}
	    }
	  for(int j=0;j<n;j++)
	    {
	      if(student[j][i]==mxr)
		{
		  righthand[j][i]=true;
		}
	    }
	}
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      if(lefthand[i][j]==true && righthand[i][j]==true)
		{
		  ans=student[i][j];
		}
	    }
	}
      if(ans!=-1)
	{
	  cout << ans << endl;
	}
      else
	{
	  cout << 0 << endl;
	}
    }
  return 0;
}



Measured memory_bytes: 3112
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int
main(void){  
  ios_base::sync_with_stdio(false);

  vector<int> v;
  int a;
  REP(i, 3){
    cin >> a;
    v.push_back(a);
  }

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

  int diff_ab = v[1] - v[0], diff_bc = v[2] - v[1];
  int ans = diff_bc;
  v[0] = v[0] + diff_bc;
  v[1] = v[2];

  /*
  cout << "ans: " <<  ans << endl;
  REP(i, 3) cout << v[i] << " ";
  cout << endl;
  */
  
  // == 1
  if(diff_ab%2) ans += (v[1]-v[0]+1)/2 + 1;
  else ans += (v[1]-v[0])/2;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,n,sum,ans;
map<long long,int>m;
int main()
{
	cin>>n;
	m[0]=1;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		sum+=a;
		ans+=m[sum];
		m[sum]++;
	}
	cout<<ans;
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
	string str,manyStr,longStr;
	map<string, int> m;
	int cnt = 1;
	int length = 0;
	while(cin >> str){
		m[str]++;
	}
	for(auto it = m.begin(); it != m.end(); it++){
		if(it->first.size() > length){
			length = it->first.size();
			longStr = it->first;
		}
		if(it->second > cnt){
			cnt = it->second;
			manyStr = it->first;
		}
	}
	cout << manyStr << " " << longStr << endl;
}

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

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

ll N,M;  vector<vector<pair<ll,ll>>> to ;

vector<ll> dist;

int main(){
cin >> N >> M; 
  dist = vector<ll> (N,INF);
  
  to.resize( N + 10);
  
  for(ll i = 0; i < M; i++){
    ll a,b,c; cin >> a >> b >> c; a--; b--; c *= -1;
    to[a].push_back(make_pair(b,c));}
  
  bool closed = false;
  
  dist[0] = 0;
  
  for(ll i = 1; i <=  2 * N - 2; i++){
    for(ll v = 0; v < N; v++){
      if( dist[v] == INF){ continue;}//
      else{
        if( to[v].empty()){ continue;}
        for( ll k = 0; k < to[v].size(); k++){
          ll p =  to[v][k].first; //vから繋がる先
          ll q =  to[v][k].second; // v- p間のコスト
          if( dist[p] > dist[v] + q){
            dist[p] = dist[v] + q;
            if( i >= N && p == N - 1){ closed = true;}}
        }}
    }}
  
  if( closed){ cout << "inf" << endl;}
  else{
    cout << -dist[N-1] << endl; } return 0;}
            
          


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S,T; cin >> S >> T;
    if (S.size() + 1== T.size()) {
        if (S == T.substr(0, S.size())) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3608
/*
Author : Gaurav Singh
*/
#include<bits/stdc++.h>
using namespace std;
#define N 5005
#define MOD 1000000007
#define ll long long
#define ld long double
#define ull unsigned long long
#define li long int
#define str string
#define vll vector<ll>
#define pb push_back
#define frn(i,n) for(ll (i) = 0; (i) <(n) ; (i)=(i+1))
#define fr(i,n) for(ll (i) = 1; (i) <=(n) ; (i)=(i+1))
#define frev(i,n) for(ll (i) = n-1; (i) >=(0) ; (i)--)
#define fr1(j,a,b,c) for(ll (j) = a; (j) <c ; (i)=(i+b))
#define w(t) while(t--)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
void solve(){
    int a,b,c;
    cin>>a>>b;
    c=a*b;
    cout<<c;
}
int main()
{   
   fast;
   int t=1;
   //cin>>t;
    w(t){
        solve();
    }
   return 0;
}   
            

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

int main()
{
  long long int i,j;
  
  long long int input;
  scanf("%d",&input);
  
  long long int sum;
  long long int count;
  count = 0;
  
  /*for(i=1;i<input;i++){
    for(j=i+1;j<input;j++){
      sum = i+j;
      if(sum == input){
        count++;
        break;
      }
    }
  }*/
  
  i = input%2;
  j = input/2;
  if(i == 0){
    count = j-1;
  }
  else{
    count = j;
  }
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 128
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let _n: usize = read()[0];
    let a: Vec<usize> = read();
    let mut v = vec![0_usize; 100_000];
    for &i in a.iter() {
        v[i] += 1;
    }
    let ans = (2..100_000)
        .map(|i| v[i - 2] + v[i - 1] + v[i])
        .max()
        .unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 6396
def sign(X):
    return [-1,0,1][(X>=0)+(X>0)]

N = int(input())
A = [int(T) for T in input().split()]

AFPCnt = 0
AFPNow = 0
for TFP in range(0,N):
    AFPNow += A[TFP]
    if sign(AFPNow)!=(-1)**TFP:
        AFPCnt += abs(AFPNow)+1
        AFPNow = (-1)**TFP

AFFCnt = 0
AFFNow = 0
for TFF in range(0,N):
    AFFNow += A[TFF]
    if sign(AFFNow)!=(-1)**(TFF+1):
        AFFCnt += abs(AFFNow)+1
        AFFNow = (-1)**(TFF+1)
print(min(AFPCnt,AFFCnt))

Measured memory_bytes: 20408
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
ll n,x,y,z,q;
int main(){
	r(x);r(y);r(z);r(q);r(n);
	if(n%2==0)printf("%lld\n",min(min(z,min(x*4,y*2))*n,n/2*q));
	else printf("%lld\n",min(min(z,min(x*4,y*2))*n,n/2*q+min(z,min(x*4,y*2))));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == '1') count++;
	}
	cout << count << endl;
	return 0;
}

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


int main() {
  int D, time, speed;
  std::cin >> D >> time >> speed;
  double space = speed*time;
  if (space >= D) {
    std::cout << "Yes" << endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
}




Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll a,b;
    cin >> a >> b;
    if((a-b)%2==0) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        xus: [(f64, String); n],
    }
    let ans = xus.into_iter().fold(0.0, |sum, (x, u)| {
        if u == "JPY" {
            sum + x
        } else {
            sum + x * 380000.0
        }
    });
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INFTY (1<<30)

vector<int> a(200005),ans(200005),color(200005,0),L(200005,INFTY);
vector<vector<int>> G(200005,vector<int>(0));

void dfs(int pos,int length){
    color[pos]=1;
    int npos=-1;
    for(int i=0;i<(int)G[pos].size();i++){
        if(color[G[pos][i]]==0){
            npos=G[pos][i];
            int it,old;
            bool flag=false;
            if(L[length-1]<a[npos]){
                flag=true;
                it=length;
                old=INFTY;
                L[length++]=a[npos];
            }
            else{
                it=distance(L.begin(),lower_bound(L.begin(),L.begin()+length,a[npos]));
                old=L[it];
                L[it]=a[npos];
            }
            ans[npos]=length;
            dfs(npos,length);
            L[it]=old;
            if(flag)length--;
        }
    }
    if(npos==-1){
        return;
    }           
} 

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    ans[0]=1;
    L[0]=a[0];
    dfs(0,1);

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

Measured memory_bytes: 34564
#include<bits/stdc++.h>
#define Rint register int
#define mem(a,b) memset(a,(b),sizeof(a))
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define For(i,j,k) for(Rint i=(j);i<=(k);i++)
#define Fordown(i,j,k) for(Rint i=(j);i>=(k);i--)

using namespace std;
typedef long long LL;

template<typename T>inline void read(T &x){
	x=0;T w=1,ch=getchar();
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
	x=x*w;
}

const int N=100+10;
int n,x;
int a[N],Ans;
int b[N];

int main(){
	read(n);read(x);
	For(i,1,n)read(a[i]);
	sort(a+1,a+n+1);
	For(i,1,n){
		if(x>=a[i])x-=a[i],b[i]+=a[i];
		if(i==n)b[i]+=x;
	}
	For(i,1,n)if(a[i]==b[i])Ans++;
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

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

func main() {
  var n int
  var k int
  fmt.Scan(&n, &k)
  k2 := k*2
  // 0 ≦ x,y ≦ 2K に圧縮
  squares := make([][]int, k2)
  for i := range squares {
    squares[i] = make([]int, k2)
  }
  sc.Split(bufio.ScanWords)
  for i := 0; i < n; i++ {
    x := nextInt()
    y := nextInt()
    color := nextString()
    // 'W'はY方向にKずらした'B'と同値
    if color == "W" {
      y += k
    }
    squares[x % k2][y % k2]++ 
  }
  // 計算量削減のために累積和を事前算出
  for i := 0; i < k2; i++ {
    for j := 1; j < k2; j++ {
      squares[i][j] += squares[i][j-1]
    }      
  }
  for j := 0; j < k2; j++ {
    for i := 1; i < k2; i++ {
      squares[i][j] += squares[i-1][j]
    }
  }  
  max_ := 0
  end := k2-1
  for i := 0; i < k; i++ {
    for j := 0; j < k; j++ {
      // ex) k = 2
      //      ■ □ □ ■ 
      //  j+k □ ■ ■ □
      //      □ ■ ■ □
      //    j ■ □ □ ■
      //      i   i+k
      cnt :=
        (squares[i][j]) +
        (squares[end][j] - squares[i+k][j]) +
        (squares[i+k][j+k] - squares[i+k][j] - squares[i][j+k] + squares[i][j]) +
        (squares[i][end] - squares[i][j+k]) +
        (squares[end][end] - squares[end][j+k] - squares[i+k][end] + squares[i+k][j+k])
      max_ = max(max(cnt, n - cnt), max_)
    }
  }  
  fmt.Print(max_)
}

func max(a int, b int) int {
  if a > b {
    return a
  } else {
    return b
  }
}

Measured memory_bytes: 37120
import sys
input = sys.stdin.readline
from itertools import permutations

def main():
    N, C = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(C)]
    grid = [list(map(int, input().split())) for _ in range(N)]

    sup0 = [0] * C
    sup1 = [0] * C
    sup2 = [0] * C
    for i in range(N):
        for j in range(N):
            if (i + j) % 3 == 0:
                sup2[grid[i][j] - 1] += 1
            elif (i + j) % 3 == 1:
                sup0[grid[i][j] - 1] += 1
            elif (i + j) % 3 == 2:
                sup1[grid[i][j] - 1] += 1

    ans = 10 ** 18
    for i, j, k in permutations(range(C), 3):
        tmp = 0
        for c in range(C):
            tmp += D[c][i] * sup0[c]
            tmp += D[c][j] * sup1[c]
            tmp += D[c][k] * sup2[c]
        ans = min(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 5620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
  
public class Main {
	
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
    
    public void exec() throws IOException {
    	InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
    	
        int N = in.nextInt();
    	int K = in.nextInt();
    	int[] A = in.nextInt(new int[N]);
    	
    	int gcd = A[0];
    	int max = A[0];
    	boolean existsK = (A[0]==K);
    	for(int i=1; i<N; i++) {
    		if(A[i] == K){
    			existsK = true;
    			break;
    		}
    		if(gcd>1){
    			gcd = getGcd(gcd,A[i]);
    		}
    		max = Math.max(max, A[i]);
    	}
        out.println((existsK || (K%gcd==0 && K<max))?"POSSIBLE":"IMPOSSIBLE");
    	out.flush();
    }
    
    public int getGcd(int a, int b) {
    	int tmp;
    	if(a < b) {
    		tmp=a; a=b;b=tmp;
    	}
    	while (a%b != 0){
    		tmp = a%b;
    		if(tmp > b){
        		a = tmp;
    		} else {
    			a = b;
    			b = tmp;
    		}
    	}
    	return b;
    }
}
 
 
 
 
/**
 * --------------------------------------------------
 * Input Utility
 * --------------------------------------------------
 */
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 50000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	}
 
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }
 
	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}
 
	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}
 
}

Measured memory_bytes: 24020
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;
    vs64 a(n);
    rep (i, n) cin >> a[i];

    map<s64, s64> m1;
    map<s64, s64> m2;
    rep (i, n)
    {
        ++m1[a[i] + i + 1];
        ++m2[i + 1 - a[i]];
    }

    s64 ans = 0;
    rep (i, n)
    {
        ans += m2[a[i] + i + 1];
        ans += m1[i + 1 - a[i]];
    }

    cout << ans / 2 << "\n";
    return 0;
}



Measured memory_bytes: 50192
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;


int main()
{
  int a,b;
  cin >> a >> b;
  if((a+b)%2==1) cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j;
	cin>>n;
	double p[n+1];
	for(i=0;i<n;i++)
	{
		cin>>p[i+1];
	}
	std::cout << std::setprecision(10);
	double dp[n+1][n+1];
	memset(dp,0,sizeof(dp));
	dp[1][1]=p[1];
	dp[0][1]=1-p[1];
	for(i=2;i<=n;i++)
		dp[0][i]=dp[0][i-1]*(1-p[i]);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{

			if(i==1 && j==1)
			continue;
			if(i<=j)
			dp[i][j]=dp[i-1][j-1]*p[j]+dp[i][j-1]*(1-p[j]);
		}
		
	}

	int temp=n/2;
	double count=0;
	for(i=temp+1;i<=n;i++)
	count=count+dp[i][n];
	cout<<count<<endl;


}

Measured memory_bytes: 70528
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int n = scan.nextInt();
		Integer[] a = new Integer[n];
		Integer[] b = new Integer[n];
		int result = 0;

		for(int i=0;i<n;i++) {
			a[i] = scan.nextInt();
		}

		b[0] = k-a[n-1]+a[0];

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

		Arrays.parallelSort(b);
		for(int i=0;i<n-1;i++) {
			result+=b[i];
		}

		System.out.println(result);


	}

}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> ans(n);
    ll sumx = 0;
    rep(i,n){
        sumx = (sumx ^ a[i]);
    }
    rep(i, n) ans[i] = (sumx ^ a[i]);
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 6300