akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{

	static int max = 0;
	static int n;
	static int a[] = new int[100000];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 0; i < n;) {
			i += calc(i);
		}
		System.out.println(max);
	}

	public static int calc(int i) {
		int count = 0;
		while (i < n - 1 && a[i] >= a[i + 1]) {
			i++;
			count++;
		}
		if (count > max)
			max = count;
		if (count == 0)
			return 1;
		return count;
	}

}


Measured memory_bytes: 50544
h, w = map(int, input().split())
s = [['#' for _ in range(w+2)]]
for _ in range(h):
    s.append(list('#' + input() + '#'))
s.append(['#' for _ in range(w+2)])

# WFS
ans = []
d = [(1,0), (0,1), (-1,0), (0,-1)]
from collections import deque
for i in range(1, h+1):
    for j in range(1, w+1): # start = s[i][j]
        if s[i][j] == '#':
            continue
        seen = [[-1 for _ in range(w+2)] for __ in range(h+2)]
        seen[i][j] = 0
        todo = deque([(i, j)])
        num = 0
        while todo != deque([]):
            x, y = todo.popleft()
            for k in d:
                xk = x + k[0]
                yk = y + k[1]
                if seen[xk][yk] == -1 and s[xk][yk] == '.':
                    num = seen[x][y] + 1
                    seen[xk][yk] = num
                    todo.append((xk,yk))
        ans.append(num)
print(max(ans))

Measured memory_bytes: 45148
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  as <- IMS.fromListWith (+)  . map (,1::Int) .
        unfoldr (BS.readInt . BS.dropWhile (==' ')) <$>
          BS.getLine
  print $ query as 0

counterpart :: Int -> Int
counterpart larger = bit highestplus1 - larger
  where
    highestplus1 = finiteBitSize larger - countLeadingZeros larger

query :: IntMap Int -> Int -> Int
query !as !acc | IMS.null as = acc
query !as !acc
  | k == k' = query as' (acc + count1 `div` 2)
  | otherwise = query rest $ acc + min count1 count2
  where
    ((k, count1), as') = IMS.deleteFindMax as
    k' = counterpart k
    (cnt2, rest) = IMS.updateLookupWithKey
                   (\_ count2 -> if count1 < count2
                                 then Just (count2 - count1)
                                 else Nothing)
                   k' as'
    count2 = fromMaybe 0 cnt2


Measured memory_bytes: 35964
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
	int to;
	T cost;
	Edge() {};
	Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
	int n;
	bool directed;
	vector<vector<Edge<T>>> edges;
public:

	Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {};
	Graph() {};

	void add(int to, T cost) {
		emplace_back(to, cost);
	}

	int size() {
		return n;
	}
};


int main() {

	int N, M;

	cin >> N >> M;

	vi A(M);

	REP(i, M) {
		cin >> A[i];
	}

	long long sum = 0;

	REP(i, M) {
		sum += A[i];
	}

	if (sum > N) {
		cout << -1 << endl;
	}
	else {
		cout << N - sum << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
<?php
	$input = trim(fgets(STDIN));
	list($n, $m, $l) = explode(" ", $input);

	$a = $b = array();
	for ($i = 0; $i < $n; $i++) {
		$a[] = explode(" ", trim(fgets(STDIN)));
	}
	for ($i = 0; $i < $m; $i++) {
		$b[]= explode(" ", trim(fgets(STDIN)));
	}

	$c = array_fill(0, $n, array_fill(0, $l, 0));
	for ($i = 0; $i < $n; $i++) {
		for ($j = 0; $j < $l; $j++) {
			for ($k = 0; $k < $m; $k++) {
				$c[$i][$j] += ($a[$i][$k] * $b[$k][$j]);
			}
		}
		echo implode(" ", $c[$i]) . "\n";
	}

Measured memory_bytes: 11608
D = int(input())
c = list(map(int,input().split()))
last_di = [0] * 26
satisfaction_list = [0] * 26

for d in range(1, D+1):
    s = list(map(int,input().split()))
    for i in range(26):
        satisfaction_list[i] += s[i] - c[i] * (d - last_di[i])
    min_index = satisfaction_list.index(min(satisfaction_list))
    last_di[min_index] = d
    print(min_index + 1)


Measured memory_bytes: 68776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int H, W; cin >> H >> W;
    int N; cin >> N;
    int field[H+1][W+1];
    vector<int> color;
    for(int i=1; i<=N; i++){
        int a; cin >> a;
        for(int j=0; j<a; j++) color.push_back(i);
    }

    int pos = 0;
    for(int i=1; i<=H; i++){
        if(i%2 == 1){
            for(int j=1; j<=W; j++){
                field[i][j] = color[pos];
                pos++;
            }
        }
        else{
            for(int j=W; j>=1; j--){
                field[i][j] = color[pos];
                pos++;
            }
        }
    }

    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            cout << field[i][j];
            if(j == W) cout << endl;
            else cout << " ";
        }
    }
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, T := sc.nextInt(), sc.nextInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = sc.nextInt()
		B[i] = sc.nextInt()
	}
	dp1 := make([][]int, N+1)
	dp2 := make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		dp1[i] = make([]int, T)
		dp2[i] = make([]int, T)
	}
	for i := 0; i < N; i++ {
		ii := N - 1 - i
		for j := 0; j < T; j++ {
			dp1[i+1][j] = dp1[i][j]
			dp2[i+1][j] = dp2[i][j]
			if j >= A[i] {
				dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j-A[i]]+B[i])
			}
			if j >= A[ii] {
				dp2[i+1][j] = max(dp2[i+1][j], dp2[i][j-A[ii]]+B[ii])
			}
		}
	}
	ans := 0
	for i := 0; i < N; i++ {
		total := 0
		for j := 0; j < T; j++ {
			total = max(total, dp1[i][j]+dp2[N-1-i][T-1-j])
		}
		ans = max(ans, total+B[i])
	}

	fmt.Fprintln(wtr, ans)
}


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

