akhauriyash/Code-Regression huggingface dataset:
H, W = map(int,input().split())

S = [input() for _ in range(H)]

a = [[0] * W for _ in range(H)] # 右
b = [[0] * W for _ in range(H)] # 左
c = [[0] * H for _ in range(W)] # 上
d = [[0] * H for _ in range(W)] # 下

for x in range(H):
    for y in range(W):
        if S[x][y] == '#':
            a[x][y] = -1
        elif y > 0:
            a[x][y] = a[x][y-1] + 1
            
for x in range(H):
    for y in range(W-1,-1,-1):
        if S[x][y] == '#':
            b[x][y] = -1
        elif y < W-1:
            b[x][y] = b[x][y+1] + 1

for y in range(W):
    for x in range(H):
        if S[x][y] == '#':
            c[y][x] = -1
        elif x > 0:
            c[y][x] = c[y][x-1] + 1

for y in range(W):
    for x in range(H-1,-1,-1):
        if S[x][y] == '#':
            d[y][x] = -1
        elif x < H-1:
            d[y][x] = d[y][x+1] + 1

ans = 0

for x in range(H):
    for y in range(W):
        if S[x][y] != '#':
            ans = max(ans,a[x][y]+b[x][y]+c[y][x]+d[y][x]+1)

print(ans)

Measured memory_bytes: 199944
n=int(input())
A=[int(i) for i in input().split()]

ans=0
left=0
right=0
tas=A[0]
xor=A[0]

while right<n-1 and left<n:
    if tas+A[right+1] == xor^A[right+1]:
        right+=1
        ans+=right-left
        tas+=A[right]
        xor^=A[right]
    else:
        tas-=A[left]
        xor^=A[left]
        left+=1

print(ans+n)

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

dp=[0]*(n+1)
dp[0]=1

if 1 not in a:
  dp[1]=1
else:
  dp[1]=0
  

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



Measured memory_bytes: 13192
K, N = map(int, input().split())
array = list(map(int, input().split()))
array_distance = []

for i in range(N):
    min = 0
    if i == N-1:
        min = abs(array[0] - array[N-1])
        if min>=K/2:
            min = abs(K-min)
        array_distance.append(min)
    else:
        min = abs(array[i] - array[i+1])
        if min>=K/2:
            min = abs(K-min)
        array_distance.append(min)

array_distance= sorted(array_distance, reverse = True)
# print(array_distance)
# print(array_distance[0])
# print(sum(array_distance))
print(sum(array_distance) - array_distance[0])



Measured memory_bytes: 26444
/**
        Bismilla- hir rahma-nir rahi-m
    @uthor Md Hasibur Rahman (Evan)
                JKKNIU
*/


#include<bits/stdc++.h>
#define         ll              long long
#define         FI              freopen("input.txt","r",stdin)
#define         FO              freopen("output.txt","w",stdout)
#define         PrintCase(i)    printf("Case %d: ",i)
#define         sc(a)           scanf("%d",&a)
#define         scl(a)          scanf("%lld",&a)
#define         rep(i,n)        for(int i=0;i<n;i++)
#define         pb              push_back
#define         MAX             1000000




using namespace std;

bool isPrime(ll a)
{
    for(ll i=2;i*i<=a;i++)
        if(a%i==0)
            return false;
    return true;
}






bool isPowerOfTwo(ll a)
{
    if(a==1)
        return true;
    if(a&1)
        return false;
    while(a)
    {
        a/=2;
        if(a!=1 && a&1)
            return false;
        if(a==1)
            return true;
    }
    return true;
}




ll gcd(ll a, ll b)
{
    if(a<0 || b<0)
    {
        a = abs(a);
        b = abs(b);
    }
    if(a<b)
        swap(a,b);
    if(a%b==0 || b==0)
        return b;
    else
        return gcd(b,a%b);
}



ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a,b);
}



ll power(ll base, ll exponent)
{
    ll ans = 1;
    for(ll i=1;i<=exponent;i++)
        ans*=base;
    return ans;
}




