akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
from copy import deepcopy
import queue

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

d1_nums = [int(x) for x in stdin.readline().rstrip().split()]
d2_nums = [int(x) for x in stdin.readline().rstrip().split()]
if set(d1_nums) != set(d2_nums):
    print("No")

d1 = Dice(d1_nums)
d2 = Dice(d2_nums)

# TとSに対応するクエリを記憶し, resをすぐに呼び出せるようにする
memo = [[False] * 7 for i in range(7)]
memo[d1.pos["T"]][d1.pos["S"]] = ""

# クエリとさいころd1の状態を記憶
res = {}
for j in ["T", "S", "E"]:
    if d1.labels[d1.pos[j]] != d2.labels[d2.pos[j]]:
        break        
    else:
        res[memo[d1.pos["T"]][d1.pos["S"]]] = d1

# BFSで探索, 今回は目の数字が同一である可能性があるため全探索
# ただし, T, S, Eがd2と同一のもののみresに登録
# diceの中身をいじってはならない
def solve(dice=d1):
    que = queue.Queue()
    que.put(dice)
    sol_q = ["E", "N", "S", "W"]
    
    while not que.empty():
        d = que.get()
        for i in sol_q:
            d_next = Dice.rolled(d, i)
            if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                que.put(d_next)
                memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                for j in ["T", "S", "E"]:
                    if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                        break
                else:
            	    res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next
    else:
        return True

solve()
check_pos = ["N", "W", "B"]
if len(res) == 0:
	print("No")
else:
    for k, v in res.items():
        for i in check_pos:
            if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                break
        else:
            print("Yes")
            break
    else:
        print("No")


Measured memory_bytes: 7056
#include <bits/stdc++.h>
int main(){
  int a=0, b=0;
	std::cin >> a >> b;
  int product = 0;
  product = a * b;
  if(product%2 == 0) std::cout << "Even" << std::endl;
  else std::cout << "Odd" << std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		int length = b - a + 1;
		if((length + 1) / 2 <= k) {
			for(int i = a ; i <= b ; i++) {
				System.out.println(i);
			}
		} else {
			for(int i = a ; i - a < k ; i++) {
				System.out.println(i);
			}
			for(int i = b - k + 1 ; i <= b ; i++) {
				System.out.println(i);
			}
		}
	}
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
int tot[26];
signed main(){
	string ss;cin>>ss;int n=ss.size(),s=0;
	for(register int i=0;i<n;i++)tot[ss[i]-'a']++,s++;
	long long ans=1ll*s*(s-1)/2;for(register int i=0;i<26;i++)ans-=1ll*tot[i]*(tot[i]-1)/2;printf("%lld\n",ans+1);
	return 0;
}

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

int main()
{
    int x, y;
    cin >> x >> y;
    if ((y - 2 * x) % 2 == 0 && (4 * x - y) % 2 == 0 && (y - 2 * x) >= 0 && (4 * x - y) >= 0)
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }

}

use std::cmp::{max, min};

