akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

#define MOD 998244353

long add(long a, long b) { long res = a + b; if (res >= MOD) res -= MOD; return res; }

long sub(long a, long b) { long res = a - b + MOD; if (res >= MOD) res -= MOD; return res; }

long mult(long a, long b) { return (a * b) % MOD; }

map<string, long> mem;

long calc(string s) {
    long res = mem[s];
    if (res > 0) return res;
    if (s.length() == 0) return 1;
    if (s[0] == '0') {
        res = calc(s.substr(1, s.length() - 1));
    } else {
        res = calc(s.substr(1, s.length() - 1));
        res = add(res, res);
    }
    for (int a = 1; a * 2 <= s.length(); a++) {
        string ss = s.substr(0, a);
        for (int b = 2; a * b <= s.length(); b++) {
            for (int i = 0; i < a; i++) {
                if (s[(b - 1) * a + i] == '0') {
                    ss[i] = '0';
                }
            }
            long c = mult(calc(ss), calc(s.substr(a * b, s.length() - a * b)));
            res = add(res, c);
        }
    }
    mem[s] = res;
    return res;
}

int main() {
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;
    cout << calc(s) << "\n";

    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

string solve() {
    string s;
    cin >> s;
    replace(begin(s), end(s), ',', ' ');
    return s;
}

int main() {
    int t = 1;
    // cin >> t;
    while (t--) cout << solve() << endl;
    return 0;
}

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

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

int main(){
    long A,B;
    cin >> A >> B;
    if(A==B){
        cout << A << "\n";
        return 0;
    }
    
    if (A>B){
        long tmp;
        tmp = A;
        A=B;
        B = tmp;
    }
    long l;

    l = euclid(A,B);
    long ans;
    ans = A*B/l;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
fn input_arr<T: std::str::FromStr> () -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().flat_map(str::parse).collect()
}

fn main() {
    let a: Vec<String> = input_arr();
    println!("{}", a.iter().rev().map(|s| s.chars()).flatten().collect::<String>());
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
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;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N;
  cin >> N;
  string S;
  cin >> S;

  ll ans = 0;
  for (char c1 = '0'; c1 <= '9'; c1++)
  {
    for (char c2 = '0'; c2 <= '9'; c2++)
    {
      for (char c3 = '0'; c3 <= '9'; c3++)
      {
        vector<char> x = {c1, c2, c3};

        ll cnt = 0;
        for (ll i = 0; i < N; i++)
        {
          if (S.at(i) == x.at(cnt))
          {
            cnt++;
            if (cnt == 3)
            {
              ans++;
              break;
            }
          }
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#5618213
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)
  
for b,c in bc:
    a.extend([c]*b)
    if len(a) > 2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))




Measured memory_bytes: 34888
#include <bits/stdc++.h>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
#define PI 3.141592653589793
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double hkaku,mkaku;
    hkaku = 30.0*h+m/2.0;
    mkaku = 6.0*m;
    double sa = min(abs(hkaku-mkaku),abs(mkaku-hkaku));
    sa = min(sa,360-sa);
    double cji = pow(a,2)+pow(b,2)-2*a*b*cos(sa*PI/180.0);
    cout << setprecision(15) <<  sqrt(cji) << endl;

        
}

Measured memory_bytes: 4204
n=int(input())
from collections import Counter as co
l=co(list(map(int,input().split())))
ans=len(l)
ng=set()
for k in l:
    if l[k]>=2:ng.add(k)
    for i in range(2*k,10**6+1,k):
        if i in l:
            ng.add(i)
print(ans-len(ng))


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

using namespace std;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
const int maxN = 100010;
const int maxC = 1e6 + 10;
const int INF = 1e9; 
int n;
char a[maxN];
char b[maxN];
char c[maxN];
int check(char x,char y,char z)
{
	if(x==y && y==z)
	{
		return 0;
	}
	
	else if((x==y && y!=z) || (x!=y && y==z))
	{
		return 1;
	}
	else
	{
		return 2;
	}
}
char d[4];
int main()
{
  
	scanf("%d%s%s%s",&n,a+1,b+1,c+1);
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		d[1] = a[i];
		d[2] = b[i];
		d[3] = c[i];
		sort(d+1,d+4);
		ans += check(d[1],d[2],d[3]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    long long s=1;
    cin>>x;
    for(int i=2;i<=x;i++){
        s*=i;
        s%=1000000000+7;
    }
    cout<<s;
       return 0;
}


Measured memory_bytes: 3604
use proconio::{fastout, input};

#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        n: usize
    }
    let mut res = 0;
    for i in (1..=n).step_by(2){
        if get_div_amount(i) == 8{
            res += 1;
        }
    }
    println!("{}",res);
}

fn get_div_amount(n: usize) -> usize{
    let mut res = 2;
    for i in 2..n{
        if n % i == 0 {
            res += 1;
        }
    }
    res
}


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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  if(n*a>=b){
    cout << b << endl;
  }
  else{
    cout << n*a << endl;
  }

  return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long a){
    cout << a + a*a+ a*a*a << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long a;
    scanf("%lld",&a);
    solve(a);
    return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
string s;
map<string,int>f;
map<string,int>g;
int F(string s);
int G(string s)
{
    if(g.find(s)!=g.end())
    return g[s];
    if(s.size()==1)
    return g[s]=s[0]-'0'+1;
    for(int i=1;i<s.size();i++)
    {
        if(s.size()%i==0)
        {
            string t;
            for(int j=0;j<i;j++)
            {
                int r=1;
                for(int k=0;k<s.size()/i;++k)
                if(s[i*k+j]=='0')
                r=0;
                t+=(char)(r+'0');
            }
            g[s]=(g[s]+F(t))%mod;
        }
    }
    return g[s];
}
int F(string s)
{
    if(f.find(s)!=f.end())
    return f[s];
    for(int i=1;i<=s.size();i++)
    f[s]=(f[s]+1ll*F(s.substr(0,s.size()-i))*G(s.substr(s.size()-i,i))%mod)%mod;
    return f[s];
}
int main()
{
    cin>>s;
    f[""]=1;
    cout<<F(s)<<endl;
    return 0;
}

Measured memory_bytes: 12928
from sys import stdin
input = stdin.readline

N, K = map(int, input().split())

lis = [0 for _ in range(N)]

for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
        lis[a - 1] += 1

ans = 0

for l in lis:
    if l == 0:
        ans += 1

print(ans)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int p[m],y[m];
  vector<int> yd[n+1];
  
  for(int i = 0;i < m;i++){
    cin >> p[i] >> y[i]; // pi and yi enter
    yd[p[i]].push_back(y[i]); // 県ごとの配列に年を入れていく
  }
  for(int i = 1;i <= n;i++){
    sort(yd[i].begin(),yd[i].end()); // 県ごとにソート
  }
  for(int i = 0;i < m;i++){
    cout << right << setw(6) << setfill('0') << p[i];
    cout << right << setw(6) << setfill('0') << (lower_bound(yd[p[i]].begin(), yd[p[i]].end(),y[i])- yd[p[i]].begin()) + 1 << endl;
  }
}


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