bool isPowerOfX(ll x, ll value)
{
    if(value==1)
        return true;
    while(value)
    {
        value/=x;
        if(value%x && value!=1)
            return false;
    }
    return true;
}





int main()
{
    int n;
    cin>>n;
    int arr[n+2];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    int cnt = 0;
    for(int i=1;i<=n;i++)
        if((i&1) && (arr[i]&1))
            cnt++;
    cout<<cnt<<"\n";
    return 0;
}




Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

set<pair<int, int>> st;

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

    for (int i = 0; i < 3; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        st.insert({x, y});
        st.insert({y, x});
    }

    int a[4];
    for (int i = 0; i < 4; i++) {
        a[i] = i;
    }

    do {
        bool ok = true;
        for (int i = 0; i + 1 < 4; i++) {
            if (!st.count({a[i], a[i + 1]})) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << "YES\n";
            return 0;
        }
    } while (next_permutation(a, a + 4));

    cout << "NO\n";

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
	int k=0;char ch=gt;
	while(ch<'-')ch=gt;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return k;
}
const int N=1e5+5,inf=1e9;
int a[N],b[N];
using std::max;
int main()
{
	int n=in();
	for(int i=1;i<=n;++i)a[i]=in();
	std::sort(a+1,a+n+1);
	ll ans=0;int l=1,r=n-1,le=0,ri=0,l_=a[n],r_=a[n];
	while(l<=r)
	{
		int t1=-1,t2=-1,t3=-1,t4=-1;
		if(!le)t1=l_-a[l];
		else t2=a[r]-l_;
		if(!ri)t3=r_-a[l];
		else t4=a[r]-r_;
		int res=max(max(t1,t2),max(t3,t4));
		if(t1==res){ans+=t1;le^=1;l_=a[l];++l;continue;}
		if(t2==res){ans+=t2;le^=1;l_=a[r];--r;continue;}
		if(t3==res){ans+=t3;ri^=1;r_=a[l];++l;continue;}
		if(t4==res){ans+=t4;ri^=1;r_=a[r];--r;continue;}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
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;
}
// a^n mod を計算する
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;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string s; cin >> s;
    int out=0;

    int l=0,r=s.size()-1;
    while(l<=r){
        cerr << l << "\t" << r << endl;
        if(s[l]==s[r]){
            l++;r--;
        }else{
            if(s[l]=='x'){
                out++;
                l++;
            }else if(s[r]=='x'){
                out++;r--;
            }else{
                out = -1;
                break;
            }
        }
    }
    cout << out << endl;
    return 0;
}


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

int main()
{
  int n, l;
  cin >> n >> l;
  
  vector<int> as(n);
  
  for (int i = 0; i < n; i++) {
    as[i] = l + i;
  }
  
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (abs(as[i]) < abs(as[j])) {
      j = i;
    }
  }
  
  int ans = 0;
  
  for (int i = 0; i < n; i++) {
    if (i == j) {
      continue;
    }
    ans += as[i];
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = Console.ReadLine().Split(' ');
            var N = long.Parse(num[0]);
            var K = long.Parse(num[1]);
            const int MOD = 1000000007;
            long add;
            long ans = 0;

            for (long k = K; k <= N + 1; k++)
            {
                add = k * (N - k + 1) + 1;
                ans += add;
            }

            Console.WriteLine(ans % MOD);
        }

    }
}


Measured memory_bytes: 17900
S = input()

p = []
for i in range(2**3):
    t = format(i, 'b').zfill(3)
    p.append(t)

for pi in p:
    st = S[0]
    for i in range(3):
        if pi[i] == '1':
            st += '+'
        else:
            st += '-'
        st += S[i+1]
    if eval(st) == 7:
        break
else:
    raise Exception()

