akhauriyash/Code-Regression huggingface dataset:
from heapq import heappop,heappush
N,M = map(int,input().split())
job = [list(map(int,input().split())) for _ in range(N)]
job.sort()
H = []
ans = 0
i = 0
for x in range(1,M + 1):
    while i < N and job[i][0] == x:
        add = [-job[i][1],job[i][0]]
        heappush(H,add)
        i += 1
    if len(H) != 0:
        salary,k = heappop(H)
        ans += -1 * salary
print(ans)

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

using namespace std;

using ll=long long;

bool isprime(int num){
  if(num<2)return false;
  else if(num==2)return true;
  else if(num % 2 == 0)return false;

  int sqrtnum=sqrt(num);
  for(int i=3;i<=sqrtnum;i+=2){
    if(num%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  int n;
  cin>>n;
  ll q[100001]={0};
  for(int i=0;i<n;++i){
    cin>>q[i];
  }
  ll dp[100001]={0};
  if(isprime(q[0]))dp[0]=1;
  if(isprime(q[1]))if(dp[0]==1 && q[0]<q[1])dp[1]=1;
  for(int i=2;i<n;++i){
    if(!isprime(q[i]))continue;
    if(q[i-1]<q[i])dp[i]+=dp[i-1];
    if(q[i-2]<q[i])dp[i]+=dp[i-2];
    dp[i]%=1000000007;
  }
  if(n==1)cout<<dp[0]<<endl;
  else cout<<(dp[n-2]+dp[n-1])%1000000007<<endl;
}


Measured memory_bytes: 4664
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        v: [i32; n],
        c: [i32; n],
    }
    let ans= v.iter().zip(c.iter()).filter(|&x| x.0 - x.1 > 0).fold(0, |acc, x| acc + x.0 - x.1);
    println!("{}", ans);
}


