akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string.h>

using namespace std;

int main(void)
{
    char S[101] = {0};
    long K;

    cin >> S;
    cin >> K;

    char prev = '\0';
    long count = 0;

    if (strlen(S) == 1)
    {
        cout << K / 2 << endl;
        return 0;
    }

    // First
    for (int i = 0; S[i] != '\0'; i++)
    {
        char c = S[i];
        if (prev == c)
        {
            count++;
            prev = '\0';
        }
        else
        {
            prev = c;
        }
    }

    if (prev == '\0')
    {
        cout << count * K << endl;
        return 0;
    }

    // second
    long count2 = 0;
    for (int i = 0; S[i] != '\0'; i++)
    {
        char c = S[i];
        if (prev == c)
        {
            count2++;
            prev = '\0';
        }
        else
        {
            prev = c;
        }
    }

    if (prev == '\0')
    {
        if (K % 2 == 0)
        {
            cout << (count + count2) * (K / 2) << endl;
            return 0;
        }
        else
        {
            cout << count * (K / 2 + 1) + count2 * (K / 2) << endl;
            return 0;
        }
    }

    cout << count + count2 * (K - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll t[20000005];
ll a[10000005];
ll b[10000005];
ll dp[10005][10005];
ll ex = 1000000007;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	int n;
	cin >> n;
	ll count = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, T; cin >> n >> T;
	int idx = -1;
	int mi = 1001;
	rep(i, n) {
		int c, t; cin >> c >> t;
		if (t <= T) {
			if (mi > c) {
				mi = c;
				idx = i + 1;
			}
		}
	}
	if (idx == -1) printf("TLE\n");
	else printf("%d\n", mi);
	return 0;
}


Measured memory_bytes: 256
/*input
19 99
*/
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll  a, b;
    cin>>a>>b;
    ll Xa = (100*a)/8;
    ll Xb = 10*b;
    ll ans = max(Xa,Xb);
    //cout<<ans<<endl;
    int flag=0;
    for(ll i = 1;;i++){
    	ll pa = i*0.08;
    	ll pb = i*0.1;
    	if(pa==a && pb==b){
	    	cout<<i<<endl;
	    	flag=1;
	    	break;
	    }
	    else if(pa>a && pb>b){
	    	cout<<"-1"<<endl;
	    	break;
	    }

    }
    // if(flag==0){
    // 	cout<<-1<<endl;
    // }
    
    return 0;
}

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

int main() {
  int n, taro[52] = {0}; // s 0~12, h 0~12, c 0~12, d 0~12
  cin >> n;
  for (int i=0;i<n;i++) {
    string mark;
    int num;
    cin >> mark >> num;
    if (mark == "S")
      taro[num - 1] = 1;
    else if (mark == "H")
      taro[13 + (num - 1)] = 1;
    else if (mark == "C")
      taro[26 + (num - 1)] = 1;
    else
      taro[39 + (num - 1)] = 1;
  }
  for (int i=0;i<52;i++)
    if (taro[i] == 0) {
      if (i < 13)
        cout << "S " << i + 1 << endl;
      else if (i < 26)
        cout << "H " << i + 1 - 13 << endl;
      else if (i < 39)
        cout << "C " << i + 1 - 26 << endl;
      else
        cout << "D " << i + 1 - 39 << endl;
    }
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
using vvb=vector<vector<bool>>;
using vb= vector<bool>;
ll f(ll a,ll b,ll p){
	if(b==0) return 1;
	if(b%2==0){
		ll t=f(a,b/2,p);
		return t*t%p;
	}
	return a*(f(a,b-1,p))%p;
} 

//__builtin_popcount()
signed main(){
	int n; cin>>n;
	string s; cin>>s;
	if(n==1){
		if(s=="0")cout<<1<<endl;
		else cout<<0<<endl;
		return 0;
	}
	string t=s;
	reverse(all(t));
	vl memo1(n),memo2(n);
	ll sum1=0,sum2=0;
	if(t[0]=='1')sum1=1,sum2=1;
	ll cnt=0;
	rep(i,0,n)cnt+=(s[i]=='1');
	if(cnt==1){

	}
	memo1[0]=1; memo2[0]=1;
	rep(i,1,n){
		memo1[i]=memo1[i-1]*2%(cnt+1);
		if(cnt-1>0)memo2[i]=memo2[i-1]*2%(cnt-1);
		if(t[i]=='1'){
			sum1+=memo1[i];
			sum1%=(cnt+1);
			sum2+=memo2[i];
			if(cnt-1>0)sum2%=(cnt-1);
		}
	}
	vl ans(n);
	rep(i,0,n){
		ll j;
		if(t[i]=='0'){
			j=sum1;
			j+=memo1[i];
			j%=(cnt+1);
		}
		else{
			j=sum2;
			j-=memo2[i];
			if(j<0)j+=(cnt-1);
			//if(cnt-1>0)j%=(cnt-1);
			if(cnt-1==0){
				ans[i]=0;
				continue;
			}
		}

		ll add=1;
		while(j>0){
			if(__builtin_popcount(j)==0){
				add++;
				break;
			}
			j%=__builtin_popcount(j);
			add++;
		}
		ans[i]=add;
	}
	reverse(all(ans));
	rep(i,0,n)cout<<ans[i]<<endl;


	return 0;
}

Measured memory_bytes: 8380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;
	cout << (s.size() % 2 ^ s[0] == s[s.size() - 1]?"First":"Second") << endl;

}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define st(v) sort(v.begin(),v.end());
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

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