print(st + '=7')

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int f(int n)
{
	int result{ 0 };
	for(;n > 0; n /= 10) {
		result += n % 10;
	}

	return result;
}

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

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

Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String[] s = new String[N];
for(int i = 0;i < N;i++){
s[i] = sc.next();
}
int M = sc.nextInt();
String[] t = new String[M];
for(int i = 0;i < M;i++){
t[i] = sc.next();
}
int[] score = new int[N];
Arrays.fill(score, 0);
for(int i = 0;i < N;i++){
 for(int j = 0;j < N;j++){
 if(s[i].equals(s[j])){score[i] = score[i] + 1;}
 }
}
for(int i = 0;i < N;i++){
 for(int j = 0;j < M;j++){
 if(s[i].equals(t[j])){score[i] = score[i] - 1;}
 }
}
Arrays.sort(score);
if(score[N-1] >= 0){
System.out.println(score[N-1]);
}
else{
System.out.println("0");
}

}
}


Measured memory_bytes: 23764
N = int(input())
T,A = map(int, input().split())
H = [int(s) for s in input().split()]
H = [T - x*0.006 for x in H]
#print(H)
palace = {}
for i in range(N):
    palace[H[i]] = abs(H[i]-A)
#print(palace)


diff = sorted(palace.items(),key=lambda x: x[1])

if diff[0][0] in H:
    print(H.index(diff[0][0])+1)



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

int main(){
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for(int i=0; i<R; i++){
        cin >> r[i];
        r[i]--;
    }
    vector<vector<int>> dist;
    dist = vector<vector<int>>(N, vector<int>(N+1,1e9));
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++) for(int j=0; j<N; j++){
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
    }

    int ans = 1e9;
    sort(r.begin(), r.end());
    do{
        int tmp = 0;
        for(int i=0; i<R-1; i++){
            tmp += dist[r[i]][r[i+1]];
        }
        ans = min(ans, tmp);
    }while(next_permutation(r.begin(), r.end()));

    cout << ans << endl;
}


Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e12;


int main(){
	int n;
	cin>>n;
	long double xa,ya,ra,xb,yb,rb;
	REP(i,n){
		cin>>xa>>ya>>ra>>xb>>yb>>rb;
		long double d=sqrt(abs(xa-xb)*abs(xa-xb)+abs(ya-yb)*abs(ya-yb));
		if(d+rb<ra){
			cout<<2<<endl;
		}else if(d+ra<rb){
			cout<<-2<<endl;
		}else if(d>(ra+rb)){
			cout<<0<<endl;
		}else{
			cout<<1<<endl;
		}
	}
	return 0;
}
/*
2
0.0 0.0 5.0 0.0 0.0 4.0
0.0 0.0 3.0 4.1 0.0 2.0
*/

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int N;

int main(){
    cin >> N;
    vector<pair<int,int>> point(N);
    for(int i=0; i<N; i++) cin >> point.at(i).first >> point.at(i).second;
    // vector<vector<double>> distan(N,vector<double>(N));
    double ans=0;
    for(int i=0; i<N; i++) {
        for(int j=i+1; j<N; j++) {
            double dis = sqrt(pow(point.at(i).first-point.at(j).first,2)+pow(point.at(i).second-point.at(j).second,2));
            ans += dis;
        }
    }
    printf("%f\n",2*ans/N);
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e5+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}


lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}

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

vvi graph(int n, int m){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	return v;
}

// ---- コーディングはここから！ ('-')7

void solve(){
	int n,m; cin>>n>>m;
	auto v = graph(n,m);
	int t = 0;
	vi vis(n+1,0);
	auto f=[&](auto &&f, int u)->void{
		vis[u]=1;
		for(auto i:v[u])if(!vis[i])f(f,i);
	};
	fore(i,1,n+1)if(!vis[i]){
		t++;
		f(f,i);
	}
	cout<<t-1<<ENDL;
}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

