akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <map>
using namespace std;

int mod(int a, int m)
{
    return (a%m + m) % m;
}

int main() {
    int n;
    cin >> n;
    int arr[n];
    map<int , int> mp;
    map<int , int> mp2;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        mp2[arr[i]]=1;
    }
    int k = n;
    for (int j = 1; j <= n; ++j,k--) {
        if(mp2[abs(k-j)])
            mp[abs(k-j)]++;

    }
    long long ans = 1;
    for(int i = 0 ; i < n ; i++){
        if (mp[arr[i]]){
            ans= mod(ans * mp[arr[i]] , 1000000007);
            mp[arr[i]]-=1;
        }else{
            return cout << 0 , 0;
        }
    }
    cout << ans;
    return 0;
}




Measured memory_bytes: 9232
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
// #define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 112345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;


int32_t main() {
    $
    int t, x;
    cin >> t >> x;
    cout << fixed;
    cout.precision(14);
    cout << t / (double)x << '\n';
}   



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

can = sum(b)-sum(a)
actA,actB = 0,0
for i in range(N):
    diff = b[i]-a[i]
    if diff==0:continue
    if diff>0:
        actA+=(diff+1)//2
        actB+=diff%2
    else:
        actB+=(-diff)
leftA = can-actA
leftB = can-actB
print("Yes" if leftA>=0 and leftA*2==leftB else "No")


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

int main(){

    int a,b;
    cin >> a >> b;
  
    vector<int> date(a);
  
  	for(int i=0 ; i<a ;i++){
      date.at(i)=0; }

    int x,y;

    for(int i = 0; i <b ; i++) {
        cin >> x; 
        for (int j = 0; j < x ;j++){
        cin >> y;   
           date.at(y-1) = 1; 
        }
    }

    int count;
  
    for(int i = 0;i < a;i++ ){
        if(date.at(i) == 0) count++;
    }
  
    cout << count << endl;
} 

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

template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
    ~debug(){cerr<<endl;}
    template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
    template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
    template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
    template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
    template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

const int MAXN = 200*1000+5;
int a[MAXN], par[MAXN], n;
ll k;

void dfs(int u) {
    if(k == 0) {
        cout << u+1 << endl;
        exit(0);
    }
    int v = a[u];
    if(par[v] != -1) {
        // cycle found
        int cur = u;
        vector<int> cycle;
        while(cur != v) {
            cycle.push_back(cur);
            cur = par[cur];
        }
        reverse(cycle.begin(), cycle.end());
        cycle.push_back(v);
        int len = cycle.size();
        cout << cycle[(len-2+k%len)%len]+1 << endl;
        exit(0);
    }
    else {
        k--;
        par[v] = u;
        dfs(v);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(par, -1, sizeof par);
    cin >> n >> k;
    forn(i, n) {
        cin >> a[i];
        a[i]--;
    }
    dfs(0);
}













// Those who say they can, and those who say they can't - are both usually right.

// Read statement carefully
// Solve on paper first!
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 17652
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	double a[59];
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-1;i++) a[i+1]=(a[i]+a[i+1])/2;
	cout<<a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
broken_lst = []
for _ in range(M):
    broken_lst.append(int(input()))

counter_arr = [0]*(N+1)

counter_arr[0] = 1
next_broken = -1
if len(broken_lst) != 0:
    next_broken = broken_lst.pop(0)
last_broken = -1

for i in range(0, N-1):
    flug = 0
    if i+1 == next_broken:
        flug = 1
#        print("p0", i, counter_arr)
    elif i+1 == last_broken:
        pass
#        print("p1",i, counter_arr)
    else:
        counter_arr[i+1] += counter_arr[i]
        counter_arr[i+1] %= 10**9 + 7
#        print("p2",i,  counter_arr)

    if i + 2 == next_broken:
        flug = 1
#        print("p3",i, counter_arr)
    else:
        if i == 0 and len(broken_lst) != 0:
            if broken_lst[0] == 2 and next_broken == 1:
                continue
        counter_arr[i+2] += counter_arr[i]
        counter_arr[i+2] %= 10**9 + 7
#        print("p4",i, counter_arr)
    
    if flug == 1:
        last_broken = next_broken
        if len(broken_lst) != 0:
            next_broken = broken_lst.pop(0)

