akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;
bool f[10] = {};

int main(){
	cin >> s;
	REP(i, s.size()){
		if (s[i] == 'N')f[0] = 1;
		if (s[i] == 'E')f[1] = 1;
		if (s[i] == 'W')f[2] = 1;
		if (s[i] == 'S')f[3] = 1;
	}
	if (f[0]){
		if (!f[3]){
			cout << "No" << endl;
			return 0;
		}
	}
	else{
		if (f[3]){
			cout << "No" << endl;
			return 0;
		}
	}
	if (f[1]){
		if (!f[2]){
			cout << "No" << endl;
			return 0;
		}
	}
	else{
		if (f[2]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}

#define SHOW(x) std::cout << #x << " = " << x << std::endl;

int const maxn = 200005;

int fromone[maxn];
int ton[maxn];


int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);


    long long k;
    cin >> k;
    int n = 50;

    long long t = (k + 49) / 50 * 50;
    vector<long long> a(n, t / 50 + 49);
    while (t > k)
    {
        auto it = max_element(begin(a), end(a));
        for(auto& x : a)
            ++x;
        (*it) -= 51;
        --t;
    }
    cout << 50 << endl;
    for(int i =0; i <n; ++i)
        cout << a[i] << " \n"[i == n - 1];
}


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

int main() {
  int64_t a, b, k;
  cin >> a >> b >> k;
  if (a>=k) {
    a-=k;
  }
  else if (a<k && b>=k-a) {
    k-=a;
    a=0;
    b-=k;
  }
  else if (a+b<k) {
    a=0;
    b=0;
  }
  cout << a << " " << b << endl;
}

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

int main() {
  int m = 2019;
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());

  int x = 1, tot = 0;
  ll ans = 0;
  vector<int> cnt(m, 0); // 余りの数ごとに何個あるか数えておく
  cnt.at(0) = 1;
  rep(i, n) {
    tot += (s.at(i) - '0') * x;
    tot %= m;
    ans += cnt.at(tot);
    cnt.at(tot)++;
    x = x * 10 % m;
  }

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

Measured memory_bytes: 3760
# 数値の取得
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

# 宿泊費の計算後結果を出力
if N <= K:
  account = N * X
else:
  account = (K * X) + (max(N - K,0) * Y) 
  
print(account)

Measured memory_bytes: 9176
using System;
using System.Collections.Generic;
using System.Linq;

static class Parallelism
{
    static void Main()
    {
        var n = int.Parse( Console.ReadLine() );
        Enumerable.Repeat<Func<string>>( Console.ReadLine, n )
            .Select( x => Array.ConvertAll( x().Split( ' ' ), decimal.Parse ) )
            .Select( x => 
                ( x[0] - x[2] ) * ( x[5] - x[7] ) 
                - ( x[1] - x[3] ) * ( x[4] - x[6] ) 
                == 0 ? "YES" : "NO"
                 )
            .ToList()
            .ForEach( Console.WriteLine );
    }
}

Measured memory_bytes: 6208
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var m = sc.nextInt();
		var a = new int[m];
		var b = new int[m];
		for (var i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		sc.close();

		var list = new ArrayList<Integer>();
		for (var i = 0; i < n; i++) {
			list.add(i + 1);
		}
		var uf = new Main().new UnionFind(list);
		for (var i = 0; i < m; i++) {
			uf.union(a[i], b[i]);
		}

		var set = new HashSet<Integer>();
		for (var i = 0; i < n; i++) {
			set.add(uf.find(i + 1));
		}
		var result = set.size() - 1;
		System.out.println(result);
	}

	public class UnionFind {
		public HashMap<Integer, Integer> parents = new HashMap<Integer, Integer>();
		public HashMap<Integer, Integer> ranks = new HashMap<Integer, Integer>();

		public UnionFind(List<Integer> numbers) {
			for (var number : numbers) {
				parents.put(number, number);
				ranks.put(number, 0);
			}
		}

		public void union(int number1, int number2) {
			var root1 = find(number1);
			var root2 = find(number2);
			if (root1 != root2) {
				if (ranks.get(root1) < ranks.get(root2)) {
					parents.put(root1, root2);
				} else {
					parents.put(root2, root1);
					if (ranks.get(root1) == ranks.get(root2)) {
						ranks.put(root1, ranks.get(root1) + 1);
					}
				}
			}
		}

		public int find(int number) {
			var parent = parents.get(number);
			if (number == parent) {
				return number;
			}
			var find = find(parent);
			parents.put(number, find);
			return find;
		}
	}
}


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

