akhauriyash/Code-Regression huggingface dataset:
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: HSI
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

// e = a + (1-p)e -> pe = a -> e = a/p

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

  int a = 1900 * m + 100 * (n - m);
  printf("%d\n", a << m);
  
  return 0;
}


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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int x,a,b;
	cin >> x >> a >> b;
	if(b <= a){
		P("delicious");
	}else if(b <= a+x){
		P("safe");
	}else{
		P("dangerous");
	}
}

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


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 200000

int Upper(int x,int y){

  if(x >= y){
    return x;
  }
  return y;
}

int Lower(int x,int y){

  if(x <= y){
    return x;
  }
  return y;
}

int main(){

  int i;
  int r[MAX];
  int num;
  int minv;
  int maxv;

  scanf("%d",&num);

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

  minv = r[0];
  maxv = r[1]-r[0];
  for(i = 1;i < num;i++){
    maxv = Upper(maxv,r[i]-minv);
    minv = Lower(minv,r[i]);
  }

  printf("%d\n",maxv);

  return 0;
}

Measured memory_bytes: 1380
import sys
input = sys.stdin.readline  # NOQA

import numpy as np


def update_h_w(h, w, H, W):
    # -->
    if h % 2 == 0:
        if w == W - 1:
            h += 1
        else:
            w += 1
    # <--
    else:
        if w == 0:
            h += 1
        else:
            w -= 1
    return h, w


def main():
    H, W = map(int, input().split())
    a = np.zeros((H, W), dtype=int)
    for i in range(H):
        a[i] = list(map(int, input().split()))

    N = 0
    ans = []
    tmp = []
    h, w = 0, 0
    search_pair = False
    while h < H:
        if search_pair:
            tmp.append((h + 1, w + 1))
            if a[h, w] % 2 == 1:
                search_pair = False
                ans.append(tmp)
                N += len(tmp) - 1
                tmp = []
        else:
            if a[h, w] % 2 == 1:
                search_pair = True
                tmp.append((h + 1, w + 1))
        h, w = update_h_w(h, w, H, W)

    print(N)
    for p in ans:
        for i in range(len(p) - 1):
            print(" ".join(map(str, (p[i][0], p[i][1], p[i+1][0], p[i+1][1]))))


if __name__ == "__main__":
    main()


Measured memory_bytes: 54260
#include<bits/stdc++.h>
using namespace std;
int n,l;
string st[102];
int main(){
    cin>>n>>l;
    for(int i=1;i<=n;i++) cin>>st[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n-i;j++)
            if(st[j]>st[j+1])
                swap(st[j],st[j+1]);
    for(int i=1;i<=n;i++) cout<<st[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    int H,W; cin>>H>>W;
    vector<string> s(H);
    REP(i,H) cin>>s[i];

    REP(i,W+2) cout<<'#'; cout<<endl;
    REP(i,H) cout<<'#'<<s[i]<<'#'<<endl;
    REP(i,W+2) cout<<'#'; cout<<endl;
    
}


Measured memory_bytes: 256
N, K = map(int, input().split())
pn = list(map(int, input().split()))

pn_t = [0]
for i in range(N):
    pn_t.append(pn[i]+pn_t[i])

l = 0
for i in range(N-K+1):
    l = max(l, pn_t[K+i]-pn_t[i])
ans = (l+K)/2
print(ans)


Measured memory_bytes: 24812
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
int n,p,q;
p=0;q=0;
string str1,str2;
cin>>n;
 
for(int i=0;i<n;i++)
{
    cin>>str1>>str2;
if(str1==str2){p++;q++;}
else if(str1<str2){q+=3;}
else if(str1>str2){p+=3;}
}
cout<<p<<" "<<q<<endl;
return 0;
}

Measured memory_bytes: 1208
n,m=gets.split.map(&:to_i)
kss=m.times.map{gets.split.map(&:to_i)}
ps=gets.split.map(&:to_i)
ans=0
(2**n).times do |i|
  switch=i.to_s(2).split("").map(&:to_i)
  ssize=switch.size
  (n-ssize).times{switch.insert(0,0)}
  check=true
  m.times do |j|
    sum=0
    kss[j][0].times{|k| sum+=switch[kss[j][k+1]-1]}
    if sum%2!=ps[j]
      check=false
      break
    end
  end
  ans+=1 if check
end
puts ans


Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <int> A(n);
	int a = 0, b = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		int c = 0;
		while(x % 2 == 0) {
			x /= 2;
			c++;
		}
		if (c == 0) {
			b++;
		}
		if (c >= 2) {
			a++;
		}
	}
	if (a + b == n) {
		cout << (a - b >= -1 ? "Yes" : "No");
	}
	else {
		cout << (a >= b ? "Yes" : "No");
	}
}


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

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  int s=0;
  for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
  sort(a,a+n);
  for(int i=0;i<k;i++)
    s+=a[i];
  cout<<s<<endl;
  return 0;
}
  

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