if last_broken != N - 1:
    counter_arr[-1] += counter_arr[-2]
counter_arr[-1] %= 10**9 + 7

print(counter_arr[-1])


Measured memory_bytes: 7848
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: usize = 998244353;

fn main() {
    let (N, S) = read!(usize, usize);
    let A = read![[usize]];

    // (L, x, R) (ただし L≤x(0) < ... < x(k) < R) の個数。
    let mut total = 0_usize;

    // dp[i][s] = (状態の数)
    // 状態:
    //     L と x(i) (L 以上 i 未満) の一部を決定済み
    //     A(x(i)) の総和が s に等しい
    let mut dp = vec![vec![0; S + 1]; N + 1];

    for i in 0..N {
        // (L=i, x=(), R=?) がある。
        dp[i][0] = 1;
    }

    for i in 0..N {
        let a = A[i];

        for s in 0..S + 1 {
            // 列 x に i を加えない遷移
            dp[i + 1][s] += dp[i][s];

            // 列 x に i を加える遷移。総和が S を超えるケースは数える意味がないので無視。
            if s + a <= S {
                dp[i + 1][s + a] += dp[i][s];
            }
        }

        for s in 0..S + 1 {
            dp[i + 1][s] %= P;
        }

        // R=i+1 に決定する遷移。総和が S でないケースは数える意味がないので無視。
        total += dp[i + 1][S];
        total %= P;
    }

    println!("{}", total);
}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

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

    create_mod_tables(4e6);

    int64_t ans = comb_mod(3*M+N-1, N-1);
    for(int i=2*M+1; i<=3*M; i++){
        add(ans, MOD - comb_mod(3*M-i+N-2, N-2) * N % MOD);
    }

    for(int k=M+1; k<=N; k++){
        if(3*M-k < 0) break;
        if((3*M-k)%2) continue;
        int64_t res = comb_mod(N, k);
        int p = (3*M-k)/2;
        mul(res, comb_mod(p+N-1, N-1));
        add(ans, MOD - res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 94080
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, m, dis[N], vis[N], in[N], ans=0, x, y; vector <int> adj[N];

void dfs(int s) {
    if (vis[s]) return;
    vis[s] = 1;
    for (auto u : adj[s]) {
        dis[u] = max(dis[u] , dis[s] + 1);
        --in[u];
        if (!in[u]) dfs(u);
    }
}

void solve()
{
    cin >> n >> m;
    for (int i=0; i<m; ++i) cin >> x >> y, adj[x].pb(y), ++in[y];
    for (int i=1; i<=n; i++) {
        if (!vis[i] && !in[i]) dfs(i);
    }
    for (int i=1; i<=n; ++i) ans = max(ans, dis[i]);
    nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 14924
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  ll Q,H,S,D,N;
  std::cin >> Q >> H >> S >> D >> N;
  ll h=min(2*Q,H);
  ll s=min(h*2,S);
  if(2*s<=D) std::cout << N*s << '\n';
  else std::cout << D*(N/2)+(N%2)*s << '\n';
  return 0;
}


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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline void read(int& a){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

bool cmp(int a,int b){
    return a>b;
}

signed main(){
    int a=read(),b=read(),c=read(),k=read();
    
    for(int i=1;i<=k;i++){
        if(b<=a){
            b*=2;
            continue;
        }
        else if(c<=b){
            c*=2;
            continue;
        }
        else{
            c*=2;
            continue;
        }
    }
    
    if(b>a && c>b){
        puts("Yes");
        return 0;
    }
    
    puts("No");        
    return 0;
}

Measured memory_bytes: 3632
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= m; ++j) {
			if (m * i + n * j - i * j * 2 == k) {
				Yes();
				return 0;
			}
		}
	}

	No();

	return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, M = getNM()
weight = []
value = []
for i in range(M):
    a, b = getNM()
    c = getList()
    weight.append(a)
    value.append(c)
"""
N, M = 4, 6
weight = [67786, 3497, 44908, 2156, 26230, 86918]
value = [[1, 3, 4], [2], [2, 3, 4], [2, 3, 4], [2], [3]]
"""

# N個のものを全て手に入れるのに必要なコストの最小値
# コストを1にすれば最小個数がわかる
# Nの数が十分に小さいと使用可能
def get_everything(n, weight, value):
    m = len(weight)
    dp = [float("inf")] * (1 << n)
    dp[0] = 0

    for i in range(m):
        bit = 0
        for item in value[i]:
            bit |= (1 << (item - 1))

        for j in range(1 << n):
            dp[j | bit] = min(dp[j | bit], dp[j] + weight[i])

    return dp[(1 << N) - 1]

ans = get_everything(N, weight, value)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 84876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderE
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();
        long mod = 1000000007;

        long[] patterns = new long[k + 1];

        long answer = 0;
        for (int i = k; i >= 1; i--)
        {
            long pattern = k / i;
            pattern = Pow(pattern, n, mod);
            for (int j = i + i; j <= k; j += i)
            {
                pattern -= patterns[j];
                if (pattern < 0)
                {
                    pattern += mod;
                }
            }
            patterns[i] = pattern;
            long tmpAnswer = (i * pattern) % mod;
            answer += tmpAnswer;
            answer = answer % mod;
        }

        Console.WriteLine(answer);
    }

    // 掛け算（mod版）
    private static long Mul(long a, long b, long c)
    {
        return ((a % c) * (b % c)) % c;
    }

    // 割り算（mod版）
    private static long Div(long a, long b, long c)
    {
        return Mul(a, Pow(b, c - 2, c), c);
    }

    // べき乗（mod版）
    private static long Pow(long a, long b, long c)
    {
        if (b == 0)
        {
            return 1;
        }
        else if (b == 1)
        {
            return a % c;
        }
        else if (b % 2 == 0)
        {
            long d = Pow(a, b / 2, c);
            return d * d % c;
        }
        else
        {
            return a * Pow(a, b - 1, c) % c;
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

using namespace std;

int mem[1005][(1<<12)];
int n,m;
int mm[1005],cst[1005];

int go(int ind,int mas)
{
	if(ind>=m)
	{
		return (mas==(1<<n)-1?0:(1<<27));
	}
	if(~mem[ind][mas]) return mem[ind][mas];
	return mem[ind][mas]=min(go(ind+1,mas),go(ind+1,mas|mm[ind])+cst[ind]);
}

int main()
{
	cin >> n >> m;
	for(int i=0;i<m;i++)
	{
		cin >> cst[i];
		int x;
		cin >> x;
		while(x--)
		{
			int y;
			cin >> y; y--;
			mm[i]|=(1<<y);
		}
	}
	memset(mem,-1,sizeof mem);
	int ans=go(0,0);
	if(ans>=(1<<27)) ans=-1;
	cout << ans << endl;
}

Measured memory_bytes: 16384
H,W=map(int,input().split())

A=[]
a=["#"]*(W+2)
A.append(a)
for i in range(H):
    s=input()
    s="#"+s+"#"
    A.append(list(s))
A.append(a)
#幅優先探索
#print(A)
P=[[1,1]]
A[1][1]=1
x=[1,-1,0,0]
y=[0,0,1,-1]
while P!=[]:
    #print(P)
    for j in range(4):
        if A[P[0][0]+x[j]][P[0][1]+y[j]]=="#":
            pass
        elif A[P[0][0]+x[j]][P[0][1]+y[j]]==".":
            A[P[0][0]+x[j]][P[0][1]+y[j]]=A[P[0][0]][P[0][1]]+1
            P.append([P[0][0]+x[j],P[0][1]+y[j]])
        elif A[P[0][0]+x[j]][P[0][1]+y[j]]<=A[P[0][0]][P[0][1]]+1:
            pass
        else:
            A[P[0][0]+x[j]][P[0][1]+y[j]]=A[P[0][0]][P[0][1]]+1
            P.append([P[0][0]+x[j],P[0][1]+y[j]])
    del P[0]
S=0
for i in range(H+2):
    for j in range(W+2):
        if A[i][j]=="#":
            S+=1
if A[H][W]==".":
    print(-1)
else:
    print((H+2)*(W+2)-S-A[H][W])

Measured memory_bytes: 3192
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
   int a,b;
   cin >> a >> b;
   if(a>0){
       cout << "Positive";
       return 0;
   }
   if(a==0||b==0||(a<0&&b>0)){
       cout << "Zero";
       return 0;
   }
   if((b-a)%2){
      cout << "Positive"; 
   }else{
       cout << "Negative";
   }
}

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


int main () {
  int N;
  cin >> N;
  long long a[N];
  for (int i = 0; i < N; ++i) cin >> a[i];
  
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    while(a[i] % 2 == 0) {
      cnt++;
      a[i] /= 2;
    }
  }
  cout << cnt << endl;
  	  
}



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

