akhauriyash/Code-Regression huggingface dataset:
def dijkstra_heap(n,s,edge,k):
    # 始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n  # True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heappush(edgelist, [e[k],e[2]])
    while edgelist:
        minedge = heappop(edgelist)
        # まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[2]]:
                heappush(edgelist, [e[k] + d[v], e[2]])
    return d

def examD():
    N, M, s, t = LI()
    edge = defaultdict(list)
#    edge2 = defaultdict(list)
    # edge2 メモリ無駄
    for i in range(M):
        x, y, z1, z2 = map(int, input().split())
        x -=1; y -=1
        edge[x].append([z1,z2,y])
        edge[y].append([z1,z2,x])
    start1 = s-1
    start2 = t-1
    res1 = dijkstra_heap(N,start1, edge,0)
    res2 = dijkstra_heap(N,start2, edge,1)
    ans = []
    snuke = 10**15
    cur = res1[N-1] + res2[N-1]
    ans.append(snuke-cur)
    for i in range(N-2,-1,-1):
        if res1[i] + res2[i]<cur:
            cur = res1[i] + res2[i]
            ans.append(snuke-cur)
        else:
            ans.append(snuke-cur)
    for v in ans[::-1]:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


Measured memory_bytes: 121816
//Bismillah_hir_rahmanir_rahim


#include<bits/stdc++.h>
using namespace std ;



int main()
{
    int n ;
    
    cin >> n ;
    
    if(n==1)
        cout<<"Hello World"<<endl;
    else
    {
        int a , b ;
        cin >> a >> b;
        cout<< a + b <<endl;
    }


    return 0;
}


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


int main(){
    ll N,M; cin >> N >> M;
    vector<pair<ll,ll>> Ene(N);
    for (int i = 0; i < N; i++)
    {
        cin >> Ene[i].first >> Ene[i].second;
    }
    sort(Ene.begin(),Ene.end());

    ll now,ans;
    now = ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(now + Ene[i].second <= M){
            ans += Ene[i].first*Ene[i].second;
            now += Ene[i].second;
        }else{
            ans += Ene[i].first * (M-now);
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		
		int N=sc.nextInt();
		int K=sc.nextInt();
		int X=sc.nextInt();
		int Y=sc.nextInt();
		
		if(N<=K) {
			System.out.println(X*N);
		}else if(N>K) {
			System.out.println(K*X+(N-K)*Y);
		}
		
		sc.close();
	}
}

Measured memory_bytes: 21716
N=int(input())
V = list(int(i) for i in input().split()) 
C = list(int(i) for i in input().split()) 
S=[]
ans=0
for i in range(N):
    S.append(V[i]-C[i])
for i in range(N):
	if S[i]>0:
		ans=ans+S[i]
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int w,a,b,x;
	scanf("%d%d%d",&w,&a,&b);
	if(b>(a+w))
	{
		x=b-(a+w);
		printf("%d",x);
	}
	else if(a>(b+w))
	{
		x=a-(b+w);
		printf("%d",x);
	}
	else
	printf("%d",x);
return 0;
}

