akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    mint ans_n = 0;
    rep(i, n){
        ans_n += (mint)i*(mint)(n-i);
    }
    ans_n *= (mint)m * (mint)m;

    mint ans_m = 0;
    rep(i, m){
        ans_m += (mint)i*(mint)(m-i);
    }
    ans_m *= (mint)n * (mint)n;

    mint ans = ans_n + ans_m;
    combination c(n*m);
    ans *= c((n*m -2), (k-2));

    cout << ans.x << endl;
}




Measured memory_bytes: 3328
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static int gcd(int a, int b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        //forl(n, array, sc);
        int n1, n2;
        int array[] = new int[n];
        for (int i = 0; i < m; i++) {
            n1 = sc.nextInt();
            n2 = sc.nextInt();
            array[n1 - 1]++;
            array[n2 - 1]++;
        }
        for (int c : array) {
            System.out.println(c);
        }
        bw.flush();
    }

    public static void forl(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }
}


Measured memory_bytes: 21844
# nCr的にn//2に近いほうがいいに決まっている
# まあnCrは計算しなくていい

n = int(input())
arr = sorted(list(map(int, input().split())))


def lower_bound(arr, t):
    l, r = 0, len(arr)
    while l < r:
        mid = (l + r) // 2
        if arr[mid] < t:
            l = mid + 1
        else:
            r = mid
    return l


lb = lower_bound(arr[:-2], round(arr[-1] / 2))
lb_left = max(0, lb - 1)
if abs(round(arr[-1] / 2) - arr[lb]) >= abs(round(arr[-1] / 2) - arr[lb_left]):
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])


Measured memory_bytes: 62832
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] argv) throws IOException {
        //*
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        int[] lines = new int[Integer.parseInt(in.readLine())];
        for (int i = 0; i < lines.length; i++) {
            lines[i] = i + 1;
        }

        int count = 1;
        count = Integer.parseInt(in.readLine());

        while (count-- > 0) {
            String[] s = in.readLine().split(",");
            swap(lines, Integer.parseInt(s[0]) - 1, Integer.parseInt(s[1]) - 1);
        }
        for (int i : lines) {
            System.out.println(i);
        }
        //*/
    }

    private static void swap(int[] lines, int a, int b) {
        int temp = lines[a];
        lines[a] = lines[b];
        lines[b] = temp;
    }
}