using namespace std;

int main(){
    int n = 5;
    int antenn[n];
    int k;
    bool flag = false;

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

    cin>>k;

    for(int i = 0; i<n-1; i++){
        for(int  j = 1; j<n-i; j++){
            if(abs(antenn[i]-antenn[j])>k){
                flag = true;
                break;    
            }
        }
    }

    if(flag){
        cout<<":(";
    }else{
         cout<<"Yay!";
    }
    
    return 0;
}

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

int main(){
  ll N,gg=0,g=0,k=0;
  bool f;
  cin>>N;
  for(int i=0;i<N;i++){
    ll a;
    cin>>a;
    if(a%4==0) gg++;
    else if(a%2==0) g++;
    else if(a%2==1) k++;
  }
  if(gg>=k) f=true;
  else if(g==N) f=true;
  else if(k==N) f=false;
  else if(g==0&&gg==k-1) f=true;
  else f=false;
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}

int main() {
  ll n;
  cin>>n;
  ll ans=0;
  rrep(i,n){
    if(i%2==0) continue;
    v(ll) ja=div(i);
    if(ja.size()==7) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
from bisect import bisect_left as bi
n=int(input())
l=sorted(map(int,input().split()))
ans=0
#print(l)
for i in range(n):
    for j in range(i+1,n):
        ans+=bi(l,l[i]+l[j])-j-1
#        print(i,j,bi(l,l[i]+l[j]),ans)
print(ans)

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

using namespace std;

int main()
{

    long long int N;
    cin >> N;

    vector<long long> ans;

    for(long long i=1; i*i <=N; i++){
		if(N % i == 0){
			ans.push_back(i);
			if(N / i != i){
				ans.push_back(N / i);
			}
		}
    }

    long long best = N-1;
    for(auto d : ans){
		best = min(best , d + N/d - 2);
    }

    cout << best << endl;

    return 0;
}


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

struct El{
    int key;
    El *head, *tail;

    El(int k, El* h, El* t) : key(k), head(h), tail(t){}
};

class List{
private:
    El *head, *tail;
public:
    List(): head(nullptr), tail(nullptr){}
    void insertEl(int x){
        El *p = new El(x, nullptr, nullptr);
        if(head == nullptr){
            head = tail = p;
            return;
        }
        p->tail = head;
        head->head = p;
        head = p;
    }
    void deleteEl(int x){
        for(El *ptr = head; ptr != nullptr; ptr = ptr->tail){
            if(ptr->key == x){
                El *back = ptr->head, *forward = ptr->tail;
                if(back == nullptr && forward == nullptr){
                    delete ptr;
                    head = tail = nullptr;
                    return;
                }else if(back == nullptr){
                    forward->head = nullptr;
                    delete ptr;
                    head = forward;
                    return;
                }else if(forward == nullptr){
                    back->tail = nullptr;
                    delete ptr;
                    tail = back;
                    return;
                }else{
                    back->tail = forward;
                    forward->head = back;
                    delete ptr;
                    return;
                }
            }
        }
    }
    void deleteFirst(){
        if(head != nullptr){
            El *work = head->tail;
            if(work != nullptr) work->head = nullptr;
            else tail = nullptr;
            delete head;
            head = work;
        }
    }
    void deleteLast(){
        if(tail != nullptr){
            El *work = tail->head;
            if(work != nullptr) work->tail = nullptr;
            else head = nullptr;
            delete tail;
            tail = work;
        }
    }

    void show(){
        for(El* ptr = head; ptr != nullptr; ptr = ptr->tail){
            cout << ptr->key << (ptr == tail ? "" : " ");
        }
        cout << endl;
    }
};

int main(){
    int n, x;
    string com;
    List list;
    cin >> n;

    while(n--){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            list.insertEl(x);
        }else if(com == "delete"){
            cin >> x;
            list.deleteEl(x);
        }else if(com == "deleteFirst"){
            list.deleteFirst();
        }else if(com == "deleteLast"){
            list.deleteLast();
        }
    }

    list.show();
}


Measured memory_bytes: 34396
// https://atcoder.jp/contests/abc090/tasks/arc091_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

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

  cout << (N == 1 ? 1 : N - 2) * (M == 1 ? 1 : M - 2) << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

int dp[200005];
int p[200005];

int main() {
	int n, ret = 0;;
	scanf("%d", &n);
	REP(i, n) {
		int p;
		scanf("%d", &p);
		dp[p] = dp[p - 1] + 1;
		ret = max(ret, dp[p]);
	}
	cout << n - ret << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int N;
int col[8];
int M = 0;


int judge(int a){
	if(1 <= a && a <= 399) return 0;
	if(400 <= a && a <= 799) return 1;
	if(800 <= a && a <= 1199) return 2;
	if(1200 <= a && a <= 1599) return 3;
	if(1600 <= a && a <= 1999) return 4;
	if(2000 <= a && a <= 2399) return 5;
	if(2400 <= a && a <= 2799) return 6;
	if(2800 <= a && a <= 3199) return 7;
	return -1;
}


void solve(){
	int ansm = 0;
	rep(i, 0, 8) ansm += col[i];
	if(ansm == 0) cout << 1 << ' ' << M << endl;
	else cout << ansm << ' ' << ansm+M << endl;
}


signed main(){
	cin >> N;
	rep(i, 0, N){
		int a;
		cin >> a;
		if(judge(a) != -1) col[judge(a)] = 1;
		else M++;
	}

	solve();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long 
ll h[200005] , a[200005] , tree[800005], x[200005] ;
ll query(int node, int start , int end , int l , int r)
{
	if(end<l||start>r)
	return(0);
	
	if(l<=start&&r>=end)
	return(tree[node]);
	int mid = (start+end)/2 ; 
	ll p1 = query(node*2+1, start, mid, l, r);
	ll p2 = query(node*2+2, mid+1, end , l ,r);
	return(max(p1,p2));
}
void _update(int node , int start , int end , int idx , ll val)
{
	if(start==end)
	{
		x[start]= val; 
		tree[node]= val ; 
		return;
	}
	int mid = (start+end)/2; 
	
	if(idx<=mid)
	{
		_update(node*2+1, start, mid, idx, val);
	}
	else
	_update(node*2+2, mid+1, end , idx, val);
	
	tree[node]= max(tree[node*2+1],tree[node*2+2]);
}
int32_t main(){
	ll n,k ;
	scanf("%lld",&n) ;

	for(int i=0;i<n;i++){
		scanf("%lld",&h[i]) ;
	}
	for(int i=0;i<n;i++)
		scanf("%lld",&a[i]) ;	
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		ll tmp = a[i]+ query(0,0,n-1,0,h[i]-1) ;
		if(tmp > x[h[i]])
		_update(0,0,n-1,h[i],tmp) ;
		ans = max(ans,tmp) ;
	}
	printf("%lld\n", ans) ; 	
}




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

using namespace std;

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

    long long a, b;
    cin >> a >> b;

    auto factorize = [](long long n) {
        set<long long> res;
        long long d = 2;
        while (d * d <= n) {
            while (n % d == 0) {
                n /= d;
                res.insert(d);
            }
            d++;
        }
        if (n > 1) {
            res.insert(n);
        }
        return res;
    };

    set<long long> s1 = factorize(a);
    set<long long> s2 = factorize(b);
    vector<long long> common;
    set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), back_inserter(common));
    cout << common.size() + 1 << '\n';

    return 0;
}

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

