akhauriyash/Code-Regression huggingface dataset:
/* Simplicity and Goodness */

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

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{
    string s;
    cin >> s;

    int n = (int) s.size();

    string ts = "";

    rep(i, 0, n-1) {
        if(s[i] == 'B' and s[i+1] == 'C')
            ts += 'D', i ++;
        else
            ts += s[i];
    }

    ll total = 0, cnt = 0;

    rep(i, 0, ts.size()) {
        if(ts[i] == 'A')
            cnt ++;
        else if(ts[i] == 'D')
            total += cnt;
        else
            cnt = 0;
    }

    lprin(total);
}

int main()
{
    int t = 1;
    // scn(t);

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

Measured memory_bytes: 3876
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<typeinfo>

using namespace std;
#define rep(i,m,n) for(int i=m;i<n;++i)
#define llrep(i,m,n) for(ll i=m;i<n;++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

ll edge[1100][1100], dist[1100];
queue<int>q;

int main() {
	int n, m;
	cin >> n >> m;
	rep(i, 0, 1100) {
		rep(j, 0, 1100) {
			edge[i][j] = -llinf;
		}
	}
	rep(i, 0, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		edge[a][b] = c;
	}
	rep(i, 0, 1100) {
		dist[i] = -llinf;
	}
	dist[1] = 0;
	q.push(1);
	int co = 0;
	ll ans;
	while (!q.empty()) {
		int hoge = q.front();
		q.pop();
		if (co == 2 * m) {
			ans = dist[n];
		}
		else if (co == 3 * m) {
			if (ans == dist[n]) {
				cout << ans << endl;
			}
			else {
				cout << "inf" << endl;
			}
			return 0;
		}
		
		co++;
		rep(i, 1, n + 1) {
			if (edge[hoge][i] != -llinf && dist[i] < dist[hoge] + edge[hoge][i]) {
				q.push(i);
				dist[i] = dist[hoge] + edge[hoge][i];
			}
		}
	}
	cout << dist[n] << endl;
	return 0;
}

Measured memory_bytes: 9728
a[2][21];main(t,n,m,f,i,j,x){for(;scanf("%d%d",&n,&m),n;printf("Case %d: %d\n",t++,i)){
for(memset(a,f=0,sizeof(a)),a[f][i=0]=n;!a[f][m];f^=1,i++)for(j=0;j<m;j++){
	x=a[f][j];
	a[f^1][j+1]+=x/2;
	a[f^1][a[f][j]=0]+=x/2;
	a[f^1][j]+=x%2;
}
}exit(0);}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main()
{
  int x;
  
  cin >> x;
  if (400 <= x && x <= 599)
  {
    cout << '8';
    return 0;
  }
  if (600 <= x && x <= 799)
  {
    cout << '7';
    return 0;
  }
  if (800 <= x && x <= 999)
  {
    cout << '6';
    return 0;
  }
  if (1000 <= x && x <= 1199)
  {
    cout << '5';
    return 0;
  }
  if (1200 <= x && x <= 1399)
  {
    cout << '4';
    return 0;
  }
  if (1400 <= x && x <= 1599)
  {
    cout << '3';
    return 0;
  }
  if (1600 <= x && x <= 1799)
  {
    cout << '2';
    return 0;
  }
  if (1800 <= x && x <= 1999)
  {
    cout << '1';
    return 0;
  }
  return 0;
}

Measured memory_bytes: 3132
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int A1, A2, A3;
	cin >> A1 >> A2 >> A3;

	if (A1+A2+A3 <= 21) {
		cout << "win" << endl;
	} else {
		cout << "bust" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int C, T;
	int Ci, Ti;
	int ans = 10000;

	cin >> C >> T;

	for (int i = 0; i < C; i++)
	{
		cin >> Ci >> Ti;

		if ((Ti <= T) && (ans > Ci))
		{
			ans = Ci;
		}
	}
	if (ans > 1000)
	{
		cout << "TLE" << endl;
	}
	else
	{
		cout << ans << endl;
	}

	return(0);
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define MAX 1000000000000000000
#define N 100000

int main(void)
{
  int n, i = 0;
  long long tmp, r = 1;
  
  scanf("%d", &n);
  i = 0;
  while(i < n)
  {
    scanf("%lld", &tmp);
    if(tmp == 0)
    {
      printf("0");
      return 0;
    }
    if(MAX / r < tmp)
    {
      r = -1;
    }
    if(r > 0) r *= tmp;
    i++;
  }
  printf("%lld", r);
  return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;

const ll INF = 1e16;

int main()
{
    int n;
    cin >> n;
    int a[100003], b[100003];
    ll c[100003];
    vector<P> v[100003];
    for(int i = 0; i < n - 1; i++){
        cin >> a[i] >> b[i] >> c[i];
        v[a[i]].push_back(P(b[i], c[i]));
        v[b[i]].push_back(P(a[i], c[i]));
    }
    ll d[100003];
    fill(d, d + n + 1, INF);
    int q, k;
    cin >> q >> k;
    d[k] = 0;
    queue<int> que;
    que.push(k);
    while(que.size()){
        int now = que.front();
        que.pop();
        int l = v[now].size();
        for(int i = 0; i < l; i++){
            int next = v[now][i].first;
            if(d[next] == INF){
                d[next] = d[now] + v[now][i].second;
                que.push(next);
            }
        }
    }
    int x[100002], y[100002];
    for(int i = 0; i < q; i++){
        cin >> x[i] >> y[i];
        cout << d[x[i]] + d[y[i]] << endl;
    }
}

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

int main() {
  int N, next,count= -1;
  cin >> N ;

   // N要素の配列
  vector<int> button(N);

  //button 読み込み処理
  for(int i=0; i<N; i++){
   cin >> button.at(i);
  }
    next = button.at(0);
    for(int i=0; i<N+1; i++){
        if(next ==2){count=i+1; break;}
        next = button.at(next-1);
    }
      cout << count << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
  
using namespace std;
 
#define endl "\n"
#define JAM(x) cout<< #x <<" = "<<x<<"\n"
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { ll a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
 
 
//Fast Reader
template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef vector<PII> VPI;
 
const int INF=2e9;
const int MX=100005;
const int MOD=1000000007;
const double PI=acos(-1.0);
 
long long int power(long long int a,long long int b)
{
    a %= MOD;
    long long int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
 
/*_______________________________________________*/
int n,m,l=3;
long long int dp[3001][3001][4];
vector<vector<long long int>> grid(3001,vector<long long int>(3001));
long long int answer(int i,int j,int k)
{
    if(i>=n || j>=m)
    return 0;
    if(dp[i][j][k]!=-1)
    return dp[i][j][k];
    if(k>0 && grid[i][j]!=0)
    dp[i][j][k]=max(max(answer(i+1,j,l)+grid[i][j],answer(i,j+1,k-1)+grid[i][j]),max(answer(i,j+1,k),answer(i+1,j,l)));
    else
    dp[i][j][k]=max(answer(i,j+1,k),answer(i+1,j,l));
    return dp[i][j][k];
}
int main()
{
    int k;
    cin>>n>>m>>k;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<k;i++)
    {
        long long int a,b,c;
        cin>>a>>b>>c;
        grid[a-1][b-1]+=c;
    }
    cout<<answer(0,0,l);
}


Measured memory_bytes: 355956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (a == c ? 0 : 1) << endl;
}	

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    int n, value;
    string key;
    cin >> n;
    vector<int> spade;
    vector<int> heart;
    vector<int> club;
    vector<int> diea;

    for (int i = 0; i < n; i++)
    {
        cin >> key >> value;
        if (key == "S")
            spade.push_back(value);
        else if (key == "H")
            heart.push_back(value);
        else if (key == "C")
            club.push_back(value);
        else if (key == "D")
            diea.push_back(value);
    }

    for (int i = 1; i <= 13; i++)
    {
        auto itr = find(spade.begin(), spade.end(), i);
        if (itr == spade.end())
        {
            cout << "S " << i << endl;
        }
    }

    for (int i = 1; i <= 13; i++)
    {
        auto itr = find(heart.begin(), heart.end(), i);
        if (itr == heart.end())
        {
            cout << "H " << i << endl;
        }
    }
    for (int i = 1; i <= 13; i++)
    {
        auto itr = find(club.begin(), club.end(), i);
        if (itr == club.end())
        {
            cout << "C " << i << endl;
        }
    }
    for (int i = 1; i <= 13; i++)
    {
        auto itr = find(diea.begin(), diea.end(), i);
        if (itr == diea.end())
        {
            cout << "D " << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3172
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

#ifdef DEBUGGING
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

using namespace std;

using namespace std;
const ll inf = 5e15;
const ll mod = 1e9 + 7;

template <ll MOD>
class Combination {
    ll N;
    V<ll> factv, ifactv;

public:
    Combination<MOD>(ll N) : N(N), factv(N + 1, 1), ifactv(N + 1) {
        for (ll i = 1; i <= N; i++) factv[i] = factv[i - 1] * i % MOD;
        ifactv.back() = inv(factv.back());
        for (ll i = N - 1; 0 <= i; i--) ifactv[i] = (i + 1) * ifactv[i + 1] % MOD;
    }

    ll fact(ll n) { return factv[n]; }

    ll ifact(ll n) { return ifactv[n]; }

    ll pow(ll a, ll b) { return b ? (b & 1 ? a : 1) * pow(a * a % MOD, b / 2) % MOD : 1; }

    ll inv(ll a) { return pow(a, MOD - 2); }

    ll comb(ll n, ll k) { return factv[n] * ifactv[n - k] % MOD * ifactv[k] % MOD; }
};

Combination<mod> C(1e6);

ll solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (n == 2) return 0;
    ll ans = C.pow(2, n) + (mod - 1);
    ll fact = 1;
    for (ll i = 0; i < b; i++) {
        fact = fact * (n - i) % mod;
        if (i + 1 == a || i + 1 == b) ans += mod - fact * C.ifact(i + 1) % mod;
    }
    return ans % mod;
}

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


Measured memory_bytes: 15872
#include <iostream>
#include <string>
using namespace std;
int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	string s;
	for(int i=0; i<2; i++){
	int max=i;
		for(int j=i+1; j<3; j++){
			if(a[max]<a[j]) max=j;
		}
		int temp=a[max];
		a[max]=a[i];
		a[i] = temp;
	}
	
	s = to_string(a[0]) + to_string(a[1]);
    int i = stoi(s);
    int sum = i + a[2];
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
immutable long MOD = 1000000007;
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    solve(N);
}

void solve(long N)
{
    if (N == 1)
    {
        writeln(0);
        return;
    }
    auto dp = new long[][](N + 1, 4);
    dp[0][0] = 1;
    foreach (i; 0 .. N)
    {
        dp[i + 1][0] = dp[i][0] * 8;
        dp[i + 1][0] %= MOD;
        dp[i + 1][0b01] = dp[i][0] + dp[i][0b01] * 9;
        dp[i + 1][0b01] %= MOD;
        dp[i + 1][0b10] = dp[i][0] + dp[i][0b10] * 9;
        dp[i + 1][0b10] %= MOD;
        dp[i + 1][0b11] = dp[i][0b01] + dp[i][0b10] + dp[i][0b11] * 10;
        dp[i + 1][0b11] %= MOD;
    }
    writeln(dp[N][0b11]);
}


Measured memory_bytes: 67732
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string ans = "keyence";
    int pos=0;
    //try at the beginning
    if(s.substr(0,7)==ans)pos=1;
    //try at the end
    if(s.substr((int)s.size()-7,7)==ans)pos=1;
    //try the other possible way
    for(int i=1;i<=6;i++){
        if((s.substr(0,i)==ans.substr(0,i))&&(s.substr((int)s.size()-(7-i),7-i)==ans.substr(i,7-i)))pos=1;
    }
    if(pos==1)cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int D,T,S;
  cin>>D>>T>>S;

  if(T*S>=D) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

public class Main {

    long MAX = (long)1e15;

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] ar = new long[n + 2];
        long[] dp = new long[3];

        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextLong();
        }

        dp[1] = dp[2] = MAX;
        dp[0] = 0;

        for (int i = 0; i < n - 1; i++) {
            int idx = i % 3;
            int n1  = (idx + 1) % 3;
            int n2  = (idx + 2) % 3;
            dp[n1]  = Math.min(dp[n1], dp[idx] + Math.abs(ar[i] - ar[i + 1]));
            dp[n2]  = Math.min(dp[n2], dp[idx] + Math.abs(ar[i] - ar[i + 2]));
            dp[idx] = MAX;
        }
        System.out.println(dp[(n - 1) % 3]);
    }

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

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


Measured memory_bytes: 50164
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
#include <tuple>
using namespace std;
#define FORN(i,m,n) for(int i=(m); i<int(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
typedef long long ll;

int h, w, k, ans = 1e9;
string table[15];

int solve(vector<int> &r){
  int cuts = r.size(), cur = 0, lc = 0;
  vector<int> sec(r.size()+1,0);
  r.push_back(h-1);
  while(cur < w){
    int last = 0;
    bool ok = true;
    FORN(j,0,r.size()){
      FORN(i,last,r[j]+1) sec[j] += (table[i][cur] == '1');
      if(sec[j] > k) ok = false;
      last = r[j] + 1;
    }
    if(ok) cur++;
    else{
      FORN(i,0,sec.size()) sec[i] = 0;
      if(lc == cur) return 1e9;
      lc = cur;
      cuts++;
    }
  }
  return cuts;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin>>h>>w>>k;
  FORN(i,0,h) cin>>table[i];
  FORN(mask, 0, 1<<(h-1)){
    vector<int> rows;
    FORN(j,0,h-1) if((1 << j) & mask) rows.push_back(j);
    ans = min(ans, solve(rows));
  }
  cout<<ans<<endl;
}

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

constexpr int INF = 1001001001;

template<typename T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    for(int i = 0; i < M; ++i){
        int A, B;
        cin >> A >> B;
        --A, --B;
        graph[A].emplace_back(B);
    }
    
    int min_cycle = INF;
    vector<int> ans;
    auto bfs = [&](int root) -> void {
        vector<int> dist(N, INF);
        vector<int> prev(N, -1);
        dist[root] = 0;
        queue<int> que;
        que.emplace(root);
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(int to : graph[from]){
                if(chmin(dist[to], dist[from] + 1)){
                    que.emplace(to);
                    prev[to] = from;
                }
                if(dist[to] == 0){
                    if(chmin(min_cycle, dist[from] + 1)){
                        ans.clear();
                        for(int s = from; s != -1; s = prev[s]){
                            ans.emplace_back(s);
                        }
                    }
                    return;
                }
            }
        }
    };
    for(int v = 0; v < N; ++v)  bfs(v);
    
    if(min_cycle == INF)    cout << -1 << endl;
    else{
        cout << min_cycle << '\n';
        for(int x : ans)    cout << x + 1 << '\n';
    }
}

