akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std; 
vector<long long> s,t;

bool isoks(int index,long long key)
{
	if(s[index]>=key)return true;
	else return false;
}
bool isokt(int index,long long key)
{
	if(t[index]>=key)return true;
	else return false;
}

int binary_search(long long key, int set)
{
	int left=-1;
	int right=(set==0 ? (int)s.size():(int)t.size());
	while (right - left > 1)
	{
		int mid = left + (right - left) / 2;
		if ((set==0 ? isoks(mid, key):isokt(mid,key))) right = mid;
		else left = mid;
	}
	return right;
}

int notmain()
{
	for(int i=0;i<10;i++)
	{
		int tmp;
		cin >> tmp;
		s.push_back(tmp);
	}
	sort(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
		cout << s[i] << " ";
	cout << endl;
	int in;
	cout << "NUM?" << endl;
	cin >> in;
	int ans=binary_search(in,0);
	cout << ans << endl << s[ans] << endl;
	return 0;
}
		

int main()
{
	int a,b,q;
	cin >> a >> b >> q;
	
	for(int i=0;i<a;i++)
	{
		long long tmp;
		cin >> tmp;
		s.push_back(tmp);
	}
	for(int i=0;i<b;i++)
	{
		long long tmp;
		cin >> tmp;
		t.push_back(tmp);
	}

	for(int que=0;que<q;que++)
	{
		long long x;
		cin >> x;
		long long sidr=binary_search(x,0);
		long long tidr=binary_search(x,1);
		long long sidl=sidr-1;
		long long tidl=tidr-1;
		if(sidr==s.size())sidr=-1;
		if(tidr==t.size())tidr=-1;
		
		long long sr=(sidr==-1 ? 1000000000005:s[sidr]-x);
		long long tr=(tidr==-1 ? 1000000000005:t[tidr]-x);
		long long sl=(sidl==-1 ? 1000000000005:x-s[sidl]);
		long long tl=(tidl==-1 ? 1000000000005:x-t[tidl]);

		long long ans=1000000000000005;
		
		ans=min(ans,max(sr,tr));
		ans=min(ans,max(sl,tl));
		ans=min(ans,(sr+tl)*2-max(sr,tl));
		ans=min(ans,(sl+tr)*2-max(sl,tr));
		
		cout << ans << endl;
	}

	return 0;
}


			



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#define rep(i,x) for(int i=0;i<x;i++)
using namespace std;

int main(){
	int N;
  cin>>N;
  int H[N];
  rep(i,N){
  	cin>>H[i];
  }
  int ans=1;
  int ma=H[0];
  rep(i,N){
  	if(i>0){
    	if(ma<=H[i]){
        	ma=max(H[i],ma);
          	ans++;
        }
    }
  }
  cout<<ans;
  
  
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    a = list(map(lambda x: int(x) - 1, input().split()))

    ans = 0
    for i in range(N):
        if i == a[a[i]]:
            ans += 1
    ans //= 2

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13876
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n,x;
  cin>>n>>x;
  vector<int> vec(n);
  rep(i,n){
    cin>>vec[i];
  }
  vector<int> vec1;
  vec1.emplace_back(0);
  for(int i=1;i<=n;i++){
    vec1.emplace_back(vec1[i-1]+vec[i-1]);
  }
  int ans=0;
  for(int j=0;j<n+1;j++){
    if(vec1[j]<=x){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
q = int(input())
s = set()
for i in range(q):
    x, y = map(int, input().split())
    if x == 0:
        s.add(y)
        print(len(s))
    elif x == 1:
        print(1) if y in s else print(0)
    else:
        s.discard(y)


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

int main()
{
	int N, a[10000],answer=0;
	cin >> N;

	//a入力
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}

	//aiの2で割り切れる回数の合計が答え
	for (int i = 0; i < N; ++i) {
		while (a[i] % 2 == 0) {
			a[i] = a[i] / 2;
			answer++;
		}
	}

	cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
n,t = map(int, input().split())

x = [list(map(int, input().split())) for i in range(n)]
x.sort()

# n-1品目までで、t-1分までで達成できる美味しさ計算
dp = [[0]*t for i in range(n)]
for i in range(1,n):
    a,b = x[i-1]
    for j in range(1,t):
        if j-a>=0:
            dp[i][j] = max(dp[i-1][j-a]+b, dp[i][j-1], dp[i-1][j])
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

# 最後に一番時間かかるの食べるときの美味しさを計算
ans = 0
for i in range(n):
    ans = max(ans, dp[n-1-i][t-1]+x[-i-1][1])
print(ans)

Measured memory_bytes: 119128
# -*- coding: utf-8 -*-
a, b = map(int, raw_input().split())
# 文字列の入力
#s = raw_input()
# 出力
if a >=13:
    print b
if a >=6 and 12 >=a:
    print b/2
if 5 >= a:
    print 0

Measured memory_bytes: 2696
n, m = map(int, input().split())
ACc = [0 for i in range(n)]
WAc = [0 for i in range(n)]

for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        if ACc[p - 1] == 0:
            ACc[p - 1] += 1
    else:
        if ACc[p - 1] != 1:
            WAc[p - 1] += 1
for j in range(n):
    if ACc[j] == 0:
        WAc[j] = 0

print(sum(ACc), sum(WAc))

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define F first
#define S second
#define ck(a,b) (0<=(a)&&(a)<b)
using namespace std;
int curdx[4]={1,-1,0,0};
int curdy[4]={0,0,1,-1};
int cmap[21][21];
int curw,curh;
int curans;
void curling(int n,pair<int,int> p){
	if(n>=curans) return;
	REP(i,0,4){
		int nx=p.S+curdx[i],ny=p.F+curdy[i];
		if(!ck(nx,curw)||!ck(ny,curh)||cmap[ny][nx]==1){
			continue;
		}
		while(1){
			if(cmap[ny][nx]==3){
				curans=n;
				return;
			}
			nx+=curdx[i];ny+=curdy[i];
			if(!ck(nx,curw)||!ck(ny,curh)) break;
			if(cmap[ny][nx]==1){
				cmap[ny][nx]=0;
				curling(n+1,{ny-curdy[i],nx-curdx[i]});
				cmap[ny][nx]=1;
				break;
			}
		}
	}
}
int main(){
	while(cin>>curw>>curh,curw){
		pair<int,int> s;
		REP(i,0,curh) REP(j,0,curw) {
			cin>>cmap[i][j];
			if(cmap[i][j]==2) s={i,j};
		}
		curans=11;
		curling(1,s);
		cout<<(curans<=10?curans:-1)<<endl;
	}
	return 0;
}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int X, Y;
    cin >> X >> Y;
    bool x = false;
    for (int i = 0; i <= X; i++)//i=ツルの数
        if (i * 2 + (X - i) * 4 == Y)
            x = true;
    cout << (x ? "Yes" : "No");
}

Measured memory_bytes: 3624
ans = []
a = []

while True:
    a = list(input().split())
    if a[1] == '+':
        ans.append(int(a[0]) + int(a[2]))
    elif a[1] == '-':
        ans.append(int(a[0]) - int(a[2]))
    elif a[1] == '*':
        ans.append(int(a[0]) * int(a[2]))
    elif a[1] == '/':
        ans.append(int(a[0]) // int(a[2]))
    else:
        break

for i in ans:
    print(i)



Measured memory_bytes: 5604
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
import fractions
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def getyaku(n):
    res = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            res.append(i)
            res.append(n // i)

    return(sorted(list(set(res))))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    n,m = getlist()
    nums = getlist()
    ans = 1
    tmp = 0
    for num in nums:
        tmp += num
        if tmp <= m:
            ans += 1
        else:
            print(ans)
            return
    print(ans)
    return

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 64748
N = int(input())
answer=0
if len(str(N))%2==0:
    for i in range(len(str(N))):
        if i%2!=0:
            answer += (10**i-10**(i-1))
else:
    answer += 1+N-(10**(len(str(N))-1))
    for i in range(len(str(N))):
        if i%2!=0:
            answer += (10**i-10**(i-1))
print(answer)

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, K;
    cin >> N >> K;
    int64_t ans = pow(N / K, 3);
    if (K % 2 == 0)
        ans += pow((N + K / 2) / K, 3);
    cout << ans;
}

Measured memory_bytes: 256
X, N = map(int, input().split())

if N == 0:
  print(X)
  
else:
  P = list(map(int, input().split()))
  A = [0]
  for i in range(1, 102):
    if (i in P) == False:
      A.append(i)
      
  c = 101
  for j in range(len(A)):
    if abs(X - A[len(A)-int(j)-1]) <= abs(X - c):
      c = A[len(A)-int(j)-1]
    else:
      c = c
  print(c)
  
  


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

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, m;
vector<vector<int>> g;

set<int> se;
bool check;
vector<bool> used;

void dfs(int v, int p, int bf) {
    used[v] = 1;
    for(int nv: g[v]) {
        if(nv == p) continue;
        if(nv == bf) {
            check = 1;
        }
        if(!used[nv] && se.find(nv) == se.end()) dfs(nv, v, bf);
    }
}

void solve() {
	cin >> n >> m;
    g.assign(n, vector<int>());
    vector<int> deg(n, 0);
    rep(i, m) {
        int a, b; cin >> a >> b;
        -- a, -- b;
        g[a].pb(b);
        g[b].pb(a);
        deg[a] ++, deg[b] ++;
    }
    rep(i, n) {
        if(deg[i] % 2 == 1) {
            cout << "No" << endl;
            return;
        }
    }
    int cnt = 0;
    int s;
    rep(i, n) {
        if(deg[i] >= 6) {
            cout << "Yes" << endl;
            return;
        }
        if(deg[i] == 4) {
            se.insert(i);
            ++ cnt;
        }
    }
    if(cnt <= 1) {
        cout << "No" << endl;
        return;
    }
    if(cnt >= 3) {
        cout << "Yes" << endl;
        return;
    }
    check = 0;
    for(int s: se) {
        used.assign(n, 0);
        dfs(s, -1, s);
    }
    if(check) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 7680
import sys
w=list(raw_input())
n=len(w)
per=-1
def good(s):
    m=len(s);z=[0]*m;c=0;g=[True]*m
    for i in range(1,m):
        if i+z[i-c]<c+z[c]:z[i]=z[i-c]
        else:
            j=max(0,c+z[c]-i)
            while i+j<n and s[j]==s[i+j]:j+=1
            z[i]=j;c=i
    for p in range(1,m):
        for k in range(2,z[p]/p+2):g[k*p-1]=False
    return g
for j in range(1,n/2+1):
    if n%j==0:
        if w[:n-j]==w[j:]:per=j;break
if per==-1:print 1;print 1;sys.exit()
if per==1:print n;print 1;sys.exit()
gl=good(w)
w.reverse()
gr=good(w)
cnt=0
for i in range(n-1):
    if gl[i] and gr[n-2-i]:cnt+=1
print 2
print cnt


Measured memory_bytes: 158708
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;


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

  ll N,M;
  cin >> N>>M;

  ll ans = 0;

  if(N>=2){
    ans += N * (N - 1) / 2;
  }
  else{
  }
  if(M>=2){
    ans += M * (M - 1) / 2;
  }

  cout << ans << endl;


  


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N,K;
    cin>>N>>K;
    vector<bool> kids(N,true);
    for(int i=0;i<K;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int a;
            cin>>a;
            kids[a-1]=false;
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(kids[i])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
// D - Maximum Sum of Minimum

#define fi first
#define se second

using namespace std;

int deg[10005],val[10005];
int a[10005],b[10005],c[10005];
set<pair<int,int>> s;
vector<int> adj[10005];

int main() {
    int N,i,cur,M;

    scanf("%d",&N);

    for (i = 1;i < N;i++) {
        scanf("%d%d",&a[i],&b[i]);

        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);

        deg[a[i]]++;
        deg[b[i]]++;
    }

    for (i = 1;i <= N;i++)
        scanf("%d",&c[i]);

    sort(c + 1,c + N + 1);

    for (i = 1;i <= N;i++)
        s.insert({deg[i],i});

    for (i = 1;i <= N;i++) {
        cur = s.begin()->se;
        val[cur] = c[i];
        s.erase(s.begin());

        for (int nxt : adj[cur]) {
            if (val[nxt] == 0) {
                s.erase({deg[nxt],nxt});
                deg[nxt]--;
                s.insert({deg[nxt],nxt});
            }
        }
    }

    M = 0;
    for (i = 1;i < N;i++)
        M += min(val[a[i]],val[b[i]]);

    printf("%d\n",M);
    for (i = 1;i <= N;i++)
        printf("%d ",val[i]);
    printf("\n");

    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a>0) cout << "Positive" << endl;
    else if(a < 0 && b > 0) cout << "Zero" << endl;
    else if(a<0 && b< 0) {
        int cnt = (-a) - (-b)+1;
        if(cnt%2==1) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define test(t) int t; cin>>t; while(t--)
#define p1(x) { cout << " [" << #x << ": " << x << "]\n"; }
#define p2(x) { cout << " [" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; }
#define pb push_back
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
 
 
void solve()
{
	int n, x, y, streak=0, flag=0;
	vector<vector<int>> d;
	cin>>n;
	F0R(i, n) {
		cin>>x>>y;
		if(x==y) streak++;
		else	streak=0;
		if(streak==3)	break;
	}
	if(streak >= 3) flag=1;
	cout<<((flag==1)?"Yes":"No")<<endl;
}
 
int main() {
	// your code goes here
	// test(t)
		solve();
	return 0;
}
 

Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const int N=100005;
vector<int> vec[N];
int n,m;
int du[N];
int fa[N];
queue<int> q;
int main()
{
	scanf("%d%d",&n,&m);m=n-1+m;
	for (int u=1;u<=m;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		vec[x].push_back(y);
		du[y]++;
	}
	for (int u=1;u<=n;u++)
		if (du[u]==0)
			{fa[u]=0;q.push(u);}
	while(!q.empty())
	{
		int x=q.front();q.pop();
		int siz=vec[x].size();
		for (int u=0;u<siz;u++)
		{
			int y=vec[x][u];
			du[y]--;
			if (du[y]==0)
			{
				q.push(y);
				fa[y]=x;
			}
		}
	}
	for (int u=1;u<=n;u++) printf("%d\n",fa[u]);
	return 0;
}

Measured memory_bytes: 7040
s = gets
f, c = 0, 0
p = []
0.upto(s.size - 1) do |i|
  if s[i] == 'R' && f == 1
    f = 0
    p.push(c)
    c = 0
  elsif s[i] == 'L' && f == 0
    f = 1
    p.push(c)
    c = 0
  end
  p.push(c) if s.size - 1 == i
  c += 1
end
ans = ''
while p.size > 0
  x = p.shift
  y = p.shift
  if (x + y).even?
    (x - 1).times do
      ans.concat('0 ')
    end
    ans.concat(((x + y) / 2).to_s)
    ans.concat(' ')
    ans.concat(((x + y) / 2).to_s)
    ans.concat(' ')
    (y - 1).times do
      ans.concat('0 ')
    end
  elsif (x.even?)
    (x - 1).times do
      ans.concat('0 ')
    end
    ans.concat(((x + y) / 2).to_s)
    ans.concat(' ')
    ans.concat(((x + y) / 2 + 1).to_s)
    ans.concat(' ')
    (y - 1).times do
      ans.concat('0 ')
    end
  else
    (x - 1).times do
      ans.concat('0 ')
    end
    ans.concat(((x + y) / 2 + 1).to_s)
    ans.concat(' ')
    ans.concat(((x + y) / 2).to_s)
    ans.concat(' ')
    (y - 1).times do
      ans.concat('0 ')
    end
  end
end
puts ans

Measured memory_bytes: 3324
/*
    B - 754
    https://atcoder.jp/contests/abc114/tasks/abc114_b
*/
#include <bits/stdc++.h>
using namespace std;

void solve(string s) {
    int diff = 9999;
    const int src = 753;
    for (size_t i = 0; i < s.size() - 2; i++) {
        string subs = "";
        for (size_t j = i; j < i + 3; j++) {
            subs += s[j];
        }
        int dst = stoi(subs);
        diff = min(diff, abs(src - dst));
    }
    cout << diff << endl;
}

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

    string s;
    cin >> s;
    solve(s);
}

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

int main() {
	int64_t a, b, x;
	cin >> a >> b >> x;

	int64_t n = 0;
	if (a) {
		n = b / x - (a - 1) / x;
	}
	else {
		n = b / x;
		n++;
	}

	cout << n << endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
  var line = chunk.toString().split('\n');
  var seconds = Number(line[0]);
  var hour_sec = 60 * 60;
  var minute_sec = 60;

  var h = Math.floor(seconds / hour_sec);
  var m = Math.floor((seconds % hour_sec) / minute_sec);
  var s = seconds % hour_sec % minute_sec;

  console.log(h + ':' + m + ':' + s);
});

Measured memory_bytes: 7648
a,b,c,x,y = [int(i) for i in input().split()]

ans = 0
dic = {x:a,y:b}

if a+b < 2*c:
    ans += a*x + b*y

else:
    n = dic[max(x,y)]
    k = min(x,y)
    
    ans += 2*c*k
    
    if n >= 2*c:
        ans += (max(x,y)-k)*2*c
        
    else:
        ans += (max(x,y)-k)*n

print(ans)

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    s = LI()
    s.sort(reverse = True)
    print(10*s[0]+s[1]+s[2])
    return

#B
def B():
    n,m,X,Y = LI()
    x = LI()
    y = LI()
    x = max(x)
    y = min(y)
    if x >= y:
        print("War")
    else:
        for z in range(x+1,y+1):
            if X < z <= Y:
                print("No War")
                quit()
        print("War")

    return

#C
def C():
    s = S()
    t = S()
    n = len(s)
    d = defaultdict(list)
    for i in range(n):
        d[s[i]].append(t[i])
    d2 = defaultdict(list)
    for i in range(n):
        d2[t[i]].append(s[i])
    for i in d.keys():
        k = d[i]
        k = list(set(d[i]))
        if len(k) > 1:
            print("No")
            quit()
    for i in d2.keys():
        k = d2[i]
        k = list(set(d2[i]))
        if len(k) > 1:
            print("No")
            quit()
    print("Yes")
#D
def D():
    n,m = LI()
    if m == 1:
        print(1)
        quit()
    d = defaultdict(int)
    i = 2
    a = m
    while i**2 <= m:
        if not a%i:
            while not a%i:
                a//=i
                d[i] += 1
        i += 1
    if a != 1:
        d[a] += 1
    fact = [1 for i in range(n+31)]
    for i in range(n+30):
        fact[i+1] = fact[i]*(i+1)%mod
    inv_fact = [None for i in range(n+31)]
    inv_fact[n+30] = pow(fact[n+30],mod-2,mod)
    for i in range(n+30)[::-1]:
        inv_fact[i] = inv_fact[i+1]*(i+1)%mod
    ans = 1
    for i in d.values():
        ans *= fact[i+n-1]*inv_fact[i]*inv_fact[n-1]%mod
        ans %= mod
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 39920
// 何個の数を用いるか、そして取り得る範囲はどこからどこまでか、この二つを考える

let n, k = stdin.ReadLine().Split() |> fun [| x1; x2 |] -> int64 x1, int64 x2

/// k=index時の取り得るmin,max
let minMaxArray =
    let array :(int64*int64)[]= Array.zeroCreate (int n + 2)
    let mutable mintmp = 0L
    let mutable maxtmp = 0L
    
    for x in [0L..n] do
        mintmp <- mintmp + int64 x
        array.[int x + 1] <- (mintmp, 0L)
    
    for x in [n .. -1L .. 0L] do
        maxtmp <- maxtmp + x
        array.[int n + 1 - int x] <- ((fst array.[int n + 1 - int x] ), maxtmp)
    
    array

{int k..int n + 1}
|> Seq.map (fun i -> snd minMaxArray.[i] - fst minMaxArray.[i] + 1L)
|> Seq.fold (fun acc x -> (acc + x) % 1_000_000_007L ) 0L
|> stdout.WriteLine


Measured memory_bytes: 56204
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    string S;
    cin >> S;
    int minDiff = 10000;
    for (int i = 0; i < S.size() - 2; i++) {
        int subS = (S.at(i) - '0') * 100 + (S.at(i + 1) - '0') * 10 + (S.at(i + 2) - '0') * 1;
        int diff = abs(753 - subS);
        minDiff = min(minDiff, diff);
    }

    cout << minDiff << endl;
    
    return 0;
}


Measured memory_bytes: 3512
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		FS r = new FS();
		int n = r.nextInt();
		int t = r.nextInt();
		int[] counter = new int[t+1];
		for(int i=0; i<n; i++) {
			counter[r.nextInt()]++;
			counter[r.nextInt()]--;
		}
		int max = 0;
		int tmp = 0;
		for(int i=0; i<=t; i++) {
			tmp += counter[i];
			max = Math.max(max, tmp);
		}
		System.out.println(max);
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 26968
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		for(int i = 0; i < n; i++){
			System.out.println(sc.nextLine().replaceAll("Hoshino", "Hoshina"));
		}
	}
}

Measured memory_bytes: 12000
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

// vector set 等
#include <map>
#include <set>
#include <vector>

//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto& i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000  // 10^12:∞
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange
//略記
#define PB push_back  //挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素

signed main() {
  //入力の高速化用のコード
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w, k, ans;
  ans = 0;
  cin >> h >> w >> k;

  vector<string> strs(h);
  REP(i, h) { cin >> strs[i]; }

  REP(R, (1 << h) - 1) {
    REP(C, (1 << w) - 1) {
      int brack = 0;
      REP(i, h) {
        REP(j, w) {
          if (((R >> i) & 1) == 0 && ((C >> j) & 1) == 0 && strs[i][j] == '#') {
            brack++;
          }
        }
      }
      if (brack == k) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
 
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
const int INF = 100000000;
const double EPS = 0.0000001;
typedef pair<int,int> P;

int n,m;

struct edge
{
	//どこから来た,コスト,速度制限
	int to,cost,ub;
	edge(int to,int cost,int ub) {
		this->to = to;
		this->cost = cost;
		this->ub = ub;
	}
};

vector<edge> G[103];
int s,g;
double dist[103][103][33];

typedef pair<double,int> PD;
typedef pair<PD,P> PP;

double dijkstra() {
	rep(i,103) rep(j,103) rep(k,33) dist[i][j][k]=INF;
	dist[s][0][0]=0;

	//最短距離 頂点 前の頂点 今の速さ
	priority_queue<PP,vector<PP>,greater<PP> > que;
	que.push(PP(PD(0,s),P(0,0)));

	while (!que.empty())
	{
		PP pp = que.top(); que.pop();
		int v = pp.first.second;

		int prev = pp.second.first;
		//今の速度
		int u = pp.second.second;

		//printf("[debug] %f,%d,%d,%d\n",pp.first.first,v,prev,u);

		if(dist[v][prev][u] < pp.first.first) continue;

		rep(i,G[v].size()) {
			edge e = G[v][i];
			if(e.to == prev) continue;
			for(int j=-1;j<=1;j++) {
				if(j+u<=0 || u+j > e.ub) continue;


				if(dist[e.to][v][u+j] > dist[v][prev][u] + (1.0*e.cost/(u+j))) {
					dist[e.to][v][u+j] = dist[v][prev][u] + (1.0*e.cost/(u+j));

					que.push(PP(PD(dist[e.to][v][u+j],e.to),P(v,u+j)));
				}
			}
		}

	}
	double ans=INF;
	rep(i,103) ans=min(ans,dist[g][i][1]);

	return ans;
	
}

void solve() {
	rep(i,103) G[i].clear();
	cin>>s>>g;
	rep(i,m) {
		int x,y,d,c;
		cin>>x>>y>>d>>c;
		G[x].push_back(edge(y,d,c));
		G[y].push_back(edge(x,d,c));
	}

	double ans;
	ans = dijkstra();
	if(ans==INF) {
		cout<<"unreachable"<<endl;
	}
	else
	{
		cout<<ans<<endl;
	}


}

int main() {
	while (cin>>n>>m)
	{
		if(n+m==0) return 0;
		solve();

	}



}

Measured memory_bytes: 4500
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int a; double b;
  cin>>a>>b;
  cout<<ceil((b-1)/(a-1));
}

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

int main(){
  string s;	cin >> s;
  long long sum=0;
  for(char c:s){
    sum+=(long long)(c-'0');
  }
  if(sum%9==0)	cout << "Yes";
  else cout << "No";
}


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

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

int main() {
  string s;
  cin >> s;
  int a=(int)s[0]-'0',b=(int)s[1]-'0',c=(int)s[2]-'0',d=(int)s[3]-'0';
  //cout << a+b+c+d << endl;
  //scanf("%d%d%d%d", &a, &b, &c, &d);
  if (a + b + c + d == 7) {
    printf("%d+%d+%d+%d=7", a, b, c, d);
    return 0;
  }
  if (a - b + c + d == 7) {
    printf("%d-%d+%d+%d=7", a, b, c, d);
    return 0;
  }
  if (a + b - c + d == 7) {
    printf("%d+%d-%d+%d=7", a, b, c, d);
    return 0;
  }
  if (a - b - c + d == 7) {
    printf("%d-%d-%d+%d=7", a, b, c, d);
    return 0;
  }
  if (a + b + c - d == 7) {
    printf("%d+%d+%d-%d=7", a, b, c, d);
    return 0;
  }
  if (a - b + c - d == 7) {
    printf("%d-%d+%d-%d=7", a, b, c, d);
    return 0;
  }
  if (a + b - c - d == 7) {
    printf("%d+%d-%d-%d=7", a, b, c, d);
    return 0;
  }
  if (a - b - c - d == 7) {
    printf("%d-%d-%d-%d=7", a, b, c, d);
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	}
}


Measured memory_bytes: 105260
#include<stdio.h>

int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	int a[n][m],b[m];
	int c[n];

	for(int i = 0;i < n;i++) {
		for(int j = 0;j < m;j++) {
			scanf("%d",&a[i][j]);
		}
	}
	for(int i = 0;i < m;i++) {
		scanf("%d",b + i);
	}
	for(int i = 0;i < n;i++) {
		c[i] = 0;
		for(int j = 0;j < m;j++) {
			c[i] += a[i][j] * b[j];
		}
	}

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


Measured memory_bytes: 2712
#include<bits/stdc++.h>
using namespace std;
int k;
int vis[100010],dis[100010];
int first[100010],cnt;
struct node{
	int to,next,val;
}edge[400010];
void add(int u,int v,int val){
	edge[++cnt].to = v;
	edge[cnt].val = val;
	edge[cnt].next = first[u];
	first[u] = cnt;
}
struct N{
	int x,dis;
	bool operator < (const N &b)const{
		return dis > b.dis;
	}
};
priority_queue<N>q;
void dij(){
	memset(dis,0x3f,sizeof dis);
	dis[1] = 0;
	q.push((N){1,1});
	while(q.size()){
		N cur = q.top();q.pop();
		int x = cur.x;
		int ds = cur.dis;
		if(vis[x])continue;
		vis[x] = 1;
		for(int i = first[x];i;i = edge[i].next){
			int to = edge[i].to;
			int val = edge[i].val;
			if(dis[to] > ds + val){
				dis[to] = ds + val;
				q.push((N){to,dis[to]});
			}
		}
	}
}
 
int main(){
	cin >> k;
	for(int i = 0; i < k; i++){
		add(i%k,(i+1)%k,1);
		add(i%k,(i*10)%k,0);
	}
	dij();
	cout << dis[0];
} 

Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int W = sc.nextInt();
    int H = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
    sc.close();

    if (0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 26268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1e9 + 7;

ll dp[111][5][5][5];
int n;

bool ok3(int a, int b, int c){
	if(a == 0 && b == 2 && c == 1)
		return false;
	if(a == 0 && b == 1 && c == 2)
		return false;
	if(a == 2 && b == 0 && c == 1)
		return false;
	return true;
}

bool ok4(int a, int b, int c, int d){
	if(a == 0 && b == 2 && d == 1)
		return false;
	if(a == 0 && c == 2 && d == 1)
		return false;
	return true;
}

ll solve(int pos, int l1, int l2, int l3){
	
	if(pos == n)
		return 1ll;
	
	if(dp[pos][l1][l2][l3] != -1)
		return dp[pos][l1][l2][l3];
	
	ll ans = 0;
	
	for(int k = 0; k < 4; k++){
		if(!ok3(l2, l3, k))
			continue;
		if(!ok4(l1, l2, l3, k))
			continue;
		ans = (ans + solve(pos + 1, l2, l3, k)) % mod;
	}
	
	return dp[pos][l1][l2][l3] = ans;
}

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cin >> n;
	
	if(n == 1){
		cout << 4 << endl;
		return 0;
	}
	
	if(n == 2){
		cout << 16 << endl;
		return 0;
	}
	
	if(n == 3){
		cout << 61 << endl;
		return 0;
	}
	
	ll ans = 0;
	
	memset(dp, -1, sizeof(dp));
	
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
			for(int k = 0; k < 4; k++)
				if(ok3(i, j, k))
					ans = (ans + solve(3, i, j, k)) % mod;
	
	cout << ans << endl;

	return 0;
}


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    vector<i64> v;
    for(i64 i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a-(i+1));
    }
    sort(v.begin(), v.end());
    i64 ans = 0, mid = v[v.size()/2];
    for(auto e: v){
        ans += abs(e-mid);
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  char buf[1010]; scanf("%s", buf);
  int w; scanf("%d", &w);
  string str(buf);
  for (int i = 0; i < str.size(); i += w) {
    putchar(str[i]);
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
#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, a, n) for(int i=(a);i < (n);i++)
#define all(e) (e).begin(), (e).end()

#ifdef LOCAL
#define show(x) cerr<< __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

using namespace std;

using ll=long long;
template<class T> using V=vector<T>;

template<class T, class U>
void chmin(T &t, const U u) {
    if (t > u) {
        t = u;
    }
}

template<class T, class U>
void chmax(T &t, const U u) {
    if (t < u) {
        t = u;
    }
}

const int INF = 1e+8+7;
#define print(X) cout << (X) << endl;

int n,m,l;
string s,t;


int main() {

    while(cin >> n >> m, !(n+m == 0)){
        double ans = INF;
        rep(i,0,n+1){
            // print(sqrt((i*i)+(n-i)*(n-i)));
            ans = min(ans, abs(sqrt((i*i)+(n-i)*(n-i))-m));
        }
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 3268
s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[j]=='?' or k[j]==t[j]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNRESTORABLE')
        


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        
        int[] H = new int[N];
        for(int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }
        
        Arrays.sort(H);
        
        long sum = 0;
        for(int i = 0; i < N - K; i++) {
            sum += H[i];
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 64576
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll R, G, B, N;
    cin >> R >> G >> B >> N;

    ll ans = 0;
    for (ll r = 0; r <= N; r++) {
        for (ll g = 0; g <= N; g++) {
            ll rem = N - r * R - g * G;
            if (rem < 0) {
                g = N;
            } else if (rem % B == 0) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    
    for(int i = 0;i < 10000;i++){
        cin >> H >> W;
        if(H == 0 && W == 0){break;}
        for(int g =0;g < W;g++){
            cout << "#";
        }
        cout << endl;
       for(int h =0;h < H-2 ;h++){
           cout << "#";
           for (int w = 0;w < W-2 ;w++)
           {
               cout << ".";
           }
            cout << "#";
           cout << endl;
       }
       for(int g =0;g < W;g++){
            cout << "#";
        }
        cout << endl;
        cout << endl;
    }
}


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

const int MAX=205;
const long long int INF=(1LL<<32);

long long int D[MAX][MAX];
int N;

void floyd(){
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            if(D[i][k]==INF) continue;
            for(int j=0;j<N;j++){
                if(D[k][j]==INF) continue;
                D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
            }
        }
    }
}

int main(){
    
    int M,R;cin>>N>>M>>R;
    vector<int> S(R);
    for(int i=0;i<R;i++){
        cin>>S[i];
        S[i]--;
    }
    sort(S.begin(),S.end());
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j) D[i][j]=0;
            else D[i][j]=INF;
        }
    }
    for(int i=0;i<M;i++){
        int s,t,d;
        cin>>s>>t>>d;
        s--;t--;
        D[s][t]=d;
        D[t][s]=d;
    }
    
    floyd();
    
    int ans=100000000;
    
    do{
        int sum=0;
        for(int i=1;i<R;i++){
            sum+=(D[S[i-1]][S[i]]);
        }
        ans=min(ans,sum);
    }while(next_permutation(S.begin(),S.end()));
    
    cout<<ans<<endl;
}



Measured memory_bytes: 512
program align
  implicit none
  integer              :: n, i
  integer, allocatable :: a(:)
  integer(8)           :: m1, m2, m3, m4
  read(*,*) n
  allocate(a(n))
  do i = 1, n
     read(*,*) a(i)
  end do
  if (n .eq. 2) then
     write(*,'(i0)') abs(a(1)-a(2))
     stop
  end if
  call merge_sort(n,a)
  m1 = 0
  m2 = 0
  m3 = 0
  m4 = 0
  if (mod(n,2) .eq. 1) then
     do i = 1, n/2
        m1 = m1 + abs(a(i)-a(n+1-i))
        m2 = m2 + abs(a(n+1-i)-a(i))
     end do
     do i = 1, n/2-1
        m1 = m1 + abs(a(n+1-i)-a(i+1))
        m2 = m2 + abs(a(i)-a(n-i))
     end do
     m1 = m1 + abs(a(1)-a(n/2+1))
     m2 = m2 + abs(a(n)-a(n/2+1))
  else
     do i = 1, n/2-1
        m1 = m1 + abs(a(i)-a(n+1-i))
        m2 = m2 + abs(a(n+1-i)-a(i))
     end do
     if (n .gt. 4) then
        do i = 1, n/2-2
           m1 = m1 + abs(a(n+1-i)-a(i+1))
           m2 = m2 + abs(a(i)-a(n-i))
        end do
     end if
     m3 = m1 + abs(a(n/2)-a(1)) + abs(a(n/2+2)-a(n/2+1))
     m4 = m2 + abs(a(n/2)-a(n)) + abs(a(n/2-1)-a(n/2+1))
     m1 = m1 + abs(a(n/2+1)-a(1)) + abs(a(n/2+2)-a(n/2))
     m2 = m2 + abs(a(n/2+1)-a(n)) + abs(a(n/2-1)-a(n/2))
     m1 = max(m1,m3)
     m2 = max(m2,m4)
  end if
  write(*,'(i0)') max(m1,m2)
  deallocate(a)
  stop
contains
  subroutine merge_sort(n,c)
    implicit none
    integer, intent(in)    :: n
    integer, intent(inout) :: c(n)
    integer                :: number, length, i, ubound
    number = n
    length = 1
    do while (number .gt. 1)
       do i = 1, number/2
          ubound = min(2*i*length,n)
          call merge(c(2*(i-1)*length+1:(2*i-1)*length),c((2*i-1)*length+1:ubound))
       end do
       length = 2*length
       number = (number+1)/2
    end do
    return
  end subroutine merge_sort

  subroutine merge(c1,c2)
    implicit none
    integer, intent(inout) :: c1(:), c2(:)
    integer                :: c(size(c1)+size(c2))
    integer                :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1)
    n2 = size(c2)
    do while (i1 .le. n1 .and. i2 .le. n2)
       if (c1(i1) .lt. c2(i2)) then
          c(i1+i2-1) = c1(i1)
          i1 = i1+1
       else
          c(i1+i2-1) = c2(i2)
          i2 = i2+1
       end if
    end do
    if (i1 .le. n1) then
       c(i1+i2-1:n1+n2) = c1(i1:n1)
    else if (i2 .le. n2) then
       c(i1+i2-1:n1+n2) = c2(i2:n2)
    end if
    c1 = c(1:n1)
    c2 = c(n1+1:n1+n2)
    return
  end subroutine merge

  subroutine swap(a,b)
    implicit none
    integer, intent(inout) :: a, b
    integer                :: c
    c = a
    a = b
    b = c
    return
  end subroutine swap
end program align

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

int main() {
    ll n;
    while (cin >> n) {
        vector<int> tail(100);
        iota(all(tail), 1);
        vector<int> head;
        int i = 1;
        while ((1LL << i) - 1 <= n) {
            // dump(i);
            head.push_back(i);
            ++i;
        }
        --i;
        n -= (1LL << i) - 1;
        // dump(n);
        int k = 50;
        for (int i = head.size() - 1; i >= 0; --i) {
            if (n >> i & 1) {
                head.insert(head.begin() + i, k);
                ++k;
            }
        }
        cout << head.size() + tail.size() << endl;
        for (auto &c : head) cout << c << ' ';
        for (auto &c : tail) cout << c << ' ';
        cout << endl;
    }
}


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

using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)

typedef long long ll;
const ll MOD = 1e9 + 7;

bool fless(pair<int, ll> a, pair<int, ll> b) {
    return a.first < b.first;
}

int main() {
    int N, M; cin >> N >> M;
    pair<ll, int> d[N]; rep(i, N) cin >> d[i].first >> d[i].second;

    sort(d, d + N);
    int pos = 0, num = 0; ll sum = 0;
    while (num < M) {
        if (num + d[pos].second <= M) {
            num += d[pos].second;
            sum += d[pos].first*d[pos].second;
            pos++;
        } else {
            int buy = (M - num + d[pos].first - 1)/d[pos].first;
            num += buy;
            sum += d[pos].first*buy;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int a,b,c;cin >> a >>b >> c;
	auto valid = [](int x,int y,int z){
		return x < y && y < z;
	};
	if(valid(a,c,b)|| valid(b,c,a))cout << "Yes" <<endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int n, answer = 0;
    cin >> n;
    for (int i = 1; i <= n; i += 2)
    {
        int count = 0;
        for (int j = 1; j <= i; j++)
        {
            if (i % j == 0)
            {
                count++;
            }
        }
        if(count==8){
            answer++;
        }
    }
    cout<<answer;
    return 0;
}


Measured memory_bytes: 256