int main() {

  vector <int> mod(224);
  for(int i=0; i<224; i++ ){
    if(i ==0){
      mod.at(i)=1;
    }
    else{
      mod.at(i)=10*mod.at(i-1)%2019;
    }
  }

  //sort(mod.begin(),mod.end());
  /*for(int i=0; i<224; i++){
    cout << "i" << i << ":" << mod.at(i) <<endl;
  }*/



  string S;
  cin >> S;

  long long int N = (long int)(S.length()); //Nketa
  //cout << len << endl;

  vector <long int> s(N);
  //cout << (s.size()) << endl;

  for(long long int i=0; i<N; i++){
    long int tmp = S.at(i)-'0';
    s.at(i) = tmp;
    //cout << s.at(i) ;
  }


  vector <int> t(N+1);
  for(long long int i=0; i<N+1; i++){
    if(i==0){
      t.at(i)=0;
    }
    else if(i==1){
      t.at(i)=s.at(N-i);
    }
    else{
      int tmp;
      tmp = (i-1)%224;
      t.at(i) = (t.at(i-1) + s.at(N-i)*mod.at(tmp)) % 2019;
    }
  }

  long long int count=0;
  long long int sum = 1;

  sort(t.begin(),t.end());
  for(long long int i=0; i<N; i++){
    if(t.at(i)==t.at(i+1)){
      sum++;
      if(i==N-1){
        count+=sum*(sum-1)/2;
      }
    }
    else{
      count+=sum*(sum-1)/2;
      sum = 1;
    }
  }
  cout << count << endl;
}


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

int main(){
  int N,T,c[100],t[100];cin >> N >> T;
  int tle= 0,fnum = 0,lcos = 10000;
  for (int i = 0; i < N; i++){
    cin >> c[i] >> t[i];
  }
  for (int i = 0; i < N; i++){
    if (t[i] > T){
      tle ++;
    }else{
      if (lcos >= c[i]){
        lcos = c[i];
        fnum = i;
      }
    }
  }
  if(tle == N){
    cout << "TLE" <<endl;
  }else{
    cout << c[fnum] <<endl;
  }
}


Measured memory_bytes: 256
import sys
k = int(input())

from collections import deque

cnt = 0


s = [[i] for i in range(1, 10)]
stack = deque(s)
while stack:
    cur = stack.popleft()
    cnt += 1
    if cnt == k:
        print(''.join(list(map(str, cur))))
        sys.exit()
    c = cur[-1]
    for i in (c-1, c, c+1):
        if i >= 0 and i <= 9:
            next = cur[:]
            next.append(i)
            stack.append(next)





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

int num[10000 + 5];
int ma[105][105];
int main()
{
    ios::sync_with_stdio(false);
    int h, w, n;
    cin >> h >> w >> n;
    for(int i = 1 ; i <= n; i++)
    {
        cin >> num[i];
    }
    int hh = 1, ww = 1;
    for(int i = 1; i <= n; i++)
    {
        while(num[i])
        {
//            cout << "i = " << i << " hh = " << hh << " ww = " << ww <<endl;
            ma[hh][ww] = i;num[i]--;
            if(hh & 1)  ww++;
            else ww--;
            if(hh & 1 && ww == w + 1)   hh++, ww--;
            else if(!(hh & 1) && ww == 0)    hh++, ww++;
        }
    }
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            cout << ma[i][j];
            if(j == w)  cout << "\n";
            else cout << " ";
        }
    }

    return 0;
}


Measured memory_bytes: 384
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,K = LI()

count = N//K

N = N-count*K
print(min(N,abs(N-K)))

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <string>
#define llint long long

using namespace std;

llint n;
string s;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> s;
	
	llint ans = 0;
	for(int i = 0; i <= n-3; i++){
		if(s.substr(i, 3) == "ABC") ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  bool ng = false;
  map<int, int> s_c;
  for(int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    map<int, int>::iterator it = s_c.find(s);
    if(it == s_c.end()) s_c[s] = c;
    else if(it->second != c) ng = true;
    if((n>1) && (s==1) && (c==0)) ng = true;
  }
 
  if(ng) {
      cout << -1 << endl;
      return 0;
  }
 
  char ans[n+1] = {'\0'};
  for(int s = 1; s <= n; ++s) {
      map<int, int>::iterator it = s_c.find(s);
      if(it == s_c.end()) ans[s-1] = ((s==1) && (n!=1) ? '1' : '0');
      else ans[s-1] = '0' + it->second;
  }
 
  cout << stoi(ans) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] ar){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
        int count=0;
        for(;;a++){
            if(c%a==0)
                count++;
            if(a==b)
                break;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26188
import java.util.Scanner;

public class Main
{

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

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());

		String ans = (n + 1)/2 >= k ? "YES" : "NO";

		System.out.println(ans);

		sc.close();
	}

}


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

