akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    put!(if n == m {
        "Yes"
    } else {
        "No"
    });
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    int K;
    cin >> K;
    int N;
    cin >> N;
    vector<int> A(N,0);
    for(int i=0;i<N;i++){cin>>A[i]
    ;}
    int Max=A[0]+(K-A[N-1]);
    for(int i=0;i<N-1;i++){
        Max=max(A[i+1]-A[i],Max);
    ;}
    cout<<K-Max<<endl;


return 0;

}  



Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
ll n, a, b;
vector<ll> h;
bool check(ll m){
    ll nokori=m;
    for(int i=0;i<n;i++){
        if(h[i]<=b*m)continue;
        else{
            ll d=h[i]-b*m;
            nokori-=(d+(a-b-1))/(a-b);
            if(nokori<0){
                return false;
            }
        }
    }
    return true;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>a>>b;

    for (int i = 0; i < n; i++)
    {
        ll temph;
        cin >> temph;
        h.push_back(temph);
    }
    sort(ALL(h));
    ll l=-1;
    ll r=1000000000;
    while(r-l>1){
        //cout<<l<<" "<<r<<"\n";
        ll mid=(r+l)/2;
        if(check(mid)){
            r=mid;
        }
        else{
            l=mid;
        }
    }
    cout << r << "\n";
}


Measured memory_bytes: 1400
package main

import "fmt"

