akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
int main(){
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    rep(x, k+1) rep(y, k+1)
    {
        if (0<=s-x-y&&s-x-y<=k)
            cnt++;
    }
    cout << cnt << endl;
}


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

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < 16; j++) {
            if (4 * i + 7 * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
s=int(input())
l=[s]
ans=[]
for i in range(10**5):
    if s%2==0:
        s=s/2
        l.append(s)
    else:
        s=s*3+1
        l.append(s)
        
for i in range(10**3):
    for j in range(i+1,10**3):
        if l[i]==l[j]:
            ans.append(j)
print(min(ans)+1)

Measured memory_bytes: 12488
import sys
import re
import queue
import collections
import math
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def gcd_list(numbers):
    return reduce(gcd, numbers)

def main():
	N = i_input()
	A = i_list()

	d = dict()

	max_A = max(A)
	count_list = []

	MAXN = 10**6+10
	sieve = [i for i in range(MAXN+1)]
	p = 2
	while p*p <= MAXN:
		if sieve[p] == p:
			for q in range(2*p,MAXN+1,p):
				if sieve[q] == q:
					sieve[q] = p
		p += 1


	for i in range(0,max(A)):
		count_list.append(0)

	for a in A:
		tmp = set()
		while a > 1:
			tmp.add(sieve[a])
			a //= sieve[a]

		for p in tmp:
			count_list[p-1] += 1


	if (max(count_list)<=1):
		print("pairwise coprime")
	elif(gcd_list(A)==1):
		print("setwise coprime")
	else:
		print("not coprime")

	return

if __name__ == '__main__':
	main()

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

using namespace std;

int main()
{
    string s;
    int n;
    cin >> n;
    
    cin >> s;
    
    for (int i=0; i<s.size(); i++){
        s[i] = ((s[i] - 'A') + n)%26 + 'A';
    }
    
    cout << s << endl;
    

    return 0;
}


Measured memory_bytes: 256
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int n, k, ans;
  std::cin >> n >> k;
  ans = 1;
  while (true) {
    if (n / k == 0) break;
    else n = n / k;
    ans++;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

mod rolling_hash {
    const MASK30: u64 = (1 << 30) - 1;
    const MASK31: u64 = (1 << 31) - 1;
    const MOD: u64 = (1 << 61) - 1;
    const MASK61: u64 = (1 << 61) - 1;
    const POSITIVIZER: u64 = MOD * 4;
    const BASE: u64 = 1_000_000_000 + 9;
    pub struct RollingHash {
        h: Vec<u64>,
        p: Vec<u64>,
    }
    impl RollingHash {
        pub fn new(s: &[u64]) -> Self {
            let n = s.len();
            let mut h = vec![0; n + 1];
            let mut p = vec![0; n + 1];
            p[0] = 1;
            for i in 0..n {
                h[i + 1] = calc_mod(mul(h[i], BASE) + s[i]);
                p[i + 1] = mul(p[i], BASE);
            }
            Self { h, p }
        }
        pub fn get(&self, range: std::ops::Range<usize>) -> u64 {
            let l = range.start;
            let r = range.end;
            calc_mod(self.h[r] + POSITIVIZER - mul(self.h[l], self.p[r - l]))
        }
    }
    fn mul(a: u64, b: u64) -> u64 {
        let au = a >> 31;
        let ad = a & MASK31;
        let bu = b >> 31;
        let bd = b & MASK31;
        let mid = ad * bu + au * bd;
        let midu = mid >> 30;
        let midd = mid & MASK30;
        au * bu * 2 + midu + (midd << 31) + ad * bd
    }
    fn calc_mod(x: u64) -> u64 {
        let xu = x >> 61;
        let xd = x & MASK61;
        let mut res = xu + xd;
        if res >= MOD {
            res -= MOD;
        }
        res
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    use rolling_hash::RollingHash;

    let n: usize = rd.get();
    let s: String = rd.get();
    let t = s.chars().map(|c| c as u64).collect::<Vec<_>>();
    let rh = RollingHash::new(&t);
    let mut ans = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            let mut ok = 0;
            let mut ng = std::cmp::min(j - i, n - j) + 1;
            while ng - ok > 1 {
                let m = (ng + ok) / 2;
                if rh.get(i..(i + m)) == rh.get(j..(j + m)) {
                    ok = m;
                } else {
                    ng = m;
                }
            }
            ans = std::cmp::max(ans, ok);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2288
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    A = I()
    B = I()
    ans = {1: True, 2:True, 3:True}
    ans[A] = False
    ans[B] = False

    for i in ans.keys():
        if ans[i] is True:
            print(i)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 66156
#include <iostream>
#include <string>

int main() {
    using namespace std;
    string str;
    cin >> str;

    for(int i=0; i<str.size(); ++i) {
        if(str[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [int(e) for e in input().split()]

def colors(score):
    if score < 400:
        return 1
    elif score < 800:
        return 2
    elif score < 1200:
        return 3
    elif score < 1600:
        return 4
    elif score < 2000:
        return 5
    elif score < 2400:
        return 6
    elif score < 2800:
        return 7
    elif score < 3200:
        return 8
    elif score >= 3200:
        return 0

ary = [colors(s) for s in a]
ary_n = set(ary)

if not 0 in ary_n:
    n_min = len(ary_n)
    n_max = len(ary_n)
else:
    n_zero = sum([e == 0 for e in ary])
    n_min = len(ary_n) - 1 if len(ary_n) > 1 else 1
    n_max = len(ary_n) + n_zero - 1

print(n_min, n_max)


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main() {
    long long price;
    cin >> price;
    long long p500 = price / 500;
    price %= 500;
    long long p5 = price / 5;
    cout << p500 * 1000 + p5 * 5 << endl;
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B, C;
    cin >> A >> B;

    cout << max({A+B, A-B, A*B}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct V {
	int c;
	int n;
	
};

bool operator < (const V& l, const V& r) {
	if (l.n > r.n) return true;
	if (l.n == r.n && l.c > r.c) return true;
	return false;
}

struct R {
	int i;
	int c;
};

V   ans[301][301] = { 0 };

struct P {
	int i;
};

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

	int n, m, l; cin >> n >> m >> l;

	unordered_multimap <int, R> road;

	FOR_LE(i, 1, n) {
		FOR_LE(j, 1, n) {
			ans[i][j].n = INT_MAX / 10;
		}
	}

	FOR_LT(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		if (c > l) continue;

		road.insert({ a, { b, c } });
		road.insert({ b, { a,c } });
	}

	FOR_LE(p, 1, n) {
		using P = pair<int, V>;
		auto comp = [](P & l, P & r) {
			return r.second < l.second;
		};

		priority_queue<P, vector<P>, decltype(comp)> search(comp);
		search.push({ p, { l, 0} });
		ans[p][p] = { l, 0 };

		//cout << p << endl;

		while (!search.empty()) {
			auto c = search.top();
			search.pop();
			//cout << "search : " << c << endl;

			if (ans[p][c.first] < c.second) continue;

			V cv = ans[p][c.first];

			auto it = road.find(c.first);
			while (it != road.end() && it->first == c.first) {
				V nv = cv;
				if (nv.c < it->second.c) {
					nv.n++;
					nv.c = l;
				}
				nv.c -= it->second.c;


				V& v2 = ans[p][it->second.i];

				//cout << it->first << " " << it->second.i << " " << nv.c << " " << nv.n << " " << v2.c << " " << v2.n << endl;
				if ((nv.n < v2.n) || (nv.n == v2.n && nv.c > v2.c)) {
					ans[p][it->second.i] = nv;
					search.push({ it->second.i, nv });
				}
				it++;
			}
		}
	}

	int q; cin >> q;
	FOR_LT(i, 0, q) {
		int s, t;  cin >> s >> t;
		if (ans[s][t].n == INT_MAX / 10) {
			cout << -1 << endl;
		}
		else {
			cout << ans[s][t].n << endl;
		}
	}

	return 0;
}

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

const int N = 1e6 + 100;

int mod = 1e9 + 7;


int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int started = 0;
    int ans = 1;
    for(int i = 1; i <= n; i++) {
        ans = 1ll*ans*i%mod;
    }
    for(int i = 0; i < s.size(); i++) {
        int col = 0;
        if(s[i] == 'B') col = 1;
        col ^= (started&1);
        if(col == 0) {
            if(started == 0) {
                cout << 0 << endl;
                return 0;
            }
            ans = 1ll*ans*started%mod;
            started--;
        }
        else {
            started++;
        }
    }

    if(started) ans = 0;

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 720
#include <stdio.h>

int main(void)
{
  int n;
  int i, j;
  int is_prime[1000000];
  int cnt;

  for (i = 0; i < 1000000; i++){
    is_prime[i] = 1;
  }

  is_prime[0] = 0;
  is_prime[1] = 0;

  for (i = 0; i * i < 1000000; i++){
    if (is_prime[i] == 1){
      for (j = i + i; j < 1000000; j += i){
        is_prime[j] = 0;
      }
    }
  }

  while (scanf("%d", &n)){
    if (n == 0){
      break;
    }

    cnt = 0;

    for (i = 0; i <= n / 2; i++){
      if ((is_prime[i] == 1) && (is_prime[n - i] == 1)) {
        cnt++;
      }
    }

    printf("%d\n", cnt);
  }

  return (0);
}

Measured memory_bytes: 4504
X,Y,Z,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = list(reversed(sorted(A)))
B = list(reversed(sorted(B)))
C = list(reversed(sorted(C)))
abc_list=[]

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1) * (j+1) * (k+1) <= K:
                abc_list.append(A[i] + B[j] +C[k])
            else:
                break

abc_list = list(reversed(sorted(abc_list)))

for i in range(K):
    print(abc_list[i])

Measured memory_bytes: 10000
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(m), d(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}

	int min = 0, p = 0;
	for (int i = 0; i < n; i++) {
		min = 1000000000;
		for (int j = 0; j < m; j++) {
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < min) {
				min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				p = j + 1;
			}
		}
		cout << p << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n, x, y = map(int, input().split())

def f(l, k):
  if l+1 <= k:
    return 0
  else:
    return l-k+1

def g(l, k):
  if l < 2*k:
    return 0
  elif l==2*k:
    return l/2
  else:
    return l

def h(l, m, k):
  M = 0
  for i in range(1, k):
    if  i<=l and k-i >1:
      M += g(m,k-i)*2/m
    elif i<=l:
      M +=1 
  return M
    
A=[n]
for k in range(2, n):
  c=f(n+x-y,k)+g(y-x+1,k)+h(x-1,y-x+1,k)+h(n-y,y-x+1,k)
  A.append(int(c))

for i in range(n-1):
  print(A[i])

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define pb push_back
const int maxn = 1000005;
int u[maxn];
int cur[maxn];
int need[maxn];
vector<pair<int,int> >e;
vector<int>g[maxn];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	while(cin >> n){
		int cont[n+5] = {};
		f(n)cin >> cont[i];
		int cnt = 0;
		f1(n-2){
			if(cont[i]<cont[i+1]&&cont[i]>cont[i-1])cnt++;
			else if(cont[i]>cont[i+1]&&cont[i]<cont[i-1])cnt++;
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 25472
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val W = map(N)(_ => ns())
    var pre: String = null
    val set = mutable.Set[String]()
    val ok = W forall { w =>
      val ok = !(set contains w) && (pre == null || pre.last == w.head)
      pre = w
      set += w
      ok
    }

    out.println(if (ok) "Yes" else "No")
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }
}

Measured memory_bytes: 25540
N, W = list(map(int, input().split()))
Wt, Vt = [], []
for _ in range(N):
    w, v = list(map(int, input().split()))
    Wt.append(w)
    Vt.append(v)


dp = [[0 for i in range(100100)] for _ in range(110)]

for i in range(N):
    for sw in range(W + 1):
        if sw - Wt[i] >= 0:
            dp[i+1][sw] = max(dp[i+1][sw], dp[i][sw-Wt[i]] + Vt[i])
        dp[i+1][sw] = max(dp[i+1][sw], dp[i][sw]) 

print(dp[N][W])

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

#define ll unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    while(t--){
        int n,k;cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        int sum=0;
        for(int i=0;i<k;i++){
            sum+=arr[i];
        }
        cout<<sum;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>
// #include <atcoder/all>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
// using namespace atcoder;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;
// using mint = modint1000000007;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ")
#define print1(v) cout << fixed << setprecision(10) << v << "\n"
#define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n"
#define print3(v1, v2, v3) cout << fixed << setprecision(10) << v1 << " " << v2 << " " << v3 << "\n"
#define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); }
#define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); }

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 500+1;
int n, m, k;
vii train(maxn, vi(maxn));

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

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

    cin >> n >> m >> k;
    REP(i, m) {
        int l, r; cin >> l >> r;
        train[l][r]++;
    }
    FOR(i, 1, n+1) {
        FOR(j, 1, n+1) {
            train[i][j] += train[i][j-1] + train[i-1][j] - train[i-1][j-1];
        }
    }
    REP(i, k) {
        int p, q; cin >> p >> q;
        p--;
        int ret = train[q][q] - train[p][q] - train[q][p] + train[p][p];
        print1(ret);
    }
}

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

int n;
string eventType;
int point;
int outCount;
bool first, second, third;

void hit()
{
	point += third;
	third = second;
	second = first;
	first = true;
}
void homerun()
{
	point++;
	point += first;
	point += second;
	point += third;
	first = false;
	second = false;
	third = false;
}
void out()
{
	outCount++;
}

int main()
{
	cin >> n;
	while (n--)
	{
		point = 0;
		outCount = 0;
		first = false;
		second = false;
		third = false;

		while (true)
		{
			cin >> eventType;
			if (eventType == "HIT") hit();
			if (eventType == "HOMERUN") homerun();
			if (eventType == "OUT") out();

			if (outCount == 3)
			{
				cout << point << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <deque>

using namespace std;

int main() {
    
    int K;
    cin >> K;
    if (K < 10) {
        cout << K;
        return 0;
    }

    deque<size_t> q = {1,2,3,4,5,6,7,8,9};
    for (size_t i = 1; i < K; ++i) {
        size_t x = q.front();
        q.pop_front();
        int s = x % 10;
        if (s != 0) {
            s -= 1;
        }
        int e = x % 10;
        if (x % 10 != 9) {
            e += 1;
        }
        while (s <= e && i < K) {
            q.push_back(x * 10 + s);
            ++s;
        }
    }
    cout << q.front();

    return 0;
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;
  std::vector<int> a(N);
  rep(i, N) {
    std::cin >> a[i];
  }

  int sum = 0;
  rep(i, N) {
    sum ^= a[i];
  }

  rep(i, N) {
    std::cout << (sum ^ a[i]) << ' ';
  }
  std::cout << "" << '\n';
}


Measured memory_bytes: 4032
#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 n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    int a = q.top();
    q.pop();
    q.push(a / 2);
  }
  ll ans = 0;
  rep(i, n) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3932
import Data.List
main = do
  [_,h] <- map read . words <$> getLine :: IO [Int]
  ks <- map (\[a,b] -> (a,b)) . map (map read . words) . lines <$> getContents :: IO [(Int,Int)] 
  let (swa,swb) = maximum $ map (\(a,b) -> (a,negate b)) ks
  let (rest,n) = throw (sortOn negate $ map snd $ filter (\(_,b) -> b >= swa) $ delete (swa,swb) ks) (h,0)
  print $ if rest <= 0 then n else n + ceiling ((fromIntegral rest) / (fromIntegral swa))
  
throw :: [Int] -> (Int,Int) -> (Int,Int)
throw [] (hp,n) = (hp,n)
throw [x] (hp,n) = (hp-x,n+1)
throw (x:xs) (hp,n) 
  | hp - x <= 0 = (hp-x,n+1)
  | otherwise = throw xs (hp-x,n+1)

Measured memory_bytes: 47356
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  VI as(n);
  FOR(a,as) {
    cin >> a;
  }
  cout << (n - 1 + k - 1 - 1) / (k - 1) << endl;
  
  return 0;
}


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
    ll n,m,x;cin>>n>>m>>x;
    vl c(n);vvl a(n,vl(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m)cin>>a[i][j];
    }
    ll MIN=INF;
    rep(bit,1<<n){
        vl ok(m,0);
        ll cost=0;
        rep(i,n){
          if(bit(bit,i)){
              cost+=c[i];
              rep(j,m)ok[j]+=a[i][j];
          }
        }
        bool paf=true;
        rep(i,m){
            if(ok[i]<x)paf=false;
        }
        if(paf)MIN=min(MIN,cost);
    }
    if(MIN>=INF)cout<<-1<<endl;
    else cout<<MIN<<endl;
}

Measured memory_bytes: 3632
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()
X=n1()

x0=bisect_left(X,0)
if x0<n and X[x0]==0:
    k=k-1
    P=X[x0+1:]
    M=X[:x0]
else:
    P=X[x0:]
    M=X[:x0]

if k==0:
    print(0)
else:
    ans1=ans2=ans3=float("inf")
    if len(P)>=k:
        ans1=P[k-1]
    if len(M)>=k:
        ans2=-M[-k]

    for i in range(1,k):
        j=k-i
        if len(P)>=i and len(M)>=j:
            ans3=min(ans3,P[i-1]*2-M[-j],P[i-1]-2*M[-j])
    print(min(ans1,ans2,ans3))

Measured memory_bytes: 14612
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef pair <ld, ld> PLD;
typedef pair <PLD, ld> PLDD;
typedef pair <PLL, ll> PLLL;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;
const ll MOD = 1e9+696969;
const long long INF = (ll)1e18+3;
int n, m, k, a, b, c, DL = 0, CC = 0, T;
#define maxn 200100
vector <int> v[2][maxn];
int d[maxn][2];
int X, Y;

void BFS(int graf, int start) {
	bool sp = 0;
	if (graf == 2) graf = 0, sp = 1;
	queue <int> q;
	while (!q.empty()) q.pop();
	FOR(i, 1, n) d[i][graf] = inf;
	d[start][graf] = 0;
	q.push(start);
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		if (sp && d[x][graf] >= d[x][1]) continue;
		for (auto u : v[graf][x])
		  if (d[u][graf] == inf) {
			  d[u][graf] = d[x][graf] + 1;
			  q.push(u);
		  }
	}
}

map <PII, bool> mapa;

const int D = 1000;
int BIG[maxn];

int main() {
	boost;
	cin >> n >> X >> Y;
	FOR(i, 2, n) {
		cin >> a >> b;
		v[0][a].pb(b);
		v[0][b].pb(a);
	}
	
	FOR(i, 2, n) {
		cin >> a >> b;
		mapa[{a, b}] = 1;
		v[1][a].pb(b);
		v[1][b].pb(a);
	}
	
	FOR(i, 1, n) sort(v[1][i].begin(), v[1][i].end());
	
	int ILE = 0;
	FOR(i, 1, n)
	  if (v[1][i].size() < 400) {
		  for (auto u : v[1][i])
		    for (auto p : v[1][i])
		      if (u != p) mapa[{u, p}] = 1;
	  }
	  else BIG[++ILE] = i;
	  
	FOR(i, 1, n)
	  for (auto u : v[0][i]) {
		  //to sumarycznie robi obrot N petli
		  FOR(cnt, 1, ILE) {
			  int kt = BIG[cnt];
			  if (binary_search(v[1][kt].begin(), v[1][kt].end(), i) &&
				  binary_search(v[1][kt].begin(), v[1][kt].end(), u)) mapa[{i,u}] = 1;
		}
  }
	
	BFS(0, X);
	BFS(1, Y);

	
	 
	BFS(2, X);
	int wynik = 0;
	FOR(i, 1, n)
	  if (d[i][0] < d[i][1]) wynik = max(wynik, 2 * d[i][1]);
	FOR(i, 1, n)
	  for (auto u : v[0][i]) {
		  if (!mapa[{i,u}] && !mapa[{u,i}]) {
			  //jest potencjalnie dobra para
			  if (d[i][0] < d[u][0]) {
				if (d[i][0] < d[i][1]) OUT(-1);
			}
			  else {
				  if (d[u][0] < d[u][1]) OUT(-1);
			  }
		  }
	  }  
	cout << wynik << endl;
}


Measured memory_bytes: 233360
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl x(n);
  rep(i, n) cin >> x[i];
  
  vl y = x;
  sort(all(y));
  ll Med1=y[n/2-1], Med2=y[n/2];
  
  rep(i, n) {
    if(x[i]<=Med1) cout << Med2 << newl;
    else cout << Med1 << newl;
  }
  return 0;
}

Measured memory_bytes: 5376
S = gets.chomp
T = gets.chomp

top = T[0]
s = T.size - 1

min_str = '~'

S.chars.each_cons(T.size).with_index do |list, index|
  sub = list.join

  next unless list.zip(T.chars).all? { |a, b| a == '?' || a == b }

  new_str = if index == 0
              [T, S[(index + T.size)..-1]]
            else
              [S[0..(index - 1)], T, S[(index + T.size)..-1]]
            end.join.gsub('?', 'a')

  min_str = [min_str, new_str].min
end

if min_str == '~'
  puts 'UNRESTORABLE'
else
  puts min_str
end


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

int main() {
  string s;
  cin >> s;
  if (s.at(5) == '1' || s.at(6) > '4') {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String S = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = sc.next();

		for(int i = 0; i < s.length(); i++) {
			int a = S.indexOf(s.charAt(i)) + n;
			if(a >= 26) a -= 26;
			System.out.print(S.charAt(a));
		}
	}
}

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int a,b,c,d;
    cin >>a>>b>>c>>d;

    if(abs(b-a)<=d && abs(c-b)<=d || abs(c-a)<=d){
        flag=true;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << dig(n) << endl;

    if(flag)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}



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

int main(){
  int n,m;
  cin >> n >> m;

  long long ans;
  if(n==2||m==2) ans=0;
  else ans = (long long) max(1,n-2) * max(1,m-2);

  cout << ans << endl;
}

Measured memory_bytes: 256
//ihdignite

#include <bits/stdc++.h>

using namespace std;

bool solve(int n, int a, string sa, string sb, char ca, char cb, int s) {
	int l=0, r=s+1;
	for(int i=n-1; ~i; --i) {
		if(sb[i]==ca)
			r = min(r+1, s+1);
		if(sb[i]==cb)
			l = max(l-1, 0);
		if(sa[i]==ca)
			++l;
		if(sa[i]==cb)
			--r;
		if(l+1>=r)
			return 0;
	}
	return l<a&&a<r;
}

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

	int h, w, n, sr, sc;
	string sa, sb;
	cin >> h >> w >> n >> sr >> sc >> sa >> sb;
	cout << (solve(n, sr, sa, sb, 'U', 'D', h)&&solve(n, sc, sa, sb, 'L', 'R', w)?"YES":"NO");
}

Measured memory_bytes: 1560
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        mp[a]++;
        mp[b]++;
    }
    bool f = true;
    for(auto it = mp.begin(); it != mp.end(); it++){
        if(it -> second % 2) f = false;
    }
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    int N; cin >> N;
    int nom = 0;
    int abmin = 1e9+5;
    ll ans = 0;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        if(a < 0) {
            a *= -1;
            nom++;
        }
        abmin = min(abmin, a);
        ans += a;
    }
    if(nom % 2 != 0) cout << ans - 2*abmin << endl;
    else cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.12Lf\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
#define double long double
typedef pair<double,double> P;

vector<P> v[4];
double solve(double m) {
  double x1=MAXL,y1=MAXL,x2=-MAXL,y2=-MAXL;
  rep(i,4) {
    rep(j,v[i].size()) {
      double x=v[i][j].F+dx[i]*m,y=v[i][j].S+dy[i]*m;
      x1=min(x1,x);
      x2=max(x2,x);
      y1=min(y1,y);
      y2=max(y2,y);
    }
  }
  return (x2-x1)*(y2-y1);
}

void Main() {
  ll n;
  R n;
  rep(i,n) {
    ll x,y;char c;
    cin >> x >> y >> c;
    if(c=='L') v[0].pb(P(x,y));
    if(c=='U') v[1].pb(P(x,y));
    if(c=='R') v[2].pb(P(x,y));
    if(c=='D') v[3].pb(P(x,y));
  }
  double l=0,r=MAX*2;
  rep(tt,1000) {
    double m1=(l*2+r)/3,m2=(l+r*2)/3;
    double d1=solve(m1),d2=solve(m2);
    if(d1>=d2) l=m1;
    else r=m2;
  }
  pd(solve(l));
}

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


Measured memory_bytes: 3844
import java.util.Scanner;

/**
 * B - Resistors in Parallel
 * N 個の整数の列A1,…,AN が与えられます。
 * これらの逆数の総和の逆数を求めてください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 整数の数
        int n = sc.nextInt();
//        System.out.println("整数：" +n);
        double result = 0;
        // 整数の列
        double[] a = new double[n];
        for( int i = 0; i < n; i++ ) {
            a[i] = sc.nextDouble();
            result += 1 / a[i];
        }
        System.out.println( 1 / result );
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define PI 3.141592653589793238
const int M = 3e3 + 5;
ld a, b, h, m;
 
int32_t main() 
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	cin >> a >> b >> h >> m;
	ld ang_h = (h * 360.0) / 12.0 + 0.5 * m, ang_m = (m * 360.0) / 60.0;
	ld bet = abs(ang_h - ang_m);
	if(bet > 180)	
		bet = 360 - bet;
	ld ans = sqrt(a * a + b * b - 2.0 * a * b * cos((bet * PI) / 180.0));
	cout << fixed << setprecision(15) << ans;
    	return 0;
}

Measured memory_bytes: 4080
dx = [1,0,0,1, 1,1, 1,0, 0,1,-1, 1, 1]
dy = [0,1,0,1,-1,0, 0,1, 1,1, 1,-1, 1]
dz = [0,0,1,0, 0,1,-1,1,-1,1, 1, 1,-1]

def judge(B,X,Y,Z,color):
    for i in range(13):
        x,y,z = X,Y,Z
        while 0 <= min(x,y,z) and max(x,y,z) <= n-1:
            x,y,z = x-dx[i],y-dy[i],z-dz[i]
        x,y,z = x+dx[i],y+dy[i],z+dz[i] 
        seq = ""
        while 0 <= min(x,y,z) and max(x,y,z) < n:
            seq += B[z][y][x]
            x,y,z = x+dx[i],y+dy[i],z+dz[i]
        if str(color)*m in seq: return True
    return False
    
while 1:
    n,m,p = map(int,raw_input().split())
    if n == 0: break
    B = [[["-"]*n for i in range(n)] for j in range(n)]
    isWin = False
    for move in xrange(p):
        x,y = map(int,raw_input().split())
        if isWin: continue

        x -= 1; y -= 1
        color = move%2
        for z in range(n):
            if B[z][y][x] == "-":
                B[z][y][x] = str(color)
                isWin = judge(B,x,y,z,color)
                break
        
        if isWin: print ["Black","White"][color],move+1
    if not isWin:
        print "Draw"

Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main()
{
	 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
     ll n;
     cin>>n;
     ll a[n+1];
     for(ll i=1;i<=n;i++)    cin>>a[i];
     ll dp[n+1]={0};
     for(ll i=2;i<=n;i++)
     {
     	 if(i==2)
     	 {
     	 	dp[i] = abs(a[i] - a[i-1]);
     	 }
     	 else
     	 {
     	 	dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
     	 }
     }
     cout<<dp[n];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll r,g,b,n; cin >> r >> g >> b >> n;
    ll ans = 0;
    for(int i = 0; i < 3001; i++){
        for(int j = 0; j < 3001; j++){
            ll t = n - r*i - g*j;
            if(t >= 0 && t%b==0){ans++;}
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int max_min(int ,int )
{
    if(a<b)
        return a;
    else
        return b;
}
int main( )
{
    cin>>n>>a>>b;
    int max,min;
    cout<<max_min(a,b)<<" ";
    min=n-a-b;
    if(min>0)
        cout<<0<<endl;
    else
        cout<<abs(min)<<endl;
    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



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

    li k;
    cin >> k;

    li res = 0;
    while (a >= b) {
        b *= 2;
        res++;
    }
    while (b >= c) {
        c *= 2;
        res++;
    }
    cout << (res <= k ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3628
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int64,int64>> A(N);
    int64 a,idx;
    REP(i,N){
        cin >> a;
        A.emplace_back(a,i);
    }
    sort(ALL(A),greater<pair<int64,int64>>());

    vector<vector<int64>> DP(N+1,vector<int64>(N+1,0));
    REP(i,N){
        tie(a,idx) = A[i];
        REP(l,i+1){
            int r = i - l;
            chmax(DP[l+1][r], DP[l][r] + abs(idx-l)*a);
            int r_idx = N-r-1;
            chmax(DP[l][r+1], DP[l][r] + abs(idx-r_idx)*a);
        }
    }

    int64 ans=0;
    for(auto a:DP) chmax(ans,*max_element(ALL(a)));
    cout << ans << endl;
}

Measured memory_bytes: 34620