akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi					3.14159265359
ll INF=1e18+10;
ll MOD=1000000007;

const int N=1e5+10;
char s[N];
ll dp[N][13];

int main()
{
    cin>>s;
    int l=strlen(s);
    if(s[0]=='?')
        rep(i,0,10)dp[0][i]=1;
    else
        dp[0][s[0]-'0']=1;
    rep(i,1,l)
    {
        if(s[i]=='?')
        {
            rep(j,0,10)
            {
                rep(k,0,13)
                {
                    ll before_ways=dp[i-1][k];
                    ll now_fill=(j+k*10)%13;
                    dp[i][now_fill]=(dp[i][now_fill]+before_ways)%MOD;
                }
            }
        }
        else
        {
            int j=s[i]-'0';
            rep(k,0,13)
            {
                ll before_ways=dp[i-1][k];
                ll now_fill=(j+k*10)%13;
                dp[i][now_fill]=(dp[i][now_fill]+before_ways)%MOD;
            }
        }
    }
    cout<<dp[l-1][5];
}


Measured memory_bytes: 10496
s = input()
t = input()

n = len(s); m = len(t)
# dp [s+1][t+1]

dp = [[0 for i in range(m+1)]for j in range(n+1)]

for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1] == t[j-1]:
      dp[i][j] = 1 + dp[i-1][j-1]
    else:
      dp[i][j] = max(dp[i-1][j],dp[i][j-1])
      
res = ""
i=n; j = m

while i>0 and j >0:
  if dp[i][j] == dp[i-1][j]:
    i=i-1
  elif dp[i][j] == dp[i][j-1]:
    j=j-1
    
  else:
    res = s[i-1] + res
    i=i-1
    j=j-1
    
print(res)


Measured memory_bytes: 119772
N = int(input())
a_list = [int(num) for num in input().split()]
a_list.sort(reverse=True)

alice = 0
bob = 0

for i, num in enumerate(a_list, 1):
  if i % 2:
    alice = alice + num
  else:
    bob = bob + num
print(alice-bob)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;


/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;

int32_t main(){

	
	FASTIO;
	string a;
	cin >> a;
	string b;
	cin >> b;
	b.pop_back();
	if(a==b){
		cout << "Yes\n";
	}
	else
		cout << "No\n";
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}
 
int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}
 
int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}
 
bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}

Measured memory_bytes: 3640
fun main(args: Array<String>) {
    val x = readListInt()
    val ans = x.indexOf(0) + 1
    println(ans)


}

private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 36292
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string k[30];
	k[25] = "Christmas";
	k[24] = "Christmas Eve";
	k[23] = "Christmas Eve Eve";
	k[22] = "Christmas Eve Eve Eve";
	int d;
	cin>>d;
	cout<<k[d]<<endl;
}

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

using namespace std;

int main(void)
{
	int n,m,p;
	int sum;
	int i1;

	while(1){
		cin >> n >> m >> p;
		if (n==0 && m==0 && p==0) break;

		vector<int> x(n);

		sum = 0;
		for(i1=0;i1<n;i1++){
			cin >> x[i1];
			sum += x[i1]*100;
		}

		sum = (sum*(100-p))/100;

		if (x[m-1]==0) cout << 0 << endl;
		else cout << sum/x[m-1] << endl;

	}

	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  string str;cin>>str;
  if(str[2] == str[3] && str[4] == str[5])
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  

  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>


#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void D_task();

int main()
{
	D_task();
	
	fflush(stdout);
	return 0;
}

class d_data {
public:
	int val = 0;
	int ball = 0;
};
static void D_task()
{
	int N;
	get1int(N);

	auto seqA = new d_data[N + 1];
	for (int i = 1; i <= N; i++) {
		get1int(seqA[i].val);
	}

	int putCount = 0;
	for (int i = N; i > 0; i--) {
		int sum = 0;
		for (int j = i; j <= N; j += i) {
			sum += seqA[j].ball;
		}
		if (sum % 2 != seqA[i].val) {
			seqA[i].ball = 1;
			putCount++;
		}
	}

	printf("%d\n", putCount);
	LLONG out = 0;
	if (putCount > 0) {
		for (int i = 1; i <= N; i++) {
			if (seqA[i].ball) {
				if(out > 0) printf(" ");
				printf("%d", i);
				out++;
			}
		}
		printf("\n");
	}

	delete[] seqA;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include "atcoder/all"

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), B(M);
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, M) {
        cin >> B[i];
    }

    auto C = atcoder::convolution(A, B);
    REP(i, C.size()) {
        cout << C[i] << " ";
    }
    cout << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin>>p.at(i);

  int sum=0;
  int m=0;
  for(int i=0;i<n;i++){
    sum+=p.at(i);
    m=max(m,p.at(i));
  }
  cout<<sum-m/2<<endl;
  return 0;
}//保留

