akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
const ll INF = 1LL << 60;

int main() {

    ll N;
    cin >> N;
    ll D[N][2];
    rep(i,N){
        cin >> D[i][0] >> D[i][1];
    }

    for(int i=0;i<N;i++){
        if(D[i][0]==D[i][1]){
            if(D[i+1][0]==D[i+1][1]){
                if(D[i+2][0]==D[i+2][1]){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;

}

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

int main() {
	int n;
	int count = 0;
	int old_count = -1;
	cin >> n;
	vector<int>a;
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		a.push_back(p);
	}
	while (count != old_count) {
		old_count = count;
		if (n == 1)break;
		for (int i = n - 1; i > 0; i--) {
			if (a[i] < a[i - 1]) {
				int k = a[i];
				a[i] = a[i - 1];
				a[i - 1] =k;
				count++;
			}
		}

	}
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1)cout << " ";
	}cout << endl;
	cout << count << endl;
}



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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
   int N;
   cin >> N;
   vector<int> H(N);
   rep(i, N){
      cin >> H[i];
   }
   rep(i, N - 1){
      if(H[i] == H[i + 1]){

      }else if(H[i] < H[i + 1]){
         H[i + 1]--;
      }else{
         cout << "No" << endl;
         return 0;
      }
   }
   cout << "Yes" << endl;
return 0;}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cfenv>
#include <cmath>
#include <string>
#include <algorithm>
#include <cassert>
#include <functional>
#include <deque>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  rep(i,(s.size()-1)/2){
    if(s[i] != s[s.size()-1-i]||s[i] != s[(s.size()-1)/2-1-i]){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

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

    int memo[N];
    for (int i = 0; i <= N; i++) memo[i] = 0;

    for (int i = 0; i < N; i++) {
      if (S[i] == 'W') {
        memo[i+1] = memo[i] + 1;
      } else {
        memo[i+1] = memo[i];
      }
    }

    int ans = N;
    for (int i = 0; i < N; i++) ans = min(ans, memo[i] + (N - (i+1)) - (memo[N] - memo[i+1]));
    cout << ans << endl;
}


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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    os << pai.first << ' ' << pai.second;
	return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

