akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
"""AtCoder Beginner Contest 174: B - Distance
https://atcoder.jp/contests/abc174/tasks/abc174_b
"""

import math


def main():
    N, D = list(map(int, input().split()))

    ans = 0
    for _ in range(N):
        X, Y = list(map(int, input().split()))
        if math.sqrt((X * X) + (Y * Y)) <= D:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

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

  while(n--){
    int a, b, c;
    cin >> a >> b >> c;
    a *= a;
    b *= b;
    c *= c;

    if(a + b == c || a + c == b || b + c == a){
      cout << "YES\n";
    }
    else{
      cout << "NO\n";
    }
  }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int n, m;
int a[5005], b[5005][205];
int dp[205];
ll sum[5005];
ll ans = 0;
void dfs(int s, int e, int optl, int optr){
    if(s > e) return;
    int mid = (s+e)/2;
    for(int j=1;j<=m;j++) dp[j] = 0;
    for(int i=mid;i<max(mid, optl);i++){
        for(int j=1;j<=m;j++) dp[j] = max(dp[j], b[i][j]);
    }
    ll res = -1e18, opt = mid;
    for(int i=max(mid, optl);i<=max(mid, optr);i++){
        ll tmp = 0;
        for(int j=1;j<=m;j++){
            dp[j] = max(dp[j], b[i][j]);
            tmp += dp[j];
        }
        if(res < tmp - (sum[i] - sum[mid])){
            res = tmp - (sum[i] - sum[mid]);
            opt = i;
        }
    }
    ans = max(ans, res);
    dfs(s, mid-1, optl, opt);
    dfs(mid+1, e, opt, optr);
}
int main(){
    scanf("%d%d", &n, &m);
    for(int i=2;i<=n;i++){
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
    }   
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d", &b[i][j]);
        }
    }
    dfs(1, n, 1, n);
    printf("%lld\n", ans);
}

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

using namespace std;

int main(){
	string ans[2] = {"vowel", "consonant"};
	string vowel[5] = {"a", "e", "i", "o", "u"};
	string c;
	cin >> c;
	int flag = 1;
	for(int i = 0; i < 5; i++){
		if(c == vowel[i]){
			flag = 0;
		}
	}
	cout << ans[flag];
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b,n ;
  int x,y;
  while(cin >> a >> b && a&& b){
    cin >> n;
    vector<vector<int>> v(a+1,vector<int>(b+1,1));
    vector<vector<int>> dp(a+1,vector<int>(b+1,0));
    rep(i,n){
      cin >> x >> y;
      --x;
      --y;
      v[x][y] = 0;
    }
    dp[0][0] = 1;
    rep(j,b){
      rep(i,a){
        if(v[i+1][j] ){
          dp[i+1][j] += dp[i][j];
        }
        if(v[i][j+1]){
          dp[i][j+1] += dp[i][j];
        }
      }
    }
    cout << dp[a-1][b-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3100
N, M = map(int, input().split())
S = input()
T = input()

def gcd(a, b) :
    if b > a : 
        a, b = b, a
    
    while b != 0 :
        a, b = b, a % b
    return a
    
def lcm(a, b) :
    return a * b // gcd(a, b)

for i in range(N) :
  if i * M % N != 0 :
    continue
  if S[i] != T[i * M // N] :
    print(-1)
    break
else :
  print(lcm(N, M))
  


Measured memory_bytes: 39792
A = int(input())
N = input()
counter = N.count("-")
N = list(map(int,N.split()))
N = list(map(abs,N))
N.sort()
if N[0] == 0:
    print(sum(N))
else:
    if counter % 2 == 0:
        print(sum(N))
    else:
        print(sum(N) - N[0] * 2)

Measured memory_bytes: 15260
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, x) = in.readLine.split(" ").map(_.toInt)

  val li = in.readLine.split(" ").map(_.toInt)

  val d = Array.ofDim[Int](n+1)
  for(i <- 1 to n) {
    d(i) = d(i-1) + li(i-1)
  }

  val ans = d.count(_ <= x)
  println(ans)
}

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

using namespace std;

int main() {

	long long a, b;
	cin >> a >> b;
	int pos;
	if(a == b) {
		puts("1");	
	} else {
		for (int i = 60; i >= 0; --i) {
			if((a &(1LL<<i)) == (b &(1LL<<i))) {
				a -= (a &(1LL<<i));
				b -= (b &(1LL<<i));
			} else {
				pos = i;
				break;
			}
		}
		long long p2 = 1LL << pos;

		long long zero = p2 - a; // a ... p2-1

		long long bn = b - p2;
		int pos_bn;
		if(bn == 0) {
			pos_bn = -1;
		} else{
			pos_bn = 63 - __builtin_clzll(bn);
		}

		long long b_lower = 1LL<<(pos_bn+1); // 0 .. (1LL<<(pos_bn+1)-1)
		long long b_upper = zero; // a ... p2-1

		long long sum = b_lower + b_upper;
		if(b_lower + b_upper >= p2) {
			sum = p2;
		}
		printf("%lld\n", zero+sum);
	}



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 1e9 + 7;
inline void reduce(int & x){ x += x >> 31 & mod; }
int n;
ll s[maxn], a, b;
int dp[maxn], pre[maxn], left[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> a >> b;
	if(a > b) std::swap(a, b);
	rep(i, 1, n) cin >> s[i];
	std::sort(s + 1,s + n + 1);
	rep(i, 3, n) if(s[i - 2] + a > s[i]) return cout << 0 << '\n', 0;
	rep(i, 1, n) left[i] = i != 1 && s[i] - s[i - 1] >= a ? left[i - 1] : i;
	dp[0] = dp[1] = pre[0] = 1, pre[1] = 2;
	rep(i, 2, n) {
		int r = std::upper_bound(s + 1,s + i, s[i] - b) - s - 1, l = left[i - 1];
		if(l - 2 <= r)
			reduce(dp[i] = pre[r] - pre[l - 2]);
		reduce(pre[i] = pre[i - 1] + dp[i] - mod);
	}
	int ans = pre[n] - pre[left[n] - 2];
	cout << ans + (ans >> 31 & mod) << '\n';
}


Measured memory_bytes: 2176
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int a[3];
    for(int i = 0;i < 3;i++)
    {
        cin >> a[i];
    }
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    for(int i = 0;i < 3;i++)
    {
        cout << a[i];
        if(i != 2)
        {
            cout << " ";
        }
    }
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int h = Integer.parseInt(sc.next());
			sc.next();
			for (int i = 0; i < h; i++) {
				String row = sc.next();
				System.out.println(row);
				System.out.println(row);
			}
		}
	}
}