fn main() {
    let n: i64 = read();
    let ans: f64 = (((n - 1) / 2) + 1) as f64 / n as f64;


    if n % 2 == 0 {
        println!("{}", 0.5)
    } else {
        println!("{}", ans)
    }

}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void) {
	int a,b;
	
	scanf("%d %d", &a,&b);
	
	if (a>0)
		printf("Positive\n");
	else if (b<0 && (b-a+1)%2==0)
		printf("Positive\n");
	else if (b<0 && (b-a+1)%2==1)
		printf("Negative\n");
	else
		printf("Zero\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000000
#define ll long long

#define maxn 205

int n;
char e[maxn][maxn];
int used[maxn];

int bfs(int s)
{
    memset(used, 0, sizeof(used));
    used[s] = 1;
    queue<int> q;
    q.push(s);
    int res = 1;
    while (!q.empty())
    {
        int now = q.front();
        q.pop();
        for (int i = 1; i <= n; i++)
        {
            if (e[now][i] == '0')
                continue;
            if (used[i] == 0)
            {
                used[i] = used[now] + 1;
                res = max(res, used[i]);
                q.push(i);
            }
            else if (abs(used[i] - used[now]) > 1 || used[i] == used[now])
                return -1;
        }
    }
    return res;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%s", e[i] + 1);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int now = bfs(i);
        if (now == -1)
        {
            printf("-1\n");
            return 0;
        }
        ans = max(ans, now);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    long long int x,y;
    scanf("%lld %lld",&x,&y);
    int k=0;
    long long int xx=x;
    if(x%y==0)
    {
        printf("-1");
        return 0;
    }
    while(k==0 && xx<=1000000000000000000)
    {
        if(xx%y!=0)
        {
            k=1;
            printf("%lld",xx);
        }
        xx=xx+x;
    }
    if(k==0)printf("-1");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
vector < pair <pii,pii> > ans;
int h,w,cell[600][600];
int main(){
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>cell[i][j];
        }
    }

    for(int i=1;i<=h;i++){
        if(i%2==1){
            for(int j=1;j<=w;j++){
                if(cell[i][j]%2==1){
                    if(j<w){ans.pb(mp(mp(i,j),mp(i,j+1)));cell[i][j]--;cell[i][j+1]++; }
                    else{
                        if(i<h){
                            ans.pb(mp(mp(i,j),mp(i+1,j)));cell[i][j]--;cell[i+1][j]++;
                        }
                    }
                }
            }
        }
        else{
            for(int j=w;j>=1;j--){
                if(cell[i][j]%2==1){
                    if(j>1){ans.pb(mp(mp(i,j),mp(i,j-1)));cell[i][j]--;cell[i][j-1]++; }
                    else{
                        if(i<h){
                            ans.pb(mp(mp(i,j),mp(i+1,j)));cell[i][j]--;cell[i+1][j]++;
                        }
                    }
                }
            }
        }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
        printf("%d %d %d %d\n",ans[i].ff,ans[i].fs,ans[i].sf,ans[i].ss);
    }


}


Measured memory_bytes: 5360
n = int(input())
s = []

for _ in range(n):
    s.append(input())

s.sort()

max1 = 0
ans = []
tmp = ''
count = 0

for i in s:
    if tmp == i:
        count += 1
    else:
        if max1 > count:
            count = 1
            tmp = i
        elif max1 == count:
            ans.append(tmp)
            count = 1
            tmp = i
        else:
            ans = [tmp]
            max1 = count
            count = 1
            tmp = i

if max1 > count:
    count = 1
    tmp = i
elif max1 == count:
    ans.append(tmp)
    count = 1
    tmp = i
else:
    ans = [tmp]
    max1 = count
    count = 1
    tmp = i

for i in ans:
    print(i)


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

using namespace std;

const int MAXN = 50;
const int MAXS = 500;
const int INF = 1000000010;

int n, x, y;

int a[MAXN];
int b[MAXN];
int c[MAXN];

int dp[MAXN][MAXS][MAXS];

int solve(int i, int sa, int sb)
{
	if( sa < 0 ) return INF;
	if( sb < 0 ) return INF;

	int& ans = dp[i][sa][sb];

	if( ans != -1 ) return ans;

	if( i == 0 )
	{
		if( sa == 0 && sb == 0 ) return ans = 0;
		return ans = INF;
	}

	ans = solve( i - 1 , sa - a[i] , sb - b[i] ) + c[i];
	ans = min( ans , solve( i - 1 , sa , sb ) );

	return ans;
}

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

	for(int i = 1 ; i <= n ; i++)
		scanf("%d %d %d",&a[i],&b[i],&c[i]);

	memset( dp , -1 , sizeof(dp) );

	int ans = INF;

	for(int k = 1 ; k <= 10 ; k++)
	{
		if( x*k >= MAXS || y*k >= MAXS ) continue;
		ans = min( ans , solve( n , x*k , y*k ));
	}

	if( ans == INF ) printf("-1\n");
	else printf("%d\n",ans);
}

Measured memory_bytes: 49024
//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000 * 1000 * 1000 + 7;
ll A[64];

int main() {
	int n; cin >> n;
	for(int i = 0; i < n; i++) {
		ll x; cin >> x;
		for(int bit = 0; bit < 60; bit++)
			if(x & (1ll << bit))
				A[bit] ++;
	}
	int r = 0;
	for(int i = 0; i < 60; i++)
		r = (r + ((A[i] * (n - A[i])) % INF) * ((1ll << i) % INF)) % INF;
	cout << r;
}