struct E{
  int to,from,cost;
};

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

  int N,M;
  cin>>N>>M;
  vector<vector<int>>v(N,vector<int>(N,INF));
  for(int i=0;i<N;i++)v[i][i]=0;
  vector<E>e(M);
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    e[i].from=a;
    e[i].to=b;
    e[i].cost=c;
    v[a][b]=c;
    v[b][a]=c;
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
      }
    }
  }

  int ans=0;
  for(int i=0;i<M;i++){
    bool ok=false;
    for(int j=0;j<N;j++){
      if(v[e[i].from][j]+e[i].cost==v[e[i].to][j])ok=true;
    }
    if(!ok)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut arr = vec![0u64; 5];
    for _ in 0..n {
        let s:String = read();
        match s.chars().nth(0).unwrap() {
            'M' => arr[0] += 1,
            'A' => arr[1] += 1,
            'R' => arr[2] += 1,
            'C' => arr[3] += 1,
            'H' => arr[4] += 1,
            _ => ()
        }
    }
    let mut ans = 0;
    for i in 0..5 {
        for j in 0..i {
            for k in 0..j {
                ans += arr[i] * arr[j] * arr[k];
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2052
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            string sa = a.ToString();
            string sb = b.ToString();
            switch (sa.CompareTo(sb))
            {
                case -1:
                    for (int i = 1; i < b; ++i)
                    {
                        sa = sa + a.ToString();
                    }
                    Console.WriteLine(sa);
                    break;
                case 0:
                    for (int i = 1; i < b; ++i)
                    {
                        sa = sa + a.ToString();
                    }
                    Console.WriteLine(sa);
                    break;
                case 1:
                    for (int i = 1; i < a; ++i)
                    {
                        sb = sb + b.ToString();
                    }
                    Console.WriteLine(sb);
                    break;
            }
        }
    }
}


Measured memory_bytes: 11232
#include<iostream>
#include<algorithm>
using namespace std;
int house[2 * 1000005];
int sum[2 * 1000005];
int main() {
	int k, n,ans=0,min1=0xfffffff;
	cin >> k >> n;
	for (int i = 1; i <=n; i++) {
		cin >> house[i];
		house[i + n] = house[i]+k;
	}
	/*for (int i = 1; i <= 2 * n - 1;i++) {
		sum[i] = sum[i - 1] + house[i];
	}*/
	for (int i = 1; i <= n; i++)
		min1 = min(house[i + n-1] - house[i], min1);
	return cout<<min1, 0;
}

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

int n;
int flag;

int main(){
  cin>>n;flag=0;
  for(int i=1;i<=n;i++)
    if (n%i==0){
      if (i<=9 && n/i<=9) flag=1;
    }
  if (flag==1) cout<<"Yes";
  else cout<<"No";
}


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

int main() {
  
  string s,t;
  cin>>s;
  cin>>t;
  string ans="Yes";
  for(int i=0;i<s.size();i++) {
    if(s.at(i)!=t.at(i)){
      ans="No";
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
  
}


Measured memory_bytes: 3600
let bfs vs n =
  let d = Array.make n (-1) in
  let q = Queue.create () in
  d.(0) <- 0;
  Queue.add 0 q;
  while not (Queue.is_empty q) do
    let i = Queue.take q in
    List.iter (fun v ->
      if d.(v-1) = (-1) then begin
        d.(v-1) <- d.(i) + 1;
        Queue.add (v-1) q;
      end)
      vs.(i);
  done;
  d

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let vs = Array.make n [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> vs.(u-1) <- l
    | _ -> assert false
  done;
  bfs vs n |> Array.iteri (fun i e -> Printf.printf "%d %d\n" (i + 1) e)

Measured memory_bytes: 2348
#include<bits/stdc++.h>
using namespace std;
int n,k;
double ans,tx;
int main()
{
	int x;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		x=i;tx=1;
		for(int j=1;x<k;j++)x*=2,tx*=0.5;
		ans+=1.0/n*tx;
	}
	printf("%.9lf",ans);
	return 0;
}

Measured memory_bytes: 3800
#include <iostream>

using namespace std;

int main (void)
{
    string o, e, ans = "";
    cin >> o >> e;

    int loop = 0;
    while (loop < o.size() + e.size()) {
        if (loop % 2 == 0) {
            ans += o[loop/2];
        } else {
            ans += e[loop/2];
        }
        loop++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define range(vec,x,y) vec.begin()+x,vec.begin()+y
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
#define eraseif(vec,condition_x) vec.erase(remove_if(all(vec),[](auto x){return condition_x;}),vec.end())
#define countif(vec,condition_x) count_if(all(vec),[](auto x){return condition_x;})
#define replaceif(vec,condition_x,n) replace_if(all(vec),[](auto x){return condition_x;},n)
#define optvalue(vec,condition_x,relation_x_opt) *min_element(all(vec),[](int x,int opt){return condition_x ? (opt==0)||!(relation_x_opt):false;})
#define erase_unique(vec) vec.erase(unique(all(vec)),vec.end())
#define calcvec(vec,calc_x) for_each(all(vec),[](int&x){x= calc_x;})
#define calc2vec(vec1,op,vec2) {rep(1){int s=min(si(vec1),si(vec2));fou(i,0,s)vec1[i]=vec1[i] op vec2[i];}}
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
template<class C>void outvec(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}
template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}




// #define int int64_t
// #define double long double


// 無名関数template
// map,makepair

signed main(){
  IOS;

  in(int,n);
  int ans;
  if(n==1) ans=2;
  elif(n%2==0) ans=n;
  else ans=2*n;
  out(ans);


}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {

	var a []int
	var n int
	count := 0

	fmt.Scan(&n)

	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	for {
		var flag int

		for k, v := range a {
			if v%2 != 0 {
				flag = 1
				break
			}
			a[k] = a[k] / 2
		}
		if flag == 1 {
			break
		}
		count++
	}

	fmt.Println(strconv.Itoa(count))
}


Measured memory_bytes: 512
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
bsort = sorted(b)
csort = sorted(c)
res = 0
asum = [0] * n
bsum = [0] * n
for i in range(n):
    asum[i] = n - bisect.bisect_right(bsort, a[i])
for i in range(n):
    bsum[i] = n - bisect.bisect_right(csort, b[i])
bsum.sort()
total = 0
for i in range(n):
    total += bsum[i]
    bsum[i] = total
res = 0
for i in range(n):
    if asum[i] != 0:
        res += bsum[asum[i] -1]
print(res)

Measured memory_bytes: 27764
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    h, w = input_to_int_map()
    zone = [input() for i in range(h)]

    from collections import deque
    black_cell = deque()

    black_distance = [[-1] * w for i in range(h)]
    for i, row in enumerate(zone):
        for j, cell in enumerate(row):
            if cell == "#":
                black_cell.append((i, j))
                black_distance[i][j] = 0

    while black_cell:
        black_h, black_w = black_cell.popleft()
        pre_black_distance = black_distance[black_h][black_w]
        for i, j in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            move_h = black_h + i
            move_w = black_w + j
            if move_h < 0 or move_w < 0 or move_h >= h or move_w >= w:
                continue
            if black_distance[move_h][move_w] == -1:
                black_distance[move_h][move_w] = pre_black_distance + 1
                black_cell.append((move_h, move_w))

    return max(list(map(max, black_distance)))


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 87516
#ABC067C
N = int(input())
an = list(map(int, input().split()))
snk = an[0]
ari = sum(an[1:])
ans = abs(snk-ari)
for i in range(N-2):
    snk += an[i+1]
    ari -= an[i+1]
    ans = min(ans, abs(snk-ari))
print(ans)

Measured memory_bytes: 24832
class Queue(object):

    def __init__(self):
        self.queue_list = []

    def enqueue(self, value):
        self.queue_list.append(value)

    def dequeue(self):
        try:
            # 先頭をとりだす
            value = self.queue_list.pop(0)
        except IndexError:
            value = None

        return value
N = int(input())

pair = []
tree = {}

for _ in range(N-1):
    a, b = list(map(int, input().split(" "))) 
    if a in tree.keys():
        tree[a].append(b)
    else:
        tree[a] = [b]
        
    if b in tree.keys():
        tree[b].append(a)
    else:
        tree[b] = [a]
    pair.append([a,b])
    
c = list(map(int, input().split(" ")))
c.sort(reverse=True)
c = c[:N+2]


queue = Queue()
tree_l = {}
for key in tree.keys():
    tree_l[key] = len(tree[key])

ans = {}
max_node = max((v, k) for k, v in tree_l.items())[1]
ans[max_node] = c[0]
used = [max_node]
cnt = 0

candi = {}
for i in tree[max_node]:
    candi[i] = tree_l[i]

for k, v in sorted(candi.items(), key=lambda x: -x[1]):
    queue.enqueue(k)
    used.append(k)

while True:
    node = queue.dequeue()
    cnt += 1
    ans[node] = c[cnt]
    
    if cnt == N-1:
        break
    
    candi = {}
    for i in tree[node]:
        candi[i] = tree_l[i]
    for k, v in sorted(candi.items(), key=lambda x: -x[1]):
        if k not in used:
            queue.enqueue(k)
            used.append(k)
total = 0
for a, b in pair:
    if ans[a] > ans[b]:
        total += ans[b]
    else:
        total += ans[a]
        
print(total)
for i in range(1, N, 1):
    print(ans[i], end=" ")

print(ans[N])


Measured memory_bytes: 9960
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut c: Chars,
    }

    let mut ans = 0;

    let mut l = 0;
    let mut r = n - 1;
    while r as i64 - l as i64 > 0 {
        if c[l] == 'R' {
            l += 1;
        } else if c[r] == 'W' {
            r -= 1;
        } else if c[l] == 'W' && c[r] == 'R' {
            ans += 1;
            l += 1;
            r -= 1;
        }
    }

    println!("{}", ans)
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int x[11], y[11];
double d(int x0, int y0, int x1, int y1) {
    return sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
}
signed main() {
    cin >> N;
    rep(i, N) { cin >> x[i] >> y[i]; }
    int cnt = 0;
    double sum = 0;
    vint v(N);
    rep(i, N) { v[i] = i; }
    do {
        for (int i = 1; i < N; i++) {
            sum += d(x[v[i - 1]], y[v[i - 1]], x[v[i]], y[v[i]]);
        }
        cnt++;
    } while (next_permutation(all(v)));
    cout << sum / cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

using Edge = tuple<ll, ll, ll>;
#include <queue>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, m, s;
    cin, n, m, s;
    vector<vector<Edge>> g(n);
    REP(i, 0, m) {
        int u, v, a, b;
        cin, u, v, a, b;
        u--;
        v--;
        g[u].emplace_back(v, a, b);
        g[v].emplace_back(u, a, b);
    }
    vector<ll> C(n), D(n);
    REP(i, 0, n) {
        cin, C[i], D[i];
    }
    ll Smax = 2510;
    chmin(s, Smax);

    priority_queue<Edge, vector<Edge>, greater<Edge>> pq;  // time, vertex, cost;
    pq.emplace(0, 0, s);
    const ll inf = 1LL << 60;
    auto Tm = make_v(n, Smax + 1, inf);
    Tm[0][s] = 0;
    while (pq.size()) {
        auto [tm, v, c] = pq.top();
        pq.pop();
        if (Tm[v][c] < tm) continue;
        Tm[v][c] = tm;

        {
            ll cc = c + C[v];
            chmin(cc, Smax);
            if (chmin(Tm[v][cc], Tm[v][c] + D[v])) {
                pq.emplace(Tm[v][c] + D[v], v, cc);
            }
        }
        for (auto [nto, aa, bb] : g[v]) {
            if (c >= aa && chmin(Tm[nto][c - aa], tm + bb)) {
                pq.emplace(tm + bb, nto, c - aa);
            }
        }
    }
    REP(i, 1, n) {
        ll ans = inf;
        REP(k, 0, Smax + 1) {
            chmin(ans, Tm[i][k]);
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 7336
#include <iostream>
using namespace std;
int main(){
    int n,q,s[100000],t[10000],v = 0,left,right,mid;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> s[i];
    }
    cin >> q;
    for(int i = 0;i < q;i++){
        cin >> t[i];
        left = 0,right = n;
        mid = (left + right) / 2;
        while(left < right){
            if(s[mid] == t[i]){
                v++;
                break;
            }
            else if(t[i] < s[mid]){
                right = mid;
            }
            else{
                left = mid + 1;
            }
            mid = (left + right) / 2;
        }
    }
    cout << v << endl;
    return 0;
}


Measured memory_bytes: 3508
from collections import defaultdict

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

s = [0] * (N+1)
for i in range(N):
    s[i+1] = (s[i] + A[i]) % M

ans = 0
m = defaultdict(int)
for i in range(N+1):
    ans += m[s[i]]
    m[s[i]] += 1

print(ans)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n+1);
    vector<bool> t(n+1);
    rep2(i,1,n+1) cin >> a[i];
    ll r,s,c=1;
    map<int,int> mp;
    vector<int> town;

    rep(i,n+1){
        if(t[c]){
            s=mp[c];
            r=i-s;
            break;
        }else{
            mp[c]=i;
            t[c]=true;
            town.push_back(c);
            c=a[c];
        }
    }
    if(k<s) cout << town[k] << endl;
    else{
        k-=s;
        k%=r;
        cout << town[s+k] << endl;
    // cout << s << ' ' << r << ' ' << k << endl;
    }
    
    return 0;
}

Measured memory_bytes: 14024
n,m=gets.split.map(&:to_i)
s=gets.chomp
l=[]
i=n
while i>=m
  if s[i-m,m].include?("0")
    t=m-s[i-m,m].index("0")
  else
    puts "-1"
    exit
  end
  l << t
  i-=t
end
l << i if i!=0
puts l.reverse


Measured memory_bytes: 4092
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){ll ans=1;rrp(i,n-r+1,n+1){ans*=i;ans%=mod;}return ans/=fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n,m,k;
 cin>>n>>m>>k;
 vector<ll>a,b;
 ll ai,bi;
 ans=0;
 rep(i,0,n){
  sc(ai);
  push(a,ai);
  if(i!=0)a.at(i)+=a.at(i-1);
  if(a[i]<=k)ans=max(ans,i+1);
//  cout<<ans<<endl;
 }
// pnn;
 rep(i,0,m){
  sc(bi);
  push(b,bi);
  if(i!=0)b.at(i)+=b.at(i-1);
  if(b[i]<=k)ans=max(ans,i+1);
//  cout<<ans<<endl;
 }
 // pnn; 
 ll st;
 rep(i,0,n){
  if(ans-i-1>0)st=ans-i-1;
  else st=0;
  rep(j,st,m){
  // cout<<ans<<" "<<a[i]+b[j]<<" "<<i+j+2<<endl;
   if(a[i]+b[j]<=k)ans=max(ans,i+j+2);
   else break;
  }
 }
 pr(ans);
return 0;}


Measured memory_bytes: 7916
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
ans=0
for i in range(N):
  A=list(map(int,input().split()))
  sum=0
  for j in range(M):
    sum+=A[j]*B[j]
  if sum+C>0:
    ans+=1
print(ans)


Measured memory_bytes: 9148
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;

$N = $sc->nextInt();
$X = $sc->nextInt();

$amounts = [];
$leftover = $X;
for ($i = 0; $i < $N; $i++) {
    $g = $sc->nextInt();
    $amounts[] = $g;
    $leftover -= $g;
}
sort($amounts);

$count = count($amounts);
while ($leftover - $amounts[0] >= 0) {
    $leftover -= $amounts[0];
    $count++;
}

echo $count;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,x=0;cin>>N;int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];a[i]--;
  }
  for(int i=0;i<N;i++)
    if(a[a[i]]==i)x++;
  cout<<x/2<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int A, B, C, N;
    cin >> A >> B >> C >> N;
    int ans = 0;
    int tmp = 0;
    REP(i, 3001)
    {
        REP(j, 3001)
        {
            tmp = N - A * i - B * j;
            if (tmp < 0)
                break;
            if (tmp % C == 0)
                ans++;
        }
    }
    cout << ans << endl;

    // system("pause");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
