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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

ll mod=1000000007;

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

/*  PrimeFact
    init(N): 初期化。O(N log log N)
    get(n): クエリ。素因数分解を求める。O(log n)
 */
template <typename T>
struct PrimeFact {
    vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    map<T, T> get(T n) { // nの素因数分解を求める
        map<T, T> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }

	T divisor_num(T N) {
    	map<T, T> pf = get(N);
    	T ret = 1;
    	for (auto p : pf) {
        ret *= (p.second + 1);
    	}
    return ret;
	}
};



int main() {
    ll n;cin >> n;
    PrimeFact<ll> p(n);
    ll ans=0;
    reps(i,n)ans+=i*p.divisor_num(i);
    cout<<ans;
}

Measured memory_bytes: 81344
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<int> r(R);
    rep(i, R) {
        cin >> r[i];
        --r[i];
    }

    sort(all(r));

    int INF = 1e9+7;
    vec<vec<int>> G(N, vec<int>(N,INF));

    rep(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        --A, --B;
        G[A][B] = C;
        G[B][A] = C;
    }

    rep(i,N) G[i][i] = 0;

    function<void(int)> warshall_floyd = [&](int n) {
        for (int k = 0; k < n; k++) {            // 経由する頂点
            for (int i = 0; i < n; i++) {        // 始点
                for (int j = 0; j < n; j++) {    // 終点
                    G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
                }
            }
        }
    };
    warshall_floyd(N);

    ll ans = INF;
    do {
        ll tmp = 0;
        rep(i, R - 1) {
            tmp += G[r[i]][r[i+1]];
        }
        ans = min(ans,tmp);
    } while (next_permutation(all(r)));


    cout << ans << endl;
}