Measured memory_bytes: 256
/*================================================
# ~  file:B.cpp
# ~~ date:2020-03-09
# ~~~author: SoMnus_L
#        |everybody finds love,in the end|
#   人の運命か,人の希望は悲しみにつづられているね
=================================================*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N=1e6+10;
using namespace std;
typedef pair<int,int>PII;

int n;
int a[100][100],b[N];
int p[100][100];
bool ans=0;
int main(){
 ios::sync_with_stdio(false);
   for(int i=1;i<=3;i++)
     for(int j=1;j<=3;j++){
	cin>>a[i][j];
     }
    cin>>n;
    for(int i=1;i<=n;i++)  cin>>b[i];
    for(int i=1;i<=3;i++)
      for(int j=1;j<=3;j++)
        for(int k=1;k<=n;k++){
	   if(a[i][j]==b[k]) p[i][j]++;
	}
    for(int i=1;i<=3;i++)  if(p[i][1]!=0 && p[i][2]!=0 && p[i][3]!=0) ans=1;
    for(int i=1;i<=3;i++)  if(p[1][i]!=0 && p[2][i]!=0 && p[3][i]!=0) ans=1;
    if(p[1][1]!=0 && p[2][2]!=0 && p[3][3]!=0)  ans=1;
    if(p[1][3]!=0 && p[2][2]!=0 && p[3][1]!=0)  ans=1;
     if(ans==1)  cout<<"Yes"<<endl;
     else  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

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

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

constexpr int MOD = 1e9 + 7;
constexpr ll INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    sort(a.begin(), a.end());

    string ans = "No";

    // 0, 0, 0, ...
    if(a[n-1] == 0){
        ans = "Yes";
    }

    if(n % 3 == 0){
        // 0, 0, X, X, X, X
        if(a[0] == a[n/3-1] && a[0] == 0 && a[n/3] == a[n-1]){
            ans = "Yes";
        }

        // X, X, Y, Y, Z, Z and X ^ Y = Z
        if(a[0] == a[n/3-1] && a[n/3] == a[n*2/3-1] &&
            a[n*2/3] == a[n-1] && (a[0] ^ a[n/3]) == a[n*2/3]){
            ans = "Yes";
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n,k;

    cin>>n>>k;

    int a[n];

    for(int i=0; i<k; i++)
    {
        cin>>a[i];
    }

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

        if(a[i-k]<a[i])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }




    return 0;
}


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

using namespace std;

int main()
{
  int n, ans = 100000000;

  scanf("%d", &n);

  int a, b, sumA, sumB;

  for (int i = 1; i <= n / 2; i++)
  {
    sumA = 0;
    sumB = 0;
    a = i;
    b = n - i;

    while (a != 0)
    {
      sumA += a % 10;
      a /= 10;
    }

    while (b != 0)
    {
      sumB += b % 10;
      b /= 10;
    }
    if (ans > sumA + sumB)
      ans = sumA + sumB;
  }

  printf("%d", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) lps(i,0,n)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define FDST int hogehogehoge;cin>>hogehogehoge
#define int long long

int foo(string s){//cout<<"s "<<s<<endl;
  int size = s.size(), ans = 0;
  for(int i = size-1, d = 1; i >= 0; i--, d *= 10){
    ans += d*( s[i]- '0');
  }
  //cout<<"ans "<<ans<<endl;
  return ans;
}

signed main(){
  map<string, int> ma;
  string S;
  int n;

  while(true){
    cin>>S;
    if(S == "END_OF_FIRST_PART") break;
    cin>>n;
    ma[S] = n;
  }

  while(true){
    int ans = 0;
      stack<int> st;
    cin>>S;
    if(S == "0")break;
    int size = S.size();
    for(int i  = 0; i < size; i++){ //cout<<i<<endl;//if(!st.empty())cout<<i<<" "<<st.top()<<endl;
      int  tn;
      if('A' <= S[i] && S[i] <= 'Z'){
	string temp; temp +=  S[i];
	if(i == size - 1){
	  tn = ma[temp];
	  //cout<<"tn "<<tn<<endl;
	  if(tn){
	    st.push(tn);
	  } else {
	    ans = -1;
	    break;
	  }
	} else {
	  if('a' <= S[i+1] && S[i+1] <= 'z'){
	    temp += S[i+1];
	    tn = ma[temp];
	    if(tn){
	      st.push(tn);
	    } else {
	      ans = -1;
	      break;
	    }
	    i++;
	  } else{
	    tn = ma[temp];
	    if(tn){
	      st.push(tn);
	    } else {
	      ans = -1;
	      break;
	    }
	  }
	  
	}
      } else if(S[i] == '('){
	st.push(-1);
      } else if(S[i] == ')'){
	int stemp = 0;
	while(true){
	  int stemp2 = st.top(); st.pop();
	  if(stemp2 == -1)break;
	  stemp += stemp2;
	}
	st.push(stemp);	
      } else if('0' <= S[i] && S[i] <= '9'){
	string num;
	int j = i;
	while(true){
	  if(j == size) break;
	  if('0' <= S[j] && S[j] <= '9') num += S[j];
	  else break;
	  j++;
	}
	i = j-1;
	int n = foo(num), tnn;
	//cout<<"n = "<<n<<endl;
	tnn = st.top(); st.pop();
	//cout<<"tnn "<<tnn<<endl;
	st.push(n*tnn);
      }
    }
   
    
    if(ans == -1) cout<<"UNKNOWN"<<endl;
    else {
      while(!st.empty()){
	ans += st.top(); st.pop();
      }
      cout<<ans<<endl;
    } 
  }
  

  return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;
string s, t;

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

    for (int i = 0; i < 2 * n; i++) {
        if (i & 1) {
            cout << t[i / 2];
        }
        else {
            cout << s[i / 2];
        }
    }
    cout << endl;

    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    if (N % 1000 == 0) {
        cout << "0\n";
    } else {
        cout << 1000 - (N % 1000) << '\n';
    }
    return 0;
}

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

string s = "aeiou";
int main(){
	char buf[2];
	scanf("%s", buf);
	if (s.find(buf[0]) != string::npos){
		puts("vowel");
	}
	else{
		puts("consonant");
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int partition(int A[], int p, int r){
  int x = A[r], i = p-1, a;
  for(int j = p;j < r;j++){
    if(A[j] <= x){
      i++;
      a = A[i], A[i] = A[j], A[j] = a;
    }
  }
  a = A[i+1], A[i+1] = A[r], A[r] = a;
  return i+1;
}

int main(void){
  int n, i, mark;
  scanf("%d", &n);
  int A[n];
  for(i=0;i<n;i++)
    scanf("%d", &A[i]);
  mark = partition(A, 0, n-1);
  for(i=0;i<mark;i++)
    printf("%d ", A[i]);
  printf("[%d]", A[mark]);
  for(i=mark+1;i<n;i++)
    printf(" %d", A[i]);
  printf("\n");
  return 0;
} 

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

typedef long long ll;
const int N = 200005;

int a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	long long ans = 0;
	for(int i=0;i<m;i++){
		ans+=a[i];
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int main(void){
    string s;
    cin >> s;

    if(s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

ll N,S;
vector<ll> A;
ll dp[3001][3001];

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

  cin>>N>>S;
  A.resize(N);
  rep(i,N)cin>>A[i];

  dp[0][0]=1;
  rep(i,N)rep(j,S+1){
  	(dp[i+1][j]+=dp[i][j])%=mod;
  	if(j+A[i]<=S){
  		ll t=1;
  		if(j==0) (t*=(i+1))%=mod;
  		if(j+A[i]==S) (t*=(N-i))%=mod;
  		(dp[i+1][j+A[i]]+=dp[i][j]*t%mod)%=mod;
  	}
  }

  cout<<dp[N][S]<<endl;

  return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

#define M 1000000007

int main() {
    string s;
    cin >> s;
    auto l = s.length();
    ll keta = 1;
    ll rest = 0;
    vector<vector<ll>> dp(2, vector<ll>(13, 0));
    dp[0][0] = 1;
    int cur = 1;
    int prev = 0;
    for (auto &c : s) {
        if (c == '?') {
            for (ll i = 0; i < 13; ++i) {
                dp[cur][i] = 0;
            }
            for (ll i = 0; i < 13; ++i) {
                for (ll j = 0; j < 10; ++j) {
                    dp[cur][(i*10+j)%13] += dp[prev][i];
                }
            }
            for (ll i = 0; i < 13; ++i) {
                dp[cur][i] %= M;
            }
        } else {
            ll p = (ll)(c - '0');
            for (ll i = 0; i < 13; ++i) {
                dp[cur][(i*10+p)%13] = dp[prev][i];
            }
        }
        cur = 1-cur;
        prev = 1-prev;
    }
    cout << dp[prev][5] << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve{
public:
    void input(){

    }
    void solve(){
        input();
        int i,j;
        cin >> i >> j;
        cout << i - j + 1 << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int A, B;
    std::cin >> A >> B;
    
    const string YESNO[2] = {"Even", "Odd"};
    std::cout << YESNO[(A * B) % 2] << std::endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int a,b;
	scanf("%d %d", &a,&b);
	if((a<10)&&(b<10))printf("%d\n",a*b);
  else printf("-1\n");
	return 0;
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

int n;
double dp[310][310][310]; // dp[i][j][k] ... 1個の皿i枚,2個の皿j枚,3個の皿k枚となる操作回数の期待値

void init()
{
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            for (int k = 0; k <= n; k++)
                dp[i][j][k] = -1;
}

double rec(int one, int two, int three)
{
    if (dp[one][two][three] >= 0)
        return dp[one][two][three];
    if (one == 0 && two == 0 && three == 0)
        return 0.;

    double ret = 0.;
    {
        if (one > 0)
            ret += rec(one - 1, two, three) * one;
        if (two > 0)
            ret += rec(one + 1, two - 1, three) * two;
        if (three > 0)
            ret += rec(one, two + 1, three - 1) * three;

        ret += n;
        ret *= 1. / (one + two + three);
    }
    return dp[one][two][three] = ret;
}

signed main()
{
    map<int, int> m;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        m[tmp]++;
    }
    init();
    // cout << m[1] << "," << m[2] << "," << m[3] << endl;
    double ret = rec(m[1], m[2], m[3]);
    printf("%.15f\n", ret);
}

Measured memory_bytes: 227712
using System;
using System.Linq;

class B
{
	static void Main()
	{
		Console.ReadLine();
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var t = 0;
		Console.WriteLine(h.Count(x => { var b = x >= t; t = Math.Max(t, x); return b; }));
	}
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;

int main(){
	int N;
	cin >> N;
	int k=0,g=0;
	for(int i=0;i<N;i++){
		int x;
		cin >> x;
		if(x%2==0) g++;
		else k++;
	}
	if(k%2==0) cout << "YES" <<endl;
	else cout << "NO" <<endl;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main ()
{
    fastio
    /*lli a[5] , sum = 0 , la , la1 ;
    loopcin(5 , a) ;
    la = 10 - a[0] % 10 ;
    la1 = 0 ;
    forr(1, 5){
        if (la <= 10 - a[i] % 10 && a[i] % 10 != 0){
            la = 10 - a[i] % 10 ;
            la1 = i ;
        }
    }
    loop(5){
        if (i != la1){
            if (a[i] % 10 != 0)
                a[i] += 10 - (a[i] % 10) ;
            sum += a[i]  ;
        }
    }
    sum += a[la1] ;
    cout << sum << endl ;*/
    /******************************************************/
    lli a[5] , m = 0 , sum = 0 ;
    loopcin(5 , a );
    loop(5){
        if (a[i] % 10 != 0){
            m = max (m , 10 - a[i] % 10 ) ;
            a[i] += 10 - (a[i] % 10) ;
        }
        sum += a[i] ;
    }
    cout << sum - m  << endl ;
    
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



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

