akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    double h,w,n;
    cin>>h>>w>>n;
    int ans=0;
    cout<<ceil(n/max(h,w))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define DIV (1000000007)

int colors[3];
int CountSameColorPattern(int A) {
	int ret = 0;
	int addpos = -1;
	for  (int i = 0; i < 3; i++) {
		if (colors[i] == A) {
			addpos = i;
			ret++;
		}
	}
	if (addpos >= 0) colors[addpos]++;
	return ret;
}


int main(void) {
	colors[0] = 0;
	colors[1] = 0;
	colors[2] = 0;

	int N;
	cin >> N;
	long long ans = 1;
	for (int i = 1; i <= N; i++) {
		int A;
		cin >> A;
		int patternCnt = CountSameColorPattern(A);
		if (patternCnt==0) { // 嘘つき
			cout << 0 << endl;
			return 0;
		}
		ans = ans * (long long)patternCnt % DIV;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
int a[5],ans;
int main(){
	SF("%d%d%d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	if((a[1]-a[0])%2){
		a[2]++;
		a[1]++;
		ans++;
	}
	ans+=(a[1]-a[0])/2;
	ans+=a[2]-a[1];
	PF("%d",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define mp make_pair
#define pb push_back
#define f first
#define s second
const ll mod=998244353;
const ll N=2e5+5;
unordered_map<ll,vector<ll>> adj;
vector<ll> vis(300005,0);
vector<ll> p(100005,0);
ll c[100005];
ll cnt;
ll n;
void dfs(ll node)
{
  if(vis[node])
    return;
  vis[node]=1;
  for(auto i:adj[node])
    {
      dfs(i);
    }
}
struct range{
  ll l;
  ll r;
  ll a;
};
bool cmp(range& p1,range& p2)
{
    if(p1.a==p2.a)
      return p1.l<p2.l;
    return p1.a<p2.a;
}
int main()
{
   ll n,m,i;
   cin>>n>>m;
   ll u,v;
   while(m--)
   {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
   }
   for(i=1;i<=n;i++)
   {
      if(!vis[i])
          {
            dfs(i);
            cnt++;
          }
   }
   cout<<cnt-1;
}

Measured memory_bytes: 16744
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    long long n,k; cin>>n>>k;
    long long x[n],left=-1,right=-1;
    rep(i,n){
        cin>>x[i];
        if(x[i]<=0) left=i;
        if(x[i]>0&&right==-1) right=i;
    }
    long long ans=1e15;
    if(left>=0){
        for(int i=0;i<k;i++){
            if(left-i>=0){
                long long tmp=abs(x[left-i]);
                if(k-1-i>0){
                    tmp+=abs(x[left-i]);
                    if(left+(k-1-i)<n) tmp+=abs(x[left+(k-1-i)]);
                    else continue;
                }
                // cout<<tmp<<endl;
                ans=min(ans,tmp);
            }
        }
    }
    if(right>=0){
        for(int i=0;i<k;i++){
            if(right+i<n){
                long long tmp=abs(x[right+i]);
                if(k-1-i>0){
                    tmp+=abs(x[right+i]);
                    if(right-(k-1-i)>=0) tmp+=abs(x[right-(k-1-i)]);
                    else continue;
                }
                // cout<<tmp<<endl;
                ans=min(ans,tmp);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
n= int(input())

lis1 = []
lis2 = []
ans = n

for a in range(1, int(n/2)+1):
	aa = 0
	bb = 0
	b = n - a
	
	for j in str(a):#文字列を一文字ずつの配列にする
		lis1.append(j)
	for i in range(len(lis1)):
		aa += int(lis1[i])
		
	for j in str(b):#文字列を一文字ずつの配列にする
		lis2.append(j)
	for i in range(len(lis2)):
		bb += int(lis2[i])
	s 	= aa + bb
	if s < ans:#和がansより小さかったら
		ans = s
		
	lis1.clear()#配列の中身を全消しする
	lis2.clear()#配列の中身を全消しする

print(ans)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val s = readLine()!!
    println("${s.first()}${s.length - 2}${s.last()}")

}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 31944
#include<iostream>
#include<vector>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    vector<vector <int>> hito(K);
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int bango;
            cin >> bango;
          bango--;
            hito[i].push_back(bango);
        }
    }
    int key = 0;
    vector<int> count(N);
    for (int h = 0; h < N; h++) {
        for (int i = 0; i < K; i++) {
            for (int j = 0; j < hito[i].size(); j++) {
                if (hito[i][j] == h) {
                    count[h]++;
                }
            }
        }
        if (count[h] > 0) {
            key++;
        }
    }
     cout << N - key << endl;
}

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

int n,a,b,cnt,ans;

int digitsum(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main() {
    ans=0;
    cin >> n >> a >> b;
    for (int i=1;i<=n;++i){
        cnt=digitsum(i);
        if (cnt>=a and cnt<=b) ans+=i;
    }
    cout << ans << endl;
}

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

using namespace std;

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

int main() {

    int a, b, c; ll k;

    scanf("%d%d%d%lld", &a, &b, &c, &k);
    printf("%d\n", k & 1 ? b - a : a - b);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
template <typename T>
T gcd(T m, T n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
         r %= 1000000007;
         rr %= 1000000007;
    }
    r /= rr;
     r %= 1000000007;
    return r;
}
#define rep(a,b,c) for(ll a = b; a < c; ++i)
ll mod = 1000000007;
//---------------------------------------------------------------------------------------------------
ll f[101010];
void init() {
    f[0] = 1;
    rep(i, 1, 101010) f[i] = (f[i - 1] * i) % mod;
}
//---------------------------------------------------------------------------------------------------
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = f[n-k]; // = (n-k)!
    ll c = f[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * inv(bc)) % mod;
}
ll pow2_(ll n){
  
  ll div = 1000000007ll;
  ll ans = 0,k=2;
  {
    bitset<48> b(n);
    FOR(i,32){
      ans+=b[i]*k%div;
      ans%=div;
      k*=k;
      k%=div;
    }
  }
  return ans;
}
int main(){
  ll N,K;
  cin>>N>>K;
  cout<<min(N%K,abs(N%K-K))<<endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::cmp;

#[allow(dead_code)]
fn getline() -> Vec<String> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok().unwrap();
    s.split(' ').map(|x| x.trim().to_string()).collect::<Vec<String>>()
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>(s: &String) -> T {
    s.parse().ok().unwrap()
}

fn main() {
    let abc = getline();
    let a: usize = get(&abc[0]);
    let b: usize = get(&abc[1]);
    let c: usize = get(&abc[2]);
    let mut v = vec![false; b];
    let mut x = 0usize;
    for _ in 0..b {
        v[x] = true;
        x = (x + a) % b;
    }
    if v[c] {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<ll> h(n);
    cins(all(h));
    SORT(h);
    ll ans = 1e9;
    rep(i,n-k+1){
        chmin(ans,h[i+k-1]-h[i]);
    }
    PRINT(ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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;
}
///////////////////////////////////////////////
int main(){
    int N,M;
    cin >> N >> M;
    static int A[32] = {};

    REP(i,N){
        int K;
        cin >> K;
        REP(j,K){
            int a; cin >> a;
            A[a]++;
        }
    }

    int ans = 0;
    REP(i,31){
        if (A[i] == N) ans++;
    }

    PRINTD(ans);

}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
import itertools

def main():
    a = [[int(x) for x in sys.stdin.readline().split()] for _ in range(3)]
    n = int(sys.stdin.readline().strip())
    bs = [int(sys.stdin.readline().strip()) for _ in range(n)]

    amap = {a[i][j]: (i, j) for i, j in itertools.product(range(3), range(3))}
    hit = [[False, False, False] for _ in range(3)]

    for b in bs:
        if b in amap:
            i, j = amap[b]
            hit[i][j] = True

    if any(all(hit[i][j] for j in range(3)) for i in range(3)):
        print('Yes')
        return
    if any(all(hit[i][j] for i in range(3)) for j in range(3)):
        print('Yes')
        return
    if ((hit[0][0] and hit[1][1] and hit[2][2])
            or (hit[0][2] and hit[1][1] and hit[2][0])):
        print('Yes')
        return
    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3192
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
     
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector <int> v;
    for(int i = 0; i < n;++i){
        int x; cin >> x;
        v.pb(x);
    }
    int cnt = 0;
    reverse(all(v));
    bool flag = true;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1 ; j < n; ++j){
            if(v[i] < v[j]){
                flag = false;
            }
        }
        if(flag == true){
            cnt++;
        }else{
            flag = true;
        }

    }
    cout << cnt;
}

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

int H, W;
string pat = "URDL";
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
char board[15][15];

void solve(int x, int y, int dir, string command, int rest) {
    // printf("x = %d, y = %d, dir = %c, rest = %d\n", x, y, pat[dir], rest);
    if(rest == 0) {
        cout << command << endl;
        exit(0);
    }

    for(int k=0; k<4; k++) {
        if(abs(k-dir) == 2) continue;
        int nx = x, ny = y;
        while(1) {
            nx += dx[k], ny += dy[k];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) break;
            // printf("k = %d, nx = %d, ny = %d, char = %c\n", k, nx, ny, board[nx][ny]);
            if(board[nx][ny] == 'o') {
                // printf("ok %d, %d\n", nx, ny);
                board[nx][ny] = '.';
                solve(nx, ny, k, command + pat[k], rest-1);
                board[nx][ny] = 'o';
                break;
            }
        }
    }
}

int main() {
    scanf("%d%d", &H, &W);
    int sx = -1, sy = -1, dir = -1, rest = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            scanf(" %c", &board[i][j]);
            if(pat.find(board[i][j]) != string::npos) {
                sx = i, sy = j;
                dir = pat.find(board[i][j]);
            }
            rest += (board[i][j] == 'o');
        }
    }

    board[sx][sy] = '.';
    solve(sx, sy, dir, "", rest);
    return 0;
}


Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -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; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll cnt = 0;
    while(1){
        bool did = false;
        for(int i=0; i<N; i++){
            if(A[i] >= N){
                ll temp = A[i]/N;
                A[i] = A[i]%N;
                for(int j=0; j<N; j++){
                    if(i != j){
                        A[j] += temp;
                    }
                }
                did = true;
                cnt += temp;
            }
        }
        if(!did) break;        
    }
    cout << cnt << enld;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e7;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[20],cost[1050],keys[1050];