Measured memory_bytes: 3628
#include <stdio.h>

#define NMAX 100

int main(void){

  int i,j,n,u,k,v;
  int M[NMAX][NMAX];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      M[i][j] = 0;
    }
  }

  for(i = 0;i < n;i++){
    scanf("%d%d",&u,&k);
    for(j = 0;j < k;j++){
      scanf("%d",&v);
      M[u - 1][v - 1] = 1;
    }
  }

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      if(j != n - 1){
      printf("%d ",M[i][j]);
      }else{
	printf("%d\n",M[i][j]);
      }
    }
  }

  return 0;
}

	       



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >>n>>m;

    vector<int>food(m,0);

    for (int i=0;i<n;i++) {
        int k;
        cin >>k;
        for (int j=0;j<k;j++) {
            int a;
            cin>>a;
            food[a-1]++;
        }
    }
    int count=0;
    for (int i=0;i<m;i++) {
        if(food[i]==n){
            count++;
        }
    }
    cout<<count<<endl;
}

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

using namespace std;

int main() {
		int A, B;
		cin >> A >> B;

		for (int i = 10; i <= 1000; i++) {
				int tax8 = i * 0.08;
				int tax10 = i * 0.10;
				if (tax8 == A && tax10 == B) {
						cout << i << endl;
						return 0;
				}
		}
		cout << -1 << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main (String[] args ) throws IOException {
        BufferedReader reader = new BufferedReader ( new InputStreamReader (System.in));
        StringBuilder builder = new StringBuilder();
        int[][][] room = new int[4][3][10];
        int MAX = 9;
        int MIN = 0;
        int dataCount = Integer.parseInt(reader.readLine());
        int tou = 0;
        int floor = 0;
        int ban = 0;
        int num = 0;
        int touMAX = 4;
        int floorMAX = 3;
        int banMAX = 10;
        
        for (int i = 0;i < dataCount; i++ ) {
            String inputData = reader.readLine();
            String[] inputCol = inputData.split(" ");
            
            tou = Integer.parseInt(inputCol[0])-1;
            floor = Integer.parseInt(inputCol[1])-1;
            ban = Integer.parseInt(inputCol[2])-1;
            num = Integer.parseInt(inputCol[3]);
            
            if ( room[tou][floor][ban] + num >= 9)
                room[tou][floor][ban] = MAX;
            else if ( room[tou][floor][ban] + num <= 0)
                room[tou][floor][ban] = MIN;
            else {
                room[tou][floor][ban] += num;
            }
        }
        
        for (int x = 0; x < touMAX ; x++ ) {
            for (int y = 0 ; y < floorMAX ; y++) {
                for (int z = 0 ; z < banMAX ; z++) {
                    System.out.print(" ");
                    System.out.print(room[x][y][z]);
                }
                System.out.println("");
            }
            if ( x != touMAX -1)
                System.out.println("####################");
        }
    }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF= 1e20;

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);

