akhauriyash/Code-Regression huggingface dataset:
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=sorted(set(X));l=len(s);return{s[i]:i for i in r(l)},s,l
h,s,K=g(X);w,t,L=g(Y);V,U,v=[[[0]*-~K for i in r(L+1)]for _ in r(3)];q=[(h[0],w[0])];z=0
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
while q:
 x,y=q.pop();v[y][x]=1;z+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in(-1,0),(1,0),(0,1),(0,-1),:
  c=x+e;d=y+f
  if 1-v[d][c]and U[(f>0)+y][x]*f+V[y][(e>0)+x]*e==0:q+=[(c,d)];v[d][c]=1
print([z,'INF'][z>F])

Measured memory_bytes: 552104
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int n;
vector<double>prob;
double dp[3001][3001];
double rec(long long ntail , long long nhead)
{
    if(ntail + nhead == n)
        return (nhead > ntail);
    if(dp[ntail][nhead] != -1.0)
        return dp[ntail][nhead];
    double a = prob[ntail + nhead]*rec(ntail,nhead+1);
    double b = (1-prob[ntail + nhead])*rec(ntail+1,nhead);
    return dp[ntail][nhead] = a + b;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i = 0 ; i<3001 ; i++)
    for(int j =0 ;j<3001 ;j++)
        dp[i][j] = -1.0;
    cin>>n;
    prob.resize(n);
    for(int i = 0 ;i<n;i++)
    cin>>prob[i];
    cout<<fixed << setprecision(9) << rec(0,0);

}


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

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

    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h + 2);
    vector<pair<int, int>> p;

	a[0].assign(w + 2, '#');
	int i;
    for (i = 1; i <= h; i++) {
		a[i].assign(w + 2, '#');
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
            if (a[i][j] == '#')
                p.emplace_back(i, j);
        }
    }
	a[i].assign(w + 2, '#');

    int d[][2] = { -1, 0, 1, 0, 0, -1, 0, 1 };
    int ans = -1;
    while (!p.empty()) {
		ans++;
        vector<pair<int, int>> s;
        for (auto const& x : p) {
            for (auto const& y : d) {
                int i = x.first + y[0], j = x.second + y[1];
				if (a[i][j] == '.') {
					a[i][j] = '#';
					s.emplace_back(i, j);
				}
            }
        }
        p = move(s);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 12708
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var hw = Reads();
            var h = hw[0];
            var w = hw[1];
            var x = new int[] { -1, 0, 1, -1, 0, 1, -1, 1 };
            var y = new int[] { -1, -1, -1, 1, 1, 1, 0, 0 };
            var s = new char[h][];
            for (int i = 0; i < h; i++)
            {
                s[i] = ReadLine().ToCharArray();
            }
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    var count = 0;
                    if (s[i][j] != '#')
                    {
                        for (int k = 0; k < 8; k++)
                        {
                            if (i + x[k] >= 0 && i + x[k] < h && j + y[k] >= 0 && j + y[k] < w && s[i + x[k]][j + y[k]] == '#') count++;
                        }
                        Write(count);
                    }
                    else
                    {
                        Write("#");
                    }
                }
                WriteLine();
            }



            

            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 19032
def cost(a):
    prev = 0
    total = 0
    for ai in a:
        total += abs(ai - prev)
        prev = ai
    total += abs(0 - prev)
    return total

def cancel(a, i, total_cost):
    prev_spot = a[i-1]
    spot = a[i]
    next_spot = a[i+1]
    if spot >= min(prev_spot, next_spot) and spot <= max(prev_spot, next_spot):
        return total_cost
    else:
        if (next_spot >= prev_spot and spot < prev_spot) or (next_spot <= prev_spot and spot > prev_spot):
            return total_cost - 2 * abs(prev_spot - spot)
        if (next_spot >= prev_spot and spot > next_spot) or (next_spot <= prev_spot and spot < next_spot):
            return total_cost - 2 * abs(next_spot - spot)
        
    