using namespace std;

int N, L;
string S[100];

void solve() {
    sort(S, S + N);
    string a;
    for (int i = 0; i < N; ++i) {
        a += S[i];
    }
    cout << a + '\n' << endl;
}

int main() {
    cin >> N >> L;
    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<cmath>
int main(){
	
	std::uint32_t n;
	std::cin >> n;


	std::uint64_t ans_{};

	for( std::uint32_t ci{ 1 }; ci < n; ++ci ) {
		const auto ab_ = n - ci;
		std::uint32_t max_ = std::sqrt( ab_ );
		for( std::uint32_t ai{ 1 }; ai <= max_; ++ai )
		{
			if( ab_ % ai != 0 )
				continue;

			ans_ += ab_ / ai == ai ? 1 : 2;
		}
	}
	std::cout << ans_ << "\n";
	return 0; 
}

Measured memory_bytes: 3192
#include<stdio.h>

int main(){

long H;
long ans=1;
scanf("%ld",&H);
int div_counter=0;

if (H==1)
{
  printf("%ld",ans);
}else
{
  while (H>1)
  {
    H /= 2;
    div_counter++;
  }

  for (int i = 0; i < div_counter+1; i++){ans *= 2; }

  printf("%ld",ans-1);  
}

return 0;

}

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

int main() {
  int N,a = 0;
  cin >> N;
  vector<int> A(N),B(N),C(N-1);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N-1; i++) {
    cin >> C.at(i);
  }
  for (int i = 0; i < N; i++) {
    a += B.at(i);
  }
  for (int i = 0; i < N-1; i++) {
    if (A.at(i) + 1 == A.at(i+1)){
      a += C.at(A.at(i) - 1);
    }
  }
  cout << a << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
#diverta2019 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        if n - i*r - j*g >= 0:
            if (n - i*r - j*g) % b == 0:
                ans += 1
print(ans)


Measured memory_bytes: 40940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        c(N);
    }
    private long pow(int base, int count) {
        if (count == 0) {
            return 1;
        }
        if (count % 2 == 1) {
            return base * pow(base, count-1);
        }
        long t = pow(base, count / 2);
        return t * t;
    }
    public void c(long N) {
        int len = 0;
        for (len = 1; len < 12; len++) {
            long t = pow(26, len);
            if (N <= t) {
                N -= 1;
                break;
            }
            N -= t;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            int t = (int) (N % 26);
            sb.append((char)(t + 'a'));
            N /= 26;
        }
        System.out.println(sb.reverse().toString());
    }
}


