akhauriyash/Code-Regression huggingface dataset:
import sys

def main():
    while True:
        M,T,P,R = map(int,input().split())
        if not M and not T and not P and not R:
            return
        prob = [[0]*(P+1) for _ in range(T+1)]
        result = dict([(t,[0,sys.maxsize]) for t in range(1,T+1)]) # (t,m,p)
        for _ in range(R):
            m,t,p,j = map(int,input().split())
            if j == 0:
                result[t][0] += prob[t][p] + m
                result[t][1] += 1
            else:
                prob[t][p] += 20
        result = list(result.items())
        result = sorted(result, key=lambda x: (-1*x[1][1], x[1][0], -1*x[0]))

        print(result[0][0], end="")
        for i in range(1,T):
            if result[i][1][0] == result[i-1][1][0] and result[i][1][1] == result[i-1][1][1]:
                print("={}".format(result[i][0]), end="")
            else:
                print(",{}".format(result[i][0]), end="")
        print()

if __name__ == '__main__':
    main()


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

int n, a, b;
vector<int> p;
int cnt[4] = {0};

int main() {
  cin >> n >> a >> b;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    p.push_back(x);
  }
  sort(p.begin(), p.end());
  for(int i = 0; i < n; ++i) {
    if(p[i] <= a)
      ++cnt[0];
    else if(p[i] <= b)
      ++cnt[1];
    else
      ++cnt[2];
  }
  cout << min(cnt[0], min(cnt[1], cnt[2])) << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

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


#define mp make_pair
#define f first
#define s second
#define ll long long
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
 
using namespace std;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 2e9+7, mod=1e9+7;
const int N = 3e5+134, N1=1e7+134;

ll xx[8]={1, 1, -1, -1, 1, -1, 0, 0};
ll yy[8]={1, -1, 1, -1, 0, 0, 1, -1};

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	string s;
	cin >> s;
	if(s[2]==s[3] && s[4]==s[5])
		cout << "Yes";
	else
		cout <<"No";
		
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a, b;
        a = scanner.nextInt();
        b = scanner.nextInt();
        if(b % a == 0){
            System.out.println(a + b);
        }
        else{
            System.out.println(b - a);
        }
    }
}

Measured memory_bytes: 21972
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
  int n, m;
  std::cin >> n >> m;
  std::cout << (n - 1) * (m - 1) << std::endl;
}


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

int main()
{
  int N;
  int a[110000];
  int x[110000];
  int res=0;
  cin >> N;

  rep(i,N) cin >> a[i];
  rep(i,100001) x[i]=0;

  rep(i,N){
    x[a[i]]++;
  }

  FOR(i,0,100000){
    if(i==0) res=x[i]+x[i+1];
    else if(i==100000) res=max(res, x[i-1]+x[i]);
    else res=max(res,x[i-1]+x[i]+x[i+1]);
  }

  cout << res << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
    https://atcoder.jp/contests/abc109/tasks/abc109_c
*/
//=================================================
int N, X;
vector<int> x;
//=================================================
void input()
{
    cin >> N >> X;
    x = vector<int>(N);
    rep(i, N) cin >> x[i];
}
//=================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void solve()
{
    sort(x.begin(), x.end());

    vector<int> diffs;

    for (int i = 0; i < N; ++i)
    {
        diffs.push_back(abs(X - x[i]));
    }

    sort(diffs.begin(), diffs.end());
    int ans = INF;
    ans = diffs[0];
    for (int i = 0; i < N - 1; ++i)
    {
        ans = min(ans, gcd(diffs[i], diffs[i + 1]));
    }

    cout << ans << endl;
}
//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>
#include <stdlib.h>
int stack[10000];
int sp=0;
void push(int x){
  stack[sp++]=x;
}
int pop(){
  return stack[--sp];
}
int main(){
  char s[15];
  int i,j;
  int x;
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      push(pop()+pop());
    }
    else if(s[0]=='-'){
      x=pop();
      push(pop()-x);
    }
    else if(s[0]=='*'){
      push(pop()*pop());
    }
    else if(s[0]=='/'){
      x=pop();
      push(pop()/x);
    }
    else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  return 0;
}