Measured memory_bytes: 256
N = int(input())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
Ci = list(map(int,input().split())) + [0]

manzoku = 0
im1 = Ai[0]
for i,A in enumerate(Ai):
  manzoku = manzoku + Bi[A-1]
  if A - im1 == 1: manzoku = manzoku + Ci[im1-1]
  im1 = A
print(manzoku)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)(v).size())
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1);



int main(void) {
    int n;
    cin >> n;
    vector<uint64_t> v(n);
    rep(i, n) {
        cin >> v.at(i);
        if (v.at(i) == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    uint64_t ans = 1;
    uint64_t pre = 1;
    rep(i, n) {
        ans *= v.at(i);
        if (ans > 1000000000000000000) {
            cout << "-1" << endl;
            return 0;
        }
        if (ans < pre) {
            cout << "-1" << endl;
            return 0;
        }
        pre = ans;
    }
    cout << ans << endl;
    return 0;
}

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


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;
#define NIL NULL


Node root;

Node treeMini(Node x);
Node treeMax(Node x);
Node treeSearch(Node u, int v);
Node treeSuccessor(Node u);
void treeDelete(Node z);
void insert(int k);
void inorder(Node u);
void preorder(Node u);

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Node treeMini(Node x){

  while(x->left!=NIL){
    x=x->left;
  }

  return x;
}

Node treeMax(Node x){

  while(x->right!=NIL){
    x=x->right;
  }

  return x;
  
}

Node treeSearch(Node u, int k){
  u=root;

  while(u!=NIL && u->key!=k){
    if(k < u->key) u=u->left;
    else u=u->right;
  }

  return u;
  
}

Node treeSuccessor(Node x){
  Node data;

  if(x->right!=NIL) return treeMini(x->right);

  data=x->parent;

  while(data!=NIL && x==data->right){
    x=data;
    data=data->parent;
  }

  return data;
}

void treeDelete(Node z){
  Node data;
  Node res;

  if(z->left==NIL || z->right==NIL) data=z;
  else data=treeSuccessor(z);

  if(data->left!=NIL) res=data->left;
  else res=data->right;

  if(res!=NIL) res->parent=data->parent;

  if(data->parent==NIL) root=res;
  else if(data==data->parent->left) data->parent->left=res;
  else data->parent->right=res;

  if(data!=z) z->key=data->key;
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }

  z->parent=y;

  if(y==NIL) root=z;
  else if (z->key < y->key) y->left=z;
  else y->right=z;

}

void inorder(Node u){
  
  if(u==NIL) return;

  if(u->left!=NIL) inorder(u->left);
  
  printf(" %d",u->key);
  
  if(u->right!=NIL) inorder(u->right);
  
}

void preorder(Node u){

  if(u==NIL) return;
  
  printf(" %d",u->key);
  
  if(u->left!=NIL) preorder(u->left);
  

  if(u->right!=NIL) preorder(u->right);
  
  
}



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

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	if((A <= C && C <= B) || (B <= C && C <= A)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
//前置き
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main(){
    // ========================================================
    int a;
    cin >> a;
    if(a % 2 == 0) cout << 0.5 << endl;
    else cout << (a/2 +1) / (double)a << endl;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}

//最小公倍数
ll lcm(ll a, ll b) {  
    return a*b/gcd(a,b);  
} 

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

using namespace std;

int main(void){

    int w, h, n;
    cin >> w >> h >> n;

    vector<vector<int>> map;
    for(int i=0; i<=h; i++) {
        vector<int> temp;
        for(int j=0; j<=w; j++) {
            temp.push_back(0);
        }
        map.push_back(temp);
    }
    
    for(int i=0; i<n; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1) {
            for(int y_index = 0; y_index < h; y_index++) {
                for(int x_index = 0; x_index < x; x_index++) {
                    map[y_index][x_index] = 1;
                }
            }
        }
        else if(a == 2) {
            for(int y_index = 0; y_index < h; y_index++) {
                for(int x_index = x; x_index < w; x_index++) {
                    map[y_index][x_index] = 1;
                }
            }
        }
        else if(a == 3) {
            for(int x_index = 0; x_index < w; x_index++) {
                for(int y_index = 0; y_index < y; y_index++) {
                    map[y_index][x_index] = 1;
                }
            }
        }
        else {
            for(int x_index = 0; x_index < w; x_index++) {
                for(int y_index = y; y_index < h; y_index++) {
                    map[y_index][x_index] = 1;
                }
            }
        }
    }
    
    int result = 0;
    for(int y_index = 0; y_index < h; y_index++) {
        for(int x_index = 0; x_index < w; x_index++) {
//            cout << map[y_index][x_index];
            if(map[y_index][x_index]) result++;
        }
//        cout << endl;
    }

    cout << h*w-result << endl;

    return 0;
    
}


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

int check(int j,int k, int a, int b){
    int ans = 0;
    if (k == 0 || k == b - 1 || j == 0 || j == a - 1)
        ans = 1;
    return (ans);
}

int main(void){
    for (int i = 0; i < 1000; i++){
        int a, b;
            cin >> a >> b;
        if (a == 0 && b == 0)
            break;
        for (int j = 0; j < a; j++){
            for (int k = 0; k < b; k++){
                if (check(j, k, a, b))
                    cout << "#";
                else
                    cout << ".";
                if (k == b - 1)
                    cout << endl;
            }
        }
        cout << endl;
    }
}



Measured memory_bytes: 3060
import collections
import heapq


class Dijkstra():
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d, directed=False):
        """
        0-indexedでなくてもよいことに注意
        u = from, v = to, d = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.e[u].append([v, d])
            self.e[v].append([u, d])
        else:
            self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def Dijkstra_search(self, s):
        """
        0-indexedでなくてもよいことに注意
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

