akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#define M 2000010

using namespace std;

typedef long long ll;

ll n, q, SC[M], SM[M], SMC[M];

char S[M];

ll getans(int l, int r) {
    if(S[l] != 'D') return 0ll;
    ll ans = SMC[l];
    ans -= SMC[r + 1];
    ans -= (SM[l] - SM[r + 1]) * SC[r + 1];
    return ans;
}

int main() {
    scanf("%lld%s%lld", &n, S + 1, &q);
    for(int i = n; i >= 1; i--) SC[i] = SC[i + 1] + (S[i] == 'C'), SM[i] = SM[i + 1] + (S[i] == 'M');
    for(int i = n; i >= 1; i--) SMC[i] = SMC[i + 1] + (S[i] == 'M') * SC[i + 1];
    for(int T = 1; T <= q; T++) {
        int k;
        scanf("%d", &k);
        long long ans = 0;
        for(ll i = 1; i <= n; i++) ans += getans(i, min(i + k - 1, n));
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 29952
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
    n = int(input())
    adj = [[]] * n
    for _ in range(0, n):
        U = list(map(int, input().split()))
        adj[U[0]] = zip(U[2::2], U[3::2])
    def dijkstra():
        d = [0] + [INF] * (n - 1)
        hq = [(0, 0)]
        while hq:
            u = heappop(hq)[1]
            for v, c in adj[u]:
                alt = d[u] + c
                if d[v] > alt:
                    d[v] = alt
                    heappush(hq, (alt, v))
        print("\n".join(str(i) + " " + str(c) for i, c in enumerate(d)))
    dijkstra()
MAIN()



Measured memory_bytes: 40036
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 
    int n; cin >> n;
    vl a(n); 
    repa(i, (n - 1)) {
        ll x; cin >> x;
        a[(x - 1)]++;     
    }

    trv(i, a)
       cout << i << endl;
       
    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 4840
n = gets.chomp("").to_i
h = gets.split(" ").map(&:to_i)

(n-1).times do |i|
  if h[i] >= h[i+1]
    if i != 0
      h[i] = 1 + h[i-1]
    else
      h[i] = 1
    end
  else
    h[i] = 0
  end
end

h.delete_at(n-1)
if n != 1
  puts h.max
else
  puts 0
end


Measured memory_bytes: 8580
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_063_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(3).
    01 a      PIC 9(1).
    01 b      PIC 9(1).
    01 tmp    PIC 9(2).

    01 ZS     PIC Z(3).
    01 DUMMY  PIC X(1).

    01 ans    PIC X(2).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO A B.

    ADD a TO b GIVING tmp.

    MOVE tmp TO ZS.

    PERFORM UNANS.

    IF 10 <= tmp THEN
        DISPLAY "error"
    ELSE
        DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans))
    END-IF.

    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 636
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const int MAX_C = 2010;
long long Com[MAX_C][MAX_C] = {0};

int main(){
  int N; cin >> N;
  int a[N];
  bool sosu[55560];
  rep(i, 55560){
    sosu[i] = true;
  }
  sosu[0]=false; sosu[1]=false;
  for(int i=2; i*i<=55555; i++){
    for(int j=2*i; j<=55555; j+=i){
      sosu[j] = false;
    }
  }
  int i=0; 
  for(int j=2; j<=55555; j++){
    if(sosu[j] && j%5==1){
      a[i] = j; i++;
    }
    if(i==N) break;
  }
  rep(i, N){
    if(i!=0) cout << " ";
    cout << a[i];
  }
  cout << endl;    
}

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

int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int p[n];
  for(i=0;i<(n+1)/2;i++){
    p[i]=a[n-1-2*i];
  }
  if(n%2==0){
    for(i=0;i<n/2;i++){
      p[n/2+i]=a[2*i];
    }
  }else{
    for(i=0;i<n/2;i++){
      p[n/2+i+1]=a[2*i+1];
    }
  }
  for(i=0;i<n;i++){
    cout<<p[i]<<endl;
  }
}

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

using namespace std;

bool check(long long n, long long d)
{
    while(n%d==0) n/=d;
    n=n%d;
    return n==1;
}

main()
{
    long long n; cin>>n;
    long long ans=0;
    for(long long d=1;d*d<=n;++d)
    {
        if(n%d) continue;
        if(d>1) ans+=check(n,d);
        if(d*d!=n) ans+=check(n, n/d);
    }
    for(long long d=1;d*d<n;++d)
    {
        if((n-1)%d) continue;
        if(d>1) ans++;
        if(d*d<n-1) ans++;
    }
    cout << ans << "\n";
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	ll a,b,k;
	ll res = 0;
	scanf("%lld", &k);
	scanf("%lld", &a);
	scanf("%lld", &b);
	bool isok = false;
	FOR(i, a, b) {
		if (i%k == 0) {
			isok = true;
		}
	}
	if (isok) {
		printf("OK\n");
	}
	else {
		printf("NG\n");
	}
	return(0);
}

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