if __name__ == '__main__':
    _ = int(input())
    a = [0] + list(map(int, input().split()))
    a.append(0)
    no_cancellations = cost(a)
    for i in range(1, len(a)-1):
        print(cancel(a, i, no_cancellations))

Measured memory_bytes: 14172
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back



int N,K;
vector<pair<int,int> > edges;
int M=0;
int mod=1000000007;

signed main(){
    scanf("%lld %lld",&N,&K);
    if(K>(int)( (N-1)*(N-2)/2) ){M=-1;printf("%lld\n",M);return 0;}
    M=(int)(N*(N-1)/2)-K;
    rep(i,N-1){
        for(int j=i+1;j<N;j++){
            edges.pb(mp(i,j));
        }
    }
    printf("%lld\n",M);
    rep(i,M){
        printf("%lld %lld\n",edges[i].first+1,edges[i].second+1);
    }
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<set>


using namespace std;

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

    for(int i=0; i<m; i++) {
        set<string> s;
        string in,first,second;
        cin >> in;

        second = in;
        while(!second.empty()) {
            first += second[0];
            second.erase(0,1);

            s.insert(first+second);
            s.insert(second+first);
            reverse(first.begin(), first.end());
            s.insert(first+second);
            s.insert(second+first);
            reverse(second.begin(), second.end());
            s.insert(first+second);
            s.insert(second+first);
            reverse(first.begin(), first.end());
            s.insert(first+second);
            s.insert(second+first);
            reverse(second.begin(), second.end());
        }

        cout << s.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1304
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

typedef pair<int, int> pii;
typedef pair<int, pii> piii;

list<int> nbrs[100010];
int parent[100010];

void solve() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        nbrs[A - 1].push_back(B - 1);
        nbrs[B - 1].push_back(A - 1);
    }
    memset(parent, -1, sizeof parent);

    priority_queue<piii, vector<piii>, greater<piii>> pq;
    pq.emplace(0, pii(0, 0));
    while (!pq.empty()) {
        piii front = pq.top();
        pq.pop();
        if (parent[front.second.first] != -1) continue;
        parent[front.second.first] = front.second.second;
        dbg << front.first << ", " << front.second.first << ", " << front.second.second << endl;
        int cost = front.first;
        for (int nbr : nbrs[front.second.first])
            if (parent[nbr] == -1) {
                dbg << "\t" << cost + 1 << ", " << nbr << ", " << front.second.first << endl;
                pq.emplace(cost + 1, pii(nbr, front.second.first));
            }
    }
    for (int i = 1; i < N; ++i) if (parent[i] == -1) { cout << "No" << endl; return; }
    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i) cout << parent[i] + 1 << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 21520
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for A in range(a + 1):
    for B in range(b + 1):
        C = (x - 500 * A - 100 * B) // 50
        if 0 <= C <= c:
            ans += 1
print(ans)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
flag = 0
for i in range(n):
  for j in range(1,n):
    if a[j] < a[j-1]:
      a[j], a[j-1] = a[j-1], a[j]
      flag = flag + 1
for i in range(n):
    print(a[i], end="")
    if i == n-1:
        print("")
    else:
        print(" ", end="")
print(flag)


Measured memory_bytes: 5624
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

namespace CSharp_Shell
{

    public static class Program 
    {
        public static void Main() 
        {
           var inputs=Console.ReadLine().Split();
           var a=int.Parse(inputs[0]);
           var b=int.Parse(inputs[1]);
           var c=int.Parse(inputs[2]);
           
           for(var i=0;i<b;i++)
           {
               if(a%b*i%b==c){Console.WriteLine("YES"); return;}
           }
           
           Console.WriteLine("NO");
        }
    }
}

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

using namespace std;

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

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//


bool prime(int x){
        bool flag = true;
        for(int i = 2; i <= x-1; i++){
                if(x % i == 0){
                        flag = false;
                        break;
                }
        }
        return flag;
}


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

        vector<int> ans;
        int cnt = 0;
        for(int i = 3; i <= 100000; i++){
                if(cnt == n) break;
                if(i % 5 == 1){
                        if(prime(i)){
                                cnt++;
                                ans.push_back(i);
                        }
                }
        }

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

        return 0;
}



Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    S = input()

    print(S.count("ABC"))