Measured memory_bytes: 9200
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int[] W = new int[N+1];
		for(int i = 0;i < N;i++) {
			W[i+1]  = W[i] + scn.nextInt();
		}
		int ans = Integer.MAX_VALUE;
		for(int i = 1;i < N;i++) {
			int S1 = W[i];
			int S2 = W[N]-W[i];
			ans = Math.min(Math.abs(S1-S2), ans);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21588
D, N = map(int, input().split())

if D == 0:
  if N != 100:
    print(N)
  else:
    print(101)
elif D == 1:
  if N != 100:
    print(N * 100)
  else:
    print(10100)
else:
  if N != 100:
    print(N*10000)
  else:
    print(1010000)

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

long long N, A[200009], minx = (1LL << 60);

long long sum(long long l, long long r) { return A[r] - A[l - 1]; }

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) { cin >> A[i]; A[i] += A[i - 1]; }
	for (int i = 1; i <= N - 1; i++) {
		long long v1 = A[i], v2 = A[N] - A[i];
		int pos1 = lower_bound(A, A + N, v1 / 2) - A;
		int pos2 = lower_bound(A, A + N, v1 + (v2 / 2)) - A;
		for (int j = pos1 - 1; j <= pos1; j++) {
			for (int k = pos2 - 1; k <= pos2; k++) {
				long long a[4] = { sum(1,j),sum(j + 1,i),sum(i + 1,k),sum(k + 1,N) };
				sort(a, a + 4);
				minx = min(minx, a[3] - a[0]);
			}
		}
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    H,W=pin()
    if H>1 and W>1:
        print((H*W+1)//2)
    else:
        print(1)
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4 5"""
        output = """10"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """7 3"""
        output = """11"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1000000000 1000000000"""
        output = """500000000000000000"""
        self.assertIO(input, output)
if __name__=="__main__":resolve()

Measured memory_bytes: 51568
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;

signed main()
{
    fast;
    int n,k;
    cin>>n>>k;
    int c = 0;
    while ( n != 0 )
    {
        n /= k;
        c++;
    }

    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
import math


def prime(n):
    p = list(range(n+1))
    p[1] = 0

    for x in p:
        if x == 0:
            continue
        if x > math.sqrt(n):
            break
        for y in range(2 * x, n+1, x):
            p[y] = 0

    return [x for x in p if x != 0]


n = int(input())

p = prime(n)
a = [1] * len(p)

for i in range(1, n+1):
    for j in range(len(p)):
        while i % p[j] == 0:
            a[j] += 1
            i //= p[j]

ans = 1

for x in a:
    ans = ans * x % (10**9+7)

print(ans)


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var H, N int
	fmt.Scan(&H, &N)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}

	sum := 0
	for _, v := range A {
		sum += v
	}
	if H-sum > 0 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


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

int main() {
    
    int n,c = 0;
    cin >> n;
    int data[n];
    
    for(int i=0;i<n;i++) data[i] = i+1;
    
    for(int i=0;i<n;i++){
        int a_i;
        cin >> a_i;
        if(data[i] != a_i) c++;
    }
    
    if(c == 0 || c == 2){
        cout << "YES" <<endl;
    }
    else{
        cout << "NO" <<endl;
    }
}

Measured memory_bytes: 3600
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: i32 = sc.read();
    let m: i32 = sc.read();
    if (n - m).abs() > 1 {
        println!("0");
    } else {
        let mut fact: Vec<i64> = vec![1; 100001];
        for i in 1..fact.len() {
            let j: i64 = i as i64;
            fact[i] = (fact[i - 1] * j) % (MOD as i64)
        }
        let mut ans = (fact[n as usize] * fact[m as usize]) % (MOD as i64);
        if n == m {
            ans = (ans * 2) % (MOD as i64);
        }
        println!("{}", ans);
    }
}

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

using namespace std;

int main()
{
    int n,a[200005],b[200005];
    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a,a + n);
    int mx1 = a[n - 1],mx2 = a[n - 2];
    for(int i = 0 ; i < n ; i ++){
        if(b[i] == mx1){
            cout << mx2 << endl;
        }
        else{
            cout << mx1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define N int(1e6+10)
#define fi first
#define si second
#define pb push_back
using namespace std; 
int spf[N];
int m[N];
vector<int>cm;
void sieve() 
{ 
	spf[1] = 1; 
	for (int i=2; i<N; i++) 
		spf[i] = i; 
		
	for (int i=4; i<N; i+=2) 
		spf[i] = 2; 

	for (int i=3; i*i<N; i++) 
	{ 
		if (spf[i] == i) 
		{ 
			for (int j=i*i; j<N; j+=i) 
				if (spf[j]==j) 
					spf[j] = i; 
		} 
	} 
} 

int main() 
{
	int n;
	cin>>n;
	int a[n],g=0;
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	sieve();
	for(int i=0,x;i<n;i++){
		x=a[i];
		g=__gcd(g,a[i]);
		while(x>1){
			m[spf[x]]++;
			x/=spf[x];
		}
	}
	bool first=true;
	for(int i=0,x;i<n&&first;i++){
		x=a[i];
		while(x>1){
			cm.pb(spf[x]);
			m[spf[x]]--;
			x/=spf[x];
		}
		for(int i=0;i<cm.size();i++)
			if(m[cm[i]]){
				first=false;
			}
		for(int i=0;i<cm.size();i++)
			m[cm[i]]++;
		cm.clear();
	}
	if(first){
		printf("pairwise coprime\n");
	}else if(g==1){
		printf("setwise coprime\n");
	}else
		printf("not coprime\n");
	return 0;
} 

Measured memory_bytes: 15344
/*
  author:@bhaskar_8998
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef vector<i64> vi;
typedef pair<int,int>ii;
typedef vector<ii> vii;
typedef map<int,int> mi;
#define all(A) (A).begin(),(A).end()
#define pb push_back
#define MOD 1000000007
#define ff first
#define ss second
#define deb(x) cerr<<#x<<" "<<x<<"\n";
#define fastio() {ios_base::sync_with_stdio(false);cin.tie(NULL);}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    fastio();
    clock_t beg=clock();
    int t=1;
    // cin>>t;
    while(t--){
      i64 n;
      cin>>n;
      i64 x=n/1000;
      if(x*1000==n){
        cout<<"0";
        return 0;
      }
      cout<<(x+1)*1000-n;
        
    }
    clock_t end=clock(); 
    fprintf(stderr, "\n%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}


  

Measured memory_bytes: 3776
n = gets.to_i
x = []

n.times{
    x.push([0, -1, 0, "root", []])
}

n.times{
    id, num, *c = gets.split.map(&:to_i)
    if num > 0 then
        c.each{|l|
            x[l][1] = id
        }
        x[id][4] = c
        x[id][3] = "internal node"
    else
        x[id][3] = "leaf"
    end
    x[id][0] = id
}

def checkdepth(x, k, d)
     if k[1] == -1 then
        return d
     else
        checkdepth(x, x[k[1]], d+1)
     end
end

x.each{|k|
    k[2] = checkdepth(x, k, 0)
}

x.each{|k|
    if k[1] == -1 then
        k[3] = "root"
    end
    printf("node %d: parent = %d, depth = %d, %s, %s\n", k[0], k[1], k[2], k[3], k[4])
}



Measured memory_bytes: 48284
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

	string t;
	cin >> t;

	if ((s[0] == t[2]) && (s[1] == t[1]) && (s[2] == t[0])) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = input()
S = []
for i in range(len(s)):
    S.append(s[i])

check = []
for i in S:
    if i == 'x':
        continue
    else:
        check.append(i)

if check == check[::-1]:
    # 先頭の文字と最後の文字が一致しているかを調べ一致していれば、除く、一致していなければ、xを加える
    first = 0
    last = len(S) - 1
    count = 0
    while first < last:
        if S[first] != S[last] and S[first] == 'x':
            count += 1
            first += 1
            continue
        elif S[first] != S[last] and S[last] == 'x':
            count += 1
            last -= 1
            continue
        else:
            first += 1
            last -= 1
            continue
    print(count)

else:
    print(-1)


Measured memory_bytes: 11160
N, Q = map(int, input().split())
s = input()
T = []
D = []
for _ in range(Q):
	t, d = input().split()
	T.append(t)
	D.append(d)


ans = 0
left = 0
right = N-1
for i in range(Q-1,-1,-1):
	if D[i] == 'R':
		if T[i] == s[right]:
			right -= 1
			if right == 0:
				print(0)
				exit()
		if left > 0 and s[left-1]==T[i]:
			left -= 1

	else:
		if T[i] == s[left]:
			left += 1
			if left == N-1:
				print(0)
				exit()
		if right < N-1 and s[right+1]==T[i]:
			right += 1
	# print(s[left:right+1])
print(max(0,right-left+1))


Measured memory_bytes: 6680
s = input()
t = input()

num_s = len(s)
num_t = len(t)
ans = len(t)

# Tの各位置において、Sの文字数のうち何個一致しているのか、全数チェック。
# > O(T*S)＞　10**6オーダー

for i in range(num_s):
    end = i + num_t
    if (end > num_s):
        break
    tar_s = s[i:end]
    # print(tar_s)

    count = 0
    for a, b in zip(tar_s, t):
        if (a != b):
            #print('add', a)
            count += 1

    ans = min(ans, count)


print(ans)


Measured memory_bytes: 9032
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path; ll pre = 0;
int main() {
	string S;
	cin >> S;
	vl alpha(26);
	N = S.length();
	for (i = 0; i < N; i++) {
		alpha[S[i]-'a']++;
	}
	for (i = 0; i < 26; i++) {
		if (alpha[i] == 0) {
			char X = 'a' + i;
			cout << X;
			exit(0);
		}
	}
	cout << "None";
}

Measured memory_bytes: 512
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { fill(arr.begin(), arr.end(), v); }
//template<typename Type> inline void sort(Type& arr, bool order = true){ sort(arr.begin(), arr.end(), order ? less<>() : greater<>()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, K;
    cin >> N >> K;
    double total = 0.0;
    rep(i, N)
    {
        ll s = i + 1;
        double p = 1.0/double(N);
        while (s < K)
        {
            s *= 2;
            p /= 2.0;
        }
        total += p;
    }
    outD(total);
    //
    return 0;
}

Measured memory_bytes: 3216
def main():
    import sys
    input = sys.stdin.readline
    import itertools
    
    one = [0,1]
    
    N,M = map(int,input().split())
    
    XYZ = [list(map(int,input().split())) for i in range(N)]
    
    ans = 0
    
    for i in list(itertools.product(one, repeat=3)):
        tmp = []
        for j in range(N):
            aji = 0
            for k in range(3):
                aji += XYZ[j][k]*(-1)**(i[k])
            tmp.append(aji)
        tmp = sorted(tmp)[::-1]
        tmpans = 0
        for i in range(M):
            tmpans += tmp[i]
        if tmpans > ans:
            ans = tmpans
    print(ans)
    
    
    
    
main()

Measured memory_bytes: 39536
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  string a;
  cin >> a;

  int n = a.length();

  int count = 0;
  int d[n + 1];
  d[n] = 1;
  int s = 0;
  for(int i = n - 1; i >= 0; i--){
    s |= 1 << (a[i] - 'a');
    if(s == ((1 << 26) - 1)){
      ++count;
      s = 0;
    }
    d[i] = count + 1;
  }

  vector< vector< int > > p(26);
  for(int i = 0; i < n; i++){
    p[a[i] - 'a'].push_back(i);
  }
  for(int i = 0; i < 26; i++){
    sort(p[i].begin(), p[i].end());
  }

  string ans;
  int t = 0;
  while(count >= 0){
    if(count == 0){
      for(char c = 'a'; c <= 'z'; c++){
        auto i = lower_bound(
            p[c - 'a'].begin(), p[c - 'a'].end(), t);
        if(i == p[c - 'a'].end()){
          ans.push_back(c);
          break;
        }
      }
      break;
    }
    for(char c = 'a'; c <= 'z'; c++){
      auto i = lower_bound(
          p[c - 'a'].begin(), p[c - 'a'].end(), t);
      if(i == p[c - 'a'].end()) continue;
      if(d[t] - 1 == d[*i + 1]){
        ans.push_back(c);
        t = *i + 1;
        --count;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(4);
  for (int i=0; i < n; i++){
    string s;
    cin >> s;
    if (s == "AC") a.at(0) ++;
    else if (s== "WA") a.at(1) ++;
    else if (s== "TLE") a.at(2) ++;
    else if (s== "RE") a.at(3) ++;
  }
  cout << "AC x " << a.at(0) << endl;
  cout << "WA x " << a.at(1) << endl;
  cout << "TLE x " << a.at(2) << endl;
  cout << "RE x " << a.at(3) << endl;
}

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

int main() {
  char s;
  cin>>s;
  
  if(s=='a'||s=='e'||s=='i'||s=='o'||s=='u'){
   cout<<"vowel"<<endl;
  }else{
  cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define INF_LL 1000000000000000000LL
#define INF 200000000
#define MOD 998244353
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

int main() {
    int n, d;
    cin >> n >> d;
    vector<P> x(n);
    rep(i, n) cin >> x[i].first >> x[i].second;
    two_sat ts(n);
    rep(i, n) REP(j, i + 1, n) {
        if(abs(x[i].first - x[j].first) < d)
            ts.add_clause(i, false, j, false);
        if(abs(x[i].first - x[j].second) < d)
            ts.add_clause(i, false, j, true);
        if(abs(x[i].second - x[j].first) < d)
            ts.add_clause(i, true, j, false);
        if(abs(x[i].second - x[j].second) < d)
            ts.add_clause(i, true, j, true);
    }
    if(ts.satisfiable()) {
        cout << "Yes" << endl;
        vector<bool> ans = ts.answer();
        rep(i, n) {
            if(ans[i]) {
                cout << x[i].first << endl;
            } else {
                cout << x[i].second << endl;
            }
        }
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3768
//A smoothe sea never made a skilled sailor.
//KEEP IT SIMPLE STUPID
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define print(o) for(auto it=(o).begin();it!=(o).end();it++) cout<<*it<<" ";
#define vll vector<ll>
#define pb push_back
#define FOR(n) for(ll i=0;i<n;i++)
#define FORr(a,b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll c=0,f=0,s[2]={a,b};
    c+=(n/(a+b))*a;
    n=n%(a+b);
    while(n>=s[f])
    {
        n-=s[f];
        if(f==0)
        {
            c+=s[f];
        }
        f++;
    }
    if(f==0)
    {
        c+=n;
    }
    cout<<c;
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

    ll N;
    cin >> N;

    vector<ll> cnt(N, 0);
    ll T = 0, tmp, D = 998244353;
    bool flag = true;

    cin >> tmp;

    if (tmp != 0) {
        flag = false;
    }

    rep(i, N - 1) {
        cin >> tmp;
        if (tmp == 0) flag = false;        
        T = max(T, tmp);
        cnt[tmp]++;
    }

    ll ans = 1;

    if (flag) {
        repl(i, 2, T + 1) {
            rep(j, cnt[i]) {
                ans *= cnt[i - 1];
                if (ans > D) ans %= D;
            }
        }
    }
    else {
        ans = 0;
    }

    cout << ans;

}



ll gcd(ll a, ll b) {
    if (a % b == 0)return(b);
    else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

Measured memory_bytes: 4040
/*
    https://atcoder.jp/contests/abc124/tasks/abc124_c
    C - Coloring Colorfully
*/
#include <bits/stdc++.h>
using namespace std;

void solve(string s) {
    int even = 0, odd = 0;
    for (size_t i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s.at(i) != '0')
                even++;
            else
                odd++;
        } else {
            if (s.at(i) != '1')
                even++;
            else
                odd++;
        }
    }
    // cout << "even, odd = " << even << ", " << odd << endl;
    cout << min(even, odd) << endl;
}

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

    string s;
    cin >> s;
    solve(s);
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int h1,h2,k1,k2,a,b,c,d,x,y;
	x=0;
	y=0;
	scanf("%d %d",&h1,&h2);
	scanf("%d %d",&k1,&k2);
	scanf("%d %d %d %d",&a,&b,&c,&d);
	x=h1*a+h2*b;
	y=k1*a+k2*b;
	if(h1>=10){
		h1/=10;
		x+=h1*c;
	}
	if(h2>=20){
		h2/=20;
		x+=h2*d;
	}
	if(k1>=10){
		k1/=10;
		y+=k1*c;
	}
	if(k2>=20){
		k2/=20;
		y+=k2*d;
	}
	if(x>y){
		printf("hiroshi\n");
	}
	else if(x<y){
		printf("kenjiro\n");
	}
	else{
		printf("even\n");
	}
	return 0;
}



