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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

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

  ll l;
  cin >> l;

  ll b = 1;
  while ((1 << b) <= l) {
    b++;
  }
  vll a(b);
  rep(i, b) {
    a[i] = (1 << i);
  }
  reverse(all(a));

  vector<tuple<ll, ll, ll>> vec;
  REP(i, b) {
    vec.emplace_back(i, (i + 1), a[i]);
    vec.emplace_back(i, (i + 1), 0ll);
  }

  ll f = a[0] - 1;

  if (a[0] != l) {
    while (1) {
      ll s = 1;
      while (f + 1 + (1 << s) <= l - 1) {
        s++;
      }
      s--;
      vec.emplace_back(1, b - s, f + 1);
      f += 1 << s;
      if (f >= l - 1) {
        break;
      }
    }
  }

  cout << b << " " << vec.size() << endl;
  for (const auto& e : vec) {
    cout << get<0>(e) << " " << get<1>(e) << " " << get<2>(e) << endl;
  }

  return 0;
}


Measured memory_bytes: 384
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    n = len(A)
    count4 = 0
    count2 = 0
    for a in A:
        if a % 4 == 0:
            count4 += 1
        elif a % 2 == 0:
            count2 += 1
    count2 = count2 // 2
    requirements = n // 2

    if requirements <= count4 + count2:
        return 'Yes'
    return 'No'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)



Measured memory_bytes: 62704
# coding: utf-8
# Here your code !
# -*- coding:utf-8 -*-
import sys

def init():
    data = []
    try:
        while(True):
            line = raw_input()
            if not line: break
            data.append(line)
    except EOFError:
        pass
    return data

def main():
    n = int(init().pop())
    if 1 <= n <= 100:
        print n**3
    else:
        print "Error / Invalid input (%d)" % n

if __name__ == '__main__':
    main()

Measured memory_bytes: 6424
#include <stdio.h>
int main(void)
{
	int n,a[101],i,mini=1000,max=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&a[i]);
		if(mini>a[i]){
			mini=a[i];
		}
		if(max<a[i]){
			max=a[i];
		}
	}
	printf("%d\n",max-mini);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	string s , t ;
	cin >> s >> t ;
	set < int > v[26] ;
	// cout << s << "  " << t << '\n' ;
	int ans = 0 ; 
	for(int i = 0 ; i < s.length() ; i++){
		v[s[i] - 'a'].insert(i) ;
	}
	int idx = -1 ;	
	for(int i = 0 ; i < t.length() ; i++){
		if(v[t[i] - 'a'].size() == 0){
			cout << -1 ;
			return 0 ;
		}
		auto it = v[t[i] - 'a'].upper_bound(idx) ;
		if(it == v[t[i] - 'a'].end()){
			ans++ ;
			idx = *v[t[i] - 'a'].upper_bound(-1)  ;
		}
		else idx = *it ;
		// cout << idx << '\n' ;
	}
	cout << ans*s.length() + idx + 1 ;
}

Measured memory_bytes: 5200
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    string s,t; cin>>s>>t;
    int S=SZ(s), T=SZ(t);
    s+=s;
    mat loc(30);
    rep(i,2*S){
        loc[s[i]-'a'].pb(i);
    }
    ll ans=0; int k=-1;
    rep(i,T){
        if(SZ(loc[ t[i]-'a' ]) == 0){
            cout<<-1<<endl;
            return 0;
        }
        k = *UB(loc[ t[i]-'a' ], k);
        if(k >= S){
            ans += S;
            k -= S;
        }
    }
    printf("%lld\n", ans+k+1);
}

Measured memory_bytes: 2804
import java.util.Scanner;

public class Main {

    boolean check1(String str) {
        int n = str.length();
        int i = 0, j = n - 1;
        while (i < j) {
            if (str.charAt(i) != str.charAt(j))
                return false;
            i++;
            j--;
        }
    return true;
}

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String str=sc.next();
        int n=str.length();
        int flag=0;
       Main ob1=new Main();
            if(ob1.check1(str)){
                if (n==3 || ob1.check1(str.substring(0,((n-1)/2))))
                    if (n==3 || ob1.check1(str.substring((n+3/2)-2,n)))
                       flag=1;

            }
            if(flag==1)
                System.out.println("Yes");
            else
                System.out.println("No");
        }

    }