using namespace std;

typedef long long int ll;

#define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define endl "\n"

int main()
{
	faster;
	
	map<string,int> mp{{"AC",0},{"TLE",0},{"WA",0},{"RE",0}};

	int n;
	cin >> n;
	while(n--){
		string s;
		cin >> s;
		mp[s]++;
	}

	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
	return 0;
}

Measured memory_bytes: 3648
def counts(nums)
  nums.each_with_object(Hash.new(0)) { |i, h| h[i] += 1 }.sort_by { |num, count| [count, num] }.reverse
end

N = gets.to_i
evens, odds = gets.split(" ").map(&:to_i).partition.with_index { |n, i| i % 2 == 0 }

even_counts = counts(evens)
odd_counts = counts(odds)

even_num, even_no_op_count = even_counts[0]
odd_num,  odd_no_op_count  = odd_counts[0]

ans = if even_num == odd_num
  candidates = [
    even_counts.fetch(1, [0]).last + odd_no_op_count,
    even_no_op_count  + odd_counts.fetch(1, [0]).last
  ]
  N - candidates.max
else
  N - (even_no_op_count + odd_no_op_count)
end

puts ans


Measured memory_bytes: 26108
#include<bits/stdc++.h>
using namespace std;
const int maxn=200004;
int rmd[maxn];
int pref[maxn];
char s[maxn];
int main(){
	cin>>(s+1);
	int base=1;
	long long cnt=0;
	rmd[0]=1;
	int len=strlen(s+1);
	for(int i=len;i>=1;i--){
		pref[i]=(pref[i+1]+base*(s[i]-'0'))%2019;
		base=base*10%2019;
		cnt+=rmd[pref[i]];
		rmd[pref[i]]++;
	}
	printf("%lld\n",cnt);
}

Measured memory_bytes: 4660
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