vector < vector < int > > g(2005) ;

int ans[2005] ;
int d[2005] ;
bool v[2005] ;
void BFS( int u , int N  ){
    for( int i = 0 ; i <= N ; i++ ){
        d[i] = INT_MAX ;
        v[i] = 0 ;
    }
    queue < int > q ;
    q.push(u);
    v[u] = 1 ;
    int D = 1 ;
    q.push(-1);
    while( !q.empty() ){
        int V = q.front() ;
        q.pop() ;
        if( V == -1 ){
            if( q.size() == 0 ) break ;
            else{
                D++ ;
                q.push(-1);
                continue ;
            }
        }
        for( int i = 0 ; i < g[V].size() ; i++ ){
            int w = g[V][i] ;
            if( !v[w]){
                q.push(w);
                ans[D]++ ;
                v[w] = 1 ;
            }
        }
    }
}
int main(){
    int N , X , Y ;
    cin >> N >> X >> Y ;
    for( int i = 1 ; i < N ; i++  ){
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[X].push_back(Y);
    g[Y].push_back(X);

    for( int i = 1 ; i <= N ; i++ ){
        BFS(i , N );
    }

    for( int i = 1 ; i < N ; i++ ){
        cout << ans[i]/2 << "\n" ;
    }






    return 0 ;
}

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

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  
  vector<string> s(h);
  
  for (int i = 0; i < h; i++) cin >> s.at(i);
  
  int ans = 0;
  
  for (int bh = 0; bh < (1 << h); bh++) {
    for (int bw = 0; bw < (1 << w); bw++) {
      
      int count = 0;
      
      for (int i = 0; i < h; i++) {
        
        if (bh >> i & 1) continue;
        
        for (int j = 0; j < w; j++) {
          if (bw >> j & 1) continue;
          if (s.at(i).at(j) == '#') count++;
        }
        
      }
      if (count == k) ans++;
    }
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
s :: [Int]
s = map (2^) [0..]

bin :: Int -> [Int]
bin 0 = []
bin x = (x `mod` 2):(bin $ x `div` 2)

tak [] = []
tak ((0,s):xs) = tak xs
tak ((1,s):xs) = s:(tak xs)
  
ans x = tak $ zip (bin x) s

main = do
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = map ans i
  mapM_ putStrLn $ map unwords $ map (map show) o

Measured memory_bytes: 3900
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
int a[200000], vs[200000],b[203][220], co[200200],sum[4][50000];
vector<int>v[300000];
string s;
int main()
{
    IO;
    long long i, j, m, k, n, l=0;
    cin>>n>>s;
    for(i=1; i<=n; i++){
        if(s[i-1]=='R'){
            a[i]=1; sum[1][i]=sum[1][i-1]+1;
        sum[3][i]=sum[3][i-1];
        sum[2][i]=sum[2][i-1];
        }
        if(s[i-1]=='G'){
            a[i]=2; sum[2][i]=sum[2][i-1]+1;
            sum[3][i]=sum[3][i-1];
            sum[1][i]=sum[1][i-1];
        }
        if(s[i-1]=='B'){
            a[i]=3; sum[3][i]=sum[3][i-1]+1;
            sum[1][i]=sum[1][i-1];
            sum[2][i]=sum[2][i-1];
        }
    }
    for(i=1; i<=n; i++){
            for(k=i+1; k<=n; k++){
                   if(a[i]!=a[k]){
                    m=6-a[i]-a[k];
                    l+=(sum[m][n]-sum[m][k]);
                    if(a[k+k-i]==m) l--;
                   }
            }
    }
    cout<<l<<endl;
    return 0;

}


Measured memory_bytes: 10720
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
ans = 1
diff = h[0]
for i in range(n):
    if diff > abs(a - (t - h[i]*0.006)) :
        diff = abs(a - (t - h[i]*0.006))
        ans = i + 1
print(ans)

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

const int bB = 9;
const int B = 1 << bB;

int up(int x) {
	return (x + (1 << bB) - 1) >> bB;
}

int down(int x) {
	return x >> bB;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	const int H = up(n);
	vector<int> bv(H, INT_MAX), v(n, INT_MAX);
	while (q--) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) {
			v[x] = y;
			int p = down(x);
			bv[p] = INT_MAX;
			for (int i = p << bB; i < n && i < (p << bB) + B; i++) {
				bv[p] = min(bv[p], v[i]);
			}
		}
		else {
			y++;
			int res = INT_MAX;
			for (int i = x; i < y && i < (up(x) << bB); i++) {
				res = min(res, v[i]);
			}
			if (up(x) <= down(y)) {
				for (int i = up(x); i < down(y); i++) {
					res = min(res, bv[i]);
				}
				for (int i = down(y) << bB; i < y; i++) {
					res = min(res, v[i]);
				}
			}
			printf("%d\n", res);
		}
	}
	return 0;
}