int main() {
  int n, m, s, c;
  int r[3] = {-1, -1, -1}, t;
  cin >> n >> m;
  REP(i, m) {
    cin >> s >> c;
    if (r[s - 1] != -1 && r[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    r[s - 1] = c;
  }
  REP(a, 10) {
    if (r[0] != -1) a = r[0];
    REP(b, 10) {
      if (r[1] != -1) b = r[1];
      REP(c, 10) {
        if (r[2] != -1) c = r[2];

        if (n == 1) {
          t = a;
        } else if (n == 2) {
          t = 10 * a + b;
        } else {
          t = 100 * a + 10 * b + c;
        }
        if (n == 1 || t >= (int)pow(10, n - 1)) {
          cout << t << endl;
          return 0;
        }

        if (r[2] != -1) break;
      }
      if (r[1] != -1) break;
    }
    if (r[0] != -1) break;
  }

  cout << -1 << endl;
  return 0;
}

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();
    int[] A = new int[N];

    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    sc.close();

    int gcd = gcd(A[0], A[1]);

    for (int i = 2; i < N-1; i++) {
      gcd = gcd(gcd, A[i]);
    }

    System.out.println(gcd);

  }

  public static int gcd(int a, int b){

    if (b == 0) {
      return a;
    }

    return gcd(b, a % b);

  }

}

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