Measured memory_bytes: 35784
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

long long n,m,v,p;
vector<long long> a;

bool can(int id)
{
	//cout << id << endl;
	if(n-id<=p)return true;
	vector<long long> b=a;
	long long vv=v-(id+1);
	vv-=(p-1);
	b[id]+=m;
	if(vv<=0)
	{
		bool flg=false;
		if(b[n-p]<=b[id])flg=true;
		return flg;
	}
	else
	{
		bool flg=false;
//		for(int i=0;i<1000000000;i++)vv=vv;
//		for(int i=abs(vv);i<p;i++)
//			if(b[n-1-i]<=b[id]+m)flg=true;

		if(b[n-p]>b[id])return false;
		long long cnt=m*vv;
		for(int i=id+1;i<=n-p;i++)
		{
			cnt-=min(max((long long)0,b[id]-b[i]),m);
		}
		return (cnt<=0);
	}
	return true;
}

int main()
{
	cin >> n >> m >> v >> p;
	a=vector<long long>(n);
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a.begin(),a.end());
	/*
	for(int i=0;i<n;i++)
		cerr << a[i] << (i==n-1 ? "\n":" ");
	*/
	int cnt=0;
	if(can(0))
	{
		cout << n << endl;
		return 0;
	}
	int ng=0,ok=n;
	int mid;
	while(abs(ok-ng)>1)
	{
		mid=(ok+ng)/2;
		if(can(mid))
			ok=mid;
		else
			ng=mid;
		//cout << ng << " " << ok << endl;
	}

	cout << n-ok << endl;
}

