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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int cntl = 0, cntr = 0, addr, addl;
  for (int i=0; i<N; i++) {
    if (S[i] == '(')
      cntl++;
    else if (S[i] == ')' && cntl == 0)
      cntr++;
    else
      cntl--;
  }
  addr = cntr;
  cntr = 0;
  cntl = 0;
  for (int i=N-1; i>=0; i--) {
    if (S[i] == ')')
      cntr++;
    else if (S[i] == '(' && cntr == 0)
      cntl++;
    else
      cntr--;
  }
  addl = cntl;
  while (addr != 0) {
    cout << '(';
    addr--;
  }
  cout << S;
  while (addl != 0) {
    cout << ')';
    addl--;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 105;
typedef long long ll;
ll f[maxn][5];
string s;
int k;
ll dfs(int pos, int now, bool lead, bool eq) {
    if (now > k) return 0;

    if (pos == s.length()) {
        if (now == k) return 1;
        else return 0;
    }
    if (!lead && !eq && ~f[pos][now]) return f[pos][now];
    int ed = eq ? (s[pos] - '0') : 9;
    ll ret = 0;
    for (int i = 0;i <= ed;i++) {
        ret += dfs(pos + 1, now + (i != 0), lead && i == 0, eq && i == ed);
    }
    if (!lead && !eq) f[pos][now] = ret;
    return ret;
}
ll solve(string& s) {
    memset(f, -1, sizeof f);
    return dfs(0, 0, true, true);
}
int main() {
   
    cin >> s;
    cin >> k;
    printf("%lld\n", solve(s));
    return 0;
}

Measured memory_bytes: 3744
A, B, C = map(int, input().split())
K = int(input())

count = 0
while True:
  if B > A:
    break
    
  else:
    B = B * 2
    count += 1
    
while True:
  if C > B:
    break
    
  else:
    C = C * 2
    count += 1    

if count <= K:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> a(n + 1);
    for(int i = 1; i < n; i++){
        if(s[i] == 'C' && s[i - 1] == 'A')
        a[i + 1] =a[i] + 1;
        else
        {
            a[i + 1] = a[i];
        }
    }
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        cout << a[r] - a[l] << endl;
    }
}

Measured memory_bytes: 1408
S = input()
A = int(S[:2])
B = int(S[2:])

def YorM(i):
  if 1 <= i and i <= 12:
    return "b"
  elif i < 1 or 12 < i:
    return "y"
  else:
    return "n"
  
isA = YorM(A)
isB = YorM(B)

if isA == "n" or isB == "n":
  print("NA")
elif isA == "b" and isB == "b":
  print("AMBIGUOUS")
elif isA == "y" and isB == "y":
    print("NA")
elif isA == "y":
  print("YYMM")
else:
  print("MMYY")

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

int main()
{
	int n, x, i, j, k;
	cin >> n >> x;
	int l[100];
	int dd = 0;
	int count = 0;
	//int b[200002];
	for (i = 0; i < n; i++)
	{
		cin >> l[i];
	}

	for (i = 0; i <= n; i++)
	{
		if (dd <= x)count++;
		dd += l[i];
	}
	cout << count;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, n) for(int i = n-1; i >= 0; i--)
#define rep4(i, x, n) for(int i = x; i > n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    bool able1 = true, able2 = true;
    rep2(i, A, C-2){
        if(S[i] == '#' && S[i+1] == '#') able1 = false;
    }
    rep2(i, B, D-2){
        if(S[i] == '#' && S[i+1] == '#') able2 = false;
    }
    if(!able1 || !able2){
        cout << "No" << endl;
        exit(0);
    }
    if(C < D){
        cout << "Yes" << endl;
        exit(0);
    }
    bool able = false;
    rep2(i, B-1, D){
        if(S[i-1] == '.' && S[i] == '.' && S[i+1] == '.') able = true;
    }
    if(able) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            Console.WriteLine(Math.Pow(N, 3));
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Minpro2019_2_9
{
    class A
    {
        public static void Solve()
        {
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var o = (inputs[0] + 1) / 2 >= inputs[1] ? "YES" : "NO";
            Console.WriteLine(o);
        }
    }
}
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Minpro2019_2_9.A.Solve();
        }
    }
}


Measured memory_bytes: 13268
# frozen_string_literal: true

x, y, a, b, c = gets.split.map(&:to_i)
p = gets.split.map(&:to_i).sort.reverse
q = gets.split.map(&:to_i).sort.reverse
r = gets.split.map(&:to_i).sort.reverse

p_tmp = p[0, x].reverse
q_tmp = q[0, y].reverse
sum = p_tmp.inject(:+) + q_tmp.inject(:+)
p_changes = 0
q_changes = 0

