akhauriyash/Code-Regression huggingface dataset:
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        x: i64,
        y: i64,
        xa: [i64; n],
        ya: [i64; m],
    }

    for z in (x+1)..(y+1) {
        let mut war = false;
        for &xi in &xa {
            if !(xi < z) {
                // この z では戦争が起こる
                war = true;
                break;
            }
        }

        if war {
            continue;
        }

        for &yi in &ya {
            if !(yi >= z) {
                // この z では戦争が起こる
                war = true;
                break;
            }
        }

        if war {
            continue;
        }

        // ここまでこれれば戦争は起こらない
        println!("No War");
        return;
    }

    // ここまで来てしまったら戦争は避けられない
    println!("War");
}


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





int main() 
{
  ll N,Q; cin>>N>>Q;
  string S; cin>>S;
  vector<ll> kosu(N);
  rep(i,N)
  {
    if(i==0) {kosu.at(0)=0; continue;}
    if(S.substr(i-1,2)=="AC") {kosu.at(i)=kosu.at(i-1)+1; continue;}
    kosu.at(i)=kosu.at(i-1);
  } 
  /*rep(i,N)
  {
    if(i!=0) {cout<<" ";}
    cout<<kosu.at(i);
    if(i==N-1) {cout<<endl;}
  } */ 
  rep(i,Q)
  {
    ll l,r; cin>>l>>r;
    l--; r--;
    cout<<kosu.at(r)-kosu.at(l)<<endl;
  }  
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int sum = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
            sum ^= a[i];
        }
        sc.close();

        // 主処理
        String[] ans = new String[n];
        for (int i = 0; i < n; i++) {
            int num = sum ^ a[i];
            ans[i] = Integer.toString(num);
        }
        String result = String.join(" ", ans);

        // 出力
        System.out.println(result);
    }
}

Measured memory_bytes: 69460
import collections
INF = 10**18
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
koho = []
d = [[-1]*w for i in range(h)]
q = collections.deque([])
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            d[i][j] = 0
            q.append([i,j])
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while q:
    p = q.popleft()
    y = p[0]
    x = p[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0<=nx<w and 0<=ny<h:
            if d[ny][nx] == -1:
                q.append([ny,nx])
                d[ny][nx] = d[y][x] + 1
ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans,d[i][j])
print(ans)

Measured memory_bytes: 176476
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long int ans=0;
    int N,T;
    cin>>N>>T;
    int t[N+1];
    scanf("%d",&t[0]);
    for(int i=1;i<N;i++){
        scanf("%d",&t[i]);
        ans+=min(t[i]-t[i-1],T);
    }
    ans+=T;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
X, Y = map(int, input().split(" "))
mod = 10 ** 9 + 7
if (2 * Y - X) % 3 == 0 and (2 * X - Y) % 3 == 0:
    n, m = (2 * Y - X) // 3, (2 * X - Y) // 3
    if n < 0 or m < 0:
        print(0)
    else:
        fact = [1, 1]
        inv = [1, 1]
        inv_fact = [1, 1]
        for i in range(2, n + m + 1):
            fact.append((fact[-1] * i) % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            inv_fact.append((inv_fact[-1] * inv[-1]) % mod)
        ans = fact[n + m] * inv_fact[n] * inv_fact[m]
        print(ans % mod)
else:
    print(0)

Measured memory_bytes: 118764
#include<bits/stdc++.h>
using namespace std;
string s;
int minn=1e9;
int main(){
	cin>>s;
	int n=s.size();
	for(int i=0;i<n-1;i++){
		if(s[i]!=s[i+1]){
			minn=min(minn,max(n-i-1,i+1));
		}
	}
	if(minn==1e9){
		cout<<n;
	}
	else
	{
		cout<<minn;
	}
} 

Measured memory_bytes: 512
A, B = gets.split(' ').map(&:to_i)

numbers = []
if B - A < 8
  numbers = (A..B)
else
  numbers.push(A)
  (1..3).each do |i|
    if (A + i) % 4 != 0
      numbers.push(A + i)
    else
      break
    end
  end
  numbers.push(B)
  (1..3).each do |i|
    if (B - i) % 4 != 3
      numbers.push(B - i)
    else
      break
    end
  end
end

puts numbers.inject(:^)

Measured memory_bytes: 3836
#include<iostream>
#include<string>
#include<algorithm>
 
typedef long long ll;
using namespace std;
int main()
{
	int a;
	cin >> a;
	if (a == 1)
	{
		cout << 1 << endl;
	}
	if (1 < a && a < 4)
	{
		cout << 2 << endl;
	}
	if (3 < a && a < 8)
	{
		cout << 4 << endl;
	}
	if (7 < a && a < 16)
	{
		cout << 8 << endl;
	}
	if (15 < a && a < 32)
	{
		cout << 16 << endl;
	}
	if (31 < a && a < 64)
	{
		cout << 32 << endl;
	}
	if (63 < a)
	{
		cout << 64 << endl;
	}
}

Measured memory_bytes: 256
package main

import "fmt"

func isEven(n int) bool { return n%2 == 0 }

type point struct{ x, y int }
type ppoint struct{ now, next point }

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	ass := make([][]int, h)
	for i := 0; i < h; i++ {
		ass[i] = make([]int, w)
		for j := 0; j < w; j++ {
			fmt.Scan(&ass[i][j])
		}
	}

	anss := make([]ppoint, 0, h*w)
	for iy := 0; iy < h; iy++ {
		for ix := 0; ix < w; ix++ {
			var now point
			if isEven(iy) {
				now.x = ix
				now.y = iy
			} else {
				now.x = w - 1 - ix
				now.y = iy
			}

			var next point
			if isEven(now.y) {
				if now.x == w-1 {
					next.x = now.x
					next.y = now.y + 1
				} else {
					next.x = now.x + 1
					next.y = now.y
				}
			} else {
				if now.x == 0 {
					next.x = now.x
					next.y = now.y + 1
				} else {
					next.x = now.x - 1
					next.y = now.y
				}
			}

			if next.y > h-1 {
				break
			}

			if isEven(ass[now.y][now.x]) {
				continue
			}
			ass[now.y][now.x]--
			ass[next.y][next.x]++
			pp := ppoint{now: now, next: next}
			anss = append(anss, pp)
		}
	}

	fmt.Println(len(anss))
	for _, pp := range anss {
		fmt.Println(pp.now.y+1, pp.now.x+1, pp.next.y+1, pp.next.x+1)
	}
}