Measured memory_bytes: 548
#include <cstdio>
#include <iostream>
#include <cstring>
#define poi(lx,ly,rx,ry) ((lx>rx||ly>ry)?0:(ice[rx][ry] + ice[lx-1][ly-1] - ice[rx][ly-1] - ice[lx-1][ry]))
int n, m, hx, hy;
int ice[41][41], ans=2147483647, f[41][41][41][41];
char tmp;
using std::min;
using std::cin;
signed main() {
	register int i, j, o, p, s, t;
	cin >> n >> m;
	memset(f, 0x7f, sizeof(f));
	f[1][1][n][m] = 0;
	for ( i = 1; i <= n; ++ i )
		for ( j = 1; j <= m; ++ j ) {
			cin >> tmp;
			if (tmp == 'P')
				hx = i, hy = j;
			ice[i][j] = ice[i-1][j] + ice[i][j-1] - ice[i-1][j-1] + (tmp == '#');
		}
	for ( i = 1; i <= hx; ++ i )
	for ( j = 1; j <= hy; ++ j )
	for ( o = n; o >= hx; -- o )
	for ( p = m; p >= hy; -- p ) {
		ans = min(ans, f[i][j][o][p]+min(min(poi(i,j,hx,hy),poi(i,hy,hx,p)),min(poi(hx,j,o,hy),poi(hx,hy,o,p))));
		for ( s = i; s <= o; ++ s )
		for ( t = j; t <= p; ++ t ) {
			if (hx<=s&&hy<=t)
				f[i][j][s][t]=min(f[i][j][s][t],f[i][j][o][p]+poi(i,t+1,s,p)+poi(s+1,j,o,t));
			if (hx<=s&&hy>=t)
				f[i][t][s][p]=min(f[i][t][s][p],f[i][j][o][p]+poi(i,j,s,t-1)+poi(s+1,t,o,p));
			if (hx>=s&&hy>=t)
				f[s][t][o][p]=min(f[s][t][o][p],f[i][j][o][p]+poi(i,t,s-1,p)+poi(s,j,o,t-1));
			if (hx>=s&&hy<=t)
				f[s][j][o][t]=min(f[s][j][o][t],f[i][j][o][p]+poi(i,j,s-1,t)+poi(s,t+1,o,p));
		}
	}
	std::cout << ans;
	return 0;
}

Measured memory_bytes: 11392
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Policy;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        int y = 0;
        int c = 0;

        while (true) {
            y += n;
            y %= 360;
            c++;
            if(y == 0) break;
        }

        return c;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        if(n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 27388
// 2020-07-27 01:18:54
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  map<int, int> mp;
  rep(i, n) mp[i+1+a[i]]++;
  ll ans = 0;
  rep(i, n) ans += mp[i+1-a[i]];
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 20904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll a,ll b)
{
    if (!a)
        return -b;
    return b/a * 2 * a + solve(b % a,a);
}
int main()
{
    ll n,x;
    cin >> n >> x;   
    cout << n + solve(x,n-x) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  int a,b;
  string s,t;
  string u;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s==u){
    cout << a-1 <<" "<< b;
  }else{
    cout << a << " " <<b-1;
  }
  return 0;
  
}

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

using namespace std;

struct Node{
	int key;
	Node *prev, *next;
};

