akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

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

	sort(h, h+n);
	
	int minv = INF;
	for(int i=0;i<n - k + 1;i++) {
		minv = min(minv, h[i + k - 1] - h[i]);
	}

	cout<< minv <<endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e5+5,mod=1e9+7;
ll f[N],invf[N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int n,k;
int main()
{
    f[0]=invf[0]=f[1]=invf[1]=1;
    for(int i=2;i<N;i++) f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<N;i++) invf[i]=invf[i-1]*invf[i]%mod;
    scanf("%d%d",&n,&k);
    k=min(n,k);
    ll ans=0;
    for(int i=0;i<=min(n-1,k);i++)
        ans=(ans+C(n,i)*C(n-1,n-i-1)%mod)%mod;
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 6528
#include <iostream>
 #include <vector>
 
 using namespace std;
 
 int main()
{
	int n;
	cin >> n;
	vector<int> S(n);
	for (auto &s:S) cin >> s;
	int q;
	cin >> q;
	vector<int> T(q);
	for (auto &t:T) cin >> t;
	int C = 0;
	for (auto t:T)
	{
		for (auto s:S)
		{
			if (s==t)
			{
				C++;
				break;
			}
		}
	}
	
	cout << C << endl;
	
	
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll d,n;
cin>>d>>n;
ll ans=n;
ll v = pow(100,d);
if(n==100){
    ans = v*101;
}
else{
    ans= v*n;
}
cout<<ans<<endl;
//system("pause");
return 0;
}

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

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

typedef long long ll;



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

    if(a + b + c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{


    int x;
    int y=0;
    cin>>x;
    if (x%1000==0)
    {
        cout<<"0";
    }

    else
    {
        for (int i=0;i<10000;i++)
        {
            if (x%1000!=0)
            {

                x=x+1;
                y=y+1;
            }
            else
                break;
        }
        cout<<y;
    }
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int n,d,x,cnt;
int a[110];
int main()
{
  cin>>n>>d>>x;
  for (int i = 0; i < n;i++)
  {
    cin >> a[i];
    for (int j = 1;;j++)
    {
      if(1+(j-1)*a[i]<=d)
        cnt++;
      else
        break;
    }
  }
  cout << cnt + x << endl;
}  

Measured memory_bytes: 256
N = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))

mon = 0
for i in range(N):
    if lb[i] <= la[i]:
        mon += lb[i]
    elif lb[i] > la[i]:
        if lb[i] - la[i] >= la[i+1]:
            mon += la[i] + la[i+1]
            la[i+1] = 0
        else:
            mon += la[i] + lb[i] - la[i]
            la[i+1] -= lb[i] - la[i]

print(mon)

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

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NM = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine((NM[0] - 1) * (NM[1] - 1));
        }
    }
}


