akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop

mod = 10 ** 9 + 7

n = int(input())
a = [int(input()) for _ in range(n)]
b = [int(input()) for _ in range(n)]

h = []
for aa in a:
    heappush(h, (aa, True))
for bb in b:
    heappush(h, (bb, False))

ca = 0
cb = 0
ans = 1
while h:
    pos, is_elm_of_a = heappop(h)
    if is_elm_of_a:
        if cb > 0:
            ans *= cb
            ans %= mod
            cb -= 1
        else:
            ca += 1
    else:
        if ca > 0:
            ans *= ca
            ans %= mod
            ca -= 1
        else:
            cb += 1
print(ans)

Measured memory_bytes: 86360
#include<bits/stdc++.h>
#define ll long long
#define P pair<ll,ll>
#define mk make_pair
using namespace std;
const int N = 200005;
int a[N];
map<int,int>mp;
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        mp[a[i]+i]++;
    }
    ll sum = 0;
    for(int i=1;i<=n;i++){
        sum += mp[i-a[i]];
    }
    cout << sum;
    return 0;
}


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

int main(){
    string S;
    ll K,len,x,y=1,z=0,j=0,jj=0,k=0,u=0;
    bool judge=true;
    cin >> S >> K;
    x=S.size();
    for(ll i=1;i<x;i++){
        if(S[i-1]!=S[i]) judge=false;
    }
    if(judge){
        len=x*K;
        cout << len/2 << endl;
    }else{
        while(S[j]==S[j+1]){
            ++j;
        }
        for(ll i=j+1;i<x;i++){
            if(S[i-1]==S[i]) y++;
            else{
                z+=y/2;
                y=1;
            }
        }
        if(S[0]==S[x-1]){
            jj=y;
            y++;
            while(S[k]==S[k+1]){
                ++k;
                ++y;
            }
            z+=y/2;
            if(jj%2==1 && y%2==0) u=1;
            ll total = z*K-u;
            cout << total << endl;
        }else{
            ll y=1,z=0;
            for(ll i=1;i<x;i++){
                if(S[i-1]==S[i]) y++;
                else{
                    z+=y/2;
                    y=1;
                }
            }
            z+=y/2;
            cout << z*K << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            decimal sum = 0;
            for (int i = 0; i < N; i++)
            {
                string[] xy = Console.ReadLine().Split(' ');
                if (xy[1] == "JPY")
                {
                    sum += decimal.Parse(xy[0]);
                }
                else
                {
                    //1.0BTC 380000円
                    sum += decimal.Parse(xy[0]) * 380000;
                }
            }
            Console.WriteLine(sum);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

bool dpx[8010][16010];
bool dpy[8010][16010];

int main(){
    string s; cin >> s;
    int x,y; cin >> x >> y;
    int n = s.size();
    int now = 0;
    rep(i,8010)rep(j,16010){
        dpx[i][j] = false;
        dpy[i][j] = false;
    }
    dpx[0][8000] = true;
    dpy[0][8000] = true;
    int cntx0 = 0;
    int cntx1 = 0;
    int cnty = 0;
    rep(i,n){
        if(now == 0 && s[i] == 'F'){
            cntx0++;
        }
        if(now == 1 && s[i] == 'F'){
            cntx1++;
        }
        if(now == 2 && s[i] == 'F'){
            cnty++;
        }
        if(s[i] == 'T'){
           rep(j,16005){
                if(now == 0){
                    dpx[i+1][cntx0+8000] = true;
                    dpy[i+1][8000] = true;
                    if(j == 16004){
                        now = 2;
                        cntx0 = 0;
                        break;
                    }
                }
                if(now == 1){
                    if(j >= cntx1) dpx[i+1][j] = dpx[i-cntx1][j-cntx1];
                    dpx[i+1][j] |= dpx[i-cntx1][j+cntx1];
                    dpy[i+1][j] = dpy[i-cntx1][j];
                    if(j == 16004){
                        cntx1 = 0;
                        now = 2;
                        break;
                    }
                }
                if(now == 2){
                    if(j >= cnty) dpy[i+1][j] = dpy[i-cnty][j-cnty];
                    dpy[i+1][j] |= dpy[i-cnty][j+cnty];
                    dpx[i+1][j] = dpx[i-cnty][j];
                    if(j == 16004){
                        cnty = 0;
                        now = 1;
                        break;
                    }
                }
           }
        }
    }
    if(cntx0 > 0){
        dpx[n][cntx0+8000] = true;
        dpy[n][8000] = true;
    }
    else{
        rep(j,16005){
            int k = max(cntx1,cnty);
            if(j >= cntx1) dpx[n][j] = dpx[n-k][j-cntx1];
            dpx[n][j] |= dpx[n-k][j+cntx1];
            if(j >= cnty) dpy[n][j] = dpy[n-k][j-cnty];
            dpy[n][j] |= dpy[n-k][j+cnty];
        }
    }
    //cout << cntx0 << endl;
    //cout << dpy[5][7998] << endl;
    if(dpx[n][x+8000] && dpy[n][y+8000]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 250752
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
P=list(map(int,input().split()))
A,B=[],[]
for i in range(1,n+1):
    A.append(25000*i)
    B.append(25000*(n-i+1))
for i,p in enumerate(P):
    A[p-1]+=i
print(*A)
print(*B)

Measured memory_bytes: 6344
import bisect
N=int(input())
L=[int(i) for i in input().split()]
L.sort()
count=0
for i in range(N-2):
    a=0
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        if l<=L[j+1]:
            a=0
        elif l>L[N-1]:
            a=1
            break
        else:
            idx=bisect.bisect_left(L,l)
            count=count+(idx-j-1)
    if a==1:
        b=N-j-1
        B=(b+1)*b//2
        count=count+B
print(count)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back

struct link{
    int num;
    struct link *before, *next;
};

struct link *nil;
const int MAX_N = 100010;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  for(int i=0;a>0&&c>0;i++){
    c-=b;
    if(c<=0){
      cout<<"Yes";
      break;
    }
    a-=d;
    if(a<=0){
      cout<<"No";
      break;
    }
  }
}
    

Measured memory_bytes: 3096
#include<stdio.h>

int main(void){
	unsigned int ans=100000,n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		ans=(ans*105)/100;
		ans=ans/1000+(ans%1000>0?1:0);
		ans*=1000;
	}
	printf("%d\n",ans);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define EPS 1e-14
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif*/
    int n;
    cin>>n;
    if(n%2==0) cout<<n<<endl;
    else cout<<n*2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int func(int , int);
int c,n,a[200];

int main(){
  int q,i,j;
  int mi[200];

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

  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&mi[j]);
  }

  for(i=0;i<q;i++){
    c = func(0,mi[i]);
    if(c)printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int func(int i,int m){
  if(m == 0) return 1;
  if(i >= n) return 0;
  if(func(i + 1,m) || func(i+1,m-a[i])) return 1;
  else return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
int main(){
    int n,m;std::cin>>n>>m;
    std::vector<int>a(n,-1);
    for(int i=0;i<m;i++){
        int s,c;std::cin>>s>>c;
        s--;
        if(a.at(s)!=-1&&a.at(s)!=c||2<=n&&s==0&&c==0){
            std::cout<<-1<<std::endl;
            return 0;
        }
        a.at(s)=c;
    }
    for(int i=0;i<n;i++){
        std::cout<<(a.at(i)==-1?(2<=n&&i==0?1:0):a.at(i));
    }
    std::cout<<std::endl;
}



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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << v[i].second; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int n;
  cin >> n;
  vector<int> s(n);
  for(int i=0; i<n; i++) cin >> s[i];
  int q;
  cin >> q;
  vector<int> t(q);
  for(int i=0; i<q; i++) cin >> t[i];

  int ans = 0;
  for(int i=0; i<q; i++){
    for(int j=0; j<n; j++){
      if(t[i] == s[j]){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 3104
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
string str;
map<string,ll> ma;
map<string,ll> :: iterator itr;
int main()
{
    ll i,n,t,k,j,x=0,y=0,m,sum=0;
    sf(t);
    rep0(i,t)
    {
        cin>>str;
        sort(str.begin(),str.end());
        if(ma.find(str)==ma.end())
        {
            ma[str] = 1;
        }
        else ma[str]++;
    }
    for(itr= ma.begin();itr!=ma.end();itr++)
    {
        y = itr->second;
        sum+= (y*(y-1))/2;
        //cout<<sum<<" "<<y<<endl;
    }
    pf(sum);
    return 0;
}



Measured memory_bytes: 11136
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, D := getInt(), getInt()
	D *= D
	cnt := 0
	for i := 0; i < N; i++ {
		x, y := getInt(), getInt()
		if x*x+y*y <= D {
			cnt++
		}
	}
	out(cnt)
}


Measured memory_bytes: 4892
#include <stdio.h>
#include <stdlib.h>

bool check(int t, int x, int y)
{
	int tmp = t - abs(x) - abs(y);
	if (tmp < 0 || (tmp % 2 != 0)) return false;
	return true;
}

int main() {
	int N;
	scanf("%d", &N);
	int* t = new int[N+1];
	int* x = new int[N+1];
	int* y = new int[N+1];
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d %d %d", &t[i + 1], &x[i + 1], &y[i + 1]);
	}
	bool ret = true;
	for (int i = 0; i < N; i++) {
		if (check(t[i + 1] - t[i], x[i + 1] - x[i], y[i + 1] - y[i]) == false) {
			ret = false;
			break;
		}
	}

	if (ret) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1408
N,K = map(int, input().split())
es = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)


MOD = 10**9+7
 
MAXN = N+5+K
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD
 

def nPr(n,r):
    if n < r:
        return 0
    return fac[n] * finv[n-r]


# 始点のノードがK個の色でぬれて、始点の子供がnPr(K-1, 始点の子の数)通りの塗り分け方がある。
# それらの子については、nPr(K-2, 子の数)の塗り方。

q  = []
used = [False] * N
used[0] = True
for nxt in es[0]:
    q.append(nxt)
    used[nxt] = True


ans = K * nPr(K-1, len(es[0]))
ans %= MOD
while q:
    curr = q.pop()
    ans *= nPr(K-2, len(es[curr]) - 1)
    ans %= MOD
    for nxt in es[curr]:
        if used[nxt]:
            continue

        used[nxt] = True
        q.append(nxt)


print(ans)

Measured memory_bytes: 75564
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, Y;
  cin >> N >> Y;

  Y /= 1000;

  rep(i,N+1){
    int remain = N - i;
    int Y2 = Y - 10*i;
    if(remain < 0) break;

    if(remain == 0 && Y2 == 0){
      cout << i << " 0 0" << endl;
      return 0;
    }
    
    rep(j,remain+1){
      int z = remain - j;
      int Y3 = Y2 - 5*j;
      if(z < 0) break;

      if(Y3 == z){
        cout << i << " " << j << " " << z << endl;
        return 0;
      }
      
    }
  }
  cout << "-1 -1 -1" << endl;
  
  return 0;
}



Measured memory_bytes: 256
// ACM-ICPCà\I2010 F. Ã¢L¯

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>

using namespace std;

const int INF = 100000000;

int d;
string mes, cur;
vector<string> piece;
vector<int> connect[30][20];
vector<string> ans;
set<string> mem[43];
int dp[43][43];
int cost[30][20];
int curdist;

int getMinedit(string s, string t){
	int n = s.size(), m = t.size();
	int cost[43], newcost[43];
	for(int i=0;i<=n;i++) cost[i] = 0;
	for(int j=1;j<=m;j++){
		newcost[0] = j;
		for(int i=1;i<=n;i++){
			newcost[i] = 1+min(newcost[i-1],cost[i]);
			newcost[i] = min(newcost[i],cost[i-1]+(s[i-1]!=t[j-1]));
		}
		memcpy(cost, newcost, sizeof(cost));
	}
	return *min_element(cost, cost+n+1);
}

bool editDist(int s, int e){
	for(int i=s+1;i<=e;i++){
		curdist = INF;
		for(int j=max(1,i-d);j<=min((int)mes.size(),i+d);j++){
			if(cur[i-1]==mes[j-1]) dp[i][j] = dp[i-1][j-1];
			else {
				dp[i][j] = dp[i-1][j-1]+1;
				dp[i][j] = min(dp[i][j], dp[i-1][j]+1);
				dp[i][j] = min(dp[i][j], dp[i][j-1]+1);
			}
			curdist = min(curdist, dp[i][j]);
		}
		if(curdist > d) return false;
	}
	return true;
}

void dfs(int pIdx, int p1, int p2){
	int len = piece[0].size();
	int csize = cur.size();
	if(dp[csize][mes.size()] <= d) ans.push_back(cur);
	int start = min(len-1, csize-p2-1);
	cur += string(len-1-start, ' ');
	int ccost = curdist;
	for(int i=start;i>=0;i--){
		int nsize = csize+len-i;
		if(nsize > mes.size() + d) break;
		cur += ' ';
		for(int j=0;j<connect[pIdx][i].size();j++){
			if(ccost + cost[connect[pIdx][i][j]][i] > d) continue;
			bool flag = true;
			for(int k=i;k<len;k++){
				cur[csize+k-i] = piece[connect[pIdx][i][j]][k];
				if(!editDist(csize+k-i, csize+k-i+1)){
					flag = false;
					break;
				}
			}
			if(!flag) continue;
			if(mem[nsize].count(cur)) continue;
			mem[nsize].insert(cur);
			dfs(connect[pIdx][i][j], nsize, p1);
		}
	}
	cur = cur.substr(0, csize);
}

int main(){
	int n, len;
	for(int i=0;i<=42;i++) dp[i][0] = dp[0][i] = i;
	while(cin >> d >> n, n){
		cin >> mes;
		piece.clear();
		for(int i=0;i<n;i++){
			string str; cin >> str;
			if(getMinedit(mes, str) > d) continue;
			piece.push_back(str);
		}
		sort(piece.begin(), piece.end());
		piece.erase(unique(piece.begin(), piece.end()), piece.end());
		len = piece[0].size();
		for(int i=1;i<=mes.size()+d;i++)
			for(int j=1;j<=mes.size()+d;j++)
				if(abs(i-j) > d) dp[i][j] = INF;
		for(int i=0;i<piece.size();i++){
			for(int j=0;j<len;j++){
				connect[i][j].clear();
				for(int k=0;k<piece.size();k++){
					if(piece[i].substr(len-j) == piece[k].substr(0,j)){
						connect[i][j].push_back(k);
						cost[k][j] = getMinedit(mes, piece[k].substr(j));
					}
				}
			}
		}
		for(int i=0;i<=mes.size()+d;i++)
			mem[i].clear();
		ans.clear();
		for(int i=0;i<piece.size();i++){
			cur = piece[i];
			if(!editDist(0, len)) continue;
			dfs(i, len, 0);
		}
		sort(ans.begin(), ans.end());
		cout << ans.size() << endl;
		if(ans.size() <= 5){
			for(int i=0;i<ans.size();i++)
				cout << ans[i] << endl;
		}
	}
}

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

int main() {
    string s, t;
    cin >> s >> t;
    vector<string> cans;
    if (t.size() > s.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    int limit = s.size() - t.size();
    for (int i = 0; i <= limit; i++) {
        string subs = s.substr(i, t.size());
        bool judge = 1;
        rep(j, t.size()) {
            if (subs[j] == '?')
                continue;
            if (subs[j] != t[j]) {
                judge = 0;
                break;
            }
        }

        int st = i;

        if (judge) {
            string ss = s;
            rep(j, t.size()) { ss[st] = t[j], st++; }

            rep(k, ss.size()) {
                if (ss[k] == '?')
                    ss[k] = 'a';
            }

            cans.push_back(ss);
        }
    }

    sort(all(cans));
    if (cans.size() == 0)
        cout << "UNRESTORABLE" << endl;
    else
        cout << cans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int K = Integer.parseInt(scan.next());
		int Q = K / 2;
		if (K % 2 == 0) {
			System.out.println(Q * Q);
		} else {
			System.out.println(Q * (Q + 1));
		}
	}
}


Measured memory_bytes: 21716
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class UnionFind {
  public:
    // 親の番号を格納する。親の場合 -1 になる
    vector<int> Parent;

    // 宣言されたとき Parent の値はすべて -1 にする
    UnionFind(int N) { Parent = vector<int>(N, -1); }

    // 与えられた値 x がどの親であるか調べる
    int root(int x) {
        // x が親だったとき
        if (Parent[x] < 0)
            return x;
        // 辺の縮約をいっしょにおこなう
        return Parent[x] = root(Parent[x]);
    }

    // 木の全体の数を返す
    int size(int x) {
        // マイナスがついているのは root
        // 以下の数をマイナスの値で管理しているから
        return -Parent[root(x)];
    }

    // 2つの引数を同じ親にする
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);

        // 同じ親の場合くっつけない
        if (x == y)
            return false;

        // x のほうが必ず大きな size にしたい
        if (size(x) < size(y))
            swap(x, y);
        Parent[x] += Parent[y];
        Parent[y] = x;
        return true;
    }
};

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

    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    int ans = 0;

    REP(i, M) {
        auto uni = UnionFind(N);
        REP(j, M) {
            if (i != j) {
                uni.merge(a[j], b[j]);
            }
        }
        if (uni.size(0) < N)
            ans++;
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;

			String[] s = new String[n];
			int[] money = new int[n];

			for(int i=0;i<n;i++){
				s[i] = sc.next().replace("*",".");
				money[i] = sc.nextInt();
			}

			int sum = 0;
			while(m-- > 0){
				String tmp = sc.next();
				for(int i=0;i<n;i++){
					if(tmp.matches(s[i])) sum += money[i];
				}
			}

			System.out.println(sum);
		}
	}
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N - 1);
    rep(i, N - 1) cin >> A[i];

    vector<int> cnt(N);
    for (auto a: A) cnt[a - 1]++;
    rep(i, N) cout << cnt[i] << endl;
}


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