Measured memory_bytes: 256
#include <iostream>
int main() {
    int n,b,f,r,v,a[4][3][10] = {};
    scanf("%d", &n);
    while (n--) {
        scanf("%d%d%d%d", &b, &f, &r, &v);
        a[b-1][f-1][r-1] += v;
    }
    for (int i=0; i<4; i++) {
        for (int j=0; j<3; j++) {
            for (int k=0; k<10; k++) {
                printf(" %d", a[i][j][k]);
            }
            puts("");
        }
        if (i != 3) puts("####################");
    }
    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rc(s) return cout<<s,0
ll n,y,a,b,c,d,e,f;
int main(){
    cin >> n >> y;
    if(y%1000!=0) {cout<<"-1 -1 -1"; return 0;}
    y/=1000;
    d=y;
    while(c<=y){
        y-=c;
        e=y;
        while(5*b<=y){
            y-=5*b;
            f=y;

             a=(n-b)-c;
            y-=10*a;
            if(y==0){ cout<<a<<" "<<b<<" "<<c; return 0;}
            b++;
            a=0;
            y=e;
        }
        c++;
        b=0;
        y=d;
    }
    
    
    
    cout<<"-1 -1 -1";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int z = 0, o = 0;
    string s; cin >> s;
    For(i, 0, s.size()) {
        if(s[i] == '0') z++;
        else o++;
    }
    cout << 2 * min(z, o) ;
    

    
    
    
    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll A, B, C;
    cin>>A>>B>>C;
    if(A>B) swap(A, B);
    if(B>C) swap(B, C);
    if(A>B) swap(A, B);
    //cout<<A<<B<<C;
    ll count=C-B;
    A+=count;
    count+=((C-A)%2==0 ? (C-A)/2 : (C-A+1)/2+1);
    cout<<count<<endl;
    return 0;
}


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

int main()
{
	int n;
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		int y, m, d;
		scanf("%d %d %d", &y, &m, &d);
		
		int cnt = 0;
		while (y != 1000 || m != 1 || d != 1){
			d++;
			cnt++;
			if (d == 20 && y % 3 != 0 && m % 2 == 0){
				d = 1;
				m++;
			}
			else if (d == 21 && (y % 3 == 0 || m % 2 == 1)){
				d = 1;
				m++;
			}
			
			if (m == 11){
				m = 1;
				y++;
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{

    public class Program
    {
        const long MOD = 1000000007;
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            string N = cin.Read;
            if(N[0] == '7' || N[1] == '7' || N[2] == '7')
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

        static long Gcd(long p, long q)
        {
            if (p % q == 0) return q;
            return Gcd(q, p % q);
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }

    }
}

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

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    int A;
    for (int i = 0; i < N; i++)
    {
        cin >> A;
        while (0 < A && A % 2 == 0)
        {
            ans++;
            A /= 2;
        }
    }
    cout << ans << endl;
}


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

int main(void) {
  int n, i;
  int a[10002] = {0};
  scanf("%d", &n);
  int x, y, z, aindex;

  for (x = 1; x <= n / 3; x++) {
    for (y = x; y <= n / 3; y++) {
      for (z = y; z <= n / 3; z++) {
        aindex = x * x + y * y + z * z + x * y + y * z + z * x;
        if (aindex > 10001) break;
        if (x == y && y == z) {
          // printf("aindex:%d x=%d, y=%d, z=%d\n", aindex,x,y,z);
          a[aindex] += 1;
        } else if (x == y || y == z || z == x) {
          a[aindex] += 3;
        } else
          a[aindex] += 6;
      }
    }
  }

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

Measured memory_bytes: 1744
n = int(input())
a = list(map(int, input().split()))
ans = 0
while True:
    exist_odd = False
    for d in a:
        if d&1 == 1:
            exist_odd = True
    if exist_odd:
        break
    for i in range(n):
        a[i] //= 2
    ans += 1
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;

signed main() {
    vvll c(3, vll(3));
    
    vvll c2(3, vll(3));
    vll sw(2), sh(2);
    
    string r = "Yes";
    
    rep(i, 3) {
        rep(j, 3) {
            cin >> c[i][j];
        }
            
    }
    
    sw[0] = c[0][1] - c[0][0];
    sw[1] = c[0][2] - c[0][0];
    sh[0] = c[1][0] - c[0][0];
    sh[1] = c[2][0] - c[0][0];
    
    c2[0][0] = c[0][0];
    
    rrep(i, 2) {
        rrep(j, 2) {
            c2[i][j] = c2[0][0] + sh[i-1] + sw[j-1];
            if (c2[i][j] != c[i][j]) r = "No";
        }
    }
    
    mes(r);
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3632
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
    
c = []      
for i in range(n):
    lss = a1[:(i+1)]
    lse= a2[(i):]
    cnt = sum(lss)+sum(lse)
    c.append(cnt)
print(max(c))

Measured memory_bytes: 38512
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  sort(ALL(a));
  map<ll, ll> cnt;
  rep(i, n){
    cnt[a[i]]++;
  }
  vll x;
  for(auto&& e: cnt){
    rep(i, e.second/2) x.emplace_back(e.first);
  }
  sort(ALL(x));
  reverse(ALL(x));
  if(SZ(x) >= 2){
    print(x[0]*x[1]);
  }else{
    print(0);
  }
}


Measured memory_bytes: 7296
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	int N, sumP = 1, sumN = -2, i = 0, beforei = 1;

	cin >> N;

	while (N != 0)
	{
		if ((N <= sumP || N <= pow(-2, i)) && N > 0)
		{
			while (beforei - 1 > i)
			{
				cout << 0;
				beforei--;
			}
			cout << 1;
			beforei = i;
			N -= pow(-2, i);
		}
		else if((N >=  sumN || N >= pow(-2, i + 1)) && N < 0)
		{
			while (beforei - 1 > i + 1)
			{
				cout << 0;
				beforei--;
			}
			cout << 1;
			beforei = i + 1;
			N -= pow(-2, i + 1);
		}
		else
		{
			i += 2;
			sumP += pow(-2, i);
			sumN += pow(-2, i + 1);
			continue;
		}

		sumP = 1;
		sumN = -2;
		i = 0;
	}

	while (beforei > 0)
	{
		cout << 0;
		beforei--;
	}

	cout << endl;
}

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

int main() {
    int d, t, s;
    cin >> d >> t >> s;

    if (d <= t * s)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;

    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;

    for(int i = 0; i < 3; i++){
        if(s[i] == 'a'){
            a = 1;
        }
        if(s[i] == 'b'){
            b = 1;
        }
        if(s[i] == 'c'){
            c = 1;
        }
    }
    if(a == 1 && b == 1 && c == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const long long MOD=1000000007;
const long double Pi=acos(-1);
long long nature(long long a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll mod_pow(ll x,ll y){//x^yを返す//計算量は0(log(y))
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
vector<long long> fact, fact_inv, inv;
void init_nCk(int n){
    fact.resize(n+54);
    fact_inv.resize(n+54);
    inv.resize(n+54);
    fact[0]=1;
    fact[1]=1;
    fact_inv[0]=1;
    fact_inv[1]=1;
    inv[1]=1;
    for(int i=2;i<n+54;i++){
        fact[i]=(fact[i-1]*i)%MOD;
        inv[i]=MOD-(inv[MOD%i]*(MOD/i))%MOD;
        fact_inv[i]=(fact_inv[i-1]*inv[i])%MOD;
    }
}
int nCk(int n,int k){
    return fact[n]*((fact_inv[k]*fact_inv[n-k])%MOD)%MOD;
}
int main(){
  #define int long long
  int N;
  cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  unordered_map<int,int> ma;
  unordered_map<int,int> mb;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    ma[A.at(i)]++;
  }
  for(int i=0;i<N;i++){
    cin>>B.at(i);
    mb[B.at(i)]++;
  }
  int MA=0;
  int MB=0;
  for(auto itr=ma.begin();itr!=ma.end();itr++){
    int a=itr->first;
    int b=itr->second;
    if(MB<b){
      MA=a;
      MB=b;
    }
    if(b+mb[a]>N){
      cout<<"No"<<endl;
      return 0;
    }
  }
  int l=-1,right=-1;
  reverse(B.begin(),B.end());
  queue<int> q;
  for(int i=0;i<N;i++){
    if(A.at(i)==B.at(i)){
      q.push(i);
    }
  }
  int S=q.size();
  for(int i=0;i<S;i++){
    int t=q.front();
    q.pop();
    if(i<S/2){
      int m1=B.at(i);
      int m2=B.at(t);
      B.at(i)=m2;
      B.at(t)=m1;
    }
    else{
      int m1=B.at(N-(i-S/2)-1);
      int m2=B.at(t);
      B.at(N-(i-S/2)-1)=m2;
      B.at(t)=m1;
    }
  }
  int Q=-1;
  int check=0;
  for(int i=0;i<N;i++){
    if(A.at(i)==B.at(i)){check++;}
  }
  if(check==0){
  cout<<"Yes"<<endl;
  for(int i=0;i<N;i++){
    cout<<B.at(i)<<" ";
  }
  cout<<endl;
    return 0;
  }
  for(int i=0;i<N;i++){
    if(A.at(i)==B.at(i)){
      Q=i;
    }
  }
  int W=A.at(Q);
  for(int i=0;i<N;i++){
    if(A.at(i)!=W && B.at(i)!=W){
      int mm1=B.at(i);
      int mm2=W;
      B.at(i)=W;
      B.at(Q)=mm1;
    }
  }
  cout<<"Yes"<<endl;
  for(int i=0;i<N;i++){
    cout<<B.at(i)<<" ";
  }
  cout<<endl;
}

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

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

    int a[n][m], b[m];
    
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
            cin >> a[i][j];
    
    for (int i=0; i<m; i++) cin >> b[i];
    
    for (int i=0; i<n; i++){
        int c=0;
        for (int j=0; j<m; j++)
            c += a[i][j]*b[j];
        cout << c << endl;
    }
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < n; i++) {
        if (a[i] - a[i - 1] > 1) {
            cout << -1;
            return 0;
        }
    }
    if (a[0] != 0) {
        cout << -1;
        return 0;
    }
    long long result = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1] + 1) {
            result++;
        } else {
            result += a[i];
        }
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    long long n,k,l,m;
    cin>>n>>k;
    l=n%k;
    m=k-l; 
    if(m<=l)
    {
        cout<<m<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define MAX_N 1000
#define INF 0x3f3f3f3f

ll N;

int main()
{
	while (~scanf("%lld", &N)) {
		int m = N % 10;
		int t = 1;
		N /= 10;
		while (N) {
			int n = N % 10;

            if (n == m) {
				t++;
                if (t >= 3) break;
            } else {
            	t = 1;
            	m = n;
            }
			N /= 10;
		}
		if (t >= 3) {
			puts("Yes");
		}else {
			puts("No");
		}
	}
    return 0;
}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, m;

vector<int> v[100005];

bool is_bipartite = true;
int col[100005];

void dfs(int id, int c){
	col[id] = c;
	for(auto to: v[id]){
		if(col[to] == -1){
			dfs(to, 1 - c);
		}
		else{
			if(col[id] == col[to]){
				is_bipartite = false;
			}
		}
	}
	return;
}

int main(){
	scanf("%d %d", &n, &m);
	FI(i, 1, m){
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	memset(col, -1, sizeof(col));
	dfs(1, 0);
	if(is_bipartite){
		int cnt = 0;
		FI(i, 1, n) if(col[i] == 0) cnt++;
		printf("%lld\n", 1LL * cnt * (n - cnt) - m);
	}
	else{
		printf("%lld\n", 1LL * n * (n - 1) / 2 - m);
	}
	return 0;
}


Measured memory_bytes: 6912
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 1e-8;

vector<int> split(string delim,string str){
	vector<int> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find(delim) != string::npos){
				int num = atoi(str.substr(i,j-1).c_str());
				if(str.substr(i,j-1).size() >0 ) res.push_back(num);
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

int main(){
	string str;
	while(getline(cin,str)){
		vector<int> data = split(" ",str);
		if(data.size()==1 && data[0]==0) break;
		set<int>* dp = new set<int>[data.size()+1]; 

		dp[0].insert(0);
		for(int i=0;i<data.size();i++){
			if(data[i] == 1){
				for(set<int>::iterator it = dp[i].begin(); it != dp[i].end(); it++){
					dp[i+1].insert(*it+1);
					dp[i+1].insert(*it+11);
				}
			}
			else if(2 <= data[i] && data[i] <= 9){
				for(set<int>::iterator it = dp[i].begin(); it != dp[i].end(); it++){
					dp[i+1].insert(*it+data[i]);
				}
			}
			else{
				for(set<int>::iterator it = dp[i].begin(); it != dp[i].end(); it++){
					dp[i+1].insert(*it+10);
				}
			}
		}

		int res=MAX_N;
		for(set<int>::iterator it = dp[data.size()].begin(); it != dp[data.size()].end(); it++){
			if(*it <= 21 && abs(*it-21) < abs(res-21)){
				res = * it;
			}
		}

		printf("%d\n",res == MAX_N ? 0 : res);
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

int n;

int main()
{
	while (cin >> n, n){
		vector<pair<int, int> > v;
		rep(i, n){
			int m, a, b;
			cin >> m >> a >> b;
			v.push_back(make_pair(a, m));
			v.push_back(make_pair(b, -m));
		}
		sort(v.begin(), v.end());
		bool res = true;
		int s = 0;
		rep(i, n * 2){
			s += v[i].second;
			if (s > 150) res = false;
		}
		cout << (res ? "OK" : "NG") << endl;
	}
}

Measured memory_bytes: 1196
n = int(input())
s = input()
r,g,b =0,0,0
ls = len(s)
for i in range(ls):
    if s[i]=='R':
        r+=1
    elif s[i]=='G':
        g+=1
    elif s[i]=='B':
        b+=1
cnt =0
for j in range(1,ls-1):
    for i in range(j):
        k = 2*j-i
        if k<ls:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                cnt+=1
print(r*g*b-cnt)


Measured memory_bytes: 9192
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	int n, i, j = 0;
	double p;
	cin >> n;
	for(i = 1; i <= n;i+=2){
		j++;
	}
	p = 1.0 * j / n;
	cout << fixed << setprecision(10) << p;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split(' '))
p = 10**9+7


def mod_inv(n, i):

    ans = n**5 % p
    
    while(1):
        n %= p

        if i == 1:
            break
        elif i % 2 == 0:
            i /= 2
            n **= 2
        elif i % 5 == 0:
            i /= 5
            n **= 5
            
    return n * ans % p

    
def nPr(n, r):
    ans = 1
    for i in range(n, n-r, -1):
        ans *= i

    return ans % p


for r in range(1,K+1):
    R = N-K
    fR = R - (r - 1)

    if fR < 0:
        print(0)
        continue
    ao = nPr(K-1,r-1) * mod_inv(nPr(r-1,r-1), p-2-5) % p
    aka = nPr(fR+r, fR+r) * mod_inv(nPr(fR,fR), p-2-5) * mod_inv(nPr(r,r), p-2-5) % p

    ans = int(ao * aka % p)

    print(ans)




Measured memory_bytes: 3316
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 1000000007;
/*
2000000011 is prime
2000000033 is prime
*/

ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];
bool dp[500005];

int main(){
    cin >> a >> b;
    p((b - 1 + a - 1 - 1) / (a - 1));
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>

char buffer[4567890];
int buffer2[1234567];

int H, W, K;
int x1, y1, x2, y2;
char* c[1234567];
int* cost[1234567];

int qs, qe;
int q[1234567][2];

int main(void) {
	int i;
	if (fgets(buffer, sizeof(buffer), stdin) == NULL) return 1;
	if (sscanf(buffer, "%d%d%d", &H, &W, &K) != 3) return 1;
	if (fgets(buffer, sizeof(buffer), stdin) == NULL) return 1;
	if (sscanf(buffer, "%d%d%d%d", &x1, &y1, &x2, &y2) != 4) return 1;
	for (i = 0; i < H; i++) {
		c[i] = &buffer[(W + 3) * i];
		cost[i] = &buffer2[W * i];
		if (fgets(c[i], W + 3, stdin) == NULL) return 1;
	}
	q[0][0] = x1 - 1;
	q[0][1] = y1 - 1;
	cost[x1 - 1][y1 - 1] = 1;
	qs = 0;
	qe = 1;
	while (qs < qe) {
		int cy = q[qs][0], cx = q[qs][1];
		int cc = cost[cy][cx];
		qs++;
		for (i = 1; i <= K && cx - i >= 0 && c[cy][cx - i] != '@' && (cost[cy][cx - i] == 0 || cost[cy][cx - i] > cc); i++) {
			if (cost[cy][cx - i] == 0) {
				q[qe][0] = cy;
				q[qe][1] = cx - i;
				qe++;
			}
			cost[cy][cx - i] = cc + 1;
		}
		for (i = 1; i <= K && cx + i < W && c[cy][cx + i] != '@' && (cost[cy][cx + i] == 0 || cost[cy][cx + i] > cc); i++) {
			if (cost[cy][cx + i] == 0) {
				q[qe][0] = cy;
				q[qe][1] = cx + i;
				qe++;
			}
			cost[cy][cx + i] = cc + 1;
		}
		for (i = 1; i <= K && cy - i >= 0 && c[cy - i][cx] != '@' && (cost[cy - i][cx] == 0 || cost[cy - i][cx] > cc); i++) {
			if (cost[cy - i][cx] == 0) {
				q[qe][0] = cy - i;
				q[qe][1] = cx;
				qe++;
			}
			cost[cy - i][cx] = cc + 1;
		}
		for (i = 1; i <= K && cy + i < H && c[cy + i][cx] != '@' && (cost[cy + i][cx] == 0 || cost[cy + i][cx] > cc); i++) {
			if (cost[cy + i][cx] == 0) {
				q[qe][0] = cy + i;
				q[qe][1] = cx;
				qe++;
			}
			cost[cy + i][cx] = cc + 1;
		}
	}
	printf("%d\n", cost[x2 - 1][y2 - 1] - 1);
	return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int t = sc.nextInt();
			int p = sc.nextInt();
			int r = sc.nextInt();
			if (t+p+r==0) {
				break;
			}
			Team[] teams = new Team[t];
			for(int i=0;i<t;i++) {
				teams[i] = new Team(i, p);
			}
			for(int i=0;i<r;i++) {
				int tid = sc.nextInt()-1;
				int pid = sc.nextInt()-1;
				int time = sc.nextInt();
				String message = sc.next();
				if (message.equals("WRONG")) {
					teams[tid].wrong(time, pid);
				}else{
					teams[tid].correct(time, pid);
				}
			}
			Arrays.sort(teams);
			for(int i=0;i<t;i++) {
				System.out.println(teams[i]);
			}
		}
	}

}
class Team implements Comparable<Team>{
	int id;
	int ac = 0;
	int penalty = 0;
	int[] wa;
	public Team(int id,int problemnum) {
		this.id = id;
		wa = new int[problemnum];
	}
	public void correct(int time,int id) {
		ac++;
		penalty += wa[id] * 1200 + time;
	}
	public void wrong(int time,int id) {
		wa[id]++;
	}
	public int compareTo(Team o) {
		int temp = (ac-o.ac) * -1;
		if (temp != 0) {
			return temp;
		}
		temp = penalty-o.penalty;
		if (temp != 0) {
			return temp;
		}
		return id- o.id;
	}
	public String toString() {
		return (id+1) + " " + ac + " " + penalty;
	}
}

Measured memory_bytes: 63156
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

double memo[1010][1010];
int n;
double solve(int now, int rest) { // rest : 開けたけど残っているもの
  //cout << now << " " << rest << endl;
  if (now >= n) return 0;
  //assert(now != n-1);
  if (memo[now][rest] >= 0) return memo[now][rest];
  int num = rest+1;
  double res = 0;
  double p = (double)rest/(n-now);
  if (rest) {
    res += solve(now+1, rest-1) * p; // 既に開けた奴とマッチ
  }
  // 1枚目が初めて
  p = 1-p;
  if (rest != n-now) {
    // 2枚目が既に開けたやつ
    double q = (double)rest/(n-now-1);
    if (rest) {
      res += (1 + solve(now+2, rest)) * p * q;
    }
    // 2枚目も初めて
    q = double(n-now-1-rest-1)/(n-now-1);
    if (n-now-1-rest-1) {
      res += (1 + solve(now+2, rest+2)) * p * q;
    }
    // 2枚目が同じ
    q = 1.0/(n-now-1);
    res += solve(now+2, rest) * p * q;
  }
  //cout << now << " " << rest << " " << res << endl;
  return memo[now][rest] = res;
}

int main() {
  while(cin>>n,n) {
    REP(i,n)REP(j,n) memo[i][j] = -1;
    
    printf("%.10f\n", solve(0,0));
  }
}

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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}

const int N = 2e5 + 20;

struct Fenwick {
	ll tree[N];

	void upd(int at, ll val) {
		for (; at < N; at |= (at + 1)) {
			tree[at] = max(tree[at], val);
		}
	}

	ll get(int r) {
		ll ans = 0;
		for (; r >= 0; r = (r & (r + 1)) - 1) {
			ans = max(ans, tree[r]);
		}
		return ans;
	}
} fenw;

void run() {
	int n;
	cin >> n;
	vector<int> h(n), a(n);
	for (int &x : h) {
		cin >> x;
	}
	for (int &x : a) {
		cin >> x;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll res = a[i] + fenw.get(h[i]);
		fenw.upd(h[i], res);
		ans = max(ans, res);
	}
	cout << ans << "\n";
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int, int> pi;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MKP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
const int INF = 999999;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll MOD = 1000000007;
int xa,ya,xb,yb;

int main()
{ 
    cin >> xa >> ya >> xb >> yb;
    int lenx,leny;
    lenx = abs(xa - xb);
    leny = abs(ya - yb);

    if(xa > xb){
        if(ya > yb){
            cout << xb + leny << " " << yb - lenx << " " << xa + leny << " " << ya - lenx << endl;
        }else{
            cout << xb - leny << " " << yb - lenx << " " << xa - leny << " " << ya - lenx << endl;
        }
    }else{
        if(ya > yb){
            cout << xb + leny << " " << yb + lenx << " " << xa + leny << " " << ya + lenx << endl;
        }else{
            cout << xb - leny << " " << yb + lenx << " " << xa - leny << " " << ya + lenx << endl;
        }
    }
   return 0;

}
 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
    int N;
    vector<int> L;

    cin >> N;

    int tmp;

    for (int i = 0; i < N; i++) {
        cin >> tmp;
        L.push_back(tmp);
    }

    sort(L.begin(), L.end());

    int ans = 0;
    int current = 0;

    for (int i = 2; i < N; i++) {
        for (int j = i - 1; j > 0; j--) {
            int sub_ans = 0;
            for (int k = 0; k < j; k++) {
                // 三角形のとき
                if (L[j] + L[k] > L[i]) {
                    sub_ans += j - k;
                    break;
                }
            }
            if(sub_ans == 0) {
                break;
            }
            ans += sub_ans;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
template<typename T, int N, T F(const T& a, const T& b)>
struct SegTree
{
public:
    SegTree()
    {
        dat = vector<T>(N * 2 - 1, 0);
    }

    void update(int i, T x)
    {
        i += N - 1;
        dat[i] = x;
        while (i > 0)
        {
            i = (i - 1) / 2;
            dat[i] = F(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = N)
    {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        else
        {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return F(vl, vr);
        }
    }

    vector<T> dat;
};

/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/











//------------------------------------------------------------------------------
ll N, A, B;
ll h[100010];
//------------------------------------------------------------------------------
bool Enough(ll n)
{
    ll need = 0;
    rep(i, 0, N)
    {
        if (h[i] > B * n)
        {
            need += (h[i] - (B * n) + (A - B - 1LL)) / (A - B);
        }
    }
    return need <= n;
}

void _main()
{
    cin >> N >> A >> B;
    rep(i, 0, N) cin >> h[i];

    ll l = -1LL;
    ll r = 1000000000;
    while (r - l > 1LL)
    {
        ll m = (l + r) / 2LL;
        if (Enough(m)) r = m;
        else l = m;
    }
    cout << r << endl;
}


Measured memory_bytes: 1024
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


# スペース区切りの整数の入力
a, b = map(int, input().split())
a_list = prime_factorize(a)
a_set = set(a_list)
b_list = prime_factorize(b)
b_set = set(b_list)

print(len(a_set & b_set)+1)


Measured memory_bytes: 3064