int dp[1005][1<<13],n,m;
int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
bool check(int N,int pos)
{
    return (bool) (N & (1<<pos));
}
int bitmask(int pos,int mask)
{
    if(pos==m)
    {
        if(mask==((1<<n)-1))
            return 0;
        return 1e8;
    }
    int &ret=dp[pos][mask];
    if(~ret)
        return ret;
    ret=bitmask(pos+1,mask);
    ret=min(ret,cost[pos]+bitmask(pos+1,mask|keys[pos]));
    return ret;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>m;
    priority_queue<pair<int,int> >pq;
    for(int i=0; i<m; i++)
    {
        cin>>cost[i];
        int a;
        cin>>a;
        for(int j=0; j<a; j++)
        {
            int b;
            cin>>b;
            keys[i]|=1<<(b-1);
        }
    }
    memset(dp,-1,sizeof(dp));
    int ans=bitmask(0,0);
    if(ans==1e8)
        ans=-1;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 35848
k, n = map(int, input().split())
a_list = list(map(int, input().split()))
longest = 0
for i in range(n):
    if i==n-1:
        longest = max(longest, k-a_list[i]+a_list[0])
    else:
        distance = a_list[i+1] - a_list[i]
        longest = max(longest, distance)
print(k-longest)

Measured memory_bytes: 32256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
  string s;
  cin>>s;
  ll num=0,ans=1e9;
  for(int i=0;i<s.size()-2;i++){
    num=0;
    for(int j=0;j<3;j++){
      ll yojo=s[i+j]-'0';
      num+=pow(10,2-j)*yojo;
    }
    ans=min(abs(753-num),ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 892
S = input()
s = list(S)
T = input()
t = list(T)
ss = len(s)
tt = len(t)
ll = ss - tt +1

A = [[] for _ in range(ll)]

for i in range(ll):
  for j in range(tt):
    A[i].append(s[int(i)+int(j)])
    
d = tt

for i in range(ll):
  e = 0
  for j in range(tt):
    if A[i][j] != t[j]:
      e += 1
  if e<d:
    d = e
  else:
    d = d
    
print(d)



Measured memory_bytes: 10828
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding

	int n;
	cin>>n;
	std::vector<int> a(n+1);

	for(int i=1;i<=n;i++)cin>>a[i];

	int m  =0 ;
	std::vector<int > b(n+1,0);

	for(int i=n;i>=1;i--){
		int cnt = 0;
		int j = 2*i;
		for(int k=3;j<=n;k++){
			cnt += b[j];
			j = i*k;
		}
		cnt%=2;
		b[i] = cnt ^ a[i];
		if(b[i]) m++;
	}
	cout<<m<<endl;
	for(int i=1;i<=n;i++){
		if(b[i]==1)cout<<i<<" ";
	}cout<<endl;
	
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}

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

template <typename T>
T safeAt(vector<T> v, int at, T def){
    if(0 <= at && at < v.size()){
        return v[at];
    }else{
        return def;
    }
}

template <typename T>
vector<T> readList(int len){
    vector<T> res(len);
    for(int i=0; i < len; i++){
        T temp;
        cin >> temp;
        res[i] = temp;
    }
    return res;
}

int n, k;
vector<long> h;
vector<long> dp;
long M = 11234567890;

int main(){
    cin >> n >> k;
    h = readList<long>(n);
    dp = vector<long>(n);

    // fill the end
    dp[n - 1] = 0;
    for(int i=n-2; i >= 0; i--){
        long current_min = M;
        for(int j=1; j <= k; j++){
            if(i + j > n - 1){
                continue;
            }
            current_min = min(current_min, dp[i + j] + abs(h[i] - h[i + j]));
        }
        dp[i] = current_min;
    }

    cout << dp[0] << endl;
}

Measured memory_bytes: 1792
N = int(input())
p = list(map(int, input().split()))

a = list(map(lambda x : x * (N + 1), range(1, N + 1)))
b = list(map(lambda x : x * (N + 1), range(N, 0, -1)))

for i in range(1, N):
    b[p[i] - 1] += i
    
print(" ".join(map(str, a)))
print(" ".join(map(str, b)))

Measured memory_bytes: 7232
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s_d,h; cin>>s_d>>h;
  int size_s, size_h;
  size_s = s_d.size(); size_h = h.size();
  vector<int> int_s_d, int_h;
  /*
  for(string::iterator it=s_d.begin(); it!=s_d.end(); ++it){
    if( *it == '?') cout<<'z';
    else cout<< *it;
  }
  cout<<endl;
  */
  for(int i=0; i<size_s; ++i){
    if( s_d[i] == '?'){
      int_s_d.push_back(0);
    }
    else int_s_d.push_back( s_d[i] - 'a' + 1);
  }
  //for(vector<int>::iterator it=int_s_d.begin(); it!=int_s_d.end(); ++it) cout<<*it;
  //cout<<endl;
  for(int i=0; i<size_h; ++i){
    if( h[i] == '?'){
      int_h.push_back(0);
    }
    else int_h.push_back( h[i] - 'a' + 1);
  }
  vector<vector<int> > ans;
  ans = vector<vector<int> >(50, vector<int>(50,0));
  int ans_n=0;
  for(int i=size_s-size_h; i>=0; --i){
    bool restorable = true;
    for(int j=0; j<size_h; ++j){
      if( s_d[i+j] != '?' && s_d[i+j] != h[j]){
        restorable = false; break;
      }
    }
    if(restorable){
      for(int j=0; j<size_s; ++j){
        ans[ans_n][j] = int_s_d[j];
      }
      //for(vector<int>::iterator it=ans[ans_n].begin(); it!=ans[ans_n].end(); ++it) cout<<*it;
      //cout<<endl;
      for(int j=0; j<size_h; ++j){
        ans[ans_n][i+j] = int_h[j];
      }
      //for(vector<int>::iterator it=ans[ans_n].begin(); it!=ans[ans_n].end(); ++it) cout<<*it;
      //cout<<endl;
      ++ans_n;
    }
  }
  if( ans_n){
    vector<vector<int> > v;
    v = vector<vector<int> >(ans_n, vector<int>(size_s));
    for(int i=0; i<ans_n; ++i){
      for(int j=0; j<size_s; ++j){
        v[i][j]=ans[i][j];
      }
    }
    //for(vector<int>::iterator it=v[0].begin(); it!=v[0].end(); ++it) cout<<*it;
    //cout<<endl;
    //sort( v.begin(), v.end());
    for(int i=0; i<size_s; ++i){
      if( v[0][i] == 0) cout<<"a";
      else cout<<(char)(v[0][i]-1+'a');
    }
    cout<<endl;
  }
  else{
    cout<< "UNRESTORABLE"<<endl;
  }
  return 0;
}


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

int main(){
  int n;
  while(cin >> n, n){
    string s;
    char thread[1010][1100];
    int len[2][1010];
    
    memset(thread, ' ', sizeof(thread));
    memset(len, 0, sizeof(len));
    
    cin >> s;
    for(int j = 0 ; j < (int)s.size() ; j++) thread[0][j] = s[j];
    len[1][0] = (int)s.size();

    for(int i = 1 ; i < n ; i++){
      cin >> s;
      int p = 0;

      for(int j = 0 ; j < (int)s.size() ; j++)
	if(s[j] != '.'){ p = j; break; }
      
      s = "+" + s.substr(p);
      
      for(int j = p ; j < p + (int)s.size() ; j++)
	thread[i][j-1] = s[j-p];      
      
      len[0][i] = p-1;
      len[1][i] = p + (int)s.size() - 1;
    }
    
    for(int i = 1 ; i < n ; i++){
      bool flag = false;
      for(int j = i+1 ; j < n ; j++){
	if(isalpha(thread[j][len[0][i]])) break;
	if(thread[j][len[0][i]] == '+'){
	  flag = true;
	  break;
	}
      }
      
      if(!flag) continue;
      
      for(int j = i+1 ; j < n ; j++){
	if(thread[j][len[0][i]] == '+' || isalpha(thread[j][len[0][i]])) break;
	thread[j][len[0][i]] = '|';	
      }      
    }
    

    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < len[1][i] ; j++){
	cout << thread[i][j];
      }
      cout << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 2312
# coding: utf-8
# Your code here!
N=int(input())

A=list(map(int,input().split()))

me=A[0]
you=sum(A)-A[0]
ans=abs(me-you)
for i in range(1,N-1):
    me+=A[i]
    you-=A[i]
    ans=min(ans,abs(me-you))

print(ans)


Measured memory_bytes: 23800
<?php
	$n=fgets(STDIN);
	$a=explode(' ',fgets(STDIN));
	$s=99;
	for($i=0;$i<$n;$i++){
		$c=0;
		while($a[$i]%2<1){
			$a[$i]=floor($a[$i]/2);
			$c++;
		}
		$s=$s<$c?$s:$c;
	}
	echo $s;


Measured memory_bytes: 3828
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
   input!{n:i64, m:i64};
   println!("{}", (n-1)*(m-1));

}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
//#define int long long

void solve() {
	int n; cin >> n;
    vector<int> a(n);
    bool ok = 0;
    rep(i, n) {
        cin >> a[i];
        if(a[i] == 1) ok = 1;
    }
    int now = 1, ans = 0;
    rep(i, n) {
        if(a[i] == now) {
            ++now;
        } else {
            ++ans;
        }
    }
    if(!ok) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int INF = 2147483647;
int n, k, h[maxn], dp[maxn];
int solve() {
    int i, j;
    for(i = 0; i < n; i++)
        dp[i] = INF;
    dp[0] = 0; dp[1] = abs(h[0] - h[1]);
    for(i = 2; i < n; i++) {
        for(j = 1; j <= k; j++) {
            if(i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
        }
    }
    return dp[n - 1];
}
int main() {
    int i;
    scanf("%d %d", &n, &k);
    for(i = 0; i < n; i++)
        scanf("%d", &h[i]);
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int ans;
int main()
{
	string s;
	cin >> s;
	string t;
	string cur;
	for (int i = 0;i < s.size();i++)
	{
		cur += s[i];
		if (cur == t)
		{
		}
		else
		{
			ans ++ ;
			t = cur;
			cur = "";
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
vector<int>memo(100001,-1);
void dp(int h[],int n)
{
    
    memo[1]=0;
    memo[2]=abs(h[2]-h[1]);
 
    for(int i=3;i<=n;i++)
    memo[i]=min(abs(h[i]-h[i-1])+memo[i-1],abs(h[i]-h[i-2])+memo[i-2]);
    
    
    
}
int main()
{
    int n;
    cin>>n;
    int h[n+1];
    for(int i=1;i<=n;i++)
    cin>>h[i];
    //cout<<h[1];
    dp(h,n);
    /*for(int i=1;i<=n;i++)
    cout<<memo[n];*/
    cout<<memo[n];
    
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<queue>
#include<iostream>

using namespace std;

void nanika(int use,vector<int> v,int m){
	vector<int> V = v;
	V.push_back(m);
	if(V.size() > 1 && V[V.size()-1] > V[V.size()-2])return;
	
	if(use == 0){
		for(int i = 0; i < V.size(); i++){
			printf("%s%d", i>0?" ":"", V[i]);
		}
		puts("");
		return;
	}
	
	for(int i = use; i > 0; i--){
		if(use-i >= 0)nanika(use-i,V,i);
	}
	return;
}		

int main(void){
	int n;
	while(scanf("%d", &n) && n != 0){
		vector<int> q;
		
		for(int i = n; i > 0; i--){
			nanika(n-i,q,i);
		}
	}
	return 0;
}

Measured memory_bytes: 928
#include<iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	if (100 <= N && N <= 111) {
		cout << "111" << endl;
	}
	else if (112 <= N && N <= 222) {
		cout << "222" << endl;
	}
	else if (223 <= N && N <= 333) {
		cout << "333" << endl;
	}
	else if (334 <= N && N <= 444) {
		cout << "444" << endl;
	}
	else if (445 <= N && N <= 555) {
		cout << "555" << endl;
	}
	else if (556 <= N && N <= 666) {
		cout << "666" << endl;
	}
	else if (667 <= N && N <= 777) {
		cout << "777" << endl;
	}
	else if (778<= N && N <= 888) {
		cout << "888" << endl;
	}
	else if (889 <= N && N <= 999) {
		cout << "999" << endl;
	}

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();

		int subX = Math.abs(x1 - x2);
		int subY = Math.abs(y1 - y2);

		int x3, y3, x4, y4;

		if (x1 >= x2) {
			if (y1 <= y2) {
				x3 = x2 - subY;
				y3 = y2 - subX;
				x4 = x1 - subY;
				y4 = y1 - subX;
			} else {
				x3 = x2 + subY;
				y3 = y2 - subX;
				x4 = x1 + subY;
				y4 = y1 - subX;
			}
		} else {
			if (y1 >= y2) {
				x3 = x2 + subY;
				y3 = y2 + subX;
				x4 = x1 + subY;
				y4 = y1 + subX;
			} else {
				x3 = x2 - subY;
				y3 = y2 + subX;
				x4 = x1 - subY;
				y4 = y1 + subX;
			}
		}

		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
		sc.close();
	}
}


Measured memory_bytes: 21588
n = int(input())

count = [0 for i in range(n+1)]

for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      f = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
      if f <= n:
        count[f] += 1

for i in count[1:]:
  print(i)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A,I;
  cin >> N >> A >> I;
 
  I=(N%500)-A;
  if (I <= 0) {
    cout << "Yes" << endl;
}else {
      cout << "No" << endl;
    }
 
 }

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



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

	int aa = a;
	rep(i,0,1000000){
        if(aa % b == c){
            YES;
            ret 0;
        }
        aa += a;
	}
	NO;
	return  0;
}

Measured memory_bytes: 256
#include<stdio.h>
int binarysearch(int);

int S[100000], n;

int main(){
  int q, i, C=0;
  int T[50000];

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);

  for( i = 0 ; i < q ; i++ ){
    scanf("%d", &T[i]);
    if( binarysearch(T[i]) ) C++;
  }
  printf("%d\n", C);
  return 0;
}

int binarysearch(int t){
  int l=0, r=n, mid;
  while( l < r ){
    mid = ( l + r ) / 2;
    if( t == S[mid] ) return 1;
    if( t > S[mid] ) l = mid + 1;
    else if( t < S[mid] ) r = mid;
  }
  return 0;
}



Measured memory_bytes: 2260
#include <stdio.h>

int main(){
	int a, n, i;
	while (1){
		scanf("%d", &a);
		if (a == 0) break;
		n = 0;
		for (i = 5; a/i >0; i *= 5){
			n += a/i;
		}
		printf("%d\n", n);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<cmath>
#include<string>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define show(x) cout<< #x << " = " << (x) << endl
#define show_array(arr) REP(i,int((arr).size()))cout<< #arr << "["<<i<<"]"<<"="<<arr[i]<<endl

int main(){

	ios::sync_with_stdio(false);

	string str;
	cin>>str;
	bool isA = false;
	for(int i = 0; i < str.size() -1 ; i++){
		if(str[i] == 'A' && str[i+1] == 'C'){
			isA = true;
		}
	}

	if(isA){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())
monstors = [int(i) for i in input().split()]
heros = [int(i) for i in input().split()]
init_monstor = sum(monstors)

for i in range(N):
    if monstors[i] >= heros[i]:
        monstors[i] -= heros[i]
        heros[i] = 0
    else:
        heros[i] -= monstors[i]
        monstors[i] = 0
    if monstors[i+1] >= heros[i]:
        monstors[i+1] -= heros[i]
        heros[i] = 0
    else:
        heros[i] -= monstors[i+1]
        monstors[i+1] = 0
print("{}".format(init_monstor - sum(monstors)))

Measured memory_bytes: 19648
fun main(args: Array<String>) {
    val (q, h, s, d) = readLine()!!.split(" ").map(String::toLong)
    val n = readLine()!!.toLong()
    val cost1 = listOf(4 * q, 2 * h, s).min()!!
    val cost2 = listOf(cost1 * 2, d).min()!!
    val ans = if (n % 2 == 0L) cost2 * (n / 2) else cost2 * (n / 2) + cost1
    println(ans)
}

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

int main(){
    string s;
    cin >> s;
    cout << 700 + (s[0] == 'o' ? 100 : 0) + (s[1] == 'o' ? 100 : 0) + (s[2] == 'o' ? 100 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();

        System.out.println(Math.max(0, C - (A - B)));
    }
}


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

int main() {
  int X, A, B;
  cin >> X >> A >> B;

  string ans;

  if (A >= B) ans = "delicious";
  else if (B - A <= X) ans = "safe";
  else ans = "dangerous";

  cout << ans << endl;
}

Measured memory_bytes: 256
//#define LOCAL_DEBUG

#include <fstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

int main() {
#ifdef LOCAL_DEBUG
	freopen("input.txt","r", stdin);
#endif


	int N; cin >> N;
	map<int, int> m;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		if (m.count(a) == 0)
			m[a] = 1;
		else
			m[a]++;
	}

	int minus_cnt = 0;
	for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
		if (it->second > 1) {
			if (it->second % 2 == 1) {

			}
			else if (minus_cnt > 0)
				minus_cnt--;
			else
				minus_cnt++;
		}
	}

	cout << m.size() - minus_cnt << endl;

	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <fstream>

#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define pb push_back
#define mp make_pair

struct entry {
	int l, r, bucket, poz;
};

struct cmp {
	bool operator () (const entry& a, const entry& b) const {
		if (a.bucket == b.bucket)
			return a.r < b.r;
		return a.bucket < b.bucket;
	}
};

#define NMAX 500100

int v[NMAX], sol[NMAX], cnt[NMAX];
entry a[NMAX];

void rem(int poz, int& rez)
{
	cnt[v[poz]]--;
	if (cnt[v[poz]] == 0) {
		rez--;
	}
}

void add(int poz, int& rez)
{
	if (cnt[v[poz]] == 0) {
		rez++;
	}
	cnt[v[poz]]++;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    // cout.setf(ios::fixed), cout.precision(20);

#ifdef LOCAL
    // ifstream cin("input.txt");
#endif
	
	int N, Q;
	cin >> N >> Q;
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
	}
	int s = (int)sqrt(N);
	for (int i = 1; i <= Q; i++) {
		cin >> a[i].l >> a[i].r;
		a[i].poz = i;
		if (a[i].l % s == 0)
			a[i].bucket = a[i].l / s;
		else a[i].bucket = a[i].l / s + 1;
	}
	sort(a + 1, a + Q + 1, cmp());
	int st = 0, dr = 0, rez = 0;
	for (int i = 1; i <= Q; i++) {
		while (st < a[i].l)
			rem(st++, rez);
		while (st > a[i].l)
			add(--st, rez);
		while (dr < a[i].r)
			add(++dr, rez);
		while (dr > a[i].r)
			rem(dr--, rez);
		sol[a[i].poz] = rez;
	}
	for (int i = 1; i <= Q; i++)
		cout << sol[i] << '\n';
    return 0;
}

Measured memory_bytes: 17396
n = gets.to_i
num = gets.strip.split.map(&:to_i)
#パスカルの三角形を考えればnとして選ぶのはnumの最大値
maxs = num.max
num.sort!
ary = []
i = 0
while i < n-1
  ary[i] = (num[i]-maxs.to_f/2).abs
  i += 1
end
mins = ary.min
puts [maxs,num[ary.index(mins)]].join(" ")

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

#define ll long long
//~ #define endl '\n'

void solve(){
	int n, k; cin>>n>>k;
	vector< ll > v(n);
	for(ll &i : v) cin>>i;
	ll l = 1, r = 1000000001;
	ll ans = r;
	while(l != r){
		ll mid = (l + r) / 2;
		ll j = k;
		for(int i = 0; i<n; i++){
			j -= (v[i] - 1) / mid;
		}
		if(j >= 0){
			r = mid;
			ans = mid;
		}else{
			l = mid + 1;
		}
	}
	cout<<ans<<endl;
	
}

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


Measured memory_bytes: 4744
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn], c[maxn];
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d %d %d", a + i, b + i, c + i);
	}
	int flg = 1;
	b[0] = c[0] = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] - a[i - 1] >= abs(b[i] - b[i - 1]) + abs(c[i] - c[i - 1])){
			if(a[i] - a[i - 1] == abs(b[i] - b[i - 1]) + abs(c[i] - c[i - 1]) || (a[i] - a[i - 1]
			 + abs(b[i] - b[i - 1]) + abs(c[i] - c[i - 1])) % 2 == 0){
			 	flg = 1;
			 }else{
			 	flg = 0;
			 	break;
			 }
		}else{
			flg = 0;
			break;
		}
	}
	if(flg == 1){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1408
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(N);
    }
}

