akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1001001000;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, n;
    int ans = Inf;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) {
      cin >> h[i];
    }
    sort(h.begin(), h.end());

    rep(i, n - k + 1) {
      ans = min(ans, h[i + k - 1] - h[i]);
    }

    cout << ans << '\n';

    return 0;
}


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

int f(int a){
	int ans = 0;
	while(0 < a){
		ans += a%10;
		a /= 10;
	}
	return ans;
}

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

	int ans = 1000000;
	for(int i = 1; i < n; i++){
		int a = f(i);
		int b = f(n-i);
		ans = min(ans, (a+b));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def output(i):
    symbol = []
    for j in range(n):
        if i>>j & 1:
            symbol.append('+')
        else:
            symbol.append('-')
    out =''
    for k in range(3):
        out += str(a[k]) + symbol[k]
    out += str(a[3])+'=7'
    print(out)

s = list(input())
a = list(map(int, s))

n = 3
comb= 2**n

for i in range(comb):
    x = a[0]
    #print('i=', i, '{:03b}'.format(i))
    for j in range(n):
        if i>>j & 1:            
            x += a[j+1]
            #print('+', j, i>>j & 1, a[j+1], x)
        else:
            x -= a[j+1]
            #print('-', j, i>>j & 1, a[j+1], x)
        
    if x ==7:
        #print(str(bin(i)))
        output(i)
        break

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, M;
vll X, Y;

int main() {
    cin >> N >> M;
    X.resize(N);
    Y.resize(M);
    rep(i, N) cin >> X[i];
    rep(i, M) cin >> Y[i];

    vll dxsum(N);
    dxsum[1] = (X[1] - X[0]) % MOD;
    ll xsum = dxsum[1];
    rep(i, 2, N) {
        dxsum[i] = dxsum[i - 1] + (X[i] - X[i - 1]) % MOD * i;
        dxsum[i] %= MOD;
        xsum += dxsum[i];
        xsum %= MOD;
    }

    vll dysum(M);
    dysum[1] = (Y[1] - Y[0]) % MOD;
    ll ysum = dysum[1];
    rep(i, 2, M) {
        dysum[i] = dysum[i - 1] + (Y[i] - Y[i - 1]) % MOD * i;
        dysum[i] %= MOD;
        ysum += dysum[i];
        ysum %= MOD;
    }

    write(xsum * ysum % MOD);
}

Measured memory_bytes: 3456
//
//  main.cpp
//  A
//
//  Created by Hashizo on 2020/01/10.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
int main(int argc, const char * argv[]) {


	ll k,x;
	cin >> k >> x;

	if ((500 * k) >=  x ) {
		
		cout << "Yes" << endl;

	}
	else {
		cout << "No" << endl;

	}

	return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define N 1010
#define M 2010
struct edge { ll from, to, cost; };
vector<edge> es(M);

vl d(N, INF);
ll n, m;

//trueを返す場合、頂点以上に更新チェック→負のコストの閉ループあり
bool bellman_ford(ll s, ll k) {
	int i;
	d[s] = 0;
	ll cnt = 0;
	bool updateFlag;
	while (true) {
		updateFlag = false;
		for (i = 0; i < m; i++) {
			if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost) {
				d[es[i].to] = d[es[i].from] + es[i].cost;
				updateFlag = true;
			}
		}

		if (cnt == n - 1 + k) return true;
		if (!updateFlag) break;

		cnt += 1;
	}

	return false;
}
int main() {
	cin >> n >> m;
	int i, j, k;
	for (i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		c *= -1;
		es[i].from = a - 1;
		es[i].to = b - 1;
		es[i].cost = c;
	}
	bellman_ford(0, 0);
	ll ans1 = d[n - 1];
	for (i = 0; i < n; i++) {
		d[i] = INF;
	}
	bellman_ford(0, 2000);
	ll ans2 = d[n - 1];
	if (ans1 != ans2) {
		cout << "inf" << endl;
	}
	else {
		cout << ans1*(-1) << endl;
	}
}

Measured memory_bytes: 256
s = input()  # 等比数列。こうひ2
n = 0
unchi = int(s)
ans = 0

while unchi > 1:
    unchi = int(unchi) // 2
    # print(unchi)
    n += 1

# for i in range(int(s)):  # 割りまくる
#     unchi = int(s) // 2

# print("")
# print("")
# print(n)
# print("")
# print("")

for i in range(n):
    # print(i)
    ans += 2**(i+1)
    # print(ans)

print(ans+1)


Measured memory_bytes: 2940
H, W, A, B = map(int, input().split())
ans = []
for i in range(H):
    if i < B:
       row = [1] * A
       row.extend([0] * (W - A))
    else:
        row = [0] * A
        row.extend([1] * (W - A))
    ans.append(row)
for row in ans:
    print(*row, sep='')


Measured memory_bytes: 14324
from math import log10


def S(x):
    a = [int(i) for i in str(x)]
    return sum(a)

def f(N):
    tmp = (N, N / S(N))
    for d in range(int(log10(N) - 1) + 1):
        x = pow(10, d + 1) * int(N / pow(10, d + 1) + 1) - 1
        sunuke = x / S(x)
        if tmp[1] > sunuke:
            tmp = (x, sunuke)
    return tmp[0]


K = int(input())
ans = [1]
N = 1
K -= 1
while K > 0:
    N = f(N + 1)
    ans.append(N)
    K -= 1

print(*ans, sep='\n')


Measured memory_bytes: 43116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buff = null;
		buff = new BufferedReader(new InputStreamReader(System.in));

		String S = buff.readLine();

		S = S.replace("eraser", "1");
		S = S.replace("erase", "1");
		S = S.replace("dreamer", "1");
		S = S.replace("dream", "1");
		S = S.replace("1", "");
		System.out.println(S.equals("") ? "YES" : "NO");
	}

	static long f() {
		long ans = 0;

		return ans;
	}
}

