akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
int main(){
    char squ[51][51];
    int h,w,ans=1;
    scanf("%d%d",&h,&w);
    for(int i=1;i<=h;i++)
        {
            getchar();
            for(int j=1;j<=w;j++)
                scanf("%c",&squ[i][j]);
        }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(squ[i][j]=='#')
            {
                 if(squ[i-1][j]=='.'&&squ[i][j+1]=='.'&&squ[i+1][j]=='.'&&squ[i][j-1]=='.')
                        ans=0;
            }
            if(ans==0)
                break;
        }
        if(ans==0)
            break;
    }
    if(ans==0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, k;
    cin >> n >> k;
    REP(i,100){
        n /= k;
        if (n == 0){
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int S, W;
    cin >> S >> W;
    cout << (S <= W ? "unsafe" : "safe") << endl;
    return 0;
}

Measured memory_bytes: 3612
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = parseInt(input.split("\n")[0]);
  
    if (input % 1000 == 0) console.log(0);
    else console.log(1000 - (input % 1000));
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29688
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int MaxN = 500;
const int MaxM = 500;

int n, m, h, w;

int mark[MaxN];

int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> m >> h >> w;

	if (n % h == 0 && m % w == 0)
	{
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	if (n % h != 0)
	{
		for (int i = 0; i < n; ++i)
			mark[i] = -1000;
		for (int i = 0; i < n; i += h)
			mark[i] = 1000 * (h - 1) - 1;

		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
				cout << mark[i] << ' ';
			cout << endl;
		}
	}
	else
	{
		for (int i = 0; i < m; ++i)
			mark[i] = -1000;
		for (int i = 0; i < m; i += w)
			mark[i] = 1000 * (w - 1) - 1;

		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
				cout << mark[j] << ' ';
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, m, n) for(ll i = (ll)m; i < (ll)n; i++)
#define PER(i, m, n) for(ll i = (ll)m; i > (ll)n; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main(){
    ll d, t, s;
    cin >> d >> t >> s;
    if(d <= t*s) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3612
import math
a, b, C = map(int, input().split())

S = a * b / 2 * math.sin(math.radians(C))
c = math.sqrt(b**2 + a**2 - 2*b*a*math.cos(math.radians(C)))
L = a + b + c
h = S*2/a

print(S, L, h, sep='\n')



Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,t; cin >> n >> t;
    vector<int> T(n);
    rep(i,n) cin >> T[i];
    
    int ans = 0;
    for (int i = 0; i < n-1; i++) {
        if(T[i]+t <= T[i+1]) ans += t;
        else ans += T[i+1] - T[i];
    }
    
    ans += t;
    
    cout << ans << endl;
    
    
    
    
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;

int main(){
    int n;
    cin >> n;
    if(n < 2) cout << 2 << endl;
    else if(n % 2) cout << 2*n << endl;
    else cout << n << endl;
}


Measured memory_bytes: 256
import sys
from heapq import *
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    
    key = []
    for i in range(n):
        s, t, x = map(int, input().split())
        l, r = max(0, s-x), max(0, t-x)
        key.append((l, 1, x))
        key.append((r, -1, x))
    
    for i in range(q):
        d = int(input())
        key.append((d, 2))

    key.sort()
    judge = []
    already = dict()
    
    for i in range(2*n+q):
        k = key[i]
        if k[1] == -1:
            if k[2] in already:
                already[k[2]] += 1
            else:
                already[k[2]] = 1
        elif k[1] == 1:
            heappush(judge, k[2])
        else:
            while judge:
                if judge[0] in already and already[judge[0]] > 0:
                    already[judge[0]] -= 1
                    heappop(judge)
                else:
                    break
            if judge:
                print(judge[0])
            else:
                print(-1)
    

    
if __name__ == "__main__":
    main()



Measured memory_bytes: 96568
fun trace(a: IntArray) = println(a.joinToString(separator = " "))

fun insertionSort(a: IntArray) {
    trace(a)
    for (i in 1 until a.size) {
        val pivotVal = a[i]
        val pivotIdx = (a.slice(0 until i)).indexOfFirst { it > pivotVal }
        if (pivotIdx != -1) {
            (i downTo pivotIdx+1).forEach { a[it] = a[it-1] }
            a[pivotIdx] = pivotVal
        }
        trace(a)
    }
}

fun main(args: Array<String>) {
    readLine()
    readLine()
            ?.split(regex = """\s+""".toRegex())
            ?.map { it.toInt() }
            ?.toIntArray()
            ?.let { insertionSort(it) }
}


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

int main() {
  int N;
  int min = 0;
  int count;
  
  cin >> N;

  for (int i = 0; i < N; i++){
    int t;
    cin >> t;

    count = 0;

    while (!(t % 2)){
      t /= 2; 
      // cout << "t:"  << t << endl;
      count++;
      // cout << "count:" << count << endl;
    }

    if (i == 0 || min > count)
      min = count;
    // cout << "min:" << min << endl;

  }

  cout << min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
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;}

int main() {
  int N, K; cin >> N >> K;
  vector<int> x(N); rep(i, N) cin >> x[i];
  int ans = 0;
  rep(i,N) {
    ans += min(abs(x[i]-K), x[i])*2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 500005
#define ll long long
#define mod 1000000007
using namespace std;

typedef pair<int, char> P;

char s[maxn];

int main()
{
    scanf("%s", s);
    int n = strlen(s);
    bool ok = 1;
    for (int i = 0; i < n - 1; i++)
        if (s[i] == s[i + 1])
            ok = 0;
    if (ok)
        printf("Good");
    else
        printf("Bad");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	ll a , b ;
  cin >> a >> b ;
  if((a + b)%2 == 0){
    cout << (a +b )/2 ;
    return 0 ; 
  }
  cout << "IMPOSSIBLE" ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  vector<int> a(3);
  rep(i,3) cin>>a[i];
  sort(ALL(a));
  cout << a[2] - a[0] << endl;
}


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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    for (int i = 0; i < N; i++) cin >> x[i];
    for (int i = 0; i < M; i++) cin >> y[i];
     
    for (int Z = X+1; Z <= Y; Z++) {
        bool ok = true;
        for (int e : x) {
            if (e >= Z) ok = false;
        }
        for (int e : y) {
            if (e < Z) ok = false;
        }
        
        if (ok) {
            cout << "No War" << '\n';
            return;
        }
    }
    cout << "War" << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>


int main() {
	int i, n;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0){
		    printf(" %d", i);
		}else{
			while (x) {
			if (x % 10 == 3) {
				printf(" %d", i);
				break;
			    }
			    x /= 10;
		    }
		}
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2040
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, M;
ll A, B, C;
ll vis[100005];
vector<ll> adj[100005];
ll cnt = 0;

void dfs(int node) {
	vis[node] = 1;
	for(int i = 0; i < adj[node].size(); i++) {
		if(!vis[adj[node][i]]) {
			vis[adj[node][i]] = 1;
			dfs(adj[node][i]);
		}
	}
}

int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < M; i++) {
		scanf("%lld %lld %lld", &A, &B, &C);
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	for(int i = 1; i <= N; i++) {
		if(!vis[i]) {
			cnt++;
			// cout << cnt << " ";
			dfs(i);
		}
	}
	for(int i = 1; i <= N; i++) {
		if(!vis[i]) {
			cnt++;
		}
	}
	printf("%lld\n", cnt);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int h, w;
  while (cin >> h >> w) {
    if (!h && !w)
      break;
    rep(i, 0, h) {
      rep(j, 0, w) cout << "#";
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
  	cout << "Possible\n";
  }else {
  	cout << "Impossible\n";
  }
}

Measured memory_bytes: 256
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac
X, Y = map(int, input().split())
dist = X + Y
if dist % 3 != 0:
    print(0)
    quit()
n = int((2 * X - Y) / 3)
m = int((2 * Y - X) / 3)
if n < 0 or m < 0:
    print(0)
    quit()
mod = 10 ** 9 + 7
fac, ifac = make_tables(mod, n + m)
ans = cmb(n + m, m, mod, fac, ifac)
print(ans)


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

int main () {
	int n, m;
	while (cin >> n >> m, n || m) {
		vector<int> member;
		for (int i = 1; i <= n; i++) {
			member.push_back(i);
		}
		m--;
		for (int i = m; member.size() != 1; i = (i + m) % member.size()) {
			member.erase(member.begin() + i);
		}
		cout << member[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
int sorts(char*,int);
int sortt(char*,int);
int main() {
	char s[101],t[101];
	int sl,tl,count,check = 0;
	scanf("%s",s);
	scanf("%s",t);
	sl = strlen(s);
	tl = strlen(t);
	sorts(s,sl);
	sortt(t,tl);
	if(sl < tl) count = sl;
	else count = tl;
	for(int i = 0;i < count;i++) {
		if(s[i] < t[i]) {
			check = 1;
			break;
		}
		if(s[i] > t[i]) {
			check = 2;
			break;
		}
	}
	if(check == 1) printf("Yes\n");
	if(check == 2) printf("No\n");
	if(check == 0) {
		if(sl < tl) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

int sorts(char * s,int sl) {
	char tmp;
	for(int j = sl - 1;j > 0;j--) {
		for(int k = 0;k < j;k++) {
			if(s[k] > s[k+1]) {
				tmp = s[k];
				s[k] = s[k+1];
				s[k+1] = tmp;
			}
		}
	}
	return 0;
}

int sortt(char * s,int sl) {
	char tmp;
	for(int j = sl - 1;j > 0;j--) {
		for(int k = 0;k < j;k++) {
			if(s[k] < s[k+1]) {
				tmp = s[k];
				s[k] = s[k+1];
				s[k+1] = tmp;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

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

        while (true) {
            s = sc.nextLine();
            if (s.equals(".")) break;

            Stack<Character> stack = new Stack<>();
            boolean flg = true;
            for (char c : s.toCharArray()) {
                switch (c) {
                    case '(':
                    case '[':
                        stack.push(c);
                        break;
                    case ')':
                        if (stack.empty() || stack.pop() != '(') flg = false;
                        break;
                    case ']':
                        if (stack.empty() || stack.pop() != '[') flg = false;
                        break;
                }
                if (!flg) break;
            }
            if (!stack.empty()) flg = false;
            System.out.println(flg ? "yes" : "no");
        }
    }
}

Measured memory_bytes: 46796
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
int n, k, t[200020], cnt;
int main()
{
    cin>>n>>k;
    for(int i = 0 ; i < n ; i++ )
    {
        int s;
        cin>>s;
        t[s]++;
    }
    sort(t, t+n);
    for(int i = n-1, j = 0 ; j < k ; i--, j++ ) cnt+=t[i];
    cout<<n-cnt<<endl;
    return 0;
}


Measured memory_bytes: 1024
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
   var [d, w] = arr.shift().split(" ").map(Number);
   if (d == 0 && w == 0) break;
   var yx = [];
   for (var i = 0; i < d; i++) yx[i] = arr.shift().split(" ").map(Number);
   
   var sumFn = function(y, x, yy, xx) {
      var min = Infinity;
      for (var i = y; i <= yy; i++) {
         for (var j = x; j <= xx; j++) {
            if (i == y || j == x || i == yy || j == xx) min = Math.min(min, yx[i][j]);
         }
      }
      var sum = 0;
      for (var i = y; i <= yy; i++) {
         for (var j = x; j <= xx; j++) {
            if (i == y || j == x || i == yy || j == xx) continue;
            if (min <= yx[i][j]) return 0;
            sum += min - yx[i][j];
         }
      }
      return sum;
   };
   
   var max = 0;
   for (var y = 0; y < d - 2; y++) {
      for (var x = 0; x < w - 2; x++) {
         for (var yy = y + 2; yy < d; yy++) {
            for (var xx = x + 2; xx < w; xx++) {
               max = Math.max(max, sumFn(y, x, yy, xx));
            }
         }
      }
   }
   console.log(max);
}


Measured memory_bytes: 17508
rolls = []
for _ in range(int(input())):
  x,y = list(map(int,input().split()))
  rolls.append((x,y))
n = len(rolls)
i = 0
curr = 0
answer = False;
while i < n:
  if rolls[i][0] == rolls[i][1]:
    curr+=1;
    if curr == 3:
      answer = True;
      break;
    i+=1
  else:
    curr = 0
    i+=1;
if answer:
  print("Yes")
else:
  print("No")
  
  

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int gcd(int a,int b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int kaizyou(int N){
  int num=1;
  for(int i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

int mod=1e9+7;

signed main() {
  int N,M;
  cin >> N >> M;
  vector<int>cnt(M);
  rep(i,N){
    int K;
    cin >>K;
    rep(j,K){
      int A;
      cin >> A;
      A--;
      cnt[A]++;
    }
  }
  int ans=0;
  rep(i,M){
    if(cnt[i]==N){
      ans++;
    }
  }
  cout << ans << endl;
}

  
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll fact[200001];
ll inv[2000001];
void factorial()
{
  ll i;
  fact[0] = 1;
  inv[0] = power(fact[0],mod-2);
  for(i=1;i<=200000;i++)
  {
    fact[i] = (i*fact[i-1])%mod;
    inv[i] = power(fact[i],mod-2);
  }
}
ll ncr(ll x,ll y)
{
  if(x<y)
    return 0;
  ll temp = fact[x];
  temp = (temp*inv[y])%mod;
  temp = (temp*inv[x-y])%mod;
  return temp;
}
signed main()
{
    fast;
    factorial();
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    ll ans = 0;
    ll tot = ncr(n-1,k-1);
    for(i=0;i<n;i++)
    {
        ll x = (ncr(i,k-1)-ncr(n-i-1,k-1)+mod)%mod*arr[i]%mod;
        x+=mod;
        x%=mod;
        ans+=x;
        ans%=mod;
    }
    cout<<ans;
}


Measured memory_bytes: 5504
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut tree: Vec<Node> = vec![Node { parent: -1, left: -1, right: -1 }; n];
    for _ in 0..n {
        let id: isize = iterator.next().unwrap().parse().unwrap();
        let left: isize = iterator.next().unwrap().parse().unwrap();
        let right: isize = iterator.next().unwrap().parse().unwrap();

        if left != -1 {
            tree[id as usize].left = left;
            tree[left as usize].parent = id;
        }
        if right != -1 {
            tree[id as usize].right = right;
            tree[right as usize].parent = id;
        }
    }

    let root_id = tree.iter().position(|node| node.parent == -1).unwrap();

    let mut ans = String::new();

    ans += "Preorder\n";

    let mut result = String::new();
    pre_order(&tree, root_id, &mut result);
    ans += &result;
    ans += "\n";

    ans += "Inorder\n";
    let mut result = String::new();
    in_order(&tree, root_id, &mut result);
    ans += &result;
    ans += "\n";

    ans += "Postorder\n";
    let mut result = String::new();
    post_order(&tree, root_id, &mut result);
    ans += &result;
    ans += "\n";

    return ans.trim().to_string();
}

fn pre_order(tree: &Vec<Node>, id: usize, result: &mut String) {
    result.push_str(&format!(" {}", id));
    let node = &tree[id];
    if node.left != -1 {
        pre_order(tree, node.left as usize, result);
    }
    if node.right != -1 {
        pre_order(tree, node.right as usize, result);
    }
}

fn in_order(tree: &Vec<Node>, id: usize, result: &mut String) {
    let node = &tree[id];
    if node.left != -1 {
        in_order(tree, node.left as usize, result);
    }
    result.push_str(&format!(" {}", id));
    if node.right != -1 {
        in_order(tree, node.right as usize, result);
    }
}

fn post_order(tree: &Vec<Node>, id: usize, result: &mut String) {
    let node = &tree[id];
    if node.left != -1 {
        post_order(tree, node.left as usize, result);
    }
    if node.right != -1 {
        post_order(tree, node.right as usize, result);
    }
    result.push_str(&format!(" {}", id));
}

#[derive(Clone)]
struct Node {
    parent: isize,
    left: isize,
    right: isize,
}



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

int main() {

	ll a, b, c, k; cin >> a >> b >> c >> k;

	ll tmp = k;
	
	if (tmp <= a) {
		cout << k << endl;
		return 0;
	}

	tmp -= a;

	if (tmp <= b) {
		cout << a << endl;
		return 0;
	}

	tmp -= b;

	if (tmp <= c) {

		cout << a - tmp << endl;
		return 0;
	}

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

Measured memory_bytes: 3636
from collections import defaultdict

class LCM_mod:
    """
    最小公倍数の計算を行う
    オーバーフローが発生しないように素因数分解し,
    因数の積を逐次余りに置き換えて最小公倍数を導出する.
    """
    def __init__(self, max_num, p=10**9+7):
        self.max_num = max_num + 1
        self.p = p
        self.prime = [0 for _ in range(self.max_num)]
        self.max_map = defaultdict(int)
        self.sieve()

    def rep_sqr(self, base, k):
        # 繰り返し二乗法
        if k == 0:
            return 1
        elif k % 2 == 0:
            return (self.rep_sqr(base, k / 2) ** 2) % self.p
        else:
            return (self.rep_sqr(base, k - 1) * base) % self.p

    def sieve(self):
        """
        エラトステネスの篩　O(n)
        nまでに含まれる素数を導出
        """
        self.prime[0], self.prime[1] = 1, 1
        for i in range(2, self.max_num):
            if self.prime[i] == 0:
                for j in range(i * 2, self.max_num, i):
                    if self.prime[j] == 0:
                        self.prime[j] = i
                self.prime[i] = i

    def lcm_list_mod(self, arr):
        """
        listのそれぞれの要素について、素因数分解する
        それぞれの因数について最大であれば更新する
        """
        for i in range(len(arr)):
            num = arr[i]
            d = defaultdict(int)

            while num > 1:
                fact = self.prime[num]
                d[fact] += 1
                num //= fact

            for i in d.keys():
                self.max_map[i] = max(self.max_map[i], d[i])

        ans = 1
        for i in self.max_map.keys():
            ans = (ans * self.rep_sqr(i, self.max_map[i])) % self.p
        return ans


def rep_sqr(base, k, mod):
    if k == 0:
        return 1
    elif k % 2 == 0:
        return (rep_sqr(base, k / 2, mod) ** 2) % mod
    else:
        return (rep_sqr(base, k - 1, mod) * base) % mod

# a^(-1) == a^(m-2)

def flt(a, mod):
    return rep_sqr(a, mod-2, mod)


n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7

lcm_mod = LCM_mod(max(a), MOD)

lcm_all = lcm_mod.lcm_list_mod(a)

b = list(map(lambda x: lcm_all * flt(x, MOD), a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)


Measured memory_bytes: 114928
#include <bits/stdc++.h>
using namespace std;
//using pi = pair<int, int>;
const int MAXN = 1005;
const int MAXM = 200005;
 
vector<int> gph[MAXN];
int adj[MAXN][MAXN], vis[MAXN];
int n, m;
int s[MAXM], e[MAXM];
 
void dfs(int r, int v){
	vis[v] = 1;
	adj[r][v]++;
	int cnt=gph[v].size();
	for(int it=0;it<cnt;it++){
		int i=gph[v][it];
		if(i == r) continue;
		if(!vis[i] && adj[r][i] < 2){
			dfs(r, i);
		}
	}
}
 
int main(){
	cin >> n >> m;
	for(int i=0; i<m; i++){
		scanf("%d %d",&s[i],&e[i]);
		gph[s[i]].push_back(e[i]);
	}
	for(int i=1; i<=n; i++){
		int cnt=gph[i].size();
		for(int it=0;it<cnt;it++){
			int j=gph[i][it];
			if(adj[i][j] < 2){
				memset(vis, 0, sizeof(vis));
				dfs(i, j);
			}
		}
	}
//	for(int i=1;i<=n;i++){
//	    for(int j=1;j<=n;j++){
//	        printf("%d ",adj[i][j]);
//	    }
//	    printf("\n");
//	}
	for(int i=0; i<m; i++){
		if(adj[e[i]][s[i]] == 0){
			puts(adj[s[i]][e[i]] > 1 ? "diff" : "same");
		}
		else{
			puts(adj[s[i]][e[i]] > 1 ? "same" : "diff");
		}
	}
}

Measured memory_bytes: 8192
#include <stdio.h>
int n, c, t[1000], p[1000], q[1000], r[1000], P, Q, R, C;
int main() {
	while(scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) scanf("%d%d%d%d", &t[i], &p[i], &q[i], &r[i]);
		scanf("%d%d%d%d", &P, &Q, &R, &C); c = 0;
		for(int i = 0; i < n; i++) {
			if(p[i] <= P && q[i] <= Q && r[i] <= R && p[i] * 4 + q[i] * 9 + r[i] * 4 <= C) printf("%d\n", t[i]), c++;
		}
		if(!c) printf("NA\n");
	}
}

Measured memory_bytes: 2672
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    const ull mod = 1000000007;

    ull n;
    cin >> n;

    vector<ull> v = fetch_vec<ull>(n);

    ull sum = 0;

    for (int bit = 0; bit < 60; ++bit)
    {
        ull ones = 0;

        for (int i = 0; i < n; ++i)
        {
            if ((v[i] & (1LL << bit)) != 0)
                ++ones;
        }

        sum = (sum + (1LL << bit) % mod * ones % mod * (n - ones) % mod) % mod;
    }

    cout << sum << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#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 RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
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; }

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

    int N; cin >> N;
    cout << 3 * pow(N, 2) << '\n';

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}

int main() {
    string t,s;
    cin >> t >> s;
    ll ans = 0;
    for(int i=0;i<t.size();i++){
        if(t.at(i)!=s.at(i))ans++;
    }
    cout<<ans<<endl;
}
    



Measured memory_bytes: 3864
#pragma region header
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int ceil_div(int X, int Y) { return (X - 1) / Y + 1; }

void solve(int a, int b) {
  cout<<ceil_div(a+b, 2)<<endl;
}

#pragma region main
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);

  int a;
  cin >> a;
  int b;
  cin >> b;
  solve(a, b);
}
#pragma endregion main


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

int main(){
  int n;  cin >> n;
  vector<int> cnt(26, 0);
  string s; cin >> s;
  for(int i=0; i<s.size(); i++){
    cnt[s[i]-'a'] += 1;
  }

  for(int i=1; i<n; i++){
    cin >> s;
    vector<int> tmp(26, 0);
    for(int i=0; i<s.size(); i++){
      if(cnt[s[i]-'a']==0) continue;
      tmp[s[i]-'a'] += 1;
    }
    for(int i=0; i<26; i++)
      cnt[i] = min(cnt[i], tmp[i]);
  }
  for(int i=0; i<26; i++)
    for(int j=0; j<cnt[i]; j++){
      printf("%c", i+'a');
    }
  cout << endl;
}


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

using namespace std;

int main(){
	int p[26]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};
	
	int n;
	cin >>n;
	long long product[n];
	char temp;
	for(int i=0;i<n;i++){
		product[i]=1;
		for(int j=0;j<10;j++){
			cin >>temp;
			product[i]=product[i]*p[((int)temp)-97];
		}
	}
	sort(product,product+n);
	long sum=1,ans=0;
	for(int i=1;i<n;i++){
		if(product[i-1]==product[i]){
			sum++;
		}else{
			ans=ans+(sum*(sum-1))/2;
			sum=1;
		}
	}
	ans=ans+(sum*(sum-1))/2;
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];

    vector<int> dp(n, 0);
    for (int i = 1; i < n; i++)
    {
        dp[i] = INT_MAX;
        if (i - 1 >= 0 && dp[i - 1] + abs(h[i] - h[i - 1]) < dp[i])
            dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        if (i - 2 >= 0 && dp[i - 2] + abs(h[i] - h[i - 2]) < dp[i])
            dp[i] = dp[i - 2] + abs(h[i] - h[i - 2]);
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }
bool reachble(vector<vint> str, int s, int e);
bool plusReachble(vector<vint> stair, int d, int m, int g);

int n;

bool reachble(vector<vint> str, int s, int e)
{
    rep(i, str.size())
    {
        if(s < n-1 && str[i][s]) s++;
        else if(0 < s && str[i][s-1]) s--;
    }
    
    return s == e;
}

bool plusReachble(vector<vint> stair, int d, int m, int g)
{
    rep(i, d) rep(j, n-1) if(!stair[i][j] && (j == 0 || !stair[i][j-1]) && (j == n-2 || !stair[i][j+1]))
    {
        stair[i][j] = 1;
        if(reachble(stair, m, g))
        {
            cout << i + 1 << " " << j + 1 << endl;
            return true;
        }
        stair[i][j] = 0;
    }
    return false;
}

int main()
{
    while(cin >> n && n)
    {
        int m, g, d;
        cin >> m >> g >> d;
        m--; g--;
        
        vector<vint> stair(d, vint(n-1));
        
        rep(i, d)
        {
            string bln;
            cin >> bln;
            
            rep(j, n - 1)
                stair[i][j] = bln[j] - '0';
        }
        
        
        if(reachble(stair, m, g)) cout << 0 << endl;
        else if(plusReachble(stair, d, m, g));
        else cout << 1 << endl;
    }    
}

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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll,ll>> sc(m);
    for(ll i = 0;i < m;i++){
        cin >> sc[i].first >> sc[i].second;
    }

    if(n == 1 && m == 0){
        cout << 0;

        return 0;
    }
    vector<ll> s(3);
    for(ll i = 0;i < 3;i++){
        s[i] = -1;
    }

    for(ll i = 0;i < m;i++){
        s[sc[i].first - 1] = sc[i].second;
    }

    for(ll i = 0;i < m;i++){
        if(s[sc[i].first - 1] != sc[i].second){
            cout << -1;

            return 0;
        }
    }

    if(s[0] == 0 && n != 1){
        cout << -1;

        return 0;
    }

    if(s[0] == -1){
        s[0] = 1;
    }

    for(ll i = 0;i < n;i++){
        if(s[i] == -1){
            s[i] = 0;
        }
        cout << s[i];
    }

    return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	vector<int> p( N );
	for( auto& v: p ) { cin >> v; }
	sort( p.begin(), p.end() );

	int result = 0;
	for( int i = 0; i < N-1; ++i ) {
		result += p[i];
	}
	result += p.back() / 2;

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val xyh = (1..readLine()!!.toInt()).map { readLine()!!.split(" ").map(String::toInt) }.sortedByDescending { it[2] }
    for (x in 0..100) {
        for (y in 0..100) {
            val h = xyh[0][2] + Math.abs(x - xyh[0][0]) + Math.abs(y - xyh[0][1])
            val r = (1 until xyh.size).map { xyh[it][2] == listOf(h - Math.abs(x - xyh[it][0]) - Math.abs(y - xyh[it][1]), 0).max() }
            if (!r.contains(false)) print("$x $y $h")
        }
    }
}

Measured memory_bytes: 56500
N = int(input())
A = [int(input()) for _ in range(N)]

max_l, max_r = [A[0]], [A[-1]]
for i in range(N-1):
    max_l.append(max(A[i+1],   max_l[i]))
    max_r.append(max(A[N-2-i], max_r[i]))

print(max_r[-2])
for i in range(1,N-1):
    print(max(max_r[-2-i], max_l[i-1]))
print(max_l[N-2])

Measured memory_bytes: 15676
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] -= i + 1;
  }

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

  int b;
  if (n % 2 == 1) {
    b = v[n / 2];
  } else {
    b = v[n / 2 - 1];
  }

  ll res = 0;
  for (int i = 0; i < n; i++) {
    res += abs(v[i] - b);
  }
  cout << res << endl;
}


Measured memory_bytes: 1024
N =gets.to_i
T,A = gets.strip.split.map(&:to_i)
H = gets.strip.split.map(&:to_i)

minh = 100000000
minhi = 0

(0..N-1).each do |i|
  if (T - 0.006 * H[i] - A).abs < minh
    minhi = i
    minh = (T - 0.006 * H[i] - A).abs
  end
end

puts minhi +1

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

int main(){
    int n;
    string a;
    cin>>n;
    for(int i=0; i<n; i++){
        int hit[3]={};
        int score= 0;;
        int out = 0;
        while(cin>>a){
            if(a=="HIT"){
                if(hit[2]==1)score++;
                hit[2]=hit[1];
                hit[1]=hit[0];
                hit[0]=1;
            }
            if(a=="HOMERUN"){
                score++;
                for(int t=0; t<3; t++){
                    if(hit[t]==1){
                        score++;
                        hit[t]=0;
                    }
                }
            }
            if(a=="OUT"){
                out++;
            }
            if(out==3)break;
        }
        cout<<score<<endl;
}
    return 0;
}

Measured memory_bytes: 3164
# coding: utf-8
N, M = map(int, input().split())
L, R = 0, 10**6
card = []
for i in range(M):
    l, r = map(int, input().split())
    L = max(L, l)
    R = min(R, r)
print(R - L + 1 if L <= R else 0)

Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a = INT()
s = input()

print(s if a >= 3200 else "red")

Measured memory_bytes: 5144
#include<iostream>
using namespace std;
int main(){
	int n,a;
	cin>>n;
	a=n/1000;
	if(a==0||n==1000)cout<<1000-n;
	else if(a==1||n==2000)cout<<2000-n;
	else if(a==2||n==3000)cout<<3000-n;
	else if(a==3||n==4000)cout<<4000-n;
	else if(a==4||n==5000)cout<<5000-n;
	else if(a==5||n==6000)cout<<6000-n;
	else if(a==6||n==7000)cout<<7000-n;
	else if(a==7||n==8000)cout<<8000-n;
	else if(a==8||n==9000)cout<<9000-n;
	else if(a==9||n==10000)cout<<10000-n;
	return 0;
}

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

int a[10][10], b[6];
int ans;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	for(int i=0; i<10; ++i)
		for(int j=0; j<10; ++j)
			cin >> a[i][j];
	++b[1];
	while(1){
//		cout << b[0] << " " << b[1] << " " << b[2] << " " << b[3] << "\n";
		int c = 0;
		for(int i=4; i>=1; --i)
			c = a[c][b[i]];
		b[0] = c;
//		cout << b[4] << " " << b[3] << " " << b[2] << " " << b[1] << " " << b[0] << "\n";
		bool f = false;
		for(int i=0; i<5; ++i)
			for(int j=1; j<10; ++j){
				b[i] += j;
				b[i] %= 10;
				int t = 0;
				for(int k=4; k>=0; --k)
					t = a[t][b[k]];
				if(t == 0)
					f = true;
				b[i] -= j - 10;
				b[i] %= 10;
			}
		for(int i=0; i<4; ++i){
			if(b[i] == b[i+1]) continue;
			swap(b[i], b[i+1]);
			int t = 0;
			for(int k=4; k>=0; --k)
				t = a[t][b[k]];
			if(t == 0)
				f = true;
			swap(b[i], b[i+1]);
		}
		if(f) ++ans;
		++b[1];
		for(int i=1; i<=4; ++i){
			if(b[i] == 10){
				b[i] = 0;
				++b[i+1];
			}
		}
		if(b[4]+b[3]+b[2] == 0 && b[1] == 1) break;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3092
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	ll N, K;
	cin >> N >> K;
	cout << max(N + K, max(N - K, N * K)) << endl;
}

Measured memory_bytes: 764
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                set.add(i * j);
            }
        }
        if (set.contains(n)) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 21844