i = 0
loop do
  break if p_changes >= x && q_changes >= y

  if q_changes >= y || p_changes <= x && p_tmp[p_changes] <= q_tmp[q_changes]
    break unless p_tmp[p_changes] < r[i]

    sum += r[i] - p_tmp[p_changes]
    p_tmp[p_changes] = r[i]
    p_changes += 1
  else
    break unless q_tmp[q_changes] < r[i]

    sum += r[i] - q_tmp[q_changes]
    q_tmp[q_changes] = r[i]
    q_changes += 1
  end
  i += 1
  break if r.length <= i
end

puts sum


Measured memory_bytes: 25824
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
current = 1
kudaita = 0
a.each do |renga|
  if (renga != current)
    kudaita += 1
  else
    current += 1
  end
end
puts n == kudaita ? '-1' : kudaita

Measured memory_bytes: 16772
n, m = map(int, input().split())

lst = [[] for i in range(3*n+1)]
dist = [-1 for i in range(3*n+1)]
for i in range(m):
    u, v = map(int, input().split())
    lst[u].append(v+n)
    lst[u+n].append(v+2*n)
    lst[u+2*n].append(v)

s, t = map(int, input().split())

next = lst[s]
next_next = []
not_empty = True
cost = 1
while not_empty:
    not_empty = False
    for i in next:
        if dist[i] == -1:
            dist[i] = cost
            next_next.extend(lst[i])
            not_empty = True
    next = next_next.copy()
    next_next = []
    cost += 1

if dist[t] % 3 == 0:
    print(dist[t]//3)
else:
    print(-1)

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

int main(){
	long long int n,k;
	long long int p=1e+9+7;
	cin>>n>>k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin>>a[i];
	}
	//同数列内の転倒数
	long long int s=0;
	for (int i = 0; i < n-1; i++) {
		for (int j = i+1; j < n; j++) {
			if (a[i]>a[j]) {
				s++;
			}
		}
	}
	s%=p;
	//別数列間の転倒数
	long long int d=0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (a[i]>a[j]) {
				d++;
			}
		}
	}
	d%=p;
	long long int ans=0;
	ans+=s*k;
	ans%=p;
	long long int temp;
	temp=k*(k-1)/2;
	temp%=p;
	temp*=d;
	temp%=p;
	ans+=temp;
	ans%=p;
	cout<<ans<<endl;
}

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

using namespace std ;

int main(){

    double W,H,x,y;

    cin >> W >> H >> x >> y;

    cout << W*H/2 << endl;


    if(x==W/2 && y==H/2){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }


    
    return 0;
}



Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))

dp= [0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]))
 
print(dp[n-1])

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

