akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const ll INF = 1e18 + 10 ; 
const ll MAXN = 1e5 + 10 ; 
ll n , k;
vector<ll> v ; 
vector<ll> dp(MAXN,INF) ; 
ll dfs(int idx){
	if ( idx >= n-1 ){
		return 0 ; 
	}
	ll &res = dp[idx] ; 
	if ( res != INF ) return res ; 
	for(int i=1;i<=k;i++){
		if ( idx+i < n )
			res = min(res,dfs(idx+i) + abs(v[idx]-v[idx+i]));
	}
	return res ; 
}
int main(){
    fastio
    cin >> n >> k; 
    v.resize(n) ; 
    for(ll i=0;i<n;i++){
    	cin >> v[i] ; 
    }
    cout << dfs(0) << endl;
    return 0 ;
}


Measured memory_bytes: 6528
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

ll b_search(ll ){

}

int main(){
    Stream io;
    
    int N, M;
    io.read(N, M);
    int ans = 0;
    for(int i = 1; i * i <= M; i++){
        if(M % i == 0){
            if(M / i >= N) ans = max(ans, i);
            if(i >= N) ans = max(ans, M / i);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3600
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n, a, b = inp
p [a*n,b].min

Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<functional>
#include <tuple>
#include <map>
#include<set>
#include <cmath>
#include <stack>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int n, m, x,a[100],i=0,lcnt=0,rcnt=0;
	cin >> n >> m >> x;
	for (int i = 0;i < m;i++)cin >> a[i];
	while (a[i] < x) {
		lcnt++;
		i++;
	}
	rcnt = m - lcnt;
	cout << min(lcnt, rcnt) << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl

int h,w,n;

int main()
{
	SPEED;	
	cin>>h>>w>>n;
	cout<<(n+max(h,w)-1)/max(h,w)<<endl;
	
	return 0;
}

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

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

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

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

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

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c; cin>>a>>b>>c;
    int ans=0;
    FOR(i,a,b){
        if (c%i==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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


using namespace std;


int main()
{

	string S;
	long long K;
	char ans = '1';

	cin >> S >> K;

	for (int ci = 0; ci < K; ci++) {
		if (S[ci] != '1') {
			ans = S[ci];
			break;
		}
	}

	printf("%c", ans);

    return 0;
}



Measured memory_bytes: 256
n,k,q = map(int, input().split())
b = []
for i in range(n):
    b.append(0)
for i in range(q):
    a = int(input())
    b[a-1] += 1
for i in range(n):
    if b[i] > q - k:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 51104
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> ab(N);
    REP(i, 0, N) cin >> ab[i].first >> ab[i].second;

    sort(ALL(ab));
    priority_queue<int> q;
    int ans = 0, j = 0;
    for (int i = 1; i <= M; i++) {
        while (j < N && ab[j].first <= i) q.push(ab[j++].second);
        if (q.size() == 0) continue;
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;

    set<int> ds;
    rep(i,0,N){
        int di;
        cin >> di;
        ds.insert(di);
    }

    cout << ds.size() << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    vector<vector<int>> tree(n + 1);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }
    queue<pair<int, int>> qa;
    qa.emplace(make_pair(v, 0));
    vector<int> dis_a(n + 1, -1);
    dis_a[v] = 0;
    while (!qa.empty()) {
        auto front = qa.front();
        qa.pop();
        for (auto e: tree[front.first]) {
            if (dis_a[e] < 0) {
                dis_a[e] = front.second + 1;
                qa.emplace(make_pair(e, front.second + 1));
            }
        }
    }

    queue<pair<int, int>> qb;
    qb.emplace(make_pair(u, 0));
    vector<int> dis_t(n + 1, -1);
    dis_t[u] = 0;
    while (!qb.empty()) {
        auto front = qb.front();
        qb.pop();
        for (auto e: tree[front.first]) {
            if (dis_t[e] < 0) {
                dis_t[e] = front.second + 1;
                qb.emplace(make_pair(e, front.second + 1));
            }
        }
    }

    int ans = -1;
    for (int i = 1; i <= n; i++) {
        if (dis_a[i] > dis_t[i]) {
            ans = max(ans, dis_a[i]);
        }
    }

    if (ans == 0) {
        cout << 1 << endl;
    } else {
        cout << ans - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 6784
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100],b[100],cha[200];
int main(){
	int n,m[100];
	while(true){
	cin>>n;
	if(n==0)break;
	for(int i=0;i<n;i++){
		cin>>m[i]>>a[i]>>b[i];
		cha[i*2]=a[i],cha[i*2+1]=b[i];
	}
	sort(cha,cha+n*2);
	bool ok=true;
	int w=0,bef=-1;
	for(int i=0;i<n*2;i++){
		if(bef!=cha[i]){
		for(int j=0;j<n;j++){
		if(cha[i]==a[j])
			w+=m[j];
		if(cha[i]==b[j])
			w-=m[j];
		}
		}
		bef=cha[i];
		if(w>150)
			ok=false;
	}
	if(ok)cout<<"OK"<<endl;
	else cout<<"NG"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,int> P;

int main(){
    int N,Q;cin>>N>>Q;
    map<ll,int> mp;
    vector<P> S,T;vec X,Y(N,0);
    for(int i=0;i<N;i++){
        ll s,t,x;cin>>s>>t>>x;
        S.push_back((P){s-x,i});
        T.push_back((P){t-x,i});
        X.push_back(x);
    }
    sort(S.begin(),S.end());
    sort(T.begin(),T.end());
    int i=0,j=0;
    for(int q=0;q<Q;q++){
        ll D;cin>>D;
        while(S[i].first<=D && i<N){
            Y[S[i].second]++;
            if(Y[S[i].second]==1)mp[X[S[i].second]]++;
            i++;
        }
        while(T[j].first<=D && j<N){
            Y[T[j].second]--;
            if(Y[T[j].second]==0){
                mp[X[T[j].second]]--;
                if(mp[X[T[j].second]]==0) mp.erase(X[T[j].second]);
            }
            j++;
        }
        if(mp.empty())cout<<-1<<endl;
        else{
            auto itr=mp.begin();
            cout<<itr->first<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 23132
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)

vector<int> v;
int main(void){
	lld n;
	scanf("%lld",&n);
	if(n==1){
		printf("0");
		return 0;
	}
	int sz = sqrt(n);
	lld tmp = n;
	for(lld e=2;e<=sz;e++){
		if(tmp%e==0){
			int num = 0;
			while(tmp%e==0){
				tmp/=e;
				num++;
			}
			v.push_back(num);
		}
	}
	if(tmp!=1) v.push_back(1);
	int tot = 0;
	for(int e=0;e<v.size();e++){
		int kk = v[e]*2;
		kk = sqrt(kk);
		int diff = v[e] - ((kk*(kk+1))/2);
		if(diff<0) tot += (kk-1);
		else tot += kk;
	}
	printf("%d\n",tot);
	return 0;
}


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

int main(void) 
{
    string n;
    cin >> n;
    for(char x : n)
    {
        if(x == '7')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long t=1;
    //cin>>t;
    for(long long q=0;q<t;q++){
        string s;
        cin>>s;
        int check=1;
        long long n=s.length();
        for(long long i=0;i<n/2;i++){
            if(s[i]!=s[n-i-1])
                check=0;
            if(s[i]!=s[n/2-i-1])
                check=0;
            if(s[i+n/2+1]!=s[n-i-1])
                check=0;
        }
        if(check)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

D, T, S = MAP()
print("Yes" if T*S >= D else "No")


Measured memory_bytes: 10556
n,k = list(map(int,input().split()))
dp = [i for i in range(n+1)]
for i in range(n):
    dp[i+1] += dp[i]
ans = 0
mod = 10**9+7

for i in range(k,n+2):
    ma = dp[-1] - dp[len(dp)-i-1]
    mi = dp[i - 1]
    if i == n + 1:ma = dp[-1]
    ans += (ma - mi + 1) % mod
    ans %= mod
print(ans)

Measured memory_bytes: 81096
n = int(input())
shougen=[[-1]*(n+1) for _ in range(n+2)]
for i in range(1,n+1):
  a = int(input())
  for j in range(a):
    x,y = map(int, input().split())
    shougen[i][x]=y
 
ans=0
for i in range(2**n):
  f=True
  for j in range(n):
    if i>>j & 1:
      for k,s in enumerate(shougen[j+1][1:],start=0):
        if s == 1 and not i>>k & 1:
          f=False
        if s == 0 and i>>k & 1:
          f=False
  else:
    if f:
      ans=max(ans, str(bin(i)).count("1"))
 
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String... a) {
        Scanner s = new Scanner(System.in);
        String input = s.nextLine();
        int k = Integer.parseInt(input);

        int nOdd = k / 2 + k % 2;
        int nEven = k / 2;
        System.out.print(nOdd * nEven);
    }
}


Measured memory_bytes: 21844
import copy as cp
N = 8
ans = []

def out(M):
    for i in range(N):
        for j in range(N):
            print(M[i][j], end="")
        print("")
    
def DFS(r,c,dp,dn,qn):
    global ans
    if qn == N:
        for h in range(N):
            for w in range(N):
                if r[h] & c[w] & dp[h+w] & dn[w-h+7]:
                    ans.append([h,w])
                    return True
        return False

    for h in range(N):
        for w in range(N):
            if r[h] & c[w] & dp[h+w] & dn[w-h+7]:
                new_r = cp.deepcopy(r)
                new_c = cp.deepcopy(c)
                new_dp = cp.deepcopy(dp)
                new_dn = cp.deepcopy(dn)
                new_r[h],new_c[w],new_dp[h+w],new_dn[w-h+7] = False,False,False,False
                if DFS(new_r,new_c,new_dp,new_dn,qn+1):
                    ans.append([h,w])
                    return True
    return False


def main():
    row = [True]*N
    col = [True]*N
    dp = [True]*(2*N-1)
    dn = [True]*(2*N-1)
    k = int(input())
    MAP = [["." for _ in range(N)] for __ in range(N)]
    for _ in range(k):
        h,w = map(int,input().split())
        MAP[h][w] = "Q"
        row[h] = False
        col[w] = False
        dp[w+h] = False
        dn[w-h+7] = False
    
    DFS(row,col,dp,dn,k+1)

    
    for h,w in ans:
        MAP[h][w] = "Q"

    out(MAP)

main()



Measured memory_bytes: 6356
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}

int main() {	
	int x,y;cin>>x>>y;
	int g=gcd(x,y);
	int ans=x+y-g+1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	int d,t,s;
	cin >>d>>t>>s;
	int nt=d/s;
	if(d%s!=0)nt++;
	if(nt>t)cout <<"No";
	else cout <<"Yes";
	return 0;
}

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

using namespace std;

const int N = 1e6 + 2;
int p[N];

void init() {
	int end = sqrt(N) + 1;
	for (int i = 2; i <= end; ++i) {
		if (!p[i]) {
			for (int j = i + i; j < N; j += i) {
				p[j] = i;
			}
		}
	}
}

int main() {
	int n; cin >> n;
	init();
	long long res = 0;
	for (int i = 1; i < n; ++i) {
		int rem = n - i;
		int cnt, cur = 1;
		
		while (p[rem]) {
			cnt = 1;
			int q = p[rem];
			while (rem % q == 0) {
				++cnt;
				rem /= q;
			}
			cur *= cnt;
		}
		cnt = rem == 1 ? 1 : 2;
		cur *= cnt;
		res += cur;
	}
	cout << res;
	
}

Measured memory_bytes: 7536
#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<algorithm>  
#include<cstdlib>  
#include<queue>  
#include<vector>  
#include<map>  
using namespace std;  
typedef long long LL;  
const int MaxN = 50;  
LL a[MaxN + 5];  
LL cnt[MaxN + 5];  
int n;  
   
int main(){  
    while(~scanf("%d", &n)){  
        for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);  
        LL tot = 0, ans = 0;  
        bool flag = true;  
        while(flag){  
            flag = false;  
            tot = 0;  
            for(int i = 1; i <= n; i++){  
                cnt[i] = a[i] / n;  
                a[i] = a[i] % n;  
                tot += cnt[i];  
            }  
            ans += tot;  
            for(int i= 1; i <= n; i++){  
                a[i] += tot - cnt[i];  
                if(a[i] >= n) flag = true;  
            }  
        }  
        printf("%lld\n", ans);  
    }  
    return 0;  
}  

Measured memory_bytes: 128
#include <iostream>
using namespace std;
static const int MAX = 100;

int main() {
    int A[MAX];
    int n;

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

    //??????????????????
    cout << A[0] << flush;
    for(int i = 1; i < n; ++i) {
        cout << " " << A[i] << flush;
    }
    cout << endl;

    int v, j;
    for(int i = 1; i < n; ++i) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        cout << A[0] << flush;
        for(int index = 1; index < n; ++index) {
            cout << " " << A[index] << flush;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<pair<int64_t,int64_t>>C(N);
  for(int i=0;i<N;i++){
  int64_t A,B;
    cin>>A>>B;
    pair<int64_t,int64_t>c(B,A);
    C.at(i)=c;
  }sort(C.begin(),C.end());
  bool ans=true;
  int64_t sum=0;
  for(int i=0;i<N;i++){
    sum+=C.at(i).second;
    if(C.at(i).first<sum){
    ans=false; break;
    }
  }if(ans)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
   return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
int main() {
    int N, M, K[30], A[30][30], cnt1[30] = {0}, cnt2 = 0;
    scanf("%d %d%*c", &N, &M);
    for (int i = 0; i < N; i++) {
        scanf("%d%*c", &K[i]);
        for (int j = 0; j < K[i]; j++) {
            scanf("%d%*c", &A[i][j]);
            cnt1[A[i][j]-1]++;
        }
    }
    for (int i = 0; i < M; i++) if (cnt1[i] == N) cnt2++;
    printf("%d\n", cnt2);
    return 0;
}

Measured memory_bytes: 128
a, b, c, d = input()
for i in range(2**3):
    ls = ['+','+','+']
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = '-'
    if eval(a + ls[0] + b + ls[1] + c + ls[2] + d) == 7:
        print(a + ls[0] + b + ls[1] + c + ls[2] + d + '=7')
        exit()

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    string X;
    cin >> X;
    int cs=0,cnt=0;
    int s=X.size();
    rep (i,s){
        if (X[i]=='S'){
            cs++;
        }
        else if (cs>0){
            cnt++;
            cs--;
        }
    }
    int ans=s-2*cnt;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, cnt[10];

int main() {
	for (int i = 0; i != 4; ++i) {
		cin >> N;
		cnt[N]++;
	}
	if (cnt[1] * cnt[9] * cnt[7] * cnt[4])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def ssum(l, r):
    return (r + l) * (r - l + 1) // 2

def solve():
    n, k = MI()
    B = [i for i in range(0, n+1)]
    # print(B)
    mod = 1_000_000_007

    cnt = 0
    for i in range(k, n+2):
        mn = ssum(B[0], B[i-1])
        mx = ssum(B[n-i+1], B[-1])
        # print(mn, mx)
        cnt = cnt + mx - mn + 1
    print(cnt % mod)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 16940
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using i64 = long long;

int main() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;
    std::sort(a.begin(), a.end());
    const int ret = std::accumulate(a.begin(), a.begin() + k, 0);
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 string n;
 cin >> n;
 if(n[0]==n[1]&&n[1]==n[2]){
     cout << "Yes" << endl;
 }else if(n[1]==n[2]&&n[2]==n[3]){
     cout << "Yes" << endl;
 }else{
     cout << "No" << endl;
 }
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,n; cin>>n;
  vector<int> b(n,0);
  for(int i=0; i<n-1; ++i){ cin>>a; ++b[a-1];}
  for(int i=0; i<n; ++i) cout<<b[i]<<endl;
  return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;



int main(void) {
  ll a, b;
  cin >> a >> b;
  
  ll k=b-a;
  pt(k*(k-1)/2-a);
  
}






Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    while(1){
    int n,k;
    cin >> n >> k;
    if(n==0 && k==0){
        break;
    }
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int s=0;
    int m=0;

    while(s+k-1<n){
        int cm=0;
        for(int j=0; j<k; j++){
            cm+=a[s+j];
        }
    if(cm>m){
        m=cm;
    }
    s++;
    }
    cout << m << endl;
    }
}


Measured memory_bytes: 2992
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var nums = GetNumbersInt();
                if (nums[0] == 0 && nums[1] == 0)
                {
                    break;
                }

                var row = new string(Enumerable.Repeat('#', nums[1]).ToArray());
                for (int i = 0; i < nums[0]; i++)
                {
                    Console.WriteLine(row);
                }

                Console.WriteLine();
            }
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<long> GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
        }

        static List<double> GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

Measured memory_bytes: 10072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N, M, X, Y;
vector<int> vx;
vector<int> vy;

void judge() {
    int x_max = X, y_min = Y;
    int vx_size = vx.size();
    int vy_size = vy.size();

    for (int i = 0; i < vx_size; i++) {
        x_max = max(x_max, vx[i]); 
    }

    for (int i = 0; i < vy_size; i++) {
        y_min = min(y_min, vy[i]); 
    }

    if (x_max < y_min) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
}

int main() {
    cin >> N >> M >> X >> Y;

    while (N--) {
        int x;
        cin >> x;
        vx.push_back(x);
    }

    while (M--) {
        int y;
        cin >> y;
        vy.push_back(y);
    }

    judge();
}

Measured memory_bytes: 256
k = int(input())

from collections import deque
queue = deque([1,2,3,4,5,6,7,8,9])

count = 0

while queue:
    now = queue.popleft()
    count += 1
    if count == k:
        print(now)
        exit()
    now_ = now%10
    if now_ == 0:
        queue.append(10*now+now_)
        queue.append(10*now+now_+1)
    elif now_ == 9:
        queue.append(10*now+now_-1)
        queue.append(10*now+now_)
    else:
        queue.append(10*now+now_-1 )
        queue.append(10*now+now_)
        queue.append(10*now+now_+1)

Measured memory_bytes: 11944
n = int(input())
x = list(map(int,input().split()))
x.sort()
y = []
minimum=x[0]
maximum=x[n-1]
s = 0
for i in range(minimum,maximum+1):
  for j in range(0,n):
    s = s + (x[j]-i)**2
  y.append(s)
  s = 0
  
lenlen = len(y)  
for k in range(1,lenlen):
  if y[k-1]<=y[k]:
    y[k] = y[k-1]

print(y[lenlen-1])


Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    ll res=a/b;
    if(a%b!=0)res++;
    cout<<res<<endl;
    return 0;
    }


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

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s;
  std::cin >> s;
  int s_len = (int)s.size();
  std::vector<int> n_children(s_len, 1);
  std::vector<bool> is_loop(s_len, false);
  std::vector<int> group(s_len, -1);
  int g = 0;
  for (int i = 0; i < s_len; ++i) {
    group[i] = g;
    if (s[i] == 'L' && s[i - 1] == 'R') {
      is_loop[i] = true;
      is_loop[i - 1] = true;
    }
    if (s[i] == 'L' && s[i + 1] == 'R') {
      ++g;
    }
  }
  std::map<int, int> dict;
  for (int i = 0; i < s_len; ++i) {
    if ( is_loop[i] ) {
      dict[group[i]] = i;
      ++i;
    }
  }
  for (int i = 0; i < s_len; ++i) {
    if (is_loop[i]) {
      continue;
    }
    else {
      --n_children[i];
      int idx = dict[group[i]];
      if (s[i] == 'L') {
        int d = std::abs(i - idx - 1);
      	if (d % 2 == 0) {
          ++n_children[idx + 1];
        }
        else {
          ++n_children[idx];
        }
      }
      else {
        int d = std::abs(i - idx);
        if (d % 2 == 0) {
          ++n_children[idx];
        }
        else {
          ++n_children[idx+1];
        }
      }
        
    }
  }
  for (int i = 0; i < s_len; ++i) {
    std::cout << n_children[i] << " ";
  }
}

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

int main() {
  
  int n;
  cin >> n;
  
 cout << (n-1) / 111 * 111 + 111 << endl;

}


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

int main(){
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    
    int right = 0;
    ll ans = 0;
    ll a_xor_sum = 0, a_sum = 0;
    for(int left = 0; left < n; ++left){
        while(right < n && (a_sum+a[right]) == (a_xor_sum^a[right])){
            a_sum += a[right];
            a_xor_sum ^= a[right];
            right++;
        }
        ans += right - left;
        a_sum -= a[left];
        a_xor_sum ^= a[left];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    private void solve(){
        int x = in.nextInt();
        if(x<1200){
            out.print("ABC");
            return;
        }
        out.print("ARC");
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

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

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 22868
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double INF = 1e10;

void gaussian_elimination(vector<vector<double> > &mat){
    int n = mat.size();
    for(int i=0; i<n-1; i++){
        for(int j=i; j<n; j++){
            for(int k=n-1; k>=i; k--){ 
                mat[j][k] /= mat[j][i];
            }
        }
        for(int j=i+1; j<n; j++){
            for(int k=i; k<n; k++){
                mat[j][k] -= mat[i][k];
            }
        }
    }
}

int main(){
    while(1){
        int d;
        cin >> d;
        if(d==0) break;

        vector<vector<double> > mat(d+3, vector<double>(d+2));
        for(int i=0; i<d+3; i++){
            int num = 1;
            for(int j=0; j<=d; j++){
                mat[i][j] = num;
                num *= i;
            }
            cin >> mat[i][d+1];
        }

        double minerror = INF;
        int ans = -1;
        for(int i=0; i<d+3; i++){
            vector<vector<double> > tmat;
            for(int j=0; j<d+3; j++){
                if(i==j) continue;
                tmat.push_back(mat[j]);
            }
            gaussian_elimination(tmat);
            if(abs(tmat[d+1][d+1]) < minerror){
                minerror = abs(tmat[d+1][d+1]);
                ans = i;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1LL)
#define set(x,i) (x|(1LL<<i))
#define unset(x,i) (x&~(1LL<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 200005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() ll t;cin>>t;while(t--)
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}

int main()
{
  boost
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);    
    freopen("output.txt", "w", stdout);
#endif 
    ll n,k,i;
    cin>>n>>k;
    ll a[n];
    REP(i,n)
    cin>>a[i];
    sort(a,a+n);
    ll s=0;
    REP(i,k)
    s+=a[i];
    cout<<s;
 }


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

using namespace std;

int main()
{
    int s=0;
    char a[10];
    scanf("%s",a);
    int i,l;
    l=strlen(a);
    for(i=0;i<l;i++)
    {
        if(a[i]=='-')
            s--;
        else
            s++;
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 256
object Main{
  def main(args: Array[String]) : Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val hash = scala.collection.mutable.HashMap.empty[String,Long].withDefault(_ => 0.toLong)
    (1 to n)
      .map{_ => sc.next.split("").sorted.mkString("")}
      .foreach(s => hash(s) = hash(s)+1)

    val result = hash.values.map(v => v * (v - 1) /2).sum
    println(result);
  }
}



Measured memory_bytes: 119332
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<1+2+3-a-b;



}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c[][] = new int[2][100005];
		for (int i=0;i<n;i++)
			c[i%2][sc.nextInt()]++;
		
		if (Maxid(c[0])!=Maxid(c[1]))
			System.out.println(Max(c[0])+Max(c[1]));
		else {
			int a = Max(c[0])+Max2(c[1]);
			int b = Max(c[1])+Max2(c[0]);
			
			if (a<b) System.out.println(a);
			else System.out.println(b);
		}
		
		
	}
	
	private static int Maxid(int[] a) {
		int max = 0;
		int id = 0;
		for (int i=0;i<a.length;i++) {
			if (max<a[i]) {
				max=a[i];
				id = i;
			}
		}
		
		return id;
	}

	private static int Max(int[] a) {
		int max = 0;
		int sum= 0;
		for (int i=0;i<a.length;i++) {
			if (max<a[i]) max=a[i];
			sum+=a[i];
		}
		
		return sum-max;
	}
	
	private static int Max2(int[] a) {
		int []cl = a.clone();
		Arrays.sort(cl);
		
		int max2 = cl[cl.length-2];
		int sum= 0;
		for (int i=0;i<a.length;i++) {
			sum+=a[i];
		}
		
		return sum-max2;
	}
}


Measured memory_bytes: 64184
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


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

  int n;
  cin>>n;
  vi a(n);
  rep(i,n){
    cin>>a[i];
  }
  int ans=1;
  int t=0;


  rep(i,n){
    if((i-t)*2>=a[i]){
      ans*=(i+1-t);
      ans%=M;
      t++;
    } 
  }

  //cout<<ans<<endl;

  FOR(i,1,n-t+1){
    ans*=i;
    ans%=M;
  }
  //cout<<t<<endl;
  cout<<ans<<endl;


}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#define N 100000

typedef struct {
  int p;
  int q;
  int *z;
}Node;

int rec(Node*,int,int);

int main(){
  int num,i,j,k,l;
  Node node[N];

  scanf("%d",&num);

  for( i = 0 ; i < num ; i++ ) {
    node[i].p = -1;
  }

  for( i = 0 ; i < num ; i++ ) {
    scanf("%d",&l);
    scanf("%d",&node[l].q);
    node[l].z = (int *) malloc(sizeof(int) * node[l].q);

    for( j = 0 ; j < node[l].q ; j++ ) {
      scanf("%d",&node[l].z[j]);
      node[node[l].z[j]].p = l;
    }
  }
 
  for( i = 0 ; i < num ; i++ ) {
    printf("node %d: parent = %d, ",i,node[i].p);
    printf("depth = %d, ",rec(node,i,0));

    if( node[i].p == -1 ) printf("root, [");
    else if( node[i].q == 0 ) printf("leaf, [");
    else printf("internal node, [");

    for( j = 0 ; j < node[i].q ; j++ ) {
      printf("%d",node[i].z[j]);
      if(j+1 < node[i].q) printf(", ");
    }
    printf("]\n");
  }
  return 0;
}

int rec(Node *node,int num,int suu){
  if(node[num].p == -1) return suu;
  suu++;
  suu = rec(node,node[num].p,suu);

  return suu;
}

Measured memory_bytes: 5688
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,p;
    cin >> n >> p;
    string s;
    cin >> s;
    if(p==2 || p==5)
    {
        ll tot=0;
        F0R(i,n)
        {
            int d=s[i]-'0';
            if(d%p==0)
                tot+=i+1;
        }
        cout << tot;
        return 0;
    }
    ll tot=0;
    map<int, int> mp;
		++mp[0];
		int t=0, p2=1;
		for(int i=n-1; ~i; --i) {
			t=(t+(s[i]-'0')*p2)%p;
			tot+=mp[t];
			mp[t]++;
			p2=p2*10%p;
		}
    /* unordered_map<int,int> cnt;
    cnt[0]++;
    ll curr=0;
    ll tot=0;
    F0R(i,n)
    {
        curr=(curr*10)%p;
        int c=s[i]-'0';
        curr=(curr+c)%p;
        tot+=cnt[curr];
        cnt[curr]++;
    } */
    cout << tot;

    return 0;
}


Measured memory_bytes: 916
import sys
sys.setrecursionlimit(10**5+5)
from collections import defaultdict,deque
input = sys.stdin.readline

def bfs():
    q = deque([1])
    while q:
        now = q.popleft()
        for nex,c,w in e[now]:
            if depth[nex]>= 0:
                continue
            depth[nex] = depth[now]+1
            dis[nex] = dis[now]+w
            lca[0][nex] = now
            q.append(nex)

def dfs1(now,p,count1,count2):
    for cou in dcount[now]:
        dcount[now][cou] = count1[cou]
    for wei in dweight[now]:
        dweight[now][wei] = count2[wei]

    for nex,c,w in e[now]:
        if nex == p:
            continue
        count1[c] += 1
        count2[c] += w
        dfs1(nex,now,count1,count2)
        count1[c] -= 1
        count2[c] -= w
n,q = map(int,input().split())
e = [[] for i in range(n+1)]

for i in range(n-1):
    a,b,c,d = map(int,input().split())
    e[a].append((b,c,d))
    e[b].append((a,c,d))
size = n+1
bitlen = 19
lca = [[0]*size for i in range(bitlen)]
depth = [-1]*size
dis = [-1]*size
depth[1] = 0
dis[1] = 0

bfs()
for i in range(1,bitlen):
    for j in range(1,size):
        if lca[i-1][j] > 0:
            lca[i][j] = lca[i-1][lca[i-1][j]]
    
def search(x,y):
    dx = depth[x]
    dy = depth[y]
    if dx < dy:
        x,y = y,x
        dx,dy = dy,dx
    dif = dx-dy
    while dif:
        s = dif & (-dif)
        x = lca[s.bit_length()-1][x]
        dif -= s
    if x == y:
        return x
    for i in range(bitlen-1,-1,-1):
        if lca[i][x] != lca[i][y]:
            x = lca[i][x]
            y = lca[i][y]
    return lca[0][x]


Q = [[] for i in range(n+1)]
ans = []
for i in range(q):
    x,y,u,v = map(int,input().split())
    a = search(u,v)
    ans.append(dis[u]+dis[v]-2*dis[a])
    Q[u].append((x,y,i,1))
    Q[v].append((x,y,i,1))
    Q[a].append((x,y,i,-2))


count = defaultdict(int)
weight = defaultdict(int)

def dfs1(now,p):
    for x,y,ind,z in Q[now]:
        ans[ind] += z*(y*count[x]-weight[x])
    for nex,c,w in e[now]:
        if nex == p:
            continue
        count[c] += 1
        weight[c] += w
        dfs1(nex,now)
        count[c] -= 1
        weight[c] -= w
    
dfs1(1,0)

for i in ans:
    print(i)

Measured memory_bytes: 767376
#include <bits/stdc++.h>
#define int long long
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
const int N = 1e6 + 233;
int n, a[N], sum[N], ans = 0;
map<int, int> mp;
main(void) {
  read(n); mp[0] ++;
  for(int i = 1; i <= n; i ++) {
    read(a[i]); sum[i] = sum[i - 1] + a[i];
    mp[sum[i]] ++;
  }
  foreach(it, mp) ans += (it->second) * (it->second - 1) / 2;
  cout << ans << "\n";
}


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

int main() {

    int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }    
    int ans = 100000000;
    for (int bit = 0; bit < (1 << n); ++bit) {
        int tmpAns = 0;
        vector<int> tmpPoint(m, 0);
        for (int i = 0; i < n; ++i) {
            if (bit & (1 << i)) {
                tmpAns += c[i];
                for (int j = 0; j < m; j++) {
                    tmpPoint[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (tmpPoint[j] < x) ok = false;
        }
        if (ok) ans = min(ans, tmpAns);
    }
    if (ans == 100000000) ans = -1;
    cout << ans << endl;
    return 0;
}

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

def times(N):
    t = 0
    while (N%2==0 and N//2>0):
        N = N//2
        t += 1
    return t

T=0
for i in range(n):
    T += times(a[i])

print(T)

Measured memory_bytes: 4148
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
    string s, t;
    cin>>s>>t;
    int ans = 1e9;
    for(int i = 0; i < s.length() - t.length() + 1; i++){
        int cnt = 0;
        for(int j = 0; j < t.length(); j++){
            if(s[i + j] != t[j]) cnt++;
        }
        ans = min(cnt, ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int 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;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

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

///////////////////////////////////////////////////////////

int A,B;

void solve() {
  cin >> A >> B;
  for(int i = 0; i < 10000; i++){
    if((int)(i * 0.08) == A && (int)(i * 0.10) == B){
      cout << i <<endl;
      return;
    }
  }
  cout << -1 <<endl;
}

Measured memory_bytes: 256