Measured memory_bytes: 27732
import sys
n = int(input())
d = {}
lines = sys.stdin.readlines()
ans = [None] * n
for i in range(n):
    q, *arg = lines[i].split()
    if q == '0':
        d[arg[0]] = arg[1]
    elif q == '1':
        ans[i] = d[arg[0]] if arg[0] in d else 0
    elif q == '2':
        if arg[0] in d:
            del d[arg[0]]
 
[print(x) for x in ans if x is not None]


Measured memory_bytes: 59576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    long long n,i,j,k,l,a,b;
    cin>>s;
    i=s[0]-'0';
    j=s[1]-'0';
    k=s[2]-'0';
    l=s[3]-'0';
    if((i+j+k+l)==7)
    {
        cout<<i<<"+"<<j<<"+"<<k<<"+"<<l<<"="<<7<<endl;
    }
    else if((i+j+k-l)==7)
    {
        cout<<i<<"+"<<j<<"+"<<k<<"-"<<l<<"="<<7<<endl;
    }
    else if((i+j-k+l)==7)
    {
        cout<<i<<"+"<<j<<"-"<<k<<"+"<<l<<"="<<7<<endl;
    }
    else if((i+j-k-l)==7)
    {
        cout<<i<<"+"<<j<<"-"<<k<<"-"<<l<<"="<<7<<endl;
    }
    else if((i-j+k+l)==7)
    {
        cout<<i<<"-"<<j<<"+"<<k<<"+"<<l<<"="<<7<<endl;
    }
    else if((i-j+k-l)==7)
    {
        cout<<i<<"-"<<j<<"+"<<k<<"-"<<l<<"="<<7<<endl;
    }
    else if((i-j-k+l)==7)
    {
        cout<<i<<"-"<<j<<"-"<<k<<"+"<<l<<"="<<7<<endl;
    }
    else if((i-j-k-l)==7)
    {
        cout<<i<<"-"<<j<<"-"<<k<<"-"<<l<<"="<<7<<endl;
    }