int N, M;
vector<int> ad[100001];
int ind[100001];
int par[100001];
int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

	cin >> N >> M;
	rep(i, N+M-1) {
		int a, b; cin >> a >> b;
		ad[a].pb(b);
		ind[b]++;
	}
	
	int root = -1;
	repp(i, N) if (ind[i] == 0) {
		root = i;
		par[i] = 0;
		break;
	}

	queue<int> q;
	q.push(root);
	int r = 10;
	while(sz(q) > 0) {
		int t = q.front(); q.pop();

		for (int c : ad[t]) if (--ind[c] == 0) {
			q.push(c);
			par[c] = t;
		}
	}

	repp(i, N) {
		cout << par[i] << '\n';
	}
}

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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = t[0];
            var H = t[1];

            long maxA = -1;
            List<long> bList = new List<long>();
            for (int i = 0; i < N; i++)
            {
                t = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
                var a = t[0];
                var b = t[1];

                if (maxA < a)
                    maxA = a;

                bList.Add(b);
            }

            bList.Sort();

            var bStrong = bList.Where(x => x > maxA).ToList();
            long bStrongNum = bStrong.Count<long>();
            var bStrongH = bStrong.Sum();

            long ans;
            if (H - bStrongH > 0)
            {
                ans = bStrongNum + ((H - bStrongH) / maxA);
                if ((H - bStrongH) % maxA >0)
                    ans++;
            }
            else
            {
                ans = 0;
                long sum = 0;
                for (int i = bList.Count -1; i >= 0; i--)
                {
                    if (sum < H)
                    {
                        sum = sum + bList[i];
                        ans++;
                    }
                    else
                    {
                        break;
                    }                        
                }
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 21052
# -*- coding: utf-8 -*-
import bisect
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


ans = [-1] * (2*10**5+1)


@mt
def slv(N, A, UV):
    A.insert(0, -1)
    g = [list() for _ in range(0, N+1)]
    for u, v in UV:
        g[u].append(v)
        g[v].append(u)

    def dfs(u, p, dp):
        global ans

        for v in g[u]:
            if v == p:
                continue

            i = bisect.bisect_left(dp, A[v])
            b = dp[i]
            dp[i] = A[v]
            ans[v] = bisect.bisect_left(dp, INF)
            dfs(v, u, dp)
            dp[i] = b
    dp = [INF] * (N+2)
    dp[0] = A[1]
    # dp[1] = A[1]
    dfs(1, 0, dp)

    ans[1] = 1
    for i in range(1, N+1):
        print(ans[i])


def main():
    N = read_int()
    A = read_int_n()
    UV = [read_int_n() for _ in range(N-1)]
    slv(N, A, UV)


if __name__ == '__main__':
    main()


Measured memory_bytes: 383228
/*input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 2020
#define INF 0x3f3f3f3f

int n , m , k , x[MAX];

int32_t main(){
	IOS;
	cin >> n >> m >> k;
	REP(i , 1 , n + 1) cin >> x[i];
	int ans = INF;
	REP(i , 1 , n + 1){
		// DBGG("now i = " , i);
		vector<int> sol , all;
		sol.pb(0);
		REP(j , 1 , n + 1) if(x[j] < x[i]) sol.pb(j);
		sol.pb(n + 1);
		// for(auto to : sol) cout << to << " "; cout << endl;

		REP(j , 1 , sol.size()){
			if(sol[j] - sol[j - 1] - 1 < m) continue;
			vector<int> tmp;
			REP(ii , sol[j - 1] + 1 , sol[j]) tmp.pb(x[ii]);
			// for(auto to : tmp) cout << to << " " ; cout << endl;

			int have = sol[j] - sol[j - 1] - m;
			nth_element(tmp.begin() , tmp.begin() + have - 1 , tmp.end());
			REP(ii , 0 , have) all.pb(tmp[ii]);

			// for(auto to : all) cout << to << " " ; cout << endl;
		}
		if(all.size() < k) continue;
		nth_element(all.begin() , all.begin() + k - 1 , all.end());
		ans = min(ans , all[k - 1] - x[i]);
		// return 0;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
$num=trim(fgets(STDIN));
$heights=trim(fgets(STDIN));
$count=0;
$heights=explode(" ",$heights);
$num=explode(" ",$num);
for($i=0;$i<$num[0];$i++){
	if($heights[$i]>=$num[1]){
    	$count+=1;
    }
}

echo $count;

Measured memory_bytes: 21372
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
constexpr const int INF=1<<30,MOD=1000000007;constexpr const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
#ifndef LOCAL
struct osd{template<class T>osd&operator<(const T&t){return*this;}template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;template<class...T>void _print(osd&a,T&&...t){}
#define cerr cer_
#endif
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}template<class T>istream&operator>(istream&i,T&t){return i>>t;}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<t<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}template<class...T>void dprint(T&&...t){_print(cerr,t...);}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<p.F<' '<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>p.F>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>queue<T>&operator<<(queue<T>&q,const T&t){q.push(t);return q;}template<class T>queue<T>&operator<<(T&t,queue<T>&q){t=q.front();q.pop();return q;}
template<class T>deque<T>&operator>>(const T&t,deque<T>&q){q.push_front(t);return q;}template<class T>deque<T>&operator<<(T&t,deque<T>&q){t=q.front();q.pop_front();return q;}
template<class T>deque<T>&operator<<(deque<T>&q,const T&t){q.push_back(t);return q;}template<class T>deque<T>&operator>>(deque<T>&q,T&t){t=q.back(t);q.pop_back();return q;}
template<class T>stack<T>&operator<<(stack<T>&s,const T&t){s.push(t);return s;}template<class T>stack<T>&operator>>(stack<T>&s,T&t){t=s.top();s.pop();return s;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    int mi=INF;
    REP(i,n+1){ // 1,6
        int a=i;
        int b=n-i;
        int cnt=0;
        while(a)cnt+=a%6,a/=6;
        while(b)cnt+=b%9,b/=9;
        chmin(mi,cnt);
    }
    cout<mi<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
	static int mod = 1000000007;
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int k = Integer.parseInt(st.nextToken());
      st = new StringTokenizer(br.readLine());
      String s = st.nextToken();
      long ans = 0;
      long[] fact = new long[2000001];
      fact[0] = 1;
      for(int i = 1; i < 2000001; i++)
    	  fact[i] = (fact[i-1]*i)%mod;
      long[] invf = new long[1000001];
      invf[1000000] = pow(fact[1000000],mod-2);
      for(int i = 1000000; i > 0; i--)
    	  invf[i-1] = (invf[i]*i)%mod;
      long[] pow25 = new long[1000001];
      long[] pow26 = new long[1000001];
      pow25[0] = 1;
      pow26[0] = 1;
      for(int i = 1; i < 1000001; i++) {
    	  pow25[i] = (pow25[i-1]*25)%mod;
    	  pow26[i] = (pow26[i-1]*26)%mod;
      }
      for(int i = 0; i <= k; i++) {
    	  ans = (ans + multiply(pow25[i],pow26[k-i])*multiply(fact[s.length()+i-1],multiply(invf[s.length()-1],invf[i])))%mod;
      }
      out.println(ans);
      out.close();
   }
   static long multiply(long a, long b) {
	   return (a*b)%mod;
   }
   static long pow(long l, int p) {
	   if(p == 0)
		   return 1;
	   if(p == 1 || l == 1)
		   return l;
	   long temp = pow(l, p/2);
	   long temp1 = (temp*temp)%mod;
	   if(p%2 == 1)
		   temp1 = (temp1*l)%mod;
	   return temp1;
   }
}

Measured memory_bytes: 84708
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{
int n,W; 
cin>>n>>W;
vector<int>v(n),w(n);
vector<long long int> first(W+1,0),second(W+1,0);
for(int i=0; i<n; i++) cin>>w[i]>>v[i];
for(int i=0; i<n; i++){ for(int k=0; k<=W; k++) second[k]=first[k]; for(int k=0; k<=W; k++) if (k<w[i]) first[k]=second[k]; else first[k]=max(second[k-w[i]]+v[i],second[k]); 
                      }//DEBUG: for(int i=0; i<=n; i++){ for(int k=0; k<=W; k++) cout<<dp[i][k]<<" "; cout<<endl; }
cout<<first[W];
return 0; 
} 


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int [] a=new int[5];
		int c=0;
		for(int i=0;i<5;i++)
		{
			a[i]=scan.nextInt();
			if(a[i]==0) c=i;
		}
		System.out.println(c+1);

	}

}


Measured memory_bytes: 35828
S = raw_input()
n = len(S)
total = 0
for i in xrange(1 << (n - 1)):
    value = 0
    for j in xrange(n):
        value = value * 10 + int(S[j])
        if (1 << j) & i:
            total += value
            value = 0
    total += value
print total


Measured memory_bytes: 2568
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
	int ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)
			ans = ans * a % mod;
	return ans;
}


vector<int> in,G[500000],K[500000];
map<pii,int> Mp;
int ans[300000];
int vis[300000],on[300000];
int n,m,k;

void dfs(int x){
	if(vis[x])return ;
	vis[x]=1;
	on[x] = 1; in.pb(x);
	for(auto i:G[x]){
		dfs(i);
	}
}
signed main()
{
	io;
	cin>>n>>m>>k;
	rep(i,1,m){
		int l,r;
		cin>>l>>r;Mp[mp(l,r)]=1;Mp[mp(r,l)]=1;
		G[l].pb(r);G[r].pb(l);
	}
	rep(i,1,k){
		int l,r;cin>>l>>r;
		if(!Mp.count(mp(l,r))){
			K[l].pb(r);
			K[r].pb(l);
		}
	}
	rep(i,1,n){
		if(!vis[i]){
			dfs(i);
			int len=in.size();
			for(auto j:in)ans[j] += len-1;
			for(auto j:in){
				for(auto v:G[j]){
					ans[v]--;
				}
				for(auto v:K[j])if(on[v]){
					ans[v]--;
				}
			}
			for(auto j:in)on[j]=0;
			in.clear();

		}
	}
	rep(i,1,n)cout<<ans[i]<<" ";
	cout<<endl;
	getchar(); //
	getchar();
}

Measured memory_bytes: 51316
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv){
    char a[11], b[11], c[11];
    scanf("%s %s %s", a, b, c);
    if (a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0]){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

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

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

inline void writes(int x)
{
	if(x>=10)writes(x/10);
	putchar('0'+x%10);
}

inline void write(int x,char ch='\n')
{
	if(x<0)putchar('-'),writes(-x);
	else writes(x);putchar(ch);
}

const int N=1e5+9;

int n;
int t[N],x[N],y[N];

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	n=read();
	for(int i=1;i<=n;i++)
	{
		t[i]=read();x[i]=read();y[i]=read();
	}

	t[0]=0;x[0]=0;y[0]=0;
	for(int i=1;i<=n;i++)
	{
		if(((abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2!=(t[i]-t[i-1])%2))
			return puts("No"),0;
		if((abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))>(t[i]-t[i-1]))
			return puts("No"),0;
	}

	puts("Yes");
	return 0;
}


Measured memory_bytes: 1408
N = int(input())
S = input()

ans = set()
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = str(i) + str(j) + str(k)

            f = -1
            s = -1
            t = -1
            for x in range(N):
                X = S[x]
                if f == -1 and X == str(i):
                    f = x
                if s == -1 and f != -1 and f < x and X == str(j):
                    s = x
                if t == -1 and s != -1 and s < x and X == str(k):
                    t = x
            if f < s < t:
                ans.add(tmp)
print(len(ans))



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

int main(){
	int n;
	while(cin >> n, n){
		int ans = 1;
	for(int i=2;i*i <= n;i++){
		if(n%i == 0){
			ans += i;
			if(i != n/i)ans+=n/i;
		}
	}
	if(ans < n || n == 1){
	cout<<"deficient number"<<endl;
}else if(ans==n){
	cout<<"perfect number"<<endl;
	}else{
		cout<<"abundant number"<< endl;
	}
}
}

Measured memory_bytes: 1156
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
#define  aryout(ary) rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n");
#define  arysort(v) sort(v.begin(), v.end())
#define  aryreverse(v) reverse(v.begin(),v.end())
#define  arysum(v) accumulate(v.begin(), v.end(), 0)
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> cnt(n, 0);
  vector<stack<pair<int, int>>> node(n);

  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a -= 1; b -= 1;
    cnt[a] += 1; cnt[b] += 1;

    pair<int, int> tmp;
    tmp.first = i;
    tmp.second = b;
    node[a].push(tmp);
    tmp.second = a;
    node[b].push(tmp);
  }

  int ans = 0;
  rep(i, n-1) ans = max(ans, cnt[i]);
  cout << ans << endl;

  vector<int> par(n, -1);
  vector<int> color(n-1, -1);
  queue<int> q;
  q.push(0);

  while (!q.empty()) {

    int next = q.front();
    q.pop();
    int cnt = 0;

    while (!node[next].empty()) {
      pair<int, int> tmp = node[next].top();

      if (color[tmp.first] == -1) {
        if (cnt == par[next]) cnt += 1;
        color[tmp.first] = cnt;
        par[tmp.second] = cnt;
        q.push(tmp.second);
        cnt += 1;
      }
      node[next].pop();
    }
  }
  rep(i, n-1) cout << color[i] + 1 << endl;
  
  return 0;
}


Measured memory_bytes: 68864
#include<stdio.h>
void sp(int n,int m) {
	int i,j;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			putchar('#');
		}putchar('\n');
	}
}


int main() {
	int H[300], W[300];
	int i;

	for(i = 0;; i++) {
		scanf("%d %d", &H[i], &W[i]);
		if (H[i] == 0 && W[i]== 0)
			break;
	}

	for (int k = 0; k < i; k++) {
		sp( H[k], W[k]);
		putchar('\n');
	 }						 

	return 0;
}

Measured memory_bytes: 1816
while True:
    n, x = map(int, input().split())
    if n==x==0:
        break

    else:
        list1 = list()
        for i in range(1, n - 1):
            for j in range(i + 1, n):
                for k in range(j + 1, n + 1):
                    list1.append(i + j + k)
    print(list1.count(x))








Measured memory_bytes: 6968
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	static long MOD = 1000000007;
	
	static long inv(long a) {
		return eleva(a, (int)MOD - 2);
	}
	
	static long eleva(long b, int e) {
		if (e == 0) return 1;
		long ret = eleva(b, e / 2);
		ret *= ret;
		ret %= MOD;
		if (e % 2 == 1) {
			ret *= b;
			ret %= MOD;
		}
		return ret;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		long[] fact = new long[N], invFact = new long[N];
		fact[0] = invFact[0] = fact[1] = invFact[1] = 1;
		for (int i = 2; i < N; i++) {
			fact[i] = (fact[i-1] * i) % MOD;
		}
		invFact[N-1] = inv(fact[N-1]);
		for (int i = N - 2; i >= 2; i--) {
			invFact[i] = (invFact[i+1] * (i+1)) % MOD;
		}
		
		long ans = fact[N-1] * (N-1) % MOD;
		for (int k = (N + 1)/2; k < N - 1; k++) {
			long tmp = (fact[k-1] * fact[k]) % MOD;
			tmp = (tmp * invFact[2*k - N]) % MOD;
			ans -= tmp;
		}
		ans %= MOD; ans += MOD; ans %= MOD;
		System.out.println(ans);
	}
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int n;
    cin >> n;
    int num_4 = 0;
    int num_2 = 0;
    int odd = 0;
    rep(i, n)
    {
        ll a;
        cin >> a;
        if (a > 4)
        {
            if (a % 4 == 0)
            {
                num_4++;
            }
            else if (a % 2 == 0)
            {
                num_2++;
            }
            else
                odd++;
        }
        else if (a == 2)
        {
            num_2++;
        }
        else if (a == 4)
        {
            num_4++;
        }
        else
            odd++;
    }
    if (odd == 0 || num_4 >= odd || (num_4 + 1 == odd && num_2 == 0))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        boolean answer = A<=C && C<=B;
        System.out.println(answer ? "Yes" : "No");
    }
}


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

using namespace std;

typedef long long ll;

const int MAXN = 2031;

struct Point
{
    int x, y;
};

double dist(Point a, Point b)
{
    return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)* (a.y - b.y));
}

const int MOD = 1e9 + 7;

int gcdExtended(int a, int b, int *x, int *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    int x1, y1;
    int gcd = gcdExtended(b%a, a, &x1, &y1);


    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}
ll inverse(ll a)
{
    int x, y;
    int g = gcdExtended(a, MOD, &x, &y);
    if (g != 1) {
        assert(false);
    }
    else {
        x = (x % MOD + MOD ) % MOD ;
        return x;
    }
}
ll c(int n, int k)
{
    vector<ll> factorial(n + 1);
    factorial[0] = 1;
    for (int i = 1; i <= n; i++) {
        factorial[i] = factorial[i - 1] * i % MOD;
    }

    return factorial[n] * inverse(factorial[k]) % MOD * inverse(factorial[n - k]) % MOD;
}

ll solve(int x, int y)
{
    if ((2*x - y) % 3 != 0) return 0;
    if (2 * x - y < 0) return 0;
    int a = (2 * x - y) / 3;
    int b = x - 2 * a;
    if (b < 0) return false;
    return c(a + b, a);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, y; cin >> x >> y;
    if (x > y) swap(x, y);
    cout << solve(x, y);
    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,a,b;
int32_t main(){
CODE_START;
cin>>n>>a>>b;
ll ans=0;
ll x=n/(a+b);
ans=ans+x*a;
x=n%(a+b);
ans=ans+min(a,x);
cout<<ans<<endl;
}






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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g)
{
    for( int i = g; i < n; i++ ){
        int v = A[i];
        int j = i - g;
        while( j >= 0 && A[j] > v ){
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n)
{
    //数列 G = { 1, 4, 13, 40, 121, 364, 1093, ... } を生成
    for( int h = 1; ; ){
        if( h > n ) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for( int i = G.size()-1; i >= 0; i-- ){ //逆順に G[i] = g を指定
        insertionSort(A, n, G[i]);
    }
}

int main()
{
    cin >> n;
    //より速い入力scanf関数を使用
    for( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for( int i = G.size() - 1; i >= 0; i-- ){
        printf("%d", G[i]);
        if( i ) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

    return 0;
}

Measured memory_bytes: 5192
N = int(input())
c = input()
ans = 0

i = 0
j = N-1
while i < j:
    while True:
        # print(1, i, j)
        if i == j:
            break
        if c[i] == 'W':
            break
        i += 1
    while True:
        # print(2, i, j)
        if i == j:
            break
        if c[j] == 'R':
            ans += 1
            break
        j -= 1
    i += 1
    j -= 1
print(ans)

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

int main(){
  int N,M,c=0;
  double tot=0;
  cin >> N >> M;
  
  vector <int> A(N);

  rep(i,N){
    cin >> A.at(i);
    tot+=A.at(i);
  }
  
sort(A.begin(),A.end());
reverse(A.begin(),A.end());
  
  
  rep(i,M){
    if(A.at(i)>=tot/(4*M))
      c++;
  }
  if(c==M)
    cout << "Yes" <<endl;
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import scipy as sp

def main():
    while True:
        try:
            li = list(map(int,input().split()))
            sorted_li = sorted(li)
            if sorted_li == [li[0], li[2], li[1]] or sorted_li == [li[1], li[2], li[0]]:
                print("Yes")
            else:
                print("No")
        except:
            break

if __name__ == '__main__':
    main()


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

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

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

    int64 a, b, n;
    cin >> a >> b >> n;

    int64 x = min(n, b - 1);
    cout << a * x / b - a * (x / b) << endl;

    return 0;
}



Measured memory_bytes: 3600
/*
	ID: Loxilante
	Time: 2020/08/16
	Prog: ABC175D
	Lang: cpp
*/
#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3")
#endif
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void) { tn k; cin>>k; return k; }
const int U = 5e3+50;
const int INF = 1e18;
int to[U], val[U], ct[U], t;
bool visited[U];
vector<int> loop;
inline void dfs(int e)
{
	if (visited[e]) return;
	visited[e] = 1;
	t += val[e];
	loop.pb(t);
	dfs(to[e]);
}
signed main(void)
{
	clock_t Begin = clock();

	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k, ans = -INF;
	cin>>n>>k;
	rep(i, 0, n) to[i] = next<int>()-1;
	rep(i, 0, n) cin>>val[i];

	clock_t InputFinished = clock();
	
	rep(i, 0, n)
	{
		ms(visited, 0);
		loop.clear();
		t = 0;
		dfs(i);
		int times = k/loop.size();
		if (loop.back() > 0 && k >= loop.size())
		{
			if (times >= 1)
			{
				int ans1 = -INF;
				rep(j, 0, loop.size()) ans1 = max(ans1, loop[j]);
				ans = max(loop.back()*(times-1)+ans1, ans);
			}
			

			int rest = k%loop.size(), ans2 = 0;
			rep(j, 0, rest) ans2 = max(ans2, loop[j]);
			ans = max(loop.back()*times+ans2, ans);
		}
		else rep(j, 0, k)
		{
			if (j >= loop.size()) break;
			ans = max(ans, loop[j]);
		}
	}
	
	cout<<ans<<endl;

	clock_t End = clock();
	
	D((double)(End-Begin)/CLOCKS_PER_SEC);
	D((double)(End-InputFinished)/CLOCKS_PER_SEC);
	
	return 0;
}
/*

 */