func main() {
	var n, b int
	fmt.Scanf("%d", &n)
	out := 0
	tmp := 0
	for i := 0; i < n; i++ {
		if i < n-1 {
			fmt.Scanf("%d", &b)
		}
		if i == 0 {
			// 初回はB0がA0の上限
			out += b
		} else if i < n-1 {
			// それ以外はBiと一回前のBiの小さい方
			if tmp < b {
				out += tmp
			} else {
				out += b
			}
		} else {
			out += tmp
		}
		// 前の値を記憶
		tmp = b
	}
	fmt.Println(out)
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<int> V;
typedef vector<V> VV;

int main(){
    int N,M;
    cin>>N>>M;
    VV p(M+1);
    REP(i,N){
        int L,R;
        cin>>L>>R;
        p[L].pb(R);
    }
    priority_queue<int> q;
    queue<int> r;
    int cnt=0;
    V a;
    for(auto &it:p[0])a.pb(it);
    
    FOR(i,1,M+1){
        r.push(i);
        int id=p[i].size();
        id--;
        while(id>=0&&r.size()){
            q.push(-p[i][id--]);
            r.pop();
        }
        while(id>=0){
            q.push(-p[i][id--]);
            a.pb(-q.top());
            q.pop();
        }
    }
    int res=0;
    sort(ALL(a));
    for(auto &it:a){
        while(r.size()&&r.front()<it){
            r.pop();
        }
        if(r.size()){
            r.pop();
        }
        else res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 9932
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int a(string s, char c) {
	int ret = 0;
	auto check = [&]() {
		for(auto& C : s) if(C != c) return false;
		return true;
	};
	while(s.size() > 0) {
		if(check() || s.size() == 1) return ret;
		string t;
		for(int i = 0; i+1< s.size(); i++) {
			if(s[i] == c || s[i+1] == c) t += c;
			else t += s[i];
		}
		s = t;
		ret++;
	}
	return INF;
}

int main(){
	string s;
	cin >> s;
	int ans = INF;
	for(char c = 'a'; c <= 'z'; c++) ans = min(ans, a(s, c));
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(ll, N);
  invar(ll, A);
  invar(ll, B);
  
  ll repeat = N / (A + B);
  ll amari = min(N % (A + B), A);
  
  ll res = repeat * A + amari;
  fin(res);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int min(int a, int b){
	return a <= b ? a : b;
}

int ABS(int a){
	return a >= 0 ? a : -a;
}

int main(){
	int N, A, B, C, i, j, k;
	scanf("%d%d%d%d", &N, &A, &B, &C);
	int *l = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &l[i]);
	}
	int a[4], ans = 1000000000, now;
	for(i = 0; i < (1 << (2 * N)); i++){
//		printf("i = %d\n", i);
		for(k = 0; k < 4; k++){
			a[k] = 0;
		}
		now = 0;
		for(j = 0; j < N; j++){
			k = ((i >> (2 * j)) & 3);
			if(i == 4626){
//			printf("(j, k) = (%d, %d)\n", j, k);
}			if(k > 0 && a[k] > 0){
				now += 10;
			}
			a[k] += l[j];
		}
		if(a[1] == 0 || a[2] == 0 || a[3] == 0){
			continue;
		}
		now += ABS(A - a[1]);
		now += ABS(B - a[2]);
		now += ABS(C - a[3]);
//		printf("now = %d\n", now);
		ans = min(ans, now);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
from itertools import accumulate
from bisect import bisect

N, Q = map(int, input().split())
A = list(map(int, input().split()))
X = [int(input()) for _ in range(Q)]

# xに応じて、高橋くんが先頭から何枚連続とれるかを
# 前処理により求めておく
INF = 10**20
B = A[::-1]
Y = [(B[i] + B[2 * i]) // 2 + 1 for i in range(1, (N + 1) // 2)][::-1]
acc1 = list(accumulate(B))
acc2 = list(accumulate(B[2::2][::-1]))[::-1] + [0] * (N - (N - 1) // 2)
ans = '\n'.join(
    str(acc1[i] + acc2[i])
    for i in (
        len(Y) - bisect(Y, x)
        for x in X
    )
)

print(ans)


Measured memory_bytes: 30820
def judge(i):
    for a in a_s:
        di = i - a
        if di < 0:
            return "Second"
        if dp[di] == "Second":
            return "First"
    return "Second"


n, k = map(int, input().split())
a_s = list(map(int, input().split()))
dp = [""] * (k + 1)
dp[0] = "Second"
for i in range(1, k + 1):
    dp[i] = judge(i)
print(dp[-1])


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long k;
   cin>>k;
   long long ans=0;
   long long p=0;
   for(int i=0;i<k;i++)
   {
       p=p*10+7;
       p %= k;
       if(!p)
       {
           cout<<i+1<<endl;
           return 0;
       }

   }
   cout<<-1;
}


Measured memory_bytes: 3644
/* created   : 2019-08-11 23:10:37
 * accepted  : 2019-08-11 23:10:37
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  c -= min(a - b, c);
  cout << c << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <unordered_map>
 
using namespace std;
 
int main()
{
    int s;
    cin >> s;

    unordered_map<int, int> exist_n;

    int n = s;
    exist_n[n] = 1;
    for (int i=0; i<=1000000; i++) {
        if (n%2==0) {
            n = n/2;
        } else {
            n = 3*n+1;
        }
        //cout << n << " ";
        auto itr = exist_n.find(n);
        if (itr != exist_n.end()) {
            //cout << "\nfind ";
            cout << i+2;
            break;
        } else {
            exist_n[n] = 1;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
  std::string s;

  std::cin >> s;

  unsigned int zero_size = 0;
  unsigned int one_size = 0;

  for (size_t i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      zero_size += 1;
    } else {
      one_size += 1;
    }
  }

  std::cout << std::min(zero_size, one_size) * 2 << std::endl;

  return 0;
}


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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)
#define fi first
#define se second

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

P n[100];
vector<P> a[4];
int sum[4][100];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, W;
    cin >> N >> W;
    rep(i, N) cin >> n[i].first >> n[i].second;
    sort(n, n + N, greater<P>());
    int latte = 0;
    rep(i, 4) a[i].push_back(P(0, 0));
    a[latte].push_back(n[0]);
    FOR(i, 1, N) {
        if(n[i].first != n[i - 1].first) ++latte;
        a[latte].push_back(n[i]);
    }
    rep(i, 4) rep(j, a[i].size()){
        if(j == 0) sum[i][j] = 0;
        else sum[i][j] += sum[i][j - 1] + a[i][j].second;
    }
    int res = 0;
    rep(i, a[0].size()) rep(j, a[1].size())  rep(k, a[2].size()) rep(l, a[3].size()) {
        if(a[0][i].first * i + a[1][j].first * j + a[2][k].first * k + a[3][l].first * l > W) continue;
        chmax(res, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
    }
    cout << res << endl;
    return 0;
}

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

int main()
{
  int N, A, B, C, X;
  while( cin >> N >> A >> B >> C >> X, N + A + B + C + X ) {
    int data[100];
    int flame = 0;
    int cnt = 0;
    for(int i=0; i<N; i++) cin >> data[i];
				       
    while( 1 ) {
      if( data[cnt] == X ) {
	cnt++;
      }
  
      if( cnt == N ) break;

      X = (A * X + B) % C;
      flame++;
      if( flame > 10000 ) break;
    }

    if( flame > 10000 ) cout << -1 << endl;
    else cout << flame << endl;
  }
}

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

int main(void)
{
    int N, X, Y;
    cin >> N >> X >> Y;

    int ans[N + 1] = {};
    int minDist;
    for (int i = 1; i < N; ++i) {
        for (int j = i + 1; j < N + 1; ++j) {
            minDist = j - i;
            minDist = min(minDist, abs(i - X) + abs(j - Y) + 1);
            minDist = min(minDist, abs(i - Y) + abs(j - X) + 1);
            ans[minDist]++;
        }
    }

    for (int i = 1; i < N; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n*a, b) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m;
//ld ;
//string s;
const string AC = "AC";
const string WA = "WA";

int main() {
    cin >> n >> m;
    ll sTotal = 0;
    ll pTotal = 0;
    bool solve[n];
    ll penal[n];
    for(ll ii=0;ii<n;ii++){
        solve[ii]=false;
        penal[ii]=0;
    }
    for(ll i=0;i<m;i++){
        ll p;
        string s;
        cin >> p >> s;
        if(!solve[p-1]){
            if(s == AC){
                solve[p-1] = true;
                sTotal++;
                pTotal += penal[p-1];
            }else if(s == WA){
                penal[p-1]++;
            }
        }
    }
    cout << sTotal << " " << pTotal << endl;
    return 0;
}

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

#define int         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;
const int M=1000006;
int f[M],inv[M];
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M){
        f[i]=(1LL*i*f[i-1])%hell;
    }
    inv[M-1]=expo(f[M-1],hell-2,hell);
    for(int i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%hell;
    }
}
int C(int n,int r){
    return (1LL*((1LL*f[n]*inv[r])%hell)*inv[n-r])%hell;
}
int n,dp[200005],s[200005],dp2[200005];
vi a[200005];
void dfs(int node,int par){
    s[node]=1;
    dp[node]=1;
    for(auto i:a[node]){
        if(i!=par){
            dfs(i,node);
            s[node]+=s[i];
            dp[node]=dp[node]*dp[i]%hell*inv[s[i]]%hell;
        }
    }
    dp[node]=dp[node]*f[s[node]-1]%hell;
}
void dfs1(int node,int par){
    if(par==-1) dp2[node]=dp[node];
    for(auto i:a[node]){
        if(i!=par){
            int temp=dp2[node]*inv[n-1]%hell*f[n-s[i]-1]%hell*expo(dp[i],hell-2,hell)%hell*f[s[i]]%hell;
            dp2[i]=dp[i]*inv[s[i]-1]%hell*f[n-1]%hell*temp%hell*inv[n-s[i]]%hell;
            dfs1(i,node);
        }
    }
}
void solve(){
    compute();
    cin>>n;
    rep(i,0,n-1){
        int u,v;
        cin>>u>>v;
        a[u].pb(v);
        a[v].pb(u);
    }
    dfs(1,-1);
    dfs1(1,-1);
    rep(i,1,n+1) cout<<dp2[i]<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 35056
import copy

def sol1(N, X, A):
  cnt = 0
  for i in range(N-1):
    diff = A[i] + A[i+1] - X
    if diff <= 0: continue
    
    if A[i+1] >= diff:
      A[i+1] -= diff
    else:
      A[i] = A[i] - (diff - A[i+1])
      A[i+1] = 0
    cnt += diff
  return cnt

def sol2(N, X, A):
  cnt = 0
  for i in range(N-2, -1, -1):
    diff = A[i] + A[i+1] - X
    if diff <= 0: continue
    
    if A[i] >= diff:
      A[i] -= diff
    else:
      A[i] = 1
      A[i+1] -= diff - (A[i] - 1)

    cnt += diff
  return cnt

if __name__ == '__main__':
  N,X = map(int,input().split())
  A = list(map(int, input().split()))

  print(min(sol1(N,X,copy.deepcopy(A)), sol2(N,X,copy.deepcopy(A))))

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

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

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	long long n,d;
	cin>>n>>d;
	int count=0;
	long long x,y;
	while(n--)
	{
		cin>>x>>y;
		if((x*x+y*y)<=(d*d))
			count++;
	}
	cout<<count<<"\n";
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x+mo_num)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e6+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;

int32_t main()
{
    IOS
    int x,y,z;
    cin>>x>>y>>z;
    cout<<max(z-(x-y),(long long )0);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const int N=2e5+5;

int n,a[N],ans;

int main()
{
    int cnt=1;
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for (int i=0;i<n;i++)
    {
        if (a[i]!=cnt)ans++;
        else
        {
            cnt++;
        }
    }
    if (ans==n)ans=-1;
    cout << ans << endl;
}


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

int main(){
    string t;
    cin >> t;
    for(long long i;i<t.size();i++){
        if(t.at(i)=='?'){
            cout << 'D';
        }else{
            cout << t.at(i);
        }
    }
    cout << endl;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define endl "\n"
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,i,j;
    cin>>n>>k;
    if(k>((n-1)*(n-2))/2)
    {
        cout<<-1;
        return 0;
    }
    cout<<(n*(n-1))/2-k<<endl;
    for(i=2;i<=n;i++)
    {
        cout<<1<<" "<<i<<endl;
    }
    for(i=2;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            if(k>0)
            {
                k--;
            }
            else
            {
                cout<<i<<" "<<j<<endl;
            }
        }
    }
    
    return 0;
}


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

const int MAXN = 105;

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

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += a[i-1];
	}
	for (int j = 1; j <= n; j++) cin >> b[j];
	for (int j = n; j >= 1; j--) b[j] += b[j+1];
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, a[i]+b[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
      a = a * a % mod;
      n >>= 1;
    }
        return res;
}

long long modinv(long long a,long long mod){
  return modpow(a,mod-2,mod);
}

long long int modfact(long long int n,long long int mod){
  if(n){
    return n*modfact(n-1,mod)%mod;
    }else{
      return 1;
    }
}
int main() {
  cout << fixed << setprecision(10);
  ll n;
  cin >> n;
  vector<ll> a(n),b(n);
  map<pair<ll,ll>,pair<ll,ll>> mp;
  ll cur = 0;
  rep(i,n){
    cin >> a.at(i) >> b.at(i);
    if(a.at(i)==0&&b.at(i)==0){
      cur++;
      continue;
    }else if(b.at(i)==0){
      mp[make_pair(1,0)].first++;
      continue;
    }else if(a.at(i)==0){
      mp[make_pair(1,0)].second++;
      continue;
    }
    ll g = gcd(a.at(i),b.at(i));
    a.at(i)/=g; b.at(i)/=g;
    if(a.at(i)<0){
      a.at(i)=-a.at(i);
      b.at(i)=-b.at(i);
    }
    if(b.at(i)<0){
      b.at(i)=-b.at(i);
      swap(a.at(i),b.at(i));
      mp[make_pair(a.at(i),b.at(i))].second++;
    }else{
      mp[make_pair(a.at(i),b.at(i))].first++;
    }
  }
  ll ans = 1;
  for(auto p:mp){
    ll fir = p.second.first;
    ll sec = p.second.second;
    ll tmp = modpow(2,fir,MOD)+modpow(2,sec,MOD)-1;
    ans = (ans*tmp)%MOD;
  }
  cout << (ans+cur-1+MOD)%MOD << endl;
}



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

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;


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

  int a, b, c, d;
  std::cin >> a >> b >> c >> d;

  bool takahashi = true;

  while (c > 0 & a > 0) {
    if (takahashi) {
      c = c - b;
    }
    else {
      a = a - d;
    }
    takahashi = !takahashi;
  }


  if (a > 0) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


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

long long n, m, ans = 1, dog = 1, monkey = 1, mod = 1000000007;

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

	if (abs(n - m) > 1) {
		ans = 0;
	}
	else {
		for (int i = n; i > 0; i--) {
			dog *= i;
			dog %= mod;
		}
		for (int i = m; i > 0; i--) {
			monkey *= i;
			monkey %= mod;
		}
		ans = dog*monkey;
		ans %= mod;
		if (n == m) {
			ans *= 2;
			ans %= mod;

		}
	}

	cout << ans << endl;
}

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

int main(){
    int a,b,c,d,x,y;
    cin >> a >> b >> c >> d;
    
    x=c;
    y=a;
   
    while( x>=0 || y>=0)
	{ 
         if (x - b <=0){
          cout << "Yes" <<endl;
           break;
         }
         else{
           x=(x-b);
          if(y-d<=0){
          cout << "No" <<endl;
          break;
          }else{
            y=(y-d);
          }
         }
      }
 }

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  int X, Y, Z, K;
  std::vector<unsigned long long> A, B, C;
  std::cin >> X >> Y >> Z >> K;
  A.resize(X);
  B.resize(Y);
  C.resize(Z);
  for (auto& x : A) std::cin >> x;
  for (auto& y : B) std::cin >> y;
  for (auto& z : C) std::cin >> z;
  
  std::sort(A.begin(), A.end(), std::greater<>{});
  std::sort(B.begin(), B.end(), std::greater<>{});
  std::sort(C.begin(), C.end(), std::greater<>{});
  
  std::vector<unsigned long long> R;
  R.resize(K);
  for (auto x : A)
  	for (auto y : B)
      for (auto z : C)
      {
        auto r = x + y + z;
        if (r <= R.back()) continue;
        
        auto i = std::lower_bound(R.begin(), R.end(), r, std::greater<>{});
        if (i == R.end()) continue;
        
        R.back() = r;
        std::rotate(i, R.end() - 1, R.end());
      }
  
  for (auto v : R) std::cout << v << std::endl;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
X = list(sorted(map(int, input().split())))

if N >= M:
    print(0)
else:
    D = []
    for i in range(len(X)-1):
        D.append(abs(X[i]-X[i+1]))
    D = list(sorted(D))
    print(sum(D[:M-N]))


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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> tasks;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    tasks.emplace_back(b, a);
  }
  
  sort(tasks.begin(), tasks.end());
  int sum = 0;
  bool isyes = true;
  for (auto v :tasks) {
    sum += v.second;
    if (sum > v.first) {
      isyes = false;
      break;
    }
  }
  
  cout << (isyes ? "Yes" : "No") << endl;
  
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vvi v(n);
  int a, b;
  REP(i, n-1) {
    cin >> a >> b;
    a--; b--;
    v[a].pb(b);
    v[b].pb(a);
  }

  vi col(n, 0);
  col[0] = 1;
  col[n-1] = -1;
  map<int, int> m;
  queue<int> q;
  q.push(0);
  q.push(n-1);
  while(!q.empty()) {
    int now = q.front(); q.pop();
    REP(i, SZ(v[now])) {
      if(col[v[now][i]] == 0) {
        m[col[now]]++;
        col[v[now][i]] = col[now];
        q.push(v[now][i]);
      }
    }
  }

  if(m[1] > m[-1]) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }
  
}


Measured memory_bytes: 6144
N = int(input())
A = list(map(int, input().split())) # food
B = list(map(int, input().split())) # manzokudo
C = list(map(int, input().split())) # add manzokudo

full = 0
pre = 0
for i in range(N):
    a = A[i]
    b = B[a-1]
    if pre+1 == a and pre != 0:
        c = C[pre-1]
    else:
        c = 0

    full += b + c
    pre = a

print(full)

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

int main(void){
  int a,k;
  cin >> a >> k;
  if(k == 1){
    cout << 0 << endl;
  }
  else{
    cout << a - k << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main(){
 ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t;
   t=1;
   while(t--){
   	long long int ans=0;
   	int n;
   	cin>>n;
   	map<int,int> mp;
   	for(int i=1;i<=100;i++){
   		for(int j=1;j<=100;j++){
   			for(int k=1;k<=100;k++){
   				mp[i*i+j*j+k*k+i*j+i*k+j*k]++;
			   }
		   }
       }
    for(int i=1;i<=n;i++){
    	cout<<mp[i]<<"\n";
	}
   }
   return 0;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main(){
    ll x, y; cin >> x >> y;
    if(x % y == 0) printf("-1\n");
    else printf("%lld\n", x);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const ll mod=1e9+7;
ll qp(ll t1,ll t2) { ll s=1;for (;t2;t1=t1*t1%mod,t2>>=1) if (t2&1) s=s*t1%mod; return s;}
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
vector<int> p[maxn];
int a[maxn];
int b[maxn];
ll dp[maxn];
ll temp[maxn];
int main()
{
    int n;

    n=read();

    for (int q=1;q<=n;q++)
    a[q]=read();

    int tot=1;
    for (int q=1;q<=n;q++)
    {
        if( a[q]!=a[q-1])
        {
            b[tot++]=a[q];
        }
    }

    dp[0]=1;
    int z,x,sz;
    memset(temp,0,sizeof temp);
    for (int q=1;q<tot;q++)
    {

        dp[q]=dp[q-1];
        z=b[q],x;
        if (temp[z]==0)
        temp[z]=dp[q-1];
        else 
        {
            dp[q]+=temp[z];
            temp[z]+=dp[q-1];
            dp[q]%=mod;
            temp[z]%=mod;
        }
    }

    printf("%lld\n",dp[tot-1]);


    return 0;
}

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

long long a[3][3];
bool t[3][3];

int main() {
  for (int i = 0; i < 3; i++)
  		for (int j = 0; j < 3; j++)
  			cin >> a[i][j];
	int n, x;
  	cin >> n;
  while (n--) {
  	cin >> x; 
     for (int i = 0; i < 3; i++)
  		for (int j = 0; j < 3; j++)
          	if (a[i][j] == x)
              	t[i][j] = true;
   }
  if ((t[0][0] && t[0][1] && t[0][2]) || (t[1][0] && t[1][1] && t[1][2]) || (t[2][0] && t[2][1] && t[2][2]))
		return cout << "Yes" << '\n', 0;
  if ((t[0][0] && t[1][0] && t[2][0]) || (t[0][1] && t[1][1] && t[2][1]) || (t[0][2] && t[1][2] && t[2][2]))
    	return cout << "Yes" << '\n', 0;
  if ((t[0][0] && t[1][1] && t[2][2]) || (t[2][0] && t[1][1] && t[0][2]))
    	return cout << "Yes" << '\n', 0;
  cout << "No" << '\n';
    
    return 0; 
}

Measured memory_bytes: 256
n, q = gets.chomp.split.map(&:to_i)
A = []
n.times{ 
    A.push([])
}

q.times{
    choice, t, x = gets.chomp.split(" ").map(&:to_i)
    case choice
    when 0
        insert_at = A[t].bsearch_index{|val| val >= x}
        if insert_at.nil?
            A[t].push(x)
        else
            A[t].insert(insert_at, x) 
        end
    when 1
        puts A[t][-1] unless A[t].empty?
    when 2
        A[t].pop unless A[t].empty?
    end
    }




Measured memory_bytes: 10520
#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
int main(){
    priority_queue<long double> que;
    int n,m;
    cin >> n >> m;
    long double t;
    for(int i = 0;i<n;i++){
        cin >> t;
        que.push(t);
    }
    for(int i = 0;i<m;i++){
        long double tmp = que.top();
        que.pop();
        que.push(tmp/2);
    }
    long long ans = 0;
    while(!que.empty()){
        long double tmp = que.top();
        que.pop();
        ans+=floor(tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#!/usr/bin/env python3
import sys
import fractions

## 最小公倍数(LCM)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def solve(N: int, M: int, S: str, T: str):
    X = lcm(N,M)
    i = j = 0

    while i < N and j < M:
        if S[i] == T[j]:
            i += X//M
            j += X//N
            continue
        else:
            print(-1)
            return
    print(X)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(N, M, S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
 
void swap (double v[], int i, int j){
	double tmp = v[i];
  	v[i] = v[j];
  	v[j] = tmp;
}
 
void sort (double v[], int n){
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n-1; j++)
      if (v[j+1] < v[j])
        swap (v, j, j+1);
}
 
int main(){
  
  int N,count = 0;
  cin >> N;
  double v[N],blend,sum;
  for (int i = 0; i < N; i++)
    cin >> v[i];
  
  sort (v, N);
 
  if (N == 2)
   blend = (v[0]+v[1])/2;
  
  else if (N >= 3){
	for(int i = 1; i < N; i++){
      if (i == 1){
        blend = (v[0]+v[1])/2;
        sum = blend;
        blend = 0;
      }
      else {
        blend = (sum + v[i])/2;
        sum = blend;
      }
    }    
  }
  cout << blend;
}

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

int main(){
	int i;
	int n;
	int l[110];
	cin >> n;
	rep(i, n) cin >> l[i];
	sort(l, l+n);
	int count = 0;
	rep(i, n-1){
		count += l[i];
	}
	if(l[n-1] < count) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{

	public static void main(String[] args) {
	Scanner src = new Scanner(System.in);
	int a = src.nextInt();
	int b = src.nextInt();
	int c = src.nextInt();
	
		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 17220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=550;
int a[maxn][maxn];
int N, ans1[maxn*maxn],ans2[maxn*maxn],ans3[maxn*maxn],ans4[maxn*maxn];
int main() {
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
	for(int j=1;j<=w;j++)
		scanf("%d",&a[i][j]);
		
	for(int i=1;i<=h;i++)
	for(int j=1;j<=w;j++){
		if(j!=w){
			if(a[i][j]%2){
				a[i][j]--; a[i][j+1]++;
				N++;
				ans1[N]=i;ans2[N]=j;ans3[N]=i;ans4[N]=j+1;
			}
		}
		if(i!=h){
			if(a[i][j]%2){
				a[i][j]--; a[i+1][j]++;
				N++;
				ans1[N]=i;ans2[N]=j;ans3[N]=i+1;ans4[N]=j;
			}
		}
	
	}
	printf("%d\n",N);
	for(int i=1;i<=N;i++){
		printf("%d %d %d %d\n",ans1[i], ans2[i], ans3[i], ans4[i]);
	}
}

Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	long long int a[n];
	long long int b[n];
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	long long int c[m];
	long long int d[m];
	for(int i = 0; i < m; i++){
		cin >> c[i] >> d[i];
	}
	for(int i = 0; i < n; i++){
		int ans;
		long long int min = 10000000000;
		for(int j = 0; j < m; j++){
			if((abs(a[i] - c[j]) + abs(b[i] - d[j])) < min){
				min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans = j + 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
mod = 10 ** 9 + 7

broken = [0] * (n + 1)
for i in a:
    broken[i] = 1

dp = [0] * (n + 2)
dp[n] = 1
for j in range(n - 1, -1, -1):
    if broken[j] == 1:
        dp[i] = 0
        continue
    dp[j] = (dp[j+1] + dp[j+2])%mod
print(dp[0])

Measured memory_bytes: 8616
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long int ll;
typedef long double ld;

int main(){
    while(true){
        ll h,w;
        cin >> h >> w;
        if(h==0 && w==0){
            break;
        }
        for (int i=0;i<h;++i){
            for (int j=0;j<w;++j){
                if (i==0 || i==h-1 || j==0 || j==w-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

void solve() {
	int a,b,k;
	cin >> a >> b >> k;
	int t = 0;
	int i = min(a,b);

	for (; i >= 1 && t < k; --i) {
		if (a%i==0 && b%i == 0) {
			++t;
		}
	}

	cout << i+1 << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    int a=n%10;
    if(a==3)cout<<"bon";
    else if(a==0||a==1||a==6||a==8)cout<<"pon";
    else cout<<"hon";
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n;
    cin>>n;
    vector<int> h;
    h.resize(n);
    for(i=0;i<n;i++)
        cin>>h[i];
    vector<int> ans(n);
    ans[0]=0;
    ans[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
        ans[i]=min(abs(h[i-1]-h[i])+ans[i-1],abs(h[i]-h[i-2])+ans[i-2]);
    }
    cout<<ans[n-1];
    return 0;

    }



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

int main () {
  
  int N;
  cin >> N;
  vector<double> A(N);
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  double ans = 0;
  
  for (int i = 0; i < N; i++) {
    ans += (1 / A[i]);
  }
  
  cout << 1 / ans << endl;
  
}

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

typedef long long ll;
using namespace std;

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

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

    sort(mati.rbegin(), mati.rend());
    stack<double> nabe;
    for (int i = 0; i < n; i++) {
        nabe.push(mati[i]);
    }

    while (nabe.size() > 1) {
        double first = nabe.top();
        nabe.pop();
        double second = nabe.top();
        nabe.pop();
        double newMati = (first + second) / 2;
        nabe.push(newMati);
    }

    printf("%.10f", nabe.top());
}


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

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    string s;
    cin>>s;
    int p=0;
    bool w=true;
    while(p<s.size()){
        if(s.at(p)=='h'){
            string tmp=s.substr(p,2);
            string hi="hi";
            p+=2;
            if(tmp==hi)continue;
            else{
                w=false;
            }
        }
        else {
            w=false;
            break;
        }

    }
    if(w)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




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

int main(void){
  int N, Y;
  cin >> N >> Y;
  int x = Y / 1000;
  int s = x / 5;
  int z, y_t, x_t = 0;
  int m = 0;
  for(int i = 0; i <= s ;++i){
    int x_t = x - 5*i;
    int y = i;
    int p = y / 2;
    for(int j = 0; j <= p; ++j){
      int y_t = y - 2*j;
      int z = j;
      if(x_t + y_t + z == N){
        cout << z << " " << y_t << " " << x_t << endl;
        m = 1;
      }
    }
    if(m == 1){
      break;
    }
  }
  if(m == 0){
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# Date [ 2020-08-15 21:53:58 ]
# Problem [ d.py ]
# Author Koki_tkg

import sys;      from decimal import Decimal
import math;     from itertools import combinations, product, accumulate
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 6 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, k = read_ints()
    p = read_int_list()
    c = read_int_list()
    loop_list = []
    visit = [False] * n

    # 閉路を探してloop_listに格納
    for i in range(n):
        if visit[i]:
            continue

        visit[i] = True
        now = i
        loop_tmp = []

        while True:
            now = p[now] - 1
            visit[now] = True
            loop_tmp.append(c[now])
            if visit[p[now] - 1]:
                loop_tmp.append(c[p[now] - 1])
                break
        loop_list.append(loop_tmp)

    #print(loop_list)
    ans = -10 ** 18

    #loopごとに全部試す
    for loop in loop_list:
        length = len(loop)
        score = sum(loop)
        if k > length:
            if score > 0:
                ans = max(ans, (k // length) * score + search_max_score(loop, k % length, length), (k // length - 1) * score + search_max_score(loop, length, length))
            else:
                ans = max(ans, search_max_score(loop, length, length))
        else:
            ans = max(ans, search_max_score(loop, k, length))
    
    print(ans)


def search_max_score(loop, rest, length):
    if rest == 0:
        ans = 0
    elif rest == 1:
        ans = max(loop)
    else:
        ans = -10**18
        loop += loop
        for i in range(length):
            tmp = list(accumulate(loop[i:i + rest]))
            #print(tmp)
            ans = max(ans, max(tmp))
    
    return ans

if __name__ ==  '__main__':
    Main()

Measured memory_bytes: 127888