akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc176/abc176_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<ll> c(N);
  rep(i, N) { cin >> c[i]; }

  ll MAX = 0;
  ll ans = 0;
  rep(i, N) {
    if (MAX >= c[i]) {
      ans += MAX - c[i];
    } else {
      MAX = c[i];
    }
 }

  cout << ans << endl;
}

Measured memory_bytes: 4772
#include<stdio.h>
int main(void)
{
	int m,f,b;
	int ans=0;

	scanf("%d",&m);
	scanf("%d",&f);
	scanf("%d",&b);

	if(m>=b){
		printf("0\n");
	}else{
		ans=b-m;
		if(f>=ans){
			printf("%d\n",ans);
		}else{
			printf("NA\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2612
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	final static long MOD = 1000000007L;
	public static void main(String[] args) {
		Reader in = new Reader();
		int n = in.nextInt();
		int k = in.nextInt();
		int[] a = in.na(n);
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 0; i<n; i++) {
			for(int j = 1; j<=k; j++) {
				if(i+j<n) 
					dp[i+j] = Math.min(dp[i+j], dp[i]+Math.abs(a[j+i]-a[i]));
			}
		}
		System.out.println(dp[n-1]);
	}
	static class Reader {
		static BufferedReader br;
		static StringTokenizer st;
		private int charIdx = 0;
		private String s;

		public Reader() {
			this.br = new BufferedReader(new InputStreamReader(System.in));
		}

		public int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public char nextChar() {
			if (s == null || charIdx >= s.length()) {
				if (st == null || !st.hasMoreTokens())
					try {
						readLine();
					} catch (Exception e) {
					}
				s = st.nextToken();
				charIdx = 0;
			}
			return s.charAt(charIdx++);
		}

		public long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[] nca() {
			return next().toCharArray();
		}

		public String[] nS(int n) {
			String[] a = new String[n];
			for (int i = 0; i < n; i++)
				a[i] = next();
			return a;
		}

		public int nextInt() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Integer.parseInt(st.nextToken());
		}

		public double nextDouble() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Double.parseDouble(st.nextToken());
		}

		public Long nextLong() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Long.parseLong(st.nextToken());
		}

		public String next() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return st.nextToken();
		}

		public static void readLine() {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
			}
		}
	}
}