Measured memory_bytes: 2132
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	s := make([]string, N)
	si := make([]int, 1)
	j := 0
	max := 1
	si[0] = 1
	for i := 0; i < N; i++ {
		s[i] = nextLine()
	}
	sort.Strings(s)
	for i := 1; i < N; i++ {
		if s[i] == s[i-1] {
			si[j]++
		} else if j == 0 {
			j++
			si = append(si, 1)
		} else {
			j++
			si = append(si, 1)
		}
		if max < si[j] {
			max = si[j]
		}
	}
	// fmt.Println(max)
	// fmt.Println(s)
	// fmt.Println(si)
	m := 0
	for i := 0; i < len(si); i++ {
		if len(si) == 1 {
			fmt.Println(s[0])
			return
		}
		if si[i] == max {
			fmt.Println(s[m])
		}
		m += si[i]
	}
}

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

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


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N,M;
    Scd2(N,M);

    vector< vector<int> > e(N);

    int a,b;
    Rep(i,M){
        Scd2(a,b);
        a--,b--;
        e[a].push_back(b);
    }

    vector< vector<int> > d(N, vector<int>(3,INF) );

    Scd2(a,b);
        a--,b--;
    d[a][0] = 0;

    using pii = pair<int,int>;
    deque<pii> s;

    s.push_back( pii(a,0) );


    while( !s.empty() ){
        int from = s.front().first;
        int dep = s.front().second;
        // printf ("%d\n", d[from][dep%3] );
        s.pop_front();

        for( int to : e[from] ){
            if( dep + 1 < d[to][(dep+1)%3]  ){
                s.push_back( pii(to,dep+1) );
                d[to][(dep+1)%3] = dep+1;
            }
        }
    }

    printf ("%d\n", d[b][0] == INF ? -1 : d[b][0] / 3 );



    return 0;
}



Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int a, b, c;
  cin >> a >> b >> c;
  cout << max(0, c-(a-b)) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}