return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0042
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int k = 0;
            while (true)
            {
                k++;

                int w = RInt();
                if (w == 0) return;

                int cnt = RInt();
                int[] dp = new int[w + 1];

                for (int i = 0 ; i < cnt ; i++)
                {
                    int[] items = RIntAr(',');
                    for (int j = w ; j >= 0 ; j--)
                    {
                        dp[j] = (j >= items[1]) ? Math.Max(dp[j], dp[j - items[1]] + items[0]) : dp[j];
                    }
                }

                Console.WriteLine("Case {0}:", k);
                Console.WriteLine(dp[w]);
                for (int i = w ; i >= 0 ; i--)
                {
                    if (dp[i] != dp[w])
                    {
                        Console.WriteLine(i + 1);
                        break;
                    }
                }
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 17932
kp = list(map(int, input().rsplit()))
A = list(map(int, input().rsplit()))
max_range = kp[0]-A[-1]+A[0]
for idx in range(len(A)-1):
  dif = A[idx+1]-A[idx] 
  if dif >max_range:
    max_range = dif
 
print(kp[0] - max_range)

Measured memory_bytes: 25840
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    O = input()
    E = input()

    ans = ""
    for i in range(len(E)):
        ans += O[i] + E[i]
    if len(O) != len(E):
        ans += O[-1]
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 4072
<?php

fscanf(STDIN,'%d',$count);

$max=1-10**9;
for($i=0;$i<$count;$i++) {
  fscanf(STDIN,'%d',$n);
  if($i===0){
    $min = $n;
  }else if($i===1){
    $max=$n-$min;
  }
  if($max<$n-$min){
    $max=$n-$min;
  }
  if($n<$min){
    $min=$n;
  }
}
echo $max . PHP_EOL;


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

int main() {
  vector<int>A;
  A={0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  cin>>x>>y;
  if(A.at(x)==A.at(y)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}  


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

const ll INF = 1e+18 + 10;
const int MAX_N = 100;
ll dp[MAX_N][MAX_N];

int main()
{
    int n;
    cin >> n;
    vector<int> r;

    for (int i = 0; i < n; i++)
    {
        int row, col;
        cin >> row >> col;
        if (i == 0)
        {
            r.push_back(row);
        }
        r.push_back(col);
    }

    // DPの初期化
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i == j)
            {
                dp[i][i] = 0;
            }
            else
            {
                dp[i][j] = INF;
            }
        }
    }

    // DPの更新
    for (int j = 1; j < n; j++)
    {
        for (int i = 0; i + j < n; i++)
        {
            for (int k = 0; k <= i + j; k++)
            {
                ll prod = r[i] * r[k + 1] * r[i + j + 1];
                dp[i][i + j] = min(dp[i][i + j], dp[i][k] + dp[k + 1][i + j] + prod);
            }
        }
    }

    cout << dp[0][n - 1] << endl;
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

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

	vector<lld> p(n);
	p[0]=0;
	lld cur_min = a[0];
	for(int i = 1; i < n; i++)
	{
		p[i] = max((lld)0,a[i] - cur_min);
		cur_min = min(cur_min,a[i]);
	}

	lld max_p = -1;
	for(int i = 0; i < n; i++)
	{
		max_p = max(max_p,p[i]);
	}
	lld ans = 0;
	for(int i = 0; i < n; i++)
	{
		if (p[i]==max_p)
		{
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
//use proconio::{input, fastout};
use proconio::input;

//#[fastout]
fn main() {
    input! {
        n: usize,
        p: [f64; n],
    }
    let mut dp = vec![0.0; n + 1];
    dp[0] = 1.0;
    for i in 0..n {
        for j in (1..=(i + 1)).rev() {
            dp[j] = dp[j] * (1.0 - p[i]) + dp[j - 1] * p[i];
        }
        dp[0] = dp[0] * (1.0 - p[i]);
    }

    let mut r = 0.0;
    for i in (n / 2 + 1)..=n {
        r += dp[i];
    }
    println!("{}", r);
}


Measured memory_bytes: 2264
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}


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

using namespace std;
using lint = long long;

lint k,a,b;

lint solve()
{
    if(b-a <= 2) return k+1;
    if(k <= a) return k+1;
    lint x=1;
    k -= (a-1);
    x += (a-1);
    if(k % 2 == 1) {
        k--;
        x++;
    }
    x += (k/2) * (b-a);
    return x;
}

int main()
{
    cin >> k >> a >> b;
    cout << solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int n,W;
    cin>>n>>W;
    int64_t sum=0;
    vector<int64_t> w(n),v(n);
    rep(i,n){
        cin>>w[i]>>v[i];
        sum += v[i];
    }
    vector<vector<int64_t>> dp(n+1,vector<int64_t> (sum+1,0));
    for(int j=1;j<=sum;j++){
        dp[0][j] = 1e13;
    }

    rep(i,n){
        rep(j,sum+1){
            if(j-v[i]>=0 && dp[i][j-v[i]]!=-1){
                    dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]);
                }
            else{
                dp[i+1][j] = dp[i][j];
            }
            
        }
    }
    /*
    rep(i,sum+1){
        cout<<i<<" ";
    }
    cout<<endl;
    rep(i,n+1){
        rep(j,sum+1){
            if(dp[i][j]==1e13){
                cout<<"No"<<" ";
            }
            else{
                cout<<dp[i][j]<<" ";
            }
        }
        cout<<endl;
    }
    */
    for(int j = sum;j>=0;j--){
        //int64_t ans=
        rep(i,n+1){
            if(dp[i][j]<=W ){
                cout<<j<<endl;
                return 0;
            }
        }
    }
}

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