Node *nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key){
	Node *cur = nil->next;
	while (cur != nil&&cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if (t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

int main(){
	int n,key;
	char com[20];
	scanf("%d", &n);
        init();
	for (int i = 0; i < n; i++){
		scanf("%s %d", com, &key);
		if (com[0] == 'i'){
			insert(key);

		}
		else if (com[0] == 'd'){
			if (strlen(com)>6){
				if (com[6] == 'F')deleteFirst();
				else if (com[6] == 'L')deleteLast();
			}
			else{
				deleteKey(key);
			}
		}
	}
	Node *cur = nil->next;
	int isf = 0;
	while (1){
		if (cur == nil)break;
		if (isf++ > 0)printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

Measured memory_bytes: 34348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_171
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            int val = 0;
            for(int i = 0; i < n; i++)
            {
                val ^= array[i];
            }

            for(int i = 0; i < n; i++)
            {
                Write(val^array[i]);
                if (i + 1 < n)
                {
                    Write(' ');
                }
            }
            WriteLine();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 53208
import numpy as np


N, K = map(int, input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N, 10 ** 10)

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    ik = max(0, i - K)
    dp[i] = np.min(dp[ik:i] + np.abs(h[i] - h[ik:i]))

print(int(dp[-1]))



Measured memory_bytes: 23092
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pair<ll, int>> v;
	vector<ll> a(n), b(n);
	ll sum = 0;
	rep(i,n){
		cin >> a[i] >> b[i];
		sum += a[i] + b[i];
		v.emplace_back(a[i]+b[i], i);
	}
	sort(v.rbegin(), v.rend());
	ll tak = 0, aok = 0;
	rep(i,n){
		if(i%2 == 0) tak += a[v[i].second];
		else aok += b[v[i].second];
	}
	ll ans = tak - aok;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3956
package main

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

func solve() {
	n, r := getInt(), getInt()
	ans := r
	if n < 10 {
		ans += 100 * (10 - n)
	}
	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] a_asArgs)
        {
			int l_iN = int.Parse(Console.ReadLine());
			int[] l_aiDX = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
			int[] l_aiA = new int[l_iN];
			for (int l_iBuf = 0; l_iBuf < l_aiA.Length; l_iBuf++)
			{
				l_aiA[l_iBuf] = int.Parse(Console.ReadLine());
			}
			int l_iCount = 0;
			for (int l_iD = 0; l_iD < l_aiDX[0]; l_iD++)
			{
				for (int l_iBuf = 0; l_iBuf < l_aiA.Length; l_iBuf++)
				{
					if (l_iD % l_aiA[l_iBuf] == 0)
					{
						l_iCount++;
					}
				}
			}
			Console.WriteLine(l_iCount + l_aiDX[1]);
		}
	}
}


Measured memory_bytes: 13396
def xor_battle(N, A, S):
    bit = [0] * 64
    # 後ろから、上位のbitから見ていく
    for i in reversed(range(N)):
        Ai, Si = A[i], S[i]
        while Ai:
            n = Ai.bit_length() -1
            if bit[n] == 0 and Si == '1':
                return 1 # 防げないbit
            elif bit[n] == 0 and Si == '0':
                bit[n] = Ai # 防げられるbit
                break
            Ai ^= bit[n]
    return 0

def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    T = int(input())

    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()[:-1]
        print(xor_battle(N, A, S))

main()

Measured memory_bytes: 9112
L = 8
table = [["11", "11"], ["1", "1", "1", "1"], ["1111"], ["01", "11", "10"],
         ["110", "011"], ["10", "11", "01"], ["011", "110"]]
table.map! {|pt| [pt.size, l = pt.first.length, pt.join("0" * (L - l))]}

$<.readlines.chunk {|l| !!l.match(/^\d/) || nil}
     .map {|a| a.last.map {|l| l.chomp}.join}.each do |field|
  table.each_with_index do |ary, k|
    y, n, pt = ary
    (L + 1 - y).times do |i|
      (L + 1 - n).times do |j|
        puts "ABCDEFG"[k] if field[i * L + j, pt.length] == pt
      end
    end
  end
end


Measured memory_bytes: 6972
fn main() {
    let (n, max_w) = read_tuple();
    let items = read_vec2::<u64>(n as u32);
    let mut dp: Vec<Vec<u64>> = Vec::new();
    for _ in 0..n+1 {
        let v = vec![0; max_w + 1];
        dp.push(v);
    }

    for i in 1..n+1 {
        for w in 0..max_w+1 {
            let cur_w = items[i-1][0];
            let cur_v = items[i-1][1];
            if w >= (cur_w as usize) {
                let v = dp[i-1][w-(cur_w as usize)] + cur_v;
                chmax(&mut dp[i][w], v);
            }
            let v = dp[i-1][w];
            chmax(&mut dp[i][w], v);
        }
    }
    println!("{}", dp[n][max_w]);
}

fn chmax(a: &mut u64, b: u64) {
    if *a < b {
        *a = b;
    }
}

fn read_tuple() -> (usize, usize) {
    let v = read_vec::<usize>();
    (v[0], v[1])
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}


Measured memory_bytes: 106876
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll gcd(ll m, ll n){
  ll m1 = m, n1 = n;
  ll tmp;

  while(n1 != 0){
    tmp = n1;
    n1 = m1 % n1;
    m1 = tmp;
  }

  return m1;
}

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

  ll C = gcd(A, B);
  ll sqC = (ll)sqrt(C) + 1;

  vl tab(sqC + 1, 1);
  vl divC = {1};
  tab[0] = tab[1] = 0;
  rep2(i, 2, sqC){
    if(tab[i] == 0) continue;

    if(C % i == 0){
      divC.push_back(i);

      while(C % i == 0) C /= i;
    }

    ll j = 2*i;
    while(j <= sqC){
      tab[j] = 0;
      j += i;
    }
  }

  if(C > 1) divC.push_back(C);

  cout << divC.size() << endl;
  
  return 0;
}


Measured memory_bytes: 8064
import math

cycles = []
for i in range(5):
    cycles.append(int(input()))

minimum_last_order_cycle = None
for cycle in cycles:
    if minimum_last_order_cycle is None and cycle % 10 > 0:
        minimum_last_order_cycle = cycle
    elif minimum_last_order_cycle is not None and cycle % 10 < minimum_last_order_cycle % 10 and cycle % 10 > 0:
        minimum_last_order_cycle = cycle

if minimum_last_order_cycle is None:
    minimum_last_order_cycle = cycles[0]

cycles.remove(minimum_last_order_cycle)

time = 0
for cycle in cycles:
    time += math.ceil(cycle / 10) * 10

time += minimum_last_order_cycle

print(time)


Measured memory_bytes: 3060
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

LL solve(LL h, LL w) {
	if (h % 3 == 0 || w % 3 == 0) return 0;

	LL ans = INF;
	for (int i = 1; i <= h; i++) {
		LL a = i * w;
		LL b = ((h * w - a) % 2 == 0 ? (h * w - a) / 2 : (h - i) * (w / 2));
		LL c = h * w - a - b;
		LL sMax = max(a, max(b, c));
		LL sMin = min(a, min(b, c));
		ans = min(ans, sMax - sMin);
	}

	for (int i = 1; i <= w; i++) {
		LL a = i * h;
		LL b = ((h * w - a) % 2 == 0 ? (h * w - a) / 2 : (w - i) * (h / 2));
		LL c = h * w - a - b;
		LL sMax = max(a, max(b, c));
		LL sMin = min(a, min(b, c));
		ans = min(ans, sMax - sMin);
	}
	return ans;
}

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

	LL h, w;
	cin >> h >> w;

	cout << solve(h, w) << endl;
	return 0;
}

