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

struct info{
    int y, x, t;
};

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

int main() {
    int t, n;
    while (cin >> t >> n, t | n) {
        vector<vector<bool> > used(200, vector<bool>(200, false));
        vector<vector<int> > w(200, vector<int>(200, 0));
        for (int i = 0; i < n; i++) {
            int y, x;
            cin >> y >> x;
            w[y + 100][x + 100] = -1;
        }
        int si, sj;
        cin >> si >> sj;
        queue<info> que;
        que.push((info){si + 100, sj + 100, 0});
        used[si + 100][sj + 100] = true;
        int ans = 1;
        while (!que.empty()) {
            info cur = que.front();
            que.pop();
            if(cur.t == t) continue;
            for (int i = 0; i < 6; i++) {
                int ni = cur.y + di[i];
                int nj = cur.x + dj[i];
                if(used[ni][nj] == false && w[ni][nj] != -1){
                    used[ni][nj] = true;
                    ans++;
                    que.push((info){ni, nj, cur.t + 1});
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18, mod = 1e9 + 7;

string s;
int n, dp[13][N];

int power(int a, int b, int p){
	int ret = 1;
	a %= p;
	while(b > 0){
		if(b % 2 == 1)
			ret = ret * a % p;
		b /= 2;
		a = a * a % p;
	}
	return ret;
}

int go(int id, int rem){
	if(id >= n)
		return rem == 5;

	int &ans = dp[rem][id];
	if(~ans)
		return ans;
	ans = 0;

	if(s[id] != '?'){
		int dig = s[id] - '0';
		int next_rem = rem + dig * power(10, id, 13);
		ans = (ans + go(id + 1, next_rem % 13)) % mod;
	}else{
		for(int i = 0; i < 10; i++){
			int next_rem = rem + i * power(10, id, 13);
			ans = (ans + go(id + 1, next_rem % 13)) % mod;
		}
	}
	return ans;
}

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

	memset(dp, -1, sizeof(dp));
	cin >> s;
	n = sz(s);
	reverse(s.begin(), s.end());
	cout << go(0, 0);
}


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

int main(){
  int N; cin >> N;
  int d[N];
  for (int i = 0; i < N; i++) cin >> d[i];
  set<int> values;
  for (int i = 0; i < N; i++){
    values.insert(d[i]);
  }
  cout << values.size() << endl;
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int l = s.length();
    for(int i=0; i<l; i++){
        s.pop_back();
        if(s.length()%2 == 1) continue;

        string s0, s1;
        s0 = s.substr(0, s.length()/2);
        s1 = s.substr(s.length()/2);

        // cout << s0 << endl;
        // cout << s1 << endl;
        if(s0 == s1){
            cout << s.length() << endl;
            break;
        }
        // cout << s0 << endl;
        // cout << s1 << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

const int IINF = 2002002002;
const ll LINF = 9009009009009009009LL;

//===

const ll mod = static_cast<int>(1e9 + 7);


int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	
	if (S[0] == 'W' || S[2 * N - 1] == 'W') {
		cout << 0 << endl;
		return 0;
	}

	Vi a(2 * N);
	a[0] = 1;
	for (int i = 1; i < 2 * N; ++i) {
		if (S[i - 1] != S[i]) {
			a[i] = a[i - 1];
		}
		else {
			a[i] = 1 - a[i - 1];
		}
	}

	ll ans = 1;
	ll num0 = 0;
	for (int i = 2 * N - 1; i >= 0; --i) {
		if (a[i] == 0) {
			++num0;
			num0 %= mod;
		}
		else {
			ans *= num0;
			ans %= mod;
			--num0;
		}
	}
	if (num0 != 0) {
		cout << 0 << endl;
	}
	else {
		ll fracN = 1;
		for (ll i = 1; i <= N; ++i) {
			fracN *= i;
			fracN %= mod;
		}

		ans *= fracN;
		ans %= mod;

		cout << ans << endl;
	}

}

Measured memory_bytes: 1412
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int a,b;
cin>>a>>b;
if(b==1) {cout<<0;return 0;}
for(int i=0;i<100;i++) {
    if(i*(a-1)>=(b-a)) {
        cout<<i+1;
        break;
    }
}
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 256
#EDPC_F
s=input()
t=input()
lens=len(s)
lent=len(t)
dp=[[0]*(lent+1) for _ in range(lens+1)]
for i in range(lens):
    for j in range(lent):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
i=lens
j=lent
ans=''
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    elif dp[i][j]==dp[i-1][j-1]+1:
        ans=s[i-1]+ans
        i-=1
        j-=1
print(ans)

Measured memory_bytes: 112220
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]
H = sorted(h, reverse=True)
delta_h = H[0]
for i in range(N-K+1):
  delta_hi = H[i]-H[i+K-1]
  if delta_h > delta_hi:
    delta_h = delta_hi
print(delta_h)

Measured memory_bytes: 8280
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
int main(){
	//freopen("in","r",stdin);
	int a=read(),b=read();
	int c=(a+b)/2;
	if(abs(a-c)==abs(b-c))
		printf("%d\n",c);
	else
		puts("IMPOSSIBLE");
	return 0;
}



Measured memory_bytes: 256
s = input()
a = [0]*3
for i in s:
  if i=="a":
    a[0] += 1
  elif i == "b":
    a[1] += 1
  elif i =="c":
    a[2] +=1
 
if a[0]==a[1]==a[2] ==1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9016
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	int arr[n+2];
	int l[n+2];
	int r[n+2];
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	int mx = INT_MIN;
	l[0] = 0;
	for(int i = 1;i<=n;i++)
	{
		l[i] = __gcd(l[i-1],arr[i]);
	}
	r[n+1] = 0;
	for(int i =n;i>=0;i--)
	{
		r[i] = __gcd(r[i+1],arr[i]);
	}
	int gcdm = 0;
	for(int i=1;i<=n;i++)
	{
		int g = __gcd(l[i-1],r[i+1]);
		gcdm = max(g,gcdm);
	}
	cout<<gcdm<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n;
    cin >> n;
    
    int ans = 0;

    rep(i, 1, n+1) {
        ans += i;
        if(ans >= n) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 384
//あらためて見るとこの問題全然わからない

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	int a[2][200000], b[2][200000];
	rep(i, N) a[0][i] = getint();
	rep(i, N) b[0][i] = getint();

	int kotae = 0;
	rep(i, 29) {
		int p = i & 1;

		int kazu[2] = {};
		rep(j, N) kazu[a[p][j] >> i & 1]++;
		kazu[1] += kazu[0];
		for (int j = N - 1; j >= 0; j--) a[!p][--kazu[a[p][j] >> i & 1]] = a[p][j];
		kazu[0] = 0;
		kazu[1] = 0;
		rep(j, N) kazu[b[p][j] >> i & 1]++;
		kazu[1] += kazu[0];
		for (int j = N - 1; j >= 0; j--) b[!p][--kazu[b[p][j] >> i & 1]] = b[p][j];

		int kari = N & 1;
		int k = N;
		int d = (1 << i + 1) - 1;
		int d2 = 1 << i;
		rep(j, N) {
			while (k > 0 && (a[!p][j] & d) + (b[!p][k - 1] & d) >= d2) {
				k--;
			}

			kari ^= k & 1;
		}
		k = N;
		rep(j, N) {
			while (k > 0 && (a[!p][j] & d) + (b[!p][k - 1] & d) >= d2 * 2) {
				k--;
			}
			kari ^= k & 1;
		}
		k = N;
		rep(j, N) {
			while (k > 0 && (a[!p][j] & d) + (b[!p][k - 1] & d) >= d2 * 3) {
				k--;
			}
			kari ^= k & 1;
		}
		kotae += kari << i;
	}
	printf("%d", kotae);

	Would you please return 0;
}

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

int n,k;
string t;

bool uruu(int y){
  return y%400==0 || y%100!=0 && y%4==0;
}

int main() {
  cin >> t;
  int n=0,w=0,s=0,e=0;
  for(auto c:t){
    if(c=='N') n++;
    if(c=='W') w++;
    if(c=='S') s++;
    if(c=='E') e++;
   }
   if((n+s==0 || n>0&&s>0) && (w+e==0 || w>0&&e>0))
   cout << "Yes" << endl;
   else 
   cout << "No" << endl;
}

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

using namespace std;

bool inString(string s,string match_string){
	for(int unsigned i = 0;i<s.size()-match_string.size();i++){
		if(s.substr(i,match_string.size()) == match_string){
			return true;
		}
	}
	return false;
}

int main(){
	string s;
	int n;
	cin >> s;
	cin >> n;
	int ans = 0;
	for(int i=0;i<n;i++){
		string a;
		cin >> a;
		ans+=inString(a + a,s);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3108
n,m,L=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
q=int(input())
ql=[list(map(int,input().split())) for i in range(q)]
distance=[[10**18]*n for i in range(n)]
for i in range(m):
  if l[i][2]<=L:
    distance[l[i][0]-1][l[i][1]-1]=l[i][2]
    distance[l[i][1]-1][l[i][0]-1]=l[i][2]
for i in range(n):
  for j in range(n):
    for k in range(n):
      distance[j][k]=min(distance[j][k],distance[j][i]+distance[i][k])
 
distance2=[[10**18]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    if distance[i][j]<=L:
      distance2[i][j]=1
      distance2[j][i]=1
for i in range(n):
  for j in range(n):
    for k in range(n):
      distance2[j][k]=min(distance2[j][k],distance2[j][i]+distance2[i][k])
 
for i in range(q):
  if distance2[ql[i][0]-1][ql[i][1]-1]>=10**18:
    print(-1)
  else:
    print(distance2[ql[i][0]-1][ql[i][1]-1]-1)

Measured memory_bytes: 82520
/* kop Chy_Chy*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll , ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define si(x)   scanf("%d", &x)
#define sl(x)   scanf("%lld", &x)
#define pi(x)   printf("%d\n", x)
#define pl(x)   printf("%lld\n", x)
#define deb(x)  cout<< #x << " = " << x << endl // debugging kop 
#define mp      make_pair
#define pb      push_back
#define MOD     1000000007
#define PI      acos(-1)
#define ff      first
#define ss      second
#define newline printf("\n")
ll binpow(ll a, ll b); // binary exponentiation kop
void prime_factorization(ll n, vll &prime_factors); // prime factorization kop
ll gcd(ll a, ll b); // greatest common divisor kop. Use LONG LONG
void speedup() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

int main(){
    speedup();
    int t = 1;
    // cin>> t;
    while(t--){
        // khela final Mamooo
        int x; cin>> x;
        if(x >= 30) cout<< "Yes\n";
        else cout<< "No\n";
        
        
        
    }
    // kop kop return 
    return 0;
}


// kop kop functions:
ll binpow(ll a, ll b){
    a = a % MOD; ll res = 1;
    while(b > 0){
        if(b & 1) res *= a % MOD;
        a = a* a % MOD;b = b >> 1;}
    return res;
}
/*---------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
/*---------------------------------------------------------------------------------------------------------------*/
void prime_factorization(ll n, vll &prime_factors){
    // first two step taking care of composite number
    // taking care of 2
    while(n%2 == 0){
        prime_factors.pb(2);
        n = n / 2;
    }
    // now n must be odd. And the remaining prime divisors are odd. so we start from 3 and increamenting 2
    for(ll i = 3; i <= sqrt(n); i = i + 2){
        while(n%i == 0){
            prime_factors.pb(i);
            n = n / i;
        }
    }
    // now we are taking care of  n is prime number and greater than 2
    if(n > 2){
        prime_factors.pb(n);
    }
}
/*---------------------------------------------------------------------------------------------------------------*/














Measured memory_bytes: 3696
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

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

int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);


    string s;
    cin >> s;

    if(s == "ABC"){
        cout << "ARC"  << "\n"; 
    }else{
        cout << "ABC"  << "\n"; 

    }

    return 0;



}


Measured memory_bytes: 3608
use proconio::input;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::vec::Vec;

fn main() {
    input! {
        n: i32,
        mut a: [i32; n],
    }
    a.sort();
    let mut a_count = BTreeMap::new();
    for &v in a.iter() {
        *a_count.entry(v).or_insert(0) += 1;
    }
    let mut removed = BTreeSet::new();
    let mut ans = 0;
    for &v in a.iter() {
        if !removed.contains(&v) && a_count[&v] == 1 {
            ans += 1;
        }
        if removed.contains(&v) {
            continue;
        }
        let mut x = v;
        while x <= 1_000_000 {
            removed.insert(x);
            x += v;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 20812
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))
#define cond(a,b,c) ((a)?(b):(c))
using ll=long long;
using namespace std;

int A[100*1000+100];

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

    int N; cin >> N;
    rep(i, 1, N) cin >> A[i];
    multiset<int> s;
    s.insert(A[1]);
    int ans = 1;

    rep(i, 2, N) {
        auto itlow = s.lower_bound(A[i]);
        while((itlow == s.end() or *itlow >= A[i]) and itlow!=s.begin()) itlow--;
        if (*itlow < A[i]) { s.erase(itlow); } else { ans++; }
        s.insert(A[i]);
    }

    END(ans);
}


Measured memory_bytes: 5376
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 0; int[] v = new int[n]; int[] c = new int[n];
		for(int i = 0; i < n; i++) v[i] = Integer.parseInt(sc.next());
		for(int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			if(a < v[i]) sum += v[i] - a;
		}
		System.out.println(sum);
		sc.close();
	}
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> v(n);
    rep(i,n){
        int pi; cin >> pi; pi--;
        p[i] = pi;
    }
    rep(i,n){
        int qi; cin >> qi; qi--;
        q[i] = qi;
    }
    rep(i,n) v[i] = i;

    int cnt = 0;
    int a, b;
    do{
        if(p == v) a = cnt;
        if(q == v) b = cnt;
        cnt++;
    }while(next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pw 1000000000
#define pi 3.141592653589793238
 
int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       cout<<2*pi*n;
       //string s;
       /*f(i,0,n)
       cin>>a[i];
       sort(a,a+n);*/
       cout<<endl;
    }
    return 0;
}

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

const long long MOD = 1e9 + 7;

long long pow_mod(int a, int n)
{
    if(!n)
        return 1;
    long long res = pow_mod(a, n / 2);
    res = res * res;
    res %= MOD;
    if(n % 2) 
        res *= a;
    res %= MOD;
    return res;
}

int main()
{
    int n;
    while(cin >> n)
    {
        vector<int> v(n + 1), cnt(n + 1);
        for(int i = 1; i <= n; i ++)
        {
            cin >> v[i];
            cnt[abs((i - 1) - (n - i))] ++;
        }
        bool ok = true;
        for(int i = 1; i <= n;i ++)
        {
            if(!cnt[v[i]])
            {
                ok = false;
                break;
            }
            cnt[v[i]] --;
        }
        if(!ok)
            cout << 0 << endl;
        else
        cout << pow_mod(2, n / 2) << endl;
    }
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール

// 処理内容
int main() {

    ll n; cin >> n;
    
    vector<vector<ll>> ans(n, vector<ll>(n, 0));

    REP(i, n) REP(j, n) if(i < j) {
        REP(k, 32) {
            if (i % (1LL << k) != j % (1LL << k)) {
                ans[i][j] = k;
                break;
            }
        }
    }
    RANGE(i, 0, n-2) RANGE(j, i+1, n-1) {
        cout << ans[i][j] << " \n"[j==n-1];
    }
    
}

Measured memory_bytes: 2432
d,g = map(int, input().split())
p = [0] * d
c = [0] * d
for i in range(d):
    p[i], c[i] = map(float, input().split())
    
ans = 0

    
for i in range(2**d):
    score = 0
    count = 0
    for j in range(d):
        if (i >> j) & 1:
            score += p[j]*100*(j+1) + c[j]
            count += p[j]
            
    if g > score:
        for k in range(d-1,-1,-1):
            if (i >> k) & 1 == 0 :
                if (g - score) <= p[k]*100*(k+1):
                    count += (g - score -1)//((k+1)*100) +1
                    break
                else:
                    count = 1145141919
                    break
                    
    if ans == 0 or count<ans:
        ans = count

print(int(ans))

Measured memory_bytes: 3064
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int M;
LL getsum(LL first, LL last, LL tot, LL mod)
{
	mod *= 2;
	return (first + last) % mod * (tot % mod) % mod / 2;
}
LL powmod(LL a, LL b, LL mod = INF)
{
	LL ret = 1;
	while (b)
	{
		if (b & 1) ret = ret * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return ret;
}
class Matrix
{
	LL a[3][3];
	int sz;
public:

	int size()
	{
		return sz;
	}
	Matrix(int n = 0)
	{
		sz = n;
		MEM(a, 0);
	}
	LL* operator [](int i)
	{
		return a[i];
	}
	Matrix ones(int n)
	{
		Matrix ret(n);
		for (int i = 0; i < n; i++) ret[i][i] = 1;
		return ret;
	}
	void init(LL A, LL B, LL C, int n = 3)
	{
		sz = n;
		MEM(a, 0);
		a[0][0] = A, a[0][1] = 1, a[0][2] = 0; // cur
		a[1][0] = 0, a[1][1] = 1, a[1][2] = C; // B
		a[2][0] = 0, a[2][1] = 0, a[2][2] = 1; // 1
	}
	Matrix operator *(Matrix& m)
	{
		int n = m.size();
		Matrix ret(n);
		for (int k = 0; k < n; k++)
		{
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					ret[i][j] = (ret[i][j] + a[i][k] * m[k][j]) % M;
				}
			}
		}
		return ret;
	}
	Matrix operator +(Matrix& m)
	{
		int n = m.size();
		Matrix ret(n);
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				ret[i][j] = a[i][j] + m[i][j];
				if (ret[i][j] >= M) ret[i][j] -= M;
			}
		}
		return ret;
	}
	Matrix operator ^(LL b)
	{
		Matrix ret = ones(sz);
		Matrix A = *this;
		while (b)
		{
			if (b & 1) ret = ret * A;
			A = A * A;
			b >>= 1;
		}
		return ret;
	}
} B;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	LL a, b;
	LL L;
	cin >> L >> a >> b >> M;
	LL l = 1, r = 10;
	int len = 1;
	LL cur = a % M;
	a = a + b;
	L--;
	while (a >= r) r *= 10, len++;
	l = r / 10;
	while (l <= a)
	{
		LL o = min((r - 1 - a) / b, L - 1);

		LL firsta = a;
		LL lasta = a + b * o;
		B.init(l % M * 10 % M, firsta % M, b % M);
		B = B ^ (o + 1);
		cur = (cur * B[0][0] % M + firsta % M * B[0][1] % M + B[0][2]) % M;
		L -= o + 1;
		a = lasta + b;
		l *= 10, r *= 10;
		len++;
		if (L == 0) break;
	}
	cout << cur << endl;
	return 0;
}

