akhauriyash/Code-Regression huggingface dataset:
import itertools
N,C = map(int,input().split())
D = [list(map(int,input().split())) for i in range(C)]
grid = [list(map(int,input().split())) for i in range(N)]
l1 = [0]*C
l2 = [0]*C
l3 = [0]*C
for i in range(1,N+1):
    for j in range(1,N+1):
        if (i+j) % 3 == 0:
            l1[grid[i-1][j-1]-1] += 1
        elif (i+j) % 3 == 1:
            l2[grid[i-1][j-1]-1] += 1
        elif (i+j) % 3 == 2:
            l3[grid[i-1][j-1]-1] += 1
color = list(range(1,C+1))
ans = float('inf')
for x,y,z in itertools.permutations(color,3):
    res = 0
    for i in range(C):
        res += D[i][x-1]*l1[i]
    for i in range(C):
        res += D[i][y-1]*l2[i]
    for i in range(C):
        res += D[i][z-1]*l3[i]
    if res < ans:
        ans = res
print(ans)

Measured memory_bytes: 48476
#include <bits/stdc++.h>
#define INT long long int
#define MOD (INT)(1e9)+7
using namespace std;

INT n, l[90] = {2, 1};
int main()
{
     cin>>n;
     for(int i = 2 ; i <= n ; i++ ) l[i] = l[i-1] + l[i-2];
     cout<<l[n]<<endl;
}


Measured memory_bytes: 256
#include <iostream>

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

lli max(lli a,lli b){
	if(a>=b)return a;
	else return b;
}

using namespace std;

int main(){

	int n;
	lli nowT=1,nowA=1;
	cin>>n;
	lli inT,inA;
	lli index=0;

	REP(i,n){
		cin>>inT>>inA;
		index = max(nowT/inT+(1<=(nowT%inT)),nowA/inA+(1<=(nowA%inA)));
		nowT = inT*index;
		nowA = inA*index;
		//cout<<nowT<<" "<<nowA<<endl;
	}

	cout<<nowT+nowA<<endl;

	return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
  int x, k;
  cin >> x >> k;
  cout << (500*x >= k ? "Yes" : "No") << endl;
    return 0;
}

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

