akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
int INF=pow(10,9);
mat d;
//頂点数
int V;
int ans=INF;
void warshall_floyd(){
    for(int k=1;k<=V;k++){
        for(int i=1;i<=V;i++){
            for(int j=1;j<=V;j++)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
    }
}
void shortest_pass(int from,set<int> S,int sum){
    if(S.empty()){
        ans=min(ans,sum);
        return;
    }
    for(auto itr=S.begin();itr!=S.end();itr++){
        set<int> T=S;
        int s=sum;
        s+=d[from][*itr];
        T.erase(*itr);
        shortest_pass(*itr,T,s);
    }
    return;
}

int main(){
    d.resize(210,vec(210,INF));
    cin>>V;
    int M,R;cin>>M>>R;
    int r[10];
    set<int> S;
    for(int i=0;i<R;i++){
        cin>>r[i];
        S.insert(r[i]);
    }
    for(int i=1;i<=V;i++)d[i][i]=0;
    int a,b,c;
    for(int i=0;i<M;i++){
        cin>>a>>b>>c;
        d[a][b]=d[b][a]=c;
    }
    warshall_floyd();
    for(int i=0;i<R;i++)
        shortest_pass(r[i],S,0);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int row, col;
  cin >> row >> col;
  bool del = true; 
  
  vector<vector<char>> grid(row, vector<char>(col));
  
  for (int i = 0; i < row; i++) {
    for(int j = 0; j < col; j++) {
      cin >> grid.at(i).at(j);
      if(grid.at(i).at(j) == '#') del = false;
    }
    if(del){
      i--;
      row--;
    }
  del = true;
  }
  
  for(int j = 0; j < col; j++) {
    for(int i = 0; i < row; i++) {
      if(grid.at(i).at(j) == '#') del = false;
    }
    if(del){
      for(int k = j; k < col; k++){
        for(int l = 0; l < row; l++) {
          if(k == col - 1) grid.at(l).at(k) = '\0';
          else grid.at(l).at(k) = grid.at(l).at(k+1);
        }
      }
      j--;
      col--;
    }
    del = true;
  }
  
      
  for (int i = 0; i < row; i++) {
    for(int j = 0; j < col; j++) {
      cout << grid.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
  s.append(input())
     
ab = 0
ab_ = 0
a = 0
b = 0
for i in s:
  ab += i.count("AB")
  if i[0] == "B" and i[-1] == "A":
    ab_ += 1
  if i[0] == "B":
    b += 1
  if i[-1] == "A":
    a += 1
if ab_ == a and ab_ == b and not ab_ == 0:
  print(ab+ab_-1)
else:
  print(ab+min([a,b]))

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

int main() {
  string s;
  cin >> s;
  cout << s.substr(0, 3);
}


Measured memory_bytes: 3612
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  def nextInt() = sc.next.toInt

  def swap(x: Int, xs: (List[Int], Int)) = {
    val (lst, cnt) = xs
    lst match {
      case List() => (List(x), cnt)
      case y :: ys =>
        if (x > y) (y :: x :: ys, cnt + 1)
        else (x :: lst, cnt)
    }
  }

  def bubble1(xs: List[Int]): (List[Int], Int) = xs match {
    case List()   => (List(), 0)
    case x :: xs1 => swap(x, bubble1(xs1))
  }

  def bubbleSort(xs: List[Int], cnt: Int): (List[Int], Int) = {
    val (lst, n) = bubble1(xs)
    if (n == 0)
      (lst, cnt)
    else
      bubbleSort(lst, cnt + n)
  }

  val n = nextInt
  val xs = List.fill(n)(nextInt)

  val (lst, cnt) = bubbleSort(xs, 0)
  println(lst.mkString(" "))
  println(cnt)
}



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

const int INF = 2147483647;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
vector<ll> prime_factorize(ll n){
    vector<ll> res;
    for(ll i=2;i*i<=n;i++){
	if(n%i != 0) continue;
	ll ex = 0;
	while(n%i == 0){
	    n /= i;
	    ex++;
	}
	res.push_back(ex);
    }
    if(n != 1) res.push_back(1);

    return res;
}
int main(){
    ll n;cin >> n;
    if(n==1){
	cout << 0 << endl;
	return 0;
    }
    vector<ll> a;
    a = prime_factorize(n);
    int ans = 0;
    for(int i=0;i<a.size();i++){
	int s = 0;
	for(int j=1;j<100;j++){
	   s += j;
	   if(a[i]<s) break;
	   ans++;
	}
    }
    cout << ans << endl; 

    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define N 200000 + 5

int n, q, Val[N];
vector<int> Vec[N];

void dfs(int z, int fa)
{
	Val[z] += Val[fa];
	for (int d : Vec[z])
		if (d != fa)
			dfs(d, z);
}

int main()
{
	scanf("%d%d", &n, &q);
	for (int i = 1, u, v; i < n; i ++)
	{
		scanf("%d%d", &u, &v);
		Vec[u].push_back(v);
		Vec[v].push_back(u);
	}
	for (int i = 1, p, x; i <= q; i ++)
	{
		scanf("%d%d", &p, &x);
		Val[p] += x;
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i ++)
		printf("%d%c", Val[i], i == n ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 23424
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i,n,cnt=0;
    string s;
    cin >> s;
    if(s.length()%2==0){
        n = s.length()/2;
    }
    else{
        n=(s.length()-1)/2;
    }
    for(i=0;i<n;i++){
        if(s[i]!=s[s.length()-1-i]){
            cnt++;
        }
    }
    cout <<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,e;
vector<vector<int> > g,g2;
vector<pair<int,int> > sol;
vector<bool> vis;
set<pair<int,int> > evis;
void DFS(int u,int p){
	vis[u]=true;
	for(auto &v:g[u])
		if(!vis[v]){
			g2[u].push_back(v);
			DFS(v,u);
		}else if(v!=p && evis.insert({min(u,v),max(u,v)}).second)
			sol.push_back({u,v});
}
vector<int> d;
bool calc(int u,int p){
	if(g[u].empty())
		return d[u];
	bool ret=d[u];
	for(auto &v:g[u])
		if(v!=p){
			bool cur=calc(v,u);
			if(cur)
				sol.push_back({v,u});
			else
				sol.push_back({u,v});
			ret^=cur;
		}
	return ret;
}
int main() {
	scanf("%d%d",&n,&e);
	g.resize(n);
	g2.resize(n);
	for(int i=0,a,b;i<e;++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vis.resize(n);
	DFS(0,-1);
	d.resize(n);
	for(auto &x:sol)
		d[x.first]^=1;
	g.swap(g2);
	int sum=0;
	for(int i=0;i<n;++i){
		d[i]^=g[i].size()&1;
		sum+=d[i];
	}
	if(sum&1){
		puts("-1");
		return 0;
	}
	calc(0,-1);
	for(auto &x:sol)
		printf("%d %d\n",x.first+1,x.second+1);
	return 0;
}

Measured memory_bytes: 23032
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n, m;
vector<int>a, b;
bool graph[55][55];
vector<bool> close;
int ans = 0;
/**********************************************/

void dfs(int cur_p){
    close[cur_p] = true;

    REP(i, n){
        if(graph[cur_p][i+1] == false) continue;
        if(close[i+1] == true) continue;
        dfs(i+1);
    }
}

int main(){
    cin >> n >> m;
    a.resize(m+5); b.resize(m+5);
    close.resize(n+5);
    REP(i, m) cin >> a[i] >> b[i];
    
    REP(i, 55){
        REP(j, 55){
            graph[i][j] = false;
            graph[j][i] = false;
        }
    }
    REP(i, m){
        graph[a[i]][b[i]] = true;
        graph[b[i]][a[i]] = true;
    }
    REP(i, m){
        graph[a[i]][b[i]] = false;
        graph[b[i]][a[i]] = false;
        
        REP(j, n) close[j+1] = false;

        dfs(1);    
        bool bridge = false;
        REP(j, n){
            if(close[j+1] == false) bridge = true;
        }
        
        if(bridge) ans++;

        graph[a[i]][b[i]] = true;
        graph[b[i]][a[i]] = true;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
l = [0]* n
for a_ in a:
    l[a_] += 1
mod = 10 ** 9 + 7
if n % 2 == 1:
    if l[0] == 1 and l[2::2] == [2] * (n // 2):
        print(2 ** (n // 2) % mod)
    else:
        print(0)
else:
    if l[1::2] == [2] * (n // 2):
        print(2 ** (n // 2) % mod)
    else:
        print(0)


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

int main() {
  ll a, b, c; cin >> a >> b >> c;
  if (c-a-b>0 && (c-a-b)*(c-a-b) > 4*a*b) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


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



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

long long Lcm(long a, long b)
{
	long long g = Gcd(a, b);
	return a / g*b;
}

int main() {
	int n;
	cin >> n;
	vector<long long> t(n);
	REP(i, n) {
		cin >> t[i];
	}

	long long L=t[0];
	REP(i, n) {
		L = Lcm(L, t[i]);
	}

	ANS(L);

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        ll ans=INF;
        for(ll z=0; z*z*z<=n; z++){
            for(ll y=0; y*y<=n; y++){
                ll x = n - z*z*z - y*y;

                if(0 <= x){
                    chmin(ans, x + y + z);
                }
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3068
/**
 *     author: qodjf
 *     created: 04.22.2020 01:33:19
 */
#include <bits/stdc++.h>
using namespace std;

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

  int N, x;
  cin >> N >> x;
  if (x == 1 || x == 2 * N - 1) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  vector<int> ans(2 * N);
  int l = 2 * N;
  for (int i = 1; i < l; i++) {
    ans[i] = i;
  }
  swap(ans[N], ans[x]);
  swap(ans[N - 1], ans[1]);
  swap(ans[N + 1], ans[2 * N - 1]);
  if (N - 2 >= 0 && x != 2 * N - 2) {
    swap(ans[N - 2], ans[2 * N - 2]);
  }
  for (int i = 1; i < l; i++) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 2304
s = input().split()
l = []

for i in s:
    if i == '+':
        a = l.pop()
        b = l.pop()
        l.append(a+b)
    elif i == '-':
        b = l.pop()
        a = l.pop()
        l.append(a-b)
    elif i == '*':
        a = l.pop()
        b = l.pop()
        l.append(a*b)
    else:
        l.append(int(i))

for j in l:
    print(j)


Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;


int main(void) {

  vector<long long int> l(100, 0);
  l[0] = 2;
  l[1] = 1;
  for(int i=2; i<87; i++){
    l[i] = l[i-1] + l[i-2];
  }

  int n; cin >> n;
  cout << l[n] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define INF (int)1e9+1
#define INFLL (int)1e18+1
#define sz(bb) (int)bb.size()
#define all(qq) qq.begin(), qq.end() 
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
const double PI=acos(-1);
// #define int unsigned long long int//used when x<=2^64-1 && x>0
#define int long long//used when x<=2^63-1
//bool cmp if returns true it keeps 1st as first else swaps
typedef long long  ll;


void solve()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    int dp[n+1][n+1];
    memset(dp, 0, sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        dp[1][i]=1;
    }
    for(int i=1;i<=n;i++)
        dp[1][i]+=dp[1][i-1];
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(str[i-2]=='<')
            {
                dp[i][j]=dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=(dp[i-1][i-1]-dp[i-1][j-1]+mod)%mod;
            }
        }
        for(int j=2;j<=n;j++)
        {
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][n]<<"\n";
}
int32_t main()
{
    IOS;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 73944
#include <iostream>

using namespace std;

int main() {
    string s; cin >> s;
    int n = s.size();
    bool firstState = true, secondState = true, thirdState = true;
    
    for (int i=0; i<n/2+1; i++) 
        if (s[i] != s[n-i-1]) {
            firstState = false;
            break;
        }
    
    int m = (n-1)/2;
    for (int i=0; i<m/2+1; i++) 
        if (s[i] != s[m-i-1]) {
            secondState = false;
            break;
        }
    
    m = (n+3)/2;
    for (int i=m; i<(n-m)/2+1; i++)
        if (s[i] != s[n-i-1]) {
            thirdState = false;
            break;
        }
    
    if (firstState && secondState && thirdState) cout << "Yes";
    else cout << "No";
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b,x,y;
	
	scanf("%d%d", &a, &b);
	
	x = a * b;
	y = 2 * (a + b);
	
	printf("%d %d\n", x, y);
	
	return 0;
}




Measured memory_bytes: 2040
import System.IO (isEOF)

main = do
    quit <- isEOF
    if quit then return () else do
        input >>= return . weights >>= output
        main

input :: IO Int
input = readLn

output :: [Int] -> IO ()
output = putStrLn . unwords . map show

weights :: Int -> [Int]
weights w = weights' w 1
    where
    weights' 0 _ = []
    weights' w' s
        | odd w' = s : weights' (w' `div` 2) (s * 2)
        | otherwise = weights' (w' `div` 2) (s * 2)

Measured memory_bytes: 4040
//Created Time:2019年12月18日 星期三 08时37分26秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 200005
#define M 4004
#define mod 1000000007

using namespace std;

int n;
int ifac[N], fac[N], f[M][M], cnt[M][M], x[N], y[N];

int read();
void init();
int quick_pow(int);
int C(int ,int);

int main(){
	n = read(); int m = 2001; init();
	for(int i = 1; i <= n; ++i){
		x[i] = read(), y[i] = read();
		f[m - x[i]][m - y[i]]++;
	}
	for(int i = 1; i <= m * 2; ++i)
		for(int j = 1; j <= m * 2; ++j)
			(f[i][j] += (f[i - 1][j] + f[i][j - 1]) % mod) %= mod;
	int ans = 0;
	for(int i = 1; i <= n; ++i){
		(ans += f[x[i] + m][y[i] + m]) %= mod;
		(ans += mod - C(x[i] * 2 + y[i] * 2, x[i] * 2)) %= mod;
	}
	cout << 1ll * ans * quick_pow(2) % mod << endl;;
	return 0;
}

int read(){
	int x = 0; char ch = getchar();
	for(; !isdigit(ch); ch = getchar());
	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	return x;
}

void init(){
	int m = 10000; fac[0] = ifac[0] = 1;
	for(int i = 1; i <= m; ++i)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[m] = quick_pow(fac[m]);
	for(int i = m; i; --i)
		ifac[i - 1] = 1ll * ifac[i] * i % mod;
	return ;
}

int quick_pow(int x){
	int sum = 1, y = mod - 2;
	for(; y; y >>= 1, x = 1ll * x * x % mod) if(y & 1) sum = 1ll * sum * x % mod;
	return sum;
}

int C(int x, int y){
	return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}


Measured memory_bytes: 65280
using System;

namespace abc140B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = new int[N];
            string[] str = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(str[i]);
            }
            int[] b = new int[N];
            string[] ltr = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                b[i] = int.Parse(ltr[i]);
            }
            int[] c = new int[N];
            string[] dtr = Console.ReadLine().Split();
            for (int i = 0; i < N-1; i++)
            {
                c[i] = int.Parse(dtr[i]);
            }
            int P = 0;
            for (int i = 0; i < N; i++)
            {
                P = P + b[a[i]-1];
                if (i < N - 1 && a[i + 1] - a[i] == 1)
                {
                    P = P + c[a[i] - 1];
                }
            }
            Console.WriteLine(P);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    map<string,ll> m;
    set<string> se;
    ll n;
    string s;
    scanf("%lld ",&n);
    vector<string> v;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        m[s]+=1;
        v.push_back(s);
    }
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        m[s]-=1;
        v.push_back(s);
    }
    map<string,ll> m2;
    ll ans=0;
    for(int i=0;i<v.size();i++)
    {
        if(m2[v[i]]==0)
        {
            ans=max(ans,m[v[i]]);
            m2[v[i]]=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int n,m;
int cnt[33];
signed main(){
    cin>>n>>m;
    rep(i,n){
        int k;cin>>k;
        while(k--){
            int a;cin>>a;
            a--;cnt[a]++;
        }
    }
    int ans=0;
    rep(i,m)if(cnt[i]==n)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h,w;
    cin >> h >> w;
    string s;
    rep(i,w+2) cout << '#';
    cout << endl;
    rep(i,h)
    {
        cin >> s;
        cout << '#' << s << '#' << endl;
    }
    rep(i,w+2) cout << '#';
    cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int cnt[9]={0};
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    cnt[MIN(8,a/400)]++;
  }
  int ans=0;
  for(i=0;i<8;i++){
    if(cnt[i]>0){
      ans++;
    }
  }
  int min=(ans>0?ans:1);
  int max=ans+cnt[8];
  printf("%d %d\n",min,max);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    for (ll i = 0; i < n - 1; i++)
    {
        ans *= k - 1;
    }

    cout << ans << endl;
}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
vector<ll> a;
vector<ll> b;
ll ret = 0;

void input() {
  IN(N);
  ll tmp;
  a.pb(0);
  b.pb(0);
  REP(i, N) {
    IN(tmp);
    a.pb(tmp);
    b.pb(0);
  }
}

void solve() {
  FOR(i, 1, N+1) {
    ll x = N-i+1;
    ll y = x + x;
    ll total = 0;
    while(y <= N) {
      total += b[y];
      y += x;
    }
    total %= 2;
    
    b[x] = (total==a[x]) ? 0 : 1;
  }
  ll cnt = 0;

  FOR(i, 1, N+1) {
    if (b[i] == 1) {
      cnt++;
    }
  }
  PRINT(cnt);
  FOR(i, 1, N+1) {
    if (b[i] == 1) {
      cout << i << " ";
    }
  }
  cout << endl;
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int i;
    long double l;
    int n;
    int k=0;
    cin >>n>>k;
    long double ans=0;
    for (i=0;i<n;i++){
        int j=i+1;
        if(j>=k) ans+=1;
        else {
            for(l=0;l<k;l++){
            j*=2;
            if(j>=k) {ans+=1/pow(2.0,double(l+1)); break;}
            }
            
        }
    }
    //std::cout << ans/n<< std::endl;
    printf("%.16Lf\n", ans/n);
   
}


Measured memory_bytes: 256
a=input()
if a[0]==a[1] and a[2]==a[3] and a[0]!=a[2]:
    print("Yes")
elif a[0]==a[2] and a[1]==a[3] and a[0]!=a[1]:
    print("Yes")
elif a[0]==a[3] and a[1]==a[2] and a[0]!=a[1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
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) << " "

int main(){
    int n;cin>>n;
    ll h[n];rep(i, n)cin>>h[i];
    pair<ll, ll>ps[n-1];
    for(int i=0;i<n-1;i++){
        ps[i].first = abs(h[i]-h[i+1]);
        if(i!=(n-2))ps[i].second=abs(h[i]-h[i+2]);
    }
    ll f[n];
    f[0] = 0;
    f[1] = ps[0].first;
    for(int i=2;i<n;i++){
        f[i] = min(f[i-2]+ps[i-2].second, f[i-1]+ps[i-1].first);
    }
    co(f[n-1]);
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    rep(i,s.size()-1){
        if (s[i]==s[i+1]){
            cout<<"Bad\n";
            return 0;
        }
    }
    cout<<"Good\n";
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int K, X;
  cin >> K >> X;
  if (K * 500 >= X) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
int W,H;
     
    while(1){
        cin>>H>>W;
        if(H==0  && W==0) break;
         
        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                if(i%2!=0){
                    if(j%2==0)
                        cout<<'.'; 
                    else
                        cout<<'#'; 
                }
                else{
                    if(j%2==0)
                        cout<<'#';
                    else
                        cout<<'.';
                }
            }
        cout<<'\n';
        }
    cout<<'\n';
    }
    return 0;
    }



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

using namespace std;

main(){
		int l;
		while(cin>>l){
			int o=0;
			for (int a=0; a < 10; a++){
				for (int b=0; b < 10; b++){
					for (int c=0; c < 10; c++){
						for (int d=0; d< 10; d++){
							if(a+b+c+d==l){
								o=o+1;
							}
						}
					}
				}
			}
			printf("%d\n",o);
		}
}



Measured memory_bytes: 3128
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	private static long n;
	private static String[] numeralSystem;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
//		n = BigInteger
		BigInteger bigInteger = new BigInteger(scanner.next());
		n = bigInteger.longValue();
		fillNumeralSystem();
//		translateNumber();
		System.out.println(translateNumber());
	}

	private static void fillNumeralSystem() {
		numeralSystem = new String[27];
		numeralSystem[0] = "z";
		int delta = (int) 'a';
		for (int i = 1; i < numeralSystem.length; i++) {
			numeralSystem[i] = Character.toString(i - 1 + delta);
		}
	}

	public static String translateNumber() {

		String res = "";

		while (n > 26) {
			res = numeralSystem[(int) (n % 26)].concat(res);
			n--;
			n /= 26;
		}

		res = numeralSystem[(int) n].concat(res);

		return res;
	}
}


Measured memory_bytes: 35808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto 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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vector<VI> edge(n);
    int u, v;
    FOR(i, 0, m) {
        cin >> u >> v;
        edge[--u].push_back(--v);
    }
    int s, t;
    cin >> s >> t;
    s--, t--;
    
    vector<vector<bool>> evermod(n, vector<bool>(3, 0));
    queue<pair<int, ll>> bfs;
    bfs.push({ s,0 });
    while (!bfs.empty()) {
        int now = bfs.front().first;
        ll dis = bfs.front().second + 1;
        bfs.pop();

        for (int i : edge[now]) {
            if (evermod[i][dis % 3])continue;
            evermod[i][dis % 3] = 1;
            bfs.push({ i,dis });
            if (i == t && !(dis % 3)) {
                cout << dis / 3 << "\n";
                return 0;
            }
        }
    }
    cout << -1 << "\n";
}

Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> P;
#define MAX_V 100000
#define INF (1<<29)
vector<P> G[MAX_V];
int memo[MAX_V];
 
int V,E;
 
void init();
void input();
P search(int);
 
int main(){

  init();
  cin>>V;
  E=V-1;
  input();
  P si=search(0);
  P ti=search(si.second);
  cout<<ti.first<<endl;
     
  
  return 0;
}
 
void init(){
  for(int i=0;i<MAX_V;i++){
    G[i].clear();
  }
}
 
void input(){
  int a,b,c;
  for(int i=0;i<E;i++){
    cin>>a>>b>>c;
    G[a].push_back(P(c,b));
    G[b].push_back(P(c,a));
  }
}
 
 
P search(int x){
  int d[MAX_V];
  for(int i=0;i<MAX_V;i++)d[i]=INF;
  d[x]=0;
  queue<P> Q;
  P p,res;
  Q.push(P(0,x));
  while(!Q.empty()){
    p=Q.front();Q.pop();
    if(p.first>d[p.second])continue;
    int pos=p.second,cost=p.first;
    for(int i=0;i<(int)G[p.second].size();i++){
      P w=G[pos][i];
      if(d[w.second]<=cost+w.first)continue;
      d[w.second]=cost+w.first;
      Q.push(P(d[w.second],w.second));
    }
  }
  res=P(0,0);
  for(int i=0;i<V;i++){
    if(res.first<d[i]){
      res.first=d[i];
      res.second=i;
    }
  }
  return res;
}

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

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr ll inf = 2e18;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	int a[n]; rep(i, 0, n) cin >> a[i];
	auto sum = [&](int l, int r) {
		ll s = 0;
		for (int i = l; i <= r; ++i) s += a[i];
		return s;
	};
	ll dp[n][n];
	per(l, 0, n) {
		dp[l][l] = 0;
		rep(r, l + 1, n) {
			dp[l][r] = inf;
			rep(m, l, r) ckmin(dp[l][r], dp[l][m] + dp[m + 1][r]);
			dp[l][r] += sum(l, r);
		}
	}
	cout << dp[0][n - 1];
}

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


double dist(vector<int> a, vector<int> b, int dim){
    double rel =0;
    rep(i,dim){
        rel+=pow(a[i]-b[i],2);
    }
    rel = pow(rel,0.5);
    return rel;
}
bool isInt(double a){
    return (int)a == a;    
}
//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main(){
    int n,d,ans;
    ans = 0;
    cin >> n >> d;
    vector<vector<int>> a(n,vector<int>(d));
    rep(i,n){
        rep(j,d){
            cin >> a[i][j];
        }
    }
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            if(isInt(dist(a[i],a[j],d)))++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;  
  vector <char> vec(W+2,'#');
  
  for (int i=0;i<H+2;i++) {
    if (i==0||i==H+1){
      vec=vector<char>(W+2,'#');
      for (int j=0;j<W+2;j++) {
        cout << vec.at(j);
      }
      cout << endl;
    }
    
    else {
      for (int j=0;j<W;j++) {
        cin >> vec.at(j+1);
      }
      for (int j=0;j<W+2;j++) {
        cout << vec.at(j);
      }
      cout << endl;
    }  
  }  
}


Measured memory_bytes: 3596
def main():
    M = int(input())
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    dc_sum = 0
    for i in range(M):
        d = dc[i][0]
        c = dc[i][1]
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print(ans - 1 + dc_sum//9 - 1)
    else:
        print(ans - 1 + dc_sum//9)


if __name__ == '__main__':
    main()


Measured memory_bytes: 77400
import sys

n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
sc = [(s - 1, c) for s, c in sc]

ans = ["x"] * n

for s, c in sc:
    if n > 1 and s == 0 and c == 0:
        print(-1)
        sys.exit()
    elif ans[s] != "x" and ans[s] != c:
        print(-1)
        sys.exit()
    else:
        ans[s] = c

if n > 1 and ans[0] == "x":
    ans[0] = 1

for i in range(n):
    if ans[i] == "x":
        ans[i] = 0

ans = [str(x) for x in ans]

print("".join(ans))

Measured memory_bytes: 9228
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
dis =[]
dis.append(a)
dis.append(b)
dis.append(c)
dis.append(d)
dis.append(e)

if max(dis)-min(dis)>k:
  print(":(")
else:
  print("Yay!") 

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
const ll MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

	if (N >= 30){
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}


	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
 
  vector<string> hands(3);
  cin>>hands[0]>>hands[1]>>hands[2];
  int turn_mng=0,next_turn;
  while(1){
  	if(hands[turn_mng].empty()){
    	cout<<(char)('A'+turn_mng)<<endl;
    	return 0;
    }else{
      next_turn=*hands[turn_mng].begin()-'a';
      hands[turn_mng].erase(hands[turn_mng].begin());
      turn_mng=next_turn;
      
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int md = 1e9+7;
long long n, k, a, b[105][100005];

int main(){
    scanf("%lld%lld", &n, &k);
    fill(b[0],b[0]+k+1,1);
    for(int i = 0; i < n; i++){
        scanf("%lld", &a);
        b[i+1][0] = 1;
        for(int j = 1; j <= k; j++){
            b[i+1][j] = (b[i][j] - b[i][j-a-1<0 ? k+1 : j-a-1] + b[i+1][j-1] + md) % md;
        }
    }
    printf("%lld\n", (b[n][k] - b[n][k-1<0 ? k+1 : k-1] + md) % md);
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;
    int a , b , c , d;
    cin>>a>>b>>c>>d;
    cout<<(max({a*d , a*c , b*c , b*d}))<<"\n";

}

Measured memory_bytes: 3652
import sys
s=input()
n=len(s)
if s[-1]=='1':
  print(-1)
  sys.exit()
if s[0]=='0':
  print(-1)
  sys.exit()
for i in range(n-1):
  if s[i]!=s[n-2-i]:
    print(-1)
    sys.exit()
ans=['1','2']
print(' '.join(ans))
current=2
for i in range(1,n-1):
  ans=[]
  ans.append(str(current))
  ans.append(str(i+2))
  print(' '.join(ans))
  if s[i]=='1':
    current=i+2

Measured memory_bytes: 74788
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    ll k,a,b;
    std::cin >> k>>a>>b;
    if(k==1){
        std::cout << 2 << std::endl;
    }
    else{
        ll a1=1ll,a2=1ll;
        a1+=k;
        k-=(a-1);
        k--;
        if(k>0){
            a2=0;
            k--;
            a2+=(b);
            a2+=(k/2)*(b-a);
            if(k%2)a2++;
        }
        std::cout << max(a1,a2) << std::endl;
    }
}

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

int main() {

    string a,b,c;

    cin >> a >> b >> c;

    if(a.back() == b.front() && b.back() == c.front())
        cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

bool is_prime(size_t n) {
  for (size_t p = 2; p * p <= n; p++) {
    if (n % p == 0) {
      return false;
    }
  }

  return true;
}

vector<size_t> factors(size_t n) {
  vector<size_t> result;
  for (size_t d = 1; d * d <= n; d++) {
    if (n % d == 0) {
      result.push_back(d);
      if (n / d != d) {
        result.push_back(n / d);
      }
    }
  }
  return result;
}

vector<pair<size_t, size_t>> factorize(size_t n) {
  vector<pair<size_t, size_t>> result;
  for (size_t p = 2; p * p <= n; p++) {
    if (is_prime(p)) {
      size_t cnt = 0;
      while (n % p == 0) {
        n /= p;
        cnt++;
      }
      if (cnt > 0) {
        result.push_back(make_pair(p, cnt));
      }
    }
  }
  if (n != 1) {
    result.push_back(make_pair(n, 1));
  }
  return move(result);
}

size_t totient(const size_t n) {
  vector<pair<size_t, size_t>> fs = factorize(n);
  size_t result = n;

  for (auto pa : fs) {
    size_t p;
    tie(p, ignore) = pa;
    result /= p;
    result *= p - 1;
  }
  return result;
}

int main() {
  size_t n;
  cin >> n;
  cout << totient(n) << endl;

  return 0;
}


Measured memory_bytes: 3120
n = int(input())
a = list(map(int,input().split()))

def solve(l,ans):
	if l == []:
		return ans
	for i in range(len(l)-1,-1,-1):
		if l[i] == i+1:
			ans.append(i+1)
			return solve(l[:i]+l[i+1:], ans)

	return 0


A = solve(a,[])
if A == 0:
	print(-1)
else:
	for a in A[::-1]:
		print(a)

Measured memory_bytes: 3064
S = input()

def check(S):
  DP = [False]*len(S)
  if S[:5] == 'dream' or S[:5] == 'erase':
    DP[4] = True
  if S[:7] == 'dreamer':
    DP[6] = True
  if S[:6] == 'eraser':
    DP[5] = True
  
  for i in range(7,len(S)):
    DP[i] = (DP[i-5]&((S[i-4:i+1]=='dream')|(S[i-4:i+1]=='erase')))|(DP[i-6]&(S[i-5:i+1]=='eraser'))|(DP[i-7]&(S[i-6:i+1]=='dreamer'))
  return DP[-1]
if check(S):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 4084
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

int const MaxSize = 50 + 5;
int N, a[MaxSize];
vector<PII> op;

int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);
	cin >> N;

	int maxAbs = 0;
	int aiV = 0;
	int mi = 0;

	LPE(i, 1, N)
	{
		cin >> a[i];

		if (abs(a[i]) > maxAbs) {
			maxAbs = abs(a[i]);
			aiV = (a[i]);
			mi = i;
		}
	}

	bool pos = aiV > 0;

	LPE(i, 1, N)
	{
		if (a[i] < 0 && pos) {
			a[i] += aiV;
			op.push_back(PII(mi, i));

		} else if (a[i] > 0 && !pos) {
			a[i] += aiV;
			op.push_back(PII(mi, i));
		}
	}

	if (pos) {
		LPE(i, 2, N)
		{
			if (a[i] < a[i - 1]) {
				a[i] += a[i - 1];
				op.push_back(PII(i - 1, i));
			}
		}
	} else {
		for (int i = N - 1; i >= 1; i--) {
			if (a[i] > a[i + 1]) {
				a[i] += a[i + 1];
				op.push_back(PII(i + 1, i));
			}
		}
	}

	cout << op.size() << endl;

	LP(i, 0, op.size())
	{
		cout << op[i].first << " " << op[i].second << endl;
	}

	return 0;
}


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

int dp[101][100001];
int W[101];
int val[101];
int knapsack(int i,int sum,int n){
    if(sum<=0)return 0;
    if(i==n)return INT_MAX-1;
    if(dp[i][sum]!=-1)return dp[i][sum];
    dp[i][sum]=min(knapsack(i+1,sum-val[i],n)+W[i],knapsack(i+1,sum,n));
    
    return dp[i][sum];
   
}
int32_t main()
{
    string s,w;
    cin>>s>>w;
    int n=s.length();
    int m=w.length();
    int lcs[n+1][m+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++){
            if(i==0||j==0)lcs[i][j]=0;
            else if(s[i-1]==w[j-1])lcs[i][j]=1+lcs[i-1][j-1];
            else lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
    }
    string ans="";
    int i=n,j=m;
    while(i!=0&&j!=0){
        if(s[i-1]==w[j-1]){
            ans+=s[i-1];
            i--;
            j--;
        }
        else if(lcs[i-1][j]>lcs[i][j-1]){
            i--;
        }
        else j--;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 73976
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

typedef long long LL;

inline bool tri(LL a, LL b, LL c){
    return a < b + c;
}

int main(){
    int n;
    cin >> n;
    vector<LL> a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<LL>());

    vector<LL> sum(n + 1);
    REP(i, n) sum[i + 1] = sum[i] + a[i];

    LL ans = 0;

    vector<LL> length;
    REP(i, n - 2) {
        if(tri(a[i], a[i + 1], a[i + 2])){
            length.push_back(a[i] + a[i + 1] + a[i + 2]);
            if(length.size() == 2) {
                ans = max(ans, accumulate(length.begin(), length.end(), 0LL));
                break;
            }
            i += 2;
        }
    }

    LL b[2][3] = {};
    int idx[2] = {};
    for(int comb = (1 << 5) | ((1 << 2) - 1); comb < (1 << 6);){
        for(int i = 0; i + 6 <= n; i++){
            LL s = sum[i + 6] - sum[i];
            if(s < ans) break;

            memset(idx, 0, sizeof(idx));
            for(int j = 0; j < 6; j++) {
                b[ comb >> j & 1 ][ idx[comb >> j & 1]++ ] = a[i + j];
            }

            if(tri(b[0][0], b[0][1], b[0][2]) && tri(b[1][0], b[1][1], b[1][2])){
                ans = s;
            }
        }

        int x = comb & -comb, y = comb + x;
        comb = ((comb & ~y) / x >> 1) | y;
    }

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

Measured memory_bytes: 2584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int a, b; cin >> a >> b;
    int i = b - a - 1;
    cout << i*(i+1)/2 - a;
}


Measured memory_bytes: 256