Measured memory_bytes: 256
/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    int N;
    cin >> N;
    cout << (N - 2) * 180 << endl;
     
    return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include <bits/stdc++.h>
#define ll long long
#define read(x) scanf("%d",&x)
using namespace std;
const int maxn = 2e5 + 10;

char s[100+10];

int main()
{   
	cin>>s+1;
	int len = strlen(s+1);
	for(int i=1;i<=len;i++){
		if((s[i]=='R'&&i%2==0)||(s[i]=='L'&&i%2==1)) 
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string.h>

typedef long long ll;
using namespace std;

int main(){
	int n,a=0,b=0;
	cin >> n;
	for(int i=1;i<=n;i+=2){
		for(int j=1;j<i;j+=2){
			if(i%j==0){
				a++;
			}
		}
		if(a==7){
			b++;
		}
		a=0;
	}
	cout << b << endl;
  return 0;
}



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

ll N, X;

ll layer_sum(ll n) {
    return (ll)pow(2, n) + (ll)pow(2, n) * 3 - 3;
}

ll patty_sum(ll n) {
    return (ll)pow(2, n+1) - 1;
}

ll patty_cnt(ll n, ll x) {
    if (n == 0) return 1; 
    else if (x == 1) return 0;
    else if (1 < x && x < layer_sum(n-1) + 2) {
        return patty_cnt(n-1, x-1);
    }
    else if (x == layer_sum(n-1) + 2) {
        return patty_sum(n-1) + 1;
    }
    else if (layer_sum(n-1) + 2 < x && x < layer_sum(n)) {
        return patty_sum(n-1) + 1 + patty_cnt(n-1, x-2-layer_sum(n-1));
    }
    else return patty_sum(n);
}

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

    cout << patty_cnt(N, X) << endl;    
    
    return 0;
}


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

int main()
{    int n,m,i,j,a,b,c;
    while(~scanf("%d %d %d",&a,&b,&c))
    {
        if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <iostream>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

	int n;
	cin >> n;
	while(n)
	{
		if(n%10 == 7)
		{
			cout << "Yes";
			return 0;
		}
		n/=10;
	}
	cout << "No";



    return 0;
}

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

int main(){
   bool b=false;

   int sz,cnt;
   cnt=0;
   string s1,s2;
   cin>>s1>>s2;
   sz=s1.size();
   for(int i=0;i<sz;i++){
        if(s1==s2){
            b=true;
            break;
        }
        s1=s1.back()+s1.substr(0,s1.size()-1);
   }
   if(b)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, x, count = 0;
  cin >> A >> B;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        x = i * 10001 + j * 1010 + k * 100;
        if (x >= A && x <= B)
          count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3592
from collections import deque
n = int(input())
grap = [[]]
for i in range(n):
    u,k,*v = map(int,input().split())
    grap.append(v)

dis = [-1]*(n+1)
dis[0] = 0
dis[1] = 0

d = deque()
d.append(1)
while d:
    v = d.popleft()
    for i in grap[v]:
        if dis[i] != -1:
            continue
        dis[i] = dis[v] + 1
        d.append(i)

for i in range(1,n+1):
    print(i,dis[i])



Measured memory_bytes: 6024
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n, k);
	vector< int > x(n), y(n);
	REP(i, n) {
		cin >> x[i] >> y[i];
	}

	vector< int > sorted_x(x), sorted_y(y);
	sort(ALL(sorted_x));
	sort(ALL(sorted_y));

	int ans = (sorted_y.back() - sorted_y[0]) * (sorted_x.back() - sorted_x[0]);
	REP(xi, n) {
		REP(yi, n) {
			FOR(xj, xi, n) {
				FOR(yj, yi, n) {
					
					int cnt = 0;
					REP(i, n) {
						if (sorted_y[yi] <= y[i] && y[i] <= sorted_y[yj] &&
								sorted_x[xi] <= x[i] && x[i] <= sorted_x[xj]) {
							cnt++;
						}
					}
					if (cnt >= k) ans = min(ans, (sorted_y[yj] - sorted_y[yi]) * (sorted_x[xj] - sorted_x[xi]));
					
				}
			}
		}
	}
	OUT(ans)BR;
  
  return 0;
}


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

using namespace std;
typedef pair<int, int> P;

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

    int sum_all = 0, sum, lev = 0;
    stack<int> st;
    stack<P> stP;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '\\')
            st.push(i);
        else if (s[i] == '/') {
            if (st.empty()) continue;
            int j = st.top(); st.pop();

            sum_all += i - j;
            sum = i - j;
            while (stP.size() > 0 && j < stP.top().first) {
                sum += stP.top().second;
                stP.pop();
            }
            stP.push(P(j, sum));
        }
    }

    vector<int> v;
    while (stP.size()) {
        v.push_back(stP.top().second);
        stP.pop();
    }
    reverse(v.begin(), v.end());


    cout << sum_all << endl;
    cout << v.size();
    for (int  i = 0; i < v.size(); i++)
        cout << " " << v[i];
    cout << endl;

    return 0;
}