Measured memory_bytes: 3804
/*input
2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	ll x, y, a, b, c, i, j, k, cr=0, cg=0, cc=0, ret=0;
	cin >> x >> y >> a >> b >> c;
	vector<int> red(a), green(b), colorless(c), merged;
	for(i=0; i<a; i++) cin >> red[i];
	for(i=0; i<b; i++) cin >> green[i];
	for(i=0; i<c; i++) cin >> colorless[i];
	sort(red.begin(), red.end(), greater<>());
	sort(green.begin(), green.end(), greater<>());
	sort(colorless.begin(), colorless.end(), greater<>());
	for(i=0; i<x; i++) merged.emplace_back(red[i]);
	for(i=0; i<y; i++) merged.emplace_back(green[i]);
	for(i=0; i<min(c, x+y); i++) merged.emplace_back(colorless[i]);
	sort(merged.begin(), merged.end(), greater<>());
	for(i=0; i<x+y; i++) ret += merged[i];
	cout << ret << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	while(t--) {
		run();
	}
}


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

int main() {
  int n,k,x;
  cin>> n>>k>>x;
 
  if(n==k&&k==x){
    cout<<1<<endl;
  }
  else if(n==k||k==x||x==n){
    cout<<2<<endl;
  }
  else{
    cout<<3<<endl;
  }
    

}

Measured memory_bytes: 256
//package abc176;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] ip = br.readLine().split(" ");
		
		int N = Integer.parseInt(ip[0]);
		int X = Integer.parseInt(ip[1]);
		int T = Integer.parseInt(ip[2]);
		
		int ans = N/X*T;
		
		if(N%X != 0) ans += T;
		
		System.out.println(ans);
	}
	
}


Measured memory_bytes: 32504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;


//System.out.println();
public class Main implements Runnable { //クラス名はMain

    public static void main(String[] args) {
    	Thread.setDefaultUncaughtExceptionHandler((t,e)->System.exit(1));
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        boolean show = true;
        HashSet<Long> a = new HashSet<Long>();
        for(int i=0; i<n; i++) {
        	long an = sc.nextLong();
        	if(a.contains(an)) {
        		System.out.println("NO");
        		show = false;
        		break;
        	}
        	a.add(an);
        }
        if(show) {
        	System.out.println("YES");
        }
    }
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 53452
#include<bits/stdc++.h>
#define ll long long
#define charToInt(c) (c-'0')
using namespace std;

int main(){
ll int n;
cin>>n;
ll int sum=0;
ll int arr[n];
for(int i=0;i<n;i++)
    cin>>arr[i];
ll int mx=*max_element(arr,arr+n);
for(int i=0;i<n-1;i++){
    if(arr[i]>arr[i+1]){
     int x=arr[i]-arr[i+1];
     arr[i+1]+=x;
     sum+=x;
    }
}
cout<<sum;
return 0;
}


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

const int INF = 1e9;

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

  int n;
  cin >> n;

  vector<int> h(n);
  for(int i=0; i<n; i++) 
    cin >> h[i];

  vector<int> dp(n, INF);
  dp[0] = 0;
  for(int i=0; i<n; i++) {
    for(int j : {i+1, i+2}) {
      if(j < n) {
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
      }
    }
  }

  cout << dp[n-1] << '\n';
  
  return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> C[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    long long sum = 0;
    for(int j = 0; j < N; j++) {
        auto iter_lower = lower_bound(A.begin(), A.end(), B[j]);
        auto iter_upper = upper_bound(A.begin(), A.end(), B[j]);
        long idx_lower = distance(A.begin(), iter_lower);
        long idx_upper = distance(A.begin(), iter_upper);
        //cout << "key 未満の要素数は " << idx_lower << "\n";
        //cout << "key より大きい数の要素数は " << N - idx_upper << "\n";

        auto itera = lower_bound(A.begin(), A.end(), B[j]);
        auto iterc = upper_bound(C.begin(), C.end(), B[j]);
        //auto iterc = lower_bound(C.begin(), C.end(), B[j]);

        //A < B < C

        //cout << "B:" << B[j] << endl;
        //cout << "A:" << *itera << "->" << (itera-A.begin()) << endl;
        //cout << "C: " << *iterc << "->" << (C.end()-iterc) << endl;
        //cout << (itera - A.begin()) * (C.end() - iterc) << endl;
        //sum += (itera - A.begin()) * (C.end() - iterc);
        sum += distance(A.begin(), itera) * (N - distance(C.begin(), iterc));
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string s;
    int n, i, start, end;

    cin >> s;

    n = s.size();

    for(i=0; i<n; i++){
        if(s[i] == 'A'){
            start = i;
            break;
        }
    }

    for(i=n-1; i>=0; i--){
        if(s[i] == 'Z'){
            end = i;
            break;
        }
    }

    cout << end-start+1 << endl;

    return 0;
}

Measured memory_bytes: 640
def main():
    N, M = input().split()
    M = int(M)
    N = int(N)
    A = []
    A = input().split()

    count = 0
    for i in range(M):
        count = count + int(A[i])
    
    if N >= count:
        print(N-count)
    else:
        print(-1)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9536
#include <bits/stdc++.h>
#include<iostream>
#include <ctype.h>
#include <sstream>
using namespace std;
using Graph = vector<vector<int>>;
#define  itn int
using ll=int64_t;
#define rep(i,n) for (int i = 0; i < (int) (n); i++)
using vi = vector<int>;
using vll = vector<ll>;
//GCD
long long gcd(long long a, long long b)
{if(a<b) swap(a,b);
   if (a%b == 0){return(b);}
   else{return(gcd(b, a%b));}
}
//lcm
long long lcm(long long a, long long b)
{return a * b / gcd(a, b);}

long long bikkuri(long long k){
    long long sum = 1;
    for (long long i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
int main() {
vi a(5);int c;
for(int i=0;i<5;i++){cin>>a.at(i);if(a.at(i)==0){c=i+1;break;}}
cout<<c;

}

Measured memory_bytes: 3624
from collections import defaultdict
n = int(input())
S = input()

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i)

ans = 0
for p in range(1000):
    p1, p2, p3 = str(p).zfill(3)

    i0 = -1
    for i in d[p1]:
        if i > i0:
            i1 = i
            break
    else:
        continue

    for i in d[p2]:
        if i > i1:
            i2 = i
            break
    else:
        continue

    for i in d[p3]:
        if i > i2:
            ans += 1
            break


print(ans)


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

using namespace std;

int n,a[2][100];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", a[0] + i);
    for (int i = 0; i < n; i++)
        scanf("%d", a[1] + i);

    for (int i = 1; i < n; i++) {
        a[0][i] += a[0][i-1];
        a[1][n-i-1] += a[1][n-i];
    }
    int m = -1;
    for (int i = 0; i < n; i++)
        m = max(m, a[0][i] + a[1][i]);
    printf("%d\n", m);

    return 0;
}

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

int main()
{
	long int N, Y;
    scanf("%ld%ld",&N,&Y);
    Y /= 1000;
	for (int i = 0; i * 10 <= Y; i++) {
		if ((Y - i * 10 - (N - i)) % 4 == 0) {
			int y = (Y - i * 10 - (N - i)) / 4;
			int z = N - i - y;
			if (y >= 0 && z >= 0) {
				cout << i << ' ' << y << ' ' << z << endl;
				return 0;
			}
		}
	}
	cout << -1 << ' ' << -1 << ' ' << -1 << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

int main(){
    int N,W,ret=0;
    cin>>N>>W;
    vector<int> v(N),w(N);
    rep(i,N)cin>>v[i]>>w[i];
    int dp[110][10100]={0};
    for(int i=0;i<N;i++){//iが品物を表す。
        for(int j=0;j<=W;j++){
            if(j>=w[i])dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
            else dp[i+1][j]=dp[i][j];
        }
    }
    cout<<dp[N][W]<<endl;
    return 0;
}

//a=97,z=122


Measured memory_bytes: 7468
#include<iostream>
#include<algorithm>
#include<string.h>
#include<set>
#include<vector>
using namespace std;
#define INF 1<<21

int N,M;
int a[1005];
int b[1005];
int c[1005];
int dist[105][105];

int main(){
    int ans;
    cin>>N>>M;
    ans=M;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j)dist[i][j]=0;
            else dist[i][j]=1000000000;
        }
    }

    for(int i=0;i<M;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        dist[a[i]][b[i]]=c[i];
        dist[b[i]][a[i]]=c[i];
    }

    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }

    for(int i=0;i<M;i++){
        bool check=0;
        for(int j=0;j<N;j++){
            if(dist[j][a[i]]+c[i]==dist[j][b[i]])check=1;
        }
        if(check)ans--;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int n;
int dp[100002];
int h[100010];

int get(int i) {
    if (i <= 0) {
        return 0;
    }
    if (dp[i] != INT_MAX) {
        return dp[i];
    }
    // cout<<"for i " <<i<<endl;
    dp[i] = min(i - 1 >= 0 ? (abs(h[i] - h[i-1]) + get(i-1)) : INT_MAX, i - 2 >= 0 ? (abs(h[i] - h[i-2]) + get(i-2)) : INT_MAX);
    // cout<<"calc: "<<i<<" "<<dp[i]<<endl;
    return dp[i];
}

int main(void) {
    cin>>n;
    for(int i = 0; i < n; ++i) {
        cin>>h[i];
        dp[i] = INT_MAX;
    }

    cout<<get(n-1);
    // cout<<endl;
    // for (int i = 0; i < n; ++i) {
        // cout<<"i: "<<dp[i]<< " ";
    // }
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
    // 文字列の入力
    string s;
    cin >> s;
    int a;
    for(int i = 0; i < 4 ;i++){
          if(s[i] == '+'){
          a++;
          }else{
          a--;
          }
    }
    // 出力
    cout << a << endl;
    return 0;
}

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

const double EPS = 1.0e-6;
int main(){
	int n;
	cin>>n;
	for(int num=0; num<n; num++){
		double xa, ya, ra, xb, yb, rb;
		cin>>xa>>ya>>ra>>xb>>yb>>rb;
		double dist2 = (xb-xa)*(xb-xa)+(yb-ya)*(yb-ya);
		double dist = sqrt(dist2);
		int ans;
		if(dist+ra < rb){
			ans = -2;
		} else if(dist+rb < ra){
			ans = 2;
		} else if(ra+rb < dist){
			ans = 0;
		} else {
			ans = 1;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int *dp;
int *ar;

void best(int x, int k) {
    if(dp[x-1] == -1)
        best(x-1, k);
    int ans = INT_MAX;
    for(int i = x-1; i >= max(0, x-k); i--)
        ans = min(ans, dp[i] + abs(ar[x] - ar[i]));
    dp[x] = ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    dp = new int[n];
    ar = new int[n];
    for(int i = 0; i < n; i++)
        cin >> ar[i];
    dp[0] = 0;
    dp[1] = abs(ar[0] - ar[1]);
    for(int i = 2; i < n; i++)
        dp[i] = -1;
    best(n-1, k);

    cout << dp[n-1] << "\n";
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

template<int SZ> struct Combo {
    ll fac[SZ+1], ifac[SZ+1];
    
    Combo() {
        fac[0] = ifac[0] = 1;
    	FOR(i,1,SZ+1) {
    	    fac[i] = i*fac[i-1] % MOD;
    	    ifac[i] = inv(fac[i]);
    	}
    }
    
    ll po (ll b, ll p) { return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD; }
    ll inv (ll b) { return po(b,MOD-2); }
    
    ll comb(ll a, ll b) {
        if (a < b || b < 0 || a < 0) return 0;
        ll tmp = fac[a]*ifac[b] % MOD;
        tmp = tmp*ifac[a-b] % MOD;
        return tmp;
    }
};

Combo<1001> Com;

int N, dp[1001], in[1001], A, B, C, D;

ll inv(ll a, ll b) { // 0 < a < b, gcd(a,b) = 1
    a %= b;
    if (a <= 1) return a;
    ll i = inv(b%a,a);
    ll tmp = -((b/a)*i+((b%a)*i)/a) % b;
    if (tmp < 0) tmp += b;
    return tmp;
}

ll ad(ll a, ll b) { return (a+b)%MOD; }
ll sub(ll a, ll b) { return (a-b+MOD)%MOD; }
ll mul(ll a, ll b) { return a*b%MOD; }

void ad(int x) {
    F0R(i,N+1) {
        int num = 1;
        for (int j = 1; j <= D && i-j*x >= 0; ++j) {
            num = mul(num,Com.comb(i-(j-1)*x,x));
            num = mul(num,in[j]);
            if (j >= C) dp[i-j*x] = ad(dp[i-j*x],mul(num,dp[i]));
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> A >> B >> C >> D;
    FOR(i,1,1001) in[i] = inv(i,MOD);
    dp[N] = 1;
    FOR(i,A,B+1) ad(i);
    cout << dp[0];
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N = 200010;
const int P = 1e9+7;
int n,x,y,a,b,fa[N],c[N];
PII p[N];
map<int,PII> M;
map<int,int> M2[N];
map<int,int>::iterator it;
int find(int x){
	if(fa[x]==x) return x;
	c[fa[x]]+=c[x];
	c[x]=0;
	return fa[x]=find(fa[x]);
}
int Pow(int a,int b){
	if(b==0) return 1;
	int ret =Pow(a,b>>1);
	ret=1ll*ret*ret%P;
	if(b&1) ret=1ll*ret*a%P;
	return ret;
}
int fac[N],inv[N];
inline int  com(int n,int m){
	if(n<m) return 0;
	return 1ll*fac[n]*inv[m]%P*inv[n-m]%P;
}
int main(){
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%P;
	inv[N-1] = Pow(fac[N-1],P-2);
	for(int i=N-2;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%P;
	scanf("%d%d%d",&n,&a,&b);
	for(int i = 1;i<=n;i++){
		scanf("%d%d",&x,&y);
		p[i].X = y,p[i].Y =x;
	}
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++)fa[i]=i,c[i]=1;
	int j=-1;
	for(int i=1;i<=n;i++) if(p[i].Y!=p[1].Y) {
		j = i;
		break;
	}
	for(int i =1;i<=n;i++){
		if(i>1){

			if(p[i].X+p[1].X<=b && p[i].Y!=p[1].Y){
				x = find(i), y = find(1);
				fa[x]=y; 
			} else 	if(j!=-1 && p[i].Y!=p[j].Y && p[i].X+p[j].X<=b){
				x = find(i), y = find(j);
				fa[x]=y; 
			}
		}
		if(!M.count(p[i].Y)) M[p[i].Y] = mp(p[i].X,i);
		else{
			if(p[i].X+M[p[i].Y].X<=a){
				x = find(i), y = find(M[p[i].Y].Y);
				fa[x]=y;
			}
		}
	}
	int ans = 1;
	for(int i=1;i<=n;i++){
		find(i);
		M2[fa[i]][p[i].Y]++;
	}	
	for(int i=1;i<=n;i++) if(c[i]){
		int tmp  =c[i];
		for(it = M2[i].begin();it!=M2[i].end();it++){
			ans=1ll*ans*com(tmp,it->Y)%P;
			tmp-=it->Y;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 32256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
//using mint = modint1000000007;
//using mint = modint998244353;

int op(int a, int b){
  return max(a, b);
}
int e(){
  return 0;
}

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  segtree<int,op,e> seg(2000005);
  int base = 1000000;
  for(int i=N-1; i>=0; i--){
    int x = v[i];
    int mn = x-K;
    int mx = x+K;
    int max_len = seg.prod(base+mn, base+mx+1);

    seg.set(base+x, max_len+1);
  }

  cout << seg.prod(0,2000005) << endl;
  
  return 0;
}




Measured memory_bytes: 28880
#include <bits/stdc++.h>
#define PI acos(-1)

using namespace std;
using LL = long long;

constexpr int MAXN = 2e5 + 5;

template <typename T>
inline void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

struct Vec2 {
    Vec2() = default;
    Vec2(LL _x, LL _y) : x(_x), y(_y) {}

    friend inline bool operator<(const Vec2& a, const Vec2& b) {
        return a.x == b.x ? a.y < b.y : a.x < b.x;
    }

    friend inline Vec2 operator-(const Vec2& a, const Vec2& b) {
        return Vec2(a.x - b.x, a.y - b.y);
    }
    /*@return cross product of two Vec2*/
    friend inline LL operator*(const Vec2& a, const Vec2& b) {
        return a.x * b.y - a.y * b.x;  //×
    }
    /*@param a 2D vector @return square norm of the vector*/
    friend inline LL normSquare(const Vec2& a) { return a.x * a.x + a.y * a.y; }
    LL x = 0, y = 0;
} vec[MAXN], cov[MAXN];

