akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
//#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 105, INF = 1e9 + 7;

int f[N][N], used[N][N], dp[N][N], n, m, cntu;
bitset<N * N> good[N * N];

void bfs(int x, int y, int st) {
    if (!f[x][y] || used[x][y] == cntu) return;
    good[st][x * m + y] = 1;
    used[x][y] = cntu;
    bfs(x + 1, y, st);
    bfs(x, y + 1, st);
}

void solve() {
    cin >> n >> m;
    loop(i, n)
        loop(j, m) {
            char c; cin >> c;
            f[i][j] = c == '#';
        }
    loop(i, n)
        loop(j, m) {
            ++cntu;
            bfs(i, j, i * m + j);
        }
    loop(i, n)
        loop(j, m) {
            if (!i && !j) {
                dp[i][j] = f[i][j]; continue;
            }
            if (!f[i][j])
                dp[i][j] = min((i ? dp[i - 1][j] : INF), (j ? dp[i][j - 1] : INF));
            else {
                dp[i][j] = INF;
                if (good[0][i * m + j]) {
                    dp[i][j] = 1; continue;
                }
                loop(u, i + 1)
                    loop(l, j + 1)
                        if (good[u * m + l][i * m + j]) {
                            if (u) dp[i][j] = min(dp[i][j], dp[u - 1][l] + 1);
                            if (l) dp[i][j] = min(dp[i][j], dp[u][l - 1] + 1);
                        }
            }
        }
    // loop(i, n) {
    //     loop(j, m)
    //         cout << dp[i][j] << " ";
    //     cout << "\n";
    // }
    cout << dp[n - 1][m - 1];
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

using namespace std;
int main(){
	string str;
	cin >> str;
	bool ok = false;
	for(int i = 0;i < str.length();i++){
		if(str[i] == 'C'){
			for(int j = i;j < str.length();j++){
				if(str[j] == 'F'){
					ok = true;
				}
			}
		}
		
	}
	if(ok) cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<String> arr = new ArrayList<>();

		while (true) {
			boolean flag = false;
			int border = Integer.parseInt(scan.next());
			if (border == 0) {
				break;
			}
			String ret = "NA";
			int sum = 0;
			for (int i = 0; i < 12; i++) {
				int m = Integer.parseInt(scan.next());
				int n = Integer.parseInt(scan.next());
				int sub = m - n;
				sum += sub;
				if (sum >= border && flag == false) {
					ret = String.valueOf(i + 1);
					flag = true;
				}
			}

			arr.add(ret);
		}
		arr.stream().forEach(System.out::println);
	}

}

Measured memory_bytes: 45068
# Problem D - Lunlun Number

from collections import deque

# input
K = int(input())

# initialization
num_queue = deque()
k = 1

# count
while True:
    if k>=1 and k<=9:
        num_queue.append(k)
        k += 1
    else:
        num = str(num_queue.popleft())
        num_str = int(num[-1])
        if num_str==0:
            for i in range(2):
                tmp = str(i)
                num_queue.append(int(num + tmp))
                k += 1
                if k-1==K:
                    break
        elif num_str==9:
            for i in range(8,10):
                tmp = str(i)
                num_queue.append(int(num + tmp))
                k += 1
                if k-1==K:
                    break
        else:
            for i in range(num_str-1, num_str+2):
                tmp = str(i)
                num_queue.append(int(num + tmp))
                k += 1
                if k-1==K:
                    break

    if k-1==K:
        break

# output
print(num_queue[-1])


Measured memory_bytes: 45660
#include<bits/stdc++.h>
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb           push_back
#define ff           first
#define ss           second
#define gcd(a, b)    __gcd(a, b)
#define lcm(a, b)    ((a)*((b)/gcd(a,b)))
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define lllim        2147483648
#define Pi           2*acos(0.0)
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define mem(a,b)     memset(a, b, sizeof(a))
#define fill_(a,b)   fill(a,a+n,b);
#define MOD          1000000007
#define fast_cin     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define filein       freopen("input.txt","r", stdin)
#define D(x)         cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define case         int t,cas=1;cin>>t;while(t--)
#define rep(i,a,n)   for(int i=a;i<n;i++)
#define rev(i,n,a)   for(int i=n;i>=a;i--)
#define sim          template<class T

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1};  // Kings Move
//const int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


sim > void read(T& a) {
    std::cin>>a;
}
sim > void read(T& a, T& b) {
    std::cin>>a>>b;
}
sim > void read(T& a,T& b, T& c) {
    std::cin>>a>>b>>c;
}

