akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define MAX_N 30005

int n;
int m;
int t[MAX_N];

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    for(int i=1;i<=n;i++){
      scanf("%d",&t[i]);
      t[i]=(t[i]%m+t[i-1])%m;
    }
    
    set<int> A;
    set<int> :: iterator it;
    int ans=0;
    A.insert(0);
    
    for(int i=1;i<=n;i++){
      it=A.upper_bound(t[i]);
      if(it==A.end()){
        it=A.lower_bound(0);
        ans=max(ans,t[i]-(*it));
      }else{
        ans=max(ans,m+t[i]-(*it));
      }
      A.insert(t[i]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2572
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, c[1000], a = 0, b = 0;
  cin >> N;

  for (int i = 0; i < N; i++) cin >> c[i];

  sort(c, c + N);

  for (int i = 0; i < N; i++) {
    if (i%2 == 0) {
      a += c[i];
    } else {
      b += c[i];
    }
  }
  printf("%d\n", abs(a-b));
}


Measured memory_bytes: 256
first = str(input()).split(' ')
n = int(first[0])
x = int(first[1])
y = int(first[2])

dist = [0 for i in range(1,n)]

for i in range(1, n):
    for j in range(i+1, n+1):
        k = min(j-i, abs(i-x) + 1 + abs(y-j))
        dist[k-1] += 1
    
print(*dist, sep='\n')

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	int a, b = 0;
	char k;
	int n;
	cin >> n;
	while (cin >> k) {
		if (k == 'R')a++;
		else b++;
	}
	if(a>b)cout<<"Yes"<<endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(a, b, c, d) = sc.nextLine.split(" ").map(_.toInt)
    val areaFirst = a * b
    val areaSecond = c * d
    if (areaFirst > areaSecond) println(areaFirst)
    else println(areaSecond)
  }
}


Measured memory_bytes: 27324
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define T 100005
bool ch[31][T];
int a[T];

int main(void){
    int N,C;
    cin>>N>>C;
    rep(_,N){
        int s,t,c;
        cin>>s>>t>>c;
        for(int i=s;i<=t;i++){
            ch[c][i]=true;
        }
    }
    int res=0;
    rep(k,C+1){
        rep(i,T){
            if(ch[k][i]){
                a[i]++;
                res = max(a[i],res);
            }
        }
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

bitset<MAXn> isp;
vector<ll> prime;
ll idx;
ll cnt[MAXn],id[MAXn];
void build(){
  for (ll i=2;i<MAXn;i++) {
    if (!isp[i]) {
      prime.eb(i);
      id[i] = idx++;
    }
    for (ll j=0;i*prime[j]<MAXn;j++) {
      isp[i*prime[j]] = true;
      if (i % prime[j] == 0) break;
    }
  }
}
int main(){
  IOS();
  build();
  ll n;
  cin >> n;
  for (ll i=2;i<=n;i++) {
    ll tmp = i;
    for (ll j=2;j*j<=tmp;j++) {
      if (tmp % j == 0) {
        while (tmp % j == 0) {
          tmp /= j;
          cnt[id[j]]++;
        }
        debug(tmp);
      }
    }
    if (tmp != 1) cnt[id[tmp]]++;
  }
  ll ans = 1;
  REP (i,MAXn) ans = (ans * (cnt[i]+1)) % MOD;
  cout << ans << endl;
}


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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	string a, b;
	cin >> a >> b;
	cout << "DH"[(b[0] == 'H') ^ (a[0] == 'D')] << endl;
}


Measured memory_bytes: 256
import Control.Applicative

noPrint :: String
noPrint = "DO_NOT_PRINT_THIS"

splitAt3 :: Int -> Int -> [a] -> [[a]]
splitAt3 a b x = [f, m, l]
    where
        (f, ml) = splitAt a x
        (m, l) = splitAt (b - a + 1) ml

doCommand :: [String] -> String -> (String, String)
doCommand (c : a1 : a2 : ar) s
    | c == "print"   = (m, s)
    | c == "reverse" = (noPrint, (f ++ (reverse m) ++ l))
    | c == "replace" = (noPrint, (f ++ p ++ l))
        where
            [a, b] = map read [a1, a2]
            [f, m, l] = splitAt3 a b s
            p = concat ar

outputs :: String -> [[String]] -> [String]
outputs _ [] = []
outputs s (l : ls) = o : outputs r ls
    where (o, r) = doCommand l s

main :: IO ()
main = do
    s <- getLine
    _ <- getLine
    putStr =<< (unlines . filter (/= noPrint). outputs s . map words . lines) <$> getContents
    

Measured memory_bytes: 5548
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn dis(a: &(f64, f64), b: &(f64, f64)) -> f64 {
    ((a.0 - b.0).powf(2.0) + (a.1 - b.1).powf(2.0 )).sqrt()
}
fn main() {
    input!{
        n: usize,
        towns: [(f64, f64); n],
    }
    let mut sum = 0.0;
    for i in 0..n {
        for j in 0..n {
            if i == j { continue; }
            sum += dis(&towns[i], &towns[j]);
        }
    }
    println!("{:.10}", sum / n as f64);
}


Measured memory_bytes: 4352
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
white_count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            white_count += 1

d = [[float("inf")] * w for _ in range(h)]

que = deque()
que.append((0, 0))
d[0][0] = 1
while que:
    x, y = que.popleft()
    for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
        nx = x + dx
        ny = y + dy
        if 0 <= nx < w and 0 <= ny < h and s[ny][nx] == '.' and d[ny][nx] == float("inf"):
            que.append((nx, ny))
            d[ny][nx] = d[y][x] + 1

res = d[h-1][w-1]
if res == float("inf"):
    print(-1)
else:
    print(white_count - res)


Measured memory_bytes: 9320
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}


