akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	int N;
	int L[15]={};
	
	cin >> N;
	for(int i=0;i<N;i++)
		cin >> L[i];
	
	sort(L,L+N);
	
	int sum=0;
	for(int i=0;i<N-1;i++)
		sum+=L[i];
	
	if(L[N-1]<sum)cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}



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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k, mx = 0;
    cin >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
        mx = max(mx, a[i]);
    }

    auto C = [&](double x){
        int cnt = 0;
        for (int i = 0; i < n; i++){
            cnt += (int) (a[i] / x);
            
            if ((int) (a[i] / x) * x == a[i])
                cnt -= 1;
        }

        return cnt <= k;
    };

    double lb = 0, ub = mx;
    for (int i = 0; i < 50; i++){
        double mid = (lb + ub) / 2.0;
        if (C(mid))
            ub = mid;
        else
            lb = mid;
    }

    cout << (int) ceil(ub) << '\n';

    return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  ll x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vi p(a),q(b),r(c);
  rep(i,a) cin>>p[i];
  rep(i,b) cin>>q[i];
  rep(i,c) cin>>r[i];
  sort(all(p)); reverse(all(p));
  sort(all(q)); reverse(all(q));
  vi v;
  rep(i,x) v.eb(p[i]);
  rep(i,y) v.eb(q[i]);
  rep(i,c) v.eb(r[i]);
  sort(all(v)); reverse(all(v));
  ll ans=0;
  rep(i,x+y) ans+=v[i];
  out(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 8688
#include <bits/stdc++.h>
#define ll long long
const int mod=1e9+7;
using namespace std;
int n,a[105],s=0,ans1=0,ans2=0,ans3=0;

int main(){
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        s+=a[i];
    }
    s=s/n;
    for(int i=1;i<=n;i++){
        ans1=ans1+(a[i]-s)*(a[i]-s);
        ans2=ans2+(a[i]-(s+1))*(a[i]-(s+1));
        ans3=ans3+(a[i]-(s-1))*(a[i]-(s-1));
    }
    cout<<min(ans3,min(ans1,ans2))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int data_sets[100000];
  int i, last=1;

  while(i<=100000){
    scanf("%d", &data_sets[i]);
    if(data_sets[i] == 0)break;
    last++;
    i++;
  }

  for(i=1;i<last;i++){
    printf("Case %d: %d\n", i,data_sets[i-1]);
  }
  return 0;
}

Measured memory_bytes: 1072
#include <cstdio>
#include <cstring>

int main(void) {
    char S[100001];
    scanf("%s", S);
    for(int i=0 ; i<strlen(S) ; ) {
        if(S[i]=='e'&&S[i+1]=='r'&&S[i+2]=='a'&&S[i+3]=='s'&&S[i+4]=='e') {
            if(S[i+5]=='r') {
                if(S[i+6]!='a'||S[i+6]==0)
                    i+=6;
                else i+=5;
            } else i+=5;
        } else if(S[i]=='d'&&S[i+1]=='r'&&S[i+2]=='e'&&S[i+3]=='a'&&S[i+4]=='m') {
            if(S[i+5]=='e'&&S[i+6]=='r') {
                if(S[i+7]!='a'||S[i+7]==0)
                    i+=7;
                else i+=5;
            } else i+=5;
        } else {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}


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


void solve(long long N){
    long long a;
    for(long long i=1LL;i<N;i++){
        if(i*i > N){
            a =i-1;
            break;
        }
    }
    // cerr << "a=" << a << endl;
    set<long long> anss;
    for(long long i=2;i<=a;i++){
        if(N%i==0){
            long long t = N;
            while(t%i==0){
                t /= i;
            }
            if(t%i ==1){
                // cerr << "div"<< endl;
                // cerr << "t=" << t << endl;
                // cerr << i << endl;
                anss.insert(i);
            }
        }else{
            if((N-1)%i ==0){
                // cerr << "mod"<< endl;
                // cerr << i << endl;
                // cerr << (N-1)/i<< endl;
                anss.insert(i);
                anss.insert((N-1)/i);
            }
        }
    }
    if(N>2){
        anss.insert(N-1);
    }
    anss.insert(N);
    cout << anss.size() << endl;


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define inf 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n,m;
	cin>>n>>m;
	cout<<(n*(n-1)/2+m*(m-1)/2);
	#ifdef ANIKET_GOYAL
		cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        vector<long long> dp(n + 1, 0);
        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            dp[i] += dp[i - 1];
            if (i > 1) dp[i] += dp[i - 2];
            if (i > 2) dp[i] += dp[i - 3];
        }
        int ans = ceil(dp[n] / 3650.0);

        cout << ans << endl;
    }

    return 0;
}


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