const int infty = 1000000007;

int N, M;
int a[60], b[60], c[60], d[60];

int main () {
  cin >> N >> M;
  for (auto i = 0; i < N; ++i) {
    cin >> a[i] >> b[i];
  }
  for (auto i = 0; i < M; ++i) {
    cin >> c[i] >> d[i];
  }
  for (auto i = 0; i < N; ++i) {
    int ans = 0;
    int dist = infty;
    for (auto j = 0; j < M; ++j) {
      int di = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dist > di) {
        ans = j;
        dist = di;
      }
    }
    cout << ans+1 << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
const Int Inf = 1e17;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

Int l;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

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

  cin>>n>>m>>l; WeightedGraph<Int>g(n),h(n); Int c;
  rep(i,m){
    cin>>x>>y>>c;
    if(c>l)continue;
    g[--x].eb(--y,c); g[y].eb(x,c);
  }
  V(Int)d1[n],d2[n];
  rep(i,n)d1[i]=dijkstra(g,i);
  rep(i,n)rer(j,i+1,n-1){
    if(i==j)continue;
    if(d1[i][j]<=l){h[i].eb(j,1); h[j].eb(i,1);}
  }
  rep(i,n)d2[i]=dijkstra(h,i);
  cin>>q;
  rep(i,q){
    cin>>x>>y;
    cout<<(d2[--x][--y]>Inf?-1:d2[x][y]-1)<<'\n';
  }
}

