akhauriyash/Code-Regression huggingface dataset:
import sys
import heapq
from collections import defaultdict
input = sys.stdin.readline
inf = 10**18



def dijkstra(repn, start, goal):
    dist = [inf for i in range(N + 1)] # 始点から各頂点までの最短距離を格納する
    
    dist[start] = 0
    q = []                  # プライオリティキュー．各要素は，(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
    heapq.heappush(q, (0, start)) # 始点をpush

    while q:
        prov_cost, src = heapq.heappop(q) # pop
        
        # プライオリティキューに格納されている最短距離が，現在計算できている最短距離より大きければ，distの更新をする必要はない
        if dist[src] < prov_cost:
            continue

        # 他の頂点の探索
        for dest in repn[src]:
            cost = repn[src][dest]
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost # distの更新
                heapq.heappush(q, (dist[dest], dest)) # キューに新たな仮の距離の情報をpush
                
    return dist[goal]
        



N, M = map(int, input().split())
repn = [defaultdict(list) for _ in range(N + 1)]
for i in range(2, N + 1):
    repn[i][i - 1] = 0
for _ in range(M):
    l, r, c = map(int, input().split())
    if repn[l][r] == [] or repn[l][r] > c: #つまずきポイントその１
        repn[l][r] = c

d = dijkstra(repn, 1, N)

if d == 10 ** 18:
    print(-1)
else:
    print(d)


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string s; cin >> s;cout<<count(all(s),'1')<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] sum = new int[100001];
		sum[0] = 0;
		for(int i=1; i<=100000; i+=2) {
			if(like2017(i))
				sum[i] = sum[i-1] + 1;
			else
				sum[i] = sum[i-1];

			sum[i+1] = sum[i];
		}

		int Q = sc.nextInt();
		for(int i=0; i<Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			System.out.println(sum[r]-sum[l-1]);
		}

	}

	public static boolean like2017(int n) {
		if(n % 2 == 0)
			return false;

		if(isPrime(n) && isPrime((n+1)/2))
			return true;
		else
			return false;
	}

	//高速な素数判定
	public static boolean isPrime(int n) {
		if(n < 2)
			return false;

		for(int i=2; i<=Math.sqrt(n); i++) {
			if(n % i == 0)
				return false;
		}

		return true;
	}

}


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

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let s = it.next().unwrap();
    let t = it.next().unwrap();
    let mut a = vec![vec![]; 26];
    for (i, c) in s.chars().enumerate() {
        let k = (c.to_digit(36).unwrap() - 10) as usize;
        a[k].push(i);
    }
    let n = s.len();
    for k in 0..26 {
        if a[k].is_empty() {
            continue;
        }
        let x = a[k][0];
        a[k].push(x + n);
    }
    let mut pos = 0;
    let mut sum = 0;
    for c in t.chars() {
        let k = (c.to_digit(36).unwrap() - 10) as usize;
        if a[k].is_empty() {
            println!("-1");
            return;
        }
        let x = a[k].binary_search(&pos).unwrap_or_else(|p| p);
        sum += a[k][x] - pos + 1;
        pos = (a[k][x] + 1) % n;
    }
    println!("{}", sum);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	s = strings.Replace(s, "BC", "D", -1)
	l := len(s)
	cnt := 0
	sq := 0
	for i := 0; i < l; i++ {
		if s[i] == 'A' {
			sq++
		} else if s[i] == 'D' {
			cnt += sq
		} else {
			sq = 0
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 2432
N, k = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    h.append(int(input()))
  
min_height = 1000000000
h.sort()
for start in range(0, N - k + 1):
    end = start + k - 1
    diff = h[end] - h[start]
    if diff < min_height:
        min_height = diff
print(min_height)

Measured memory_bytes: 7484
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
	string s;
	unsigned long long int M[5]={},ans=0;
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>s;
		if(s[0]=='M'){
			M[0]++;
		}else if(s[0]=='A'){
			M[1]++;
		}else if(s[0]=='R'){
			M[2]++;
		}else if(s[0]=='C'){
			M[3]++;
		}else if(s[0]=='H'){
			M[4]++;
		}
	}

	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<5;k++){
				ans+=M[i]*M[j]*M[k];
			}
		}
	}
	cout<<ans<<endl;	
	
	
}

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

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  int a[30] {};

  for (auto i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (auto j = 0; j < k; j++) {
      int aa;
      cin >> aa;
      a[aa - 1]++;
    }
  }
  auto ans = 0;
  for (auto i = 0; i < m; i++) {
    if (a[i] == n) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    vector<int> a(n);
    forn (i, n)
        cin >> a[i];
    a.erase(unique(a.begin(), a.end()), a.end());
    n = sz(a);

    int res = 1;
    for (int i = 1; i + 1 < n; ++i) {
        if (a[i] > a[i - 1] && a[i] > a[i + 1])
            ++res, ++i;
        else if (a[i] < a[i - 1] && a[i] < a[i + 1])
            ++res, ++i;
    }
    cout << res << '\n';
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  cout<<s1.at(0)<<s2.at(1)<<s3.at(2)<<endl;
}


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