int main() {
	int ANS = 0;

	string s;
	cin >> s;
	REP(i, 4)(s[i] == '+') ? ANS++ : ANS--;

	COUT(ANS)
	return 0;
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;

main(){
    int n=in();
    int m=in();
    vector<vector<ll>> dp(610,vector<ll>(610)),dp2(610,vector<ll>(610));
    dp[1][0]=1ll;
    //if(n>m){cout<<0;return 0;}
    rep(i,m){
        rep(j,n+1){
            rep(k,n+1){
                ll s=dp[j][k];
                dp2[j+k][0]=(dp2[j+k][0]+s*j)%MOD;
                dp2[j][k]=(dp2[j][k]+s*k)%MOD;
                dp2[j][k+1]=(dp2[j][k+1]+s*(n-j-k))%MOD;
            }
        }
        //cout<<"passed";
        dp=dp2;
        dp2=vector<vector<ll>>(610,vector<ll>(610));
        //cout<<"passed";
    }
    cout<<dp[n][0]<<endl;
}



Measured memory_bytes: 9100
def main():
    N = int(input())
    ps = list(map(int, input().split(" ")))

    ans = 1
    minnum = ps[0]
    for i in range(N):
        if minnum > ps[i]:
            minnum = ps[i]
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()

    

Measured memory_bytes: 73180
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, T;
  cin >> N >> T;
  vector<int> t(N);
  for (int i = 0; i < N; i++){
    cin >> t[i];
  }
  int sum = 0;
  for (int i = 0; i < N - 1; i++){
    sum += min(t[i + 1] - t[i], T);
  }
  cout << sum + T << endl;
}

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