Measured memory_bytes: 1920
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		long[][] dp=new long[s.length()+1][2];
		dp[s.length()][1]=11;
		for(int i=s.length()-1; i>=0; i--){
			if(s.charAt(i)=='9'){
				dp[i][0]=dp[i+1][0]+(s.charAt(i)-'0');
				dp[i][1]=Math.min(dp[i+1][0]+11-(s.charAt(i)-'0'),dp[i+1][1]);
			}else{
				dp[i][0]=Math.min(dp[i+1][0]+(s.charAt(i)-'0'),dp[i+1][1]+(s.charAt(i)-'0'));
				dp[i][1]=Math.min(dp[i+1][0]+11-(s.charAt(i)-'0'),dp[i+1][1]+9-(s.charAt(i)-'0'));
			}
		}
		System.out.println(Math.min(dp[0][0],dp[0][1]));
	}
}


Measured memory_bytes: 72392
#include <bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0); cout.tie(0);
	ios::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;

	priority_queue<pair<long long,int>> v;
	for(int i=0; i<n; ++i){
		int a;
		cin >> a;
		v.push(make_pair(a,1));
	}
	for(int i=0; i<m; ++i){
		int b, c;
		cin >> b >> c;
		v.push(make_pair(c,b));
	}
	
	long long ans=0;
	int cnt=0;
	for(int i=0; i<n+m && cnt<n; ++i){
		auto z=v.top();
		v.pop();
		if(cnt+z.second>=n){
			ans += z.first*(n-cnt);
			break;
		}
		ans += z.first*z.second;
		cnt += z.second;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include <stdio.h>
int main(void){

    int H,W,i,j;

    while(1){
        scanf("%d", &H);
        scanf("%d", &W);
     
         if(H==0 && W==0){
             break;
         }
         
        for ( i = 0; i < H; i++ ){
            for ( j = 0; j < W; j++ ){
                 printf("#");
            }
            printf("\n");
        }
    printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2052
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b;
    int ans=0;
    if(a>b){
        ans+=a;
        a--;
    }
    else{
        ans+=b;
        b--;
    }
    if(a>b){
        ans+=a;
        a--;
    }
    else{
        ans+=b;
        b--;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

const int MOD = 1000000007;

int main(){
  int n; cin >> n;
  vector<string> s(2);
  rep(i,2) cin >> s[i];
  
  ll ans = 1;
  bool vertical = false;
  rep(i,n){
    if(s[0][i]==s[1][i]){//ドミノが縦のケース
      if(i==0){
        ans *= 3;
      }else if(vertical){//前が縦だった場合
        ans *= 2;
      }else{
        ans *= 1;
      }
      vertical = true;
    }else{//ドミノが横のケース
      if(i==0){
        ans *= 6;
      }else if(vertical){
        ans *= 2;
      }else{
        ans *= 3;
      }
      vertical = false;
      i++;
    }
    ans %= MOD;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    if(s[0]=='A'){
        if(s.indexOf('C') in 2 until s.length-1){
            if((s.substring(1,s.indexOf('C'))+s.substring(s.indexOf('C')+1)).all { it.isLowerCase() }){
                println("AC")
                return
            }
        }
    }
    println("WA")
}

Measured memory_bytes: 33780
#include<bits/stdc++.h>
using namespace std;
int a, b;
int main(){
  cin >> a >> b;
  if(a == 1) a+=100;
  if(b == 1) b+=100;
  if(a>b) cout << "Alice" << endl;
  else if(a==b) cout << "Draw" << endl;
  else cout << "Bob" << endl;
  return 0;
  }

Measured memory_bytes: 256
N = int(input())
L = [int(x) for x in input().split()]
L = sorted(L)

cn = 0
for k in range(N-2):
    a = L[k]
    for l in range(k+1,N-1):
        b = L[l]
        for m in range(l+1,N):
            c = L[m]
            if a + b > c and a != b and b != c and c != a:
                cn += 1

print(cn)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int d[200005][2] = {}, n = (int)s.length();
    if (n == 1) {cout << 1; return 0;}
    d[0][0] = 1; d[0][1] = -890328;
    if (s[0] != s[1]) d[1][0] = 2;
    else d[1][0] = -890328;
    d[1][1] = 1;
    for (int i = 2; i < n; i++) {
        if (s[i] == s[i - 1]) {
            d[i][0] = d[i - 1][1] + 1;
            d[i][1] = max(d[i - 2][0], d[i - 2][1]) + 1;
        } else {
            d[i][0] = max(d[i - 1][0], d[i - 1][1]) + 1;
            d[i][1] = max(d[i - 2][0], d[i - 2][1]) + 1;
        }
    }
    cout << max(d[n - 1][0], d[n - 1][1]);
    /*
    vector<int> a;
    int c = 1, z = 0;
    cin >> s;
    for (int i = 1; i < s.length(); i++) {
        if (s[i] == s[i - 1]) c++;
        else a.push_back(c), c = 1;
    }
    a.push_back(c);
    for (int i : a) {
        if (i % 3 == 0) z += i / 3 * 2;
        else z += i / 3 * 2 + 1;
    }
    cout << z << '\n';
    //1 2 12 121 212 1212 12121
    //1 1 2 3 3 4 5 5 6
     */
}


Measured memory_bytes: 2704
N = int(input())
A = list(map(int,input().split()))
if N == 1:
  print(1)
  exit()
ans = 0
i = 0
while i < N-1:
  ans += 1
  tag = A[i]
  if tag == A[i+1]:
    while tag == A[i+1]:
      i += 1
      if i >= N - 1:
        break
  if tag < A[i+1]:
    #単調非減少
    while tag <= A[i+1]:
      tag = A[i+1]
      i += 1
      if i >= N - 1:
        break
    i += 1
    if i == N - 1:
      ans += 1
  else:
    #単調非増加
    while tag >= A[i+1]:
      tag = A[i+1]
      i += 1
      if i >= N - 1:
        break
    i += 1
    if i == N - 1:
      ans += 1
print(ans)

Measured memory_bytes: 14480
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var H = int.Parse(Console.ReadLine());
            var W = int.Parse(Console.ReadLine());
            Console.WriteLine((N - H + 1) * (N - W + 1));
        }

    }
}
//A

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

int main() {
	int c[3][3];
	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < 3;j++) {
			cin >> c[i][j];
		}
	}
	bool ans = true;
	int a,b,d;
	a = c[0][1]-c[0][0];
	b = c[1][1]-c[1][0];
	d = c[2][1]-c[2][0];
	if (!(a==b&&b==d)) ans = false;
	a = c[0][2]-c[0][1];
	b = c[1][2]-c[1][1];
	d = c[2][2]-c[2][1];
	if (!(a==b&&b==d)) ans = false;
	a = c[1][0]-c[0][0];
	b = c[1][1]-c[0][1];
	d = c[1][2]-c[0][2];
	if (!(a==b&&b==d)) ans = false;
	a = c[2][0]-c[1][0];
	b = c[2][1]-c[1][1];
	d = c[2][2]-c[1][2];
	if (!(a==b&&b==d)) ans = false;
	if (ans) {cout << "Yes" << endl;}
	else {cout << "No" << endl;}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

