akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 100000000000000003;

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


	int N;
	cin >> N;
	set<pair<int, string>> ST;
	rep(i, N) {
		string S;
		cin >> S;
		int n = S.size();
		ST.insert(mp(n, S));
	}

	ll kotae = 0;
	map<ll, int> ha;
	for (auto p : ST) {
		string S = p.second;
		int M = S.size();
		int k[26] = {};
		ll are = 0;
		for (int i = M - 1; i >= 1; i--) {
			if (ha.find(are) != ha.end()) {
				int tmp = ha[are];
				rep(j, 26) if ((tmp >> j & 1)) {
					k[j]++;
				}
			}
			if (k[S[i] - 'a']) {
				kotae += k[S[i] - 'a'];
				k[S[i] - 'a'] = 0;
			}
			are = (are * 30 + S[i] - 'a' + 1) % mod;
		}

		if (k[S[0] - 'a']) {
			kotae += k[S[0] - 'a'];
			k[S[0] - 'a'] = 0;
		}

		ha[are] |= 1 << (S[0] - 'a');
	}
	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 27932
#!/usr/bin/env python3
l, r = map(int, input().split())
a = 2019
b = 0
for i in range(l, r + 1):
    for j in range(i+1, r + 1):
        if i % 2019 == 0 or j % 2019 == 0:
            print(0)
            b = 1
            break
        else:
            a = min(a, (i%2019)*(j%2019)%2019)
    else:
        continue
    break
if b == 0:
    print(a)

Measured memory_bytes: 3064
M, D = map(int, input().split())

ans = 0
for m in range(4, M+1):
    for d in range(20, D+1):
        d10 = d//10
        d1 = d%10
        if d10>=2 and d1>=2 and d10*d1==m:
            ans += 1

print(ans)

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

int main() {
    int N, M;   
    cin >> N >> M;
    long long int x[1100], y[1100], z[1100]; 
    for(int i = 0; i < N; ++i){
    cin >> x[i] >> y[i] >> z[i];
    }
    long long int A[1100]; 
    for(int i = 0; i < N; ++i){
    A[i] = x[i] + y[i] + z[i];
    }
    long long int X1 = 0; 
    sort(A, A + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X1 += A[i] ;
    }
    long long int B[1100]; 
    for(int i = 0; i < N; ++i){
    B[i] = x[i] + y[i] - z[i];
    }
    long long int X2 = 0; 
    sort(B, B + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X2 += B[i] ;
    }
    long long int C[1100]; 
    for(int i = 0; i < N; ++i){
    C[i] = x[i] - y[i] + z[i];
    }
    long long int X3 = 0; 
    sort(C, C + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X3 += C[i] ;
    }
    long long int D[1100]; 
    for(int i = 0; i < N; ++i){
    D[i] = x[i] - y[i] - z[i];
    }
    long long int X4 = 0; 
    sort(D, D + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X4 += D[i] ;
    }
    long long int E[1100]; 
    for(int i = 0; i < N; ++i){
    E[i] = - x[i] + y[i] + z[i];
    }
    long long int X5 = 0; 
    sort(E, E + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X5 += E[i] ;
    }
    long long int F[1100]; 
    for(int i = 0; i < N; ++i){
    F[i] = - x[i] + y[i] - z[i];
    }
    long long int X6 = 0; 
    sort(F, F + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X6 += F[i] ;
    }
    long long int G[1100]; 
    for(int i = 0; i < N; ++i){
    G[i] = - x[i] - y[i] + z[i];
    }
    long long int X7 = 0; 
    sort(G, G + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X7 += G[i] ;
    }
    long long int H[1100]; 
    for(int i = 0; i < N; ++i){
    H[i] = - x[i] - y[i] - z[i];
    }
    long long int X8 = 0; 
    sort(H, H + N, greater<long long int>()); 
    for(int i = 0; i < M; ++i){
    X8 += H[i] ;
    }
    long long int k, l, m, n;
    k = max(X1, X2); 
    l = max(X3, X4); 
    m = max(X5, X6); 
    n = max(X7, X8); 
    cout << max(max(k, l), max(m, n)) << endl; 
}

Measured memory_bytes: 384
k = %[Man Oku Cho Kei Gai Jo Jou Ko Kan Sei Sai Gok Ggs Asg Nyt Fks Mts].split.to_a
k.unshift("")
while gets
  m, n = $_.split.map(&:to_i)
  break if m == 0 && n == 0
  v = m ** n
  x = []
  a = v.to_s.size / 4
  (0..a).each{ |i| x[i] = v / 10**(4*i) % 10000 }
  (0..a).each{ |i| print x[a-i], k[a-i] if x[a-i] > 0 }
  puts
end

Measured memory_bytes: 8760
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    long long a, b, x;

    scanf("%lld%lld%lld", &a, &b, &x);

    long long l, r;

    if(a % x == 0){
        l = a / x;
    }else{
        l = a / x + 1;
    }

    r = b / x;

    printf("%lld\n", r - l + 1);

    return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