Measured memory_bytes: 27936
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    //cin >> t;
    for(int T = 0; T < t ; T++){
        string s, t;
        cin >> s >> t;
        int n = s.size(), m = t.size(), cnt = 0, ans = m;
        for(int i = 0; i < n - m + 1; i++){
            for(int j = 0; j < m; j++){
                if(s[j + i] != t[j])
                    cnt++;
            }
           // cout << cnt << endl;
            ans = min(ans, cnt);
            cnt = 0;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int L;
map<int, int> st;

int Mk(vector<int> &as) {
  int ret = 0;
  rep(i, L) {
    ret = ret*10 + as[i];
  }
  return ret;
}

int Nxt(int a) {
  vector<int> ds;
  rep(i, L) {
    ds.eb(a%10);
    a /= 10;
  }
  sort(all(ds));
  int l = Mk(ds);
  reverse(all(ds));
  int r = Mk(ds);
  return r - l;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  while (1) {
    int a;
    cin >> a >> L;
    if (a == 0 && L == 0) return 0;

    st.clear();
    st[a] = 0;
    int cnt = 0;
    while (1) {
      //cout << cnt << " : " << a << endl;
      a = Nxt(a);
      cnt++;
      if (st.count(a)) {
        cout << st[a] << " " << a << " " << cnt - st[a] << "\n";
        break;
      }
      st[a] = cnt;
    }
  }
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  string s;
  cin >> s;
  ll N = s.size();
  if (N == 2)
  {
    if (s.at(0) == s.at(1))
    {
      cout << 1 << ' ' << 2 << endl;
      return 0;
    }
  }
  for (ll i = 0; i < N - 2; ++i)
  {
    if (s[i] == 'e')
    {
      continue;
    }
    // cout << s[i + 2] << endl;
    if (s[i] == s[i + 1])
    {
      cout << i + 1 << ' ' << i + 2 << endl;
      return 0;
    }
    if (s[i] == s[i + 2])
    {
      cout << i + 1 << ' ' << i + 3 << endl;
      return 0;
    }
    if (s[i + 1] == s[i + 2])
    {
      cout << i + 2 << ' ' << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int N,i,count;
  double H,W,A[N],B[N];
  scanf("%d%f%f \n",&N,&H,&W);
for(i=0;i<N;i++){
  scanf("%f%f\n",&A[i],&B[i]);
}
for(i=0;i<N;i++){
for(A[i];A[i]>=H;A[i]-=H){
for(B[i];B[i]>=W;B[i]-=W){
  count+=1; A[i]-=H; B[i]-=W;}
   }
}
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    int n[3];
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    n[0] = A,n[1]=B,n[2]=C;
    for (int i = 0;i<3;i++)
    {
        for(int j = 0;j<3;j++)
        {
            if (i<j){
                if (n[i]<n[j]){
                    int a = n[i];
                    n[i] = n[j];
                    n[j] = a;
                }
            }
        }
    } 
    printf("%d",n[0]*10+n[1]+n[2]);
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  string s,t;
  cin >> s >> t;
  map<char,int>a,b;
  vector<int>A(s.size()),B(s.size());
  int now = 1;
  rep(i,s.size()){
    if(a[s[i]] != 0)A[i] = a[s[i]];
    else{
      A[i] = now;
      a[s[i]] = now;
      now++;
    }
  }
  now = 1;
  rep(i,s.size()){
    if(b[t[i]] != 0)B[i] = b[t[i]];
    else{
      B[i] = now;
      b[t[i]] = now;
      now++;
    }
  }
  if(A == B)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


Measured memory_bytes: 2312
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def dfs(lst, cnt):

    sub = []
    min_ = INF
    # print(lst, cnt, sub, min_)
    for l in lst:
        if l == 0:
            if min_ != INF:
                # print(min_, sub)
                cnt += min_
                cnt = dfs(list(map(lambda x: x-min_, sub)) + [0], cnt)
                sub = []
                min_ = INF
            else:
                continue
        else:
            min_ = min(min_, l)
            sub.append(l)
    # print('a')
    return cnt

def solve():
    n = II()
    H = LI()

    ans = dfs(H + [0], cnt=0)
    print(ans)

if __name__ == '__main__':
    solve()


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

int main() {
  int n;cin >> n;
  cout << (n+1)/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,tmp[100000];
bool used[100000];
const int mod=1e9+7;
vector<int>G[100000];
int dfs(int v){
	used[v]=true;
	long long ret=k-tmp[v];
	for(int i=0,cnt=0;i<G[v].size();i++){
		if(used[G[v][i]])
			continue;
		cnt++;
		tmp[G[v][i]]+=cnt;
		for(int j=0;j<G[G[v][i]].size();j++)
			if(G[G[v][i]][j]!=v)
				tmp[G[G[v][i]][j]]++;
		(ret*=dfs(G[v][i]))%=mod;
	}
	return ret;
}
int main(){
	int n,a[99999],b[99999];
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	cout<<dfs(0)<<endl;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';

void solve(){
    ll i,j,k,l,m,n,u,v,x,y;
    cin>>n;
    vector<ll> vc(n+1),sm(n+1);
    sm[0]=0;
    for(i=1;i<=n;i++){
        cin>>vc[i];
        sm[i]=(vc[i]+sm[i-1])%mod;
    }
    ll ans=0;
    for(i=1;i<n;i++){
        ans= ((vc[i] * (sm[n]-sm[i]+mod)%mod)%mod + ans%mod)%mod;
    }
    cout<<ans%mod<<nl;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<< i++ <<": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 6360
package main

import "fmt"

var N int
var h []int

func main() {
	fmt.Scanf("%d", &N)

	h = make([]int, N)
	for i := range h {
		fmt.Scanf("%d", &h[i])
	}

	fmt.Println(cnt(0, N-1))
}

func cnt(i, j int) int {
	// fmt.Printf("i,j=%d,%d %v\n", i, j, h)
	if i > j {
		return 0
	}
	if i == j {
		v := h[i]
		// h[i] = 0
		return v
	}

	p := i
	total := 0
	for k := i; k <= j; k++ {
		if h[k] == 0 {
			total += cnt(p, k-1)
			p = k + 1
		}
	}

	if p != i {
		return total + cnt(p, j)
	}

	for k := i; k <= j; k++ {
		h[k] -= 1
	}

	return cnt(i, j) + 1
}


Measured memory_bytes: 1888
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int MOD = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];

	ll ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] + a[i + 1] > x) {
			ans += a[i] + a[i + 1] - x;
			if (x - a[i] >= 0) a[i + 1] = x - a[i];
			else a[i + 1] = 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
#define pui pair<int, pair<int,int> >
using namespace std;



/*
            ॐ
    || Jai Shree Ram ||  
 
 */

void solve(){
    
    int  n;
    cin>>n;

    vec arr(n);

    rep(i,n) {
        cin>>arr[i];
    }
    unordered_map<int,int> mp;
    for(auto it : arr) {
        mp[it]++;
    }
    int ans = 1;
    sort(all(arr));
    if(arr[0] == arr[1]) {
        ans = 0;
    } else {
        ans = 1;
    }
    set<int> st;
    st.insert(arr[0]);

    for(int i=0; i<n; i++) {
        if(mp[arr[i]] == 1) {
            int val = arr[i];
            bool count = true;
            for(int j=1; j<=sqrt(val); j++) {
                if(val%j == 0 ) {
                    int x = val/j;
                    if(st.find(x) != st.end()) {
                        count = false;
                        break;
                    }

                    if(val % x== 0) {
                        if(st.find(val/x) != st.end()) {
                        count = false;
                        break;
                    }
                    }
                }
            }
            st.insert(arr[i]);

            if(count) ans++;
        }
        st.insert(arr[i]);
    }

    cout<<ans<<endl;



}

 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(25);
    int t = 1;
    // //cin >> t;
    while (t--)
    {
        solve();
    }
}



Measured memory_bytes: 21556
let rec fix f x = f (fix f) x
let isprime x =
  fix (fun f d -> if d * d > x then true else x mod d <> 0 && f (d+1)) 2

let () =
  Scanf.scanf "%d" @@ fun x ->
  fix (fun f v -> if isprime v then v else f (v+1)) x
  |> Printf.printf "%d\n"


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>


using namespace std;

int main() {
    int n, l, best=1000, sum = 0;
    cin >> n >> l;
    for (int i=1; i<=n; i++) {
        if (abs(l + i - 1) < abs(best))
            best = l + i - 1;
        sum += l + i - 1;
    }
    cout << sum - best << '\n';
    return 0;
}


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

int main(){
    int N; cin>>N;
    string S;
    int ans[4]{0};

    for(int i=0; i<N; i++){
        cin>>S;
        if(S=="AC"){
            ans[0]++;
        }else if(S=="WA"){
            ans[1]++;
        }else if(S=="TLE"){
            ans[2]++;
        }else if(S=="RE"){
            ans[3]++;
        }
    }

    cout<<"AC x "<<ans[0]<<endl;
    cout<<"WA x "<<ans[1]<<endl;
    cout<<"TLE x "<<ans[2]<<endl;
    cout<<"RE x "<<ans[3]<<endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  cin>>n;
  rep(i,n){
    string ans;
    string s;
	cin>>s;
	if(s[0]!='>'){cout<<"NA"<<endl;continue;}
	if(s[1]=='^'){
	  ans='B';
	  int j=2;
	  if(s[j]!='Q'||s[j+1]!='=')ans="NA";
	  while(s[j]=='Q'&&s[j+1]=='=')j+=2;
      if(s[j]!='~'||s[j+1]!='~')ans="NA";
	  j+=2;
	  if(j!=s.size())ans="NA";
	}else if(s[1]=='\''){
	  ans='A';
	  int h1=0,h2=0;
	  int j=1;
	  while(s[++j]=='=')h1++;
	  if(s[j]!='#')ans="NA";
	  while(s[++j]=='=')h2++;
	  if(s[j]!='~')ans="NA";
	  if(++j!=s.size())ans="NA";
	  if(h1!=h2||!h1)ans="NA";
	}else ans="NA";
	cout<<ans<<endl;
  }
}

Measured memory_bytes: 1208
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    long long n,m;
    scanf("%lld%lld",&n,&m);
    if(abs(n-m)<=1) cout<<"Brown"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
n,d = map(int,raw_input().split())
l = []
ctr = 0
for ii in xrange(n):
    l.append(map(int,raw_input().split()))

for i in xrange(n):
    for j in xrange(i+1,n):
        
        res = 0
        for k in xrange(d):
            # print l[i][k] , l[j][k]
            res += (l[i][k] - l[j][k])**2
        if str(math.sqrt(res))[-2:] == ".0":
            ctr += 1
        # print str(math.sqrt(res))
print ctr

Measured memory_bytes: 2948
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

template <class Cost = int>
struct StronglyConnectedComponents {
    Graph<Cost> graph, rgraph;
    std::vector<bool> visited;
    std::vector<int> stk;

    // id[v] = 頂点vはgroups[id[v]]に属する
    std::vector<int> id;
    std::vector<std::vector<int>> groups;

    explicit StronglyConnectedComponents(const Graph<Cost>& g)
        : graph(g), visited(graph.size(), false), id(graph.size(), -1) {
        revinit();

        for (int v = 0; v < (int)graph.size(); ++v) dfs(v);

        while (!stk.empty()) {
            int v = stk.back();
            stk.pop_back();
            if (id[v] < 0) {
                groups.emplace_back();
                rdfs(v);
            }
        }
    }

    void revinit() {
        rgraph = Graph<Cost>(graph.size());
        for (int v = 0; v < (int)graph.size(); ++v) {
            for (const auto& e : graph[v]) {
                rgraph[e.dst].emplace_back(e.dst, v, e.cost);
            }
        }
    }

    void dfs(int v) {
        if (visited[v]) return;
        visited[v] = true;
        for (const auto& e : graph[v]) dfs(e.dst);
        stk.push_back(v);
    }

    void rdfs(int v) {
        if (id[v] >= 0) return;
        id[v] = groups.size() - 1;
        groups.back().push_back(v);
        for (const auto& e : rgraph[v]) rdfs(e.dst);
    }
};

using ldouble = long double;

bool solve() {
    int n;
    std::cin >> n;
    if (n == 0) return false;

    std::vector<ldouble> ps(n);
    Graph<> graph(n);
    for (int u = 0; u < n; ++u) {
        int m;
        std::cin >> ps[u] >> m;

        while (m--) {
            int v;
            std::cin >> v;
            --v;
            graph[u].emplace_back(u, v);
        }
    }

    StronglyConnectedComponents<> scc(graph);
    int nn = scc.groups.size();

    std::vector<int> deg(nn, 0);
    std::vector<ldouble> pro(nn, 1);  // 全員寝坊する確率

    for (int u = 0; u < n; ++u) {
        pro[scc.id[u]] *= ps[u];
        for (auto e : graph[u]) {
            if (scc.id[u] == scc.id[e.dst]) continue;
            ++deg[scc.id[e.dst]];
        }
    }

    ldouble ans = 1;
    for (int v = 0; v < nn; ++v) {
        if (deg[v] > 0) continue;
        ans *= 1 - pro[v];
    }
    std::cout << std::fixed << std::setprecision(10)
              << ans << std::endl;
    return true;
}

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

    while (solve()) {}

    return 0;
}



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

int main() {
  int t, n;
  cin >> t;
  int flag = 0;
  while (t--) {
    cin >> n;
    if (n % 2 == 0) {
      if (n % 3 != 0 && n % 5 != 0) {
        flag = 1;
      }
    }
  }
  if (flag == 0) 
    cout << "APPROVED";
  else
    cout << "DENIED";
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int i = s.indexOf("C");
		int j = s.lastIndexOf("F");
		System.out.println((i >= 0 && j >= 0 && i < j) ? "Yes" : "No");
	}

}


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


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define PB push_back
vector<vint> vv;
vint vis;

int dfs(int a,int b){
	// cout<<a<<endl;
	vis[a]=1;
	int ret=0;
	rep(i,vv[a].size()){
		if(vis[vv[a][i]]) continue;
		ret=max(ret,dfs(vv[a][i],b));
	}
	vis[a]=0;
	return ret+1;
}

void mainmain(){
	int n;
	while(cin>>n,n){
		// cout<<n<<endl;
		vv=vector<vint>(100);
		vis=vint(100,0);
		rep(i,n){
			int a,b;
			cin>>a>>b;
			a--;
			b--;
			// cout<<a<<" "<<b<<endl;
			vv[a].PB(b);
			vv[b].PB(a);
		}
		int ans=0;
		rep(i,100) vis[i]=0;
		rep(i,100){
			// cout<<"i "<<i<<endl;
			int t=dfs(i,0);
			// cout<<i<<" "<<t<<endl;
			ans=max(ans,t);
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1224
#include <iostream>

int main() {
    char X, Y;
    std::cin >> X >> Y;

    if (X < Y) {
        std::cout << "<" << std::endl;
    } else if (X > Y) {
        std::cout << ">" << std::endl;
    } else {
        std::cout << "=" << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    int n;
    cin >> n;
    string s;
    unordered_set<string> us;
    while(n --) {
        cin >> s;
        us.insert(s);
    }
    cout << us.size() << endl;
    return 0;
}



Measured memory_bytes: 17724
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int w, h; cin >> w >> h;
    int x1 = 0, y1 = 0, x2 = w, y2 = h;
    int n; cin >> n;
    rep(i, n){
        int x, y, a; cin >> x >> y >> a;
        switch(a){
            case 1: { chmax(x1, x); break; }
            case 2: { chmin(x2, x); break; }
            case 3: { chmax(y1, y); break; }
            case 4: { chmin(y2, y); break; }
        }
    }
    chmax(x2, x1);
    chmax(y2, y1);

    cout << (x2 - x1) * (y2 - y1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
        REP(i,n) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

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


int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    UnionFind uf(n);
    REP(i,n) {
        cin >> v[i];
        v[i]--;
    }
    REP(i,m) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
    }

    int ans = 0;
    REP(i,n) {
        if (uf.same(i,v[i])) ans++;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b)
    {
        printf("%d\n",c);
    }
    else
    if(a==c)
    {
        printf("%d\n",b);
    }
    else
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 128
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=10**19
###############################################################################\n=17
s=input()
t=input()
ans=10**6
for i in range(len(s)-len(t)+1):
    count=0
    for j in range(len(t)):
        if s[i+j]!=t[j]:
            count+=1
    ans=min(count,ans)
print(ans)


Measured memory_bytes: 102200
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long LL;
const int maxn=1e5+7;
int n,X;
LL sum,cnt;
struct Node{
	int c,s,t;LL val;
	Node(int x=0,int y=0,int z=0){c=x,s=y,t=z,val=c*1ll*s+(X-c)*1ll*t;}
	inline bool operator <(const Node &a)const{return val>a.val;}
}a[maxn];
inline LL HA(int x,int k){
	if(k<=a[x].c)return a[x].s*1ll*k;
	return a[x].val-(X-k)*1ll*a[x].t;
}
inline LL HAHA(LL xx){
	LL now=0,Max=0;
	int k=xx/X,q=xx%X;
	for(int i=1;i<=k+1;++i)now+=a[i].val;
	for(int i=1;i<=k;++i)
		Max=std::max(Max,now-a[i].val+HA(i,q));
	now-=a[k+1].val;
	for(int i=k+1;i<=n;++i)
		Max=std::max(Max,now+HA(i,q));
	return Max;
}
int main(){
	scanf("%d%d",&n,&X);
	for(int i=1,x,y,z;i<=n;++i){
		scanf("%d%d%d",&x,&y,&z);
		a[i]=Node(x,y,z),cnt+=x,sum+=x*1ll*y;
	}
	if(cnt==X*1ll*n)
		return printf("%lld\n",cnt),0;
	std::sort(a+1,a+n+1);
	LL s=0,t=cnt;
	while(s<=t){
		LL mid=(t+s)>>1;
		if(HAHA(mid)>=sum)t=mid-1;
		else s=mid+1;
	}printf("%lld\n",s);
	return 0;
}


Measured memory_bytes: 2560
//0609 Chrisjmas Party//
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int m,n,a[100],b[101],ten[101],i,j;
	scanf("%d",&n);
	scanf("%d",&m);
	for(i=0;i<m;i++) scanf("%d",&a[i]);
	for(i=0;i<=n;i++)		ten[i]=0;
	for(i=0;i<m;i++) {
		for(j=1;j<=n;j++)	{
			scanf("%d",&b[j]);
			if(b[j]==a[i])	ten[j]++;
			else ten[a[i]]++;
		}
	}
	for(i=1;i<=n;i++)	printf("%d\n",ten[i]);
	return 0;
}


Measured memory_bytes: 2736
#include<iostream>
#include<cstdlib>

int main()
{
	int n;
	std::cin>>n;
	for(int i=0;i<n;i++)
	{
		char c;
		int h,m;
		
		std::cin>>h>>c>>m;
		
		int angl=h*60+m;
		int angs=m*12;

		int diff=abs(angl-angs);
		if(diff>360)diff=720-diff;
		
		if(diff<60)
		{
			std::cout<<"alert"<<std::endl;
		}
		else if(diff<180)
		{
			std::cout<<"warning"<<std::endl;
		}
		else
		{
			std::cout<<"safe"<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main(){
  long a,b,c,d;
  cin >> a >> b >> c >> d;
  long x1, x2, x3, x4;
  x1 = a * c;
  x2 = a * d;
  x3 = b * c;
  x4 = b * d;
  if (x1 > x2 && x1 > x3 && x1 > x4) cout << x1;
  else if (x2 > x3 && x2 > x4) cout << x2;
  else if (x3 > x4) cout << x3;
  else cout << x4;
}

Measured memory_bytes: 3608
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (A == 1) { A = 14; }
	if (B == 1) { B = 14; }

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


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

int main(){
    int N;
    cin >> N;
    vector<tuple<string,int,int>> p(N);
    for (int i=0;i<N;i++){
        string S;
        int q;
        cin >> S >> q;
        p.at(i) = make_tuple(S,-q,i+1);
    }
    sort(p.begin(),p.end());
    
    for (int i=0;i<N;i++){
        int j;
        tie(ignore,ignore,j) = p.at(i);
        cout << j << endl;
    }
}

Measured memory_bytes: 3608
def makerectangle(n , a):

    listmax = []
    a.sort(reverse=True)
    for i in range(n):
        if len(a) > i + 1 and a[i] == a[i + 1] and listmax.count(a[i]) == 0:
            if len(a) > i + 3 and a[i] == a[i + 3] and len(listmax) == 0:
                return a[i] * a[i]
            else:
                listmax.append(a[i])
        if len(listmax) > 1:
            return listmax[0] * listmax[1]
    return 0


def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(makerectangle(n , a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 62704
#include<iostream>
//#define int long long

using namespace std;

long long dp[100001];

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

    int n, m;
    cin >> n >> m;

    if (n <= 25)
    {
        long long ans = 0, p[25], l[25];
        for (int i = 0; i < 25; i++)
            cin >> p[i] >> l[i];
        for (int i = 0; i < (1 << 25); i++)
        {
            bool use[25];
            int t = i;
            for (int j = 0; j < n; j++)
                use[j] = t % 2, t /= 2;

            long long tp = 0, tl = 0;
            for (int j = 0; j < n; j++)
                tp += use[j] * p[j], tl += use[j] * l[j];

            if (tp <= m)
                ans = max(ans, tl);
        }
        cout << ans << '\n';
    }
    else// if (m <= 1000000)
    {
        long long p, l;
        for (int i = 0; i < n; i++)
        {
            cin >> p >> l;
            for (int j = m; j >= p; j--)
                dp[j] = max(dp[j], dp[j - p] + l);
        }

        long long ans = 0;
        for (int i = 0; i <= m; i++)
            ans = max(ans, dp[i]);
        cout << ans << '\n';
    }
    /*else
    {
        for (int i = 1; i <= 100000; i++)
            dp[i] = 1e18;

        long long p, l, sum = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> p >> l;

            if (l < 0)
                continue;
            sum += l;
            for (int j = sum; j >= l; j--)
                dp[j] = min(dp[j], dp[j - l] + p);
        }
        while (dp[sum--] > m);
        cout << sum + 1 << '\n';
    }*/

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    ll A, B;
    cin >> A >> B;
    if((A+B) % 2 != 0){
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (A+B) / 2 << endl;
    }
    
    return 0;
}


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

int main(void)
{
  string s;
  cin>>s;
  if(s.size()==3){
    for(int i=0;i<=2;i++){
      cout<<s[2-i];
    }
    cout<<endl;
  }
  else{
    cout<<s<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
//const int INF = 1001001001;
const int MOD = 1000003;

int main(){
    int n, k;
    cin >> n >> k;
    vi a(n);
  	rep(i,n)cin >> a[i];
  	cout << 1 + (n-k + k-1 -1)/(k-1) << endl;
  	return 0;
}

Measured memory_bytes: 3696
n, m = map(int, input().split())
h = list(map(int, input().split()))
edge = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
c = 0
for i in range(n):
    ans = True 
    for j in edge[i]:
        if h[j]>=h[i]:
            ans = False 
    if ans:
        c += 1

print(c)

Measured memory_bytes: 29508
// Toll Gates

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int N, M, X;
	cin >> N >> M >> X;
	int A[M];
	for (int i = 0; i < M; ++i)
		cin >> A[i];

	int rcost = 0, lcost = 0;

	for (int i = 0; i < M; ++i){
		if (A[i] < X)
			lcost++;
		else
			rcost++;
	}

	cout << min(lcost, rcost) << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
Ns = []
for i in range(N):
  Ns.append(input())
  
M = int(input())
Ms = []
for i in range(M):
  Ms.append(input())
  
Ws = list(set(Ns + Ms))

As = []
for i in Ws:
  ans = 0
  for j in Ns:
    if i == j:
      ans += 1
  for j in Ms:
    if i == j:
      ans -= 1
  As.append(ans)
  
print(max(max(As), 0))


Measured memory_bytes: 9196
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
double ruijo(double x, int n) {
    double res = 1;
    rep(i, 0, n) { res *= x; }
    return res;
}
int intruijo(int x, int n) {
    int res = 1;
    rep(i, 0, n) { res *= x; }
    return res;
}
int main() {
    long long W, H, x, y;
    cin >> W >> H >> x >> y;
    long long S = W * H;
    if(S % 2 == 1) {
        S--;
        cout << S / 2 << ".5";
    } else {
        cout << S / 2;
    }
    //     long double max = (long double)S / 2.0;
    // cout << max << " ";
    // printf("%20.1f", max);
    if(x == W / 2 && y == H / 2 && W % 2 == 0 && H % 2 == 0) {
        cout << " " << 1 << endl;
    } else {
        cout << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
def sunukee(a):
    num = 0
    for i in range(len(a)):
        if (a[i] % 2) == 0:
            num += 1
        #2で割れるか確かめる
    if num == len(a):
        return True
    else:
        return False
def sunuke(a):
    for i in range(len(a)):
        a[i] = a[i]/2
    return a
n = int(input())
a = list(map(int, input().split()))
s = 0
while sunukee(a):
    a = sunuke(a)
    s += 1
print(s)


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

namespace ALDS1_4_B {
    public static class MyExtension {
        public static bool Contains(this int[] nums,int n) {
            int left = 0;
            int right = nums.Length;
            while (left < right) {
                int mid = (left + right) / 2;
                if (n == nums[mid])
                    return true;
                if (n > nums[mid])
                    left = mid + 1;
                else
                    right = mid;
            }
            return false;
        }
    }

    class Program {
        static void Main(string[] args) {
            Console.ReadLine();
            int[] S = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.ReadLine();
            int[] T = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int count = 0;
            foreach (int t in T) {
                if (S.Contains(t))
                    count++;
            }
            Console.WriteLine(count);
        }
    }
}

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

typedef pair<int, int> Pi;
typedef pair<int, Pi > Ti;
#define fi first
#define se second

signed main()
{
  int N, M, A;
  int val[105];
  Ti data[1005];
  
  while(cin >> N >> M >> A, N || M || A) {
  
    for(int i = 0; i < 105; i++) {
      val[i] = i + 1;
    }
  
    for(int i = 0; i < M; i++) {
      cin >> data[i].fi >> data[i].se.fi >> data[i].se.se;
      data[i].se.fi--, data[i].se.se--;
    }

    sort(data, data + M, greater<Ti>());
  
    for(int i = 0; i < M; i++) {
      swap(val[data[i].se.fi], val[data[i].se.se]);
    }
    
    for(int i = 0; i < N; i++) {
      if(val[i] == A) cout << i + 1 << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<55)
#define mod 1000000007
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;}

void make_prime(vector<ll> &ret,ll n){
    ll x=n;
    for(ll i=2;i*i<=x;i++){
	    while(n%i==0){
  		    n/=i;
            ret.push_back(i);
	    }
    }
    if(n!=1){ 
	    ret.push_back(n);
    }

    return;
}

ll modpow(ll x,ll n) {
    ll ret=1;
    while(n>0){
        if(n&1) ret=ret*x%mod;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x=x*x%mod;
        n>>=1;  // n を1bit 左にずらす
    }
    return ret;
}

int main(){
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    vector<vector<ll>> prime(n);

    rep(i,n){//それぞれ素因数分解
        make_prime(prime[i],a[i]);
        prime[i].push_back(-1ll);//sentinel
    }

    //以下で最小公倍数を考える
    vector<ll> howmany(1000010,0);
    rep(i,n){
        ll num=1;
        rep(j,prime[i].size()-1){
            if(prime[i][j]==prime[i][j+1]){
                num++;
            }else{
                if(howmany[prime[i][j]]<num){
                    howmany[prime[i][j]]=num;
                }
                num=1;
            }
        }
    }

    vector<P> num_how;
    rep(i,howmany.size()){
        if(howmany[i]!=0){
            num_how.push_back({i,howmany[i]});
        }
    }

    ll ans=0;
    rep(i,n){
        vector<P> instead;
        ll num=1;
        rep(j,prime[i].size()-1){
            if(prime[i][j]==prime[i][j+1]){
                num++;
            }else{
                instead.push_back({prime[i][j],num});
                num=1;
            }
        }

        ll add=1,now=0;
        rep(j,num_how.size()){
            if(now<instead.size() && instead[now].first==num_how[j].first){
                add*=modpow(num_how[j].first,num_how[j].second-instead[now].second);
                now++;
            }else{
                add*=modpow(num_how[j].first,num_how[j].second);
            }
            add%=mod;
        }

        ans+=add;
        ans%=mod;
    }

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

Measured memory_bytes: 12288
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  // tmp0 = input[0].split(" ")
  // N = Number(tmp0[0])
  // M = Number(tmp0[1])
  A = Number(input[0])
  B = Number(input[1])
  C = Number(input[2])
  D = Number(input[3])
  E = Number(input[4])

  // 1のくらいで1~9の最小
  list_1 = []
  list_1.push(Number(String(A).split("").slice(-1)[0]) === 0 ? 10 : Number(String(A).split("").slice(-1)[0]))
  list_1.push(Number(String(B).split("").slice(-1)[0]) === 0 ? 10 : Number(String(B).split("").slice(-1)[0]))
  list_1.push(Number(String(C).split("").slice(-1)[0]) === 0 ? 10 : Number(String(C).split("").slice(-1)[0]))
  list_1.push(Number(String(D).split("").slice(-1)[0]) === 0 ? 10 : Number(String(D).split("").slice(-1)[0]))
  list_1.push(Number(String(E).split("").slice(-1)[0]) === 0 ? 10 : Number(String(E).split("").slice(-1)[0]))


  min_index = list_1.indexOf(Math.min(...list_1))

  Num_list = [A, B, C, D, E]
  ans=0
  for(var i=0; i < 5; i++)
  {
    if(i !== min_index){
      ans += Math.ceil(Num_list[i] / 10) * 10
    }
  }
  ans += Num_list[min_index]
  console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("29\n20\n7\n35\n120\n")

Measured memory_bytes: 7372
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n;
int w[400][400], d[400][400];

int check() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				d[j][k] = MIN(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (d[i][j] != w[i][j]) {
				return 0;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (i == k || j == k) continue;
				if (w[i][j] == d[i][k] + d[k][j]) {
					w[i][j] = -1;
				}
			}
		}
	}

	LL ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (w[i][j] == -1) continue;
			ans += w[i][j];
		}
	}
	printf("%lld\n", ans);
	return 1;
}

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

	if (!check()) printf("-1\n");

	
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vl a;
	range(i,m-n+1,m+n)a.push_back(i);
	puta(a);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string str ;
    getline(cin, str) ;
    for (int i= 0 ; i< str.size() ; ++i)
    {
        if (str[i]==',')
        {
            str[i]=' ' ;
        }
    }
    cout << str ;
    return 0 ;
}
///||


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

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int mx = 0;
    a.push_back(k+a[0]);

    rep(i,n){
        mx = max(mx,a[i+1]-a[i]);
    }

    int ans = k - mx;
    cout << ans << endl;
}

Measured memory_bytes: 1792