int main() {
	ll N;
	cin >> N;
	ll ans = 0;
	vi H(N);

	ll h; cin >> h;
	ll n = 0;
	repa(i, 1, N) {
		ll t; cin >> t;
		if (h >= t) {
			n++;
		}
		else {
			n = 0;
		}
		h = t;
		H[i] = n;
		if (ans < n) {
			ans = n;
		}
	}


	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
	int a, b;
	char op;
	while(true){
		cin >> a >> op >> b;
		if(op=='+'){
			cout << a+b << "\n";
		}
		else if(op=='-'){
			cout << a-b << "\n";
		}
		else if(op=='*'){
			cout << a*b << "\n";
		}
		else if(op=='/'){
			cout << a/b << "\n";
		}
		else{
			break;
		}
	}
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr ll INF = 1001001001001001001;
ll N, A[2100];
ll I[2100];
ll dp[2100][2100];

ll rec(int n, int m, int s){
    if(s == N){
        return 0;
    }

    if(dp[n][m] != -INF){
        return dp[n][m];
    }

    dp[n][m] = std::max(A[I[s]] * (I[s] - n) + rec(n + 1, m, s + 1), // +1
                        A[I[s]] * ((N - 1 - m) - I[s]) + rec(n, m + 1, s + 1)); // -1

    return dp[n][m];
}

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

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> A[i];
  }

  std::iota(I, I + N, 0);
  std::sort(I, I + N, [&](int i, int j){
                          if(A[i] != A[j]){
                              return A[i] < A[j];
                          }
                          return i < j;
                      });
  std::reverse(I, I + N);
  

  std::fill(&dp[0][0], &dp[0][0] + 2100 * 2100, -INF);
  
  ll res = rec(0, 0, 0);
  std::cout << res << std::endl;
}