Measured memory_bytes: 3252
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
// typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

typedef tuple<string, int, int> T;
int main() {
    int N,M; cin >> N >> M;
    int k[11];
    int s[11][11];
    int p[11];
    rep(i,M){
        cin >> k[i];
        rep(j,k[i]){
            cin >> s[i][j];
        }
    }

    rep(i,M){
        cin >> p[i];
    }
    int ans=0;
    for(int i=0; i<(1<<N); i++){
        int num=0;
        for(int j=0; j<M; j++){
            int on=0;
            for(int l=0; l<k[j]; l++){
                if( (i>>(s[j][l]-1)) & 1 ){
                    on++;
                }
            }

            if(on%2==p[j]){
                num++;
            }
        }

        if(num==M){
            ans++;
        }
    }


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


Measured memory_bytes: 256
#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) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using point = complex<double>;

constexpr double eps = 1e-8;

// 円の交点
vector<point> kouten(point p, double s, point q, double t) {
  double d = abs(p - q);
  if (d >= s + t - eps) return {};
  double theta = acos((s * s + d * d - t * t) / (2 * s * d));
  point e = (q - p) / abs(q - p);
  point res1 = p + e * polar(s, theta);
  point res2 = p + e * polar(s, -theta);
  return {res1, res2};
}

int main() {
  int N, K; cin >> N >> K;
  vector<double> X(N), Y(N), C(N);
  rep(i, N) cin >> X[i] >> Y[i] >> C[i];
  double l = 0;
  double r = 1e7;
  rep(ii, 100) {
    double m = (l + r) / 2;
    int mx = 0;
    vector<point> cand;
    rep(i, N) cand.push_back(point(X[i], Y[i]));
    rep(i, N) rep(j, i) {
      for (point p : kouten(point(X[i], Y[i]), m / C[i], point(X[j], Y[j]), m / C[j])) {
        cand.push_back(p);
      }
    }
    for (point p : cand) {
      int cnt = 0;
      rep(i, N) {
        point q(X[i], Y[i]);
        if (abs(p - q) <= m / C[i] + eps) {
          cnt++;
        }
      }
      mx = max(mx, cnt);
    }
    if (mx >= K) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << fixed << setprecision(15) << l << endl;
}

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

long long sum(int n){
    if(n==1) return 1;
    if(n==2) return 2;

    return n*sum(n-1);
      }
    
    int main(){
        int n;
        cin>>n;
        cout<<sum(n)<<endl; 
        
        return 0;
    }

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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[ ";
    for (auto a : v) os << a << " ";
    os << "]";
    return os;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> L(N + 1), R(N + 1);
    R[0] = N;
    REP(i, N) {
        L[i + 1] = L[i] + (i + 1);
        R[i + 1] = R[i] + (N - i - 1);
    }

    ll mod = 1e9 + 7;
    ll ans = 0;
    FOR(k, K, N + 1) ans = (ans + (R[k - 1] - L[k - 1] + 1)) % mod;

    // cout << L << endl;
    // cout << R << endl;
    cout << ans << endl;
    return 0;
}

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

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

    int count = 0;
    int record = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            count += 1;
        }else{
            record = max(record, count);
            count = 0;
        }
    }
    record = max(record, count);
    cout << record << endl;
    return 0;
}