namespace AtCoder.Beginner164
{
    public class ABC164A
    {
        public static void Main(string[] args)
        {
            int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(nums[1] >= nums[0] ? "unsafe" : "safe");
        }
    }
}

Measured memory_bytes: 28292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
  cin >> n;
  cout << 0 << endl;
  string prev;
  cin >> prev;
  if(prev == "Vacant"){
    return 0;
  }

  vector<int> a(n);
  rep(i, n){
    a[i] = (prev == "Male") ? i & 1 : (i & 1) ^ 1;
  }
  
  int left = 0;
  int right = n;
  for(int i = 1; i < 20; ++i){
    int t = (left + right) / 2;
    cout << t << endl;
    string s;
    cin >> s;
    int tmp;
    if(s == "Vacant"){
      return 0;
    }
    else if(s == "Male"){
      tmp = 0;
    }
    else{
      tmp = 1;
    }

    if(a[t] == tmp){
      left = t;
    }
    else{
      right = t;
    }
  }
	return 0;
}



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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

int lis(vector<ll> const& a) {
    int n = a.size();
    const ll INF = 1e18;
    vector<ll> d(n+1, INF);
    d[0] = -INF;

    for (int i = 0; i < n; i++) {
        int j = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (d[j-1] <= a[i] && a[i] <= d[j])
            d[j] = a[i];
    }

    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (d[i] < INF)
            ans = i;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N;
    cin >> N;
    vll A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) A[i] *= -1;

    int ans = lis(A);
    cout << ans << endl;

    return 0;
}

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