if __name__ == '__main__':
    main()


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll N=100,A,B;
char ans[100][100];

signed main() {
    cin>>A>>B;
    A--;
    B--;
    rep(y,0,100){
        rep(x,0,50)   ans[y][x]='.';
        rep(x,50,100) ans[y][x]='#';
    }

    for(ll y=0; y<100; y+=2){
        for(ll x=0; x<48; x+=2){
            if (B>0){
                ans[y][x]='#';
                B--;
            }
        }
    }

    for(ll y=0; y<100; y+=2){
        for(ll x=52; x<100; x+=2){
            if (A>0){
                ans[y][x]='.';
                A--;
            }
        }
    }

    cout<<"100 100"<<endl;
    rep(y,0,100){
        rep(x,0,100){
            cout<<ans[y][x];
        }
        cout<<endl;
    }
    return 0;
}


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

ll f(ll n) {
  if (n % 4 == 0) return n;
  if (n % 4 == 1) return 1;
  if (n % 4 == 2) return n+1;
  if (n % 4 == 3) return 0;
  return 0;
}

int main() {
  ll a,b;
  cin >> a >> b;
  ll ans = f(max((ll)0,a-1)) ^ f(b);
  cout << ans << endl;
  return 0;
}


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

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

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int a[4];
	rep(i,4) scanf("%d",&a[i]);
	sort(a,a+4);
	puts(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9?"YES":"NO");
	return 0;
}


Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vint vector<int>
#define vll vector<ll>
#define vstr vector<string>
#define vbl vector<bool>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}
#pragma endregion template

void solve(string S) {
  vstr days = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  int cnt = 7;
  for (auto x: days) {
    if (x == S) cout << cnt << endl;
    cnt--;
  }
}