Measured memory_bytes: 3864
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w = inpl()
s = [input() for _ in range(h)]
res = []
for i in range(h+2):
    if i == 0 or i == h+1:
        res.append('#' * (w+2))
    else:
        res.append('#' + s[i-1] + '#')
for x in res:
    print(x)

Measured memory_bytes: 10468
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int n,k;
char a[N];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	  cin>>a[i];
	int maxx=0,h=1,t=1,ans=0;
	for(int i=1;i<=k;i++)
	{		
	    for(;a[t]=='1';t++)ans++;
		for(;a[t]=='0';t++)ans++;
	}
	for(;a[t]=='1';t++)ans++;
	maxx=ans;
	for(;a[h]=='1';h++)ans--;
	for(;a[t]=='1';t++)ans++;
	maxx=max(maxx,ans);
	while(h<=t&&h<=n)
	{		
	    for(;a[h]=='0';h++)ans--;
	    for(;a[t]=='0'&&t<=n;t++)ans++;
	    for(;a[t]=='1'&&t<=n;t++)ans++;
	    maxx=max(ans,maxx);
		for(;a[h]=='1';h++)ans--;
		for(;a[t]=='1'&&t<=n;t++)ans++;
		maxx=max(maxx,ans);
	}
	cout<<maxx;
	return 0;
}

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