int main(){

  int a,b,c,d;
  cin >> a >> b >> c >> d;

  if(a!=c){
    for(int i=0;i<abs(a-c);i++) cout << (a>c?"L":"R") << flush;
  }
  if(b!=d){
    for(int i=0;i<abs(b-d);i++) cout << (b>d?"D":"U") << flush;
  }

  cout << (a>c?"R":"L") << flush;

  if(b!=d){
    for(int i=0;i<abs(b-d)-1;i++) cout << (b>d?"U":"D") << flush;
  }
  if(a!=c){
    for(int i=0;i<abs(a-c)-1;i++) cout << (a>c?"R":"L") << flush;
  }

  cout << (b>d?"U":"D") << flush;
  cout << (b>d?"U":"D") << flush;

  if(a!=c){
    for(int i=0;i<abs(a-c)+1;i++) cout << (a>c?"L":"R") << flush;
  }
  if(b!=d){
    for(int i=0;i<abs(b-d)+1;i++) cout << (b>d?"D":"U") << flush;
  }

  cout << (a>c?"R":"L") << flush;
  cout << (b>d?"D":"U") << flush;
  cout << (a>c?"R":"L") << flush;
  cout << (a>c?"R":"L") << flush;

  if(b!=d){
    for(int i=0;i<abs(b-d)-1;i++) cout << (b>d?"U":"D") << flush;
  }
  if(a!=c){
    for(int i=0;i<abs(a-c)-1;i++) cout << (a>c?"R":"L") << flush;
  }

  cout << (b>d?"U":"D") << flush;
  cout << (b>d?"U":"D") << flush;
  cout << (a>c?"L":"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;

int main(){
    int H,W;
    while(cin>>H>>W, H){
        rep(i,H){
            rep(j,W){
                if((i + j) & 1)cout<<".";
                else cout<<"#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3080
#include <cstdio>

#include <algorithm>
using namespace std;

typedef pair<int, int> POS;

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);

	POS students[50 + 2];
	for (int i = 0; i < N; ++i)
	{
		int ai, bi;
		scanf("%d%d", &ai, &bi);
		students[i] = POS(ai, bi);
	}

	POS checkpoints[50 + 2];
	for (int i = 0; i < M; ++i)
	{
		int ai, bi;
		scanf("%d%d", &ai, &bi);
		checkpoints[i] = POS(ai, bi);
	}

	for (int i = 0; i < N; ++i)
	{
		int minIx = -1;
		int minDist;
		for (int j = 0; j < M; ++j)
		{
			int dx = students[i].first - checkpoints[j].first;
			int dy = students[i].second - checkpoints[j].second;
			int d = abs(dx) + abs(dy);
			if (minIx < 0 || minDist > d)
			{
				minIx = j;
				minDist = d;
			}
		}
		printf("%d\n", minIx+1);
	}

	return 0;
}


Measured memory_bytes: 128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define sz(x) (int)(x.size())
#define pb push_back
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define endl "\n"
#define int long long


const int N = (int)(1e6) + 322;
const long long inf = (long long)(1e18) + 123;
const int mod = (int)(1e9);
const double EPS = 1e-9;


int n, x[N], y[N];

inline int dot(int i, int j) {
    return x[i] * x[j] + y[i] * y[j];
}

signed main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> x[i] >> y[i];
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = i; j <= n; ++j) {
            int curx = 0, cury = 0;
            for(int k = 1; k <= n; ++k) {
                if (dot(i, k) > 0 || dot(j, k) > 0) {
                    curx += x[k];
                    cury += y[k];
                }
            }
            //cout << i << ' ' << j <<
            ans = max(ans, curx * curx + cury * cury);
        }
    }
    cout << setprecision(10) << fixed << sqrt(ans);
    return 0;
}



Measured memory_bytes: 2812
import Control.Monad
import Data.Array
import Data.List
main = do
  [n,k] <- map read . words <$> getLine
  abs <- replicateM n $ map read . words <$> getLine
  let ar = accumArray (+) 0 (1,10^5) [(a,b) | [a,b] <- abs]
      (Just i) = findIndex (>=k) $ scanl1 (+) $ elems $ ar
  print (i+1)

Measured memory_bytes: 99708
#include <iostream>
#include <vector>
using namespace std;
long long INF = 1e18;
struct edge{
    int from;
    int to;
    long long cost;
};
vector<int> used1, used2;
void solve(int N, int M, vector<edge> &es, int s, int t){
    vector<long long> d(N);//各頂点までの距離
    for(int i = 0; i < N; i++) d[i] = INF;
    d[s] = 0;
    long long k = 0;
    long long ans = 0;
    bool flag2 = false;
    while(true){
        bool flag = false;
        for(int i = 0; i < M; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost && used1[e.to] == 1 && used2[e.to] == 1){
                d[e.to] = d[e.from] + e.cost;
                flag = true;
            }
        }
        ans = min(ans, d[t]);
        k++;
        if(k >= N) flag2 = flag2 || flag;
        if(k == 2 * N && flag2) {
            cout << -1 << endl;
            break;
        }
        else if(k == 2 * N){
            cout << -ans << endl;
            break;
        }
    }
}
void dfs(int s, vector<int> &use, vector<vector<int>> &g){
    use[s] = 1;
    for(int x: g[s]){
        if(use[x] == 0) dfs(x, use, g);
    }
}
int main(){
    int N, M;
    cin >> N >> M;
    long long P;
    cin >> P;
    vector<edge> es(M);
    vector<vector<int>> G(N), rG(N);
    for(int i = 0; i < M; i++){
        int x, y;
        long long c;
        cin >> x >> y >> c;
        x--;
        y--;
        edge e = {x, y, -c + P};
        G[x].push_back(y);
        rG[y].push_back(x);
        es[i] = e;
    }
    used1.resize(N, 0);
    used2.resize(N, 0);
    dfs(0, used1, G);
    dfs(N - 1, used2, rG);
    solve(N, M, es, 0, N - 1);
}

Measured memory_bytes: 4092
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const ll INF = 1e15;

int n;
ll d[201][201];

void warshallfloyd(){
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[j][k]);
            }
        }
    }
}

int main()
{
    int m, r;
    cin >> n >> m >> r;
    int l[10];
    for(int i = 0; i < r; i++){
        cin >> l[i];
        l[i]--;
    }
    for(int i = 0; i < n; i++){
        fill(d[i], d[i] + n, INF);
    }
    int a[40000], b[40000];
    ll c[40000];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> c[i];
        d[a[i] - 1][b[i] - 1] = c[i];
        d[b[i] - 1][a[i] - 1] = c[i];
    }
    warshallfloyd();
    ll ans = INF;
    int enu[10];
    for(int i = 0; i < r; i++) enu[i] = i;
    do{
        ll dist = 0;
        for(int i = 0; i < r - 1; i++){
            dist += d[l[enu[i]]][l[enu[i + 1]]];
        }
        ans = min(ans, dist);
    }while(next_permutation(enu, enu + r));
    cout << ans << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = max((a),(b))