LL n, top, ans;

inline void convex() {
    top = 0;
    sort(vec + 1, vec + n + 1);
    for (int i = 1; i <= n; i++) {  //下凸壳
        while (top > 1 && (cov[top] - cov[top - 1]) * (vec[i] - cov[top]) <= 0)
            cov[top--] = Vec2(0, 0);
        cov[++top] = vec[i];
    }
    int up = top;                      //上凸壳起点
    for (int i = n - 1; i > 0; i--) {  //上凸壳
        while (top > up && (cov[top] - cov[top - 1]) * (vec[i] - cov[top]) <= 0)
            cov[top--] = Vec2(0, 0);
        cov[++top] = vec[i];
    }
}

inline LL rotatingCalipers(LL res = 0) {  //旋转卡壳
    convex();
    int up = 1, left = 1, right = 1;
    if (top == 3) return abs(cov[1].x - cov[2].x) + abs(cov[1].y - cov[2].y);
    for (int i = 1; i < top; i++) {
        while (true) {  //寻找对踵点 two polong doubleers
            auto s = cov[i], t = cov[i + 1];
            auto x1 = cov[up], x2 = cov[up + 1];
            res = max(res, abs(x1.x - s.x) + abs(x1.y - s.y));
            res = max(res, abs(x1.x - t.x) + abs(x1.y - t.y));
            res = max(res, abs(x2.x - s.x) + abs(x2.y - s.y));
            res = max(res, abs(x2.x - t.x) + abs(x2.y - t.y));
            LL s1 = abs((s - x1) * (t - x1));
            LL s2 = abs((s - x2) * (t - x2));
            if (s1 <= s2)
                up = up % (top - 1) + 1;  // h1 <= h2
            else
                break;
        }
        res = max(res, abs(cov[i].x - cov[up].x) + abs(cov[i].y - cov[up].y));
        res = max(
            res, abs(cov[i + 1].x - cov[up].x) + abs(cov[i + 1].y - cov[up].y));
    }
    return res;
}

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (LL i = 1; i <= n; i++) cin >> vec[i].x >> vec[i].y;
    cout << rotatingCalipers() << endl;
    return 0;
}

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