void fastio(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	return;
}
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
	if (n == 0)return 1;
	if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
	return (x * modexp((x * x) % md, n / 2, md)) % md;
}
vi ans(200001,0),g[200001],b,a(200001);
void dfs(int s=1,int p=1){
    int x = lower_bound(all(b),a[s])-b.begin();
	int curr=-1;
	if(x>=size(b))
		b.pb(a[s]);
    else {
		curr=b[x];
		b[x]=a[s];
	}
    ans[s]=size(b);
	fr(i,g[s]){
		if(i==p)
			continue;
		dfs(i,s);	
	}
	if(curr==-1){
		b.pop_back();
	}
	else{
		b[x]=curr;
	}
}
int main() {
	fastio();
	//clock_t tm = clock();
	int n,x,y;
	cin>>n;
	f(i,1,n+1)cin>>a[i];
	f(i,1,n){
		cin>>x>>y;
		g[x].pb(y);g[y].pb(x);	
	}
	dfs();
	f(i,1,n+1)cout<<ans[i]<<endl;
	//cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}


Measured memory_bytes: 27136
s=input()
if (s[0]==s[1] and s[2]==s[3] and s[0]!=s[2]) or (s[0]==s[2] and s[1]==s[3] and s[0]!=s[1]) or (s[0]==s[3] and s[1]==s[2] and s[0]!=s[1]):
    print("Yes")
else:
    print("No")

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


int dp[100005];
int h[100005];

int abs(int x){
	if(x<0)
		return -x;
	return x;
}

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>h[i];
	dp[1]=0;
	dp[2]=abs(h[1]-h[2]);	
	for(int i=3;i<=n;++i){
		int prev=dp[i-1]+abs(h[i]-h[i-1]);
		int pprev=dp[i-2]+abs(h[i]-h[i-2]);
		dp[i]=min(prev,pprev);
	}	
	cout<<dp[n]<<endl;
	return 0;
}


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

A, B, C = list(map(int, input().split()))
exist_even = False

for x in [A, B, C]:
    if x % 2 == 0:
        exist_even = True
        ans = 0
        break

if not exist_even:
    ans_1 = (A + 1) // 2 * B * C - (A - 1) // 2 * B * C
    ans_2 = (B + 1) // 2 * A * C - (B - 1) // 2 * A * C
    ans_3 = (C + 1) // 2 * B * A - (C - 1) // 2 * B * A
    ans = min([ans_1, ans_2, ans_3])

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(3*n);
    rep(i,0,3*n) cin>>a.at(i);
    sort(all(a));
    reverse(all(a));
    
    ll ans=0;
    rep(i,0,n){
        ans+=a.at(1+2*i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,a,b,cnt=0; cin>>n;
    vector<int> p(n,0),q(n,0),r(n,0);
    rep(i,n) r[i]=i+1;
    rep(i,n) cin>>p[i];
    rep(i,n) cin>>q[i];
    do{
        cnt++;
        if(r==p) a=cnt;
        if(r==q) b=cnt;
    }while(next_permutation(al(r)));
    cout<<abs(b-a)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  #define endl "\n"
  #define ll long long int
  #define vi vector<int>
  #define vll vector<ll>
  #define vvi vector < vi >
  #define pii pair<int,int>
  #define pll pair<long long, long long>
  #define mod 1000000007
  #define inf 1000000000000000001;
  #define all(c) c.begin(),c.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define pb push_back
  #define f first
  #define se second
  
  using namespace std;
  int main()
  {
    std::ios::sync_with_stdio(false);
    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    cin>>n;

    ll arr[n+1][3],dp[n+1][3];
    mem(arr,0); mem(dp,0);

    for (ll i = 1; i <= n; ++i){
      for (ll j = 0; j < 3; ++j)
      {
        cin>>arr[i][j];
      }
    }

    for (ll i = 1; i <=n; ++i)
    {
      for (ll j = 0; j < 3; ++j)
      {
        dp[i][j]=arr[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
      }
    }

    cout<<max({dp[n][0],dp[n][1],dp[n][2]});

    return 0;
  }

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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



int main(){

    int a;
    cin >> a;

    cout << a + a * a + a * a * a << endl;
    
    return 0;
}

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

const int N = 5005;
const ll INF = 1e18;

int p[N];
int C[N];
bool vis[N];
int a[N];
int pos[N];

ll calc(vector<int> vec1, vector<int> vec2, int k) {
    ll ans = -INF;
    int n = vec1.size(), m = vec2.size();
    if (k < n) {
        ll cursum = 0;
        for (int i = 0; i < k; i++) {
            cursum += vec1[i];
            ans = max(ans, cursum);
        }
        return ans;
    } else {
        ll cursum = 0;
        for (int i = 0; i < n; i++) {
            cursum += vec1[i];
            ans = max(ans, cursum);
        }

        ll tans = cursum;
        ll cirsum = 0;
        ll maxprefix = 0;
        for (int i = 0; i < m; i++) {
            cirsum += vec2[i];
            maxprefix = max(maxprefix, cirsum);
        }
        k -= n;
        int cirnum = k/m;
        if (cirsum <= 0 || cirnum == 0) {
            cursum = 0;
            ll add = 0;
            for (int i = 0; i < min(m, k); i++) {
                cursum += vec2[i];
                add = max(add, cursum);
            }
            ans = max(ans, tans+add);
        } else {
            ll add1 = 0, add2 = 0;
            cursum = 0;
            for (int i = 0; i < k%m; i++) {
                cursum += vec2[i];
                add1 = max(add1, cursum);
            }
            add1 += cirsum*cirnum;

            add2 = cirsum*(cirnum-1) + maxprefix;

            ans = max(ans, tans+max(add1, add2));
        }
    }
    return ans;
}

void solve() {

    int n, k;
    scanf("%d%d", &n, &k);
    bool neg = 1;
    for (int i = 1; i <= n; i++) scanf("%d", p+i);
    ll ans = -INF;
    for (int i = 1; i <= n; i++) scanf("%d", C+i), ans = max(ans, 1LL*C[i]);

    if (ans <= 0) {
        printf("%lld\n", ans);
        return ;
    }

    for (int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis));

        vector<int> vec1, vec2;
        int u = i;

        int curpos = 0;
        while (!vis[u]) {
            vis[u] = 1;
            pos[u] = ++curpos;
            a[curpos] = C[u];
            u = p[u];
        }

        if (u == i) {
            for (int i = 2; i <= curpos; i++) vec2.push_back(a[i]);
            vec2.push_back(a[1]);
        } else {
            int startpos = pos[u];
            for (int i = 2; i < startpos; i++) vec1.push_back(a[i]);
            for (int i = startpos; i <= curpos; i++) vec2.push_back(a[i]);
        }
        ans = max(ans, calc(vec1, vec2, k));
    }
    printf("%lld\n", ans);

}

int main() {
    int T = 1;
    // scanf("%d", &T);
    while (T--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3916
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        int k=sc.nextInt();
        boolean[][] nums=new boolean[h][w];
        String tmp;
        for(int i=0;i<h;i++){
            tmp=sc.next();
            for(int j=0;j<w;j++){
                nums[i][j]=tmp.charAt(j)=='1';
                //ホワイトチョコが1
            }
        }
        int[][] sum=new int[h][w+1];
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                sum[i][j+1]=sum[i][j]+(nums[i][j]?1:0);
            }
        }
        int bit=0;
        int count;
        int ans;
        int finalans=Integer.MAX_VALUE;
        int finalcut;
        int finalcuttmp;
        boolean done;
        flag:while(bit<Math.pow(2, h-1)){
            finalcut=0;
            finalcuttmp=0;
            ans=0;
            done=false;
            for(int i=0;i<h-1;i++){
                if((bit&(int)Math.pow(2, i))>0){
                    ans++;
                }
            }
            for(int i=0;i<w;i++){
                count=0;
                for(int j=0;j<h;j++){
                    count+=sum[j][i+1]-sum[j][finalcut];
                    
                    if((bit&(int)Math.pow(2, j))>0||j==h-1){
                        if(count>k){
                        finalcut=i;
                        ans++;
                        if(finalcut==finalcuttmp){
                            bit++;
                            continue flag;
                        }
                    }
                        count=0;
                    }
                }
                finalcuttmp=finalcut;
                if(i==w-1&&!done){
                    done=true;
                    i--;
                }
            }
            finalans=Math.min(ans, finalans);
            bit++;
        }
        System.out.println(finalans);

    }

}