int main() {
  string S;
    cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
import Control.Monad
main=do
 [h,w]<-map read.words<$>getLine
 s<-replicateM h getLine
 putStr(f h w s)
  where f h w s |h==1&&w==1 =if (s!!0)!!0=='#' then"#\n" else"0\n"
                |h==1       =concat[x s j w|j<-[1..w]]
                |w==1       =concat[y s i h|i<-[1..h]]
                |otherwise  =concat[g s i j h w|i<-[1..h],j<-[1..w]]
        x s j w |j==1      =if ((s!!0)!!(j-1))/='#' then(if ((s!!0)!!j)/='#' then"0" else"1") else"#"
                |j==w      =if ((s!!0)!!(j-1))/='#' then(if ((s!!0)!!(j-2))/='#' then"0\n" else"1\n") else"#\n"
                |otherwise =if ((s!!0)!!(j-1))/='#' then(show(length(filter(=='#')[(s!!0)!!j,(s!!0)!!(j-2)]))) else"#"
        y s i h |i==1      =if ((s!!(i-1))!!0)/='#' then(if ((s!!i)!!0)/='#' then"0\n" else"1\n") else"#\n"
                |i==h      =if ((s!!(i-1))!!0)/='#' then(if ((s!!(i-2))!!0)/='#' then"0\n" else"1\n") else"#\n"
                |otherwise =if ((s!!(i-1))!!0)/='#' then((show(length(filter(=='#')[(s!!i)!!0,(s!!(i-2))!!0])))++"\n") else"#\n"
        g s i j h w |i==1&&j==1 =if ((s!!(i-1))!!(j-1))/='#' then(show(length(filter(=='#')[(s!!(i-1))!!j,(s!!i)!!j,(s!!i)!!(j-1)]))) else"#"
                    |i==1&&j==w =if ((s!!(i-1))!!(j-1))/='#' then((show(length(filter(=='#')[(s!!i)!!(j-1),(s!!i)!!(j-2),(s!!(i-1))!!(j-2)])))++"\n") else"#\n"
                    |i==1       =if ((s!!(i-1))!!(j-1))/='#' then(show(length(filter(=='#')((take 3(drop(j-2)(s!!(i-1))))++(take 3(drop(j-2)(s!!i))))))) else"#"
                    |i==h&&j==1 =if ((s!!(i-1))!!(j-1))/='#' then(show(length(filter(=='#')[(s!!(i-1))!!j,(s!!(i-2))!!j,(s!!(i-2))!!(j-1)]))) else"#"
                    |j==1       =if ((s!!(i-1))!!(j-1))/='#' then(show(length(filter(=='#')((take 2(s!!(i-1)))++(take 2(s!!i))++(take 2(s!!(i-2))))))) else"#"
                    |i==h&&j==w =if ((s!!(i-1))!!(j-1))/='#' then((show(length(filter(=='#')[(s!!(i-1))!!(j-2),(s!!(i-2))!!(j-2),(s!!(i-2))!!(j-1)])))++"\n") else"#\n"
                    |j==w       =if ((s!!(i-1))!!(j-1))/='#' then((show(length(filter(=='#')((drop (w-2)(s!!(i-1)))++(drop (w-2)(s!!i))++(drop (w-2)(s!!(i-2)))))))++"\n") else"#\n"
                    |i==h       =if ((s!!(i-1))!!(j-1))/='#' then(show(length(filter(=='#')((take 3(drop(j-2)(s!!(i-1))))++(take 3(drop(j-2)(s!!(i-2)))))))) else"#"
                    |otherwise  =if ((s!!(i-1))!!(j-1))/='#' then(show(length(filter(=='#')((take 3(drop(j-2)(s!!(i-1))))++(take 3(drop(j-2)(s!!i)))++(take 3(drop(j-2)(s!!(i-2)))))))) else"#"

Measured memory_bytes: 1148
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=405,mn=1e5+5;
bitset<maxn>s[maxn];
int i,j,n,m,t,x[mn],y[mn],ans;
int main(){
	n=read(),m=read();
	fo(i,1,m) x[i]=read(),y[i]=read();
	fo(i,1,n){
		s[i][i]=1;
		for(t=m;t;t--){
			if (s[i][x[t]]&&s[i][y[t]]) break;
			if (!s[i][x[t]]&&!s[i][y[t]]) continue;
			s[i][x[t]]=s[i][y[t]]=1;
		}
		s[i][0]=t>0;
	}
	fo(i,1,n-1)
	fo(j,i+1,n) if (!s[i][0]&&!s[j][0]) ans+=!((s[i]&s[j]).any());
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
/*
 *  Language:   C++
 *  Author:     Debajyoti Dasgupta
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1), vis(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int i = 1;
    vector<int> tmp;
    while (!vis[a[i]]) {
        tmp.emplace_back(a[i]);
        vis[a[i]] = true;
        i = a[i];
    }
    int st = i;
    vector<int> cycle;
    while (a[i] != st) {
        cycle.emplace_back(a[i]);
        i = a[i];
    }
    cycle.insert(cycle.begin(), a[i]);
    i = (int) tmp.size() - (int) cycle.size();
    if (k <= i) {
        cout << tmp[k - 1] << endl;
        return 0;
    }
    k -= i;
    k = k % cycle.size();
    cout << cycle[k] << endl;
}

Measured memory_bytes: 10684
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	x := int64(getNextInt(scanner))

	aa := make([]int64, n)

	for i := 0; i < n; i++ {
		aa[i] = int64(getNextInt(scanner))
	}

	ans := int64(0)
	for i := 1; i < n; i++ {
		if aa[i-1]+aa[i] > x {
			ans += aa[i-1] + aa[i] - x
			aa[i] = x - aa[i-1]
			if aa[i] < 0 {
				aa[i-1] += aa[i]
				aa[i] = 0
			}
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   
using namespace std;
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  tree_order_statistics_node_update>  ordered_set; 
typedef long long ll;
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)

// DEBUGGING TEMPLATE
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const ll mod=1000000007;
const ll mod1=998244353;

ll modpow(ll a, ll b, ll c)
{ //a^b%c in O(logb)
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % c;
		}
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}
ll modinv(ll m, ll n)
{ //modular inverse of n w.r.t m provided 1<=n<=(m-1) in O(logn) and m is prime
	ll inv[n + 1];
	inv[1] = 1;
	for (int i = 2; i < n + 1; ++i)
		inv[i] = (m - (m / i) * inv[m % i] % m) % m;
	return inv[n];
}

void solve(){
	int a, b, m;
	cin >> a >> b >> m;
	int ax[a + 1], bx[a + 1], mina=INT_MAX, minb = INT_MAX;
	ff(i, 1, a + 1) {
		cin >> ax[i];
		mina = min(mina, ax[i]);
	}
	ff(i, 1, b + 1){
		cin >> bx[i];
		minb = min(minb, bx[i]);
	}
	int ans = mina + minb;
	while(m--){
		int x, y, c;
		cin >> x >> y >> c;
		ans = min(ans, ax[x] + bx[y] -c);
	}
	cout<<ans<<"\n";
}

//a+b=a^b+2*(a&b)
int main()
{
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t=1;
	while(t--){
		solve();
	}


	return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int X[11][11];
int N, D;

int dist2(int i, int j) {
    int res = 0;
    rep(k, D) {
        res += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
    }
    return res;
}

signed main() {
    cin >> N >> D;
    rep(i, N) {
        rep(j, D) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    rep(i, N) {
        for (int j = i + 1; j < N; ++j) {
            int dis2 = dist2(i, j);
            int a = 0, b = 1000;//a^2<=dis2<b^2
            while (b - a > 1) {
                int m = (a + b) / 2;
                if (m * m > dis2)b = m;
                else a = m;
            }
            if (a * a == dis2)++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    S = input()

    r_sums = [0] * N
    g_sums = [0] * N
    b_sums = [0] * N

    for i in range(N):
        r = 0
        g = 0
        b = 0
        if S[i] == 'R':
            r = 1
        if S[i] == 'G':
            g = 1
        if S[i] == 'B':
            b = 1
        
        if i == 0:
            r_sums[0] = r
            g_sums[0] = g
            b_sums[0] = b
        else:
            r_sums[i] = r_sums[i-1] + r
            g_sums[i] = g_sums[i-1] + g
            b_sums[i] = b_sums[i-1] + b

    ans = 0
    for i in range(N-2):
        for j in range(i,N-1):
            st = set([S[i],S[j]])
            if len(st) == 1:
                continue
            k_color = ""
            for color in ["R","G","B"]:
                if not color in st:
                    k_color = color
                    break
            
            sub = 0
            if 0 <= j+(j-i) < N:
                if S[j+(j-i)] == k_color:
                    sub = 1

            if k_color == "R":
                ans += r_sums[-1] - r_sums[j] - sub
            elif k_color == "G":
                ans += g_sums[-1] - g_sums[j] - sub
            elif k_color == "B":
                ans += b_sums[-1] - b_sums[j] - sub
    
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 69072
H, W = gets.split.map( &:to_i )
Board = Array.new( H ) do |i|
	 gets.strip
end

H.times do |i|
	W.times do |j|
		if Board[i][j] == '#' then
			next
		end

		cnt = 0
		( i - 1 ).upto( i + 1 ) do |y|
			( j - 1 ).upto( j + 1 ) do |x|
				if 0 <= y && y < H && 0 <= x && x < W && Board[y][x] == '#' then
					cnt += 1
				end
			end
		end

		Board[i][j] = ( cnt + '0'.ord ).chr
	end
end

Board.each do |s|
	puts s
end



Measured memory_bytes: 1788
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    vi a(3);
    rep (i, 3) {
        cin >> a[i];
    }
    sort(all(a));
    if ( a[0] == 5 && a[1] == 5 && a[2] == 7 ) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<" "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{

}

int main()
{
    FASTIO;
    int t;
    t = 1;
    cin >> t;
    cout<<t+t*t+t*t*t;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
// ミント
const int mod = 1e9+7 ;
//998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}   ;
 

int main(){
   ll x,y ;cin>>x>>y ;
   combination c(x+y+5) ;
   if((x+y)%3!=0)cout<<0<<endl; 
   else{
     ll a= (2*x-y)/3 ;
     ll b= (-x+2*y)/3 ;
     mint ans = c(a+b,a) ;
    cout<<ans<<endl ;
   }
       return 0;
  }

Measured memory_bytes: 31616
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int b[3];
  for (int i=0; i<3; i++) cin >> b[i];
  sort(b,b+3);
  int ans = b[0]+b[1];
  cout << ans << endl;
} 
  

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

int main() {
	std::uint16_t N, K;
	std::cin >> N >> K;

	std::vector<std::uint16_t> l;
	l.resize(N);
	for (std::uint16_t i = 0; i < N; ++i) {
		std::cin >> l[i];
	}

	std::sort(std::begin(l), std::end(l), std::greater<std::uint16_t>());
	std::uint32_t ans = 0;

	for (std::uint32_t i = 0; i < K; ++i) {
		ans += l[i];
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W,H,N; cin>>W>>H>>N;
  int A=0,B=W,C=0,D=H;
  for(int i=0;i<N;i++){
    int a,b,c; cin>>a>>b>>c;
    if(c==1)A=max(A,a);
    else if(c==2)B=min(B,a);
    else if(c==3)C=max(C,b);
    else D=min(D,b);
  }
  cout<<max(B-A,0)*max(D-C,0)<<endl;
}


Measured memory_bytes: 3556
#include<iostream>
using namespace std;
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string str;
	cin>>str;
	if(str[1]=='S')
	{
		if(str[0]=='R'||str[2]=='R')
		{
			cout<<1<<endl;
		}
		else
		{
			cout<<0<<endl;
		}
	}
	else
	{
		int val=1;
		if(str[0]=='R')
		   val++;
		if(str[2]=='R')
		   val++;
		cout<<val<<endl;
	}
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;

constexpr int MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	
	int n , k;
	cin >> n >> k;
	
	vector<int> v(istream_iterator<int>{cin} , istream_iterator<int>());
	
	vector<vi> dp(n , vi(k + 1));
	dp[0][0] = 1;
	rep(i , v[0] + 1)
		dp[0][i] = 1;
	
	repi(i , n - 1)
	{
		int cur = 0;
		rep(j , k + 1)
		{
			if(i > 0)
			{
				cur += dp[i - 1][j];
				cur %= MOD;
				if(j - v[i] - 1 >= 0)
					cur -= dp[i - 1][j - v[i] - 1];
			}
			cur = (cur + MOD) % MOD;
			dp[i][j] = cur;
		}
	}

	
	cout << dp[n - 1][k] << endl;


	return 0;
}

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


int main() {
  int n;
  cin >> n;
  int memo = - 1;
  for (int i = n; i >= n / 1.08; i--) {
    if (floor(i * 1.08) == n) {
      memo = i;
      break;
    }
  }
  if (memo == -1) cout << ":(" << endl;
  else cout << memo << endl;
}

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


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

  int cnt = 0;
  long long ans = 0;
  long long mini = (int) 1e10;
  int judge = 0;
  for(int i = 0; i < N; i++) {
    if(A[i] < 0) cnt++;
    if(A[i] == 0) judge = 1;
    if(abs(A[i]) < mini) mini = abs(A[i]);
    ans+=abs(A[i]);
  }
  if(cnt % 2 == 0) judge = 1;
  cout << (judge ? ans:ans - 2*mini) << endl;
  
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {


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

		long d, r;//d = ??????r = ?????????
		double f;//f = ???????°???°
		long a = scan.nextInt();//a = ??????????????°
		int b = scan.nextInt();//b = ????????°

		d = a / b;
		r = a % b;
		f = (double)a / b;

		System.out.println(String.format("%d %d %f", d, r, f));
		
        scan.close();
    }

}

Measured memory_bytes: 26472
#include<bits/stdc++.h>
#define nl '\n'
#define dbg(a) cout<<#a<<"="<<a<<endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<ll,ll>
#define vi vector<ll>
#define MX 600000
#define MXX 1000000000
using namespace std;

void solve(){
    ll k;
    cin>>k;
    map<ll, ll> mp;
    ll x=0;
    ll ct=0;
    while(mp[x]==0)
    {
        ct++;
        mp[x]=1;
        x=(x*10+7)%k;
        // dbg(x);
        if(x==0)
        {
            cout<<ct<<endl;
            return ;
        }
    }
    cout<<-1<<endl;
}

int main()
{
    fast;
    solve();
    return 0;
}


Measured memory_bytes: 66072
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int X,A,B;
	cin >> X;
	
	if(X==1){cout << "Hello World" << endl;}
	else
	{
		cin >> A >> B;
		cout << A + B << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;

	cout<<S[0]<<S.size()-2<<S[S.size()-1]<<endl;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;
int main()
{   
    int n;
    cin >> n;
    cout << (n/2) + (n % 2) << endl;
    
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int H, N;
int A[100010];

signed main()
{
	cin >> H >> N;
	int sum = 0;
	REP(i, N)
	{
		int a;
		cin >> a;
		sum += a;
	}
	if (H <= sum)
	{
		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);
        
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        sc.close();

        if(a == 0){
            System.out.println(b/x + 1);
        } else {
            if(a%x == 0)
                System.out.println(b/x - a/x + 1);
            else
                System.out.println(b/x - a/x);
        }
    }
}

Measured memory_bytes: 23764
N = int(input())
D, X = [int(i) for i in input().split()]

def chocoCounter(a, D):
    choco_cnt = 0
    choco_day = 0
    day = 0
    while True:
        if day == 0:
            choco_day = 1
        else :
            choco_day = (a * day) + 1
        
        if choco_day <= D:
            choco_cnt += 1
        else :
            break
        day += 1
    return choco_cnt

cnt = 0
for i in range(N):
    a = int(input()) # 傾きの大きさ
    cnt += chocoCounter(a, D)

print(cnt+X)

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

int gcd(int a, int b){
  if(b==0) return a;
  return gcd(b, a%b);
}

int main(){
  using namespace std;
  int k,sum=0;
  cin >> k;
  // aとbの最大公約数の総和を求めてから、cerr
  for(int i=1; i<=k; i++){
    for(int j=1; j<=k; j++){
        for(int l=1; l<=k; l++){
          sum+=gcd(gcd(i,j),l);
        }
    }
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std ;

#define N 500010
#define inf 0x3f3f3f3f

struct node {
	int to , nxt , belong ;
}e[ N << 2 ];

int n , m ; 
int head[ N << 2 ] , cnt ;
int d[ N * 2 ]  ;

void ins( int u , int v , int c ) {
	e[ ++ cnt ].to = v ;
	e[  cnt ].nxt = head[ u ] ;
	e[ cnt ].belong = c ;
	head[ u ] = cnt ;
}

std::set< int > st[ N ] ;
priority_queue< pair<int,int> > q;

int main() {
	scanf( "%d%d" , &n ,&m ) ;
	for( int i = 1 ; i <= m ; i ++ ) {
		int x , y , c ;
		scanf( "%d%d%d" , &x , &y , &c ) ;
		ins( x , y , c ) ;
		ins( y , x , c ) ;
	}
	for( int i = 1 ; i <= n ; i ++ ) d[ i ] = inf ;
	d[ 1 ] = 0 ;
	q.push( { 0 , 1 } ) ;
	while(!q.empty()){
		int u = q.top().second , ans = -q.top().first;
		q.pop() ;
		if( d[ u ] < ans ) continue ;
		for( int i = head[ u ] ; i ; i =e[ i ].nxt ) {
			int v = e[ i ].to ;
			int num = ans + ( !st[ u ].count( e[ i ].belong ) ) ;
			if( d[ v ] > num ) {
				d[ v ] = num ;
				q.push( { -num , v } ) ;
				st[ v ].clear() ;
				st[ v ].insert( e[ i ].belong ) ;
			}else if( d[ v ] == num ) {
				st[ v ].insert( e[ i ].belong ) ;
			}
		}
	}
	if( d[ n ] == inf ) puts( "-1" ) ;
	else printf( "%d\n" , d[ n ] ) ;
}

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

int main(){
int N;cin >> N;
vector<vector<int>> A(10,vector<int>(10,0));

for(int i = 1; i <= N;i++){
    int a = i;
    int b = i%10;
    while(a >= 10) a/=10;
    A.at(a).at(b)++;
}
long int ans = 0;

for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10;j++){
        ans += A.at(i).at(j) * A.at(j).at(i);
    }
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;
int mod = 1e9+7;

ll modpow(ll a,int p) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int halfP = p / 2;
        ll half = modpow(a,halfP);
        return half*half % mod;
    }
    else
        return a*modpow(a,p-1)%mod ;
};

ll calcComb(int a, int b) {
    if (b > a-b) return calcComb(a,a-b);
    ll ans1 = 1;
    ll ans2 = 1;
    for (int i = 0; i < b; i++) {
        ans1 *= (a-i);
        ans2 *= (b-i);
        ans1 %= mod;
        ans2 %= mod;
    }
    return ans1 * modpow(ans2,mod-2) % mod;
}

int main()
{
    int N,M;
    cin >> N >> M;

    vector<int> P;
    int Mnokori = M;
    for (int i = 2; i*i <= Mnokori; i++) {
        if (Mnokori % i == 0) {
            P.push_back(0);
            while (Mnokori % i == 0) {
                Mnokori /= i;
                P.back()++;
            }
        }
    }
    if (Mnokori != 1)
        P.push_back(1);

    ll ans = 1;
    for (int i = 0; i < P.size(); i++) {
        ans *= calcComb(N-1+P[i],N-1) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));
ll SumC = 0;

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(d + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        last[t[i]] = i;

        for (int j = 1; j <= 26; j++)
        {
            ans -= c[j] * (i - last[j]);
        }
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
        SumC += c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    // printf("%lld\n", scoring(BestT));

    double BestScore = scoring(BestT);

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1);

    double T0 = 1e6;
    double T1 = 1e3;
    double TL = 1950;

    ll count = 0;

    while (1)
    {
        ll msec;

        auto end = chrono::system_clock::now(); // 計測終了時刻を保存
        auto dur = end - start;                 // 要した時間を計算
        msec = chrono::duration_cast<chrono::milliseconds>(dur).count();

        if (msec >= TL)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        double score = scoring(t);

        if (exp((score - BestScore) / T) > 0.5)
        {
            BestT = t;
            BestScore = score;
        }
    }

    for (int i = 1; i <= d; i++)
    {
        printf("%d\n", BestT[i]);
    }

    // printf("%lld\n", scoring(BestT));
}


Measured memory_bytes: 4480
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>

int main() {
	/*
	int n, m;
	scanf("%d%d", &n, &m);
	printf("%d", (n - 1)*(m - 1));
	*/
	/*
	char s[200],o[10];
	int l,i;
	s[0] = '\0';
	o[0] = '\0';

	scanf("%s", s);

	l = strlen(s);
	sprintf(o, "%c%d%c", s[0], l-2,s[l-1]);

	printf("%s", o);
	*/

	unsigned int n,a[100000],x2=0,x4=0;
	unsigned int i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 4==0)
			x4++;
		else if (a[i] % 2==0)
			x2++;
	}
	if (x2 != 0)x2--;
	if (x4 >= (n - x2)/2)
		printf("Yes");
	else
		printf("No");

	return(0);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long long ull;
typedef long double ld;
#define inp_arr(name,size) for(int i = 0;i<size;i++)\
cin >> name[i];
#define cepat cin.tie(0);


int main(){
    cepat
    cout.precision(9);
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    cout << w*h/2 << " " << (x==w/2&&y==h/2);

    return 0;
}








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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] mochiArray = new int[n];
		for(int i =0;i <n;i++) {
			mochiArray[i] = sc.nextInt();
		}
		Arrays.sort(mochiArray);
		int answer = 1;
		for(int i =1;i <n;i++) {
			if(mochiArray[i] == mochiArray[i-1]) {
				continue;
			}else {
				answer++;
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 35956