using namespace std;
int arr[4];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int a,b;
    cin>>a>>b;
    
    if(a<=5)
        cout<<"0";
    else if(a>=6 && a<=12)
        cout<<b/2;
    else
        cout<<b;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  
  if (S.size() % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  for (int i=0; i<S.size() -1; i += 2) {
    if (S[i] != 'h' || S[i+1] != 'i') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int A, B;
  cin >> A >> B;

  int tmp = 1;  //現在の未使用の差込口の数
  int ans = 0;  //使った電源タップの数
  while (true){
    if (tmp >= B) break;
    tmp += A - 1;
    ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  double p;
  int n;
  while(cin>>p>>n,n){
    double t=sqrt(p);
    int x=0,y=1,u=1e9,v=1;
    for(int i=1;i<n;i++){
      int l=0,r=n+1,m;
      while(l<r){
	m=(l+r)/2;
	if(t<(1.0*m/i))r=m;
	else l=m+1;
      }
      if(x*i<(r-1)*y)x=r-1,y=i;
      if(r!=n+1&&u*i>v*r)u=r,v=i;
    }
    cout<<u<<'/'<<v<<' '<<x<<'/'<<y<<endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 55;
int n,m,tot;
ll dis[maxn][2600],c[maxn],t[maxn];
ll s;
int head[maxn];
struct node
{
    int to,next;
    ll w,cost;
}e[maxn*maxn];
void add(int u,int v,ll w,ll c){
    e[tot].to = v;
    e[tot].w = w;
    e[tot].cost = c;
    e[tot].next = head[u];
    head[u] = tot++;
}
void dijkstra(ll s,ll d[][2600]){
    queue<pair<int,ll> > q;
    int vis[n+5][2600];
    for(int i = 1;i<=n;i++){
        for(int j = 0;j<=2500;j++) dis[i][j] = 0x3f3f3f3f3f3f3f3f,vis[i][j] = 0;
    }
    d[1][s] = 0;
    q.push({1,s});
    while(!q.empty()){
        int cur = q.front().first;
        ll w = q.front().second;
        q.pop();
        //if(vis[cur][w]) continue;
        //vis[cur][w] = 1;
        for(int i = head[cur];~i;i = e[i].next){
            int y = e[i].to;
            ll a = e[i].w,b = e[i].cost;
            if(w>=b && d[y][w - b] > d[cur][w] + a ){
                d[y][w-b] = d[cur][w] + a;
                q.push({y,w-b});
            }
        }
        if(d[cur][min(w + c[cur],(ll)2500)]> d[cur][w] + t[cur]){
            d[cur][min(w + c[cur],(ll)2500)] = d[cur][w] + t[cur];
            q.push({cur,min(w + c[cur],(ll)2500)});
        }
    }
}
int main(){
    scanf("%d%d%lld",&n,&m,&s);
    s = min(s,(ll)2500);
    for (int i = 0; i <=n; ++i) head[i] = -1;
        /* code */
    for (int i = 0; i <m; ++i)
    {
        int u,v;ll a,b;
        scanf("%d%d%lld%lld",&u,&v,&a,&b);
        add(u,v,b,a);
        add(v,u,b,a);
        /* code */
    }
    for(int i = 1;i<=n;i++){
        scanf("%lld%lld",&c[i],&t[i]);
    }
    dijkstra(s,dis);
    for(int i = 2;i<=n;i++){
        ll ans = 0x3f3f3f3f3f3f3f3f;
        for(int j = 0;j<=2500;j++) ans = min(ans,dis[i][j]);
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 5844
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll a; cin>>a;
  ll b; cin>>b;
  ll x; cin>>x;
  ll c,d;
  if(a%x!=0) c=a/x+1;
  else c=a/x;
  d=b/x;
  ll ans=d-c+1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	char A[100][100];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> A[i][j];
		}
	}
	int H[100], W[100];
	for (int i = 0; i < h; i++) {
		int  flag = 0;
		for (int j = 0; j < w; j++) {
			if (A[i][j] == '#')flag = 1;
		}
		if (flag == 1)H[i] = 1;
	}
	for (int j = 0; j < w; j++) {
		int flag = 0;
		for (int i = 0; i < h; i++) {
			if (A[i][j] == '#')flag = 1;
		}
		if (flag == 1)W[j] = 1;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (H[i]==1 && W[j]==1)cout << A[i][j];
		}
		cout << endl;
	}
}

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

using namespace std;

typedef long long ll;

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}






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

ll n;cin>>n;

vl a(n+1);

for(int i=1;i<=n;i++)cin>>a[i];

  ll cnt=0;

for(int i=1;i<n;i++)
{
  if(a[i]==i)
    {
      swap(a[i],a[i+1]);
      cnt++;
    }
    else continue;

}

if(a[n]==n)cnt++;

cout<<cnt<<"\n";


return 0;

}

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