int main(){
    string S;
    char C[26];
    int N, dummy;
    cin >> N;
    cin >> S;
    
    size_t size = S.length();
    
    C[0] ='A';
    C[1] ='B';
    C[2] ='C';
    C[3] ='D';
    C[4] ='E';
    C[5] ='F';
    C[6] ='G';
    C[7] ='H';
    C[8] ='I';
    C[9] ='J';
    C[10] ='K';
    C[11] ='L';
    C[12] ='M';
    C[13] ='N';
    C[14] ='O';
    C[15] ='P';
    C[16] ='Q';
    C[17] ='R';
    C[18] ='S';
    C[19] ='T';
    C[20] ='U';
    C[21] ='V';
    C[22] ='W';
    C[23] ='X';
    C[24] ='Y';
    C[25] ='Z';
    
    for(int i=0; i< size; i++){
        for(int j=0; j<26; j++){
            if(S[i] == C[j]){
                dummy = j+N;
                if(dummy>=26) dummy = dummy - 26;
                cout << C[dummy];
            }
        }
    }

return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(true){
            int h = in.nextInt();
            int w = in.nextInt();

            if(h == 0 && w == 0){
            break;
            } 
           for(int i=0; i<h; i++){
               for(int j=0; j<w; j++){
            System.out.print("#");
            } 
            System.out.print("\n");
        } 
        System.out.print("\n");
    } 
  }                                                                                           
}

Measured memory_bytes: 37496
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    ll now = 1;
    ll res = 5;
    vll data;
    repr(i,n-1,-1){
        if (s[i]=='?'){
            data.pb(now);
        }
        else{
            res = (13 + res -( now * (s[i] - '0'))%13) % 13;
        }
        now = (now * 10) % 13;
    }
    ll m = data.size();
    vvll dp(m + 1, vll(13, 0));
    dp[0][0] = 1;
    rep(i,m){
        rep(j,13){
            rep(k,10){
                dp[i + 1][(j + k * data[i]) % 13] = (dp[i + 1][(j + k * data[i]) % 13] + dp[i][j]) % mod;
            }
        }
    }
    cout << dp[m][res] << endl;
}


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

int main() {
	string s;
	cin >> s;
	int n[100000];
	for (int i = 0; i < s.size(); i++)
		n[i] = s[i] - 48;
	int c1 = 0, c2 = 0;
	for (int i = 0; i < s.size(); i += 2)//01~
		if (n[i] != 0)
			c1++;
	for (int i = 1; i < s.size(); i += 2)
		if (n[i] != 1)
			c1++;
	for (int i = 0; i < s.size(); i += 2)//10~
		if (n[i] != 1)
			c2++;
	for (int i = 1; i < s.size(); i += 2)
		if (n[i] != 0)
			c2++;
	cout << min(c1, c2) << endl;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=0&&b>=0) printf("Zero");
	else if(a>0&&b>0||abs(a+b)%2==1) printf("Positive");
	else printf("Negative");
	return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int,input().split()))

m = max(a)

if m % 2 == 0:
  h = m // 2
  
  c = sys.maxsize
  for i in range(n):
    if m == a[i]:
      continue
    
    if c > abs(h-a[i]):
      c = abs(h-a[i])
      ans = a[i]
    
  print(m, ans)
  