#define chmin(a, b) a = min((a),(b))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;



int main(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
}

Measured memory_bytes: 256
from itertools import permutations as perm
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    primes = [2]
    for x in range(3, 100000 + 100, 2):
        for p in primes:
            if x % p == 0:
                break
        else:
            primes.append(x)
    for p in primes:
        if N <= p:
            print(p)
            break


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 40976
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		System.out.println(cal(a, 0));
	}

	private static int cal(int a, int count) {

		if (a < 6) return count + a;

		int tmp6 = 1;
		int tmp9 = 1;

		while (tmp6 * 6 <= a) tmp6 *= 6;
		while (tmp9 * 9 <= a) tmp9 *= 9;

		return Math.min(cal(a - tmp6, count + 1), cal(a - tmp9, count + 1));
	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int getint() {
	char C;
	while (!isdigit(C = getchar()));
	int x = C - '0';
	while (isdigit(C = getchar())) x = x * 10 + C - '0';
	return x;
}

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


	int N, Q;
	N = getint();
	Q = getint();
	char S[200000];
	rep(i, N) S[i] = getchar();
	char T[200000], D[200000];
	rep(i, Q) {
		getchar();
		T[i] = getchar();
		getchar();
		D[i] = getchar();;
	}
	int L = 0;
	int R = N;
	for (int i = Q - 1; i >= 0; i--) {
		if (R > 0 && D[i] == 'R' && S[R - 1] == T[i]) R--;
		else if (R < N && D[i] == 'L' && S[R] == T[i]) R++;
		if (L > 0 && D[i] == 'R' && S[L - 1] == T[i]) L--;
		else if (L < N && D[i] == 'L' && S[L] == T[i]) L++;
	}

	co(R - L);

	Would you please return 0;
}

Measured memory_bytes: 896
/***/





#include<bits/stdc++.h>

using namespace std;

#define fastinput   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll          long long
#define bn          1000090
#define sn          1010
#define mod         100000007
#define iii(i)      cin>>i
#define ooo(i)      cout<<i
#define sss         cout<<" "
#define nnn         cout<<"\n"/**
#define iii(i)      iii>>i
#define ooo(i)      ooo<<i
#define sss         ooo<<" "
#define nnn         ooo<<"\n"*/
#define ff          first
#define ss          second
#define psb         push_back

/**
        ifstream iii;iii.open("D:\\prgrms\\codechef cntst 1\\input.txt");
        ofstream ooo;ooo.open("D:\\prgrms\\codechef cntst 1\\my output.txt");

		ooo("a a["<<n<<"] = "<<a[n]<<"  yom["<<y<<"] = "<<m[y]);nnn;
*/


ll a[bn];
map<ll,ll>m;

int main()
{
	///fastinput;
	ll n; iii(n);
	for(ll i = 1; i <= n; i++)
	{
		iii(a[i]);
		m[a[i]]++;
		a[i] += a[i-1];
	}
	ll q; iii(q);
	for(ll i = 1; i <= q; i++)
	{
		ll x,y;
		iii(x>>y);
		a[n] += m[x]*(y-x);
		ooo(a[n]); nnn;
		m[y] += m[x]; m[x] = 0;
	}
        return 0;
}




/**



4
1 2 3 4
3
1 2
3 4
2 4












*/















/***/


Measured memory_bytes: 10340
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans


void solve() {
}

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

    int N, X, T;
    cin >> N >> X >> T;
    int ans = 0;
    while (N >= 1) {
        N -= X;
        ans += T;
    }
    cout << ans << endl;

    solve();
    return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  string S;
  cin >> N >> S;

  ll r = 0, g = 0, b = 0;
  REP(i, 0, S.size()) {
    if (S[i] == 'R') {
      r++;
    } else if (S[i] == 'G') {
      g++;
    } else if (S[i] == 'B') {
      b++;
    }
  }

  if (r * g * b == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll m = 0;
  REP(i, 0, N - 1) {
    REP(j, i + 1, N) {
      ll k = 2 * j - i;
      if (k < N && S[i] != S[j] && S[j] != S[k] && S[i] != S[k]) {
        m++;
      }
    }
  }
  cout << r * g * b - m << endl;

  return 0;
}


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

