akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    map<int,int>mp;
    rep(i,n){
        mp[a[i]]++;
    }
    vector<int> cnt(n + 1, 0);
    for(auto x : mp){
        cnt[x.second]++;
    }
    show(cnt);
    int all = n;
    for(int k = 1; k <= n; k++){
        int x = all / k;
        //x枚以上あるやつは無駄
        show(k, x, all, cnt.size());
        while((int) cnt.size() - 1 > all / k){
            if(cnt.back() == 0){
                cnt.pop_back();
                continue;
            }
            all--;
            cnt.back()--;
            cnt[cnt.size() - 2]++;
            if(cnt.back() == 0)cnt.pop_back();
        }
        show(all);
        show(cnt);
        cout << all / k << "\n";
    }
}


Measured memory_bytes: 16640
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int x=0,n,max=0;
	char s[100];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	
	for(int i=0;i<n;i++){
		if(s[i]=='I'){
			x=x+1;
			
			if(x>max){
				max=x;
			}
		}
		
		else if(s[i]=='D'){
			x=x-1;
		}
	}
	
	cout<<max<<endl;
	
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Queue;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String input_str[] = new String[2];
			input_str = br.readLine().split("\\s+");
			int V = Integer.parseInt(input_str[0]);
			int E = Integer.parseInt(input_str[1]);

			Node nodes[] = new Node[V];
			for(int i = 0; i < V; i++)nodes[i] = new Node();

			int in_num[] = new int[V];
			for(int i = 0; i < V; i++)in_num[i] = 0;

			int from,to;
			StringBuilder ans = new StringBuilder();

			for(int loop = 0; loop < E; loop++){
				input_str = br.readLine().split("\\s+");
				from = Integer.parseInt(input_str[0]);
				to = Integer.parseInt(input_str[1]);
				in_num[to]++;
				nodes[from].list.add(to);
			}

			Queue<Integer> Q = new ArrayDeque<Integer>();
			for(int i = 0; i < V; i++){
				if(in_num[i] == 0){
					Q.add(i);
				}
			}

			int tmp,tmp2;

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				ans.append(Integer.toString(tmp)).append("\n");

				for(int i = 0; i < nodes[tmp].list.size(); i++){
					tmp2 = nodes[tmp].list.get(i);
					in_num[tmp2]--;
					if(in_num[tmp2] == 0){
						Q.add(tmp2);
					}
				}
			}
			System.out.print(ans.toString());

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}

class Node{
	public ArrayList<Integer> list;

	Node(){
		list = new ArrayList<Integer>();
	}
}


Measured memory_bytes: 69872
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N,A,B;
    R(N,A,B);
    W(min(A*N,B));
    return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    L = [0 for _ in range(N+1)]
    L[0] = 2
    L[1] = 1
    for i in range(N-1):
         L[i+2] = L[i+1] + L[i]
    print(L[N])







if __name__ == "__main__":
    solve()


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

map<string, int> m;


int main(){

    int n;
    cin >> n;

    vector<int> a(n);
    vector<ll> count(2 * 100000 + 1);
    vector<ll> comb(2 * 100000 + 1);

    rep(i, n){
        cin >> a[i];
        count[a[i]]++;
    }

    ll sum = 0;

    for(int i = 1; i <= 2 * 100000; i++){
        comb[i] = count[i] * (count[i] - 1) / 2;
        sum += comb[i];
    }

    rep(i, n){
        ll tmpcount = count[a[i]];
        tmpcount--;
        ll tmpsum = tmpcount * (tmpcount - 1) / 2;

        cout << sum - comb[a[i]] + tmpsum << endl;
    }

    return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        long a = scanner.nextInt();
        long b = scanner.nextInt();
        
        long d = a / b;
        long r = a % b;
        double f = a * 1.0 / b;
        
        System.out.printf("%d %d %.5f\n", d, r, f);
    }
}