Measured memory_bytes: 37264
#include<iostream>
using namespace std;
int sum(int a)
{
  if(a<=0) return 0;
  if(a==1) return 1;
  return a+sum(a-1);
}
int main()
{
  int a,b;
  cin>>a>>b;
  cout<<sum(a-1)+sum(b-1);
}

Measured memory_bytes: 3572
// AOL 1059 Mysterious Onslaught
// 2018.2.18 bal4u

#include <stdio.h>
#include <string.h>

int n;
int map[5][5][5][5];
char memo[1<<25];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int b)
{
	int r1, c1, r2, c2, k, ans;

	if (!b) return 0;
	if (memo[b] >= 0) return memo[b];

	for (k = r1 = 0; r1 < n; r1++, k += n) for (c1 = 0; c1 < n; c1++) {
		if (b & (1<<(k + c1))) goto next;
	}
next:
	ans = n*n;
	for (r2 = r1; r2 < n; r2++) for (c2 = c1; c2 < n; c2++) {
		k = b ^ map[r1][c1][r2][c2];
		k = calc(k) + 1;
		if (ans > k) { ans = k; if (ans == 1) break; }
	}
	return memo[b] = ans;
}

void init()
{
	int r1, r2, c1, c2, r, c;

	for (r1 = 0; r1 < n; r1++) for (c1 = 0; c1 < n; c1++)
		for (r2 = r1; r2 < n; r2++) for (c2 = c1; c2 < n; c2++)
			for (r = r1; r <= r2; r++) for (c = c1; c <= c2; c++)
				map[r1][c1][r2][c2] |= (1<<(r*n+c));
}