using namespace std;
int main(){

  while(1){
    double n,sum=0,a[1000];
    double av=0,s=0;
    cin>>n;
    if(n==0)break;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  av=sum/n;
  for(int i=0;i<n;i++){
    s+=pow(a[i]-av,2);
  }
  s/=n;
  //printf("%.10f\n",sqrt(s));
  cout<<setprecision(10)<<sqrt(s)<<endl;
  }
  return 0;
  
}


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

int main()
{
	int n, a, b, count = 0, pointX = 0, pointY = 0;
	cin >> n;
	do {
		cin >> a >> b;
		if (a > b) {
			pointX += (a + b);
		}
		else if (a < b) {
			pointY += (a + b);
		}
		else {
			pointX += a;
			pointY += b;
		}
		count++;
		if (count == n) {
			cout << pointX << " " << pointY << endl;
			pointX = pointY = count = 0;
			cin >> n;
		}
	} while (n != 0);
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 1;i<=n;++i)
using ll = long long;
using P = pair<string,int>;

int main(){
  int n;
  cin >> n;
  vector<int> a(n+10);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(i,n){
    if(a[a[i]] == i) ++ans;
  }
  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 640
import numpy as np
n, m, c = map(int, input().split())
b = np.array(list(map(int, input().split())))
a_l = [ np.array(list(map(int, input().split()))) for _ in range(n) ]

r = 0
for a in a_l:
    if np.dot(a, b) + c > 0:
      r += 1
print(r)

Measured memory_bytes: 12508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if ("AKIHABARA".equals(s) || "KIHABARA".equals(s) || "AKIHBARA".equals(s) || "AKIHABRA".equals(s)
				|| "AKIHABAR".equals(s) || "KIHBARA".equals(s) || "KIHABRA".equals(s) || "KIHABAR".equals(s)
				|| "AKIHBRA".equals(s) || "AKIHBAR".equals(s) || "AKIHABR".equals(s) || "AKIHBR".equals(s)
				|| "KIHABR".equals(s) || "KIHBRA".equals(s) || "KIHBAR".equals(s)|| "KIHBR".equals(s)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 35696
<?php

fscanf(STDIN, "%f %f %f %f", $x_1, $y_1, $x_2, $y_2);
$x_diff = abs($x_2 - $x_1);
$y_diff = abs($y_2 - $y_1);

$x_diff = $x_diff ** 2;
$y_diff = $y_diff ** 2;

echo sqrt($x_diff+$y_diff)."\n";


Measured memory_bytes: 9204
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    string S;
    cin >> S;
    if (S[0] == S[1] && S[1] == S[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3600
//強連結成分分解
//O(V + E)
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
#define MAX_V 100010
 
int V, E;                                       //頂点数　辺数
vector<int> G[MAX_V];                           //グラフの隣接リスト表現(0-indexed)
vector<int> rG[MAX_V];                          //辺の向きを逆向きにしたグラフ
vector<int> vs;                                 //帰りがけ順での頂点の並び
bool used[MAX_V];                               //dsfのために、すでに訪れたかどうかを管理する
int cmp[MAX_V];                                 //属する強連結成分のトポロジカル順序
 
void dfs(int v){
 
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++){
        if(!used[G[v][i]]) dfs(G[v][i]);
    }
 
    //帰りがけ順に格納
    vs.push_back(v);
}
 
void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    for(int i = 0; i < (int)rG[v].size(); i++){
        if(!used[rG[v][i]]) rdfs(rG[v][i], k);
    }
}
 
int scc(){
    memset(used, false, sizeof(used));
    vs.clear();
    for(int v = 0; v < V; v++){
        if(!used[v]) dfs(v);
 
    }
    memset(used, false, sizeof(used));
    int k = 0;
    for(int i = V - 1; i >= 0; i--){
        if(!used[vs[i]]){
            rdfs(vs[i], k);
            k++;
        }
    }    
    return k;
}
 
int main(){
 
    //入力
    cin >> V >> E;                              //頂点数　辺数
     
    for(int i = 0; i < E; i++){
        int from, to; cin >> from >> to;        //from -> toへの有向辺
        G[from].push_back(to); 
        rG[to].push_back(from);
    }
 
    memset(used, false, sizeof(used));
    scc();
     
    int Q; cin >> Q;
    for(int i = 0; i < Q; i++){
        int u, v; cin >> u >> v;
        cout << (cmp[u] == cmp[v]) << endl;
    }
    return 0;
}


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


int main(){
  int64_t N,M,t=0;
  cin >> N >> M;
  vector<int> s(M),c(M);
  for(int64_t i=0;i<M;i++){
    cin >> s.at(i) >> c.at(i);
  }
  if(N==1){
    for(int64_t j=0;j<M;j++){
      if(c.at(j)!=0){
        t=1;
        break;
      }
    }
    if(t==0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int64_t i=pow(10,N-1);i<pow(10,N);i++){
    t=0;
    for(int64_t j=0;j<M;j++){
      if(i/(int)pow(10,N-s.at(j))-(i/(int)pow(10,N-s.at(j)+1))*10!=c.at(j)){
        t=1;
        break;
      }
    }
    if(t==0){
      cout << i << endl;
      return 0;
    }
    
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<string>
typedef long long int lli;
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //vector<string> v = {"ABC"};
    lli t;
    cin >> t;
    lli cnt=0;
    for(lli i=1; i<=t; ++i){
        if((i>9&&i<100)){
            continue;
        }else if(i>999&&i<10000){
            continue;
        }else if(i>99999&&i<=1000000){
            continue;
        }
        else{
        cnt++;
        }
    }
    
 
  
        
        cout<<cnt<<"\n";
    return 0;
}

//100 >1000
//10000 > 1000000

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
typedef long long Int;

int N, M, L, P[200], T[200], V[200];
double zp[200][200], zt[200][200];

Int C[100][100];

int main() {
    C[0][0] = 1;
    rep(i, 80) rep(j, 80) C[i+1][j]+=C[i][j], C[i+1][j+1]+=C[i][j];

    scanf("%d%d%d", &N, &M, &L);
    rep(i, N) scanf("%d%d%d", P+i, T+i, V+i);
    rep(i, N) rep(j, M+1) {
        const double p = P[i]/100.0;
        zt[i][j] = (double)L/V[i] + (double)j*T[i];
        zp[i][j] = (double)C[M][j] * pow(p, j) * pow(1-p, M-j);
    }
    rep(i, N) {
        double ans = 0;
        if(V[i]!=0) rep(j, M+1) {
            double f = 1.0;
            rep(k, N) if(i!=k) {
                double p = 0;
                rep(l, M+1) if(zt[i][j]<zt[k][l]) p += zp[k][l];
                f *= p;
            }
            ans += zp[i][j] * f;
        }
        printf("%.9f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int t, p, r;
class Team{
public:
  int id, ac, pa;
  int prob[11];
  Team(int id, int ac, int pa):id(id), ac(ac), pa(pa){
    fill(prob, prob+11, 0);
  }
  bool operator < (const Team &o)const{
    if(ac < o.ac)return false;
    else {
      if(ac == o.ac){
	if(pa == o.pa) return id < o.id;
	return pa < o.pa;
      }
    }
    return true;
  }
};
vector<Team> v;
int main(){
  while(cin >> t >> p >> r, (t || p || r)){
    v.clear();
    for(int i = 0 ; i < t; i++) v.push_back(Team(i+1,0,0));
    for(int i = 0 ; i < r; i ++){
      int tID, pID, time;
      string msg;
      cin >> tID >> pID >> time >> msg;
      if(msg == "WRONG"){
	v[tID-1].prob[pID]++;
      }else{
	v[tID-1].ac++;
	v[tID-1].pa += v[tID-1].prob[pID]*1200+time;
      } 
    }
    sort(v.begin(), v.end());
    for(int i = 0 ; i <  v.size(); i++){
      cout << v[i].id << " " << v[i].ac << " " << v[i].pa << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
n, m = map(int, input().split())
a = list()
for i in range(n) :   #1行ずつn行まで読み込みlistに格納
 a.append(list(map(int, input().split())))
b = list()
for j in range(m) :
 b.append(int(input()))
   
for i in range(n) :
 s = 0
 for j in range(m) :
   s += a[i][j] * b[j]
 print(s)


Measured memory_bytes: 6004
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long Int;

Int fblen(Int x){//x inclusive
	return (x/3 + x/5) * 4;
}

Int cntnum(Int x){
	return x - x/3 - x/5 + x/15;
}

Int numlen(Int x){
	Int res = 0;
	Int b = 1;
	while(b <= x){
		res += cntnum(x) - cntnum(b-1);
		b *= 10;
	}
	return res;

	
}

Int len(Int x){
	return numlen(x) + fblen(x);
}

string num(Int x){
	if(x == 0)return "";
	return num(x/10) + (char)('0' + (x%10));
}


int main(){
	Int s;
	cin >> s;
	Int bottom = 0, top = 1e18;
	while(top - bottom > 1){
		Int mid = (top + bottom) / 2;
		if(len(mid) < s)bottom = mid;
		else top = mid;								 
	}
	Int l = len(bottom);
	string tmp;
	for(Int i = bottom + 1;l + tmp.size() <= s + 20;i++){
		if(i % 3 == 0)tmp += "Fizz";
		if(i % 5 == 0)tmp += "Buzz";
		if(i % 3 != 0 && i % 5 != 0)tmp += num(i);
	}
	for(Int i = 0;i < tmp.size();i++){
		if(l + i < s-1)continue;
		if(l + i > s + 18)continue;
		cout << tmp[i];
	}cout << endl;
	return 0;
}


Measured memory_bytes: 3220
N, A, B = map(int,input().split())

s = 0

for x in range(1,N+1):
    a = int(x%10)
    b = int((x%100)/10)
    c = int((x%1000)/100)
    d = int((x%10000)/1000)
    e = int((x%100000)/10000)
    t = a+b+c+d+e
    if t<=B and t>=A:
        s = s + x
print(s)


Measured memory_bytes: 3060
import java.util.Scanner

fun main(argv : Array<String>){
    
    val sc = Scanner(System.`in`)
    
    val x = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
 
    when {
        Math.abs(x-a)-Math.abs(x-b) <0 -> println("A")
        else -> println("B")
    }
}


Measured memory_bytes: 31260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,k; cin>>a>>b>>c>>d>>k;
    int mi = (c-a)*60 + (d-b);
    cout<<max(mi-k, 0)<<endl;
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main () {
  int A, B, M;
  cin >> A >> B >> M;
  int amin = 1000000;
  int bmin = 1000000;
  int re[100002];
  int mi[100002];
  for (int i = 0; i < A; i ++) {
    cin >> re[i];
    if (amin > re[i]) amin = re[i];
  }
  for (int i = 0; i < B; i ++) {
    cin >> mi[i];
    if (bmin > mi[i]) bmin = mi[i];
  }
  int ans = amin + bmin;
  for (int i = 0; i < M; i ++) {
    int a, b, c;
    cin >> a >> b >> c;
    a --;
    b --;
    int kj = re[a] + mi[b] - c;
    if (ans > kj) ans = kj;
  }
  cout << ans << endl;
}

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

int main () {
  int A;
  cin >> A;
  
  if (A < 10) {
    if (A == 2 || A == 4 || A ==5 || A == 7 || A == 9) {
      cout << "hon" << endl;
    }
    
    if (A == 0 || A == 1 || A == 6 || A == 8) {
      cout << "pon" << endl;
    }
    
    if (A == 3) {
      cout << "bon" << endl;
    }
  }
  
  if (A >= 10) {
    if (A % 10 == 2 || A % 10 == 4 || A % 10 == 5 || A % 10 == 7 || A % 10 == 9) {
      cout << "hon" << endl;
    }
    
    if (A % 10 == 0 || A % 10 == 1 || A % 10 == 6 || A % 10 == 8) {
      cout << "pon" << endl;
    }
    
    if (A % 10 == 3) {
      cout << "bon" << endl;
    }
  }
}


Measured memory_bytes: 3600
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int keep = 1;
        int left = 0;
        int now = 0;
        int next = 0;
        long result = 0;
        for(int i = 0; i < S.length(); i++){
            char c = S.charAt(i);
            if(c == '<'){
                next = now + 1;
                result += next;
                keep = 0;
                left = next;
            }else{
                next = 0;
                if(now == 0){
                    if(left > keep - 1){
                        result += keep - 1;
                    }else{
                        result += keep;
                    }
                }
            }
            keep++;
            now = next;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 28876
#include <stdio.h>

int main(void){
  int a,b,x,num=0;
  scanf("%d",&x );
  int i=1;
  while(1){
    num=num+i;
    if(num>=x){
      break;
    }
    i++;
  }
  printf("%d\n",i );

  return 0;
}


Measured memory_bytes: 128
import java.util.*
import kotlin.collections.ArrayList

data class Node(val p:Int, val n:Int)

fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val list = ArrayList<Node>()
    var start = 0
    var end = 0

    for(i in 0 until n) {
        var k = 0
        var minus = 0
        var plus = 0
        val s = sc.next()
        for(c in s) {
            if(c == '(') {
                if(k < 0) {
                    minus += k
                    k = 0
                }
                ++k
            } else if(c==')'){
                --k
            }
        }
        if(k > 0) {
            plus += k
        } else if(k < 0) {
            minus += k
        }

        if(minus == 0 || plus == 0) {
            start += plus
            end += minus
        } else {
            list.add(Node(plus, minus))
        }
    }

    val pq = PriorityQueue<Node>(kotlin.Comparator { o1, o2 ->
        val v1 = o1.n + o1.p
        val v2 = o2.n + o2.p
        return@Comparator v2.compareTo(v1)
    })

    list.sortByDescending { it.n }

    var idx = 0
    var isSuccess = true

    while (isSuccess && idx < list.size) {
        while(idx < list.size && list[idx].n <= start) {
            pq.add(list[idx++])
        }
        while (pq.isNotEmpty()) {
            val node = pq.poll()
            start += node.n
            if(start < 0) {
                isSuccess = false
                break
            }
            start += node.p
        }
    }
    if(isSuccess) {
        val ret = start + end
        isSuccess = ret == 0
    }

    if(isSuccess) {
        print("Yes")
    } else {
        print("No")
    }
}

Measured memory_bytes: 67876
#include<stdio.h>

int main(void){

  int N, L;

  scanf("%d",&N);

  if(N<=10000){

    if(N<=1000){
      L=1000-N;
    }if((1000<N)&&(N<=2000)){
      L=2000-N;
    }if((2000<N)&&(N<=3000)){
      L=3000-N;
    }if((3000<N)&&(N<=4000)){
      L=4000-N;
    }if((4000<N)&&(N<=5000)){
      L=5000-N;
    }if((5000<N)&&(N<=6000)){
      L=6000-N;
    }if((6000<N)&&(N<=7000)){
      L=7000-N;
    }if((7000<N)&&(N<=8000)){
      L=8000-N;
    }if((8000<N)&&(N<=9000)){
      L=9000-N;
    }if((9000<N)&&(N<=10000)){
      L=10000-N;
    }

    printf("%d\n",L);

  }

  return 0;
}


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

int main() {
    string S;
    cin >> S;
    
    if (S == "SUN") cout << 7 << endl;
  if (S == "MON") cout << 6 << endl;
  if (S == "TUE") cout << 5 << endl;
  if (S == "WED") cout << 4 << endl;
  if (S == "THU") cout << 3 << endl;
  if (S == "FRI") cout << 2 << endl;
  if (S == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    while (true)
    {
        ll a, b, t;
        cin>>a>>b;
        if (a==0 && b==0) break;
        if (b<a)
        {
            t=a;
            a=b;
            b=t;
        }
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}



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

using namespace std;

int solve() {
    int n, k; cin >> n >> k;
    vector<int> nums;
    int a;
    for (int i = 0 ; i < n; ++i) {
        cin >> a;
        nums.push_back(a);
    }
    sort(nums.begin(), nums.end());

    int res = 0;
    for (int i = 0; i < k; ++i) {
        res += nums[i];
    }

    return res;
}

int main() {
	cout << solve() << endl;
}


Measured memory_bytes: 3128
#include<iostream>
#include<functional>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

struct edge{
	int from;
	int to;
	int cost;
};

struct city{
	int number;
	int cost;
};

int main(){
	int n,m,k,a,cost[3002],ret=0;
	edge e;
	vector<edge> ve[3002];
	vector<edge> E;
	priority_queue<city,vector<city>,function<bool(city,city)>> c([](city x,city y){return x.cost<=y.cost;});
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		cost[i]=100000000;
	}
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&e.from,&e.to,&e.cost);
		E.push_back(e);
		ve[e.from].push_back(e);
		a=e.from; e.from=e.to; e.to=a;
		ve[e.from].push_back(e);
	}
	for(int i=0;i<k;i++){
		city C;
		scanf("%d",&C.number);
		C.cost=0;
		cost[C.number]=0;
		c.push(C);
	}
	while(!c.empty()){
		city C=c.top(); c.pop();
		if(C.cost==cost[C.number]){
			int s=ve[C.number].size();
			for(int i=0;i<s;i++){
				edge ed=ve[C.number][i];
				if(cost[ed.to]>cost[ed.from]+ed.cost){
					cost[ed.to]=cost[ed.from]+ed.cost;
					city cit;
					cit.number=ed.to; cit.cost=cost[ed.to];
					c.push(cit);
				}
			}
		}
	}
	/*for(int i=1;i<=n;i++){
		printf("%d\n",cost[i]);
	}*/
	for(int i=0;i<m;i++){
		ret=max(ret,(cost[E[i].from]+cost[E[i].to]+E[i].cost+1)/2);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 6584
#include<stdio.h>
int main(void){
  int H,W;
  do{
    int i,j;
    scanf("%d %d",&H,&W);
    if(H==0&&W==0||H>300||300<W)
      return 0;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        if(i==0||i==H-1||j==0||j==W-1)
          printf("#");
        else
          printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }while(H!=0||W!=0);
  return 0;
}

Measured memory_bytes: 572
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    
    #でかいやつから左右両端のどちらかに動かす
    B=sorted(zip(A,range(N)),reverse=True)
    
    #dp[i][j]は左からi個右からj個埋まっている時の最大値
    dp=[[0]*(N+1) for _ in range(N+1)]
    
    for k in range(N):
        a=B[k][0]
        x=B[k][1]
        
        for i in range(k+1):
            j=k-i
            #右詰
            y=N-j-1
            dp[i][j+1]=max(dp[i][j+1],dp[i][j]+a*abs(x-y))
            
            #左詰
            y=i
            dp[i+1][j]=max(dp[i+1][j], dp[i][j]+a*abs(x-y))
                
    ans=0
    for i in range(N+1):
        ans=max(ans,dp[i][N-i])
    print(ans)
        
    
    

        
        
        

main()


Measured memory_bytes: 105644
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 1; i <= N; i++){
    if (i % K == 0){
      ans1++;
    } else if ((2*i) % K == 0){
      ans2++;
    }
  }
  long long int ans = pow(ans1, 3.0) + pow(ans2, 3.0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main(){
  string S;
  cin >> S;
  int len = S.length();
  int midPos = (int)(len/2);
  int tmp = len % 2;
  int cnt = 0;
  for(int i = 0; i <= midPos-1; i++){
    if(S[midPos-i-1] != S[midPos+i+tmp]){
      cnt = cnt + 1;
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

ll reve(ll x){
    ll t=0;
    while(x>0)
    {
        t+=x%10;
        x/=10;
        t*=10;
    }
    t/=10;
    return t;
}
int main(){
    ll A,B,cnt=0;
    cin>>A>>B;
    for(ll i=A;i<=B;i++){
        if(i==reve(i)) cnt++;
    }
    p(cnt);
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 10000;
// const ll INF = 1LL<<60;
// // typedef struct Node { ll num; char c; } node;
// const ll N_MAX = 2000001;
// const ll V_MAX = 10000;
const int NIL = -1;

struct node { int parant, left, right; };
vector<int> depth, height;
vector<struct node> tree;

void setDepth(int u, int d) {
    if( u == NIL) return;
    depth.at(u) = d;
    setDepth(tree.at(u).left, d + 1);
    setDepth(tree.at(u).right, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if( tree.at(u).left != NIL) h1 = setHeight(tree.at(u).left) + 1;
    if( tree.at(u).right != NIL) h2 = setHeight(tree.at(u).right) + 1;
    return height.at(u) = (h1 > h2 ? h1 : h2);
}

int getSiblink(int u) {
    if( tree.at(u).parant == NIL ) return NIL;
    if( tree.at(tree.at(u).parant).left != u && tree.at(tree.at(u).parant).left != NIL )
        return tree.at(tree.at(u).parant).left;
    if( tree.at(tree.at(u).parant).right != u && tree.at(tree.at(u).parant).right != NIL )
        return tree.at(tree.at(u).parant).right;
    return NIL;
}

void print(ll u) {
    int i, c, deg = 0;
    cout << "node " << u << ": ";
    cout << "parent = " << tree.at(u).parant << ", ";
    cout << "sibling = " << getSiblink(u) << ", ";
    if( tree.at(u).left != NIL) deg++;
    if( tree.at(u).right != NIL) deg++;
    cout << "degree = " << deg << ", ";
    cout << "depth = " << depth.at(u) << ", ";
    cout << "height = " << height.at(u) << ", ";
    if( tree.at(u).parant == NIL) cout << "root\n";
    else if( tree.at(u).left == NIL && tree.at(u).right == NIL ) cout << "leaf\n";
    else cout << "internal node\n";
}

signed main() {
    ll n; scanf("%lld", &n); 
    depth.resize(n); tree.resize(n); height.resize(n);
    ll l, c;
    for( ll i = 0; i < n; i++ ) tree.at(i).parant = NIL;
    for( ll i = 0; i < n; i++ ) {
        ll v, l, d; cin >> v >> l >> d;
        tree.at(v).left = l;
        tree.at(v).right = d;
        if( l != NIL ) tree.at(l).parant = v;
        if( d != NIL ) tree.at(d).parant = v;
    }
    int root = 0;
    for(ll i = 0; i < n; i++) if( tree.at(i).parant == NIL ) root = i;
    setDepth(root, 0);
    setHeight(root);

    for( ll i = 0; i < n; i++ ) print(i);

    return 0;
}





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

int main() {
  ll n, p;
  cin >> n >> p;
  ll r = 1;
  if (n == 1) {
    r = p;
  } else if (n < 40) {
    for (int i = 1; i <= p; i++) {
      ll x = pow(i, n);
      if (x > p) {
        break;
      }
      if (p % x == 0) {
        r = i;
      }
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 256
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
    

def cnt(n):
    x = int(-0.5 + pow(1+8*n,0.5)/2)
    if n < x*(x+1)//2:
        return x-1
    else:
        return x
    

def main():
    n = ni()
    ps = factorization(n)
    ans = 0
    for pi in ps:
        if pi[0] != 1:
            ans += cnt(pi[1])
    print(ans)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 63544
<?php
fscanf(STDIN,"%d%d",$n,$k);
$p_li = explode(" ",trim(fgets(STDIN)));

$expect_val = array();
for($i=0;$i<$n;$i++){
  $expect_val[] += ($p_li[$i]*(1+$p_li[$i]))/(2*$p_li[$i]);
}

$sum = 0;
for($i=0;$i<$k;$i++) $sum += $expect_val[$i];
$max = $sum; 
for($i=0;$i<$n-$k;$i++){
  $sum -= $expect_val[$i];
  $sum += $expect_val[$i+$k];
  $max = max($sum,$max);
}
echo $max;

Measured memory_bytes: 37416
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;

public class Main {
	private static class Edge implements Comparable<Edge> {
		int cost = Integer.MAX_VALUE;
		int from;
		int to;

		@Override
		public int compareTo(Edge o) {
			return this.cost - o.cost;
		}
	}

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		List<List<Edge>> G = new ArrayList<List<Edge>>();
		for (int i = 0; i < n; i++) {
			G.add(new ArrayList<Edge>());
		}
		for (int i = 0; i < n; i++) {
			String line = br.readLine().trim();
			String[] nums = line.split(" ");
			int k = Integer.parseInt(nums[1]);
			for (int j = 0; j < k; j++) {
				Edge e = new Edge();
				e.to = Integer.parseInt(nums[2 + j * 2]);
				e.cost = Integer.parseInt(nums[2 + j * 2 + 1]);
				G.get(i).add(e);
			}
		}

		PriorityQueue<Edge> q = new PriorityQueue<Edge>();
		long[] cost = new long[n];
		cost[0] = 0;
		for (int i = 1; i < n; i++) {
			cost[i] = Integer.MAX_VALUE;
		}
		Edge s = new Edge();
		s.cost = 0;
		s.from = 0;
		q.offer(s);

		while (!q.isEmpty()) {
			Edge e = q.poll();
			int v = e.from;
			if (cost[v] < e.cost) {
				continue;
			}

			List<Edge> adjs = G.get(v);
			for (int i = 0; i < adjs.size(); i++) {
				Edge adj = adjs.get(i);
				if (cost[adj.to] > cost[v] + adj.cost) {
					cost[adj.to] = cost[v] + adj.cost;
					Edge to = new Edge();
					to.cost = (int) cost[adj.to];
					to.from = adj.to;
					q.offer(to);
				}
			}
		}

		for (int i = 0; i < n; i++) {
			System.out.println(i + " " + cost[i]);
		}

		if (br != null) {
			br.close();
			br = null;
		}
	}
}

Measured memory_bytes: 80860
# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, A):
    flag = 0
    ans = 1
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            if flag == -1:
                ans += 1
                flag = 0
            else:
                flag = 1

        if A[i] > A[i + 1]:
            if flag == 1:
                ans += 1
                flag = 0
            else:
                flag = -1

    return ans


def main():
    N = II()
    A = ILI()
    print(solve(N, A))
 
 
if __name__ == "__main__":
    main()


Measured memory_bytes: 15408
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e9+7;

int main(){
   int n; cin >> n;
   bool flag = false;
   for(int i = 0; i < 3; i++){
      int a = n%10;
      if(a == 7) flag = true;
      n /= 10;
   }
   if(flag == true) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 3620
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int[] digits={111111, 110, 1011011, 1001111, 1100110, 1101101,
				1111101, 100111, 1111111, 1101111};
		for(;;){
			int n=sc.nextInt();
			if(n<0){
				break;
			}
			int digit=0;
			for(int k=0;k<n;k++){
				int m=sc.nextInt();
				int d=1000000;
				for(int i=0; i<7; i++){
					// debug(i,(digit/d)%10,(digits[m]/d)%10);
					if((digit/d)%10==(digits[m]/d)%10){
						print("0");
					}else{
						print("1");
					}
					d/=10;
				}
				println("");
				digit=digits[m];
			}
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

int main(){
	int n,x;
	cin >> n >> x;
	vector<int> a(n+1,0);
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	
	long long int count = 0;
	for(int i=1; i<=n; i++){
		if(a[i]+a[i-1]>x){
			count += a[i]+a[i-1] -x;
			a[i] = x-a[i-1];
		}
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;
#define repeat(i, n) for(int i = 0; i < (n); i++)


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

	int A[100001] = {};
	long long B[100001] = {};
	map<int, int> MAP;

	repeat(i, N) {
		cin >> A[i];
		B[i + 1] = B[i] + A[i];

		B[i + 1] %= M;

		MAP[(int)B[i + 1]]++;
	}
	MAP[0]++;

	long long result = 0;

	for (auto ITR : MAP){
		result += 1ll * ITR.second * (ITR.second - 1) / 2;
	}


	//出力
	cout << result << endl;






	return 0;
}

Measured memory_bytes: 4352
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> a(n, true);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      a.at(tmp) = false;
    }
  }

  int ans = 0;
  for (auto hoge : a) {
    if (hoge) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
n, m = map(int, input().split())
k = []
s = []
for i in range(m):
	tmp = list(map(int, input().split()))
	k.append(tmp[0])
	s.append(tmp[1:])
p = list(map(int, input().split()))

ans = 0
for switchs in range(1<<n):
	switch_on = []
	for j in range(n):
		if (switchs>>j)&1 == 1:
			switch_on.append(j+1)
	for denkyu in range(m):
		tmp = 0
		for s_denkyu in s[denkyu]:
			if s_denkyu in switch_on:
				tmp += 1
		if tmp%2 != p[denkyu]: 
			break
	else:
		ans += 1

print(ans)

		

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	int c[N] = {};
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		c[a]++; c[b]++;
	}
	rep(i, N) {
		cout << c[i] << endl;
	}


    return 0;
}


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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n;
    cin >> n;

    string s = "";

    while(n != 0) {
        if(n % 2 != 0) {
            n--;
            s += "1";
        }
        else {
            s += "0";
        }

        n  /= (-2);
    }
    reverse(s.begin(), s.end());
    if(s.size() == 0) {
        cout << 0 << endl;
    }
    else {
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
import collections
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(N))
c_values = list(c.values())

list = []
number = 1

cnt = 2
while len(list) < 100:
    for j in range(cnt):
        list.append(number)
    number += 1
    cnt += 1

ans = 0
for i in range(len(c_values)):
    ans += list[c_values[i]-1]

print(ans)

Measured memory_bytes: 9472
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    s = 0
    ans = "YES"
    for i in range(n):
        k = input()
        if k == "Un":
            s -= 1
        else:
            s += 1
        if s < 0:
            ans = "NO"
    if s:
        print("NO")
    else:
        print(ans)
    return

#B
def B():
    return

#C
def C():
    n,q = LI()
    p = LIR(n)
    for _ in range(q):
        x0,y0,z0,s,t,u = LI()
        a,b,c = (s-x0,t-y0,u-z0)
        ans = 0
        su = a**2+b**2+c**2
        for xr,yr,zr,r,l in p:
            x = (su-a**2)/su*x0-a/su*(b*y0+c*z0-a*xr-b*yr-c*zr)
            y = (su-b**2)/su*y0-b/su*(a*x0+c*z0-a*xr-b*yr-c*zr)
            z = (su-c**2)/su*z0-c/su*(b*y0+a*x0-a*xr-b*yr-c*zr)
            if min(x0,s)-1e-4 <= x <= max(x0,s)+1e-4 and min(y0,t)-1e-4 <= y <= max(y0,t)+1e-4 and min(z0,u)-1e-4 <= z <= max(z0,u)+1e-4:
                x -= xr
                y -= yr
                z -= zr
                r2 = x**2+y**2+z**2
                if r2 <= r**2+1e-4:
                    ans += l
        print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    C()



Measured memory_bytes: 8260
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,C,K,T[100010];

int main(){
    cin >> N >> C >> K;

    int i;
    for (i=1; i<=N; i++) cin >> T[i];

    sort(T+1,T+N+1);
    int nr=1,res=1,ind=1;
    for (i=2; i<=N; i++){
        if (nr==C || T[ind]+K<T[i]){
            res++,ind=i,nr=1;
        }
        else nr++;
    }

    cout << res << "\n";
    return 0;
}


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

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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> c(N);
    vector<int> t(N);

    for (int i = 0; i < N; i++) {
        cin >> c.at(i) >> t.at(i);
    }

    int ans = 1001;
    for (int i = 0; i < N; i++) {
        if (t.at(i) <= T)
            ans = min(ans, c.at(i));
    }

    if (ans == 1001)
        cout << "TLE" << endl;
    else
        cout << ans << endl;
}

Measured memory_bytes: 256
def nCr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
mod = 10**9+7 #出力の制限
size = 10**6 # size >= n
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, size + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
 
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)
 
    if temp!=1:
        arr.append(1)
 
    return arr
 
N, M = map(int,input().split())
L = factorization(M)
 
ans = 1
 
for i in L:
    ans *= nCr(i+N-1,N-1,mod)
    ans %= mod
 
print(ans)

Measured memory_bytes: 127396
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define inl inline
#define re register
#define LL long long
#define MAXN 10100
using namespace std;
struct con
{
	int p;LL sum;
}hh[100100];
LL read()
{
    LL f=1,p=0;
    char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}
    return f*p;
}
void write(LL x)
{
    if(x<0)putchar('-'),x=-x;
    if(x/10)write(x/10);
    putchar(x%10+'0');
}
LL n,a[100100];
LL l=1000000000l,r,mid,ans,f[100100];
LL sum[100100];
inl LL lowbit(LL x){return x&(-x);}
inl bool cmp(const con&a,const con &b)
{
	if(a.sum==b.sum)return a.p<b.p;
	return a.sum<b.sum;
}
void add(int b){for(int i=b;i<=n;i+=lowbit(i))f[i]++;}
LL find(int a)
{
	LL u=0;
	for(int i=a;i>0;i-=lowbit(i))u+=f[i];
	return u;
}
bool check()
{
	ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<mid)hh[i].sum=-1;
		else hh[i].sum=1;
	}
	for(int i=1;i<=n;i++)
		hh[i].sum+=hh[i-1].sum;
	for(int i=1;i<=n;i++)hh[i].p=i;
	sort(hh+1,hh+n+1,cmp);
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++)
	{
		add(hh[i].p);
		ans+=find(hh[i].p-1);
		if(hh[i].sum>=0)ans++; 
	}
	return 4*ans<n*(n+1);
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		l=min(l,a[i]);
		r=max(r,a[i]);
	}
	while(l<r)
	{
		mid=(l+r+1)/2;
		if(check()) r=mid-1;
		else l=mid;
	}
	write(l);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S,T;cin>>S>>T;
    int L=S.size();
    for(int i=0;i<L;i++){
        bool ok=true;
        for(int j=0;j<L;j++){
            if(S[j]!=T[(i+j)%L]){
                ok=false;break;
            }
        }
        if(ok){
            cout<<"Yes"<<endl;return 0;
        }
    }
    cout<<"No"<<endl;
}

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

int main(){
	int N;
	cin>>N;
	bool yes=false;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j == N){
				yes = true;
			}
		}
	}
	if(yes)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int dp[101][100001], arr[100][2], N, W;
void solve()
{
	memset(dp[0],0,sizeof(dp[0]));
    for(int i=1;i<=N;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(j-arr[i-1][0] >= 0){
              dp[i][j] = max(dp[i-1][j-arr[i-1][0]]+arr[i-1][1], dp[i-1][j]);
            }
            else dp[i][j] = dp[i-1][j];
        }
    }
}
/*void printarr() {
	for(int i=0;i<N;i++)
		for(int j=0;j<3;j++)
			cout << arr[i][j] << " ";
	cout << endl;
}*/
void printdparr()
{
	for(int i=0;i<=N;i++)
	{
		for(int j=0;j<=W;j++)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
}
int main() {
	// your code goes here
	cin >> N >> W;
    for(int i=0;i<N;i++){
      cin >> arr[i][0] >> arr[i][1];
    }
    solve();
    //printdparr();
    cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <map>
using namespace std;
map <int,int> sum;
int main()
{
	int K,S,ans = 0,k = 0;
	int A[5][2005];
	scanf("%d %d",&K,&S);
	for(int i = 0;i <= K;i++){
		for(int j = 0;j <= K;j++){
			if(i + j <= S && i + j >= S - K) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256