ll prim(vector<vector<pll>> &g) {
  ll total = 0;
  vector<bool> used(g.size(), false);
  priority_queue<pll, vector<pll>, greater<pll>> que;
  que.emplace(0, 0);
  while (!que.empty()) {
    auto p = que.top();
    que.pop();
    if (used[p.second]) continue;
    used[p.second] = true;
    total += p.first;
    for (auto &e : g[p.second]) {
      que.emplace(e.second, e.first);
    }
  }
  return total;
}

int main() {
  //
  ll n;
  cin >> n;
  vector<pll> pos;
  vector<pll> xs, ys;
  vector<vector<pll>> g(n);
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    pos.emplace_back(x, y);
    xs.emplace_back(x, i);
    ys.emplace_back(y, i);
  }
  sort(ALL(xs));
  sort(ALL(ys));
  for (int i = 0; i < n - 1; i++) {
    ll x1 = xs[i].second;
    ll x2 = xs[i + 1].second;
    ll y1 = ys[i].second;
    ll y2 = ys[i + 1].second;
    ll dx = min(abs(pos[x1].first - pos[x2].first),
                abs(pos[x1].second - pos[x2].second));
    ll dy = min(abs(pos[y1].first - pos[y2].first),
                abs(pos[y1].second - pos[y2].second));
    g[x1].emplace_back(x2, dx);
    g[x2].emplace_back(x1, dx);
    g[y1].emplace_back(y2, dy);
    g[y2].emplace_back(y1, dy);
  }
  cout << prim(g) << endl;
  return 0;
}


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

#define F first
#define S second
#define pb push_back
#define ld  double
#define ll long long
#define int long long


using namespace std;

const int MAXN = 333  , MOD = 1e9 + 7 , sq = 333  ;

int dp[MAXN][MAXN][MAXN] ;

