akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, K;
        public int[] A;

        public void Run()
        {
            // input
            {
                var line = Input.ReadIntArray();
                N = line[0];
                K = line[1];
            }

            {
                A = Input.ReadIntArray();
            }

            // position of 1
            int p1 = 0;
            for(int i = 0; i < N; i++)
                if (A[i] == 1)
                    p1 = i;
            
            // left, right of p1
            int left = p1;
            int right = (N - 1) - p1;

            int ret = int.MaxValue;
            for (int i = 0; i <= K - 1; i++)
            {
                int l = left - i;
                int r = right - (K - 1 - i);
                if (l >= 0 && r >= 0)
                {
                    int _ret = Count(l, K - 1) + Count(r, K - 1) + 1;
                    ret = Math.Min(ret, _ret);
                }
            }

            Console.WriteLine(ret);
        }

        public int Count(int x, int a)
        {
            return (x + a - 1) / a;
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 19936
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
int main(){
    cout << fixed << setprecision(10);
    int h,w;
    cin >> h >> w;
    vector<vector<int>> dp(h+10,vector<int>(h+10, inf));
    string s[h];
    rep(i,h) cin >> s[i];
    if(s[0][0] == '.') dp[0][0] = 0;
    else dp[0][0] = 1;
    rep(i,h){
        rep(j,w){
            rep(k,2){
                int dx[] = {1, 0};
                int dy[] = {0, 1};
                int ni = i + dx[k], nj = j + dy[k];
                if(ni >= h || nj >= w) continue;
                if(s[ni][nj] == '#' && s[i][j] == '.') chmin(dp[ni][nj], dp[i][j] + 1);
                else chmin(dp[ni][nj], dp[i][j]);
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}


Measured memory_bytes: 3700
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main() 
{
	int ans=1;
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		ans+=min(ans,k);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n,i,c=0;
  scanf("%d",&n);

  int p[n];
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);

  for(i=0;i<n;i++)
    if(p[i]!=i+1)
      c++;

  if(c<=2)
    printf("YES\n");

  else
    printf("NO\n");

  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, K: int):
    g = [[1] * N for _ in range(N)]
    for i in range(N):
        g[i][i] = 0

    k = K
    for i in range(N):
        if k == 0:
            break
        for j in range(N - 1):
            if j <= i:
                continue

            g[i][j] = 0
            g[j][i] = 0
            k -= 1
            if k == 0:
                break

    if 0 < k:
        return '-1'

    ret = []
    for i in range(N):
        for j in range(N):
            if j <= i:
                continue

            if g[i][j] != 0:
                ret.append('{} {}'.format(i+1, j+1))
    ret = [str(len(ret))] + ret
    return '\n'.join(ret)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(N, K)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


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

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vector<ii> > vvii;
typedef long long ll;

int main(){
    
    ll r = 0;
    int n;
    cin >> n;
    if(n == 1){
    	cout << 1 << endl;
    } else {
	    ll a = 2;
	    ll b = 1;
	    for(int i = 0; i < n - 1; i++){
	    	r = a + b;
	    	a = b;
	    	b = r;
	    }
	    cout << r << 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;
typedef long long ll;

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

    string o, e;
    cin >> o >> e;

    rep(i, e.length()){
        cout << o[i];
        cout << e[i];
    }
    if(o.length()>e.length()) cout << o[o.length()-1];

    cout << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()
	K := nextInt()
	count := 0
	for i := 0; i < N; i++ {
		h := nextInt()
		if h >= K {
			count += 1
		}
	}
	fmt.Printf("%d\n", count)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

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

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

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

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


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
  int A, B, K, num=100;
  std::cin >> A >> B >> K;
  while(K > 0){
    if(A%num == 0 && B%num == 0){
      K--;
      num--;
    }else num--;
  }
  std::cout << num + 1<< '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String args []){
        Scanner sc = new Scanner (System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();
        boolean check = false;
        if(A-K>0){
            A-=K;
            check = true;
        }
        else{
            K-=A;
            A=0;
        }
        if(!check&&B-K>0) B-=K;
        else if(!check) B=0;
        System.out.println(A+" "+B);
    }
}

Measured memory_bytes: 21844
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


int main() {
    int t, x;
    cin >> t >> x;
    cout << double(t) / x << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            int W = input[0];
            int H = input[1];
            int x = input[2];
            int y = input[3];
            // 面積の最大値は半分
            double area = (double)W * (double)H / 2;
            // 長方形の中点が整数で存在する、かつx, yが中点の時
            int isMultiple = 0;
            if (x + x == W && y + y == H)
            {
                isMultiple = 1;
            } else
            {
                isMultiple = 0;
            }
            Console.WriteLine($"{area:0.000000000} {isMultiple}");
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
using namespace std;
int N;
const int n=1e9+7;
int main() {
    cin >> N;
    long long ans=1;
    for(int i=1; i<=N; ++i){
        ans*=i;
        ans%=n;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc106c()
}

fun abc106c() {
    val s = readLine()!!
    val k = readLine()!!.toLong()

    val notOneString = s.findAnyOf((2..9).map { it.toString() })

    val answer = if (notOneString == null || notOneString.first >= k) {
        "1"
    } else {
        notOneString.second
    }

    println(answer)
}


Measured memory_bytes: 33784
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
L.insert(0, [0,0,0])

cnt = 0

for l in range(len(L)-1):
    length = abs(L[l+1][1] - L[l][1]) + abs(L[l+1][2] - L[l][2]) - abs(L[l+1][0] - L[l][0]) 
    if not (length <= 0 and length % 2 == 0):
        print("No")
        break
    else:
        cnt += 1

if cnt == len(L) - 1:
    print("Yes")

Measured memory_bytes: 27300
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mkp make_pair
#define mod 1000000007
#define F first
#define S second
#define ld long double
#define f(i,l,f,n) for(i=(l); i<(n) && !(f); i++)
#define endl "\n"

ll countt[101][100001], wt[100001], val[100001];

ll dp(int pos, int w)
{
    //cout<<pos<<" ";
    if(pos<0)
    return 0;
    else if(countt[pos][w]!=-1)
    return countt[pos][w];
    else if(w>=wt[pos])
    {
        countt[pos][w] = max(val[pos]+dp(pos-1, w-wt[pos]), dp(pos-1, w));
    }
    else
    countt[pos][w] = dp(pos-1, w);
    return countt[pos][w];
}

void solve()
{
    int i, j, k, n, w;
    cin>>n>>w;
    f(i,0,0,n)
    cin>>wt[i]>>val[i];
    memset(countt, -1, sizeof(countt));
    cout<<dp(n-1, w);
    // cout<<endl;
    // f(i,0,0,n)
    // cout<<countt[i][w]<<" ";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1, i=0;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<i++<<": "<<solve()<<endl;
        solve();
    }
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;

string ss[] = { "dream", "dreamer", "erase", "eraser" };
int main() {
#ifdef HIRO
  string file_path(QUIZ);
  ifstream cin(file_path + "/input.txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  // int n;
  // int m;
  // cin >> n;
  // cin >> m;
  string str;
  cin >> str;
  reverse(str.begin(), str.end());
  for(string& s: ss)
    reverse(s.begin(), s.end());
  // cout << "xx" << endl;
  for(int i = 0; i < str.size();) {
    bool can = false;
    for(string s: ss) {
      // cout << s << endl;
      // cout << str.substr(i, s.size()) << endl;
      if(str.substr(i, s.size()) == s) {
        i += s.size();
        can = true;
      }
    }
    if(!can) {
      cout << "NO";
      return 0;
    }
  }

  cout << "YES";
  // cout << ans << endl;
  return 0;
}



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

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  for (auto &it : A)
    cin >> it;
  map<ll, ll> mp;
  ll ans = 0;
  ll total = 0;
  for (int i = 0; i < N; i++)
  {
    mp[total]++;
    total += A[i];
    total %= M;
    ans += mp[total];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7844
package main

/*
線形探索
*/

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

func find(i int, arr []int) bool {
	for _, e := range arr {
		if i == e {
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	eGetInt(scanner)
	s := eGetInts(scanner)
	eGetInt(scanner)
	t := eGetInts(scanner)
	c := 0
	for _, et := range t {
		if find(et, s) {
			c++
		}
	}
	fmt.Println(c)
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	var ints []int
	for _, f := range fields {
		ints = append(ints, eAtoi(f))
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = " "
	}
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}



Measured memory_bytes: 1820
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;
typedef unsigned long long ull;

struct sort_cand
{
  bool operator()(const pair<ull,ull> &lhs, const pair<ull,ull> &rhs) {
    if (lhs.first == rhs.first) {
      return lhs.second > rhs.second;
    }
    else {
      return lhs.first < rhs.first;
    }
  }
};

void create_candidates(vector<ull>& v, vector<ull>& w, int lb, int ub, vector< pair<ull, ull> >& cand_vec) {
  if (lb > ub) {
    cand_vec.push_back(make_pair(0, 0));
    return;
  }

  int bits = ub - lb + 1;
  vector< pair<ull, ull> > tmp_cand;
  for (int i = 0; i < (1<<bits); ++i) {
    ull sv=0, sw=0;
    for (int j = 0; j < bits; ++j) {
      if (i & (1<<j)) {
        sv += v[lb+j];
        sw += w[lb+j];
      }
    }
    tmp_cand.push_back(make_pair(sw, sv));
  }

  sort(tmp_cand.begin(), tmp_cand.end(), sort_cand());

  int cand_idx = 0;
  cand_vec.push_back(tmp_cand[0]);
  for (int i = 1; i < (1<<bits); ++i) {
    if (cand_vec[cand_idx].second < tmp_cand[i].second) {
      cand_vec.push_back(tmp_cand[i]);
      cand_idx++;
    }
  }
}

int main() {
  ull N,W;
  vector<ull> v, w;
  cin>>N>>W;
  for (int i = 0; i < N; ++i) {
    ull vv, ww;
    cin>>vv>>ww;
    v.push_back(vv);
    w.push_back(ww);
  }

  int splt = N/2;
  vector< pair<ull, ull> > form_cand;
  create_candidates(v, w, 0, splt, form_cand);

  vector< pair<ull, ull> > latt_cand;
  create_candidates(v, w, splt+1, N-1, latt_cand);

  ull ans = 0;
  ull INF = ULLONG_MAX;
  for (int i = 0; i<form_cand.size(); ++i) {
    ull tmp_w = form_cand[i].first;
    ull tmp_v = form_cand[i].second;
    if (tmp_w <= W) {
      ull opt_latt = (lower_bound(latt_cand.begin(), latt_cand.end(), make_pair(W-tmp_w, INF))-1)->second;
      ans = max(ans, tmp_v+opt_latt);
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

int main(){
  int a,b;
  cin >>a >>b;
  if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << 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:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
from collections import defaultdict

n = int(input())
as_ = list(map(int, input().strip().split()))

numbers = defaultdict(int)
for a in as_:
    numbers[a] += 1

total = sum([m * (m - 1) // 2 for m in numbers.values()])

for k in range(1, n + 1):
    m_k = as_[k - 1]
    num_k = numbers[m_k]
    ans = total
    if num_k > 1:
        ans += - num_k * (num_k - 1) // 2 \
               + (num_k - 1) * (num_k - 2) // 2

    print(ans)


Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
int main () {
	int a,b;
	cin >> a >> b;
	int tmp = b-a;
	int sum = 0;
	for (int i = 0; i < tmp; ++i)
	{
		sum += i;
	}
	cout << sum - a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<b){
    printf("a < b\n");
  }
  else if(a>b){
    printf("a > b\n");
  }
  else if(a==b){
    printf("a == b\n");
  }
     return 0;
}

Measured memory_bytes: 2596
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M,C;
    cin >> N >> M >> C;
    vector<int>B(M);
    for(int i = 0; i < M; i++) {
        cin >> B[i];
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int res = 0;
        for(int j = 0; j < M; j++) {
            int A;
            cin >> A;
            res += A*B[j];
        }
        res += C;
        if(res > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3576
import java.util.*;
//System.out.println("")

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n = sc.next(); 
        if(n.contains("9")) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
p = p[len(p)-x:]
q.sort()
q = q[len(q)-y:]
r.extend(q)
r.extend(p)
r.sort()

print(sum(r[len(r)-(x+y):]))

Measured memory_bytes: 23540
import java.io.*;
import java.util.*;
import java.lang.*;
 class Main{
  public static void main(String args[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    Point p1 = new Point(0.0, 0.0);
    Point p2 = new Point(100.0, 0.0);
    System.out.printf("%.8s %.8s\n",p1.x,p1.y);
    koch(n, p1, p2);
    System.out.printf("%.8s %.8s\n",p2.x,p2.y);
  }
  static void koch(int d, Point p1, Point p2){
    if(d==0)return;
    double rad = 60*Math.PI/180.0;//Math.toRadians(60);
    Point s = new Point((2.0*p1.x+1.0*p2.x)/3.0, (2.0*p1.y+1.0*p2.y)/3.0);
    Point t = new Point((1.0*p1.x+2.0*p2.x)/3.0,(1.0*p1.y+2.0*p2.y)/3.0);
    Point u = new Point((t.x-s.x)*Math.cos(rad)-(t.y-s.y)*Math.sin(rad)+s.x, (t.x-s.x)*Math.sin(rad)+(t.y-s.y)*Math.cos(rad)+s.y);
    koch(d-1, p1, s);
    System.out.printf("%.8s %.8s\n",s.x,s.y);
    koch(d-1, s, u);
    System.out.printf("%.8s %.8s\n",u.x,u.y);
    koch(d-1, u, t);
    System.out.printf("%.8s %.8s\n",t.x,t.y);
    koch(d-1, t, p2);
  }
}

class Point{
  double x = 0.0;
  double y = 0.0;
  Point(double x, double y){
    this.x = x;
    this.y = y;
  }
  Point(){
    this.x = 0.0;
    this.y = 0.0;
  }
}


Measured memory_bytes: 39656
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main(){
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	puts(s<t? "Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c;cin>>a>>b>>c;
  if(a <= c && c <= b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        while (scanner.hasNext()) {
            int n =scanner.nextInt();
            int result = 0;
            boolean[] prime = new boolean[n+1];
            
            for (int i = 2; i < n+1; i++) {
                prime[i] = true;
            }
            
            for (int i = 2; i < n+1; i++) {
                if (prime[i]) {
                    result++;
                    for (int j = i+i; j < n+1; j += i) {
                        prime[j] = false;
                    }
                }
            }
            System.out.println(result);
        }
    }
}

Measured memory_bytes: 35616
#include<stdio.h>
int main(){
    int k;
    scanf("%d",&k);

    int a,b;
    scanf("%d %d",&a,&b);

    for(int i=a;i<=b;i++){
        if((i % k) == 0){
            printf("OK\n");
            break;
        }
        if(i == b)printf("NG\n");
    }

    return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
  {
    cin >> A[i];
    A[i]--;
  }
  vector<vector<i64>> to(60, vector<i64>(N));
  for (i64 i = 0; i < N; i++)
    to[0][i] = A[i];
  for (i64 i = 0; i < 59; i++)
    for (i64 j = 0; j < N; j++)
      to[i + 1][j] = to[i][to[i][j]];
  i64 ans = 0;
  for (i64 i = 0; i < 60; i++)
    if (K & (1LL << i))
      ans = to[i][ans];
  cout << ans + 1 << endl;
  return 0;
}


Measured memory_bytes: 100156
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <memory.h>
using namespace std;
typedef long long LL;

struct edge
{
	int from, to;
	LL w;
};

const int N = 1001;

vector<int> G[N];
LL d[N];

vector<edge> E;

void add_edge(int from, int to, int w)
{
	G[from].push_back((int)E.size());
	E.push_back({from, to, w});
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n, m, a, b;
	LL c;
	cin >> n >> m;

	for (int i = 1; i <= n; ++i)
		d[i] = -1000000000000000000;
	d[1] = 0;

	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b >> c;
		add_edge(a, b, c);
	}
	
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < E.size(); ++j)
			d[E[j].to] = max(d[E[j].to], d[E[j].from] + E[j].w);
	
	LL res = d[n];

	for (int j = 0; j < E.size(); ++j)
			d[E[j].to] = max(d[E[j].to], d[E[j].from] + E[j].w);

	if (d[n] <= res)
		cout << res << '\n';
	else
		cout << "inf\n";
}

Measured memory_bytes: 384
N,K = map(int,input().split())
A = [0 for _ in range(N)]
d = [0 for _ in range(K)]

for i in range(K):
    d[i] = int(input())
    temp = list(map(int,input().split()))
    for j in temp:
        A[j-1] += 1
   
ans=0     
for i in A:
    if i==0:
        ans+=1
print(ans)

Measured memory_bytes: 9156
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<bitset>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

int main(){
  string s;
  while(true){
    cin >> s;
    if(s == "0")return 0;
    int ans = 0;
    for(int i=0; i < s.size(); i++){
      ans += s[i] - '0';
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3172
import sys
input = sys.stdin.readline
sys.setrecursionlimit(int(1E+7))
def main():
    N, Q = map(int, input().split())
    link = [[] for _ in range(N+1)]
    for n in range(N-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    V = [0] * (N+1)
    ans = [0] * (N+1)
    for q in range(Q):
        p, x = map(int, input().split())
        V[p] += x

    def dfs(i, parent, acc):
        V[i] += acc
        for j in link[i]:
            if j != parent:
                dfs(j,i,V[i])
    cur = 1
    parent = 0
    acc = 0
    dfs(cur, parent , acc)
    V = [str(v) for v in V]
    print (" ".join(V[1:]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 280752
#include <stdio.h>

int main(){
  int a,b,i,min,max,temp;
  scanf("%d %d",&a,&b);
  if(a > b){
    min = b;
    max = a;
  }else{
    min = a;
    max = b;
  }

  while(1){
    if(max%min == 0)break;
    temp = min;
    min = max%min;
    max = temp;
  }
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
int main(){
    int a,b;
    int i=0;
    while(i==0){
            cin>>a>>b;
            int l=0;
            if(a==0&&b==0)break;
            for(int i=b-3;i>0;i-=1){
                for(int j=b-3;j>0;j-=1){
                    for(int k=b-3;k>0;k-=1){
                    int m;
                    if(i+j+k==b){
                      if(i==j||j==k||i==k||a<i||a<j||a<k){
                        m+=1;
                    }  
                    else {l+=1;
                    }
                  }
               }
            }
         }
           cout<<l/6<<endl;
         }
         return 0;
}
                  


Measured memory_bytes: 3076
import math
s=int(input())
def sosuuukana(x):
    y=int(math.sqrt(x))
    f=0
    for i in range(2,y+1):
        if x%i==0:
            f=f+1
            break
    return f
while sosuuukana(s)>0:
    s=s+1
else:
    print(s)

Measured memory_bytes: 9072
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
char S[100005];
bool check(int t){
	int k=t-1;
	while(k>=0&&S[k]==S[k-1])k--;
	return strlen(S)-k>=t;
}
int main(){
	scanf("%s",S);
	int l=1,r=strlen(S)+1;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid))l=mid+1;
		else r=mid;
	}
	printf("%d\n",r-1);
	return 0;
}

Measured memory_bytes: 384
while line = gets
    x1, y1, x2, y2, x3, y3, xp, yp = line.split.map(&:to_f)
    
    z1 = (x3 - x2) * (yp - y2) - (y3 - y2) * (xp - x2)
    z2 = (x1 - x3) * (yp - y3) - (y1 - y3) * (xp - x3)
    z3 = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
 
    if (z1 > 0 && z2 > 0 && z3 > 0) || (z1 < 0 && z2 < 0 && z3 < 0) then
        puts 'YES'
    else
        puts 'NO'
    end
end

Measured memory_bytes: 8624
H1,M1,H2,M2,K = map(int,input().split())

def hourToMinute(H,M):
  ret = H*60 +M  
  return ret

start = hourToMinute(H1,M1)
fin = hourToMinute(H2,M2)

ans = fin - K

ans = ans- start

print(ans)


	  

Measured memory_bytes: 9164
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define LL long long
using namespace std;
const int maxn = 1e5+10;
const double pi=acos(-1.0);

LL read(){
	LL x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}
struct node{
    LL x,y;
    double k;
}a[maxn];

int cmp(node a,node b){
	return a.k<b.k;
}

int main(){
    int m,n,now;
    LL nowx=0,nowy=0,ans=0;
    n=read();
    for(register int i=1;i<=n;i++){
		a[i].x=read();a[i].y=read();
		a[i].k=atan2(a[i].y,a[i].x);
	}
	sort(a+1,a+n+1,cmp);
	now=1;
    for(register int i=1;i<=n;i++){
        while(now<i+n && a[now].k-a[i].k<pi){
			nowx+=a[now].x;
			nowy+=a[now].y;
			now++;
			ans=max(ans,nowx*nowx+nowy*nowy);
        }
		nowx-=a[i].x;nowy-=a[i].y;ans=max(ans,nowx*nowx+nowy*nowy);
        a[i+n].x=a[i].x;a[i+n].y=a[i].y;a[i+n].k=a[i].k+2*pi;
    }
    printf("%.15lf\n" ,sqrt(ans));
    return 0;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rnk=[0]*(n+1)

    def Find_Root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        if x==y:
            return
        elif self.rnk[x]>self.rnk[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y]+=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

uf=UnionFind(n)
for _ in range(m):
    x,y,z=map(int,input().split())
    uf.Unite(x,y)
ans=set()
for i in range(1,n+1):
    ans.add(uf.Find_Root(i))
print(len(ans))


Measured memory_bytes: 78552
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef long long ll;
typedef long double ld;

using namespace std;
using namespace __gnu_pbds;

void solve();

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    solve();
    return 0;
}

const int INF = 1e9;
const ll INFL = 1e18;
const double EPS = 1e-9;

void solve(){
    vector<int> digits(3);
    cin >> digits[0] >> digits[1] >> digits[2];
    sort(rall(digits));
    cout << digits[0] * 10 + digits[1] + digits[2];
    return;
}


Measured memory_bytes: 892
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	w := strings.ToUpper(sc.Text())

	count := 0
	for sc.Scan() {
		s := sc.Text()
		if s == "END_OF_TEXT" {
			break
		}
		s = strings.ToUpper(s)
		if s == w {
			count++
		}
	}

	fmt.Println(count)
}



Measured memory_bytes: 1104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int a, b;
  cin >> a >> b;
  if (a+b < 10) cout << a+b << endl;
  else cout << "error\n";
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())

ichigo = [[] for _ in range(h)]
for i in range(h):
    c = input()
    for j, x in enumerate(c):
        if x == "#":
            ichigo[i].append(j)

ans = []
cnt = 1
for i, ichi in enumerate(ichigo):
    if len(ichi) == 0:
        ans.append([])
        continue

    straw = ichi[::-1]
    tmp = []
    first = True

    for j in range(w):
        if not straw:
            tmp.append(cnt)
            continue
        if straw[-1] == j:
            if first:
                straw.pop()
                first = False
            else:
                cnt += 1
                straw.pop()
        tmp.append(cnt)
    else:
        cnt += 1

    ans.append(tmp)

for i, a in enumerate(ans):
    if len(a) != 0:
        j = i-1
        while 0 <= j:
            if len(ans[j]) != 0:
                break
            ans[j] = [x for x in a]
            j -= 1
        j = i+1
        while j < h:
            if len(ans[j]) != 0:
                break
            ans[j] = [x for x in a]


for a in ans:
    print(*a, sep=" ")


Measured memory_bytes: 8656
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=4e6+10;
const int mod7=1e9+7;
const int mod=1e9+7;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
ll quickmod(ll x,ll y)
{
    ll res=1,base=x;
    while(y)
    {
        if(y&1) res=res*base%mod;
        base=base*base%mod;
        y>>=1;
    }
    return res;
}
ll ifac[N],fac[N];
void init(int n)
{
    fac[0]=1;
    for(re int i=1;i<=n;i++) fac[i]=i*fac[i-1]%mod;
    ifac[n]=quickmod(fac[n],mod-2);
    for(re int i=n-1;~i;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
ll C(int n,int m) {return n<m?0:fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
int main()
{
    init(4000000);
    //cout<<C(3,2)<<endl;
    int a,b;
    read(a),read(b);
    if((a+b)%3) return puts("0"),0;
    int y=(a+b)/3;
    int x=2*y;
    if(a>x||b>x) return puts("0"),0;
    printf("%lld\n",C(y,x-a));
    return 0;
}

Measured memory_bytes: 62848
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,m;
  while(cin>>n>>k>>m,n){
  vector<int> v;
  for(int i=1;i<=n;i++)v.push_back(i);
  m--;
  while(--n){
    v.erase(v.begin()+m);
    m=(m+k-1)%n;
  }
  cout<<v[0]<<endl;
  }
  return 0;
}

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

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

    int n;
    cin >> n;

    vector<int> b(n-1);
    rep(i,n-1) cin >> b[i];

    vector<int> a(n);
    a[0] = b[0];
    rep(i,n){
        if(!i) continue;
        a[i] = b[i-1];
        if(i<n-1) a[i] = min(b[i],b[i-1]);
    }

    int ans = 0;
    rep(i,n) ans += a[i];
  	
  	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# B - TAKOYAKI FESTIVAL 2019
n = (int)(input())

tako = list(map(int, input().split()))

sum = 0

for i in range(n):
    for j in range(n):
        if i == j or i > j:
            continue
        else:
            sum += tako[i] * tako[j]

print(sum)

Measured memory_bytes: 2940
A, B, C = map(int, input().split())
K = int(input())
flag = False
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      x = A * (1 << i)
      y = B * (1 << j)
      z = C * (1 << k)
      if i + j + k <=K and x < y and y < z:
        flag = True

if flag == True:
  print("Yes")
else:
  print("No")



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

using namespace std;

 


typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;



void solve()
{
	ll r,c;
	cin>>r>>c;
	ll n;
	cin>>n;
	vector<PLL> arr(n);
	fr(i,0,n)
	{
		cin>>arr[i].F;
		arr[i].S=i+1;
	}
	sort(ALL(arr));
	VL ans;
	fr(i,0,n)
	{
		ll j=0;
		while(j<arr[i].F)
		{
			ans.pb(arr[i].S);
			j++;
		}
	}
	bool fg=true;
	ll ct=0;
	vector<VL> mat(r,VL(c,0));
	fr(i,0,r)
	{
		if(fg==true)
		{
			fr(j,0,c)
			{
				mat[i][j]=ans[ct];
				ct++;
			}
		}
		else
		{
			frr(j,c,0)
			{
				mat[i][j]=ans[ct];
				ct++;
			}
		}
		fg=!fg;
	}
	fr(i,0,r)
	{
		fr(j,0,c)
		{
			//cout<<i<<" "<<j<<endl;
			cout<<mat[i][j]<<" ";
		}
		cout<<"\n";
	}
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
    ll t=1;
    //cin>>t;
   	// cout<<"ok\n";
    while(t--)
    {
		solve();
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    string S,T;cin>>S>>T;
    vector<set<int>> pls;
    pls.assign(26,set<int>({INF}));
    REP(i,S.size()){
        pls[S[i]-'a'].insert(i);
    }
  	bool ok=true;
    REP(i,T.size()){
        if(*pls[T[i]-'a'].lower_bound(0)==INF){
            ok=false;
            break;
        }
    }
    int piyo=-1;
  	int count=0;
    if(ok){
        REP(i,T.size()){
            int d=*pls[T[i]-'a'].lower_bound(piyo+1);
      	    if(d!=INF)piyo=d;
      	    else{
                count++;
                piyo=-1;
                i--;
            }
        }
    }
  	if(ok)cout<<1+piyo+count*S.size()<<endl;
  	else cout<<-1<<endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a, b, c;
	cin >> a >> b >> c;
	int la = a.length(), lb = b.length(), lc = c.length();
	if (a[la - 1] == b[0] && b[lb - 1] == c[0]) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{int n , m;
 cin>>n>>m;
 int a[m];
 int sum =0;
 for(int i=0;i<m;i++)
 {  cin>>a[i];
  sum+=a[i];
  
 }
  if(n<sum)
    cout<<-1;
    else
      cout<< n-sum;
  return 0;
}

Measured memory_bytes: 3636
a = list(map(int,input().split()))
  
a.sort()
  
ans = True
  
if a[0] != 5:
    ans = False
if a[1] != 5:
    ans = False
if a[2] != 7:
    ans = False

if(ans):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
// #define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int max = 10000000;
  int N, M;
  cin >> N >> M;
  
  vector<PII> v;
  int res = 1;
  
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(a, b);
  }
  
  sort(ALL(v));
  
  int minv = max;
  REP(i, M) {
    
    minv = min(minv, v[i].second);
    if (v[i].first >= minv) {
      res ++;
      minv = v[i].second;
    }
  }
  
  cout << res;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const ll MOD = 1000000007;

int main() {
    ll n;
    cin >> n;

    int bin[70] = {};
    rep(i,70){
        bin[69-i] = n%2;
        n /= 2;
    }

    ll dp[70][3];
    rep(i,70){
        rep(j,3){
            dp[i][j] = 0;
        }
    }

    rep(i,70){
        if(i<5){
            dp[i][0] = 1;
            srep(j,1,3)dp[i][j] = 0;
        }else{
            if(bin[i]==0){
                dp[i][2] = dp[i-1][2]*3 + dp[i-1][1]*1;
                dp[i][1] = dp[i-1][1]*1;
                dp[i][0] = dp[i-1][1]*1 + dp[i-1][0]*1;
            }else{
                dp[i][2] = dp[i-1][2]*3 + dp[i-1][1]*2;
                dp[i][1] = dp[i-1][1]*1 + dp[i-1][0]*1;
                dp[i][0] = dp[i-1][0]*1;
            }
            rep(j,3){
                dp[i][j] %= MOD;
            }
        }
    }

    ll ans = 0;
    rep(i,3){
        ans += dp[69][i];
    }
    ans %= MOD;
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, T;
	cin >> N >> T;
	
	int ans = INF;
	REP(i, N) {
		int c, t;
		cin >> c >> t;
		if (t <= T) chmin(ans, c);
	}
	
	if (ans == INF) puts("TLE");
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define mod 1000000007
#define max(p,q)((p)>(q)?(p):(q))
ll powe(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
ll n;
ll x[212345];
ll y[212345];
ll p[212345],m[212345];

int main(){
  scanf("%lld",&n);
  for(int i=0;i<n;i++){
    scanf("%lld%lld",&x[i],&y[i]);
    p[i]=x[i]+y[i];
    m[i]=x[i]-y[i];}
  sortup(p,n);
  sortup(m,n);
  ll ans =max(p[n-1]-p[0],m[n-1]-m[0]);

  
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 9548
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

#define MOD 1000000007

int n;ll k;
void mmul(ll rr[][55], ll a[][55], ll b[][55]){
	ll r[55][55];
	fore(i,0,n)fore(j,0,n){
		r[i][j]=0;
		fore(k,0,n){
			r[i][j]=(r[i][j]+a[i][k]*b[k][j])%MOD;
		}
	}
	fore(i,0,n)fore(j,0,n)rr[i][j]=r[i][j];
}

ll a[55][55];
ll r[55][55];

int main(){
	scanf("%d%lld",&n,&k);
	fore(i,0,n)fore(j,0,n)scanf("%lld",&a[i][j]);
	fore(i,0,n)fore(j,0,n)r[i][j]=i==j;
	while(k){
		if(k&1)mmul(r,r,a);
		k>>=1;
		mmul(a,a,a);
	}
	ll s=0;
	fore(i,0,n)fore(j,0,n)s=(s+r[i][j])%MOD;
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <unordered_set>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) { cin >> a[i]; }

  int cur = 0;
  int count = 0;
  unordered_set<int> visited;
  visited.insert(cur);
  while (cur != 1) {
    int next = a[cur];
    cur = next - 1;
    if (visited.find(cur) != visited.end()) {
      if (cur != 1) {
        cout << "-1" << endl;
        return 0;
      }
    }
    visited.insert(cur);
    count++;
  }
  cout << count << endl;
 }


Measured memory_bytes: 4772
import sys; readline = sys.stdin.readline
from collections import deque

N, M = map(int, readline().split())
A = list(map(int, readline().split()))

if any(a % 2 == 1 for a in A):
    print(0)
    exit(0)

h = [a // 2 for a in A]

def gcd(x, y):
    if x < y:
        x, y = y, x
    
    while x % y != 0:
        r = x % y
        x, y = y, r
    
    return y

def gcp(x, y):
    return x * y // gcd(x,y)

cum_g = h[0]

for i in range(1, len(A)):
    cum_g = gcp(cum_g, h[i])

rs = [cum_g // x for x in h]
if any(r % 2 == 0 for r in rs):
    print(0)
    exit(0)


if cum_g > M:
    print(0)
else:
    print(1 + (M - cum_g) // (2 * cum_g))


Measured memory_bytes: 70516