int main() {
  int n,k;
  cin  >> n >> k;
  int cnt = 0;
  for(int i = 1; i <= n; i++){
    if(i % 2 == 1) cnt++;
  }
  if(cnt >= k) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(ans)


Measured memory_bytes: 27756
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){
      
  fastio();
  string s;
  int n,m,i,j,t;
  cin>>s;
  int temp=0,longest=0;
  for(i=0;i<s.size();i++)
  {
  	if(s[i]=='A' or s[i]=='G' or s[i]=='C' or s[i]=='T')
  	{
  		temp++;
  		if(temp>longest)
  			longest=temp;
  	}
  	else
  	{
  		if(longest<temp)
  			longest=temp;
  		temp=0;
  	}
  }
  cout<<longest;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  for (int i = a; i <= b; i++){
    if (c % i == 0){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3116
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;


int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		char buf[9];
		scanf("%s\n", buf);
		sort(buf, buf+8);
		int minVal = atoi(buf);
		sort(buf, buf+8, greater<char>());
		int maxVal = atoi(buf);
		printf("%d\n", maxVal-minVal);
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <algorithm>
using namespace std;

char S[100100];
int main()
{
  scanf ("%s",S);
  int c[3] = {0,};
  for (int i=0;S[i];i++) c[S[i]-'a']++;
  puts(max({c[0],c[1],c[2]})-min({c[0],c[1],c[2]})<=1?"YES":"NO");
return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n, k;

int main(){
  cin >> n >> k;
  vector<int>h(n+1);
  for(int i = 0; i<n; i++)cin >> h[i];

  int dp[n];
  for(int i = 0; i < n; i++) dp[i] = intMAX;

  dp[0] = 0;
  for(int i = 0; i<n; i++){
    for(int j = 0; j < k; j++){
      if(i-j >= 0){
        int tmp = dp[i-j] + abs(h[i-j] - h[i+1]);
        // cout << i << " " << j << endl;
        // cout << tmp << endl;
        dp[i+1] = min(dp[i+1], tmp);
        // cout << dp[i+1] << endl;
      }
    }
    // cout << i <<": "<<dp[i] << endl;
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n, m;

struct uni {
  vector<int> p;
  uni(int n) :
      p(n, -1) {}
  int root(int a) {
    return p[a] < 0 ? a : (p[a] = root(p[a]));
  }
  bool find(int a, int b) {
    return root(a) == root(b);
  }
  bool merge(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return false;
    p[a] = b;
    return true;
  }
};

struct edge {
  int f, t, c;
  edge() {}
  edge(int f, int t, int c) :
      f(f), t(t), c(c) {}
  bool operator<(const edge& e) const {
    return c < e.c;
  }
};

edge e[444444];
vector<edge> g[4444];
int res[4444][4444];

void solve(int f, int v, int p, int c) {
  res[f][v] = c;
  for (int i = 0; i < int(g[v].size()); i++) {
    if (g[v][i].t == p) continue;
    solve(f, g[v][i].t, v, max(c, g[v][i].c));
  }
}

int main(void) {
  scanf("%d%d", &n, &m);
  uni u(n);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &e[i].f, &e[i].t, &e[i].c);
    --e[i].f;
    --e[i].t;
  }
  sort(e, e+m);
  long long c = 0;
  for (int i = 0; i < m; i++) {
    if (u.merge(e[i].f, e[i].t)) {
      c += e[i].c;
      g[e[i].f].push_back(edge(e[i].f, e[i].t, e[i].c));
      g[e[i].t].push_back(edge(e[i].t, e[i].f, e[i].c));
    }
  }
  for (int i = 0; i < n; i++) {
    solve(i, i, -1, 0);
  }
  int q; scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int s, t; scanf("%d%d", &s, &t); --s; --t;
    printf("%lld\n", c-res[s][t]);
  }
  return 0;
}


Measured memory_bytes: 75904
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() {
   int a, b, c , d;
   cin >> a >> b >> c >> d;
   int ans = min(b,d) - max(a,c);
   if (ans < 0) {
	   ans =0;
   }
   cout << ans;
	return 0;
}



















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

using namespace std;

int main()
{
    int n,k;
    char str[100];

    cin>>n>>k;
    scanf(" %[^\n]",str);

    for(int i=0;i<n;i++){
        if(i+1==k) printf("%c",tolower(str[i]));
        else printf("%c",str[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Double> list = new ArrayList<>();
		ArrayList<String> checkList = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			list.add(Double.parseDouble(sc.next()));
			checkList.add(sc.next());
		}
		sc.close();

		double money = 0;
		for(int i = 0; i < N; i++) {
			if(checkList.get(i).equals("JPY")) {
				money += list.get(i);
			}else {
				money += list.get(i) * 380000.0;
			}
		}
		System.out.println(money);
	}

}

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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<25];

//dist(i,j)<r[i]+r[j]->ok
bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    if(memo[bit]==true)return 0;
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(((bit>>i)&1)==0)continue;
            if(((bit>>j)&1)==0)continue;
            if(c[i]==c[j]&&ok(i,bit)&&ok(j,bit)){
                ret=max(ret,dfs((bit^(1<<i))^(1<<j)));
            }
        }
    }

    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}
