akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    vs u = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 4) {
        reverse(all(u[i]));
    }
    reverse(all(s));
    while (sz(s) > 0) {
        bool flag = false;
        rep(j, 4) {
            if (s.substr(0, sz(u[j])) == u[j]) {
                flag = true;
                s = s.substr(sz(u[j]), sz(s) - sz(u[j]));
                break;
            }
        }
        if (!flag) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inp = br.readLine().split(" ");
		String input = null;
		int n = Integer.parseInt(inp[0]);
		int l = Integer.parseInt(inp[1]);
		String[] in = new String[n];
		for (int i = 0; i < n; i++) {
			in[i] = br.readLine();
		}
		Arrays.sort(in);
		for (int i = 0; i < n; i++) {
			System.out.print(in[i]);
		}
		System.out.println();
	}

}

Measured memory_bytes: 22484
# Python 3
import sys
import itertools
import numpy as np
 
read = sys.stdin.buffer.read #標準入力から複数行取得するための関数です。 readlines() が結果を行単位で分割してリストで返すのに対して、 read() は結果をそのまま1つの文字列として取得します。
readline = sys.stdin.buffer.readline #標準入力から1行取得するための関数です。
readlines = sys.stdin.buffer.readlines #標準入力から複数行取得するための関数です。戻り値はリストで、入力された文字列が1行ずつ要素として格納されています。

N, M, Q = map(int, readline().split())
 
A = np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N)))
# [[1 1 1]
#  [1 1 2]
#  [1 1 3]
#  [1 1 4]
#  [1 2 2] ...
# NumPy配列

n = len(A)
score = np.zeros(n, np.int32)
m = map(int, read().split())
for a, b, c, d in zip(m, m, m, m):
    cond = A[:, b - 1] - A[:, a - 1] == c # NumPy配列
    score += d * cond
 
print(score.max())