int main(){
//srandom((unsigned long)time(NULL));

long long x;
cin>>x;
long long cnt=1;
long long money=100;
while(money<x){
    cnt++;
    money*=1.01;
}
cout<<cnt-1<<endl;

return 0;
}



Measured memory_bytes: 3584
#include <map>
#include <iostream>
using namespace std;
typedef long long ll;

int main(){

    //税抜き価格と8%税金、10％税金の組みのマップを作る
    //指定された価格から、条件を満たす価格の範囲を出す
    //範囲がかぶっているか、（インデックスの最大と最小を比較する）

    map<ll, ll> mA, mB; //<price, tax>

    ll A, B;//tax

    for(int i=1;i<2000;i++){
        mA.insert(make_pair(i*0.08, i)); 
        mB.insert(make_pair(i*0.1, i)); 
    }

    cin >> A >> B;

    ll minAi, maxAi, minBi, maxBi;

    minAi = mA.at(A);
    maxAi = mA.at(A+1)-1;
    minBi = mB.at(B);
    maxBi = mB.at(B+1)-1;

    //cout << minAi << " " << maxAi << " " << minBi << " " << maxBi << endl;

    if(maxAi < minBi || minAi > maxBi){
        cout << "-1\n";
    }else{
       if(minAi >=  minBi){
           cout << minAi << endl;
       }else{
           cout << minBi << endl;
       }
    }
    
    return 0;

 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(x) ((long long)x%modulo)


int main(){
	int N,K;
	cin>>N>>K;
	int D[K];
	for(int i=0;i<K;i++)cin>>D[i];
	
	for(int i=N;i<9999999;i++){
		int x = i;
		bool flag = true;
		while(x!=0){
			for(int j=0;j<K;j++){
				if(D[j]==x%10){
					flag=false;
					goto Label;
				}
			}
			x/=10;
		}
		Label:
		if(flag){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    string s; int k;
    cin >> k >> s;

    cout << (((int)s.size() <= k) ? s : s.substr(0,k) + "...") << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int s[3],t[3];
    for(int i=0;i<3;i++){
        int a,b,c;
        cin>>a>>b>>c;
        s[i]=a-b;
        t[i]=b-c;
    }
    if(s[0]==s[1] && s[1]==s[2] &&t[0]==t[1] && t[1]==t[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;
  cin>>n;
  int a[n];
  cin>>a[0];
  for(int i=1;i<n;i++){
    cin>>a[i];
    if(a[i]==a[i-1]){
      a[i]=101;
      c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();

		char[] ch = S.toCharArray();
		Map<Character, Integer> chMap = new HashMap<>();
		for(int i = 0;i < N;i++) {
			if(chMap.containsKey(ch[i])) {
				chMap.put(ch[i], chMap.get(ch[i])+1);
			}else {
				chMap.put(ch[i], 1);
			}
		}
		long ans = 1;
		for(Map.Entry<Character, Integer> entry : chMap.entrySet()) {
			ans = (ans * (entry.getValue() + 1)) % 1_000_000_007;
		}
		ans--;
		System.out.println(ans);
	}
}

Measured memory_bytes: 26644
import java.math.*;
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int t = 1;
		while (t-->0) {
		    int k = sc.nextInt(), n = sc.nextInt();
		    int[] a = new int[n];
		    for (int i=0;i<n ;i++ ) a[i] = sc.nextInt();
		    Arrays.sort(a);
		    int max = 0;
		    for(int i=0;i<n-1;i++){
		        max = Math.max(max,a[i+1]-a[i]);
		    }
		    max = Math.max(max,k-a[n-1]+a[0]);
		    System.out.println(k-max);
		}
	}
	static ArrayList<Integer> key;
	static int n1;
	static void insert(int key1){
		key.add(key1);
		n1++;
		swim(n1);
	}
	static void swim(int k){
		while (k>1 && less(k/2, k)) {
			swap(k/2, k);
			k/=2;
		}
	}
	static int deleteMax(){
		int max = key.get(1);
		key.set(1,key.get(n1--));
		sink(1);
		key.remove(n1+1);
		return max;
	}
	static void sink(int k){
		while (2*k<=n1) {
			int j = 2*k;
			if (j<n1 && less(j,j+1)) {
				j++;
			}
			if (!less(k, j)) {
				break;
			}
			swap(k,j);
			k=j;
		}
	}
	static boolean less(int a, int b){
		return key.get(a)<key.get(b);
	}
	static void swap(int a, int b){
		int c=key.get(a);
		key.set(a,key.get(b));
		key.set(b,c);
	}
	static String getit(String s, String b){
	    StringBuilder temp=new StringBuilder(" ");
        temp.append(s);
        temp.append("#");
        temp.append(b);
	    int n = temp.length()-1;
	    String p = temp.toString();
	    int[] pi = new int[n+1];
	    pi[0] = -1;
	    int k = -1;
	    for (int i=1;i<=n ;i++ ){
	        while(k>=0 && p.charAt(k+1)!=p.charAt(i)) k = pi[k];
	        pi[i] = ++k;
	    } 
	    return s.substring(1,pi[n]);
	}
	static class Query {
		int x1, x2, y, id;
		public Query(int c, int d, int e, int a){
			x1 = c;
			x2 = d;
			y = e;
			id = a;
		}
	}
	static class Compare1 implements Comparator<Query>{
		@Override
		public int compare(Query q1, Query q2){
			if(q1.x2==q2.x2) return q1.x1-q2.x1;
			return q1.x2-q2.x2;
		}
	}
	static class Pair implements Comparable<Pair>{
		int a, b;
		public Pair(int c, int d){
			a = c;
			b = d;
		}
		public int compareTo(Pair p){
		    return a-p.a;
		}
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}
		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 45656
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll in[1050][3];

ll val[1050];
int main() {
	int N, M, i, j, k;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) for (j = 0; j < 3; j++) scanf("%lld", &in[i][j]);

	ll ans = 0;
	for (i = 0; i < 8; i++) {
		for (j = 1; j <= N; j++) {
			val[j] = 0;
			for (k = 0; k < 3; k++) {
				if (i & (1 << k)) val[j] += in[j][k];
				else val[j] -= in[j][k];
			}
		}
		sort(val + 1, val + N + 1);
		reverse(val + 1, val + N + 1);
		ll sum = 0;
		for (j = 1; j <= M; j++) sum += val[j];
		ans = max(ans, sum);
	}
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string answer;
  vector<char> color(N);
  for (int i; i<N; i++){
    cin >> color.at(i);
  }
  for (int i; i<N; i++) {
    if(color.at(i)=='Y'){
      answer="Four";
    break;
    }
    else{
      answer="Three";
    }
  }
  cout << answer << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

#include <ext/rope> //header with rope
using namespace std;
using namespace __gnu_cxx; //namespace with rope and some additional stuff
using namespace __gnu_pbds;

#define rep(i, a, b) for(int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;



int c[505], s[505], f[505];

int main(){
		
	int n; cin >> n;
	
	rep(i, 0, n-1) scanf("%d %d %d", &c[i], &s[i], &f[i]);
	
	rep(i, 0, n-1){
		int u = i, tempo = s[u];
		while(u!=n-1){
			tempo += c[u];
			u = u+1;
			if(u==n-1) break;
			int aux = (tempo-s[u]+f[u]-1)/f[u];
			if(aux<0) aux = 0;
			tempo = s[u] + aux*f[u];
			
		}
		cout << tempo << '\n';
	}
	
	puts("0");
	
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

long long mod = 1000000007;
long long fact[1 << 18], inv[1 << 18];
long long N, K, A[1 << 18];

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 32; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

void init() {
	fact[0] = 1;
	for (int i = 1; i <= 200000; i++) fact[i] = (1LL * i * fact[i - 1]) % mod;
	for (int i = 0; i <= 200000; i++) inv[i] = Div(1, fact[i], mod);
}

long long ncr(long long n, long long r) {
	if (n < r || r < 0) return 0;
	return (fact[n] * inv[r] % mod) * inv[n - r] % mod;
}

int main() {
	init();
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> A[i];
	sort(A + 1, A + N + 1);

	long long ret = 0;
	for (int i = 1; i <= N; i++) {
		ret += A[i] * ncr(i - 1, K - 1);
		ret = (ret + mod * mod) % mod;
	}
	for (int i = 1; i <= N; i++) {
		ret -= A[i] * ncr(N - i, K - 1);
		ret = (ret + mod * mod) % mod;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;

struct Info{
	char word[6];
	int num,length;
};

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int strCmp2(char* left,char* right){
	int i;

	if(strCmp(left,right))return 3;

	for(i=0;left[i] != '\0' && right[i] != '\0'; i++){
		if(left[i] != right[i]){
			if(left[i] < right[i])return 1;
			else{
				return 2;
			}
		}
	}
	if(left[i] == '\0')return 1;
	else{
		return 2;
	}
}


int main(){

	int length;
	char buf[6];
	bool Found;

	int n,index,tmp;

	scanf("%d",&n);

	Info* info = (Info*)malloc(sizeof(Info)*n);

	for(int i = 0; i < n; i++){
		info[i].length = 0;
		info[i].num = 0;
	}

	index = 0;
	for(int i = 0; i < n; i++){
		scanf("%s %d",buf,&tmp);

		Found = false;

		for(int k = 0; k < index; k++){
			if(strCmp(buf,info[k].word)){
				info[k].num += tmp;
				Found = true;
				break;
			}
		}
		if(!Found){
			strcpy(info[index].word,buf);
			info[index].num += tmp;
			for(length = 0;buf[length] != '\0';length++);
			info[index].length = length;
			index++;
		}
	}

	for(int i = 1;i <= index-1; i++){
		for(int k = index-1; k >= i; k--){
			if(info[k].length < info[k-1].length)swap(info[k],info[k-1]);
			else if(info[k].length == info[k-1].length && strCmp2(info[k].word,info[k-1].word) == 1)swap(info[k],info[k-1]);
		}
	}

	for(int i = 0; i < index; i++){
		printf("%s %d\n",info[i].word,info[i].num);
	}


    return 0;
}

Measured memory_bytes: 3244
#include <stdio.h>

int main(void)
{
    int N,i;
    char S[200000];

    scanf("%d",&N);
    scanf("%s",S);

    while(S[i] != '\0'){
        S[i]+=N;
        if(S[i] > 90){
            S[i]-=26;
        }
        i++;
    }

    printf("%s\n",S);

    return 0;
}

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

using namespace std;

int n , a[200] ,sum=0;

bool grt ( int i , int j ){
return i > j ;
}

int main()
{
    cin >> n ;
    for (int i = 0 ; i < n ; ++ i){
        cin >> a[i] ;
    }
    sort (a,a+n,grt);
    /*int l = 0 , r = n-1 ;
    if (n&1)
        sum+=a[n/2];
    while (l<r){
        sum +=a[l]-a[r];
        ++l;
        --r;
    }*/
    for (int i = 0 ; i < n ; ++ i){
        if (i&1)
            sum-=a[i];
        else
            sum+=a[i];
    }
    cout << sum ;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x=0;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<n;i++){
        if(s[i]=='I')
            x++;
        else
            x--;
        if(x>ans)
            ans=x;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
# Stable Sort
# Result:
# Modifications
# - modify inner loop start value of bubble_sort
#   This was the cause of the previous wrong answer.
# - improve performance of is_stable function
import sys

ary_len = int(sys.stdin.readline())
ary_str = sys.stdin.readline().rstrip().split(' ')
ary = map(lambda s: (int(s[1]), s), ary_str)

# a is an array of tupples whose format is like (4, 'C4').
def bubble_sort(a):
    a_len = len(a)
    for i in range(0, a_len):
        for j in reversed(range(i + 1, a_len)):
            if a[j][0] < a[j - 1][0]:
                v = a[j]
                a[j] = a[j - 1]
                a[j - 1] = v

# a is an array of tupples whose format is like (4, 'C4').
def selection_sort(a):
    a_len = len(a)
    for i in range(0, a_len):
        minj = i;
        for j in range(i, a_len):
            if a[j][0] < a[minj][0]:
                minj = j
        if minj != i:
            v = a[i]
            a[i] = a[minj]
            a[minj] = v

def print_ary(a):
    vals = map(lambda s: s[1], a)
    print ' '.join(vals)

def is_stable(before, after):
    length = len(before)
    for i in range(0, length):
        for j in range(i + 1, length):
            if before[i][0] == before[j][0]:
                v1 = before[i][1]
                v2 = before[j][1]
                for k in range(0, length):
                    if after[k][1] == v1:
                        v1_idx_after = k
                        break
                for k in range(0, length):
                    if after[k][1] == v2:
                        v2_idx_after = k
                        break
                if v1_idx_after > v2_idx_after:
                    return False
    return True

def run_sort(ary, sort_fn):
    ary1 = list(ary)
    sort_fn(ary1)
    print_ary(ary1)
    if is_stable(ary, ary1):
        print 'Stable'
    else:
        print 'Not stable'

### main
run_sort(ary, bubble_sort)
run_sort(ary, selection_sort)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<pi> ab;
  REP(i, n) {
    int a = read(), b = read();
    ab.PB(MP(a, b));
  }
  sort(ALL(ab));
  int ans = 0;
  REP(i, n) {
    int buyCount = m < ab[i].second ? m : ab[i].second;
    ans += buyCount * ab[i].first;
    m -= ab[i].second;
    if (m <= 0) break;
  }
  print(ans);
}


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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, m;
int dp[1 << 15][15], cost[1 << 15][15];
int calc(const vector<tuple<int,int,int>> &es, int bit, int to){
	int res = 0;
	for(const auto &e: es){
		int a, b, c; tie(c, a, b) = e;
		if((bit & 1 << a) && (bit & 1 << b) ||
			(bit & 1 << b) && a == to ||
			(bit & 1 << a) && b == to)
		res += c;
	}
	return res;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> m;
	vector<tuple<int,int,int>> es;
	int sum = 0, e[15][15];
	rep(i, n) rep(j, n) e[i][j] = -inf;
	rep(i, m){
		int a, b, c; cin >> a >> b >> c; a--; b--;
		es.emplace_back(c, a, b);
		e[a][b] = e[b][a] = c;
		sum += c;
	}
	rep(i, 1 << n) rep(j, n) if(!(i >> j & 1)) cost[i][j] = calc(es, i, j);
	
	memset(dp, -1, sizeof(dp));
	dp[1][0] = 0;
	rep(i, 1 << n) rep(j, n) if(dp[i][j] >= 0){
		for(int mask = (1 << n) - 1 - i, bit = mask; bit; bit = bit - 1 & mask)
			dp[i ^ bit][j] = max(dp[i ^ bit][j], dp[i][j] + cost[bit][j]);
		
		rep(k, n) if(!(i >> k & 1)) dp[i ^ 1 << k][k] = max(dp[i ^ 1 << k][k], dp[i][j] + e[j][k]);
	}
	cout << sum - dp[(1 << n) - 1][n - 1] << endl;
	
	return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] ca = new int[N+1];
		int[] cb = new int[N+1];
		foreach(var n in A) ca[n]++;
		foreach(var n in B) cb[n]++;
		
		bool chk = false;
		int ma = 0;
		int idx = -1;
		for(int i=0;i<=N;i++){
			if(ca[i] + cb[i] > N) chk = true;
			if(ca[i] + cb[i] > ma){
				idx = i;
				ma = ca[i] + cb[i];
			}
		}
		if(chk){
			Console.WriteLine("No");
			return;
		}
		
		int[] a = new int[N];
		int[] b = new int[N];
		
		for(int i=0;i<ca[idx];i++) a[i] = idx;
		for(int i=0;i<cb[idx];i++) b[i + ca[idx]] = idx;
		int cnt = ca[idx] + cb[idx];
		ca[idx] = 0;
		cb[idx] = 0;
		
		int r = 1;
		for(int i=1;i<=N;i++){
			if(cnt == N) break;
			if(ca[i] == 0) continue;
			while(ca[i] > 0){
				while(cb[r] == 0 || r == i){
					r++;
					if(r > N) r = 1;
				}
				a[cnt] = i;
				b[cnt] = r;
				ca[i]--;
				cb[r]--;
				cnt++;
				if(cnt == N) break;
			}
		}
		
//Console.WriteLine(String.Join(" ",a));		
//Console.WriteLine(String.Join(" ",b));		
		
		
		Queue<int> qa = new Queue<int>();
		for(int i=1;i<=N;i++){
			if(ca[i] != 0){
				while(ca[i] > 0){
					qa.Enqueue(i);
					ca[i]--;
				}
			}
		}
		Queue<int> qb = new Queue<int>();
		for(int i=1;i<=N;i++){
			if(cb[i] != 0){
				while(cb[i] > 0){
					qb.Enqueue(i);
					cb[i]--;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(a[i] == 0) a[i] = qa.Dequeue();
		}
		for(int i=0;i<N;i++){
			if(b[i] == 0) b[i] = qb.Dequeue();
		}
//Console.WriteLine(String.Join(" ",a));		
//Console.WriteLine(String.Join(" ",b));		
		
		Array.Sort(a, b);
		
		Console.WriteLine("Yes");
		Console.WriteLine(String.Join(" ",b));
		
		
		
	}
	int N;
	int[] A;
	int[] B;
	public Sol(){
		N = ri();
		A = ria();
		B = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int64_t A, B, C;

int cookieclicker() {
    int64_t res = 0;
    for (int i = 0; i < 100; i++) {
        if (A % 2 != 0) return i;
        if (B % 2 != 0) return i;
        if (C % 2 != 0) return i;
        
        int64_t tA = (B + C) / 2;
        int64_t tB = (C + A) / 2;
        int64_t tC = (A + B) / 2;
        A = tA; B = tB; C = tC;
    }
    return -1;
}

int main() {
    cin >> A >> B >> C;
    cout << cookieclicker() << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int N = 100'000;
double x[N], y[N], dx[N], dy[N], nx[N], ny[N];
template <typename signature> using f = const function<signature>&;
template <typename TIn, typename TOut> TIn tsearch(TIn L, TIn R, f<TOut(TIn)> obj, f<bool(TOut, TOut)> cmp = less<TOut>()) {
    for(int i = 0; i < 1000; i++) {
        TIn M1 = (2 * L + R) / 3;
        TIn M2 = (L + 2 * R) / 3;
        cmp(obj(M1), obj(M2)) ? R = M2 : L = M1;
    }
    return cmp(obj(L), obj(R)) ? L : R;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        char dir;
        cin >> dir;
        dx[i] += (dir == 'R') - (dir == 'L');
        dy[i] += (dir == 'U') - (dir == 'D');
    }
    auto diffx = [&](double t) {
        for(int i = 0; i < n; i++) {
            nx[i] = x[i] + dx[i] * t;
        }
        return *max_element(nx, nx + n) - *min_element(nx, nx + n);
    };
    auto diffy = [&](double t) {
        for(int i = 0; i < n; i++) {
            ny[i] = y[i] + dy[i] * t;
        }
        return *max_element(ny, ny + n) - *min_element(ny, ny + n);
    };
    auto diff = [&](double t) {
        return diffx(t) * diffy(t);
    };
    double tminx = tsearch<double, double>(0, 2e8, diffx);
    double tminy = tsearch<double, double>(0, 2e8, diffy);
    double tmin = tsearch<double, double>(0, 2e8, diff);
    cout << fixed << setprecision(9) << min({diffx(tminx) * diffy(tminx), diffx(tminy) * diffy(tminy), diff(tmin)}) << endl;
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> boroken(n+1);
  for(int i = 0; i < m; i++) {
    int a;
    cin >> a;
    boroken[a] = true;
  }
  vector<int> dp(n+2);
  const int mod = 1000000007;
  dp[n] = 1;
  for(int i = n-1; i >= 0; i--) {
    if(boroken[i]) {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i+1] + dp[i+2]) % mod;
  }
  cout << dp[0]<< endl;
  return 0;
}


Measured memory_bytes: 640
n = gets.chomp.to_i
h = gets.chomp.split(" ").map(&:to_i)

cnt = -1
tar = h[0] 
max = 0
for i in 1..h.size do
    if h[i-1] <= tar
        cnt += 1
    else
        if max < cnt 
            max = cnt
        end
        cnt = 0
    end
    tar = h[i-1]
end

if max < cnt 
    max = cnt
end
p max

Measured memory_bytes: 11676
import java.util.*;
public class Main {
	
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		int sh = s.nextInt();
		int w = s.nextInt();
		if(w >= sh) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 35612
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n;
  cin>>n;
  ll a[n];
  ll minusCount = 0;
  ll minNum = INF;
  bool zeroIs = false;
  REP(i,n){

    cin>>a[i];
    if(a[i]<0)minusCount++;
    minNum = min((ll)minNum,(ll)max(a[i],-1*a[i]));
    if(a[i]==0)zeroIs = true;

  }

  ll ans = 0;

  REP(i,n){
    ans += max(a[i],-1*a[i]);
  }
  if(zeroIs==false&&minusCount % 2 == 1){
    ans -= minNum * 2;
  }

  cout<<ans<<endl;
 

  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int m;
    cin >> m;
    cout << 48-m << "\n";
    return 0;
}

Measured memory_bytes: 3648
use proconio::input;

fn main() {
    input! {
        x: usize,
        y: usize,
    }

    let mut ans = "No";

    for a in 0..(x + 1) {
        let b = x - a;
        if 2 * a + 4 * b == y {
            ans = "Yes"
        }
    }

    println!("{}", ans);
}


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

int main(){
    ll x;
    cin>>x;
    ll k=0;
    ll a,b;
    ll i=0,j=0;
    while(k<x){
        a=pow(i,5);
        j=0;
        while(j<i){
            b=pow(j,5);
            k=a-b;
            if(a+b==x){
                cout<<i<<" "<<j*-1<<endl;
                return 0;
            }
            if(k==x) {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
            j++;
        }
        i++;
    }
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  
  ll ans=LINF;
  irep(i,k-1,n){
    chmin(ans,a[i]-a[i-k+1]);
  }
  cout<<ans<<endl;
}

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

int N, K;
const int MAX_N = 50;
int l[MAX_N];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> l[i];

    sort(l, l+N, greater<>());

    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += l[i];
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

int main(){
	ll L,R; cin>>L>>R;
  if(R-L>=2018){
    printf("0");
    return 0;
  }

  vector<ll> mod(R-L+1);
  for(int i=0;i<=R-L;i++){
  	mod[i]=(i+L)%2019;
  }
  ll tmp=10000000;
  for(int i=0;i<R-L;i++){
  	for(int j=i+1;j<=R-L;j++){
    	if(tmp>mod[i]*mod[j]%2019) tmp=mod[i]*mod[j]%2019;
    }
  }
  
  printf("%lld",tmp);
  
}

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();
		long[] a=new long[n];
		long[] b = new long[n];
		int[] p=new int[n];
		a[0]=1;
		b[n-1]=1;
		for(int i =0; i<n; i++){
			int p1 = sc.nextInt()-1;
			p[i]=p1;
			if(i>0){
				a[i]=a[i-1]+20000;
				b[n-1-i]=b[n-i]+20000;
			}
		}
		for(int i=0; i<n; i++){
			a[p[i]]+=i;
		}
		for(int i =0; i<n; i++){
			System.out.print(a[i]+" ");
		}
		System.out.println();
		for(int i =0; i<n; i++){
			System.out.print(b[i]+" ");
		}
	}
}

Measured memory_bytes: 42736
#include <iostream>
using namespace std;
#define LL long long
const LL MAX=1e6+10;
LL n,m,x,y,z,k,x1,y1,z1;
LL a[MAX];
int main ()
{
    cin>>x>>y>>z>>k;
    //cout<<x<<"_"<<y<<"_"<<z<<endl;
    if(k%2==0)
        cout<<x-y<<endl;
    else
        cout<<y-x<<endl;
    return 0;
}


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

const int Max = 105;
int G[Max][Max], color[Max], d[Max], f[Max];
int t, n;

void dfs_visit(int u)
{
    color[u] = 0;
    d[u] = ++t;
    for(int j=0; j<n; j++)
    {
        if(!G[u][j]) continue;
        if(color[j]==-1)
            dfs_visit(j);
    }
    color[u] = 1;
    f[u] = ++t;
}
void dfs()
{
    memset(color, -1, sizeof(color));
    t = 0;
    for(int i=0; i<n; i++)
    {
        if(color[i]==-1)
            dfs_visit(i);
    }
    for(int i=0; i<n; i++)
    {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}
int main()
{
    int u, k, v;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> u >> k;
        for(int j=0; j<k; j++)
        {
            cin >> v;
            G[u-1][v-1] = 1;
        }
    }
    dfs();
    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;
int gcd(int a, int b);
int main()
{
    long long int n, temp, res = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (j < i)
                temp = gcd(i, j);
            else
                temp = gcd(j, i);

            for (int k = 1; k <= n; k++)
            {
                if (temp < k)
                {
                    res += gcd(k, temp);
                }
                else
                {
                    res += gcd(temp, k);
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

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

int main() {
  int N; cin >> N;
  vector<int> T(N), A(N);
  for (int i = 0; i < N; i++) cin >> T.at(i) >> A.at(i);
  long long t = 1, a = 1;
  for (int i = 0; i < N; i++) {
    long long n = max((t + T.at(i) - 1) / T.at(i), (a + A.at(i) - 1) / A.at(i));
    t = n * T.at(i);
    a = n * A.at(i);
  }
  cout << t + a << endl;
}

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

typedef long long ll;

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

    ll ans = 0;
    ll r = 0, g = 0, b = 0;
    for (int i = 0; i < N; ++i)
    {
        switch (S[i])
        {
        case 'R':
            ++r;
            break;
        case 'G':
            ++g;
            break;
        case 'B':
            ++b;
            break;
        default:
            break;
        }
    }
    ans = r * g * b;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i + 1; j < N; ++j)
        {
            int k = (2 * j) - i;

            if (k < N && S[i] != S[j] && S[j] != S[k] && S[i] != S[k])
            {
                --ans;
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
  int a, b; cin >> a >> b;
  if (a + b % 2 == 0) {
    cout << (a + b) / 2 << endl;
  }
  else {
    cout << (a + b + 1) /2 << endl;
  }
}

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();
		String s = sc.next();
		String t = sc.next();

		String result = "";
		for (int i = 0; i < n; i++) {
			result = result + s.charAt(i) + t.charAt(i);
		}

		System.out.println(result);
	}

}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define INF INT_MAX
#define P pair<int,int>
using namespace std;

int d[100000];
vector<P>f[500000]{};
signed main(){
int a,b,c;
cin>>a>>b>>c;
fill(d,d+a+1,INF);
d[c]=0;
priority_queue<P,vector<P>,greater<P>>Q;
Q.push(P(0,c));
for(int h=0;h<b;h++){
int i,j,k;
scanf("%lld%lld%lld",&i,&j,&k);
f[i].push_back(P(k,j));
}
while(Q.empty()==false){
P o=Q.top();
Q.pop();
int u=o.second;
if(d[u]<o.first)continue;
for(int x=0;x<f[u].size();x++){
P l=f[u][x];
if(d[l.second]>d[u]+l.first){
d[l.second]=d[u]+l.first;
Q.push(P(d[l.second],l.second));
}
}
}
for(int y=0;y<a;y++){
if(d[y]!=INF) printf("%lld\n",d[y]);
else printf("INF\n");
}
}

Measured memory_bytes: 28932