Measured memory_bytes: 6784
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{   
    int n, y;
    scanf("%d %d", &n, &y);

    int flag = 0;
    int a, b, c;
    for (int i=0; i <= y/10000; i++){
        for (int j=0; j <= n-i; j++){
            if (i*10000 + j*5000 + (n-i-j)*1000 == y){
                a = i;
                b = j;
                c = n-i-j;
                flag = 1;
                break;
            }
        }
    }

    if (flag == 1) printf("%d %d %d\n", a, b, c);
    else printf("%d %d %d\n", -1, -1, -1);



    return 0;
}


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

int main()
{
	int i, j;
	int n, count=0;
	int p[20];

	cin >> n;

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

	int a, b;
	for (i = 0; i < n - 2; i++){
		a = p[i + 1] - p[i];
		b = p[i + 2] - p[i + 1];
		if (a * b >= 0){
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <stack>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<set>
#include<map>
#include<cmath>
#define MAXN 51
#include<utility>
#define DEBUG 0

using namespace std;
typedef long long ll;
ll M;
ll c=0;
ll a[3]={3,5,7};
ll vis[3]={0};
void dfs(ll n,ll cur)
{
    if(n>M) return ;
    else
    {
        if(n>=357&&vis[0]&&vis[1]&&vis[2]) c++;
        ll p=1;
        for(int i=0;i<cur;i++) p*=10;
        for(int i=0;i<3;i++)
            {
                vis[i]++;
                dfs(n*10+a[i],cur+1);
                vis[i]--;
            }
    }
}
int main()
{
    #if DEBUG
    freopen("in.txt","r",stdin);
    #endif // DEBUG
    scanf("%lld",&M);
    vis[0]=1;
    dfs(3,1);
    vis[0]=0;
    vis[1]=1;
    dfs(5,1);
    vis[1]=0;
    vis[2]=1;
    dfs(7,1);
    vis[2]=0;

    printf("%lld\n",c);
    #if DEBUG
    fclose(stdin);
    #endif // DEBUG

    return 0;
}


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



int main() {
    int m1,m2,d1,d2;

    cin >> m1 >> m2 >> d1 >> d2;

    if(m1<m2 && d1>d2){
        cout << 1;
    }
    else
    cout << 0;

}

Measured memory_bytes: 3656