import collections
import heapq


class Dijkstra():
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d=1, directed=False, ):
        """
        0-indexedでなくてもよいことに注意
        u = from, v = to, d = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.e[u].append([v, d])
            self.e[v].append([u, d])
        else:
            self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def Dijkstra_search(self, s):
        """
        0-indexedでなくてもよいことに注意
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d


graph = Dijkstra()
N, M = map(int, input().split())
for i in range(M):
    u, v = map(int, input().split())
    graph.add(u, v+N, directed=True)
    graph.add(u+N, v+2*N, directed=True)
    graph.add(u+2*N, v, directed=True)


S, T = map(int, input().split())
d = graph.Dijkstra_search(S)
if d[T] == float('inf'):
    print(-1)
else:
    print(d[T] // 3)

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define PI 3.141592653589793

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

    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double kaku;
    kaku = 0.5 * (60*H + M) - 6.0 * M;
    double l;
    l = A * A + B * B - 2.0 * A * B *cos(kaku * PI / 180.0);
    l = pow(l,0.5);
    cout << setprecision(15) << l << endl;
    return 0;
}


Measured memory_bytes: 4372
#include "bits/stdc++.h"
using namespace std;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

/* baseのべき乗を求める */
template<class T>
T getPower(int exponet, int base)
{
	T ans = 1;
	for (int i = 0; i < exponet; i++) {
		ans *= base;
	}
	return ans;
}