Measured memory_bytes: 256
def mx(inp,w,h):
	if h <= c/2:
		if w == 0: inp[h][w] += inp[h-1][w]
		elif w == len(inp[h])-1: inp[h][w] += inp[h-1][w-1]
		else: inp[h][w] += max(inp[h-1][w],inp[h-1][w-1])
	else:
		inp[h][w] += max(inp[h-1][w],inp[h-1][w+1])
	return inp

c = 0
inp = []
while True:
	try:
		inp.append(map(int, raw_input().split(",")))
		c += 1
	except:
		break
	
for h in range(1,c):
	for w in range(len(inp[h])):
		inp = mx(inp,w,h)
print inp[c-1][0]

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

//　基本方針は安い順に並び替えて総当りだが、この問題ではstd::pairを使うことが重要。
//  以下が自分で途中まで書いた奴

/* int main(){
    int N,M;
    cin >> N >> M ;
    long long int A,B;
    vector<long long int> Ai(N+1);
    vector<long long int> Bi(N+1);

    for(int i = 0;i < N;i++){ // 配列化 O(N)
        cin >> Ai[i] >> Bi[i] ;
    }

    sort(Ai.begin(),Ai.last());

} */

//　ここで問題になるのは、sortでAiを昇順にしても、その商品の個数を知れないという点である。
//  これをpairで解決する。

//  pairは pair<int,int> のように型、型を宣言する。
//  そんで、これをint とかと同じようにぶち込めばおｋ
//  vector<pair<int,string>> ???(N); てな感じ

//  細かい使い方は良く分からんけど、とりあえず配列の中に2つのデータを保管できると考えればいい。
//  Classの定義とかでもいいんだけど、pairの便利なところは定義がいらないのと、sortが各キーに対して使えることらしい
//  基本的にpairのsortはfirstとsecondがそれぞれ昇順になるっぽい。
//  つまり、(1,2),(1,6),(2,5),(2,7),(5,5)とかそんな感じ。