Measured memory_bytes: 24404
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    DLazyFaith solver = new DLazyFaith();
    solver.solve(1, in, out);
    out.close();
  }

  static class DLazyFaith {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int a = in.nextInt();
      int b = in.nextInt();
      int q = in.nextInt();
      long[] jinja = new long[a];
      long[] tera = new long[b];
      long[] query = new long[q];
      for (int i = 0; i < a; i++) {
        jinja[i] = in.nextLong();
      }
      for (int i = 0; i < b; i++) {
        tera[i] = in.nextLong();
      }
      for (int i = 0; i < q; i++) {
        query[i] = in.nextLong();
        long leftJinja = nibutan(jinja, query[i], 1);
        long rightJinja = nibutan(jinja, query[i], 0);
        long leftTera = nibutan(tera, query[i], 1);
        long rightTera = nibutan(tera, query[i], 0);

        // out.println(String.format("lj: %d, rj: %d, lt: %d, rt: %d", leftJinja, rightJinja, leftTera,rightTera));
        // lj lt, lt ljは同じ
        long res = query[i] - Math.min(leftJinja, leftTera);
        // lj -> rt
        res = Math.min(res, rightTera + query[i] - 2 * leftJinja);
        // rt -> lj
        res = Math.min(res, 2 * rightTera - query[i] - leftJinja);
        // rj -> lt
        res = Math.min(res, 2 * rightJinja - query[i] - leftTera);
        // lt -> rj
        res = Math.min(res, rightJinja + query[i] - 2 * leftTera);
        // rt <-> rj
        res = Math.min(res, Math.max(rightTera, rightJinja) - query[i]);
        out.println(res);
      }

    }

    long nibutan(long[] ar, long n, int type) {
      int high = ar.length;
      int low = 0;
      int mid = (high + low) / 2;
      // n より大きい最小のar[i]を求める
      while (low < high) {
        if (ar[mid] <= n) {
          low = mid + 1;
        } else {
          high = mid;
        }
        mid = (high + low) / 2;
      }
      low -= type;
      if (low < 0) {
        return (long) -1e12;
      }
      if (low == ar.length) {
        return (long) 1e12;
      }
      return ar[low];

    }

  }
}



Measured memory_bytes: 99700
N, M = map(int, input().split(' '))
ac_set = set()
wa_cnt, wa_cnt_ls = 0, [ 0 for i in range(N) ]

for i in range(M):
    p, s = input().split(' ')
    idx = int(p) - 1
    if not idx in ac_set:
        if s == 'AC':
            ac_set.add(idx)
            wa_cnt += wa_cnt_ls[idx]
        else:
            wa_cnt_ls[idx] += 1
print(len(ac_set), wa_cnt)

Measured memory_bytes: 18252
str=input()
if(str[0]=='R' and str[1]=='R' and str[2]=='R'):
    print(3)
elif(str[1]=='R' and (str[0]=='R' or str[2]=='R')):
    print(2)