int main(){

    int a=(1<<5)-1;
    while(input())solve();
    return 0;
}

Measured memory_bytes: 19588
import math

n = int(input())

N = math.ceil(math.sqrt(n))

ans = 10**10

if n == 1:
    print(1)
    exit()

for a in range(1,N+1):
    amari = n%a
    if amari == 0:
        b = int(n / a)
        f = max(len(str(a)),len(str(b)))
        ans = min(f,ans)

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
#define PP 1000000007
using namespace std;

int main(){
ll K, Ans = 0;cin >> K;
bool C = 1;
map<ll, bool> M;

ll num = 0;
  
if(K%2 == 0)C = 0;

while(C){

  Ans++;num *= 10;num += 7;num %= K;

  if(num == 0)break;

  if(M[num]){C = 0;break;}

  M[num] = 1;

}

if(C)cout << Ans;

if(!C)cout << -1;

}

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

class Solve {
private:
public:
	bool is_last_query{};
	Solve()
	{
		int D, E;
		scanf("%d%d", &D, &E);
		if (D == 0)
		{
			is_last_query = true;
			return;
		}
		double min{1e9};
		for (int i{}; i <= D; i++)
			min = std::min(min, std::abs(hypot(i, D - i) - E));
		printf("%lf\n", min);
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3164
n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]
nl2 = [int(i2) for i2 in input().split()]

s1 = 0
for i3 in range(n1):
    if nl1[i3] - nl2[i3] >= 0:
        s1 += nl1[i3] - nl2[i3] 

print(str(s1))

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

void swap(int *a,int *b){
	int tmp=*a;
	*a=*b,*b=tmp;
}
int gcd(int a,int b){
	while(b%a!=0){
		b=b%a;
		swap(&a,&b);
	}
	return a;
}

int main(){
	int N,i,j,L,max;
	int l,r;
	int *A;int *M;int *R;
	scanf("%d",&N);
	A=(int*)malloc(sizeof(int)*N);
	M=(int*)malloc(sizeof(int)*N);
	R=(int*)malloc(sizeof(int)*N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	if(N==2){
		if(A[1]>A[0])printf("%d\n",A[1]);
		else printf("%d\n",A[0]);
		return 0;
	}
	L=0;
	R[N-1] = A[N-1];
	for(j=N-2;j>0;j--){
		R[j] = gcd(R[j+1],A[j]);
	}
	M[0]=R[1];
	for(i=2;i<N;i++){
		if(i==2)L=A[0];
		else L=gcd(L,A[i-2]);
		l=L,r=R[i];
		M[i-1]=gcd(l,r);
	}
	M[N-1]=gcd(L,A[N-2]);
	max=M[0];
	for(i=0;i<N;i++){
		if(max<M[i])max=M[i];
	}
	printf("%d\n",max);
	return 0;
}

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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

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

using namespace std;

ll a[MAXN];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n>>m;
	rep(i,0,m){
		cin>>j>>k;
		a[j]++;
		a[k+1]--;
	}
	partial_sum(a,a+MAXN,a);
	rep(i,1,n+1){
		if(a[i]==m) ans++;
	}ret(ans)
	return 0;
}

Measured memory_bytes: 1024
S = input().split(' ')

num_stack = []
for char in S:
    if char == '+':
        num2 = num_stack.pop(-1)
        num1 = num_stack.pop(-1)
        num_stack.append(num1+num2)
    elif char == '-':
        num2 = num_stack.pop(-1)
        num1 = num_stack.pop(-1)
        num_stack.append(num1-num2)
    elif char == '*':
        num2 = num_stack.pop(-1)
        num1 = num_stack.pop(-1)
        num_stack.append(num1*num2)
    else:
        num_stack.append(int(char))
print(num_stack[0])


Measured memory_bytes: 5600
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1e8;


int main(){
  int N;
  cin >> N;
  ll A[N+1],B[N+1],C[N+1];
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  A[N] = INFLL;
  for(int i=0; i<N; i++){
    cin >> B[i];
  }
  for(int i=0; i<N; i++){
    cin >> C[i];
  }
  C[N] = INFLL;
  sort(A,A+N);
  sort(C,C+N);
  ll sum=0;
  for(ll i=0; i<N; i++){
    ll *a;
    a = lower_bound(A,A+N,B[i]);
    ll ai;
    if(*lower_bound(A,A+N,B[i]) == B[i]){
      ai--;
    }
    ai = distance(A,a);
    ll *c;
    c = lower_bound(C,C+N,B[i]+1);
    ll ci;
    ci = distance(C,c);
    sum += ai*(N-ci);
  }
  cout << sum << endl;
  return 0;
}


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

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int64_t n, x, m;
	cin >> n >> x >> m;
	deque <int> cycle;
	map <int, int> seen;
	while (seen[x] < 2) {
		cycle.push_back(x);
		++seen[x];
		(x *= x) %= m;
	}
	int64_t ans = 0, took = 0;
	while (took < n && seen[cycle.front()] < 2) {
		ans += cycle.front();
		cycle.pop_front();
		++took;
	}
	n -= took;
	if (n) {
		cycle.resize(cycle.size() / 2);
		int64_t s = 0;
		for (size_t i = 0; i < cycle.size(); ++i)
			s += cycle[i];
		ans += s * (n / int64_t(cycle.size()));
		n %= int64_t(cycle.size());
		for (int64_t i = 0; i < n; ++i)
			ans += cycle[i];
	}
	cout << ans << '\n';
}