int main() {
  int H = 0, W = 0;
  cin >> H >> W ;
  string pict[101];
  for (int i = 0; i < H; i++) {
    cin >> pict[i];
  }
  for (int i = 0; i < W+2;i++) {
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < H;i++) {
    cout << '#' << pict[i] << '#' << endl;
  }
  for (int i = 0; i < W+2;i++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
from math import sqrt

A, B = map(int, input().split())

def divisor(a, b):
    max_num = int(sqrt(a))
    divisor_list = []
    for i in range(1, max_num + 1):
        if a % i == 0 and b % i == 0:
            divisor_list.append(i)
            # for j in divisor_list:
            #     if a % (i*j) == 0 and b % (i*j) == 0:
            #         divisor_list.append(i)
            # divisor_list.append(i)
        tmp = a//i
        if a % tmp == 0 and b % tmp == 0:
            divisor_list.append(tmp)
            # for j in divisor_list:
            #     if a % (tmp*j) == 0 and b % (tmp*j) == 0:

    return list(set(divisor_list))

common_list = divisor(A, B)
common_list.sort()

# print(common_list)

length = len(common_list)
max_common = common_list[-1]
prods = []
dic = {c: 0 for c in common_list}

for i in range(1, length):
    for j in range(1, length):
        prod = common_list[i] * common_list[j]
        if prod > max_common:
            continue
        else:
            dic[prod] = 1
ans = 0
for c in common_list:
    if dic[c] == 0:
        ans += 1
        # print(c)

print(ans)

Measured memory_bytes: 108444
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int out[100002];
int n, t[100001];
bool solve() {
	Rep(i, 1, n+1) {
		if (t[i] ^ out[i])out[i + 1] = 1 - out[i - 1];
		else out[i + 1] = out[i - 1];
	}
	if (out[n]==out[0]&&out[n+1]==out[1]) {
		rep(i, n) {
			if (out[i])cout << 'S';
			else cout << 'W';
		}
		cout << endl; return true;
	}
	return false;
}
int main() {
	string s; cin >> n >> s;
	rep(i, n) {
		if (s[i] == 'o')t[i] = 1;
		else t[i] = 0;
	}
	t[n] = t[0];
	out[0] = out[1] = 1;
	if (!solve()) {
		out[0] = 1; out[1] = 0;
		if (!solve()) {
			out[0] = 0; out[1] = 1;
			if (!solve()) {
				out[0] = out[1] = 0;
				if (!solve()) {
					cout << -1 << endl;
				}
			}
		}
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int A,B,C,X,Y; 
    cin >> A >> B >> C >> X >> Y;
    int m,l,b;
    if(X > Y){
        m = Y;
        l = X;
        b = A;
    }else{
        m = X;
        l = Y;
        b = B;
    }

    ll ans = 0;

    if(A*m + B*m >= 2*C*m){
        ans += 2*C*m;
    }else{
        ans += A*m + B*m;
    }
    int d = l - m;;
    if(b*d > 2*d*C){
        ans += 2*d*C;
    }else{
        ans += b*d;
    }
    cout << ans << endl;
}

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

from collections import defaultdict
d = defaultdict(int)

for a in A:
  d[a] += 1

ans = 0
for k,v in d.items():
  if k > v:
    ans += v
  else:
    ans += v-k

print(ans)

Measured memory_bytes: 18164
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n,x[100005],a=0;
	long long s[2];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x[i];
	}
	sort(x,x+n);
	for(int i=n-1;i>0;i--){
		if(x[i]==x[i-1]){
			a++;
			s[a-1]=x[i];
			i--;
			if(a==2){
				cout << s[0]*s[1] << endl;
				return 0;
			}
		}
	}
	cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define maxs(x,y) (x = max(x,y))
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int n,m,ans,a,b;
vvi to;
vi used, vs;
void dfs(int v)
{
	if (used[v]) return;
	used[v]=1;
	for (int u : to[v]) dfs(u);
	vs.pb(v);
}
int main()
{
	cin>>n>>m;
	to=vvi(n); used=vi(n);
	for (int i=0;i<m;i++)
	{
		cin>>a>>b;
		a--,b--;
		to[a].pb(b);
	}
	for (int i=0;i<n;i++) dfs(i);
	vi dp(n,0);
	for (int v : vs)
	{
		for (int u : to[v]) maxs(dp[v], dp[u]+1);
		maxs(ans, dp[v]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
map<ll,ll>mp;
vector<ll>v;
int main()
{
    ll a,b,c,i,j,k;
    string s,d,e;
    cin>>s;
    a=s.size();
    for(i=0;i<a;i++)
    {
        cout<<'x';
    }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[][] board = new char[n][];
            for (int i = 0; i < n; ++i) board[i] = in.next().toCharArray();
            int res = 0;
            outer:
            for (int s = 0; s < n; ++s) {
                for (int i = 0; i < n; ++i) {
                    for (int j = 0; j < n; ++j) {
                        char c1 = board[i][(j + s) % n];
                        char c2 = board[j][(i + s) % n];
                        if (c1 != c2) {
                            continue outer;
                        }
                    }
                }
                res += n;
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

int H, W, K;
char c[6][6];
int sum_with_mask[6][1 << 6];

int dfs(int crt_col, int row_mask, int crt_sum) {
    if(crt_col == W) {
        if(crt_sum == K) return 1;
        else return 0;
    }

    int ret = 0;

    ret += dfs(crt_col + 1, row_mask, crt_sum); // not select
    ret += dfs(crt_col + 1, row_mask, crt_sum + sum_with_mask[crt_col][row_mask]); // select

    return ret;
}

int main() {
    cin >> H >> W >> K;
    rep(i, H) rep(j, W) cin >> c[i][j];

    rep(j, W) rep(row_mask, (1 << H)) {
        int sum = 0;
        rep(i, H) if((row_mask & (1 << i)) && c[i][j] == '#') sum++;
        sum_with_mask[j][row_mask] = sum;
    }

    int ans = 0;
    rep(row_mask, (1 << H)) {
        ans += dfs(0, row_mask, 0);
    }

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


Measured memory_bytes: 3576
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	A := make([][]int, 3)
	for i := 0; i < 3; i++ {
		A[i] = ReadInts(3)
	}
	N := ReadInt()
	b := ReadInts(N)
	for _, bi := range b {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if A[i][j] == bi {
					A[i][j] = 0
				}
			}
		}
	}

	for i := 0; i < 3; i++ {
		ok := true
		for j := 0; j < 3; j++ {
			if A[i][j] != 0 {
				ok = false
			}
		}
		if ok {
			fmt.Println("Yes")
			return
		}
	}

	for i := 0; i < 3; i++ {
		ok := true
		for j := 0; j < 3; j++ {
			if A[j][i] != 0 {
				ok = false
			}
		}
		if ok {
			fmt.Println("Yes")
			return
		}
	}

	ok := true
	for i := 0; i < 3; i++ {
		if A[i][i] != 0 {
			ok = false
		}
	}
	if ok {
		fmt.Println("Yes")
		return
	}

	ok = true
	for i := 0; i < 3; i++ {
		if A[i][2-i] != 0 {
			ok = false
		}
	}
	if ok {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
#define enl << endl
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n, a;
    int marker[8];
    rep(i, 8){
        marker[i] = 0;
    }

    cin >> n;

    int cnt = 0;
    rep(i, n){
        cin >> a;
        if(a < 3200){
            marker[a/400] = 1;
        }else{
            cnt++;
        }
    }

    int res = 0;
    rep(i, 8){
        if(marker[i]) res++;
    }

    if(res == 0 && cnt > 0){
        cout << 1 sp min(cnt, 8) << endl;
        return 0;
    }

    cout << res sp res+cnt << endl;

    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input().rstrip()

dp = [[0] * 3 for _ in range(n)]


def score(i, j):
    if j == 0:  # 'r'
        if t[i] == 's':
            return r
    elif j == 1:  # 's'
        if t[i] == 'p':
            return s
    else:  # 'p'
        if t[i] == 'r':
            return p
    return 0


for i in range(n):
    for j in range(3):
        if i >= k:
            dp[i][j] = max(dp[i-k][(j+1)%3], dp[i-k][(j+2)%3]) + score(i, j)
        else:
            dp[i][j] = score(i, j)

total = 0
for i in range(n-k, n):
    total += max(dp[i][0], dp[i][1], dp[i][2])

print(total)


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

int main(){
	int num[3];
	int tmp;
	for(int n=0;n<3;n++)cin>>num[n];
	for(int x=0;x<3;x++){
		for(int y=2;y>0;y--){
			if(num[y]<num[y-1]){
				tmp=num[y];
				num[y]=num[y-1];
				num[y-1]=tmp;
			}
		}
	}
	cout<<num[0]<<" "<<num[1]<<" "<<num[2]<<endl;
	return 0;
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

ll f(ll x, ll a, ll b, ll c, ll d, map<ll, ll>& memo) {
    if (x == 0) return 0;
    if (x == 1) return d;
    if (memo[x] != 0) return memo[x];
    ll ans = LLONG_MAX;
    if ((double)x * d <= 1e18) ans = x * d;
    ans = min(ans, f(x / 2, a, b, c, d, memo) + a + (x - x / 2 * 2) * d);
    ans = min(ans, f((x + 1) / 2, a, b, c, d, memo) + a + ((x + 1) / 2 * 2 - x) * d);
    ans = min(ans, f(x / 3, a, b, c, d, memo) + b + (x - x / 3 * 3) * d);
    ans = min(ans, f((x + 2) / 3, a, b, c, d, memo) + b + ((x + 2) / 3 * 3 - x) * d);
    ans = min(ans, f(x / 5, a, b, c, d, memo) + c + (x - x / 5 * 5) * d);
    ans = min(ans, f((x + 4) / 5, a, b, c, d, memo) + c + ((x + 4) / 5 * 5 - x) * d);
    return memo[x] = ans;
}

int main() {
    int T; cin >> T;
    while (T--) {
        ll x, a, b, c, d;
        cin >> x >> a >> b >> c >> d;
        map<ll, ll> memo;
        cout << f(x, a, b, c, d, memo) << endl;;
    }
}


Measured memory_bytes: 4352
from typing import MutableSequence


def insertion_sort(A_list: MutableSequence, num: int) -> None:
    """挿入ソート"""
    for i in range(num):

        j = i
        tmp = A_list[i]

        while j > 0 and A_list[j - 1] > tmp:
            A_list[j] = A_list[j - 1]
            j -= 1

        A_list[j] = tmp
        print_list = [str(i) for i in A_list]
        print(' '.join(print_list))


if __name__ == '__main__':
    n = int(input())
    input_list = [int(x) for x in input().split()]

    insertion_sort(input_list, n)


Measured memory_bytes: 7168
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const ll INF1 = ll(1e15);
const int MAX = 200002;

int N,M;
int ny,nx;
int edge[200][200] = {0};
int visit[MAX] = {0};
int cx[MAX],cy[MAX];

struct S
{
    int x,y;
};
S a[200],b[200];

int part(int u)
{
    for(int v= 1;v<=ny;v++)
    {
        if(edge[u][v]&&!visit[v])
        {
            visit[v] = 1;
            if(cy[v]==-1||part(cy[v]))
            {
                cx[u] = v;
                cy[v] = u;
                return 1;
            }
        }
    }
    return 0;
}

int maxmatch()
{
    int res = 0;
    memset(cx,-1,sizeof(cx));
    memset(cy,-1,sizeof(cy));
    for(int i = 1;i<=nx;i++)
    {
        if(cx[i]==-1)
        {
            memset(visit,0,sizeof(visit));
            res +=part(i);
        }
    }
    return res;
}

int main()
{
    cin>>N;
    for(int i = 1;i <=N;i++)
        cin>>a[i].x>>a[i].y;
    for(int i = 1;i <= N;i++)
        cin>>b[i].x>>b[i].y;
    ny = nx = N;
    for(int i = 1;i <= 100;i++)
    {
        for(int j = 1;j <= 100;j++){
            if(a[i].x<b[j].x&&a[i].y<b[j].y)
                edge[i][j] = 1;
        }
    }

    cout<<maxmatch()<<endl;

    return 0;
}


Measured memory_bytes: 2688
N, M, X, Y=map(int, input().split())

X_Y=list(range(X+1,Y+1))
X_max=max(map(int, input().split()))
Y_min=min(map(int, input().split()))
count=0
for i in X_Y:
  if X_max<i and Y_min>=i:
    print('No War')
    count+=1
    break

if count!=1:
  print('War')
  

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
  int N, A, B;
  
  // 標準入力から数値を受け取る
  cin >> N >> A >> B;
  
  // 数値の範囲チェック
  if( ( 1 <= N ) && ( 20 >= N ) &&
      ( 1 <= A ) && ( 50 >= A ) &&
      ( 1 <= B ) && ( 50 >= B ) )
  {
    int a_price = N * A;
    if( a_price < B )
      cout << a_price << endl;
    else
      cout << B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
V = gets.chomp.split.map(&:to_i)
C = gets.chomp.split.map(&:to_i)

summed = Array.new(N)
0.upto(N-1).each do |i|
  summed[i] = V[i] - C[i]
end

ans = 0
summed.sort_by {|e| - e }.each do |k|
  if k > 0
    ans += k
  end
end

p ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
  
 
  
int main(){
  
    int n; 
    while(scanf("%d",&n),n){
 
        vector<pair<int,int> > rw(n);
        int sum_r=0,sum_w=0;
        for(int i=0;i<n;i++){
            cin>>rw[i].first>>rw[i].second;
            sum_r+=rw[i].first;
            sum_w+=rw[i].second;
        }
        sort(rw.begin(),rw.end(),greater< pair<int,int> >());
 
        int r0=rw[0].first;
        int r=sum_r-r0;
 
        if(r0 <= r){
            cout<<sum_r+sum_w<<endl;
        }else{
 
            int res=2*r0;
            vector<vector<bool> > dp(1001,vector<bool>(1000,false));
 
            dp[1][0]=true;
            for(int i=1;i<n;i++){
                for(int j=0;j<=1000;j++){
                    if(dp[i][j]){
                        dp[i+1][j]=true; 
                        if(j+rw[i].second<=1000)
                            dp[i+1][j+rw[i].second]=true; 
                    }
                }
            }
 
            int opt=0;
            for(int i=1;i<=r0-r;i++){
                if(dp[n][i]) opt=i;
            }
 
            res+=sum_w-opt;
            printf("%d\n",res);
 
 
 
        }
         
         
    }
}

Measured memory_bytes: 3396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;


int main() {
	int r, d, x, ans;
	cin >> r >> d >> x;
	for (int i = 1;i <= 10;i++) {
		ans = r * x - d;
		cout << ans << endl;
		x = ans;
	}
}

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

int main() {
  string n;
  cin >> n;
  for ( int i = 0; i < n.length(); i++ ) {
    n[i] = ( n[i] == '1' ) ? '9' : '1';
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
w = [input() for i in range(n)]
check = set(w)
counter = [w.count(i) for i in check]
if 2 <= max(counter):
    print('No')
else:
    tail = w[0][-1]
    cnt = 0
    for i in w[1:]:
        if tail == i[0]:
            cnt += 1
        tail = i[-1]
    print('Yes' if cnt == n-1 else 'No')

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,q;
	cin>>n>>q;
	while(q--){
		ll a,b;
		cin>>a>>b;
		if(n==1)cout<<min(a,b)<<endl;
		else{
			vi A({-1});
			vi B({-2});
			while(a!=1){
				A.pb(a);
				a=(a+n-2)/n;
			}
			while(b!=1){
				B.pb(b);
				b=(b+n-2)/n;
			}
			A.pb(1);
			B.pb(1);
			rep(i,40)if(A[A.size()-1-i]!=B[B.size()-1-i]){
				cout<<A[A.size()-i]<<endl;
				break;
			}
		}
	}
}




















Measured memory_bytes: 1280
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=300+10;
const int mod=1e9+7;

int n,m;
vector<pair<int,int>> v[N];
int dp[N][N][N];

bool check(int x,int y,int z) {
	for (auto i:v[x]) {
		int l=i.first,c=i.second;
		if ((x>=l)+(y>=l)+(z>=l)!=c) return 0;
	}
	return 1;
}

int main() {
	n=read(),m=read();
	for (int i=1;i<=m;++i) {
		int l=read(),r=read(),c=read();
		v[r].emplace_back(make_pair(l,c));
	}
	dp[1][0][0]=3;
	for (int i=1;i<n;++i)
		for (int j=0;j<i;++j)
			for (int k=0;!k||k<j;++k) {
				if (check(i+1,j,k))
					dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%mod;
				if (check(i+1,i,j))
					dp[i+1][i][j]=(dp[i+1][i][j]+dp[i][j][k])%mod;
				if (check(i+1,i,k))
					dp[i+1][i][k]=(dp[i+1][i][k]+dp[i][j][k])%mod;
			}
	int ans=0;
	for (int i=0;i<n;++i)
		for (int j=0;!j||j<i;++j)
			if (check(n,i,j)) ans=(ans+dp[n][i][j])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 59328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(v) (v).begin(),(v).end()

int main() {

  ll N;
  cin >> N;
  ll ans = 1e13;
  for(ll i=sqrt(N)+1; i>0; i--) {
    if(N%i != 0) continue;
    ans = min(ans, i+N/i-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
    vector<int>c;
    vector<ll>s;
    vector<int>f;
ll solve(int p,ll t){
    if(p==n-1)return t;
    while(1){
        if(t>=s[p]&&t%f[p]==0){
            return solve(p+1,t+c[p]);
        }
        else{
            t++;
        }
        
    }
}
int main(){
    cin >> n;
    c.resize(n-1);
    s.resize(n-1);
    f.resize(n-1);
    rep(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
    }
    rep(i,n-1){
        cout << solve(i,0) << endl;
    }
    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = sorted([''.join(sorted(input())) for _ in range(n)])
# print(s)

prv = ''
ans = 0
cnt = 0
for i in range(n):
    if s[i] == prv:
        cnt += 1
    else: 
        ans += cnt * (cnt - 1) // 2
        cnt = 1
    prv = s[i]
    # print(i, cnt, ans)

ans += cnt * (cnt - 1) // 2
print(ans)


        

Measured memory_bytes: 60120
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define fore(i,a,b) for(int i=a,thxicesi=b; i<thxicesi;i++)
#define FIN ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define sz(s) int(s.size())
using namespace std;

int main()
{FIN;
    int N; cin>>N;
    set<string> kinds;
    while(N--){
        string s; cin>>s;
        kinds.insert(s);
    }
    cout<<sz(kinds)<<"\n";
    return 0;
}


Measured memory_bytes: 19228
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    string S;cin >> S;
    bool is_ok = false;
    for (auto s : S)
    {
        if (s=='9') is_ok=true;
    }
    cout << (is_ok ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int N;
    scanf("%d",&N);
    int number[N];
    for(int i = 0;i < N;i++)
    {
        int x;
        scanf("%d",&x);
        number[i] = x;
    }
    int n4 = 0,n2 = 0,n1 = 0;
    for(int i = 0;i < N;i++)
    {
        if(number[i] % 4 == 0)
        {
            n4 = n4 + 1;
        }
        else if((number[i] % 2 == 0) && (number[i] % 4 != 0))
        {
            n2 = n2 + 1;
        }
    }
    n1 = N - n2 - n4;
    if(n1 != 0)
    {
        if(n2 == 0)
        {
            if(n4 >= n1 - 1)
            {
                printf("Yes");
            }
            else
            {
                printf("No");
            }
        }
        else
        {
            if(n4 == n1)
            {
                printf("Yes");
            }
            else
            {
                printf("No");
            }
        }
    }
    else
    {
        if(n4 == 0)
        {
            if(n2 >= 2)
            {
                 printf("Yes");
            }
            else
            {
                 printf("No");
            }
        }
        else
        {
            printf("Yes");
        }
    }
    return 0;
}

Measured memory_bytes: 512
from itertools import count


def count_div_by_100(n: int) -> int:
    for idx in range(4):
        q, r = divmod(n, 100)
        if r != 0:
            return idx
        n //= 100
    return -1


D, N = map(int, input().split())
current = 0
current_idx = 0
for n in count(start=1):
    if count_div_by_100(n) == D:
        current = n
        current_idx += 1
    if current_idx == N:
        print(current)
        break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n,k;
cin>>n>>k;
ll p[n]={};
ll counter=0;
for(ll i=0; i<n; i++){
cin>>p[i];}
sort(p,p+n);
for(ll i=0; i<k; i++){
counter+=p[i];}
cout<<counter<<endl;}

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

int main() {
    int x;
    cin >> x;

    int ans;
    if (x >= 400 && x <= 599) ans = 8;
    if (x >= 600 && x <= 799) ans = 7;
    if (x >= 800 && x <= 999) ans = 6;
    if (x >= 1000 && x <= 1199) ans = 5;
    if (x >= 1200 && x <= 1399) ans = 4;
    if (x >= 1400 && x <= 1599) ans = 3;
    if (x >= 1600 && x <= 1799) ans = 2;
    if (x >= 1800 && x <= 1999) ans = 1;

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3468
n = gets.to_i
#s = n.times.map { gets.chomp.split('').sort! }.sort
s = Array.new(n){ gets.chomp.chars.sort }.sort
#puts s

#s.sort! {|a,b| a[0] <=> b[0]}
=begin
for i in 0..n-1
  s[i].sort
end
=end
#s.sort[].sort!
#puts s[1]
ans = 0
count=1
for  i in 0..n-2

  if s[i]==s[i+1]
    count+=1
  else
    if count>1
      ans += count * (count-1) / 2
    end
    count=1
  end
end
ans+=count * (count-1) /2 if count>1

puts ans


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

using namespace std;

int main(){
    string S;
    int s1, s2;

    cin >> S;

    s1 = atoi(S.substr(0, 2).c_str());
    s2 = atoi(S.substr(2, 2).c_str());

    if( s1 >= 0 && s2 >= 1 && s2 <= 12){
        if( s1 >= 1 && s1 <= 12 ) printf("AMBIGUOUS\n");
        else printf("YYMM\n");
    }
    else if( s2 >= 0 && s1 >= 1 && s1 <= 12){
        if( s2 >= 1 && s2 <= 12 && s2 > 0) printf("AMBIGUOUS\n");
        if( s2 >= 1 && s2 <= 12 && s2 == 0) printf("NA\n");
        else printf("MMYY\n");
    }
    else printf("NA\n");



    return 0;
}
    




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,mod,div,i;
    string s;
    vector<char>v;
    cin>>n;
    while(n>0)
    {
        n--;
        mod=n%26;
        //div=n/26;
        n/=26;
        /*if(mod==0)
        {
            mod=26;
            n--;
        }*/
        char j='a'+mod;
        v.push_back(j);
        //cout<<mod<<endl;
    }
    reverse(v.begin(),v.end());
    for(i=0; i<v.size(); i++)
        cout<<v[i];
    v.clear();
    return 0;
}


Measured memory_bytes: 3652
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main() {
int N,M;
cin>>N>>M;
int num[M+1];
rep3(i,M){
    num[i]=0;
}
rep(i,N){
    int K;
    cin>>K;
    rep(j,K){
        int A;
        cin>>A;
        num[A]++;
    }
}
int count=0;
rep3(i,M){
    if(num[i]==N){
        count++;
    }
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <deque>

using namespace::std;

int ri()
{
	int x;
	scanf("%d", &x);

	return x;
}

int64_t ri64()
{
	int64_t x;
	scanf("%lld", &x);

	return x;
}

void wi(int x)
{
	printf("%d\n", x);
}

void wvi(vector<int> &v)
{
	for (int i = 0; i < v.size(); i++)
		printf("%d ", v[i]);
	printf("\n");
}

void dbg(string &str, int x)
{
	cout << str << ": ";
	wi(x);
}

void dbg(string &str, vector<int> &x)
{
	cout << str << ": ";
	wvi(x);
}

int main()
{
	int N = ri();
	int x = ri();

	vector<int> A(N);
	for (int i = 0; i < N; i++)
		A[i] = ri();

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

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (A[i] > x)
			break;

		ans++;
		x -= A[i];

		if (i == (N - 1) && (x > 0))
			ans--;
	}	

	wi(ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib> 
#include <cmath>

using namespace std;

int main()
{
	int nX, nN;
	int nP[120];

	cin >> nX;
	cin >> nN;

	if (nN == 0)
	{
		cout << nX << endl;
		return 0;
	}
	
	for (int i = 0; i < nN; i++)
	{
		cin >> nP[i];
	}

	int nAbs = nX + 1;
	bool isCalc = true;

	for (int i = 0; i < (nX * 2) + 1; i++)
	{
		int nTemp;
		isCalc = true;

		//同じ値があるか検索
		for (int j = 0; j < nN; j++)
		{
			if (i == nP[j])
			{
				isCalc = false;
			}
		}

		//同じ値がないなら、絶対値を計算
		if (isCalc)
		{
			nTemp = abs(nX - i);

			if (nAbs > nTemp)
			{
				nAbs = nTemp;
			}
		}
	}

	if (nAbs == 0)
	{
		cout << nX << endl;
		return 0;
	}

	bool isUp = false;
	bool isDown = false;

	//上と下どちらかの判定
	for (int j = 0; j < nN; j++)
	{
		if ((nX-nAbs) == nP[j])
		{
			isUp = true;
		}

		if ((nX + nAbs) == nP[j])
		{
			isDown = true;
		}
	}
	
	if (!isUp && !isDown)
	{
		cout << nX - nAbs << endl;
		return 0;
	}
	else if(isUp)
	{
		cout << nX + nAbs << endl;
		return 0;
	}
	else if (isDown)
	{
		cout << nX - nAbs << endl;
	}
}

Measured memory_bytes: 3636
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=1&&a<=9&&b>=1&&b<=9)cout<<a*b<<endl;
    else cout<<"-1"<<endl;
    return 0;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
map<int, int> prime_factor(int n) {
    map<int, int> ret;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }

    if (n != 1) ret[n] = 1;
    return move(ret);
};

signed main() {
    int N;
    cin >> N;

    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }

    map<int, int> primes;
    map<int, int> :: iterator it;

    for (int i = 2; i <= N; i++) {
        map<int, int> tmp_primes = prime_factor(i);

        for (it = tmp_primes.begin(); it != tmp_primes.end(); it++) {
            primes[it->first] += it->second;
        }
    }

    // ここまではdebug済み

    int ret = 0;

    int cnt_2 = 0;
    int cnt_4 = 0;
    int cnt_14 = 0;
    int cnt_24 = 0;
    int cnt_74 = 0;
    for (it = primes.begin(); it != primes.end(); it++) {
        if (it->second >= 2) cnt_2++;
        if (it->second >= 4) cnt_4++;
        if (it->second >= 14) cnt_14++;
        if (it->second >= 24) cnt_24++;
        if (it->second >= 74) cnt_74++;
    }

    if (cnt_4 >= 2 && cnt_2 >= 3) {
        ret += (((cnt_4) * (cnt_4 - 1)) / 2) * (cnt_2 - 2);
    }

    if (cnt_74 >= 1) {
        ret += cnt_74;
    }

    if (cnt_24 >= 1 && cnt_2 >= 2) {
        ret += cnt_24 * (cnt_2 - 1);
    }

    if (cnt_14 >= 1 && cnt_4 >= 2) {
        ret += cnt_14 * (cnt_4 - 1);
    }

    cout << ret << endl;

    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());;
		int m = Integer.parseInt(sc.next());;
		long[] array = new long[n];
		Long[][] bc = new Long[m][2];
		long sum=0;
		int count=0;

		for(int i=0;i<n;i++) {
			array[i]=Long.parseLong(sc.next());
		}
		Arrays.sort(array);

		for(int i=0;i<m;i++) {
			bc[i][1]=Long.parseLong(sc.next());
			bc[i][0]=Long.parseLong(sc.next());
		}
		Arrays.sort(bc, (a, b) -> Long.compare(a[0], b[0]));

		for(int i=m-1;i>=0;i--) {
			for(int j=count;j<n;j++) {
				if(array[j]<bc[i][0]) {
					array[j] = bc[i][0];
					bc[i][1]--;
					count++;
				}
				if(bc[i][1]<1) {
					break;
				}
			}
			if(bc[i][1]>0) {
				break;
			}
		}
		for(long i:array) {
			sum+=i;
		}
		System.out.println(sum);
	}

}




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

int main()
{
	double r, S, L;
	cin >> r;
	S = r * r * 3.141592653589;
	L = r * 2 * 3.141592653589;

	printf("%f %f\n", S, L);

	return 0;
}


Measured memory_bytes: 3204
N=int(input())
S=input()


def solve(N, start, end):
    memory=[-1]*N
    memory[0]=start
    for i in range(1,N):
        pre=memory[i-2]
        if i==1:
            pre=end
        if memory[i-1]==0:
            if S[i-1]=="o":
                now=pre
            else:
                now=(pre+1)%2
        else:
            if S[i-1]=="o":
                now=(pre+1)%2
            else:
                now=pre
        if i==N-1:
            if now!=end:
                return False
        memory[i]=now
    ok=True
    if memory[-1]==0:
        if S[-1]=="o" and memory[0]!=memory[-2]:
            ok=False
        if S[-1]=="x" and memory[0]==memory[-2]:
            ok=False
    else:
        if S[-1]=="o" and memory[0]==memory[-2]:
            ok=False
        if S[-1]=="x" and memory[0]!=memory[-2]:
            ok=False

    if ok:
        return memory
    else:
        return False
        



#sheep:0, wolf:1
ans1=solve(N, 0, 0)
ans2=solve(N, 0, 1)
ans3=solve(N, 1, 0)
ans4=solve(N, 1, 1)

for ans in [ans1, ans2, ans3, ans4]:
    if ans:
        for a in ans:
            if a==0:
                print("S", end="")
            else:
                print("W", end="")

        exit()

print(-1)

Measured memory_bytes: 74652
package main
import "fmt"
func main(){
  s, k, an := 0, 0, 0
  fmt.Scanf("%d %d", &k, &s)
  for i:=0;i<=k;i++{
    for j:=0;j<=k;j++{
      if 0 <= (s-i-j) && (s-i-j) <= k{
        an++
      }
    }
  }
  fmt.Println(an)
}

Measured memory_bytes: 1832