import numpy as np

def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(input())
    return x

N = int(input())
S = input()

ans = 0

for i in range(1,N-1):
    set1 = set(list(S[0:i]))
    set2 = set(list(S[i:N]))
    ans = max(ans,len(set1&set2))

print(ans)

Measured memory_bytes: 27092
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
vector<char> c;
//=============================
void input()
{
    cin>>N;
    c.resize(N);
    rep(i,0,N-1){
        cin>>c[i];
    }

}
//=============================
void func(){}
//=============================
void solve()
{
    set<char> st;
    for(auto x : c){
        st.insert(x);
    }
    cout<<(st.size()==3? "Three" : "Four")<<endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
/**
 * Author : RDP
 * There are no two words in the English language more harmful than "good job".
 * 1729 ;)
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <numeric>
using namespace std;
using ll = long long;
#define endl '\n'
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) 
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define all(x) (x).begin(), (x).end()
/* **************************************************************************************** */
vector<set<int>> adj;
int ans = 0;
vector <bool> vis;
int dfs(int u)
{
    int con = 1;
    vis[u] = true;
    for(int v : adj[u])
    {
        if(!vis[v])
            con += dfs(v);
    }
    return con;
}
void test_case()
{
    int n, m;
    cin >> n >> m;
    vis.resize(n + 1, false);
    adj.resize(n + 1);
    for(int i = 0; i < m; i ++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].insert(b);
        adj[b].insert(a);
    }

    for(int i = 1; i <= n; i ++)
    {
        if(!vis[i])
        {
            ans = max(dfs(i), ans);
        }
    }

    cout << ans << endl;
}
int main()
{
	FAST_IO
    int t = 1;
    //cin >> t;
    while(t--)
        test_case();
	return 0;
}