Measured memory_bytes: 4352
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 700;
    for(char c : s){
        if(c=='o'){
            ans += 100;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
ll lcm(ll A, ll B) {
    return A / gcd(A, B) * B;
}


int multiple(int l, int r, int d) {
    return (r-1)/d - (l-1)/d;
}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int A,B,C,D; cin>>A>>B>>C>>D;

    // [A, B]
    // x%C != 0 and x%D != 0
    int cmult = multiple(A, B+1, C);
    int dmult = multiple(A,  B+1, D);
    int lc = lcm(C, D);
    int cdmult = multiple(A, B+1, lc);

    int ans = B-A+1 - cmult - dmult + cdmult;

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    string str[] = {"AC", "WA", "TLE", "RE"};
    vector<int> cnt(4, 0);
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        for(int j=0;j<4;j++){
            if(s == str[j]) cnt[j]++;
        }
    }
    for(int j=0;j<4;j++){
        cout << str[j] << " x " << cnt[j] << endl;
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
using namespace std;
 
class Dice{
public:
    long r[6];
    Dice(){};
    void roll(long a, long b, long c, long d){swap(r[a], r[b]);swap(r[b], r[c]);swap(r[c], r[d]);}
    void spin(char c){if (c == 'W') roll(0, 2, 5, 3); else roll(0, 1, 5, 4);}
};
 
int main(){
    char SWS[8]={"NNNWNNN"};
    int n;
    cin >> n;
    vector<Dice> D(n);
    for (int i = 0; i < n ; i++) for (int j = 0; j < 6; j++) cin >> D[i].r[j];
    for (int i = 0; i < n - 1; i++){
        for (int j = i + 1; j < n; j++){
            for (int k = 0; k < 8; k++){
                if (D[i].r[1] == D[j].r[1]) break;
                D[j].spin(SWS[k]);
            }
            for (int k = 0; k < 4; k++){
                int ans = 0;
                for (int l = 0; l < 6; l++) if (D[i].r[l] == D[j].r[l]) ans++;
                if (ans == 6){cout << "No" << endl; return 0;}
                D[j].spin('W');
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1196
import Control.Applicative
import Control.Monad

rInt s = read s :: Int

checkNum x = mod x 3 == 0
include3 x 
	| x==0 = False
	| mod x 10 == 3 = True
	| otherwise = include3 $ div x 10

main  = do
	n <- readLn
	putStrLn $ unwords $ "" : (map show $ filter f [1..n])
		where
			f x = or $ [include3, checkNum] <*> [x]

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

pair<long long, int> dfs(int cur, vector<vector<int> > &g, vector<bool>& used, vector<long long>& a){

    pair<long long, int> res(a[cur], cur);
    for(auto to : g[cur]){
        if(!used[to]){
            used[to] = true;
            pair<long long, int> tmp = dfs(to, g, used, a);
            if(res.first > tmp.first){
                res = tmp;
            }
        }
    }

    return res;
}

int main(){

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

    vector<long long> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int> > g(n);
    for(int i = 0; i < m; i++){

        int x, y; cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    if(m == n - 1){
        return !puts("0");
    }

    if(n < 2*(n - m - 1)){
        return !puts("Impossible");
    }

    set<int> S;                  //使った頂点集合
    vector<bool> used(n, false);
    long long ans = 0;
    int cnt = 0;                 //初期状態の木の個数
    for(int i = 0; i < n; i++){
        if(!used[i]){
            used[i] = true;
            pair<long long, int> p = dfs(i, g, used, a);
            ans += p.first;
            S.insert(p.second);
            cnt++;
        }
    }

    priority_queue<long long> pq;
    for(int i = 0; i < n; i++){
        if(S.find(i) == S.end()) pq.push(-a[i]);
    }
    //cout << cnt << endl;
    for(int i = 0; i < 2 * (n - m - 1) - cnt; i++){
        //cout << "error" << endl;
        ans += -pq.top();
        pq.pop();
    }

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

Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  if (k == 1) cout<<0<<endl;
  else cout<<n-k<<endl;
  return 0;
}






















Measured memory_bytes: 256
s = input()
ans = 'WA'

if s[0] == 'A':
    if s[2:-1].count('C') == 1:
        index = s[2:-1].find('C') + 2
        if s[1:index].islower() and s[index + 1:].islower():
            ans = 'AC'
print(ans)

Measured memory_bytes: 8976
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <climits>
using namespace std;

#define rep(i,beg,end)   for (int i=(beg);i<(end);i++)
#define rrep(i,beg,end)   for (int i=(beg);i>=(end);i--)
#define all(cont)           begin(cont), end(cont)
#define INFMAX                   LLONG_MAX
#define INFMIN                   LLONG_MIN
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef list<ll> li;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);


ll right(ll d[], int n, int k, ll v)
{
    if (k < 0) return 0;
    else if (k == 0 || n == 0) return v;

    ll m = v;
    ll t = d[n - 1];
    m = max(right(d, n - 1, k - 1, v + t), m);
    if (t < 0) m = max(right(d, n - 1, k - 2, v), m);
    return m;
}

ll left(ll d[], int n, int k, ll v)
{
    if (k < 0) return 0;
    else if (k == 0 || n == 0) return v;

    ll m = v;
    ll t = d[0];
    m = max(left(d+1, n - 1, k - 1, v + t), m);
    if (t < 0) m = max(left(d+1, n - 1, k - 2, v), m);
    return max(right(d, n, k, v), m);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    const int N_MAX = 50;
    ll d[N_MAX];
    rep(i, 0, n)
    {
        cin >> d[i];
    }
    if (n * 2 <= k) {
        cout << accumulate(d, d + n, 0LL, [](ll acc, ll v) {return acc + max(0LL, v); }) << endl;
    }
    else {
        cout << left(d, n, k, 0) << endl;
    }
    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int BUFF_MAX = 1024;
    char buf[BUFF_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}

vi get_n_array(int n)
{
    vi v;
    while (n-- > 0) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    return v;
}

Measured memory_bytes: 256
N = int(input())
X = [int(x) for x in input().split()]
M = int(input())
A = [int(a) for a in input().split()]

for i in range(M):
    new_p = X[A[i]-1] + 1
    if new_p in X or new_p == 2020:
        continue
    X[A[i]-1] = new_p

for i in X:
    print(i)



Measured memory_bytes: 5616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const double DELTA = 1e-10;

/* typedef */

struct tri {
  double x, y0, y1;
  tri() {}
  tri(double _x, double _y0, double _y1) { x = _x, y0 = _y0, y1 = _y1; }
  bool operator<(const tri& t0) const { return x < t0.x; }
};

/* global variables */

int n, cn;
double r, minx, maxx;
double xs[MAX_N], ys[MAX_N];
tri cxys[MAX_N * 2];

/* subroutines */

// (x0,y0)-(x1-y1)
// dx=x1-x0,dy=y1-y0
// y = dy/dx * (x-x0) + y0 = dy/dx * x + (dx*y0-dy*x0)/dx

inline void line_eq(double x0, double y0, double x1, double y1,
		    double& a, double& b) {
  double dx = x1 - x0;
  double dy = y1 - y0;
  a = dy / dx;
  b = (dx * y0 - dy * x0) / dx;
}

double f(double x) {
  if (x <= minx || x >= maxx) return 0.0;
  int k = upper_bound(xs, xs + n, x) - xs - 1;
  double a, b;
  line_eq(xs[k], ys[k], xs[k + 1], ys[k + 1], a, b);
  return a * x + b;
}

/* main */

int main() {
  for (;;) {
    cin >> n >> r;
    if (n == 0) break;

    for (int i = 0; i < n; i++)
      cin >> xs[i] >> ys[i];
    minx = xs[0];
    maxx = xs[n - 1];

    cn = 0;
    for (int i = 0; i < n; i++) {
      if (xs[i] + r <= maxx)
	cxys[cn++] = tri(xs[i], ys[i], f(xs[i] + r));
      if (xs[i] - r >= minx)
	cxys[cn++] = tri(xs[i] - r, f(xs[i] - r), ys[i]);
    }

    sort(cxys, cxys + cn);

    double sum = 0.0;

    for (int i = 0; i < cn - 1; i++) {
      double a0, b0, a1, b1;
      tri& cxy0 = cxys[i], cxy1 = cxys[i + 1];
      double x0 = cxy0.x, x1 = cxy1.x;
      if (x1 - x0 < DELTA) continue;

      line_eq(x0, cxy0.y0, x1, cxy1.y0, a0, b0);
      line_eq(x0, cxy0.y1, x1, cxy1.y1, a1, b1);

      // f(x)*f(x+r) = (a0*x+b0)(a1*x+b1)=(a0a1)*x^2+(a0b1+a1b0)*x+(b0b1)
      double aa = a0 * a1;
      double bb = a0 * b1 + a1 * b0;
      double cc = b0 * b1;

      double itg =
	aa * (x1 * x1 * x1 - x0 * x0 * x0) / 3 +
	bb * (x1 * x1 - x0 * x0) / 2 +
	cc * (x1 - x0);

      sum += itg;
    }

    printf("%.10lf\n", sum);
  }

  return 0;
}

Measured memory_bytes: 1256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int64 MOD = 1000000007;

int n; int64 k;
vector<vector<int>> graph(101010);

int64 ans;

void dfs(int v, int p) {
  int64 can = k - 1;
  if (p != -1) --can;
  for (auto next : graph[v]) {
    if (next == p) continue;
    (ans *= can) %= MOD;
    --can;
    dfs(next, v);
  }
}

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

  cin >> n >> k;
  rep(i, n - 1) {
    int x, y; cin >> x >> y;
    --x; --y;
    graph[x].emplace_back(y);
    graph[y].emplace_back(x);
  }
  ans = k;
  dfs(0, -1);

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define PI acos(-1.0)
#define EPS 1e-9 //epsilon 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define go(i,a,n) for(int i=a;i<n;i++)
#define og(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(i,n) go(i,0,n)
#define per(i,n) og(i,0,n)
#define sz(x) (x.size())
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
#define all(x) x.begin(),x.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pr(x) cout<<(x)<<endl
#define exist(e,s) ((s).find(e)!=(s).end()) //Element e in structure s
#define existstr(c,s) ((s).find(c) !=string::npos) //Character in structure
#define fo(x,s) for(auto &x:s) //for all x in structure s
typedef vector<int> vi;typedef vector<ll> vll;typedef vector< vector<int> > vvi;
typedef vector< vector<ll> > vvll;typedef pair<int,int> ii;typedef pair<int, pair<int,int> > iii;
typedef pair<ll,ll> pll;typedef vector<ii> vii;typedef vector<iii> viii;typedef map<int,int> mii;
const int inf=1e9+7; //10^9 +7
inline void rvi(vi& v, int n){int temp; go(i,0,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll& v, int n){ll temp;go(i,0,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi&a){go(i,0,a.size()){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll&a){go(i,0,a.size()){cout<<a[i]<<" ";}cout<<endl;}
inline void prmii(map<int,int>& m){for(auto x:m){cout<<x.fi<<" "<<x.se<<endl;}}
inline vll prefixsum(vi& a){vll b;b.pb(a[0]);go(i,1,a.size()){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi& a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];og(i,0,sz(a)-1){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll& a){vll b;b.pb(a[0]);go(i,1,a.size()){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll& a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];og(i,0,sz(a)-1){b[i]=a[i]+b[i+1];}return b;}
void solve();
int main(){ios;solve();return 0;}
//--------SOLVE---------------------------------------------------------------------
void solve()
{
 	int n,m;
 	cin>>n>>m;
 	vi a(n);
 	rep(i,n) cin>>a[i];
 	vll p=prefixsum(a);
 	rep(i,n) p[i]=p[i]%m;
 	mii mapi;
 	rep(i,n) mapi[p[i]]++;
 	auto it=mapi.begin();
 	ll count=0;
 	if(it->fi==0) count+=it->se;
 	fo(x,mapi)
 	{
 		if(x.se>1)
 		{
 			count+=(((ll)x.se)*(x.se-1))/2;
 		}
 	}
 	cout<<count<<endl;
}

Measured memory_bytes: 4340
n = int(input())
a = list(map(int, input().split()))

print(' '.join(map(str, a)))

for i in range(1, n):
    v = a[i]
    j = i - 1
    while j >= 0 and v < a[j]:
        a[j+1] = a[j]
        j -= 1

    a[j+1] = v

    print(' '.join(map(str, a)))



Measured memory_bytes: 5600
a,b,k=map(int,input().split())
ans=set()
for i in range(a,min(a+k,b+1)):
    ans.add(i)
for i in range(max(a,b-k+1),b+1):
    ans.add(i)
A=[]
for i in ans:
    A.append(i)
A.sort()
for i in A:
    print(i)
    

Measured memory_bytes: 3060
#include<stdio.h>
 
int main(void)
{
    long long a, b, sum, temp;
    while(scanf("%lld %lld",&a,&b) != EOF)
    {
        if(a < b){
            temp = a;
            a = b;
            b = temp;
        }
        sum = a * b;
        while(b != 0)
        {
            a %= b;
            temp = a;
            a = b;
            b = temp;
        }
        printf("%lld %lld\n",a,sum/a);
    }
    return 0;
}



Measured memory_bytes: 1988
import datetime

inp = str(input())
dateHeiseiEnd = datetime.datetime(2019, 5, 1, 0, 0, 0)
dateInput = datetime.datetime.strptime(inp, "%Y/%m/%d")

if dateInput < dateHeiseiEnd:
	print("Heisei")
else:
	print("TBD")
	

Measured memory_bytes: 4336
using System;
using System.Collections;

namespace ABC073C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Hashtable table = new Hashtable(N);

            for (int i = 0; i < N; i++)
            {
                int val = int.Parse(Console.ReadLine());
                if (table.ContainsKey(val))
                {
                    table.Remove(val);
                }
                else
                {
                    table.Add(val, 0);
                }
            }

            Console.WriteLine(table.Count);
        }
    }
}


Measured memory_bytes: 24028
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;
const int N=131072;
int ch[N][2],t0t[N],fa[N],n,V[N];
typedef vector<pair<LL,LL> >VPII;
void merge(VPII&L,VPII&R,VPII&vec,const LL&lim){
	for(int i=0,it=0;i<L.size();++i){
		while(it+1<R.size()&&L[i].second+R[it+1].first<=lim)++it;
		if(it==R.size())break;
		if(L[i].second+R[it].first<=lim)vec.push_back(make_pair(L[i].first,R[it++].second));
	}
}
void dfs(int now,LL lim,VPII&vec){
	if(t0t[now]==0){
		if(V[now]<=lim)vec.push_back(make_pair(V[now],V[now]));
		return;
	}
	VPII L,R,Lv,Rv;
	dfs(ch[now][0],lim,L),dfs(ch[now][1],lim,R);
	merge(L,R,Lv,lim),merge(R,L,Rv,lim);
	int it1=0,it2=0;
	while(it1<Lv.size()&&it2<Rv.size())
	if(Lv[it1].first<Rv[it2].first){
		vec.push_back(Lv[it1]);
		++it1;
	}else
	if(Lv[it1].first>Rv[it2].first){
		vec.push_back(Rv[it2]);
		++it2;
	}else{
		Lv[it1].second=min(Lv[it1].second,Rv[it2].second);
		vec.push_back(Lv[it1]);
		++it1,++it2;
	}
	while(it1<Lv.size()){
		vec.push_back(Lv[it1]);
		++it1;
	}
	while(it2<Rv.size()){
		vec.push_back(Rv[it2]);
		++it2;
	}
	for(auto&i:vec)i.first+=V[now],i.second+=V[now];
}
bool check(LL x){
	VPII vp;
	dfs(1,x,vp);
	return!vp.empty();
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=2;i<=n;++i){
		cin>>fa[i];
		cin>>V[i];
		ch[fa[i]][t0t[fa[i]]++]=i;
	}
	LL l=0,r=1145141919810,ans=r;
	while(l<=r){
		const LL mid=l+r>>1;
		if(check(mid))r=(ans=mid)-1;else l=mid+1;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define MAX 100000
typedef long long ll;
using namespace std;
int n,k;
ll T[MAX];
int check(ll P){
	int i=0;
	for(int j=0;j<k;j++){
		ll s=0;
		while(s+T[i]<=P){
			s+=T[i];
			i++;
			if(i==n)
				return n;
		}
	}
	return i;
}
int solve(){
	ll l = 0;
	ll r = 100000 * 10000;
	ll mid;
	while(r>l+1){
		mid = (r+l)/2;
		int v = check(mid);
		if(v>=n){  //满足此式子v=n于是要缩小r的值 
			r = mid;
		}
		else{
			l = mid;
		}
	}
	return r;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>T[i];
	}
	ll ans = solve();
	cout<<ans<<endl;
	return 0;
} 


Measured memory_bytes: 3876
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int num2 = scan.nextInt();
        
        long dp[][] = new long[num1+1][num2+1];
        Arrays.fill(dp[0],0);

        long value[] = new long[num1];
        int weight[] = new int[num1];
                
        for(int i=0; i<num1; i++){
            weight[i] = scan.nextInt();
            value[i] = scan.nextInt();
        }
        for(int i=1; i<num1+1; i++){
            for(int j=0; j<num2+1; j++){
                if(weight[i-1] > j){
                    dp[i][j] = dp[i-1][j];
                }
                else{
                    dp[i][j] = Math.max(dp[i-1][j], value[i-1] + dp[i-1][j - weight[i-1]]);
                }
            }
        }

        System.out.println(dp[num1][num2]);
        

    }
}

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

int main(){
	int n;
	cin>>n;
	vector<int>v(n);
	for(int i = 0;i<n;i++){
		cin>>v[i];
	}
	int flag=0;
	for(int i = 1;i<n-1;i++){
		int a = min(v[i-1],v[i+1]);
		int b = max(v[i-1],v[i+1]);
		if(v[i]>a && v[i]<b)
			flag++;
	}
	cout<<flag;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<vector>
#include<queue>
using namespace std;
int main(){
	int N,A,B;
	int sum=0,ans=0;
	cin>>N>>A>>B;
	for(int i=1;i<=N;i++){
		int ddd=i;
		while(ddd!=0){
			sum+=ddd%10;
			ddd=(ddd-(ddd%10))/10;
		}
		if(A<=sum&&sum<=B){
			ans+=i;
		}
		sum=0;
	}
	cout<<ans<<endl;
}
	
	


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    n %= 10;
    if (n == 3) cout << "bon" << endl;
    else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3596
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define INF 100000000
#define MAXN 110
typedef long long ll;

int n;
int a[MAXN][MAXN], dp[MAXN][MAXN];

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) 
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + a[i-1][j-1];
        }
    }
//    for (int i = 1; i <= n; i++) {
//        for (int j = 1; j <= n; j++) {
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }
    int ret = -INF;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                for (int l = k; l <= n; l++) {
                    int num = dp[j][l] - dp[i-1][l] - dp[j][k-1] + dp[i-1][k-1];
                    ret = max(ret, num);
                }
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1256
using System;

namespace C___Walk_on_Multiplication_Table
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = long.Parse (Console.ReadLine ());
            var min = long.MaxValue;
            for (var i = 1L; i <= Math.Sqrt (n); i++)
            {
                if (n % i == 0)
                {
                    min = Math.Min (i + n / i, min);
                }
            }
            Console.WriteLine (min - 2);
        }
    }
}