int main(){
    int A, B;
    cin >> A >> B;
    int ans = 0;
    for(int i = A; i <= B; i++){
        string reverse_string = to_string(i);
        reverse(reverse_string.begin(), reverse_string.end());
        if(to_string(i) == reverse_string){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# D - Islands War

N, M = map(int, input().split())
Q = []
for _ in range(M):
    a, b = map(int, input().split())
    Q.append((a, b))
Q.sort(key = lambda x: x[1])

ans = []
for i in range(M):
    (a, b) = Q[i]
    if ans == [] or ans[-1] < a:
        ans.append(b-1)
    else:
        continue
print(len(ans))

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

int main(){
    int n, m, poll=0, num=0;
    cin >> n >> m;
    vector<int> a(n);
    for (int i=0; i<n; i++){
        cin >> a[i];
        poll += a[i];
    }
    for (int i=0; i<n; i++){
        if(a[i]*(4*m) >= poll){
            num++;
        }
    }
    if (m <= num){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := nextInt()
	if n == m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
    int n;
    int i = 0;
    char s[105];
    char t[105];
    scanf("%d",&n);
    scanf("%s%s",s,t);
    while (i < n)
    {
        printf("%c%c",s[i],t[i]);  
        i++;
    }
    
    return 0;
}

Measured memory_bytes: 1688
from math import ceil
H, W = map(int, input().split())

if H == 1 or W == 1:
    ans = 1
elif H % 2 == 0 and W % 2 == 0:
    ans = H*W//2
elif H % 2 == 0 and W % 2 == 1:
    ans = H*W//2
elif H % 2 == 1 and W % 2 == 0:
    ans = H*W//2
else:
    ans = (W//2)*H + H//2+1
print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int H;
int N;
int A;
int B;
int dp[10001];
int main(){
  int Q5VJL1cS, i;
  rd(H);
  rd(N);
  for(i=(1);i<(10001);i++){
    dp[i] = 1073709056;
  }
  for(Q5VJL1cS=(0);Q5VJL1cS<(N);Q5VJL1cS++){
    rd(A);
    rd(B);
    for(i=(0);i<(A);i++){
      chmin(dp[i], B);
    }
    for(i=(A);i<(10001);i++){
      chmin(dp[i], B + dp[i-A]);
    }
  }
  wt_L(dp[H]);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int H, N, A, B;
// int dp[10001];
// {
//   rd(H,N);
//   rep(i,1,10001) dp[i] = int_inf;
//   rep(N){
//     rd(A,B);
//     rep(i,A) dp[i] <?= B;
//     rep(i,A,10001) dp[i] <?= B + dp[i-A];
//   }
//   wt(dp[H]);
// }


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

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

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

    int ans = 0;
    FOR(i, 1, N+1) {
        int c = 0;
        int t = i;
        while ((t /= 10) > 0) {
            c++;
        }
        if ((c & 1) == 0) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<string.h>
#define LEN 100005

// プロセスを表す構造体
typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){ return a < b ? a : b; }

int main(){
    int elaps = 0, c;
    int i,q;
    P u;
    scanf("%d %d", &n, &q);

    // 全てのプロセスをキューに順番に追加する
    for(i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;

    // シミュレーション
    while( head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }
}


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

int main(){
   ll n,m,x;cin>>n>>m>>x;
   
   ll c[n];
   ll a[n][m];
   
   for(int i=0;i<n;i++){
   	   for(int j=-1;j<m;j++){
   	       if(j==-1){
   	       	cin>>c[i];
			  }
			  else{
			  	cin>>a[i][j];
			  }
   }
   }
   
   
   ll ans=1e18,temp=0,temp1;
   ll a1[m];
   
   for(int i=0;i<(1<<n);i++){
   	   temp=0;
   	   temp1=i;
   	    for(int j=0;j<m;j++){
   	    	a1[j]=0;
		}
		
   	   for(int j=0;j<n;j++){
   	   	   if(temp1%2){
   	   	   	temp+=c[j];
   	   	   	for(int j1=0;j1<m;j1++){
   	   	   		a1[j1]+=a[j][j1];
				}
			}
			temp1/=2;
		}
   	    
   	    int g=1;
   	    for(int j=0;j<m;j++){
   	    	if(a1[j]<x){
   	    		g=0;break;
			   }
		   }
		
		if(g){
			ans=min(ans,temp);
		}
   }
   
   if(ans==1e18){
   	cout<<-1<<endl;return 0;
   }
   
   cout<<ans<<endl;
   
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
long long longpow(long long n, long long a, long long mod) {
  if (a == 0) return 1;
  if (a == 1) return n % mod;
  if (a % 2 == 1) return (n * longpow(n, a - 1, mod)) % mod;
  ll t = longpow(n, a / 2, mod) % mod;
  return (t * t) % mod;
}
int main() {
  ll N, M;
  cin >> N >> M;
  ll ans = M / N;
  while (true) {
    if ((M - ans * N) % ans == 0) {
      cout << ans << endl;
      return 0;
    }
    ans--;
  }
}

Measured memory_bytes: 3620
#include<stdio.h>
int main() {
	int n,i,k,ans;
	int MAX_V=1000000;
	int prime[MAX_V];
	int sum[MAX_V+1];
	for(i=2;i<=MAX_V;i++) {
		prime[i]=1;
	}
	for(i = 2; i*i <= MAX_V; i++) { 
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	while(scanf("%d", &n) != EOF) {
		for(i=0;i<=n;i++) {
			sum[i+1]=sum[i]+prime[i];
		}
		ans=sum[n+1];
		printf("%d\n",ans);
	}
	return 0; 
}

Measured memory_bytes: 10568
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>

using namespace std;

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

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};

const D EPS = 1e-8;

int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}
namespace std {
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
}

P vec(L a) {return a.b - a.a;}

D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(P a, P b, P c) {
  if (near(a, c) || near(b, c)) return ON;
  int s = sig(det(b - a, c - a));
  if (s) return s > 0 ? LEFT : RIGHT;
  return (a < b) == (b < c) ? FRONT : (c < a) == (a < b) ? BACK : ON;
}

bool iSSs(L a, L b) {
  int cwa = ccw(a.a, a.b, b.a) | ccw(a.a, a.b, b.b);
  int cwb = ccw(b.a, b.b, a.a) | ccw(b.a, b.b, a.b);
  return (cwa & cwb) == (LEFT | RIGHT);
}

P pLL(L a, L b) {return a.a + vec(a) * (det(vec(b), b.a - a.a) / det(vec(b), vec(a)));}

void solve() {
  D x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  L a = {P(x1, y1), P(x2, y2)};
  int n;
  cin >> n;
  vector<pair<P, bool> > vp;
  rep (i, n) {
    int o, l;
    cin >> x1 >> y1 >> x2 >> y2 >> o >> l;
    L b = {P(x1, y1), P(x2, y2)};
    if (iSSs(a, b)) vp.push_back(make_pair(pLL(a, b), o == l));
  }
  sort(vp.begin(), vp.end());
  int res = 0;
  rep (i, vp.size() - 1) if (vp[i].second != vp[i + 1].second) ++res;
  cout << res << endl;
}

int main() {
  int t;
  cin >> t;
  rep (i, t) solve();
}

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

int main() {
	int a[4];
	int b[4];
	bool flag[4];
	while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
		int hitNumber = 0;
		int blowNumber = 0;
		for(int i = 0; i < 4; i++) flag[i] = false;
		for(int i = 0; i < 4; i++) {
			if(a[i] == b[i]) {
				hitNumber++;
				flag[i] = true;
			}
		}
		for(int i = 0; i < 4; i++) {
			if(flag[i] == true) continue;
			else {
				for(int j = 0; j < 4; j++) {
					if(a[i] == b[j]) {
						blowNumber++;
					}
				}
			}
		}
		cout << hitNumber << " " << blowNumber << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main()
{
	int a,b,f=0;
	char x[100];
	cin>>a>>b>>x;
	for(int i=0;i<a;i++)if(x[i]<'0'||x[i]>'9')f=1;
	if(x[a]!='-')f=1;
	for(int i=a+1;i<a+b+1;i++)if(x[i]<'0'||x[i]>'9')f=1;
	if(x[a+b+1]!='\0'||f)cout << "No\n";
	else cout << "Yes\n";
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld n,i,s=0,j,p,k,m,l,x,y;
    cin>>n;
    lld a[100001]={0};
    rep(i,0,n)
    {
        cin>>x>>y;
        rep(j,x,y+1)
         a[j]=1;
    }
    rep(i,0,100001)
        if(a[i]==1)
            s++;
    cout<<s;





}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vi packs(3);
  while(cin >> packs[0] >> packs[1] >> packs[2]){
    TSTART();
    string ans;
    sort(ALL(packs));
    if(packs[0] + packs[1] == packs[2])ans = "Yes";
    else ans = "No";

    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()

ans = 0
for i in range(N-2):
    for j in range(N-i-1):
        a = L[i]
        b = L[i+j+1]
        c_right = bisect.bisect_left(L[i+j+2:], b + a)
        ans += c_right
print(ans)


Measured memory_bytes: 52316
/* ex6_1
  terakura */

#include <stdio.h>
#include <string.h>

#define SIZE 256

int main(void){
    int length;
    char message[SIZE];

    //文字列入力
    fgets(message, SIZE, stdin);

    //文字列の長さを代入
    length = strlen(message);

    //最後の改行を消してnull文字を代入
    if (length > 0 && message[length - 1] == '\0'){
        message[--length] = '\0';
    }

    printf("%c%d%c\n", message[0], length - 3, message[length - 2]);

    return 0;

}


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

int main() {
	int N;
	cin >> N;
	vector<vector<int>> D(N, vector<int>(2));
	rep(i, N) cin >> D[i][1] >> D[i][2];

	bool ans = false;
	int cnt = 0;
	rep(i, N) {
		if(D[i][1] == D[i][2]) cnt++;
		else cnt = 0;
		if(cnt == 3) ans = true;
	}

	if(ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3632
N,M=map(int,input().split())
a=[input().split() for i in range(N)]
count=0
b=[0 for i in range(M+1)]#1~Mの食べ物の個数→b[1]~b[M]
for i in range(N):
    for j in range(1,len(a[i])):#a[i][1]~a[i][len-1]
        b[int(a[i][j])]+=1
for i in range(1,M+1):
    if b[i]==N:
        count+=1
print(count)

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

struct si_t {
	int P, Y;
	int idx;
};

int kitaeri(const void* x, const void* y) {
	int a = ((const struct si_t*)x)->Y, b = ((const struct si_t*)y)->Y;
	return a < b ? -1 : a > b;
}

int N, M;
struct si_t si[114514];

int yakusimaruhiroko[114514];
int yosinagasayuri[114514];
int takagireni[114514];

int main(void) {
	int i;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &si[i].P, &si[i].Y) != 2) return 1;
		si[i].idx = i;
	}
	qsort(si, M, sizeof(*si), kitaeri);
	for (i = 0; i < M; i++) {
		yosinagasayuri[si[i].idx] = ++yakusimaruhiroko[si[i].P];
		takagireni[si[i].idx] = si[i].P;
	}
	for (i = 0; i < M; i++) {
		printf("%06d%06d\n", takagireni[i], yosinagasayuri[i]);
	}
	return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  int sum = 0;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
  }
  int ans = 0;
  rep(i,n) {
    if (4 * m * a[i] >= sum) {
      ans += 1;
    }
  }
  if (ans >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
(n, m) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = []
for i in range(1, len(x)):
    diff.append(x[i] - x[i-1])
diff.sort(reverse=True)
sum = 0
for i in range(n - 1, len(diff)):
    sum += diff[i]
print(sum)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}

signed main(){
    string s;
    cin>>s;
    rep(i,s.size())cout<<'x';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
S = [x for x in input()]
a = int(S[0]+""+S[1])
b = int(S[2]+""+S[3])

if 0 < a and a <= 12:
    if 0 < b and b <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0 < b and b <= 12:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 2940