void Solve()
{
	ll N;
	cin >> N;
	vector<string> A(N);
	REP(i, N) cin >> A[i];

	vector<P> primePair(N);

	auto getSosuuPari = [](ll val) {
		ll tmp;
		tmp = val;
		P res = { 0, 0 };

		while (tmp % 2 == 0) {
			tmp /= 2;
			res.first++;
		}
		
		tmp = val;
		while (tmp % 5 == 0) {
			tmp /= 5;
			res.second++;
		}

		return res;
	};

	REP(i, N) {
		auto &one = A[i];
		auto pos = one.find('.');

		ll topVal;
		ll divVal;
		if (pos == string::npos) {
			divVal = 1;
			topVal = stoll(one);
		} else {
			ll strLen = one.size() - pos - 1;
			string join = one.substr(0, pos) + one.substr(pos + 1);
			divVal = getPower<ll>(strLen, 10);
			topVal = stoll(join.c_str());
		}
		P topPrime = getSosuuPari(topVal);
		P divPrime = getSosuuPari(divVal);
		primePair[i].first = topPrime.first - divPrime.first;
		primePair[i].second = topPrime.second - divPrime.second;
	}

	ll geta = 50;
	VVL matrix(100, VL(100, 0));
	for (auto &one : primePair) {
		matrix[one.first + geta][one.second + geta]++;
	}

	ll ans = 0;
	REP(idx, N) {
		auto &one = primePair[idx];
		ll fstMin = (one.first * -1) + geta;
		ll secMin = (one.second * -1) + geta;
		REPN(i, fstMin, 100) {
			REPN(j, secMin, 100) {
				ans += matrix[i][j];
			}
		}
		if (0 <= one.first && 0 <= one.second) ans--;
	}

	cout << ans / 2 << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 12680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  string s;
  cin >> s;
  if (s > "2019/04/30") {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[5],mx=0,mn=100000000;
	for(int i=1;i<=5;i++)
	{
	  cin>>a[i];
	  if(a[i]>mx)
	  mx=a[i];
	  if(a[i]<mn)
	  mn=a[i]; 
    }
	int k;
	cin>>k;
	if(mx-mn>k)
	  cout<<":(";
	else
	  cout<<"Yay!";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,ans,mind=1e7;
int cnt(int a){
    int sum=0;
    while(a){
        sum+=a%10;
        a/=10;
    }
    return sum;
}
main(){
    cin>>n;
    for(int i=1;i<=n/2;i++){
        ans=cnt(i)+cnt(n-i);
        if(mind>ans)mind=ans;
    }
    cout<<mind<<endl;
}

Measured memory_bytes: 256
from sys import stdin


def main() -> None:
    a, b = [int(next_str()) for _ in range(2)]
    ans = 0

    for i in range(a, b + 1):
        ans += judge(i)

    print(ans)


def judge(a: int) -> bool:
    s = str(a)
    n = len(s)

    for i in range(n // 2):
        if s[i] != s[n - i - 1]:
            return False

    return True


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

int p[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int y2,m2,d2;

bool leap(int y){

  if(y%400 == 0) return true;
  if(y%100 == 0) return false;
  if(y%4 == 0) return true;
  return false;

}

int solve(int y, int m, int d){

  if(y == y2 && m == m2 && d == d2) return 0;

  if(leap(y) && m == 2 && d == 28) return solve(y,3,1)+2;
  else if(m == 12 && d == 31) return solve(y+1,1,1)+1;
  else if(p[m] == d) return solve(y,m+1,1)+1;
  else return solve(y,m,d+1)+1;

}

int main(){

  int y,m,d;

  while(true){
    cin >> y >> m >> d >> y2 >> m2 >> d2;
    if(y < 0 || m < 0 || d < 0 || y2 < 0 || m2 < 0 || d2 < 0) break;

    cout << solve(y, m, d) << endl;
  }

}

Measured memory_bytes: 1160
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
                    .map(|e| e.parse().ok().unwrap())
                    .collect()
}


fn main() {
    let n: i64 = read();
    let mut ans = 0;
    for i in 0..100000 {
        if i*i > n {
            ans = i - 1;
            break
        }
    }
    println!("{}", ans*ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll n,k;
ll a[N],b[N];
bool ok(ll x)
{
	ll now=0;
	for(int i=1;i<=n;++i)
	{
		if(a[i]*b[i]<=x)continue;
		ll v=x/b[i];
		now+=a[i]-v;
		if(now>k)return 0;
	}
	return 1;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
	for(int i=1;i<=n;++i)scanf("%lld",&b[i]);
	sort(a+1,a+n+1);sort(b+1,b+n+1,greater<int>());
	ll l=0,r=a[n]*b[1];
	while(l<=r)
	{
		ll mid=(l+r)/2;
		if(ok(mid))r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",l); 
	return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;
const int nax = 100005;
vector <int> edges[nax];
void add_self(int &a,int b)
{
    a+=b;
    if (a>=mod)
        a-=mod;
}

long long    mul (int a,int b)
{
    return (long long)a*b%mod;
}

pair <int,int> dfs (int v,int parent)
{
    int all_white=1,sth_is_black=0;
    for (int i:edges[v])
    {
        if (i==parent)
            continue;
        pair <int,int> p=dfs(i,v);
        int pr=all_white;
        all_white = mul(all_white,p.second);
        sth_is_black = (mul(pr,p.first)+mul(sth_is_black,(p.first+p.second)%mod)) % mod;
    }
    return {all_white,(all_white+sth_is_black)% mod};
}
int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    for (int i=0;i<n-1;i++)
    {
        int x,y;
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }

    pair <int,int> ans = dfs(1,-1);
    cout << (ans.first+ans.second) % mod;
}


Measured memory_bytes: 12672
x=int(input())
arr=set(range(2,x))
for i in range(2,int(x**0.5)+1):
  arr.difference_update(range(2*i,x,i))
res=True
x-=1
while res:
  res=False
  x+=1
  for i in arr:
    if x%i==0:
      res=True
      break
print(x)

Measured memory_bytes: 14312
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n, k;
    cin >> n >> k;

    if (k == 0){
        cout << n * n << endl;
        return 0;
    }

    ll ans = (n + 1) * (n + 1);

    FOR(b,0,n){
        if (b <= k){
            ans -= n + 1;
            continue;
        }
        ll a = n + 1, tmp = 0;
        tmp += a / b * k;
        tmp += min(k, a % b);
        ans -= tmp;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int d;
	int i;
	int area;
	
	while (scanf("%d", &d) != EOF){
		
		area = 0;
		
		i = 1;
		while (i * d < 600){
			area += d * d * d * i * i;
			i++;
		}
		
		printf("%d\n", area);
	}
	
	return (0);
}

Measured memory_bytes: 0
def main():
    N = int(input())
    S = list(input())

    ans = 0
    ruiseki_r = [0]*N
    ruiseki_g = [0]*N
    ruiseki_b = [0]*N

    for i in range(N):
        if S[i] == "R":
            ruiseki_r[i] = ruiseki_r[i-1] + 1
            ruiseki_g[i] = ruiseki_g[i-1]
            ruiseki_b[i] = ruiseki_b[i-1]
        if S[i] == "G":
            ruiseki_r[i] = ruiseki_r[i-1]
            ruiseki_g[i] = ruiseki_g[i-1] + 1
            ruiseki_b[i] = ruiseki_b[i-1]
        if S[i] == "B":
            ruiseki_r[i] = ruiseki_r[i-1]
            ruiseki_g[i] = ruiseki_g[i-1]
            ruiseki_b[i] = ruiseki_b[i-1] + 1
    set_rg = set(["R", "G"])
    set_gb = set(["G", "B"])
    set_rb = set(["R", "B"])
    for i in range(N-2):
        Si = S[i]
        for j in range(i+1, N-1):
            Sj = S[j]
            if Si != Sj:
                Sij = set([Si, Sj])
                if len(Sij^set_rg) == 0:
                    remain_b = ruiseki_b[-1] - ruiseki_b[j]
                    if 2*j-i < N:
                        if S[2*j-i] == "B":
                            remain_b -= 1
                    ans = ans + remain_b
                if len(Sij^set_gb) == 0:
                    remain_r = ruiseki_r[-1] - ruiseki_r[j]
                    if 2*j-i < N:
                        if S[2*j-i] == "R":
                            remain_r -= 1
                    ans = ans + remain_r
                if len(Sij^set_rb) == 0:
                    remain_g = ruiseki_g[-1] - ruiseki_g[j]
                    if 2*j-i < N:
                        if S[2*j-i] == "G":
                            remain_g -= 1
                    ans = ans + remain_g
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74904
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
//constexpr int MOD = /**/ 1000000007; //*/ 998244353;
constexpr int MOD = 104857601;
////////////////

void solve(){
  ini(N); ins(S);
  each(x,S) {
    trc(x , N);
    rep(i,N) { x = 'A' + (x-'A'+1) % 26; trc(x); }
    trc(S);
  }
  out(S);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())

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

  ll N ; cin >> N;
  vector<ll> A;
  rep(i,N) {
    ll inp; cin >> inp;
    A.pb(inp);
  }

  sort(all(A));

  ll ans=0 ;
  ll before = -1;
  ll sum = 0;
  rep(i,N){
    if(A[i]!=before){
      ans += (sum%2);
      sum =1;
      if(i==N-1) ans++;
    }
    else {
      sum ++;
      if(i==N-1)ans += (sum%2);
    }
    before = A[i];
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);


using namespace std;

const int N = 26;
vector<int> a[26];

int main()
{
    set<int> a;
    FOR(i, 3, 0)
    {
        int x; cin >> x;
        a.insert(x);
    }
    if(a.size() == 2)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

bool is_parindrome(const string &s, char c = '?'){
    auto n = s.length();
    for (int i = 0; i < (n+1)/2; ++i) {
        if(s[i] == c || s[n-i-1] == c) continue;
        if(s[i] != s[n-i-1]) return false;
    }
    return true;
}
int main() {
    string s; int ans = 0;
    while(cin >> s) if(is_parindrome(s)) ans++;
    cout << ans << "\n";
    return 0;
}


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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define rept(i,n) for(ll (i)=0;(i)<=(ll)(n);(i)++)
#define reps(i,s,n) for(ll (i)=(s);(i)<(ll)(n);(i)++)
#define repst(i,s,n) for(ll (i)=(s);(i)<=(ll)(n);(i)++)
#define repr(i,n) for(ll (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, b, t, r;

int c(int x) {
	string s = to_string(x);
	int r = 0;
	rep(i,s.length()) r += s[i]-'0';
	return r;
}

int main() {
	cin >> n >> a >> b;
	repst(i,1,n) {
		t = c(i);
		r += (a<=t && t<=b) * i;
	}
	cout << r << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
ll gcd(ll a,ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
int main(){
    ll n,m;cin>>n>>m;
    vi v(n),num(n);
    rep(i,n)cin>>v[i];
    rep(i,n){
        ll k=v[i];
        while(k%2==0){
            k/=2;
            num[i]++;
        }
    }
    sort(all(num));
    if(num[0]!=num[n-1]){
        cout<<0<<endl;
        return 0;
    }
    ll g=1;
    rep(i,n)g=lcm(g,v[i]);
    g/=2;
    ll ans=m/g;
    if(ans==0)cout<<0<<endl;
    else cout<<(ans-1)/2+1<<endl;
}

Measured memory_bytes: 1792
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
	new Main().run();
    }
    
    boolean[][] M;
    int n;
    boolean color[];
    int d[];
    int f[];
    
    private void run() {
	Scanner scanner = new Scanner(System.in);
	n = scanner.nextInt();
	M = new boolean[n][n];
	color = new boolean[n];
	d = new int[n];
	f = new int[n];
	for (int i = 0; i < n; i++) {
	    int u = scanner.nextInt();
	    int k = scanner.nextInt();
	    u--;
	    for (int j = 0; j < k; j++) {
		int v = scanner.nextInt();
		v--;
		M[u][v] = true;
	    }
	}
	bfs(0);
    }
    
    private void bfs(int s) {
	Deque<Integer> deque = new ArrayDeque<Integer>();
	deque.offer(s);
	int count = 0;
	Arrays.fill(d, -1);
	d[0] = 0;
	color[0] = true;
	while (!deque.isEmpty()) {
	    int size = deque.size();
	    for (int i = 0; i < size; i++) {
		int q = deque.poll();
		d[q] = count;
		for (int j = 0; j < n; j++) {
		    if (M[q][j] && !color[j]) {
			color[j] = true;
			deque.offer(j);
		    }
		}
	    }
	    count++;
	    
	}
	for (int u = 0; u < n; u++) {
	    System.out.printf("%d %d\n", u + 1, d[u]);
	}
    }
    
    int tt = 1;
    
}



Measured memory_bytes: 29332
import sys
import math
def Ii():return int(sys.stdin.readline().rstrip())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

s = sys.stdin.readline().rstrip()
ans = 0
for i in s:
	ans += int(i)
	ans %= 9

print('Yes' if ans%9 == 0 else 'No')

Measured memory_bytes: 9180
#include<stdio.h>

#define M 200000
#define S 2000000000

int L[M/2+2],R[M/2+2];
long b1,b2,b3;

long mer(int *a,int n,int left,int right,int man){

  int i,j,k=0;
  long cou=0;

  int na=man-left;
  int nb=right-man;

  for(i=0;i<na;i++) L[i]=a[left+i];
  for(i=0;i<nb;i++) R[i]=a[man+i];

  L[na]=R[nb]=S;

  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      a[k]=L[i++];
    }else{
      
      a[k]=R[j++];
      cou+=na-i;
    }
  }
  return cou;
}

long sort(int *a,int n,int right,int left){
  int man;
  long b1,b2,b3;
  

  if(left+1<right){
    man=(left+right)/2;
    b1=sort(a,n,man,left);
    b2=sort(a,n,right,man);
    b3=mer(a,n,left,right,man);
    return b1+b2+b3;
  }else return 0;
}

int main(){
  int a[M],n,i;
  long ans=0;

  scanf("%d",&n);

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


  ans=sort(a,n,n,0);
  printf("%ld\n",ans);

  return 0;
}

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

using namespace std;

void solve() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (auto&& e : A) {
    cin >> e;
  }
  string S;
  cin >> S;
  vector<int64_t> B;
  for (int i = N - 1; i > -1; i--) {
    int64_t x = A[i];
    for (auto b : B) {
      x = min(x, x ^ b);
    }
    if (S[i] == '0') {
      if (x > 0) B.emplace_back(x);
    } else if (x > 0) {
      cout << 1 << '\n';
      return;
    }
  }
  cout << 0 << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}


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

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

    int T;
    cin >> T;

    while (T--) {
        int n;
        cin >> n;

        ll s = 0;
        vector<vector<int>> c[2];
        for (int h = 0; h < 2; h++) {
            c[h].resize(n + 1);
        }
        for (int i = 0; i < n; i++) {
            int k, l, r;
            cin >> k >> l >> r;

            s += max(l, r);
            int g = l - r;
            int h = g < 0;
            c[h][h == 0 ? k : n - k].push_back(abs(g));
        }
        for (int h = 0; h < 2; h++) {
            priority_queue<int, vector<int>, greater<>> pq;
            for (int i = 0; i <= n; i++) {
                for (int g : c[h][i]) {
                    pq.push(g);
                }
                while ((int)pq.size() > i) s -= pq.top(), pq.pop();
            }
        }
        cout << s << '\n';
    }

    return 0;
}

Measured memory_bytes: 17928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int product = a * b;
		if(product % 2 == 0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef long long ll;
 
using namespace std;

ll comb(int n,int k){
  ll dp[n+1][n+1];
  rep(i,n){
    dp[i][0]=1;
    dp[i][i+1]=1;
  }
  rep(i,n-1){
    REP(j,1,i+2)  dp[i+1][j]=dp[i][j-1]+dp[i][j];
  }
  return dp[n-1][k];
}

int main(){
  int N,A,B,temp;
  cin >> N >> A >> B;
  temp=A;
  ll a,prea=0,ans=0;
  double ave;
  bool first=true;
  map<ll,int,greater<ll>> mp;
  rep(i,N){
    cin >> a ;
    if(EXIST(mp,a)){
      mp[a]++;
    }else{
      mp[a]=1;
    }
  }

  auto itr=mp.begin();
  while(itr!=mp.end()){
    if((temp - itr->second <= 0) && first){
      REP(i,A,min(itr->second,B)+1)  ans+=comb(itr->second,i);
      ave=itr->first;
      printf("%.6lf\n",ave);
      cout << ans << endl;
      return 0;
    }else if (temp - itr->second <= 0){
      ans=comb(itr->second,temp);
      ave = (ave + itr->first * temp)/A;
      printf("%.6lf\n",ave);
      cout << ans << endl;
      return 0;
    }
    temp -= itr->second;
    ave += itr->first * itr->second;
    first=false;
    ++itr;
  }

  return 0;
}

Measured memory_bytes: 256