akhauriyash/Code-Regression huggingface dataset:
H,W = list(map(int,input().split(" ")))
mass = []
for _ in range(H):
    mass.append(input())


dirs = [[0,1],[1,0],[0,-1],[-1,0]]

flag = True
for h,row in enumerate(mass):
    for w,temp in enumerate(row):
        if temp == "#":
            cont = False
            for dir in dirs:
                x = dir[0]
                y = dir[1]
                hy =h+y
                wx = w + x
                if  hy < 0 or wx< 0 or wx==W or hy == H:
                    continue
                else:
                    if mass[hy][wx] == "#":
                        cont = True
            if not cont:
                flag = False
if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 40560
N = int(input())

A,B = [],[]

for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
ans = 0
for a,b in zip(A[::-1],B[::-1]):
    if (ans+a)%b!=0: ans += b-((ans+a)%b)

print(ans)

Measured memory_bytes: 12600
import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

lis = list(itertools.permutations(range(1,N+1)))
a = lis.index(P)+1
b = lis.index(Q)+1
ans = abs(a-b)
print(ans)

Measured memory_bytes: 13976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N; cin >> N;
  double d = sqrt(N);
  int r = (int)d;
  for(int i=r; i>0; i--){
    if(N%i==0){
      cout << (i-1)+((N/i)-1) << endl;
      return 0;
    }
  }
  cout << N-1 << endl;
  return 0;  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()


int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;

    ll a = 0, b = 0, c = 0, d = 0;

    for (ll i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (s == "AC")
        {
            a++;
        }
        else if (s == "WA")
        {
            b++;
        }
        else if (s == "TLE")
        {
            c++;
        }
        else if (s == "RE")
        {
            d++;
        }
    }

    cout << "AC "
         << "x " << a << endl;
    cout << "WA "
         << "x " << b << endl;
    cout << "TLE "
         << "x " << c << endl;
    cout << "RE "
         << "x " << d << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N,K;
	cin>>N>>K;
	ll ans=0;
	fx(N){
		int a;
		cin>>a;
		ans+=min(2*a,2*abs(K-a));
	}
	ce(ans)
	
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

vector<vector<int> > graph;
vector<int> visited;
int sz;

void dfs(int u) {
	if (!visited[u]) {
		visited[u] = 1;
		++sz;
	}

	for (auto v : graph[u]) {
		if (!visited[v]) {
			dfs(v);
		}
	}
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

	graph = vector<vector<int> > (n + 1, vector<int> ());
	int u, v;
	for (int i = 0; i < m; ++i) {	
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}

	visited = vector<int> (n + 1);
	int groups = 0;
	for (int i = 1; i <= n; ++i) {
		sz = 0;
		if (!visited[i]) {
			dfs(i);
		}

		groups = max(groups, sz);
	}

	cout << groups << "\n";

	return 0;

}

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

const int MAXN = 85;

int n, a[MAXN];
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	
	long long r = 1000;
	for(int i = 0; i < n - 1; i++){
		if(a[i + 1] <= a[i])continue;
		r =  r % a[i] + r / a[i] * a[i + 1];
	}
	printf("%lld\n", r);
	
	return 0;
}


Measured memory_bytes: 3724
from math import ceil


def solve(string):
    n, h, * ab = map(int, string.split())
    max_a = max(ab[::2])
    cnt = 0
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h-sum(b)) / max_a)
    else:
        for _b in b:
            cnt += 1
            h -= _b
            if h <= 0:
                break
    return str(cnt)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m)+'\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 27268
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu
const int N=1005;
char s[N][N];
int n,m,dis[N][N];
queue<pii >qu;
int dx[]={1,0,0,-1};
int dy[]={0,1,-1,0};
//
inline bool isvalid(int x,int y){
	if(x>=0&&x<n&&y>=0&&y<m&&dis[x][y]==-1)return true;
	return false;
}
int main(){
	n=getint();m=getint();
	memset(dis,-1,sizeof(dis));
	rep(i,n){
		scanf("%s",s[i]);
		rep(j,m)if(s[i][j]=='#'){
			dis[i][j]=0;
			qu.push(mp(i,j));
		}
	}
	int res=0;
	while(!qu.empty()){
		pii u=qu.front();qu.pop();
		rep(i,4){
			int fx=dx[i]+u.first,fy=dy[i]+u.second;
			if(!isvalid(fx,fy))continue;
			dis[fx][fy]=dis[u.first][u.second]+1;
			res=max(res,dis[fx][fy]);
			qu.push(mp(fx,fy));
		}
	}
	printf("%d\n",res);
	return 0;
}


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

char p[10000001];