class Solver {
    public void solve(long N) {
        if (N > 999) {
            System.out.println("ABD");
        } else {
            System.out.println("ABC");
        }
    }
}



Measured memory_bytes: 21844
#include <stdio.h>

int main(void)
{
        int n;
        scanf("%d", &n);
        int r[n];

        int i, j, max, r_min;
        for(i = 0; i < n; i++){
                scanf("%d", &r[i]);
        }

        max = r[1] - r[0];
        r_min = r[0];
        for(i = 0; i < n - 1; i++){
                if((i == 0) || (r[i] < r_min)){
                        for(j = i + 1; j < n; j++){
                                if(r[j] - r[i] > max){
                                        max = r[j] - r[i];
                                        r_min = r[i];
                                }
                        }
                }
        }
        printf("%d\n", max);

        return 0;
}


Measured memory_bytes: 2524
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  int s[10000];
  for (int i = 0; i < 10000; i++) {
    cin >> s[i];
    if (s[i] == 0) break;
  }

  for (int i = 0; i < 10000; i++) {
    if (s[i] == 0) break;
    cout << "Case " << i + 1 << ": " << s[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int sum,ans;
string s;
int main() {
	ios::sync_with_stdio(false);
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		sum += s[i] == 'S';
		if(sum && s[i] == 'T') {
			ans++;
			sum--;
		}
	}
	cout << s.size() - ans * 2 << endl;
	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m;
  cin >> n >> m;
  double k[n];
  double y=0;
  rep(i,n){
    double r;
    cin >> r;
    k[i]=r;
    y+=r;
  }
  y/=(4*m);
  int cnt=0;
  rep(i,n){
    if(k[i]>=y){
      cnt++;
    }
  }
  if(cnt>=m)cout << "Yes"  << endl;
  else cout << "No" << endl;
  }  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  char c[52][52];
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>c[i][j];
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(c[i][j]=='#') cout<<'#';
      else{
        int cn=0;
        if(c[i-1][j-1]=='#') cn++;
        if(c[i-1][j]=='#') cn++;
        if(c[i-1][j+1]=='#') cn++;
        if(c[i][j-1]=='#') cn++;
        if(c[i+1][j+1]=='#') cn++;
        if(c[i][j+1]=='#') cn++;
        if(c[i+1][j-1]=='#') cn++;
        if(c[i+1][j]=='#') cn++;
        cout<<cn;
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256