akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(M)]

V = [i+1 for i in range(N)]
import itertools

ptr = list(itertools.permutations(V, N))

res = 0
for p in ptr:       
    if p[0] == 1:
        now = 1
        flag = [0 for _ in range(N)]
        flag[0] = 1
        for i in range(N-1):
            for j in range(M):
                if A[j][0] == now and A[j][1] == p[i+1]:
                    flag[A[j][1] - 1] += 1
                    now = p[i+1]
                if A[j][1] == now and A[j][0] == p[i+1]:
                    flag[A[j][0] - 1] += 1
                    now = p[i+1]
                    
        tmp = 1         
        for i in range(N):
            if flag[i] != 1:
                tmp = 0
                break
                
        res += tmp
 
print(res)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main() {
    int n,m;
    cin>>n>>m;
    vector<ll> x(n),y(n),z(n);
    rep(i,n) cin>>x[i]>>y[i]>>z[i];

    ll ans=-1LL<<60;
    rep(bit,1<<3){
        vector<ll> v;
        rep(i,n){
            ll tmp=0;
            if(bit & 1<<0) tmp+=x[i];
            else tmp-=x[i];
            if(bit & 1<<1) tmp+=y[i];
            else tmp-=y[i];
            if(bit & 1<<2) tmp+=z[i];
            else tmp-=z[i];
            v.push_back(tmp);
        }
        sort(all(v));
        reverse(all(v));
        ll tmp=0;
        
        rep(i,m) tmp+=v[i];
        //cout<<bit<<" "<<tmp<<endl;
        ans=max(ans,tmp);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main(void)
{
     int i,j,k,n,m;
     char x,y;
     scanf("%c %c",&x,&y);
     if(x>y)
          printf(">\n");
     else if(x<y)
          printf("<\n");
     else
          printf("=\n");
     return 0;
}


Measured memory_bytes: 256
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

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

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

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int64) int64 {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := int64(1); i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int64) int64 {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int64) int64 {
	res := int64(1)
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()

	ss := make(map[string]int, 0)

	for i := 0; i < n; i++ {
		s := readString()
		strs := make([]string, 0, 10)
		for _, c := range s {
			strs = append(strs, string(c))
		}
		sort.Strings(strs)

		sortedStr := ""
		for _, str := range strs {
			sortedStr += str
		}
		ss[sortedStr]++
	}

	var ans int64 = 0
	for _, v := range ss {
		if v > 1 {
			ans += int64(v) * int64(v-1) / 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 12160
package main
import (
  "fmt"
  "strconv"
)
func main() {
  var s,t string
  var k,n int
  fmt.Scan(&s)
  fmt.Scan(&t)
  if len(t) <= 3 {
    k,_ = strconv.Atoi(t)
  } else {
    k = 101
  }
  n = 1
  for i:=0;i<k;i++ {
    if i > len(s) { break }
    if s[i:i+1] != "1" {
      n,_ = strconv.Atoi(s[i:i+1])
      break
    }
  }
  fmt.Println(n)
}

Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

#define likely(expr) (__builtin_expect(!!(expr), 1))
#define unlikely(expr) (__builtin_expect(!!(expr), 0))

int Ans[100016];
int Now[100016];

int main() {
    int N;
    scanf("%d", &N);
    vector<pair<int, int> > A, B;
    for(int n=0; n<N; ++n) {
        int a;
        scanf("%d", &a);
        A.emplace_back(a, n);
    }
    for(int n=0; n<N; ++n) {
        int b;
        scanf("%d", &b);
        B.emplace_back(b, n);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    for(int n=0; n<N; ++n) {
        if(B[n].first<A[n].first) {
            printf("No\n");
            return 0;
        }
    }
    for(int n=1; n<N; ++n) {
        if(A[n].first<=B[n-1].first) {
            printf("Yes\n");
            return 0;
        }
    }
    for(int n=0; n<N; ++n) {
        Now[n] = n;
        Ans[B[n].second] = A[n].second;
    }
    for(int n=0; n<N-1; ++n) {
        if(Now[n]==Ans[n]) {
            printf("Yes\n");
            return 0;
        }
        int ans = Ans[n];
        int * Now2 = Now + n;
        for(int i=N-1-n; i; --i) {
            if likely(ans==Now2[i]) {
                Now2[i] = Now2[0];
                break;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

ll X;

int main(){
	cin>>X;
	ll a=100;
	ll i=0;

	while(1){
		if(a>=X)
			break;
		a = a*1.01;
		i++;
	}

	cout<<i<<endl;
	
}

Measured memory_bytes: 3636
class SegmentTree:
    def __init__(self, data, default=0, func=max):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        """func of data[start, stop)"""
        start += self._size
        stop += self._size

        res_left = res_right = self._default
        while start < stop:
            if start & 1:
                res_left = self._func(res_left, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res_right = self._func(self.data[stop], res_right)
            start >>= 1
            stop >>= 1

        return self._func(res_left, res_right)

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

import sys
input = sys.stdin.readline

n, q = map(int, input().split())
out = 0

stl = SegmentTree([n] * (n+1),default = n, func = min)
st_r = SegmentTree([n] * (n+1),default = n, func = min)

for _ in range(q):
    t, x = map(int, input().split())
    if t == 1:
        rFin = st_r.query(x, n+1)
        out += rFin - 2
        #minL = min(minL, x)
        stl[rFin] = min(stl[rFin], x)
    else:
        lFin = stl.query(x, n+1)
        out += lFin - 2
        #minR = min(minR, x)
        st_r[lFin] = min(st_r[lFin], x)
    #print(out)
print((n - 2) * (n - 2) - out)


Measured memory_bytes: 129428
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
 int n,r;
 cin>>n>>r;
 if(n<10){
   cout<<100*(10-n)+r<<endl;
 }else{
   cout<<r<<endl;
 }


}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N;

int main(){
    cin>>N;
    out(800*N-(N/15)*200);
    
    
}


Measured memory_bytes: 256
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline);

line.shift();

tree = {};
for (i in line) {
  ary = line[i].split(' ');
  tree[ary[0]] = {'left': ary[1], 'right': ary[2], 'root': true};
}

for (i in tree) {
  if (tree[i].left !== '-1') tree[tree[i].left].root = false;
  if (tree[i].right !== '-1') tree[tree[i].right].root = false;
}
for (i in tree)
  if (tree[i].root) root_id = i;


function preorder(id) {
  var node = tree[id], left = node.left, right = node.right, res = [id];
  if (left !== '-1') res = res.concat(preorder(left));
  if (right !== '-1') res = res.concat(preorder(right));
  return res;
}

console.log('Preorder');
console.log(' ' + preorder(root_id).join(' '));

function inorder(id) {
  var node = tree[id], left = node.left, right = node.right, res = [];
  if (left !== '-1') res = res.concat(inorder(left));
  res.push(id);
  if (right !== '-1') res = res.concat(inorder(right));
  return res;
}

console.log('Inorder');
console.log(' ' + inorder(root_id).join(' '));

function postorder(id) {
  var node = tree[id], left = node.left, right = node.right, res = [];
  if (left !== '-1') res = res.concat(postorder(left));
  if (right !== '-1') res = res.concat(postorder(right));
  res.push(id);
  return res;
}

console.log('Postorder');
console.log(' ' + postorder(root_id).join(' '));

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    string s;cin>>s;
    rep(i,s.size()){
        if(s[i]==','&&i!=s.size()-1)cout<<" ";
        else if(s[i]!=','&&i!=s.size()-1)cout<<s[i];
        else if(i==s.size()-1)cout<<s[i]<<endl;
    }
}

Measured memory_bytes: 256
def cost(target, ls)
  l = ls.reduce(:+)
  (ls.size-1)*10 + (target-l).abs
end

def sub(ary1, ary2)
  ary2.reduce(ary1.clone) {|ary, elem| ary.delete_at(ary.find_index(elem)); ary}
end

n, a, b, c = gets.split.map(&:to_i)
ls = n.times.map do
  gets.to_i
end

total_cost = (1..n-2).flat_map {|i| ls.combination(i).to_a}.map do |as|
  (1..n-as.size-1).flat_map {|j| sub(ls, as).combination(j).to_a}.map do |bs|
    (1..n-as.size-bs.size).flat_map {|k| sub(ls, as+bs).combination(k).to_a}.map do |cs|
  		cost(a, as) + cost(b, bs) + cost(c, cs)
    end
  end
end.flatten.min

puts total_cost

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n;cin >> n;
    ll t=0;
    rep(i,n){
        ll a;cin >> a;
        t^=a;
    }
    cout << (t? "No":"Yes") <<endl;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x;
    cin >> x;
    int a=x%7;
    if(a==0)
        cout << "thu" << endl;
    else if(a==1)
        cout << "fri" << endl;
    else if(a==2)
        cout << "sat" << endl;
    else if(a==3)
        cout << "sun" << endl;
    else if(a==4)
        cout << "mon" << endl;
    else if(a==5)
        cout << "tue" << endl;
    else
        cout << "wed" << endl;
}


Measured memory_bytes: 3100
H = int(input())
L = list(map(int, input().split()))
def maxHeapify(A, i):
    l = i * 2 + 1
    r = i * 2 + 2
    if l < H and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r < H and A[r] > A[largest]:
        largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest)
def buildMaxHeap(A):
    for i in range(H // 2, -1, -1):
        maxHeapify(A, i)
buildMaxHeap(L)
print("", " ".join(map(str, L)))



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

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

    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, 0, n) cin >> l[i];
    ll ans = 0;
    sort(l.begin(), l.end());
    rep(i, 0, n - 1) rep(j, i + 1, n) {
        int a = l[i], b = l[j];
        int k = lower_bound(l.begin(), l.end(), a + b) - l.begin();

        ans += k - j - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a_list=("abcdefghijklmnopqrstuvwxyz")
word=(raw_input())
flag=0
out="None"
for i in a_list:
    for n,k in enumerate(word):
        if i==k:
            break
        if n==len(word)-1:
            out=i
            flag=1
    if flag==1:
        break
print(out)

Measured memory_bytes: 2692
#include<iostream>
using namespace std;
int n,m;
char juzhen[101][101];
void dfs(int y,int x)
{
  if(juzhen[y][x]=='0')
  {
    for(int dy=-1; dy<=1; dy++)
    {
      for(int dx=-1; dx<=1; dx++)
      {
        int nx=dx+x,ny=dy+y;
        if(0<=ny&&ny<n&&0<=nx&&nx<m&&juzhen[ny][nx]=='#')                juzhen[y][x]+=1;
      }
    }
  }
  return;
}
int main()
{
  cin>>n>>m;
  for(int i=0; i<n; i++)        for(int j=0; j<m; j++)
    {
      cin>>juzhen[i][j];
      if(juzhen[i][j]=='.')            juzhen[i][j]='0';
    }
  for(int i=0; i<n; i++)        for(int j=0; j<m; j++)            dfs(i,j);
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<m; j++)            cout<<juzhen[i][j];
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    
    if m == -1 or f == -1:
        print('F')
    elif m+f >= 80:
        print('A')
    elif m+f >= 65 and m+f<80:
        print('B')
    elif m+f >= 50 and m+f<65:
        print('C')
    elif m+f >= 30 and m+f<50:
        if r>=50:
            print('C')
        else:
            print('D')
    elif m+f < 30:
        print('F')


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


int main() {
  int H,W;
  cin>>H>>W;
  vector<long> a(26);
  for(int i=0;i<H;i++) for(int j=0;j<W;j++){
    char c;
    cin>>c;
    a[c-'a']++;
  }
  int req4=(H/2)*(W/2);
  int req1=H%2*W%2;
  int req2=(H*W-req1-req4*4)/2;

  //cout<<req4<<endl;
  //cout<<req2<<endl;
  //cout<<req1<<endl;
  int a4=0,a2=0,a1=0;
  for(int i=0;i<26;i++){
    //cout<<a[i]<<endl;
    a4+=a[i]/4;
    a[i]%=4;
    a2+=a[i]/2;
    a[i]%=2;
    a1+=a[i];
  }
  //cout<<a4<<a2<<a1<<endl;
  if(req4>a4){
    cout<<"No"<<endl;
    return 0;
  }
  a4-=req4;
  a2+=a4*2;
  if(req2>a2){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
using namespace std;
template <class T> void rd(T &x){
  x = 0; int f = 1; char ch = getchar();
  while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  x *= f;
}

typedef long long ll;
int a, b, c, n;
ll ans;

int main(){
  rd(a), rd(b), rd(c), rd(n);
  rep(i, 0, n / a) rep(j, 0, n / b){
	int t = n - a * i - b * j;
	if(t < 0) continue;
	if(t % c == 0) ans ++;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
using System;

public class First_problem{
  public static void Main(){
    string[] str = Console.ReadLine().Split(' ');
    int h, n;
    h = int.Parse(str[0]);
    n = int.Parse(str[1]);
    
    int[] a = new int[n];
    int sum = 0;
    string[] str_weapon = Console.ReadLine().Split(' ');
    for(int i = 0 ; i < n ; i++){
      a[i] = int.Parse(str_weapon[i]);
      sum += a[i];
    }
    
	if( h - sum <= 0 ){
      Console.WriteLine("Yes");
    }
    else{
      Console.WriteLine("No");
    }
    
  }
}

Measured memory_bytes: 18528
N = int(input())
T,A = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
sub = [0 for i in range(N)]
for i in range(N):
    sub[i] = abs(A - (T - 0.006*H[i]))
print(sub.index(min(sub))+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//const int INF = 1e9;//INT_MAX=1<<31-1=2147483647
const ll INF = (ll)1e18;//1<<63-1=9223372036854775807
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
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 T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


class UnionFind {
public:
	UnionFind(size_t size) : v(size, -1) {}
	vector<int> v;

	int root(int x) {
		return (v[x] < 0 ? x : v[x] = root(v[x]));
	}

	bool is_root(int x) {
		return x == root(x);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) {
			if (v[x] > v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}

	int size(int x) {
		return -v[root(x)];
	}
};


const ll N_MAX = 100000;
const ll M_MAX = 100000;
const ll Z_I_MAX = 100;

ll N, M;
vector<ll> X,Y,Z;

void input() {
	scanf("%lld%lld", &N, &M);
	X=vector<ll>(M,0);
	Y=vector<ll>(M,0);
	Z=vector<ll>(M,0);
	rep(i,M){
		cin >>X[i]>>Y[i]>>Z[i];
		X[i]--;Y[i]--;
	}
}

void solve() {
	UnionFind tree=UnionFind(N);
	ll ans = 0;

	rep(i,M){
		tree.unite(X[i],Y[i]);
	}

	rep(i,N){
		int root=tree.root(i);
		if(root==i){
			ans++;
		}
	}


	p(ans);
}

signed main() {
	input();
	solve();
	return 0;
}


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

int main(){
	int n;
	cin>>n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<long long> b(n+1,0);
	for(int i=0;i<n;i++){
		b[i+1]=b[i];
		b[i+1]+=a[i];
	}
	long long ans=90000000000;
	long long min;
	for(int i=0;i<=n-1;i++){
		min=abs((b[n]-b[i+1])-(b[i+1]-b[0]));
		if(min<ans) ans=min;
	}

	cout<<ans<<endl;


	
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;

const int MOD = 1000000007;
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  ll k;
  cin >> k;
  int n = 50;
  ll x = (k + n*n - n) / n;
  ll arr[50];
  for(int i = 0;i < 50;i++){
    arr[i] = x;
  }
  ll rem = k - (x * n - n*n + n);
  for(int i = 0;i < rem;i++){
    arr[i] += n;
    for(int j = 0;j < 50;j++){
      if(i != j)
        arr[j]--;
    }
  }
  cout << 50 << endl;
  for(int i = 0;i < n;i++)
    cout << arr[i] << ' ';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        return fact[n]*ifact[n-k];
    }
};

mint comb(ll a, ll b) {
    if (a<b) return mint(0);
    if (b==0 || b==a) return mint(1);
    mint res = 1;
    rep(i, b) {
        res *= (a-i);
        res /= (i+1);
    }
    return res;
}
 
mint dp[64][3];

int main(){
    ll n;
    cin >> n;
    mint ans = 0;
    dp[61][0] = 1;
    for (ll i=60; i>=0; i--) {
        ll x = n>>i&1;
        if (x==0) {
            dp[i][0] = dp[i+1][0] + dp[i+1][1];
            dp[i][1] = dp[i+1][1];
            dp[i][2] = dp[i+1][1] + dp[i+1][2]*3;
        }
        if (x==1) {
            dp[i][0] = dp[i+1][0];
            dp[i][1] = dp[i+1][0] + dp[i+1][1];
            dp[i][2] = dp[i+1][1]*2 + dp[i+1][2]*3;
        }
        //debug(i);
        //rep(j, 3) debug(dp[i][j]);
    }

    rep(j, 3) ans += dp[0][j];

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


Measured memory_bytes: 3604
a[6000];main(t){int*p=a,*q=a;for(;scanf("%d%d",p,p+1),*p||*(p+1);p+=2)*p>*(p+1)&&(t=*p,*p=*(p+1),*(p+1)=t);for(;q<p;q+=2)printf("%d %d\n",*q,*(q+1));}



Measured memory_bytes: 1992
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))


;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))

;;本体
(defun main ()
  (let ((x (read)) (y (read)) (z (read)))
    (println (floor (/ (- x z) (+ y z))))))

#-swank(main)


Measured memory_bytes: 20452
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	string s,t;
	cin>>s>>t;
	int i=0,j=0;
	while(i<min(s.size(),t.size()))
	{
		if(s[i]!=t[j])
		return cout<<"No",0;
		i++;j++;
	}
	return cout<<"Yes",0;
}



Measured memory_bytes: 3636
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        int d = (int)a / (int)b;
        int r = (int)a % (int)b;
        double f = a/b;
        System.out.println(d + " " + r + " " + String.format("%.5f", f));
    }
}



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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll mod = 2019;

int main(void)
{
	string s;
	cin >> s;
	const int n = s.size();

	vector<ll> m(2019, 0);
	vector<ll> next(2019, 0);
	m[0] = 1;
	ll r = 0;
	ll sum = 0;
	rep(i, n) {
		next.assign(2019,0);
		rep(j, 2019) {
			next[(j * 10LL) % mod] += m[j];
		}
		ll b = r * 10 + (int)(s[i] - '0');
		b %= mod;
		r = b;
		sum += next[b];
		next[b]++;
		swap(m, next);
	}
	cout << sum << endl;
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    int ans = 0;

    for (size_t i = N; i > 0; i--)
    {
        if(to_string(i).size() % 2 != 0){
            ans++;
        }
        
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int segtree[12000000];
int n,m;
int H;
/*int query(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c)return 0;
	if(c<=a&&b<=d)return segtree[f][e-1];
	return max(query(a,(a+b)/2,c,d,e*2,f),query((a+b)/2+1,b,c,d,e*2+1,f));
}*/
int query2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j){
	if(d<a||b<c||h<e||f<g)return 0;
	if(c<=a&&b<=d){
		if(g<=e&&f<=h)return segtree[(i-1)*H+j-1];
		return max(query2(a,b,c,d,e,(e+f)/2,g,h,i,j*2),query2(a,b,c,d,(e+f)/2+1,f,g,h,i,j*2+1));
	}
	return max(query2(a,(a+b)/2,c,d,e,f,g,h,i*2,j),query2((a+b)/2+1,b,c,d,e,f,g,h,i*2+1,j));
}
/*void update(int a,int b,int c){
	b+=m;
	//while(a){
		int d=b;
		while(d){
			segtree[a][d-1]=max(segtree[a][d-1],c);
			d/=2;
		}
	//	a/=2;
	//}
}*/
void update2(int a,int b,int c){
	a+=n;b+=m;
	while(a){
		int d=b;
		while(d){
			segtree[(a-1)*H+d-1]=max(segtree[(a-1)*H+d-1],c);
			d/=2;
		}
		a/=2;
	}
}
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		n=1;
		while(n<a)n*=2;
		m=1;
		while(m<b)m*=2;
		H=m+b-1;
	/*	if((n+a-1)*(b+m-1)>1200000){
			//segtree=new int*[a];
			//for(int i=0;i<a;i++){
				segtree[i]=new int[m+b-1];
				for(int j=0;j<m+b-1;j++)segtree[i][j]=0;
			}
		//	segtree=vector<vector<int> >(n+a,vector<int>(m+b,2147483647));
			for(int i=0;i<a;i++)for(int j=0;j<b;j++){
				int d;scanf("%d",&d);
				update(i,j,2147483647-d);
			}
			for(int i=0;i<c;i++){
				int p,q,r,s;
				scanf("%d%d%d%d",&p,&q,&r,&s);
				int ret=0;
				for(int j=p;j<=r;j++)ret=max(ret,query(0,m-1,q,s,1,j));
				printf("%d\n",2147483647-ret);
			}
			for(int i=0;i<a;i++)delete[] segtree[i];
			delete[] segtree;
		}else{*/
		//	segtree=new int*[n+a-1];
		//	for(int i=0;i<n+a-1;i++){
		//		segtree[i]=new int[m+b-1];
		//		for(int j=0;j<m+b-1;j++)segtree[i][j]=0;
		//	}
		//  segtree=vector<vector<int> >(n+a,vector<int>(m+b,2147483647));
			for(int i=0;i<(n+a-1)*(m+b-1);i++)segtree[i]=0;
			for(int i=0;i<a;i++)for(int j=0;j<b;j++){
				int d;scanf("%d",&d);
				update2(i,j,2147483647-d);
			}
			for(int i=0;i<c;i++){
				int p,q,r,s;
				scanf("%d%d%d%d",&p,&q,&r,&s);
				printf("%d\n",2147483647-query2(0,n-1,p,r,0,m-1,q,s,1,1));
			}
		//	for(int i=0;i<n+a-1;i++)delete[] segtree[i];
		//	delete[] segtree;
		//}
	}
}

Measured memory_bytes: 25580
require 'matrix'

class String
	def replace_select
		return nil unless i = self =~ /,/	
		l = 0
		j = i
		until l == 1
			j -= 1
			l += 1 if self[j] == ?(
			l -= 1 if self[j] == ?)
		end
		r = 0
		k = i
		until l == 1
			k += 1
			r += 1 if self[j] == ?)
			r -= 1 if self[j] == ?(
		end
		self[0..j-1] + '.select(' + self[j+1..i-1] + ?@ + self[i+1..-1]	
	end
end

MOD = 2 ** 15

class Matrix
	def &(other)
		Matrix[*self.to_a.zip(other.to_a).map(&:flatten)]
	end
	def |(other)
		Matrix[*(self.to_a + other.to_a)]
	end
	def -@
		(-1 * self).map {|x| x % MOD}
	end
	def select(rows, cols)
		a =	rows.to_a[0].map {|i|
			cols.to_a[0].map {|j|
				self[i-1, j-1]
			}
		}
		Matrix[*a]
	end
	alias :orig_mul :*
	def *(other)
		if row_size * column_size == 1
			(self[0, 0] * other).map {|x| x % MOD}
		elsif other.row_size * other.column_size == 1
			(other[0, 0] * self).map {|x| x % MOD}
		else
			send(:orig_mul, other).map {|x| x % MOD}
		end
	end
	alias :orig_add :+
	def +(other)
		send(:orig_add, other).map {|x| x % MOD}
	end
	alias :orig_sub :-
	def -(other)
		send(:orig_sub, other).map {|x| x % MOD}
	end
	def to_s
		to_a.map{|row| row * ' '}*"\n"
	end
end

loop do
	dataset = gets.to_i
	break if dataset == 0
	a=b=c=d=e=f=g=h=i=j=k=l=m=n=o=p=q=r=s=t=u=v=w=x=y=z=nil
	dataset.times do
		exp = gets.chomp.chop
		exp.gsub!('--', '')
		exp.gsub!("''", '')
		exp.gsub!(?', '.transpose')
		while rep = exp.replace_select
			exp = rep
		end
		exp.gsub!(?@, ?,)
		exp.gsub!(' ', ?&)
		exp.gsub!(';', ?|)
		exp.gsub!(?[, ?()
		exp.gsub!(?], ?))
		exp.downcase!
		exp.gsub!(/(\d+)/, 'Matrix[[\1]]')
		puts eval(exp)
	end
	puts '-----' 
end

Measured memory_bytes: 9952
#include <iostream>
#define rt(q) if (q) cout<<"Yes"<<endl;else cout<<"No"<<endl;return 0;
using namespace std;
int abs1(int k)
{
  return max(k,-k);
}
bool move(int x1,int y1,int x2,int y2,int time)
{
  int al=abs1(x2-x1)+abs1(y2-y1);
  if (time<al) return false;
  if ((time-al)%2) return false;
  return true;
}
int N,xl,yl,xc,yc,tl,tc;
int main()
{
  cin>>N;
  for (int i=0;i<N;i++)
  {
    cin>>tc>>xc>>yc;
    if (!move(xl,yl,xc,yc,tc-tl)) {rt(0)}
    xl=xc;
    yl=yc; 
    tl=tc;
  }
  rt(1)
}

Measured memory_bytes: 256
from collections import defaultdict

H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

d = defaultdict(list)
for i in range(H):
    for j in range(W):
        d[A[i][j]].append([i, j])


p = []
for s in range(1, D + 1):
    c = 0
    q = [0]
    for i in range(s + D, H * W + 1, D):
        i0, j0 = d[i - D][0]
        i1, j1 = d[i][0]
        c += abs(i0 - i1) + abs(j0 - j1)
        q.append(c)
    p.append(q)


for l, r in LR:
    i = l % D - 1
    s = (l - 1) // D
    e = (r - 1) // D
    print(p[i][e] - p[i][s])


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

int main()
{
	string A,B,C;
	cin >> A >> B >> C;
	cout << A[0] << B[1] << C[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1 << 30;
template<class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }


int main() {
    int H, N;
    cin >> H >> N;
    vector<int> dp(H + 1, INF);
    dp[0] = 0;
    rep(_, N) {
        int a, b;
        cin >> a >> b;
        rep(i, H) chmin(dp[min(H, i + a)], dp[i] + b);
    }
    cout << dp[H] << '\n';
}


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

#define int long long
#define pb push_back
#define ff first
#define ss second

signed main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);    
     
     string s; cin >> s;
     int n = (int)s.size(), ans = 0;
     
     int i = 0, j = n-1;
     while(i <= j){
         if(s[i]!= s[j])ans++;
         i++; j--;
     }
     cout << ans << '\n';
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
ll slide(vector<ll>& v, ll a, ll b) {
	ll azv = abs(v[0] - a);
	ll bzv = abs(v[0] - b);
	ll aov = abs(v[1] - a);
	ll bov = abs(v[1] - b);
	v[0] = a;
	v[1] = b;
	return max((azv + bov), (bzv + aov));
}


void solv() {
	int n, c;
	cin >> n >> c;
	int ti[31][100010];
	memset(ti, 0, sizeof(ti));
	for (size_t i = 0; i < n; i++)
	{
		int s, t, cp;
		cin >> s >> t >> cp;
		ti[cp][s] = 1;
		ti[cp][t] = (ti[cp][t] == 1 ? 1 : -1);
	}

	for (size_t i = 1; i <= c; i++)
	{
		for (size_t j = 1; j < 100010; j++)
		{
			if (ti[i][j] == -1) ti[i][j] = 0;
			else if (ti[i][j] == 0) ti[i][j] = ti[i][j - 1];
		}
	}
	int res = 0;
	for (size_t i = 1; i < 100010; i++)
	{
		int cha = 0;
		for (size_t j = 0; j <= c; j++)
		{
			cha += ti[j][i] == 1 || ti[j][i - 1] == 1;
		}
		res = max(res, cha);
		//if (res == 3) {
		//	cout << endl;
		//}
	}
	cout << res << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;cin>>S;
  
  int c1=0;
  int c2=0;
  int c3=0;
  
  for(int i=0;i<3;i++){
    if(S[i]=='a'){
      c1++;
    }
    else if(S[i]=='b'){
      c2++;
    }
    else{
      c3++;
    }
  }
  
  if(c1==1&&c2==1&&c3==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    

Measured memory_bytes: 3624
n,w=map(int,input().split())
ab=[]
w-=1
take=[]
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
	a,b=map(int,input().split())
	ab.append([a,b])
	for j in range(w):
		if j+1-a>=0:
			dp[i+1][j+1]=max(dp[i][j+1],dp[i][j+1-a]+b)
		else:
			dp[i+1][j+1]=dp[i][j+1]
k=w
take=[]
for i in range(n):
	if dp[n-i-1][w]!=dp[n-i][w]:
		w-=ab[n-i-1][0]
		take.append(n-i-1)
take=set(take)
ans=0
for i in range(n):
	if i not in take:
		ans=max(ans,ab[i][1])
print(dp[-1][-1]+ans)




Measured memory_bytes: 119644
while True:
    H,W=map(int,input().split())
    if H==W==0:
        break
    S1=S2=''
    for i in range(W):
        if i%2==0:
            S1+='#'
            S2+='.'
        else:
            S1+='.'
            S2+='#'
    for i in range(H):
        if i%2==0:
            print(S1)
        else:
            print(S2)
    print('')            


Measured memory_bytes: 5616
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

/*void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<111111;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

int COM(int n,int k){
	if(n<k)return 0;
	if(n<0||k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}*/

//}

unordered_map<int,int> b;
int n,m,ans;

int tn(int x){
    return x*(x-1)/2;
}

main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    rep(i,n)cin>>a[i];
    for(int i=0;i<n-1;i++){
        a[i+1]+=a[i];
    }
    rep(i,n)a[i]%=m;
    for(int x:a){
        //cout<<x<<endl;
        if(b[x])b[x]++;
        else b[x]=1;
    }
    for(auto x:b){
        ans+=tn(x.se+(!(x.fi)));
    }
    dans;
}


Measured memory_bytes: 4492
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b)
    {
        if(a==c)printf("No\n");
        else printf("Yes\n");
    }
    else if(c==b)
    {
        if(a==c)printf("No\n");
        else printf("Yes\n");
    }
    else if(c==a)
    {
        if(a==b)printf("No\n");
        else printf("Yes\n");
    }
    else printf("No\n");
}


Measured memory_bytes: 256
/// Thank you tanakh!!!
///  https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(q: usize, ab: [(usize, usize); q]);
    for &(a, b) in ab.iter() {
        let (a, b) = if a > b { (b, a) } else { (a, b) };
        if a == b {
            println!("{}", 2 * a - 2);
        } else if a + 1 == b {
            println!("{}", 2 * a - 2);
        } else {
            println!("{}", solve2(a, b));
            let a1 = solve1(a, b);
            let a2 = solve2(a, b);
            if a1 != a2 {
                println!("{} {}", a, b);
                println!("{} != {}", a1, a2);
                panic!();
            }
        }
    }
}

fn solve1(a: usize, b: usize) -> usize {
    let c = ((a * b) as f64).sqrt() as usize;
    assert!(c * c <= a * b);
    let c = if c * c == a * b { c - 1 } else { c };
    if c * (c + 1) >= a * b {
        2 * c - 2
    } else {
        2 * c - 1
    }
}

fn solve2(a: usize, b: usize) -> usize {
    let mut x = (((a * b) as f64).sqrt() * 2.0) as usize - a - 1;
    let t = if x > a { (x - a - 1) / 2 } else { 0 };
    if (x - t) * (a + 1 + t) >= a * b {
        x -= 1;
    } else if (x - (t + 1)) * (a + 1 + (t + 1)) >= a * b {
        x -= 1;
    }
    a - 1 + x
}


Measured memory_bytes: 4352