int n;
int kura_num[15], dis[15], hako_kosu[15];
double dp[1 << 15][15];
int next[1 << 15][15];

double rec(int S, int v) {
	//printf("rec S = %d, v = %d\n", S, v);

	if (dp[S][v] >= 0.0) {
		return dp[S][v];
	}

	if (S == (1 << n) - 1) {
		return dp[S][v] = 0.0;
	}

	int kosu = 0;
	for (int u = 0; u < n; u++)
		if (S >> u & 1) kosu += hako_kosu[u];

	double res = DBL_MAX;
	for (int u = 0; u < n; u++) {
		if (!(S >> u & 1)) {
			double cost = (double)(fabs(dis[u] - dis[v]) / (2000.0 / (70.0 + 20.0 * kosu)));
			//printf("cost = %.5f\n", cost);
			double temp = rec(S | 1 << u, u) + cost;
			if (temp < res)
			{
				res = temp;
				next[S][v] = u;
			}
		}
	}

	return dp[S][v] = res;
}

signed main()
{
	cin >> n;
	rep(i,n) cin >> kura_num[i] >> dis[i] >> hako_kosu[i];
	
	rep(i,1<<15) rep(j,15) dp[i][j] = -1.0;	//??????????????????rec?????????????????????????????????????????????

	int first_v;
	double ans = DBL_MAX;
	rep(i,n)
	{
		double temp = rec(0, i);
		if (temp < ans)
		{
			ans = temp;
			first_v = i;
		}
	}

	vector<int> ans_list;
	ans_list.push_back(first_v);
	int s = 0 | 1 << first_v;
	int v = first_v;
	rep(i,n-1)
	{
		int next_v = next[s][v];
		ans_list.push_back(next_v);
		s = s | 1 << next_v;
		v = next_v;
	}

	rep(i,n)
	{
		cout << kura_num[ans_list[i]];
		if (i != n - 1) cout << " ";
	}
	cout << endl;
	
	//printf("%.5f\n", ans);
}

Measured memory_bytes: 6976
S=input()
if S=="SAT":
    print(1)
elif S=="FRI":
    print(2)
elif S=="THU":
    print(3)
elif S=="WED":
    print(4)
elif S=="TUE":
    print(5)
elif S=="MON":
    print(6)