Measured memory_bytes: 36312
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d, x;
    cin >> n >> d >> x;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        x += (d - 1) / a[i] + 1;
    }
    cout << x;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline
    #define re register
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
#define N 100005
int n,m;
priority_queue <int> q;
int main(){
	int x;
	ll ans=0;
	in2(n,m);
	for(re int i=1;i<=n;i++) read(x),q.push(x);
	while(m--){
		int val=q.top();
		q.pop();
		q.push(val/2);
	}
	for(re int i=1;i<=n;i++) ans+=q.top(),q.pop();
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 892
#include <iostream>

int main(int argc, char const *argv[]) {
  int W,H,x,y,r;
  std::cin >> W >> H >> x >> y >> r;
  if ((x-r) < 0 || (x+r) > W || (y-r) < 0 || (y+r) > H) {
    std::cout << "No" << '\n';
  } else {
    std::cout << "Yes" << '\n';
  }
  return 0;
}

Measured memory_bytes: 3088
n = int(input())
xy = []
for i in range(n):
    a = int(input())
    data = [list(map(int, input().split())) for _ in range(a)]
    xy.append(data)

# --------------------------
ans = 0
for bit in range(1, 2**n):
    flg = True
    # i人目の証言を検証する
    for i in range(n):
        if not flg:
            break

        # i人目が不親切の場合は検証する意味なし
        if not (bit >> i & 1):
            continue

        # i人目の各証言を確認
        for j in xy[i]:
            x = j[0]
            y = j[1]

            # 証言と矛盾していたらダメ
            # ^ : xor
            # どちらかが１どちらかが０なら、Break
            if (bit >> (x - 1) & 1) ^ y:
                flg = False
                break
    if flg:
        ans = max(ans, bin(bit).count('1'))

print(ans)


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

int ar[10004];

int main()
{
	int n, i, ans;

	cin>>n;
	for(i=1; i<=n; i++)
	{
		cin>>ar[i];

	}
	bool ok=true;
	for(i=1; i<=n; i++)
	{
		if(ar[i]%2==0)
		{
			if(ar[i]%3!=0&&ar[i]%5!=0)
			{ 
				ok=false;
			}
		}		
	}
	if(!ok)cout<<"DENIED"<<endl;
	else cout<<"APPROVED"<<endl;
}

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

int main() {
    int N;
    cin >> N;
    bool ans = false;
    for (int i = 0; i <= N / 4; i++) {
        for (int j = 0; j <= N / 7; j++) {
            if (i * 4 + j * 7 == N) {
                ans = true;
                break;
            }
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

Measured memory_bytes: 600
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
halfA = maxA // 2
tmp = 10 ** 9
r = 0
for a in A:
    if a == maxA:
        continue
    half = abs(halfA - a)
    if tmp > half:
        tmp = half
        r = a

print(maxA, r)

Measured memory_bytes: 14428
class Node():
    def __init__(self):
        self.parent = -1
        self.left = -1
        self.right = -1


def reconstruction(preo, ino):
    root = preo[0]

    ileft = ino[0:ino.index(root)]
    iright = ino[ino.index(root)+1:]

    pleft = preo[1:]
    pright = preo[1:]

    for item in iright:
        pleft.remove(item)

    for item in ileft:
        pright.remove(item)

    if len(pleft) == 0:
        pass
    elif len(pleft) == 1:
        Nodes[root-1].left = pleft[0]
    else:
        Nodes[root-1].left = reconstruction(pleft, ileft)

    if len(pright) == 0:
        pass
    elif len(pright) == 1:
        Nodes[root-1].right = pright[0]
    else:
        Nodes[root-1].right = reconstruction(pright, iright)

    return root


def postorder(id):
    if Nodes[id-1].left != -1:
        postorder(Nodes[id-1].left)

    if Nodes[id-1].right != -1:
        postorder(Nodes[id-1].right)

    ans.append(id)


def main():
    n = int(input())
    global Nodes
    Nodes = [Node() for i in range(n)]

    preorder = list(map(int, input().split()))
    inorder = list(map(int, input().split()))

    rootid = reconstruction(preorder, inorder)

    global ans
    ans = []
    postorder(rootid)
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto nmxy = readln.chomp.split.to!(int[]);
  auto x = max(readln.chomp.split.to!(int[]).reduce!(max), nmxy[2]);
  auto y = min(readln.chomp.split.to!(int[]).reduce!(min), nmxy[3]);

  if (x < y) {
    writeln("No War");
  } else {
    writeln("War");
  }
}


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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll mod(ll a, ll m)
{
    return ((a % m) + m) % m;
}

ll solve(int N, ll K, const vector<ll>& xs)
{
    vector<ll> ps(N + 1);
    ps[0] = 0;

    for (int i = 1; i <= N; ++i)
        ps[i] = (ps[i - 1] + xs[i]) % K;

    map<ll, ll> hs;
    ++hs[0];

    int last = 0;
    ll ans = 0;

    for (int i = 1; i <= N; ++i)
    {
        if (i - last == K)
        {
            ll q = mod(ps[last] - last, K);
            hs[q]--;
            ++last;
        }

        ll r = mod(ps[i] - i, K);
        ans += hs[r];

#ifdef DEBUG
//    cout << "xs[" << i << "] = " << xs[i] << ", ps[" << i << "] = " << ps[i] << ", r = " << r << ", ans = " << ans << endl;
//    for (auto [x, v] : hs)
 //       cout << x << ": " << v << endl;
#endif
        hs[r]++;
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    vector<ll> xs(N + 1);

    for (int i = 1; i <= N; ++i)
        cin >> xs[i];

    auto ans = solve(N, K, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 0; i < n - k; i++) {
			if (a[i] < a[i + k]) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 60180
n = int(input())						# 5
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...


NextNum=1
Crash=0
for _ in range(n):
	
	if A[_]==NextNum:
		NextNum += 1
	else:
		Crash+=1

ans=-1
if NextNum>1:
	ans = Crash

print(ans)


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

const LL mod = 1000000007;
LL N, M;
std::vector<LL>S, T;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (i == -1 || j == -1) return 0;
	if (memo[i][j] != -1) return memo[i][j];
	LL res = 0;
	if (S[i] == T[j])
	{
		(res += dp(i - 1, j - 1)) %= mod;
		(++res) %= mod;
	}
	(res += dp(i - 1, j)) %= mod;
	(res += dp(i, j - 1)) %= mod;
	(res += -dp(i - 1, j - 1) + mod) %= mod;
	return memo[i][j] = res;
}

int main()
{
	in >> N >> M;
	S.resize(N); T.resize(M);
	rep(i, N) in >> S[i];
	rep(i, M) in >> T[i];

	memo.resize(N, std::vector<LL>(M, -1));
	out << (dp(N - 1, M - 1) + 1) % mod << std::endl;
}


Measured memory_bytes: 31872
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni(), k = in.ni();
        int[] h = in.ni(n);
        int[] c = new int[n];
        Arrays.fill(c, inf);
        c[0]= 0;
        for (int i = 0; i < n; i++) {
            for (int j = 1; j <= k; j++) {
                if(i+j<n) c[i+j] = Math.min(c[i+j], c[i]+Math.abs(h[i+j]-h[i]));
                else break;
            }
        }
        out.println(c[n-1]);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 34904
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=2e5+5,maxm=1e6+5;
struct node
{
    int a,b;
}job[maxn];
bool cmp(node x,node y)
{
    if(x.b==y.b)
        return x.a<y.a;
    else return x.b<y.b;
}
int main()
{int n;
cin>>n;
for(int i=1;i<=n;i++)
{
    cin>>job[i].a>>job[i].b;
}
sort(job+1,job+n+1,cmp);
int sum=0;
bool flag=1;
for(int i=1;i<=n;i++)
{
    if(sum+job[i].a>job[i].b)
    {
        flag=0;
        break;
    }
    else sum+=job[i].a;
}
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int passenger = 0;
    for (int j = 0; j < c && v[i + j] <= v[i] + k; ++j) {
      passenger = j;
      if (i + j + 1 >= n)
        break;
    }
    i += passenger;
    ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){

    string s,p;
    string result = "No";

    cin>>s;
    cin >> p;

    char c[200] = { };

    for(int i = 0; i< sizeof(c)/sizeof(c[0]);i++)
    {
        c[i]= s[i%s.length()];
    }

    for(int i = 0; i< sizeof(c)/sizeof(c[0]);i++)
    {
        int count = 0;
        while (p[count] == c[i + count])
        {
            count++;
            if(p.length() == count)
            {
                result = "Yes";
            }
        }
    }


    cout << result << endl;

    return 0;
}

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

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

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

int main() {
    ios_base::sync_with_stdio(false);
    int n,k,x; cin >> n >> k;
    int ans = 0;
    while(n--) {
        cin >> x;
        ans += (x >= k);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int N, K;
   cin >> N >> K;
   int h[N];
   for (int i = 0; i < N; i++) {
      cin >> h[i];
   }
   sort(h, h + N);

   int ans = -1;
   for (int i = 0; i < N - K + 1; i++) {
      int tmp = h[i + K - 1] - h[i];
      if (ans == -1) ans = tmp;
      else if (ans > tmp) ans = tmp;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

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

func main() {
	sc.Split(bufio.ScanWords)
	r, d, x := nextInt(), nextInt(), nextInt()
	for i := 1; i <= 10; i++ {
		x = r*x - d
		fmt.Println(x)
	}
}


Measured memory_bytes: 640
//??????????????????
//0?????§???????????´???, 1?????§???????????´???, ?????¨??????????????????????????¨?§£?????????
#include <iostream>
#include <vector>
using namespace std;

int n, m, a, b, c;
vector<int> et[50];
bool dp[50][50][101];	//dp[i][k][j] = ??????a????????????k???????????????j?????§?§??????§????????????

int main() {
	int i, j, k, l;
	
	cin >> n >> m >> a >> b >> c;
	for (i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		et[u].push_back(v);
	}
	
	for (i = 0; i < n; i++) {
		dp[i][i][0] = true;
		for (j = 0; j < 100; j++) {
			for (k = 0; k < n; k++) {
				if (!dp[i][k][j]) continue;
				for (l = 0; l < et[k].size(); l++) {
					dp[i][et[k][l]][j + 1] = true;
				}
			}
		}
	}
	
	int minCost[50];
	for (i = 0; i < n; i++) minCost[i] = 114514;
	minCost[n - 1] = 0;
	
	for (i = 1; i < n; i++) {
		for (j = 0; j < n; j++) {
			for (k = 0; k < n; k++) if (minCost[k] <= i - 1 && dp[j][k][a]) break;
			if (k == n) continue;
			for (k = 0; k < n; k++) if (minCost[k] <= i - 1 && dp[j][k][b]) break;
			if (k == n) continue;
			for (k = 0; k < n; k++) if (minCost[k] <= i - 1 && dp[j][k][c]) break;
			if (k == n) continue;
			if (minCost[j] > i) minCost[j] = i;
		}
	}
	
	if (minCost[0] < 114514) { cout << minCost[0] << endl; }
	else { cout << "IMPOSSIBLE" << endl; }
	return 0;
}

Measured memory_bytes: 3408
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl


int main() {
	int N;
	int a[110];
	rd(N);
	repi(i, 0, N) rd(a[i]);
	sort(a, a + N);
	wrln(a[N - 1] - a[0]);
	return 0;
}

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


using Coordinate = pair<int, int>;


int solve(int h, int w, vector<string> grid) {
  vector<Coordinate> d;
  d.push_back(Coordinate(-1, 0));
  d.push_back(Coordinate(1, 0));
  d.push_back(Coordinate(0, -1));
  d.push_back(Coordinate(0, 1));

  queue<Coordinate> q;
  vector< vector<int> > n_step(h, vector<int>(w));

  for (int ih = 0; ih < h; ih++) {
    for (int iw = 0; iw < w; iw++) {
      if (grid[ih][iw] == '#') {
        q.push(make_pair(ih, iw));
        n_step[ih][iw] = 1;
      }
    }
  }

  while (!q.empty()) {
    Coordinate c0 = q.front();
    q.pop();
    int ih0 = c0.first;
    int iw0 = c0.second;
    int n = n_step[ih0][iw0];

    for (int i = 0; i < 4; i++) {
      int ih1 = ih0 + d[i].first;
      int iw1 = iw0 + d[i].second;

      if (ih1 < 0) continue;
      if (ih1 >= h) continue;
      if (iw1 < 0) continue;
      if (iw1 >= w) continue;

      if (n_step[ih1][iw1] == 0) {
        n_step[ih1][iw1] = n + 1;
        q.push(Coordinate(ih1, iw1));
      }
    }
  }

  int m = 0;
  for (int ih = 0; ih < h; ih++) {
    for (int iw = 0; iw < w; iw++) {
      m = max(m, n_step[ih][iw]);
    }
  }

  return m - 1;
}

int main() {
  /* int h, w; */
  /* h = 3; */
  /* w = 3; */
  /* vector<string> grid(h); */
  /* grid[0] = "..."; */
  /* grid[1] = ".#."; */
  /* grid[2] = "..."; */

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int ih = 0; ih < h; ih++) cin >> grid[ih];

  int answer = solve(h, w, grid);
  cout << answer << endl;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;
string s;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> s;
    cout << s.substr(0, 3) << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,a,b;
	cin>>k>>a>>b;

	l=1;
	k=k-(a-l);
	l=a;
	for(i=1;i<=k;i++){
		if(b>a+1&&i+1<=k){
			l-=a;
			l+=b;
			i++;
		}
		else {
			l++;
		}
		//cout<<i<<" "<<l<<endl;
	}
	cout<<l;
	return 0;
}
//ctrl H replace

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int H, W, N;
int ix, iy;
string S, T;

bool solve() {
    // left, right
    int left = 0, right = W;
    if (S[N-1] == 'L') ++left;
    if (S[N-1] == 'R') --right;
    for (int i = N-2; i >= 0; --i) {
        if (T[i] == 'L'){
            right = min(right+1, W);
        }
        else if(T[i] == 'R'){
            left = max(0, left-1);
        }

        if (S[i] == 'L'){
            left = left + 1;
        }
        else if (S[i] == 'R'){
            right = right - 1;
        }

        if (left >= right){
            return false;
        }
    }
    if (iy < left || iy >= right){
        return false;
    }

    // up, down
    left = 0, right = H;
    if (S[N-1] == 'U') ++left;
    if (S[N-1] == 'D') --right;
    for (int i = N-2; i >= 0; --i) {
        if (T[i] == 'U'){
            right = min(right+1, H);
        }
        else if (T[i] == 'D'){
            left = max(0, left-1);
        }

        if (S[i] == 'U'){
            left = left + 1;
        }
        else if (S[i] == 'D'){
            right = right - 1;
        }

        if (left >= right){
            return false;
        }
    }

    if (ix < left || ix >= right){
        return false;
    }

    return true;
}


int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    cin >> H >> W >> N >> ix >> iy >> S >> T;
    --ix, --iy;
    if (solve()){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;

#ifdef LOCAL
#define err cerr
#else
#define err if (false) cerr
#endif

typedef long long ll;

const int MAXN = 55;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a, b; cin >> a >> b; cout << 6 - a - b;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

vector<int> TopologicalSort(vector<vector<int>> &G) {
    int N = G.size();
    vector<int> cnt(N);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < G[i].size(); j++) {
            cnt[G[i][j]]++;
        }
    }
    vector<int> S;
    for (int i = 0; i < N; i++) {
        if (!cnt[i]) S.push_back(i);
    }
    if (!S.size()) return vector<int>();

    vector<int> L;
    while(!S.empty()) {
        int n = S.back(); S.pop_back();
        L.push_back(n);
        for(int i = 0; i < G[n].size(); i++) {
            cnt[G[n][i]]--;
            if (!cnt[G[n][i]]) {
                S.push_back(G[n][i]);
            }
        }
    }
    if (L.size() == N) return L;
    return vector<int>();
}


void solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    vector<int> T = TopologicalSort(G);

    vector<int> dp(N, 0);
    for (int i = 0; i < T.size(); i++) {
        int v = T[i];
        for (int j = 0; j < G[v].size(); j++) {
            int u = G[v][j];
            dp[u] = max(dp[u], dp[v] + 1);
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 6780
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int ans = 0;

		//偶数＋偶数
		ans += N * (N - 1) / 2;
		
		//奇数＋奇数
		ans += M * (M - 1) / 2;
		
		System.out.println(ans);
		sc.close();
	}
	
}

Measured memory_bytes: 23764
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    public void solve() {
    	int N = ni();
    	int M = ni();
    	PriorityQueue<PP> PQ = new PriorityQueue<PP>(comparing(PP::getVal)); 
    	int a, b;
    	for (int i = 0; i < M; i++) {
			a = ni() - 1;
			b = ni() - 1;
			PQ.add(new PP(a,b));
		}
    	int ans = 0, sv = -1;
    	PP p;
    	while(!PQ.isEmpty()) {
    		p = PQ.poll();
    		if(p.key <= sv)		continue;
    		ans++;
    		sv = p.val-1;
    	}
    	out.println(ans);
    }
    static class PP{
    	public int key, val;
    	public PP(int key, int val) {
    		this.key = key;
    		this.val = val;
    	}
		public int getKey() {
			return key;
		}
		public void setKey(int key) {
			this.key = key;
		}
		public int getVal() {
			return val;
		}
		public void setVal(int val) {
			this.val = val;
		}
    }

    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] ndii(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


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

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if (k-a <= 0) {
    cout << a-k << " " << b << endl;
    return 0;
  }
  
  if ((a+b)-k <= 0) cout << 0 << " " << 0 << endl;
  else cout << 0 << " " << b-(k-a) << endl;
  
  return 0;
}

Measured memory_bytes: 3632
import math
A, B, X = map(int, input().split())
pi = 3.14159265359

if X == A*A*B:
    print("0")
elif X <= A*A*B/2:
    print(math.atan(A*B*B/2/X)/pi*180)
else:
    print(math.atan(2*(A*A*B-X)/(A*A*A))/pi*180)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll INF = 1e10;

int main() {
  int N; cin >> N;
  vector<int> A(N), B(N); for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
  ll s = 0, m = INF;
  for (int i = 0; i < N; ++i) {
    if (A[i] > B[i] && B[i] < m) m = B[i];
    s += A[i];
  }
  cout << ( (m == INF) ? 0 : s - m ) << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main() {
	int r, g, b, sum;

	cin >> r >> g >> b;

	sum = r * 100 + g * 10 + b;

	if (sum % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}
template <class T> T up(T a, T div) { return (a + div - 1) / div; }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    scan(N);
    vector<ll> v(N);
    scan(v);

    REP(i, N) { v[i] -= i + 1; }
    SORT(v);
    int b   = v[N / 2 - 1];
    ll ans1 = 0;
    REP(i, N) { ans1 += abs(v[i] - b); }
    b       = v[N / 2];
    ll ans2 = 0;
    REP(i, N) { ans2 += abs(v[i] - b); }

    print(min(ans1, ans2));

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
using namespace std;
#define REP0(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
typedef long long ll;
ll gcd(ll a,ll b){
	while(b>0){
		if(a>b) swap(a,b);
		b%=a;
	}
	return a;
}
int main(){
	ll a,b;
	while(scanf("%lld%lld",&a,&b)!=EOF) printf("%lld %lld\n",gcd(a,b),a/gcd(a,b)*b);
	return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  if(n == 1) {
    cout << 1 << '\n';
    return 0;
  }
int  base = 2, bc = 1;
  vector<int> a(n+1, 0);
  while(base <= n) {
    int mul = 1;
    while(base * mul <= n) {
      a[base*mul] = bc;
      mul++;
    }
    bc++;
    base = 2 * base;
  }
  int max_id = 0;
  for(int i=1; i<=n; i++) {
    if(a[i] > a[max_id]) max_id = i;
  }
  cout << max_id << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			if (A == 1 && B == 1) {
				System.out.println("Draw");
			} else if (A == 1) {
				System.out.println("Alice");
			} else if (B == 1) {
				System.out.println("Bob");
			} else if (A > B) {
				System.out.println("Alice");
			} else if (A < B) {
				System.out.println("Bob");
			} else {
				System.out.println("Draw");
			}

		}
	}
}


Measured memory_bytes: 23764
import itertools
import math
H,W = list(map(int,input().split(" ")))
mines = []
dirs = [0,1,-1]

for _ in range(H):
    l =input()
    mines.append(l)


for h in range(H):
    for w in range(W):

        if mines[h][w] == "#":
            print("#",end="")

        else:
            c = 0
            for d1 in dirs:
                for d2 in dirs:
                    x = w - d1
                    y = h - d2
                    if x >=0 and x < W and y >= 0 and y < H:
                        if mines[y][x] == "#":
                            c += 1
            print(c,end="")
    print()



Measured memory_bytes: 3444
/*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;

#define ll 					  long long int
#define boost		          ios_base::sync_with_stdio(0);
#pragma GCC optimize("O3")
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define eb                    emplace_back
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()
#define bug()				  debug() <<

///////////////////////

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

///////////////////////
const int INF = 1e9 + 90;
const ll LINF = 1e18 + 90 ;
using pii = pair<int,int >;
using vec = vector<int> ;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int n , k ; cin >> n >> k;

    vector<long long int> v(n+1) ;
    for(int i = 1 ; i <= n ; i++){
        cin >> v[i] ;
    }
    vector<long long int> path ;
    bool rem[n+1] = {} ;

    long long int x = 1, pos = 1 ;
    long long int reoc = -1 ;
    for(int i = 1 ; i <= k ; i++){
        pos = v[x] ;
        if(rem[pos]){
            reoc = pos ;
            break ;
        }
        rem[pos] = true ;
        path.emplace_back(pos) ;
        x = pos ;
    }
    long long int p = -1 ;
    if(reoc != -1){
        for(int i = 0 ; ; i++){
            if(path[i] == reoc){
                p = i ;
                break ;
            }
        }
    }
    if( k < p){
        cout << path[k-1] << endl ;
    }
    else{
        k -= p ;
        long long int pth = path.size() - p ;
        long long int mod = k % pth ;
        if(mod == 0){
            mod = pth ;
        }
        cout << path[p+mod - 1] << endl ;
    }

    bug() dbg(path) dbg(p) dbg(reoc);

    return 0;
}


Measured memory_bytes: 7008
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

vector<vector<char> > vv;
vector<vint> vis;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int n,m;
void foo(int x,int y,char t){
	if(x>=0&&x<n&&y>=0&&y<m){
		if(vv[x][y]==t&&!vis[x][y]){
			vis[x][y]=1;
			rep(i,4){
				foo(x+dx[i],y+dy[i],t);
			}
		}
	}
}




int main(){
	// int n,m;
	while(cin>>n>>m,n||m){
		// vector<vint> vv;
		initvv(vv,n,m);
		initvv(vis,n,m);
		rep(i,n){
			rep(j,m){
				cin>>vv[i][j];
				vis[i][j]=0;
			}
		}
		int ans=0;
		rep(i,n){
			rep(j,m){
				if(vis[i][j]==0){
					ans++;
					foo(i,j,vv[i][j]);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1744
N,x = map(int, input().split())
a= [int(i) for i in input().split()]

a_s = sorted(a)

count=0
if sum(a) < x:
  count = -1
for i in range(N):
  if a_s[i] <= x:
    count += 1
    x -= a_s[i]
print(count)

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll(x);cin >> (x);
#define stin(x) str(x);cin >> (x);
#define vllin(x,n) vll(x)(n);FOR(i,0,n-1){cin >> (x)[i];}
#define vllin2(a,b,n) vll(a)(n);vll(b)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vllin3(a,b,c,n) vll(a)(n);vll(b)(n);vll(c)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >> (x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vpl4in(x,n) vpl4(x)((n),mp(0,0));FOR(i,0,n-1){cin >> x[i].fi >> x[i].se;}
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define rFOR(i,b,a) for(ll i=a;i>=b;i--)
#define SORT(x) sort(x.be,x.en)
#define rSORT(x) sort(x.rbegin(),x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll MOD = 1000000007;

signed main()
{
    llin(n);
    llin(m);
    vpl4 a(m);
    FOR(i,0,m-1){
        cin >>a[i].fi>>a[i].se;
    }
    SORT(a);
    ll c=a[0].se;
    ll k=1;
    FOR(i,0,m-1){
        if(c<=a[i].fi){
            c=a[i].se;
            k++;
        }else{
            c=min(c,a[i].se);
        }
    }
    sal(k)
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll>sum(n),a(n),sum2(n);
	rep(i, n) {
		cin >> a[i];
	}
	ll count = 0;
	ll count2 = 0;
	sum[0] = a[0];
	if (sum[0]>0) {
		sum2[0] = -1;
		count2 += sum[0] + 1;
	}
	else if (sum[0] < 0) {
		sum2[0] = 1;
		count2 += abs(sum[0])+1;
	}
	else {
		sum[0] = 1;
		count++;
		sum2[0] = -1;
		count2++;
	}
	FOR(i,1, n) {
		sum[i] = sum[i - 1] + a[i];
		if (sum[i - 1] > 0) {
			if (sum[i] >= 0) {
				count += sum[i] + 1;
				sum[i] = -1;
			}
		}
		else if (sum[i - 1] < 0) {
			if (sum[i] <= 0) {
				count += abs(sum[i]) + 1;
				sum[i] = 1;
		    }
		}
	}
	FOR(i, 1, n) {
		sum2[i] = sum2[i - 1] + a[i];
		if (sum2[i - 1] > 0) {
			if (sum2[i] >= 0) {
				count2 += sum2[i] + 1;
				sum2[i] = -1;
			}
		}
		else if (sum2[i - 1] < 0) {
			if (sum2[i] <= 0) {
				count2 += abs(sum2[i]) + 1;
				sum2[i] = 1;
			}
		}
	}
	cout << min(count,count2) << endl;
}

Measured memory_bytes: 2560
def resolve():
    n=int(input())
    l1=list(map(int, input().split()))
    l2=list(map(int, input().split()))
    amemax=0
    for i in range(n):
        ame=0
        ame=sum(l1[:i+1])+sum(l2[i:n])
        amemax=max(ame,amemax)
    print(amemax)
resolve()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>

using namespace std;

char S[10];


int main()
{
  cin >> S;
  
  if(strcmp(S,"SUN")==0) cout << 7;
  else if(strcmp(S,"MON")==0) cout << 6;
  else if(strcmp(S,"TUE")==0) cout << 5;
  else if(strcmp(S,"WED")==0) cout << 4;
  else if(strcmp(S,"THU")==0) cout << 3;
  else if(strcmp(S,"FRI")==0) cout << 2;
  else if(strcmp(S,"SAT")==0) cout << 1;


  
  
 return 0; 
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    string s,t; cin >> s >> t;
    int ans = 0;
    rep(i,0,s.size()){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << "\n";
    
}

Measured memory_bytes: 3856
-- Repetitive Processing - Swapping Two Numbers

import Control.Applicative

main :: IO ()
main = do
  xs <- map read . words <$> getContents
  let ys = loop xs
  mapM_ putStrLn $ [show a ++ " " ++ show b | (a, b) <- ys]
    where
      loop :: [Int] -> [(Int, Int)]
      loop (0 : 0 : _) = []
      loop [] = []
      loop (a : b : xs) = (if (a < b) then (a, b) else (b, a)) : loop xs



Measured memory_bytes: 4580
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next()),l=Integer.parseInt(sc.next());
        String[] s = new String[n];
        for(int i =0;i<n;i++){
            s[i] = sc.next();
        }
        Arrays.sort(s);
        for(int i =0;i<n;i++){
            System.out.print(s[i]);
        }
    }
}

Measured memory_bytes: 21972
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();
		Sushi[] arr = new Sushi[n];
		for (int i = 0; i < n; i++) {
			Sushi s = new Sushi(sc.nextInt(), sc.nextInt());
			arr[i] = s;
		}
		Arrays.sort(arr, new Comparator<Sushi>() {
		public int compare(Sushi s1, Sushi s2) {
			return s2.d - s1.d;
		}
		});
		int[] counts = new int[100001];
		long count = 0;
		long value = 0;
		ArrayList<Sushi> klist = new ArrayList<>();
		for (int i = 0; i < k; i++) {
			Sushi s = arr[i];
			if (counts[s.t] == 0) {
				count++;
			}
			counts[s.t]++;
			value += s.d;
		}
		long max = value + count * count;
		int j = k;
		for (int i = 0; i < k; i++) {
			Sushi s1 = arr[k - i - 1];
			if (counts[s1.t] < 2) {
				continue;
			}
			while (j < n) {
				Sushi s2 = arr[j];
				j++;
				if (counts[s2.t] == 0) {
					value = value - s1.d + s2.d;
					count++;
					counts[s1.t]--;
					counts[s2.t]++;
					long v = value + count * count;
					if (max < v) {
						max = v;
					}
					break;
				}
			}
		}
		System.out.println(max);
	}
	
	static class Sushi {
		int t;
		int d;
		public Sushi(int t, int d) {
			this.t = t;
			this.d = d;
		}
	}
	
}


Measured memory_bytes: 92620
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N,K;
	cin >> N >> K;
	int h[N];
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h, h + N);
/*
	for (int i = 0; i < N; i++) {
		cout << h[i] << ":";
	}
	cout << endl;
*/
	int min_dif = 2000000000;

	for (int i = 0; i < N - K + 1; i++) {

		int cur = h[i + K - 1] - h[i];

		if (cur < min_dif) {
			min_dif = cur;
		}
	}

	cout << min_dif << endl;



	return 0;
}

Measured memory_bytes: 640