const int vmax=10010;
const int inf=1<<29;
struct edge{int to,cap,rev;bool original;};
vector<edge> graph[vmax];
int level[vmax],iter[vmax];

void add_edge(int from,int to,int cap){
	graph[from].push_back({to,cap,(int)graph[to].size(),true});
	graph[to].push_back({from,0,(int)graph[from].size()-1,false});
}

int dfs(int v,int t,int f){
	if(v==t) return f;
	for(int &i=iter[v];i<graph[v].size();i++){
		edge &e=graph[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d==0) continue;
			e.cap-=d;graph[e.to][e.rev].cap+=d;
			return d;
		}
	}
	return 0;
}

int bfs(int s,int t){
	rep(i,vmax) level[i]=-1;
	queue<int> q;
	level[s]=0,q.push(s);
	while(!q.empty()){
		int v=q.front();q.pop();
		for(auto &e:graph[v]){
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				q.push(e.to);
			}
		}
	}
	return level[t]>=0;
}


int max_flow(int s,int t){
	int flow=0;
	while(bfs(s,t)){
		rep(i,vmax) iter[i]=0;
		while(1){
			int f=dfs(s,t,inf);
			if(f==0) break;
			flow+=f;
		}
	}
	return flow;
}

int flow(int s,int t){
	if(!bfs(s,t)) return 0;
	rep(i,vmax) iter[i]=0;
	return dfs(s,t,1);
}

int add(int from,int to,int s,int t){
	add_edge(from,to,1);
	add_edge(to,from,1);
	return flow(s,t);
}

int erase(int from,int to,int s,int t){
	int ft=0;
	for(auto &e:graph[from]){
		if(e.to==to&&e.original){
			if(graph[e.to][e.rev].cap==1) ft++;
			e.cap=0,graph[e.to][e.rev].cap=0;
		}
	}

	for(auto &e:graph[to]){
		if(e.to==from&&e.original){
			if(graph[e.to][e.rev].cap==1) ft--;
			e.cap=0,graph[e.to][e.rev].cap=0;
		}
	}

	if(ft==0) return 0;

	if(ft>0&&flow(from,to)==1) return 0;
	if(ft<0&&flow(to,from)==1) return 0;

	if(ft>0)flow(t,to),flow(from,s);
	if(ft<0)flow(t,from),flow(to,s);
	return -1;
}


void show(int n){
	rep(i,n)for(auto &e:graph[i]) if(e.original)
		cout << i << " -> " <<  e.to << " : " << graph[e.to][e.rev].cap << endl;
}


int main(void){
	int n,m,q;
	cin >> n >> m >> q;
	rep(i,m){
		int a,b;
		cin >> a >> b ;
		add_edge(a-1,b-1,1);
		add_edge(b-1,a-1,1);
	}
	int sum=max_flow(0,n-1);
	rep(loop,q){
		int type,a,b;
		cin >> type >> a >> b;
		if(type==1)
			sum+=add(a-1,b-1,0,n-1);
		else
			sum+=erase(a-1,b-1,0,n-1);
		cout << sum << endl;
		//show(n);
	}
	return 0;
}

Measured memory_bytes: 3268
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define GCD(v) gcd(ALL(v), 0l)

/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/

template <typename T>
using vec = vector<T>;

template <typename T>
using vvec = vector<vector<T>>;