else:
  h1 = m // 2
  h2 = h1 + 1
  c = sys.maxsize
  
  for i in range(n):
    if m == a[i]:
      continue
    
    if c > abs(h1-a[i]):
      c = abs(h1-a[i])
      ans = a[i]    
      
    if c > abs(h2-a[i]):
      c = abs(h2-a[i])
      ans = a[i]
      
  print(m,ans)

Measured memory_bytes: 14428
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 200010
ll n,k,cnt[N];
int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++)cnt[i]=0;
  for(int i=0;i<n;i++){
      ll a;cin>>a;
      cnt[a-1]++;
  }
  sort(cnt,cnt+n,greater<ll>());
  ll ans=0;
  for(int i=0;i<k;i++)ans+=cnt[i];
  cout<<n-ans<<endl;
  return 0;
}


Measured memory_bytes: 1920
class Node
  def initialize(id, key)
    @id = id
    @key = key
    @parent = nil
    @left = nil
    @right = nil
  end

  def print_self
    print "node #{@id}: "
    print "key = #{@key}, " unless @key == nil
    print "parent key = #{@parent}, " unless @parent == nil
    print "left key = #{@left}, " unless @left == nil
    print "right key = #{@right}, " unless @right == nil
    print "\n"
  end

  attr_accessor :id, :key, :parent, :left, :right
end

n = gets.chomp.to_i
input = gets.chomp.split.map(&:to_i)
array = ["dummy"]
input.each_with_index do |key, id|
  next if key == "dummy"
  id += 1
  node = Node.new(id, key)
  if (id/2) > 0 then
    node.parent = array[id/2].key 
    if (id % 2) == 0 then
      array[id/2].left = node.key
    else
      array[id/2].right = node.key
    end
  end
  array << node
end

array.shift
array.each do |node|
  node.print_self
end

Measured memory_bytes: 8852
#include <cstring>
#include <iostream>
using namespace std;
char s[200005];
long long t[35];
int main()
{
 cin>>s;
 long long n=strlen(s);
 long long ans=1+n*(n-1)/2;
 for(int i=0;i<n;i++)
  t[s[i]-'a']++;
 for(int i=0;i<26;i++)
  ans-=t[i]*(t[i]-1)/2;
 cout<<ans<<endl;
 return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ( (A + B) > (C + D) ) {
    cout << "Left" << endl;
  }
  else if ( (A + B) == (C + D) ) {
    cout << "Balanced" << endl;
  }
  else  {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
// ITP1_9_A

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;

int main(){
  string W;
  cin >> W;
  transform(W.begin(), W.end(), W.begin(), ::toupper);
  int count = 0;
  while (true) {
    string T;
    cin >> T;
    if (T == "END_OF_TEXT")
      break;
    else {
      transform(T.begin(), T.end(), T.begin(), ::toupper);
      if (T == W)
        count++;
    }
  }
  cout << count << endl;
}



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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()  {
  string s ; 
  string S = "CODEFESTIVAL2016"  ; 
  cin >> s ;
  int ans = 0 ; 
  
  rep(i,s.size()){
    if(s.at(i) != S.at(i) ) ans ++ ;
  }
  
  cout << ans ;
  
}


Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<4;i++)cout<<s[i];
	cout<<" ";
	for(int i=4;i<12;i++)cout<<s[i];
	cout<<endl;
	return 0;
}



