akhauriyash/Code-Regression huggingface dataset:
import math
# import numpy as np
import sys

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

ans = ["pon", "pon", "hon", "bon","hon","hon","pon","hon","pon","hon"]

n = NextInt()
print(ans[n%10])


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<P> bc(m);
    rep(i,m){
        int b, c;
        cin >> b >> c;
        bc[i] = P(c,b);
    }
    sort(bc.begin(), bc.end());
    reverse(bc.begin(), bc.end());
    int idx = 0;
    rep(i,m){
        int b = bc[i].second;
        int c = bc[i].first;
        rep(j,b){
            if(a[idx] < c){
                a[idx] = c;
                idx++;
            }
            else{
                i = m;
                break;
            }
        }
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 4120
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int cost = 0;
    if(A + B <= 2*C){
        cost = A * X + B * Y;
    }else{
        if(X < Y){
            cost = X * 2 * C;
            cost += (Y - X) * min(2 * C, B);
        }else if(X == Y){
            cost = X * 2 * C;
        }else{
            cost = Y * 2 * C;
            cost += (X - Y) * min(2 * C, A);
        }

    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
# ABC097 D - Equals
class UnionFind:
    # 最初は全てを根として初期化
    def __init__(self, n):
        self.par = [i for i in range(n)]
    
    # データxが属する木の根を再帰で取得する：root(x) = {xの木の根}
    def root(self, x):
        if (self.par[x] == x):
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
    
    # xとyの木を併合する
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        if x < y:
            self.par[ry] = rx
        else:
            self.par[rx] = ry
    # 2つのデータx, yが属する木が同じならtrueを返す
    def same(self, x, y):
        return self.root(x) == self.root(y)

n,m = map(int, input().split())
p = [int(x)-1 for x in input().split()]

ans = 0
UF = UnionFind(n)

for _ in range(m):
    x, y = map(int, input().split())
    UF.unite(x - 1, y - 1)

for i in range(n):
    if UF.same(i,p[i]):
        ans += 1
print(ans)

Measured memory_bytes: 14452
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    string s;cin>>s;
    unordered_map<char,set<ll>> mp;
    vector<vector<ll>> memo(n,vector<ll>(n,-1));
    rep(i,n){
        mp[s[i]].insert(i);
    }
    function<ll(ll,ll)> check = [&](ll cur, ll mx){
        ll result = 0;
        auto it = mp[s.at(cur)].upper_bound(cur+mx*2);
        while(it!=mp[s[cur]].end()){
            ll from = *it;
            ll length = 1;
            while(cur+length<from&&from+length<n&&s[cur+length]==s[from+length]){
                length++;
            }
            chmax(result, length);
            it++;
        }
        DEBUG{
            printf("cur: %lld, res: %lld\n",cur,result);
        }
        return result;
    };
    ll res = 0;
    rep(i,n){
        if(res>=(n-i)/2){
            DEBUG{
                printf("out\n");
            }
            break;
        }
        chmax(res, check(i,res)); 

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 196096
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

int h, w, k;

char c[6][6];
bool blockr[6], blockc[6];

int go(int mskr, int mskc){
	int ans = 0;
	For(i,0,w) if((mskc>>i)&1) blockc[i]=1;
	For(i,0,h) if((mskr>>i)&1) blockr[i]=1;
	For(i,0,h) For(j,0,w) if(!blockr[i] && !blockc[j])
		ans += c[i][j]=='#';
	For(i,0,w) blockc[i]=0;
	For(i,0,h) blockr[i]=0;
	return ans==k;
}

int main(){
	fastio;
	cin>>h>>w>>k;
	For(i,0,h) For(j,0,w) cin>>c[i][j];
	int msk1 = 1<<h, msk2 = 1<<w;
	int ans=0;
	For(i,0,msk1) For(j,0,msk2)
		ans += go(i,j);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>

int main(){
	char c;
	char s[20];
	int i, sum;
	while(1 + scanf("%s", &s)){
		i = 0, sum = 0;

		while(s[i]){
			switch(s[i]){
				case 'M':
					sum += 1000;
					break;
				case 'D':
					sum += 500;
					break;
				case 'C':
					sum += 100;
					break;
				case 'L':
					sum += 50;
					break;
				case 'X':
					sum += 10;
					break;
				case 'V':
					sum += 5;
					break;
				case 'I':
					sum += 1;
					break;
			}
			i++;
		}
		if(strstr(s, "CM") || strstr(s, "CD")){
			sum -= 200;
		}
		if(strstr(s, "XC") || strstr(s, "XL")){
			sum -= 20;
		}
		if(strstr(s, "IX") || strstr(s, "IV")){
			sum -= 2;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <string>
using namespace std;
int ans = 0, n;

int dfs(long long i, int x, int y, int z)
{
    if (i > n)
    {
        return 0;
    }
    if (x >= 1 && y >= 1 && z >= 1)
    {
        ans++;
    }
    dfs(10 * i + 3, x + 1, y, z);
    dfs(10 * i + 5, x, y + 1, z);
    dfs(10 * i + 7, x, y, z + 1);
    return 0;
}

int main()
{
    cin >> n;
    dfs(3,1,0,0);
    dfs(5,0,1,0);
    dfs(7,0,0,1);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int x = inp.nextInt();
        boolean a = (x == 7 || x == 5 || x == 3);
        String ans = (a ? "YES" : "NO");
        System.out.println(ans);
    }
}

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

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int fact[N];
int inv[N];

int add(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return (a + b) % mod;
}

int mul(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return ((ll)a * b) % mod;
}

int fastpow(int base, int power)
{
    if(power == 0)
      return 1;
    int ret = fastpow(base, power / 2);
    ret = mul(ret, ret);
    if(power & 1)
      ret = mul(ret, base);
    return ret;
}

void init()
{
  fact[0] = 1;
  for(int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
  for(int i = 0; i < N; i++)
    inv[i] = fastpow(fact[i], mod - 2);
}

bool can(int n, int m, int turn)
{
  while (true)
  {
    if(n == 0 && m == 0)
      return 1;
    if(turn == 0 && n == 0)
      return 0;
    if(turn == 1 && m == 0)
      return 0;
    if(turn == 0)
      n--;
    else
      m--;
    turn = (turn + 1) % 2;
  }
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  int n, m;
  cin >> n >> m;
  int ans = 0;
  if(can(n, m, 0))
    ans = add(ans, mul(fact[n], fact[m]));
  if(can(n, m, 1))
    ans = add(ans, mul(fact[n], fact[m]));
  cout << ans;
  return 0;
}


Measured memory_bytes: 1792
k=[0]*26
while True:
    try : n=input()
    except EOFError: break
    for i in range(len(n)):
        a=ord(n[i])-ord('a')            
        if a>=0 and a<26 :
            k[a]+=1
        b=ord(n[i])-ord('A')
        if b>=0 and b<26 :                
            k[b]+=1

for i in range(26):
    print(chr(i+ord('a')),':',k[i])



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

int main() {
    int n;
    cin>>n;
    lli a[n+1],b[n+1],c[n];
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<n;i++)cin>>c[i];
    lli sum = 0;
    for(int i=1;i<=n;i++){
        if(i == 1){
            sum += b[a[i]];
        }else{
            if((a[i] - 1) == a[i-1]){
                sum += (b[a[i]] + c[a[i-1]]);
            }else{
                sum += b[a[i]];
            }
        }
        //cout<<sum<<"\n";
    }
    cout<<sum<<"\n";
    return 0;
}


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

int main() {
  cout << setprecision(15);
  int n;
  cin >> n;
  vector<int> h(n);
  for (auto& e : h) cin >> e;
  bool ok = true;
  for (int i = h.size() - 1; i >= 0 && ok; --i) {
    if (h[i-1] - h[i] >= 2) ok = false;
    if (h[i-1] - h[i] == 1) h[i-1] -= 1;
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
import sys
import queue
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def ccc(start, goal, mat):
	open=queue.PriorityQueue()
	close=set()
	open.put((0, start))
	
	while True:
		cost, pos = open.get()
		#pa((cost,pos))
		if pos == 1:
			return cost
		if pos in close:
			continue
		for i in range(0,9+1):
			if i == pos:
				continue
			open.put((cost + mat[pos][i], i))
		else:
			close.add(pos)
	
	return -1

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	mm = [lin() for _ in range(10)]
	dist=dict()
	for i in range(0, 9+1):
		dist[i] = ccc(i,1,mm)
	dist[-1]=0
	
	ret=0
	for hi in range(h):
		al = lin()
		for v in al:
			ret += dist[v]
	return ret
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main(){
int A, B;
cin >> A >> B;
if (A <= 5) {
    cout << '0' << endl;
} else if (A <= 12 && A >= 6){
    cout << B/2 << endl;
} else {
    cout << B << endl;
}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005;
int n,m,tot,a[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&a[i]);
		if(a[i]%2){
			tot++;
		}
	}
	if(m==1){
		if(a[1]==1){
			printf("1\n1\n1\n");
		}else{
			printf("%d\n2\n1 %d\n",a[1],a[1]-1);
		}
		return 0;
	}
	if(tot>2){
		puts("Impossible");
		return 0;
	}
	for(int i=1;i<=m;i++){
		if(a[i]%2){
			swap(a[1],a[i]);
			break;
		}
	}
	for(int i=2;i<=m;i++){
		if(a[i]%2){
			swap(a[m],a[i]);
			break;
		}
	}
	for(int i=1;i<=m;i++){
		printf("%d ",a[i]);
	}
	puts("");
	if(a[m]!=1){
		printf("%d\n",m);
		printf("%d ",a[1]+1);
		for(int i=2;i<m;i++){
			printf("%d ",a[i]);
		}
		printf("%d ",a[m]-1);
	}else{
		printf("%d\n",m-1);
		printf("%d ",a[1]+1);
		for(int i=2;i<m;i++){
			printf("%d ",a[i]);
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 128
<?php
$name=["Sunny", "Cloudy", "Rainy"];
list($S)=sscanf(trim(fgets(STDIN)),"%s");
for($i=0;$i<=2;$i++){
    if($name[$i] == $S){
        $current = $i;
    }
}
$current++;
if($current > 2){
    $current = 0;
}
printf($name[$current]);

Measured memory_bytes: 4604
A,B,C,X,Y = [int(x) for x in input().split()]
ans = 10**15
ans = min(ans,X*A+Y*B)
if(X<Y):
    ans = min(ans,2*X*C+(Y-X)*B)
else:
    ans = min(ans,2*Y*C+(X-Y)*A)
ans = min(ans,2*max(X,Y)*C)
print(ans)


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

int main(void)
{
    int N;
    cin >> N;

    pair<int, int> taskList[N];

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        taskList[i] = make_pair(b, a);
    }

    sort(taskList, taskList+N);
    int t = 0;
    for (int i = 0; i < N; i++) {
        if (t + taskList[i].second > taskList[i].first) {
            cout << "No" << endl;
            return 0;
        }
        t += taskList[i].second;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1792
MOD = 1000000007

N = int(input())
S = input()

cnt = {}
for s in S:
    if s not in cnt:
        cnt[s] = 1
    else:
        cnt[s] += 1

ans = 1
for v in cnt.values():
    ans *= v + 1
    ans %= MOD

print(ans - 1)


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

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

    vector<string> sub;
    for (int i = 0; i < s.length(); i++)
    {
        for (int j = 1; j <= k && i + j - 1 <= s.length() - 1; j++)
        {
            string tmp = s.substr(i, j);
            sub.push_back(tmp);
        }
    }
    sort(sub.begin(), sub.end());
    unique(sub.begin(), sub.end());
    cout << sub[k - 1] << endl;
}

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

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

Measured memory_bytes: 1156
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int a, b, c; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
	a = read <int> (), b = read <int> (), c = read <int> ();
	if(a + b + c >= 22) puts("bust");
	else puts("win"); 
	return 0; 
}


Measured memory_bytes: 256
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1, x2 in zip(range(H), range(H - 1, -1, -1)):
        for y1, y2 in zip(range(W), range(W - 1, -1, -1)):
            if S[x1][y1] == "#":  # left and upper sides of S[i][j]
                L[x1][y1] == 0
                U[x1][y1] == 0
            else:
                U[x1][y1] = 1 if x1 == 0 else U[x1 - 1][y1] + 1
                L[x1][y1] = 1 if y1 == 0 else L[x1][y1 - 1] + 1

            if S[x2][y2] == "#":  # right and under sides
                R[x2][y2] == 0
                D[x2][y2] == 0
            else:
                D[x2][y2] = 1 if x2 == H - 1 else D[x2 + 1][y2] + 1
                R[x2][y2] = 1 if y2 == W - 1 else R[x2][y2 + 1] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 177928
package main

import (
	"fmt"
	"math"
)

func main() {
	var x string
	fmt.Scan(&x)

	var answer int = 0
	for i := range x {
		n := int(math.Pow(10, float64(2-i)))
		switch x[i] {
		case '1':
			answer += 9 * n
		case '9':
			answer += 1 * n
		}
	}

	fmt.Println(answer)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}
ll kj(ll x){
    ll s = 1;
    for(ll i = 1; i <= x; i++){
        s = s * i % MOD;
    }
    return s;
}
ll combination(ll a, ll b){
    if(a == 0 && b == 0) return 1;
    if(a < b || a < 0) return 0;
    return (kj(a) * mpow(kj(b), MOD-2) % MOD) * mpow(kj(a-b), MOD-2) % MOD;
}


int main(){
    int N,K;
    cin >> N >> K;
    int Sepa;
    for(int i=1; i <= K; i++){
        if(N-K+1 < i or K-1 < i-1){
            cout << 0 << endl;
        }else{
            cout <<  combination(N-K+1,i) % MOD * combination(K-1,i-1) % MOD << endl;
        }
    }
}


Measured memory_bytes: 256
def resolve():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    
    dis = [0]*N
    for i in range(N-1):
        dis[i] = A[i+1]-A[i]
    dis[N-1] = K-A[N-1]+A[0]
    ans = K-max(dis)
    
    print(ans)
resolve()


Measured memory_bytes: 77260
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define MP make_pair
#define fs first
#define sc second
#define F first
#define S second
#define nl "\n"
#define asche cerr<<"Ekhane asche\n";
#define pf printf
#define sf scanf
#define mem(a,x) memset(a,x,sizeof(a))
#define SZ(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define one(x) __builtin_popcount(x)
#define fout(x) fixed<<setprecision(x)
#define BeatMeScanf ios_base::sync_with_stdio(false)
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    deb(++it, args...);
}
//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace IO
{
    #define in() ( { int a ; scanf("%d",&a); a; } )
    #define LL() ( { ll a ; scanf("%lld",&a); a; } )
       #define ULL() ( { ull a ; scanf("%llu",&a); a; } )
    #define DD() ({ double a; scanf("%lf", &a); a;})
    #define CC() ( { char a ; scanf("%c",&a); a; } )
    #define pf1(a) printf("%d\n",a)
    #define pf1ll(a) printf("%lld\n",a)
}
using namespace IO;

const int mod=1e9+7;
const int N=3e5+9;
const double eps=1e-9;
const double PI=acos(-1.0);
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}


int32_t main()
{
    int a=in(),b=in();
    cout<<max(0,a-2*b)<<nl;
    return 0;
}
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1



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

#define N 100000

pair<int, int> odd[N], even[N];

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];      
    if(i%2==0){
      even[a[i]].first++;
      even[a[i]].second = a[i];
    } else {
      odd[a[i]].first++;
      odd[a[i]].second = a[i];
    }    
  }

  sort(even, even+N);
  sort(odd, odd+N);

  int e1 = even[N-1].second;
  int ec1 = even[N-1].first;
  int ec2 = even[N-2].first;
  int o1 = odd[N-1].second;
  int oc1 = odd[N-1].first;
  int oc2 = odd[N-2].first;

  int ans;
  if(e1!=o1){
    ans = n - ec1 - oc1;
  } else {
    ans = min(n-ec1-oc2, n-ec2-oc1);
  }

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


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string a = in<string>(),b = in<string>(),c = in<string>();
    cout << a[0] << b[1] <<c[2]<< "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include<cmath>
int main(){
    int l;
    scanf("%d\n",&l);

    bool a[4][13];
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < 13;j++){
            a[i][j] = false;
        }
    }

    for(int i = 0;i < l;i++){
        char c;
        scanf("%c",&c);
        
        int x;
        scanf("%d\n",&x);
            
        if(c == 'S'){
            a[0][x - 1] = true;
        }
        else if(c == 'H'){
             a[1][x - 1] = true;
        }
        else if(c == 'C'){
             a[2][x - 1] = true;
        }
        else if(c == 'D'){
             a[3][x - 1] = true;
        }
    }
    
    
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < 13;j++){
            if(a[i][j] == false){ 
                if(i == 0){
                    printf("S %d\n",j+1);
                }
                else if(i == 1){
                    printf("H %d\n",j+1);
                }
                else if(i == 2){
                    printf("C %d\n",j+1);
                }
                else if(i == 3){
                    printf("D %d\n",j+1);
                }
            }
        }
        
    }
    return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	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;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	const ll mod = 1e9 + 7;
	ll n;
	cin >> n;

	ll s = pow2(8, n, mod);
	ll t = pow2(9, n, mod);
	ll ans = pow2(10, n, mod);

	ans -= (2 * t) % mod;
	if (ans < 0) {
		ans += mod;
	}
	ans += s;
	ans %= mod;

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


Measured memory_bytes: 3636
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll dp[200010][2][2]={};

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  string s;cin>>s;

  V<ll> lesum(n+1,0),risum=lesum;
  rep(i,0,n){
    if(s[i]=='W')lesum[i+1]=lesum[i]+1;
    else lesum[i+1]=lesum[i];
  }

  repr(i,0,n){
    if(s[i]=='R')risum[i]=risum[i+1]+1;
    else risum[i]=risum[i+1];
  }


  ll ans=INF;
  rep(i,0,n){
    chmin(ans,max(lesum[i],risum[i+1]));
  }
  chmin(ans,lesum[n]);
  chmin(ans,risum[0]);
  cout<<ans<<ENDL;

}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 333;
int n, f[N], a[N], mx;

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

	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		mx = max(a[i], mx);
		f[a[i]]++;
	}
	int l = -1, r = -1;
	int mn = (mx + 1) / 2;
	for(int i = 0; i < mn; i++) if(f[i])
		return cout << "Impossible\n", 0;

	if(mx % 2 == 1) {
		if(f[mn]!= 2)
			return cout << "Impossible\n", 0;
	} else {
		if(f[mn]!= 1)
			return cout << "Impossible\n", 0;
	}
	for(int i = mn + 1; i <= mx; i++)
		if(f[i] < 2) 
			return cout << "Impossible\n", 0;
	cout << "Possible\n";
}	

	