Measured memory_bytes: 3312
S=int(input())

arr=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(arr[S-1])

Measured memory_bytes: 3060
//
//  peaks.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define PI 3.14159265
void dfs(vector<int> A, int n, int m)  {
  if  (A.size() > n) {
    for (int i = 1; i <= n; i++) {
      std::cout << A[i];
    }
    std::cout << std::endl;
    return;
  }
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A, n, m);
    A.back()++;
  }
}

int main(int argc, const char* argv[]) {

  int n, m;
  std::cin >> n >> m;
  ll h[n];
  std::priority_queue<ll> road[n];

  for (int i = 0; i < n; i++) {
    std::cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    std::cin >> a >> b;
    road[a-1].push(h[b-1]);
    road[b-1].push(h[a-1]);
  }

  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (!road[i].empty()) {
      int high = road[i].top();
      if (h[i] > high) {
        sum++;
      }
    }
    else {
      sum++;
    }
  }


  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 11004
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 100007
const ll inf=1e13+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();;
void sieve();
int main()
{
	//sieve();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(2);
	ll t=1;
	//cin>>t;
	for(ll i=1;i<=t;i++)
	solve();
	return 0;
}
ll arr[maxn],dp[maxn],n,k;
void intl()
{
	for(ll i=0;i<maxn;i++)
	dp[i]=-1;
}
ll go(ll pos)
{
	//cout<<pos<<" "<<k<<endl;
	if(pos==n-1)
	return 0;
	if(pos>=n)
	return inf;
	if(dp[pos]!=-1)
	return dp[pos];
	ll ans=inf;
	for(ll i=1;i<=k;i++)
	{
		if(pos+i<n)
		ans=min(ans,go(pos+i)+abs(arr[pos+i]-arr[pos]));
	}
	return dp[pos]=ans;
}
void solve()
{
	intl();
	cin>>n>>k;
	for(ll i=0;i<n;i++)
	cin>>arr[i];
	cout<<go(0);
}
	
	

		


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