class Main{


	static	ArrayList<Integer> one ;
	static	ArrayList<Integer> two ;
	static	ArrayList<Integer> three ;
	static	ArrayList<Integer> four ;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		String x = sc.next();
		String y = sc.next();
		String z = sc.next();

		System.out.print(Character.toUpperCase(x.charAt(0)));	
		System.out.print(Character.toUpperCase(y.charAt(0)));		
		System.out.print(Character.toUpperCase(z.charAt(0)));		

	}

}

class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 21972
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int ans = Math.max(a + b, Math.max(a - b, a * b));
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, ans = 0, c;
    cin >> n;
    vector<int> v(n);
    for (int i = n; i--; ) cin >> v[i];
    for (int i = n; i--; ) {cin >> c; ans += max(v[i] - c, 0);}
    cout << ans << endl;
}

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

void search(int last, int s, int n)
{
    if(n==0){
        if(s==0) c++;
        return;
    }
    if(n==1){
        if(last<s&&s<10) c++;
        return;
    }
    --n;
    for(int i=last+1; i<10; i++){
        search(i, s-i, n);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true){
        int n, s;
        cin>>n>>s;
        if(n==0&&s==0) break;
        c=0;
        for(int i=0; i<10; i++){
            search(i, s-i, n-1);
        }
        cout<<c<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3104
MOD = 10 ** 9 + 7
N = int(input())
x = list(map(int, input().split()))
x.sort()
 
kaijo = [1]
for i in range(1, N):
    kaijo.append(kaijo[-1] * i % MOD)
 
ans = 0
for i in range(N - 1):
    ans = (ans * (i + 1) + (x[-1] - x[i]) * kaijo[i]) % MOD
 
print(ans)

Measured memory_bytes: 15020
import scala.math.abs

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  sc.useDelimiter("\n")
  val N = sc.nextInt()
  val K = sc.nextInt()
  val X = sc.next().split(' ').map(_.toInt).toList
  val ans = for ((x, i) <- X.zipWithIndex) yield {
    if (x < abs(K - x)) {
      x * 2
    } else {
      abs(K - x) * 2
    }
  }
  println(ans.sum)

}

Measured memory_bytes: 55660
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector <int> v(n, 0);
    if (n != 1)
    v[0] = 1;
    map <int, int> q;
    vector <pair <int, int> > p(m);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        p[i] = mp(a, b);
    }
    for (int i = 0; i< m; i++){
        if ((n != 1)&&(p[i].F == 1)&&(p[i].S == 0)){
            cout << -1;
            return 0;
        }
        else if (!q[p[i].F]){
            v[p[i].F-1] = p[i].S;
            q[p[i].F] = 1;
        }
        else if ((q[p[i].F])&&(v[p[i].F-1] != p[i].S)){
            cout << -1;
            return 0;
        }
    }
    for (int x : v) cout << x;
    return 0;
}




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