sim > void readvec( std::vector<T>& v, const int n) {
    rep(i,0,n) {
        T p;
        std::cin>>p;
        v.pb(p);
    }
}

using namespace std;
using namespace __gnu_pbds;

const int maxn=1e5+5;


void solve()
{
	
	ll ans=0;
	
	ll a,b,c;
	read(a,b,c);
	ans=min(b/a,c);
	

    cout<<ans<<endl;
}


int main()
{
    //fast_cin;

//case
    {
        // cout<<"Case "<<cas++<<": ";
        solve();

    }

    return 0;
}


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

int main() {
    string S;
    string T;
    int correct = 0;

    cin >> S >> T;

    for (int i=0;i<3;i++) {
        if (S[i]==T[i]){
            correct += 1;
        }
    }
    cout << correct << "\n";


    return 0;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
p = pow(10,9)+7

from functools import reduce
def comb(n,k,p):
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p

print((pow(2,n,p)-comb(n,a,p)-comb(n,b,p)-1)%p)

Measured memory_bytes: 71216
n = int(input())
p = list(map(int, input().split()))

q = sorted(p)

if p==q:
    print('YES')
    exit()

for i in range(n):
    for j in range(i+1,n):
        r = [x for x in p]
        r[i]=p[j]
        r[j]=p[i]
        if q==r:
            print('YES')
            exit()
print('NO')

Measured memory_bytes: 40048
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int field[11][11];
int land[20];
pair<int,int> place[20];

int w,h,n;
bool ok;

struct landInfo{
	int minx;
	int miny;
	int maxy;
	int maxx;
};

landInfo mem[20];
landInfo fin[20];

bool no=false;

void dfs(int num,int sum){
	if(no)
		return;
	if(num==n+1){
		if(sum==h*w){
			if(ok){
				no=true;
			}
			else{
				ok=true;
				for(int i = 1; i < num; i++){
					fin[i]=mem[i];
				}
			}
		}
		return;
	}
	else{
		// ßûð·×ÄµÄÝé
		for(int i = 1; i <= land[num]; i++){
			if(land[num]%i!=0)
				continue;
			int tate=i;
			int yoko=land[num]/i;
			// Ç±É»ÝÌynÌÔÌÊuðÁÄ­é©
			for(int j = 0; j < tate; j++){
				for(int k = 0; k < yoko; k++){
					// ÍÝoÄÈ¯êÎAßé
					int minx=place[num].second-k;
					int miny=place[num].first-j;
					int maxx=minx+yoko-1;
					int maxy=miny+tate-1;
					if(minx>=0&&miny>=0&&minx<w&&miny<h&&maxx>=0&&maxy>=0&&maxx<w&&maxy<h){
						// àµ¼ÌynÌÍÍÆðíÁÄ¢È¯êÎ
						vector<pair<int,int> > ps;
						ps.push_back(make_pair(miny,minx));
						ps.push_back(make_pair(miny,maxx));
						ps.push_back(make_pair(maxy,minx));
						ps.push_back(make_pair(maxy,maxx));

						bool f=false;
						for(int l = 1; l < num; l++){
							if((maxx<mem[l].minx||maxy<mem[l].miny)||(minx>mem[l].maxx||miny>mem[l].maxy)){

							}
							else{
								f=true;
								break;
							}
						}
						if(!f){
							landInfo li;
							li.minx=minx;
							li.maxx=maxx;
							li.miny=miny;
							li.maxy=maxy;
							mem[num]=li;
							dfs(num+1,sum+land[num]);
							if(no)
								return;
						}
					}
				}
			}
		}
	}
}

int main(){
	while(cin>>w>>h>>n&&!(w==0&&h==0&&n==0)){
		ok=false;
		no=false;
		int b,k;
		for(int i = 0; i < n; i++){
			cin>>b>>k;
			land[b]=k;
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				if(field[i][j]!=0){
					place[field[i][j]].first=i;
					place[field[i][j]].second=j;
				}
			}
		}
		// ÔÉynðßÄ¢­
		dfs(1,0);
		if(ok&&!no){
			for(int i = 1; i <= n; i++){ 
				for(int j = fin[i].miny; j <= fin[i].maxy; j++){
					for(int k = fin[i].minx; k <= fin[i].maxx; k++){
						field[j][k]=i;
					}
				}
			}
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					cout<<field[i][j];
					if(j!=w-1)
						cout<<" ";
				}
				cout<<endl;
			}
		}
		else
			cout<<"NA"<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <assert.h>