Measured memory_bytes: 40608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

vector<ll> divisor(ll n){
  vector<ll> v;
  for(int i=1; i<=sqrt(n); i++){
    if(n%i == 0){
      v.push_back(i);
      //if(i!=n/i) v.push_back(n/i);
    }
  }
  return v;
}

int calc_digit(ll x){
  int count = 0;
  while(x!=0){
    ++count;
    x/=10;
  }
  return count;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N;cin >> N;
  vector<ll> v = divisor(N);
  ll x = v[v.size()-1];
  cout << calc_digit(N/x) << endl;
  return 0;
}


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A[9] = {0};
    bool B[9] = { 0 };
    rep(i, 9) cin >> A[i];
    ll N;
    cin >> N;
    rep(i, N)
    {
        ll b;
        cin >> b;
        rep(j, 9)
        {
            if (A[j] == b) 
                B[j] = true;
        }
    }
    //
    yes(// 横
        (B[0] && B[1] && B[2]) ||
        (B[3] && B[4] && B[5]) ||
        (B[6] && B[7] && B[8]) ||
        // 縦
        (B[0] && B[3] && B[6]) ||
        (B[1] && B[4] && B[7]) ||
        (B[2] && B[5] && B[8]) ||
        // 斜め
        (B[0] && B[4] && B[8]) ||
        (B[2] && B[4] && B[6]));
    //
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int A[3][3];
bool done[3][3];