Measured memory_bytes: 15488
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

int main(){
  vector<int> v;
  for(int i = 0; i < 10; i++){
    int b;
    cin >> b;
    v.push_back(b);
  }
  sort(v.begin(), v.end(), greater<int>());
  cout << v[0] << endl << v[1] << endl << v[2] << endl;
}

Measured memory_bytes: 1216
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while numB < M:
        if timeB + B[numB] <= K - timeA:
            timeB += B[numB]
            numB += 1
        else:
            break
    ans = max(ans, t + numB)
print(ans)

Measured memory_bytes: 42216
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
main(){
	int n,m,p,q,r,x,y;
	vector<int>::iterator v,w,z;
	for(;cin>>n>>m>>p>>q>>r;cout<<x<<endl){
	vector<int>t(1),u;

	for(t.push_back(r);m--;u.clear()){
		cin>>x>>y;
		v=upper_bound(t.begin(),t.end(),x);
		w=upper_bound(t.begin(),t.end(),y);

		u.insert(u.end(),w-t.begin()&1?1:2,0);
		for(z=w;z<t.end();++z)
			u.push_back(*z-y);
			
			if(t.end()-v&1)u.push_back(n-y);
			for(z=v;z<w;++z)
				u.push_back(*z-x+n-y);
			
			z=t.begin();
			if(w-t.begin()&1)++z;
			if(!z[1])z+=2;
			if(*z+n-x==u.back())++z,u.pop_back();
			for(;z<v;++z)
				u.push_back(*z+n-x);
			
			t.swap(u);
		}
		t.insert(upper_bound(t.begin(),t.end(),p-1),2,p-1);
		t.insert(lower_bound(t.begin(),t.end(),q),q);
		t.push_back(n);
		z=upper_bound(t.begin(),t.end(),p-1);
		if(z-t.begin()&1)--z;
		for(x=0;*z<q;
			x+=*++z-m,++z)
			m=*z;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);

struct UnionFind{
  vector<int> data;
  int __size;
  UnionFind(int sz) {
  data.assign(sz, -1);
  __size = sz;
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);//親は負でサイズを保存
    __size--;
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }

  int union_count() {
    return (__size);
  }
};

int main() {
  int n, m;
  cin >> n >> m;
 
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }
  
  auto calc = [&](ll n) {
    return n * (n - 1) / 2;
  };

  ll res = 0;

  ll x = uf.size(0), y = uf.size(1);
  ll z = n - x - y;
  res = max(calc(x + z) + calc(y) - m, calc(y + z) + calc(x) - m);
  cout << res << endl;
  return 0; 
} 

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