int main(){
    string s;
    cin>>s;
    int n=s.length();
    int i=0;
    while(i<n){
        if(i%2==0){
            if(s[i]=='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        if(i%2==1){
            if(s[i]=='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        i++;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second

#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int main() {
    clue();
    return 0;
}
int clue() {


    // brute force solution
    string s;
    cin>>s;

    int cnt=0;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') {
        cnt=3;
    }
    else if((s[0]=='R'&&s[1]=='R') || (s[1]=='R'&&s[2]=='R')) {
        cnt=2;
    }
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R') {
        cnt=1;
    }
    else {
        cnt=0;
    }

    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
//AtCoderC++.cpp

using namespace std;

int main() {
	int N, K; cin >> N >> K;
	if (N == 2) {
		if (K == 0) {
			cout << "1" << endl;
			cout << "1 2" << endl;
		} else {
			cout << -1 << endl;
		}
		return 0;
	}
	int max = (N - 1) * (N - 2) / 2;
	if (K > max) {
		cout << -1 << endl;
		return 0;
	}
	using edge = pair<int, int>;
	auto graph = vector<edge>(N - 1);
	auto pairs = max;
	for (size_t i = 2; i <= N; i++) {
		graph[i - 2] = { 1,i };
	}
	auto from = 2;
	auto to = N;
	while (pairs != K) {
		graph.push_back({ from,to });
		from++;
		if (from == to) {
			to--;
			from = 2;
		}
		pairs--;
	}
	cout << graph.size() << endl;
	for (auto e : graph) {
		cout << e.first << " " << e.second << endl;
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>
using namespace std;
const long long mod = 998244353;
string S;
int K, no = 0;
vector<int> cnt;
vector<int> pfx;
long long dptable[301][301][301][2];
long long dp(int a, int b, int c, bool d) {
	if (b > no || c < 0) return 0;
	if (a == cnt.size()) return 1;
	if (dptable[a][b][c][d] != -1) return dptable[a][b][c][d];
	if (d == true) {
		if (a + 1 == cnt.size()) return dptable[a][b][c][d] = dp(a + 1, b, c, d);
		dptable[a][b][c][d] = 0;
		for (int i = max(b, pfx[a + 1]); i < b + cnt[a + 1]; ++i) dptable[a][b][c][d] += dp(a + 1, i, c, 1), dptable[a][b][c][d] %= mod;
		dptable[a][b][c][d] = (dptable[a][b][c][d] + dp(a + 1, b + cnt[a + 1], c, 0)) % mod;
		return dptable[a][b][c][d];
	} else return dptable[a][b][c][d] = (dp(a, b, c, 1) + dp(a, b + 1, c - 1, 0)) % mod;
}
int main() {
	memset(dptable, -1, sizeof dptable);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> S >> K;
	int x = 0;
	for (char c: S) {
		if (c == '1') ++x, ++no;
		else cnt.push_back(x), x = 0;
	}
	K = min(K, no);
	if (cnt.size() == 0) {
		cout << 1;
		return 0;
	}
	pfx.push_back(cnt[0]);
	for (int i = 1; i < cnt.size(); ++i) pfx.push_back(cnt[i] + pfx[i - 1]);
	cout << dp(0, cnt[0], K, false);
	return 0;
}

Measured memory_bytes: 429800
#include "bits/stdc++.h"
using namespace std;

#define rep(i,beg,end)   for (auto i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
#define rall(cont)           rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s;
	cin >> n >> s;
	const int N_MAX = 300000;
	vector<ll> dp(n);
	dp[0] = count(begin(s)+1, end(s), 'E');
	rep(i, 1, n) {
		ll t = dp[i - 1];
		if (s[i] == 'E')
			t--;
		if (s[i - 1] == 'W')
			t++;
		dp[i] = t;
	}
	cout << *min_element(all(dp)) << endl;
	return 0;
}


Measured memory_bytes: 2964
#include<bits/stdc++.h>
using namespace std;
int t,a;
long long ans,q,b;
priority_queue<int> L, R;
int main(){
	cin>>q>>t>>a>>ans;
	L.push(a);
	for(int i = 1; i < q; i++){
		cin>>t;
		if(t == 1){
			cin>>a>>b;
			ans += b + abs(L.top() - a);
			if(a < L.top()) L.push(a);
			else R.push(-a);
			if(L.size() > R.size() + 1){
				R.push(-L.top()); L.pop();
			}else if(L.size() < R.size()){
				ans += R.top() + L.top();
				L.push(-R.top()); R.pop();
			}
		}else cout<<L.top()<<" "<<ans<<"\n";
	}
}

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

ll solve() {
    ll N, a, x, y;
    cin >> N;
    vector<vector<int>> X(N), Y(N);
    for ( int n = 0; n < N; n++ ) {
        cin >> a;
        for ( int i = 0; i < a; i++ ) {
            cin >> x >> y;
            x--;
            X[n].push_back(x);
            Y[n].push_back(y);
        }
    }
    int ans = 0;
    for ( int b = 0; b < (1<<N); b++ ) {
        bool ng = false;
        vector<int> yy(N);
        for ( int i = 0; i < N; i++ ) {
            yy[i] = ((b >> i) & 1) == 0 ? 0 : 1;
        }
        for ( int i = 0; i < N; i++ ) {
            if ( yy[i] != 1 ) continue;
            for ( int j = 0; j < X[i].size(); j++ ) {
                x = X[i][j], y = Y[i][j];
                if ( yy[x] != y ) {
                    ng = true;
                    break;
                };
            }
            if ( ng ) break;
        }
        if ( !ng ) {
            int cnt = 0;
            for ( int i = 0; i < N; i++ ) {
                if ( yy[i] == 1 ) cnt++;
            }
            ans = max(ans, cnt);
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int N;cin>>N;
  if(N>=1000)cout<<"ABD"<<endl;
  else cout<<"ABC"<<endl;
  
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}

template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

template<class Monoid>
class SegmentTree {
    private:
        using T = typename Monoid::T;
        const size_t n;
        vector<T> d;

        void build() {
            for(size_t b = n - 1; b > 0; b--) d[b] = Monoid::op(d[b << 1], d[b << 1 | 1]);
        }

    public:
        SegmentTree(size_t n)
            : n(n), d(2 * n, Monoid::identify()) {}

        template<typename InputItr>
            SegmentTree(InputItr first, InputItr last)
            : n(distance(first, last)), d(2 * n, Monoid::identify()) {
                copy(first, last, next(d.begin(), n));
                build();
            }

        /* set one value */
        void modify(size_t k, T v) {
            for(d[k += n] = v; k > 1; k >>= 1) d[k >> 1] = Monoid::op(d[k], d[k ^ 1]);
        }

        /* return [l, r) value */
        T query(size_t l, size_t r) {
            T res {Monoid::identify()};
            for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
                if (l&1) res = Monoid::op(res, d[l++]);
                if (r&1) res = Monoid::op(res, d[--r]);
            }
            return res;
        }
        
        T get(size_t i) {
            return query(i, i + 1);
        }

    };

template<typename U = ll>
struct RMQ {
    using T = U;
    static T op(const T& a, const T& b) {
        return min<T>(a, b);
    }
    static constexpr T identify() {
        return numeric_limits<T>::max();
    }
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> l(m), r(m), c(m);

    REP(i, m) {
        cin >> l[i] >> r[i] >> c[i];
        --l[i]; --r[i];
    }

    vector<int> o(m);
    iota(o.begin(), o.end(), 0);
    sort(o.begin(), o.end(), [&](int i, int j) {
        return r[i] < r[j];
    });

    SegmentTree<RMQ<>> tree(n);
    tree.modify(0, 0);
    
    REP(i, m) {
        ll m = tree.query(l[o[i]], r[o[i]]);
        if (m == RMQ<>::identify()) continue;

        ll now = tree.get(r[o[i]]);
        tree.modify(r[o[i]], min(now, m + c[o[i]]));
    }

    if (tree.get(n-1) != RMQ<>::identify()) {
        cout << tree.get(n-1) << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
} 




Measured memory_bytes: 3328
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

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

  ll m = N % K;
  ll n = abs(m - K);

  cout << min(m, n) << endl;

}


Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M, P = lr()
# 終了時、T*P枚支払う
graph = [tuple(lr()) for _ in range(M)]

def bellmanford(start, N):
    INF = 10 ** 12
    dist = [-INF] * (N+1) # 1-indexed
    dist[start] = 0
    for i in range(N+N+5):
        for pre, ne, weight in graph:
            if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]:
                dist[ne] = dist[pre] + weight - P
                # n回繰り返してもスコアが更新された場合
                if i > N-1:
                    dist[ne] = INF
    if dist[N] == INF:
        return -1
    else:
        return max(0, dist[N])

answer = bellmanford(1, N)
print(answer)


Measured memory_bytes: 42940
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 1000000000;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second



////////////////////////////////////////////////////////

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

ll H, W;
string s[1010];
ll F[1010][1010];
ll sy, sx, gy, gx; 

void bfs(){
    rep(i, 0, 1010) rep(j, 0, 1010) F[i][j] = INF;

    deque<pair<ll, ll>> qu;
    qu.push_front({sy, sx});
    F[sy][sx] = 0;
    while(!qu.empty()){
        ll y, x;
        y = qu.front().first, x = qu.front().second;
        qu.pop_front();
        rep(i, 0, 4){
            ll ny, nx;
            ny = y + dy[i], nx = x + dx[i];
            if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
            if(s[ny][nx] == '#') continue;
            if(F[ny][nx] <= F[y][x])  continue;
            chmin(F[ny][nx], F[y][x]);
            qu.push_front({ny, nx});
        }
        Rep(i, -2, 2) Rep(j, -2, 2){
            ll ny, nx;
            ny = y + i, nx = x + j;
            if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
            if(s[ny][nx] == '#') continue;
            if(F[ny][nx] <= F[y][x]+1)  continue;
            chmin(F[ny][nx], F[y][x]+1);
            qu.push_back({ny, nx});
        }
    }
}

int main() {
    cin >> H >> W;
    cin >> sy >> sx >> gy >> gx;
    sy--, sx--, gy--, gx--;
    rep(i, 0, H)  cin >> s[i];

    bfs();

    co((F[gy][gx]==INF ? -1 : F[gy][gx]));

    return 0;
}
 
 


Measured memory_bytes: 13544
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
for i in range(1, n):
  if i < k:
    dp[i] = min([ dp[j]+abs(h[j]-h[i]) for j in range(i) ])
  else:
    dp[i] = min( [ dp[i-j-1]+abs(h[i-j-1]-h[i]) for j in range(k) ] )
print(dp[n-1])

Measured memory_bytes: 55264
#include<bits/stdc++.h>
#define N 500050
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
inline void read(int &a){
	int f=a=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=1;ch=getchar();}
	while(ch<='9'&&ch>='0') a=a*10+ch-'0',ch=getchar();
	if(f) a=-a;
}
int n;
LL A,B,C,D;
LL f[N][3];
int main(){
	scanf("%d%lld%lld%lld%lld",&n,&A,&B,&C,&D);
	f[1][0]=C,f[1][1]=D;
	for(int i=2;i<=n;i++) f[i][0]=f[i-1][0]+C,f[i][1]=f[i-1][1]+D;
	for(int i=0;i<=n-1;i++)
		if(f[i][0]-f[n-i-1][1]<=B-A&&B-A<=f[i][1]-f[n-i-1][0]){
			puts("YES");
			return 0;
		}
	puts("NO");
	return 0;
}

Measured memory_bytes: 11904
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
  	cin >> n;
  	vi h(n);
  	rep(i,n) cin >> h[i];
	
  	int temp = 0, ans = 0;
  
  	rep(i,n) {
      	if(temp >= h[i]){
          	temp = h[i];
        }else{
        	ans += h[i] - temp;
          	temp = h[i];
        } 
    }

  	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int A,B,C;
	ll K;
	scan(A);scan(B);scan(C);scan(K);
	if(K%2==0) prin(A-B);
	else prin(B-A);
	return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
        "log"
        "math"
)

func solution(a, b, h, m float64) float64 {
        M := 6 * m
        H := (h / 12 * 360) + (m / 60 * 30)
        log.Printf("H: %v M: %v", H, M)
        A := abs(H, M)
        if A >= 180 {
                A = 360 - A
        }
        log.Print(A)
        log.Print(math.Pow(a, 2))
        log.Print(math.Pow(b, 2))
        return math.Sqrt(math.Pow(a, 2) + math.Pow(b, 2) - 2*a*b*math.Cos(A*(math.Pi/180)))
}

func main() {
        var a, b, h, m int
        fmt.Scan(&a, &b, &h, &m)
        fmt.Println(solution(float64(a), float64(b), float64(h), float64(m)))
}

func abs(x, y float64) float64 {
        if x > y {
                return x - y
        }
        return y - x
}

Measured memory_bytes: 2004
import Control.Applicative

main :: IO ()
main = do
  getLine
  ss <- lines <$> getContents
  putStrLn $ show $ solve ss

solve :: [String] -> Int
solve ss = choose 3 $ filter (/= 0) $ length' ss "MARCH"

choose :: Int -> [Int] -> Int
choose _ []      = 0
choose 1 (n:ns)  = n + choose 1 ns
choose n' (n:ns) = n * (choose (n' - 1) ns) + choose n' ns

length' :: [String] -> String -> [Int]
length' _ []      = []
length' ss (c:cs) = (length (filter' (== c) ss)) : (length' (filter' (/= c) ss) cs)
  where
    filter' v = filter (v . head)


Measured memory_bytes: 39164