const int MAXN = 2e5+3; //AREGLAAAAAAAAR!!!!
const int MAXLOG = 20;


int main(){
	int a,b;
	rii(a,b);
	int ans = b*a-(b+a-1);
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define Imax 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  ll int L,R;
  cin>>L>>R;
  ll int min=Imax;
  int md;
  rep(i,L,R+1){
    if(i>L+2020) break;
    rep(j,i+1,R+1){
      if(j>i+2020) break;
      md=(i*j)%2019;
      if(md<min) min=md;
    }
  }
  cout<<min;
      
  

}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P


int main(){
	char s[4];
	scanf("%s", s);
	int ans = 0;
	if(s[0]>'0') ans++;
	if(s[1]>'0') ans++;
	if(s[2]>'0') ans++;

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
// #define int long long
#define mod (int)(1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

int hako[111111];
int muki[111111];
vector<pii> ai;
void ironuri(int x, int y){
  if(hako[x]!=-1) return;
  hako[x]=y;
  ironuri(muki[x],y);
}

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  vector<pii> ba(n);
  
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];

  
  for(int i=0;i<n;i++){
    ba[i]=pii(b[i],a[i]);
  }
  
  sort(ba.begin(),ba.end());
  sort(b.begin(),b.end());
  sort(a.begin(),a.end());

  bool f=true;
  for(int i=0;i<n && f;i++){
    if(a[i]>b[i]) f=false;
  }
  if(!f){
    cout<<"No"<<endl;
    return 0;
  }
  
  ai.resize(n);
  for(int i=0;i<n;i++){
    ai[i]=pii(ba[i].second,i);
  }
  sort(ai.begin(),ai.end());
  fill(hako, hako+n,-1);
  for(int i=0;i<n;i++){
    muki[ai[i].second]=i;
  }
  int t=0;
  for(int i=0;i<n;i++){
    if(hako[i]==-1){
      ironuri(i,i);
      t++;
    }
  }

  if(t>1) cout<<"Yes"<<endl;
  else{
    for(int i=1;i<n && f;i++){
      if(a[i]<=b[i-1]) f=false;
    }
    if(!f) cout<<"Yes"<<endl;
    else   cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
  int N;
  int cnt = 0, C = 0;
  cin >> N;
  int h[N];
  for(int i = 0;i < N; ++i){
    cin >> h[i];
    if(h[i] > C)
      cnt += h[i] - C;
    C = h[i];
  }
  
  cout << cnt << endl;
}  

Measured memory_bytes: 256
from collections import Counter
S = list(input())
s = set(Counter(S).keys())
if len(s) == 4:
    print("Yes")
elif len(s) == 2 and "E" in s and "W" in s:
    print("Yes")
elif len(s) == 2 and "N" in s and "S" in s:
    print("Yes")
else:
    print("No")





Measured memory_bytes: 3316
fun main(args: Array<String>) {
    val s = readLine()!!
    val q = readLine()!!.toInt()

    var reverseCount = 0
    val beforeList = mutableListOf<String>()
    val afterList = mutableListOf<String>()
    repeat(q) {
        val command = readLine()!!.split(" ")
        if (command.size == 1) {
            reverseCount += 1
            return@repeat
        }
        val isReversed = reverseCount % 2 == 1
        val str = command[2]

        if (isReversed) {
            if (command[1] == "1") {
                afterList.add(str)
            } else {
                beforeList.add(str)
            }
        } else {
            if (command[1] == "1") {
                beforeList.add(str)
            } else {
                afterList.add(str)
            }
        }
    }

    var ans = beforeList.joinToString("").reversed() + s + afterList.joinToString("")
    if (reverseCount % 2 == 1) {
        ans = ans.reversed()
    }
    println(ans)
}