int main(){
  string s;
  cin>>s;
  if(s=="RRR")cout<<3;
  else if(s=="RRS"||s=="SRR")cout<<2;
  else if(s=="SSS")cout<<0;
  else cout<<1;
}


/* きょむ〜 */


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

using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10;

int sz[maxn], tot;
ll d[maxn], dis[maxn];
map<ll, int> mp;
vector<int> edge[maxn];
int ans[maxn][2];

void dfs(int u, int pre)
{
    for(auto v : edge[u])
    {
        if(v == pre) continue;
        dis[v] = dis[u] + 1;
        ans[tot][0] = u, ans[tot++][1] = v;
        dfs(v, u);
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++)
    {
        scanf("%lld", &d[i]);
        mp[d[i]] = i, sz[i] = 1;
    }
    int cnt = 0;
    for(auto it = mp.rbegin(); it != mp.rend(); it ++)
    {
        int v = it->second, u = mp[it->first + 2 * sz[v] - n];
        if(!u || u == v) return puts("-1"), 0;
        edge[u].push_back(v);
        edge[v].push_back(u);
        sz[u] += sz[v];
        if(++cnt == n - 1) break;
    }
    int rt = mp.begin()->second;
    dfs(rt, 0);
    if(accumulate(dis + 1, dis + n + 1, 0ll) != d[rt]) return puts("-1"), 0;
    for(int i = 0; i < tot; i ++)
        printf("%d %d\n", ans[i][0], ans[i][1]);
    return 0;
}


Measured memory_bytes: 18176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    VI oddRow, evenRow;
    int N; cin >> N;
    REP(i,N)
    {
        int tmp; cin >> tmp;
        if(i % 2 == 0) evenRow.pb(tmp);
        else oddRow.pb(tmp);
    }
    reverse(evenRow.begin(), evenRow.end());
    evenRow.insert(evenRow.end(), oddRow.begin(), oddRow.end());

    if(N % 2 == 0) reverse(evenRow.begin(), evenRow.end());

    for(auto p : evenRow)
    {
        cout << p << " ";
    }
    cout << endl;


}


Measured memory_bytes: 3564
#!/usr/bin/env python3
import sys

def main():
    n = int(input())
    n_str = str(n)
    s = 0
    for i in range(len(n_str)):
        s += int(n_str[i])

    if n%s == 0:
        print("Yes")
    else:
        print("No")

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import itertools as itr

n, wmax = list(map(int, input().split()))
w = [0]*(n+1)
v = [0]*(n+1)
for i in range(1, n+1):
    wi, vi = list(map(int, input().split()))
    w[i] = wi
    v[i] = vi
    
dp = [[0]*(wmax+1) for _ in range(n+1)]

for i, wi in itr.product(range(1, n+1), range(1, wmax+1)):
    if wi-w[i] >= 0:
        dp[i][wi] = max(dp[i-1][wi], dp[i-1][wi-w[i]]+v[i])
    else:
        dp[i][wi] = dp[i-1][wi]
            
print(dp[n][wmax])

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