Measured memory_bytes: 256
/***************************************************
 * Problem Name : A.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2020-01-19
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    //~ cout << setprecision (10);
    //~ cout << fixed;
    int n, m;
    cin >> n >> m;

    if (n == m) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}else if(a>b){
		cout<<"a > b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3056
# include <iostream>
using namespace std;
struct info{int left,right,bro = -1,p = -1;}*a;
int h;
void dfs(int i,int high)
{
	if(i == -1) return ; 
	h = max(h,high);
	dfs(a[i].left,high+1);
	dfs(a[i].right,high+1); 
} 
int main(void)
{
	char w[3][20] = {"internal node","root","leaf"};
	int n,index,l,r;
	scanf("%d",&n);a = new info [n];
	for(int i = 0;i < n;i++)
	{
		scanf("%d %d %d",&index,&l,&r);
		a[index].left = l; a[index].right = r;
		if(l != -1)
		{
			a[l].p = index;
			a[l].bro = r;
		}
		if(r != -1)
		{
			a[r].p = index;
			a[r].bro = l;
		}
	}
	for(int i = 0;i < n;i++)
	{
		int m = 0,cnt = 2,d = 0,r = i;
		h = 0;
		while(a[r].p != -1)
		{
			r = a[r].p;
			d++;
		}
		dfs(i,0);
		if(a[i].left == -1) cnt--;
		if(a[i].right == -1) cnt--;
		if(a[i].p == -1) m = 1;
		else if(a[i].left == -1 && a[i].right == -1) m = 2;
		
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",i,a[i].p,a[i].bro,cnt,d,h,w[m]);
	}
	return 0;
} 


Measured memory_bytes: 3208
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n, a[10000] , g = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 1; i < n - 1; ++i) {
		if (a[i] < a[i - 1] && a[i] > a[i + 1] || a[i] > a[i - 1] && a[i] < a[i + 1]) ++g;
	}
	cout << g;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

signed main() {
	int N, p;

	cin >> N >> p;
	if (N == 1) {
		cout << p << endl;
		return 0;
	}

	map<int, int> mp = prime_factor(p);

	int ans = 1;

	for (int i = 2; i * i <= p; i++) {
		if (mp[i] / N > 0) ans *= pow(i, mp[i] / N);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 62720
s = input()
k = int(input())

if len(s) == 1:
  print(k // 2)
else:
  cnt = 0
  p = 1
  while p < len(s):
    if s[p-1] == s[p]:
      cnt += 1
      p += 1
    p += 1
      
  cnt2 = 0
  p2 = 1
  s2 = s + s
  while p2 < len(s2):
    if s2[p2-1] == s2[p2]:
      cnt2 += 1
      p2 += 1
    p2 += 1

  flg = 1
  for i in range(len(s)-1):
    if s[i] != s[i+1]:
      flg = 0
  
  if 2*cnt < cnt2:
    if flg == 1:
      print(k*cnt + (k//2))
    else:
      print(k*cnt + (k - 1))
  else:
    print(k*cnt)

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

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	multiset<string> m;
	for(int i=0;i<n;i++)
	{
		string s1;
		cin>>s1;
		m.insert(s1);
	}
	cout<<"AC x "<<m.count("AC")<<endl;
	cout<<"WA x "<<m.count("WA")<<endl;
	cout<<"TLE x "<<m.count("TLE")<<endl;
	cout<<"RE x "<<m.count("RE")<<endl;
	return 0;
}


Measured memory_bytes: 11428
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge { int to, id; };
int n, vc, a[200009], b[200009], c[200009]; long long sd, ans[200009], s[200009], dist[200009]; vector<edge> g[200009];
void dfs(int pos, int pre) {
	c[pos] = 1;
	for (edge e : g[pos]) {
		if (e.to != pre) {
			dfs(e.to, pos);
			c[pos] += c[e.to];
			// e.to -> pos, increased nodes = c[e.to], decreased nodes = n - c[e.to]
			if (n - c[e.to] * 2 != 0) {
				ans[e.id] = (s[e.to] - s[pos]) / (n - c[e.to] * 2);
			}
		}
	}
}
void dfs2(int pos, int pre, int flag) {
	if (flag) vc++; sd += dist[pos];
	for (edge e : g[pos]) {
		if (e.to != pre) {
			dist[e.to] = dist[pos];
			if (ans[e.id] != -1) dist[e.to] += ans[e.id];
			dfs2(e.to, pos, (flag | (ans[e.id] == -1 ? 1 : 0)));
		}
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i] >> b[i]; a[i]--, b[i]--;
		g[a[i]].push_back(edge{ b[i], i });
		g[b[i]].push_back(edge{ a[i], i });
	}
	for (int i = 0; i < n; i++) cin >> s[i];
	fill(ans, ans + n - 1, -1);
	dfs(0, -1);
	int zp = -1;
	for (int i = 0; i < n - 1; i++) {
		if (ans[i] == -1) zp = i;
	}
	if (zp != -1) {
		dfs2(0, -1, 0);
		ans[zp] = (s[0] - sd) / vc;
	}
	for (int i = 0; i < n - 1; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 22656
#include <bits/stdc++.h>
using namespace std;
#define modulo N
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005



int main(){
	
	int N;
	cin>>N;
	long long K;
	cin>>K;
	
	vector<vector<int>> A(60,vector<int>(N));
	
	for(int i=0;i<N;i++){
		cin>>A[0][i];
		A[0][i]--;
	}
	
	for(int i=1;i<60;i++){
		for(int j=0;j<N;j++){
			A[i][j] = A[i-1][A[i-1][j]];
		}
	}
	
	vector<int> t(N);
	for(int i=0;i<N;i++)t[i]=i;
	
	for(int i=0;i<60;i++){
		if(K&1){
			for(int j=0;j<N;j++){
				t[j] = A[i][t[j]];
			}
		}
		K>>=1;
	}
	
	cout<<t[0]+1<<endl;
	
	return 0;
}


Measured memory_bytes: 51036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll p1 = (c-a-b)*(c-a-b)-(4*a*b);
    ll p2 = c-a-b;
    if (p1>0 && p2>=0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    static int h,w;
    static char[][] s;
    static int[][] d;
    static int[] dr={0,-1,0,1};
    static int[] dc={-1,0,1,0};
    public static void main(String[] $) {
        h=sc.nextInt();
        w=sc.nextInt();
        s=new char[h][w];
        for (int i = 0; i < h; i++) {
            s[i]=sc.next().toCharArray();
        }
        d=new int[h][w];
        int black=0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                d[i][j]=Integer.MAX_VALUE;
                if(s[i][j]=='#'){
                    black++;
                }
            }
        }
        dfs(1,0,0);
        int ans;
        if(d[h-1][w-1]==Integer.MAX_VALUE){
            ans=-1;
        }else {
            ans=h*w-d[h-1][w-1]-black;
        }
        out.println(ans);
        out.close();
    }

    static void dfs(int count,int row,int column){
        if(!(0<=row&&row<h&&0<=column&&column<w))return;
        if(s[row][column]=='#')return;
        if(count>=d[row][column])return;
        d[row][column]=count;
        if(row==h-1&&column==w-1)return;
        for (int i = 0; i < 4; i++) {
            dfs(count+1,row+dr[i],column+dc[i]);
        }
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
}

Measured memory_bytes: 22868
n,m = map(int,input().split(" "))
c = tuple(map(int,input().split(" ")))
m = min(c)
dp = [2**60 for _ in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
    for v in c:
        if i >= v:
            dp[i] = min(dp[i],dp[i-v]+1)
print(dp[n])


Measured memory_bytes: 7376
#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define m_p make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
map<vector<ll>,int> go; 
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> vl;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		vl.push_back(a);
	}
	map<ll,ll> mp;
	ll cnt = 1;
	vector<ll> used;
	ll zhouqi;
	ll left=0;
	for(int i=0;;)
	{
		if(mp[i]>0)
		{
			zhouqi = cnt-mp[i];
			left = mp[i]-1;
			break;
		}
		mp[i] = cnt;
		cnt++;
		used.push_back(i);
		i = vl[i]-1;
	}
	//3 2 4 1
	//mp[0]=1,mp[2]=2,mp[3]=3,mp[0]
	//cout<<"period:"<<zhouqi<<",left="<<left<<",k="<<k<<endl;
	if(zhouqi==0)
	{
		cout<<1<<endl;
		return 0;
	}
	if(k-1<left)
	{
		cout<<used[k]+1<<endl;
		return 0;
	}
	ll chu = (k-left)%zhouqi;
	cout<<used[chu+left]+1<<endl;
	return 0;
}




Measured memory_bytes: 18592
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int n,tmp;
int gcd(int x, int y) {
    return (x % y) ? gcd(y, x % y) : y;
}

void solve(){

    long long sum=0;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                sum+=gcd(gcd(i+1,j+1),k+1);
            }
        }
    }

    cout<<sum<<endl;
}

int main(){
    cin>>n;


    solve();
    return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
void func(int p);
int n;
int box[101][101];
int d[101];
int f[101];
int flg[101];
int t;
int main(void){
	int u,k,v;
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			box[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			box[u][v]=1;
		}
	}
	t=0;
	for(i=1;i<=n;i++){
		if(!flg[i]){
			func(i);
		}
	}
	for(i=1;i<=n;i++)	cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}
void func(int p){
	int i;
	t++;
	d[p]=t;
	flg[p]=true;
	for(i=1;i<=n;i++){
		if(box[p][i]==1){
			if(!flg[i]){
				func(i);
			}
		}
	}
	t++;
	f[p]=t;
}

	
	


Measured memory_bytes: 3124
// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    double d,a,b,ans =0;
    ll coun =0;
    cin>>d;
    while(n--)
    {
        cin>>a>>b;
        ans = sqrt(a*a+b*b);
        if(ans<=d)
            coun++;
    }
    cout<<coun<<endl;
    return 0;
}



Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

// 文字列S の各i に対し, S と S[i:|S|-1] の最長共通接頭辞を求める
// https://snuke.hatenablog.com/entry/2014/12/03/214243
// verified: https://atcoder.jp/contests/arc055/submissions/2711907
/*
 * ex.  s = "aaabaaaab"
 * -> z[i]= "*21034210"
 */