Measured memory_bytes: 256
/*
	ARIJIT SUR 
	@duke_knight
	@surcode
    @comeback
	IIT ISM 
 */
#include<bits/stdc++.h>
#define SIZE 100008
#define mod (ll)(1e9+7)
#define INF 0x3f3f3f3f
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(a) (a>0?a:-a)
#define all(a) a.begin(),a.end()
#define maxelem(a) *max_element(all(a))
#define minelem(a) *min_element(all(a))
#define pb push_back
#define pi pair<int,int>
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a) {for(int i1=0;i1<a.size();i1++) cin>>a[i1];}
#define display(a) {for(int i1=0;i1<a.size();i1++) cout<<a[i1]<<" "; cout<<endl;}
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define  vi vector<int>
typedef long long ll;

void dfs(int x, int &cnt, vi g[], vector<bool> &vis)
{
    vis[x]=true;
    cnt++;
    int neigh=g[x].size();
    for(int i=0;i<neigh;i++)
    {
        if(!vis[g[x][i]])
        dfs(g[x][i],cnt,g,vis);
    }
}
void solve(){
    int n,m;
        cin>>n>>m;
        
        vector<int> g[n+1];
        vector<bool>vis(n+1);       
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            g[x].pb(y);g[y].pb(x);
        }
        
        int ma=-1;
        for(int u=1;u<=n;u++)
        {
            if(!vis[u])
            {
                int count=0;
                dfs(u,count,g,vis);
                ma=max(count,ma);
            }
        }
        cout<<ma;
}
int main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}