Measured memory_bytes: 13140
program abc
	implicit none
	integer :: x,n,m,nn,b
    integer :: an(10000)=0 
    double precision :: a

	read(*,*) n,m
	read(*,*) (an(x),x=1,n)
	
	do x = 1, n
		nn = nn + an(x)
	enddo
    
    a = nn / (4. * m)
    b = 0

	do x = 1, n
    	if(dble(an(x)) >= a) b = b + 1
    enddo

	if(b >= m) then
		write(*,*) "Yes"
	else
    	write(*,*) "No"
    endif
    
end program abc

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 1e6+5;
string s;
vector<int> v[N];
ll n,m;
ll a,b,x;

template <typename T> T gcd(T a, T b) {
  if(b == 0) return a;
  return gcd(b, a%b);
}

template <typename T> T lcm(T a, T b) {
  return a / gcd(a, b) * b ;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> a >> b;
  
  cout << lcm(a,b) << endl;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
int main(void){
	long long l=2,ll=1,n,i,temp;
	cin>>n;
	for(i=0;i<n-1;i++){
		l=ll+l;
		temp=ll; ll=l; l=temp;
	}
	cout<<ll<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		List <Integer> a = new ArrayList<Integer>();
		
		for(int i = 0 ; i < n ;i++) {
			int b = Integer.parseInt(sc.next());
			a.add(b);
		}
		int []c = new int [n];
		int m = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = a.size()-1 ; j >= 0; j--) {
				if(a.get(j) == j+1) {
					c[m] = j+1;
					m++;
					a.remove(j);
					break;
				}
			}
		}
		
		if(a.size() != 0) {
			System.out.println(-1);
		}
		
		else {
			for(int i = n-1; i >= 0 ; i--) {
				System.out.println(c[i]);
			}
		}
	}

}