Measured memory_bytes: 83056
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n;
ll a[3010];
ll dp[3010][3010];

ll f(int x,int y,int c){
	//このあとたろうが取れる得点の最大値
	if(dp[x][y])return dp[x][y];
	if(x+y==n)return 0;
	if(c==0){
		//自分の手番
		return dp[x][y]=max(f(x+1,y,1)+a[x],f(x,y+1,1)+a[n-1-y]);
	}else{
		return dp[x][y]=min(f(x+1,y,0),f(x,y+1,0));
	}
}

int main(){
	scanf("%lld",&n);
	ll s=0;
	rep(i,0,n){
		scanf("%lld",a+i);
		s+=a[i];
	}
	printf("%lld\n",2*f(0,0,0)-s);
	return 0;
}

Measured memory_bytes: 70144
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int K = nextInt();
		int[] h = new int[N];
		for(int i=0;i<N;i++){
			h[i]=nextInt();
		}
		Arrays.sort(h);
		long ans = Long.MAX_VALUE;
		for(int i=0;i<=N-K;i++){
			ans=Math.min(ans, h[i+K-1]-h[i]);
		}
		System.out.println(ans);
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 35004
#include<iostream>
#include<map>
#include<string>
#include<utility>
#include<vector>
#include<cctype>
#include<cmath>
#include<algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define rFOR(i, a, b) for(int i=b; i>=a; i--)
#define all(a)  a.begin(), a.end()
#define MAX 10
typedef long long ll;
using namespace std;

char ToUpper(char cX) { return toupper(cX); }

int main(void){
  int a, b, c; cin >> a >> b >> c;
  cout << ((b-a==c-b)?"YES":"NO");
  return 0;
}

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

S = input()

count = 0
if len(S)%2==0:
	a = int(len(S)/2-1)
	for i in range(a+1):
		if S[a+1+i] != S[a-i]:
			count += 1