Measured memory_bytes: 580
#include <stdio.h>

int main(void) {

	char S[80];

	fgets(S, 80, stdin);

	if (S[0] == 'S') {
		puts("Cloudy");
	}
	else if (S[0] == 'C') {
		puts("Rainy");
	}
	else {
		puts("Sunny");
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
 
  if (op == "+") {
    cout << A + B << endl;
  }
  else if (op == "-") {
    cout << A - B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N , K;
    cin >> N >> K;
    K = min(N,K);
    string S;
    cin >> S;
    vector<int> a(4*N+2, 0);
    a[0] = 0; a[1] = 0;
    int cnt = 0;
    int nowi = 2;
    char tmpchar = '0';
    for(char i: S){
        if(i == tmpchar){
        }
        else{
            a[nowi] = cnt;
            nowi++;
            tmpchar = i;
        }
        cnt++;
    }
    for(;nowi < 4*N+2; nowi++){
        a[nowi] = cnt;
    }
    int maxi = 0;
    for (int i = 0; i < 4*N-(2*K+1); i += 2) {
        maxi = max(maxi, a[i+2*K+1]-a[i]);
    }
    printf("%d\n", maxi);
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define repb(i,n) for(int i = (int)n;i >= 0;i--)
#define reps(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i,m,n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v,n) sort(v,v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int n,k;
    cin>>n>>k;

    if((n+1)/2>=k)  cout<<"YES"<<endl;
    else  cout<<"NO"<<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() {
    ll N;
    cin >> N;
    ll n = 1, s = 26, p = 26;
    while (N > s) {
        n++;
        p *= 26;
        s += p;
    }
    //cout << "n=" << n << " p=" << p << " s=" << s << "\n";
    ll x = N - (s - p) - 1;
    string ans = "";
    rep(i, n) {
        ans = (char)(x % 26 + 'a') + ans;
        x /= 26;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define previous fake_previous
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL MAXN = 1000001;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	LL n, x, ans = 0;
	cin >> n >> x;

	if (x + x == n)
	{
		cout << 3LL * x << endl;
		return 0;
	}
	if (x + x > n)
		x = n - x;

	ans = n;
	LL d = n -  x;
	while (d && x)
	{
		if (x > d)
			swap(x, d);

		if (x == d)
		{
			ans += x;
			break;
		}

		if (d%x == 0)
		{
			ans += x * (2*(d/x) - 1);
			break;
		}
		
		if (d > x)
		{
			ans += 2LL * (d / x) * x;
			d %= x;
		}
	}

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

Measured memory_bytes: 256
def main():
	inf=10**9
	h,n=map(int,input().split())
	ab=[]
	r=0
	for i in range(n):
		a,b=map(int,input().split())
		ab.append((a,b))
		r=max(r,a)
	#dp[number][damage]
	dp=[[inf for _ in range(r+h)]for _ in range(n+1)]
	for i in range(n+1):
		dp[i][0]=0
	for i in range(n):
		for j in range(r+h):
			if j-ab[i][0]>=0:
				dp[i+1][j]=dp[i+1][j-ab[i][0]]+ab[i][1]
			dp[i+1][j]=min(dp[i][j],dp[i+1][j])
	ans=inf
	for i in range(r):
		ans=min(ans,dp[n][i+h])
	print(ans)
if __name__ == '__main__':
	main()

Measured memory_bytes: 171136
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn is_palindrome(s: &str) -> bool {
// sが回文であるかどうかを判定する
	let mut flag = true;
	let v:Vec<char> = s.chars().collect();
	let L = v.len();
	for n in 0..(L/2) {
		if v[n] != v[L - 1 - n] {
			flag = false;
			break;
		};
	}
	flag
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0].to_string();
	if is_palindrome(&n) {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	int x; cin >> x;

	cout << "ABC" << x << endl;
	return (0);
}

Measured memory_bytes: 256
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    ll x,k,d;
    cin >> x>> k>> d;
    ll a=abs(x)/d;
    if(a>k){
        cout<<abs(x)-d*k<<endl;
        return 0;
    }
    ll b=abs(x)-d*a;
    ll c=abs(abs(x)-d*(a+1));
    if((k-a)%2==0){
        cout<<b<<endl;
    }else if((k-a)%2==1){
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int n, a[101][101];

void SSSP(){
  int i, j, u, min, d[101], c[101];

  for(i=0; i<n; i++){
    d[i]=1000000;
    c[i]=0;
  }
  d[0]=0;
  c[0]=1;
  while(1){
    min=1000000;
    u=-1;
    for(i=0; i<n; i++){
      if(min>d[i] && c[i]!=2){
	u=i;
	min=d[i];
      }
    }
    if(u==-1)break;
    c[u]=2;
    for(j=0; j<n; j++){
      if(c[j]!=2 && a[u][j]!=1000000){
	if(d[j]>d[u]+a[u][j]){
	  d[j]=d[u]+a[u][j];
	  c[j]=1;
	}
      }
    }
  }
  for(i=0; i<n; i++){
    printf("%d ", i);
    if(d[i]==1000000)printf("-1");
    else printf("%d\n", d[i]);
  }
}

int main(){
  int i, j, u, k, c, v;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      a[i][j]=1000000;
    }
  }
  for(i=0; i<n; i++){
    scanf("%d %d", &u, &k);
    for(j=0; j<k; j++){
      scanf("%d %d", &v, &c);
      a[u][v]=c;
    }
  }
  SSSP();

  return 0;
}

  

Measured memory_bytes: 640
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll n, k, diff = pow(10, 9);
	in(n);
	in(k);

	vll h(n);
	rep(i, 0, n) {
		in(h[i]);
	}
	sort(h.begin(), h.end());
	repeq(i, 0, n - k) {
		diff = min(h[i + k - 1] - h[i], diff);
	}
	outn(diff);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NIL NULL

struct node{

  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
 
Node root;

void insert(int k){

  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    
    y = x;
    
    if(z->key < x->key){
      x = x->left;
    }
    else {
      x = x->right;
    }
  }
  
  z->parent = y;
  
  if( y ==  NIL ){
    root = z;
  }
  else if( z->key < y->key ){
    y->left = z;
  }
  else {
    y->right = z;
  }
  
  
}

void inorder(Node u){

  if(u->left != NIL){

    inorder(u->left);
  }

  printf(" %d",u->key);

  if(u->right != NIL){
    
    inorder(u->right);
  }

}
void preorder(Node u){

  printf(" %d",u->key);
  
  if(u->left != NIL){
    preorder(u->left);
  }
  
  if(u->right != NIL){
    preorder(u->right);
  }
  
}

Node find(Node u,int k){

  while(u!=NIL && k!=u->key){
    if(k < u->key) u = u->left;
    else u=u->right;
  }
  return u;
}


int main(){
  int n, i, x;
  char com[20];
  Node T;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);


    /* if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      } else */
    if ( com[0] == 'i' ){
      scanf("%d", &x);
       insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'f' ){
      scanf("%d",&x);
      T = find(root,x);
      if(T != NIL)printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i + 1] == s[i] && i != s.size() - 1) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (b), _a = (a); i >= _a; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<"debug : "<<x<<endl
#define debug2(x,y) cout<<"debug : "<<x<<" | "<<y<<endl
#define debug3(x,y,z) cout<<"debug : "<<x<<" | "<<y<<" | "<<z<<endl
#define debug4(x,y,z,w) cout<<"debug : "<<x<<" | "<<y<<" | "<<z<<" | "<<w<<endl
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define M 1000000007          // 1e9+7
#define INF 10000000000       // 1e9
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;
 
bool cus(pair<int,int> a, pair<int,int> b){
    if(a.ff<b.ff)
        return true;
    if(a.ff>b.ff)
        return false;
    return a.ss<b.ss;
}
 
ll gcd(ll a, ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}

ll dp[2001];
void solve(){
    ll s;
    cin >> s;
    dp[0] = 1;
    dp[1] = 0;
    dp[2] = 0;
    fr(i, 3, s){
        dp[i] = 0;
        fr(j, 3, s){
            if(j <= i) dp[i] = (dp[i]%M + dp[i - j]%M)%M;
        }
    }
    cout << dp[s] << endl;

  }

int main () 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(11);
 
    //ll t = 1;
    //cin>>t;
    //while(t--)
        solve();
 
    return 0;
}
  

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  char s;
  ll A, B;
  cin >> A >> s >> B;
  if (s == '+')
  {
    cout << A + B << endl;
  }else{
    cout << A - B <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    int N, K, S;  cin >> N >> K >> S;
    vector<int> ans(N);
    int notS;
    if(S + 1 > 1e9){
        notS = 1e9 - 1;
    }else {
        notS = S + 1;
    }

    if(K == 0){
        for(int i=0; i<N; i++){
            ans[i] = notS;
        }
    }else{
        for(int i=0; i<K; i++){
            ans[i] = S;
        }
        for(int i=K; i<N; i++){
            ans[i] = notS;
        }
    }

    for(auto a: ans){
        cout << a << " ";
    }cout << endl;
}   

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

using namespace std;

int main(){
    int N; cin >> N;
    int K; cin >> K;
    int max = N - K;
    if(K == 1){
        cout << '0' << endl;
    }
    else{
        cout << max << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define endl "\n"
using namespace std;


void solve(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll suff[n];
	suff[n-1]=a[n-1];
	for(ll i=n-2;i>=0;i--){
		suff[i]=(suff[i+1]+a[i])%mod;
	}
	ll ans=0;
	for(ll i=0;i<n-1;i++){
		ll x=suff[i+1];
		ll y=a[i];
		ans=(ans+(x*y)%mod)%mod;
	}
	cout<<ans<<endl;
}


int main(){
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 6728
#include<stdio.h>

int main(){
  int A,B,hoge,foo,ans;
  scanf("%d %d",&A,&B);
  hoge=A+B;
  foo=A-B;
  ans=A*B;
  if(hoge>=foo&&hoge>=ans){
    printf("%d\n",hoge);
  }else if(foo>=hoge&&foo>=ans){
    printf("%d\n",foo);
  }else{
    printf("%d\n",ans);
  }
  return(0);
}


Measured memory_bytes: 128
from collections import deque

sa = deque(list(input()))
sb = deque(list(input()))
sc = deque(list(input()))

x = "a"
while True:
    if x=="a" and len(sa)==0:
        print("A")
        exit()
    elif x=="b" and len(sb)==0:
        print("B")
        exit()
    elif x=="c" and len(sc)==0:
        print("C")
        exit()
    
    if x=="a":
        x = sa.popleft()
    elif x=="b":
        x = sb.popleft()
    elif x=="c":
        x = sc.popleft()


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){
  
  int n,i=1;
  cin >> n;
  
  while(1){
    i*= 2;
    if(i > n) break;
  }
  
  cout << i/2 << endl;



 return 0;
}

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

int main(){
  int N,L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
    cout << S.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    ll old = 0;
    ll tenN = 1;
    for(int i=0; i<s.size(); ++i) {
        old = old * 10 + (s[i]-'0');
        tenN *= 10;
    }
    vector<int> v={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    ll res = 0, memo = 0;
    do {
        ll t = 0;
        for(int i=0; i<s.size(); ++i) {
            t = t*10 + v[i];
        }
        ll t2 = abs(old - t);
        ll t3 = min(tenN - t2, t2);
        if(memo < t3) {
            res = t;
            memo = t3;
        }
    } while(next_permutation(v.begin(), v.end()));
    string ret;
    for(int i=0; i<s.size(); ++i) {
        tenN /= 10;
        ret += (res/tenN) + '0';
        res = res - (res/tenN)*tenN;
    }
    cout << ret << endl;
}


Measured memory_bytes: 3176
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, K = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))
A = np.array(A, dtype=float)


def test(l):
    # l 以下にできますか
    return np.ceil(A / l - 1).sum() <= K


ok = A.max() + 1
ng = 1e-9
while abs(ok - ng) > 1e-2:
    mid = (ok + ng) / 2
    if test(mid):
        ok = mid
    else:
        ng = mid
ans = math.ceil(ng)
print(ans)


Measured memory_bytes: 46144
#include<bits/stdc++.h>            //  IT'S NEVER TOO LATE...
    	using namespace std;
        #include<math.h>
    	#define ll long long
    	#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
        #define forn(i, n) fore(i, 0, n)
        #define fori(i, l, r) fore(i, l, (r) + 1)
        #define sz(v) int((v).size())
        #define all(v) (v).begin(), (v).end()
        #define pb push_back
        #define mp make_pair
        #define ff first
        #define ss second

        const double PI = atan(1)*4;

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

    	
    	vector<int> ar[1000001];
        vector<pair<int,int>> path;
        int vis[1000001],dis[1000001];

        /*void dfs(int node)
        {
            vis[node]=1;

            for(int child : ar[node])
            {
                if(vis[child]==0)
                {
                    dis[child]=dis[node]+1;
                    dfs(child);
                }
            }
        }*/

    /*    void bfs(int i)
        {
            queue<int> q;
            q.push(i);
            vis[i]=1;
            dis[i]=0;

            while(!q.empty())
            {
                int curr=q.front();
                q.pop();

                for(int child : ar[curr])
                    if(vis[child]==0)
                    {
                        q.push(child);
                        dis[child]=dis[curr]+1;
                        vis[child]=1;
                    }
            }
        }*/

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

        bool comp(pair<int,int> a, pair<int,int> b)
        {
            return b.ff < a.ff ;
        }

        int modpow(int b,int p,int m)
        {
            if(p==0) return 1%m;
            if(p%2) return (b*modpow(b,p-1,m))%m;
            int u=modpow(b,p/2,m);
            return (u*u)%m;
        }

    	int main()  
    	{

    		
    		int t=1;
    		//cin>>t;
    		
    		while(t--)
    		{
                int x,y,ok=0;
                cin>>x>>y;

                fori(i,0,100)
                {
                    fori(j,0,100)
                    {
                        if(i+j==x && 4*i+2*j==y)
                        {
                            ok=1;
                            break;
                        }

                        if(i>x || j>x)
                            break;
                    }
                } 

                if(ok)
                cout<<"Yes";
                else
                cout<<"No";     

            }
            return 0;
    	}

        //              NOW IT'S TIME TO WAKE UP...

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

void search(int y, int x, char field[12][13]) {
    field[y][x] = '0';
    for (int nx = x - 1; nx <= x + 1; nx += 2) {
        if (0 <= nx && nx < 12 && field[y][nx] == '1') {
            search(y, nx, field);
        }
    }
    for (int ny = y - 1; ny <= y + 1; ny += 2) {
        if (0 <= ny && ny < 12 && field[ny][x] == '1') {
            search(ny, x, field);
        }
    }
}

int main() {
    char field[12][13];
    while (cin >> field[0]) {
        for (int i = 1; i < 12; i++) {
            cin >> field[i];
        }
        int islandNum = 0;
        for (int i = 0; i < 12; i++) {
            for (int j = 0; j < 12; j++) {
                if (field[i][j] == '1') {
                    search(i, j, field);
                    islandNum++;
                }
            }
        }
        cout << islandNum << endl;
    }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define ASC(vec) vec.begin(), vec.end()			// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
typedef long long ll;

int main() 
{
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;

	for (int i = 0; i < N; i++)
	{
		int val; cin >> val;
			X = max(X, val);
	}

	for (int i = 0; i < M; i++)
	{
		int val; cin >> val;
		Y = min(Y, val);
	}

	if (X < Y)
	{
		cout << "No War" << endl;
	}
	else
	{
		cout << "War" << endl;
	}
}

Measured memory_bytes: 256
//Chandigarh University
//author:- shivamkr21
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int l[m],r[m],ll=1,rr=n;
  for(int i=0;i<m;i++)
  {
    cin>>l[i]>>r[i];
    if(ll<l[i])
    {
      ll=l[i];
    }
    if(rr>r[i])
    {
      rr=r[i];
    }
  }
  if(rr<ll)
    cout<<0;
  else
  cout<<rr-ll+1;

  return 0;
}


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

ll g(ll a,ll b){
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}
int main(){
  ll i,j,k,cnt=0;
  ll n;
  cin>>n;
  for(i=1;4*i<=3*n;i++){
    for(j=i;j<=3500;j++){
      ll m=n/g(n,4*i*j);
      for(k=0;k<=3500;k+=m){
        if(n*(i*j+j*k+k*i)==4*i*j*k){
          cout<<i<<" "<<j<<" "<<k<<endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
    return 0;
};

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){

  int *A,i,minj,n,j,k,s=0;

  scanf("%d",&n);

  A=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  for(i=0;i<n;i++){
    minj=i;
    for(j=i+1;j<n;j++){
      if(A[j]<A[minj]){
	
	minj=j;
      }}
    if(i !=minj){
    	k=A[i];
	A[i]=A[minj];
	A[minj]=k;s++;}
      }
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i !=n-1)printf(" ");
  }printf("\n");
  printf("%d\n",s);
  return 0;
}



Measured memory_bytes: 2100
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[N], B[N];
    ll AB[N], BB[N];
    REP(i, 0, N) {
        cin >> A[i];
        AB[i] = A[i];
    }
    REP(i, 0, N) {
        cin >> B[i];
        BB[i] = B[i];
    }
    sort(AB, AB + N);
    sort(BB, BB + N);
    bool ok = true;
    REP(i, 0, N) {
        if (AB[i] > BB[i]) {
            ok = false;
        }
    }
    if (!ok) {
        cout << "No" << endl;
        return 0;
    }
    bool okb = false;
    REP(i, 1, N) {
        if (AB[i] <= BB[i - 1]) {
            okb = true;
        }
    }
    if (okb) {
        cout << "Yes" << endl;
        return 0;
    }
    plglg C[N], D[N];
    REP(i, 0, N) {
        C[i] = plglg(A[i], i);
        D[i] = plglg(B[i], i);
    }
    sort(C, C + N);
    sort(D, D + N);
    plglg CB[N], DB[N];
    REP(i, 0, N) {
        CB[i] = plglg(C[i].second, i);
        DB[i] = plglg(D[i].second, i);
    }
    sort(CB, CB + N);
    sort(DB, DB + N);
    bool mark[N];
    fill(mark, mark + N, false);
    ll num = 0;
    ll next = 0;
    REP(i, 0, N) {
        mark[next] = true;
        num++;
        next = D[CB[next].second].second;
        if (mark[next]) {
            break;
        }
    }
    if (num < N) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 9728
N = int(input())
E = [[] for x in range(N)]
D = [0]*N
L = [0]*N
for i in range(N-1):
    u,v,w = map(int,input().split(" "))
    u -= 1
    v -= 1
    E[u].append([v,w])
    E[v].append([u,w])

q = [[-1,0,0]]
while len(q):
    root,to,dis = q.pop()
    L[to] = 1
    if root != -1:
        D[to] = D[root] + dis
    for t,d in E[to]:
        if L[t]:
            continue
        q.append([to,t,d])

for d in D:
    print(d%2)

Measured memory_bytes: 51784
class SegmentTree:
    def __init__(self, a):
        self.padding = 0
        self.n = len(a)
        self.N = 2 ** (self.n-1).bit_length()
        self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        for i in range(2*self.N-2, 0, -2):
            self.seg_data[(i-1)//2] = self.seg_data[i] + self.seg_data[i-1]
    
    def __len__(self):
        return self.n
    
    def update(self, i, x):
        idx = self.N - 1 + i
        self.seg_data[idx] += x
        while idx:
            idx = (idx-1) // 2
            self.seg_data[idx] = self.seg_data[2*idx+1] + self.seg_data[2*idx+2]
    
    def query(self, i, j):
        # [i, j)
        if i == j:
            return self.seg_data[self.N - 1 + i]
        else:
            idx1 = self.N - 1 + i
            idx2 = self.N - 2 + j # 閉区間にする
            result = self.padding
            while idx1 < idx2 + 1:
                if idx1&1 == 0: # idx1が偶数
                    result = result + self.seg_data[idx1]
                if idx2&1 == 1: # idx2が奇数
                    result = result + self.seg_data[idx2]
                    idx2 -= 1
                
                idx1 //= 2
                idx2 = (idx2 - 1)//2
            return result
    
    @property
    def data(self):
        return self.seg_data[self.N-1:self.N-1+self.n]


N, K = map(int, input().split())
A = list(map(int, input().split()))
max_a = max(A)
MOD = 10**9 + 7

st = SegmentTree([0]*(max_a + 1))

num = 0
for a in A:
    st.update(a, 1)
    if a == max_a:
        continue
    num += st.query(a+1, max_a+1)

num_larger = 0
for a in A:
    if a == max_a:
        continue
    num_larger += st.query(a+1, max_a+1)

ans = ((num*K % MOD) + ((K*(K-1)//2)*num_larger) % MOD) % MOD
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int n,k,i,j,ans[200001],cnt,t,p;
int main()
{
   cin>>n>>k;
   for(i=1;i<=n;++i)
   {
   		cin>>t;
   		ans[t]++;
   }
   sort(ans+1,ans+n+1);
   for(i=n;i>n-k;--i)cnt+=ans[i];
   cout<<n-cnt<<endl;
   return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{

int a,b,c,d;
int x,y;
cin>>a>>b>>c>>d;

for(int i=0;i<200;i++)
{
a-=d;
if(a<=0){x=i;break;}
}

for(int i=0;i<200;i++)
{
c-=b;
if(c<=0){y=i;break;}
}

if(x>=y)cout <<"Yes";
else cout <<"No";
  
}

Measured memory_bytes: 3624