int main()
{
	int r, c, b, k;

	while (n = in()) {
		memset(map, 0, sizeof(map));
		memset(memo, -1, sizeof(memo));
		init();
		b = 0;
		for (k = r = 0; r < n; r++, k += n) for (c = 0; c < n; c++) {
			if (getchar_unlocked() & 1) b |= 1 << (k+c);
			getchar_unlocked();
		}
		k = calc(b);
		while (k--) printf("myon");
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 34508
import math

n = int(input())
lst = [0]*n
const = int(math.sqrt(n))

if n < 6:
  for i in range(n):
    print(0)
  exit()

for x in range(1, const):
  for y in range(1, const):
    for z in range(1, const):
      s = x*x + y*y + z*z + x*y + y*z + z*x
      if s > n:
        continue
      else:
        lst[s-1] += 1

for i in lst:
  print(i)

Measured memory_bytes: 9132
#include<iostream>
using namespace std;
int main(){
	int m,n;
	cin>>m>>n;
	char a[100][100];
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			cout<<a[i][j];
		}
		cout<<endl;
		for(int j=0;j<n;j++){
			cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  for(ll i=0; i<N; i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  ll ans=0;
  for(ll i=0; i<N; i++){
    ll num=1;
    while(A[i] == A[i+1]){
      num++;
      i++;
    }
    if(num%2 == 1){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::string S;

int main() {
  std::cin >> N >> S;

  rep( i, S.size() ) {
    S[i] = char((S[i]-'A'+N)%26+'A');
  }

  std::cout << S << endl;

  return 0;
}

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

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

    ll count = 0;
    count = N / 11 * 2;
    N %= 11;
    if(N == 0)
    {
        
    }
    else if(N <= 6)count++;
    else count += 2;
    
    cout << count << endl;
    return 0;
}

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

int main(){
  for(int i = 1; i < 10001; i++){
    int x, y;
    cin >> x >> y;
    if(x == 0 && y == 0){
      break;
    }
    else{
      cout << min(x, y) << " " << max(x, y) << endl;
    }
  }
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int n, k;
vi ans;

void dfs(vi v, int a) {
  if(a>=n) {
    ans.push_back(a);
    return;
  }
  rep(i,v.size()) {
    if(a==0&&v[i]==0) continue;
    dfs(v,a*10+v[i]);
  }
}

int main() {
  cin >> n >> k;
  vi d(k);
  rep(i,k) cin >> d.at(i);
  vi v;
  for(int i = 0; i <= 9; i++) {
    bool ok = true;
    rep(j,d.size()) {
      if(i==d[j]) ok = false;
    }
    if(ok) v.push_back(i);
  }
  dfs(v,0);
  sort(ans.begin(),ans.end());
  cout << ans[0] << endl;
  return 0;
}

Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    s = S()
    f = [0,0]
    for i in s:
        if "A" <= i <= "M":
            f[0] += 1
        elif "N" <= i <= "Z":
            f[0] -= 1
        elif "a" <= i <= "m":
            f[1] += 1
        else:
            f[1] -= 1
    ans = []
    for i in s:
        if "A" <= i <= "M" and f[0] > 0:
            f[0] -= 1
            ans.append(i)
        elif "N" <= i <= "Z" and f[0] < 0:
            f[0] += 1
            ans.append(i)
        elif "a" <= i <= "m" and f[1] > 0:
            f[1] -= 1
            ans.append(i)
        elif "n" <= i <= "z" and f[1] < 0:
            f[1] += 1
            ans.append(i)
    print(len(ans))
    print(*ans,sep = "")
    return

if __name__ == "__main__":
    solve()



Measured memory_bytes: 9608
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli c, d, e, f, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n >> k;
  vector<lli> a(n, 0), b(n + 1, 0);
  cin >> a;
  rep(i, 0, n)
  {
    b[a[i]]++;
  }
  SORT(b);
  repe(i, 0, n)
  {
    if (b[i] > 0)
      count++;
  }
  repe(i, 0, n)
  {
    if (b[i] > 0 && count > k)
    {
      ans += b[i];
      count--;
    }
  }
  cout << ans << endl;
}

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

public class Program
{
    static void Main()
    {
        int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int n = input[0];
        int k = input[1];
        bool[] sunuke = new bool[n];
        for (int i = 0; i < k; i++)
        {
            int d = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            for (int j = 0; j < d; j++)
            {
                sunuke[a[j] - 1] = true;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (!sunuke[i])
                ans++;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27648
def solve():
  n,k = map(int,input().split())
  h = list(map(int,input().split()))
  dp = [float("inf")]*n
  dp[0] = 0
  for i in range(0,n-1):
    for j in range(1,k+1):
      if (i-j)>=-1:
        dp[i+1]=min(dp[i+1],dp[i+1-j]+abs(h[i+1]-h[i+1-j]))
  print(dp[-1])
solve()


Measured memory_bytes: 55264
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<ll> a(n * 3);
  for(int i = 0;i < n * 3;i++)cin >> a[i];
  sort(a.rbegin(),a.rend());
  ll res = 0;
  for(int i = 0;i < n;i++){
    res += a[i * 2 + 1];
  }
  cout << res << endl;
}

Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 1e5 + 100;
const int mod = 1e9 + 7;

int add(int a, int b){
	a += b;
	if(a >= mod) a -= mod;
	return a;
}
int mul(int a , int b){
	return (a*1ll*b)%mod;
}
int sub(int a, int b){
	a -= b;
	if(a < 0)a += mod;
	return a;
}
int power(int x , int y){
	int res = 1;
	while(y){
		if(y&1)
			res = mul(res , x);
		x = mul(x , x);
		y >>= 1;
	}
	return res;
}
int fac[N];
int inv[N];
void pre(){
	fac[0] = 1;
	inv[0] = 1;
	for(int i =1 ;i < N ; ++i){
		fac[i] = mul(fac[i-1] , i);
		inv[i] = power(fac[i] , mod-2);
	}
}
int nCr(int n , int r){
	if(n < 0 || r < 0 || r > n)
		return 0;
	else
		return mul(fac[n] , mul(inv[r] , inv[n-r]));
}
int A[N];
int main(){
	fio; cout<<fixed<<setprecision(25);	
	int n , k; cin >> n >> k;
	for(int i =1 ;i <= n ; ++i)
		cin >> A[i];
	sort(A+1, A+n+1);
	pre();
	int ans = 0;
	for(int i = 1;i <= n;  ++i){
		ans = add(ans , mul(A[i] , nCr(i-1 , k-1)));
		ans = sub(ans , mul(A[i] , nCr(n-i , k-1)) );
	}
	cout << ans << endl;




	return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		String str[]=new String[a];
		int arr[]=new int[a];
		int ind[]=new int[a];
		for(int i=0;i<a;i++){
			str[i]=sc.next();
			arr[i]=sc.nextInt();
			ind[i]=i+1;
		}
			for(int i=0;i<a-1;i++){
				for(int j=i+1;j<a;j++){
					if(str[i].compareTo(str[j])>0){
						String t=str[i];
						str[i]=str[j];
						str[j]=t;
						int t1=arr[i];
						arr[i]=arr[j];
						arr[j]=t1;
						int t2=ind[i];
						ind[i]=ind[j];
						ind[j]=t2;
					}
						
				}
			}
			for(int i=0;i<a-1;i++){
				for(int j=i+1;j<a;j++){
					if(str[i].compareTo(str[j])==0&&arr[i]<arr[j]){
						String t=str[i];
						str[i]=str[j];
						str[j]=str[i];
						int t1=arr[i];
						arr[i]=arr[j];
						arr[j]=t1;
						int t2=ind[i];
						ind[i]=ind[j];
						ind[j]=t2;
						
					}
				}
			}
					for(int i=0;i<a;i++)
				System.out.println(ind[i]);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1001001001
#define LINF (1LL << 62)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solv() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N) {
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    int diff = INF;
    rep(i, N - K+1) {
        if (diff > h.at(i + K - 1) - h.at(i))
            diff = h.at(i + K - 1) - h.at(i);
     //   cout << h.at(i + K - 1) << h.at(i) << endl;
    }
    cout << diff << endl;
}

int main() {
    solv();
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#define S 1000000000
#define N 500000

int count =0;
void merge(int A[], int left, int mid, int right)
{
  int n1,n2,i,j,k,*L,*R;
  n1 = mid - left;
  n2 = right - mid;
  L = (int *)malloc(sizeof(int)*(n1+1));
  R = (int *)malloc(sizeof(int)*(n2+1));
  for(i = 0; i<=n1-1; i++){
    L[i] = A[left + i];
  }
  for(i = 0; i<=n2-1; i++){
    R[i] = A[mid + i];
  }
  L[n1] = S;
  R[n2] = S;
  i = 0;
  j = 0;
  for(k = left; k<=right-1; k++){
    if (L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
      count++;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
      count++;
    }
  }
  free(L);
  free(R);
}
void mergeSort(int A[], int left, int right)
{
  int i,mid;
  if (left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
      }
}
int main()
{
  int i,n,A[N];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0; i<n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  return 0;
}



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

bool check(int n,vector<bool>digit){
    while(n!=0){
        if(digit[n%10]==true){
            return false;
        }
        n/=10;
    }
    return true;
}


int main(){
    int n,k;
    cin>>n>>k;
    vector<bool>digits(10,false);
    for(int i=0;i<k;i++)
    {
        int element;
        cin>>element;
        digits[element]=true;
    }
    while(1){
        if(check(n,digits)){
            cout<<n;
            return 0;
        }
        n++;
    }
}

Measured memory_bytes: 3568
#include<stdio.h>

int main(void)
{

    int W,H;
    int i,j;

    scanf("%d %d",&H,&W);

    while(W != 0 && H != 0){
      for(i = 0;i<H;i++){
        for(j=0;j<W;j++){
          if(i == 0 || i == H-1 || j == 0 || j == W-1)
            printf("#");
          else
            printf(".");
        }
        printf("\n");
      }

      scanf("%d %d",&H,&W);
      printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2580
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
/*----------------------------------------------------------------------*/

int n,m;
const int N = 1e5+5;
vi g[N];
bool visited[N];
int dp[N];

void dfs(int curr, vi &ts) {
	visited[curr] = true;
	for(auto next: g[curr]) {
		if(!visited[next]) dfs(next, ts);
	}

	ts.push_back(curr);
}

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

    int u,v;
    cin>>n>>m;
    F(i, 0, m) {
    	cin>>u>>v; u--; v--;
    	g[u].push_back(v);
    }
    memset(visited, false, sizeof(visited));
    vi ts;
    memset(dp, 0, sizeof(dp));
    F(i, 0, n) {
    	if(!visited[i]) {
    		dfs(i, ts);
    	}
    }

    dp[ts[n-1]]=0;
    RF(i, n-1, 1) {
    	for(auto next: g[ts[i]]) {
            dp[next]=max(dp[next], dp[ts[i]]+1);
        }
    }
    cout<<*max_element(dp, dp+N);

    return 0;
}/*

*/


Measured memory_bytes: 8956
n, k = gets.split.map(&:to_i)
a = Array.new(n){gets.split.map(&:to_i)}
a.sort_by!{|x, y| x}
ans = a[0][0]
n.times do |i|
  ans = a[i][0]
  k -= a[i][1]
  break if k <= 0
end
puts ans

Measured memory_bytes: 12664
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}



Measured memory_bytes: 2760
n = int(input())
a = []
b=[]

for i in range(1,n+1):
  a.append(i)
count = 0


for i in range(1,n+1):
  
  count = 0
  while True:
    if (a[i-1]%2) == 0:
      count += 1
      a[i-1] = a[i-1]/2
      
    else:
      break
  b.append(count)


c =max(b)
print(b.index(c)+1)

Measured memory_bytes: 3064
#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.at(i);
  int ans = 0;
  int now = 1;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == now) {
      now++;
    } else ans++;
  }
  cout << ((ans == N) ? -1 : ans) << "\n";
}

Measured memory_bytes: 4024
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	map<string, int> freq;
	int n; cin >> n;
	int max_f = 0;
	for (int i = 1; i <= n; i++) {
		string s; cin >> s;
		freq[s]++;
		max_f = max(max_f, freq[s]);
	}

	for (auto i : freq) {
		if (i.ss == max_f) cout << i.ff << endl;
	}

	return 0;
}

Measured memory_bytes: 18748
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;
const int MaxM = MaxN * 2;
const int MaxSegN = MaxM * 4;

int n, m, k;
int vl[MaxN + 1], vr[MaxN + 1];

int li[MaxM + 1];

int seg[MaxSegN];

inline void seg_tag_down(int p)
{
	if (seg[p] > 0)
	{
		seg[p << 1 | 0] = seg[p];
		seg[p << 1 | 1] = seg[p];
		seg[p] = 0;
	}
}

void seg_cover(int p, int pL, int pR, int qL, int qR, int v)
{
	if (qL > qR)
		return;
	if (qL <= pL && qR >= pR)
	{
		seg[p] = v;
		return;
	}

	seg_tag_down(p);

	int pM = pL + pR >> 1;
	if (qL <= pM)
		seg_cover(p << 1 | 0, pL, pM, qL, qR, v);
	if (qR > pM)
		seg_cover(p << 1 | 1, pM + 1, pR, qL, qR, v);
}

int seg_query(int p, int pL, int pR, int q)
{
	if (pL == pR)
		return seg[p];

	seg_tag_down(p);

	int pM = pL + pR >> 1;
	if (q <= pM)
		return seg_query(p << 1 | 0, pL, pM, q);
	if (q > pM)
		return seg_query(p << 1 | 1, pM + 1, pR, q);
}

s64 f[MaxN + 1];

inline s64 query(int l)
{
	int v = seg_query(1, 1, m, l);
	return !v ? 0 : f[v] + (li[vl[v]] - li[l] + k) % k;
}

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

	s64 sum = 0;
	int pre = 0;
	for (int i = 1; i <= n; ++i)
	{
		int a = getint() * 2;
		int t = getint();
		sum += a;

		if (t == 1 && a > k)
		{
			cout << -1 << endl;
			return 0;
		}

		a = (pre - a % k + k) % k;

		if (t == 2)
			vl[i] = 0, vr[i] = k - 1;
		else
			vl[i] = pre, vr[i] = a;

		pre = a;

		li[++m] = vl[i];
		li[++m] = vr[i];
	}

	sort(li + 1, li + m + 1);
	m = unique(li + 1, li + m + 1) - li - 1;

	for (int i = n; i >= 1; --i)
	{
		vl[i] = lower_bound(li + 1, li + m + 1, vl[i]) - li;
		vr[i] = lower_bound(li + 1, li + m + 1, vr[i]) - li;
		f[i] = query(vl[i]);

		if (vl[i] <= vr[i])
		{
			seg_cover(1, 1, m, 1, vl[i] - 1, i);
			seg_cover(1, 1, m, vr[i] + 1, m, i);
		}
		else
			seg_cover(1, 1, m, vr[i] + 1, vl[i] - 1, i);
	}

	s64 res = f[1];
	for (int l = 1; l <= m; ++l)
		res = min(res, query(l));

	cout << res + sum << endl;

	return 0;
}

Measured memory_bytes: 5504
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

#define MOD ((lli)(1000000007))
lli mop(lli p,lli q){
	lli res=1,bp=p,b=1;
	while(q){
		if(q&b){
			res=(res*bp)%MOD;
			q-=b;
		}
		bp=(bp*bp)%MOD;
		b*=2;
	}
	return res;
}

lli inv(lli p){
	return mop(p,MOD-2);
}

lli fdat[500005];

lli fact(int p){
	if(fdat[p]>=0)return fdat[p];
	lli res=1;
	reg(i,1,p)res=(res*i)%MOD;
	return (fdat[p]=res);
}

lli comb(lli p,lli q){
	lli res=(((fact(p)*inv(fact(q)))%MOD)*inv(fact(p-q)))%MOD;
	return res;
}


lli nk(int p,int q){ //p+q susumi q modoru
	if(q<=0)return 1;
	return (MOD + comb(p+2*q,q) - comb(p+q*2,q-1))%MOD;
	//
}

int n,m,k;
int main(void){
	
	memset(fdat,-1,sizeof(fdat));
	//printf("%lld\n",nk(2,1));
	//printf("%lld\n",nk(3,2));
	
	scanf("%d%d%d",&n,&m,&k);
	lli ans = 0;
	reg(i,0,k){
		lli na = comb(n+m+k*2,n+i*2);
		//printf("%lld\n",na);
		na = (na * nk(n,i))%MOD;
		na = (na * nk(m,k-i))%MOD;
		ans = (ans+na)%MOD;
	}
			
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 5100
N=int(input())
li=[]
ans="Yes"
t=0
for i in range(N):
    A,B=map(int,input().split())
    li.append([B,A])
li.sort()

for j in range(N):
    t+=li[j][1]
    if t<=li[j][0]:
        pass
    else:
        ans="No"
        
print(ans)


Measured memory_bytes: 38156
// 2_abc132_b
#include <algorithm>
#include <bitset>
#include <complex>
#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>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#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>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }
    int ans = 0;
    for(int i = 1; i < n - 1; i++){
        if((p[i] - p[i - 1]) * (p[i] - p[i + 1]) < 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define EPS 1e-9
#define For(i,N) FOR(i,N)
#define Forr(i,a,b) FORR(i,a,b)
#define Fotr(i,a,b,c) FOTR(i,a,b,c)
#define FOR(i,N) FORR(i, 0, N)
#define FORR(i,a,b) FOTR(i, a, b, 1)
#define FOTR(i,a,b,c) for(int i=(a);i<(b);i+=(c))
#define FOREACH(i,x) for(__typeof__((x).begin())i=(x).begin();i!=(x).end();i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define BCHK(a,x) (((a)>>(x))&1)
#define BSET(a,x) ((a)|(1<<(x)))
#define BCLR(a,x) ((a)&(~(1<<(x))))
#define BTGL(a,x) ((a)^(1<<(x)))
#define FMT(...) (sprintf(CRTBUFF, __VA_ARGS__)?CRTBUFF:0)
#define read() freopen("input.txt","r",stdin)
#define write() freopen("output.txt","w",stdout)
#define cpp_io() {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define BUFFSIZE 30000
#define INF 1000000000
#define MAX 300010
#define MOD 1000000007
#define pb push_back
#define mkpr make_pair
#define pii pair<int, int>
#define PI acos(-1)
#define ll long long
#define fi first
#define si second
#define all(x) x.begin(), x.end()

char CRTBUFF[BUFFSIZE];
#define dbg(args...) {cerr<<"-->";debugger::call(#args,args);cerr<<"\n";}
struct debugger {
    static void call(const char* it) {}
    template<typename T, typename ... aT>
    static void call(const char* it, T a, aT... rest) {
        string b;
        for (; *it&&*it != ','; ++it) if (*it != ' ')b += *it;
        cerr << b << "=" << a << " ";
        call(++it, rest...);
    }
};
ll power(ll x,ll y)
{
    if( y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);

}
int main(){
    cpp_io();
    #ifdef LOCAL
        //read();
        //write();
    #endif
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string x;
    cin>>x;
    if(x==s) cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;





    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long dp[2010][2010];
const int mod = 1e9+7;
template<typename T> void add(long long& l, const T r) {
    l += r;
    if (l > mod) l -= mod;
}
template<typename T> void sub(long long& l, const T r) {
    if (l < r) l += mod;
    l -= r;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    for (auto &s : S) {
        cin >> s;
    }
    for (auto &t : T) {
        cin >> t;
    }
    dp[0][0] = 1;
    for (int i = 0; i < N; ++i) {
        dp[i+1][0] = 1;
    }
    for (int j = 0; j < M; ++j) {
        dp[0][j+1] = 1;
    }
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            add(dp[i+1][j+1], dp[i+1][j]);
            add(dp[i+1][j+1], dp[i][j+1]);
            sub(dp[i+1][j+1],  dp[i][j]);
            if (S[i] == T[j]) {
                add(dp[i+1][j+1], dp[i][j]);
            }
        }
    }
    printf("%lld\n", dp[N][M]);
    return 0;
}


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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#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 NP(v) next_permutation(v.begin(),v.end())
#define debug(x) cout << #x << ":" << x << endl;
#define debug2(x) for(auto a : x) cout << a << " "; cout << endl;
#define debug3(x) rep(i, sizeof(x)) cout << x[i] << " "; cout << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

//------------------------------------------------------

const int MAX_V = 1000;

template <typename T = int, typename U = ll> class MaxFlow {
public:

    struct edge {
        T to;
        U cap, rev;
    };

    map<T, vector<edge> > G;
    map<T, bool> used;

    void add_edge(T from, T to, U cap) {
        G[from].push_back((edge){to, cap, G[to].size()});
        G[to].push_back((edge){from, 0, (U) G[from].size() - 1});
    }

    U dfs(T v, T t, U f) {
        if (v == t) return f;
        used[v] = true;
        for (auto&& e : G[v]) {
            if (!used[e.to] && e.cap > 0) {
                U d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    U max_flow(T s, T t) { //sからtへの最大流
        U flow = 0;
        while (1) {
            used.clear();
            U f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //pairの最大値のtest
    int n;
    cin >> n;
    MaxFlow<pii> mf;
    int a[n], b[n], c[n], d[n];
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n) cin >> c[i] >> d[i];

    rep(red, n) rep(blue, n) {
        if (a[red] < c[blue] && b[red] < d[blue]) {
            mf.add_edge(MP(a[red], b[red]), MP(c[blue], d[blue]), 1);
        }
    }

    rep(i, n) {
        mf.add_edge(MP(-1, -1), MP(a[i], b[i]), 1);
        mf.add_edge(MP(c[i], d[i]), MP(INF, INF), 1);
    }
    cout << mf.max_flow(MP(-1, -1), MP(INF, INF)) << endl;
    return 0;
}



Measured memory_bytes: 512
// 9/19 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    int count = 0;

    bool ans = false;

    while (N--) {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2) {
            count++;
            if (count == 3) {
                ans = true;
                // break;
            }
        } else {
            count = 0;
        }
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;



Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else {
    return treeSearch(u->right,k);
  }
}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NIL){
    root = z;
  }else{
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void inorder(Node u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

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


int main(){
  int n, i, x;
  char com[20];
  Node t;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
       t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int L, R; cin >> L >> R;
    int l = L / 2019, r = R / 2019;
    R %= 2019;
    L %= 2019;
    if(l != r) {
        cout << 0 << endl;
        return 0;
    } else {
        int ans = 2018;
        for(int i = L; i < R; i++) {
            for(int j = i + 1; j <= R; j++) {
                int res = i * j % 2019;
                ans = min(ans, res);
            }
        }
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
l = gets.chomp.split(" ").map(&:to_i)
f = l.size
a =l.max
all = 0
(0..f-1).each do |i|
    all += l[i]
end

if all - a > a
    puts "Yes"
else
    puts "No"
end


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


int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());

  ll ans=0;
  for(int i=1;i<N;i++){
    ans+=A[i/2];
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 131072
#define B 100
#define dpb push_back
#define fi first
#define se second
typedef pair<int, int> P;
typedef long long ll;
const int inf = 1e9;
const ll INF = 2147483647;
//__gcd(a,b), __builtin_popcount(a);

int n;
ll dat[MAX*2], add[MAX*2];
void init(int m){
	n = 1;
	while(n < m)n *= 2;
	for(int i = 0;i < 2*n;i++)dat[i] = INF;
	for(int i = 0;i < 2*n;i++)add[i] = -1;
}

void lazy_update(int k){
	if(add[k] == -1)return;
	if(k < n-1){
		add[k*2+1] = add[k];
		add[k*2+2] = add[k];
	}
	add[k] = -1;
}

void update(int a, int b, int x, int k, int l, int r){
	if(r <= a || b <= l)return;
	if(a <= l && r <= b){
		add[k] = dat[k] = x;
		lazy_update(k);
		return;
	}
	if(add[k] != -1)dat[k] = add[k];
	lazy_update(k);
	update(a, b, x, k*2+1, l, (l+r)/2);
	update(a, b, x, k*2+2, (l+r)/2, r);
	ll t1 = dat[k*2+1], t2 = dat[k*2+2];
	if(add[k*2+1] != -1)t1 = add[k*2+1];
	if(add[k*2+2] != -1)t2 = add[k*2+2];
	dat[k] = min(t1, t2);
	return;
}

ll find(int a, int b, int k, int l, int r){
	if(r <= a || b <= l)return INF;
	if(a <= l && r <= b){
		if(add[k] != -1){
			dat[k] = add[k];
		}
		lazy_update(k);
		return dat[k];
	}
	if(add[k] != -1)dat[k] = add[k];
	lazy_update(k);
	ll vl = find(a, b, k*2+1, l, (l+r)/2);
	ll vr = find(a, b, k*2+2, (l+r)/2, r);
	/*ll t1 = dat[k*2+1], t2 = dat[k*2+2];
	if(add[k*2+1] != -1)t1 = add[k*2+1];
	if(add[k*2+2] != -1)t2 = add[k*2+2];*/
	return min(vr, vl);
}

int main(){
	int m, q, c, s, t, x;
	scanf("%d%d", &m, &q);
	init(m);
	while(q--){
		scanf("%d", &c);
		if(c == 0){
			scanf("%d%d%d", &s, &t, &x);
			update(s, t+1, x, 0, 0, n);
		}else{
			scanf("%d%d", &s, &t);
			ll ans = find(s, t+1, 0, 0, n);
			printf("%lld\n", ans);
		}
	}
	return 0;
}



Measured memory_bytes: 7288
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

int main()
{
    int n, t;
    std::cin >> n >> t;
    std::vector<int> list;
    list.reserve(n);
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        std::cin >> tmp;
        list.push_back(tmp);
    }

    std::vector<int> min_list(n);
    int a = list[0];
    for (int i = 0; i < n; ++i)
    {
        if (list[i] < a)
        {
            a = list[i];
        }
        min_list[i] = a;
    }

    std::unordered_map<int, int> profits;
    int max_profit = 0;
    for (int i = 0; i < n; ++i)
    {
        const int tmp = list[i] - min_list[i];

        max_profit = std::max(max_profit, tmp);
        ++profits[tmp];
    }

    std::cout << profits[max_profit] << std::endl;
    return 0;
}


Measured memory_bytes: 5156