Measured memory_bytes: 23636
# 桁dp + 二分探索
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def lunlun_num(N):
    N = str(N)
    L = len(N)

    dp = [[0]*10 for j in range(L)]
    for j in range(1,int(N[0])):
        dp[0][j] = 1

    flag = True
    for i in range(L-1):
        d = int(N[i+1])
        b = int(N[i])
        
        dp[i+1][0] += dp[i][0] + dp[i][1]
        dp[i+1][9] += dp[i][8] + dp[i][9]
        for j in range(1,9):
            dp[i+1][j] += dp[i][j-1] + dp[i][j] + dp[i][j+1]
        for j in range(1,10):
            dp[i+1][j] += 1

        if flag:
            if d < b - 1:
                flag = False
            elif d <= b + 1:
                for j in range(max(0, b-1),d):
                    dp[i+1][j] += 1
            else:
                for j in range(max(0, b-1),b+2):
                    dp[i+1][j] += 1
                    flag = False

    return sum(dp[L-1]) + 1 if flag else sum(dp[L-1])


def main():
    K = int(readline())

    # xを決め打って二分探索
    left = 0
    right = 10**10
    while left + 1 < right:
        x = (left + right) // 2

        if lunlun_num(x) >= K:
            right = x
        else:
            left = x
    
    print(right)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
n = int(input())
A = [int(i) for i in input().split()]

dp = [[0,0] for i in range(n+1)]
dp[0][1] = (-1)*float('inf')

for i in range(n):
    dp[i+1][0] = max(dp[i][0]+A[i],dp[i][1]-A[i])
    dp[i+1][1] = max(dp[i][0]-A[i],dp[i][1]+A[i])

print(dp[n][0])

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, -1, 1, 1, -1};

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    string S;
    std::cin >> S;
    int n = S.size();

    int ans = INF;
    rep2(i, 1, n) {
        if (S[i] != S[i - 1]) {
            ans = min(ans, max(i, n - i));
        }
    }
    cout << min(ans, n) << endl;

    return 0;
}


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

using ll = long long int;

const int MAX_N = 2005;
const ll INF = (ll)1e10;

ll answer, a[MAX_N], memo[MAX_N][2];
ll N, W, Z;

ll ans(int il, int f, ll cx, ll cy) {
  if (memo[il][f] != (-1)) {return memo[il][f];}
  ll tmp;
  if (il == N) {
    return abs(cx - cy);
  }

  if (f == 1) {
    tmp = INF;
    for (int i = il; i < N; ++i) {
      tmp = min(tmp, ans(i + 1, 0, cx, a[i]));
    }
  }
  else {
    tmp = -1;
    for (int i = il; i < N; ++i) {
      tmp = max(tmp, ans(i + 1, 1, a[i], cy));
    }
  }
  return memo[il][f] = tmp;
}

int main(void){
    // Here your code !
    scanf("%d %lld %lld", &N, &W, &Z);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &a[i]);
    }
    memset(memo, -1, sizeof(memo));
    answer = ans(0, 0, W, Z);
    printf("%lld\n", answer);
    return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1024)