vll z_algorithm(const std::string &s) {
  int sz = s.length();
  vll z(sz, 0);
  int i = 1, j = 0;
  while (i < sz) {
    while (i + j < sz && s[j] == s[i + j]) j++;
    z[i] = j;
    if (j == 0) {
      i++;
      continue;
    }
    int k = 1;
    while (i + k < sz && k + z[k] < j) {
      z[i + k] = z[k];
      k++;
    }
    i += k;
    j -= k;
  }
  return z;
}

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

    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<string> ss(n);
    REP(i, n) {
        ss[i] = s.substr(i, n - i);
    }

    ll res = 0;
    REP(i, n) {
        vll v = z_algorithm(ss[i]);
        REP(j, n - i) {
            ll tmp = v[j];
            if (j >= v[j]) res = max(res, tmp);
        }
    }
    cout << res << endl;
    return 0;
}

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

int main()
{
    int a,b,c,temp;
    scanf("%d %d %d", &a,&b,&c);

  temp=a;
  a=b;
  b=temp;

  int temp2;
  temp2=a;
  a=c;
  c=temp2;

    printf("%d %d %d", a,b,c);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    vector <ll> as;
    ll sum_as = 0;
    REP(i, n){
        ll a; cin >> a;
        sum_as += a;
        as.push_back(a);
    }
    //ll max_abs = sum_as + k*2;
    vector <int> cands;
    for(int i=1; i<=pow(sum_as, 0.5)+ 1; i++){
        if (sum_as%i == 0){
            cands.push_back(i);
            cands.push_back(sum_as/i);
        }
    }
    sort(cands.begin(), cands.end());
    dump(n)
    dump(k)
    dump(sum_as)
    dumparr(as)
    dumparr(cands)
    int ans = 1;
    for(auto cand: cands){
        map <int, int> amari_cnt;
        REP(i, n){
            ll a = as[i];
            amari_cnt[(a+cand)%cand]++;
        }
        ll sum_amari = 0;
        for(auto amari: amari_cnt){
            sum_amari += amari.first * amari.second;
        }
        int k_tmp = k;
        int haba = sum_amari / cand;
        for(auto amari: boost::adaptors::reverse(amari_cnt)){
            int haba_used = min(haba, amari.second);
            haba -= haba_used;
            k_tmp -= (cand-amari.first) * haba_used;
        }
        if (k_tmp >= 0){
            ans = cand;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
N, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
if A[0] > x:
  ans = A[0] - x
  A[0] = x
for i in range(N-1):
    if A[i] + A[i+1] > x:
        ans += A[i]+A[i+1]-x
        A[i+1] = x-A[i]
print(ans)


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

int main(){
	int a[3],tmp,b,c;
	char array[3] = {'A','B','C'};
	a[0] = 1;
	string str;
	while(cin >> str){
		if(str[0] == 'A') b = 0;
		else if(str[0] == 'B') b = 1;
		else b = 2;
		if(str[2] == 'A') c = 0;
		else if(str[2] == 'B') c = 1;
		else c = 2;
		tmp = a[b];
		a[b] = a[c];
		a[c] = tmp;
	}
	for(int i=0;i<3;i++){
		if(a[i] == 1){
			cout << array[i] << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque,Counter
n,p=map(int,input().split())
# if n==1:
#   print(p)
#   exit()



if p==1:
  print(1)
  exit()
if p==1:
  print(p)
  exit()

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
factors=Counter(prime_factors(p))
ans=1
for i,v in factors.items():
  ans*=i**(v//n)
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include <sstream>

using namespace std;

void chmax(string &a,string b){
  if(a.length() < b.length()) a = b;
  else if(a.length()==b.length() && a < b) a = b;
}

int main(){
  int N,M;
  string A[10];
  int AA[10];
  int B[10] = {100,2,5,5,4,5,6,3,7,6};
  string dp[111111] = "";
  dp[0] = " ";
  cin >> N >> M;
  int i,j;
  for(i=0;i<=M-1;i++)
    cin >> A[i];
  for(i=0;i<=M-1;i++){
    if(A[i]=="1") AA[i]=1;
    if(A[i]=="2") AA[i]=2;
    if(A[i]=="3") AA[i]=3;
    if(A[i]=="4") AA[i]=4;
    if(A[i]=="5") AA[i]=5;
    if(A[i]=="6") AA[i]=6;
    if(A[i]=="7") AA[i]=7;
    if(A[i]=="8") AA[i]=8;
    if(A[i]=="9") AA[i]=9;
    }
  for(i=1;i<=N;i++)
    for(j=0;j<=M-1;j++)
      if(i>=B[AA[j]] && dp[i-B[AA[j]]] != "") chmax(dp[i],dp[i-B[AA[j]]]+A[j]);
  cout << dp[N] << endl;
}

Measured memory_bytes: 42368
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	for (int i = 0; i < M; i++) {
		cin >> X[i];
	}

	sort(X.begin(), X.end());

	if (M != 1 && N < M) {
		vector<int> aida(M - 1);
		for (int i = 0; i < M - 1; i++) {
			aida[i] = X[i + 1] - X[i];
		}

		sort(aida.begin(), aida.end(), greater<int>());

		ll none = 0;
		for (int i = 0; i < N - 1; i++) {
			none += aida[i];
		}

		cout << X[M - 1] - X[0] - none;
	}
	else {
		cout << 0;
	}
	
	
}	


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

using namespace std;
using ll = long long;

int main(){
    long long a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    long long dist = abs(a-b);
    if(v*t - w*t >= dist) cout << "YES" << endl;
    else cout << "NO" << endl; 
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int head[10], vis[10], k;
int ans;
struct Edge
{
    int v, next;
}edge[200];
void add_edge(int x, int y)
{
    edge[++k].v = y;
    edge[k].next = head[x];
    head[x] = k;
}
void dfs(int u, int rest)
{
    if(rest == 0)
    {
        ans++;
        return ;
    }
    for(int kk = head[u]; kk; kk = edge[kk].next)
    {
        int v = edge[kk].v;
        if(vis[v]) continue;
        vis[v] = 1;
        dfs(v, rest - 1);
        vis[v] = 0;
    }
}
int main()
{
    int n, m, u, v;
    scanf("%d%d", &n, &m);
    memset(head, 0, sizeof(head));
    memset(vis, 0, sizeof(vis));
    k = 0;
    while(m--)
    {
        scanf("%d%d", &u, &v);
        add_edge(u, v);
        add_edge(v, u);
    }
    ans = 0;
    vis[1] = 1;
    dfs(1, n - 1);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
AA = list(map(int, input().split()))
A = [0] + AA
DP = [[0 for i in range(N+1)] for k in range(61)]

for i in range(1, N+1):
	DP[0][i]=A[i]
for k in range(1, 61):
    for i in range(1, N+1):
        DP[k][i] = DP[k-1][DP[k-1][i]]

now = 1
for k in range(61):
	if (K>>k) & 1:
		now = DP[k][now]

print(now)

Measured memory_bytes: 219476
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define BIT(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> v(M, 0);
    REP(i, N)
    {
        int K;
        cin >> K;
        REP(j, K)
        {
            int A;
            cin >> A;
            v[--A]++;
        }
    }
    int count = 0;
    REP(i, M)
    {
        count += (v[i] == N);
    }
    cout << count << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
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, m;
    cin >> n >> m;
    vector<int> ac(n), wa(n);
    rep(i, m) {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if (s == "AC") ac[p]++;
        if (s == "WA" && ac[p] == 0) wa[p]++;
    }

    int AC = 0, WA = 0;
    rep(i, n) {
        if (ac[i] > 0) {
            AC++;
            WA += wa[i];
        }
    }
    cout << AC << " " << WA << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define INF 200000000

int n,m;
int a,b,c,d;
int s,g,V,P;

int mat[21][21];

int main(){
	//init
	for(int i = 0; i < 21; i++){
		for(int j = 0; j < 21; j++){
			mat[i][j] = INF;
			if(i == j)
				mat[i][j] = 0;
		}
	}
	//input
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= m; i++){
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		mat[a][b] = c;
		mat[b][a] = d;
	}
	scanf("%d,%d,%d,%d",&s,&g,&V,&P);
	//update mat
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				int r = mat[i][k] + mat[k][j];
				mat[i][j] = mat[i][j] > r ? r : mat[i][j];
			}
		}
	}
	//output
	printf("%d\n", V - P - mat[s][g] - mat[g][s]);

	return 0;
}



Measured memory_bytes: 2692
n, m, l = map(int, input().split())

A = []
for i in range(n):
    row = list(map(int, input().split()))
    A.append(row)

B = []
for i in range(m):
    row = list(map(int, input().split()))
    B.append(row)

C = []
for i in range(n):
    row = []
    for j in range(l):
        sum = 0
        for k in range(m):
            sum += A[i][k] * B[k][j]
        row.append(sum)
    C.append(row)

for i in range(n):
    print(' '.join(map(str, C[i])))



Measured memory_bytes: 6908
n = int(input())
bbb = list(map(int, input().split()))
for i, b in enumerate(bbb, start=1):
    if i < b:
        print(-1)
        exit()

ans = []
for _ in range(n):
    for i, b in reversed(list(enumerate(bbb, start=1))):
        if i == b:
            ans.append(i)
            bbb.pop(i - 1)
            break
ans.reverse()
print('\n'.join(map(str, ans)))


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

int main() {
	using usize = unsigned int;
	using u64 = unsigned long long;
	static constexpr u64 Max = static_cast<u64>(1) << 40;

	usize n;
	u64 k;
	::std::cin >> n >> k;
	::std::vector<u64> a(n);
	for (auto &e : a) ::std::cin >> e;

	u64 x = 0, y = 0;
	for (u64 i = 1;i != Max;i <<= 1) {
		u64 zero = 0, one = 0;
		for (const auto e : a) (e&i ? one : zero) += i;
		if (k&i)
			x = ::std::max(x + zero, y + one);
		else
			x += one;
		y += ::std::max(zero, one);
	}

	::std::cout << x << ::std::endl;

	return 0;
}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
long h[100005];
long cnt;
long ans;

int main(){
    scanf("%ld", &n);
    for(int i = 0 ;  i < n; i++){
        scanf("%ld", &h[i]);
    }
    h[n] = LINF;
    for(int i = 0; i < n; i++){
        if(h[i] >= h[i+1]){
            cnt++;
        }else{
            ans = std::max(ans,cnt);
            cnt = 0;
        }
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 1024
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    N, M = li_input()
    L = []

    for i in range(M):
        a, b = li_input()

        if a == 1:
            L.append(b)

        if b == N:
            L.append(a)

    if len(L) == len(set(L)):
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")


main()


Measured memory_bytes: 24888