akhauriyash/Code-Regression huggingface dataset:
from collections import deque

H, W = map(int, input().split())
maze = []
for _ in range(H):
    maze.append(list(input()))


def bfs(initial):
    # goal判定はなく、一番遠いところで返す
    distance = [[-1] * W for _ in range(H)]
    frontier = deque()
    frontier.append(initial)
    distance[initial[0]][initial[1]] = 0
    while len(frontier):
        current_node = frontier.popleft()
        x, y = current_node
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_x, new_y = x + i, y + j
            if 0 <= new_x < H and 0 <= new_y < W:
                if maze[new_x][new_y] == '.' and distance[new_x][new_y] == -1:
                    distance[new_x][new_y] = distance[x][y] + 1
                    frontier.append((new_x, new_y))
    return distance[x][y]


ans = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            continue
        solution = bfs((i, j))
        if ans < solution:
            ans = solution

print(ans)


Measured memory_bytes: 3316
from collections import deque

n = int(input())

node = [-1 for _ in range(n)]
que = deque()
neighbors = [[] for _ in range(n)]

for _ in range(n - 1):
    v1, v2, w = map(int, input().split())
    v1, v2 = v1 - 1, v2 - 1
    neighbors[v1].append((v2, w))
    neighbors[v2].append((v1, w))

que.append(0)
node[0] = 0
while len(que) > 0:
    p = que.popleft()
    for neighbor in neighbors[p]:
        v, w = neighbor
        if node[v] == -1:
            if w % 2 == 0:
                node[v] = node[p]
            else:
                if node[p] == 1:
                    node[v] = 0
                else:
                    node[v] = 1
            que.append(v)

for ni in node:
    print(ni)

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

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H);
    for (int i=0; i<H; ++i) cin >> S[i];

    vector<vector<int>> T(H+2, vector<int>(W+2, 0));
    for (int i=1; i<H+1; ++i) {
        for (int j=1; j<W+1; ++j) {
            if (S[i-1].at(j-1) == '#') T[i][j]++;
        }
    }

    vector<vector<int>> U(H, vector<int>(W, 0));
    for (int i=1; i<H+1; ++i) {
        for (int j=1; j<W+1; ++j) {

            for (int x=0; x<3; ++x) {
                for (int y=0; y<3; ++y) {
                    if (!(x == 1 && y == 1) && T[i+x-1][j+y-1] == 1) {
                        U[i-1][j-1]++;
                    }
                }
            }
        }
    }
    for (int i=0; i<H; ++i) {
        for (int j=0; j<W; ++j) {
            if (S[i].at(j) != '#') cout << U[i][j];
            else cout << '#';
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import sys
import itertools

h,w,k=map(int,input().split())

if w==1:
    print(1)
    sys.exit()
    
mod=10**9+7

ww=[]
for i in itertools.product([0,1], repeat=w-1):
    yn=""
    for wi in range(w-2):
        if i[wi]==1 and i[wi+1]==1:
            yn="no"
            break
    if yn=="" :
        ww.append(i)

dp=[[0]*w for i in range(h+1)]
dp[0][0]=1

for i in range(h):
    for wi in ww:
        j=0
        if wi[j]==1:
            dp[i+1][j]=(dp[i+1][j]+dp[i][j+1])%mod
        else:    
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod

        for j in range(1,w-1):
            if wi[j-1]==1:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j-1])%mod
            elif wi[j]==1:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j+1])%mod
            else:    
                dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod
        j=w-1
        if wi[j-1]==1:
            dp[i+1][j]=(dp[i+1][j]+dp[i][j-1])%mod
        else:    
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod
                
print(dp[h][k-1])
        

Measured memory_bytes: 73876
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
   ll x;
  cin >> x;
  ll ans;
  if(x%2==1){
    ans=0;
  }
  else{
    ll t=x/10;
    ll sum=t;
    while(t!=0){
      sum+=t/5;
      t/=5;
    }
    ans=sum;
  }
  cout << ans << endl;
}


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

