akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

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

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] array = ReadLongs();

            long other= 0;
            for(int i = 2; i < n; i++)
            {
                other ^= array[i];
            }

            long res = DFS(array[0], array[1], other, 1);
            if (res == -1 || res == array[0])
            {
                WriteLine(-1);
            }
            else
            {
                WriteLine(res);
            }
        }

        static long DFS(long a, long b, long other, long div)
        {
            if (a == 0 && b == 0 && other == 0)
            {
                return 0;
            }
            if ((a ^ b) % 2 != other % 2)
            {
                return -1;
            }

            long val1 = DFS(a / 2, b / 2, other / 2, div * 2);
            long val2 = DFS((a - 1) / 2, (b + 1) / 2, other / 2, div * 2);

            if (val1 == -1 && val2 == -1)
            {
                return -1;
            }
            if (val1 == -1)
            {
                return val2 + div;
            }
            if (val2 == -1)
            {
                return val1;
            }
            return Min(val1, val2 + div);
        }

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


Measured memory_bytes: 27808
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := scanNums(n + 1)
	b := scanNums(n)

	var answer int
	for k, v := range b {
		if a[k] >= v {
			a[k] -= v
			answer += v
		} else {
			v -= a[k]
			answer += a[k]
			a[k] = 0
			if a[k+1] <= v {
				answer += a[k+1]
				a[k+1] = 0
			} else {
				a[k+1] -= v
				answer += v
			}
		}
	}
	fmt.Println(answer)
}

func scanNums(length int) (numbers []int) {
	var number int
	for i := 0; i < length; i++ {
		fmt.Scan(&number)
		numbers = append(numbers, number)
	}
	return
}

Measured memory_bytes: 7684
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long A, B;
    cin >> A >> B;
    ll count=0;
    ll input=1;
    while(input < B)
    {
        input--;
        input+=A;
        count++;
    }
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << c / a * b << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
s = [readline().rstrip().decode().split() for _ in range(h)]
al = [chr(ord('A') + i) for i in range(26)]
for i in range(h):
    for j in range(w):
        if s[i][j] == 'snuke':
            print(al[j] + str(i + 1))


Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    input! {
        n: usize,
        aa: [u64;n]
    }
    let mut l = aa.iter().scan(0, |acc, a| {
        *acc = gcd(*acc, *a);
        Some(*acc)
    }).take(n-1).collect::<Vec<_>>();
    l.insert(0,0);
    let mut r = aa.iter().rev().scan(0, |acc, a| {
        *acc = gcd(*acc, *a);
        Some(*acc)
    }).take(n-1).collect::<Vec<_>>();
    r.reverse();
    r.push(0);
    let res = l.iter().zip(r.iter()).map(|(a,b)| gcd(*a,*b)).max().unwrap();
    println!("{}", res);
}


Measured memory_bytes: 10492
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let (l, r) = (read::<usize>(), read::<usize>());

    if r - l >= 2019 {
        println!("0");
        return;
    }
    let mut m = 2019;
    for i in l..r+1 {
        for j in i+1..r+1 {
            m = std::cmp::min(m, (i*j)%2019)
        }
    }
    println!("{}", m);
}

Measured memory_bytes: 4352
#include <stdio.h>