Measured memory_bytes: 46696
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,a,ans;
int main(){
  while(scanf("%d",&n)&&n){
    int t[1000001]={0};
    ans=-1;
    for(int i=0;i<n;i++){
      scanf("%d",&a);
      t[a]++;
      if(t[a]>n/2)ans=a;
    }
    if(ans==-1)printf("NO COLOR\n");
    else printf("%d\n",ans);
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define INF 2e8
#define all(a) a.begin(), a.end()
#define maxel max_element
#define minel min_element
#define Bit(i) pow(2, i)

int gcd(int n, int m) {
  if (n < m) {
    swap(n, m);
  }
  while (n % m) {
    n = n % m;
    swap(n, m);
  }
  return m;
}

int main() {
  int n, nGCD;
  cin >> n >> nGCD;
  rep(i, n - 1) {
    int a;
    cin >> a;
    nGCD = gcd(nGCD, a);
  }
  cout << nGCD << endl;
}


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

using namespace std;
void dijkstra(int start, vector<uint64_t> &costs,
              unordered_map<int, vector<pair<int, uint64_t>>> &edges) {
  priority_queue<pair<uint64_t, int>, vector<pair<uint64_t, int>>,
                 greater<pair<uint64_t, int>>>
      q;
  costs[1] = start;
  q.push(make_pair(0, start));
  while (!q.empty()) {
    auto v = q.top();
    q.pop();
    for (auto &e : edges[v.second]) {
      if (v.first + e.second < costs[v.second]) {
        costs[e.first] = v.first + e.second;
        q.push(make_pair(costs[e.first], e.first));
      }
    }
  }
}

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

  int h, w;
  int pow[10][10];
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> pow[i][j];
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
    }
  }

  int mins[10];
  for (int i = 0; i < 10; ++i) {
    if (i == 1)
      mins[1] = 0;
    else
      mins[i] = 1000;
  }
  priority_queue<pair<int, int>,
                 vector<pair<int, int>>,
                 greater<pair<int, int>>> q;
  q.push(make_pair(0, 1));
  while (!q.empty()) {
    auto v = q.top();
    q.pop();
    for (int j = 0; j < 10; ++j) {
      if (v.first + pow[j][v.second] < mins[j]) {
        mins[j] = v.first + pow[j][v.second];
        q.push(make_pair(v.first + pow[j][v.second], j));
      }
    }
  }

  uint64_t cost = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j] < 0) continue;
      cost += mins[a[i][j]];
    }
  }
  cout << cost << "\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,sum=0;
    cin>>n;
    rep(i,n){
        int a;
        cin>>a;
        sum+=a-1;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <functional>
#include <iomanip>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>

using ll = long long;
ll INF = LLONG_MAX / 4 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
    int n; cin >> n;
    int ans = 0;
    FOR (i,1,n+1) {
        if (to_string(i).size()%2==1) {
            ans++;
        }
    }
    cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	sort(a.begin(), a.end());
	cout << a[N - 1] - a[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    int t=1;;
    //cin>>t;
    while(t--)
    {
        ll n,x,t;
        cin>>n>>x>>t;
        cout<<((n+x-1)/x)*t<<endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
long long dp[100200][3];
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
  	dp[0][0] = a[0];
  	dp[0][1] = b[0];
  	dp[0][2] = c[0];
  	for(int i = 1; i < n; i++) {
    	dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]);
    	dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
    	dp[i][2] = max(dp[i-1][0]+c[i], dp[i-1][1]+c[i]);
    }
	long long tmp = max(dp[n-1][0], dp[n-1][1]);
  	cout << max(tmp, dp[n-1][2]) << endl;
	
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

vector<bool> beki(1010);

int main() {
    int ans;
    string s;
    cin >> s;
    while(s.size() > 0){
        s = s.substr(0,s.size()-2);
        string s1,s2;
        s1 = s.substr(0,s.size()/2);
        s2 = s.substr(s.size()/2,s.size()/2);
        if(s1 == s2){
            ans = 2*s1.size();
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

namespace GRL_2_A
{
    class Program
    {
        const int MAX = 10000;
        const int INF = 1 << 30;
        static int N;
        static List<Edge> L = new List<Edge>();
        static void Main(string[] args)
        {
            var t = scan;
            N = t[0];
            int m = t[1];
            for (int i = 0; i < m; i++)
            {
                t = scan;
                L.Add(new Edge(t[0], t[1], t[2]));
            }
            int total = 0;
            var A = L.OrderBy(s => s.cost).ToArray();
            var d = new UnionFind(N);
            for (int i = 0; i < m; i++)
            {
                if (d.Same(A[i].source, A[i].target)) continue;
                total += A[i].cost;
                d.Unite(A[i].source, A[i].target);

            }
            Console.WriteLine(total);
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
    public class Edge
    {
        public int source, target, cost;
        public Edge(int source, int target, int cost)
        {
            this.source = source;
            this.target = target;
            this.cost = cost;
        }
        public bool Equals(Edge a)
        {
            return source == a.source && target == a.target && cost == a.cost;
        }
    }
    public class UnionFind
    {
        int[] rank;
        int[] p;
        public UnionFind(int size)
        {
            rank = new int[size];
            p = new int[size];
            for (int i = 0; i < size; i++)
            {
                rank[i] = 0;
                p[i] = i;
            }
        }
        public void Unite(int x, int y)
        {
            x = FindSet(x);
            y = FindSet(y);
            if (rank[x] > rank[y]) p[y] = x;
            if (rank[x] < rank[y]) p[x] = y;
            if (rank[x] == rank[y])
            {
                p[x] = y;
                rank[y]++;
            }
        }
        public bool Same(int x, int y)
        {
            return FindSet(x) == FindSet(y);
        }
        public int FindSet(int x)
        {
            var H = new HashSet<int>();
            while (p[x] != x)
            {
                H.Add(x);
                x = p[x];
            }
            foreach (var h in H)
            {
                p[h] = x;
            }
            return x;
        }
    }
}

Measured memory_bytes: 21392
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))

    a.sort()
    ret = 1
    for i in range(n):
        ret *= a[i]
        if ret > 10 ** 18:
            ret = -1
            break

    print(ret)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21648
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int i,j,k,n,ans;
  string str,match;
  while(cin >> match){
    cin >> n;
    ans = 0;
    for(i=0;i<n;i++){
      cin >> str;
      for(j=0;j<str.size();j++){
	if(str[j] == match[0]){
	  for(k=0;k<match.size();k++){
	    if(str[(j+k)%str.size()] != match[k]) break;
	  }
	  if(k == match.size()){
	    ans++;
	    break;
	  }
	}
      }
    }

    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
static char s[100001];
static int n, l;
static int f_cmp(const void *a, const void *b) {
    int i, j;
    
    for (i = 0; i < l; ++i) {
        if (j = *((char *)a + i) - *((char *)b + i))
            return j;
    }
    return 0;
}
int main(void) {
    int i;
    scanf("%d%d", &n, &l);
    for (i = 0; i < n; ++i)
        scanf("%s", s + i * l);
    qsort(s, n, l * sizeof(char), f_cmp);
    printf("%s\n", s);
    return 0;
}


Measured memory_bytes: 252
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
t = bisect_left(a, 0, 0, len(a))
ans = float("inf")
if t + k <= n:
    ans = a[t + k - 1]
if t >= k:
    ans = min(ans, -a[t - k])
for i in range(max(0, t - k + 1), min(t, n-k+1)):
    ans = min(ans, a[i+k-1]-2*a[i], 2*a[i+k-1]-a[i])
print(ans)


Measured memory_bytes: 14480
import sys
from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.root = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.root[x] == x:
            return x
        else:
            y = self.find(self.root[x])
            self.root[x] = y
            return self.root[x]

    def unite(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.root[rx] = ry
        else:
            self.root[ry] = rx
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    

def main():
    input = sys.stdin.readline
    N, K, L = map(int, input().split())
    road = UnionFind(N)
    rail = UnionFind(N)

    for _ in range(K):
        p, q = map(int, input().split())
        road.unite(p-1, q-1)

    for _ in range(L):
        r, s = map(int, input().split())
        rail.unite(r-1, s-1)

    d = defaultdict(lambda: 0)
    for i in range(N):
        n = road.find(i)
        m = rail.find(i)
        d[(n, m)] += 1

    ans = []
    for i in range(N):
        n = road.find(i)
        m = rail.find(i)
        ans.append(d[(n, m)])

    return print(*ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int x,n,i;
    cin >> x >> n;

    vector<int> p(n);
    for(i=0; i<n; i++)
    cin >> p.at(i);

    int ans =0;
    for(int q=0; q<=101; q++){
        int f= 1;
        for(i=0; i<n; i++){
            if(q == p.at(i)){
                f = 0;
            }
        }

        if(f==0){
            continue;
        }
        if(abs(ans - x) > abs(q-x)){
            ans = q;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) (n int, err error) {
	sc.Scan()
	s := sc.Text()
	n, err = strconv.Atoi(s)
	return
}

func readIntNums(sc *bufio.Scanner, n int) ([]int, error) {
	nums := make([]int, n)
	for i, _ := range nums {
		if a, err := nextInt(sc); err == nil {
			nums[i] = a
		} else {
			return nums, err
		}
	}
	return nums, nil
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for {
		arr, err := readIntNums(sc, 5)
		if err != nil {
			break
		}
		W, H, x, y, r := arr[0], arr[1], arr[2], arr[3], arr[4]
		if x >= r && x+r <= W &&
			y >= r && y+r <= H {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}



Measured memory_bytes: 1084
#include<stdio.h>
int main(void)
{
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0 && y==0) break;
        if(x<y) printf("%d %d\n",x,y);
        else printf("%d %d\n",y,x);
    }
    return 0;
}

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

int main()
{
	int N,M;
  	cin>>N>>M;
  	int i,sum=0,A[M];
  	for(i=0;i<M;i++)
    {
    	cin>>A[i];
      	sum=sum+A[i];
    }
  	if(sum<=N)
    {
      cout<<N-sum;
    }
  	else
    {
    	cout<<-1;
    }




	return 0;
}


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

int main(){
 int N ;
 char S ;
 string L;
 cin >> N; 
  for (int i = 0 ; i < N ; i++){
    cin >> S;
    if ( S == 'Y' ){
      L = "Four";
      break;
   }
    else {
      L = "Three";
   }
   }
   cout << L << endl;
}

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

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n = lread();
    auto p = aryread();
    auto q = aryread();
    long iter, p_n, q_n;
    auto tmp = iota(n).map!(x => x + 1).array();
    while (tmp.nextPermutation())
    {
        iter++;
        if (p == tmp)
            p_n = iter;
        if (q == tmp)
            q_n = iter;
    }
    writeln(abs(p_n - q_n));
}

bool is_reversable(string s)
{
    bool ret = true;
    foreach (i; iota(s.length / 2))
    {
        ret &= (s[i] == s[$ - 1 - i]);
    }
    return ret;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N , M = map(int, input().split())
    sc = {}
    ans = 0

    for _ in range(M):
        s, c = map(int, input().split())

        if N != 1:
            if s == 1 and c == 0:
                print(-1)
                quit()

        if s in sc:
            if c != sc[s]:
                print(-1)
                quit()
        else:
            sc[s] = c
            ans += c * (10 ** (N - s))

    if N != 1:
        if ans < 10 ** (N - 1):
            ans += 10 ** (N - 1)

    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

template <class It> string join(It i1, It i2)
{
    ostringstream ss;
    for (auto it = i1; it != i2; ++it)
        ss << ((it == i1) ? "" : ", ") << (*it);
    return ss.str();
}

void Print() { cout << endl; }
template <class Head, class... Args> void Print(Head &&head, Args&&... args)
{
    cout << head;
    Print(args...);
}

#define Repeat(x, i, j) for (size_t x = i; x < j; ++x)

#ifdef DEBUG
#define Dump(x) cerr << #x << " = " << x << endl;
#define Dumps(x) cerr << #x << " : { " << join(x.begin(), x.end()) << " }" << endl;
#else
#define Dump(x)
#define Dumps(x)
#endif


using ull_t = unsigned long long;


int main()
{
    int H, W;
    cin >> H >> W;
    
    vector<vector<char>> M(H, vector<char>(W, '.'));
    vector<int> N1(H, 0), N2(W, 0);
    
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            cin >> M[i][j];
            if (M[i][j] == '#')
            {
                ++N1[i];
                ++N2[j];
            }
        }
    }

    for (int i = 0; i < H; ++i)
    {
        if (N1[i] == 0) continue;
        
        for (int j = 0; j < W; ++j)
        {
            if (N2[j] == 0) continue;

            cout << M[i][j];
        }
        cout << endl;
    }
}


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

int main(){
   int n;
   cin>>n;
   vector<int>vec(3);
   for(int i=0;i<3;i++){
       vec[i]=n%10;
       n/=10;
       if(vec[i]==1){
           vec[i]=9;
       }
       else {
           vec[i]=1;
       }
   }

cout<<vec[2]<<vec[1]<<vec[0]<<endl;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n;
	int h[25];
	cin >> n;
	rep(i, n) cin >> h[i];
	int ans = 0;
	int target = h[0];
	for (int i = 0; i < n;++i) {
		if (target <= h[i]) {
			ans++;
			target = h[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using f32 = float;
using f64 = double;
using LL = long long;
using ULL = unsigned long long;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
int main()
{ 
 string a,b;
  cin>> a>>b;
  cout <<b+a;
}

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

using namespace std;

typedef long long ll;

#define INF 10000000
#define mp make_pair
#define fi first
#define se second

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(0,min(b,d)-max(a,c));
    return 0;
}


Measured memory_bytes: 256
#include <ctime>
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

#define int long long
#define INF 1e18
#define EPS 1e-9
#define NIL -1
#define N 100

signed main() {
    int n; cin >> n;
    vector<int> h(n); for(int i = 0; i < n; i++) cin >> h[i];
    int ans = 0;
    int active = 0;

    for(int i = 0; i < n; i++) {
        if(active >= h[i]) {
            active = h[i];
        } else {
            ans += h[i] - active;
            active = h[i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int a, b; cin >> a >> b;
    cout << (a + b) / 2 << endl;
    return 0;
}



Measured memory_bytes: 3104
from sys import stdin
input = list(stdin.readline().rstrip())

n = len(input)

if n % 2 == 1:
    del input[n//2]
    n = len(input)
cnt = 0
for i in range(int(n/2)-1, -1, -1):
    if input[i] != input[n-i-1]:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>


using namespace std;
#define MAX 100000

int main(){
    int N;

    scanf("%d", &N);
    int i = 0;
    for (i = 0; i <= N; i++){
        if ((0 == i % 4) && (0 == (N - i) % 7)){
            printf("Yes");
            return 0;
        }
    }

    printf("No");
    

    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<pair<long long int,long long int>>num(N);
	for (int i = 0; i < N; i++) {
		cin >> num[i].first;
		num[i].second = i;
	}
	sort(num.begin(), num.end());
	map<long long int, int>m;
	m[-1] = 1;
	m[N] = 1;
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		//cout << num[i].second << endl;
		m[num[i].second] = 1;
		auto j = m.find(num[i].second);
		auto k = j;
		k--;
		j++;
		ans += (num[i].second - (*k).first)*((*j).first - num[i].second)*num[i].first;
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


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

const int MAXN = 2e5;
int N;
int cnt[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		cnt[a]++;
	}

	for (int i = 0; i < N; i++) {
		int v = abs(i - (N-1-i));
		if (cnt[v] != 2 - (v == 0)) {
			cout << 0 << '\n';
			exit(0);
		}
	}

	const int MOD = 1e9 + 7;
	int ans = 1;
	for (int i = 0; i < N/2; i++) {
		ans = 2 * ans % MOD;
	}
	cout << ans << '\n';

	return 0;
}


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

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> size;
	
	UnionFind(int N) : par(N), rank(N), size(N){
		rep(i,N){
			par[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
	}
	
	int root(int x) {
		if (par[x] == x) return x;
		par[x] = root(par[x]);
		return par[x];
	}
	
	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		if(rank[rx] < rank[ry]){
			par[rx] = ry;
			size[ry] += size[rx];
		}else{
			par[ry] = rx;
			size[rx] += size[ry];
			if(rank[rx] == rank[ry]) rank[rx]++;
		}
	}
	
	bool same(int x, int y){
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main(){
	ll n,m;
	cin >> n >> m;
	UnionFind tree(n);
	rep(i,m){
		ll a,b;
		cin >> a >> b;
		a--;b--;
		tree.unite(a,b);
	}
	int ans = 0;
	rep(i,n) ans = max(ans, tree.size[tree.root(i)]);
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5624
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
	string[] inputs = split(readln());
	int a, b;
	foreach(v; inputs) {
		switch(v) {
			case "5":
				a++;
				break;
			case "7":
				b++;
				break;
			default:
				break;
		}
	}
	if(a == 2 && b == 1) "YES".writeln;
	else "NO".writeln;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,i,j;
  double x[10];
  char u[2][4]={"JPY","BTC"};
  char str[10][4];
  double sum=0.0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%lf",&x[i]);
    scanf("%s", str[i]);
  }
  
  for(j=0;j<n;j++){
    if(u[0][0]==str[j][0]){
      sum+=x[j];
    }
    if(u[1][0]==str[j][0]){
      sum+=x[j]*380000.0;
    }
  }
  
  printf("%f\n",sum);
  return 0;
}
    

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,x,sum=0;

int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		cin>>x;
		sum+=x;
	}
	if(sum>n) puts("-1");
	else cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 3620
N,Q = map(int,input().split())
S = '_'+input()+'_'
td = [input().split() for _ in range(Q)]
R = N+1
L = 0
for i in range(Q-1,-1,-1):
    t,d = td[i]
    if t == S[R-1] and d == 'R':
        R -= 1
    elif t == S[R] and d == 'L':
        R += 1
    if t == S[L+1] and d == 'L':
        L += 1
    elif t == S[L] and d == 'R':
        L -= 1
print(max(0,R-L-1))

Measured memory_bytes: 41396
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
std::vector<int> fac(200001); //n!(mod M)
std::vector<int> ifac(200001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

int mpow(int x, int n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    int ans = 1;
    while(n != 0){
        if(n&(int)1) ans = (ans*x) % INT_DMAX;
        x = (x*x) % INT_DMAX;
        n = n >> (int)1;
    }
    return ans;
}

int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a <= 0)return 0;
    int tmp = (ifac[a-b]* ifac[b]) % INT_DMAX;
    return (tmp * fac[a]) % INT_DMAX;
}

signed main()
{
int n,m;
std::cin >> n >> m;
std::vector<int> mult;
fac[0] = (int)1;
ifac[0] = (int)1;
    for(int i = 0; i<200000; i++){
        fac[i+1] = fac[i]*(i+1) % INT_DMAX; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, INT_DMAX - 2) % INT_DMAX; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
int div = m;
for(int i = 2; i <= sqrt(div); i++){
    int temp = 0;
    while(div % i == 0){
        div = div / i;
        temp++;
    }
    if(temp != 0){
        mult.pb(temp);
    }
}
if(div != 1){
    mult.pb(1);
}
int out = 1;
for(int i = 0; i < mult.size(); i++){
    out = (out * comb(n + mult[i] - 1, mult[i])) % INT_DMAX;
}
std::cout << out;
return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

    vector<pii> pairs;
    int value = n - n%2;
    for (int i = 1; i*2 <= value; i++)
        pairs.emplace_back(i, value - i+1);

    if (n%2 == 0)
        pairs.emplace_back(1, value);
    else
    {
        pairs.emplace_back(n, -1);
        pairs.emplace_back(1, value);
    }
    
    vector<pii> res;
    rep(i, 0, pairs.size() - 1)
    {
        pii p1, p2;
        p1 = pairs[i];
        p2 = pairs[i+1];

        if (p1.first != -1 and p2.first != -1)
            res.emplace_back(p1.first, p2.first);
        if (p1.first != -1 and p2.second != -1)
            res.emplace_back(p1.first, p2.second);
        if (p1.second != -1 and p2.first != -1)
            res.emplace_back(p1.second, p2.first);
        if (p1.second != -1 and p2.second != -1)
            res.emplace_back(p1.second, p2.second);
    }

    // filtering
    vector<pii> result;
    set<int> used;
    for (auto p: res)
    {
        if (p.first > p.second) swap(p.first, p.second);
        int now = p.first * 200 + p.second;
        if (used.count(now) == 0)
        {
            used.insert(now);
            result.push_back(p);
        }
    }

    cout << result.size() << endl;
    for (auto p: result)
        cout << p.first << ' ' << p.second << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF =ll(1e18)+5;

int main() {
    string S;
    cin >> S;
    vector<vector<ll>> place(26);
    for(int i=0;i<S.size();i++){
        int t = S[i] -'a';
        place[t].push_back(i);
    }
    for(int i=0;i<26;i++){
        place[i].push_back(S.size());
    }
    ll ans =INF;
    for(int i=0;i<26;i++){
        ll temp = 0;
        ll last =-1;
        for(ll t:place[i]){
            // cerr <<"t=" << t << endl;
            temp =max(temp,t-last-1);
            last = t;
        }
        // cerr << char('a' +i) << "temp=" << temp <<endl;
        ans = min(temp,ans);
    }
    cout << ans << 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(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF 1e12
#define SIZE 1e5
typedef long long ll;
typedef pair<ll,int> P;
int main(){
	int N,W;
	cin >> N >> W;
	vector<P> items(N+1);
	rep(i,N){
		ll w;
		int v;
		cin >> w >> v;
		items[i+1] = make_pair(w,v);
	}

	vector<vector<ll>> knap(N+1,vector<ll>(SIZE+1,INF));
	for(int i=1; i<=N; i++){
		knap[i][items[i].second] = min(knap[i-1][items[i].second],items[i].first);
		for(int j=1; j<=SIZE; j++){
			if(j-items[i].second > 0){
				knap[i][j] = min(knap[i-1][j],knap[i-1][j-items[i].second]+items[i].first);
			} else {
				knap[i][j] = min(knap[i-1][j], knap[i][j]);
			}
		}
	}
	int ans = 0;
	for(int j=SIZE; j>0; j--){
		for(int i=1; i<=N; i++){
			if(knap[i][j] <= W){
				ans = j;
				break;
			}
		}
		if(ans)break;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 83244
N,D= map(int,input().split())
X =[]
for n in range(N):
    X.append([int(i) for i in input().split()])
cnt =0
from itertools import combinations
for i in list(combinations(X,2)):
    tmp=0
    for j in range(len(X[0])):
        tmp += ((i[0][j]-i[1][j])**2 )
    
    if int(tmp**0.5)==tmp**0.5:
        cnt+=1
print(cnt)

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

const int MAXN = 510;

int K;
int a[MAXN][MAXN];

int main() {
	scanf("%d", &K);
	int n = std::min(500, K);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) a[i][j] = (i + j - 2) % n + 1;
	for (int i = n + 1; i <= K; ++i)
		for (int j = 1, k = i - n; j <= n; j += 2, k = (k - 3 + n) % n + 1) a[j][k] = i;
	printf("%d\n", n);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) printf("%d%c", a[i][j], " \n"[j == n]);
	return 0;
}

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


int main() {

  int n,k;
  cin>>n>>k;


  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }

  sort(p.begin(),p.end());

  int64_t sum=0;
  for(int i=0;i<k;i++){
    sum+=p.at(i);
  }

  cout<<sum<<endl;

  return 0;
}




Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
vector<int>g[110000];
int dp[110000];
int v[110000];
int dfs(int a){
	if(g[a].size()==0){
		return dp[a]=0;
	}
	for(int i=0;i<g[a].size();i++){
		dfs(g[a][i]);
	}
	for(int i=0;i<g[a].size();i++){
		v[i]=dp[g[a][i]];
	}
	int n=g[a].size();
	std::sort(v,v+n);
	int ret=0;
	for(int i=0;i<n;i++){
		ret=max(ret,(i+1)+v[n-1-i]);
	}
	return dp[a]=ret;
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		int p;scanf("%d",&p);p--;
		g[p].push_back(i+1);
	}
 
	int ret=dfs(0);
	printf("%d\n",ret);
}

Measured memory_bytes: 12544
#include <iostream>
using namespace std;
int main(){
  int a,b,c;cin>>a>>b>>c;
  cout << a << " " << b << " " << c+c+c-a-b << endl;
  cout << c+c+c+c-a-a-b << " " << c << " " << a+a+b-c-c << endl;
  cout << a+b-c  << " " << c+c-b << " " << c+c-a << endl;
}

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

int main() {
    long long a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if (v<=w){
        cout << "NO" << endl;
        return 0;
    }
    long long d = a > b ? (a - b) : (b - a);
    long long u = v-w;
    cout << (u*t >= d ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[3];
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a,a+3);
	for(int i=0;i<3;i++){
		cout<<a[i];
		if(i==2) break;
		else cout<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3152
// abc067_b
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define FOR(i, a) for (auto i : a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define show1d(v)                                                              \
  rep(i, v.size()) cout << " " << v[i];                                        \
  cout << endl << endl;
#define show2d(v)                                                              \
  rep(i, v.size()) {                                                           \
    rep(j, v[i].size()) cout << " " << v[i][j];                                \
    cout << endl;                                                              \
  }                                                                            \
  cout << endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main(int argc, char *argv[]) {
  int n, k, sum = 0;
  cin >> n >> k;
  vi l(n);
  rep(i, n) { cin >> l.at(i); }
  sort(l.rbegin(), l.rend());
  rep(i, k) { sum += l.at(i); }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<ll, ll>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    vector<pair<ll, ll> > v(n);
    fore(i, 0, n) {
        cin >> v[i].F >> v[i].S;
    }
    sort(all(v), [](ii a, ii b) {
        return (a.F+a.S) < (b.F+b.S);
    });
    ii a = v[0];
    ii b = v.back();
    ll res = b.F + b.S - a.F - a.S;
    sort(all(v), [](ii a, ii b) {
        return (a.F-a.S) < (b.F-b.S);
    });
    a = v[0];
    b = v.back();
    res = max( res, (b.F - b.S) - (a.F - a.S) );
    cout << res << '\n';
    return 0;
}
// Dinosaurs are cool!

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

int main(){
  int N,C;
  int s[100000], t[100000],c[100000];
  int temp_channel[200002], integrate_channel[200002];


  cin >> N >> C;
  for(int i=0;i<N;i++){
    cin >> s[i] >> t[i] >> c[i];
  }
  for(int i=0;i<200002;i++){
    integrate_channel[i] = 0;
  }
  //cout << "hogehoge"<< endl;
  for(int i=1;i<=C;i++){
    //まずはtemp_channelの初期化
    for(int j=0;j<200002;j++){
      temp_channel[j] = 0;
    }
    //録画始まりの時間を+1, 終わりの時間を-1する(将来は累積和をとる。)
    //もし連続して予約したい番組もこれでケア可能。
    for(int j=0;j<N;j++){
      if(c[j]==i){
        temp_channel[2*s[j]-1]++;
        temp_channel[2*t[j]]--;
      }
    }
    //チャンネルiについて累積和を計算
    for(int j=1;j<200002;j++){
      temp_channel[j] += temp_channel[j-1];
      //cout << "i:" <<j<< "    temp_channel:" << temp_channel[j] << endl;
    }
    //チャンネル統合枠にぶちこみ
    for(int j=0;j<200002;j++){
      if(temp_channel[j] > 0){
        integrate_channel[j]++;
      }
    }
  }
  //integrate_channelの最大値を探す。
  int mx=0;
  for(int i=0;i<200002;i++){
    if(mx < integrate_channel[i]){
      mx = integrate_channel[i];
    }
  }
  cout << mx << endl;
}


Measured memory_bytes: 2944
import scala.io.StdIn.readLine
 
object Main {
  def search(a:Array[Int],len:Int,value:Int) = {
    def scan(l:Int,r:Int):Boolean = {
      val mid = (l+r)/2
      if(a(mid) == value) true
      else if(l>=r) false
      else if(a(mid)<value) scan(mid+1,r)
      else scan(l,mid-1)
    }
    scan(0,len)
  }
 
  def main(args:Array[String]) = {
    readLine
    val s = readLine.split(" ").map(_.toInt)
    readLine
    val t = readLine.split(" ").map(_.toInt)
    val len = s.length-1
    println(t.count(i=> search(s,len,i) ))
  }
}

Measured memory_bytes: 71048
#include<stdio.h>
int iP(int);
int main(){
  int n,a,b,i,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    b=iP(a);
    if(b==1)count++;
  }
  printf("%d\n",count);
}
int iP(int a){
  int i;
  if(a<2)return 0;
  for(i=2;i*i<=a;i++){
    if(a%i==0)return 0;
  }
  return 1;
}



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

int main(){
    int n, m;
    int matrix[101][101] = {};
    int vec1[101] = {};
    int ans[101] = {};
    
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cin >> matrix[i][j];
    }
    for(int i = 0; i < m; i++) cin >> vec1[i];
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) ans[i] += matrix[i][j] * vec1[j];
    }
    
    for(int i = 0; i < n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void orz(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18;
/***********************************************************************/

int32_t main() {
 
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  map<string,int> freq;
  for (int i = 0; i < n; ++i) {
    string s; cin >> s;
    sort(ALL(s));
    freq[s]++;
  }
  i64 ans = 0;
  for (const auto &e : freq) {
    ans += (i64) (e.second - 1) * e.second / 2;
  }
  orz(ans);
  
  return 0;
}


Measured memory_bytes: 11264
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int a, b, c;
    cin>>a>>b>>c;
    int ans=0;
    for(int i=a; i<=b; i++) {
        if(c%i==0) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 1192