void mkPrime(void){
	memset(p,1,sizeof(p));
	p[0] = p[1] = 0;
	for(int i=2;i<=10000000;i++){
		if(p[i]){
			for(int j=i*2;j<=10000000;j+=i){
				p[j] = 0;
			}
		}
	}
}

int main(void){
	mkPrime();

	int n;

	while(cin>>n && n){
		int i = n;
		while(!(p[i] && p[i-2] && p[i-6] && p[i-8])) i--;
		cout<<i<<endl;
	}

	return 0;
}

Measured memory_bytes: 10000
n = int(input())
tree = list(map(int, input().split()))

def main() :
    createHeap(n)
    print('', ' '.join(map(str, tree)))

def createHeap(x):
    for i in range((x - 1) // 2, -1, -1) :
        maxHeap(i)

def maxHeap(i) :
    if i * 2 + 1 >= n:
        return

    tmp = i * 2 + 1

    if i * 2 + 2 < n :
        if tree[i * 2 + 1] < tree[i * 2 + 2] :
            tmp = i * 2 + 2

    if tree[i] < tree[tmp] :
        tree[i], tree[tmp] = tree[tmp], tree[i]
        maxHeap(tmp)

if __name__ == '__main__':
    main()



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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define PB push_back
#define pb push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len(stuff) (int) stuff.size()

#define int long long
#define float long double 
#define ll long long
#define ld long double

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const int inf = (int) 2e18;
const int upper = (int) 3e5 + 50;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

int n, m;
int dist[1005][1005];
bool taken[1005][1005];
bool vis[1005][1005];
queue<pair<pii, int>> q;

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

bool legit (int i, int j) {
	return (i >= 1 and i <= n and j >= 1 and j <= m);
}

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	cin >> n >> m;
	for (int i = 1; i <= n; i += 1) {
		for (int j = 1; j <= m; j += 1) {
			char c; cin >> c;
			if (c == '#') taken[i][j] = true;
			else taken[i][j] = false;

			vis[i][j] = false;
			if (taken[i][j]) {
				q.push(make_pair(make_pair(i, j), 0));
				dist[i][j] = 0;
				vis[i][j] = true;
			}
		} 
	}
	while (!q.empty()) {
		int x = q.front().first.first, y = q.front().first.second, d = q.front().second;
		dist[x][y] = d;
		q.pop();
		for (int i = 0; i < 4; i += 1) {
			int new_x = x + dx[i], new_y = y + dy[i];
			if (legit(new_x, new_y)) {
				if (!vis[new_x][new_y]) {
					q.push(make_pair(make_pair(new_x, new_y), d + 1));
					vis[new_x][new_y] = true;
				}
			}
		}
	}

	int mx = -1;
	for (int i = 1; i <= n; i += 1) {
		for (int j = 1; j <= m; j += 1) {
			mx = max(mx, dist[i][j]);
		}
	}
	cout << mx;
 	end_routine();		
}


Measured memory_bytes: 34228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		/**
		 * お札を定義します
		 */
		
		int a = 10000;
		int b = 5000;
		int c  = 1000;
		
		/**
		 *入力を取得します 
		 */
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int y = sc.nextInt();
		
		/**
		 * 計算部分
		 */
		
		int bol = 0;
		int total;
		cal : for (int i = 0 ; i <= n ; i++) {
			for (int j = 0 ; j <= n - i ; j++) {
				total = a * i + b * j + c * (n - i - j);
				if (total == y) {
					bol = 1;
					System.out.println(i + " " + j + " " + (n - i - j));
					break cal;
				} 

			}
			
		}
		if (bol != 1) {
			System.out.println("-1 -1 -1");
		}

		
	}

}


Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
 
const int N = 1e5 + 10;
const int MOD = 10000000;
const int inf = 0x3f3f3f3f;


int main(){
	int n,k;
	cin>>n>>k;
	int vis[n+1];
	memset(vis,0,sizeof(vis));
	while(k--){
		int c;
		cin>>c;
		while(c--){
			int x;cin>>x;vis[x]=1;
		} 
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(!vis[i])ans++;
	}
	cout<<ans<<endl;
	
	return 0;
	
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
  int a, b;
  cin >> a >> b;
  if(a < 10 && b < 10) cout << a * b;
  else cout << -1;
    return 0;
}


Measured memory_bytes: 256
S = input()
a = 0
hoge = -1
v = 0
ans = 0
for i in S:
    if i == "<":
        a += 1
        ans += a
        v = a
        hoge = -1
    else:
        hoge += 1
        a = 0
        if hoge < v:
            ans += hoge
        else:
            ans += hoge+1
print(ans)