Measured memory_bytes: 30076
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
#define int long long

const int mod = 998244353;
const int inf = 2e9;
const int N = 5e6 + 15;
int n, m, ans, a[N], fact[N];

inline void calc_factorial() {
    fact[0] = fact[1] = 1;
    for(int i = 2; i < N; ++i)
        fact[i] = (fact[i-1] * i) % mod;
}

inline int binpow(int n, int k) {
    int res = 1;
    while(k) {
        if(k & 1)
            res = (res * n) % mod;
        k >>= 1;
        n = (n * n) % mod;
    }
    return res;
}

inline int multiply(int a, int b) {
    return (a * b) % mod;
}

inline int divide(int a, int b) {
    return multiply(a, binpow(b, mod - 2));
}

inline int C(int n, int k) {
    if(k > n || n < 0 || k < 0)
        return 0;
    return divide(fact[n], multiply(fact[n - k], fact[k]));
}

inline void add(int &a, int b) {
    a += b;
    if(a >= mod)
        a -= mod;
    if(a < 0)
        a += mod;
}

main() {
    cin >> n >> m;
    calc_factorial();
    for(int odd = 0; odd <= min(n, m); ++odd) {
        if((3 * m - odd) & 1)
            continue;
        int even = (3 * m - odd) / 2;
        add(ans, multiply(C(n, odd), C(even + n - 1, n - 1)));
    }
    for(int odd = 0; odd <= min(n, m); ++odd) {
        if((m - odd) & 1)
            continue;
        int even = (m - odd) / 2;
        add(ans, -multiply(n, multiply(C(n, odd), C(even + n - 1, n - 1))));
        add(ans, multiply(n, multiply(C(n - 1, odd), C(even + n - 2, n - 2))));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 41216
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        new Thread(null, () -> {
            int n;
            int k;
            List<Integer> as = new ArrayList<>();
            try (Scanner sc = new Scanner(System.in)) {
                n = sc.nextInt();
                k = sc.nextInt();
                for (int i = 0; i < n; i++) {
                    as.add(sc.nextInt() - 1);
                }
            }
            System.out.println(new Calculator(n, k, as).calculate());
        }, "", 1 << 25).start();
    }
}