elif S=="SUN":
    print(7)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n;
    cin >> n;
    string order;
    for (int i = 0; i < n; i++) {
        cin >> order;
        if (order == "print") {
            int a, b;
            cin >> a >> b;
            for (int i = a; i <= b; i++) {
                cout << s[i];
            }
            cout << endl;
        } else if(order == "reverse") {
            int a, b;
            cin >> a >> b;
            string tmp;
            for (int i = b; i >= a; i--) {
                tmp += s[i];
            }
            s.replace(a, b - a + 1, tmp);
        } else {
            int a, b;
            string p;
            cin >> a >> b >> p;
            s.replace(a, b - a + 1, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3228
using System;

class Sample31
{
    static void Main()
    {
        int[] ret = new int[500];
            
        while (true)
        {
             string s = Console.ReadLine();
                
            //終了処理
            if (s == null) 
            {
                break;
            }
                
            s = s.ToLower();
            for (int i = 0; i < s.Length; i++)
            {
                ret[s[i]]++;
            }
        }
            
        //出力
        for (int i = 'a'; i <= 'z'; i++)
        {
      
            Console.WriteLine((char)i + " : " + ret[i]);
        }
    }
}


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

int main(){
    
    int N, x;
    cin >> N >> x;
    vector<int> l(N);
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }
    
    sort(l.begin(), l.end());
    
    int ans = 0;
    
    for(int i = 0; i < N; i++){
        x -= l[i];
        if(x >= 0) ans++;
        else break;
    }
    
    if(x > 0) cout << ans - 1 << endl;
    else cout << ans << endl;
    
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

const int N = 200005;
int fa[N];
int si[N];
int getfa(int a) {
    return a == fa[a] ? a : fa[a] = getfa(fa[a]);
}
void uni(int a, int b) {
    int faa = getfa(a);
    int fab = getfa(b);
    if(faa == fab) return;
    if(si[a] > si[b]) {
        fa[faa] = fab;
        si[fab] += si[faa];
    }else {
        fa[fab] = faa;
        si[faa] += si[fab];
    }
}

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    for(int i=1; i<=n; i++) fa[i] = i, si[i] = 1;
    for(int i=0; i<m; i++) {
        int a, b; cin >> a >> b;
        uni(a, b);
    }
    int res = 1;
    
    for(int i=1; i<=n; i++) {
        // debug_out(si[i]);
        res = max(res, si[i]);
    }
    cout << res << endl;
}


Measured memory_bytes: 5160
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, l: i64,
        s: [String; n],
    }
    let mut s = s;
    s.sort();
    for i in 0..n {
        puts!("{}",s[i]);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int M = 2e6 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, t;
struct node{
    int l,r;
}s[N];
multiset<pii> st;

int main(){
    ios;
    cin>>n;
    rep(i,1,n){
        cin>>s[i].l>>s[i].r;
        st.insert({s[i].l,1});
        st.insert({s[i].r,-1});
    }
    int L=0,R=0, l, r, ansl=0, ansr=0;
    ll ans=0;
    for(auto it=st.begin();it!=st.end();it++){
        auto tmp=*it;
        //printf(" %d %d\n",tmp.fi,tmp.se);
        if(tmp.se==1) L++;
        else R++;
        if(n&1){
            if(tmp.se==1&&L==n/2+1) ansl=tmp.fi;
            if(tmp.se==-1&&R==n/2+1) ansr=tmp.fi;
        }
        else{
            if(tmp.se==1&&L==n/2) l=tmp.fi;
            if(tmp.se==1&&L==n/2+1) ansl=tmp.fi+l;
            if(tmp.se==-1&&R==n/2) r=tmp.fi;
            if(tmp.se==-1&&R==n/2+1) ansr=tmp.fi+r;
        }
    }
    //printf("%d %d\n", ansl,ansr);
    cout<<ansr-ansl+1<<endl;
    return 0;
}

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

int main(){
    int a = 0, b = 0, c = 0, x = 0;
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;
    std::cin >> x;
    
    int count = 0;
    
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for(int k = 0; k <= c; k++){
                if(x == (500 * i + 100 * j + 50 * k)) count++;
            }
        }
    }
    
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;

typedef double number;
const number eps = 1e-8;
typedef vector<number> array;
typedef vector<array> matrix;
struct LUinfo {
  vector<number> value;
  vector<int> index;
};
// O( n^3 ), Gaussian forward elimination
LUinfo LU_decomposition(matrix A) {
  const int n = A.size();
  LUinfo data;
  for (int i = 0; i < n; ++i) {
    int pivot = i;
    for (int j = i+1; j < n; ++j)
      if (abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
    swap(A[pivot], A[i]);
    data.index.push_back(pivot);
    // if A[i][i] == 0, LU decomposition failed.
    for(int j = i+1; j < n; ++j) {
      A[j][i] /= A[i][i];
      for(int k = i+1; k < n; ++k)
        A[j][k] -= A[i][k] * A[j][i];
      data.value.push_back(A[j][i]);
    }
  }
  for(int i = n-1; i >= 0; --i) {
    for(int j = i+1; j < n; ++j)
      data.value.push_back(A[i][j]);
    data.value.push_back(A[i][i]);
  }
  return data;
}
// O( n^2 ) Gaussian backward substitution
array LU_backsubstitution(const LUinfo &data, array b) {
  const int n = b.size();
  int k = 0;
  for (int i = 0; i < n; ++i){
    swap(b[data.index[i]], b[i]);
    for(int j = i+1; j < n; ++j)
      b[j] -= b[i] * data.value[k++];
  }
  for (int i = n-1; i >= 0; --i) {
    for (int j = i+1; j < n; ++j)
      b[i] -= b[j] * data.value[k++];
    b[i] /= data.value[k++];
  }
  return b;
}

int n;
double v[10];

vector<double> solve2(int i1, int i2){
	matrix M(n + 1, array(n + 1));
	array b(n + 1);
	int r = 0;
	rep(i, n + 3) if(i != i1 && i != i2){
		rep(j, n + 1) M[r][j] = j ? pow(i * 1.0, j) : 1.0;
		b[r++] = v[i];
	}
	/*
	dbg(i1); dbg(i2);
	rep(i, n + 1) rep(j, n + 1) cerr<<M[i][j]<<(j==n?"\n":" ");
	rep(i, n + 1) cerr<<b[i]<<(i==n?"\n":" ");
	*/
	LUinfo data = LU_decomposition(M);
	b = LU_backsubstitution(data, b);
	
	vector<double> res;
	rep(i, n + 3){
		double tmp = 0;
		rep(j, n + 1) tmp += (j ? pow(i * 1.0, j) : 1.0) * b[j];
		res.pb(tmp);
	}
	return res;
}
double EPS;
double solve(int idx){
	double err;
	rep(it, n + 3) if(it != idx){
		vector<double> res = solve2(idx, it);
		if(abs(res[it] - v[it]) > EPS) return 1e12;
		err = abs(res[it] - v[idx]);
	}
	return err;
}
int main(){
	while(cin >> n, n){
		rep(i, n + 3) cin >> v[i];
		for(EPS = 1e-9; ; EPS *= 10){
			double mnerr = 1e12; int mni = -1;
			rep(i, n + 3){
				double err = solve(i);
				if(err < mnerr) mnerr = err, mni = i;
			}
			if(mni >= 0){
				cout << mni << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1268
#include<stdio.h>
int main()
{
    long long i,n,sum;

    scanf("%lld",&n);
    if(n==1)
    {
        sum=n;
    }
    else
    {
        sum=3;
        for(i=3; i<=n; i++)
        {

            if(i%3==0||i%5==0||i%15==0)
            {
                continue;
            }
            sum=sum+i;
        }
    }
    printf("%lld\n",sum);

    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

vector<int> bucket[MAXN];
int pre[MAXN];
void solve(){

	int n;
	cin>>n;
	for(int i=0;i<=n;i++){
		bucket[i].clear();
		pre[i]=0;
	}
	for(int i=1;i<=n;i++){
		int m,p;
		cin>>m>>p;
		bucket[m].pb(p);
	}
	
	for(int i=0;i<=n;i++){
		pre[i+1] = pre[i] + bucket[i].size();
	}	
	int cnt=0;
	multiset<int> S;
	int ans=0;
	for(int i=n;i>0;i--){
		for(int j=0;j<bucket[i].size();j++)S.insert(bucket[i][j]);
		
		while(pre[i] + cnt<i){
			cnt++;
			ans+=*S.begin();
			S.erase(S.begin());
		}
		
	}
	cout<<ans<<endl;
}
int32_t main(){
	string s,t;
	cin>>s>>t;
	cout<<t+s<<endl;
}

Measured memory_bytes: 4992
str_a = gets.chomp.split("")
str_b = gets.chomp.split("")
str_c = gets.chomp.split("")

ans = ""
n = str_a.shift
loop do
    if n == "a" && str_a.empty?
        ans = "A"
        break
    elsif n == "b" && str_b.empty?
        ans = "B"
        break
    elsif n == "c" && str_c.empty?
        ans = "C"
        break
    end

    if n == "a"
        n = str_a.shift
    elsif n == "b"
        n = str_b.shift
    elsif n == "c"
        n = str_c.shift
    end
end

puts ans

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

int main()
{
    int N, C, K; cin >> N >> C >> K;

    auto times = vector<int>(N);
    for (auto& x : times) cin >> x;
    sort(begin(times), end(times));

    auto result = 0;
    for (auto i = 0; i < N; i++)
    {
        result++;
        auto bus = 1;
        const auto departure = times[i] + K;
        while (bus != C && i+1 < N && times[i+1] <= departure)
        {
            i++;
            bus++;
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 640
def main():
    n,x=map(int,input().split())
    a,b=n-x,x
    if(a<b):
       a,b=b,a
    path_length = calc_path(a,b,n)
    print(path_length)

def  calc_path(a1,b1,c1):
    q , mod=divmod(a1,b1)
    count=0
    if mod==0:
         c2=c1+2*b1*q-b1
         return c2
    else:
        count=count+1
        c2=c1+2*b1*q
        a2=a1-b1*q
        b2=b1
        if(a2<b2):
           a2,b2=b2,a2
        return calc_path(a2,b2,c2)
if __name__=='__main__':
  main()


Measured memory_bytes: 3064
n, k = map(int, input().split())


# 組み込み関数のlogを使うとたまに壊れる
def calc_multi(k, x):
    cnt = 0
    while x < k:
        cnt += 1
        x *= 2
    return cnt


ans = 0
for i in range(1, n+1):
    ans += (1/2) ** calc_multi(k, i)
print(ans / n)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define m 1000000007
#define N 50
using namespace std;
int n;
struct M{
    int adj[N][N];
    M operator*(const M&b) const{
        M c = M();
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                long long su=0LL;
                for(int k=0;k<n;k++){
                    su = (su+(adj[i][k]*1LL*b.adj[k][j])%m)%m;
                }
                c.adj[i][j]=su;
            }
        }
        return c;
    }
    int sum(){
        long long ans = 0LL;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                ans+=adj[i][j];
                ans%=m;
            }
        }
        return ans;
    }

};
int main(){
    long long k;
    cin>>n>>k;
    M a = M();
    M res = M();
    for(int i=0;i<n;i++)res.adj[i][i] = 1;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a.adj[i][j];
    while(k){
        if(k%2)res=res*a;
        a = a*a;
        k>>=1;
    }   
    cout<<res.sum()<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

typedef vector<vector<pair<ll,int>>> wgraph;
typedef pair<ll,int> pli;

vector<ll> bfs(wgraph v,int x){
  priority_queue<pli,vector<pli>,greater<pli>> q;
  vector<ll> dist(v.size(),longinf);
  dist[x]=0;
  q.push({0LL,x});

  while(q.size()){
    pli p=q.top(); q.pop();
    ll d=p.F, now=p.S;
    if(dist[now]<d){ continue; }
    for(auto to:v[now]){
      if(dist[to.S]>d+to.F){
        dist[to.S] = d+to.F;
        q.push({dist[to.S], to.S});
      }
    }
  }
  return dist;
}

int main(){
  int n,m;
  cin >> n >> m;
  wgraph v(n);
  rep(i,m){
    int x,y,z;
    cin >> x >> y >> z; x--; y--;
    v[x].emplace_back(z,y);
  }
  for(int i=n-1; i>0; i--){
    v[i].emplace_back(0,i-1);
  }
  vector<ll> dist=bfs(v,0);
  ll ans = dist[n-1];
  if(ans==longinf) ans=-1;
  cout << ans << endl;
  return 0;  
}

Measured memory_bytes: 15996
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 101
#define INF 9999999

int c,n,m,s,d,a,b,f,cost[MAX+1][MAX+1],dd[MAX+1][MAX+1];
bool used[MAX+1][MAX+1];
int x,y;

int dijkstra(int s,int d,int c){
    fill(dd[0],dd[MAX],INF);
    fill(used[0],used[MAX],false);
    
    dd[c][s-1] = 0;
    while(true){
        int Mini = -1 , Minj;
        
        for(int i = y ; i <= x ; i++){
            for(int j = 0 ; j <= c ; j++){
                if((dd[j][i] < dd[Minj][Mini] || Mini == -1)&&!used[j][i]){
                    Mini = i;
                    Minj = j;
                }
            }
        }
        
        if(Mini == -1) break;
        used[Minj][Mini] = true;
        
        for(int i = y ; i <= x ; i++){
            dd[Minj][i] = min(dd[Minj][i],dd[Minj][Mini]+cost[Mini][i]);
            if(Minj > 0) dd[Minj-1][i] = min(dd[Minj-1][i],dd[Minj][Mini]+cost[Mini][i]/2);
        }
    }
    
    int res = INF;
    for(int i = 0 ; i <= c ; i++){
        res = min(res,dd[i][d-1]);
    }
    
    return res;
}

int main(){
    x = 0; y = INF;
    while(cin >> c >> n >> m >> s >> d, c+n+m+s+d){
        fill(cost[0],cost[MAX],INF);
        for(int i = 0 ; i < m ; i++){
            cin >> a >> b >> f;
            cost[a-1][b-1] = f;
            cost[b-1][a-1] = f;
            x = max(x,max(a-1,b-1));
            y = min(y,min(a-1,b-1));
        }
        
        cout << dijkstra(s,d,c) << endl;
    }
    
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,x;
    cin >> n >> x;
    int32 cnt = 1;
    int32 d = 0;
    REP(i,n){
        int32 l;
        cin >> l;
        d += l;
        if(d <= x){
            cnt++;
        }else{
            break;
        }
    }
    ANS(cnt);
    return 0;
}

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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n+1);
    a[0] = 0;
    for(int i=1; i<n+1; i++){
        cin >> a[i];
    }

    vector<vector<int> > ans(h+1, vector<int>(w+1));
    int tmp = 1;
    for(int i=1; i<=h; i++){
        if(i%2){
            for(int j=1; j<=w; j++){
                if(!a[tmp]){
                    tmp++;
                }
                ans[i][j] = tmp;
                a[tmp]--;
            }
        }else{
            for(int j=w; j>=1; j--){
                if(!a[tmp]){
                    tmp++;
                }
                ans[i][j] = tmp;
                a[tmp]--;
            }
        }
    }

    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cout << ans[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}

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

int main(){
  int n;
  int a[110];
  cin >> n;
  int ans = 0;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    ans += a[i];
    a[i] *= n;
  }

  int ans_num = 0;
  int ans_p = abs(ans-a[0]);
  for(int i = 1;i < n;i++){
    if(ans_p > abs(ans-a[i])){
      ans_num = i;
      ans_p = abs(ans-a[i]);
    }
  }

  cout << ans_num << endl;

  return 0;
}

Measured memory_bytes: 256
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,c = readInts()
    if (max(a,b,c)*3 - a - b - c) % 2 == 0:# 3 4 5  5 * 3 = 15 15 - 12 = 3
        print((max(a,b,c)*3 - a - b - c)//2)
    else:
        print(((max(a,b,c)*3 - a - b - c) //2)+2) # 3 4 5 (1+2) 
if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int x, top, mn = 10;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	for(int i = 1; i <= 5; i++){
		scanf("%d",&x);
		int bol = (x/10)*10;
		if(bol == x)
			bol -= 10;
		int kal = x - bol;
		mn = min(mn, kal);
		top += bol + 10;
	}
	cout << top + mn - 10 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define MAX 101

using namespace std;


int main(){
  int n; cin>>n;
  int a[MAX][MAX]={};
  for(int i=1;i<=n;i++){
    int u,k; cin>>u>>k;
    for(int j=0;j<k;j++){
      int v; cin>>v;
      a[i][v]=1;
    }
  }
  for(int r=1;r<=n;r++){
    for(int c=1;c<=n;c++){
      cout<<a[r][c];
      if(c==n){
        cout<<endl;
      }else{
        cout<<' ';
      }
    }
  }

}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
#define mem(a) memset(a, 0, sizeof(a))
#define memm(a) memset(a, -1, sizeof(a))
#define INF 0x3f3f3f3f
#define maxn 1000005
using namespace std;
typedef long long LL;
typedef pair <int,int> PP;
LL n,m;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    while(cin >> n >> m){
        if(n==1 && m==1){
            cout << "1" << endl;
            continue;
        }
        LL ans=0;
        ans+=max(n-2,0*1ll)*max(m-2,0*1ll);
        ans+=max(n-2,0*1ll)*(m==1 ? 1 : 0);
        ans+=max(m-2,0*1ll)*(n==1 ? 1 : 0);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;

typedef long long ll;
const ll N = 1e5 + 10;
bool st[N];
ll h[N];
ll n, m;

int main() {
	cin >> n >> m;
	for (ll i = 1; i <= n; i++) cin >> h[i];
	memset(st, true, sizeof st);
	for (ll i = 1; i <= m; i++) {
		ll a, b;
		cin >> a >> b;
		if (h[a] == h[b]) {
			st[a] = st[b] = false;
		}
		else if (h[a] > h[b]) {
			st[b] = false;
		}
		else {
			st[a] = false;
		}
	}

	ll res = 0;
	for (ll i = 1; i <= n; i++) {
		if (st[i]) {
			res++;
		}
	}
	cout << res << endl;

	return 0;
}

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

int main(){
	stack<int> st;
	int n, a;

	while(cin >> n){
		if(n!=0){
			st.push( n );
		}else{
			a = st.top();
			cout << a << endl;
			st.pop();
		}
	}
}

Measured memory_bytes: 3060
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

apples = p[:x] + q[:y] + r
apples.sort(reverse=True)

ans = sum(apples[:x+y])
print(ans)


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

int N, K;

int main()
{
    cin >> N >> K;
    long long res = 0;
    for (int b=K+1; b<=N; b++)
    {
        res += N/b*(b-K) + max((N%b)-max(K, 1)+1, 0);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct A{
	int num,tl;
}a[500000];
int n,t=0;
bool cmp(const A &a,const A &b) {
	return a.tl<b.tl;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&a[i].num,&a[i].tl);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i) {
		t+=a[i].num;
		if(t>a[i].tl) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

long long a, b;

bool read() {
    if (!(cin >> a >> b))
        return false;

    return true;
}

void solve() {
    if (a > b)
        swap(a, b);

    auto c = a * b - 1;
    auto s = static_cast<long long>(sqrtl(c));
    cout << s - 1 + (a == b) + c / (s + 1) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin >> q;

    while (read())
        solve();

    return 0;
}



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

using namespace std;

bool checkYY(string s)
{
  return true;
}

bool checkMM(string s)
{
  if (
    s == "01" || s == "02" || s == "03" || s == "04" || s == "05" || s == "06" ||
    s == "07" || s == "08" || s == "09" || s == "10" || s == "11" || s == "12"
  ) {
    return true;
  }
  return false;
}

int main()
{
  string S; cin >> S;
  stringstream ss; 
  ss.str("");
  ss << S[0] << S[1];
  string s1 = ss.str();
  ss.str("");
  ss << S[2] << S[3];
  string s2 = ss.str();

  string ans = "";
  if ((checkYY(s1) && checkMM(s2))) {
    ans = "YYMM";
  }
  if ((checkMM(s1) && checkYY(s2))) {
    ans = "MMYY";
  }
  if (checkYY(s1) && checkMM(s2) && checkMM(s1) && checkYY(s2)){
    ans = "AMBIGUOUS";
  }
  if (ans.empty()) {
    ans = "NA";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP; ll mod_inverse(ll a) {
	ll n = mod - 2;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}
const int N_MAX = 1<<17;
ll p[N_MAX], invp[N_MAX];
void init() {
	p[0] = 1;
	rep1(i, N_MAX - 1) {
		p[i] = p[i - 1] * i%mod;
	}
	invp[N_MAX - 1] = mod_inverse(p[N_MAX - 1]);
	per(i, N_MAX - 1) {
		invp[i] = invp[i + 1] * (i + 1) % mod;
	}
}
//xCyを求める
ll comb(ll x, ll y) {
	if (x < y || y<0)return 0;
	ll res = p[x];
	(res *= invp[y]) %= mod;
	(res *= invp[x - y]) %= mod;
	return res;
}
//xPyを求める
ll comb2(ll x, ll y) {
	if (x < y)return 0;
	return p[x] * invp[x - y] % mod;
}
int n, m;
int a[16];
ll dp[1 << 16];
int main() {
	init();
	cin >> n >> m;
	rep(i, m) {
		cin >> a[i];
	}
	int z = 1 << n;
	dp[0] = 1;
	per(i, m) {
		per(j, (1 << n) - 1) {
			rep(k, n) {
				int s = (1 << k);
				if (j&s)continue;
				int nj = j ^ s;
				dp[nj] += s*dp[j]%mod * comb2(z - a[i] - j, s - 1)%mod;
				dp[nj] %= mod;
			}
		}
	}
	ll ans = 0;
	rep(i, (1 << n)) {
		int num = 0;
		rep(j, n) {
			if (i&(1 << j))num++;
		}
		if (num % 2) {
			ans = (ans - dp[i]*p[z-i-1]%mod + mod) % mod;
		}
		else {
			ans = (ans + dp[i]*p[z-i-1]%mod) % mod;
		}
		//cout << i << " " << dp[i] << endl;
	}
	cout << ans * z%mod << endl;
	//stop
	return 0;
}

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

int main(){
 ll n,W;
 cin>>n>>W;
 vector<ll> w(n);
 vector<ll> v(n);
 
 for(ll i=0;i<n;i++){
 	cin>>w[i]>>v[i];
 }
 
 vector<vector<ll>> dp(n+1,vector<ll>(W+1,0));
 ll maxval=INT_MIN;
 for(ll i=1;i<=n;i++){
 //	cout<<v[i-1]<<endl;
 	for(ll j=1;j<=W;j++){
 		dp[i][j]=dp[i-1][j];
 		if(j-w[i-1]>=0){
 			dp[i][j]=max(dp[i][j],dp[i-1][j-w[i-1]]+v[i-1]);	
		}	
		//cout<<dp[i][j]<<" ";
		maxval=max(maxval,dp[i][j]);
	}
	//cout<<endl;
 }
 cout<<maxval<<endl;
 return 0;
}



Measured memory_bytes: 83084
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
using namespace std;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

int main(){
	int field[10][10] = {};
	int dx[13] = {0, -1, 0, 1, 0, -1, 1, 1, -1, -2, 0, 2, 0};//5, 9, 13
	int dy[13] = {0, 0, -1, 0, 1, -1, -1, 1, 1, 0, -2, 0, 2};
	int x, y, size;
	char split;
	while (cin >> x >> split >> y >> split >> size) {
		int m = 1 + 4 * size;
		for (int i = 0; i < m; ++i) {
			if (x + dx[i] >= 0 && x + dx[i] < 10 && y + dy[i] >= 0 && y + dy[i] < 10)
				++field[x+dx[i]][y+dy[i]];
		}
	}
	int zero = 0;
	int maxnum = 0;
	for (int i = 0; i < 10; ++i) {
		for (int j = 0; j < 10; ++j) {
			if (field[i][j] == 0) ++zero;
			maxnum = max(maxnum, field[i][j]);
		}
	}
	cout << zero << endl;
	cout << maxnum << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int gcd(int a,int b){
  return (a%b ? gcd(b,a%b):b);
}
int main(){
  int n,k;cin>>n>>k;
  int mxg;cin>>mxg;
  int mx = mxg;
  for(int i = 0; n-1 > i; i++){
    int tmp;cin>>tmp;
    mxg = gcd(mxg,tmp);
    mx = max(mx,tmp);
  }
  if(k > mx){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  if(k%mxg){
    cout << "IMPOSSIBLE" << endl;
  }else{
    cout << "POSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#coding:utf-8
N, K = map(int,input().split())
A = list(map(int,input().split()))
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
ls = sorted(make_divisors(sum(A)))[::-1]


def cost(ls,n):
    ls = sorted(ls)
    #print (ls)
    left = 0
    right = len(ls)-1
    sm = 0
    while left < right:
        if (ls[left] + ls[right])<=n:
            op = ls[left]
            ls[left] = 0
            ls[right] += op
            left += 1
        else:
            op = n-ls[right]
            ls[right] = 0
            right -= 1
            ls[left] -= op
            if ls[left] == 0:
                left += 1


        sm += op
        #print (left,right)
        #print (ls)
        #print (sm)
    return sm

    

for n in ls:
    if cost([a%n for a in A],n) <= K:
        print (n)
        exit()
    


    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define all(v) v.begin(), v.end()
using pint = pair<int, int>;
using tint = tuple<int, int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int N;
	cin >> N;
	vector<int64_t> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	int64_t a=0, b=0, c=0, x, y, z;
	int64_t p[1000000];
	x = 500000;
	rep(i, N) {
		y = v.at(i);
		if (x+y < 1000000) {
			a += p[x+y];
		}
		if (x-y >= 0) {
			p[x-y]++;
		}
		x--;
	}
	std::cout << a << '\n';
}


Measured memory_bytes: 8048
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            int n = Integer.parseInt(in.next());
            int a[] = new int[n + 1];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            a[n] = a[0] + k;
            int ans[] = new int[n + 1];
            for (int i = 0; i < n; i++) {
                if (a[i] > k) a[i] = a[i] - k;
//            if (a[i] < 20 && i == n - 1) {
//                ans[i] = a[i] - a[0];
//            } else {
                ans[i] = a[i + 1] - a[i];
//            }
            }

            Arrays.sort(ans);
            int tmp = 0;
            // 出力
            for (int i = 0; i < n; i++) {
                tmp += ans[i];
            }
            out.println(tmp);

        }

    }
}



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

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 998244353;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		String s=sc.nextLine();
		if(s.contains("A") && s.contains("B"))
			out.print("Yes");
		else
			out.print("No");
		out.flush();
	}

	static long modPow(long a, long e)

	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res = (res * a) % mod;
			a = (a * a) % mod;
			e >>= 1;
		}
		return res;
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21204
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

void swap(int a,int b) {
	int tmp = a;
	a = b;
	b = tmp;
}

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

	if (n[2]==n[3] && n[4]==n[5]) {
		cout <<"Yes"<< endl;
	}
	else{
		cout << "No" << endl;
	}


	

	return 0;
}

Measured memory_bytes: 3624