else:
	a = int(len(S)//2)
	for i in range(a):
		if S[a+1+i] != S[a-1-i]:
			count += 1

print(count)

Measured memory_bytes: 59500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,N;
#define p(i,n,vect) for(ll i=0;i<(ll)n;++i) {cout<<vect[i]<<" ";} cout<<"\n";
void solve()
{
    cin>>N;
    if(N==0)
    cout<<1<<"\n";
    else
    {
        cout<<0<<"\n";
    }
    
}
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
   
  
    solve();
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?(c=getchar()):0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
const int N=10010,O=998244353;
inline int fpow(int x,int n){
	int a=1;
	for(;n;n>>=1,x=(lint)x*x%O){
		if(n&1){
			a=(lint)a*x%O;
		}
	}
	return a;
}
inline int inv(int x){
	return fpow(x,O-2);
}
int fac[N],invfac[N];
inline int c(int n,int k){
	return (lint)fac[n]*invfac[k]%O*invfac[n-k]%O;
}
inline void gmath(int n){
	fac[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=(lint)fac[i-1]*i%O;
	}
	invfac[n]=inv(fac[n]);
	for(int i=n;i>=1;i--){
		invfac[i-1]=(lint)invfac[i]*i%O;
	}
}
namespace poly{
    const int SH=15,N=1<<SH;
    int sh,n,invn;
    int rev[N],o[SH][N>>1],io[SH][N>>1];
    inline void init(int _n){
        for(sh=0;(1<<sh)<_n;sh++);
        n=1<<sh,invn=inv(n);
        rev[0]=0;
        for(int i=0;i<n;i++){
            rev[i]=(rev[i>>1]>>1)|((i&1)<<(sh-1));
        }
        for(int i=0;i<sh;i++){
            int half=1<<i,full=half<<1;
            lint w=1,iw=1,wn=fpow(3,(O-1)/full),iwn=inv(wn);
            for(int j=0;j<half;j++,(w*=wn)%=O,(iw*=iwn)%=O){
                o[i][j]=w,io[i][j]=iw;
            }
        }
    }
    inline void ntt(int a[],int d=1){
        for(int i=0;i<n;i++){
            if(rev[i]>i){
                swap(a[i],a[rev[i]]);
            }
        }
        for(int i=0;i<sh;i++){
            int half=1<<i,full=half<<1;
            for(int j=0;j<half;j++){
                int w=(d==1?o:io)[i][j];
                for(int k=j;k<n;k+=full){
                    int p=a[k],q=(lint)a[k+half]*w%O;
                    a[k]=(p+q)%O;
                    a[k+half]=(p+O-q)%O;
                }
            }
        }
        if(d==-1){
            for(int i=0;i<n;i++){
                a[i]=(lint)a[i]*invn%O;
            }
        }
    }
	inline void fpow(int a[],int b[],int o,int e){
		if(e==0){
			memset(a,0,n<<2);
			ntt(b);
			a[0]=1;
			return;
		}
		fpow(a,b,o,e>>1);
		ntt(a);
		for(int i=0;i<n;i++){
			a[i]=(lint)a[i]*a[i]%O;
		}
		ntt(a,-1);
		memset(a+o,0,(n-o)<<2);
		if(e&1){
			ntt(a);
			for(int i=0;i<n;i++){
				a[i]=(lint)a[i]*b[i]%O;
			}
			ntt(a,-1);
			memset(a+o,0,(n-o)<<2);
		}
	}
}
int f[poly::N],g[poly::N];
int main(){
	int a=0,b=0;
	{
		static char s1[N],s2[N];
		scanf("%s%s",s1,s2);
		for(int i=0;s1[i];i++){
			if(s2[i]=='1'){
				(s1[i]=='1'?a:b)++;
			}
		}
	}
	gmath(a+b);
	lint ans=0;
	poly::init((a<<1)|1);
	memset(g,0,poly::n<<2);
	for(int i=0;i<=a;i++){
		g[i]=invfac[i+1];
	}
	poly::fpow(f,g,a+1,b);
	for(int i=0;i<=a;ans+=f[i],i++);
	ans=ans%O*fac[a+b]%O*fac[a]%O*fac[b]%O;
	printf("%lld\n",ans);
	return 0;
}

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


def solve(N: int):
    return print(math.ceil(N/2))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll    long long int
#define ld    long double
#define pb    push_back
#define mp    make_pair
#define Maxn  1000007
#define ff    first
#define se    second
using namespace std;
 
int main(){
    ll n,sum=0,sum1=0,ans=0,i;
    cin>>n;
    ll a[n+1],b[n];
    for(i=0;i<n+1;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        cin>>b[i];
    }
    for(i=0;i<n;i++){
        if(a[i]>b[i]){
            ans+=b[i];
        }
        else{
            sum=a[i]+a[i+1];
            if(sum<=b[i]){
                ans+=sum;
                a[i+1]=0;
            }
            else{
                sum1=(sum-b[i]);
                ans+=b[i];
                a[i+1]=(sum-b[i]);
            }
        }
    }
    cout<<ans;
        
}

Measured memory_bytes: 1792
#include<iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int N;
  cin >> N;
  ll cost[100010];
  for (int i = 0; i < N; ++i)
  {
      cin >> cost[i];
  }
  ll dp[100010];
  for (int i = 0; i < 100010; ++i)
  {
      dp[i] = LLINF;
  }

  dp[0] = 0;

  for (int i = 1; i < N; i++)
  {
      chmin(dp[i],dp[i-1] + abs(cost[i] - cost[i-1]));
      if(i > 1)  chmin(dp[i],dp[i-2] + abs(cost[i] - cost[i-2]));  
  }
  
  //Nまでのコストの最小
  cout << dp[N-1] <<endl;
  
}

Measured memory_bytes: 1792
n = int(input())
 
li = [[0] * 9 for _ in range(9)]
 
for i in range(1, n + 1):
    str_i = str(i)
    top = int(str_i[0])
    bottom = int(str_i[-1])
    if bottom == 0:
        continue
    li[top-1][bottom-1] += 1
 
cnt = 0
for i in range(1, n + 1):
    str_i = str(i)
    top = int(str_i[0])
    bottom = int(str_i[-1])
    if bottom == 0:
        continue
    cnt += li[bottom-1][top-1]
 
print(cnt)
    

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