class Calculator {
    private int k;
    private int answer = 0;
    private boolean isCalculate = false;
    private List<List<Integer>> lists = new ArrayList<>();

    Calculator(int n, int k, List<Integer> as) {
        this.k = k;
        for (int i = 0; i < n; i++) {
            this.lists.add(new ArrayList<>());
        }
        for (int i = 0; i < n; i++) {
            int j = as.get(i);
            if (0 < i) {
                this.lists.get(j).add(i);
            } else if (0 < j) {
                this.answer++;
            }
        }
    }

    int calculate() {
        if (!this.isCalculate) {
            this.dfs(0, 0);
            this.isCalculate = true;
        }
        return this.answer;
    }

    private int dfs(int a, int pre) {
        int h = 0;
        for (int i : this.lists.get(a)) {
            h = Math.max(h, this.dfs(i, a));
        }
        if (0 < pre && h == this.k - 1) {
            h = 0;
            this.answer++;
        } else {
            h++;
        }
        return h;
    }
}

Measured memory_bytes: 48384
#include <stdio.h>

int
main()
{

  int d;
  int i;
  int menseki;
  
  while (-1 != scanf("%d\n", &d))
    {
      menseki = 0;
      for (i = d; i < 600; i += d)
	{
	  menseki = menseki + d * i * i;
	}

      printf ("%d\n", menseki);
    }
  return 0;
}



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