func readLine() string {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func atoi(s string) int {
	i, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return i
}

func readStringArray() []string {
	return strings.Split(strings.TrimSpace(readLine()), " ")
}

func readInt() int {
	return atoi(readLine())
}

func readIntArray() []int {
	var a []int
	sa := readStringArray()
	for _, s := range sa {
		a = append(a, atoi(s))
	}
	return a
}

func main() {
	S := readLine()

	var ans int
	if S == "SUN" {
		ans = 7
	} else if S == "MON" {
		ans = 6
	} else if S == "TUE" {
		ans = 5
	} else if S == "WED" {
		ans = 4
	} else if S == "THU" {
		ans = 3
	} else if S == "FRI" {
		ans = 2
	} else if S == "SAT" {
		ans = 1
	}
	fmt.Println(ans)
}


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


int main(){
  int N;
  cin >> N;
  long ene =1;
  long mod = 1000000007;
  for (int i = 1; i<= N; i++){
    ene*=i;
    ene %=mod;
  }
 cout <<ene << endl;
}


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

int main(){
    long long n, m, K;
    cin >> n >> m >> K;


    bool flag = false;

    for(long long k = 0; k <= n; k++){
        for(long long l = 0; l <= m; l++){
            if(k*(m-l) + l*(n-k) == K){
                flag = true;
                break;
            }
        }
    }
    if(flag == true){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scan(&x)
	k := 0
	switch {
	case 400 <= x && x < 600:
		k = 8
	case 600 <= x && x < 800:
		k = 7
	case 800 <= x && x < 1000:
		k = 6
	case 1000 <= x && x < 1200:
		k = 5
	case 1200 <= x && x < 1400:
		k = 4
	case 1400 <= x && x < 1600:
		k = 3
	case 1600 <= x && x < 1800:
		k = 2
	case 1800 <= x && x < 2000:
		k = 1
	}
	fmt.Println(k)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1768
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
int main() {
  int n, k; cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<ll> dp(n, ll(INFINITY)); dp[n-1] = 0;
  for (int i = n-2; i >= 0; i--) {
    for (int j = 1; j <= k; j++) {
      if (i + j < n) {
        dp[i] = min(dp[i], abs(h[i+j]-h[i])+dp[i+j]);
      }
    }
  }
  cout << dp[0];
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<ll>>;

ll dp[100100][2];//dp[v][color]
Graph G;

ll rec(int v, int color, int parent){
    if(dp[v][color]!=-1) return dp[v][color];
    ll res = 1;
    for(auto nv : G[v]){
        ll tmp = 0;
        if(nv != parent){
            if(!color) (tmp += rec(nv,1,v)) %= MOD;
            (tmp += rec(nv,0,v)) %= MOD;
            tmp %= MOD;
            if(tmp!=0) (res *= tmp) %= MOD;
        }
    }
    res %= MOD;
    return dp[v][color] = res;
}

int main(){
    int N; cin>>N;
    G.resize(N);
    rep(i,N-1){
        int x,y; cin>>x>>y;
        x--;y--;
        G[x].push_back(y); G[y].push_back(x);
    }
    rep(i,100100)rep(j,2)dp[i][j] = -1;
    ll res = rec(0,0,-1);
    res += rec(0,1,-1);
    res %= MOD;
    cout<<res<<endl;
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d; // 根なら (-サイズ), そうでないなら親の番号
    UnionFind(int N) : d(N, -1){} // 全て根として初期化

    int root(int x) { // データ x が属する木の根を再帰で得る
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y) { // x と y の木を併合. 併合した場合 true
        x = root(x); y = root(y); // x <- x の根, y <- y の根
        if (x == y) return false; 
        // merge technique（データ構造をマージするテク. 小を大にくっつける）
        if (d[x] > d[y]) swap(x, y);    // x の木のサイズ > y の木のサイズにする. d[x], d[y] < 0 に注意.
        d[x] += d[y];   // x の木のサイズ += y の木のサイズ
        d[y] = x;   // y の親は x
        return true;
    }

    bool same(int x, int y) { // 2つのデータ x, y が属する木が同じなら true
        return root(x) == root(y);
    }
    
    int size(int x) { // 素集合のサイズ
        return -d[root(x)]; // d[root(x)] < 0 に注意.
    }
};


void Main(){
    int n, m; cin >> n >> m;
    UnionFind UF(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        UF.unite(a, b);
    }
    int mx = 0;
    rep(i, n){
        mx = max(mx, UF.size(i));
    }
    cout << mx << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define po pop_back
#define fi first
#define se second
#define mxn 200001
#define ll long long int
#define ldb long double
#define endl "\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

using namespace std;

typedef pair<ll,ll> pp;
typedef vector<ll> vi;

vi adj[mxn];
bool visited[mxn];

void solve(ll test){

    ll n;
    cin >> n;
    ll a[n];
    ll s = 0;
    for(ll i=0 ; i<n ; i++){
        cin >> a[i];
        s ^= a[i];
    }

    for(ll i=0 ; i<n ; i++){
        ll temp = s^a[i];
        cout << temp << " ";
    }


}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        solve(i);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 9888
#include <iostream>
#include <string>
const int MAX_X = 1100;
const int MAX_Y = 1100;


int main() {
  std::string X;
  std::string Y;
  int q;
  int answers[160];
  std::cin >> q;
  int dp[MAX_X][MAX_Y];
  
  for(int p=0; p<q; ++p) {
    std::cin >> X;
    std::cin >> Y;

    for(int i=0; i<MAX_X; ++i) {
      for(int j=0; j<MAX_Y; ++j) {
        dp[i][j] = 0;
      }
    }

    int xlen = X.size();
    int ylen = Y.size();

    X = " " + X;
    Y = " " + Y;

    for(int i=1; i<=xlen; ++i) {
      for(int j=1; j<=ylen; ++j) {
        if(X[i] == Y[j]) {
          dp[i][j] = dp[i-1][j-1] + 1;
        } else {
          dp[i][j] = std::max(
            dp[i][j-1],
            dp[i-1][j]
          );
        }
      }
    }
    answers[p] = dp[xlen][ylen];  
  }

  for(int i=0; i<q; ++i) {
    std::cout << answers[i] << std::endl;
  }

}


Measured memory_bytes: 7892
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define pb push_back
# define mp make_pair
//# define int ll
using namespace std;

int c[maxn];
vector<int>vec[maxn];
int l[maxn][11];
int x,y,n,m,q,d;


int32_t main(){_
    //freopen("input","r",stdin);
    cin >> n >> m;
	while(m --)
	{
		cin >> x >> y;
		vec[x].pb(y);
		vec[y].pb(x);
	}
	for(int i = 1;i <= n;i++) for(int j = 1;j <= 10;j++) l[i][j] = -1;
	cin >> q;
    for(int i = 1;i <= q;i++)
    {
		cin >> x >> d >> c[i];
		l[x][d] = i;
    }
    for(int i = 10;i;i--)
    {
		for(int x = 1;x <= n;x++)
		{
			for(auto it : vec[x]) l[it][i - 1] = max(l[it][i - 1],l[x][i]);
		}
    }
    for(int i = 1;i<=n;i++)
    {
        int ans = 0;
        for(int j = 0;j <= 10;j++) ans = max(ans,l[i][j]);
		cout << max(c[ans],0) << "\n";
    }
}


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

int checker(int i,double* x1,double* y1,double* r1,double* x2,double*y2,double* r2){
  double x=x1[i]-x2[i];
  double y=y1[i]-y2[i];
  if(r1[i]>r2[i]){
    if(sqrt(x*x+y*y)<r1[i]-r2[i])return 2;
    else if(sqrt(x*x+y*y)>=r1[i]-r2[i]&&sqrt(x*x+y*y)<=r1[i]+r2[i])return 1;
    else if(sqrt(x*x+y*y)>r1[i]+r2[i])return 0;
  }
  else {
    if(sqrt(x*x+y*y)<r2[i]-r1[i])return -2;
    else if(sqrt(x*x+y*y)>=r2[i]-r1[i]&&sqrt(x*x+y*y)<=r1[i]+r2[i])return 1;
    else if(sqrt(x*x+y*y)>r1[i]+r2[i])return 0;
  }
}
int main(){
  int x;
  cin>>x;
  int answers[x];double x1[x],y1[x],r1[x],x2[x],y2[x],r2[x];
  for(int i=0;i<x;i++){
    cin>>x1[i]>>y1[i]>>r1[i]>>x2[i]>>y2[i]>>r2[i];
    answers[i]=checker(i,x1,y1,r1,x2,y2,r2);
  }
  for(int i=0;i<x;i++){
    cout<<answers[i]<<endl;
  }
}

Measured memory_bytes: 3044
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    sys.setrecursionlimit(int(pow(10,6)))
    sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass


n,m=L()
A=[L() for i in range(m)]
g=[[] for i in range(n+1)]
for x,y in A:
    g[x].append(y)

vis=[0 for i in range(n+1)]
dp=[-1 for i in range(n+1)]
def rec(v):
    if vis[v]:
        return dp[v]
    best=0
    vis[v]=1
    for neigh in g[v]:
        best=max(best,rec(neigh)+1)
    dp[v]=best
    return best
best=0
for i in range(1,n+1):
    best=max(best,rec(i))
print(best)




endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")



Measured memory_bytes: 78728
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

double M;
ll N;

void quickSort(int x[ ], int left_i, int right_i);
void quickSwap(int x[ ], int i, int j);
void quickSort(int x[ ], int left_i, int right_i)
{
    int li, ri;
    int pivot;
    li = left_i;
    ri = right_i;
    pivot = x[(left_i + right_i) / 2]; /* 基準値を配列の中央付近にとる */
    while (1) {                    /* 無限ループ */
        while (x[li] < pivot)       /* pivot より大きい値が */
            li++;                   /* 出るまで i を増加させる */
        while (pivot < x[ri])       /* pivot より小さい値が */
            ri--;                   /*  出るまで j を減少させる */
        if (li >= ri)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */
        quickSwap(x, li, ri);             /* x[i] と x[j]を交換 */
        li++;                       /* 次のデータ */
        ri--;
    }
    if (left_i < li - 1)              /* 基準値の左に 2 以上要素があれば */
        quickSort(x, left_i, li - 1);    /* 左の配列を Q ソートする */
    if (ri + 1 <  right_i)            /* 基準値の右に 2 以上要素があれば */
        quickSort(x, ri + 1, right_i);    /* 右の配列を Q ソートする */
}
/* 配列の要素を交換する */
void quickSwap(int x[ ], int i, int j)
{
    int temp;
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

int main(){


    cin >> N;
    cin >> M;
    double sum=0;

    int A[N];

    rep(ni,N){
        cin >> A[ni];
        sum+=A[ni]/ 4.0 / M  ;
    }
    quickSort(A,0,N-1);

    //cout << A[N-1-(M-1)] << endl;
    if(A[N-1-(int(M)-1)]< sum){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;

    }
    

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int i,N,x[1000]={},y[1000]={},z[1000]={};
	N=0;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d %d %d",&x[i],&y[i],&z[i]);
	}
	for(i=0;i<N;i++){
		if(x[i]*x[i] == y[i]*y[i]+z[i]*z[i]){
		printf("YES\n");
	}
		else if(y[i]*y[i] == x[i]*x[i]+z[i]*z[i]){
		printf("YES\n");
	}
		else if(z[i]*z[i] == x[i]*x[i]+y[i]*y[i]){
		printf("YES\n");
	}
		else if(x[i]*x[i] != y[i]*y[i]+z[i]*z[i] && y[i]*y[i] != x[i]*x[i]+z[i]*z[i] && z[i]*z[i] != x[i]*x[i]+y[i]*y[i]){
			printf("NO\n");
	}
	}
return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
int dp[2001][20001]={0};
int save[2001]={0};
bool sign=false;
int recoursion(int n,int y){
        if(n==0 && y==0){
                sign=true;
                return true;
        }
        if(sign==true)
                return true;
        else if(n==0 || y==0 )
                return false;
        if(dp[n][y]==1)
                return true;
        else if(dp[n][y]==2)
                return false;
        bool res=false;
        if(recoursion(n-1,y-1)){
                res=true;
                save[n-1]=1;
        }
        if(sign==true)  return true;
        if(recoursion(n-1,y-5)){
                res=true;
                save[n-1]=5;
        }
        if(sign==true)  return true;
        if(recoursion(n-1,y-10)){
                res=true;
                save[n-1]=10;
        }
        if(res) dp[n][y]=1;
        else dp[n][y]=2;
        return res;
}
int main(){
        int N,Y;
        cin >> N >> Y;
        Y/=1000;
        //10 5 1
        int min=N;
        int max=N*10;
        if(!recoursion(N,Y)){
                cout <<"-1 -1 -1"<<endl;
                return 0;
        }
        int m10=0,m5=0,m1=0;
        for(int i=0 ; i<N ; i++ ){
                if(save[i]==10)
                        m10++;
                else if(save[i]==5)
                        m5++;
                else if(save[i]==1)
                        m1++;
        }
        cout << m10 <<" "<<m5<<" "<<m1 <<endl;
        return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;

  cout << N * N * N << endl;
  

  return 0;
}



Measured memory_bytes: 256
from math import ceil

A,B = map(int,input().split())

min8 = ceil(A*12.5)
max8 = int((A+1)*12.5-0.001)
min10 = ceil(B*10)
max10 = int((B+1)*10-0.001)
#print(min8,max8,min10,max10)

if max8<min10 or max10<min8:
    print(-1)
else:
    print(max(min8,min10))

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

int main() {
  int a,b,t;
  cin >> a >> b >> t;
  
  int num = 0;
  for (int i = 1; i<30; i++) {
    if (i < t+0.5 && i%a == 0)
      num += b;
  }

  cout << num << endl;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

ll s,c;

int main(){
	cin.sync_with_stdio(false);
	cin>>s>>c;
	if(s*2>=c){
		cout<<c/2<<endl;
	}else{
		cout<<s+(c-s*2)/4<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	cnt := 0
	for i := a; i <= b; i++ {
		s := strconv.Itoa(i)
		if s[0] == s[4] && s[1] == s[3] {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl '\n'
ll gcd(ll a, ll b)
{
    for (;;)
    {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}

ll lcm(ll a, ll b)
{
    ll temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}


int main() {

    fast
    
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll div=0;
  
    div=div+(b/c)-((a-1)/c);
    //cout<<div<<endl;

    div=div+(b/d)-((a-1)/d);
    //cout<<div<<endl;
    //ll lcm=boost::math::lcm(a,b);
    ll lc=lcm(c,d);
    ll rep=0;
    rep=rep+(b/lc)-((a-1)/lc);
    
    //cout<<div<<" "<<rep<<endl;
    cout<<b-a+1-div+rep;
    

#ifndef ONLINE_JUDGE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  int l;
  string str;
  string s;

  cin>>str;

  l=str.size();

  for(int i=l-1;i>=0;i--)
    {
      cout<<str[i];
    }

  puts("");

}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    int x,y;
    cin>>x>>y;


    cout<<round((x+y)/2.0)<<endl;
    return 0;
}


Measured memory_bytes: 384
import sys
from io import StringIO
import unittest
def resolve():
    S = input()
    a = 0
    for i in range(len(S) - 1):
        if (S[i] == S[i + 1]):
            a = 1
    if (a == 0):
        print("Good")
    else:
        print("Bad")
resolve()

Measured memory_bytes: 50928
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

int main() {
  long long W, H, x, y;
	cin >> W >> H >> x >> y;
	
	if(x*2==W && y*2==H) {//center
		cout << (double)(W*H)/2.0 << ' ' << 1 << endl;
	} else { 
		cout << (double)(W*H)/2.0 << ' ' << 0 << endl;
	} 
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  double a,b,c,d,e,f;
  while(cin >> a >> b >> c >> d >> e >> f){
    double x=(c*e-b*f)/(a*e-b*d);
    double y=(c*d-a*f)/(b*d-a*e);
    if(x==-0) x=0;
    if(y==-0) y=0;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}


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

a.sort(reverse=True)
al = True
al_s = 0
bo_s = 0

for i in a:
    if al:
        al_s = al_s + i
        al = False
    else:
        bo_s = bo_s + i
        al = True

print(al_s - bo_s)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int long long
const int N = 10007;

int n, sA, sB, cA, cB;

int A[N];
int B[N];

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

	cin >> n;

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

	for(int i = 1; i <= n; ++i)
	{
		cin >> B[i];
		sB += B[i];
	}	

	int ile = sB-sA;

	if(ile<0)
	{
		cout << "No";
		return 0;
	}

	for(int i = 1; i <= n; ++i)
	{
		if(A[i]>B[i])
			cB += A[i]-B[i];
		else if(B[i]>A[i])
		{
			if((B[i]-A[i])%2==0)
				cA += (B[i]-A[i])/2;
			else
			{
				cA += (B[i]-A[i])/2+1;
				cB += 1;
			}
		}
	}

	if(cA>ile || cB>ile)
	{
		cout << "No";
		return 0;
	}

	if(2*(ile-cA)==(ile-cB))
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > G[100005];
int vis[100005];
int ans[100005];
void dfs(int x)
{
    //cout<<x<<endl;
    vis[x]=1;
    for(vector<pair<int,int> >:: iterator it=G[x].begin();it!=G[x].end();it++)
    {
        if(vis[it->first]==0)
        {
            if(it->second%2==1)
            {
                ans[it->first]=ans[x]^1;
            }
            else
            {
                ans[it->first]=ans[x];
            }
            dfs(it->first);
        }
    }

}
int main()
{
    memset(vis,0,sizeof(vis));
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        int tmp1,tmp2,tmp3;
        scanf("%d%d%d",&tmp1,&tmp2,&tmp3);
        G[tmp1].push_back(make_pair(tmp2,tmp3));
        G[tmp2].push_back(make_pair(tmp1,tmp3));
    }
    ans[1]=0;
    dfs(1);
    for(int i=1;i<=n;i++)
    {
        printf("%d\n",ans[i]);
    }
}


Measured memory_bytes: 7936
#include<stdio.h>

void dfs(int,int);

int h,w,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char grid[101][101];

int main(void){
  int i,j,count;

  while(scanf("%d %d",&h,&w),h,w){

    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	scanf(" %c",&grid[i][j]);

    count=0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(grid[i][j]!='$'){
	  count++;
	  dfs(i,j);
	}
      }
    }

    printf("%d\n",count);
  }

  return 0;
}

void dfs(int y,int x){
  char ch=grid[y][x];
  int i;
  
  grid[y][x]='$';
  for(i=0;i<4;i++){
    if(grid[y+dy[i]][x+dx[i]]==ch && 
       y+dy[i]>=0 && y+dy[i]<h && x+dx[i]>=0 && x+dx[i]<w)
      dfs(y+dy[i],x+dx[i]);
  }

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
void solve()
{
	ll n;
	cin>>n;
	vector<ll> x(n);
	for(ll i=0;i<n;i++)
		cin>>x[i];
	sort(x.begin(),x.end());
	ll a=0,b=0,c=0;
	for(ll i=n-1;i>=0;i--)
	{
		if(x[i]==x[i-1])
		{
			// cout<<x[i];
			a=x[i];
			c=i-1;
			break;
		}
	}
	// cout<<c<<a;
	for(ll i=c-1;i>=0;i--)
	{
		if(x[i]==x[i-1])
		{
			b=x[i];
			break;
		}
	}
	cout<<a*b;
	return;
}


int main()
{
	fast;
	ll q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3956
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

template <typename T> std::vector<T> make_v(usize a) {
  return std::vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type fill_v(T &t,
                                                                   const V &v) {
  t = v;
}
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

template <typename T, typename V> inline void chmin(T &a, V b) {
  if (a > b)
    a = b;
}
template <typename T, typename V> inline void chmax(T &a, V b) {
  if (a < b)
    a = b;
}

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  i32 N, D;
  std::cin >> N >> D;
  std::cout << (N + 2 * D) / (2 * D + 1) << std::endl;
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

////////////////////////////////
#define P 1000000007
#define N_MAX 2000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
    return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
    fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
ll pd(ll a, ll b){
  return (a * inv[b])%P;
}
//////////////////////////////////////
int main(int argc, char const *argv[]) {
  ll N, A, B, C, D;
  init();
  std::cin >> N >> A >> B >> C >> D;
  vvl dp = vv(B+1, N+1, 0, ll);
  dp[A-1][0] = 1;
  for(int i=A;i<=B;i++){
    ll tmp = 1;
    for(int j=0;j<N+1;j++) dp[i][j] = dp[i-1][j];
    for(int j=0;j<C;j++) tmp = pp(tmp, finv[i]);
    for(int j=C;j<=D;j++, tmp = pp(tmp, finv[i])){
      for(int k=0;k+i*j<N+1;k++){
        dp[i][i*j+k] = (dp[i][i*j+k] + pp(pp(dp[i-1][k], pp(pp(fac[N-k], tmp), finv[N-k-i*j])), finv[j]))%P;
      }
    }
  }
  /*
  for(int i=1;i<=B;i++){
    for(int j=0;j<=N;j++) std::cout << dp[i][j] << " ";
    std::cout << '\n';
  }
  */
  std::cout << dp[B][N] << '\n';
  return 0;
}


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

const int MOD = 1000000007;

template<typename T> T combination(T N, T K) {
	if (N < K) return 0;
	if (N == K || K == 0) return 1;
	vector<T> v(N, 1);
	T prev1 = 1, prev2 = 1; // prev1 = n−1Ck−1, prev2 = n−1Ck

	for (T n = 2; n <= N; n++) {
		prev1 = 1;
		T k = 1;
		while (k < n && k <= K) {
			prev2 = v[k];
			v[k++] = (prev1 + prev2) % MOD; // 余りを答えるように要求された時用
			prev1 = prev2;
		}
	}
	return v[K];
}

signed main()
{
	using ULL = unsigned long long;
	ULL N, M;
	cin >> N >> M;

	// Mを素因数分解
	ULL L = static_cast<ULL>(ceil(sqrt(M))), i = 0;
	vector<pair<ULL, ULL>> prime(L, make_pair(0,0));
	for (ULL x = 2; x <= L; x++) {
		while (M % x == 0) {
			if (prime[i].first) prime[i].second++;
			else prime[i] = make_pair(x, 1);
			M /= x;
		}
		if (M == 1) break;
		if (prime[i].first) i++;
	}
	if (M > 1) prime[i] = make_pair(M, 1);

	ULL comb = 1;
	for (auto& p : prime) {
		if (p.first == 0) break;
		comb = (comb * combination(p.second + N - 1, p.second)) % MOD;
	}

	cout << comb << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

// const ll LLINF = (1LL<<60);
// const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

const double EPS = 1e-10;
const double INF = 1e12;

//point
typedef complex<double> P;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
// line
struct L : public vector<P> {
	L(const P& a, const P& b) {
		push_back(a); push_back(b);
	}
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;								  // a--c--b on line
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}

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

  int T;
  cin >> T;
  REP(_, T) {
    double ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    L line(P(ax,ay), P(bx,by));

    // 交点の位置とその交点が高架か地下か
    vector<pair<P, int>> po;
    int n;
    cin >> n;
    REP(i, n) {
      double xs, ys, xt, yt;
      int o, l;
      cin >> xs >> ys >> xt >> yt >> o >> l;
      L l2(P(xs,ys), P(xt,yt));
      if(intersectSS(line, l2)) {
        P c = crosspoint(line, l2);
        po.PB({c, o^l});
      }
    }
    sort(ALL(po));
    // cout << po << endl;
    int ret = 0;
    FOR(i, 1, po.size()) {
      if(po[i].second != po[i-1].second) ret++;
    }
    cout << ret << endl;
  }

  return 0;
}



Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,t1,t2;
bool f;
int main() {
	scanf("%lld",&n);
	for (ll a=1;a<=3500;a++) {
		for (ll b=1;b<=3500;b++) {
			t1=n*a*b;
			t2=4*a*b-n*b-n*a;
			if (t2==0) continue;
			if (t1%t2==0&&t1/t2>0) {
				printf("%lld %lld %lld\n",a,b,t1/t2);
				f=1; break;
			}
		}
		if (f) break;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  ll N, M, X;
  cin >> N >> M >> X;
  ll C_left=0, C_right=0;
  rep(i, 0, M){
    ll tmp;
    cin >> tmp;
    if(tmp < X){
      ++C_left;
    }else{
      ++C_right;
    }
  }

  cout << min(C_left, C_right) << endl;
  
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FSelectHalf {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<ll> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      ll dp[n+1][5][4];
      rep(i, n+1) rep(j, 5) rep(k, 4) {
        dp[i][j][k] = LLONG_MIN/2;
      }
      dp[0][2][1] = 0;
      for(int i=0; i<n; i++) {
        if (i%2==0) {
          // not take
          for(int j=0; j<5; j++) {
            for(int k=0; k<3; k++) {
              chmax(dp[i+1][j][k+1], dp[i][j][k]);
            }
          }
          // take
          for(int j=0; j<4; j++) {
            for(int k=1; k<4; k++) {
              chmax(dp[i+1][j+1][0], dp[i][j][k] + a[i]);
            }
          }
        } else {
          // not take
          for(int j=1; j<5; j++) {
            for(int k=0; k<3; k++) {
              chmax(dp[i+1][j-1][k+1], dp[i][j][k]);
            }
          }
          // take
          for(int j=0; j<5; j++) {
            for(int k=1; k<4; k++) {
              chmax(dp[i+1][j][0], dp[i][j][k] + a[i]);
            }
          }
        }
      }

      ll ans = LLONG_MIN;
      rep(k, 4) {
        chmax(ans, dp[n][2][k]);
      }

      cout << ans << endl;

    }
};

signed main() {
  FSelectHalf solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 35928
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_fermat(self,n):
        pnum = 0
        for i in range(2,n+1):
            if i % 2 == 0 and i != 2:
                continue
            if pow(2,i-1,i) == 1:
                pnum += 1
        return pnum

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    for line in sys.stdin.readlines():
        n = int(line)
        n_pn = mymath.pnum_eratosthenes(n)
        print(len(n_pn))

if __name__ == '__main__':
    main()


Measured memory_bytes: 20836