main()
{
    string s; string t;
    cin >> s >> t;
    int a = s.length(); int b = t.length();

    int dp[a+1][b+1];
    for(int i=0;i<=b;i++) dp[0][i]=0;
    for(int i=0;i<=a;i++) dp[i][0]=0;

    for(int i=1;i<=a;i++)
    {
        char x = s[i-1];
        for(int j=1;j<=b;j++)
        {
            char y = t[j-1];

            if(x!=y)
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            else
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
        }
    }

    string ans="";
    int i=a;int j=b;
    while( i>0 && j>0)
    {
        if(dp[i][j]==dp[i][j-1])
        {
            j--;
        }
        else if(dp[i][j]==dp[i-1][j])
        {
            i--;
        }
        else 
        {
            ans=s[i-1]+ans;
            i--;j--;
        }
    }
    //dp[a][b] gives length of LCS
    cout << ans << endl;
}


Measured memory_bytes: 35456
N, X = map(int, input().split())
L = list(map(int, input().split()))
count = 1
d = [0] * (N+3)
for i in range(1,N+1):
  d[i] = d[i-1]+L[i-1]
  if d[i] <= X:
    count += 1
print(count)

Measured memory_bytes: 3060
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7
INF = float("inf")

N,M,P = map(int,(input().split()))
line = []
for i in range(M):
    a,b,c = map(int,(input().split()))
    line.append([a-1,b-1,-c+P])