Measured memory_bytes: 6256
N,M = map(int,input().split())
keep_value = [None]*N
check = False
for i in range(M):
    s,c = map(int,input().split())
    if((keep_value[s-1]!=None) and (keep_value[s-1]!=c)):
        print('-1')
        exit()
    else:
        keep_value[s-1]=c
if(None not in keep_value):
    print(''.join(map(str,keep_value)))
else:
    if(N>2 and keep_value[0]==0):
        print('-1')
    else:
        if(keep_value[0]==None and N>=2):
            keep_value[0]=1
        keep_value=[0 if i==None else i for i in keep_value]
        print(''.join(map(str,keep_value)))

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

int main()
{
  string s;cin>>s;
  map<char,int> mp;
  for (auto &&c : s)
  {
    if (c=='N')
    {
      mp['N']++;
    }
    if (c=='W')
    {
      mp['W']++;
    }
    if (c=='S')
    {
      mp['S']++;
    }
    if (c=='E')
    {
      mp['E']++;
    }
    
  }
  if ((bool)(mp.count('N'))==(bool)(mp.count('S')) && (bool)(mp.count('E'))==(bool)(mp.count('W')))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  
  
}

Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))

ok, ng = n, 0
while ok-ng > 1:
	x = (ok+ng)//2
	#d = defaultdict(int)
	d = dict()
	last = 0
	valid = True
	if x == 1:
		for i in range(n-1):
			if a[i] >= a[i+1]:
				valid = False
				break
		if valid:
			ok = x
		else:
			ng = x
		continue

	for i in range(n-1):
		dels = []
		if a[i] < a[i+1]:
			last = a[i+1]
			continue

		j = a[i+1]
		for k in d.keys():
			if j < k:
				dels.append(k)

		while j > 0:
			if j in d and d[j] == x-1:
				#d[j] = 0
				dels.append(j)
				j -= 1
			else:
				break

		if j in d:
			d[j] += 1
		else:
			d[j] = 1

		for k in dels:
			del d[k]

		if 0 in d:
			valid = False
			break
		last = j

	if valid:
		ok = x
	else:
		ng = x