const int N = 100000 + 5;
const int MOD = (int)1e9 + 7;
int a[N], b[N];
long long C[N], INV[N];
int pow(long long x, int n) {
	long long y = 1;
	while(n) {
		if(n & 1) y = y * x % MOD;
		x = x * x % MOD;
		n /= 2;
	}
	return y % MOD;
}
inline long long extend_gcd(long long a,long long b,long long &x,long long &y)
{
    if(a==0&&b==0)
        return -1ll;
    if(b==0)
    {
        x=1ll;
        y=0ll;
        return a;
    }
    long long d=extend_gcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
inline long long mod_reverse(long long a,long long n)
{
    long long x,y,d=extend_gcd(a,n,x,y);
    if(d==1)
        return (x%n+n)%n;
    else
        return -1ll;
}
int main(){
	int n, x;
	cin >> n;
	rep(i,0,n+1) {
		cin >> b[i];
		a[b[i]-1]++;
		if(a[b[i]-1]>1) x = b[i];
	}
	//cout << x << endl;
	n++;
	C[0] = 1;
	INV[0] = 1;
	rep(i,1,n+1) C[i] = C[i-1] * i % MOD; 
	//rep(i,1,n+1) INV[i] = mod_reverse(C[i], MOD);
	INV[n] = pow(C[n], MOD-2);
	for(int i=n-1; i; --i) INV[i] = INV[i+1] * (i+1) % MOD;
	//rep(i,1,n+1) INV[i] = pow(C[i], MOD-2);
	int y = 0, z = 0;
	rep(i,0,n) {
		if(b[i] != x) y++;
		else break;
	}
	for(int i=n-1; i>=0; --i) {
		if(b[i] != x) z++;
		else break;
	}
	//cout << y << " " << z << endl;
	cout << n - 1 << endl;
	rep(i,2,n) {
		long long t = (C[n] * INV[i] % MOD) * INV[n-i] % MOD;
		long long tt = 0;
		if(y + z >= i - 1) {
			tt = (C[y+z] * INV[i-1] % MOD) * INV[y+z-i+1] % MOD;
		}
		cout << (t - tt + MOD) % MOD << endl;
	}
	cout << 1 << endl;
    return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	string s;
	llong K;
	cin >> s >> K;

	for(int i = 0; i < (int)s.size() && K > 0; i++){
		if(i == (int)s.size()-1){
			s[i] = 'a' + (s[i] - 'b' + K + 1)%26;
		}else{
			if(s[i] == 'a')
				continue;
			if('z' - s[i] + 1 <= K){
				K -= 'z' - s[i] + 1;
				s[i] = 'a';
			}
		}
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }

const int MOD = 1000000007;


int main(){
    int N, K; cin >> N >> K;
    vector<int> P(N), C(N);
    rep(i,N) cin >> P[i];
    rep(i,N) cin >> C[i];
    rep(i,N) P[i]--;

    ll ans = -1e18;
    rep(si,N){
        int x = si;
        vector<int> cycle_points;
        ll cycle_total = 0;
        // total:サイクルを一周した際のスコア
        // cycle_pointsに1サイクル中の各得点を格納
        while (true){
            x = P[x];
            cycle_points.push_back(C[x]);
            cycle_total += C[x];
            // サイクルが検知できたら終了
            if (x == si) break;
        }
        int l = cycle_points.size();
        ll total = 0;
        // サイクル内の各点で止めた場合を
        // すべて試す。
        rep(i,l){
            // 各点で止めた場合の点数を求める。
            total += cycle_points[i];
            // 1サイクル内でkを超えてしまう場合は終了
            if (i+1 > K)break;
            
            ll now = total;
            // サイクル1周した際のスコアが正の場合
            if (cycle_total > 0){
                // i+1回の時点で止めた場合に
                // サイクルは何回回せるかを算出
                ll e = (K-(i+1))/l;
                now += cycle_total*e;
            }
            ans = max(ans, now);
        }
    }

    cout << ans << endl;


}


Measured memory_bytes: 3732
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; i++) cin >> H[i];
    for(int i=0; i<N; i++) {
        if(i == 0 or H[i-1] < H[i]) H[i]--;
    }

    bool ok = true;
    for(int i=0; i<N-1; i++) ok &= (H[i] <= H[i+1]);
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
  char str[201];
  int s,i=0;
  scanf("%s",str);
  while(1){
    // cin>>str[i];
    if(str[i]=='\0'){
      s=i;
      break;
    }
    i++;
  }
//読み込み（2回分）
  for(i;i<2*s;i++){
    str[i]=str[i-s];
  }
  // for(int i=0;i<2*s;i++){
  //   if(i==2*s-1){
  //     cout<<str[i]<<endl;
  //   }else{
  //     cout<<str[i];
  //   }
  // }
  char p[101];
  scanf("%s",p);
  int k; //配列ｐの長さを知るため。
  i=0;
  while(1){
    if(p[i]=='\0'){
      k=i;
      break;
    }
    i++;
  }
  int x=0;//判別用
  for(i=0;i<2*s;i++){
    if(str[i]==p[0]){
      if(k==1)x=1;
      for(int v=1;v<k;v++){
        if(str[i+v]!=p[v])break;
        if(v==k-1){
          x=1;
          // break;
        }
      }
    }
  }
  if(x==1)cout<<"Yes"<<endl;
  if(x!=1)cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 3168
#include <atcoder/mincostflow>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, ll> P;

const ll MAX = 1000000000;

int main() {
	int n, k; cin >> n >> k;
	vector<string> a(n, string(n, '.'));
	mcf_graph<int, ll> g(2 * n + 2), h(2 * n + 2);
	int S = 2 * n, T = 2 * n + 1;
	for (int i = 0; i < n; ++i) {
		g.add_edge(S, i, k, 0); h.add_edge(S, i, k, 0);
		g.add_edge(n + i, T, k, 0); h.add_edge(n + i, T, k, 0);
		for (int j = 0; j < n; ++j) {
			ll x; cin >> x;
			g.add_edge(i, n + j, 1, MAX - x);
			h.add_edge(i, n + j, 1, MAX - x);
		}
	}
	vector<P> slope = g.slope(S, T);
	ll ans = 0;
	int ans_flow;
	for (int i = 0; i < slope.size(); ++i) {
		int flow = slope[i].first; ll cost = slope[i].second;
		if (MAX * flow - cost > ans) {
			ans = MAX * flow - cost;
			ans_flow = flow;
		}
	}
	cout << ans << endl;
	h.flow(S, T, ans_flow);
	for (auto e : h.edges()) {
		if (e.from == S or e.to == T or e.flow < 1) continue;
		a[e.from][e.to - n] = 'X';
	}
	for (string s : a) cout << s << endl;
	return 0;
}

Measured memory_bytes: 4164
package main

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

var sc = bufio.NewScanner(os.Stdin);

func main() {
	var s, t string
	sc.Scan()
	s = sc.Text()
	sc.Scan()
	t = sc.Text()
	var cnt = 0

	for i := 0; i < 3; i++ {
		if s[i]==t[i] {
			cnt++
		}
	}

	fmt.Println(cnt)
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int N;
vector<int> a, ans, L;
vector<vector<int>> g;
void dfs(int v, int p){
  bool add = false;
  int id, pre;
  if(L.size()==0 || L.back() < a[v]){
    L.push_back(a[v]);
    add = true;
  }
  else{
    auto it = lower_bound(L.begin(), L.end(), a[v]);
    pre = *it;
    *it = a[v];
    id = it - L.begin();
  }
  ans[v] = L.size();
  for(auto nv : g[v]){
    if(nv == p) continue;
    dfs(nv, v);
  }
  if(add){
    L.pop_back();
  }
  else{
    L[id] = pre;
  }
}

int main(){
  cin >> N;
  a.resize(N), g.resize(N);
  REP(i, N){
    cin >> a[i];
  }
  REP(i, N-1){
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ans.resize(N);
  dfs(0, -1);
  REP(i, N){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 30128
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
"""
#N,K,Mが入力
    n,k,m=LI() 
    #N
    #x1 y1
    #.  .
    #xn ynが入力
    N=I()
    p=LIR(N)
    print(n,k,m,p)
"""

import fractions
def lcm(a, b):
    #return a * b // gcd (a, b)
    return a * b // fractions.gcd (a, b)

def resolve():
    a,b=LI()
    ans=lcm(a,b)
    print(ans)

    return

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 3"""
        output = """6"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """123 456"""
        output = """18696"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """100000 99999"""
        output = """9999900000"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 78316
#include<iostream>
using namespace std;
int main()
{
	int n, m, p;
	int x[101];
	while (cin >> n >> m >> p && n != 0 && m != 0)
	{
		int sum = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> x[i];
			sum += x[i]*100;
		}
		if (x[m] == 0)
		{
			cout << 0 << endl;
			continue;
		}
		double ans  =sum - ((double)p /100.0) * sum;
		cout << (int)(ans / x[m]) << endl;

	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>

int H;

bool exist(int x){
	if(x >= 1 && x <= H) return true;
	else return false;
}

int main(void){
	scanf("%d", &H);
	int s[H], i, p, l, r;
	for(i = 1;i <= H;i++) scanf("%d", &s[i]);
	for(i = 1;i <= H;i++){
		printf("node %d: key = %d, ", i, s[i]);
		p = i / 2;
		if(exist(p)) printf("parent key = %d, ", s[p]);
		l = i * 2;
		if(exist(l)) printf("left key = %d, ", s[l]);
		r = i * 2 + 1;
		if(exist(r)) printf("right key = %d, ", s[r]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  getline(cin,s);
  string ans="";
  rep(i,s.size()){
    if(i+4<s.size() && s.substr(i,5)=="apple"){
      ans+="peach";
      i+=4;
    }else if(i+4<s.size() && s.substr(i,5)=="peach"){
      ans+="apple";
      i+=4;
    }else{
      ans+=s[i];
    }
  }
  cout<<ans<<endl;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  int g = __gcd(n, m);
  for (int i = 0, j = 0; i < n && j < m; i += n / g, j += m / g) {
    if (s[i] != t[j]) {
      cout << -1 << '\n';
      return;
    }
  }
  cout << n / g * m << '\n';
}

signed main() {
  // ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  bool d = false;
  for(int i = 0;i < 3;i++){
    if(a.at(i)=='7')d = true;
  }
  if(d)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

set<pair<pii, int > > s;

int main() {
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int ans = 0;
  while(1) {
    if(a & 1) break;
    if(b & 1) break;
    if(c & 1) break;
    ans++;
    int x = (b + c) / 2;
    int y = (c + a) / 2;
    int z = (a + b) / 2;
    pair<pii, int > p = mp(mp(x,y),z);
    if(s.find(p) != s.end()) {
      P(-1);
      return 0;
    }
    s.insert(p);
    a = x;
    b = y;
    c = z;
  }
  P(ans);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int res = 1;
    int two = 2;
    while(two<=n){
        res = two;
        two = two*2;
    }
    cout << res << endl;
    return 0;
}

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

const int MAXN = 1e5 + 10;
int n, m, num[MAXN];
bool r[MAXN];

int main() {
	cin >> n >> m;
	r[1] = 1;
	for (int i = 1; i <= n; i++)
		num[i] = 1;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		num[a]--, num[b]++;
		if (r[a])
			r[b] = 1;
		if (num[a] == 0)
			r[a] = 0;
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		cnt += r[i];
	cout << cnt;
}

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

int main() {
    string s;
    cin >> s;
    int a=0;
    int z=s.size()-1;
    for (int i = 0; ;i++){
        if (s.at(i) == 'A') break;
        a++;
    }
    for (int j = s.size()-1; ;j--){
        if (s.at(j) == 'Z') break;
        z--;
    }
    cout << z-a+1 << endl;
}

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

struct zahyo{
  int y,x;
};

int h,w;
vector<string> s(20);

bool rangeCheck(int y,int x){
  if(y<0||y>=h||x<0||x>=w){
    return false;
  }
  return true;
}

int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  int dirY[]={0,1,0,-1};
  int dirX[]={1,0,-1,0};
  int ans=-1;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        continue;
      }
      int cntmax=-1;
      vector<vector<int>> cnt(h,vector<int> (w,-1));
      queue<zahyo> q;
      zahyo xy;
      xy.y=i;
      xy.x=j;
      q.push(xy);
      cnt[i][j]=0;
      while(!q.empty()){
        xy=q.front();
        q.pop();
        cntmax=max(cntmax,cnt[xy.y][xy.x]);
        for(int k=0;k<4;k++){
          int ny=dirY[k]+xy.y;
          int nx=dirX[k]+xy.x;
          if(rangeCheck(ny,nx)==false){
            continue;
          }
          if(s[ny][nx]=='#'){
            continue;
          }
          if(cnt[ny][nx]!=-1){
            continue;
          }
          cnt[ny][nx]=cnt[xy.y][xy.x]+1;
          zahyo temp;
          temp.y=ny;
          temp.x=nx;
          q.push(temp);
        }
      }
      ans=max(cntmax,ans);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int a1=a*60+b,c1=c*60+d;
	cout<<c1-a1-e<<endl; 
	return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
        BufferedReader in = new BufferedReader(reader);
        String[] str = in.readLine().split("");
        double num = 0;
        double res = 0;

        for(int i=0; i < str.length; i++) {
        	num = num*10 + Integer.parseInt(str[i]);
        	if(i % 5 == 0 ) {
        		res += num % 9;
        		num = 0;
        	}
            else if(i == str.length-1){
        		res += num % 9;
            }
        }
        if(res % 9 == 0) {
            System.out.println("Yes");

        }else {
            System.out.println("No");
        }

    }
}

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

int main() {
  string S,T;
  cin>>S>>T;
  int N=S.size();
  int Z=0;
  for(int i=0;i<N;i++){
    if(S.at(i)!=T.at(i)){
      Z++;
    }
  }
  cout<<Z<<endl;
}

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

const int MAXN=100000;

int n,a[MAXN];
long long f() {
	int sign=a[0]>0 ? 1 : -1;
	long long sum=a[0],res=0;
	for(int i=1;i<n;i++) {
		sign=-sign; sum+=a[i];
		if(sum*sign <= 0) {
			res+=-sum*sign + 1;
			sum = sign;
		}
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",a+i);

	long long mx,ad=0;
	int a0=a[0];
	if(a0<=0) a[0]=1, ad=-a0+1;
	else a[0]=a0,ad=0;
	
	mx=f()+ad;
	if(a0>=0) a[0]=-1, ad=a0+1;
	else a[0]=a0, ad=0;
	
	mx=min(mx,f()+ad);
	printf("%lld\n",mx);

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=n;
    rep(i,n-1)if(s.at(i)==s.at(i+1))ans--;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		
		// 計算
		long result = 1000;
		ArrayList<Long> buy = new ArrayList<Long>();
		ArrayList<Long> sell = new ArrayList<Long>();
		long b = 0;
		long pre = 0;
		for(int i = 0; i < n; i++){
		    if(i == 0){
		        b = a[i];
		        pre = a[i];
		    }else{
		        if(pre < a[i]){
		            pre = a[i];
		        }else if(b < pre){
		            buy.add(b);
		            sell.add(pre);
		            b = a[i];
		            pre = a[i];
		        }else{
		            b = a[i];
		            pre = a[i];
		        }
		    }
		}
		if(b < pre){
		    buy.add(b);
		    sell.add(pre);
		}
		//System.out.println(buy.toString());
		//System.out.println(sell.toString());
		
		for(int i = 0; i < buy.size(); i++){
		    long B = buy.get(i);
		    long S = sell.get(i);
		    result = result - (result/B)*B + (result/B)*S;
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 25356
n = int(raw_input())
d ={}
for i in range(1,n+1):
    nt = int(raw_input())
    all_testemonies = []
    for ii in range(nt):
        testemony_inpt = raw_input().split(" ")
        
        x, y =int(testemony_inpt[0]), int(testemony_inpt[1])
        all_testemonies.append([x,y])
    d[i] =all_testemonies

def get_honest_shougens(state, d, for_target):
    shougens = []
    for i in range(len(state)):
        if i+1 == for_target: # skip shougens from target
            continue
        elif state[i] != 1: #only collect honest shougens
            continue
        else:
            current_shougens = d[i+1]
            for ii in current_shougens:
                if ii[0] == for_target:
                    shougens.append(ii)
    return shougens

def check_consistency(state, d):
    c = 0
    for i in range(len(state)):
        shougens = get_honest_shougens(state, d, i+1)
        if state[i] == 1:
            if [i+1, 0] in shougens:
                return False
            else:
                c+=1
        elif state[i] == 0:
            if [i+1,1] in shougens:
                return False
            else:
                c+=1
        else:
            print("strange state..", state[i])
    if c == len(state):
        return True
    else:
        return False

import itertools
combinations = list(itertools.product([0, 1], repeat=n))
highest = 0
for i in combinations:
    s = sum(i)
    if s == 0:
        continue # always consistent if everyone can lie
    else:
        c = check_consistency(i, d)
        if c:
            if s>highest:
                highest = s
print(highest)

Measured memory_bytes: 10776
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int K = sc.nextInt();
    	String S = sc.next();
    	sc.close();
    	if(S.length() <= K){
    		System.out.println(S);
    	}else{
    		System.out.println(S.substring(0, K) + "...");
    	}
    }
}

Measured memory_bytes: 38600
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(){
	int n, k, b;
	std::bitset<18> flag;
	int num_all_subsets = 0;
	std::vector<int> T;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n >> k;
#else
	std::cin >> n >> k;
#endif



	for(int i = 0; i < k; i++){
#if INPUT_FROM_FILE
		ifs >> b;
#else
		std::cin >> b;
#endif
		T.push_back(b);
	}

	num_all_subsets = pow(2, n);
	if(T.empty()){
		std::cout << "0:" << std::endl;
	}
	for(int i = 1; i < num_all_subsets; i++){
		flag = std::bitset<18>(i);
		int num_subsets = flag.count();
		std::vector<int> S;

		for(int j = 0; j < 18; j++){
			std::bitset<18> mask;

			mask.set(j);

			if(flag.test(j) && mask.test(j)){
				S.push_back(j);
			}
		}
		if(std::includes(S.begin(), S.end(), T.begin(), T.end())){
			std::cout << i << ":";
			for(int j = 0; j < S.size(); j++){
				std::cout << " " << S[j];
			}
			std::cout << std::endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3284
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(x)  cout << #x << " = " << (x) << endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(4);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    ll n,k;
    string s;
    cin >> n >> k >>s;
    char cur = s[0];
    ll cnt = 1;
    rep(i,1,n){
        if(s[i] != cur){
            cnt++;
            cur = s[i];
        }
    }
    cnt = max(1ll,cnt-2*k);
    cout << n - cnt;
    cout << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long n;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
if (n&1) {cout << "0"; return 0;}
//if (n==1000000000000000000LL){cout << "aaa"; return 0;}
long long ans=0, pov=1;
pov=10;
for (int i=0; pov<=n; i++){
	ans+=n/pov; pov*=5;
//	cout << ans << " " << pov << endl;
} 
cout << ans;
return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int N;
vector<ll>X,Y,H;

bool ch(ll x,ll y,ll h)
{
	{
		for(int i=0;i<X.size();i++)
		{
			bool a=H[i]==max(h-abs(X[i]-x)-abs(Y[i]-y),0LL);
			if(!a)return false;
		}
	}
	return true;
}

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		if(c>=1)
		{
			X.push_back(a);
			Y.push_back(b);
			H.push_back(c);
		}
	}
	if(X.size()==1)
	{
		cout<<X[0]<<" "<<Y[0]<<" "<<H[0]<<endl;
		return 0;
	}
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
		{
			ll h=H[0]+abs(X[0]-i)+abs(Y[0]-j);
			if(ch(i,j,h))
			{
				cout<<i<<" "<<j<<" "<<h<<endl;
				return 0;
			}
		}
	return 0;
}


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


int main() {
    long long K,A,B;
    bool isok = false;
    cin >> K >> A >> B;
    for (int i = 1; i<=1000; i++){
        if (A<=K*i && K*i<=B) {
            isok = true;
            break;
        }
    }
    if (isok){
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef pair<int, int> P;

vector<int> edge[108000], edge2[108000];
vector<P> edges;
bool come[108000];
int dp[108000];
int w[108000];
int imos[108000];
int sum[108000];
int n, m, u, v;

int root[108000];
int r(int x){
	if(root[x] == x)return x;
	return root[x] = r(root[x]);
}

int unite(int x, int y){
	x = r(x);
	y = r(y);
	root[x] = y;
}

bool dfs(int x, int last = -1){
	come[x] = true;
	for(int i = 0;i < edge[x].size();i++){
		int to = edge[x][i];
		if(to == last)continue;
		if(!come[to]){
			if(dfs(to, x))unite(to, x);
			else edges.push_back(P(x, to));
			imos[x] += imos[to];
		}
		else{
			imos[to]--;
			imos[x]++;
		}
	}
	return imos[x] > 0;
}

int dfs2(int x){
	int res = 0;
	for(int i = 0;i < edge2[x].size();i++){
		int to = edge2[x][i];
		res = max(res, dfs2(to));
	}
	return res + sum[x];
}

int main(){
	cin >> n >> m;
	for(int i = 1;i <= n;i++){
		cin >> w[i];
		root[i] = i;
	}
	for(int i = 0;i < m;i++){
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	dfs(1);
	for(int i = 1;i <= n;i++)sum[r(i)] += w[i];
	for(int i = 0;i < edges.size();i++){
		P e = edges[i];
		int u = edges[i].first, v = edges[i].second;
		edge2[r(u)].push_back(r(v));
	}
	cout << dfs2(r(1)) << endl;
	return 0;
}


Measured memory_bytes: 25964
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		ArrayList<ArrayList<Integer>> p = new ArrayList<ArrayList<Integer>>();
		for (int i = 0; i < 10; ++i) {
			p.add(new ArrayList<Integer>());
		}
		for (int i = 0; i < N; ++i) {
			int C = sc.nextInt();
			int G = sc.nextInt() - 1;
			p.get(G).add(C);
		}
		for (int i = 0; i < 10; ++i) {
			Collections.sort(p.get(i));
			Collections.reverse(p.get(i));
		}
		int[][] dp = new int[11][K + 1];
		for (int i = 0; i < 10; ++i) {
			ArrayList<Integer> b = p.get(i);
			int sum = 0;
			for (int j = 0; j <= Math.min(b.size(), K); ++j) {
				if (j != 0) {
					sum += b.get(j - 1);
					sum += 2 * (j - 1);
				}
				for (int k = 0; k + j <= K; ++k) {
					dp[i + 1][k + j] = Math.max(dp[i + 1][k + j], dp[i][k] + sum);
				}
			}
		}
		System.out.println(dp[10][K]);
	}
}

Measured memory_bytes: 13000
N,M=map(int,input().split())
KA=[list(map(int,input().split())) for i in range(N)]
food=[0]*M
for i in KA:
  A=i[1:]
  for j in A:
    food[j-1]+=1
ans=0
for i in food:
  if i==N:
    ans+=1
print(ans)
  

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

int main(int argc, char **argv)
{
    char o[64];
    char e[64];
    scanf("%s", o);
    scanf("%s", e);

    char s[124];
    for (int i = 0; i < 50; ++i) {
        s[i*2] = o[i];
        if (o[i] == '\0') {
            break;
        }
        s[i*2+1] = e[i];
        if (e[i] == '\0') {
            break;
        }
    }
    s[100] = '\0';
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

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

    int a;
    ll b, n;
    cin >> a >> b >> n;

    n = min(n, b - 1);

    int ans = 0;
    for (int i = 0; i < a; i++) {
        if (n >= (i * b + a - 1) / a) {
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
N = int(input())
C=[]
S=[]
F=[]
for i in range(N-1):
  a,b,c = map(int,input().split())
  C.append(a)
  S.append(b)
  F.append(c)

for i in range(N-1):
  T = 0
  for j in range(i,N-1):
    if T < S[j]:
      T = S[j]
    elif T%F[j]==0:
      T = T
    else:
      T = T+F[j] - T%F[j]
    T = T + C[j]
  print(T)
print(0)

Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import *
import sys

N = int(input())
marks = input()
marks = [ 1 if mark == 'x' else 0 for mark in marks]

for comb in product([0, 1], repeat=2):
    arr = [None for _ in range(N)]
    arr[:2] = comb
    for i in range(2, N):
        arr[i] = arr[i-2] ^ arr[i-1] ^ marks[i-1]
    if (arr[-2] ^ arr[-1] ^ arr[0] == marks[-1]) \
       and (arr[-1] ^ arr[0] ^ arr[1] == marks[0]) \
       and (arr[0] ^ arr[1] ^ arr[2] == marks[1]):
        print(''.join('S' if x == 0 else 'W' for x in arr))
        sys.exit(0)
print(-1)




Measured memory_bytes: 6136
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>/
// #include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define mod 1000000007LL
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define SZ(z) ((int)z.size())
#define sq(x) ((x)*(x))

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL)

#define EPS 1e-7

// using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 100005

int a[1005][1005] ;

int main()
{
    int r , c , A , B ;

    scanf("%d %d %d %d",&r,&c,&A,&B) ;

    for(int i=1 ; i<=2*B ; i++)
    {
        int fl = i%2 ;
        for(int j=1 ; j<=A ; j++) a[i][j] = fl ;
        fl ^= 1  ;
        for(int j=A+1 ; j<=2*A ; j++) a[i][j] = fl ;
    }

    for(int i=2*B+1 ; i<=r ; i++)
    {
        for(int j=1 ; j<=A ; j++) a[i][j] = 1 ;
    }

    for(int j=2*A+1 ; j<=c ; j++)
    {
        for(int i=1 ; i<=B ; i++) a[i][j] = 1 ;
    }

    for(int i=1 ; i<=r ; i++)
    {
        for(int j=1 ; j<=c ; j++) printf("%d",a[i][j]) ;
        printf("\n") ;
    }

    return 0 ;
}


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

using namespace std;

int main(){
  int n,a;
  cin >> n >> a;
  int ans = 0;
  if(n > a) {
    ans += n;
    n--;
  } else {
    ans += a;
    a--;
  }
  ans += max(n,a);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {

  int ans;

  for( int i = 1; i < 6; i++){

    int x;
    cin >> x;
    if( x == 0 ) ans = i;

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

}

Measured memory_bytes: 3584
<?php
fscanf(STDIN, "%d %d", $n, $l);

$apple = [];
$check = [];
for($i=1; $i<=$n; $i++){
    $apple[] = $l+$i-1;
}

if(in_array('0',$apple)){
    echo array_sum($apple);
}elseif(min($apple) > 0){
    array_splice($apple, 0, 1);
    echo array_sum($apple);
}elseif(min($apple) < 0){
    for($i=0; $i<count($apple); $i++){
        $check[] = abs($apple[$i] - 0);
    }
    $del_key = array_keys($check, min($check));
    array_splice($apple, $del_key[0], 1);
    echo array_sum($apple);
}
?>

Measured memory_bytes: 3700
#include <stdio.h>

int pow_10(int n) {
  int t = 1, i;
  for (i = 0; i < n; i++)
    t *= 10;
  return t;
}

void maxsort(int a[], int n) {
  int i, j, t;
  for (i = 0; i < n; i++)
    for (j = i; j > 0; j--)
      if (a[j - 1] > a[j]) {
	t = a[j - 1];
	a[j - 1] = a[j];
	a[j] = t;
      }
}

void minsort(int a[], int n) {
  int i, j, t;
  for (i = 0; i < n; i++)
    for (j = i; j > 0; j--)
      if (a[j - 1] < a[j]) {
	t = a[j - 1];
	a[j - 1] = a[j];
	a[j] = t;
      }
}

void copy(int a[], int b[]) {
  int i;
  for (i = 0; i < 6; i++)
    b[i] = a[i];
}

int main(void) {
  int a0, l, i, j, k, p, q;
  int a[6], t[20], b[6], c[6];

  while (1) {
    scanf("%d%d", &a0, &l);
    if (a0 == 0 && l == 0) return 0;
    t[0] = a0;

    for (i = 1; ; i++) {
      for (j = 0; j < 6; j++) {
	a[i] = 0;
	b[i] = 0;
	c[i] = 0;
      }
      if (i > 1) a0 = t[i - 1];
      for (j = 0; j < l; j++) {
	a[j] = a0 % 10;
	a0 /= 10;
      }

      copy(a, b);
      copy(a, c);
      maxsort(b, l);
      minsort(c, l);

      p = 0;
      q = 0;
      for (j = 0; j < l; j++) {
	p += b[j] * pow_10(j);
	q += c[j] * pow_10(j);
      }

      t[i] = p - q;
      for (j = 0; j < i; j++) {
	if (t[i] == t[j]) {
	  printf("%d %d %d\n", j, t[i], i - j);
	  goto loop_end;
	}
      }
    }
  loop_end: ;
  }
}

Measured memory_bytes: 2580
N,H = map(int,input().split(" "))
a = [0] * N
b = [0] * N

for i in range(N):
    a[i],b[i] = map(int,input().split(" "))
a.sort(reverse = True)
b.sort(reverse = True)
c = 0
while(b[c] > a[0]):
    H -= b[c]
    c += 1
    if c == len(b):break
    if H <= 0:break
if H > 0:
    if (H % a[0] != 0):c += 1
    c += H // a[0]
print(c)

Measured memory_bytes: 11312
n = int(input())
dp = [[[[0] * 5 for _ in range(5)] for _ in range(5)] for _ in range(n + 1)]
mod = 10 ** 9 + 7

dp[0][0][0][0] = 1
for i in range(n):
    for j in range(5):
        for k in range(5):
            for l in range(5):
                for s in range(1, 5):
                    if l == 3 and k == 1 and s == 2:
                        continue
                    if l == 2 and k == 1 and s == 3:
                        continue
                    if l == 1 and k == 3 and s == 2:
                        continue
                    if k == 3 and j == 1 and s == 2:
                        continue
                    if l == 3 and j == 1 and s == 2:
                        continue
                    dp[i + 1][s][l][k] += dp[i][l][k][j]
                    dp[i + 1][s][l][k] %= mod
ans = 0
for j in range(1, 5):
    for k in range(1, 5):
        for l in range(1, 5):
            ans += dp[n][j][k][l]
print(ans % mod)

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

const ll MOD = 1LL * (1e9 + 7);
ll P[100009]; // P[i] = (1/1 + 1/2 + ... + 1/i) * N!

ll myp(ll x, ll y) {
    if(y == 0LL) return 1LL;
    long long t = myp(x, y/2LL);
    if(y%2LL) return t*t%MOD*x%MOD;
    return t*t%MOD;
}

inline ll rv(ll x) {
    return myp(x, MOD-2LL);
}

int main() {
    int N; ll ans = 0LL, NF = 1LL;
    scanf("%d",&N);
    for(int i=1; i<=N; i++) NF = NF * i % MOD;
    for(int i=1; i<=N; i++) {
        P[i] = (P[i-1] + NF * rv(i) % MOD) % MOD;
    }
    for(int i=1; i<=N; i++) {
        ll foo;
        scanf("%lld",&foo);
        ans += P[i] * foo % MOD; ans %= MOD;
        ans += (P[N-i+1] - NF + MOD) * foo % MOD; ans %= MOD;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1024
def resolve():
    s = input()
    ls = len(s)
    for i in range(1, ls - 1):
        t = s[:-i]
        lt = len(t)
        if lt % 2 == 0 and t[:lt // 2] * 2 == t:
            print(lt)
            return 0


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

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

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

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

	ll a;
	double _b;
	cin >> a >> _b;
	ll b = (ll)(_b * 100 + 0.5);

	a *= b;
	a /= 100;
	cout << a << endl;

	return 0;
}

Measured memory_bytes: 3196