int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   int n , m ;
   cin >> n >> m ;
   dp[n][0][0] = 1 ;

   for(int k = 1 ; k <= m ;  k ++ )
   {
       for(int i = 1 ; i <= n ; i ++ )
       {
           for(int j = 0 ; i + j <= n ; j ++ )
           {
               dp[i][j][k] = (i*dp[i+j][0][k-1]+j*dp[i][j][k-1]+(n-i-j)*dp[i][j+1][k-1]) % MOD ;
      //         cout<<i<<' '<<j<<' '<<k << ' '<<dp[i][j][k]<<'\n';
           }
       }
   }

   cout<<dp[1][0][m] ;


}


Measured memory_bytes: 118784
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    auto f = [](int a, int b, int c){ return c >= a && c <= b;};
    cout << (f(a,b,c) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define num(a) a-'0'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	string s;
	cin>>s;
	int ans=0;
	int h=0;
	for(int i=0;i<3;i++){
		if(s[i]=='R'){
			h++;
		}
		else{
			maxs(ans,h);
			h=0;
		}
	}
	maxs(ans,h);
	cout<<ans<<ln;
}	

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


Measured memory_bytes: 3608
#include <stdio.h>

int main(void) {
	int N;
	char S[128];
	int i;
	int minKakko, kakko;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%127s", S) != 1) return 1;
	minKakko = kakko = 0;
	for (i = 0; i < N && S[i] != '\0'; i++) {
		if (S[i] == '(') kakko++;
		else if (S[i] == ')') kakko--;
		if (kakko < minKakko) minKakko = kakko;
	}
	if (minKakko < 0) {
		for (i = minKakko; i < 0; i++) putchar('(');
	}
	fputs(S, stdout);
	if (kakko - minKakko > 0) {
		for (i = 0; i < kakko - minKakko; i++) putchar(')');
	}
	putchar('\n');
	return 0;
}

/*

'(' は辞書順の比較の時に前の文字 → なるべく前に集めると吉
')' は辞書順の比較の時に前の文字 → なるべく後ろに集めると吉

*/


Measured memory_bytes: 128
def main():
    n,m,x = map(int,input().split())
    costs = [0]+[0] * (n+1)
    a = list(map(int,input().split()))
    for i in a:
        costs[i] = 1
    left = sum(costs[1:x])
    right = sum(costs[x+1:n+1])
    print(min(left,right))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

class Union_Find {
    public:
    std::vector<int> par;
    Union_Find() {}
    Union_Find(int n){
        par.resize(n, 0);
        for(int i = 0; i < n; i++){
            par[i] = i;
        }
    }

    void simplify(int x) {
        std::vector<int> path;
        while (par[x] != x) {
            path.push_back(x);
            x = par[x];
        }
        for (int p : path) {
            par[p] = x;
        }
    }
    
    int find(int x){
        simplify(x);
        return par[x];
    }
    
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x != y) {
            par[y] = x;
            // 改造する時は「根になっているノードの親を変更する」という原則が守られていることに注意。
        }
    }
};

const int MAX = 100050;
const int MAX_N = 200050;
const int MAX_K = 100050;

int N, M;
int K[MAX];
std::vector<int> L[MAX];

Union_Find uf = Union_Find(MAX * 2);

int main(int argc, char **argv) {
    std::cin >> N >> M;

    int tmp;
    for (int i = 1; i <= N; i++) {
        std::cin >> K[i];
        for (int j = 1; j <= K[i]; j++) {
            std::cin >> tmp;
            L[i].push_back(tmp);
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j : L[i]) {
            uf.unite(i, N + j);
        }
    }

    for (int i = 1; i <= N; i++) {
        if (uf.find(i) != uf.find(1)) {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }

    std::cout << "YES" << std::endl;

    return 0;
}

Measured memory_bytes: 7548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int64_t i=ini;i<n;i++)
#define _rep(i,ini,n) for(int64_t i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

map<int64_t,int64_t> mp;

int64_t Exponenti(int64_t n, int64_t i){
    int64_t v=0;
    while(n%i==0){
        v++;
        n/=i;
    }
    return v;
}

void Prime(int64_t n){
    int64_t _n=n;
    for(int64_t i=2;i*i<=_n;i++){
        if(n%i==0){
            mp[i]=Exponenti(n,i);
            n/=pow(i,mp[i]);
        }
    }
    if(n!=1) mp[n]++;
}

int main(){
    int64_t N,P; cin>>N>>P;

    Prime(P);

    int64_t ans=1;
    for(auto m:mp){
        ans*=pow(m.first,m.second/N);
    }

    cout<<ans<<endl;
}

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

using namespace std;

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