elif(str[0]=='R' or str[1]=='R' or str[2]=='R'):
    print(1)
else:
    print(0)

Measured memory_bytes: 9092
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY =1 ;
static const int BLACK =2;

int n,M[MAX][MAX];

void dijkstra()
{
	int minv;
	int d[MAX],color [MAX];
	
	for(int i=0;i<n;i++)
	{
		d[i]=INFTY;
		color[i]=WHITE;
	}
	d[0]=0;
	color[0]=GRAY;
	while(true)
	{
		minv=INFTY;
		int u=-1;
		for(int i=0;i<n;i++)
		{
			if(minv>d[i]&&color[i]!=BLACK)
			{
				u=i;
				minv=d[i];
			}
		}
		if(u==-1) break;
		color[u]=BLACK;
		for(int v=0;v<n;v++)
		{
			if(color[v]!=BLACK&&M[u][v]!=INFTY)
			{
				if(d[v]>d[u]+M[u][v])
				{
					d[v]=d[u]+M[u][v];
					color[v]=GRAY;
				}
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			M[i][j]=INFTY;
		}
	}
	int k,c,u,v;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&u,&k);
		for(int j=0;j<k;j++)
		{
			scanf("%d%d",&v,&c);
			M[u][v]=c;
		}
	}
	dijkstra();
}


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

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  rep(i,0,n){
    char s;
    cin>>s;
    if(s=='c'){cout<<"No"<<endl;continue;}
    if(s=='a'){
      if(a+b!=0){cout<<"Yes"<<endl;a--;continue;}
      else{cout<<"No"<<endl;continue;}
    }
    if(s=='b'){
      if(a+b!=0&&b!=0){cout<<"Yes"<<endl;b--;continue;}
      else{cout<<"No"<<endl;continue;}
    }
  }

  //cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
using namespace std;
int x,y;
int main(void)
{
	while(cin>>x>>y)
	{
//	2m+4n=y;
//	m+n=x; 4m+4n=4x
//	n=(y-x)/2; m=x-(y-x)/2;
int fg=1;
	for(int i=0;i<=x;++i)
	{
		if(2*i+4*(x-i)==y)
		{
			puts("Yes");
			fg=0;
			break;
		}
	}
	if(fg)
	puts("No");
	}
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin>>A>>B;
  if(A == 1) A = 14;
  if(B == 1) B = 14;
  if( A > B ) cout << "Alice" ;
  else if(A<B) cout << "Bob";
  else cout << "Draw" ;
  return 0;
}

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

using namespace std;

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

    unsigned long long int nm[100000];
    long double ans = 1;
    for (int i = 0; i < n; i++)
    {
        scanf("%llu", &nm[i]);
        if (nm[i] == 0)
        {
            printf("0");
            return 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        ans *= nm[i];

        if (ans > 1000000000000000000)
        {
            printf("-1");
            return 0;
        }
    }

    printf("%lld", (long long int)ans);

    return 0;
}

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