char x[3];
int main() {
    int n;
    scanf("%s", x);
    if (x[0] < x[1]) printf("%c%c%c", x[0]+1, x[0]+1, x[0]+1);
    else if (x[0] > x[1]) printf("%c%c%c", x[0], x[0], x[0]);
    else {
        if (x[1] < x[2]) printf("%c%c%c", x[0]+1, x[0]+1, x[0]+1);
        else if (x[0] > x[2]) printf("%c%c%c", x[0], x[0], x[0]);
        else cout << x;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 768
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tgmath.h>

int main(int argc, char **argv)
{
    int a, b;
    scanf("%d %d", &a, &b);
    int x = a < b ? a : b;
    int y = a < b ? b : a;
    for (int i = 0; i < y; i++) printf("%d", x);
    printf("\n");
    return EXIT_SUCCESS;
}


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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e3 + 5;
const int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    string s;cin >> s;
    if((s.size() & 1) ^ (s.front() == s.back()))cout << "First";
    else cout << "Second";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

int n,m;

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

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n,m;
	cin>>n>>m;
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	--x1,--y1,--x2,--y2;
	vector<string> s(n);
	for(int i=0;i<n;++i) cin>>s[i];
	vector<vector<int>> score(n,vector<int>(m,INF));
	deque<pair<int,int>> dq;
	score[x1][y1]=0;
	dq.emplace_back(x1,y1);
	while(!dq.empty()){
		int x=dq.front().first;
		int y=dq.front().second;
		int dist=score[x][y];
		dq.pop_front();
		if(score[x][y]!=dist) continue;
		for(int dir=0;dir<4;++dir){
			int nx=x+dx[dir];
			int ny=y+dy[dir];
			if(nx<0||nx>=n||ny<0||ny>=m) continue;
			if(s[nx][ny]=='#') continue;
			if(score[nx][ny]<=dist) continue;
			score[nx][ny]=dist;
			dq.emplace_front(nx,ny);
		}
		for(int i=-2;i<=2;++i){
			for(int j=-2;j<=2;++j){
				int nx=x+i;
				int ny=y+j;
				if(nx<0||nx>=n||ny<0||ny>=m) continue;
				if(s[nx][ny]=='#') continue;
				if(score[nx][ny]<=dist+1) continue;
				score[nx][ny]=dist+1;
				dq.emplace_back(nx,ny);
			}
		}
	}
	int ans=score[x2][y2];
	if(ans==INF) cout<<-1;
	else cout<<ans;
	return 0;
}


Measured memory_bytes: 8656
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int N, x;
    cin >> N >> x;
    int a[110];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a, a + N);
    int cnt = 0;
    while (0 < x && cnt < N - 1)
    {
        x -= a[cnt];
        if (0 <= x)
        {
            cnt++;
        }
    }

    if (0 < x && a[cnt] == x)
    {
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a;
  int b;
  int c;
  int d;
  int s1;
  int s2;
  int s3;
  int m,sm,si;
  cin >>a>>b;
  if (a%3==0|b%3==0){
    cout <<0<<endl;
    return 0;
  }else {
    m=a;
    if (m>b) m=b;
    c=a/3+(a%3)/2;
    d=b/2;
    s1=d*(a-c);
    s2=(b-d)*(a-c);
    s3=b*c;
    sm=s2;
    si=s1;
    if (sm<s3) sm=s3;
    if (si>s3) si=s3;
    if (m>sm-si) m=sm-si;
    c=b/3+(b%3)/2;
    d=a/2;
    s1=d*(b-c);
    s2=(a-d)*(b-c);
    s3=a*c;
    sm=s2;
    si=s1;
    if (sm<s3) sm=s3;
    if (si>s3) si=s3;
    if (m>sm-si) m=sm-si;
  }
  cout <<m<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
set<ll> enum_divisors(ll n){
    set<ll> res;
    for(ll i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            res.insert(i);
            if(n / i != i)
                res.insert(n / i);
        }
    }
    return res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
ll ans = 0;
set<ll> st = enum_divisors(n);
for(auto v : st){
    ll k = v - 1;
    if(k == 0)
        continue;
    if(floor(n / k) ==  n % k)
        ans += k;
}
cout << ans << endl;
}

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

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