Measured memory_bytes: 42732
import java.io.BufferedReader;
import java.io.InputStreamReader;

	public class Main {
	    public static void main(String[] args) throws Exception {
	        // Here your code !
	        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	        while(true) {
		        String line = br.readLine();
		        String[] line2 = line.split(" ");
		        if(Integer.parseInt(line2[0])==0)
		        	if(Integer.parseInt(line2[1]) == 0)
		        		break;
		        print(Integer.parseInt(line2[0]),Integer.parseInt(line2[1]));
	        }
	    }
	    static void print(int w,int h) {
	    		for(int j=0;j < w;j++) {
	    	    	for(int i=0;i < h;i++) {
	    	    		System.out.print("#");
	    	    	}
		    		System.out.println();
	    		}
	    		System.out.println();
	    }
	}

Measured memory_bytes: 24140
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))


n,l=input_list()

r=l+n-1

ans=0

bite=0
if r<0:
    bite=r

if l>0:
    bite=l

for i in range(l,r+1):
    if i==bite:
        continue
    ans+=i

print(ans)

Measured memory_bytes: 12412
from collections import Counter
from string import ascii_lowercase

n = int(input())
sss = [input() for _ in range(n)]
flags = {c: 1 << (ord(c) - 97) for c in ascii_lowercase}

trie_chr = [-1]
trie_children = [{}]
trie_fin = [0]
l = 1

for s in sss:
    node = 0
    for i in range(len(s) - 1, 0, -1):
        c = ord(s[i]) - 97
        if c in trie_children[node]:
            node = trie_children[node][c]
        else:
            trie_chr.append(c)
            trie_children.append({})
            trie_fin.append(0)
            trie_children[node][c] = l
            node = l
            l += 1
    trie_fin[node] |= flags[s[0]]

ans = 0

for s in sss:
    cnt = Counter(s)
    flag = 0
    for c in cnt:
        flag |= flags[c]
    node = 0
    if len(s) > 1 and trie_fin[node] > 0:
        ans += bin(trie_fin[node] & flag).count('1')

    for i in range(len(s) - 1, 1, -1):
        c = s[i]
        cnt[c] -= 1
        if cnt[c] == 0:
            flag ^= flags[c]
        k = ord(c) - 97
        node = trie_children[node][k]
        if trie_fin[node] > 0:
            ans += bin(trie_fin[node] & flag).count('1')

print(ans)


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

using namespace std;

int main(){
	string str;
	cin>>str;
    int cur = 0,m = 0;
    for(int i = 0;i < (int)str.length();i++)
    {
    	if(str[i] == 'R')
        cur++;
        else{
        	m = max(m,cur);
          	cur = 0;
        }
    }
  	m = max(m,cur);
  	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 3636
// mapはキー／値の対を保持する理想コンテナ
// 連想配列

#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main(void){

  string s;
  map< string , int > count; // キーがstring型、値がintのmap
  string num;
  string len;

  while( cin >> s ){
    int c = ++count[s];                    //初期化は必要なし？  
    if( c > count[num] ) num = s;          //ここで単語
    if( s.size() > len.size() ) len = s;   //ここで文字数
  }
  cout << num << " " << len << endl;
  return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<math.h>
#include<cmath>
#include <iomanip> 
using namespace std;
int main(){
    double A,B,H,M,L,l;
    cin >>A>>B>>H>>M;
    double pi = 2.0*acos(0.0);
    L = A*A + B*B - 2.0*A*B*cos(((30.0*H-5.5*M)/180.0)*pi);
    l = sqrt(L);
    cout << fixed << setprecision(20) << l;
    return 0;
}

Measured memory_bytes: 4116
using System;

namespace noteCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputstr = Console.ReadLine().Split(char.Parse(" "));
            int a = int.Parse(inputstr[0]);
            int b = int.Parse(inputstr[1]);
            int d = a / b;
            int r = a % b;
            if ((double)((double)a / (double)b) != 0)
            {
                double f = ((double)a / (double)b);
                while (true)
                {
                    if (f > 10000)
                    {
                        f -= 10000;
                    }
                    else
                    {

                    }
                    if (f > 1)
                    {
                        f -= 1;
                    }
                    else
                    {
                        break;
                    }
                }
                if (f < 0.000001)
                {
                    f = 0;
                }
                string fstrtemp = f.ToString();
                string fstrtemp1 = fstrtemp.Substring(1);
                Console.WriteLine(d + " " + r + " " + d + fstrtemp1);
            }
            else
            {
                Console.WriteLine(d + " " + r + " " + d);
            }
        }
    }
}



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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000007LL
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(i=a;i<=b;i++)

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