int main(){
	int N;
	cin >> N;
	double ans1 = 0, ans2 = 0;
	for(int i = 0; i < N; i++){
		double x;
		string u;
		cin >> x >> u;
		if(u == "JPY")
			ans1 += x;
		else
			ans2 += x;
	}
	cout << ans1 + ans2*380000 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000009
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;
typedef unsigned short int usi;

typedef struct {
    int a;
    int dif;
    int idx;
} at;

// 昇順
int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main()
{
    int i, n, m, ans=0, x[100000];
    scanf("%d %d",&n, &m);
    for(i=0; i<m; i++) {
        scanf("%d",x+i);
    }
    qsort(x,m,sizeof(int),cmp);
    int dif[m];
    dif[0] = 0;
    for(i=1; i<m; i++) {
        dif[i] = x[i] - x[i-1];
    }
    qsort(dif, m, sizeof(int), cmp);
    for(i=1; i<=m-n; i++) {
        ans += dif[i];
    }
    printf("%d",ans);
    return 0;
}


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

using namespace std;
int f[4],a,b;
int main()
{
    cin>>a>>b;
    f[a]=1;
    f[b]=1;
    for(int i=1;i<=3;i++)
        if(f[i]==0)
    {
        cout<<i;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
const int maxn=100010; 
int a[maxn];
int n,ans = 1,t = 0;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i = 1;i <= n; i++){
        cin >> a[i];
    }
    for (int i = 2; i<= n;i++){
        if( t == 0){
            if(a[i] > a[i-1]){ 
                t = 1;
            }
            else if (a[i] < a[i-1]){
                t = -1;
            }
        }else if (t == 1){
            if (a[i]<a[i-1]){
                ans++;
                t = 0;
            }
        }else{
            if (a[i] > a[i-1]){
                ans++;
                t = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

const int gmax_n = 200005;

int fa[gmax_n * 2];
int Dep[gmax_n * 2];

void init(int n)
{
    rep(i, 1, n)
    {
        fa[i] = i;
        Dep[i] = 0;
    }
}

int find(int x)
{
    if(fa[x] == x) return x;
   	return fa[x] = find(fa[x]);
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(Dep[x] < Dep[y]) fa[x] = y;
    else
    {
        fa[y] = x;
        if(Dep[x] == Dep[y]) Dep[x] ++;
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

int main()
{
    int n, k, l;
    cin >> n >> k >> l;

    init(n * 2);
    rep(i, 1, k)
    {
        int a, b;
        cin >> a >> b;
        unite(a, b);
    }

    rep(i, 1, l)
    {
        int a, b;
        cin >> a >> b;
        unite(a + n, b + n);
    }

    pair<int, int> p[gmax_n];
    map<pair<int, int>, int> m;
    rep(i, 1, n) p[i] = mp(find(i), find(i + n));
    rep(i, 1, n) m[p[i]] ++;
    rep(i, 1, n) cout << m[p[i]] << " ";
    return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,a) FOR(i,0,a)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int INF = 1e8;

struct edge{
  int from, to, cost, cap, rev;
  edge(int a, int b, int c, int d, int e)
    :from(a), to(b), cost(c), cap(d), rev(e) {}
};


struct minFlow{
  int v;
  vector< vector<edge> > graph;
  vi d, use, h, pv, pe;

  minFlow(int n):v(n){
    graph.resize(v);
    pv.resize(v); pe.resize(v);
  }

  void add(int s, int g, int c, int p){
    graph[s].pb(edge(s,g,c,p,graph[g].sz));
    graph[g].pb(edge(g,s,-c,0,graph[s].sz-1));
  }

  int maxFlow(int s, int t, int k){
    int res = 0, cost = 0;
    h = vi(v,0);

    while(1){
      int f = 1;
      priority_queue< pii, vector<pii>, greater<pii> > q;
      d = vi(v,INF);
      d[s] = 0; q.push(MP(0,s));
      
      while(q.sz){
	pii p = q.top(); q.pop();
	int u = p.second;
	if(d[u] < p.first) continue;
	rep(i, graph[u].sz){
	  edge &e = graph[u][i];
	  if(e.cap>0 && d[e.to] > d[u] + e.cost + h[u] - h[e.to]){
	    d[e.to] = d[u] + e.cost + h[u] - h[e.to];
	    pv[e.to] = u; pe[e.to] = i;
	    q.push( MP(d[e.to], e.to) );
	  }
	}
      }
      if(d[t] == INF) break;
      rep(u,v) h[u] += d[u];
      
      int x = f;
      for(int u=t;u!=s;u=pv[u]) x = min(x, graph[pv[u]][pe[u]].cap);
      f -= x;
      cost += x*h[t];

      if(cost>k) break;
      res++;
      for(int u=t;u!=s;u=pv[u]){
	edge &e = graph[pv[u]][pe[u]];
	e.cap -= x; graph[u][e.rev].cap += x;
      }

    }

    return res;
  }
};

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

  int n = a+b+2;
  int S = a+b, T = S+1;
  minFlow mf(n);

  vector<vi> w(a, vi(b,0));

  rep(i,a){
    string x; cin >> x;
    rep(j,b){
      if(x[j] == '1') w[i][j]++;
    }
  }

  rep(i,b){
    string x; cin >> x;
    rep(j,a){
      if(x[j] == '1') w[j][i]++;
    }
  }

  rep(i,a)rep(j,b){
    mf.add(i,j+a,w[i][j],1);
  }

  rep(i,a) mf.add(S,i,0,1);
  rep(i,b) mf.add(i+a,T,0,1);

  cout << mf.maxFlow(S,T,k) << endl;
}

Measured memory_bytes: 5328
// Problem : C - Marks
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
#define 	ll		    long long
#define 	rep(i,a,n)  for(int i=a;i<n;i++)
#define 	MOD 		1000000007
#define 	vp 			vector<pair<int,int> >
#define 	ff 			first
#define 	ss 			second
#define 	pb 			push_back
#define 	all(x) 		(x.begin(),x.end())
#define 	dg(x)		cerr<<"--- x = "<<x<<"\n"
#define 	endl		"\n"
#define int  unsigned long long

using namespace std;
const int N = 1e5;
ll ar[N];

void solve(){
	int n,k; cin >> n >> k;
	int ar[n+1] ;
	double pro[n+1];
	double pp=0;
	rep(i,1,n+1)
		cin >> ar[i];
		
	rep(i,1,k+1)
		pp += log(ar[i]);
		
	pro[k]=pp;
	vector<string> res;
	string s="Yes";
	string s2="No";
	
	rep(i, k+1 , n+1 ){
		
		pro[i] = pro[i-1] +log( ar[i]) - log(ar[i-k]);
		if(pro[i] > pro[i-1])
			res.pb(s);
		else
			res.pb(s2);
	}
	for(auto zz: res)
		cout << zz << endl;
}

int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 14544
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
#include<climits>

#define MAX 100001

int n,k;
int data[MAX];

using namespace std;

void solve(){
	int ans=n+1;
	int l=0,r=0;
	map<int,int> m;
	while(1){
		while(r<n&&m.size()<k){
			if(data[r]<=k) m[data[r]]++;
			r++;
		}
		if(m.size()<k) break;
		ans=min(ans,r-l);
		if(data[l]<=k){
			if(m[data[l]]==1) m.erase(data[l]);
			else m[data[l]]--;
		}
		l++;
	}
	if(ans>n) ans=0;
	printf("%d\n",ans);
}

int main(){
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&data[i]);
	solve();
}

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

int main()
{
    float a,b ,c;
    cin >> a>> b >> c;
    float time = a/c;
    if (time <= b){
        cout << "Yes" << endl;
        //cout << time << endl;
    } 
    else if(time > b) {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3564
N = int(input())
S = list(input())
arr = [0]*N
for i in range(1, N):
    if S[i] == 'E':
        arr[0] += 1
for i in range(1, N):
    arr[i] = arr[i-1]
    if S[i-1] == 'W':
        arr[i] += 1
    if S[i] =='E':
        arr[i] -= 1
print(min(arr))

Measured memory_bytes: 17484
N=int(input())
A=list(map(int,input().split()))
# N=5
# A=[2,4,4,0,2]
mod=10**9+7
# N=8
# A=[7,7,5,5,3,3,1,1]
Asorted = sorted(A,reverse=True)
# print(Asorted)
for i in range(0,len(A)-1,2):

    if Asorted[i]==Asorted[i+1]==N-i-1:
        # print("ok:",N-i-1)
        pass
    else:
        print("0")
        exit(0)


print(2**(N//2)%mod)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
vector<int> adj[2000005];
int n,m;
int d[2000005];
bool visited[2000005];
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int e4=0,e2=0,od=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]%4==0)e4++;
		else if(a[i]%2==0)e2++;
		else od++;
	}
	if(od>0)
	{
		if(od==e4&&e2>0)cout<<"Yes";
		else if(od==e4+1&&e2==0)cout<<"Yes";
		else cout<<"No";
	}
	else if(od==0)
	{
		cout<<"Yes";
	}
}
	

Measured memory_bytes: 49152
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#define INF 100000000

#define MAX_H 300
#define MAX_W 301

typedef long long int ll;
using namespace std;



int main(){

	int H,W;

	while(true){
	
		scanf("%d %d", &H, &W);

		if(H == 0 && W == 0)
			break;
		else{
		
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					if(i == 0 || i == H-1)
						printf("#");
					
					else if(j == 0 || j == W-1)
						printf("#");
					
					else
						printf(".");
				}
				printf("\n");
			}
		
			printf("\n");
		
		}
	
	}


	return 0;

}

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

int main(){
 int n, m ;
 cin>>n>>m ;
 vector<int> v[n+2] ;
 vector<pair<int, int> > vp ;
 map<pair<int, int> , string > mp ;
 for(int i =  0 ; i< m ; i++){
    int p,y ;
    cin>>p>>y ;
    vp.push_back({p,y}) ;
    v[p].push_back(y) ;
 }

 for(int i = 1 ; i<= n ; i++){
    if(v[i].size() != 0){
        sort(v[i].begin(),v[i].end()) ;
    }
    for(int j = 0 ; j< v[i].size() ; j++){
        string str = "" ;
        int num = j+1 ;
        while(num != 0){
            str = (char)(num%10 + '0') + str ;
            num = num/10 ;
        }
        while(str.length() != 6){
            str = "0"+str ;
        }
        mp[make_pair(i,v[i][j])] = str ;
    }
 }
 for(int i = 0 ; i<  m ; i++){
    string str = "" ;
    int num = vp[i].first ;
    while(num != 0){
            str = (char)(num%10 + '0') + str ;
            num = num/10 ;
        }
        while(str.length() != 6){
            str = "0"+str ;
        }
    string ans = mp[{vp[i].first,vp[i].second}] ;
    ans = str+ans ;
    cout<<ans<<endl ;
 }
 return 0 ;
}


Measured memory_bytes: 18676
#include <stdio.h>

int main(void)
{
    int t[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

    for (;;) {
        int n, i;
        int l[200][2];
        int lx, ly, sx, sy;

        scanf("%d", &n);
        if (n == 0)
            break;

        l[0][0] = l[0][1] = 0;
        lx = ly = sx = sy = 0;
        for (i = 1; i < n; ++i) {
            int m, d;

            scanf("%d %d", &m, &d);
            l[i][0] = l[m][0] + t[d][0];
            l[i][1] = l[m][1] + t[d][1];

            if (l[i][0] > lx)
                lx = l[i][0];
            if (l[i][1] > ly)
                ly = l[i][1];
            if (l[i][0] < sx)
                sx = l[i][0];
            if (l[i][1] < sy)
                sy = l[i][1];
        }

        printf("%d %d\n", lx - sx + 1, ly - sy + 1);
    }

    return 0;
}

Measured memory_bytes: 600
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

[<EntryPoint>]
let main _ =
    let n = stdin.ReadLine() |> int
    let k = stdin.ReadLine() |> int
    seq { 1..n }
    |> Seq.fold (fun a _ -> a + min a k) 1
    |> printfn "%d"
    0

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

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	
	int sum = 0;
	if(n <= k) {
		for (int i = 0; i < n; ++i)
		{
			sum += x;
		}
	} else {
		for (int i = 0; i < k; ++i)
		{
			sum += x;
		}
		for (int i = k; i < n; ++i)
		{
			sum += y;
		}
	}
	cout<<sum;
	return 0;
}

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

void update_dpk12(int k, vector<vector<int>> & dp, const vector<int> & As){
    int m1, m2;
    if (As[0] > As[k]){
        m1 = As[0];
        m2 = As[k];
        dp[k][1] = 0;
        dp[k][2] = k;
    }else{
        m1 = As[k];
        m2 = As[0];
        dp[k][1] = k;
        dp[k][2] = 0;
    }
    for (int mask = 1; mask < k; mask <<= 1) {
        if ((mask & k) == 0) continue;
        int s = k ^mask;
        if (As[dp[s][1]] > m1) {
            dp[k][2] = dp[k][1];
            dp[k][1] = dp[s][1];
            m2 = m1;
            m1 = As[dp[s][1]];
        }else if (As[dp[s][1]] == m1){
            if (dp[s][1] != dp[k][1]){
                dp[k][2] = dp[s][1];
                m2 = m1;
            }
        }else if (As[dp[s][1]] > m2){
            dp[k][2] = dp[s][1];
            m2 = As[dp[s][1]];
        }
        if (s > 0 and As[dp[s][2]] > m2 ){
            dp[k][2] = dp[s][2];
            m2 = As[dp[s][2]];
        }
    }
}


int main() {
    int N;
    cin >> N;
    const int L = (1 << N);
    vector<int> As(L);
    for (auto & a : As) cin >> a;

    vector<vector<int>> dp(L,{-1,-1,-1});
    // dp[k][0]  k 以下の i or j についての、Ai + Aj の最大値
    // dp[k][1]  k の bit列 のサブセット i について、Aiが最大となるときの i
    // dp[k][2]　k の bit列 のサブセット i について、Aiが２番目に大きい値となるときの i

    dp[0][0] = -1;
    dp[0][1] = 0;
    dp[0][2] = -1;
    dp[1][0] = As[0] + As[1];
    dp[1][1] = (As[0] > As[1]) ? 0 : 1;
    dp[1][2] = 1 - dp[1][1];
    cout << dp[1][0] << '\n';

    for (int k = 2; k < L; ++k){
        update_dpk12(k, dp, As);
        dp[k][0] = max(dp[k - 1][0], As[dp[k][1]] + As[dp[k][2]]);
        cout << dp[k][0] << '\n';
    }

    return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll a, b;
    cin >> a >> b;
    if (a <= 5) cout << 0 << endl;
    else if (a <= 12) cout << b / 2 << endl;
    else cout << b << endl;
}

Measured memory_bytes: 256
#!/usr/bin/python
import sys,heapq
try:
	import rpython.rlib.streamio
	stream=rpython.rlib.streamio.fdopen_as_stream(sys.stdin.fileno(),'r')
	raw_input=stream.readline
	def cmp_lt(x,y): return x < y
	heapq.cmp_lt=cmp_lt
	COMPILE=123456789012
	def compile(a,b,c):
		return ((a+COMPILE)<<18) | (b<<9) | c
	def decompile(a):
		return ((a>>18)-COMPILE,(a>>9)&511,a&511)
except ImportError:
	def compile(a,b,c):
		return (a,b,c)
	def decompile(a):
		return a
	if sys.version_info[0]>=3: raw_input=input

INF=1234567890123456789
def shortestPath(g,dist,prev):
	n = len(g)-1
	h = [INF]*n+[0]
	for k in range(n+1):
		for i in range(n+1):
			for e in g[i]:
				if h[e[1]]<INF and e[0]<INF and h[e[2]] > h[e[1]] + e[0]:
					h[e[2]] = h[e[1]] + e[0]
					if k==n: return False # negative cycle
	for i in range(n):
		for e in g[i]:
			e[0]+=h[i]-h[e[2]]
	for s in range(n):
		Q=[]
		heapq.heappush(Q,compile(0,s,s))
		while Q:
			e = decompile(heapq.heappop(Q))
			if prev[s][e[2]]!=-2: continue
			prev[s][e[2]] = e[1]
			for f in g[e[2]]:
				if e[0]<INF and f[0]<INF and dist[s][f[2]] > e[0] + f[0]:
					dist[s][f[2]] = e[0] + f[0]
					heapq.heappush(Q,compile(e[0]+f[0],f[1],f[2]))
		for u in range(n):
			if dist[s][u]<INF: dist[s][u] += h[u] - h[s]
	return True

def entry_point(argv):
	V,E=[int(e) for e in raw_input().rstrip().split(' ')]
	g=[[] for i in range(V+1)]
	dist=[[INF]*V for i in range(V)]
	prev=[[-2]*V for i in range(V)]
	for i in range(V): g[i].append([0,i,i])
	for i in range(V): g[V].append([0,V,i])
	for i in range(E):
		s,t,e=[int(e) for e in raw_input().rstrip().split(' ')]
		g[s].append([e,s,t])
	if not shortestPath(g,dist,prev):
		print("NEGATIVE CYCLE")
	else:
		for i in range(V):
			print(' '.join(["INF" if dist[i][j]>=INF else str(dist[i][j]) for j in range(V)]))
	return 0

def target(*args):
	return entry_point, None

if __name__ == '__main__': entry_point([])

Measured memory_bytes: 8468
#include <bits/stdc++.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <tuple>
#include <map>
#include <numeric>

using namespace std;
#define PI 3.14159265359
#define ll long long int





int main(void)
{
    ll n;
    cin >> n;
    ll h[n];
    for(ll i = 0; i < n; i++) cin >> h[i];

    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for(ll i = 2; i < n; i++){
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

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

 

    
    
    
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int N,a,b;
	scanf("%d/%d/%d", &N,&a,&b);
	int i;
	if (N>=2019){
      if(a>4)      printf("TBD");
      else printf("Heisei");
    }
	else printf("Heisei");
	return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/agc029/tasks/agc029_b

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    vector<int> v(n);
    // 値に対して個数を持つ。ペアとして使用する際に個数を数える。
    multiset<int> m;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m.insert(a);
    }

    // 大きい値から順に処理する
    while (!m.empty()) {
        int x = *(m.rbegin());
        // m.erase(x)にしてしまうと値xがすべて消えてしまう
        m.erase(m.find(x));
        // xより大きい２のべき乗を作成
        ll p = 1;
        while (p <= x)
            p *= 2;
        int y = p - x; // ペアとなるyは1通り
        auto itr = m.find(y);
        if (itr != m.end()) {
            m.erase(itr);
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr int MOD=1000000007;
constexpr ll INF=(1LL<<61)-1;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
bool inside(int h,int w,int H,int W){return 0<=h&&h<H&&0<=w&&w<W;}
void solve(){
    int W,H;
    int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
    while((cin>>W>>H,H|W)){
        bool use[H][W];
        vector<string> S(H);
        rep(i,H)cin>>S[i];
        rep(i,H)rep(j,W)use[i][j]=0;
        queue<int> Q;
        int rw=0,rb=0;
        rep(i,H)rep(j,W)if(!use[i][j]&&S[i][j]=='.'){
            int ct=0,wh=0,bl=0;
            use[i][j]=1;
            Q.push(i*100+j);
            while(Q.size()){
                int p=Q.front();Q.pop();ct++;
                int h=p/100,w=p%100;
                rep(k,4){
                    int y=h+dy[k],x=w+dx[k];
                    if(!inside(y,x,H,W)||use[y][x])continue;
                    if(S[y][x]=='W')wh=1;
                    else if(S[y][x]=='B')bl=1;
                    else {Q.push(y*100+x);use[y][x]=1;}
                }
            }
            if(wh&&!bl)rw+=ct;
            if(!wh&&bl)rb+=ct;
        }
        cout<<rb<<" "<<rw<<endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}   


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int A, B, K;

int main(void){
    
    scanf("%d %d %d", &A, &B, &K);
    map<int, int> mp;
    for(int i = A; i < A + K && i <= B; ++i) ++mp[i];
    for(int i = B - K + 1; i <= B; ++i) if(mp.find(i) == mp.end() && i >= A) ++mp[i];
    for(auto m : mp) printf("%d\n", m.first);
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, Y, Z, K; cin >> X >> Y >> Z >> K;
	vector<int> A(X); rep(i, 0, X) {
		cin >> A[i];
	}
	vector<int> B(Y); rep(i, 0, Y) {
		cin >> B[i];
	}
	vector<int> C(Z); rep(i, 0, Z) {
		cin >> C[i];
	}
	sort(all(A), greater<int>());
	sort(all(B), greater<int>());
	sort(all(C), greater<int>());
	priority_queue<int, vector<int>, greater<int>> pq;
	rep(i, 0, X)rep(j, 0, Y)rep(k, 0, Z) {
		int x = A[i] + B[j] + C[k];
		if (pq.size() >= K) {
			if (pq.top() >= x)
				break;
			pq.push(x);
			pq.pop();
		}
		else {
			pq.push(x);
		}
	}
	vector<int> ans(K);
	rep(i, 0, K) {
		ans[i] = pq.top();
		pq.pop();
	}
	sort(all(ans), greater<int>());
	rep(i, 0, K) {
		cout << ans[i] << endl;
	}
	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  for (int i = sqrt(n); i >= 1; i--) {
    if (n % i == 0) {
      cout << i + n / i - 2 << '\n';
      return 0;
    }
  }
}


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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int dps[200000];
int dpe[200000];
int dp[200000];
bool ans[200000];
int32_t main() {
    nitin;
    int n,k,c;
    cin>>n>>k>>c;
 string s; cin>>s;
    for(int i=0;i<n;i++)
    {
        ans[i]=true;
        if(i>=1)
        dps[i]=dps[i-1];
        if(s[i]=='o')
        {
            dps[i]=max(dps[i],(int)1);
            if(i>=c+1)
            dps[i]=max(dps[i-c-1]+1,dps[i]);
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(i+1<n)
        dpe[i]=dpe[i+1];
        if(s[i]=='o')
        {
            dpe[i]=max(dpe[i],(int)1);
            if(i+c+1<n)
                dpe[i]=max(dpe[i+c+1]+1,dpe[i]);
        }
    }
    int cnt=0;

    for(int i=0;i<n;i++)
    {
        if(s[i]=='o')
        {
            int op1=0,op2=0;
            if(i-c-1>=0)
                op1=dps[i-c-1];
            if(i+c+1<n)
                op2=dpe[i+c+1];
            dp[i]=op1+op2+1;
        }
    }
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        if(i-c-1>=0)
        {
            m[dp[i-c-1]]--;
            if(m[dp[i-c-1]]==0)
                m.erase(dp[i-c-1]);
        }
        if(m.count(dp[i]))
            ans[i]=false;
        m[dp[i]]++;

    }
    m.clear();

    for(int i=n-1;i>=0;i--)
    {
        if(i+c+1<n)
        {
            m[dp[i+c+1]]--;
            if(m[dp[i+c+1]]==0)
                m.erase(dp[i+c+1]);
        }
        if(m.count(dp[i]))
        {
            ans[i]=false;
        }
        m[dp[i]]++;

    }

    for(int i=0;i<n;i++)
    {
        if(ans[i] && dp[i]==k)
            cout<<i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 8644
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    for (int i = 0; i < 7; i++)
    {
        if(S[i] == s){
            cout << 7 - i << endl;
            return 0;
        }
    }
    
}

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

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

    //1の桁の数
    int count = N % 10;

    if (count == 3) {
        cout << "bon";
    } else if (count == 0 or count == 1 or count == 6 or count == 8) {
        cout << "pon";
    } else {
        cout << "hon";
    }

    return 0;
}

Measured memory_bytes: 3652