int main(){
  int n; string s;
  cin >> n >> s;
  
  int c=0;
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){c++;}
  }
  
  cout << n-c;
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main( int argc, char** argv ){
	char c;
  
  cin >> c;
  
  if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
  
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int a[101];
	int asum=0;
	scan(N);
	rep(i,N){
		scan(a[i]);
		asum+=a[i];
	}
	double amean=(double)asum/N;
	int ans=-1;
	double absmin=INF;
	rep(i,N){
		if(fabs(amean-a[i])+eps<absmin){
			ans=i;
			absmin=fabs(amean-a[i]);
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

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

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/


int main()
{
	int n, m;
	
	while (cin >> n >> m, n | m)
	{
		int p[n];
		
		REP(n) cin >> p[i];
		sort(p, p + n);
		
		int sum = 0, cnt = 0;
		for (int i=n-1; i>=0; i--)
		{
			cnt++;
			if (cnt == m)
			{
				cnt = 0;
				continue;
			}
			sum += p[i];
		}
		
		cout << sum << endl;
		
		/*
		//テスト出力
		REP(n) cout << p[i] << " ";
		*/
	}
	
	return 0;
}

Measured memory_bytes: 1180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            int ans = 0;

            for(int i = 0; i < a.Length; i++)
            {
                if (a.Equals(b)) break;
                if (!a[i].Equals(b[i]))
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27420
#include<iostream>
#include<string>

using namespace std;
int main(){
        string s;
        int sw=0;
        cin >> s;
        for(int i=0;i<3;i++){
                if(s[i]==s[i+1])
                        sw = 1;
        }
        if(sw==0)
                cout << "Good\n";
        else
                cout << "Bad\n";
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main() {
	int a, b, c, k, ans = 0;
	scanf("%d %d %d %d", &a, &b, &c, &k);
	if (k < a)ans = k;
	else if (k <= a + b)ans = a;
	else ans = a + a + b - k;
	printf("%d", ans);
}

Measured memory_bytes: 1736
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 x;
  std::cin>>x;

  if(x>=30)std::cout<<"Yes\n";
  else std::cout<<"No\n";
  
  return 0;
}

Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

bool check(string& s, string& t, int& x, int& y){
  for(int i=2, j=2*y-x; i<s.size(); ++i, j+=y-x){
    if(j >= t.size()) return false;
    if(s[i] != t[j]) return false;
  }
  return true;
}

bool solve(string& s, string& t){
  if(t.size() < s.size()) return false;
  int i=0, j=0;
  while(1){
    i = t.find(s[0], i);
    if(i == string::npos) return false;
    j=i+1;
    while(1){
      j = t.find(s[1], j);
      if(j == string::npos) break;
      if(check(s, t, i, j)) return true;
      ++j;
    }
    ++i;
  }
}

int main(){
  int n, sum=0;
  string s, t;
  cin >> n >> s;
  for(int i=0; i<n; ++i){
    cin >> t;
    sum += solve(s, t);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1208
from collections import deque

N, M = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
s, t = map(lambda x: int(x)-1, input().split())

INF = 10 ** 10
dist = [[INF] * 3 for _ in range(N)]
dist[s][0] = 0

que = deque([[s, 0]])

while len(que):
    pv, pl = que.popleft()
    for nv in link[pv]:
        nl = (pl + 1) % 3
        if dist[nv][nl] != INF:
            continue
        dist[nv][nl] = dist[pv][pl] + 1
        que.append([nv, nl])

ans = dist[t][0]
if ans == INF:
    ans = -1
else:
    ans //= 3

print(ans)


Measured memory_bytes: 71072
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int no,shit,sherlock,holmes;
    double fuck;
    cin >> no >> shit;
    
    sherlock=no/shit;
    holmes=no%shit;
    fuck=(double)no/shit;
    
    cout<< sherlock << endl << holmes << endl;
    
    cout.precision(5);
    cout << fixed << fuck << endl;;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n; scanf("%d",&n);
   vector<int> a(n);
   rep(i,0,n)scanf("%d",&a[i]);
   int pos=inf,res=0;
   rep(i,0,n){
      if(pos>a[i]){
         res++; pos=a[i];
      }
   }
   printf("%d\n",res);
   return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
int main() {
    cin>>s;

    ll cnt=0;
    REP(i, 0, s.size()){
        if(s[i]=='o') cnt++;
    }
    if(cnt+(15-s.size()) >= 8) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if a[i] != max(a[i-1],a[i],a[i+1]) and a[i] != min(a[i-1],a[i],a[i+1]):
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

int main() {

	int a, b;
	cin >> a >> b;
	if (a > 8 || b > 8)cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mp make_pair
#define ll long long

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int minCost(int a[],vector<int> &dp,int n,int k,int i)
{
	if(i==n-1)
	{
		return 0;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	int m=INT_MAX;
	for(int j=1;j<=k && i+j<n;j++)
	{
		m=min(m,abs(a[i]-a[i+j])+minCost(a,dp,n,k,i+j));
	}
	return dp[i]=m;
}

int main()
{
	fastio
	int n,i,k;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	vector<int> dp(n,-1);
	cout<<minCost(a,dp,n,k,0);
}

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

int main()
{
  int N, A, B, total = 0;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> A >> B;
    total += B - A + 1;
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,k,Min=99999999;
	cin>>x;
	if(x==1) 
	{
		cout<<1;
		return 0;
	}
	for(int i=1;i<=x;i++)
	for(int j=2;j<=x;j++)
	{
		k=pow(i,j);
		//cout<<k<<" "<<Min<<endl;
		if(k>x) break;
		else if((x-k)<Min) Min=x-k;
	}
	cout<<x-Min;
	return 0;
}

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

/* define const */
const long Div = 1000000007;
/* finish defineing const */

int n;
int k[1010] = {1};
int idx[1010] = {};

int f[1010] = {};
bool prime[40];

bool p(int n)
{
  if (n == 1) return true;
  else if (n == 2) return true;
  else if (n == 3) return true;
  else {
    for (int i = 2; i*i <= n; i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}

int main()
{
  cin >> n;

  if (n == 1)  { cout << 1 << endl; }
  else {
    for (int i = 1; i <= n; i++) {
      k[i] = (k[i-1]*i)%Div;
    }
    for (int i = 1; i < 40; i++) {
      if (p(i)) prime[i] = true;
    }
    // input
    
    for (int i = 2; i <= n; i++) {
      for (int j = 2; j <= i; j++) {
	int t = i;
	while (p(j) && t%j == 0) {
	  f[j]++;
	  t /= j;
	}
      }
    }
    /*    
    for (int i = 1; i <= n; i++) {
      cout << i << ":" << f[i] << " ";
    }
    cout << endl;
    */
    long cnt = 1;
    
    for (int i = 2; i <= n ; i++) {
      cnt = (cnt*(f[i]+1))%Div;
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 256
mycode = '''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

from libcpp.vector cimport vector


ctypedef long long LL
cdef LL MOD = 10**9 + 7
cdef LL N = int(input())
cdef LL ans = 1
cdef vector[LL] ansls

cdef i
for i in range(2, N + 1):
    ans *= i
    ans %= MOD
    ansls.push_back(ans)
print(ans)
# print(type(ansls))

'''
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    import os
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


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


int32_t main() {


	int n ;
	cin >> n;

	mk(a, 20, int);
	mk(b, 20, int);
	mk(c, 20, int);
	for (int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	for (int i = 0 ; i < n ; i++) {
		cin >> b[i];
	}
	for (int i = 0 ; i < n - 1 ; i++) {
		cin >> c[i];
	}
	int sum = 0 ;
	for (int i = 0 ; i < n ; i++) {
		int dish = a[i];
		sum += b[dish - 1];
		if (i != 0) {
			int dish2 = a[i - 1];
			if (dish - dish2 == 1) {
				sum += c[dish - 2];
			}
		}

	}
	cout << sum;





	return 0;
}

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

d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

ans = 0
for i in d:
    ans += d[i]*(d[i]-1)//2
for i in a:
    print(ans - d[i]*(d[i]-1)//2 + (d[i]-2)*(d[i]-1)//2)


Measured memory_bytes: 86604
#include <iostream>
#define ll long long
using namespace std;

int fun(int a, int b, ll h[]){
  if(h[a-1]<h[b-1]){return a;}
  else if(h[a-1]>h[b-1]){return b;}
  else{return -1;}
}

int main(){
  int n,m; cin>>n>>m;
  ll h[n]; int stat[n];
  for(int i=0;i<n;i++){
    cin>>h[i]; stat[i]=1;
  }
  
  int a,b,mi;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    mi = fun(a,b,h);
    if(mi!=-1){stat[mi-1]*=0;}
    else{stat[a-1]=stat[b-1]=0;}
  }
  
  int sum=0;
  for(int i=0;i<n;i++){sum+=stat[i];}
  
  cout<<sum;
  
  return 0;
}

Measured memory_bytes: 4792
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		char[] input = sc.next().toCharArray();
		Arrays.parallelSort(input);
		if(input[0]==input[1] && input[2]==input[3] && input[1]!=input[2]) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
using namespace std;
char s[20][20];
int ans,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void func(int y,int x){
	s[y][x]='0';
	int q,p;
	for(int i=0;i<4;i++){
		q=x+dx[i];
		p=y+dy[i];
		if(q>=0&&q<12&&p>=0&&p<12){
			if(s[p][q]=='1')
			func(p,q);
		}
	}
}
int main(){
	
	while(cin>>s[0]){
		ans=0;
		for(int i=1;i<12;i++)
		cin>>s[i];
		for(int i=0;i<12;i++)
		for(int j=0;j<12;j++)
		if(s[i][j]=='1'){
			ans++;
			func(i,j);
		}
		cout<<ans<<endl;
	}
	return 0;
}	

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

long long dp[100][100001];

long long maxvalue(long long cur,long long B,long long w[],long long v[],long long n)
{
    if(cur==n){
        return 0;
    }
    if(B<=0){
        return 0;
    }
    if(dp[cur][B]!=-1){
        return dp[cur][B];
    }
    long long a=0;
    if(B>=w[cur]){
        a=v[cur]+maxvalue(cur+1,B-w[cur],w,v,n);
    }
    long long b=maxvalue(cur+1,B,w,v,n);
    dp[cur][B] = max(a,b);
    return dp[cur][B];
}

int main()
{
    long long n,W;
    cin>>n>>W;
    long long w[n],v[n];
    for(long long i=0; i<n; i++)
    {
        cin>>w[i]>>v[i];
    }
    for(long long i=0;i<n;i++){
        fill(dp[i],dp[i]+W+1,-1);
    }

    cout << maxvalue(0,W,w,v,n);
}



Measured memory_bytes: 78336
#include <stdio.h>


int main()
{
  int n;
  int a, b, c, d;
  int count = 0;

  while (scanf("%d", &n)!=EOF) {

    for (a = 0; a <= 9; a++) {
      for (b = 0; b <= 9; b++) {
	for (c = 0; c <= 9; c++) {
	  for (d = 0; d <= 9; d++) {
	    if (a + b + c + d == n)
	      count++;
	  }
	}
      }
    }

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

Measured memory_bytes: 0
def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  _L = a[left..mid-1]
  _R = a[mid..right-1]
  _L[n1] = _R[n2] = 1.0 / 0.0
  i = j = 0
  left.upto(right-1){|k|
    if _L[i] <= _R[j] then
      a[k] = _L[i]
      i += 1
    else
      a[k] = _R[j]
      j += 1
    end
  }
  return right - left
end

def mergeSort(a, left, right)
  count = 0
  if left+1 < right then
    mid = (left + right) / 2
    count += mergeSort(a, left, mid)
    count += mergeSort(a, mid, right)
    count += merge(a, left, mid, right)
  end
  return count
end

n = gets.to_i
a = gets.split.map(&:to_i)

count = mergeSort(a, 0, n)

puts a.join(" ")
puts count

Measured memory_bytes: 72860
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, ans;

int main()
{
	in >> N;
	std::vector<int>p(N);
	rep(i, N) in >> p[i];
	std::sort(p.begin(), p.end());
	for (int i = 0; i <= 100; ++i)
	{
		auto it = std::lower_bound(p.begin(), p.end(), i);
		auto num = p.end() - it;
		if (i <= num) ans = i;
		else break;
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3152
s = input()
q = int(input())
li=[list(map(str,input().split())) for _ in range(q)]

moji = "0"
frag = True

for i in range(q):
    que = li[i]
    if que[0] == "1":
        if frag:
            frag = False
        else:
            frag = True
    else:
        f = que[1]
        c = que[2]
        if frag:
            if f == "1":
                moji = c+moji
            else:
                moji = moji+c
        else:
            if f == "1":
                moji = moji+c
            else:
                moji = c+moji


if frag:
    print(moji.replace("0",s))
else:
    moji = moji[::-1]
    print(moji.replace("0",s[::-1]))

Measured memory_bytes: 40520
#include <iostream>
#include <string>


using namespace std;
 
struct Node {
    int key;
    Node *parent, *left, *right;
};
 
Node *root, *NIL;
 
void insert(int key) {
    Node *y = NIL;
    Node *x = root;
    Node *z = (Node *)malloc(sizeof(Node));
 
    z->key = key;
    z->left = NIL;
    z->right = NIL;
 
    while (x != NIL) {
        y = x;
        if (key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    };
    
    z->parent = y;
 
    if (y == NIL) {
        root = z;
        return;
    }
 
    if (key <= y->key) {
        y->left = z;
    } else {
        y->right = z;
    }
};
 
void preorder(Node *node) {
    if (node == NIL) return;
    cout << " " << node->key;
    preorder(node->left);
    preorder(node->right);
}

void inorder(Node *node) {
    if (node == NIL) return;
    inorder(node->left);
    cout << " " << node->key;
    inorder(node->right);
}

int main() {
    int n, x;
    string op;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> op;
        if (op == "insert") {
            cin >> x;
            insert(x);
            continue;
        } else {
            inorder(root); cout << endl;
            preorder(root); cout << endl;
            continue;
        }
    }
    

    return 0;
}


Measured memory_bytes: 26588
//ProblemC

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

#ifndef REDIRECT_STDIO
#define REDIRECT_STDIO {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
#endif // REDIRECT_STDIO

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

//vector
template<typename T> using vt = std::vector<T>;
template<typename T> using vvt = vt<vt<T>>;
template<typename T> using vvvt = vt<vvt<T>>;
using vi = vt<int>;
using vvi = vvt<int>;
using vvvi = vvvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;
using vvvl = vvvt<ll>;
using vb = vt<bool>;
using vpii = vt<pii>;

static inline bool Solve();

int main(int argc, char* argv[]) {
	REDIRECT_STDIO;

	cout << (Solve() ? "Yes" : "No") << endl;
	return 0;
}

vvi edges;
vi color;
unordered_set<int> seen { };
int color_seq[4] = {0, 0, 1, 1};

int dfs(int i, int c, unordered_set<int>& s) {
	int msk = i * 10 + c;
	if(s.count(msk)) return 1;
	if(seen.count(msk)) return 0;

	s.insert(msk);
	seen.insert(msk);
	int nc = (c + 1) % 4;
	for(auto n : edges[i]) {
		if(color[n] == color_seq[nc]) {
			if(dfs(n, nc, s)) return 1;
		}
	}
	s.erase(msk);
	return 0;
}

//ProblemC
bool Solve() {
	int n, m; 
	string s;
	cin >> n >> m >> s;

	color.assign(n, 0);
	edges.assign(n, {});

	for(int i = 0; i < n; i++) color[i] = s[i] == 'A' ? 0 : 1;
	for(int _ = 0; _ < m; _++) {
		int x, y; cin >> x >> y;
		x--, y--;
		edges[x].push_back(y);
		if (x != y)
			edges[y].push_back(x);
	}

	seen.clear();

	for(int i = 0; i < n; i++) {
		unordered_set<int> ts;
		if(dfs(i, color[i] == 0 ? 0 : 2, ts)) return true;
	}

	return false;
}


Measured memory_bytes: 36492
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int **dp;

void func(int N,int limit){
	int table[N][N+1],nextState,tmp;

	for(int i = 0; i < N; i++){
		for(int k = 0; k <= N; k++)scanf("%d",&table[i][k]);
	}

	for(int i = 0; i < N; i++){
		tmp = pow(2,i);
		dp[1][tmp] = table[i][0];
	}

	bool check[N];

	for(int i = 2; i <= N; i++){
		for(int k = 0; k < limit;k++){
			if(dp[i-1][k] != BIG_NUM){
				for(int p = 0; p < N; p++){
					if(k & (1 << p)){
						check[p] = true;
					}else{
						check[p] = false;
					}
				}

				for(int p = 0; p < N; p++){
					if(check[p] == false){
						nextState = k + pow(2,p);
						for(int a = 0; a < N; a++){
							if(check[a]){
								dp[i][nextState] = min(dp[i][nextState],dp[i-1][k] + min(table[p][0],table[p][a+1]));
							}else{
								dp[i][nextState] = min(dp[i][nextState],dp[i-1][k]+table[p][0]);
							}
						}
					}
				}
			}
		}
	}
	printf("%d\n",dp[N][limit-1]);
}

int main(){

	dp = new int*[17];

	for(int i = 0; i <= 16; i++){
		dp[i] = new int[65536];
	}

	int N,limit;
	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		limit = pow(2,N);

		for(int i = 0; i <= N; i++){
			for(int k = 0; k < limit; k++)dp[i][k] = BIG_NUM;
		}

		func(N,limit);
	}
    return 0;
}

Measured memory_bytes: 7172
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
H = LI() + [0]

ans = 0
state = 1
for i in range(max(H)):
    for h in H:
        if state:
            if h >= i + 1:
                state = 0
        else:
            if h < i + 1:
                ans += 1
                state = 1


print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_W 10000

int main() {
	int n, w;
	struct ITEM {
		int v, w;
	} item[1001];
	cin >> n >> w;
	for (int i = 1; i <= n; i++)
		cin >> item[i].v >> item[i].w;
	int dp[MAX_W+1];
	fill_n(dp, MAX_W+1, 0);
	for (int i = 1; i <= n; i++) {
		for (int j = item[i].w; j <= w; j++) {
			dp[j] = max(dp[j], dp[j - item[i].w] + item[i].v);
		}
	}
	cout << dp[w] << endl;
	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
int main()
{
   int x,k,n,y,j,t;
   scanf("%d %d %d %d",&n,&k,&x,&y);
if(n>=k){
   j=n-k;
   t=(k*x)+(y*j);

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


if(n<k){

    t=n*x;
     printf("%d\n",t);
}





    return 0;
}


Measured memory_bytes: 128
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

class Point {
 public:
  double x, y;

  Point(double x = 0, double y = 0): x(x), y(y) {}

  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }

  double abs() { return sqrt(norm()); }
  double norm() {return x * x + y * y; }

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

};

typedef Point Vector;

double dot(Vector a, Vector b) {
  return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
  return a.x * b.y - a.y * b.x;
}

struct Segment {
  Point p1, p2;
};

typedef Segment Line;

class Circle {
 public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
};

double arg(Vector p) {
  return atan2(p.y, p.x);
}

Vector polar(double a, double r) {
  return Point(cos(r) * a, sin(r) * a);
}

pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
  // assert(intersect(c1, c2));
  double d = (c2.c - c1.c).abs();
  double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
  double t = arg(c2.c - c1.c);
  return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}

int main() {
  Circle c1, c2;
  cin >> c1.c.x >> c1.c.y >> c1.r;
  cin >> c2.c.x >> c2.c.y >> c2.r;
  pair<Point, Point> result = getCrossPoints(c1, c2);
  cout << fixed;
  if (result.first.x < result.second.x) {
    cout << setprecision(10) << result.first.x << " " << result.first.y << " " << result.second.x << " " << result.second.y << endl;
  } else if (result.first.x == result.second.x && result.first.y < result.second.y) {
    cout << setprecision(10) << result.first.x << " " << result.first.y << " " << result.second.x << " " << result.second.y << endl;
  } else {
    cout << setprecision(10) << result.second.x << " " << result.second.y << " " << result.first.x << " " << result.first.y << endl;
  }

  return 0;
}



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

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> MAT;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<ll,ll> UMLL;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef unordered_set<int> USI;

// Display Map
//~for (auto const& pair: m) {
//~std::cout << "{" << pair.first << ": " << pair.second << "}\n";
//~}

// Extract word(w) from sentence(s)
//~stringstream str(s);
//~string w;
//~while(str >> w){
//~// w is your word
//~}

//Memset Syntax
// memset(array, value,sizeof(array)) val is 0,-1 or bool only

// To get accurate precision
//~cout.precision(20);

// Concatinate Vectors
//~

int main() {
    fast_io;
	ll n;
	cin >> n;
	string s;
	cin >> s;
	int rc = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R') rc++;
	}
	int ded = 0;
	for(int i = 0; i < rc; i++){
		if(s[i] == 'R') ded++;
	}
	cout << rc - ded << endl;
}


Measured memory_bytes: 3772
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] edge = new int[m][2];
		for(int i = 0; i < m; i++){
		    edge[i][0] = sc.nextInt()-1;
		    edge[i][1] = sc.nextInt()-1;
		}
		
		// 計算
		int result = 0;
		UnionFind uf;
		for(int i = 0; i < m; i++){
		    uf = new UnionFind(n);
		    for(int j = 0; j < m; j++){
		        if(i == j) continue;
		        uf.union(edge[j][0], edge[j][1]);
		    }
		    if(!uf.same(edge[i][0], edge[i][1])) result++;
		}
		
		
		// 出力
		System.out.println(result);
	}
}

class UnionFind {
    int[] parent;
    int[] rank;
    
    UnionFind(int n){
        this.parent = new int[n];
        this.rank = new int[n];
        for(int i = 0; i < n; i++){
            parent[i] = i;
            rank[i] = 0;
        }
    }
    
    public int find(int i){
        if(i == parent[i]) return i;
        parent[i] = find(parent[i]);
        return parent[i];
    }
    
    public void union(int x, int y){
        int xRoot = find(x);
        int yRoot = find(y);
        if(rank[xRoot] < rank[yRoot]){
            parent[xRoot] = yRoot;
        }else if(rank[xRoot] > rank[yRoot]){
            parent[yRoot] = xRoot;
        }else{
            parent[yRoot] = xRoot;
            rank[xRoot]++;
        }
    }
    
    public boolean same(int x, int y){
        return find(x) == find(y);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
    int n,m,l;
    cin >> n >> m >> l;
    long int A[150][150],B[150][150],C[150][150];
    
    for(int i=0;i<n;i=i+1){
        for(int j=0;j<m;j=j+1){
         cin >> A[i][j];
        }
    }
   
    for(int j=0;j<m;j=j+1){
        for(int k=0;k<l;k=k+1){
         cin >> B[j][k];
       // cout << B[j][k] << endl;
        }
    }
        
    for(int i=0;i<n;i++){
        
        for(int k=0;k<l;k=k+1){
            for(int j=0;j<m;j=j+1){
                C[i][k]=A[i][j]*B[j][k]+C[i][k];
            }
        
         //   cout << C[i][k] << endl;
     //   printf("%d ",C[i][k]);
        }
 //   printf("\n");
    }
    
    for(int i=0;i<n;i++){
        for(int k=0;k<l;k++){
            if(k==l-1){
                printf("%ld\n",C[i][k]);
            }else{
                printf("%ld ",C[i][k]);
            }
        }
    }
}



Measured memory_bytes: 3428
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
	double max = -1,min = 1000001,tmp;

	while(scanf("%lf",&tmp)!=EOF){
		max = (max >= tmp)?max:tmp;
		min = (min <= tmp)?min:tmp;
	}

	printf("%.1lf\n",max-min);

    return 0;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
#define int long long

#define size 100100
/*#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(container, it) \
for(typeof((container).begin()) it = (container).begin(); it != (container).end(); it++)
#define present(container, element) ((container).find(element) != (container).end())
#define cpresent(container, element) (find(all(container),element) != (container).end())
*/

using namespace std;

/*typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
*/

vector<bool> is_prime(size+1,1);

void calc_prime()
{
is_prime[0]=is_prime[1]=0;

for(int i=2; i*i<=size; i++)
{

 if(is_prime[i])
 {
  for(int j=i*i; j<=size; j+=i)
  {
   is_prime[j]=0;
   }
  }
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int a;
cin>>a;

calc_prime();

for(int i=a; i<=size; i++)
{
	if(is_prime[i])
	{
		cout<<i;
		break;
	}
}
return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::Reverse;

#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars};

#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
pub fn main() {
    input! {
        k: usize,
        s: Chars,
    }

    if s.len() > k {
        let st: String = s[..k].iter().collect();
        println!("{}...", st);
    } else {
        println!("{}", s.iter().collect::<String>());
    }
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();ite++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

//---------------------
#define MAXN 100000
//---------------------

double w,h,x,y;
double ret,num=0;
int main(){
	cin>>w>>h>>x>>y;
	if(x==w/2 && y==h/2) num=1;
	cout<<w*h/2<<" "<<num <<endl;
	
	return 0;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const int C = 31;
const int T = 1e5 + 2;
int v[C][T];
int ok[T];
int n,c;

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> c;

    for(int i = 0; i < n; i++) {
        int s,t,ci;
        cin >> s >> t >> ci;
        v[ci][s]++;
        v[ci][t+1]--;
    }

    int ans = 0;

    for(int i = 1; i < C; i++) {
        for(int j = 1; j < T; j++) v[i][j] += v[i][j-1];
        for(int j = 0; j < T; j++) {
            v[i][j] = min(v[i][j],1);
            ok[j] += v[i][j];
            ans = max(ans,ok[j]);
        }
    }

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


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

using namespace std;

struct Dinic {
    using F = int;
    const static F INF = 0x3f3f3f3f; 
    struct Edge {
        int v, bro; F cap;
        Edge() {}
        Edge(int _v, int _bro, F _cap) : v(_v), bro(_bro), cap(_cap) {}
    };
    vector<Edge> e;
    vector<int> pos, cur;
    int n, s, t, m;
    Dinic(int _n, int _s, int _t) : n(_n), s(_s), t(_t), m(0) {
        pos.assign(n, -1);
        cur.resize(n);
        d.resize(n);
        q.resize(n);
        e.reserve(4e5);
    }
    void add(int u, int v, F c=INF) {
        assert(u < n && v < n);
        e.emplace_back(v, pos[u], c); pos[u] = m++;
        e.emplace_back(u, pos[v], 0); pos[v] = m++;
    }
    vector<int> d;
    vector<int> q; int back;
    bool bfs() {
        fill(d.begin(), d.end(), -1);
        d[s] = 0;
        q[back=0] = s;
        for (int _ = 0; _ <= back;) {
            int u = q[_++];
            for (int i = cur[u] = pos[u]; i != -1; i = e[i].bro) {
                int v = e[i].v;
                if (d[v] == -1 && e[i].cap != 0) {
                    d[v] = d[u] + 1;
                    q[++back] = v;
                }
            }
        }
        return d[t] != -1;
    }
    F dfs(int u, F lim) {
        if (u == t) return lim;
        F tot = 0;
        for (int& i = cur[u]; i != -1; i = e[i].bro) {
            int v = e[i].v;
            if (e[i].cap != 0 && d[v] == d[u] + 1) {
                int flow = dfs(v, min(e[i].cap, lim-tot));
                tot += flow;
                e[i].cap -= flow;
                e[i^1].cap += flow;
                if (tot == lim) return lim;
            }
        }
        return tot;
    }
    F flow() {
        F res = 0;
        while (bfs()) {
            res += dfs(s, INF);
        }
        return res;
    }
};


void solve() {
    int n; cin >> n;
    vector<int> p(n), q(n);
    for (auto& x: p) {
        cin >> x;
    }
    for (auto& x: q) {
        cin >> x;
    }
    int s = 0;
    int cyc_cnt = 0;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        if (!a[i] && p[i] != i) {
            cyc_cnt++;
            for (int x = i; !a[x]; x = p[x]) {
                a[x] = cyc_cnt;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (!b[i] && q[i] != i) {
            cyc_cnt++;
            for (int x = i; !b[x]; x = q[x]) {
                b[x] = cyc_cnt;
            }
        }
    }
    int t = cyc_cnt + 1;
    Dinic mc(t+1, s, t);
    int res = 0;
    for (int i = 0; i < n; i++) {
        int x = p[i], y = q[i];
        if (x == i && y == i) continue;
        res++;
        if (x == i) mc.add(s, b[i], 1);
        else if (y == i) mc.add(a[i], t, 1);
        else {
            mc.add(a[i], b[i], 1);
            if (x == y) mc.add(b[i], a[i], 1);
        }
    }
    res -= mc.flow();
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 8704
route=''
sx,sy,tx,ty=map(int,input().split())
h=abs(ty-sy)
w=abs(tx-sx)
for i in range(h):
    route+=str("U")
for j in range(w):
    route+=str("R")
for i in range(h):
    route+=str("D")
for i in range(w+1):
    route+=str("L")
for i in range(h+1):
    route+=str("U")
for i in range(w+1):
    route+=str("R")
route+=str("D")
route+=str('R')
for i in range(h+1):
    route+=str("D")
for i in range((w+1)):
    route+=str("L")
route+=str("U")
print(route)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
#define db double
#define mo 1000000007

using namespace std;
int a[25],b[25];
int main(){
	ll n;
	int top=0;
	scanf("%lld",&n);
	for (;n;a[++top]=n%10,n/=10);
	for (int i=200;i>=0;i--){
		int Top=0;
		int tmp=i;
		memset(b,0,sizeof(b));
		for (;tmp>=9;tmp-=9,b[++Top]=9);
		b[++Top]=tmp;
		bool fl=1;
		for (int j=18;j>=0;j--)
			if (b[j]>a[j]){
				fl=0;
				break;
			}
			else if (b[j]<a[j])
				break;
		if (fl==1){
			printf("%d\n",i);
			return 0;
		}
	}
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};

int h, w;
int fld[1001][1001];
int sea[1001][1001];
queue<P> que[2];
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

bool wave(bool flag) {
	if(que[flag].empty()) return 0;
	while(!que[flag].empty()) {
		P p = que[flag].front();
		que[flag].pop();
		rep(i, 8) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			sea[ny][nx]++;
			if(fld[ny][nx] != 0 && fld[ny][nx] == sea[ny][nx]) {
				que[!flag].push(P(nx, ny));
			}
		}
	}
	return 1;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	cin >> h >> w;
	rep(i, h) {
		string s;
		cin >> s;
		rep(j, w) {
			if(s[j] == '.') fld[i][j] = 0;
			else fld[i][j] = s[j] - '0';
		}
	}

	REP(i, 1, h-1) {
		REP(j, 1, w-1) {
			rep(d, 8) {
				int nx = j + dx[d];
				int ny = i + dy[d];
				if(fld[ny][nx] == 0) sea[i][j]++;
			}
			if(fld[i][j] != 0 && sea[i][j] >= fld[i][j]) {
				que[0].push(P(j, i));
			}
		}
	}

	int ans = 0;
	bool f = 0;
	while(wave(f)) {
		f = !f;
		ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 18852
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

typedef long long int ll;
typedef long int li;

int main(void){
    ll a;
    cin >> a;
    if(a==3||a==5||a==7)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256