akhauriyash/Code-Regression huggingface dataset:
a = 0
z = list()
while True:
    n,x = map(int,input().split())
    if n==x==0:
        break
    else:
        for i in range(1,n+1):
            for j in range(1,n+1):
                for k in range(1,n+1):
                    if i < j and i < k:
                        if j < k:
                            b = i+j+k
                            if b == x:
                                a += 1
                            else:
                                pass
                        else:
                            pass
                    else:
                        pass
        z.append(a)
        a = 0

for i in z:
    print(i)  
     
           


Measured memory_bytes: 5596
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
LL euclidean_gcd(LL a, LL b) {
  if(a < b) return euclidean_gcd(b, a);
  LL r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
bool IsPrime(LL num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (LL i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


void solve(long long A, long long B){
    LL v = euclidean_gcd(A, B);
    auto pf = prime_factorize(v);
    cout<<pf.size()+1<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> T input() {T t; cin>>t; return t;}
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define PRINT_ARRAY_H(i,a) REPALL(i,a) {cout<<a[i]<<(i != a.size()-1 ? " " : "");} newline;
#define e1 first
#define e2 second
#define newline putchar('\n')
#define cspace ' '
#define sspace " "
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int H, W;
vector<string> s;
ll ans = 0ll;
VVI visited(444, VI(444));

ll bfs(int y, int x)
{
    int num_b = 1, num_w = 0;

    deque<pair<int, int>> frends;
    frends.push_back(make_pair(y, x));
    visited[y][x] = 1;

    while (!frends.empty()) {
        auto p = frends.front();
        frends.pop_front();

        if (s[p.e1][p.e2] == '#') {
            REP(i,4) {
                if (0 <= p.e2 + dx[i] && p.e2 + dx[i] < W && 0 <= p.e1 + dy[i] && p.e1 + dy[i] < H
                    && visited[p.e1 + dy[i]][p.e2 + dx[i]] == 0 && s[p.e1 + dy[i]][p.e2 + dx[i]] == '.') {

                    frends.push_back(make_pair(p.e1 + dy[i], p.e2 + dx[i]));
                    visited[p.e1 + dy[i]][p.e2 + dx[i]] = 1;
                    num_w++;
                }
            }
        } else if (s[p.e1][p.e2] == '.') {
            REP(i,4) {
                if (0 <= p.e2 + dx[i] && p.e2 + dx[i] < W && 0 <= p.e1 + dy[i] && p.e1 + dy[i] < H
                    && visited[p.e1 + dy[i]][p.e2 + dx[i]] == 0 && s[p.e1 + dy[i]][p.e2 + dx[i]] == '#') {

                    frends.push_back(make_pair(p.e1 + dy[i], p.e2 + dx[i]));
                    visited[p.e1 + dy[i]][p.e2 + dx[i]] = 1;
                    num_b++;
                }
            }
        }
        //cout<<p.e1<<sspace<<p.e2<<sspace<<visited[p.e1][p.e2]<<endl;
    }

    //cout<<num_b<<sspace<<num_w<<endl;
    return (ll)num_b * num_w;
}

int main()
{
    cin>>H>>W;
    REP(i,H) s.push_back(input<string>());

    REP(i,H) {
        REP(j,W) {
            if (s[i][j] == '#' && visited[i][j] == 0) {
                ans += bfs(i, j);
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4636
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
const int maxn = 1e5+100;
int main()
{
    int r,g,b, k;
    cin >> r >> g >> b;
    //cout << b << endl;
    cin >> k;
    while (g <= r && k > 0)
    {
        g = g*2;
        k--;
    }
    while (b <= g && k >0)
    {
        b = b*2;
        k--;
    }
    //cout << k << " " << r << " " << g << " " << b << endl;
    if (k >= 0 && g > r && b > g)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int n, sol, i, p[30];
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> p[i];
    }
    for(i = 2; i < n; i++){
        if(p[i] > min(p[i - 1], p[i + 1]) && p[i] < max(p[i - 1], p[i + 1]) ){
            sol++;
        }
    }
    cout<< sol;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
double f(ll x){
	ll sum=0,xx=x;
	while(xx){
		sum+=xx%10;
		xx/=10;
	}
	return x*1.0/sum;
}
int main(){
	cin >> n;
	ll num=1;
	ll base=1;
	for(int i=1;i<=n;i++){
		cout << num << endl;
		double ii=f(num+base);
		double jj=f(num+base*10);
		if(ii>jj)
            base*=10;
		num+=base;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
// using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

#define MAX 300005

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  segtree<int, op, e> dp(MAX);
  rep(i, n) {
    int x = a[i];
    int l = x - k, r = x + k + 1;
    l = max(l, 0);
    r = min(r, MAX);
    int now = dp.prod(l, r) + 1;
    // dp.set(x, max(dp.get(x), now));
    dp.set(x, now);
  }
  int ans = dp.prod(0, MAX);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9832
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

a,b,c = map(int, input().split())
k = int(input())

ans = sum([a,b,c]) - max(a,b,c) + max(a,b,c) * 2**k
print(ans)




Measured memory_bytes: 9164
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;

int main()
{
int n;
cin >> n;
vector<int> x(n);
vector<double> xy(n);
for(int i=0;i<n;i++){cin >> x.at(i);}
for(int i=0;i<n;i++){int y;cin >> y;xy.at(i)=abs(x.at(i)-y);}
for(int i=1;i<4;i++){double ans=0;for(int j=0;j<n;j++){ans+=pow(xy.at(j),i);}ans=pow(ans,(double)1/i);cout << fixed << setprecision(7) << ans << endl;}
double ans=0;
for(int i=0;i<n;i++){ans=max(ans,xy.at(i));}
cout << fixed << setprecision(7) << ans << endl;
}


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

int main()
{   
    int n,l;
    cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++) cin>>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++){
        cout<<s[i];
    }
    
}


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

using namespace std;

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

    if ( N % 2 != 0 ) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 0;
    long long divisor = 10;

    while ( divisor <= N ) {
        ans += N / divisor;
        divisor *= 5;
    }

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


Measured memory_bytes: 256
using System;

namespace _099_B_StoneMonument
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] var = Console.ReadLine().Split();
            int a = int.Parse(var[0]);
            int b = int.Parse(var[1]);
            int div = b - a;
            int hoge = 0;
            for (int i = 0; i < div; i++)
            {
                hoge += i;
            }          
            Console.WriteLine(hoge-a);
        }
    }
}


Measured memory_bytes: 13140
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

T lcm(T)(T a, T b) {
    return a * (b / gcd(a, b));
}

long calc(long a, long b, long c, long d) {
    // [1, n] で k で割り切れない数の個数
    long f(long n, long k) {
        return n - (n / k);
    }

    long x = f(b, c) + f(b, d) - f(b, lcm(c, d));
    long y = f(a-1, c) + f(a-1, d) - f(a-1, lcm(c, d));
    return x - y;
}

void main() {
    long a, b, c, d; scan(a, b, c, d);
    writeln(calc(a, b, c, d));
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N), 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());
  ll res = 0;
  for (int i = 0; i < N; i++) {
    res += distance(A.begin(), lower_bound(A.begin(), A.end(), B[i])) *
           distance(upper_bound(C.begin(), C.end(), B[i]), C.end());
  }
  cout << res << '\n';
  return 0;
}


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

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for(int i=0; i<N; ++i) {
        cin >> v[i] >> w[i];
    }
    vector<int> dp(W+1);
    for(int i=0; i<N; ++i) {
        for(int j=0; j<=W-w[i]; ++j) {
            dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
        }
    }
    cout << dp[W] << endl;
}


Measured memory_bytes: 3148
N = int(input())
cost_list = list(map(int, input().split()))
#print(N, cost_list)

dp = [float('INF')] * N
dp[0] = 0


def change_min(a, b):
    if a > b:
        a = b
        
    return a



for n in range(1, N):
    dp[n] =  change_min(dp[n], dp[n-1] + abs(cost_list[n] - cost_list[n-1]))
    if n > 1:
        dp[n] =  change_min(dp[n], dp[n-2] + abs(cost_list[n] - cost_list[n-2]))
print(dp[-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define int long long
#define m_k make_pair
using namespace std;
const int N=2*1e5+100;
int n,a[N],b[N],vi[N],ans;
queue <int> q;
inline int pre(int x){return((x==1)?n:x-1);}
inline int suc(int x){return((x==n)?1:x+1);}
inline bool check(int x){return(b[x]>=b[pre(x)]+b[suc(x)]&&b[x]>a[x]);}
signed main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++) scanf("%lld",&b[i]);
	bool bl=1;
	for (int i=1;i<=n;i++) if (b[i]<a[i]) bl=0;
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<=n;i++)
	{
		if (check(i))
		{
			vi[i]=1;
			q.push(i);
		}
	}
	bl=1;
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		vi[x]=0;
		int delta=b[x]-a[x];
		delta/=b[pre(x)]+b[suc(x)];
		ans+=delta;
		b[x]-=(b[pre(x)]+b[suc(x)])*delta;
		if (delta==0)
		{
			bl=0;
			break;
		}
		if (check(pre(x)) && !vi[pre(x)]) vi[pre(x)]=1,q.push(pre(x));
		if (check(suc(x)) && !vi[suc(x)]) vi[suc(x)]=1,q.push(suc(x));
	}
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) bl=0;
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 8968
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			int[] hs = new int[N];
			for(int i = 0; i < N; i++) {
				hs[i] = sc.nextInt();
			}
			
			ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer>>();
			for(int i = 0; i < N; i++) { adj.add(new ArrayList<Integer>()); }
			
			for(int i = 0; i < M; i++) {
				final int A = sc.nextInt() - 1;
				final int B = sc.nextInt() - 1;
				
				adj.get(A).add(B);
				adj.get(B).add(A);
			}

			int answer = 0;
			LOOP:
			for(int i = 0; i < N; i++) {
				for(final int next : adj.get(i)) {
					if(hs[next] >= hs[i]) { continue LOOP; }
				}
				
				answer++;
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


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

using namespace std;
int main()
{
    string s,t;
    int n,c=0;
    cin>>s>>t;
    n = s.length();
    for(int i=0;i<n;i++)
    {
        if(s[i]!=t[i])
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3844
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
#include <functional>
using namespace std;

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x){
    if( x == 0 ) return 0;
    return counter( x >> 1) + ( x & 1);
}

void solve(){

    // input
    cin >> N;
    for(int i = 1 ; i <= N ; i++){
        cin >> A[i];
        for( int j = 1 ; j <= A[i] ; j++){
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;

    for( int bits = 1; bits < (1 << N); bits++){
        bool ok = true;
        for(int i = 1 ; i <= N ; i++){
            if(!(bits & (1 << (i-1)))) continue;
            for( int j = 1 ; j <= A[i] ; j++ ){
                if( ((bits >> (x[i][j] - 1)) & 1) ^ y[i][j] ) ok = false;
            }
        }
        if(ok) ans = max( ans, counter(bits) );
    }
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 256
/* A */

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

int main(){
	int a,b;
	cin >> a >> b;

	int p = 0;
	p += max(a,b);

	if(p == a) a--;
	else b--;

	p += max(a,b);

	cout << p << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MAX_N (123456 * 2 + 1)

using namespace std;

int main() {
    bool isPrime[MAX_N];
    fill_n((bool *)isPrime, MAX_N, true);
    isPrime[0] = false; isPrime[1] = false;
    for (int i = 2; i < MAX_N; i++) {
        for (int j = i+i; j < MAX_N; j += i) {
            isPrime[j] = false;
        }
    }
    
    int n;
    while (cin >> n, n) {
        int count = 0;
        for (int i = n+1; i <= n*2; i++) {
            if (isPrime[i]) count++;
        }
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(void){
    int n, k;
    int d[128], a[128][128];
    int sum = 0;
    int memo[128] = {0};

    scanf("%d %d", &n, &k);
    for(int i = 1; i <= k; ++i){
        scanf("%d", &d[i]);
        for(int j = 1; j <= d[i]; ++j){
            scanf("%d", &a[i][j]);
            memo[a[i][j]] = 1;
        }
    }

    for(int i = 1; i <= n; ++i) sum += memo[i];

    printf("%d\n", n - sum);

    return 0;
}

Measured memory_bytes: 1736
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b,c,d=map(int,input().split())
    from fractions import gcd
    L=c*d//gcd(c,d)
    M=b-(b//c)-(b//d)+(b//L)
    m=a-1-((a-1)//c)-((a-1)//d)+((a-1)//L)
    print(M-m)
resolve()

Measured memory_bytes: 64748
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const string inf = "-";

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> vec(M);
  for (int i = 0; i < M; i++) {
    cin >> vec[i];
  }
  
  vector<string> dp(N + 1);
  for (int i = 0; i <= N; i++) {
    dp[i] = inf;
  }
  
  dp[0] = "";
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < M; j++) {
      if (i - match[vec[j]] >= 0 && dp[i - match[vec[j]]] != inf) {
        chmax(dp[i], dp[i - match[vec[j]]] + (char)('0' + vec[j]));
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 41472
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
typedef long long ll;
using namespace std;

int main() {

    int N, M;
    cin >> N >> M;
    
    vector<vector<int>> s(M);
    for (int i = 0; i < M; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int a; cin >> a; a--;
            s[i].push_back(a);
        }
    }

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

    ll res = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        bool ok = true;
        for (int i = 0; i < M; i++) {
            int con = 0;
            for (auto v : s[i]) {
                if (bit & (1<<v)) con++;
            }
            if (con % 2 != p[i]) ok = false;
        }
        if (ok) res++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var O = Console.ReadLine();
            var E = Console.ReadLine();

            for (var i = 0; i < O.Length; i++)
            {
                Console.Write(O[i]);
                if (i < E.Length) Console.Write(E[i]);
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 13140
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	as := make([][]int, 2)
	for i := range as {
		as[i] = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&as[i][j])
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += as[0][j]
		}
		for j := i; j < n; j++ {
			sum += as[1][j]
		}
		ans = max(ans, sum)
	}

	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    alphas = 'abcdefghijklmnopqrstuvwxyz'
    N = read_int()
    answer = []
    while N != 0:
        d = (N%26-1)%26
        answer.append(alphas[d])
        N = (N-1)//26
    return ''.join(reversed(answer))


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61732
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<string>
#define int long long
using namespace std;

int parse(string a) {
	int b = 0;
	for (char c : a)b = b * 10 + c - 48;
	return b;
}
signed main() {
	int S = 0;
	string a; cin >> a;
	for (int i = 0; i < (1 << (a.length() - 1)); i++) {
		string k[10];
		for (int r = 0; r < a.length(); r++)k[r] = a[r];
		for (int j = 1,l=0; j < (1 << (a.length() - 1)); j <<= 1,l++) {
			if (i&j) {
				k[l + 1] = k[l] + k[l + 1];
				k[l] = "";
			}
		}
		for (int p = 0; p < a.length(); p++) {
			if (k[p] != "")S += parse(k[p]);
		}
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))

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

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n;
  string s, t;
  cin >> n >> s >> t;
  rep(i,n){
    bool ok = true;
    rep(j,n-i){
      if(s[i+j] != t[j]) ok = false;
    }
    if(ok){
      int ans = i + n;
      cout << ans << endl;
      return 0;
    }
  }
  cout << n*2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for(int i=0;i<n;i++){
    cin >> a[i].first ;
    a[i].second = i;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    cout << a[i].second + 1 << " ";
  }
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
#define lint long long
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
class Edge{
public:
//int s;
int t;
long long len;
};
class Node{
    public:
    int num;//node番号
    long long dist;//startからの距離
    vector<Edge> edge;//自分から生えている辺
    bool comp;//dijkstra中で到達しているかどうか
    int nxt;
    void in_edge(int in_t,int in_len){
        Edge in;in.t=in_t;in.len=in_len;
        edge.push_back(in);
        nxt=0;
    }  
};
bool operator >(const Node& a,const Node &r){
        return a.dist > r.dist;
    }
void dijkstra(vector<Node> &node,int s,int n){
    //n個のノードでできたグラフのsからtまでの最短距離を計算する
    //この時各要素のdistの値はsからの最短距離となる
    for(int i=1;i<=n;i++){
        //初期化
        node[i].dist=inf;
        node[i].num=i;
        node[i].comp=true;
        node[i].nxt=0;
    }
    node[s].dist=0;
    priority_queue<Node,vector<Node>,greater<Node>> que;
    que.push(node[s]);
    while(!que.empty()){
        Node buf;
        buf=que.top();//
        que.pop();
        int k=buf.num;
        if(node[k].comp){
            node[k].comp=false;
            int edge_num=buf.edge.size();
            for(int i=0;i<edge_num;i++){
                int buf_t=node[k].edge[i].t;
                int buf_len=node[k].edge[i].len;
                if(node[buf_t].dist>node[k].dist+buf_len){
                node[buf_t].dist=node[k].dist+buf_len;
                que.push(node[buf_t]);
                }
            }
        }
    }
}
signed main(){
  int n,m;cin>>n>>m;
  vector<Node> node(n+1);
  rep(i,m){
    int a,b;cin>>a>>b;
    node[a].in_edge(b,1);
    node[b].in_edge(a,1);
  }
  dijkstra(node,1,n);
  queue<Node> que;
  que.push(node[1]);
  while(!que.empty()){
    Node buf=que.front();que.pop();
    int num=buf.edge.size();
    rep(i,num){
      int buf_t=buf.edge[i].t;
      if(node[buf_t].dist==buf.dist+1&&node[buf_t].nxt==0){
        node[buf_t].nxt=buf.num;
        que.push(node[buf_t]);
      }
    }
  }
  cout<<"Yes"<<"\n";
  for(int i=2;i<=n;++i){
    cout<<node[i].nxt<<"\n";
  }
  return 0;
}


Measured memory_bytes: 30948
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 405;
int g[maxn][maxn],H,W, vis[maxn][maxn];
int dx[]={0,0, 1,-1};
int dy[]={1,-1,0, 0};

long long  cntw ,cntb;
void dfs(int x, int y){
    if(vis[x][y])return;
    vis[x][y] = 1;
    if(g[x][y]==0)cntw++;
    else cntb++;
    for(int i = 0; i< 4;i++){
        int xn = x+dx[i];
        int yn = y+dy[i];
        if(xn<0||yn<0||xn>=H||yn>=W||g[xn][yn] == g[x][y])continue;
        dfs(xn, yn);
    }
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    

    cin>>H>>W;
    char c;
    for(int i = 0; i<H; i++){
        for(int j = 0; j < W; j++){
            cin>>c;
            if(c == '.')g[i][j]= 0;
            else g[i][j] = 1;
        }
    }
    

    long long ans = 0;
    for(int i = 0; i<H; i++){
        for(int j = 0; j < W; j++){
            if(!vis[i][j]){
                cntw = cntb = 0;
                dfs(i,j);
                ans += cntw*cntb;
            }
        }
    }

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


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=5e5;

  ll n,A;
  ll a[N],l[N],k[N],r[N];
ll cmp(ll x,ll y)
{
  return a[x]>a[y];
}

int main()
{
  cin>>n;
  for (ll i=0;++i<=n;)
    scanf("%d",a+i),
	  l[i]=i-1,k[i]=i,r[i]=i+1;
  sort(k+1,k+n+1,cmp);
  for (ll i=0;++i<=n;)
    {
      A+=a[k[i]]*(r[k[i]]-k[i])*(k[i]-l[k[i]]);
      r[l[k[i]]]=r[k[i]];
      l[r[k[i]]]=l[k[i]];
    }
  cout<<A;
  exit(0);
}

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

int main(int argc, char const* argv[])
{
    long long N, A, B;
    cin >> N >> A >> B;
    long long ans;
    if ((B-A) % 2 == 0) {
        ans = (B - A) / 2;
    } else {
        if (A - 1 <= N - B) {
            ans = A + ((B - A - 1) / 2);
        } else {
            ans = N - B + 1 + ((B - A - 1) / 2) ;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int year;
    int pay;

    scanf("%d%d",&year,&pay);
    
    if(year<=5){
        printf("0\n");
    }else if(year>=13){
        printf("%d\n",pay);
    }else{
        printf("%d\n",pay/2);
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  char S[101], *p;
  cin >> K >> S;
  for(p=S;*p!='\0';K--,p++){
    if(!K){
      cout << "...";
      return 0;
    }
    putchar(*p);
  }
}

Measured memory_bytes: 3632
from __future__ import division
from collections import defaultdict, deque
from heapq import heappush, heappop
from sys import stdin


def floyd(graph):
    n = len(graph["nodes"])
    dis = [[10 ** 20 for _ in range(n)] for _ in range(n)]
    for i in range(n): dis[i][i] = 0

    for x in graph["nodes"]:
        for (y, w) in graph["adj"][x]:
            dis[x][y] = w


    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dis[i][k] < 10 ** 20 and dis[k][j] < 10 ** 20:
                    dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])

    return dis


if __name__ == '__main__':
    V, E= map(int, stdin.readline().strip().split())
    graph = {}
    graph["nodes"] = [i for i in range(V)]
    graph["edges"] = []
    graph["adj"] = defaultdict(list)
    for _ in range(E):
        x, y, w = map(int, stdin.readline().strip().split())
        graph["edges"].append((x, y, w))
        graph["adj"][x].append((y, w))

    dis = floyd(graph)

    negcycle = False

    for i in range(len(graph["nodes"])):
        if dis[i][i] < 0:
            negcycle = True

    if negcycle:
        print "NEGATIVE CYCLE"
    else:
        for row in dis:
            print ' '.join(map(lambda x: str(x) if x < 10 ** 20 else "INF", row))

Measured memory_bytes: 6680
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, ans = 0;
	cin >> a >> b >> c;
	for(int i=a; i<=b; i++){
		if(c%i==0)
			ans ++;
	}
	cout << ans << endl;
	return 0;
} 


Measured memory_bytes: 3116
n, m = map(int, input().split())
C = list(map(int, input().split()))

N = [float('inf')] * (50000 + 1)
N[0] = 0
for i in range(1, 50000 + 1):
    for c in C:
        if i - c < 0:
            continue
        N[i] = min(N[i - c] + 1, N[i])

print(N[n])


Measured memory_bytes: 7268
N, K = map(int, input().split())


memo = {}
def times(i, count):
    if i in memo:
        return memo[i]
    if i < K: 
        ret  = times(i * 2, count + 1)
    else:
        ret = count
    memo[i] = ret - count
    return ret


ret = 0
for n in range(1, N + 1):
    t = times(n, 0)

    ret += (1/N) * pow((1/2), t)

print(ret)


Measured memory_bytes: 50156
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int main(){
    // cout << (int)'0' << endl; //48
    // cout << (int)'1' << endl; //49

    string s;
    while(true){
        cin >> s;
        if(s == "0") break;
        int res = 0;
        for(int i=0;i<s.size();i++){
            res += (int)(s[i]) - 48;
        }
        cout << res << endl;
    }
}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int t;
	cin >> t;
	while (t--)
	{
		ll n, a, b, c, d;
		cin >> n >> a >> b >> c >> d;

		vector<ll> cost = { 0, 0, a, b, 0, c };

		map<ll, ll> mp;
		function<ll(ll)> f = [&](ll x)
		{
			if (x <= 1) return x * d;
			if (x == 2) return min(a + d, 2*d);

			ll &ret = mp[x];
			if (ret > 0) return ret;
			ret = min(x, (ll)(3e18)/d) * d;
			for (auto i : { 2, 3, 5 })
			{
				ll y = x / i, r = x % i;
				ret = min({ ret, min(min(x-y, (ll)(3e18)/d)*d, r*d + cost[i]) + f(y), (i-r)*d + cost[i] + f(y+1) });
			}
			return ret;
		};

		cout << f(n) << "\n";
	}

	return 0;
}


Measured memory_bytes: 4804
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }


const int maxn = 510;

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    int n;
    while (cin >> n) {
        int dp[210] = {0};
        dp[0] = 1;
        int A[] = {4,7};
        FOR(i,0,2) FOR(j,A[i],n+1)
            dp[j] |= dp[j-A[i]];
        if (dp[n])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

double X;
double PI = 3.1415926535;
int main(){
	fast;
	
	cin>>X;
	X *= 2 * PI / 360;
	
	double curx = 0, cury = 0;
	int i = 0;
	int ans = 0;
	do{
		//cout<<curx<<' '<<cury<<'\n';
		curx += sin(i * X);
		cury += cos(i * X);
		ans++; i++;
	}while (abs(curx) > 1e-4 || abs(cury) > 1e-4);
	cout<<ans;
}



Measured memory_bytes: 4044
using System;

namespace ABC145B {
    class Program {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if (n % 2 != 0) {
                Console.WriteLine("No");
                return;
            }

            var front = s.Substring(0, n / 2);
            var back = s.Substring(n / 2, n / 2);
            Console.WriteLine(front == back ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s;
    cin>>s;
    int d=s/100;
    int m=s%100;
    if((d<=12 && m>12 && d!=0) || (d<=12 && d!=0 && m==0))
        cout<<"MMYY\n";
    else if((d>12 && m<=12 && m!=0) || (m<=12 && m!=0 && d==0))
        cout<<"YYMM\n";
    else if(d<=12 && m<=12 && d!=0 && m!=0)
        cout<<"AMBIGUOUS\n";
    else if(d>12 && m>12 || d==0 && m==0 || d>12 && m==0||d==0 && m>12)
        cout<<"NA\n";
}



Measured memory_bytes: 3600
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll cnt(26,1000000) ;
	for(int i=0;i<n;i++){
		string s ; cin >> s ;
		vll sub(26,0) ;
		for(int j=0;j<s.size();j++){
			sub.at(s.at(j)-'a')++ ;
		}
		for(int j=0;j<26;j++){
			if(sub.at(j)<cnt.at(j)) cnt.at(j) = sub.at(j) ;
		}
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<cnt.at(i);j++) cout << (char)('a'+i) ;
	}
	cout << endl ;
}


Measured memory_bytes: 256
import heapq

def dijkstra(s,path):
    inf = float('inf')
    n = len(path)

    # 距離をinfで初期化
    d = [inf for i in range(n)]
    d[s] = 0

    # sへの距離は0
    q = [(0,s)]
    heapq.heapify(q)

    # 距離が最小の頂点から更新していけば良い
    while q:
        c,p = heapq.heappop(q)

        # 頂点pまでの距離がheap内のpまでの距離より小さい場合、continue
        if d[p]<c:
            continue

        # 頂点pから伸びる、全ての辺の距離を確認
        for cost,to in path[p]:
            # 頂点pから行ける頂点の距離がpまでの距離とpからの距離の和より小さい場合 -> 距離を更新し、heapに追加
            if d[to] > d[p] + cost:
                d[to] = d[p]+cost
                heapq.heappush(q,(d[to], to))
    return d

xs,ys,xt,yt = map(int,input().split())
n = int(input())
barrier = [list(map(int, input().split())) for i in range(n)]

barrier = [[xs,ys,0]] + barrier + [[xt,yt,0]]
n+=2

path = [[] for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        length = max(((barrier[i][0]-barrier[j][0])**2 + (barrier[i][1]-barrier[j][1])**2)**0.5-barrier[i][2]-barrier[j][2],0)
        path[i].append([length,j])
        path[j].append([length,i])

d = dijkstra(0,path)

print(d[-1])

Measured memory_bytes: 171520
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}
ll arr[1010];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(8);

    int N, K;
    cin >> N >> K;
    vector<ll> v;
    for (int i = 0; i < N; ++i)
        cin >> arr[i];

    for (int i = 0; i < N; ++i)
    {
        ll t = arr[i];
        v.push_back(t);
        for (int j = i + 1; j < N; ++j)
        {
            t += arr[j];
            v.push_back(t);
        }
    }
    ll ans = 0;
    ll tt = (1LL << 39);
    for (ll i = 39; i >= 0; --i)
    {
        int t = 0;
        for (ll j = 0; j < v.size(); ++j)
        {
            if (((ans + tt) & v[j]) == (ans + tt))
            {
                t++;
            }
        }

        if (t >= K)
        {
            ans += tt;
        }
        tt /= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6000
#include<iostream>
#include<stdio.h>
#define rep(p) for(int i = 0; i < p; i++)
using namespace std;
int main() {
    int l,min = 10000,max = 0;long int sum = 0;
    cin >> l;
    int a[l];
    rep(l) {
        cin >> a[i];
        if(i == 0){
            min = a[i];
            max = a[i];
        }
        if(min > a[i])min = a[i];
        if(max < a[i])max = a[i];
        sum += a[i];
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll dp[301][301][301];
ll n, m;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	dp[0][1][1] = 1;
	REP(i,m + 1) REP(j,n + 1) REP(k,n + 1) {
		dp[i][j][k] %= MOD;
		if(i < m) {
			dp[i + 1][j][j] += k * dp[i][j][k];
			dp[i + 1][j][k] += (j - k) * dp[i][j][k];
			if(j < n) dp[i + 1][j + 1][k] += (n - j) * dp[i][j][k];
		}
	}
	cout << dp[m][n][n] << endl;
	return 0;
}


Measured memory_bytes: 213376
import sys


class UnionFind:
    def __init__(self, node_size):
        self._node = node_size
        self.par = [i for i in range(self._node)]
        self.rank = [0] * self._node

    def find(self, ver):
        if self.par[ver] == ver:
            return ver
        else:
            self.par[ver] = self.find(self.par[ver])
            return self.par[ver]

    def unite(self, ver1, ver2):
        ver1, ver2 = self.find(ver1), self.find(ver2)
        if ver1 == ver2:
            return
        if self.rank[ver1] < self.rank[ver2]:
            ver1, ver2 = ver2, ver1
        self.par[ver2] = ver1
        if self.rank[ver1] == self.rank[ver2]:
            self.rank[ver1] += 1

    def same(self, ver1, ver2):
        return self.find(ver1) == self.find(ver2)

if __name__ == '__main__':
    n, m = map(int, sys.stdin.readline().split())
    uf = UnionFind(n)
    for i in range(m):
        s, t = map(int, sys.stdin.readline().split())
        uf.unite(s, t)
    q = int(sys.stdin.readline())
    for i in range(q):
        s, t = map(int, sys.stdin.readline().split())
        if uf.same(s, t):
            print("yes")
        else:
            print("no")


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

int main() {
    ios::sync_with_stdio(false);
    int n, t[102] = {}, v[102] = {}, d[40004][202] = {};
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> t[i], t[i] += t[i], t[i] += t[i - 1];
    for (int i = 1; i <= n; i++) cin >> v[i], v[i] += v[i];
    for (int i = 0; i <= 40000; i++) for (int j = 0; j <= 201; j++) d[i][j] = -mod;
    d[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = t[i - 1] + 1; j <= t[i]; j++) {
            for (int k = 0; k <= v[i]; k++) {
                d[j][k] = d[j - 1][k];
                if (k) d[j][k] = max(d[j][k], d[j - 1][k - 1]);
                if (k < v[i]) d[j][k] = max(d[j][k], d[j - 1][k + 1]);
                d[j][k] += k;
            }
        }
    }
    cout << setprecision(13) << d[t[n]][0] / 4.0 << '\n';
}


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        int[] counter = new int[M];
        for (int i = 0; i < N; i++) {
            int K = scan.nextInt();
            for (int j = 0; j < K; j++) {
                int a = scan.nextInt();
                counter[a-1] += 1;
            }
        }
        int answer = 0;
        for (int i = 0; i < M; i++) {
            if (counter[i] == N) {
                answer += 1;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 22996