char li[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

char bin_six(string bin){
    reverse(bin.begin(),bin.end());
    int tmp = 0;
    for(int i = 0; i < 4; i++){
        if(bin[i] == '1'){
            tmp += pow(2,i);
        }
    }
    return li[int(tmp)];
}

int main() {
	int n,r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;;
    }else{
        cout << r + 100*(10-n) << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}



int main(){
  int n,m;
  cin>>n;
  string s1[n];
  for(int i = 0; i < n; i++){
    cin>>s1[i];
  }
  cin>>m;
  string s2[m];
  for(int i = 0; i < m; i++){
    cin>>s2[i];
  }
  int ans  = 0;
  for(int i = 0; i < n; i++){
    int buf=1;
    for(int j = i+1; j < n; j++){
      if(s1[i]==s1[j]) buf++;
    }
    for(int j = 0; j < m; j++){
      if(s1[i]==s2[j]) buf--;
    }
    ans = max(ans,buf);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int a,b;
    cin>>a>>b;
    if(a < b){
        cout<<"a < b"<<endl;
    }
    else if(a > b){
        cout<<"a > b"<<endl;
    }
    else if(a == b){
        cout<<"a == b"<<endl;
    }
}
    


Measured memory_bytes: 3096
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long N, long long M, std::vector<long long> H, std::vector<long long> A, std::vector<long long> B){
    vll isGood(N, 1);
    vector<vll> G(N);
    REP(i, M){
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    REP(u, N){
        for(auto v: G[u]){
            if(H[u] <= H[v]) {isGood[u] = 0; break;}
        }
    }
    ll ans = 0;
    REP(i, N){
        if(isGood[i]) ans++;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        A[i] --;
        B[i] --;
    }
    solve(N, M, std::move(H), std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 11856
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/random.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;
namespace rnd = boost::random;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> D;

  invec<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));
  for (auto&& i : s)
    for (auto&& j : i)
      cin >> j;
  vector<int> t, highest(D);
  ll high = -9999999999, cost = 0;
  rnd::mt19937 mt;
  rnd::uniform_int_distribution rnd_plan(1, 26);
  rnd::uniform_real_distribution<> dist2(0.0, 1.0);

  REP(i, 26) {
    cost += c[i];
  }

  const int tier = cost;
  const int ITER = 1077721600 / D;
  highest[0] = 1;
  for (int i : bst::irange(1, (int)D))
    highest[i] = rnd_plan(mt);
  t = move(highest);
  long double temp = 1.0;
  const long double temp_down = pow(0.2, 1.0 / (double)ITER);
  
  REP(loop, ITER) {
    int r = 0;
    int last[26] = {0};
    
    const int update = loop % D;
    const int told = t[update];
    t[update] = rnd_plan(mt);
    
    REP(i, D) {
      const int plan = t[i] - 1;
      r += s[i][plan];
      cost -= c[plan] * (i + 1 - last[plan]);
      last[plan] = i + 1;
      r -= cost;
      cost += tier;
    }
    
    if (r > high) {
      high = r;
      highest = t;
    }
    else if (dist2(mt) > exp((double)(r - high) / 128.0 / temp))
      t[update] = told;
    cost = tier;
    temp *= temp_down;
  }
  
  for (auto i : highest)
    cout << i << endl;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}




Measured memory_bytes: 4184
N=int(input())
for n in range(N):
    gx,gy=map(int,input().split())
    T=[[0 for i in range(gy+1)] for j in range(gx+1)]
    left=[[0 for i in range(gy+1)] for j in range(gx+1)]
    upper=[[0 for i in range(gy+1)] for j in range(gx+1)]
    p=int(input())
    for i in range(p):
        x1,y1,x2,y2=map(int,input().split())
        if x1==x2:
            upper[x1][max(y1,y2)]=1
        if y1==y2:
            left[max(x1,x2)][y1]=1
    for i in range(gx+1):
        for j in range(gy+1):
            if i==0 and j==0:
                T[i][j]=1
            elif upper[i][j]==1 and left[i][j]==1:
                T[i][j]=0
            elif (upper[i][j]==1 or left[i][j]==1) and (i==0 or j==0):
                T[i][j]=0
            elif i==0:
                T[i][j]=T[i][j-1]
            elif j==0:
                T[i][j]=T[i-1][j] 
            elif upper[i][j]==1:
                T[i][j]=T[i-1][j]
            elif left[i][j]==1:
                T[i][j]=T[i][j-1]
            else:
                T[i][j]=T[i-1][j]+T[i][j-1]
    if T[gx][gy]==0:
        print("Miserable Hokusai!")
    else:
        print(T[gx][gy])


Measured memory_bytes: 5624
#include <iostream>
#include <list>

int main() {
  int num,bag,sum;
	
  while(std::cin >> num >> bag){
	
    if(num!=0 && bag!=0){
      std::list<int>  beg;
      for(int i=0;i<num;++i){
	int price;
	std::cin >> price;
	beg.push_back(price);
      }
      beg.sort(std::greater<int>());
      sum=0;
	        
      for(int i=1;beg.empty()!=true;i++){	   
        if(i%bag != 0){
          sum+=beg.front();
        }	
        beg.pop_front();
      }
      std::cout << sum << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 100005;


ll solve(int n, string s)
{
    vector<int> red;
    vector<int> green;
    vector<bool> blue(n, false);
    int bluect = 0;
    for(int i=0; i<n; i++)
    {
        if(s[i] == 'R')
            red.push_back(i);
        else if(s[i] == 'G')
            green.push_back(i);
        else
        {
            blue[i] = true;
            bluect++;
        }
    }
    ll ans = red.size()*green.size()*bluect;
    for(auto &r: red)
    {
        for(auto &g: green)
        {
            if((r+g)%2 == 0 && blue[(r+g)/2])
            {
                ans--;
            }
            if(2*r - g>=0 && 2*r - g <n && blue[2*r-g])
            {
                ans--;
            }
            {
            if(2*g - r>=0 && 2*g - r <n && blue[2*g-r])
                ans--;
            }
        }
    }
    return ans;
    
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    cout<<solve(n,s);
	return 0;
}

Measured memory_bytes: 3688
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    VV dp(m+1,V((1<<n)+1,INF));
    V vec1(m);
    V vec2(m); 
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        vec1[i]=a;
        rep(j,b){
            ll c;cin>>c;c--;
            vec2[i]+=(1<<c);
        }
    }
    dp[0][0]=0;
    rep(i,m){
        rep(j,(1<<n)){
            chmin(dp[i+1][j|vec2[i]],dp[i][j]+vec1[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    if(dp[m][(1<<n)-1]==INF){
        cout<<-1<<endl;
        return 0;
    }
    cout<<dp[m][(1<<n)-1]<<endl;
}

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

using ll = long long;

int main() {
    int X, Y;
    cin >> X >> Y;
    if (X == 1 && Y == 1) {
        cout << 1000000 << endl;
        return 0;
    }
    int ans = 0;
    rep(i, 3) {
        if (X == i + 1) ans += (3 - i) * 100000;
        if (Y == i + 1) ans += (3 - i) * 100000;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
stones = list(input())
l = 0
r = N-1
count = 0

while(True):
  while(stones[l] == "R" and l < N-1):
    l += 1
  while(stones[r] == "W" and r > 0):
    r -= 1
  if (l >= r):
    print(count)
    exit()
  else:
    count += 1
    l += 1
    r -= 1

Measured memory_bytes: 82696
/*0429??????????????§??£?§£???
 * 12??????????????????????¢???? ????????°??????????????????????????????????????????????????????????´???°????????????int ????????§????????????.?????????maxvalue???memory?¶??????????????????????
 * 
 * Created by SharpDevelop.
 * User: yog-sothoth
 * Date: 2017/04/23
 * Time: 17:25
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System.Collections.Generic;
using System;
using System.IO;

namespace Dictionary
{
	
	public class DictionaryList
	{
		
		
		public static void Main(string[] args)
		{		
			int num = int.Parse(Console.ReadLine());// the number of instructions
			
			
			byte[] table = new byte[68000000];
		
			var sw = new StreamWriter(Console.OpenStandardOutput())
	    	{ AutoFlush = false };
			
			Console.SetOut(sw);
			
			for (int i = 0; i < num; i++) {
				string iands = Console.ReadLine();//instruction and s tring
				string[] instAndStr = iands.Split();
			
				
				//Add list instAndStr[1]		
				if (instAndStr[0] == "insert") {//??????????????\???
					//??????????????°????????????????????????table[index]???????????°??????????????????????????¨????????????????????§????????????
					//????????°???????????????
					int index = 0;
					for (int j = 0; j < instAndStr[1].Length; j++) {
			
						index *= 4;
				
						switch (instAndStr[1][j]) {
							case 'A':
								index += 1;
								break;
							case 'C':
						
								index += 2;
						
								break;
							case 'G':
						
								index += 3;
								break;
							case 'T':
						
								index += 4;
								break;			
						}
						
		
					}
					table[index]=1;
		
					
				} else { //?????????find
					
					
					int index = 0;
					for (int k = 0; k < instAndStr[1].Length; k++) {
			
						index *= 4;
				
						switch (instAndStr[1][k]) {
							case 'A':
								index += 1;
								break;
							case 'C':
						
								index += 2;
						
								break;
							case 'G':
						
								index += 3;
								break;
							case 'T':
						
								index += 4;
								break;			
						}
						
		
					}
					if(table[index]!=1)
					{
						Console.WriteLine("no");
					}else
						Console.WriteLine("yes");
				}
				
			}
			Console.Out.Flush();
		}
		
	}
}

Measured memory_bytes: 117576
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

if N==K:
    print(1)
else:
    a=-(-(N-1)//(K-1))
    print(a)

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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


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

  vector<int> v(N);
  for(int i = 0; i < N; i++) {
    cin >> v.at(i);
  }

  int cnt = 0;
  int flag = false;
  while(1) {
    for(int i = 0; i < N; i++) {
      if(v.at(i) % 2 == 1) {
        flag = true;
        break;
      }
      v.at(i) /= 2;
    }
    if(flag) break;
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}


Measured memory_bytes: 256