int main(){
    int N;
    long long M;
    cin >> N >> M;
    vector<pair<long long ,long long>> v(N);
    
    for (int i = 0;i < N;i++) cin >> v[i].first >> v[i].second;

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

    long long res = 0;
    for(int i = 0; i < N && M > 0;i++){
        res += v[i].first * min(M,v[i].second);
        M -= min(M, v[i].second);

    }
    cout << res << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner
 
object Primes {
  val primes = new Array[Int](1001)
  for(i <- 2 to 1000){
    var flag = true
    for(k <- 2 to i-1)
      if(i % k == 0)
        flag = false
    primes(i) = 1
  }
}
 
object Main extends App{
  import Primes._
 
  val MOD = 1e9.toInt + 7
 
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
 
  for(k <- 2 to n){
    var rest = k
    for(i <- 2 to 1000) {
      if(primes(i) > 0){
        while(rest % i == 0){
          rest /= i
          primes(i) += 1
        }
      }
    }
  }
 
  var ans = 1L
  for(i <- 2 to 1000) {
    if(primes(i) > 1) {
      ans *= primes(i)
      ans %= MOD
    }
  }
 
  println(ans)
}

Measured memory_bytes: 26948
#include <cstdio>
#include <array>
#include <utility>

template <unsigned int N> struct myprimes {
    unsigned int minPrime[N + 1];
    unsigned int Primes[N + 1];
    unsigned int size_;

    constexpr myprimes(void): minPrime(), Primes(), size_(0U) {
        minPrime[0] = 1; minPrime[1] = 1;
        for (int even = 2, odd = 3; odd <= N; even += 2, odd += 2) {
            minPrime[even] = 2;
            minPrime[odd] = odd;
        }

        if (!(N & 1))
            minPrime[N] = 2;

        Primes[size_++] = 2;

        for (int x = 3; x <= N; x += 2) {
            if (minPrime[x] == x)
                Primes[size_++] = x;
            for (int y = 0; y < size_ and Primes[y] <= minPrime[x] and x * Primes[y] <= N; ++y)
                    minPrime[x * Primes[y]] = Primes[y];
        }
    }

    // 範囲for文用の begin() と end()
    const unsigned int *begin(void) const noexcept {
        return Primes;
    }

    const unsigned int *end(void) const noexcept {
        return Primes + size_;
    }

    const unsigned int size(void) const {
        return this.size_;
    }
};

using uint = unsigned int;
constexpr uint N = 1e6;
constexpr uint mod = 1e9 + 7;
constexpr uint M = mod - 2;
constexpr myprimes<N> P;
std::array<uint, N + 1> Count;

// a^nを返す関数
const uint power(uint a, uint n)noexcept{
    unsigned long long res = 1, waiting = a;

    while (n) {
        if (n & 1) {
            res *= waiting;
            res %= mod;
        }
        waiting *= waiting; waiting %= mod; 
        n >>= 1;
    }

    return res;
}

uint fastRead(void) {
	char c;

	while (true) {
        c = getchar();
        if('0' <= c and c <= '9')
            break;
	}

    uint res = c - '0';
	while (true) {
		c = getchar();
        if (c < '0' or c > '9')
            break;
		res = 10 * res + (c - '0');
	}

    return res;
}


int main(void) {
    uint n = fastRead();
    uint inv_sum = 0;

    for (uint _ = 0; _ < n; ++_){
        uint a = fastRead();
        inv_sum += power(a, M);

        if(inv_sum >= mod)
            inv_sum -= mod;

        while (a - 1U) {
            uint fac = P.minPrime[a];
            uint cnt = 1; a /= fac;

            while (a % fac == 0)
                a /= fac, cnt++;

            if (Count[fac] < cnt)
                Count[fac] = cnt; 
        }
    }

    unsigned long long int lcm = 1;

    for(unsigned int x : P)
        if(Count[x])
            (lcm *= power(x, Count[x])) %= mod;

    unsigned int res = lcm * inv_sum % mod;
    
    printf("%u\n", res);
    return 0;
}


Measured memory_bytes: 3200
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){
    CIN(n);V a(n);V b(n);VECCIN(a);VECCIN(b);
    int max_=0;
    REP(i,n){
    int cou=0;

        REP(j,n){
            if(i>j)cou+=a[j];
            else if(i==j){cou+=a[j];cou+=b[j];}
            else cou+=b[j];
        }
       max_=max(max_,cou); 
    }
    COUT(max_);



    return 0;
}


Measured memory_bytes: 256
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
import std.numeric;
void main()
{
    immutable n = readln.chomp.to!int;
    auto a = readln.chomp.split.to!(int[]);
    int i = 1;
    a = a.find(i);
    if (a.empty)
        return (-1).writeln;
    while (!a.empty)
    {
        i += 1;
        a = a.find(i);
    }
    (n-i+1).writeln;
}