int main() {
    int x, y, x0, y0, x1, y1;
    int q;
    double v0x, v0y, vx, vy, k, v0d;

    scanf("%d %d %d %d", &x0, &y0, &x1, &y1);
    scanf("%d", &q);

    v0x = x1 - x0;
    v0y = y1 - y0;
    v0d = v0x*v0x+v0y*v0y;
    while (q--) {
        scanf("%d %d", &x, &y);
        vx = x - x0;
        vy = y - y0;
        k = (v0x * vx + v0y * vy)/v0d;
        printf("%.10f %.10f\n", x0+k*v0x, y0+k*v0y);
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

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

using namespace std;

int main()
{
    ll n, l;
    cin >> n >> l;

    vector<string> s(n);

    rep(i, 0, n) cin >> s[i];

    sort(s.begin(), s.end());
        
    for (auto i: s)
        cout << i ;

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
//ワーシャルフロイド（全点対最短路問題）
$file_handle = fopen('php://stdin', "r");
//$file_handle = fopen('aoj0117_in.txt', "r");


function warshall_floyd($cost) {
	global $n;

	for ($i = 1; $i <= $n; ++$i) {
	    for ($j = 1; $j <= $n; ++$j) {
	        for ($k = 1; $k <= $n; ++$k) {
	            // j -> kへ行くのにiを経由した方が良いかどうか(cost)
	            $via_c = $cost[$j][$i] + $cost[$i][$k];
	            if ($via_c < $cost[$j][$k]) {
	                $cost[$j][$k] = $via_c;
	            }
	        }
	    }
	}
	return $cost;
}


//変数の初期化


//ファイル読み込み
$n = trim(fgets($file_handle));

//ワーシャルフロイド準備。
for ($i=1; $i<=$n; ++$i){
	for ($j=1; $j<=$n; ++$j){
		if ($i === $j){
			$cost[$i][$i] = 0;
		} else {
			$cost[$i][$j] = INF;
		}
	}
}

$m = trim(fgets($file_handle));
for ($i=1; $i<=$m; ++$i){
	$info = trim(fgets($file_handle));
	$explode = explode(',', $info);
	$a1 = $explode[0]; $b1 = $explode[1]; $c1 = $explode[2]; $d1 = $explode[3];
	$cost[$a1][$b1] = $c1; $cost[$b1][$a1] = $d1;
}
$info2 = trim(fgets($file_handle));
$explode = explode(',', $info2);
$start = $explode[0]; $goal = $explode[1]; $y1 = $explode[2]; $y2 = $explode[3];


//探索
$res = warshall_floyd($cost);

//収支計算
$income = $y1;
$expense = $res[$start][$goal] + $res[$goal][$start] + $y2;
$output = $income - $expense;


//出力
echo $output;
echo PHP_EOL;


fclose($file_handle);

Measured memory_bytes: 6712
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge
{
    ll to, cost, val;
};
template <class T, class U>
bool chmin(T &a, const U &b)
{
    if (a <= b)
        return false;
    a = b;
    return true;
}
template <class T, class U>
bool chmax(T &a, const U &b)
{
    if (a >= b)
        return false;
    a = b;
    return true;
}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll

bool is_prime[110000];
ll prime[110000];

//n以下の素数の数を返す
//計算量は大体O(n)
ll sieve(ll n){
  ll count=0;
  for(int i=0;i<=n;i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      prime[count++]=i;
      for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
    }
  }
  return count;
}


signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    sieve(109999);
    int N;
    cin>>N;
    for(int i=0;i<110000;i++){
        if(i>=N && is_prime[i]){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int A, B;
  cin >> A >> B;
  for (int x = 1; x <= 3; ++x) {
    if (A != x and B != x) {
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int sum=0,a=1;
	char s,lt='#';
	for(int i=1;i<=3;i++){
		cin>>s;
		sum+=s;
		if(s==lt)a=0;
	}
	if(sum==294&&a!=0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N (int)2e5
int n,memo[N],c[N];

int dp(int curr) {
    if (curr == n) return 0;
    if (curr > n) return 1e9;
    int &sol = memo[curr];
    if (sol != -1) return sol;
    sol = min(
        dp(curr + 1) + abs(c[curr] - c[curr + 1]) ,
        dp(curr + 2) + abs(c[curr] - c[curr + 2])
    );
    return sol;
}

int main() {
    scanf("%d" , &n);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d" , &c[i]);
    memset (memo , -1 , sizeof memo);
    printf("%d\n" , dp(1));
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 a(n + 1);
  vi32 b(n);
  cin >> a >> b;
  i64 ans = 0;
  rep(i, n) {
    if (b[i] <= a[i]) {
      ans += b[i];
    } else {
      ans += a[i];
      b[i] -= a[i];
      if (b[i] <= a[i + 1]) {
        ans += b[i];
        a[i + 1] -= b[i];
      } else {
        ans += a[i + 1];
        a[i + 1] = 0;
      }
    }
  }
  cout << ans << endl;
}


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

count = 0

def solve():
    from collections import Counter
    cc=Counter()
    ans=0
    for i,val in enumerate(A,1):
        if i-val>0:
            ans+=cc[i-val]
        cc[i+val]+=1
    print(ans)
    
def dfs(x, y):
    global count
    if x >= N or y >= N:
        return
    
    if (A[x]+A[y]) == y-x:
        count += 1

    if x+1 >= N and y+1 >= N:
        return
        
    if y+1 >= N:
        dfs(x+1, x+2)
    else:
        dfs(x, y+1)


#dfs(0, 1)
#print(count)
solve()


Measured memory_bytes: 40760
def main():
  from statistics import mean
  from math import floor,ceil

  n = int(input())
  x = list(map(int, input().split()))
  x_mean = mean(x) 
  if x_mean == 0.5:
      greater_than_x = len([i for i in x if i > x_mean])
      if greater_than_x * 2 >= n:
          x_mean = ceil(x_mean)
      else:
          x_mean = floor(x_mean)
  elif x_mean % 1 > 0.5:
      x_mean = ceil(x_mean)
  else:
      x_mean = floor(x_mean)
  x2 = [(num - x_mean)**2 for num in x]
  print(sum(x2))

main()

Measured memory_bytes: 5084
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    vector<vector<int> > A(N,vector<int>(M));
    REP(i,M){
        cin >> B[i];
    }
    REP(i,N){
        REP(j,M){
            cin >> A[i][j];
        }
    }
    int count =0;
    REP(n,N){
        llong ans = C;
        REP(m,M){
            ans+=B[m] * A[n][m];
        }
        if(ans>0){count++;}
    }
    cout << count <<endl;

    
    return 0;
}

Measured memory_bytes: 256
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Array.sort (fun x y -> y - x) ls; Array.sub ls 0 k |> Array.fold_left (+) 0 |> Printf.printf "%d\n"

Measured memory_bytes: 384
//

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

	if (R < 1200)
		cout << "ABC" << endl;
	else if (R < 2800)
		cout << "ARC" << endl;
	else
		cout << "AGC" << endl;

	return 0;
}

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

int main(){
  ll a,b,c;
  cin>> a>>b>>c;
  ll ans=0;
  if(a%2!=0 && (b%2!=0 && c%2!=0)){
    ans=min(a*b,min(a*c , b*c));
  }
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
import itertools

N, M, Q = map(int, input().split())

a = [0]
b = [0]
c = [0]
d = [0]

for _ in range(Q):
    l = list(map(int, input().split()))
    a.append(l[0])
    b.append(l[1])
    c.append(l[2])
    d.append(l[3])

A = list(itertools.combinations_with_replacement(range(1, M + 1), N))

ans = 0
for l in A:
    s = 0
    for i in range(1, Q + 1):
        if l[b[i]-1] - l[a[i]-1] == c[i]:
            s += d[i]
    else:
        if s > ans:
            ans = s

print(ans)

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


ll a,b,H,W,N;
map<pair<ll,ll>,ll>mp;
ll cnt[10];
ll sm;

int main(){
    cin>>H>>W>>N;
    
    for(int i=0;i<N;i++){
        cin>>a>>b;
        a--;b--;
        for(int j=-2;j<=0;j++){
            for(int k=-2;k<=0;k++){
                if(a+j<0 || a+j+2>H-1 || b+k<0 || b+k+2>W-1) continue;
                mp[make_pair(a+j,b+k)]++;
            }
        }
    }
    
    sm=(H-2)*(W-2);
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        for(int i=1;i<=9;i++){
            if((itr->second)==i) cnt[i]++;
        }
    }
    for(int i=1;i<=9;i++){
        sm-=cnt[i];
    }
    cnt[0]=sm;
    for(int i=0;i<=9;i++) cout<<cnt[i]<<endl;
}

Measured memory_bytes: 56448
import           Control.Monad
import           Data.List

main :: IO ()
main = do
    n  <- fmap read getLine :: IO Int
    ws <- replicateM n getLine :: IO [String]
    putStrLn $ if iscont ws && not (isdup ws) then "Yes" else "No"

iscont :: [String] -> Bool
iscont ws = all (\(v, w) -> last v == head w) $ zip (init ws) (tail ws)

isdup :: [String] -> Bool
isdup ws = length ws /= length (nub ws)


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> X(N);
    for(int i=0;i<N;i++)
       cin >> X.at(i);
    int min = N*99*99;
    for(int i=1;i<=100;i++){
         int dist = 0;
        for(int j=0;j<N;j++){
            dist += (X.at(j) - i)*(X.at(j) - i);
        }
        if(dist < min){
            min = dist;
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

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

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int N; cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];

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

    int K = 0, L = 0;

    rep(i, N - 1) { 
        if (S[i] == S[i + 1]) { ++K; }
        else { if (K >= L) { L = K; }
        K = 0;
        }
    }

    if (K >= L) { L = K; }
    K = 0;

    deque<string> deq;

    rep(i, N - 1) {
        if (S[i] == S[i + 1]) { ++K; }
        else {
            if (K == L) { deq.push_back(S[i]); }
            K = 0;
        }
    }

    if (K == L) { deq.push_back(S[N-1]); }

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

    rep(i, deq.size()) cout << deq[i] << endl;

}

Measured memory_bytes: 11392
#include <iostream>

using namespace std;

int n;
int a[25];
int q;

bool solve(int sum, int i) {
    if (sum == 0) {
        return true;
    }
    if (i == n) {
        return false;
    }
    return solve(sum, i + 1) || solve(sum - a[i], i + 1);
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int tmp;
        cin >> tmp;
        cout << (solve(tmp, 0) ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 3100
#include<stdio.h>
int main( ){
  int w,h,x,y,r;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
  if(x-r>=0&&x+r<=w&&y-r>=0&&y+r<=h){printf("Yes\n");
  }else{printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 584
from collections import Counter, defaultdict
n = int(input())
s= []
t = defaultdict(int)
for _ in range(n):
    s.append(input())
u = Counter(s)
m = int(input())
for _ in range(m):
    word = input()
    t[word] -= 1
    if word in u.keys():
        u[word] -= 1

ans = u.most_common(1)[0][1]
t = sorted(t.items(), key=lambda x:x[1], reverse=True)[0][1]
t = max(t, 0)
print(max(ans,t))


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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2) ;
  sort ( a.begin() , a.end() ) ;
  cout << a.at(2)-a.at(0) << endl;
}
  
    

Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0),eps=1e-8;
const int maxn=1e5+10;
const ll mod=1e9+7;

int main()
{

    ll a;
    cin>>a;
    if(a>=30)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    string S;
    cin >> N >> S;
    int ans=0;
    rep(i,N-2){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    }
    cout << ans << endl;




}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long n;
    vector<long long> x;
    
    cin >> n;
    for(long long i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        x.push_back(temp);
    }
    
    vector<long long> color;
    for(long long i = n - 1; 0 <= i; i--){
        vector<long long>::iterator itr = upper_bound(color.begin(), color.end(), x[i]);

        if(distance(color.begin(), itr) >= color.size())
            color.push_back(x[i]);
        else
            color[distance(color.begin(), itr)] = x[i];
    }
    
    cout << color.size() << endl;
    
    return 0;
    
}

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

#define what_is(x) cout << #x << " is " << x << endl;
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775805
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-9
#define MAX 10
#define N 500001
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX];
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a,ll b,ll p){
    if(b==0)
        return 1;
    if(b==1)
            return a;
    ll temp=vpow(a,b/2,p);
    temp*=temp;
    temp%=p;
    if(b%2==0)
        return temp;
    temp=temp*a;
    temp%=p;
    return temp;
}

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


ll inverseMod(ll a,ll b,ll p){
    if(b==0)
        return 1;
    ll temp=vpow(b,p-2,p);
    ll ans=temp*a;
    ans%=p;
    return ans;
}
void sieve()
{
    prime[0] = prime[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}
ll max(ll a, ll b)
{
    return a>b?a:b;
}

void factorial(){
    fact[0]=1;
    fact[1]=1;
    rep(i,2,MAX){
        fact[i]=(fact[i-1]*i);
        // fact[i]%=M;
    }
}
ll rand(ll a,ll b){
    return a+rand()%(b-a+1);
}

void solve(ll ttt){
    ll n;
    cin>>n;
    ll a[n];
    ll sum=0;
    ll i=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }

    }
    cout<<sum<<endl;
    return;
}
int main(){
    io;
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    //
    //freopen("input1.txt","r",stdin);
    // freopen("output1.txt","w",stdout);
#endif
    ll t=1;
     //cin>>t;
    fix(12);
    rep(q,1,t+1){
         //cout<<"Case #"<<q<<": ";
         solve(q);
        //solve2();
    }
    return 0;

}




Measured memory_bytes: 5220
fun main(args: Array<String>) {
    val N = readInputLine().toInt()

    val (S, T) = readInputLine().split(" ").map { it.toCharArray() }

    for (i in 0 until N) {
        print(S[i])
        print(T[i])
    }
    println()
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37924
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e2+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
  }


void solve() {
      int n,k;
      cin>>n>>k;
      vi v(n,0);
      rep(i,0,n) cin>>v[i];
      sort(all(v));
      
      int sum=0;
      rep(i,0,n-k) {
		     sum+=v[i];
		  }
    cout<<sum<<endl;            
}

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

  return 0;	   
}


Measured memory_bytes: 4780
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

typedef pair<int, vector<int> > P;

int main(){
  int n,c[10][10];
  map<vector<int>,int> d;
  priority_queue<P,vector<P>,greater<P> > q;
  vector<int> v;
  int ans = 0;

  cin >> n;
  for(int i=0;i<n;i++){
    v.push_back(i);
    for(int j=0;j<n;j++)cin >> c[i][j];
  }

  do{
    d[v] = 100000000;
  }while(next_permutation(v.begin(),v.end()));
  q.push(P(0,v));
  d[v] = 0;

  while(q.size()){
    P p = q.top(); q.pop();
    int dis = p.first; v = p.second;

    if(d[v]<dis)continue;
    ans = dis;

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	int cost = dis + c[v[i]][v[j]];
	swap(v[i],v[j]);
	if(cost<d[v]){
	  d[v] = cost;
	  q.push(P(cost,v));
	}
	swap(v[i],v[j]);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 7524
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main(){
  int n; cin >>n;
  string s; cin >>s;
  int q; cin >>q;
  rep(_,q){
    int k; cin >>k;
    vector<vector<li>> dp(4,vector<li>(n+1,0));
    rep(i,n){
      dp[0][i+1]=(s[i]=='D')+dp[0][i];
      if(i-k+1>=0) dp[0][i+1]-=(s[i-k]=='D');
      dp[1][i+1]=(s[i]=='M')+dp[1][i];
      if(i-k+1>=0) dp[1][i+1]-=(s[i-k]=='M');
      dp[2][i+1]=(s[i]=='M')*dp[0][i+1]+dp[2][i];
      if(i-k+1>=0) dp[2][i+1]-=(s[i-k]=='D')*dp[1][i];
      dp[3][i+1]=(s[i]=='C')*dp[2][i+1]+dp[3][i];
    }
    if(df)rep(j,4)print(dp[j]);
    print(dp[3][n]);
  }
}


Measured memory_bytes: 43556
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
using namespace std;


int main(void) {

  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for(int i=0; i<n; i++) cin >> x[i];
  for(int i=0; i<n; i++) cin >> y[i];

  vector<double> ans(4, 0);

  for(int i=0; i<n; i++){
    ans[0] += abs(x[i]-y[i]);
  }

  for(int i=0; i<n; i++){
    ans[1] += (x[i]-y[i])*(x[i]-y[i]);
  }
  ans[1] = sqrt(ans[1]);

  for(int i=0; i<n; i++){
    ans[2] += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
  }
  ans[2] = cbrt(ans[2]);

  for(int i=0; i<n; i++){
    ans[3] = max(ans[3], (double)abs(x[i]-y[i]) );
  }

  for(int i=0; i<4; i++) printf("%.8lf\n",ans[i]);

  return 0;
}

Measured memory_bytes: 3344
# encoding: utf-8
N,K,Q = map(int, input().split())

A=[int(input()) for _ in range(Q)]

#初期ポイント
points=[K for _ in range(N)]

# 問題数分、ポイントを引いてしまい、
# あとから正解者にポイントを足す
points=list(map(lambda x: x - Q, points))

for a in A:
    points[a-1] += 1

#print(list(map(lambda x: 'Yes' if x > 0 else 'No', points)))

for point in points:
    print('Yes' if point > 0 else 'No')


Measured memory_bytes: 11820
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back

int n;

void solve() {
  vector<P> train;
  rep(i,n) {
    int hh, mm, ss, b, e;
    char c;
    cin>>hh>>c>>mm>>c>>ss;
    b = hh * 3600 + mm * 60 + ss;
    cin>>hh>>c>>mm>>c>>ss;
    e = hh * 3600 + mm * 60 + ss;
    train.pb(P(b, e));
  }
  sort(train.begin(), train.end());
  
  const int zzz = train.size();
  vector<P>::iterator it = train.begin();
  vector<int> times;
  rep(z,zzz) {
    bool flag = false;
    rep(i,times.size()) {
      if (times[i] <= (int)(it->first)) {
        times[i] = it->second;
        flag = true; break;
      }
    }
    if (!flag) times.pb(it->second);
    train.erase(it);
  }
  cout<<times.size()<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("O3")

#include<bits/stdc++.h>
#define sp " "
#define endl "\n"
#define MAX 10e9
#define MAXN 100001
#define mod 1000000007
#define inf_int 2e9
#define inf_ll 2e18
#define e 1e-9
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpl vector<pair<ll,ll>>
#define vpc vector<pair<char,char>>
#define adj_list vector<vl>
#define umap unordered_map<ll, ll>
#define pll pair<ll,pair<ll, ll>>
#define clr(x) memset(x,0,sizeof(x))
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define google cout << "Case #" << ++it << ": " << ans << endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long int ll;

ll it = 0, ans = 0;

ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (auto i=2; i<MAXN; i++)
  		spf[i] = i;
  	for (auto i=4; i<MAXN; i+=2)
        spf[i] = 2;
    for (auto i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (auto j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
	return;
}

vl getFactorization(ll x)
{
    vl ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}


void check()
{
	ll n, ans = 0;
	cin >> n;
	for(int i=1;i<n;i++) ans += (n-1)/i;
	cout << ans << endl;
    return ;	
}

int32_t main()
{
    fastio
    ll t = 1;
    // cin >> t;
    while(t--)
        check();
    return 0;
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll s;
    cin >> s;
    vector<bool> already(1000001, false);
    already.at(s) = true;
    ll count = 1;
    while (true)
    {
        count++;
        if (s % 2)
        {
            s = s * 3 + 1;
        }
        else
        {
            s /= 2;
        }
        if (already.at(s))
        {
            break;
        }
        already.at(s) = true;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1,
    x=-x;
  }
  while(x){
    f[s++]=x%10,
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int a, b;
  rd(a);
  rd(b);
  wt_L((a+b+1)/2);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170910-1

// --- original code ---
// {
//   int a, b;
//   rd(a,b);
//   wt((a+b+1)/2);
// }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

constexpr int MAX = 114;

int v;
int deg[MAX], dv[MAX];
vector<int> res[MAX];

void dfs(size_t& idx, int depth, const vector<int>& q)
{
    deg[v] += q[idx];
    dv[depth] = v;
    
    int nv = v++;
    
    while (idx < q.size() && deg[nv] > 0) {
        const int val = q[++idx];
        if (val > 0) {
            deg[nv]--; deg[v]--;
            res[nv].emplace_back(v);
            res[v].emplace_back(nv);
            dfs(idx, depth + 1, q);
        } else {
            int u = dv[depth + val];
            deg[u]--; deg[nv]--;
            res[u].emplace_back(nv);
            res[nv].emplace_back(u);
        }
    }
}

void init(int N)
{
    v = 0;
    for (int i = 0; i < N; i++) {
        res[i].clear();
        deg[i] = 0;
    }
}

int main()
{
    int Tc;
    cin >> Tc;
    while (Tc--) {        
        int x, N = 0;
        vector<int> q;
        while (cin >> x, x != 0) {
            N += (x > 0);
            q.emplace_back(x);
        }
        
        init(N);
        size_t idx = 0;
        dfs(idx, 0, q);

        for (int i = 0; i < N; i++) {
            cout << i + 1;
            sort(res[i].begin(), res[i].end());
            for (const auto& r : res[i]) {
                cout << " " << r + 1;
            }
            cout << endl;;
        }
    }
    return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
int p;
int sum(int a, int b) {return (a += b) >= p ? a -= p : a;}
int dif(int a, int b) {return (a -= b) < 0 ? a += p : a;}
void inc(int &a, int b) {(a += b) >= p ? a -= p : 0;}
int power(int base, int exp) {
    int result = 1;
    while (exp > 0) {
        if (exp & 1)
            result = 1LL * result * base % p;
        base = 1LL * base * base % p;
        exp >>= 1;
    }
    return result;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m, k;
    cin >> n >> m >> k >> p;
    
    int binom[101][101] = {};
    for (int i = 0; i <= 100; ++i) {
        binom[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            binom[i][j] = sum(binom[i - 1][j], binom[i - 1][j - 1]);
    }
    
    int coef[101][101][101][2] = {};
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            for (int t = 0; t < k; ++t) {
                int tmp = 1LL * dif(power(t + 1, m - j), power(t, m - j)) * power(k - t, j) % p;
                coef[i][j][t][0] = power(tmp, i);
                tmp = 1LL * dif(power(k - t, i), power(k - t - 1, i)) * power(t + 1, n - i) % p;
                coef[i][j][t][1] = power(tmp, j);
            }
        }
    }
    
    int dp[101][101][101][2] = {};
    dp[0][0][0][0] = 1;
    
    
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            for (int t = 0; t < k; ++ t) {
                for (int x = 0; i + x <= n; ++x)
                    inc(dp[i + x][j][t][1], 1LL * binom[i + x][i] * dp[i][j][t][0] % p * coef[x][j][t][0] % p);
                for (int y = 0; j + y <= m; ++y)
                    inc(dp[i][j + y][t + 1][0], 1LL * binom[j + y][j] * dp[i][j][t][1] % p * coef[i][y][t][1] % p);
            }
        }
    }
    
    cout << dp[n][m][k][0] << endl;
    return 0;
}

Measured memory_bytes: 16384
s=input()
n=len(s)
for i in range(n):
    if s[i]!=s[n-1-i]:
        print("No")
        exit()
harf=int((n-1)/2)
for i in range(harf):
    if s[i]!=s[harf-1-i]:
        print("No")
        exit()
for i in range(harf+1,n):
    if s[i]!=s[n-1-(i-harf-1)]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2*10**5)
mod = 10**9 + 7
n = int(input())
g = [list() for _ in range(n)]
for _ in range(n-1):
  x,y = map(int, input().split())
  x -= 1; y -= 1
  g[x].append(y)
  g[y].append(x)

def dfs(v,p):
  vb,vw = 1,1
  for x in g[v]:
    if x == p:
      continue
    xb,xw = dfs(x,v)
    vb = vb*xw%mod
    vw = vw*(xb+xw)%mod
  return vb, vw

ab,aw = dfs(0,-1)
print((ab+aw)%mod)

Measured memory_bytes: 99760
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <deque>

#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;



signed main() {
	int N;
	cin >> N;
	vector<int> a(N);
	vector<ll> s(N, 0);
	for (int i = 0; i < N; i++) cin >> a[i];
	s[0] = a[0];
	for (int i = 1; i < N; i++) s[i] = s[i - 1] + a[i];
	ll sum = s[N - 1];

	ll diff = LLMAX;
	for (int i = 0; i < N - 1; i++) {
		diff = min(diff, abs(s[i] - (sum - s[i])));
	}

	cout << diff NL;


	return 0;
}

Measured memory_bytes: 2560
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>

#define MAX(a,b) ((a)<(b) ? (a) : (b))
#define MIN(a,b) ((a)>(b) ? (a) : (b))


using namespace std;




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

	if ( n < 1200) { 
		cout << "ABC" << endl;
	} else {
		cout << "ARC" << endl;
	}

}

Measured memory_bytes: 256
import java.math.BigInteger

/**
 * Created by m00nlight on 7/27/15.
 */
object Main {
  def main(args: Array[String]) {
    val xs = io.Source.stdin.getLines().toList.head.split("\\s+").map(_.toInt)
    val a = new BigInt(BigInteger.valueOf(xs.head))
    val b = new BigInt(BigInteger.valueOf(xs.tail.head))
    println(a.gcd(b))
  }
}

Measured memory_bytes: 44128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int n;
int X;
int a[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &X, &n);
	n++;
	for (int i = 1; i < n; i++)
		scanf("%d", &a[i]);
	int q;
	scanf("%d", &q);
	int l = 0, r = X;
	int forL = 0;
	int it = 0;
	int z = 0;
	while(q--) {
		int t, w;
		scanf("%d%d", &t, &w);
		while(it + 1 < n && a[it + 1] <= t) {
			if (z == 0) {
				forL -= a[it + 1] - a[it];
			} else {
				forL += a[it + 1] - a[it];
			}
			if (forL < 0) {
				l -= forL;
				forL = 0;
			}
			if (forL + r - l > X) {
				r -= forL + r - l - X;
				forL = X - r + l;
			}
			if (l > r) {
				l = r = 0;
				if (forL > X)
					forL = X;
			}
			z ^= 1;
			it++;
		}
		t -= a[it];
		if (w < l) w = l;
		if (w > r) w = r;
		w = forL + w - l;
		if (z == 0)
			w -= t;
		else
			w += t;
		if (w < 0) w = 0;
		if (w > X) w = X;
		printf("%d\n", w);
	}

	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int x = h2 - h1;
    x *= 60;
    int y = m2 - m1;
    x += y;
    cout << x - k << endl;

    return 0;
}

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

inline int read() {
	int n = 0;
    bool b = 0;
    char c = getchar();

	while(c < '0' || c > '9') {
        if(c == '-')
        b = 1;
        c = getchar();
    }
	while(c >= '0' && c <= '9')
    n = (n<<3) + (n<<1) + (c^48), c = getchar();
	return b ? -n : n;
}

int cnt[400100];
int n, ans;

main()
{
	n = read();
	for(int i = 1; i <= n; ++i)
	{
		int a = read();
		if(i >= a && i - a <= 400001)
        ans += cnt[i - a];
		++cnt[min(400010ll, i + a)];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6668