Measured memory_bytes: 38184
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple2<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn read_touple3<T: std::str::FromStr + Copy>() -> (T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

fn main() {
  let (n, m) = read_touple2::<usize>();

  let mut g = Vec::new();
  for _ in 0..m {
    let i = read_touple3::<usize>();
    g.push(i);
  }

  let (dist, paths) = warshal_floyd_path(n, &g, false);

  // for v in &dist {
  //   println!("{:?}", v);
  // }
  // println!("");

  // for v in &paths {
  //   println!("{:?}", v);
  // }

  // for i in 0..n {
  //   for j in 0..n {
  //     let shortest_path = path_print(&paths, i, j);
  //     print!("{} to {}: ", i, j);
  //     println!("{:?}", shortest_path);
  //     // for i in 0..shortest_path.len() {
  //     //   print!("{} -> ", shortest_path[i] + 1);
  //     // }
  //   }
  // }

  let mut p = vec![vec![0; n]; n];
  for i in 0..n-1 {
    for j in i+1..n {
      let shortest_path = path_print(&paths, i, j);
      for k in 0..shortest_path.len()-1 {
        let from = shortest_path[k];
        let to = shortest_path[k+1];
        p[from][to] = 1;
      }
    }
  }
  let mut ans = 0;
  for i in 0..n-1 {
    for j in i+1..n {
      if p[i][j] > 0 {
         ans += 1;
      }
    }
  }

  println!("{}", m-ans);
}


//
// O(V^3)
fn warshal_floyd_path(
  n: usize,
  v: &Vec<(usize, usize, usize)>,
  direct: bool,
) -> (Vec<Vec<usize>>, Vec<Vec<usize>>) {
  let mut dist = vec![vec![std::usize::MAX / 2; n]; n];
  let mut next = vec![vec![0; n]; n];
  // init
  for &(x, y, c) in v {
    dist[x-1][y-1] = c;
    if !direct {
      dist[y-1][x-1] = c;
    }
  }

  // 復元用のマトリックスの初期化
  for i in 0..n {
    for j in 0..n {
      next[i][j] = j;
    }
  }

  for k in 0..n {
    for i in 0..n {
      for j in 0..n {
        if dist[i][j] > dist[i][k] + dist[k][j] {
          dist[i][j] = dist[i][k] + dist[k][j];
          next[i][j] = next[i][k];
        }
      }
    }
  }
  (dist, next)
}

// 経路復元用のの関数
// O(V)
fn path_print(paths: &Vec<Vec<usize>>, start: usize, goal: usize) -> Vec<usize> {
  let mut res = Vec::new();
  let mut cur = start;
  while {
    cur != goal
  } {
    res.push(cur);
    cur = paths[cur][goal];
  }
  res.push(goal);
  //println!("{:?}", res);
  res
}

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

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

    int y=min(a,b);
    int z=max(a,b);

    if(y==1 && z==3)
        cout<<2<<endl;

    else if(y==1 && z==2)
        cout<<3<<endl;

    else
        cout<<1<<endl;


}


Measured memory_bytes: 256
N, L = map(int, input().split())
taste = [L + i  for i in range(N)]

min = abs(taste[0])
sum = taste[0]
index = 0
for i in range(1, N):
    if abs(taste[i]) < min: 
        index = i
        min = abs(taste[i])
    sum += taste[i]
sum = sum - taste[index]
print(sum)

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.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;
}

// {s = digit, c = number}
vector<pair<int, int>> conds;

vector<int> calc_digits(int x) {
    if (x == 0) {
        return {0};
    }

    vector<int> res;
    while (x != 0) {
        int d = x % 10;
        res.push_back(d);
        x /= 10;
    }
    reverse(res.begin(), res.end());
    return res;
}

int solve(const int N, const int M) {
    for (int i = 0; i < 1000; i++) {
        vector<int> digits = calc_digits(i);
        if ((int) digits.size() != N) continue;

        bool ok = true;
        for (auto &cond : conds) {
            if (digits[cond.first] != cond.second) {
                ok = false;
                break;
            }
        }
        if (ok) {
            return i;
        }
    }

    return -1;
}

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

    conds.resize(M);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        conds[i] = {s, c};
    }

    int ans = solve(N, M);
    cout << ans << endl;

    return 0;
}


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