int main()
{
  int n, cnt = 0, flag = 0;
  cin >> n;
  int *a = new int[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  while (1) {
    for (int i = 0; i < n; i++)
      if (a[i]%2) {
        flag = 1; break;
      }
    if (flag)
      break;
    else {
      for (int i = 0; i < n; i++)
        a[i] /= 2;
      cnt++;
    }
  }
  
  delete a;
  cout << cnt << endl;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	seg := Segment{}
	seg.init(n)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[getNextInt(scanner)-1] = i
	}
	var ans int64
	for i := 0; i < n; i++ {
		seg.add(aa[i], 1)
		l := seg.nextLeft(aa[i])
		r := seg.nextRight(aa[i])
		ans += int64(aa[i]-l) * int64(r-aa[i]) * int64(i+1)

	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i int
	unit    []int
	bucket  [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 2
	i := 0
	for n > chunk+1 {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
		i++
	}
	seg.h = len(seg.unit)
}

func (seg *Segment) add(index, value int) {
	for i := 0; i < seg.h; i++ {
		seg.bucket[i][index/seg.unit[i]] += value
	}
}

func (seg *Segment) nextLeft(index int) int {
	raw := seg.bucket[0]
	for index = index - 1; index >= 0; index-- {
		if raw[index] > 0 {
			return index
		}
		for seg.i = 0; seg.i < seg.h; seg.i++ {
			if (index+1)%seg.unit[seg.i] != 0 {
				break
			}
			if seg.bucket[seg.i][index/seg.unit[seg.i]] != 0 {
				break
			}
		}
		seg.i--
		index -= seg.unit[seg.i] - 1
	}

	return -1
}

func (seg *Segment) nextRight(index int) int {
	raw := seg.bucket[0]
	for index = index + 1; index < seg.n; index++ {
		if raw[index] > 0 {
			return index
		}
		for seg.i = 0; seg.i < seg.h; seg.i++ {
			if index%seg.unit[seg.i] != 0 {
				break
			}
			if seg.bucket[seg.i][index/seg.unit[seg.i]] != 0 {
				break
			}
		}
		seg.i--

		index += seg.unit[seg.i] - 1
	}

	return seg.n
}

func (seg *Segment) get(index int) int {
	for i := 0; i < seg.n; i++ {
		for seg.i = 0; seg.i < seg.h; seg.i++ {
			if index%seg.unit[seg.i] != 0 {
				break
			}
			if seg.bucket[seg.i][index/seg.unit[seg.i]] >= index {
				break
			}
		}
		seg.i--

		index -= seg.bucket[seg.i][index/seg.unit[seg.i]]
		i += seg.unit[seg.i] - 1

		if index == 0 {
			return i
		}
	}

	return -1
}


Measured memory_bytes: 7424
local mfl = math.floor
local TranFFT = {}

TranFFT.initialize = function(self)
  self.size = 18
  -- 2^18
  self.n = 262144
  -- 1007681537: prime,
  -- 1007681537 % 262144 = 1
  self.mod = 1007681537
  -- (6161^262144) % mod = 1
  self.w = 6161
  -- (1007677693 * 262144) % mod = 1
  self.ninv = 1007677693
  -- (534835031 * 6161) % mod = 1
  self.winv = 534835031
  self.p2 = {1}
  for i = 2, self.size do
    self.p2[i] = self.p2[i - 1] * 2
  end
  self.binv = {}
  for i = 1, self.n do
    local y, z = 0, i - 1
    for j = 1, self.size do
      y = y + (z % 2) * self.p2[self.size + 1 - j]
      z = mfl(z / 2)
    end
    self.binv[i] = y + 1
  end
  self.wmul = {1}
  for i = 2, self.n do
    self.wmul[i] = self:mul(self.wmul[i - 1], self.w)
  end
  self.winvmul = {1}
  for i = 2, self.n do
    self.winvmul[i] = self:mul(self.winvmul[i - 1], self.winv)
  end
end

-- (44893^2) % 1007681537 = 18375
-- 1007681537 = 22446 * 44893 + rem(13259)
-- x0, y0 <= 44892
-- x1, y1 <= 22446
-- max(x1y1*18375+(x1y0+x0y1)*44893+x0y0) < 10^14
TranFFT.mul = function(self, x, y)
  local x0, y0 = x % 44893, y % 44893
  local x1, y1 = mfl(x / 44893), mfl(y / 44893)
  return (x1 * y1 * 18375 + (x1 * y0 + x0 * y1) * 44893 + x0 * y0) % self.mod
end

TranFFT.add = function(self, x, y) return (x + y) % self.mod end

TranFFT.fft_common = function(self, ary, wmul)
  local ret = {}
  for i = 1, self.n do
    ret[i] = ary[self.binv[i]]
  end
  for i = 1, self.size do
    local step_size = self.p2[i]
    local step_count = self.p2[self.size + 1 - i]
    for istep = 1, step_count do
      local ofst = (istep - 1) * step_size * 2
      for j = 1, step_size do
        local a1, a2 = ret[ofst + j], ret[ofst + step_size + j]
        ret[ofst + j] = self:add(a1, self:mul(a2, wmul[1 + (j - 1) * step_count]))
        ret[ofst + step_size + j] = self:add(a1, self:mul(a2, wmul[1 + (j + step_size - 1) * step_count]))
      end
    end
  end
  return ret
end

TranFFT.fft = function(self, ary)
  return self:fft_common(ary, self.wmul)
end
TranFFT.ifft = function(self, ary)
  local ret = self:fft_common(ary, self.winvmul)
  for i = 1, self.n do
    ret[i] = self:mul(ret[i], self.ninv)
  end
  return ret
end

TranFFT:initialize()
local a = {}
for i = 1, TranFFT.n do
  a[i] = 0
end
local k, s = io.read("*n", "*n")
for i = 1, k + 1 do
  a[i] = 1
end

local at = TranFFT:fft(a)
for i = 1, TranFFT.n do
  local z = at[i]
  at[i] = TranFFT:mul(z, TranFFT:mul(z, z))
end
local b = TranFFT:ifft(at)
print(b[s + 1])


Measured memory_bytes: 12672
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int A[500][500];
struct data {
  int x;
  int y;
  int x_;
  int y_;
  data(int x, int y, int x_, int y_) : x(x), y(y), x_(x_), y_(y_) {}
};

int main(){
  int H, W;
  cin >> H >> W;
  vector<data> D;
  for(int i=0; i<H; i++)
    for(int j=0; j<W; j++)
      cin >> A[i][j];
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if(A[i][j] % 2 == 1) {
	A[i][j]--;
	if(j == W-1) {
	  if(i != H-1) {
	    D.push_back(data(i+1, j+1, i+2, j+1));
	    A[i+1][j]++;
	  }
	} else {
	  D.push_back(data(i+1, j+1, i+1, j+2));
	  A[i][j+1]++;
	}
      }
    }
  }
  cout << D.size() << endl;
  for(int i=0; i<D.size(); i++)
    cout << D[i].x << ' ' << D[i].y << ' ' << D[i].x_ << ' ' << D[i].y_ << endl;
  return 0;
}