#include <stdlib.h>
using namespace std;

void smain();
int main() {
    ios_base::sync_with_stdio(0);
#ifdef TASK
    freopen(TASK".in","rt",stdin);
    const clock_t start = clock();
#endif
    smain();
#ifdef TASK
    cerr << "\nTotal Execution Time: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

#ifndef M_PI
#define M_PI 3.14159265358979311599796346854418516
#endif
#define forn(i,n) for (int i=0;i<n;i++)
#define rforn(i,n) for (int i=n-1;i>=0;i--)
#define LL long long
#define int long long
#define mp(a,b) make_pair(a,b)
#define INF 2305843009213693951LL
#define MOD 1000000007
#define EPS 1E-9
#define N 3002
/* --------- END TEMPLATE CODE --------- */

void smain() {
    string s;
    for (; cin >> s; ) {
        vector<int> cnt(26);
        for (auto c : s) cnt[c - 'A'] += 1;
        bool ok = true;
        if ((cnt['N' - 'A'] > 0 || cnt['S' - 'A'] > 0) && cnt['N' - 'A'] * cnt['S' - 'A'] == 0) ok = false;
        if ((cnt['W' - 'A'] > 0 || cnt['E' - 'A'] > 0) && cnt['W' - 'A'] * cnt['E' - 'A'] == 0) ok = false;
        cout << (ok ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[2][101];
int dp[2][101];
int main() {
    int n;
    cin >> n;
    for (int i=0;i<2;i++) {
        for (int j=0;j<n;j++) {
            cin >> a[i][j];
        }
    }
    dp[0][0] = a[0][0];
    for (int i=0;i<2;i++) {
        for (int j=0;j<n;j++) {
            if (i == 0) {
                dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a[i+1][j]);
            }
            if (j < n) {
                dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a[i][j+1]);
            }
        }
    }
    cout << dp[1][n-1] << endl;
}


Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

vector<pii> G[200010];
bool visited[200010];
int rec[200010];
int x, y;
int R, C, N;

void dfs(int p, int par=-1) {
    if(p < R) chmin(x, rec[p]);
    else chmin(y, rec[p]);

    for(auto e : G[p]) {
        int to = e.first, cost = e.second;
        if(par == to || visited[to]) continue;
        visited[to] = true;
        rec[to] = cost - rec[p];
        dfs(to, p);
    }
}

signed main() {
    cin >> R >> C >> N;

    rep(i,0,N) {
        int r, c, a; cin >> r >> c >> a;
        r--; c--;
        int u = r, v = R+c;
        G[u].push_back(pii(v, a));
        G[v].push_back(pii(u, a));
    }

    bool ng = false;
    int ans = INF;
    rep(i,0,R+C) {
        x = y = INF;
        dfs(i);
        chmin(ans, x+y);
    }
    rep(i,0,R+C) rep(j,0,G[i].size()) {
        int u = i, v = G[i][j].first;
        if(rec[u] + rec[v] != G[i][j].second) ng = true;
    }
    if(ans < 0) ng = true;

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

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }

  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  ll count = 0;

  rep(i, 1, N) {
    if (H[i - 1] >= H[i]) {
      count++;
    } else {
      count = 0;
    }
    chmax(ans, count);
  }

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

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int i, len = 0;
	char s1[21], s2[21];

	scanf("%s",s1);
	while(s1[len]){
		len++;
	}
	for (i = 0; i < len; i++){
		s2[i] = s1[len - 1 - i];
	}
	s2[i] = '\0';

	printf("%s\n", s2);

	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
int tbl[10][10];
string to_s(int n) {
  char number[6];
  sprintf(number, "%05lld", n);
  return string(number);
}
int check(const string &s) {
  int d = tbl[0][s[0] - '0'];
  d = tbl[d][s[1] - '0'];
  d = tbl[d][s[2] - '0'];
  d = tbl[d][s[3] - '0'];
  d = tbl[d][s[4] - '0'];
  return d == 0;
}
string make(int n) {
  char number[5];
  sprintf(number, "%04lld", n);
  string s = string(number);
  int d = tbl[0][s[0] - '0'];
  d = tbl[d][s[1] - '0'];
  d = tbl[d][s[2] - '0'];
  d = tbl[d][s[3] - '0'];
  s.push_back(d + '0');
  return s;
}
signed main() {
  ios::sync_with_stdio(false);
  REP(i,10) REP(j,10) cin >> tbl[i][j];
  int error = 0;
  REP(n,10000) {
    string s = make(n);
    if(!check(s)) continue;
    bool e = false;
    REP(i,5) REP(j,10) {
      string t = s;
      t[i] = '0' + j;
      if(t != s) {
        if(check(t)) {
          e = true;
          // DEBUG(s);
          // DEBUG(t);
        }
      }
    }
    REP(i,4) {
      string t = s;
      swap(t[i], t[i + 1]);
      if(t != s) {
        if(check(t)) {
          e = true;
          // DEBUG(s);
          // DEBUG(t);
        }
      }
    }
    if(e) {
      error++;
    }
  }
  cout << error << endl;
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll sum=0;
    ll n; cin >> n;
    vector<ll> num(n+1,0);
    rep(i,1,n+1){
        for(int j=i;j <= n; j+=i ) {
            num[j]++;
        }
    }
    rep(i,1,n+1) sum += i*num[i];
    cout << sum << endl;
}

Measured memory_bytes: 81316
#include"bits/stdc++.h"

using namespace std;

typedef long long LL;

int main() 
{
	string s;
	cin >> s;
	int Ans = 0;
	for (int i = 0; i < 6; i++)
	{
		if (s[i] == '1')
		{
			Ans++;
		}
	}
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 500000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
vi dp(1000,-1);
int f(int a){
	if(dp[a]+1)return dp[a];
	return dp[a]=powmod(fact[a],MOD-2,MOD);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	vs in(n);
	rep(i,n)cin>>in[i];
	vvi a,b;
	int c=0;
	rep(i,n){
		int s=0,mi=0;
		rep(j,in[i].size()){
			if(in[i][j]=='(')s++;
			else s--;
			cmin(mi,s);
		}
		if(s>0){
			a.pb({mi,s-mi});
		}else b.pb({s-mi,mi});
		c+=s;
	}
	if(c){
		no;
		return 0;
	}
	int s=0;
	sort(all(a));
	for(int i=a.size()-1;i>=0;i--){
		if(s+a[i][0]<0){
			no;
			return 0;
		}
		s+=a[i][0]+a[i][1];
	}
	sort(all(b));
	rep(i,b.size()){
		if(s+b[b.size()-1-i][1]<0){
			no;
			return 0;
		}
		s+=b[b.size()-1-i][1]+b[b.size()-1-i][0];
	}

	yes;
}


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

int main() {
    string S, T;
    cin >> S >> T;

    int64_t ans = LLONG_MAX;
    for (int64_t i = 0; i <= S.size() - T.size(); i++) {
        int64_t curr_ans = 0;
        for (int64_t j = 0; j < T.size(); j++) {
            if (T[j] != S[i + j]) {
                curr_ans++;
            }
        }
        ans = min(ans, curr_ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int l[100005];

int main() {
  int n;
  ll a, b;
  scanf("%d%lld%lld", &n, &a, &b);
  for(int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }
  ll ret = 0;
  for(int i = 0; i < n-1; i++) {
    ret += min(b, a * (l[i+1] - l[i]));
  }
  printf("%lld\n", ret);
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN=10005;

int n;
vector<int> v[MAXN];
int c[MAXN];
int ans=0;
int index=0;
int xans[MAXN];

bool cmp(int x,int y){
	return x>y;
}

void dfs(int no,int father){
	xans[no]=++index;
	for (int i=0;i<v[no].size();i++){
		int u=v[no][i];
		if (u!=father){
			dfs(u,no);
		}
	}
}
int main()

{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}

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

	sort(c+1,c+1+n,cmp);

	for (int i=2;i<=n;i++){
		ans+=c[i];
	}
	cout<<ans<<endl;

	dfs(1,-1);
	for (int i=1;i<=n;i++){
		cout<<c[xans[i]]<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
   ll n,a,b;
   cin >> n >> a >> b;
   ll ans;
   ans = n/(a+b);
   ll mod = n%(a+b);
   ans*= a;
   if (mod <= a) ans += mod;
   else ans += a;
   cout << ans << 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;
using ll = long long;
using P = pair<int, int>;

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

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int>> d(h, vector<int>(w, 0));
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '#') {
        rep(k, 8) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (0 <= nx && nx < h && 0 <= ny && ny < w) d[nx][ny]++;
        }
      }
    }
  }

  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '#') {
        cout << '#';
      } else {
        cout << d[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def func(a):
    for i in range(1, 10):
        for n in range(1, 10):
            if a == i * n:
                print("Yes")
                return
    print("No")


# for i in range(1, 101):
#     print("{0}:".format(i), end="")
i = int(input())
func(i)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,winner,max=0,a,v;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>a>>v;
        if (v>max) {
            winner=a;
            max=v;
        } else if (v==max) {
            if (a<winner) {
                winner=a;
            }
        }
    }
    cout<<winner<<" "<<max<<endl;
}



Measured memory_bytes: 3104
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  for(i=0;i<d;i++){
    ans1[i]=randxor()%26;
  }
  if(score<keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=i%26;
    ans[i]=ans1[i];
  }
  score=keisan();
  while(clock()-ti<197.4*CLOCKS_PER_SEC/100){
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3920
object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  val name = readLine.trim
  val kanban = Array.tabulate(n){_ ⇒ readLine.trim}

  println((for (k ← kanban) yield {
    (for (i ← 1 to (k.length - 1) / (name.length - 1)) yield {
      (for (j ← 0 until k.length - i * (name.length - 1)) yield {
        name.zipWithIndex.forall{case (c, idx) ⇒ k(i * idx + j) == c}
      }).exists(f ⇒ f)
    }).exists(f ⇒ f)
  }).count(f ⇒ f))
  implicit class ScopeFunc[T](val value: T) {
    def let[A](func: T ⇒ A): A = func(value)

    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

/*
 */


Measured memory_bytes: 145928
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      String str = sc.next();
      String first = str.substring(0,k-1);
      String x = str.substring(k-1,k);
      String last = str.substring(k,n);
      x = x.toLowerCase();
      System.out.println(first + x + last);
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <numeric> 
#include <bits/stdc++.h>
typedef long long ll;
typedef std::pair<std::pair<int,int>,int>pi;
using namespace std;

int main() {
    int n,m; cin >> n >>m;
    vector<int>v(m);
    int total = 0;
    for(int i = 0; i < m; i++){
        cin >> v[i]; 
        total += v[i];
    }
    if(total > n) cout << -1 << endl;
    else cout << n - total << endl;
}



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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int main()
{
    _upgrade
    string s; cin >> s;
    for(auto c: s)
    {
        if(c == '9')
        {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}


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

int q[2000010],l,r,d[2000010],x,y,z,n,f[100010][17],dep[100010],fa[100010],hd[100010],cnt,L[100010],R[100010],Fa[100010];
struct node{int to,next;}e[200010];
vector<int> t[100010],v[2000010];

void getdfn(int x,int fa)
{
	L[x]=(++cnt),Fa[x]=fa;
	for (int i=0,sz=t[x].size(); i<sz; i++)
		if (t[x][i]!=fa) getdfn(t[x][i],x);
	R[x]=cnt;
}

void getdep(int x)
{
	dep[x]=dep[fa[x]]+1;
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=fa[x]) fa[e[i].to]=x,getdep(e[i].to);
}

int lca(int x,int y)
{
	if (dep[x]<dep[y]) swap(x,y);
	for (int j=16; j>=0; j--)
		if (dep[f[x][j]]>=dep[y]) x=f[x][j];
	if (x==y) return x;
	for (int j=16; j>=0; j--)
		if (f[x][j]!=f[y][j]) x=f[x][j],y=f[y][j];
	return f[x][0];
}

int calc(int x,int y) {return y*(n+1)+x;}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<n; i++) 
	{
		scanf("%d%d",&x,&y);
		e[++cnt]=(node){y,hd[x]},hd[x]=cnt;
		e[++cnt]=(node){x,hd[y]},hd[y]=cnt;
	}
	for (int i=1; i<n; i++) 
	{
		scanf("%d%d",&x,&y);
		t[x].push_back(y);
		t[y].push_back(x);
	}
	cnt=fa[1]=0,getdfn(1,0),getdep(1);
	for (int i=1; i<=n; i++) f[i][0]=fa[i];
	for (int j=1; j<=16; j++)
		for (int i=0; i<=n; i++)
			f[i][j]=f[f[i][j-1]][j-1],v[calc(i,j)].push_back(calc(i,j-1)),v[calc(i,j)].push_back(calc(f[i][j-1],j-1));
	cnt=calc(n,16);
	for (int i=2; i<=n; i++)
	{
		x=i,y=Fa[i],z=lca(x,y);
		if (L[z]>=L[i]&&L[z]<=R[i]) 
		{
			for (int j=16; j>=0; j--)
				if (dep[f[y][j]]>=dep[z]&&(L[f[y][j]]<L[i]||L[f[y][j]]>R[i])) y=f[y][j];
			int p=y; y=Fa[i];
			for (int j=16; j>=0; j--)
				if (dep[f[y][j]]>=dep[p]) v[calc(p,0)].push_back(calc(y,j)),y=f[y][j];
			y=f[y][0];
			for (int j=16; j>=0; j--)
				if (dep[f[y][j]]>=dep[z]) v[calc(p,0)].push_back(calc(y,j)),y=f[y][j];
			for (int j=16; j>=0; j--)
				if (dep[f[x][j]]>=dep[z]) v[calc(p,0)].push_back(calc(x,j)),x=f[x][j];
		} else
		{
			for (int j=16; j>=0; j--)
				if (dep[f[x][j]]>=dep[z]&&L[f[x][j]]>=L[i]&&L[f[x][j]]<=R[i]) x=f[x][j];
			int p=x; x=i;
			for (int j=16; j>=0; j--)
				if (dep[f[x][j]]>=dep[p]) v[calc(p,0)].push_back(calc(x,j)),x=f[x][j];
			x=f[x][0];
			for (int j=16; j>=0; j--)
				if (dep[f[x][j]]>=dep[z]) v[calc(p,0)].push_back(calc(x,j)),x=f[x][j];
			for (int j=16; j>=0; j--)
				if (dep[f[y][j]]>=dep[z]) v[calc(p,0)].push_back(calc(y,j)),y=f[y][j];
		}
	}
	for (int i=0; i<=cnt; i++)
		for (int j=0,sz=v[i].size(); j<sz; j++) d[v[i][j]]++;
	l=1,r=0;
	for (int i=0; i<=cnt; i++) if (!d[i]) q[++r]=i;
	while (l<=r)
	{
		x=q[l++];
		for (int i=0,sz=v[x].size(); i<sz; i++)
			if (!(--d[v[x][i]])) q[++r]=v[x][i];
	}
	if (r==cnt+1) puts("YES"); else puts("NO");
	return 0;
}

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

int N;

void solve(){
  int a, count = 0;
  for (int i = 0; i < 8; ++i){
    a = pow(10, i);
    count += N / a % 10;
  }
  if (N % count == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

int main() {
  cin >> N;
  solve();
  return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	string a,b;
	cin>>a;
	for(int i=0;i<(int)a.length();i++) {
		if((i&1)==0)b+=a[i];
	}
	cout<<b;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

N, Q = map(int, input().split())
S = input().rstrip()
TD = [list(map(str, input().split())) for _ in range(Q)]

l = 0
r = N
while r - l > 1:
    m = (l+r)//2
    right_over = False
    pl = m
    for t, d in TD:
        if S[pl] == t:
            if d == 'L':
                pl -= 1
                if pl == -1:
                    break
            else:
                pl += 1
                if pl == N:
                    right_over = True
                    break
    if right_over:
        r = m
    else:
        l = m

right = l

l = 0
r = N
while r - l > 1:
    m = (l+r)//2
    left_over = False
    pl = m
    for t, d in TD:
        if S[pl] == t:
            if d == 'L':
                pl -= 1
                if pl == -1:
                    left_over = True
                    break
            else:
                pl += 1
                if pl == N:
                    break
    if left_over:
        l = m
    else:
        r = m

left = l

print(right-left)

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int cake_num[3];
VVL cake(3);
set<ll> visited_set;
ll cake_sum(ll index) {
    ll res = 0;
    REP(i, 3) {
        res += cake[i][index % 1000];
        index /= 1000;
    }
    return res;
}

VL next_indeces(ll index) {
    VL res;
    ll temp_index = index;
    REP(i, 3) {
        if(temp_index % 1000 < cake_num[i] - 1) 
            res.push_back(index + (ll)pow(1000, i));
        temp_index /= 1000;
    }
    return res;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    REP(i, 3) {
        cin >> cake_num[i];
        cake[i].resize(cake_num[i]);
    }
    cin >> k;
    REP(i, 3)REP(j, cake_num[i]) cin >> cake[i][j];
    REP(i, 3) sort(ALL(cake[i]), greater<ll>());

    priority_queue<PL> ans;
    ll index = 0;
    ans.push(PL(cake_sum(index), index));
    visited_set.insert(index);
    REP(i, k) {
        for(auto next_index : next_indeces(index)) {
            if(visited_set.count(next_index) > 0) continue;
            ans.push(PL(cake_sum(next_index), next_index));
            visited_set.insert(next_index);
        }
        cout << ans.top().first << ln;
        index = ans.top().second;
        ans.pop();
    }
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
using namespace std;

typedef long long li;

// const int mod = 1e9 + 7, inv2 = mod + 1 >> 1;
// inline int Add(int x) { return x >= mod ? x - mod : x; }
// inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
// inline int Sub(int x) { return x < 0 ? x + mod : x; }
// inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
// inline int Mul(int x, int y) { return (li)x * y % mod; }

// int Pow(int x, int y) {
//   int z = 1;
//   for (; y; y >>= 1) {
//     if (y & 1) z = Mul(z, x);
//     x = Mul(x, x);
//   }
//   return z;
// }

// ----------------------------------------

const int maxn = 5000;

int n;
char s[maxn + 1], t[maxn + 1];
vector<int> a, b;

int Get(vector<int> &a, int i) {
  if (i < 0) return 0;
  if (i >= a.size()) return n;
  return a[i];
}

int main(void) {
  scanf("%d%s%s", &n, s, t);
  for (int i = 0; i < n - 1; ++i) if (s[i] != s[i + 1]) a.push_back(i + 1);
  for (int i = 0; i < n - 1; ++i) if (t[i] != t[i + 1]) b.push_back(i + 1);
  int best = 1e9;
  int odd = (s[0] != t[0]);
  for (int d = -n; d <= n; ++d) {
    if (odd + d & 1) continue;
    int ans = 0;
    for (int i = -n; i < 2 * n; ++i) {
      ans += abs(Get(a, i) - Get(b, i + d));
    }
    best = min(best, ans);
  }
  printf("%d\n", best);
  return 0;
}


Measured memory_bytes: 384
'use strict'

const main = (input) => {
    const num = input.split('\n')[0]
    const nums = num.split('')

    if([...new Set(nums)].length === 1){
        console.log(num)
        return;
    }

    const a = nums.shift()
    const as = a + a + a
    if(num < as){
        console.log(as)
    } else {
        const b = (parseInt(a) + 1).toString()
        const bs = b + b + b
        console.log(bs)
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 11468
N = int(input())
L = []
for i in range(N):
    l = list(map(str, input().split()))
    l[1] = int(l[1])
    l.append(i+1)
    L.append(l)
L = sorted(L, key=lambda x:(x[0],-x[1]) )
#L = sorted(L, key=lambda x:x[1], reverse=True)
for i in range(N):
    a = L[i][2]
    print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

int main(){
  int n,C;
  int imos[100005]={0};
  
  cin>>n>>C;
  rep(i,n){
    int s,t,c;
    cin>>s>>t>>c;
    imos[s]++;
    imos[t+1]--;
  }
  REP(i,1,100005)imos[i]+=imos[i-1];
  int ans=0;
  rep(i,100005)ans=max(ans,imos[i]);
  cout<<min(ans,C)<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main() {
	int a, b;
	bool input[3] = { false };
	cin >> a >> b;
	input[a - 1] = true;
	input[b - 1] = true;
	for (int i = 0; i < 3; i++) {
		if (!input[i]) {
			cout << (i + 1) << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

query = []

for _ in range(Q):
    t, d = input().split()
    query.append((t, d))

def isDropLeft(i):
    now = i

    for t, d in query:
        if S[now] == t:
            if d == 'L':
                now -= 1
            else:
                now += 1
        if now < 0:
            return True
        if now >= N:
            return False
    return False

def isDropRight(i):
    now = i

    for t, d in query:
        if S[now] == t:
            if d == 'L':
                now -= 1
            else:
                now += 1
        if now < 0:
            return False
        if now >= N:
            return True
    return False

okLeft = -1
ngLeft = N

while ngLeft - okLeft > 1:
    mid = (okLeft + ngLeft) // 2
    if isDropLeft(mid):
        okLeft = mid
    else:
        ngLeft = mid

okRight = N
ngRight = -1

while okRight - ngRight > 1:
    mid = (okRight + ngRight) // 2
    if isDropRight(mid):
        okRight = mid
    else:
        ngRight = mid

ans = N - ((okLeft + 1) + (N - okRight))
print(ans)

Measured memory_bytes: 19656
def resolve():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    u = [[] for _ in range(n)]
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        u[a].append(b)
        u[b].append(a)
    ans = 0
    for i in range(n):
        if u[i] == [] or h[i] > max([h[x] for x in set(u[i])]):
            ans += 1
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 32016
#include <cstdio>
#include <vector>
using namespace std;

const int SIZE = 100000;
int n, k, c;
vector<int> ch[SIZE];
int par[SIZE], depth[SIZE];

void dfs(int id) {
	if (ch[id].empty()) return;
	for (int i = 0;i < ch[id].size();i++) {
		depth[ch[id][i]] = depth[id] + 1;
		dfs(ch[id][i]);
	}
}

int main() {
	int id, root;
	bool list;

	scanf("%d", &n);
	for (int i = 0;i < n;i++) {
		par[i] = -1;
		depth[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &id, &k);
		for (int i = 0;i < k;i++) {
			scanf("%d", &c);
			ch[id].push_back(c);
			par[c] = id;
		}
	}

	for (int i = 0;i < n;i++) {
		if (par[i] == -1) {
			dfs(i);
			break;
		}
	}

	for (int i = 0;i < n;i++) {
		list = false;
		printf("node %d: parent = %d, depth = %d, ", i, par[i], depth[i]);
		if (par[i] == -1) {
			printf("root, [");
			list = true;
		}
		else if (ch[i].empty()) {
			printf("leaf, []");
		}
		else {
			printf("internal node, [");
			list = true;
		}
		if (list) {
			if (ch[i].empty()) printf("]");
			for (int j = 0;j < ch[i].size();j++) {
				printf("%d", ch[i][j]);
				if (j + 1 == ch[i].size()) {
					printf("]");
				}
				else {
					printf(", ");
				}
			}
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 4960
import Data.Bool
import Data.List

main=getLine>>=putStrLn.bool"NO""YES".isK

keyence :: String
keyence = "keyence"

isK :: String -> Bool
isK cs = or $ do
    (k0, k1) <- zip (inits keyence) (tails keyence)
    return $ k0 `isPrefixOf` cs && k1 `isSuffixOf` cs


Measured memory_bytes: 380
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

double a,b,c,d,e,f,g,h;

int main() {
	while(cin>>a>>b>>c>>d>>e>>f>>g>>h){
		if(c<e){cout<<"NO"<<endl;continue;}
		if(g<a){cout<<"NO"<<endl;continue;}
		if(d<f){cout<<"NO"<<endl;continue;}
		if(h<b){cout<<"NO"<<endl;continue;}
		cout<<"YES"<<endl;
	}
	return 0;
}

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

int main() {
    int n, q;
    std::string s;
    std::cin >> n >> q >> s;

    int counts[n]; // 累積和

    for (int i = 0; i < n; i++) {
        char current = s[i];
        char before;
        int count = 0;

        if (i == 0) {
            count = 0;
            before == '/0';
        } else {
            count = counts[i - 1];
            before = s[i - 1];
        }

        if (current == 'C' && i != 0 && before == 'A') {
            count++;
        }

        counts[i] = count;
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        std::cin >> l >> r;
        std::cout << counts[r - 1] - counts[l - 1] << std::endl;
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W, 0));
  REP(i, H) REP(j, W) cin >> A[i][j];
  while (true) {
    bool t = true;
    //縦
    REP(i, A[0].size()) {
      bool ok = true;
      REP(j, A.size()) {
        if (A[j][i] == '#') ok = false;
      }
      if (ok) {
        t = false;
        REP(j, A.size()) { A[j].erase(A[j].begin() + i); }
      }
    }
    //横
    REP(i, A.size()) {
      bool ok = true;
      REP(j, A[0].size()) {
        if (A[i][j] == '#') ok = false;
      }
      if(ok){
        t = false;
        A.erase(A.begin()+i);
      }
    }
    if (t) break;
  }
  REP(i,A.size()){
    REP(j, A[i].size()) { cout << A[i][j];
    }
    cout << endl;
  }
}

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

bai2 = 0
bai4 = 0
bai1 = 0

for i in range(n):
    if a[i] % 4 == 0:
        bai4 += 1
    elif a[i] % 2 == 0:
        bai2 = 1
    else:
        bai1 += 1

if bai1 == 0:
    print('Yes')
    exit()
        
if (bai4+1) >= (bai2 + bai1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252