int f(int a){
    if(a%2 == 0) return a/2;
    else return 3*a+1;
}

int main() {
    const int max_num = 1000000;
    int s; cin >> s;
    vector<int> x(max_num);
    x[s]++; 
    rep(i, max_num){
        s = f(s);
        if(2 == x[s]++){
            cout << i-1 << endl;
            break;
        }
    }
    return 0;
}


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

int main() {
    ll  A,B,X;
    cin >> A >>B>>X;
    if(A>X || A+B<X){
        cout <<"NO" << endl;
        return 0;
    }
    cout <<"YES" << endl;


    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vll l(n);
    REP(i,n) cin >> l[i];
    sort(ALL(l));
    ll cnt = 0;
    REP(i,n){
        for(int j=i+1;j<n;++j){
            for(int k=j+1;k<n;++k){
                if(l[i]!=l[j]&&l[j]!=l[k]&&l[i]+l[j]>l[k])cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

struct S{
    int now, used;
    double cost;
    //costの昇順
    bool operator<(const S &s) const {
        return cost > s.cost;
    }
};
struct edge{
   int to;
   double cost;
};
int n, m, p, a, b;
double t[10], d[31][1 << 8];
vector<edge> G[31];

void dijkstra(){
    rep(i, 0, m) rep(j, 0, 1 << 8) d[i][j] = INF;
    d[a][0] = 0;
    S start = {a, 0, 0};
    // priority_queue<S, vector<S>, greater<S> > q;
    priority_queue<S> q;
    q.push(start);
    while(!q.empty()){
        S p = q.top(); q.pop();
        int from = p.now;
        double cost = p.cost;
        int used = p.used;
        if(d[from][used] < cost) continue;
        rep(i, 0, G[from].size()){
            edge e = G[from][i];
            int next = e.to;
            rep(j, 0, n){
                int nextused = used;                
                if(used & (1 << j)) continue;
                nextused |= 1 << j;
                double newCost = e.cost / t[j] + cost;
                if(d[next][nextused] > newCost){
                    // cout << from << ' ' << next << ' ' << j << ' ' << newCost << endl;
                    d[next][nextused] = newCost;
                    q.push({next, nextused, newCost});
                }
            }
        }
    }
    double ans = INF;
    rep(i, 0, 1 << 8){
        chmin(ans, d[b][i]);
    }
    if(ans > INF - 10) cout << "Impossible" << endl;
    else printf("%.10f\n", ans);
}

signed main(){
    while(1){
        cin >> n >> m >> p >> a >> b;
        if(n + m + p + a + b == 0) break;
        a--; b--; 
        rep(i, 0, m) G[i].clear();
        rep(i, 0, n) cin >> t[i];
        rep(i, 0, p){
            int x, y; 
            double z;
            cin >> x >> y >> z;
            x--; y--;
            G[x].push_back({y, z});
            G[y].push_back({x, z});
            // dist[x][y] = z;
            // dist[y][x] = z;
        }
        dijkstra();
    }
}


Measured memory_bytes: 5436
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;


#define X first
#define Y second
#define MAXN 2010

char s[MAXN][MAXN];
int h[MAXN];


int main()
{
	//freopen("input", "r", stdin);
	//freopen("output", "w", stdout);
	
	int n, m, ans;
	scanf("%d %d", &n, &m);
	ans= max(n, m);
	for (int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);

    for (int i = 1; i < n; ++i)
    {
    	for (int j = 1; j < m; ++j)
    	{
    		int cnt = (s[i][j] == '#') + (s[i + 1][j] == '#') + (s[i][j + 1] == '#') + (s[i + 1][j + 1] == '#');
			if (cnt & 1) h[j] = 0;
			else h[j]++;
		}
		int sta[MAXN], l[MAXN], r[MAXN], top = 0;
		sta[++top] = 0; h[m] = h[0] = -1;
		for (int j = 1; j <= m; ++j)
		{
			 while (h[j] < h[sta[top]])
			 {
			 	 r[sta[top]] = j;
			 	 --top;
			 }
			 sta[++top] = j;
		}
		top = 0; sta[++top] = m;
		for (int j = m - 1; j >= 0; --j)
		{
			while (h[j] < h[sta[top]])
			 {
			 	 l[sta[top]] = j;
			 	 --top;
			 }
			 sta[++top] = j;
		}
		for (int j = 1; j < m; ++j)
			ans = max(ans, (h[j] + 1) * (r[j] - l[j]));
		//cout << "line = " << i << endl;
	//	for (int j = 1; j < m; ++j) cout << j << "  " << h[j] << " " << l[j] << " " << r[j] << endl;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] arg) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a, b;
		String line, str;
		String[] splitedLine;
		while ((line = br.readLine()) != null) {
			splitedLine = line.split(" ");
			a = Integer.parseInt(splitedLine[0]);
			b = Integer.parseInt(splitedLine[1]);
			str = String.valueOf(a + b);
			System.out.println(str.length());
		}
	}
}

Measured memory_bytes: 17000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
using vi = vector<int>;
using vll = vector<ll>;
const ll INF = 1LL<<60;

int main(){
  int a,b; cin >> a >> b;
  vector<int> t(999);
  t[0] = 1;
  for(int i = 2; i <= 999; i++){
    t[i-1] = t[i-2] + i;
  }
  int c = b - a;

  cout << t[c-1] - b << endl;
  return 0;
}


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

class Program {
	static void Main(string[] args) {
		char[] s = { ' ' };
		var c = Console.ReadLine().Split(s, StringSplitOptions.RemoveEmptyEntries).Select(x => x[0]);
		foreach (var q in c) {
			Console.Write(q.ToString().ToUpper());
		}
		Console.WriteLine();
	}
}

Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	string fest = "FESTIVAL";

	int pos = s.rfind(fest);
	cout << s.substr(0, pos) << endl;

	return 0;
}


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

using namespace std;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 3;
long long dp[MAXN];

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> cango(N, true);
  for (int i = 0; i < M; ++i) {
    int a; cin >> a;
    cango[a] = false;
  }

  dp[0] = 1;
  for (int i = 1; i <= N; ++i) {
    if (!cango[i]) {
      dp[i] = 0;
    } else {
      dp[i] = (i > 1 ? dp[i - 1] + dp[i - 2]: dp[i - 1]);
      dp[i] %= MOD;
    }
  }
  cout << dp[N] << endl;
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
#define mod 1000000007
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}
bool vis[200005];
vector<int> vec[100005];
int child[100005];
int div1[100005];
void dfs(int node)
{
    vis[node] = 1;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            child[node] += child[vec[node][i]];
        }
    }
}
void belman(int n, int m, vector<pair<int, pair<int, int>>> vec, int dis[])
{
    for (int i = 0; i <= n + m - 1; i++)
    {
        for (int j = 0; j < vec.size(); j++)
        {
            int u = vec[j].second.first;
            int v = vec[j].second.second;
            int w = vec[j].first;

            if (dis[u] + w < dis[v])
            {
                dis[v] = dis[u] + w;
            }
        }
    }
}
int fun(int a, int b)
{
    if (a > b)
        return 0;
    if (a == b)
        return 1;
    else
    {
        return fun(a + 1, b) + fun(a, b - a);
    }
}
int32_t main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    int n, l;
    cin >> n >> l;
    vector<string> vec;
    for (int i = 0; i < n; i++)
    {
        string str;
        cin >> str;
        vec.push_back(str);
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < n; i++)
        cout << vec[i];

    return 0;
}


