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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define all(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int N, L;

	cin >> N >> L;

	int ans;
	if (L >= 0) {
		ans = L * (N - 1) + N * (N - 1) / 2;
	}
	else if (L + N - 1 <= 0) {
		ans = L * (N - 1) + (N - 2) * (N - 1) / 2;
	}
	else {
		ans = L * N + N * (N - 1) / 2;
	}

	COL(ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    char a[10] = {0};
    ll n;
    cin >> n;
    sprintf(a, "%d", n);
    ll sum = 0;
    for (ll i = 0; a[i] != 0; i++)
    {
        sum += a[i] - 48;
    }

    if (n % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int X[100000], Y[100000];
int p2[100001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  p2[0] = 1;
  for (int i=1; i<=100000; i++) p2[i] = (2*p2[i-1]) % MOD;

  cin >> N >> M;
  rep(i, N) cin >> X[i];
  rep(i, M) cin >> Y[i];
  long long xs = 0, ys = 0;
  for (int i=1; i<N; i++) {
    long long b = (1LL*i*(N-i)) % MOD;
    xs += (1LL * ((X[i] - X[i-1]) % MOD) * b) % MOD;
    xs %= MOD;
  }
  for (int i=1; i<M; i++) {
    long long b = (1LL*i*(M-i)) % MOD;
    ys += (1LL * ((Y[i] - Y[i-1]) % MOD) * b) % MOD;
    ys %= MOD;
  }
  cout << (xs*ys) % MOD << "\n";
  return 0;
}


Measured memory_bytes: 2560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class CSlimes {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      string s; cin >> s;
      char before = '?';
      int ans = 0;
      rep(i, n) {
        if (s[i] != before) {
          ans++;
        } else {

        }
        before = s[i];
      }
      cout << ans << endl;
    }
};

signed main() {
  CSlimes solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 512
from sys import stdin, setrecursionlimit
from heapq import heapify, heappop, heappush


def main():
    input = stdin.buffer.readline
    n = int(input())
    v = list(map(int, input().split()))
    heapify(v)

    for _ in range(n - 1):
        x = heappop(v)
        y = heappop(v)
        heappush(v, (x + y) / 2)

    print(v[0])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    int n , x ;
    cin >> n >> x;
    vector < int > l(n) ;
    for( int i = 0 ; i < n ; i++) cin >> l[i] ;
    ll b = 0 , ans = 0 ;
    if(b<=x)
        ans++;
    for( int i = 0 ; i < n ; i++){
        b = b + l[i] ;
        if(b<=x)
            ans++;
       // cout << b << " " ;
    }
    cout << ans ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}



Measured memory_bytes: 256
/***
 @ Author       : RobsonChen
 @ Date         : 2020-09-20 19:35:23
 @ LastEditTime : 2020-09-20 22:17:14
 @ Got AC       : Σ(っ °Д °;)っ
*/
#include <bits/stdc++.h>

using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int mod = 998244353;
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define FW freopen("data2.txt", "w", stdout);

//快速读入输出，只适用于整数，使用时流同步打开，C语言不准关流
// getchar()<<cin(关流)<<scanf()<<cin
template <class T>
inline bool Read(T& ret)
{
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF)
        return 0;
    while (c != '-' && (c < '0' || c > '9'))
        c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
        ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//输出只能用于整数
template <class T>
inline void Write(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        Write(x / 10);
    putchar(x % 10 + '0');
}

LL sum[N * 2] = { 0 }, num = 1;

void slove(int qnum)
{
    LL n, q;
    cin >> n >> q;
    LL ans = (n - 2) * (n - 2);
    vector<int> a(n + 1), b(n + 1);
    int x, pos;
    int d = n, r = n;
    for (int i = 1; i <= n; ++i)
        a[i] = b[i] = n;
    while (q--) {
        scanf("%d%d", &x, &pos);
        if (x == 1) {
            if (pos < r) {
                for (int i = pos; i < r; ++i) {
                    a[i] = d;
                }
                r = pos;
            }
            ans -= (a[pos] - 2);
        } else {
            if (pos < d) {
                for (int i = pos; i < d; ++i) {
                    b[i] = r;
                }
                d = pos;
            }
            ans -= (b[pos] - 2);
        }
    }
    cout << ans << endl;
}

int main()
{
    int qnum = 1;
    // cin >> num;
    for (int i = 1; i <= qnum; ++i) {
        slove(i);
    }
    //system("pause");
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<str> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

#define f(i, a, b, s) for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define forr(i, b, e) f(i, b, e, 1)
#define fo(i, b, e, s) f(i, b, e, s)
#define trav(a, x) for (auto &a : x)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert

#define sll unordered_set<ll>
#define sii unordered_set<int>
#define mll unordered_map<ll, ll>
#define mii unordered_map<int, int>
#define pqb priority_queue<ll>
#define pqs priority_queue<ll, vll, greater<ll>>

#define zerobits(x) __builtin_ctzll(x)
#define setbits(x) __builtin_popcountll(x)
#define ps(x, y) fixed << setprecision(y) << x
#define mem(arr, x) memset(arr, x, sizeof(arr))
#define mk(arr, type, n) type *arr = new type[n];
#define endl '\n'

const ll INF = 9e18;
ll mod = 1000000007;

template <typename T>
ostream &operator<<(ostream &stream, vector<T> &v)
{
    for (T &x : v)
        stream << x << " ";
    return stream;
}

template <typename T>
istream &operator>>(istream &stream, vector<T> &v)
{
    for (T &x : v)
        stream >> x;
    return stream;
}

template <typename T>
void sort(vector<T> &v)
{
    std::sort(v.begin(), v.end());
    return;
}

template <typename T>
T max(vector<T> &v)
{
    return *(max_element(v.begin(), v.end()));
}

template <typename T>
T min(vector<T> &v)
{
    return *(min_element(v.begin(), v.end()));
}

// =============== !!! ~ ~ ~ code starts here ~ ~ ~ !!! ===============

int sol(int idx, int n, vi &dp, vi &a)
{
    if (n - idx == 1)
    {
        dp[idx] = abs(a[idx] - a[idx + 1]);
        return dp[idx];
    }
    if (n - idx == 2)
    {
        dp[idx] = min(abs(a[n] - a[idx]), (abs(a[n] - a[idx + 1]) + abs(a[idx + 1] - a[idx])));
        return dp[idx];
    }
    if (dp[idx] != -1)
        return dp[idx];
    int ans = min((abs(a[idx + 1] - a[idx]) + sol(idx + 1, n, dp, a)), (abs(a[idx + 2] - a[idx]) + sol(idx + 2, n, dp, a)));
    dp[idx] = ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef RAGHAV
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    clock_t t1, t2;
    t1 = clock();
    int tc = 1;
    // cin >> tc;
    while (tc--)
    {

        int n;
        cin >> n;
        vi a(n);
        cin >> a;
        vi dp(n, -1);
        int ans = sol(0, n - 1, dp, a);
        cout << ans << endl;
    }
#ifdef RAGHAV
    t2 = clock();
    cout << "\n\ntime taken: " << (t2 - t1) / (long double)CLOCKS_PER_SEC;
#endif
    return 0;
}


Measured memory_bytes: 8012
#![allow(unused_imports)]
#![allow(non_snake_case)]

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

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

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

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

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

fn main() {
    let N = read!(i64);

    let mut k = 1;
    loop {
        let t = k * (k - 1) / 2;
        if t == N {
            let mut G = vec![vec![]; k as usize];
            let mut i = 1_usize;
            for u in 0..k {
                for v in u + 1..k {
                    G[u as usize].push((v as usize, i));
                    G[v as usize].push((u as usize, i));
                    i += 1;
                }
            }

            println!("Yes");
            println!("{}", k);
            for u in 0..k {
                let mut xs = G[u as usize]
                    .iter()
                    .map(|&(_, i)| i.to_string())
                    .collect::<Vec<_>>();
                println!("{} {}", G[u as usize].len(), xs.join(" "));
            }
            break;
        } else if t > N {
            println!("No");
            break;
        } else {
            k += 1;
            continue;
        }
    }
}


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

int n, m;
vector<P> v;

int main(){
	scanf("%d%d",&n,&m);
	rep(i,n){
		int x, y;
		scanf("%d%d",&x,&y);
		v.push_back(P(x,y));
	}
	sort(v.begin(),v.end());
	rep(i,m){
		int x1, y1, x2, y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int sx = 0, ex = n-1, smid;
		int s, e;
		int cnt = 0;
		while(ex-sx > 1){
			smid = (sx+ex)/2;
			if(v[smid].first >= x1) ex = smid;
			else sx = smid;
		}
		//cout << sx << " " << ex << endl;
		s = sx;
		sx = 0; ex = n-1;
		while(ex-sx > 1){
			smid = (sx+ex)/2;
			if(v[smid].first <= x2) sx = smid;
			else ex = smid;
		}
		//cout << sx << " " << ex << endl;
		e = ex;
		e = ex;
		if(x1 <= v[s].first && v[s].first <= x2 && y1 <= v[s].second && v[s].second <= y2) cnt++;
		if(x1 <= v[e].first && v[e].first <= x2 && y1 <= v[e].second && v[e].second <= y2) cnt++;
		
		for(int j = s+1; j <= e-1; j++) if(y1 <= v[j].second && v[j].second <= y2) cnt++;
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1320
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nx = br.readLine().split(" ");
        int n = Integer.parseInt(nx[0]);
        int start = Integer.parseInt(nx[1]);
        
        int[] cities = new int[n+1];
        int [] diffs = new int[n];
        String[] line = br.readLine().split(" ");
        
        cities[0] = start;
        for (int i = 0; i < n; i++) {
            cities[i+1] = Integer.parseInt(line[i]);
            
            
        }
        
        
        
        Arrays.sort(cities);
        
        //for (int i = 0; i < n+1; i++) System.out.println(cities[i]);
        
        for (int i = 0; i < n+1; i++) {
            if (i==0) continue;
            else {
                diffs[i-1] = cities[i] - cities[i-1];
            }
            
        }
        
        int cd = 1;
        
        if (diffs.length == 1) cd = diffs[0];
        else {
            int tmp;
            int x = diffs[0];
            int y = diffs[1];
            while ((tmp = x % y) != 0) {
                x = y;
                y = tmp;
            }
            cd = y;
        
            for (int i = 2; i < n; i++) {
                x = cd;
                y = diffs[i];
                while ((tmp = x % y) != 0) {
                    x = y;
                    y = tmp;
                }
                cd = y;
            }
        }
        
        System.out.println(cd);
        
        
    }
}


Measured memory_bytes: 48212
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;


int main(){
   int N,A,B,C;
   cin >> N >> A >> B >> C;
   int L[]={A,B,C};
   int l[N];
   for(int i=0;i<N;i++) cin >> l[i];
   sort(l,l+N);
   int ans = INT_MAX;

   for(int i=0;i<(1<<(2*N)); i++){
      int cnt[4];
      int len[4];
      int mask = i;
      memset(cnt,0,sizeof(cnt));
      memset(len,0,sizeof(len));
      for(int j=0;j<N;j++){
         cnt[mask%4]++;
         len[mask%4]+=l[j];
         mask>>=2;
      }
      int mp=0;
      bool ok = true;
      for(int j=0;j<3;j++){
         if(cnt[j]==0) ok=false;
         mp += 10*(cnt[j]-1);
         mp += abs(len[j]-L[j]);
      }
      if(ok==true) ans = min(ans,mp);
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll   long long
#define ld long double
#define endl '\n'
#define INF 10000000000000000
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;
const ll N = 3005;
const ll MOD = 10e8+7;
ld dp[N];
int main()
{
 //freopen("input.txt","r",stdin);
 //  freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n;
    dp[0]=1;
    for(ll i =1;i<=n;i++) {
        ld p;
        cin>>p;
        for(ll j=i;j>=0;j--) {
            dp[j]=dp[j-1]*p+dp[j]*(1-p);
        }
    }
    ld ans=0;
    for(ll i =0;i<=n;i++) {
        ll tail = n-i;
        if(i>tail) {
        ans+=dp[i];
        }
    }
    cout.precision(10);
    cout.setf(ios::fixed);
    cout<<ans;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;


int main() {
  set<int> st;
  int n; cin>>n;
  for(int i=0;i<n;i++){
    int t;
    cin >>t;
    st.insert(t);
  }
  if(st.size()==n){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LaL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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 namespace std;

int main(){
  ll X;
  cin>>X;
  
  ll A[11000];
  for(ll i=0; i<1000; ++i){
    A[i]=i*i*i*i*i;
  }
  
  for(ll i=0; i<1000; ++i){
    for(ll j=0; j<=i; ++j){
      if(A[i]-A[j]==X){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
      else if(A[i]+A[j]==X){
        j*=-1ll;
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 3644
import sys
input=sys.stdin.readline
def main():
    N=int(input())
    S=[""]*N
    result={}
    for i in range(N):
        S[i]=input().strip()
        if S[i] not in result:
            result[S[i]]=1
        else:
            result[S[i]]+=1

    result=sorted(result.items())
    result=sorted(result,key=lambda x:-x[1])

    max_num=result[0][1]
    for i in range(len(result)):
        if result[i][1]==max_num:
            print(result[i][0])
        else:
            break
    
if __name__=="__main__":
    main()

Measured memory_bytes: 43996
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
map<char, int> m;
signed main() {
    int n;
    cin >> n;
    if(n>=30)cout << "Yes" << endl;
    else cout << "No" << endl;
  return 0; 
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep2(i, n, m) for (int i = m; i < (int)(n); i++)
#define rep(i, n) rep2(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;  //
template <typename T>
T sq(T x) {
  return x * x;
}
signed main() {
  int N, K;
  cin >> N;
  cin >> K;
  int ans;

  rep(i, N) {
    if (i == 0) {
      ans = K;
    } else {
      ans *= (K - 1);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
    long long int a,b;
    scanf("%lld %lld",&a,&b);
    if(a<0&&b>0||a==0||b==0)
        printf("Zero\n");
    else if(a>0)
        printf("Positive\n");
    else if(b<0)
    {
        if((b-a)%2==0)
            printf("Negative\n");
        else
            printf("Positive\n");
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll N, T; std::cin >> N >> T;

  std::vector<ll> t(N);
  rep(i,N) std::cin >> t[i];

  ll ans = 0;
  rep(i,N-1) {
    if ( t[i+1] - t[i] > T ) ans += T;
    else ans += ( t[i+1]-t[i] );
  }
  ans += T;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
class Main{
  public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int a = s.nextInt();
    int b = s.nextInt();
    int c = s.nextInt();
    int d = s.nextInt();
    int turn = 0;
    while(a>0 && c >0){
        if(turn == 0){
            c -= b;
            turn = 1;
        }else{
            a -= d;
            turn = 0;
        }
    }
    if(a>0)
        System.out.println("Yes");
    else 
    System.out.println("No");
  }
}

Measured memory_bytes: 35800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 5000010
int main()
{
	int n;cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	for(int k=1;k<=n;k++)
	{
		int t=__gcd(i,j);
		t=__gcd(t,k);
		sum+=t;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i=0; i<n; i++){
        cin >> x[i];
    }
    for(int i=0; i<n; i++){
        cin >> y[i];
    }
    int d1 = 0, d_inf = 0;
    double d2 = 0, d3 = 0;
    for(int i=0; i<n; i++){
        d1 += abs(x[i]-y[i]);
        d2 += pow(x[i]-y[i], 2);
        d3 += abs(pow(x[i]-y[i], 3));
        if(abs(x[i]-y[i]) >= d_inf) d_inf = abs(x[i]-y[i]);
    }
    d2 = sqrt(d2);
    d3 = cbrt(d3);
    cout << fixed << setprecision(10);
    cout << d1 << endl;
    cout << d2 << endl;
    cout << d3 << endl;
    cout << d_inf << endl;
    return 0;
}


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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int digits(ll n){
  return log10(n) + 1;
}

int main(){
  FAST();

  string str;
  cin >> str;

  int n = str.length();
  string ans(n, 'x');
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 2005
#define maxl 1000000000

using namespace std;

#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()

template <class T>
void mini(T& l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T& l, T r) {
  l = max(l, r);
}

using LL = long long;
using LD = long double;
using ULL = unsigned long long;
const int dx[] = {0, -1, 1, 0, -1, -1, 1, 1},
          dy[] = {-1, 0, 0, 1, -1, 1, -1, 1};
const int INF = 1e9;
const LL MOD = 1e9 + 7;

int t, T;

void Solve() {
  // TODO
  long long a, b, k;
  cin >> a >> b >> k;
  long long t = min(a, k);
  a -= t;
  k -= t;
  t = min(b, k);
  b -= t;
  k -= t;
  cout << a << " " << b << '\n';
}

void Prepare() {
  // TODO
  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // Prepare();
  // cin >> T;
  // for (t = 1; t <= T; t++) {
  //   printf("Case #%d: ", t);
  Solve();
  //}
  return 0;
}


Measured memory_bytes: 256
use proconio::input;


fn solve(mut h: i64) -> i64 {
    let mut i = 1;

    loop {
        if h > 1 {
            h /= 2;
            i += 1;
        }
        else {
            break;
        }
    }

    return 2i64.pow(i) - 1;
}


fn main() {
    input! {
        h: i64,
    }

    println!("{}", solve(h));
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll mod(ll a, ll b)
{
  if (a >= 0)
    return a % b;
  else
    return (b - (-a) % b) % b;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  ll n, k;
  cin >> n >> k;
  ll a[200010];
  rep(i, n) cin >> a[i];
  ll S[200010];
  S[0] = 0;
  rep(i, n) S[i + 1] = S[i] + a[i];
  map<ll, ll> mp; //S[i]

  ll ans = 0;
  for (int i = 0; i <= n + k; i++)
  {
    //追加
    if (i <= n)
    {
      ans += mp[mod(S[i] - i, k)];
      mp[mod(S[i] - i, k)]++;
    }

    //破棄
    if (i + 1 - k >= 0)
    {
      mp[mod(S[i + 1 - k] - (i + 1 - k), k)]--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15872
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N, K = map(int, input().split(" "))
ds = list(map(int, input().split(" ")))
cs = []
for i in range(10):
    if i not in ds: cs.append(i)

ns = str(N)


def solve(N, digit):
    if digit == -1:
        return N
    n = int((N // (10**digit)) % 10)
    if n not in ds:
        return solve(N, digit - 1)
    else:
        new_N = N // (10**(digit + 1))
        new_N = new_N * (10**(digit + 1))
        for i in range(n + 1, 10):
            if i not in ds:
                new_N = new_N + (10**digit) * i
                return solve(new_N, digit-1)
        else:
            new_N = new_N + 10**(digit + 1)
            return solve(new_N, len(str(new_N))-1)

print(solve(N, len(str(N))-1))


Measured memory_bytes: 10044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    vi a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll K;
    cin >> K;
    OUT(a[K - 1]);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll ans = 0;

  REP(i, ceil(SQRT(N))) {
    if (i == 0)
      continue;
    if ((N - i) % i == 0) {
      ll a = (N - i) / i;
      if (i * a <= N && N < (i + 1) * a)
        ans += a;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)

using namespace std;

void solve() {
	int n;
	cin >> n;
	vector <int > a(n);
	
	rep(i, 0, n)
		cin >> a[i];

	ll cnt = 0;
	int num = 1;
	rep(i, 0, n) {
		if(a[i] == num) {
			num++;
		}
		else {
			cnt++;
		}
	}
	if(cnt == n && num == 1) {
		cout << -1 << endl;
		return;
	}
	cout << cnt << endl;

}

int main() {
	int t = 1;
	//cin >> t;
	while(t--)
		solve();

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=305;
const int MOD=998244353;
int n,m;
char s[N];
int a[N];
int sum[N];
long long dp[N][N][N];
int main()
{
	scanf("%s%d",s+1,&m);
	n=strlen(s+1);
	s[++n]='0';
	m=min(m,n);
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(s[i]=='0') cnt++;
		else a[cnt+1]++;
	for(int i=1;i<=cnt;i++)
		sum[i]=sum[i-1]+a[i];
	dp[0][0][0]=1;
	for(int i=1;i<=cnt;i++)
		for(int j=sum[i];j<=n-cnt;j++)
			for(int k=0;k<=m;k++)
			{
				for(int p=0;p<=min(j,n-sum[i-1]-cnt);p++)
					if(k>=max(p-a[i],0)) dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-p][k-max(p-a[i],0)])%MOD;
			}
	long long ans=0;
	for(int k=0;k<=m;k++)
		ans=(ans+dp[cnt][n-cnt][k])%MOD;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 57032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

const string YES = "Yes";
const string NO = "No";

int main() {
  ll N;
  cin >> N;
  ll M;
  cin >> M;
  vector<ll> A(N);
  ll s = 0;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    s += A[i];
  }

  sort(A.begin(), A.end(), greater<ll>());  // 降順

  if (A[M - 1] * 4 * M < s) {
    cout << NO << endl;
    return 0;
  }

  cout << YES << endl;
}


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

#define ff              first
#define ss              second
#define endl            "\n"
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi              acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	int tt = 1;
	// cin >> tt;
	while (tt--)
	{
		int n, W, ans;
		cin >> n >> W;
		int w[n + 1], v[n + 1];
		w[0] = 0; v[0] = 0;
		for (int i = 1; i <= n; i++)
			cin >> w[i] >> v[i];
		int dp[n + 1][100001];
		// dp[i(objects processed)][j(value)] = min weight
		for (int i = 0; i <= n; i++)
			for(int j=0;j<=1e5;j++)
				dp[i][j]=INT_MAX;
		dp[0][0] = 0;
		dp[1][0] = 0;
		dp[1][v[1]] = w[1];
		for (int i = 2; i <= n; i++)
		{
			dp[i][0] = 0;
			for (int j = 1; j <=1e5; j++)
			{
				dp[i][j] = dp[i - 1][j];
				if (j >= v[i])
					dp[i][j] = min(dp[i - 1][j], w[i] + dp[i - 1][j - v[i]]);
			}
		}
		for (int i = 1e5; i >= 0; i--)
		{
			if (dp[n][i] <= W)
			{
				ans = i;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 82468
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <map>
#define R register
#define IN inline
#define gc getchar()
#define W while
#define ll long long
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	W (!isdigit(c)) c = gc;
	W (isdigit(c))
	x = (x << 1) + (x << 3) + c - 48, c = gc;
}
ll cnt[10];
std::map < std::pair<int, int>, int> mp;
int n, m, q, x, y;
int main(void)
{
	in(n), in(m), in(q);
	cnt[0] = 1ll * (n - 2) * (m - 2);
	W (q--)
	{
		in(x), in(y);
		for (R int i = 0; i <= 2; ++i)
		for (R int j = 0; j <= 2; ++j)
		if(x + i <= n && y + j <= m && x + i >= 3 && y + j >= 3) --cnt[mp[{x + i, y + j}]], ++cnt[++mp[{x + i, y + j}]];
	}
	for (R int i = 0; i < 10; ++i) printf("%lld\n", cnt[i]);
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, w;
    cin >> h >> w;
    int h2, w2;
    cin >> h2 >> w2;
    cout << (h - h2) * (w - w2) << endl;
    return 0;
}


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

int main() {
  string A;
  cin >> A;
  int a=0;
  int max=0;
  for (int i = 0; i < 3; i++) {
    if (A.at(i) == 'S')
      a = 0;
    if (A.at(i) == 'R') {
      a++;
      if (max < a)
        max = a;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,sum=0;
    cin>>n;
    vector<ll>a;
    for(ll i=1;i<=n;i++){
    	if(i%3==0 or i%5==0){
    		continue;
		}else{
			sum+=i;
		}
	}
	cout<<sum;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
pii p[200005];
queue<pii> seg;
int main(){
    int n, d, a, x, h;
    scanf("%d%d%d", &n, &d, &a);
    for(int i=1;i<=n;i++) scanf("%d%d", &x, &h), p[i] = pii(x, h);
    sort(p+1, p+1+n);
    LL sum = 0, ans = 0;
    for(int i=1;i<=n;i++){
        x = p[i].first, h = p[i].second;
        while(!seg.empty() && seg.front().first < x){
            sum -= seg.front().second*1ll*a;
            seg.pop();
        }
        if(sum >= h) continue;
        int dv = (h-sum+a-1)/a;
        sum += dv*1ll*a;
        ans += dv;
        seg.push(pii(min((LL)2e9, x+2*1ll*d), dv));
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 2688
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const long long inf = 1234567891234567891;
const int inf_int = 1012345678;
int N; vector<int> A, c, commence; vector<vector<int> > G; vector<vector<long long> > dp0, dp1;
void calc_subtree(int pos, int pre) {
	for (int i : G[pos]) {
		if (i != pre) {
			calc_subtree(i, pos);
			c[pos] += c[i];
		}
	}
}
void calc(int pos, int pre) {
	dp0[pos].resize(c[pos] + 1, inf); dp0[pos][0] = 0;
	dp1[pos].resize(c[pos] + 1, inf);
	int sum = 1;
	for (int i : G[pos]) {
		if (i != pre) {
			calc(i, pos);
			for (int j = sum + c[i] - 1; j >= 0; --j) {
				dp1[pos][j] = min(min(min(dp0[pos][j], dp1[pos][j]) + dp1[i][0], dp1[pos][j] + dp0[i][0]), inf);
				dp0[pos][j] = min(dp0[pos][j] + dp0[i][0], inf);
				for (int k = max(j - sum + 1, 1); k <= c[i] && k <= j; ++k) {
					dp1[pos][j] = min(dp1[pos][j], min(min(dp0[pos][j - k], dp1[pos][j - k]) + dp1[i][k], dp1[pos][j - k] + dp0[i][k]));
					dp0[pos][j] = min(dp0[pos][j], dp0[pos][j - k] + dp0[i][k]);
				}
			}
			sum += c[i];
		}
	}
	for (int i = 0; i < c[pos]; ++i) {
		if (A[pos] > 0) {
			dp0[pos][i] += A[pos];
			dp1[pos][i] += A[pos];
		}
		else {
			dp1[pos][i] = min(dp0[pos][i], dp1[pos][i]) + A[pos];
			dp0[pos][i] = inf;
		}
	}
	for (int i = c[pos] - 1; i >= 0; --i) {
		if (dp0[pos][i] < inf / 2 || dp1[pos][i] < 0) {
			dp0[pos][i + 1] = min(dp0[pos][i + 1], (long long)(0));
			commence[pos] = i;
		}
	}
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N;
	A = vector<int>(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	G = vector<vector<int> >(N);
	for (int i = 0; i < N - 1; ++i) {
		int u1, u2;
		cin >> u1 >> u2; --u1, --u2;
		G[u1].push_back(u2);
		G[u2].push_back(u1);
	}
	c = vector<int>(N, 1);
	calc_subtree(0, -1);
	dp0.resize(N);
	dp1.resize(N);
	commence = vector<int>(N, inf_int);
	calc(0, -1);
	cout << commence[0] << endl;
	return 0;
}

Measured memory_bytes: 164096
#include <iostream>
#include <map>


int main()
{
    int n;
    char d1, d2;
    std::map<char, char> data;
    while(std::cin >> n){
        data.clear();
        if(n == 0){
            break; 
        }
        for(int i = 0; i < n; ++i){
            std::cin >> d1 >> d2;
            data.insert(std::map<char, char>::value_type(d1, d2));
        }

        std::string out;
        std::cin >> n;
        std::map<char, char>::iterator it;
        for(int i = 0; i < n; ++i){
            std::cin >> d1;
            it = data.find(d1);
            if(it == data.end()){
                out += d1; 
            }
            else {
                out += data[d1];
            }
        }
        std::cout << out << std::endl;
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    vector<vector<ll>>cnt(10,vector<ll>(10,0));
    ll n;cin >>n;
    for (int i = 1; i <=n; ++i) {
        int b=i%10;
        int keta;
        if(i<10)keta=0;
        else if(i<100)keta=1;
        else if(i<1000)keta=2;
        else if(i<10000)keta=3;
        else if(i<100000)keta=4;
        else keta=5;
        ll d=1;
        for (int i = 0; i < keta; ++i) {
            d*=10;
        }
//        cout <<d<<endl;
        int f=i/d;
        cnt[f][b]++;
    }
    ll ans=0;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            ans+=cnt[i][j]*cnt[j][i];
        }
    }
    cout <<ans <<endl;
    return 0;
}



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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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 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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
	VL a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	LL ans = INT32_MAX;
	for (int lat = 0; lat < 5; lat++) {
		LL tmp = 0;
		for (int i = 0; i < 5; i++) {
			if (lat == i) {
				continue;
			}
			tmp += a[i];
			if (tmp % 10 != 0) {
				tmp += 10 - (tmp % 10);
			}
		}
		tmp += a[lat];
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
H,W = map(int, input().split())
S = [input() for i in range(H)]

count = []
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    if 0 <= i+x < H and 0 <= j+y < W:
                        if S[i+x][j+y] == "#":
                            cnt += 1
            print(cnt,end="")
        else:
            print("#",end="")
    print()



Measured memory_bytes: 3444
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def isPal(st):
    if(st==st[::-1]):
        return True
    return False

s = input()
n = len(s)
k = (n-1)//2
p = (n+3)//2
# print(s[:k+1], s[p:])
if(isPal(s) and isPal(s[:k]) and isPal(s[p-1:])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll n;
	cin >> n;
	ll nex=1,ans=0,a;
	FOR(i,0,n){
		cin >> a;
		if(a==nex){
			nex++;
		}else{
			ans++;
		}
	}
	if(ans==n)ans=-1;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	long long n,m;
	cin>>n>>m;
	if(n%m)cout<<n;
	else cout<<-1;
    return 0;
}


Measured memory_bytes: 256