int main(){
  int N,M; cin>>N>>M;
  vector<int>A(0);
  vector<int>B(0);
 
  for(int i=0;i<M;i++){
    int a,b; cin>>a>>b;
    if(a==1)
      A.push_back(b);
    if(b==N)
      B.push_back(a);
  }
  
  vector<int>check(200000);
  for(int i=0;i<200000;i++)
    check.at(i)=2;
  
  for(int i=0;i<A.size();i++)
    check.at(A.at(i)-1)--;
  for(int i=0;i<B.size();i++)
    check.at(B.at(i)-1)--;
  
  bool OK=false;
  
  for(int i=0;i<200000;i++){
    if(check.at(i)==0)
      OK=true;
  }
  
  if(OK)
    cout<<"POSSIBLE"<<endl;
  else
    cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mod 1000000007
#define null NULL
#define test cout<<"#"
#define maX 1000000000
 
ll ans[100001];
 
void solve(vector<ll> &w, vector<ll> &v, ll n, ll wt)
{	
	for(ll x = 0; x < n; x++)
	{
		for(ll y = wt; y>=0; y--)
		{
			if(w[x]<=y)
				ans[y] = max(ans[y], ans[y - w[x]]+v[x]);
		}
	}
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	memset(ans, 0, sizeof(ans));
    ll n, w;
	cin>>n>>w;
    vector<ll> a(n);
	vector<ll> b(n);
    for(ll x = 0; x < n; x++)
	{
		cin>>a[x];
		cin>>b[x];
	}
	solve(a, b, n, w);
	cout<<ans[w];
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

int per[8];
vector<int> g[8];
int n;
int m;

bool ispath(int x){
    if(x == 0){
        if(per[x] != 0){
            return false;
        }
    }
    // cout << x << endl;
    if (x == n - 1){
        return true;
    }
    for (int i = 0; i < g[per[x]].size(); i++){
        if (g[per[x]][i] == per[x+1]){
            return ispath(x + 1);
        }
    }
    return false;
}

int main(){
    cin >> n >> m;
    int a, b;
    rep(i, m){
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i, n) per[i] = i;
    int ans = 0;
    do{

        // rep(i, n) cout << per[i];
        // cout << endl;
        if (ispath(0)){
            ans++;
        }
    }while(next_permutation(per, per + n));
    cout << ans << endl;
    
}

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

using namespace std;

int main() {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (a * b > c * d) {
		printf("%d\n", a * b);
	} else {
		printf("%d\n", c * d);
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll n, a, b, c, d, e;
	cin>>n>>a>>b>>c>>d>>e;
	ll m = min({a, b, c, d, e});
	cout<<(n + m - 1)/m + 4<<endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = max(hc)
    maw = max(wc)
    ans = mah+maw
    hmaps = []
    wmaps = []
    for i, h in enumerate(hc):
        if mah == h:
            hmaps.append(i)
    for i, w in enumerate(wc):
        if maw == w:
            wmaps.append(i)

    for h in hmaps:
        for w in wmaps:
            if (h, w) not in maps:
                print(ans)
                return
    else:
        print(ans-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 177564
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main() {
  ll N;
  cin>>N;
  ll A[101]={};
  for(int i=1;i<10;++i){
    for(int j=1;j<10;++j){
      A[i*j]=1;
    }
  }
  putYN(A[N]==1);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt()-1;
		
		}
		sc.close();
		int temp = -1;
		
		for(int i = 0; i < n-1 ; i++) {
			if(h[i] - h[i+1] == 1) {
				h[i+1] = h[i+1] + 1;
			}
			if(h[i] - h[i+1] >= 2) {
				temp = 0;
			break;
		 }
		}
		if(temp == -1) {
			System.out.println("Yes");
			
		}
		if(temp == 0) {
			System.out.println("No");
		}

	}
	}


Measured memory_bytes: 49476
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    K = read_int()
    S = input().strip()
    if len(S) <= K:
        return S
    return S[:K]+'...'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;

int main()
{
    int n; cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];

    int cut = 0, ans = 0;

    rep(i,n) {
        if (a[i] % 2 == 0) {
            cut++;
            if (a[i] % 3 == 0 || a[i] % 5 == 0) {
                ans++;
            }
        }
    }

    if (ans == cut) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    let mut sn = 0;
    let mut x = n;
    while x > 0 {
        sn += x % 10;
        x /= 10;
    }
    let res = if n % sn == 0 {"Yes"} else {"No"};
    println!("{}", res);
}


Measured memory_bytes: 4352
#include <cstdio>

using namespace std;

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

    int p[N + 1];

    for (int i = 1; i <= N; ++i) {
        scanf("%d", &p[i]);
    }

    int twisted = -1;

    for (int i = 1; i <= N; i++) {
        if (p[i] != i) {
            if (twisted == -1) {
                twisted = p[i];
            } else if (twisted == i) {
                twisted = 0;
            } else if (twisted != i) {
                printf("NO\n");
                return 0;
            }
        }
    }

    printf("YES\n");

    return 0;
}

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

using namespace std;

using ll = long long;
using LL = long long;
using vi = vector<int>;
LL INF = 100000000000LL;

// https://scrapbox.io/ganariya/%E9%81%85%E5%BB%B6%E8%A9%95%E4%BE%A1%E3%82%BB%E3%82%B0%E3%83%A1%E3%83%B3%E3%83%88%E6%9C%A8%E3%80%80%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA
struct LazySegmentTree {
private:
  LL n;
  vector<LL> node, lazy;
  vector<bool> lazyFlag;

public:
  LazySegmentTree(vector<LL> v) {
    LL sz = (LL) v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, INF);
    lazyFlag.resize(2 * n - 1, false);

    for (LL i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (LL i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
  }

  void lazyEvaluate(LL k, LL l, LL r) {
    if (lazyFlag[k]) {
      node[k] = min(node[k], lazy[k]);
      if (r - l > 1) {
        lazy[k * 2 + 1] = min(lazy[k * 2 + 1], lazy[k]);
        lazy[k * 2 + 2] = min(lazy[k * 2 + 2], lazy[k]);
        lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
      }
      lazyFlag[k] = false;
    }
  }

  void update(LL a, LL b, LL x, LL k = 0, LL l = 0, LL r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = min(lazy[k], x);
      lazyFlag[k] = true;
      lazyEvaluate(k, l, r);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }

  LL find(LL a, LL b, LL k = 0, LL l = 0, LL r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return INF;
    if (a <= l && r <= b) return node[k];
    LL vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
    LL vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  LazySegmentTree lr(vector<ll>(1 << 20, 0));
  for (int i = 0; i < n; i++) {
    ll l = max(0LL, a[i] - k), r = a[i] + k + 1;
    ll v = lr.find(l, r);
    lr.update(a[i], a[i] + 1, v - 1);
  }
  cout << -lr.find(0, 300001) << endl;
  return 0;
}


Measured memory_bytes: 46772
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>

#define MAX(x,y) (x>y)?x:y
#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end());
#define ll long long 
#define INF 2000000000
#define MAX(x,y) (x>y)?x:y

using namespace std;
int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
	else {
		int max = 0;
		if (max < a) max = a;
		if (max < b)max = b;
		if (max < c)max = c;

		if (max == a) cout << b*c << endl;
		else if (max == b)cout << a*c << endl;
		else if (max == c)cout << a*b << endl;

	}


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(abs(a-b) > 10e18) cout << "Unfair" << endl;
  else{
    if(k % 2 == 0){
      cout << a - b << endl;
    }else{
      cout << b - a << endl;
    }
  }
  return 0;
}

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

ll N;

ll answer = 0;
void dfs(ll num, ll threeCount, ll fiveCount, ll sevenCount, ll nokoriKeta)
{
    if(num <= N && threeCount && fiveCount && sevenCount)
    {
        answer++;
    }
    if(nokoriKeta == 0)
    {
        return;
    }
    dfs(num * 10 + 3, threeCount + 1, fiveCount, sevenCount, nokoriKeta - 1);
    dfs(num * 10 + 5, threeCount, fiveCount + 1, sevenCount, nokoriKeta - 1);
    dfs(num * 10 + 7, threeCount, fiveCount, sevenCount + 1, nokoriKeta - 1);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    ll tmp = N;
    ll keta = 0;
    while(tmp)
    {
        keta++;
        tmp /= 10;
    }
    dfs(0, 0, 0, 0, keta);
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int N, M, T, a, t = 0, ans = 0;
  cin >> N >> M >> T;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    if (!i) {
      if (a > M) ans += a - M;
      t = a;
    } else {
      if (t + 2*M < a) ans += a - t - 2*M;
      t = a;
    }
  }
  if (t + M < T) ans += T - t - M;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3108
a, b, c, d, e, f = map(int, input().split())
a, b = 100 * a, 100 * b
limit = 100 * e / (100 + e)
mx = -1

for i in range(f // a + 1):
    for j in range((f - i * a) // b + 1):
        for k in range((f - i * a - j * b) // c + 1):
            for l in range((f - i * a - j * b - k * c) // d + 1):
                water = i * a + j * b + k * c + l * d
                sugar = k * c + l * d
                if water > f or water == 0:
                    break
                if (100 * sugar / water) <= limit:
                    if (100 * sugar / water) > mx:
                        mx = (100 * sugar / water)
                        x, y = water, sugar
print(x, y)

Measured memory_bytes: 3064
#include<string>
#include<vector>
#include<iostream>

using namespace std;

bool isDelimiter(char c){return c==' '||c=='.'||c==',';}

int main()
{
	string s;	getline(cin,s);
	vector<string> vs;
	for(int i=0,b=0;i<s.length();i++){
		if(isDelimiter(s[i])){
			if(3<=i-b && i-b<=6)
				vs.push_back(s.substr(b,i-b));
			b=i+1;
		}
	}

	for(int i=0;i<vs.size();i++)	cout<<(i?" ":"")<<vs[i];
	cout<<endl;

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

//using WG = map<int,map<int,ll>>; // weighted graph
template<typename W>
// verified with https://beta.atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_d
// example const ll inf=1e15;
void dijkstra(int s, map<int,map<int,W>>& g, vector<W>& dist, const W inf) {
  vector<bool> visited(dist.size());
  fill(dist.begin(),dist.end(),inf);
  using P = pair<W,int>;
  priority_queue<P,vector<P>, greater<P>> pq;
  dist[s]=0;
  //visited[s]=true;
  pq.push(make_pair(0,s));
  while(!pq.empty()) {
    int v;
    W d;
    tie(d,v)=pq.top();
    pq.pop();
    if(visited[v]) continue;
    visited[v]=true;
    for(auto& uw : g[v]) {
      int u;
      W w;
      tie(u,w)=uw;
      if(visited[u]) continue;
      if(d+w<dist[u]) {
        dist[u]=d+w;
        pq.push(make_pair(dist[u],u));
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll xs,ys,xt,yt;
  cin>>xs>>ys>>xt>>yt;
  int n;
  cin>>n;
  vector<ll> x(n+2);
  vector<ll> y(n+2);
  vector<ll> r(n+2);
  x[0]=xs;
  y[0]=ys;
  r[0]=0;
  x[1]=xt;
  y[1]=yt;
  r[1]=0;
  rep(i,n)cin>>x[i+2]>>y[i+2]>>r[i+2];
  using WG = map<int,map<int,double>>;
  WG g;
  vector<double> dist(n+2);
  rep(i,n+2) {
    rep(j,n+2) {
      if(i==j)
        continue;
      ll dx=x[i]-x[j];
      ll dy=y[i]-y[j];
      g[i][j]=max(0.0,sqrt(dx*dx+dy*dy)-r[i]-r[j]);
    }
  }
  dijkstra<double>(0,g,dist,1e15);
  cout << fixed;
  cout << dist[1] << endl;
  return 0;
}


Measured memory_bytes: 68464
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

mint f(int n){
    if(n == 0)return 1;
    mint x= f(n/2);
    x*=x;
    if(n%2==1)x*=2;
    return x;
}

mint choose(int n,int a){
    mint x=1,y=1;
    REP(i,a){
        x*=n-i;
        y*=i+1;
    }
    return x/y;
}

int main(void){
    int n,a,b;
    cin >> n >> a >> b;
    mint ans=f(n);
    ans-=1;
    ans -= choose(n,a);
    ans -= choose(n,b);
    cout << ans.x;
    return 0;
}

Measured memory_bytes: 3648
loop do
    n, q = gets.split.map(&:to_i)
    break if n == 0 && q == 0
    date = Array.new(101, 0)
    n.times do
        d = gets.split.map(&:to_i)
        for i in 1...d.size
            date[d[i]] += 1
        end
    end
    max = maxi = 0
    date.each_with_index do |d, i|
        next if d < q
        if d > max
            max = d
            maxi = i
        end
    end
    puts maxi
end

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

int main()
{
    int h,w;
    cin>>h>>w;
    
    char a[h][w];
    
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        cin>>a[i][j];
    }
    
    int m=1e9+7;
    int dp[h][w];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
                if(a[i][j]=='.')
                {
                    //cout<<i<<" "<<j<<endl;
                    if(i+1<h)
                    {
                        dp[i+1][j]+=dp[i][j];
                        if(dp[i+1][j]>m)
                        dp[i+1][j]-=m;
                    }
                    
                    if(j+1<w)
                    {
                        dp[i][j+1]+=dp[i][j];
                        if(dp[i][j+1]>m)
                        dp[i][j+1]-=m;
                    }
                    
                    
                }
  
        }
    }
    
   
    
    cout<<dp[h-1][w-1];
    
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

string  S;


int main()
{
  cin >> S;
  int t,d;
  vector<int> v(0);
  for(int i=0;i<S.size()-1;i++){
    if(S[i] != S[i+1])
      v.push_back(max(i+1,(int)S.size()-i-1));
  }
  if(v.size() == 0){
    cout << S.size() << endl;
  }else{
    sort(v.begin(),v.end());
    cout << v[0] << endl;
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}



Measured memory_bytes: 896
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = 0
H_ = H
flag = True
for j in sorted(throw_l)[::-1]:
    H_ -= j
    ans += 1
    if H_ <= 0:
        flag = False
        break
if flag:
    ans = (H - sum(throw_l))/swing_m
    ans = math.ceil(ans)
    print(ans+len(throw_l))
else:
    print(ans)

Measured memory_bytes: 13348
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;

using namespace std;

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());

    for (int i = 0; i < (int)s.length() - 1; i++)
    {
        if (s[i]==s[i+1]) {
            cout << "no";
            return 0;
        }
    }
    cout << "yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    string s;
    cin>>s;
    if(s == "SUN"){
        cout<<7;
    } 
    else if(s == "MON"){
        cout<<6;
    }
    else if(s == "TUE"){
        cout<<5;
    }
    else if(s == "WED"){
        cout<<4;
    }
    else if(s == "THU"){
        cout<<3;
    }
    else if(s == "FRI"){
        cout<<2;
    }
    else if(s == "SAT"){
        cout<<1;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int main() {
	int p,q,r,fl=0;
	scanf("%d", &p);
	scanf("%d", &q);
	if (p > q) fl = 1;
	scanf("%d", &r);
	if (fl == 0) {
		if (q > r) printf("%d", p + r);
		else printf("%d", p + q);
	}
	else {
		if (p > r) printf("%d", q + r);
		else printf("%d", p + q);
	}
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    if(n >= 9 || m >= 9)cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}

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

int H, A[MAX + 1];

void maxHeapify(int i)
{
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;

    if (l <= H && A[l] > A[i])
        largest = l;
    else
        largest = i;
    if (r <= H && A[r] > A[largest])
    {
        largest = r;
    }

    if (largest != i)
    {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main()
{
    cin >> H;
    for (int i = 1; i <= H; i++)
    {
        cin >> A[i];
    }
    for (int i = H / 2; i >= 1; i--)
    {
        maxHeapify(i);
    }
    for (int i = 1; i <= H; i++)
    {
        cout << " " << A[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4968
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
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 long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;
    cin>>s;
    bool a=false;
    for(int i=0;i<s.size();i++){
        for(int j=0;i+j<s.size();j++){
            if(s.substr(0,i)+s.substr(i+j)=="keyence"){
                a=true;
                break;
            }
        }
    }
    if(a) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x / 500 * 1000;
    ans += (x % 500) / 5 * 5;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){

  int n,m;
  vector<int> a(1000);
  int sum=0;
  int max=0;
  
  while(1){
	sum=0;
	max=0;
	cin>>n>>m;
	  
	if(n == 0 && m  == 0)
	  break;
	
	for(int i=0;i<n;++i)
	  cin>>a[i];
	
	for(int i=0;i<n-1;++i){
	  for(int j=i+1;j<n;++j){
	   
		sum=a[i]+a[j];
		
		if(sum > max && sum <= m)
		  max = sum;
			
	  }
	}

	if(max == 0)
	  cout<<"NONE"<<endl;
	else
	  cout<<max<<endl;
	
  }

  return 0;
}



Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
 
#define mod 1000000007

int fact(int n){
	if(!n) return 1;
	return n * fact(n-1);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	int a=0, b=0;
	int min = 1;
	int arr[n+1] = {};
	for(int i = 1; i <= n; i++){
		arr[i] = i-1;
	}
	for(int i = 1; i <= n; i++){
		int s; cin>>s;
		a += arr[s] * fact(n-i);
		for(int u = s; u <= n; u++){
			arr[u]--;
		}
	}
	for(int i = 1; i <= n; i++){
		arr[i] = i-1;
	}
	for(int i = 1; i <= n; i++){
		int s; cin>>s;
		b += arr[s] * fact(n-i);
		for(int u = s; u <= n; u++){
			arr[u]--;
		}
	}
	cout<<abs(a-b);
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = []
if m<=n:
    print(0)
else:
    for i in range(0, m-1):
        l.append(x[i+1]-x[i])
    l.sort(reverse=True)
    for j in range(n-1):
        del l[0]
    print(sum(l))


Measured memory_bytes: 13968
A = int(input())
B = int(input())
C = int(input())
X = int(input())

value = 0
for a in range(0, A+1):
    for b in range(0, B+1):
        for c in range(0, C+1):
            if 500*a + 100*b + 50*c == X:
                value += 1
print(value)


Measured memory_bytes: 39536
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	int p,res = 0;
	int prev = -2;
	for (int i = 0; i < N; ++i) {
		cin >> p;
		if (((i+1)-p) == 0) {
			if (i != prev+1) {
				++res;
				prev = i;
			}
			else {
				prev = -2;
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3104
(defun fact (n)
  (if (= n 0)
      0
      (loop with a = 1
            for i from 2 to n
            do (setf a (* a i))
            finally (return a))))

(defun nth-permutation (n p)
  (if p
      (let ((x (first p)))
        (+ (* (fact (1- n)) (1- x))
           (nth-permutation (1- n)
                            (mapcar (lambda (y)
                                      (if (< x y)
                                          (1- y)
                                          y))
                                    (rest p)))))
      0))

(defun solve (n p q)
  (abs (- (nth-permutation n p)
          (nth-permutation n q))))

#-swank
(let* ((n (read))
       (p (loop repeat n collect (read)))
       (q (loop repeat n collect (read))))
  (format t "~A~%" (solve n p q)))


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	long long int sum=0;
	int a[n];
	int i;
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=0;i<k;i++)
	sum+=a[i];
	cout<<sum<<endl;
	return 0;
}



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

using namespace std;

int main(){
    int R, G, B, N, ans;
    cin >> R >> G >> B >> N;
    
    ans = 0;
    
    for(int i = 0; i <= N/R; i++)
    {

        for(int j = 0; j <= N/G; j++)
        {
            
            if ((N - R*i - G*j) % B == 0 && (N - R*i - G*j) >= 0) {
                ans += 1;
            }
            
        }
        
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t A, B;

    scanf("%zu %zu", &A, &B);

    size_t total = 0;

    if (A < B) {
        total += B;
        B--;
    }
    else {
        total += A;
        A--;
    }

    if (A < B) {
        total += B;
    }
    else {
        total += A;
    }

    printf("%zu", total);

    return 0;
}


Measured memory_bytes: 128
N, Ma, Mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(N)]

inf = float('inf')
dp = [[[inf] * 401 for _ in range(401)] for _ in range(N + 1)]

dp[0][0][0] = 0

for i in range(N):
    for j in range(401):
        for k in range(401):
            if j - abc[i][0] >= 0 and k - abc[i][1] >= 0:
                dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2])
            else:
                dp[i + 1][j][k] = dp[i][j][k]
ans = inf
for a in range(1, 401):
    if a % Ma == 0:
        b = a // Ma * Mb
        if b <= 401:
            ans = min(ans, dp[N][a][b])
if ans == inf:
    ans = -1
print(ans)


Measured memory_bytes: 142812
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
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; }
 
using edge = struct {
    int to;
    ll cost;
};
 
int main() {
    int N;
    scanf("%d", &N);
    vector<edge> tree[N];
    rep(i, N-1){
        int a,b,c;
        scanf("%d%d%d", &a, &b, &c);
        a--; b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }
    int Q, K;
    scanf("%d%d", &Q, &K);
    K--;
    stack<edge> s;
    s.push({K, 0});
    ll depth[N];
    rep(i, N) depth[i] = -1;
    while(!s.empty()){
        edge from = s.top();
        s.pop();
        depth[from.to] = from.cost;
        for(const edge &to : tree[from.to]){
            if(depth[to.to] == -1) s.push({to.to, to.cost + from.cost});
        }
    }
    rep(i, Q){
        int x, y;
        scanf("%d%d", &x, &y);
        x--, y--;
        printf("%lld\n", depth[x] + depth[y]);
    }
 
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

string pattern[] = {"000", "111", "222", "333", "444", "555", "666", "777", "888", "999"};

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

    string n;
    bool found = false;
    cin >> n;
    for (int i = 0; i < 10; i++)
    {
        if (n.find(pattern[i]) != string::npos)
            found = true;
    }
    if (found)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

const int maxn=2e5+10;

int n,m,col[maxn],sz[maxn],c[9],edge_cnt;
int tote,NEXT[maxn],TO[maxn],FIR[maxn],INV[maxn];
LL Ans;

void addedge(int G[],int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=G[u];
	G[u]=tote;
}

bool dfs(int u)
{
	bool Ans=1;
	c[col[u]]++;
	sz[u]=1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		edge_cnt++;
		int v=TO[p];
		if (!col[v])
		{
			col[v]=col[u]%3+1;
			Ans&=dfs(v);
			sz[u]+=sz[v];
		}
		else Ans&=col[v]==(col[u]%3+1);
	}
	for (int p=INV[u];p;p=NEXT[p])
	{
		edge_cnt++;
		int v=TO[p];
		if (!col[v])
		{
			col[v]=(col[u]+1)%3+1;
			Ans&=dfs(v);
			sz[u]+=sz[v];
		}
		else Ans&=col[v]==((col[u]+1)%3+1);
	}
	return Ans;
}

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(FIR,u,v);
		addedge(INV,v,u);
	}
	for (i=1;i<=n;i++)
		if (!col[i])
		{
			edge_cnt=0;
			memset(c,0,sizeof(c));
			col[i]=1;
			if (dfs(i))
			{
				if (c[1]&&c[2]&&c[3])
				{
					Ans+=(LL)c[1]*c[2];
					Ans+=(LL)c[2]*c[3];
					Ans+=(LL)c[3]*c[1];
				}
				else Ans+=edge_cnt>>1;
			}
			else Ans+=(LL)sz[i]*sz[i];
		}
	printf("%lld\n",Ans);
}


Measured memory_bytes: 8448
#include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
#include<cstring>
using namespace std;

int v[100005];
int n,x,y,tot=0,h[100005];
int scc[100005],dfn[100005],low[100005],C,cnt;
bool vis[100005];
struct Edge{
	int x,next;
}e[5000000];
pair<int,int> a[20005];
stack<int> s;

inline void add_edge(int x,int y){
	e[++tot].x=y;
	e[tot].next=h[x],h[x]=tot;
}

void tarjan(int x){
	dfn[x]=low[x]=++cnt;
	s.push(x),vis[x]=true;
	for(int i=h[x];~i;i=e[i].next){
		if(!dfn[e[i].x]){
			tarjan(e[i].x),low[x]=min(low[x],low[e[i].x]);
		}else if(vis[e[i].x]){
			low[x]=min(low[x],dfn[e[i].x]);
		}   
	}
	if(dfn[x]==low[x]){
		C++;
		int tmp;
		for(;;){
			tmp=s.top();
			vis[tmp]=false,scc[tmp]=C;
			s.pop();
			if(tmp==x)break;
		}
	}
}

void build(int o,int l,int r){
	if(r-l==1){
		add_edge(o+n*2,a[l].second^1);
		return;
	}
	add_edge(o+n*2,(o<<1)+n*2);
	add_edge(o+n*2,(o<<1|1)+n*2);
	int mid=l+r>>1;
	build(o<<1,l,mid),build(o<<1|1,mid,r);
}

void link(int o,int l,int r,int x,int y,int a){
	if(l>=x&&r<=y){
		add_edge(a,o+n*2);
		return;
	}
	int mid=l+r>>1;
	if(x<mid)link(o<<1,l,mid,x,y,a);
	if(y>mid)link(o<<1|1,mid,r,x,y,a);
}

inline pair<int,int> get(int x,int len){
	int l=0,r=x;
	pair<int,int> ans;
	while(l<r){
		int mid=l+r>>1;
		if(a[x].first-a[mid].first<len)r=mid;
		else l=mid+1;
	}
	ans.first=l;
	l=x,r=n*2-1;
	while(l<r){
		int mid=l+r+1>>1;
		if(a[mid].first-a[x].first<len)l=mid;
		else r=mid-1;
	}
	ans.second=l;
	return ans;
}

inline bool check(int d){
	memset(scc,0,sizeof(scc));
	memset(dfn,0,sizeof(dfn));
	memset(low,0,sizeof(low));
	memset(h,-1,sizeof(h)),tot=0;
	build(1,0,n*2);
	for(int i=0;i<n*2;i++){
		int id=a[i].second;
		pair<int,int> x=get(i,d);
		if(i<x.second)link(1,0,n*2,i+1,x.second+1,id);
		if(x.first<i)link(1,0,n*2,x.first,i,id);
	}
	C=cnt=0;
	for(int i=0;i<n*2;i++)if(!dfn[i])tarjan(i);
	for(int i=0;i<n*2;i++)
		if(scc[a[i].second]==scc[a[i].second^1])return false;
	return true;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&x,&y);
		a[2*i+1]=make_pair(x,2*i+1);
		a[2*i]=make_pair(y,2*i);
	}
	sort(a,a+n*2);
	int l=0,r=1000000000;
	while(l<r){
		int mid=l+r+1>>1;
		if(check(mid))l=mid;
		else r=mid-1;
	}
	printf("%d",l);
}

Measured memory_bytes: 12544
#!usr/bin/env python3

import sys


def main():
    passage = str()
    alphabets = 'abcdefghijklmnopqrstuvwxyz'

    for line in sys.stdin:
        passage += line.lower()

    for alphabet in alphabets:
        print('%s : %d' % (alphabet, passage.count(alphabet)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7376