Measured memory_bytes: 5988
#include<iostream>
#include<math.h>
#include<iomanip>

int main()
{
	const double pi = 3.141592653589;
	double r;
	std::cin >> r;

	std::cout << std::fixed << std::setprecision(6) << r * r * pi << " " << r * pi * 2.0 << std::endl;
}

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

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[] x = new int[]
		{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
		
		for(int i = 0; i < 28; i++)
			x[sc.nextInt() - 1] = 0;
		
		Arrays.sort(x);
		
		System.out.println(x[28]);
		System.out.println(x[29]);
	}
}

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

int main() {
	int n, m, x, cnt = 0, mi = 105, w;
	cin >> n >> m >> x;
	vector<bool> f(n);

	for (int i = 0; i < m; i++) {
		cin >> w;
		f.at(w) = true;
	}
	for (int i = x; i < n; i++) {
		if (f.at(i) == true) {
			cnt++;
		}
	}
	mi = min(mi, cnt);
	cnt = 0;
	for (int i = x; i >= 0; i--) {
		if (f.at(i) == true) {
			cnt++;
		}
	}
	mi = min(mi, cnt);
	cout << mi << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long N,K=0,A;
  cin >> N;
  A=N;
  while(A>0){
    K+=A%10;
    A=A/10;
  }if(N%K==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
    int A, B;
    cin >> A >> B;

    if(A == 1) A += 13;
    if(B == 1) B += 13;

    if(A > B) cout << "Alice" << endl;
    else if(A < B) cout << "Bob" << endl;
    else cout << "Draw" << endl;
}

Measured memory_bytes: 256