ll mypow(ll a, ll b) { if(b == 0) return 1; ll temp=mypow(a,b/2); temp=(temp*temp)%INF; if(b%2 == 1) temp=(a*temp)%INF; return temp; }
int mygcd(int a, int b) { if(b==0) return a; return mygcd(b,a%b); }
int cntBits(ll a) { int ret=0; while(a>0) { ret++; a/=2; } return ret; }

int main()
{
	ios::sync_with_stdio(0);
	int tt=1,tcase; 
	//cin >> tt;
	rep(tcase,1,tt)
	{
		int n,ans=0; cin >> n;
		vi v1,v2;
		for(int i=0;i<n;i++) { int val; cin >> val; v1.pb(val); v2.pb(val); }
		sort(all(v1)); 
		sort(all(v2));
		for(int i=1;i<n;i++) v1[i]=mygcd(v1[i],v1[i-1]);
		for(int i=n-2;i>=0;i--) v2[i]=mygcd(v2[i],v2[i+1]);
		ans=max(ans, v2[1]);
		ans=max(ans, v1[n-2]);
		for(int i=1;i<n-1;i++) ans=max(ans, mygcd(v1[i-1], v2[i+1]));
		cout << ans << "\n";
	}
	return 0;
}


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

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

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

#define INF 1e16
#define mod 1000000007