int main() {
	// your code goes here
	int x,y;
	cin >> x>>y;
	if(x<y) swap(x,y);
	while(y!=0){
		int r=x%y;
		x=y;
		y=r;
	}
	cout <<x<<endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>

using namespace std;

long long lcm(long long a, long long b);

int main(void)
{
  long long a, b;

  cin >> a >> b;

  cout << a * b / lcm(max(a, b), min(a, b)) << endl;

  return 0;
}

long long lcm(long long a, long long b)
{
  long long c = a % b;
  if(c == 0){
    return b;
  }

  return lcm(b, c);
}


Measured memory_bytes: 256
S = input()
 

dp = [0]*2019
c = 0
dp[0] = 1

p = 0
q = 1
for i in range(len(S)):
  p += int(S[len(S)-1-i])*q
  p %= 2019
  q *= 10
  q %= 2019
  dp[p] += 1
 
for j in dp:
  c += j * (j-1) // 2
print(c)

Measured memory_bytes: 9276
from collections import Counter


N = int(input())
S = Counter()
for _ in range(N):
    s = input()
    S.update([s])
M = int(input())
T = Counter()
for _ in range(M):
    t = input()
    T.update([t])

ans = 0
for s, s_cnt in S.items():
    ans = max(ans, max(s_cnt - T.get(s, 0), 0))
print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	if(a=="Sunny")
	{
		cout<<"Cloudy";
	}
	if(a=="Cloudy")
	{
		cout<<"Rainy";
	}
	if(a=="Rainy")
	{
		cout<<"Sunny";
	}
	return 0;
}

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

int main() {
	string ss;
	cin>>ss;
	int ones=0;
	int zeros=0;
	string x="";
	for (int i=0; i<ss.length(); i++){
		if (ss[i]=='B'){
			if (x.length()==0) continue;
			else x.pop_back();
		}
		else if(ss[i]=='1'){
			x+='1';
		}
		else if (ss[i]=='0'){
			x+='0';
		}
	}
	cout << x<< endl;
	
}

Measured memory_bytes: 256
//　幅優先探索

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int bfs(int x, int y);

const int INF = 1e6;

int H, W;
vector<vector<char>> area(20, vector<char>(20));

vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
vector<vector<int>> st_distance(20, vector<int>(20));
int max_distance_s = 0;
int max_distance_g = 0;
int max_tmp = 0;

int main(){

    cin >> H >> W;
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            cin >> area.at(i).at(j);
        }
    }

    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            max_tmp = bfs(i, j);

            if (max_tmp > max_distance_g){
                max_distance_g = max_tmp;
            }
        }
    }

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

int bfs(int x, int y){

    queue<pair<int, int>> q;
    P p_tmp;

    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            st_distance.at(i).at(j) = INF;
        }
    }

    st_distance.at(x).at(y) = 0;
    q.push(P(x, y));

    while (q.size()){
        p_tmp = q.front();
        q.pop();

        for (int i=0; i<4; i++){
            int nx, ny;
            nx = p_tmp.first + dx.at(i);
            ny = p_tmp.second + dy.at(i);
            
            if ((0<=nx) && (nx<H) && (0<=ny) && (ny<W) && (st_distance.at(nx).at(ny) == INF) && (area.at(nx).at(ny) == '.') && (area.at(p_tmp.first).at(p_tmp.second) == '.')){
                q.push(P(nx, ny));
                st_distance.at(nx).at(ny) = st_distance.at(p_tmp.first).at(p_tmp.second) + 1;

                if (st_distance.at(nx).at(ny) > max_distance_s){
                    max_distance_s = st_distance.at(nx).at(ny);
                }
            }
        }
    }

    return max_distance_s;
}