Measured memory_bytes: 256
//IIT Kanpur FacelessMen India
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

vector<int> arr;
int main(){
  // freopen("product.in","r",stdin);
  // freopen("product.out","w",stdout);
  int n; scanf("%d",&n);
  REP(i,3*n){
    int x; scanf("%d",&x); arr.pb(x);
  }
  sort(all(arr));
  reverse(all(arr));
  ll ans = 0;
  REP(i,n){
    ans+=arr[i*2+1];
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 2420
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

fn main() {
    scan!(a; char);

    let res = match a {
        'A' ..= 'Z' => 'A',
        _ => 'a',
    };

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


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

int main(void) {
	char c; cin >> c;
	printf("%c\n",c+1);
}




Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		long[] f = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		for (int i = 0; i < n; i++) {
			f[i] = sc.nextLong();
		}
		Arrays.sort(a);
		Arrays.sort(f);
		long ok = a[n - 1] * f[n - 1];
		long ng = -1;
		while (Math.abs(ok - ng) > 1) {
			long mid = (ok + ng) / 2;
			long tmpk = k;
			for (int i = 0; i < n; i++) {
				tmpk -= Math.max(a[i] - mid / f[n - 1 - i], 0);
			}
			if (tmpk < 0) {
				ng = mid;
			} else {
				ok = mid;
			}
		}
		System.out.println(ok);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int H, W, N;
    cin >> H >> W;
    cin >> N;
    vector<int> a(N, 0);
    rep(i, N) cin >> a[i];
    vector<vector<int>> res;
    bool odd = true;
    int num = 1;
    int cnt = 1;
    rep(i, H)
    {
        vector<int> row;
        rep(j, W)
        {
            row.push_back(num);
            cnt++;
            if (a[num - 1] < cnt)
            {
                num++;
                cnt = 1;
            }
        }
        if (i % 2 == 1)
        {
            reverse(row.begin(), row.end());
        }
        res.push_back(row);
    }
    rep(i, H)
    {
        rep(j, W)
        {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n, vector<int> & u){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            if(u[i] == 0){
                u[i] = 1;
                dfs(A, B, i, n, u);
            }
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    vector<int> u(n, 0);
    u[0] = 1;
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n, u);
    }
    

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != 2) cout << B[i][j] << " ";
            else cout << B[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
#include<cstdio>
#define mod 1000000007
using namespace std;
long h,w,a,b,g[100000],kai[200001],inv[200001];

long calc(long x){
    long two[32],ans,t[32],y=mod-2;
    two[0]=1;
    ans=t[0]=x;
    for(int i=1;i<32;i++){
        two[i]=2*two[i-1];
        t[i]=t[i-1]*t[i-1];
        t[i]%=mod;
        if(y&two[i]){
            ans*=t[i];
            ans%=mod;
        }
    }
    return ans;
}
int main(){
    long ans=0;
    scanf("%ld %ld %ld %ld",&h,&w,&a,&b);
    kai[0]=kai[1]=inv[0]=inv[1]=1;
    for(long i=2;i<=h+w;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    inv[h+w]=calc(kai[h+w]);
    for(long i=h+w-1;i>1;i--){
        inv[i]=inv[i+1]*(i+1L)%mod;
    }
    for(int i=b;i<w;i++){
        g[i]=kai[i+h-a-1]*inv[i];
        g[i]%=mod;
        g[i]*=inv[h-a-1];
        g[i]%=mod;
        g[i]*=kai[a-1+w-1-i];
        g[i]%=mod;
        g[i]*=inv[w-1-i];
        g[i]%=mod;
        g[i]*=inv[a-1];
        g[i]%=mod;
        ans+=g[i];
        ans%=mod;
    }
    printf("%ld\n",ans);
}

Measured memory_bytes: 4096
import math
from functools import reduce
ans = 0
k = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            ans += gcd(i,j,m)

print(ans)
            

Measured memory_bytes: 69684
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,K = inpl()
S = list(map(int,list(str(input()))))
ss = []

cnt = 0
flag1 = (S[0] == 1)
if S[0] == 0:
    ss.append(0)

for s in S:
    if flag1 and s == 0:
        ss.append(cnt)
        cnt = 1
        flag1 = False
    elif not flag1 and s==1:
        ss.append(cnt)
        cnt = 1
        flag1 = True
    else:
        cnt += 1

ss.append(cnt)
if S[-1] == 0:
    ss.append(0)

#print(ss)

l = 0
r = 2*K
tmp = sum(ss[l:r+1])
ans = tmp
while True:
    l += 2
    r += 2
    if r >= len(ss):
        break
    tmp -= ss[l-2] + ss[l-1]
    tmp += ss[r-1] + ss[r]
    ans = max(ans,tmp)

print(ans)


Measured memory_bytes: 6468
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int N, K;
  cin >> N >> K;
  int ans = N - K + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader(); 
        long A, B, C, D;
        {long[] a = r.ll(); A = a[0]; B = a[1]; C = a[2]; D = a[3];}
        long all = B-A+1;
        long c = B/C-(A-1)/C;
        long d = B/D-(A-1)/D;
        long E = lcm(C, D);
        long cd = B/E-(A-1)/E;
        println(all-c-d+cd);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static long lcm(long... ll){
        int N = ll.length;   
        long gcd = gcd(ll);
        long lcm = ll[0];
        for(int i = 1; i < N; i++)
            lcm = lcm/gcd(lcm, ll[i])*ll[i];        
       return lcm;
    }
    static long gcd(long... ll){
        int N = ll.length;
        long gcd = ll[0];
        for(int i = 1; i < N; i++){
            long a = gcd;
            long b = ll[i];
            if(b < a){
                long c = a;
                a = b;
                b = c;
            }
            long r;
            while((r=b%a)>0){
                b = a;
                a = r;
            }   
            gcd = a;
        }
        return gcd;
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<bool>>g(h, vector<bool>(w));
  for(int i=0; i<h; i++)for(int j=0; j<w; j++){
    char t;
    cin >> t;
    g[i][j] = (t=='#');
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(i==0 || (i!=h-1 && j%2==0) || g[i][j])cout << '#';
      else cout << '.';
    }
    cout << endl;
  }
  cout << endl;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(i==h-1 || (i!=0 && j%2==1) || g[i][j])cout << '#';
      else cout << '.';
    }
    cout << endl;
  }
  return 0;
}

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

bool a[20];
int ans = 1000000;
int d;
long long g;
int p[20], c[20];

void ff(void){
  int count = 0;
  int score = 0;
  for(int i = 1; i <= d; i++){
    if(a[i]){
      count += p[i];
      score += 100 * i * p[i] + c[i];
    }
  }
  if(score < g){
    for(int i = d; i >= 1; i--){
      if(!a[i]){
	if(score >= g) break;
	for(int j = 0; j < p[i]; j++){
	  count++;
	  score += 100 * i;
	  if(score >= g) break;
	}
      }
    }
  }
  ans = min(ans, count);
}

void f(int p, int d){
  if(p == d + 1) {
    ff();
    return;
  }
  a[p] = false;
  f(p + 1, d);
  a[p] = true;
  f(p + 1, d);
}

int main(void){
  cin >> d >> g;
  for(int i = 1; i <= d; i++) cin >> p[i] >> c[i];
  f(1, d);
  cout << ans << endl;
  return 0;
}


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


int main(){
  int S,W;
  cin >> S >>W;
  if (W >= S){ cout << "unsafe";}
  else { cout <<"safe";}
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


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

#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define ull unsigned long long int
#define lli long long int
#define li long int

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%ld",&n)
#define sll(n) scanf("%lld",&n)

#define pi(n) printf("%d",n)
#define pl(n) printf("%ld",n)
#define pll(n) printf("%lld",n)

using namespace std;

const int MAX=1e5+5;

bool is(int start, string S, string T) {
    int N = T.length();
    bool flag = 1;
    for(int i=0; i<N; i++) {
        if(S[start+i] != T[i]) {
            flag = 0; break;
        }
    }
    return flag;
}

int main() {
    // freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    string tmp,S,T;
    cin >> tmp >> T;
    S = tmp + tmp;

    int N = T.length(); bool flag = 0;
    for(int i=0;i<=N; i++) {
        flag = is(i,S,T);
        if(flag)
            break;
    }

    if(flag) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge{ int to, time, cost; };
const double esp = 1e-9;
const int inf = (int)1e+9;

std::string str;
std::string::iterator it;
ll mod;
bool flg = false;

ll modPow(ll x, ll y){
	if (y == 0)return 1;
	if (y & 1)return x * modPow(x, y - 1) % mod;
	else return modPow(x * x % mod, y / 2) % mod;
}

ll number(){
	ll ret = 0;
	while (isdigit(*it)){
		ret *= 10;
		ret += (*it - '0');
		++it;
	}
	return ret;
}

ll expression();

ll factor(){
	ll ret;
	if (*it == '('){
		++it;
		ret = expression();
		++it;
		return ret;
	}
	else ret = number();
	return ret;
}

ll term(){
	ll ret = factor();
	while (true){
		if (*it == '*'){
			++it;
			ret = (ret * factor()) % mod;
		}
		else if (*it == '/'){
			++it;
			ll d = factor();
			if (d == 0){
				flg = true; 
				return 0;
			}
			ret = (ret * modPow(d, mod - 2)) % mod;
		}
		else break;
	}
	return ret;
}

ll expression(){
	ll ret = term();
	while (true){
		if (*it == '+'){
			++it;
			ret = (ret + term()) % mod;
		}
		else if (*it == '-'){
			++it;
			ret = (ret - term()) % mod;
			ret += (ret < 0 ? mod : 0);
		}
		else break;
	}
	return ret;
}

int main(){
	while (true){
		std::getline(std::cin, str);
		if (str == "0:")break;
		while (str.find(' ') != std::string::npos)str.erase(str.find(' '), 1);
		mod = 0;
		flg = false;
		while (isdigit(str[0])){
			mod *= 10;
			mod += (str[0]) - '0';
			str.erase(0, 1);
		}
		str.erase(0, 1);
		str += " = ";
		it = str.begin();
		ll ans = expression();
		if (flg)std::cout << "NG" << std::endl;
		else std::cout << str << ans << " (mod " << mod << ")" << std::endl;
	}
	return 0;
}

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


int main(){
    string s;
    cin>>s;
    int g=0,p=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='g') g++;
        else p++;
    }
    cout<<s.size()/2-p<<endl;
}

Measured memory_bytes: 512
(let* ((w (concatenate 'list (read-line)))
       (lst (remove-duplicates (loop for i in w
                                     collect (cons i (count i w)))
                               :test #'equal)))

  (format t "~A~%"
          (if
            (every #'evenp (mapcar #'cdr lst))
            "Yes"
            "No")))



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    vector<vector<bool>> a(4,vector<bool> (14,false));
    rep(i,n){
        char c;
        cin >> c;
        int t;
        cin >> t;
        if(c == 'S')a[0][t] = true;
        if(c == 'H')a[1][t] = true;
        if(c == 'C')a[2][t] = true;
        if(c == 'D')a[3][t] = true;
    

    }
    rep(i,4){
            for(int j =1; j< 14; j++){
                if(!a[i][j]){
                    char ans;
                    if(i == 0) ans = 'S';
                    if(i == 1) ans = 'H';
                    if(i == 2) ans = 'C';
                    if(i == 3) ans = 'D';
                    cout << ans << " " << j << endl;
                }
            }
        }
    return 0;
}


Measured memory_bytes: 3092