min_distance = [INF]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする

def Bellman_Ford(S,V,E,distance):
    
    flag = 0
    for _ in range(V):
        update = False
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != INF and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = min_distance[s] + d # 最短距離を上書きする
                update = True
        if not update:
            flag = 1
            break
    return min_distance,flag

def Bellman_Ford2(S,V,E,distance):
    for _ in range(V):
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != INF and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = -INF
                if g == N-1:
                    break
        else:
            continue
        break
    return min_distance

min_distance,flag = Bellman_Ford(1,N,M,line)

if flag == 1:
    ans = min_distance[N-1]
    print(max(-ans,0))
else:
    min_distance = Bellman_Ford2(1,N,M,line)
    ans = min_distance[N-1]
    if ans == -INF:
        print(-1)
    else:
        print(max(-ans,0))

#print(min_distance)


Measured memory_bytes: 75584
#include<cstdio>
#include<cstring>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#define mod 1000000007
using namespace std;
int main(){
    int n,q,s,t,x,d,left,right,mid,cnt=0;
    vector<pair<pair<int,int> ,int> >st;
    multiset<int> ms;
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;i++){
        scanf("%d %d %d",&s,&t,&x);
        st.push_back(make_pair(make_pair(s-x,1),x));
        st.push_back(make_pair(make_pair(t-x,-1),x));
    }
    int it=0;
    sort(st.begin(),st.end());
    for(int i=0;i<q;i++){
        scanf("%d",&d);
        while(it!=st.size()&&st[it].first.first<=d){
            if(st[it].first.second==1){
                ms.insert(st[it].second);
                cnt++;
            }
            else{
                ms.erase(st[it].second);
                cnt--;
            }
            it++;
        }
        if(cnt){
            multiset<int>::iterator ans=ms.begin();
            printf("%d\n",*ans);
        }
        else{
            printf("-1\n");
        }
    }
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define endl '\n'

using namespace std;

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

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	string s;
	int ans=0;
	cin>>s;
	for(int i=0,j=sz(s)-1;i<sz(s)/2;++i,--j){
		ans+=(s[i]!=s[j]);
	}
	cout<<ans<<endl;
	return 0;
}

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

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

  ll n;
  cin >> n;
  string s;
  vector<pair<ll,ll> > p;

  for(ll i=0; i<n; i++) {
    cin >> s;
    ll x=0, d=0;
    for(ll j=0; j<(ll)s.size(); j++) {
      if (s[j]=='(') x++;
      if (s[j]==')') {
        x--;
        d = min(d, x);
      }
    }
    if(x<0) d-=x;
    p.push_back(make_pair(-d,x));
  }
  
  sort(p.begin(), p.end());
  
  ll h=0;
  for(ll i=0; i<n; i++) {
    if(p[i].second>=0) {
      if(h-p[i].first<0) {
        cout << "No" << '\n';
        return 0;
      }
      h += p[i].second;
    }
  }
  for(ll i=n-1; i>=0; i--) {
    if(p[i].second<0) {
      if(h-p[i].first+p[i].second<0) {
        cout << "No" << '\n';
        return 0;
      }
      h += p[i].second;
    }
  }
  if(h!=0) {
    cout << "No" << '\n';
    return 0;
  }
  
  cout << "Yes" << '\n';
  return 0;
}