Measured memory_bytes: 11408
def main():
    n, m = map(int, raw_input().split())
    aa = [None] * n
    for _ in xrange(m):
        s, c = raw_input().split()
        s = int(s) - 1
        if aa[s] is not None and aa[s] != c:
            print '-1'
            return
        aa[s] = c
    if n == 1:
        if aa[0] is None:
            print 0
        else:
            print aa[0]
        return
    if aa[0] is None:
        aa[0] = '1'
    for i, a in enumerate(aa):
        if a is None:
            aa[i] = '0'
    if aa[0] == '0':
        print -1
    else:
        print ''.join(aa)

main()


Measured memory_bytes: 28396
n=int(input())
a=list(map(int,input().split()))
b=sorted(list(set(a)))
print("Yes"if (len(b)==3 and len(list(set([a.count(i)for i in b])))==1and b[0]^b[1]==b[2])or (len(b)==2 and a.count(0)==n//3 and n%3==0) or(len(b)==1 and b[0]==0)else"No")

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

const int MAX_N = 1e5 + 5;
int N, M, X[MAX_N];
vector<int> seg;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N >> M;
    for(int i=0;i<M;i++) cin >> X[i];

    int sum = 0;
    if(N>=M) {cout << 0 << endl; return 0;}
    sort(X, X+M);
    for(int i=1;i<M;i++) {seg.push_back(X[i]-X[i-1]); sum += X[i]-X[i-1];}

    sort(seg.begin(), seg.end()); reverse(seg.begin(), seg.end());
    for(int i=0;i<N-1;i++) sum -= seg[i];

    cout << sum << endl;
    return 0;
}


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

using namespace std;

const int N = 200001;
int cnt[N];
int n;

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

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

    for(int i = 1; i <= n; i++)
        cout << cnt[i] << "\n";

    return 0;
}


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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n;
  string s;
  cin >> n >> s;
  
  rep(i,0,s.size()){
    ll m = s.at(i) - 'A';
    m = (m+n)%26;
    s.at(i) = 'A' +m;
  }
  
 
  
  cout << s << endl;
}

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

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  string s;
  int n;
  cin >> s;
  n = s.size();
  if (s[n-1] == '3'){
    cout << "bon\n";
    return 0;
  }
  if (s[n-1] == '0' || s[n-1] == '1' || s[n-1] == '6' || s[n-1] == '8'){
    cout << "pon\n";
    return 0;
  }
  cout << "hon\n";
  return 0;
}

Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X  =sc.nextInt();
        int Y  =sc.nextInt();
        int Z  =sc.nextInt();
        int K  =sc.nextInt();

        long[] x = new long[X];
        for (int i = 0; i <X ; i++) x[i]=sc.nextLong();
        long[] y = new long[Y];
        for (int i = 0; i <Y ; i++) y[i]=sc.nextLong();
        long[] z = new long[Z];
        for (int i = 0; i <Z ; i++) z[i]=sc.nextLong();

        long[] xy = new long[X*Y];
        int idx = 0;
        for (int i = 0; i < X ; i++) {
            for (int j = 0; j < Y ; j++) {
                xy[idx++] = x[i] + y[j];
            }
        }

        Arrays.sort(xy);
        int loop1 =Math.min(K,xy.length);
        long[] xyz = new long[loop1*Z];
        idx=0;
        for (int i = xy.length-1; i >= xy.length-loop1 ; i--) {
            for (int j = 0; j < Z ; j++) {
                xyz[idx++] = xy[i] + z[j];
            }
        }

        Arrays.sort(xyz);

        for (int i = 0; i < K; i++) {

            System.out.println(xyz[xyz.length-1-i]);

        }
    }

}


Measured memory_bytes: 62192
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

int n;
multiset <int> st;
vector <int> r[222], b[222];

int main() {
    scanf("%d", &n);
    FOR(i, 1, n) {
        int x, y;   scanf("%d%d", &x, &y);
        r[x].push_back(y);
    }
    FOR(i, 1, n) {
        int x, y; scanf("%d%d", &x, &y);
        b[x].push_back(y);
    }
    int cnt = 0;
    REP(x, 222) {
        for (int y : b[x]) {
            auto it = st.lower_bound(y);
            if (it != st.begin()) {
                it--; st.erase(it);
                cnt++;
            }
        }
        for (int y : r[x]) st.insert(y);
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256