Measured memory_bytes: 21844
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    for(int i = 0; i < n; i++){
      count += -sc.nextInt() + sc.nextInt() + 1;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 25328
import java.util.Arrays;
import java.util.Scanner;

public class Main 
{
	static boolean[] prime = new boolean[1000001];
	
	static void buildprime()
	{
		Arrays.fill(prime, true);
		prime[0] = prime[1] = false;
		
		for(int i = 2; i*i <= 1000000; i++)
		{
			if(prime[i])
			{
				for(int j = i*i; j<=1000000; j+= i)
				{
					prime[j] = false;
				}
			}
		}
		
	}

	public static void main(String[] args) 
	{
		buildprime();
		Scanner sc = new Scanner(System.in);

		while(true)
		{
			int a = sc.nextInt();
			int d = sc.nextInt();
			int n = sc.nextInt();
			if(a == 0 && d == 0 && n == 0)return;

			{
				int mul = 1;
				int th = 1;
				int num = a-d;
				while(true)
				{
//					int num = a + (d*mul);
					num += d;
					
//					System.out.println(num + " " + th + " of " + n);
//					System.out.println(num + " " + (n-th+2));
					
					if(prime[num])
					{
						if(th == n)
						{
							System.out.println(num);
							break;
						}
						
						th++;
					}
					
					mul++;
				}
			}
		}
		

	}

}



Measured memory_bytes: 30128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  cin >> n >> a >> b;
 
  if (n * a < b) {
    cout << n*a << endl;
  }
  else if(n * a > b){
    cout << b << endl;
  }
  else{
    cout << b << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
using ll = long long;
using namespace std;
signed main() {
	ll n, m; cin >> n;
	map<ll, ll> M;
	rep(i, n) { ll a; cin >> a; M[a]++; }
	cin >> m;
	rep(i, m) {
		ll a; cin >> a;
		if (M[a] > 0) { M[a]--; }
		else { cout << "NO\n"; return 0; }
	}
	cout << "YES\n";
	return 0;
}

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

ll p;

struct FenwickTree{
  int n;
  vl bit;
  FenwickTree(int x = 0):n(x){bit = vl(x+1,0);}

  inline void add(int i, ll x){
    i++;
    while(i <= n){
      (bit[i] += x) %= p;
      i += i & -i;
    }
  }

  inline ll sum(int i){
    i++;
    ll res = 0;
    while(i > 0){
      (res += bit[i]) %= p;
      i -= i & -i;
    }
    return res;
  }

  inline ll partial_sum(int l, int r){
    return (sum(r-1) - sum(l-1) + p) % p;
  }
};

inline string LLtoS(ll a){
  stringstream ss;
  ss << a;
  return ss.str();
}

inline ll StoLL(string s){
  stringstream ss(s);
  ll res; ss >> res;
  return res;
}

int main(){
  ll a,b;
  while(cin >> a >> b >> p, a){
    FenwickTree bit(b-a+2);
    for(ll x=a;x<=b;x++){
      string s = LLtoS(x);
      ll l=1, sum = 1, r = 0;
      for(int i=0;i<(int)s.size();i++){
	r = r*10 + (ll)(s[i]-'0');
	if(a<=r){
	  (sum += bit.partial_sum(max(l,a)-a,min(r,b)-a+1)) %= p;
	}
	l*=10;
      }
      bit.add(x-a,sum);
    }
    cout << bit.partial_sum(0,b-a+1) << endl;
  }
}

Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
typedef long long ll;
const int N=20000005;
int n,k,x,t,a,b;
string s;
vector<int>v;
int main(){

	cin >> x >> a >> b;
	swap(x,a);
	swap(x,b);
	cout << x << " " << a << " " << b <<endl;

	return 0;
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let (r, g, b) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    let ans = if (r * 100 + g * 10 + b) % 4 == 0 { "YES" }
    else { "NO" };
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


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

int main(){
  int n; cin >> n;
  vector<long long> A(n);
  int m = 1001001001;
  int cnt;
  long long ans = 0;
  
  for(int i = 0; i < n; i++){
    cin >> A.at(i);
    long long tmp = abs(A.at(i));
    ans += tmp;
    if(m > tmp){
      m = tmp;
      cnt = i;
    }
  }
  for(int i = 0; i < cnt; i++){
    if(A.at(i) < 0) A.at(i+1) = -1*A.at(i+1);
  }
  for(int i = n-1; i > cnt; i--){
    if(A.at(i) < 0) A.at(i-1) = -1*A.at(i-1);
  }
  if(A.at(cnt) >= 0) cout << ans << endl;
  else cout << ans + 2 * A.at(cnt) << endl;
}
  
    

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double
using namespace std;

    const ll N = 1e2 + 7;
    const ll mod = 1e9 + 7;

bool b;
map < int , int > mp;

void f(int n){
    for(int i = 2; i <= sqrt(n); ++ i){
        if(n % i == 0){
            if(mp[i] || mp[n / i]){
                    b = 0;
                    return;
            }
        }
    }
}

void solve(){
    int n;
    cin >> n;
    vector < int > a(n + 1);
    for(int i = 1; i <= n; ++ i){
        cin >> a[i];
        mp[a[i]] ++;
    }
    if(mp[1] > 1){
        cout << 0;
        exit(0);
    }
    if(mp[1] == 1){
        cout << 1;
        exit(0);
    }
    int ans = 0;
    for(int i = 1; i <= n; ++ i){
        int x = a[i];
        if(mp[x] > 1)continue;
        b = 1;
        f(x);
        ans += b;
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 33032
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#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>
#define iPair pair<ll,ll> 
ll n,s,d,dist[100005][3],cnt=ass;
vector<ll>v[100005];

void dfs()
{
	queue<iPair> pq; 
  	for(ll i=0;i<=n;i++)
  	{
  		dist[i][0]=INT_MAX;
  		dist[i][1]=INT_MAX;
  		dist[i][2]=INT_MAX;
  	}
  	pq.push(mp(s,0)); 
    dist[s][0]=0; 
  	while(!pq.empty()) 
    { 
        iPair u =pq.front(); 
        pq.pop(); 
        ll c=u.se;
        ll d=u.fi;
        for (ll i=0;i<v[d].size();i++) 
        { 
	        ll a=v[d][i];
	        ll e=(c+1)%3;
	        if (dist[a][e]!=INT_MAX)
	        	continue; 
	        dist[a][e]=dist[d][c]+1;
	        pq.push(mp(a,e)); 
        } 
    } 
}
	
int main()
{
	ll m,i;
	cin>>n>>m;
	while(m--)
	{
		cin>>s>>d;
		v[s].pb(d);
	}
	cin>>s>>d;
	dfs();
	if(dist[d][0]==INT_MAX)
		cout<<-1;
	else
		cout<<dist[d][0]/3;
	return 0;
}

Measured memory_bytes: 8064
from collections import deque
H,W=map(int, input().split())
 
A=[]
que=[]
done=[[-1]*W for _ in range(H)]
for h in range(H):
    a=list(input())
    A.append(a)
    for w in range(W):
        if a[w]=="#":
            que.append((h,w))
            done[h][w]=0
 
d=[(1,0),(-1,0),(0,1),(0,-1)]
que=deque(que)
ans=0
while que:
    h,w=que.popleft()
    now=done[h][w]
    for t in d:
        dh,dw=t
        nh=h+dh
        nw=w+dw
        if 0<=nh<H and 0<=nw<W:
            if done[nh][nw]==-1:
                done[nh][nw]=now+1
                que.append((nh,nw))
                ans=max(ans, now+1)
print(ans)


Measured memory_bytes: 178840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,w;
	cin>>h>>w;
	ll ans=0;
	if(h==1&&w==1){
		ans=1;
	}
	else if(h==1||w==1){
		ans=h*w-2;
	}
	else{
		ans=(h-2)*(w-2);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		while(n-- != 0)
		{
			double x1 = stdIn.nextDouble();
			double y1 = stdIn.nextDouble();
			double x2 = stdIn.nextDouble();
			double y2 = stdIn.nextDouble();
			double x3 = stdIn.nextDouble();
			double y3 = stdIn.nextDouble();
			double x4 = stdIn.nextDouble();
			double y4 = stdIn.nextDouble();
			if(x1 == x2 && x3 == x4)
			{
				System.out.println("YES");
			}
			else if(x1 == x2 || x3 == x4)
			{
				System.out.println("NO");
			}
			else
			{
				double a1 = (y2 - y1) / (x2 - x1);
				double a2 = (y4 - y3) / (x4 - x3);
				if(a1 == a2)
				{
					System.out.println("YES");
				}
				else
				{
					System.out.println("NO");
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> L(N,0);
    for(int i=0;i<N;i++){
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    int st=0;
    int count=0;
    for(int i=2;i<N;i++){
        for(int j=0;j<i;j++){
            for(int k=0;k<j;k++){
                if(L[j]+L[k]>L[i]){
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
    return 0;
}

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

const int MX = 100005;
int n, v, u, c = 2;
vector<int> G[MX], a;

int dfs1(int u, int p) {
	int c = u != v, ret = u;
	for (int nx : G[u]) if (nx != p && G[nx].size() > 1) {
		if (c++ > 1) {
			puts("-1");
			exit(0);
		}
		ret = dfs1(nx, u);
	}
	return ret;
}
void dfs2(int u, int p) {
	a.push_back((int)G[u].size());
	for (int nx : G[u]) if (nx != p && G[nx].size() > 1) dfs2(nx, u);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		scanf("%d%d", &v, &u);
		v--; u--;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	if (G[v].size() == 1) v = G[v][0];
	v = dfs1(v, -1);
	dfs2(v, -1);
	u = (int)a.size();
	for (int i = 0; i < u; i++) if (a[i] != a[u - 1 - i]) {
		if (a[i] > a[u - 1 - i]) reverse(a.begin(), a.end());
		break;
	}
	printf("1 ");
	for (int i = 0; i < u; i++) {
		int t = c++;
		for (int j = 0; j < a[i] - 2; j++) printf("%d ", c++);
		printf("%d ", t);
		if (i == u - 1) printf("%d\n", c++);
	}

	return 0;
}

Measured memory_bytes: 13048
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	char map[10][10];
};

struct Data{
	Data(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

int H,W;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
char base_map[10][10];
bool FLG;

char to_color[3] = {'R','G','B'};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void back_track(Info info,int depth,int max_depth){

	if(FLG)return;

	if(depth == max_depth){
		bool is_cleared = true;
		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				if(info.map[row][col] != info.map[0][0]){
					is_cleared = false;
					break;
				}
			}
			if(!is_cleared)break;
		}

		if(is_cleared){
			FLG = true;
		}
		return;
	}

	char pre_color = info.map[0][0];

	queue<Data> Q;
	int adj_row,adj_col;

	for(int loop = 0; loop < 3; loop++){
		if(to_color[loop] == pre_color)continue;

		Info next_info;
		for(int row = 0;row < H; row++){
			for(int col = 0; col < W; col++){
				next_info.map[row][col] = info.map[row][col];
			}
		}

		next_info.map[0][0] = to_color[loop];

		Q.push(Data(0,0));

		while(!Q.empty()){

			for(int i = 0; i < 4; i++){
				adj_row = Q.front().row + diff_row[i];
				adj_col = Q.front().col + diff_col[i];

				if(!rangeCheck(adj_row,adj_col))continue;

				if(next_info.map[adj_row][adj_col] == pre_color){
					next_info.map[adj_row][adj_col] = to_color[loop];
					Q.push(Data(adj_row,adj_col));
				}
			}

			Q.pop();
		}
		if(depth < max_depth){
			back_track(next_info,depth+1,max_depth);
		}
	}
}

void func(){

	char buf[2];

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			scanf("%s",buf);
			base_map[row][col] = buf[0];
		}
	}

	FLG = false;
	int ans = 0;

	for(int i = 0; ; i++){
		Info info;

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				info.map[row][col] = base_map[row][col];
			}
		}
		back_track(info,0,i);

		if(FLG){
			ans = i;
			break;
		}
	}

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


int main(){

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

	return 0;
}

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

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

    ll ans = 0;

    if(n == 1 && m == 1){
        ans = 1;
    }else if(n == 1){
        ans = m - 2;
    }else if(m == 1){
        ans = n - 2;
    }else if(n == 2 || m == 2){
        ans = 0;
    }else{
        ans = (n - 2) * (m - 2);
    }
    

    cout << ans << endl;
}

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

string o, e;

int main() {
  cin >> o >> e;
  string ans = "";
  for (int i=0; i<o.size(); i++) {
    ans += o[i];
    if (i < e.size()) ans += e[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll x,y; cin>>x>>y;
    ll fl = 0;
    for(int q=0; q<=x; q++){
        int w = x-q;
        fl |= q*2+w*4==y;
    }
    cout<<(fl  ? "Yes" : "No");
}

Measured memory_bytes: 3652