int N;
bool bump(int x, int y) { return x<0||y<0||N<=x||N<=y; }

int main() {
  
  int Tc = 1;
  while(cin >> N && N) {
    int cnt = 1;
    int dx = 1, dy = -1;
    int x = 0, y = 0;
    int ans[N][N];
    
    for(;;) {
      ans[y][x] = cnt++;
      if(x == N-1 && y == N-1) break;
      x += dx, y += dy;
      if(x < N && y < N) {
        if(dx == -1 && bump(x, y)) { x ++; dx = 1, dy = -1; }
        else if(dx == 1 && bump(x, y)) { y ++; dx = -1, dy = 1; }
      }
      else {
        if(dx == -1 && bump(x, y)) { x += 2, y --; dx = 1, dy = -1; }
        else if(dx == 1 && bump(x, y)) { y += 2, x --; dx = -1, dy = 1; }
      }
    }
    printf("Case %d:\n", Tc++);
    rep(i, N) {
      rep(j, N) printf("%3d", ans[i][j]);
      puts("");
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 1160
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

x, y = inm()
INF = 1 << 50


def solve():
    ans = INF
    if x < y:
        ans = min(ans, y - x)
        if x < 0 and -x <= y:
            ans = min(ans, 1 + y + x)
        if x < 0 and -x > y:
            ans = min(ans, -y - x + 1)
    elif x >= 0:
        if -y >= -x:
            ans = min(ans, 1 + (-y + x) + 1)
        if y >= -x:
            ans = min(ans, y + x + 1)
        else:
            ans = min(ans, -y - x + 1)
    else:
        ans = min(ans, -y - x + 1)
        if -y >= -x:
            ans = min(ans, -y + x + 2)

    return ans


print(solve())


Measured memory_bytes: 9156
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include <cassert>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int n,k;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    int ans = min(n%k,k-n%k);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
  int a,b,c,d;
  scanf("%d%d%d",&a,&b,&c);
  for(a;a<b+1;a++)
    {
      if(c%a==0)d++;
    }
  printf("%d\n",d);
  return 0;
}


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

int main() {
    int k,x; cin>>k>>x;
    if (k==1){
        cout<<x<<endl;
        return 0;
    }
    int n = k - 1;
    int m = k - 1;
    for (int i = 0; i < m; i++){
        cout<<x-n;
        cout<<" ";
        n--;
    }
    cout<<x<<" ";
    for (int i = 0; i < m; i++){
        x++;
        cout<<x<<" ";
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():  
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = [a - 1 for a in A]
    X = K.bit_length()
    to = [[-1] * X for _ in range(N)]
    for i,a in enumerate(A):
        to[i][0] = a
    for i in range(X - 1):
        for j in range(N):
            to[j][i + 1] = to[to[j][i]][i]
    now = 0
    i = 0
    while K > 0:
        if K&1:
            now = to[now][i]
        i += 1
        K >>= 1
    print(now + 1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 202584
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<ll> a(n + 1);
	rep(i, n + 1) cin >> a[i];
	vector<ll> sum(n + 1);
	sum[n] = a[n];
	for (int i = n - 1; i >= 0; i--) sum[i] = sum[i + 1] + a[i];
	bool flag = true;
	vector<ll> cnt(n + 1);
	rep(i, n + 1) {
		ll m = 1;
		if (i != 0) m = (cnt[i - 1] - a[i - 1]) * 2;
		chmin(m, sum[i]);
		if (a[i] > m) flag = false;
		cnt[i] = m;
	}
	if (!flag) cout << "-1\n";
	else {
		ll ans = 0;
		rep(i, n + 1) ans += cnt[i];
		cout << ans << '\n';
	}
}

Measured memory_bytes: 5560
A = sum([list(map(int,input().split()))for _ in range(3)],[])
N = int(input())
b = [int(input()) for _ in range(N)]

f=0
for i in range(9):
	if A[i]in b:f|=1<<i
ans=[v for v in [7,56,73,84,146,273,292,448]if f&v==v]
print('Yes' if ans else 'No')


Measured memory_bytes: 9124
n,m = map(int, input().split())
ans = 0
light = []
for i in range(m):
    light.append(list(map(int, input().split())))
p = list(map(int, input().split()))
for bit in range(1 << n):
    switch = [0 for i in range(n)]
    for j in range(n):
        if (bit >> j & 1):
            #j番目のスイッチがついている
            switch[j] += 1
    flag = True
    for i in range(m):
        count = 0
        for j in light[i][1:]:
            count += switch[j-1]
        if count % 2 != p[i]:
            flag = False
    if flag:
        ans += 1
print(ans)

    


Measured memory_bytes: 42204