int main() {
  for (int i: range(0, 3)) {
    for (int j: range(0, 3)) {
      std::cin >> A[i][j];
    }
  }
  int N;
  std::cin >> N;
  for (int k: range(0, N)) {
    int b;
    std::cin >> b;
    for (int i: range(0, 3)) {
      for (int j: range(0, 3)) {
        if (A[i][j] == b) {
          done[i][j] = true;
        }
      }
    }
  }
  bool ans = false;
  for (int i: range(0, 3)) {
    bool flag = true;
    for (int j: range(0, 3)) {
      if (!done[i][j]) {
        flag = false;
      }
    }
    if (flag) {
      ans = true;
    }
  }
  for (int i: range(0, 3)) {
    bool flag = true;
    for (int j: range(0, 3)) {
      if (!done[j][i]) {
        flag = false;
      }
    }
    if (flag) {
      ans = true;
    }
  }
  {
    bool flag = true;
    for (int i: range(0, 3)) {
      if (!done[i][i]) {
        flag = false;
      }
    }
    if (flag) {
      ans = true;
    }
  }
  {
    bool flag = true;
    for (int i: range(0, 3)) {
      if (!done[i][2 - i]) {
        flag = false;
      }
    }
    if (flag) {
      ans = true;
    }
  }
  std::cout << (ans ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char S[200000 + 100];
int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	scanf("%s", S);
	int Cnt = 0, Ans = 0;
	/*
	int f = 0, l = 0;
	for (int i = 0; i < strlen(S); ++i)
		if (S[i] == 'S')
		{
			f = i;
			break;
		}
	for (int i = strlen(S) - 1; i > 0; --i)
		if (S[i] == 'T')
		{
			l = i;
			break;
		}
	int Cnt1 = 0, Cnt2 = 0;
	for (int i = f; i <= l; ++i)
		if (S[i] == 'S') Cnt1++;
		else Cnt2++;
	cout<<strlen(S) - 2 * min(Cnt1, Cnt2)<<endl;
	*/
	for (int i = 0; i < strlen(S); ++i)
	{
		if (S[i] == 'S') ++Cnt;
		if (Cnt > 0 && S[i] == 'T') ++ Ans, --Cnt;
	}
	cout<<strlen(S) - 2 * Ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>

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

using namespace std;

struct Edge {
  int src,dst,weight; 
  bool operator < ( const Edge &e ) const { return weight < e.weight; }
};

const int MAX = 10010;
int par[MAX];
//vector<Edge> edges;
Edge edges[MAX];

void init(int _size=MAX) { rep(i,_size) par[i] = i; } 

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

void unit(int x,int y){
  x = find(x), y = find(y);
  if( x != y ) par[x] = y;
}

bool buffer[MAX];
bool choose[MAX];
int counter[MAX];
//vector<int> bases;
int bases[MAX];
int V,t,k;

bool isValid(int index){
  choose[index] = false;
  //map<int,int> mp;
  rep(i,V) counter[i] = 0, par[i] = i;

  rep(i,V-1) if( choose[i] ) unit(edges[i].src,edges[i].dst);
  rep(i,t) ++counter[find(bases[i])];
  rep(i,V) if( counter[find(i)] == 0 ) return false;
  return true;
}

void compute(){
  sort(edges,edges+V-1);
  if( V == t ) {
    int sum = 0;
    rep(i,k) sum += edges[i].weight;
    printf("%d\n",sum);
    return;
  }
  rep(i,V) buffer[i] = true;
  int answer = 0;
  int remain = k;
  int cur = 0;
  while( cur < V-1 && remain ){
    rep(i,V) choose[i] = buffer[i];
    if( isValid(cur) ) {
      --remain;
      answer += edges[cur].weight;
      buffer[cur] = false;
    }
    ++cur;
  }
  printf("%d\n",answer);
}

int main(){
  int CNT = 1;  
  while( scanf(" %d %d %d",&V,&t,&k) , V|t|k ){
    
    rep(i,V-1) {
      int s,t,c;
      scanf(" %d %d %d",&s,&t,&c);
      --s, --t;
      //edges.push_back((Edge){s,t,c});
      edges[i] = (Edge){s,t,c};
    }
    rep(i,t){
      int base;
      scanf(" %d",&base);
      --base;
      //bases.push_back(base);
      bases[i] = base;
    }
    printf("Case %d: ",CNT++);
    compute();
  }
  return 0;
}

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

long a[111111], b[111111];
int main() {
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++)
        cin >> a[i];
    if(n && a[0] || !n && a[0] != 1) {
        cout << -1 << endl;
        return 0;
    }
    for(int i = n; i--;)
        b[i] = b[i + 1] + a[i + 1];
    b[0] = 1;
    long r = 1;
    for(int i = 0; i < n; i++) {
        b[i + 1] = min(b[i + 1], b[i] * 2 - a[i + 1]);
        if(b[i + 1] < 0) {
            cout << -1 << endl;
            return 0;
        }
        r += a[i + 1] + b[i + 1];
    }
    cout << r << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans = 0;
  while(1){
    bool pl = false;
    rep(i, n){
      if (h[i] != 0){
        h[i]--;
        if (!pl){
          ans++;
          pl = true;
        }
      }
      else{
        pl = false;
      }
    }
    bool flag = true;
    rep(i, n){
      if (h[i] != 0) flag = false;
    }
    if (flag) break;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;

typedef long long ll;

ll lu(ll a,ll b){
	ll t;
	if (a<b){
		t=a;
		a=b;
		b=t;
	}
	if (a%b==0) return b;
	else return lu(b,a%b);
}

ll zheng(ll a,ll b){
	return a/lu(a,b)*b;
}

int main()
{
	int N;
	ll a[105],s;
	while (cin>>N){
		s=1;
		for(int i=1;i<=N;i++){
			cin>>a[i];
			s=zheng(s,a[i]);
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,W;cin>> n>>W;
	vector<ll> w(n);
	vector<ll> ww(n);
	vector<ll> v(n);
	for(int i = 0; i < n; i++) {
		cin>>w[i]>>v[i];
		ww[i] = w[i] - w[0];
	}
	vector<vector<vector<ll>>> dp(n + 1,vector<vector<ll>>(n + 1,vector<ll>(600,0LL)));
	//dp[i][j][k] i番目までを使ってj個使用して重さがkのときの価値の最大値
	for(ll i = 1; i <= n; i++) {
		for(ll j = 1; j <= n; j++) {
			for(ll k = 0; k < 500; k++) {
				if (ww[i - 1] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k],dp[i - 1][j - 1][k - ww[i - 1]] + v[i - 1]);
				}
				else{
					dp[i][j][k] = dp[i - 1][j][k];
				}
			}
		}
	}




	ll ans = 0LL;
	for(ll i = 0; i <= n; i++) {
		ll k = 0;
		while(W - i * w[0] >= k && k < 500){
			ans = max(ans,dp[n][i][k]);
			k++;
		}
	}
	// for(int i = 0; i < 10; i++) {
	// 	cout << dp[n][i].fs << " " << dp[n][i].sc << endl;
	// }
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

ll dp[3005][3005], ans[3005];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	ll ans = 0;
	for (int lim = n; lim >= n - 1; lim--) {
		for (int i = 0; i <= lim; i++) dp[0][i] = 1;
		for (int i = 1; i <= m; i++) {
			for (int j = 0; j <= lim; j++) {
				dp[i][j] = 0;
			}
		}
		for (int i = 0; i < m; i++) {
			for (int j = 0; j <= lim; j++) {
				if (j > 0) {
					(dp[i + 1][j] += dp[i][j]) %= MOD;
					(dp[i + 1][j - 1] += dp[i][j]) %= MOD;
				}
				if (j < lim) {
					(dp[i + 1][j] += dp[i][j]) %= MOD;
					(dp[i + 1][j + 1] += dp[i][j]) %= MOD;
				}
			}
		}	

		for (int i = 0; i <= lim; i++) {
			if (lim == n) (ans += dp[m][i]) %= MOD;
			else (ans += (MOD - dp[m][i]) % MOD) %= MOD;
		}	
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
const int N=233;

void GG()
{
  puts("Impossible");
  exit(0);
}

  int n,l=100,m,x;
  int v[N];
int main()
{
  cin>>n;
  for (int i=0;++i<=n;)
    cin>>x,++v[x];
  while (!v[l]) --l;
  m=l+1>>1;
  if (l==1&&n>2) GG();
  if (!(l&1)&&(v[m]^1)&&n>2) GG();
  if ((l&1)&&(v[m]^2)&&n>1) GG();
  for (int i=m;++i<=l;)
    if (v[i]<2) GG();
  for (int i=0;++i<m;)
    if (v[i]) GG();
  puts("Possible");
  exit(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=2e5;
const int INF=1e9;
int main(){
	int N;cin>>N;
	double A[N];double res=1;
	rep(i,0,N){ cin>>A[i];res*=A[i]; }
	double sum=0;
	rep(i,0,N) sum+=res/A[i];
	cout<<setprecision(14)<<res/sum<<endl;
}

Measured memory_bytes: 256
o=998244353
r=2500100
f=[1]
for i in range(1,r):f.append(f[-1]*i%o)
def v(x):return pow(x,o-2,o)
def c(n,k):return f[n]*v(f[n-k])*v(f[k])%o
n,m=map(int,input().split())
w=3*m
a=(c(n+w-1,n-1)-n*c(n+m-2,n-1))%o
if n>m+1:
 for i in range(m+1,min(w,n)+1):
  if (w-i)%2:continue
  x=(w-i)//2
  a=(a-c(n,i)*c(x+n-1,n-1))%o
print(a)

Measured memory_bytes: 107144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const int INF = 10000000;
int main(){
    int n,m,x;
    ll ans=INF;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    rep(bit,1<<n){
        ll nedan=0;
        bool ok=true;
        vector<ll> skill(m);
        rep(i,n){
            if(bit>>i&1){
                nedan += c[i];
                rep(j,m){
                    skill[j] += a[i][j];
                }
            }
        }
        rep(i,m){
            if(skill[i] < x) ok = false;
        }
        if(ok) ans=min(ans,nedan);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    int r,c;
    cin >> r >> c;
    
    int ss[r+1][c+1];
    for(int row =0;row<r+1;row++){
        for(int col=0;col<c+1;col++){
            ss[row][col]=0;
        }
    }
    
    for(int row =0;row<r;row++){
        for(int col=0;col<c;col++){
            int val;
            cin >> val;
            ss[row][col]=val;
            ss[row][c]+=val;
            ss[r][col]+=val;
            ss[r][c]+=val;
        }
    }
    
    for(int row =0;row<r+1;row++){
        for(int col=0;col<c+1;col++){
            if(col)cout << " ";
            cout << ss[row][col];
        }
        cout << endl;
    }
    

}

Measured memory_bytes: 1196
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll min_num = min({a, b, c, d, e});
    ll times = (n%min_num==0) ? n/min_num : n/min_num+1;
    cout << times + 4 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(),.end());
int main(){
  ll n, m, ans = 0;
  cin >> n >> m;
  if (abs(n - m) == 0) {
    ans = 1;
    for (ll i = 1; i <= n; i++) {
      ans *= i;
      ans %= mod;
    }
    ans *= ans;
    ans %= mod;
    ans *= 2;
    ans %= mod;
  }
  if (abs(n - m) == 1) {
    ans = 1;
    for (ll i = 1; i <= min(n, m); i++) {
      ans *= i;
      ans %= mod;
      ans *= i;
      ans %= mod;
    }
    ans *= max(n, m);
    ans %= mod;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int gcd(int a,int b){return a<b?gcd(b,a):b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*(b/gcd(a,b));}
int main(){
  int a,b,c=1;
  scanf("%d",&a);
  while(a--){
    scanf("%d",&b);
    c=lcm(b,c);
  }
  printf("%d\n",c);
  return 0;
}

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

int main() {
    long long n; scanf("%lld", &n);
    long long ans = 0;
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            if (i - 1 > 0 && n / i < (i - 1)) ans += i - 1;
            if (i * i != n && n / (n / i) < (n / i) - 1) ans += n / i - 1;
        }
    }
    printf("%lld\n", ans);
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (int i=0; i<n; ++i) cin >> p[i];

    int res = 0, dif = INF;
    for (int i=0; i<=101; ++i) {
        bool ok = true;
        for (int y : p) {
            if (i == y) {
                ok = false;
                break;
            }
        }
        if (ok) if (chmin(dif, abs(x-i))) res = i;
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    int n, x, y; cin >> n >> x >> y;
    x--, y--;
    vector<vector<int>> dp(n, vector<int>(n));
    rep(i, n)rep(j, n) dp[i][j] = abs(i - j);
    rep(i, n){
        rep(j, n){
            dp[i][j] = min(dp[i][j], dp[i][x] + dp[y][j] + 1);
            dp[i][j] = min(dp[i][j], dp[i][y] + dp[x][j] + 1);
        }
    }
    vector<int> ans(n, 0);
    rep(i, n)_rep(j, i + 1, n) ans[dp[i][j]]++;
    _rep(i, 1, n) cout << ans[i] << endl;   
}

Measured memory_bytes: 19308
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b,c;
	cin >> a >> b >> c;
	cout << (a*b)/2 << endl;
	
	return 0;
}

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

int main(){
  char n[3];
  cin >> n;
  for(int i=0; i < 3; i++){
    if(n[i] == '1') cout << "9";
    if(n[i] == '9') cout << "1";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    ll c = 0;
    if (s[0] == t[0]) c++;
    if (s[1] == t[1]) c++;
    if (s[2] == t[2]) c++;
    cout <<c << endl;
}

Measured memory_bytes: 256