#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*****************************************************START******************************************************************/


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1 ;
	 //cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		int n , x = 1; cin >> n; 
		while(n>x*1000){
			x++;
		}
		cout << x*1000 - n << endl;
		
	}
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  if(a!="1"&&b!="1"){
    cout << "1" << endl;
  }else if(a!="2"&&b!="2"){
    cout << "2" << endl;
  }else{
    cout << "3" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
ll a[1000002];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,k,ans;
	cin>>k>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	ans=a[n-1]-a[0];
	ll j=0;
	for (int i = 1; i < n; ++i)
	{
		ans=min(ans, a[j++]+k-a[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 27008
#include <stdio.h>
int main(){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  while(A>0 && C>0){
    C=C-B;
    A=A-D;
  }
  if(C<1) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 1736
#include<string>
#include<iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int A[N];
    int B[N];
    int C[N];
    for(int i=0;i<N;++i){
        cin >> A[i] ;
    }
    for(int i=0;i<N;++i){
        cin >> B[i] ;
    }
    for(int i=0;i<N-1;++i){
        cin >> C[i] ;
    }
    int m=0;
    int b=-2;
    for(int i=0;i<N;++i){
        m+=B[A[i]-1];
        if(b+1==A[i]){
            m+=C[A[i]-2];
        }
        b=A[i];
    }
    cout << m;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
using namespace std;

int InsertionSort(int *array, int size, int span);
string JoinWith(int *array, int size, const char *joiner);

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

	int array[n];
	for (int i = 0; i < n; i++) {
		cin >> array[i];
	}

	// Start shell sort.
	stack<int> span_stack;
	for (int i = 1; i <= n; i = 3 * i + 1) {
		span_stack.push(i);
	}

	int times_of_inssort = span_stack.size();
	int spans[times_of_inssort];
	int index = 0;
	int count = 0;
	while(!span_stack.empty()) {
		int span = span_stack.top();
		span_stack.pop();
		count += InsertionSort(array, n, span);
		spans[index++] = span;
	}

	cout << times_of_inssort << endl;
	cout << JoinWith(spans, times_of_inssort, " ") << endl;
	cout << count << endl;
	cout << JoinWith(array, n, "\n") << endl;
	return 0;
}

int InsertionSort(int *array, int size, int span) {
	int count = 0;
	for (int i = span; i < size; i++) {
		int current = array[i];
		int j = i - span;
		while (j >= 0 && array[j] > current) {
			array[j + span] = array[j];
			j -= span;
			count++;
		}
		array[j + span] = current;
	}
	return count;
}

string JoinWith(int *array, int size, const char *joiner) {
	ostringstream oss;
	for (int i = 0; i < size - 1; i++) {
		oss << array[i] << joiner;
	}
	oss << array[size - 1];
	return oss.str();
}

Measured memory_bytes: 24468
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define N 1000010
#define mo 1000000007ll
int jc[N],ij[N],n,m,k,p3[N],ans;
int c(int y,int x){
	return jc[y]*ij[y-x]%mo*ij[x]%mo;
}
int qp(int x,int y){
	int r=1;
	for(;y;y>>=1,x=x*x%mo)
		if(y&1)r=r*x%mo;
	return r;
}
signed main(){
	jc[0]=ij[0]=p3[0]=1;
	for(int i=1;i<N;i++){
		jc[i]=jc[i-1]*i%mo;
		p3[i]=p3[i-1]*3%mo;
	}
	ij[N-1]=qp(jc[N-1],mo-2);
	for(int i=N-1;i;i--)
		ij[i-1]=ij[i]*i%mo;
	cin>>n>>m>>k;
	n--;
	if(m<k)swap(m,k);
	int j=1;
	for(int i=0;i<=m+k;i++){
		ans=(ans+c(n+i,n)*p3[m+k-i]%mo*j%mo)%mo;
		if(i<k)j=j*2%mo;
		else if(i>=m)j=(j*2-c(i,k)-c(i,i-m)+mo)%mo;
		else j=(j*2-c(i,k))%mo;
		j=(j+2*mo)%mo;
	}
	cout<<ans;
}

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

	cin >> n;
	long long ans=0;
	if(!(n%2)){
		long long t=10;
		while(n>=t){
			ans+=n/t;
			t*=5;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N;
vector<int> G[MAXN];

void input()
{
    read(N);
    for (int i = 1; i < N; ++i) {
        int u, v;
        read(u); read(v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
}

int calc(int u, int f)
{
    int ret = 0;
    for (int i = 0; i < SZ(G[u]); ++i) {
        int v = G[u][i];
        if (v == f)
            continue;
        ret ^= calc(v, u) + 1;
    }
    return ret;
}

void solve()
{
    puts(calc(1, 0) ? "Alice" : "Bob");
}

int main()
{
#ifdef __DEBUG
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 宁可枝头抱香死，何曾吹落北风中。
//     -- 郑思肖《画菊》


Measured memory_bytes: 10368
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

LL MOD = 1000000007;
PII xy[55];

int main() {
	int n;
	cin >> n;
	int ret = n;
	REP(i, n)scanf("%d%d", &xy[i].first, &xy[i].second);
	REP(i, n) {
		FOR(j, i + 1, n) {
			int dy = xy[i].second - xy[j].second;
			int dx = xy[i].first - xy[j].first;
			int tmp = n;
			REP(k, n) {
				REP(l, n) {
					if (k == l)continue;
					int ddy = xy[k].second - xy[l].second;
					int ddx = xy[k].first - xy[l].first;
					if ((ddy == dy) && (ddx == dx))tmp--;
				}
			}
			ret = min(ret, tmp);
		}
	}
	printf("%d\n", ret);
	return 0;
}

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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
const int INF = 1 << 28;



int main() {
    int n ; cin >> n;
    cout << n*n*n << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(ans);
    }

}


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

int main() {
  int w, h;
  cin >> h >> w;
  
  string l;
  rep(i,h) {
    cin >> l;
    cout << l << endl;
    cout << l << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(4);
  vector<int> b={1,4,7,9};
  for(int i=0;i<4;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  if(a==b)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	unsigned long long n=50,k,x,cnt;
	scanf("%lld",&k);
	x=n+k/n-1;cnt=k%n;
	cout<<n<<endl;
	x-=cnt;
	for(int i=1;i<=n;i++)
	if(cnt>0){cout<<x+n<<" ";cnt--;}
	else cout<<x<<" ";
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = 2147483647;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int p, i, k, n;
	cin >> n >> k;
	cout << (n + k - 3) / (k - 1) << endl;
	return 0;
}


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

bool paircompare(const pair<int, int>& first, const pair<int, int>& second)
{
    return first.first < second.first;
}

int main()
{
    int n, m;
    long long ans = 0;
    cin >> n >> m;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++){
        scanf("%d%d", &a[i].first, &a[i].second);
    }
    sort(a.begin(), a.end(), paircompare);
    for(int i = 0; i < n && m > 0; i++){
        if(a[i].second <= m) {
            ans += (long long)a[i].first * a[i].second;
            m -= a[i].second;
        }
        else {
            ans += (long long)a[i].first * m;
            m = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int d;
    cin >> d;
    int c[26];
    for(int i = 0; i < 26; i++) cin >> c[i];
    int s[400][26];
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++) cin >> s[i][j];
    }
    int last1[26];
    for(int i = 0; i < 26; i++) last1[i] = -1;
    int ans = 0;
    for(int i = 0; i < d; i++){
        int l = 0;
        int u = 0;
        for(int j = 0; j < 26; j++){
            int last2[26];
            for(int k = 0; k < 26; k++) last2[k] = last1[k];
            last2[j] = i;
            int t = ans;
            t += s[i][j];
            for(int x = i + 1; x < d; x++){
                int r = 0;
                for(int y = 0; y < 26; y++){
                    if(s[x][y] + (x - last2[y]) * c[y] > s[x][r] + (x - last2[r]) * c[r]) r = y;
                }
                last2[r] = x;
                t += s[x][r];
                for(int y = 0; y < 26; y++) t -= (x - last2[y]) * c[y];
            }
            if(t > u){
                u = t;
                l = j;
            }
        }
        cout << l + 1 << endl;
        last1[l] = i;
        ans += s[i][l];
        for(int j = 0; j < 26; j++) ans -= (i - last1[j]) * c[j];
    }
}


Measured memory_bytes: 3680
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>

//#define DEBUG

using namespace std;

int main(){
    int N, M;
    int ans=0;

    cin >> N >> M;

    vector<pair<int, int> > pairs(M);
    for(int i=0; i<M; i++){
#ifdef DEBUG
        cout << "M = " << M << ", i=" << i << endl;
#endif
        int ta, tb;
        cin >> ta >> tb;
        pairs[i] = make_pair(ta, tb);
    }

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

    int prev_f = -1;
    int tmax = -1;
    for(int i=0; i<M; i++){

        // 同じ始動の橋なのでスルー
        if(pairs[i].first == prev_f){
            continue;
        }

        // 新規橋はいらない
        if(pairs[i].first <= tmax){
            // 橋を左に移動
            if(pairs[i].second - 1 < tmax){
                tmax = pairs[i].second - 1;
            }
        // 新規橋を作成
        }else{
            tmax = pairs[i].second - 1;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
/*input
3
-2 5 -1
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 60
#define INF 0x3f3f3f3f

int n , x[MAX];
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	int big = 1;
	REP(i , 1 , n + 1) if(abs(x[i]) > abs(x[big])) big = i;
	vector<PII> ans;
	if(x[big] < 0){
		REP(i , 1 , n + 1) if(x[i] > 0) ans.pb(big , i) , x[i] += x[big];
		RREP(i , n - 1 , 1) ans.pb(i + 1 , i);
	}
	else {
		REP(i , 1 , n + 1) if(x[i] < 0) ans.pb(big , i) , x[i] += x[big];
		REP(i , 2 , n + 1) ans.pb(i - 1 , i);
	}
	cout << ans.size() << endl;
	for(auto to : ans) cout << to.A << " " << to.B << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate


if __name__ == '__main__':
    # ??????????????\???
    for line in sys.stdin:
        data = [int(x) for x in line.strip().split(',')]
        # data = [1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 50, 50]

        # ??????????????????
        v1 = data[-2]
        v2 = data[-1]
        data = data[:-2]

        # ??????????????¢0??¨????????????????????§????´?????????¢????¨??????????
        acc = list(accumulate(data))
        total_distance = acc[-1]  # ???????????§????????????????????¢
        meeting_point = total_distance * v1 / (v1 + v2)  # ???????????????????????????????????????????????§???v1??¨v2????????????????????´?????§????????????

        # acc[]??????i+1????????????????????????????????????????????????????????¢?????\??£??????????????§??????????????¢?????????????????????????????\??????????????¨???????????????
        ans = 1
        for i, distance in enumerate(acc):
            if distance >= meeting_point:
                ans = i + 1
                break

        # ???????????¨???
        print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> t(n),a(n);
  REP(i,n) cin >> t[i] >> a[i];

  ll T = 1, A = 1;
  REP(i,n) {
    ll div = max((T+t[i]-1)/t[i], (A+a[i]-1)/a[i]);
    T = t[i]*div; A = a[i]*div;
  }
  cout << T + A << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int H,W,K,M=1e9+7,dp[101][9],i,j,k,l;
bool flag;
int main(){
	cin>>H>>W>>K;
	dp[0][0]=1;
	for(i=0;i<H;++i){
		for(j=0;j<W;++j){
			for(k=0;k<1<<(W-1);++k){//横線の候補は2^{W-1}通りある
				flag=true;
				for(l=0;l<W-2;++l){
					if(((k>>l)&1)&&((k>>(l+1))&1)){//連続二箇所で横棒があったら
						flag=false;//あみだくじの条件を満たさない
					}
				}
				if(flag){
					//下左と移動する場合
					if(j>=1&&((k>>(j-1))&1)){//下左と移動するためには2本目移行にいないといけない、かつ左下の位置から右方向に横棒がないといけない
						dp[i+1][j-1]+=dp[i][j];
						dp[i+1][j-1]%=M;
					}
					//下右と移動する場合
					else if(j<=W-2&&((k>>j)&1)){//下右と移動するためにはW-1本目までにいないといけない、かつ真下の位置から右方向に横棒がないといけない
						dp[i+1][j+1]+=dp[i][j];
						dp[i+1][j+1]%=M;
					}
					//真下へ移動する場合
					else{
						dp[i+1][j]+=dp[i][j];
						dp[i+1][j]%=M;
					}
				}
			}
		}
	}
	cout<<dp[H][K-1]<<endl;
	return 0;
}


Measured memory_bytes: 256
class Solution:
    def solve(self, a: int, b: int) -> int:

        if 1 <= a <= 9 and 1 <= b <= 9:
            return a*b
        else:
            return -1


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))


Measured memory_bytes: 2940
#coding:utf-8

n,k = map(int,input().split())

sunuke = ["{}".format(i) for i in range(1,n+1)]

for i in range(k):
    d = int(input())
    a = input().split()
    for i in a:
        if i in sunuke:
            sunuke.remove(i)

ans = len(sunuke)

print("{}".format(ans))

Measured memory_bytes: 9192
import sys
import numpy as np


def solve(sequence):

    sequence.sort()

    max_v = sequence[-1]

    dp = [True] * (max_v + 1)

    previous = -1
    for v in sequence:
        if v == previous:
            dp[v] = False
            continue

        previous = v

        if not dp[v]:
            continue

        for iv in range(2 * v, max_v+1, v):
            dp[iv] = False

    count = 0
    for v in sequence:
        if dp[v]:
            count += 1

    return count


# if sys.argv[-1] == 'ONLINE_JUDGE':
#     from numba.pycc import CC
#     cc = CC('my_module')
#     cc.export('main', '(i8[::1])')(solve)
#     cc.compile()
#     exit()
#
#
# from my_module import solve


def main():
    _ = input()
    sequence = np.array(input().split(), np.int64)
    print(solve(sequence))


if __name__ == "__main__":
    main()


Measured memory_bytes: 50416
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"s=input()\n"
"d='BDEFGHIJKLMNOPQRSTUVWXYZ'\n"
"if s[0]=='A' and s.count('A')==1 and s.count('C')==1 and s[2:-1].count('C')==1:\n"
"    for t in d:\n"
"        if t in s:\n"
"            break\n"
"    else:\n"
"        print('AC')\n"
"        exit()\n"
"print('WA')\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1
print(ans)

Measured memory_bytes: 3060
import copy
n,m=map(int,input().split())
k=[[] for _ in range(n)]

for i in range(m):
    for j in [int(_) for _ in input().split()][1:]:
        k[j-1].append(i)
#偶数回はFalse、奇数回はTrue
p=[bool(int(i)) for i in input().split()]

#print(k)
#print(p)
p2=[False]*m
c=0
for i in range(2**n):
    l=format(i,"0>10b")[-n:]
    #print(l)
    t=copy.deepcopy(p)
    #print(t)
    #print(n)
    for j in range(n):
        if l[j]=="1":
            for h in k[j]:
                t[h]= not t[h]
    #print(t)
    if t==p2:
        c+=1
print(c)


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

using namespace std;

using ll = long long;

const string s1 = "MARCH";

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> cnt(5, 0);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 5; j++) {
            if (s[0] == s1[j]) {
                cnt[j]++;
                break;
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

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

  vector<int> a(n);

  for (auto &i : a) {
    cin >> i;
  }

  vector<bool> winning(k + 1, false);

  for (auto i = 0; i <= k; ++i) {
    for (auto j = 0; j < n; ++j) {
      if (!winning[i] && i + a[j] <= k) {
        winning[i + a[j]] = 1;
      }
    }
  }

  if (winning[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int N = 0;
    scanf("%d", &N);
    char S[N];
    char T[N];

    scanf("%s %s", S, T);

    for (int i = 0; i < N; i++){
        printf("%c", S[i]);
        printf("%c", T[i]);
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    int ans;
    for(int i=0;i<21;++i) {
        if(a+(i-1)*(a-1)>=b) {
            ans=i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sn = new Scanner(System.in);
		while(true){
			Slot slot = new Slot(sn.nextInt(), sn.nextInt(), sn.nextInt(), sn.nextInt(), sn.nextInt(), sn.nextInt());
			if(slot.isEnd()) break;
			System.out.println(100 + slot.getBenefit() - slot.getLost());
		}
		
	}
}

class Slot{
	int b, r, g, c, s, t;
	Slot(int b, int r, int g, int c, int s, int t){
		this.b = b;
		this.r = r;
		this.g = g;
		this.c = c;
		this.s = s;
		this.t = t;
	}
	
	int getLost(){
		return  (t-5*b-3*r-s)*3 + (5*b+3*r)*2;
	}
	
	int getBenefit(){
		return b*15+r*15+g*7+c*2 + (b*5+r*3)*15;
	}
	
	boolean isEnd(){
		return b+r+g+c+s+t == 0;
	}
}

Measured memory_bytes: 20888
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

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

  long long tmp;

  long long result;

  tmp = N / K;
  result = tmp * tmp * tmp;

  if(K % 2 == 0){
    if((N % K) >= (K/2)){
      tmp++;
    }
    result += tmp * tmp * tmp;
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())

answer = deque()
for i in range(n):
    command = input()
    if " " in command:
        command, key = command.split()
    
    if command == "insert":
        answer.appendleft(key)
    elif command == "delete":
        if key in answer:
            answer.remove(key)
    elif command == "deleteFirst":
        answer.popleft()
    elif command == "deleteLast":
        answer.pop()

print(*answer)


Measured memory_bytes: 69736
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=1e5+1e2;
int n,k;
int Ans,L,R;

inline void file() {
	freopen("ARC099C.in","r",stdin);
	freopen("ARC099C.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read(); k=read();
	For (i,1,n) {
		int x=read();
		if (x==1) L=i-1,R=n-i;
	}
	Ans+=L/(k-1)+R/(k-1);
	L=(L+R)-Ans*(k-1);
	Ans+=L/k;
	Ans+=(L%k!=0);
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main() {
    int n, p;
    string s;
    cin >> n >> p;
    cin >> s;
    reverse(ALL(s));
    if (p == 2) {
        ll cnt = 0, ans = 0;
        for (int i = 0; i < n;i++){
            int t = s[i] - '0';
            if (t % 2 == 0) cnt++;
            ans += cnt;
        }
        cout << ans << endl;
        return 0;
    }
    if (p == 5) {
        ll cnt = 0, ans = 0;
        for (int i = 0; i < n;i++){
            int t = s[i] - '0';
            if (t % 5 == 0) cnt++;
            ans += cnt;
        }
        cout << ans << endl;
        return 0;
    }
    ll cnt[p] = {};
    cnt[0] = 1;
    ll ans = 0;
    int now = 0;
    int d = 1;
    for (int i = 0; i < n; i++) {
        int t = s[i] - '0';
        now = (d * t + now) % p;
        ans += cnt[now];
        cnt[now]++;
        d *= 10;
        d %= p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool isPerfectSquare(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
} 
int main(int argc, char const *argv[])
{    
   
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n;
    cin>>n;
    while(n>=1){
        if(isPerfectSquare(n)){
            cout<<n<<endl;break;
        }
        n--;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 5) {
        cout << 0;
    }
    else if (a >= 5 and a <= 12) {
        cout << (b / 2);
    }
    else {
        cout << b;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef pair<ll, ll> pll;
#define fi first
#define se second
#define pb push_back
#define ppb pop_back

int main() {
  ll n,a[200010];
  scanf("%lld", &n);
  for (ll i=0;i<n;++i) {
    scanf("%lld", a+i);
  }
  sort(a, a+n);
  reverse(a, a+n);
  multiset<ll> ms;
  ll ans = a[0];
  ms.insert(a[1]);
  ms.insert(a[1]);
  for (ll i=2;i<n;++i) {
    ans += *ms.rbegin();
    ms.erase(ms.find(*ms.rbegin()));
    ms.insert(a[i]);
    ms.insert(a[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14644