Measured memory_bytes: 26560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
 
 
int main() {
  int n;
  cin >> n;
  int higher_n, lower_n;
  higher_n = n / 10;
  lower_n = n % 1000;
  if (higher_n % 111 == 0 || lower_n % 111 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"

    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    char c;
    cin>>c;
    if(isupper(c))cout<<"A";
    else cout<<"a";

}




Measured memory_bytes: 3648
#include <iostream>

auto Pow(std::uint64_t base, std::size_t i) {
    auto result = std::uint64_t(1);

    while (i > 0) {
        if (i % 2 == 0) {
            base *= base;
            i /= 2;
        } else {
            result *= base;
            i--;
        }
    }

    return result;
}

int main() {
    auto s = std::string();
    std::cin >> s;

    auto sum = std::uint64_t(0);
    for (auto i = std::size_t(0); i < s.size(); ++i) {
        const auto num = static_cast<std::uint64_t>(s[i] - '0');

        const auto exp = s.size() - 1 - i;
        auto pow_2 = Pow(2, i);
        sum += num * Pow(10, exp) * pow_2;

        for (auto j = std::size_t(1); j <= exp; ++j) {
            sum += num * Pow(10, exp - j) * pow_2;
            pow_2 *= 2;
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


class Combination(object):
    """
    組み合わせを求める。
    cmbで使いうる最大のNまでを前処理で準備。
    """

    def __init__(self, N, mod=10**9+7):
        fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
        fac[:2] = 1, 1
        finv[:2] = 1, 1
        inv[1] = 1
        for i in range(2, N+1):
            fac[i] = fac[i-1]*i % mod
            inv[i] = -inv[mod % i]*(mod//i) % mod
            finv[i] = finv[i-1]*inv[i] % mod
        self.N = N
        self.MOD = mod
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def __call__(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.fac[n] * (self.finv[k]*self.finv[n-k] % self.MOD) % self.MOD


def solve(X: int, Y: int):

    if X > Y:
        X, Y = Y, X
    sub = Y-X

    if (X - (Y-X)) % 3 != 0:
        print(0)
        return

    A = (X - (Y-X))//3 + sub
    B = (X - (Y-X))//3

    cmb = Combination(A+B)
    print(cmb(A+B, A))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 54256
#include "bits/stdc++.h"
using namespace std;

int main(){
	int a, b;
	cin>>a>>b;
	if(a <= 0 and b >= 0)	cout<<"Zero\n";
	else{
		if(a > 0)	cout<<"Positive\n";
		else{
			int diff = (b - a) + 1;
			if((diff % 2) == 0)	cout<<"Positive\n";
			else cout<<"Negative\n";
		}
	}
	return 0;
}

Measured memory_bytes: 384
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto T = RDR.ARR;
	auto M = RD;
	auto px = new long[][](M, 2);
	foreach (i; 0..M)
	{
		px[i] = [RD-1, RD];
	}
	auto base = T.sum;
	foreach (i; 0..M)
	{
		writeln(base - T[px[i][0]] + px[i][1]);
	}

	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
static constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template<class T>bool bmaxi(T&a, const T&b) { if (b<a)return 0;a = b;return 1; }
template<class T>bool bmini(T&a, const T&b) { if (a<b)return 0;a = b;return 1; }
template<class T>bool nmaxi(T&a, const T&b) { if (a<b) { a = b;return 1; }return 0; }
template<class T>bool nmini(T&a, const T&b) { if (b<a) { a = b;return 1; }return 0; }
template<typename T>auto scan(T&d)->typename std::enable_if<std::is_same<T, std::string
>::value>::type {
	d.clear();int c = fgetc(stdin);while (c<'a' || 'z'<c)c = fgetc(stdin);
	while ('a' <= c&&c <= 'z') { d.push_back(c);c = fgetc(stdin); }
}
template <typename T>auto scan(T&d)->
typename std::enable_if<std::is_same<T, double>::value>::type {
	scanf("%lf", &d);
}
template <typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value
	== std::is_same<T, std::string>::value>::type {
	d = 0;int c = fgetc(stdin);
	while (c<'0' || '9'<c)c = fgetc(stdin);while ('0' <= c&&c <= '9') { d = d * 10 + c - '0';c = fgetc(stdin); }
}
template <typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value
	!= std::is_same<T, double>::value>::type {
	d = 0;int c = fgetc(stdin);bool f = 0;while (c<'0' || '9'<c)
	{
		if (c == '-')f = 1;c = fgetc(stdin);
	}while ('0' <= c&&c <= '9') { d = d * 10 + c - '0';c = fgetc(stdin); }if (f)d = -d;
}
template<typename F, typename...R>void scan(F&f, R&...r) { scan(f);scan(r...); }

bool P(uint32 t) {
	std::vector<uint32> a;
	while (t) {
		a.push_back(t % 10);
		t /= 10;
	}
	for (uint32 i = 0;i < a.size()/2;++i) {
		if (a[i] != a[a.size() - 1 - i]) return false;
	}
	return true;
}

int main(void) {
	uint32 a, b;
	scan(a, b);
	uint32 c = 0;
	for (uint32 i = a;i <= b;++i)
		if (P(i))++c;
	
		printf("%u\n", c);
	return 0;
}

Measured memory_bytes: 256
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMODPR = 998244353;

ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
    sys.stdin  = open("input.txt","r")
    sys.stdout = open("output.txt","w")
    sys.stderr = open("output.txt","w")

# for _testcases_ in range(int(input())):
s = input()
d = {}; flag = True
from collections import Counter as C
d = C(s)
for _, v in d.items():
    if v % 2:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
DO NOT PLAGIARISE.
TESTCASES:
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[101];
	int i;
	int MAX;
	for(i=1;i<=100;i++)	box[i]=0;
	while(1){
		cin>>n;
		if(cin.eof()==1)	break;
		box[n]++;
	}
	MAX=-1;
	for(i=1;i<=100;i++)		MAX=max(MAX,box[i]);
	for(i=1;i<=100;i++)		if(MAX==box[i])	cout<<i<<endl;
	return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,x;
  cin>>n>>x;
  vector<int >nos(n,0);
  for(int i=0;i<n;i++)cin>>nos[i];
  long long mini=0,ny=0;
  for(int i=0;i<n-1;i++){
  if(nos[i]>x){mini+=(nos[i]-x);nos[i]=x;}
    if(nos[i]+nos[i+1]>x){
    	ny = x-nos[i];
      	mini+=(nos[i+1]-ny);
      	nos[i+1]=ny;
          
    }
  }
  cout<<mini;
}

Measured memory_bytes: 3760
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt();

        Arrays.sort(arr);

        long ans = 0;

        for (int i=0; i<n-2; i++) {
            for (int j=i+1; j<n-1; j++) {
                int a = arr[i];
                int b = arr[j];
                int left = j+1;
                int right = n;
                while (left<right) {
                    int mid = (left+right)/2;
                    if (arr[mid]<a+b) {
                        left = mid+1;
                    } else {
                        right = mid;
                    }
                }                 
                ans += (left-j-1);

            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 28032
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vl v(m),dif(m-1);
	ll ans=0;
	rep(i,m)cin>>v[i];
	ans=*max_element(all(v))-*min_element(all(v));
	sort(all(v));
	rep(i,m-1)dif[i]=v[i+1]-v[i];
	sort(all(dif),greater<ll>());
	int d=min(n-1,(int)dif.size());
	rep(i,d){
		ans-=dif[i];
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 1792
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.range;
void main()
{
    readln;
    auto a = readln().strip.split(" ").map!(to!int);
    auto b = new typeof(a[0])[10000];
    foreach (i; a)
    {
        b[i]++;
    }
    bool aaf = false;
    foreach (i, j; b)
    {
        foreach (k; iota(j))
        {
            write(aaf ? " " : "", i);
            aaf = true;
        }
    }
    writeln();
}


Measured memory_bytes: 69520
X, Y, Z, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
AB = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001, X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])


Measured memory_bytes: 141768
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

int f(int n)
{
    vi h(n+1);
    rep(i, n+1) cin >> h[i];
    
    rep(i, n+1){
        int d = h[1+(2>i)] - h[1>i];
        bool ok = true;
        reps(j, 1, n){
            if(h[j+((j+1)>i)] - h[j-1+(j>i)] != d){
                ok = false;
                break;
            }
        }
        if(ok){
            return h[i];
        }
    }
}

int main()
{
    int n;
    while(cin >> n, n){
        cout << f(n) << endl;
    }
}

Measured memory_bytes: 1196
s = input()
n = input()
ans = set([])
test = list(s)

for i in range(len(test)):
    s = test[i]
    ans.add(s)
    for j in range(i+1, min(i+5, len(test))):
        s = s + test[j]
        ans.add(s)
    
ans = list(ans)

ans.sort()
print(ans[int(n)-1])

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

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        int[] count = new int[4];
        for(int i = 0 ; i <= 2 ; i++) {
            String[] strs = stdR.readLine().split(" ");
            count[Integer.parseInt(strs[0]) - 1]++;
            count[Integer.parseInt(strs[1]) - 1]++;   
        }
        Arrays.sort(count);
        if(count[0] == 1 && count[1] == 1 && count[2] == 2 && count[3] == 2) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 22356
#include<stdio.h>
#include<algorithm>
using namespace std;
double a[32],b[32],c[32],d[32];
double Abs(double e){return e<0?-e:e;}
double calc(int i,int j){
	double X[6];
	double Y[6];
	Y[1]=(a[i]*(d[j]-c[j])+c[j])/((a[i]-b[i])*(d[j]-c[j])+1);
	X[1]=(c[j]*(b[i]-a[i])+a[i])/((d[j]-c[j])*(a[i]-b[i])+1);
	Y[2]=(a[i+1]*(d[j]-c[j])+c[j])/((a[i+1]-b[i+1])*(d[j]-c[j])+1);
	X[2]=(c[j]*(b[i+1]-a[i+1])+a[i+1])/((d[j]-c[j])*(a[i+1]-b[i+1])+1);
	Y[3]=(a[i+1]*(d[j+1]-c[j+1])+c[j+1])/((a[i+1]-b[i+1])*(d[j+1]-c[j+1])+1);
	X[3]=(c[j+1]*(b[i+1]-a[i+1])+a[i+1])/((d[j+1]-c[j+1])*(a[i+1]-b[i+1])+1);
	Y[4]=(a[i]*(d[j+1]-c[j+1])+c[j+1])/((a[i]-b[i])*(d[j+1]-c[j+1])+1);
	X[4]=(c[j+1]*(b[i]-a[i])+a[i])/((d[j+1]-c[j+1])*(a[i]-b[i])+1);
	Y[5]=Y[1];
	X[5]=X[1];
	Y[0]=Y[4];
	X[0]=X[4];
	double S=0;
	for(int k=1;k<=4;k++)S+=(X[k+1]-X[k])*(Y[k-1]-Y[k])-(X[k-1]-X[k])*(Y[k+1]-Y[k]);
	return Abs(S/4);
}
int main(){
	int n;
	while(scanf("%d",&n),n){
		for(int i=0;i<n;i++)scanf("%lf",a+i+1);
		for(int i=0;i<n;i++)scanf("%lf",b+i+1);
		for(int i=0;i<n;i++)scanf("%lf",c+i+1);
		for(int i=0;i<n;i++)scanf("%lf",d+i+1);
		a[n+1]=b[n+1]=c[n+1]=d[n+1]=1;
		double ret=0;
		for(int i=0;i<=n;i++)
			for(int j=0;j<=n;j++)
				ret=max(ret,calc(i,j));
		printf("%.6f\n",ret);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=203,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll S,T,D;cin>>S>>T>>D;
    vector<ll> A(D);
    ll sum=0,mini=INF;
    for(int i=0;i<D;i++) cin>>A[i];
    
    for(int i=0;i<D;i++){
        sum+=A[i];
        if(S+sum<=T){
            cout<<i+1<<endl;
            return 0;
        }
        mini=min(mini,sum);
    }
    
    if(sum>=0) cout<<-1<<endl;
    else{
        ll rem=S-T+mini;
        sum*=(-1);
        ll need=(rem+sum-1)/sum;
        
        rem=S-T-sum*need;
        if(rem<=0){
            cout<<need*D<<endl;
            return 0;
        }
        for(int i=0;i<D;i++){
            rem+=A[i];
            if(rem<=0){
                cout<<need*D+i+1<<endl;
                return 0;
            }
        }
    }
    
}





Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int root[100000];
int size[100000];
int getRoot(int v){ return root[v] == -1 ? v : root[v] = getRoot(root[v]); }

int main(){
    int N;
    while(cin >> N){
        map<int, int> xDict;
        map<int, vector<int>> ySet;
        vector<set<int>> S(N);
        vector<int> ySize(N, 0);
        for(int i=0;i<N;i++){
            int x, y; cin >> x >> y;
            if(!xDict.count(x)){
                int idx = xDict.size();
                xDict[x] = idx;
            }
            S[xDict[x]].insert(y);
            ySize[xDict[x]]++;
            if(!ySet.count(y)) ySet[y] = vector<int>();
            ySet[y].push_back(xDict[x]);
        }
        fill(root, root+N, -1);
        fill(size, size+N, 1);
        for(auto& item : ySet){
            auto& v = item.second;
            for(int i=0;i+1<v.size();i++){
                int p = getRoot(v[i]);
                int q = getRoot(v[i+1]);
                if(p == q) continue;
                if(S[p].size() < S[q].size()) swap(p, q);
                for(auto t : S[q]) S[p].insert(t);
                root[q] = p;
                size[p] += size[q];
                ySize[p] += ySize[q];
            }
        }
        long long res = 0;
        for(int i=0;i<N;i++){
            int r = getRoot(i);
            if(r != i) continue;
            res += (long long)size[r] * S[r].size() - ySize[r];
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 31616
def abc131d_megalomania():
    n = int(input())
    d = []
    for _ in range(n):
        d.append(list(map(int, input().split())))
    d.sort(key=lambda x: x[1])
    t = 0
    for item in d:
        t += item[0]
        if t > item[1]:
            print('No')
            return
    print('Yes')
abc131d_megalomania()

Measured memory_bytes: 116228
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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; }

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a,b;
typedef pair<int, int> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{
	int n = av.size();
	vector<pair_t> p(n);
	vector<ll> av2(n), bv2(n);
	for (int i = 0; i < n; i++)
		p[i] = make_pair(av[i], bv[i]);
	sort(p.begin(), p.end(), comp);
	for (int i = 0; i < n; i++) {
		av2[i] = p[i].first;
		bv2[i] = p[i].second;
	}
	av = av2;
	bv = bv2;
}

int main()
{
	ll n, m;
	ll s = 0;
	ll ans = 0;
	cin >> n >> m;
	for (ll i = 0; i < n; i++){
		ll tmp1,tmp2;
		cin >> tmp1 >> tmp2;
		a.push_back(tmp1);
		b.push_back(tmp2);
	}

	//sort(a.begin(), a.end());
	sort2vectors(a, b);
	ll cnt = 0;
	bool flag = false;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < b[i]; j++) {
			ans += a[i];
			cnt++;
			if (cnt >= m) {
				flag = true;
				break;
			}
		}
		if (flag == true) {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4332
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int h, w, m; cin >> h >> w >> m;
    V<int> tate(w), yoko(h);
    V<P> p(m);
    rep(i, m) {
        int H, W; cin >> H >> W; H--; W--;
        tate[W]++; yoko[H]++;
        p[i] = {W, H};
    }
    int mx1 = 0, mx2 = 0;
    rep(i, w) chmax(mx1, tate[i]);
    rep(i, h) chmax(mx2, yoko[i]);
    set<int> mx_tate, mx_yoko;
    rep(i, w) {
        if (tate[i] == mx1) mx_tate.insert(i);
    }
    rep(i, h) {
        if (yoko[i] == mx2) mx_yoko.insert(i);
    }
    int ans = mx1 + mx2 - 1;
    ll c = (ll)mx_tate.size() * mx_yoko.size();//一つでも爆破対象じゃないところがあったらmx1+mx2
    ll cnt = 0;//爆破対象かつ、maxの行と列に属するものの数
    rep(i, m) {
        int x = p[i].first, y = p[i].second;
        if (mx_tate.count(x) && mx_yoko.count(y)) cnt++;
    }
    if (c > cnt) ans = mx1 + mx2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35840
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int n; int ans = 1;
    cin>>n;
    int a[n];int store[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    int j = 0;
    for(int i=0;i<n; i++){
        if(a[j] == 2){
            cout<<ans;return 0;
        }

        j=a[j]-1;
        //cout<<j<<endl;
        //cout<<a[j]<<endl;
        ans++;

    }

    cout<<"-1";
}

Measured memory_bytes: 640
#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 pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[100000];
	ll S[100001];
	S[0] = 0;
	ll kari = 0;
	priority_queue<int, vector<int>, greater<int>> que;
	priority_queue<int> que2;
	rep(i, N) {
		int a = getint();
		que.push(a);
		S[0] += a;
	}
	rep(i, N) A[i] = getint();
	rep(i, N) {
		int a = getint();
		que2.push(a);
		kari += a;
	}

	rep(i, N) {
		que.push(A[i]);
		S[i + 1] = S[i] + A[i] - que.top();
		que.pop();
	}
	ll kotae = S[N] - kari;
	for (int i = N - 1; i >= 0; i--) {
		que2.push(A[i]);
		kari += A[i] - que2.top();
		que2.pop();
		kotae = max(kotae, S[i] - kari);
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 2424
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------



int main() {
    //ll ans=0;
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s.at(i)=='P') cout<<s.at(i);
        else cout<<'D';
       
    }
    cout<<endl;
}


Measured memory_bytes: 3752
N = int(input())
H = [int(x) for x in input().split()]

ma = max(H)
cnt = 0

while ma:
    flg = False
    for i in range(N):
        if H[i]==ma:
            flg = True
            H[i] -= 1
        elif flg and H[i]!=ma:
            cnt += 1
            flg = False
    if flg:
        cnt += 1
    ma -= 1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define INS(x) (x).begin(),(x).end()
#define gcd(x,y) __gcd((x),(y))

int a[205];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,k;
    cin>>n>>k;

    for (int i=1;i<=k;i++)
    {
        int d;
        cin>>d;

        for (int j=1;j<=d;j++)
        {
            int t;
            cin>>t;
            
            a[t]++;
        }
    }

    int cnt=0;
    for (int i=1;i<=n;i++)
        if (!a[i]) cnt++;

    cout<<cnt<<'\n';
    
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n; cin >> n;
  map<int,int> mp;
  vector<ll> l;
  l.emplace_back(0);
  l.emplace_back(0);
  rep(i,n){
    int x; cin >> x;
    mp[x]++;
    if(mp[x]==2){l.emplace_back(x);}
    if(mp[x]==4){l.emplace_back(x);}
  }
  sort(l.rbegin(),l.rend());
  cout << l[0]*l[1] << endl;
  return 0;
}


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

int main() {
	// your code goes here
    int n,m;
cin>>n>>m;
int ar[m];
for(int i=0;i<m;i++)  cin>>ar[i]
;int sum=0;
for(int i=0;i<m;i++) sum+=ar[i];
if(sum>n) cout<<-1<<endl;
else cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll k; cin >> k;
    queue<ll> que;
    rep(i,9){
        que.push(i+1);
    }
    Rep(i,k-1){
        ll x = que.front();
        que.pop();
        for(ll j = -1; j<=1; j++){
            ll add = (x%10) + j;
            if(add>=0 && add<=9){
                que.push(x*10+add);
            }
        }
    }
    cout << que.front() << endl;
}

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

using namespace std;
using ll = long long;

int main() {

	ll N, A, B;
	cin>>N>>A>>B;
	ll x = 0;
	ll ans = N/(A+B) * A + min(N % (A + B), A);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int d = int.Parse(input[1]);

		Console.WriteLine((n+2*d)/(2*d+1));
	}
}

Measured memory_bytes: 13140
#include<stdio.h>
int p[100005];
int root(int n)
{
	if (p[n] == n)
		return n;
	p[n] = root(p[n]);
	return p[n];
}
void f(int x, int y)
{
	if (root(x) == root(y))
		return;
	p[root(x)] = root(y);
	return;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int x, y, z;
	for (i = 0; i < n; i++)
		p[i] = i;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d %d", &x, &y, &z);
		f(x - 1, y - 1);
	}
	int v[100005];
	for (i = 0; i < n; i++)
		v[i] = 0;
	int ans = 0;
	for (i = 0; i < n; i++)
	{
		if (v[root(i)] == 0)
		{
			ans++;
			v[root(i)]++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1408
import sys
from collections import deque

    
def dfs(x,s):
    used = {s}
    search = deque([s])
    while search:
        ss = search.pop()
        for sss in x[ss]:
            if sss in used:
                continue
            used.add(sss)
            search.append(sss)
    return used


def bellmanford(edges):
    coins = [-float("inf")] * N
    coins[0] = 0
    for _ in range(N):
        f = True
        for u,v,c in edges:
            if coins[u] + c > coins[v]:
                coins[v] = coins[u] + c
                f = False
        if f:
            return max(0, coins[-1])
    return -1

N,M,P = map(int, input().split())
ABC = []
Adake = [[] for _ in range(N)]
Bdake = [[] for _ in range(N)]
for _ in range(M):
    A,B,C = map(int, input().split())
    ABC.append((A-1,B-1,C-P))
    Adake[A-1].append(B-1)
    Bdake[B-1].append(A-1)

U = dfs(Adake,0) & dfs(Bdake,N-1)
ABC = [(a,b,c) for (a,b,c) in ABC if a in U and b in U]

print(bellmanford(ABC))

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int N, M;
map<int, bool> mp;

int main() {
	while(scanf("%d %d", &N, &M), N || M) {
		map<int, bool> mp;
		vector<int> fri[501];
		vector<int> t_fri;
		rep(i, M) {
			int A, B;
			scanf("%d %d", &A, &B);
			fri[A].push_back(B);
			fri[B].push_back(A);
		}
		rep(i, fri[1].size()) {
			mp[fri[1][i]] = true;
			t_fri.push_back(fri[1][i]);
		}
		rep(i, t_fri.size()) {
			rep(j, fri[ t_fri[i] ].size()) {
				mp[fri[t_fri[i]][j]] = true;
			}
		}
		int ans = 0;
		FOR(i, 2, N + 1) if(mp[i]) ++ans;
		printf("%d\n", ans); 
	}
	return 0;
}

Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    if (s.size() == 2)
        cout << s;
    else
        cout << s[2] << s[1] << s[0];
}

Measured memory_bytes: 3648
### SNIPPET
  # array = [*1..q].map { |_| gets.split.map(&:to_i) }
  # n = gets.split.map(&:to_i)
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さh = a * Math.sin(w / 180.0 * Math::PI)
  # 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  def chmax(a, b) a > b ? a : b end
  INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end
n = gets.to_i
array = [*1..n].map { |_| gets.split.map(&:to_i) }
dp = []
dp[0] = [0,0,0]
n.times {dp.push([-INF]*3)}

n.times do |i|
  3.times do |j|
    3.times do |k|
      dp[i+1][j] = chmax(dp[i+1][j], dp[i][k]+ array[i][j]) if j != k || i == 0
    end
  end
end

puts dp[n].max

Measured memory_bytes: 17916
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#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 possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair


int main(){
  SCIN(s);
  LCIN(k);
  REP(i,k){
    if(s[i] != '1'){
      COUT(s[i]);
      return 0;
    }
  }
  COUT(1);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll X;
    cin>>X;
    ll i=1;
    while(true){
        if((1+i)*i/2>=X){
            break;
        }
        i++;
    }
    cout<<i<<endl;;
}



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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int nums[] = new int[in.nextInt()];
        for (int i = 0; i < nums.length; i++)
            nums[i] = in.nextInt();
        int numx[] = new int[in.nextInt()];
        for (int i = 0; i < numx.length; i++)
            numx[i] = in.nextInt();
        int counter = 0;
        for (int x = 0; x < nums.length; x++) {
            int index = 0;
            for (int y = 0; y < numx.length; y++) {
                if (nums[x] == numx[y]) {
                    ++counter;
                    numx[index] = 10001;
                }
                index++;
            }
        }
        System.out.println(counter);
    }
}



Measured memory_bytes: 39812
S=[int(x) for x in list(input())]

out=[]

for n in range(2,len(S)):
  S_0 = S[n-2]
  S_1 = S[n-1]
  S_2 = S[n]
  
  Check_Num = S_0*100+S_1*10+S_2

  out.append(abs(Check_Num-753))
  
print(min(out))

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

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

	int n;
	cin >> n;
	int heights[n];
	for(int i=0; i<n; i++) cin >> heights[i];
	int ans = 1; int mx = heights[0];
	for(int i=1; i<n; i++){
		if(max(heights[i],mx)==heights[i]){
			ans++;
			mx = heights[i];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3608