using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 0; i < n; ++i){
		if(a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0)){
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
$n=<>;$s=<>;
$o=0;
for(1..$n-1){
    $l=substr($s,0,$_);
    $r=substr($s,$_);
    $c=0;
    for $x(a..z){
        $c++ if ($l=~/$x/ and $r=~/$x/);
    }
    $o=$o>$c?$o:$c;
}
print $o

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

struct Card {char suit, value;};

void BubbleSort(struct Card A[], int N) {
    rep(i, N) {
        for(int j = N - 1; j >= i; j--) {
            if(A[j].value < A[j - 1].value) {
                swap(A[j], A[j - 1]);
            }
        }
    }
}

void SelectionSort(struct Card A[], int N) {
    rep(i, N) {
        int minj = i;
        for(int j = i; j < N; j++) {
            if(A[j].value < A[minj].value) {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
    }
}

void print(struct Card A[], int N) {
    rep(i, N) {
        if(i) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
    rep(i, N) {
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

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

    int n; cin >> n;
    Card C1[100], C2[100];
    rep(i, n) cin >> C1[i].suit >> C1[i].value;
    rep(i, n) C2[i] = C1[i];

    BubbleSort(C1, n);
    SelectionSort(C2, n);

    print(C1, n);
    cout << "Stable" << endl;
    print(C2, n);
    if(isStable(C1, C2, n)) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n;
multiset<pair<LL, LL>> ML, MR, ml, mr;
LL sum, pos;

void R() {
	auto e = *(ml.rbegin());
	
	if(pos < e.FI) {
		sum += e.FI - pos;
		pos = e.FI;
	}
	if(inII(pos, e.FI, e.SE)) {
		
	}
	if(e.SE < pos) {
		sum += pos - e.SE;
		pos = e.SE;
	}
	
	ml.erase(ml.find(e)); swap(e.FI, e.SE);
	mr.erase(mr.find(e));
}

void L() {
	auto e = *(mr.begin());
	swap(e.FI, e.SE);
	
	if(pos < e.FI) {
		sum += e.FI - pos;
		pos = e.FI;
	}
	if(inII(pos, e.FI, e.SE)) {
		
	}
	if(e.SE < pos) {
		sum += pos - e.SE;
		pos = e.SE;
	}
	
	ml.erase(ml.find(e)); swap(e.FI, e.SE);
	mr.erase(mr.find(e));
}

LL f(int x) {
	ml = ML;
	mr = MR;
	sum = 0;
	pos = 0;
	inc(i, n) { (i % 2 == x ? L : R)(); }
	
	return sum + abs(pos);
}

int main() {
	cin >> n;
	inc(i, n) {
		LL l, r;
		cin >> l >> r;
		ML.emplace(l, r);
		MR.emplace(r, l);
	}
	
	cout << max(f(0), f(1)) << endl;
	
	return 0;
}


Measured memory_bytes: 26368
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	Bag[] bags;
	int n;
	
	boolean ok(int x) {
		if( x == 0 ) return true;
		long sum = 0;
		
		PriorityQueue<Bag> que = new PriorityQueue<Bag>(1, new Comp());
		
		for(int i=0;i<x-1;i++) que.add(bags[i]);
		
		for(int i=0;i<x-1;i++) sum += bags[i].a;
		
		debug(x, sum);
		for (Bag bag: que) debug(" ", bag.a);
		
		for(int i=x-1;i<n;i++) {
			long min = (long)x * bags[i].b - bags[i].a;
			if( sum <= min ) return true;
			sum += bags[i].a;
			que.add(bags[i]);
			sum -= que.remove().a;
		}
		
		return false;
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		bags = new Bag[n];
		
		for(int i=0;i<n;i++) bags[i] = new Bag(Integer.parseInt( sc.next() ), Integer.parseInt( sc.next() ) );
		sort(bags);
		
		for(Bag bag: bags) debug(bag.a, bag.b);
		
		int l = 0, r = n;
		
		while( r-l>1 ) {
			int c = (l+r) / 2;
			if( ok(c) ) l = c;
			else r = c;
		}
		System.out.println(ok(r)? r:l);
	}
	
	class Bag implements Comparable<Bag>{
		int a, b;
		Bag(int a, int b) {
			this.a = a;
			this.b = b;
		}
		@Override
		public int compareTo(Bag o) {
			// TODO 自動生成されたメソッド・スタブ
			return o.b - b;
		}
	}
	
	class Comp implements Comparator<Bag> {

		@Override
		public int compare(Bag o1, Bag o2) {
			// TODO 自動生成されたメソッド・スタブ
			return o2.a - o1.a;
		}
		
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
//		System.err.println(Arrays.deepToString(os));
	}
}

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

const int MAXN = 100010;

int n, ans, c, k, t[MAXN];

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	scanf( "%d%d%d", &n, &c, &k );
	for( int i = 1 ; i <= n ; i++ ) scanf( "%d", &t[ i ] );
	sort( t + 1, t + n + 1 );
	for( int i = 1, j = 1 ; i <= n ; ans++, i = j )
		while( j <= n && j - i + 1 <= c && t[ j ] <= t[ i ] + k ) j++;
	return printf( "%d\n", ans ), 0;
}


Measured memory_bytes: 640
N = int(input())
T = list(map(int, input().split()))
M = int(input())

ans = []

for i in range(M):
    P, X = map(int, input().split())
    l = [j for j in T]
    l[P-1] = X
    ans.append(sum(l))
print('\n'.join(map(str, ans)))

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

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

const int maxn = 1e3 + 3;
const int mod = 1e9 + 7;

int n, k;
int a[maxn];
int C[maxn][maxn];
int dp[21][maxn];

/*int mul(vector<int> v) {
	int ret = 1;
	for(int x : v) {
		ret = ((ll)ret * (ll)x) % mod;
	} return ret;
}*/

int mul() { return 1; }
template <typename T, typename... V>
T mul(T x, V... v) {
	return ((ll)x * mul(v...)) % mod;
}

int main(int argc, char const *argv[])
{
#ifdef LOCAL
	freopen("in", "r", stdin);
#endif
	for(int i = 0; i < maxn; i++) {
		C[i][i] = C[i][0] = 1;
	}
	for(int i = 1; i < maxn; i++) {
		for(int j = 1; j < i; j++) {
			C[i][j] = C[i-1][j] + C[i-1][j-1];
			if(C[i][j] >= mod) C[i][j] -= mod;
		}
	}
	cin >> n >> k;
	for(int i = 1; i <= k; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for(int i = 1; i <= k; i++) {
		dp[i][0] = mul(dp[i-1][0], C[n][a[i]]);
		for(int j = 1; j <= n; j++) {
			for(int tek = 0; tek <= j and tek <= a[i]; tek++) {
				dp[i][j] += mul(dp[i-1][j-tek], C[j][tek], C[n-tek][a[i]-tek]);
				if(dp[i][j] >= mod) dp[i][j] -= mod;
			}
		}
	}
	cout << dp[k][n] << endl;
	return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	ll q,n,k,input;
	vector<ll> v;
	cin>>n>>k>>q;
	REP(i,0,n-1)
		v.push_back(k-q);
	REP(i,0,q-1)
	{
		ll a;
		cin>>a;
		v[a-1]=v[a-1]+1;
	}
	REP(i,0,n-1)
	{
		if(v[i]>0)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
}

Measured memory_bytes: 1524
#include <iostream>
using namespace std;
typedef long long ll;
#define MAX_N 100000
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    ll dp[MAX_N + 10];
    for (int i = 0; i <= MAX_N; i++) dp[i] = INF;

    dp[0] = 0;
    for (int i = 0; i <= n; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        for (int j = 6; i + j <= n; j *= 6) dp[i + j] = min(dp[i + j], dp[i] + 1);
        for (int k = 9; i + k <= n; k *= 9) dp[i + k] = min(dp[i + k], dp[i] + 1);
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int N;
  N = n;
  
  int N_sum = 0;
  while (N > 0) {
    N_sum += N % 10;
    N /= 10;
  }
  
  if (n % N_sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var ans int
	for i := a; i <= b; i++ {
		v := strconv.Itoa(i)
		if v[0] == v[4] && v[1] == v[3] {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main(){
    int W;
    int H;

    cin >> H >> W;

    while(W != 0 && H != 0){
        for (int x=1; x <= H; x++){
             for (int y=1; y <= W; y++){
                 cout << '#';
            } 
             cout << endl;
        }

        cout << endl;

         cin >> H >> W;
    }

    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

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

  int N,K,X,Y;
  cin >> N >> K >> X >> Y;

  cout << min(K, N) * X + max(0, N - K) * Y << eol;
  
  return 0;
}


Measured memory_bytes: 256
def factorization(n):
    d = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            d[i] = cnt
    if temp!=1:
        d[temp] = 1
    if len(d) == 0:
        d[n] = 1
    return d

N = int(input())
fac_dict = {}
for n in range(1, N+1):
  d = factorization(n)
  for p in d:
    if p in fac_dict:
      fac_dict[p] += d[p]
    else:
      fac_dict[p] = d[p]

# [74個以上, 24個以上, 14個以上, 4個以上, 2個以上]
num_prime = [0, 0, 0, 0, 0]
for p in fac_dict:
  num = fac_dict[p]
  if num >= 2:
    num_prime[4] += 1
    if num >= 4:
      num_prime[3] += 1
      if num >= 14:
        num_prime[2] += 1
        if num >= 24:
          num_prime[1] += 1
          if num >= 74:
            num_prime[0] += 1

ans = 0
ans += num_prime[0] # A = p**74 のパターン
ans += num_prime[1] * (num_prime[4]-1) # A = p1**2 * p2**24 のパターン
ans += num_prime[2] * (num_prime[3]-1) # A = p1**4 * p2**14 のパターン
ans += (num_prime[3]*(num_prime[3]-1)//2) * (num_prime[4]-2) # A = p1**2 * p2**4 * p3**4 のパターン
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
int fib[45];
int fibn(int n){
  int i;
  fib[0] = 1;
  fib[1] = 1;
  for(i =2;i < 45; i++){
    fib[i] = fib[i-1] + fib[i-2];
  }
  return fib[n];
}
int main(){
  int n;
  scanf("%d",&n);
  printf("%d\n",fibn(n));
}



Measured memory_bytes: 2056
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

typedef struct {
	int Up;
	int Sorth;
	int East;
	int West;
	int North;
	int Down;
}DICE;/*
	  DICE North(DICE *t);
	  DICE Sorth(DICE *t);
	  DICE East(DICE *t);
	  DICE West(DICE *t);
	  DICE Rot(DICE *t);
	  */
void assignment(DICE *t);
int main()
{
	unsigned int i, k;
	int up, front;
	DICE Dice1, shoki;
	assignment(&Dice1);
	shoki = Dice1;
	scanf("%d", &k);
	for (i = 0; i < k; i++){
		scanf("%d %d", &up, &front);
		if (up == Dice1.Up){
			if (front == Dice1.Sorth) printf("%d\n", Dice1.East);
			if (front == Dice1.North){ printf("%d\n", Dice1.West); }
			if (front == Dice1.East){ printf("%d\n", Dice1.North); }
			if (front == Dice1.West){ printf("%d\n", Dice1.Sorth); }
		}
		if (up == Dice1.Down){
			if (front == Dice1.Sorth){ printf("%d\n", Dice1.West); }
			if (front == Dice1.North){ printf("%d\n", Dice1.East); }
			if (front == Dice1.East){ printf("%d\n", Dice1.Sorth); }
			if (front == Dice1.West){ printf("%d\n", Dice1.North); }
		}

		if (up == Dice1.Sorth){
			if (front == Dice1.West){ printf("%d\n", Dice1.Down); }
			if (front == Dice1.East){ printf("%d\n", Dice1.Up); }
			if (front == Dice1.Up){ printf("%d\n", Dice1.West); }
			if (front == Dice1.Down){ printf("%d\n", Dice1.East); }
		}
		if (up == Dice1.North){
			if (front == Dice1.West){ printf("%d\n", Dice1.Up); }
			if (front == Dice1.East){ printf("%d\n", Dice1.Down); }
			if (front == Dice1.Up){ printf("%d\n", Dice1.East); }
			if (front == Dice1.Down){ printf("%d\n", Dice1.West); }
		}
		if (up == Dice1.East){
			if (front == Dice1.Sorth){ printf("%d\n", Dice1.Down); }
			if (front == Dice1.North){ printf("%d\n", Dice1.Up); }
			if (front == Dice1.Up){ printf("%d\n", Dice1.Sorth); }
			if (front == Dice1.Down){ printf("%d\n", Dice1.North); }
		}
		if (up == Dice1.West){
			if (front == Dice1.Sorth){ printf("%d\n", Dice1.Up); }
			if (front == Dice1.North){ printf("%d\n", Dice1.Down); }
			if (front == Dice1.Up){ printf("%d\n", Dice1.North); }
			if (front == Dice1.Down){ printf("%d\n", Dice1.Sorth); }
		}
	}

	return 0;
}

void assignment(DICE *t){
	int i, as, a[6];
	DICE temp;
	for (i = 0; i < 6; i++){
		scanf("%d", &as);
		a[i] = as;
	}
	t->Up = a[0], t->Sorth = a[1], t->East = a[2], t->West = a[3], t->North = a[4], t->Down = a[5];
}
/*
DICE North(DICE *t){
DICE temp = { t->Sorth, t->Down, t->East, t->West, t->Up, t->North };
return temp;
}
DICE Sorth(DICE *t){
DICE temp = { t->North, t->Up, t->East, t->West, t->Down, t->Sorth };
return temp;
}
DICE East(DICE *t){
DICE temp = { t->West, t->Sorth, t->Up, t->Down, t->North, t->East };
return temp;
}
DICE West(DICE *t){
DICE temp = { t->East, t->Sorth, t->Down, t->Up, t->North, t->West };
return temp;
}
DICE Rot(DICE *t){
DICE temp = { t->Up, t->East, t->North, t->Sorth, t->West, t->Down };
return temp;
}
*/

Measured memory_bytes: 1024
def main():
    # * - * - *
    n, m = [int(i) for i in input().split()]
    abc = []
    for i in range(m):
        a, b  = [int(j) for j in input().split()]
        abc.append([a,b])
    abc.sort(key=lambda x:x[1])
    i = 1
    ans = 1
    now = abc[0]
    while i < m:
        if now[1] <= abc[i][0]:
            ans += 1
            now = abc[i]
        i += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21404
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

struct Segtree {
    int n;
    vpii dat;

    void init(int n_) {
        n = 1;

        while (n < n_) n *= 2;

        dat.resize(2 * n);

        for (int i = 0; i < 2 * n - 1; ++i) dat[i] = pii(0, -inf);
    }

    void update(int a, int x) {
        int idx = a;
        a += n - 1;

        dat[a].fst += x;
        dat[a].scd = -idx;

        while (a > 0) {
            a = (a - 1) / 2;
            dat[a] = max(dat[a * 2 + 1], dat[a * 2 + 2]);
        }
    }

    //pii get_max(int a, int b, int k = 0, int l = 0, int r = -1) {
    pii get_max() {
        return dat[0];

        //if (r == -1) r = N;

        //if (r <= a || l >= b) return pii(-inf, -inf);

        //if (a <= l && r <= b) return dat[k];

        //pii vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
        //pii vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);

        //return max(vl, vr);
    }
};

typedef pair<int, pair<int, int> > Query;

int res[100010];

signed main()
{
    int N, R, L; cin >> N >> R >> L;

    Segtree seg;
    seg.init(N);

    vector<Query> queries(R);

    rep(i, R) {
        int d, t, x;
        cin >> d >> t >> x;

        -- d;

        queries[i] = Query(t, pii(d, x));
    }

    queries.PB(Query(L, pii(0, 0)));
    
    sort(all(queries));

    rep(i, R) {
        Query query = queries[i];
        Query next_query = queries[i + 1];

        seg.update(query.scd.fst, query.scd.scd);

        if (query.fst != next_query.fst) {
            res[-seg.get_max().scd] += next_query.fst - query.fst;
        }
    }

    int ma = -1;
    int ans = -1;

    rep(i, N) {
        if (ma < res[i]) {
            ma = res[i];
            ans = i;
        }
    }

    cout << ans + 1 << endl;
}

Measured memory_bytes: 18820
from math import sin, cos, pi
def koch(px, py, qx, qy, n):
    if n == 0:
        return True
    sx = (2 * px + qx) / 3
    sy = (2 * py + qy) / 3
    tx = (px + 2 * qx) / 3
    ty = (py + 2 * qy) / 3
    ux = sx + (tx - sx) * cos(pi / 3) - (ty - sy) * sin(pi / 3)
    uy = sy + (tx - sx) * sin(pi / 3) + (ty - sy) * cos(pi / 3)
    koch(px, py, sx, sy, n - 1)
    print("{:.8f} {:.8f}".format(sx, sy))
    koch(sx, sy, ux, uy, n - 1)
    print("{:.8f} {:.8f}".format(ux, uy))
    koch(ux, uy, tx, ty, n - 1)
    print("{:.8f} {:.8f}".format(tx, ty))
    koch(tx, ty, qx, qy, n - 1)
n = int(input())
print("{:.8f} {:.8f}".format(0, 0))
koch(0, 0, 100, 0, n)
print("{:.8f} {:.8f}".format(100, 0))

Measured memory_bytes: 7976
from collections import Counter
def main():
    n = int(input())
    s = input()
    d = Counter(s)
    ans = d['R'] * d['G'] * d['B']

    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j-i
            if s[i]!=s[j] and k < n and s[i] != s[k] and s[j] != s[k]:
                ans -= 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 74052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		String s = sc.next();
		boolean ans = false;
		if(turn(s)) {
			int le = s.length();
			String s1 = s.substring(0, (le/2));
			String s2 = s.substring((le/2)+1, le);
			if(turn(s1) && turn(s2)) {
				ans = true;
			}
		}

		if(ans) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	static boolean turn(String str) {
		boolean ans = true;
		char[] c = str.toCharArray();
		int back = c.length-1;
		for(int i = 0; i < back; i++) {
			if(c[i] != c[back-i]) {
				ans = false;
				break;
			}
		}
		return ans;
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

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

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

Measured memory_bytes: 21204