int main(){
    int a,b;
    char s[12];
    bool flag=true;
    cin >> a >> b;
    cin >> s;
    for(int i=0;i<a;i++){
        if(s[i] == '-'){
            flag=false;
            break;
        }
    }
    if(s[a] != '-') flag = false;

    for( int i=a+1;i < a+b+1 ; i++){
        if(s[i]=='-'){
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

const int MAXN = 1e5+5;
int N,U,V,dist1[MAXN],dist2[MAXN],visit[MAXN];
vector<int> adj[MAXN];

void dfs1(int x, int par) {
    if (visit[x]) return;
    visit[x] = 1;
    for (auto it: adj[x]) {
        if (it == par) continue;
        dist1[it] = dist1[x]+1;
        dfs1(it,x);
    }
}

void dfs2(int x, int par) {
    if (visit[x]) return;
    visit[x] = 1;
    for (auto it: adj[x]) {
        if (it == par) continue;
        dist2[it] = dist2[x]+1;
        dfs2(it,x);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> U >> V;
    for (int i = 0; i < N-1; i++) {
        int a,b;
        cin >> a >> b;
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }
    dfs1(U,-1);
    memset(visit,0,sizeof(visit));
    dfs2(V,-1);
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (dist1[i] < dist2[i]) ans = max(ans,dist2[i]);
    }
    cout << ans-1;
    return 0;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  int a,b;
  cin>>a>>b;
  int gc=__gcd(a,b);
  cout<<a*b/gc<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


Measured memory_bytes: 256
N = int(input())
def rec ():
	global now,l
	if s[now].isdigit():
		res = 0
		while (now < l and s[now].isdigit()):
			res = ((10 * res) + int(s[now]))
			now += 1
		return (res+1)//2
	else:
		g = []
		while(now < l and s[now] == '['):
			now += 1
			g.append(rec())
			now += 1
		g.sort()
		return sum(g[:(len(g)+1)//2])

for i in range(N):
	s = input()
	l = len(s)
	now = 0
	print(rec())





Measured memory_bytes: 5676
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
    	int n=ni(),k=ni(),h[]=new int[n+1];
    	for(int i=1;i<=n;i++) h[i]=ni();

    	Arrays.sort(h);
    	long res=0l;
    	for(int i=Math.max(0,n-k);i>=1;i--)
    		res+=h[i];
    	pn(res);
    }


   	static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

    	//oj = System.getProperty("ONLINE_JUDGE") != null;
    	if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
	
	
	

Measured memory_bytes: 57336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
int main() {
  int a, b;
  string s[100];
  cin >> a >> b;
  rep(i, a) cin >> s[i];
  sort(s, s + a);
  rep(i, a) cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int INF = 1001001001;

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

    int n, x;
    cin >> n >> x;

    int min = INF;
    REP(i, n) {
        int tmp;
        cin >> tmp;
        if (tmp < min)
            min = tmp;
        x -= tmp;
    }

    cout << n + x / min << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,nc,score,i;
	int sum,max,min;
	while(1){
		scanf("%d",&n);
		if(n == 0){break;}
		nc = n;
		do{
			sum = 0;
			for(i = 0; i < 5; i++){
				scanf("%d",&score);
				sum += score;
			}
			if(nc == n){
				max = sum;
				min = sum;
			}else{
				if(sum > max){
					max = sum;
				}
				if(sum < min){
					min = sum;
				}
			}
			nc--;
		}while(nc > 0);
		
		printf("%d %d\n",max,min);
	}


	return 0;
}

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

struct node{

  struct node *right;
  struct node *left;
  struct node *parent;
  int key;

};

typedef struct node * Node;

Node root, NIL;

Node treeSearch(Node u, int k){

  while((u != NIL) && (k != u->key)){
    if(k < u->key){
      u = u->left;
    }
    
    else{
      u = u->right;
    }

  }
  
  return u;

}

void insert(int k){

  int H;
  Node y = NIL;
  Node x = root;
  Node z;


  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){

    y = x;

    if(z->key < x->key){
      x = x->left;
    }
    
    else{
      x = x->right;
    }
    
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    
    else{
      y->right = z;
    }
    
  }

}

void inorder(Node u){

  if(u == NIL){
    return;
  }
  
  inorder(u->left);
  
  printf(" %d",u->key);

  inorder(u->right);

}

void preorder(Node u){

  if(u == NIL){
    return;
  }
  
  printf(" %d",u->key);
  
  preorder(u->left);

  preorder(u->right);

}

int main(){

  int n,i,x;
  char c[20];
  
  scanf("%d",&n);

  
  for(i=0;i<n;i++){
    scanf("%s",c);
    
    if(c[0] == 'f'){

      scanf("%d",&x);

      Node t = treeSearch(root, x);

      if(t != NIL){
	printf("yes\n");
      }
      
      else{
	printf("no\n");
      }
    }

    else if(c[0] == 'i'){
      scanf("%d",&x);
      insert(x);
      
    }

    else if(c[0] == 'p'){

      inorder(root);

      printf("\n");

      preorder(root);

      printf("\n");

    }
    
  }

  return 0;

}



Measured memory_bytes: 20496
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i<=i##end;++i)
#define DREP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i>=i##end;--i)
template<typename T>bool chkmin(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template<typename T>T read(){
	T x=0,f=1;
	char c=getchar();
	while((c<'0')||(c>'9')){if(c=='-')f=-1;c=getchar();}
	while((c>='0')&&(c<='9'))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define read() read<int>()
template<typename T>void write(T x,char c){
	static char t[25];
	static int tlen;
	t[tlen=1]=c;
	if(x<0)putchar('-'),x=-x;
	do t[++tlen]=(x%10)^48;
	while(x/=10);
	while(tlen)putchar(t[tlen--]);
}
#define pb push_back
typedef long long ll;
typedef double lf;
const int maxn=2005;
int n,m,val[maxn][maxn][2];
int sum[maxn][maxn][2];
char s[10];
int calc(int x1,int y1,int x2,int y2,int k){
	if((x1>x2)||(y1>y2))return 0;
	int res=sum[x2][y2][k];
	if(x1)res-=sum[x1-1][y2][k];
	if(y1)res-=sum[x2][y1-1][k];
	if(x1&&y1)res+=sum[x1-1][y1-1][k];
	return res;
}
int main(){
	n=read(),m=read();
	REP(i,1,n){
		int x,y,t;
		x=read()%(2*m),y=read()%(2*m),scanf("%s",s),t=(s[0]=='B');
		if(y>=m){
			if(x>=m)x-=m,y-=m;
			else x+=m,y-=m;
		}if(x>=m)x-=m,t^=1;
		val[x][y][t]++;
	}
/*
	REP(i,0,m-1)
		REP(j,0,m-1)
			REP(k,0,1)
				if(val[i][j][k])
					cout<<i<<' '<<j<<' '<<k<<' '<<val[i][j][k]<<endl;
*/
	REP(i,0,m-1)
		REP(j,0,m-1)
			REP(k,0,1)
				sum[i][j][k]=val[i][j][k];
	REP(i,0,m-1)
		REP(j,0,m-1)
			REP(k,0,1){
				if(i)sum[i][j][k]+=sum[i-1][j][k];
				if(j)sum[i][j][k]+=sum[i][j-1][k];
				if(i&&j)sum[i][j][k]-=sum[i-1][j-1][k];
			}
	int ans=0;
	REP(i,0,m-1)
		REP(j,0,m-1){
			chkmax(ans,calc(0,0,i,j,0)+calc(0,j+1,i,m-1,1)+calc(i+1,0,m-1,j,1)+calc(i+1,j+1,m-1,m-1,0));
			chkmax(ans,calc(0,0,i,j,1)+calc(0,j+1,i,m-1,0)+calc(i+1,0,m-1,j,0)+calc(i+1,j+1,m-1,m-1,1));
//			if(i==j&&i==0)
//				cout<<calc(0,0,i,j,1)<<' '<<calc(0,j+1,i,m-1,0)<<' '<<calc(i+1,0,m-1,j,0)<<' '<<calc(i+1,j+1,m-1,m-1,1)<<endl;
		}
	write(ans,'\n');
	return 0;
}

Measured memory_bytes: 32512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
using namespace std;

int main() {
    int n,m; cin >> n >>m;
    int minnum=1000000,maxnum=0;
    for(int i = 0; i<m; i++){
        int a,b;
        cin >> a >> b;
        maxnum = max(maxnum,a);
        minnum = min(minnum,b);
    }
    cout << max(minnum-maxnum+1,0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	int a;

	int min = 1001;
	int max = -1;
	
	int i;

	scanf("%d", &N);
	for (i = 0; i < N; i++){
		scanf("%d", &a);
		if (a < min) min = a;
		if (a > max) max = a;
	}

	printf("%d\n", max - min);

	return 0;
}


Measured memory_bytes: 128
r=[]
a=[]
min_=11
num=-1
for n in range(5):
    temp=int(input())
    r.append(temp)
    amari=temp%10
    if amari==0:
        amari=10
    a.append(amari)
    if amari < min_:
        min_=amari
        num=n
sumtime=0
for i,(j,a_) in enumerate(zip(r,a)):
    if i!=num:
        s=j+(10-a_)
        sumtime+=s
    else:
        sumtime+=j
print(sumtime)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;
  if(m2-m1==1){
    if(m1==1 && d1==31) cout<<1;
     else if(m1==2 && d1==28) cout<<1;
    else if(m1==3 && d1==31) cout<<1;
     else if(m1==4 && d1==30) cout<<1;
     else if(m1==5 && d1==31) cout<<1;
     else if(m1==6 && d1==30) cout<<1;
     else if(m1==7 && d1==31) cout<<1;
     else if(m1==8 && d1==31) cout<<1;
     else if(m1==9 && d1==30) cout<<1;
     else if(m1==10 && d1==31) cout<<1;
     else if(m1==11 && d1==30) cout<<1;
     else if(m1==12 && d1==31) cout<<1;
  }
  else cout<<0;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin >>s;
	for (int i=0; i<s.size(); i++) 
		if (s[i]=='9') cout<<"1";
		else cout <<"9";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import collections
N = int(input())
s = []
for i in range(N):
  word = input()
  chars = []
  sortedWord = ''

  for j in range(10):
    chars.append(word[j])
    chars.sort()

  #print(chars)
  
  for j in range(10):
    sortedWord += chars[j]

  #print(sortedWord)

  s.append(sortedWord)

c = collections.Counter(s)

sum = 0
for value in c.values():
  sum += (value * (value-1) / 2)

print(int(sum))


Measured memory_bytes: 19824
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

string c[]={"S", "W"};

int main(){
	int n;
	string s, t;
	cin >> n >> s;
	s+=s[0];
	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			t=c[i]+c[j];
			for(int k=1; k<=n; k++)
			if(s[k]=='o'){
				if(t[k-1]==t[k]) t+='S';
				else t+='W';
			}else{
				if(t[k-1]==t[k]) t+='W';
				else t+='S';
			}
			if(t[0]==t[n] && t[1]==t[n+1]){
				cout << t.substr(0,n) << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    long long s=0;
    long long t=0;
    for(int i=0; i<n; i++) {
        long long x,y;
        cin >> x >> y;
        s += x*y;
        t += y;
    }
    long long k=s%9;
    if(k==0) k=9;
    cout << t-1+(s-k)/9 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  ll n;
  cin >> n;
  ll a=1;
  for(ll i=1;i<=pow(n,0.5);i++){
    if(n%i==0){
      a=i;
    }
  }
  ll b=n/a;
  cout << a+b-2 << endl;
}

Measured memory_bytes: 4028
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

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

    int f[100][10];
    int p[100][11];
    
    REP(i, n) {
        REP(j, 5) {
            int fi;
            cin >> fi;
            f[i][j * 2 + 0] = fi;
            cin >> fi;
            f[i][j * 2 + 1] = fi;
        }
    }

    REP(i, n) REP(j, 11) {
        int pi;
        cin >> pi;
        p[i][j] = pi;
    }

    long long bestProfit = -LLONG_MAX;
    
    for (int i = 1; i <= 0b1111111111; i++) {
        long long profit = 0;
        REP(k, n) {
            int open = i;
            int c = 0;
            REP(j, 10) {
                if (((open & 0x1) == 1) && (f[k][j] == 1))
                    c++;
                open >>= 1;
            }
            profit += p[k][c];
        }
        bestProfit = max(bestProfit, profit);
    }

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


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

char buf[200005];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    gstr(buf);
	int n = strlen(buf);
	rep(i, n-1) if(buf[i] == 'P' && buf[i+1] == '?') buf[i+1] = 'D';
	for(int i=n-1; i>=0; i--) {
		if(buf[i] == '?') buf[i] = 'D';
	}
	pstr(buf);
}


Measured memory_bytes: 4248
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>

using namespace std;
int main(void){
    // Your code here!
    int a,s;
    int result = 0;

    cin >> a >> s;
    
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= a; j++) {
            int sum = s - (i + j);

            if (sum <= a && sum >=0) {
                result++;
            }
        }
    } 
    
    cout << result << endl;


    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int V, E;
vector<int>G[110];
bool used1[110];//探索中に同じところを通ったら閉路があるとみなすフラグ
bool used2[110];//一回探索したことがあるか?のフラグ
bool dfs(int u) {
	if (used1[u])return true;
	used1[u] = true;
	for (int i = 0; i < G[u].size(); ++i) {
		if (used2[G[u][i]])continue;
		if (dfs(G[u][i]))return true;
	}
	used2[u] = true;
	used1[u] = false;
	return false;
}
int main() {
	cin >> V >> E;
	for (int i = 0; i < E; ++i) {
		int s, t; cin >> s >> t;
		G[s].push_back(t);
	}
	fill(used2, used2 + 110, false);
	for (int i = 0; i < 110; ++i) {
		fill(used1, used1 + 110, false);
		if (used2[i])continue;
		if (dfs(i)) {
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3160
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int a[] = new int[m];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      int k = Integer.parseInt(str[0]);
      for(int j=1; j<=k; j++) {
        int t = Integer.parseInt(str[j]);
        a[t-1]++;
      }
    }
    
    int count = 0;
    for(int i=0; i<m; i++) {
      if(a[i] == n)
        count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 32864
<?php
while (1) {
  $str = rtrim(fgets(STDIN));
  
  if ($str == '.') {
    break;
  }

  $flg = true;
  $stack = array();
  for ($i = 0; $i < strlen($str); $i++) {
    if ($str[$i] == '(' || $str[$i] == '[') {
      array_push($stack, $str[$i]);
    } else if ($str[$i] == ')' || $str[$i] == ']') {
      if (empty($stack)) {
        $flg = false;
      } else {
        $c = array_pop($stack) . $str[$i];
        if ($c != "()" && $c != "[]") {
          $flg = false;
        }
      }
    }
    if (!$flg) {
      break;
    }
  }
  
  if (!empty($stack)) {
    $flg = false;
  }
  
  print $flg ? "yes\n" : "no\n";
}

Measured memory_bytes: 6628
fun main(args: Array<String>) {
    var (N, K) = listOfInt()
    var (R, S, P) = listOfInt()
    var T = next()
    var G = CharArray(N)
    fun g(n: Int) = if (n - K >= 0) G[n - K] else ' '
    var ans = 0
    for (n in 0 until N) {
        when (T[n]) {
            'r' -> {
                if(g(n) != 'p') {
                    ans += P
                    G[n] = 'p'
                }
            }
            's' -> {
                if(g(n) != 'r') {
                    ans += R
                    G[n] = 'r'
                }
            }
            'p' -> {
                if(g(n) != 's') {
                    ans += S
                    G[n] = 's'
                }
            }
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 41688
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

//           mai, sum
long long dp[100][3000];
long long N, A;
long long x[100];

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

	for(long long i = 0; i < N; i++){
		cin >> x[i];
	}

	dp[0][0] = 1;

	//i番目のカードを使う
	for(long long i = 0; i < N; i++){

		for(long long mai = N; mai >= 0; mai--){
			for(int sum = 0; sum < 3000; sum++){
				if(dp[mai][sum]){
					dp[mai+1][sum+x[i]] += dp[mai][sum];
				}
			}	
		}

	}

	long long ret = 0;
	for(long long mai = 1; mai <= N; mai++){
		ret += dp[mai][mai*A];
	}
	cout << ret << endl;


}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

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

ll a[100005], b[100005];
int n, k;

void solve()
{
    for (int i = 2; i <= n; ++i)
    {
        if (a[i] == -1)
            continue;
        b[i] = (b[i - 1] + b[i - 2]) % 1000000007;
    }
}

int main()
{
    cin >> n >> k;
    b[0] = 1;
    b[1] = 1;
    b[2] = 2;
    int x;
    for (int i = 0; i < k; ++i)
    {
        sf(x);
        a[x] = -1;
    }
    if (a[1] == -1)
        b[1] = 0;

    if (a[2] == -1)
        b[2] = 0;
    solve();
    cout << b[n] << endl;
return 0;
}

Measured memory_bytes: 1792
#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>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
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 complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second


void solve() {
	string s;
	getline(cin, s);
	vector<string> v;
	int le = 1;
	rep(i, s.length()) {
		if (s[i] == '.'&&i>0) {
			string u = s.substr(le, i - le);
			v.push_back(u);
			le = i + 1;
		}
	}
	v.push_back(s.substr(le, s.length() - le));
	int cur = 0; int loc = -1;
	string t;
	while (getline(cin, t)) {
		int m = t.length();
		int le=-1, ri;
		rep(i, m) {
			if (t[i] != ' '&&le<0) {
				le = i;
			}
			if (t[i] == ':') {
				ri = i; break;
			}
		}
		if (loc >= le)continue;
		string u = t.substr(le, ri - le);
		//cout << u << endl;
		if (u == v[cur]) {
			cur++; loc = le;
			if (cur == v.size()) {
				int cle = ri + 2;
				if (cle >= m) {
					cout << "object" << endl; return;
				}
				else {
					string z = t.substr(cle, m - cle);
					cout << "string \"" << z << "\"" << endl; return;
				}
			}
		}
	}
	cout << "no such property" << endl; return;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	string t; while (cin >> t);
	//stop
	return 0;
}



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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset ((a), v, sizeof (a))

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ii> vii;

int n;
int A[15], B[15];
int ans;

void rec (int cur) {
	if (cur == n) {
		bool ok = false;
		for (int i = 0; i < n; ++i) {
			if (B[i] % 2 == 0) {
				ok = true;
			}
		}
		if (ok) ++ans;
		return;
	}

	B[cur] = A[cur] - 1; rec (cur + 1);
	B[cur] = A[cur]; rec (cur + 1);
	B[cur] = A[cur] + 1; rec (cur + 1);
}

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n; ++i) scanf ("%d", &A[i]);
	rec (0);
	printf ("%d\n", ans);
	return 0;
}

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

int di[4] = {0, -1, 0, 1};
int dj[4] = {-1, 0, 1, 0};

void print(int c){
    if(c == 0) cout << "L";
    else if(c == 1) cout << "U";
    else if(c == 2) cout << "R";
    else cout << "D";
}

int main(){


    vector<vector<bool> > a(13, vector<bool> (13, true));
    for(int i = 0; i < 13; i++){
        a[i][0] = a[i][12] = false;
    }

    for(int j = 0; j < 13; j++){
        a[0][j] = a[12][j] = false;
    }

    for(int i = 0; i < 9; i++){

        if(i % 2 == 0){
            int h = i + 2;
            string s; cin >> s;
            for(int j = 0; j < 4; j++){
                int w = j * 2 + 3;
                if(s[j] == '1'){
                    a[h][w - 1] = false;
                    a[h][w] = false;
                    a[h][w + 1] = false;                    
                }
            }
        }else{
            int h = i + 2;
            string s; cin >> s;
            for(int j = 0; j < 5; j++){
                int w = j * 2 + 2;
                if(s[j] == '1'){
                    a[h - 1][w] = false;
                    a[h][w] = false;
                    a[h + 1][w] = false;                    
                }
            }
        }
    }

    /*for(int i = 0; i < 13; i++){
        for(int j = 0; j < 13; j++){
            cout << a[i][j];
        }
        cout << endl;
    }*/

    int s_k = 2;
    int s_i = 2;
    int s_j = 2;
    int k = 2;
    int i = 2;
    int j = 2;
    bool flag = false;
    while(1){

        if(flag && i == s_i && j == s_j) break;
        
        flag = true;
        for(int h = 0; h < 4; h++){

            int c = (k - 1 + 4 + h) % 4;
            if(a[i + di[c]][j + dj[c]] == 0 && a[i + 2*di[c]][j + 2*dj[c]] == 0){
                print(c);
                i = i + 2*di[c];
                j = j + 2*dj[c];
                k = c;
                break;
            }

        } 
    
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3088
N, W = map(int, input().split())
w = [0 for i in range(N+1)]
v = [0 for i in range(N+1)]
for i in range(1, N+1):
  a, b = map(int, input().split())
  w[i] = a
  v[i] = b
V = sum(v)
dp = [[10**12 for j in range(V+1)] for i in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
  for j in range(0, V+1):
    if j - v[i] >= 0:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i])
    else:
      dp[i][j] = dp[i-1][j]
for j in range(V, -1, -1):
  if dp[N][j] <= W:
    print(j)
    break

Measured memory_bytes: 217664
package main

import "fmt"

func main() {
	var n, m int64
	fmt.Scan(&n, &m)
	count := int64(0)
	if n * 2 <= m {
		count += n
		count += (m - n * 2) / 4
	} else {
		count += m / 2
	}
	fmt.Println(count)
}

Measured memory_bytes: 512