Measured memory_bytes: 5104
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
hash = Hash.new(0)
sides = []
as.each do |a|
  hash[a] += 1
end
hash.each do |k,v|
  if v >= 4
    sides << k
    sides << k
  elsif v >= 2
    sides << k
  end
end
if sides.size < 2
  ans = 0
else
  sides.sort!
  ans = sides[-1] * sides[-2]
end
puts ans

Measured memory_bytes: 16004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
char in[2];
int main() {
  int k, x; cin >> k >> x;
  if(k*500>=x) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
ans_re = []
ans = ""
dic = {}
dic_re = {}

for i in range(n):
    S = list(input())
    for x in S:
        if x not in dic_re:
            dic_re[x] = 1
        else:
            dic_re[x] += 1
    
    if i == 0:
        dic = dic_re.copy()
    else:
        for x in dic:
            if x in dic_re:
                a = dic[x]
                b = dic_re[x]
                dic[x] = min(a, b)
            else:
                dic[x] = 0
    dic_re.clear()

for x in dic:
    ans_re.append([x, dic[x]])
ans_re.sort()
l = len(ans_re)
for i in range(l):
    ans = ans + ans_re[i][0]*ans_re[i][1]
print(ans)

Measured memory_bytes: 3064
cc = [list(map(int, input().split())) for i in range(3)]
tc = [x for c in cc for x in c]

if sum(tc) % 3 != 0:
  print('No')
else:
  cnt = 0
  for i in range(3):
    cnt  += cc[i][i]
  if cnt == sum(tc)//3:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 9044
#include<iostream>
using namespace std;
int main()
{
	int a[3], max, min;
	cin >> a[0];
	max = min = a[0];
	for (int i = 1; i <= 2; i++)
	{
		cin >> a[i];
		if (a[i] > max)max = a[i];
		if (a[i] < min)min = a[i];
	}
	cout << min << " " << max << endl;
	return 0;
}


Measured memory_bytes: 3108
#include<iostream>
using namespace std;
#define int long long int
int function(int weight[],int value[],int initial,int final,int W,int memo[][100001])
{
	if(initial>final)
	  return 0;
	if(memo[initial][W]!=-1)
	  return memo[initial][W];
	else
	{
		if(W>=weight[initial])
		{
			int x=value[initial]+function(weight,value,initial+1,final,W-weight[initial],memo);
			int y=function(weight,value,initial+1,final,W,memo);
			memo[initial][W]=max(x,y);
			return memo[initial][W];
		}
		else
		{
			int x=function(weight,value,initial+1,final,W,memo);
			memo[initial][W]=x;
			return memo[initial][W];
		}
	}
}
main()
{
     int n,w;
	 scanf("%lld%lld",&n,&w);
	 int memo[n+1][100001];
	 int i,j;
	 for(i=0;i<=n;i++)
	 {
	 	for(j=0;j<=100000;j++)
	 	{
	 		memo[i][j]=-1;
		}
	}
	int weight[n],value[n];
	for(j=0;j<n;j++)
	{
		scanf("%lld%lld",&weight[j],&value[j]);
	 } 
	int answer=function(weight,value,0,n-1,w,memo);
	printf("%lld\n",answer);
}

Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define maxn 100005
struct Node
{
    int t;
    int x;
    int y;
};
Node node[maxn];
int n;
int main()
{
    int flag=1;
    node[0].t=node[0].x=node[0].y=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>node[i].t>>node[i].x>>node[i].y;
    for(int i=1;i<=n;i++)
    {
        int tt=fabs(node[i].x-node[i-1].x)+fabs(node[i].y-node[i-1].y);
        int t=node[i].t-node[i-1].t;
        //cout<<tt<<" "<<t<<endl;
        if(t<tt)
            flag=0;
        else
        {
            int x=tt%2;
            int y=t%2;
            //cout<<x<<" "<<y<<endl;
            if(x!=y)
                flag=0;
        }
    }
    if(!flag)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll a, b, c;
    cin >> a >> b >> c;

    double det = ( c - (a+b) ) * ( c - (a+b) ) - 4 * a * b;

    if(det > 0 && (c-(a+b)>0)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int i, a;
	char S[4];
	scanf("%s", S);
	a = 0;
	for (i = 0; i < 4; i++) {
		if (S[i] == S[i + 1]) {
			a = a + 1;
		}
	}
	if (a > 0) {
		printf("Bad");
	}
	else {
		printf("Good");
	}

	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
A = list(map(int, input().split()))

l = 1
r = max(A)
while l != r:
    mid = (r + l) // 2
    count = 0
    for log in A:
        count += (log - 1) // mid
    if count <= K:
        r = mid
    else:
        l = mid + 1

print(r)


Measured memory_bytes: 103972
#include <iostream>

using namespace std;

int main () {
   int N;
   cin>>N;
   bool x = false;
   for(int i=1;i<=9;++i)
   {
       for(int j=1;j<=9;++j){
           int y=i*j;
           if (y==N)
                   x=true;
       }
   }
   if (x)
           cout<<"Yes";
   else
   cout<<"No";

   return 0;}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <cassert>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-9;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9 + 7;
const LL MAX = 3e5;

char is[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	FOR(i, 0, MAX)
		is[i] = 1;
	FOR(i, 2, MAX)
		if (is[i])
			for(LL j = i*1LL*i; j < MAX; j += i)
				is[j] = 0;

	int n;
	cin >> n;
	VI a;
	for (int i = 6; i < MAX; i += 5)
	{
		if (SZ(a) == n)
			break;
		if (is[i])
			a.push_back(i);
	}

	for (auto i : a)
		cout << i << " ";

	cin >> n;
	return 0;
}

Measured memory_bytes: 512