Measured memory_bytes: 19684
#include<stdio.h>
 
int main(){
     
    int x, a, b, c;
 
    scanf("%d %d %d\n", &a, &b, &c);
 
    if (a > b) {
      x = a;
      a = b;
      b = x;
    }

    if (b > c) {
      x = b;
      b = c;
      c = x;
    }
    
    if (a > b) {
      x = a;
      a = b;
      b = x;
    }

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

 
    return 0;
}

Measured memory_bytes: 1772
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::string s; std::cin >> s;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = s[i] - '1';
    }
    bool one = false;
    for (int i = 0; i < n; i++) one |= a[i] == 1;
    for (int i = 0; i < n; i++) {
        a[i] = one ? a[i] == 1 : a[i] == 2;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        bool even = (((n - 1) | i)^(n - 1)) == 0;
        ans ^= even*a[i];
    }
    if (!one) ans *= 2;
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 5252
import numpy as np

def main():
    H, W = list(map(int, input().split()))
    s = [input() for i in range(H)]
    ans = []
    for row in s:
        ans.append(list(row))
    
    diffs = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
    for y in range(H):
        for x in range(W):
            if s[y][x] == '#': continue
            count = 0
            for dx, dy in diffs:
                if (x + dx < 0) or (x + dx > W - 1) or (y + dy < 0) or (y + dy > H - 1):
                    continue
                if s[y + dy][x + dx] == '#':
                    count += 1
            ans[y][x] = str(count)
    
    for i in range(H):
        print(''.join(ans[i]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 12436
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  string s;
  cin >> s;
  // Sunny, Cloudy, Rainy
  string ans;
  if (s == "Sunny") {
    ans = "Cloudy";
  }
  if (s == "Cloudy") {
    ans = "Rainy";
  }
  if (s == "Rainy") {
    ans = "Sunny";
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[1000];
bool vis[1000];
int main(){
	 int n,k;
	 cin>>n>>k;
	 for(int i=1;i<=k;i++){
			int tp;
			cin>>tp;
			for(int i=1;i<=tp;i++){
				int x;
				cin>>x;
				vis[x]=1;
			}
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			if(!vis[i]) ans++;
		}
		cout<<ans<<'\n';
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m,ans=0; cin >> n >> m;
  M map;
  REP(i,n) {
    int k; cin >> k;
    REP(j,k) {
      int x; cin >> x;
      map[x]++;
    }
  }

  REP(i,31) if (map[i] == n) ans++;
  COUT(ans);
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():

    a, b = map(str, input().split())

    if a == 'H':
        if b == 'H':
            ans = 'H'
        else:
            ans = 'D'

    else:
        if b == 'H':
            ans = 'D'
        else:
            ans = 'H'

    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  ll L,R;
  cin >> L >>R;
  R = min(R,L+2019);
  ll a = 2019;
    ll ans = 100000;
    for(int i = L;i<R;i++){
      for(int j = L+1;j<=R;j++){
        if(i<j){
          ans = min(ans,((i%a)*(j%a))%a);
        }
      }
    }
    cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 2e18
using namespace std;
typedef long long ll;
ll arr[2000005];
int main()
{
    //freopen("in.txt", "r", stdin);
    ll n;
    cin>>n;
    if((n%100)<=(n/100)*5){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(int argc, char**argv){
    string s;
    cin >> s;
    int ans = 0;
    int len = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
            len++;
        }else{
            ans = max(len, ans);
            len = 0;
        }
    }
    ans = max(len, ans);
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
const int inf = 1e9 + 7;

#define nd second
#define st first
#define mp make_pair
#define pb push_back

const int N = 2e5 + 6;
const int logN = 17;

int n, k, x, F[N], a[N], pre[N];

void upd(int x) {
	for(; x < N; x += x & -x)
		F[x]++;
}

int que(int x) {
	int ans = 0;
	for(; x > 0; x -= x & -x)
		ans += F[x];
	return ans;
}

ll get(int x) {
	memset(pre, 0, sizeof pre);
	for(int i = 1; i <= n; i++) {
		if(a[i] > x)
			pre[i] = -1;
		else pre[i] = 1;
		pre[i] += pre[i - 1];
	}
	int T = min(*min_element(pre + 1, pre + n + 1), 0);
	for(int i = 0; i <= n; i++) { pre[i] -= T - 1; }
	memset(F, 0, sizeof F);
	ll cur = 0; upd(pre[0]);
	for(int i = 1; i <= n; i++) {
		cur += que(pre[i] - 1);
		upd(pre[i]);
	} return cur;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int bas = 1, son = 1e9;
	ll look = (n) * (ll) (n + 1) / 2 / 2 + 1;
	while(bas < son) {
		int mid = (bas + son) / 2;
		if(get(mid) >= look) son = mid;
		else bas = mid + 1;
	} cout << bas << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define int long long
using pint = pair<int, int>;

int n;
vector<vector<int>> g (100050); // now : {visit}
int dijkstra (int s, int t) {
    int seen[n][3]; // seen[number][amari] : min time
    // q : {visit,count}
    queue<pint> q;
    rep (i, 0, n) rep (j, 0, 3) seen[i][j] = -3;
    seen[s][0] = 0;
    q.push ({s, 0});

    while (!q.empty()) {
        pint p = q.front();
        q.pop();
        int count = p.second;
        int v = p.first;
        for (auto nv : g[v]) {
            int ncount = (count + 1) % 3;
            if (seen[nv][ncount] == -3) {
                seen[nv][ncount] = seen[v][count] + 1;
                q.push ({nv, ncount});
            }
        }
    }
    return seen[t][0] / 3;
}

signed main() {
    int m;
    cin >> n >> m;
    rep (i, 0, m) {
        int u, v;
        cin >> u >> v;
        g[--u].push_back (--v);
    }
    int s, t;
    cin >> s >> t;
    cout << dijkstra (--s, --t) << "\n";
}

Measured memory_bytes: 11148
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import numpy as np

n,m = map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(m)]

row,col,data = zip(*abc)
L = csr_matrix((data, (row,col)), shape=(n+1,n+1))
_,path = dijkstra(L,directed = False, return_predecessors = True)

s,e = np.where(path>0)
path_use = set(map(tuple,np.vstack([path[s,e],e]).T))

print( m - len(path_use)//2)

Measured memory_bytes: 14392
// https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_e
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn is_zero(a: &Vec<i32>, p: usize) -> bool {
    let n = a.len();
    if a[n - 1] % (p as i32) != 0 {
        return false;
    }
    for i in 1..p {
        let mut sum = 0;
        let mut j = i;
        while j < n {
            sum += a[n - 1 - j];
            j += p - 1;
        }
        if sum.abs() % (p as i32) != 0 {
            return false;
        }
    }
    return true;
}

fn gcd(a: usize, b: usize) -> usize {
    return if a % b == 0 { b } else { gcd(b, a % b) };
}

fn main() {
    input! {
        n: usize,
        a: [i32; n+1]
    };

    let mut g = a[0].abs() as usize;
    for i in 1..n + 1 {
        if a[i] != 0 {
            g = gcd(g, a[i].abs() as usize);
        }
    }

    let mut isp = vec![true; 500000];
    for p in 2..isp.len() {
        if isp[p] {
            let mut pp = p * 2;
            while pp < isp.len() {
                isp[pp] = false;
                pp += p;
            }
            if is_zero(&a, p) {
                println!("{}", p);
            }
            while g % p == 0 {
                g /= p;
            }
        }
    }
    if g >= 2 {
        println!("{}", g);
    }
}


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

using namespace std;

// Prioridade
typedef long long   ll;
typedef pair<ll,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i = a; i < (b); i++)
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (((a)*(b))/__gcd((a), (b)))

// fim da Prioridade
int dp[3010][3010];
string s, t;
int solve(int i ,int j){
	if(i == 0 || j == 0){
		return dp[i][j] = 0;
	}
	if(dp[i][j] != -1)
		return dp[i][j];
	int ans = max(solve(i-1,j-1) + (t[i-1] == s[j-1]),max(solve(i,j-1),solve(i-1,j)));
	return dp[i][j] = ans;
}
void reconstruct(int i, int j){

	if(i == 0 || j == 0){
		return;
	}
	int aux = (t[i-1] == s[j-1]);
	if(dp[i][j] == (dp[i-1][j-1] + aux)){
		reconstruct(i-1,j-1);
		if(aux)
			cout << s[j-1];
	}else if(dp[i][j] == dp[i-1][j]){
		reconstruct(i-1,j);
	}else if(dp[i][j] == dp[i][j-1]){
		reconstruct(i,j-1);
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> s >> t;
	memset(dp,-1,sizeof dp);
	 solve(t.size(),s.size()) ;
	 reconstruct(t.size(),s.size());
	cout << endl;
	return 0;
}


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

#define lint long long
#define P pair<int, lint>

const lint INF = 1E15;

int main() {
    int N, M;
    cin >> N >> M;
    int L[M], R[M];

    int Min = 0, Max = 1000000;

    for(int i = 0 ; i < M; ++i){
        cin >> L[i] >> R[i];
        Min = max(Min, L[i]);
        Max = min(Max, R[i]);
    }

    cout << max(Max - Min + 1, 0) << endl;
    
}


Measured memory_bytes: 1024