ll n,k;
ll a[100010];
ll cnt[41];

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

  cin>>n>>k;
  rep(i,n){
    cin>>a[i];
    rep(j,40)if((a[i]>>j)&1LL)cnt[j]++;
  }

  ll res=0;
  rep(i,n)res+=a[i];
  ll ksum=0;
  rep(i,n)ksum+=k^a[i];
  maxch(res,ksum);
  rep(i,40){
    if((k>>i)&1LL){
      ll sum=0;
      rep(j,i){
        sum+=(1LL<<j)*max(cnt[j],n-cnt[j]);
      }
      sum+=(1LL<<i)*(cnt[i]);
      repl(j,i+1,40){
        if((k>>j)&1LL) sum+=(1LL<<j)*(n-cnt[j]);
        else sum+=(1LL<<j)*cnt[j];
      }
      maxch(res,sum);
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef unsigned long long ll;
const int maxn = 100005;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  for(int i=1;i<s.size();i++)
    if(s[i]==s[i-1]){
      cout<<"Bad"<<endl;
      return 0;
    }
  cout<<"Good"<<endl;
  return 0;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(void){
    int n;
    cin >> n;
    if(n < 10) cout << n << endl;
    else if(10 <= n && n < 100) cout << 9 << endl;
    else if(100 <= n && n < 1000) cout << 9 + (n-100+1) << endl;
    else if(1000 <= n && n < 10000) cout << 9 + 900<< endl;
    else if(10000 <= n && n < 100000) cout << 9 + 900 + (n-10000+1) << endl;
    else if(100000 <= n) cout << 9 + 900 + 90000 << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test(t) int t;cin>>t;while(t--)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define rforn(i,b,a) for(int i=b-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl;

const int MOD = 1e9+7,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{
	ll n;
	cin>>n;
	if(n%2) cout<<0<<endl;
	else
	{
		n/=2;
		ll x=0;
		while(n)
		{
			x+=n/5;
			n/=5;
		}
		cout<<x<<endl;
	}
	
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int p, q;
	while(cin >> p)
	{
		cin >> q;
		vector<P> Vec;
		int pos = 0;
		p *= 10;
		bool circulation_flag = true;
		while(true)
		{
			if(p % q == 0)
			{
				circulation_flag = false;
				Vec.push_back(P(p / q, p % q));
				break;
			}
			else
			{
				P Pair(p / q, p % q);
				int n = Vec.size();
				for(int i = 0; i < n; ++i)
				{
					if(Vec[i].first == Pair.first && Vec[i].second == Pair.second)
					{
						pos = i;
						goto NEXT;
					}
				}
				Vec.push_back(Pair);
				p = p - p / q * q;
				p *= 10;
			}
		}
NEXT:
		if(circulation_flag)
		{
			int n = Vec.size();
			for(int i = 0; i < n; ++i)
			{
				cout << Vec[i].first;
			}
			cout << endl;
			for(int i = 0; i < pos; ++i)
			{
				cout << " ";
			}
			for(int i = pos; i < n; ++i)
			{
				cout << "^";
			}
			cout << endl;
		}
		else
		{
			int n = Vec.size();
			for(int i = 0; i < n; ++i)
			{
				cout << Vec[i].first;
			}
			cout << endl;
		}
	}
}

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

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

int main(){
  long long H;
  cin >> H;
  
  int count = 0;
  
  while(H > 1){
    H = H/2;
    count++;
  }
  
  long long sum=0;
  
  for(int i=0;i<=count;i++){
    sum += pow(2,i);
  }
  
  cout << sum << endl;
    
}

Measured memory_bytes: 256
//c.c C-Modulo Summation
#include<stdio.h>

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

    for(int i=0;i<n;++i){
        ans += a[i]-1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<utility>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<long long>ca(N);
  vector<pair<long long, int>>ha(M);
  for (int i = 0; i < N; i ++) cin >> ca[i];
  sort(ca.begin(), ca.end());
  for (int i = 0; i < M; i ++) {
    int a;
    long long b;
    cin >> a >> b;
    ha[i] = make_pair(b, a);
  }
  sort(ha.begin(), ha.end());
  //for (int i = 0; i < M; i ++) cout << ha[i].first << ' ' << ha[i].second << endl;
  int j = M - 1;
  for (int i = 0; i < N;) {
    bool ok = true;
    int b = ha[j].second;
    long long a = ha[j].first;
    for (int k = 0; k < b; k ++) {
      if (ca[i + k] > a || i + k >= N) {
        ok = false;
        break;
      }
      ca[i + k] = a;
    }
    if (!ok) break;
    i += b;
    j --;
  }
  long long ans = 0;
  for (int i = 0; i < N; i ++) {
    //cout << ca[i] << endl;
    ans += ca[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n;

string s;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s;
    int n = s.size();
    s = " " + s;
    bool flag0 = true;
    for (int i = 1; i <= n / 2; ++ i)
        if (s[i] != s[n - i + 1]) flag0 = false;
    bool flag1 = true;
    for (int i = 1; i <= (int) (n / 2) / 2; ++ i)
        if (s[i] != s[(int)(n / 2) - i + 1]) flag1 = false;
    bool flag2 = true;
    for (int i = (n + 3) / 2; i <= n; ++ i)
        if (s[i] != s[n - i + 1]) flag2 = false;
    if (flag0 && flag1 && flag2) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#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;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, c;
    cin >> n >> c;
    vector<P> g[31], h[31];
    int d[100010] = {};
    rep(i, 0, n){
        int s, t, ch;
        cin >> s >> t >> ch;
        ch--;
        g[ch].push_back(P(s, t));
    }
    rep(i, 0, c){
        sort(all(g[i]));
        if(g[i].size() == 0) continue;
        int r = g[i][0].second;
        int l = g[i][0].first;
        g[i].push_back(P(INF, INF));
        rep(j, 1, g[i].size()){
            if(g[i][j].first == r){
                r = g[i][j].second;
            }else{
                d[l - 1]++;
                d[r]--;
                l = g[i][j].first;
                r = g[i][j].second;
            }
        }
    }
    int ans = d[0];
    rep(i, 1, 100010){
        d[i] += d[i - 1];
        chmax(ans, d[i]);
    }
    cout << ans << endl;
}

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

int keta(int x) {
  int tmp = 0;
  while (x > 0) {
    tmp += x % 10;
    x /= 10;
  }
  return tmp;
}

int main() {
  int n;
  cin >> n;
  int ans = 100000000;
  for (int i = 1; i < n; i++) {
    ans = min(keta(i) + keta(n - i), ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);
//lli t;
//cin>>t;
//while(t--){
    lli n;
    cin>>n;
    vector<lli> arr(n),store(n);
    for(lli i=0;i<n;i++){
        cin>>arr[i];
    }
    store[0]=arr[0]%mod;
    for(lli i=1;i<n;i++){
        store[i]=(arr[i]+store[i-1])%mod;
    }
    lli ans=0;
    for(lli i=1;i<n;i++){
        ans=(ans+store[i-1]*arr[i])%mod;
    }
    cout<<ans<<endl;
//}
return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

// 二分累乗 O(funcの計算量*logE)
template<typename T>
T binpow(T x, int e, auto func=[](T a, T b){return a*b%MOD;}, T d=1) {
  T ret = d, p = x;
  while(e > 0) {
    if(e%2 == 0) {p = func(p, p); e /= 2;}
    else {ret = func(ret, p); e--;}
  }
  return ret;
};

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

  int n;
  cin >> n;
  vector<int> x(n);
  REP(i, n) cin >> x[i];
  int m, k;
  cin >> m >> k;
  vector<int> a(m);
  REP(i, m) cin >> a[i], a[i]--;

  // iがjについて反転
  // (x[i] + x' ) / 2 = x[j]
  // x' = 2x[j] - x[i]
  // aが反転するなら
  // E[x'] = E[2x[a-1]-x[a]]/2 + E[2x[a+1]-x[a]]/2 = E[x[a-1]] + E[x[a+1]] - E[x[a]]
  // xについて差分をとった数列dxを用意すると上の操作は swap(dx[a-1], dx[a]) となる
  // 1セット分の運動は置換として考えられる
  // K回置換は二分累乗のようにするとO(NlogK)でできる

  // 置換の積
  auto func = [&](vector<int> v1, vector<int> v2) {
    vector<int> ret(v1.size());
    REP(i, v1.size()) ret[i] = v2[v1[i]];
    return ret;
  };

  // 1セット分の置換
  vector<int> p(n-1), d(n-1);
  REP(i, n-1) d[i] = p[i] = i;
  REP(i, m) swap(p[a[i]-1], p[a[i]]);
  // 二分累乗でKセット分を計算
  auto ret = binpow<vector<int>>(p, k, func, d);
  // 差分を計算
  vector<int> dx(n-1), dy(n-1);
  FOR(i, 1, n) dx[i-1] = x[i] - x[i-1];
  // 置換に従ってswapして累積和
  vector<int> ans(n);
  ans[0] = x[0];
  REP(i, n-1) ans[i+1] = ans[i] + dx[ret[i]]; 

  REP(i, n) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 8924
/*input
11 10 9

*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
void solve()
{
	lld a,b,n;
	cin >> a >> b >> n;
	lld st=min(b-1,n);
	lld ans=a*st/b;
	ans=max(ans,(a*n)/b-a*(n/b));
	cout << ans << endl;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 3652
x,n = map(int, input().split())
if n ==0:
  print(x)
if n != 0:
  i = list(map(int, input().split()))


  
  if x not in i:
    print(x)
  
  else:
    p = 1
    while True:
      z = x - p
      if z not in i:
        print(z)
        break
        
      z = x + p
      if z not in i:
        print(z)
        break
        
      p = p +1

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
    int n,m,l,r;
    long long ans,k,a[200010]={};
int main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    l=1;r=2;
    k=a[l];
    ans=0;
    while (r<=n)
    {
        if ((k^a[r])==k+a[r])
        {
            k+=a[r];
            r++;
        }
        else
        {
            k-=a[l];
            ans+=(r-l);
            l++;
        }
    }
    m=r-l;
    for (;m>=0;m--)
        ans+=m;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;

/*
const int MAX_E=2*(100-1);
const int MAX_V=100;
const long long int INF=100000000;
struct edge { int from,to,cost;};
edge es[MAX_E];
//int d[MAX_V];
int V,E;
void shortest_path(int s,int e,vector<int>& d);
int main(){
	int n,k;
	while(cin >> n >> k&&n!=0&&k!=0){
		int V=n;
		int E=2*(n-1);
		vector<int> land(V);
		int l=0;
		for(int i=0; i<E; ++i){
			es[i].cost=-1;
			es[i].from=-1;
			es[i].to=-1;
		}
		for(int i=0; i<k; ++k){
			int m;
			cin >> m;
			if(m==0){
				int a,b;
				cin >> a >> b;
				shortest_path(a,b,land);
				cout << land[b] << "\n";
			} else if(m==1){
				int c,d,e;
				cin >> c >> d >> e;
				es[l].from=c;
				es[l].to=d;
				es[l].cost=e;
				es[l+1].from=d;
				es[l+1].to=c;
				es[l+1].cost=e;
				l+=2;
			}
		}
	}
	return 0;
}

void shortest_path(int s,int e,vector<int>& d){
	cout << "ok1\n";
	for(int i=0; i<V; ++i) {
		cout << "ok\n";
		d[i]=INF;
	}
	d[s]=0;
	while(true){
		cout << "ok2\n";
		bool update=false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
}
*/

const int INF=100000000;
int main(){
	int n;
	while(cin >> n&&n!=0){
		vector<int> color;
		for(int i=0; i<n; ++i){
			int t;
			cin >> t;
			color.push_back(t);
		}
		int maxDel=INF;
		for(int i=0; i<n; ++i){
			for(int j=1; j<=3; ++j){
				if(color[i]==j) continue;
				int up=i-1;
				int down=i+1;
				int sum=0;
				int c=1;
				bool first=true;
				int col=j;
				while(1){
					int nCal=-1;
					while(1){
						if(up<0) break;
						if(color[up]!=col){
							nCal=color[up];
							break;
						}
						up--;
						c++;
					}
					while(1){
						if(down>=n) break;
						if(color[down]!=col){
							if(nCal==-1) nCal=color[down];
							break;
						}
						++down;
						++c;
					}
					if(c>=4){
						sum+=c;
					} else{
						break;
					}
					c=0;
					if(nCal==-1){
						break;
					}else{
						col=nCal;
					}
				}
				maxDel=min(maxDel,n-sum);
			}
		}
		cout << maxDel << "\n";
	}
	return 0;
}

Measured memory_bytes: 1320
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/* define */
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define REP(i, n) for ( int i = 0; i < (n) ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}

/* main */
int n, s = 0, c[5] = {}, visit[5] = {};
ll ans = 0;
void com(int x) {
	if (s == 3) {
		ll m = 1;
		REP(i, 5) if (visit[i] == 1) m *= c[i];
		ans += m;
		return;
	}
	for(int i = x; i < 5; i++) {
		if (visit[i] == 0) {
			visit[i]++;
			s++;
			com(i);
			visit[i]--;
			s--;
		}
	}
	return;
}

int main() {
	char a[11];
	scanf("%d%*c", &n);
	REP(i, n) {
		scanf("%s", a);
		if (a[0] == 'M')c[0]++;
		if (a[0] == 'A')c[1]++;
		if (a[0] == 'R')c[2]++;
		if (a[0] == 'C')c[3]++;
		if (a[0] == 'H')c[4]++;
	}
	com(0);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
vector<int> G[105],rG[105];
vector<int> vs;
int N;
bool used[105];
int cmp[105];
vector<int> cmp_v[105];
bool Gmat[105][105];
double p[105];
double q[105];
int in[105];
void add_edge(int from,int to){
	//cout << from << ' ' << to << endl;
	G[from].pb(to);
	rG[to].pb(from);
	return;
}
void dfs(int v){
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]])dfs(G[v][i]);
	}
	vs.pb(v);
}
void rdfs(int v,int k){
	used[v]=true;
	cmp[v]=k;
	cmp_v[k].pb(v);
	for(int i=0;i<rG[v].size();i++){
		if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
}
int scc(){
	memset(used,false,sizeof(used));
	vs.clear();
	for(int i=0;i<N;i++){
		if(!used[i])dfs(i);
	}
	/*for(int i=0;i<vs.size();i++){
		cout << vs[i] <<  ' ';
	}
	cout << endl;*/
	memset(used,false,sizeof(used));
	int k = 0;
	for(int i=vs.size()-1;i>=0;i--){
		if(!used[vs[i]])rdfs(vs[i],k++);
	}
	return k;
}
bool conn(int a,int b){
	for(int i=0;i<cmp_v[a].size();i++){
		for(int j=0;j<cmp_v[b].size();j++){
			int u = cmp_v[a][i];
			int v = cmp_v[b][j];
			if(Gmat[u][v])return true;
		}
	}
	return false;
}
void dump(){
	for(int i=0;i<N;i++){
		cout << cmp[i] << endl;
	}
}
bool solve(){
	cin >> N;
	if(N==0)return false;
	memset(Gmat,false,sizeof(Gmat));
	memset(in,0,sizeof(in));
	memset(cmp,0,sizeof(cmp));
	for(int i=0;i<105;i++){
		G[i].clear();
		rG[i].clear();
		cmp_v[i].clear();
	}
	for(int i=0;i<N;i++){
		cin >> p[i];
		int m;
		cin >> m; 
		for(int j=0;j<m;j++){
			int to;
			cin >> to;
			to--;
			Gmat[i][to]=true;
			add_edge(i,to);
		}
	}
	int K = scc();
	for(int i=0;i<K;i++){
		double res = 1.0;
		for(int j=0;j<cmp_v[i].size();j++){
			res *= p[cmp_v[i][j]];
		}
		q[i] = 1.0-res;
	}		
	for(int i=0;i<K;i++){
		for(int j=0;j<K;j++){
			if(i==j)continue;
			if(conn(j,i))in[i]++;
		}
	}
	double ans = 1.0;
	for(int i=0;i<K;i++){
		if(in[i]==0){
			ans *= q[i];
		}
	}
	//dump();
	printf("%.12f\n",ans);

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


Measured memory_bytes: 3428
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
d=[int(i) for i in input().split()]
for i in range(1,100001):
    if i<n:
        continue
    now=str(i)
    for j in now:
        if int(j) in d:
            break
    else:
        print(now)
        sys.exit()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000000
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
ll t,n,m,k,z,x,c,s;
int main()
{
    fast;
    cin>>n>>k>>s;
    for(int i=1;i<=k;i++)cout<<s<<" ";
    for(int j=k+1;j<=n;j++)cout<<(s+1)%mod<<" ";
    cout<<endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n-1; i >= 0; i--)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd2(i, s, n) for (ll i = n-1; i >= (s); i--)

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) {
        rep(j, 26) cin >> s[i][j];
    }

    vector<int> t(d);
    rep(i, d) cin >> t[i];

    vector<int> prev(26, -1);
    int ans = 0;
    rep(i, d){
        ans += s[i][t[i]-1];
        prev[t[i]-1] = i;
        rep(j, 26){
            ans -= c[j] * (i - prev[j]);
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3568
n = int(input())

xy_sum = []
xy_dif = []
for i in range(n) :
    x, y = map(int, input().split())
    xy_sum.append(x + y)
    xy_dif.append(x - y)

print(max(abs(max(xy_sum) - min(xy_sum)), abs(max(xy_dif) - min(xy_dif))))

Measured memory_bytes: 24760
#include <bits/stdc++.h>
#define rep(i, k) for(int i = 0; i < k; i++)
using namespace std;
int main() {
    int n, k, q;
    int enter;
    cin >> n >> k >> q;
    int a[n];
    rep(i, n) a[i] = k;
    rep(i, q) {
        cin >> enter;
        a[enter - 1] += 1;
    }
    rep(i, n) a[i] -= q;
    rep(i, n) {
        if(a[i] <= 0)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
# 素朴に実装
N, M, Q = [int(i) for i in input().split()]
B = [[0, 0, 0, 0] for i in range(Q)]
for i in range(Q):
    B[i][0], B[i][1], B[i][2], B[i][3] = [int(j) for j in input().split()]
MAXC = [0]

def dfs(A, pre):
    # 終端条件 --- 10 重ループまで回したら処理して打ち切り
    if len(A) == N:
        counter = 0
        for i in range(Q):
            if A[B[i][1]-1] - A[B[i][0]-1] == B[i][2]:
                counter += B[i][3]
        if MAXC[0] < counter:
            MAXC[0] = counter
        return 
    for v in range(pre, M+1):
        A.append(v)
        dfs(A, v)
        A.pop() 
dfs([], 1)
print(MAXC[0])

Measured memory_bytes: 78464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        init(n, m);
        for (int i = 0; i < m; i++) {
            int x = nextInt() - 1;
            int y = nextInt() - 1;
            addEdge(x, y, i);
        }
        int[][] zz = new int[n][n];
        boolean[] g = new boolean[n];
        for (int i = 0; i < n; i++) {
            z = zz[i];
            Arrays.fill(z, -1);
            if (dfs(i, m)) {
                g[i] = true;
            }
        }
        int res = 0;
        for (int i = 0; i < n; i++) if (g[i]) {
            for (int j = i + 1; j < n; j++) if (g[j]) {
                boolean ok = true;
                for (int k = 0; k < n; k++) {
                    if (zz[i][k] >= 0 && zz[j][k] >= 0) {
                        ok = false;
                    }
                }
                if (ok) res++;
            }
        }
        out.println(res);
    }


    void init(int n, int m) {
        m *= 2;
        this.n = n;
        this.m = m;
        last = 0;
        head = new int[n];
        nx = new int[m];
        dst = new int[m];
        src = new int[m];
        tm = new int[m];
        Arrays.fill(head, -1);
    }

    void addEdge(int x, int y, int time) {
        nx[last] = head[x];
        src[last] = x;
        dst[last] = y;
        tm[last] = time;
        head[x] = last;
        last++;
        nx[last] = head[y];
        src[last] = y;
        dst[last] = x;
        tm[last] = time;
        head[y] = last;
        last++;
    }

    private boolean dfs(int x, int time) {
        if (z[x] != -1) return false;
        z[x] = time;
        int j = head[x];
        while (j >= 0) {
            int y = dst[j];
            if (tm[j] < time) {
                if (!dfs(y, tm[j])) {
                    return false;
                }
            }
            j = nx[j];
        }
        return true;
    }

    int n, m;
    int[] head;
    int[] nx;
    int[] src;
    int[] dst;
    int[] tm;
    int[] z;
    int last;


    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 45092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ATUI, SAMUI;
  string YUNI, KUROE = "#";
  vector<string> OOT(200);
  
  cin >> ATUI >> SAMUI;
  
  for(int JNY =0; JNY < ATUI; JNY++){
    cin >> OOT.at(JNY);
  }
  
  for(int JNY =0; JNY < SAMUI + 2; JNY++){
    YUNI += '#';
  }
  
  cout << YUNI << endl;
  for(int JNY =0; JNY < ATUI; JNY++){
    cout << KUROE + OOT.at(JNY) + KUROE << endl;
  }
  cout << YUNI << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int S=sc.nextInt();
        int h=S/3600;
        int m=(S-h*3600)/60;
        int s=S-(h*3600+m*60);
        System.out.println(h+":"+m+":"+s);
    }
}

Measured memory_bytes: 17220