print(ok)

Measured memory_bytes: 91472
void main() {
	auto ip = readAs!(int[]), D = ip[0], N = ip[1];
	if(D == 0) {
		if(N == 100) writeln(101);
		else writeln(N);
	} else if(D == 1) {
		if(N == 100) writeln(100*101);
		else writeln(100*N);
	} else {
		if(N == 100) writeln(100*100*101);
		else writeln(10000*N);
	}
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    fori(i, 1, 4) if(s[i] == s[i - 1]) return cout << "Bad" << endl, 0;
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
n,m,x,y = map(int, input().split())
px = list(map(int, input().split()))
py = list(map(int, input().split()))
# import ipdb; ipdb.set_trace()
if max(px) < min(py) and (x+1) < y and max(px) < y and x < min(py) :
    for z in range(x+1, y+1):
        if z in range(max(px), min(py)+1):
            print('No War')          
            break
    else:
        print('War')
else:
    print('War')

Measured memory_bytes: 3064
N = int(input())
edge = [set() for i in range(N)]
for i in range(N-1):
  a,b=[int(s) for s in input().split()]
  a-=1
  b-=1
  edge[a].add((b,i))
  edge[b].add((a,i))

def color(set):
  val=len(set)+1
  if not(val in set):
    return(val)
  c=1
  while True:
    if c in set:
      c+=1
    else:
      return(c)

#幅優先探索
ans=[0 for _ in range(N-1)]
colors=set()
vrt_color=[set() for _ in range(N)] #辺に塗った
stack=[(0,-1)]
while stack:
  vrt, _from =stack.pop(-1) #現在の場所と親
  for _to, e_i in edge[vrt]: #行き先と辺の番号
    if _to==_from:
      continue     #逆流防止
    x=color(vrt_color[vrt])
    ans[e_i]=x
    vrt_color[_to].add(x)
    vrt_color[vrt].add(x)
    colors.add(x)
    stack.append((_to,vrt))
print(len(colors))
for a in ans:
  print(a)
    
    

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

typedef long long int lli;

long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
typedef pair<int,int> pii;
typedef vector<int> vec;
void solve(){
  string s;
  cin>>s;
  int n = s.length();
  vec pref(n);
  pref[0] = (s.at(0)=='B'?1:0);
  for(int i = 1;i<n;i++){
    if(s.at(i)=='B'){
      pref[i] = pref[i-1]+1;
    }
    else{
      pref[i] = pref[i-1];
    }
  }

  lli ans = 0;
  for(int i = 0;i<n;i++){
    if(s.at(i)=='W'){
      ans+=pref[i];
    }
  }

  cout<<ans;
}

int main(){
  solve(); 
}

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

int t[3], nt[3], d, e;

void solve(){
  int res = 0;
  for(int i = 0; i < 3; i++){
    res += t[i] * nt[i];
  }

  int sum = res;
  int cnt = 0;

  for(int i = 2; i >= 0; i--){
    while(nt[i] > 0){
      int cal = sum + max(d, cnt) * e;

      res = min(res, cal);
      sum -= t[i];
      nt[i]--;
      cnt++;
    }
  }

  res = min(res, max(d, cnt) * e);

  cout << res << endl;
}

int main(){
  while(cin >> t[0] >> t[1] >> t[2] >> d >> e, t[0]){
    cin >> nt[0] >> nt[1] >> nt[2];
    solve();
  }
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
    private static Scanner sc;
    public static void main(String[] args){
    	int a,b,c,d,e;
    	List <Integer> list1 = new ArrayList<Integer>();
    	List <Integer> list2 = new ArrayList<Integer>();
        sc = new Scanner(System.in);
        a=sc.nextInt();
        for (int i=0; i<a; i++){
        	b=sc.nextInt();
        	c=sc.nextInt();
        	for (int j=0; j<b; j++){
        		list1.add(d=sc.nextInt());
        	}
        	int sum = 0;
        	if (b-c<1){
        		System.out.println(0);
        	}
        	else{
        		for (int l=0; l<b-1; l++){
        			e=list1.get(l+1)-list1.get(l);
        			list2.add(e);	
        		}
        		Collections.sort(list2);
        		for (int m=0; m<b-c; m++){
        			sum=sum+list2.get(m);
        		}
        		System.out.println(sum);
        	}
        list1.clear();
        list2.clear();
       	}    	
    }
}

Measured memory_bytes: 107228
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vi p(n);
  scan(p);
  int minval = INT_MAX;
  int ans = 0;
  rep (i, n) {
    if (minval >= p[i]) {
      ans += 1;
      minval = p[i];
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define pq_max priority_queue<ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>=b;i--)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9+7;
const ll N=2e18 + 5;

ll power(ll a,ll b,ll p)
{
    a=a%p;
    ll ans=1;
    while(b>0)
    {
        if(b%2==1)
        {
            ans=(ans*a)%p;
        }
        b=b/2;
        a=(a*a)%p;
    }
    return ans;
}

 
int main()
{
    fast;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}

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

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<vector<double>> memo(n+1, vector<double>(n+1,0));
    double prob;
    cin >> prob;
    memo[1][1] = prob;
    memo[1][0] = 1-prob;
    for(int i = 2; i <= n; ++i) {
        cin >> prob;
        double total = 0;
        for(int j = 0; j <= n; ++j) {
            if(j-1 >= 0)
                memo[i][j] += memo[i-1][j-1]*prob;
                memo[i][j] += memo[i-1][j]*(1-prob);
            total += memo[i][j];
        }
        //cout << "here: " << i << ' ' << total << '\n';
    }
    double sum = 0;
    for(int j = (n+1)/2; j <= n; ++j) {
        sum += memo[n][j];
    }
    cout << setprecision(12) << fixed << sum << '\n';
    return 0;
}


























Measured memory_bytes: 70656