Measured memory_bytes: 256
def main():
    S = input()
    S = S[:-1]

    N = len(S)

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for i in range(N):
        for j in range(N):
            if S[i] == S[j]:
                dp[i + 1][j + 1] = min(
                    dp[i][j] + 1,
                    max(0, j - i)
                )

    ans = 0
    for i in range(N):
        if i * 2 < N and dp[i][i * 2] == i:
            ans = max(ans, i * 2)

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
    int N;
    int count = 0;
    bool able = true;
    cin >> N;
    int A[210];

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

    while(able == true){

        for(int i = 0; i < N; i++){
            if(A[i] % 2 != 0){
                able = false;
                break;
            }
        }
        if(able == true){
            for(int i = 0; i < N; i++){
                A[i] = A[i] / 2;
            }
            count ++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    val (x, y, a, b, c) = readLine()!!.split(" ").map { it.toInt() }
    val p = readLine()!!.split(" ").map { it.toLong() }.sorted().reversed()
    val q = readLine()!!.split(" ").map { it.toLong() }.sorted().reversed()
    val r = readLine()!!.split(" ").map { it.toLong() }.sorted().reversed()

    val p1 = p.take(x)
    val q1 = q.take(y)
    val ans = longArrayOf(*p1.toLongArray(), *q1.toLongArray(), *r.toLongArray()).sorted().reversed().take(x+y).sum()
    println(ans)
}

Measured memory_bytes: 118096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n;
    cin >> n;
    string ans = "";
    while(n > 0){
        n--;
        char c = 'a' + (n % 26);
        ans = c + ans;
        n /= 26;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll = pair<ll,ll>;
using Graph = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) // x/yの除算の切り上げ
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 inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = acos(-1);
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;
    vector<vector<ll>> to(n),cost(n);
    rep(i,n-1){
        ll a,b,w;
        cin >> a >> b >> w;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
        cost[a].push_back(w);
        cost[b].push_back(w);
    }
    vector<ll> ans(n,-1);
    queue<ll> q;
    ans[0]=0;
    q.push(0);
    while(!q.empty()){
        ll v=q.front();
        q.pop();
        rep(i,to[v].size()){
            ll u=to[v][i];
            ll w=cost[v][i];
            if(ans[u]!=-1) continue;
            ans[u]=(ans[v]+w)%2;
            q.push(u);
        }
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 15804
def solve():
    N,W = map(int,input().split())
    weight = []
    value = []
    for i in range(N):
        w,v = map(int,input().split())
        weight.append(w)
        value.append(v)
    sum_value = sum(value)
    
    dp = [[float('inf')] * (sum_value+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(1,N+1):
        for v in range(sum_value+1):
            if v - value[i-1] < 0:
                dp[i][v] = min(dp[i][v], dp[i-1][v])
            else:
                dp[i][v] = min(dp[i][v], dp[i-1][v-value[i-1]] + weight[i-1])
                dp[i][v] = min(dp[i][v], dp[i-1][v])
    
    ans = 0
    for i in range(N+1):
        for v in range(sum_value+1):
            if dp[i][v] <= W:
                ans = max(ans,v)
    
    print(ans)

if __name__ == '__main__':
    solve()

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

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  Int len;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(string S_,ull B_=1000000007LL):
    S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
    hash[0]=0;p[0]=1;
    for(Int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(Int l,Int r){
    return hash[r]-hash[l]*p[r-l];
  }
};

struct RollingHash2{
  typedef unsigned long long ull;
  string S;
  ull B;
  Int len;
  vector<ull> hash,p;
  const ull MOD = 1000000007LL;
  RollingHash2(){}
  RollingHash2(string S_,ull B_=177771):
    S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
    hash[0]=0;p[0]=1;
    for(Int i=0;i<len;i++){
      hash[i+1]=(hash[i]*B+S[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l,r)
  ull find(Int l,Int r){
    return (hash[r]+MOD-hash[l]*p[r-l]%MOD)%MOD;
  }
};
//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  {
    string t(s);
    t.erase(unique(t.begin(),t.end()),t.end());
    if(t.size()==1u){
      cout<<n<<endl<<1<<endl;
      return 0;
    }
  }

  vector<vector<Int> > v(n+1);
  for(Int i=1;i<=n;i++)
    for(Int j=i+i;j<=n;j+=i)
      v[j].emplace_back(i);

  RollingHash  rh1(s);
  RollingHash2 rh2(s);
  auto check=[&](Int l,Int r)->Int{
    for(Int x:v[r-l])
      if(rh1.find(l,r-x)==rh1.find(l+x,r)&&
	 rh2.find(l,r-x)==rh2.find(l+x,r)) return 0;
    return 1;
  };
  
  if(check(0,n)){
    cout<<1<<endl<<1<<endl;
    return 0;
  }

  //assert(0);
  assert(check(0,n-1));
  cout<<2<<endl;
  
  Int ans=0;
  for(Int i=1;i<n;i++)
    ans+=check(0,i)&&check(i,n);
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 104112
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>

int main() {
	int m, f, r;
	char rank[5][2] = {"A", "B", "C", "D", "F"};
	int flug;
	while (1) {
		scanf("%d%d%d", &m, &f, &r);
		if (m + f + r == -3)break;
		if (m + f >= 80) flug = 0;
		else if (m + f >= 65) flug = 1;
		else if (m + f >= 50) flug = 2;
		else if (m + f >= 30 && r >= 50) flug = 2;
		else if (m + f >= 30 && r <= 50) flug = 3;
		else flug = 4;
                if(m==-1||f==-1) flug = 4;
		printf("%s\n", rank[flug]);
	}
	return 0;
}

Measured memory_bytes: 2560
def resolve():
    '''
    code here
    '''
    import collections
    import numpy as np
    H, W = [int(item) for item in input().split()]

    grid = [[item for item in input()] for _ in range(H)]
    dp = [[300 for _ in range(W+1)] for _ in range(H+1)]
    for i in range(H):
        for j in range(W):
            if i == 0 and j == 0:
                if grid[0][0] == '#':
                    dp[i+1][j+1] = 1
                else:
                    dp[i+1][j+1] = 0
            else:
                add_v = 0
                add_h = 0
                if grid[i][j] != grid[i][j-1]:
                    add_h = 1
        
                if grid[i][j] != grid[i-1][j]:
                    add_v = 1

                dp[i+1][j+1] = min(dp[i+1][j]+add_h, dp[i][j+1]+add_v)
    # print(dp)
    if grid[H-1][W-1] == '#':
        print(dp[H][W]//2+1)
    else:
        print(dp[H][W]//2)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 27320
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}

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

int n;
long long dp[10][10];
long long ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n;
}

void solve(){
    for(int i = 1; i <= n; i++){
        string t = to_string(i);
        ans += dp[t[0] - '0'][t.back() - '0'] * 2;
        dp[t.back() - '0'][t[0] - '0']++;
        if(t[0] == t.back())
            ans++;
    }
}

void out(){
    cout << ans;
}


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

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  if (b > a + w) {
    cout << b - (a + w) << endl;
  } else if (b + w < a) {
    cout << a - (b + w) << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> v(26);
    rep(i, 0, s.size()) {
        v[s[i] - 'a'].push_back(i);
    }
    ll ans = 0;
    int ite = -1;
    rep(i, 0, t.size()) {
        if (upper_bound(all(v[t[i] - 'a']), ite) - v[t[i] - 'a'].begin() < (int)v[t[i] - 'a'].size()) {
            ans += *upper_bound(all(v[t[i] - 'a']), ite) - ite;
            ite = *upper_bound(all(v[t[i] - 'a']), ite);
        } else {
            ans += ((int)s.size() - 1 - ite);
            ite = -1;
            if (upper_bound(all(v[t[i] - 'a']), ite) - v[t[i] - 'a'].begin() < (int)v[t[i] - 'a'].size()) {
                ans += *upper_bound(all(v[t[i] - 'a']), ite) + 1;
                ite = *upper_bound(all(v[t[i] - 'a']), ite);
            } else {
                cout << -1 << endl;
                return 0;
            }
        }
    }

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


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

int main(){
    char S[4];
    int i;
    int result=0;
    scanf("%s",&S);

    for(i=0;i<3;i++){
        if(S[i]==S[i+1]){
            result=1;
            break;
        }
    }

    if(result==0){
        printf("Good\n");
    }else{
        printf("Bad\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n;
    cin >> m;
    VI cnt(m);
    REP(i,0,n) {
        int k,a;
        cin >> k;
        REP(j,0,k) {
            cin >> a;
            cnt[a-1]++;
        }
    } 
    int ans = 0;
    REP(i,0,m) if (cnt[i] == n) ++ans;
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimization_level 3
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using P = pair<int,int>;
int main() {
   int H,W;cin>>H>>W;
   set<P> end_start;
   vector<P> walls;
   multiset<int> dist;
   rep(i,H){
      int A,B;cin>>A>>B;
      A--;B--;
      walls.push_back({A,B});
   }
   rep(i,W){
      end_start.insert({i,i});
      dist.insert(0);
   }
   rep(i,H){
      P wall=walls[i];
      auto l=end_start.lower_bound({wall.first,0});
      auto r=end_start.lower_bound({wall.second+1,0});
      P best={W,0};
      int most_right=0;
      vector<P> extr;
      for(;l!=r;l++){
         P now=*l;
         dist.extract((l->first)-(l->second));
         extr.push_back(now);
         if(now.second>=most_right){
            most_right=now.second;
            now.first=wall.second+1;
            best=now;
         }
      }
      for (auto &&j : extr) end_start.extract(j);
      if(best.first!=W){
         end_start.insert(best);
         dist.insert(best.first-best.second);
      }
      if(dist.empty())cout<<-1<<endl;
      else cout<<(*dist.begin()+i+1)<<endl;
   }
}

Measured memory_bytes: 23540
def rec(lst, left, right):
    if left == right:
        return 0
    if not 0 in lst[left:right]:
        m = min(lst[left:right])
        lst[left:right] = [x - m for x in lst[left:right]]
        return m + rec(lst, left, right)
    k = lst[left:right].index(0)
    return rec(lst, left, left + k) + rec(lst, left + k+1, right)


N = int(input())
lst = list(map(int, input().split()))
print(rec(lst, 0, len(lst)))

Measured memory_bytes: 3188
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    while 1:
        s=input()
        if s=="0":
            break
        else:
            print(sum(map(int,s)))
if __name__ == '__main__':
    main()


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a) {
		cout << k;
		return 0;
	}
	if (k <= a+b) {
		cout << a;
		return 0;
	}
	cout << a-(k-b-a);
	return 0;
}


Measured memory_bytes: 3612
n = gets.chomp.to_i
as = gets.chomp.split.map(&:to_i)

f = as.all? { |a| (a % 2 == 1) || (a % 2 == 0 && (a % 3 == 0 || a % 5 == 0)) }

puts f ? 'APPROVED' : 'DENIED'


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

int dat[5000*5001/2];
int conv(int y,int x){
    return y*(y+1)/2+x;
}

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

    for(int i=0;i<M;i++){
        int y,x,d;
        cin>>y>>x>>d;
        y--;x--;
        int idx=conv(y,x);
        dat[idx]=max(dat[idx],d+1);
    }

    for(int i=0;i<N-1;i++){
        for(int j=0;j<=i;j++){
            int idx=conv(i,j);
            int l=conv(i+1,j);
            int r=conv(i+1,j+1);
            dat[l]=max(dat[l],dat[idx]-1);
            dat[r]=max(dat[r],dat[idx]-1);
        }
    }

    int ans=0;
    for(int i=0;i<N*(N+1)/2;i++)if(dat[i])ans++;

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

Measured memory_bytes: 50000
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

long long gcd(long long a, long long b){
  return b == 0LL ? a : gcd(b, a % b);
}

int main(){
  ll k;
  cin>>k;
  ll ans = 0;
  rep(i,1,k+1){
    rep(j,1,k+1){
      rep(l,1,k+1){
        ans += gcd(i,gcd(j,l));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>

using namespace std;
using lli = long long int;

vector<lli> input(int N) { vector<lli> r(N); for (int i = 0; i < N; i++)cin >> r[i]; return r; }

int main() {
	lli N;
	cin >> N;
	vector<lli> h = input(N);
	vector<lli> dp(N + 10);
	for (int i = 0; i < N; i++)dp[i] = INT64_MAX;
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		if (i > 0) {
			dp[i] = min(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
		}
		if (i > 1) {
			dp[i] = min(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
		}
	}
	cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long

#define si(x) scanf("%d", &x)
#define sll(x) scanf("%lld", &x)

#define pi(x) printf("%d", x)

int main()
{
    ll a, b, c, d, mul = 1;

    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

    printf("%lld\n", max(a * c, max(a * d, max(b * c, b * d))));

    return 0;
}

Measured memory_bytes: 3828
class UF():
  def __init__(self, N):
    self._parent=[n for n in range(0, N)]
    self._size=[1] * N

  def find_root(self, x):
    if self._parent[x]==x:return x
    self._parent[x]=self.find_root(self._parent[x])
    return self._parent[x]

  def unite(self, x, y):
    gx=self.find_root(x)
    gy=self.find_root(y)
    if gx==gy:return

    if self._size[gx]<self._size[gy]:
      self._parent[gx]=gy
      self._size[gy]+=self._size[gx]
    else:
      self._parent[gy]=gx
      self._size[gx]+=self._size[gy]

  def size(self, x):
    return self._size[self.find_root(x)]

  def samegroup(self, x, y):
    return self.find_root(x)==self.find_root(y)

  def groupnum(self):
    N=len(self._parent)
    ans=0
    for i in range(N):
      if self.find_root(i)==i:
        ans+=1
    return ans

from collections import defaultdict
n,k,l=map(int,input().split())
UF1=UF(n)
for i in range(k):
  p,q=map(int,input().split())
  UF1.unite(p-1,q-1)
UF2=UF(n)
for i in range(l):
  r,s=map(int,input().split())
  UF2.unite(r-1,s-1)
d=defaultdict(int)
for i in range(n):
  d[UF1.find_root(i),UF2.find_root(i)]+=1
ans=[]
for i in range(n):
  ans.append(str(d[UF1.find_root(i),UF2.find_root(i)]))
print(' '.join(ans))

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

int N, Q;
const int INF = INT_MAX;
struct LazySegmentTree {
private:
    int n;
    vector<int> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, int x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    cin >> N >> Q;
    LazySegmentTree seg( vector<int>(N, INF) );
    for(int i=0; i<Q; i++) {
        int query; cin >> query;
        if(query == 0) {
            int s, t, x; cin >> s >> t >> x;
            seg.update(s, t+1, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << seg.find(s, t+1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5224