akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>

using namespace std;
const int MAX_N = 301;
double dp[MAX_N][MAX_N][MAX_N];
int N;

double dfs(int i, int j, int k) {

  if (dp[i][j][k] >= 0) return dp[i][j][k];
  if (i == 0 && j == 0 && k == 0) return 0.0;

  double res = 0.0;
  if (i > 0) res += dfs(i-1, j,   k  ) * i;
  if (j > 0) res += dfs(i+1, j-1, k  ) * j;
  if (k > 0) res += dfs(i,   j+1, k-1) * k;
  res += N;
  res *= 1.0 / (i + j + k);
  dp[i][j][k] = res;
  
  return dp[i][j][k];
}


int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin >> N;

  int a, n1, n2, n3;
  n1 = n2 = n3 = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    
    if (a == 1)      n1++;
    else if (a == 2) n2++;
    else if (a == 3) n3++;
  }

  memset(dp, -1.0, sizeof(dp));
  dp[0][0][0] = 0.0;

  double ans = dfs(n1, n2, n3);
  printf("%0.12lf\n", ans);
  return 0;
}



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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int x, res =0;
    cin >> x;
    cout << x/500 * 1000 + (x%500)/5 *5 <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int i,j,a[3],mini=100000,maxi=0,mediumx,minix,maxix;
    for(i=0;i<3;i++){
        cin >> a[i];
    }
    for(i=0;i<3;i++){
        if(a[i]<mini){
            mini = a[i];
            minix = i;
        }
        if(a[i]>maxi){
            maxi = a[i];
            maxix = i;
        }
    }
    for(i=0;i<3;i++){
        if(i!=maxi && i!= minix ){
            mediumx = a[i];
        }
    }
    cout << a[mediumx]-a[minix]+a[maxix]-a[mediumx];
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
struct pt{
  ll x,y;
};
ll dist(pt a,pt b){
  return abs(a.x-b.x) + abs(a.y-b.y);
}
ll fmax(ll a,ll b,ll c,ll d){
  return max(max(a,b),max(c,d));
}
const ll INF = 1e15;
signed main(){
  init_io();
  ll n;
  cin >> n;
  vector<ll> x(n),y(n);
  ll zmin=INF,zmax=-INF,wmin=INF,wmax=-INF;
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
    ll z=x[i]+y[i];
    ll w=x[i]-y[i];
    zmin = min(zmin,z);
    zmax = max(zmax,z);
    wmin = min(wmin,w);
    wmax = max(wmax,w);
  }
  cout << max(zmax-zmin,wmax-wmin) << endl;
}


Measured memory_bytes: 6304
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
        String s = sc.next();
        String[] line = s.split("");
		int index = sc.nextInt();
        String a = line[index-1];
        for(int i=0; i<num; i++){
          if(!line[i].equals(a)) line[i] = "*";
          System.out.print(line[i]);
        }


	}
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int cnt =0;
	for(int x =a; x<=b; x++){
		if(c%x == 0) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> rec(10);
	rep(i, k) {
		int d;
		cin >> d;
		rec[d] = 1;
	}
	while (1) {
		bool elf = true;
		int now = n;
		while (now) {
			if (rec[now % 10]) elf = false;
			now /= 10;
		}
		if (elf) {
			cout << n << endl;
			return 0;
		}
		n++;
		
	}
	return 0;
}

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

t = [0] * 5
for i in range(5):
    t[i] = int(input())

t.sort()
l = []
import math
s = 0
for i in range(5):
    if t[i] % 10 == 0:
        s += t[i]
    else:
        l.append(t[i])
        
ll = len(l)
l = sorted(l, key = lambda n: n % 10, reverse = True)

for i in range(ll):
    if i == ll - 1:
        s += l[i]
    else:
        s += math.ceil(l[i] / 10) * 10
print(s)

Measured memory_bytes: 3064
//11942

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner Input = new Scanner(System.in);
        HashMap<String, Integer> HM = new HashMap();
        int N = Input.nextInt();
        for (int I = 0; I < N; I++) {
            String S = Input.next();
            HM.put(S, 0);
        }
        if (HM.size() == 4) {
            System.out.println("Four");
        } else if (HM.size() == 3) {
            System.out.println("Three");}
    }
}


Measured memory_bytes: 21844
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k,ans=0,min=inf,min2=inf;
	string s;
	cin >> n >> k;
	//cin >> s;

	for(int i=1;i<=n;i++){
		ans+=k+i-1;
		if(min>abs(k+i-1)){
			min=abs(k+i-1);
			min2=k+i-1;
		}
	}
	if(min2>=0){
	ans -= min;
	}
	else{
		ans += min;
	}

	cout << ans << endl;
}

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

typedef long long LL;

int k,n,a[105];
char s[105];

int main()
{
	scanf("%s",s+1);
	scanf("%d",&k);
	n=strlen(s+1);
	int tot=0;
	for (int i=1;i<=n;i++)
		if (i==1||s[i]!=s[i-1]) a[++tot]=1;
		else a[tot]++;
	int ans=0;
	for (int i=1;i<=tot;i++) ans+=a[i]/2;
	if (tot==1) printf("%lld\n",(LL)n*k/2);
	else if (s[1]!=s[n]) printf("%lld\n",(LL)ans*k);
	else if ((a[1]&1)&&(a[tot]&1)) printf("%lld\n",(LL)ans*k+(LL)(k-1));
	else printf("%lld\n",(LL)ans*k);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n,m;
bool b[210000];

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

  vector<int> ans;

  rep(i,m){
    if(b[a[i]]) continue;
    ans.PB(a[i]);
    b[a[i]]=true;
  }

  FOR(i,1,n+1){
    if(!b[i]) ans.PB(i);
  }

  rep(i,n){
    cout<<ans[i]<<endl;
  }

}



Measured memory_bytes: 6052
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * https://atcoder.jp/contests/dp/tasks/dp_e
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int W = in.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];
        for (int i = 0; i < N; i++) {
            w[i] = in.nextInt();
            v[i] = in.nextInt();
        }
        System.out.println(maxValue(N, W, w, v));
    }

    public static int maxValue(int N, int W, int[] w, int[] v) {
        int sum = Arrays.stream(v).sum();
        long[] dp = new long[sum + 1];
        Arrays.fill(dp, Long.MAX_VALUE);
        dp[0] = 0;
        for (int i = 0; i < N; i++) {
            for (int j = sum; j >= 0; j--) {
                if (j - v[i] >= 0 && dp[j - v[i]] != Long.MAX_VALUE) {
                    dp[j] = Math.min(dp[j], dp[j - v[i]] + w[i]);
                }
            }
        }
        return IntStream.range(0, sum + 1).filter(l -> dp[l] <= W).max().getAsInt();
    }

}


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

void visit(vector<long long> &runrun, long long n,long long len,long long keta){
    long long m;
    if(len >= keta){
        runrun.push_back(n);
    }else{
        for(m = (n%10)-1; m <= (n%10)+1; m++){
            if(m < 0) continue;
            if(m > 9) continue;
            visit(runrun, 10*n + m, len + 1,keta);
        }
    }
}


void search(vector<long long> &runrun){
    long long n, keta;
    for(n = 1; n <= 9; n++){
        for(keta = 1; keta <= 10; keta++){
            visit(runrun,n,1,keta);
        }
    }
}

int main(){
    vector<long long> runrun;
    long long K;
    cin >> K;
    search(runrun);
    sort(runrun.begin(),runrun.end());
    long long i;
    cout << runrun[K-1] << endl;    
    system("pause");
    return 0;
}

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

int main(int argc, char const *argv[])
{
	string n; cin >> n;
	cout << (n[0] == '7' or n[1] == '7' or n[2] == '7' ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define forN(N) if(N >= 0)for(size_t i = 0;i < N;++i)
typedef unsigned long long ul ;

int main() {
  ul D;
  vector<int>c;
  vector<int>last;
  vector<vector<int>>s;
  cin >> D;
  forN(26){
    int t;
    cin >> t;
    c.push_back(t);
    last.push_back(-1);
  }
  forN(D){
    vector<int> tv;
    int maxI = -1;
    int maxN = -1;
    for(int j = 0;j < 26;++j){
      int t;
      cin >> t;
      tv.push_back(t);
      int nnn = (t - (c[j] * (i - last[j])));
      //cout << nnn << ",";
      if(maxN < t - nnn){
		maxN = t - nnn;
        maxI = j;
      }
    }
    cout << (maxI + 1) << endl;
    last[maxI] = i;
    s.push_back(tv);
  }
}


Measured memory_bytes: 3680
#include<stdio.h>

int main(void)
{
	int a, b, d,N,K,sum=0;
	int A[101] = {0};
	scanf("%d %d", &N ,&K);

	for (int i = 0;i<K;i++) {
		scanf("%d", &d);
		for (int j = 0;j < d;j++) {
			scanf("%d",&a);
			A[a]++;
		}
	}


	for (int i = 1;i <= N;i++) {
		if (A[i] == 0)sum++;
}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
using namespace std;

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


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

int main(){
  int r;
  cin >> r;
  if (r < 1200){
    cout << "ABC" << endl;
  }
  else if (r < 2800){
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "a") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main() {
    //setIO();
    int a, b, c; cin >> a >> b >> c; 
    set <int> se; se.insert(a); se.insert(b); se.insert(c);
    cout << se.size() << "\n";
}

Measured memory_bytes: 3520
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    string s;
    cin >> s;

    bool ans{};

    for (int i = 0; i < s.size(); ++i)
        for (int l = 0; l + i < s.size(); ++l)
        {
            string sub;
            sub += s.substr(0, i);
            sub += s.substr(i + l);
            if (sub == "keyence")
            {
                ans = true;
                break;
            }
        }

    if (ans)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// 基本テンプレート
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// Effective std
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }

template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }

template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }

template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }

template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }

template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }


// グラフテンプレート
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main() {
  int N, L;
  cin >> N >> L;
  string S;
  string arr[N];
  rep(i, N) {
    string s, t;
    cin >> s;
    arr[i] = s;
  }

  rep(i, N) {
    int minIndex = 0;
    rep(j, N) {
      if(arr[j] < arr[minIndex]) minIndex = j;
    }
    S += arr[minIndex];
    arr[minIndex] = "zzzzzzzzzzzzzzzzz";
  }
  cout << S << endl;
  return 0;
}



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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    int l,r,d;
    cin >> l >> r >> d;
    cout << r/d-(l-1)/d;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

bool kirino(string s,char c) {
    for (auto i:s) {
        if (i!=c) return false;
    }
    return true;
}

int main () {
    string s;
    cin >> s;
    int mn = 12345678;
    for (int i='a';'z' >= i;i++) {
        bool check=false;
        for (auto j:s) {
            if (j==i) {
                check=true;
                break;
            }
        }
        if (!check) continue;
        string ss=s;
        int cnt=0;
        while (kirino(ss,i) == false) {
            cnt++;
            string sss;
            sss.resize(ss.size()-1);
            for (int j=0;ss.size()-1>j;j++) {
                if (ss[j] == i) sss[j]=i;
                if (ss[j+1]==i) sss[j]=i;
            }
            ss=sss;
        }
        mn = min(mn,cnt);
    }
    cout<<mn<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int N, K;
vector<int> h(1000001);

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

	for (int i = 1; i <= N; i++)
	{
		cin >> h[i];
	}

	vector<ll> dp(100001, 1e18);
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);

	for (int n = 3; n <= N; n++)
	{
		for (int k = 1; k <= K && k < n; k++)
		{
			dp[n] = min(dp[n - k] + abs(h[n] - h[n - k]), dp[n]);
		}
	}

	cout << dp[N] << endl;
}

Measured memory_bytes: 4992
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        mut a: i64, mut b: i64, c: i64,
    }

    if a > b {
        std::mem::swap(&mut a, &mut b);
    }
    if a < c && c < b {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2096
fun main(args: Array<String>) {
    val (k,a,b) = readLine()!!.split(" ").map { it.toLong() }
    if(k<=a || a>=b-2) {
        println(k+1)
        return
    }

    val i = k-a+1
    println( a + (b-a) * (i/2) + i%2 )

}


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

using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int r1, r2;
    cin >> r1 >> r2;
    cout << (ld)(r1 * r2) / (r1 + r2) << EOL;
}


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

int main() {
	int n, k; cin >> n >> k;
	long long ans = 0, cnt = 0;
	if (k % 2 == 0) {
		for (int i = 1; i <= n; i++) {
			if (i % k == (k / 2))cnt++;
		}
	}
	ans += cnt * cnt * cnt;
	cnt = 0;

	for (int i = 1; i <= n; i++) {
		if (i % k == 0)cnt++;
	}
	ans += cnt * cnt * cnt;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1111];
long long s[1111*1111];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int t=0;
	for(int i=0;i<n;i++)
	{
		long long sum=0;
		for(int j=i;j<n;j++)
		{
			sum+=a[j];
			s[++t]=sum;
		}
	}
	long long ans=0;
	for(int i=40;i>=0;i--)
	{
		int cnt=0;
		for(int j=1;j<=t;j++)
		{
			if(s[j]&(1ll<<i))
			{
				++cnt;
			}
		}
		if(cnt>=k)
		{
			int nt=0;
			for(int j=1;j<=t;j++)
			{
				if(s[j]&(1ll<<i))
				{
					s[++nt]=s[j];
				}
			}
			t=nt;
			ans|=1ll<<i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4352
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_plus_index = list(A[i]+i+1 for i in range(N))
    A_plus_index = Counter(A_plus_index)
    index_minus_A = list(i+1-A[i] for i in range(N))
    ans = 0
    for a in index_minus_A:
        ans += A_plus_index.get(a, 0)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 43448
import sys

n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if a[i+k][j:j+m] != b[k]:
                break
            if k == m-1:
                print('Yes')
                sys.exit(0)
print('No')

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

int main(){
	int m,n,k;
static 	char c[1002][1002];
static	int J[1002][1002],O[1002][1002],I[1002][1002];

	scanf("%d%d%d",&m,&n,&k);
	for(int i=1;i<=m;i++){
		scanf("\n");
		for(int j=1;j<=n;j++){
			scanf("%c",&c[i][j]);
		}
	}

	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			J[i][j]=J[i-1][j]+J[i][j-1]-J[i-1][j-1];
			O[i][j]=O[i-1][j]+O[i][j-1]-O[i-1][j-1];
			I[i][j]=I[i-1][j]+I[i][j-1]-I[i-1][j-1];

			if(c[i][j]=='J')J[i][j]++;
			else if(c[i][j]=='O')O[i][j]++;
			else if(c[i][j]=='I')I[i][j]++;
		}
	}

	for(int i=0;i<k;i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int retJ=J[c][d]-J[a-1][d]-J[c][b-1]+J[a-1][b-1];
		int retO=O[c][d]-O[a-1][d]-O[c][b-1]+O[a-1][b-1];
		int retI=I[c][d]-I[a-1][d]-I[c][b-1]+I[a-1][b-1];
		printf("%d %d %d\n",retJ,retO,retI);
	}
}

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

#define N 100000
#define NIL -1

typedef struct t{
  int id;
  int parent;
  int degree;
  int depth;
  int child[2];
  int sibling;
  int height;
}Tree;

void depthcalculation(int, int);
void heightcalculation(int);

Tree T[N];
int maxdepth = 0;

int main(){
  int treenum, i, id, j;
  
  scanf("%d", &treenum);
  
  //preparation
  for(i = 0; i < treenum; i++){
    T[i].parent = NIL;
    T[i].depth = 0;
    T[i].sibling = -1;
    T[i].height = 0;
    T[i].degree = 0;
  }
  
  //input
  for(i = 0; i < treenum; i++){
    scanf("%d", &id);
    T[id].id = id;
    
    for(j = 0; j < 2; j++){
      
      scanf("%d", &T[id].child[j]);
      
      if(T[id].child[j] != NIL){
	T[ T[id].child[j] ].parent = T[id].id;
	T[id].degree++;
      }
      
    }
   
      T[ T[id].child[0] ].sibling = T[id].child[1];
      T[ T[id].child[1] ].sibling = T[id].child[0];
    
  }
  
  //root search
  for(i = 0; i < treenum; i++){
    if(T[i].parent == NIL){
      break;
    }
  }
  
  depthcalculation(i, 0);
  heightcalculation(treenum);
  T[i].height = maxdepth;
  
  //output
  for(i = 0; i < treenum; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, ", T[i].id, T[i].parent, T[i].sibling, T[i].degree);

    printf("depth = %d, height = %d, ",T[i].depth, T[i].height);
    
    if(T[i].parent == -1){
      printf("root\n");
    }
    else if(T[i].degree == 0){
      printf("leaf\n");
    }
    else{
      printf("internal node\n");
    }
  }
  
  return 0;
}

void depthcalculation(int t, int d){
  int i;

  T[t].depth = d;
  
  if(maxdepth < d){
    maxdepth = d;
  }
  
  for(i = 0; i < 2; i++){
    if(T[t].child[i] != NIL){
    depthcalculation(T[t].child[i], d+1);
    }
  }
  
}

void heightcalculation(int treenum){
  int i, h, id;

  for(i = 0; i < treenum; i++){
    if(T[i].degree == 0){
      h = 0;
      id = T[i].id;
      T[i].height = 0;
      
      while(1){
	id = T[id].parent;
	if(id == NIL){
	  break;
	}
	h++;

	if(T[id].height < h){
	  T[id].height = h;
	}
      }
      
    }
  }
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
void _read();
const int nax = 2e5 + 11;
struct fenwick {
      vector<int> ft;
      int n;
      fenwick() { ft = vector<int>(nax); n = nax; }; 
      void update( int idx, int p ) {
            for(; idx < nax - 3; idx += idx&-idx) {
                  ft[idx] = max(ft[idx],p);
            }
      };
      int qry( int idx ) {
            int res = 0;
            for( --idx ; idx > 0 ; idx -= idx&-idx) {
                  res = max(res,ft[idx]);
            }
            return res;
      };
} ft;
main () { _read(); 

      int n, best = 0;
      cin >> n;
      vector<int> h(n);
      for( int &x : h ) cin >> x;
      for( int i = 0; i < n; ++i ) {
            int x; cin >> x;
            int curr = x + ft.qry(h[i]);
            best = max(best,curr);
            ft.update(h[i],curr);
      }
      cout << best << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


Measured memory_bytes: 6340
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

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

    set<string> st;
    REP(i,s.length()){
        FOR(j,1,20){
            if (i + j > s.length()) break;
            st.insert(s.substr(i, j));
        }
    }

    for (string t : st){
        k--;
        if (k == 0){
            cout << t << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 9088
N,K=map(int,input().split())
p = list(map(int,input().split()))

ruisekiwa=[0]

for i in range(N):
    ruisekiwa.append(ruisekiwa[i]+(1+p[i])/2)

max_value=0
for i in range(N-K+1):
    tmp=ruisekiwa[i+K]- ruisekiwa[i]
    if(max_value < tmp):
        max_value=tmp
print(max_value)

Measured memory_bytes: 25060
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    H, N = map(int, input().split())
    A = list(map(int, input().split()))

    if sum(A) >= H:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

typedef std::map <int, int> map;
const int N = 200054;

int n, a[N];
map M;

inline bool check(int B) {
	int i, L = a[1]; bool result;
	map::iterator it; M.clear();
	for (i = 2; i <= n; ++i) if (a[i] <= L) {
		for (L = a[i]; !M.empty(); )
			if (it = --M.end(), it->first >= L) M.erase(it);
			else if (it->first == L - 1 && it->second == B - 1) M.erase(it), --L;
			else break;
		if (!L) return false;
		std::tie(it, result) = M.emplace(L - 1, 1);
		if (!result) ++it->second;
	} else L = a[i];
	return true;
}

int main() {
	int i, L, R, M; bool incr = true;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) if (scanf("%d", a + i), a[i] <= a[i - 1]) incr = false;
	if (incr) return putchar(49), putchar(10), 0;
	for (L = 2, R = n; L < R; check(M = (L + R) / 2) ? R = M : L = M + 1);
	printf("%d\n", L);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n, d[4];
    while(cin >> n){
        if(n == 0)  break;
        if(n % 1111 == 0){
            cout << "NA" << endl;
        }else{
            int tmpn = n;
            for(int i = 3; i >= 0; i--){
                d[i] = tmpn%10;
                tmpn /= 10;
            }
            
            int ans = 0;
            while(n != 6174){
                ans++;
                sort(d, d+4);
                n = (1000*d[3] + 100*d[2] + 10*d[1] + d[0]) -
                        (1000*d[0] + 100*d[1] + 10*d[2] + d[3]);
                tmpn = n;
                for(int i = 3; i >= 0; i--){
                    d[i] = tmpn%10;
                    tmpn /= 10;
                }
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

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

  if (K > (N-1)*(N-2)/2) {
    cout << -1 << endl;
    return 0;
  }

  vector<vector<int>> ans(N);

  for (int i = 1; i < N; i++) {
    ans[0].push_back(i+1);
  }

  int now = (N-1)*(N-2)/2;
  int id = 1;
  while (now > K) {
    int cnt = ans[id].size();
    ans[id].push_back(cnt+id+2);
    now--;
    if ((cnt+1) == (N-id-1)) id++;
  }
  
  int cntE = 0;
  rep(i, N) {
    cntE += ans[i].size();
  }
  cout << cntE << endl;

  rep(i, N) {
    for (auto x : ans[i]) {
      cout << (i+1) << " " << x << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = map(int, input().split())
P = list(map(int, input().split()))
PP = sorted(P)
count = 0
for n, p in enumerate(P):
    if p != PP[n]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#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 llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef pair<ll,int> LL_IP;

#define ARRAY_MAX 100005


int main(){

    int n,t;
    cin >> n >> t;
    vector<int> l(ARRAY_MAX,0),r(ARRAY_MAX,0);
    vector<int> imos(ARRAY_MAX,0);

    REP(i,n){
        cin >> l[i] >> r[i];
        imos[l[i]]++;
        imos[r[i]]--;
    }

    REP(i,t){
        imos[i+1] += imos[i];
    }

    /*REP(i,t+1){
        cout << imos[i] << " ";
    }
    cout << endl;*/


    int maxi = -1;
    REP(i,t+1){
        maxi = max(maxi,imos[i]);
    }
    cout << maxi << endl;


    return 0;
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int n, q;
	set<int> ss;
	int ans = 0;

	cin >> n;
	for (int i = 0; i < n; i++){
		int s;
		cin >> s;
		ss.insert(s);
	}
	cin >> q;
	for (int i = 0; i < q; i++){
		int t;
		cin >> t;
		if (ss.find(t) != ss.end())
			ans++;
	}

	cout << ans << endl;

	return 0;
}



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

using namespace std;
struct UnionFind{
	vector<long long>data;
	UnionFind(long long sz){
		data.assign(sz,-1);
	}
	bool unite(long long x,long long y){
		x=find(x),y=find(y);
		if(x==y)return (false);
		if(data[x]>data[y])swap(x,y);
		data[x]+=data[y];
		data[y]=x;return (true); 
	}
	long long find(long long k){
    	if(data[k]<0)return (k);
		return (data[k]=find(data[k]));
	}
	long long size(int k){
    	return (-data[find(k)]);
	}
};
int main(){
	long long n,m,A[100005],B[100005];
	cin>>n>>m;
	UnionFind uf(n);
	for(long long i=0;i<m;i++) {
    	cin>>A[i]>>B[i];
    	--A[i],--B[i];
	}	
	long long ret=0;
	vector<long long>ans(m);
	for(int i=0;i<m;i++)ans[i]=0;
	for(long long i=m-1;i>=0;i--) {
    	ans[i]=1LL*n*(n-1)/2-ret;
    	if(uf.find(A[i])!=uf.find(B[i])) {
    		ret+=1LL*uf.size(A[i])*uf.size(B[i]);
    		uf.unite(A[i],B[i]);
    	}
	}
	for(long long p=0;p<ans.size();p++)cout<<ans[p]<<endl;
	return 0;
}

Measured memory_bytes: 4480
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

const int N = 5e5 + 5;

template <typename T> inline void Read(T &x) {
  x = 0; char ch;
  while (!isdigit(ch = getchar()));
  do {x = (x << 1) + (x << 3) + ch - '0';} while (isdigit(ch = getchar()));
}

int arr[N], pos[N], cant[N];

int main() {
  int n, d, q, x;
  Read(n); Read(d);
  for (int i = 1; i <= n; i ++) {
    Read(arr[i]);
    if (pos[i - 1] <= d) {
      if (abs(pos[i - 1] + arr[i] - d) < abs(pos[i - 1] - d))
	pos[i] = pos[i - 1] + arr[i];
      else pos[i] = pos[i - 1];
    }
    else {
      if (abs(pos[i - 1] - arr[i] - d) < abs(pos[i - 1] - d))
	pos[i] = pos[i - 1] - arr[i];
      else pos[i] = pos[i - 1];
    }
  }
  cant[n + 1] = 1;
  for (int i = n; i >= 1; i --) {
    if (arr[i] >= cant[i + 1] * 2) cant[i] = cant[i + 1];
    else cant[i] = cant[i + 1] + arr[i];
  }
  // for (int i = 1; i <= n; i ++) cout << cant[i] << " " ;puts("");
  Read(q);
  while (q --) {
    Read(x);
    if (abs(pos[x - 1] - d) >= cant[x + 1]) puts("YES");
    else puts("NO");
  }
  return 0;
}


Measured memory_bytes: 7808
#include<stdio.h>
long long a[100005];
int main()
{
	long N,i;
	long long x,a[100005],sum,t;
	while(~scanf("%d%d",&N,&x))
	{
		sum=0;
		for(i=0;i<N;i++)
		scanf("%lld",&a[i]);
		for(i=0;i<N-1;i++)
		if(a[i]+a[i+1]>x)
		{
			t=a[i]+a[i+1]-x;
			sum+=t;
			a[i+1]-=t;
			if(a[i+1]<0) a[i+1]=0;
		}
		printf("%lld\n",sum);
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll a, b;
  cin >> a >> b;

  if ((a + b) % 2) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (a + b) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    s = SI()

    W = [0]
    B = [0]
    for c in s:
        b = c == '#'
        w = c == '.'
        B.append(B[-1] + b)
        W.append(W[-1] + w)

    res = n - max(B[-1], W[-1])
    for i in range(n - 1):
        res = min(res, B[i] + W[-1] - W[i + 1])

    return res


print(main())


Measured memory_bytes: 19556
import java.util.Arrays;
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[] a = new int[n];
        int[] c = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
            c[i] = a[i] -(i+1);
        }
        
        Arrays.sort(c);
        int b;
        if(n%2 == 0){
            b = (c[n/2 -1] + c[n/2]) /2;
        }else{
            b = c[n/2];
        }
        
        long ans = 0;
        for(int i = 0; i < n; i++){
            ans += Math.abs(a[i] - (b+i+1));
        }
        
        System.out.println(ans);
    }
}

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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

vector<vector<int>> g(100010);
vector<int> c(100010,0);

void dfs(int i) {
  if (c[i]==1) return;
  c[i] = 1;
  for (auto& t: g[i]) {
    dfs(t);
  }
}

void solve()
{
  int n,m; cin>>n>>m;
  for (int i=0; i<m; i++) {
    int x,y,z; cin>>x>>y>>z;
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
  }
  int ans = 0;
  for (int i=0; i<n; i++) {
    if (c[i]==0) {
      dfs(i);
      ans++;
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 9216
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll H,W,h,w,sum; cin>>H>>W>>h>>w;
    if(h==1 && w==1){
        printf("No\n");
        return 0;
    }
    ll d=999999999LL/(h*w-1);
    vector<vector<ll>> ans(H,vector<ll>(W,d));
    sum=H*W*d;
    for(int i=h-1;i<H;i+=h)for(int j=w-1;j<W;j+=w){
        sum-=d+(h*w-1)*d+1; ans[i][j]=-(h*w-1)*d-1;
    }
    if(sum>0){
        printf("Yes\n");
        rep(i,H){
            rep(j,W) printf("%lld ",ans[i][j]);
            printf("\n");
        }
    }
    else printf("No\n");
}


Measured memory_bytes: 5656
s = [int(x) for x in input()]
insert_operator_number = len(s) - 1

for iter_op in range(1 << insert_operator_number):
  result_sum = s[0]
  result_string = ""
  for i in range(insert_operator_number):
    if (iter_op & (1 << i)):
      result_sum += s[i+1]
      result_string += "{}+".format(s[i])
    else:
      result_sum -= s[i+1]
      result_string += "{}-".format(s[i])
    
  if result_sum == 7:
    break

print("{}{}=7".format(result_string,s[-1]))

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

int main(){
 long long n;
 long long H;
 long long W;
  cin>>n>>H>>W;
  long long cuttable=0;

  for(int a=0;a<n;a++){
    long long A,B;
   cin>>A>> B;
    if(A>=H&&B>=W){
cuttable++;

    }
  }
  cout<<cuttable;
  return 0;
}

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

map <pair <string, string>, int> mp;
long long ans;

void solve(string s, bool add)
{
    for (int mask = 0; mask < (1 << s.size()); mask++) {
        string a, b;
        for (int i = 0; i < s.size(); i++) {
            if (mask & (1 << i))
                a.push_back(s[i]);
            else
                b.push_back(s[i]);
        }

        if (add)
            mp[{ a, b }]++;
        else
            ans += mp[{ a, b }];
    }
}

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

    string s1 = s.substr(0, n), s2 = s.substr(n, n);

    reverse(s2.begin(), s2.end());

    solve(s1, 1);
    solve(s2, 0);

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


Measured memory_bytes: 91904
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace
import Data.List (sort)

main = do
  [n,k] <- getInts
  xs <- reverse . sort <$> getInts
  print . sum $ take k xs

-- util
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine


Measured memory_bytes: 508
# include <stdio.h>
//# include <iostream>
//# include <cstdio>
//# include <conio.h>

//using namespace std;

const int N = 100100;

//int n, a [N], i, j, k;

int main ()
{
   int n, a [N], i, j, k;

   scanf ("%d", &n);
   
   for ( i=1; i <= n; i++ )
      scanf ("%d", &a [i]);

   for ( i=1; i <= n; i++ )
   {
      j = a [i];
      if ( a [j] == i )
         k++;
   }

   printf ("%d", k/2);

//getch();
   return 0;
}


Measured memory_bytes: 640
n=int(input())
ans=''
check='abcdefghijklmnopqrstuvwxyz' #c(a)-1=0,c(b)-1=1,…,c(z)-1=25を対応づける文字列
while n!=0:
 n-=1
 ans+=check[n%26] #(n-1)%26がc(Sk)-1を表すので、上記の文字列を用いてc(Sk)-1からSkを求める
 n//=26
print(ans[::-1])

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

int n,k;
int a[N];
int dp[N][2];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    cin >> n >> k;
    REP(i,0,n-1) cin >> a[i];

    // dp[k][p] = the player who wins if there are k stones and p starts

    REP(i,0,k)
    {
        dp[i][0] = 1;
        REP(j,0,n-1)
        {
            if (i-a[j] >= 0) dp[i][0] = min(dp[i][0],dp[i-a[j]][1]);
        }

        dp[i][1] = 0;
        REP(j,0,n-1)
        {
            if (i-a[j] >= 0) dp[i][1] = max(dp[i][1],dp[i-a[j]][0]);
        }
    }

    if (dp[k][1]) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}


Measured memory_bytes: 1024
// AOJ 2076 Flame of Nucleus
// 2018.3.10 bal4u

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

/*******************************************/
/* Dinic's Max Flow Algorithm 
/*******************************************/

#define INF 0x01010101
#define VMAX 205
typedef struct { int to; int cap; int rev; } EDGE;
EDGE edge[VMAX][VMAX]; int hi[VMAX];
int V;				// 頂点数
int level[VMAX], iter[VMAX];
int queue[VMAX], qtop;

void add_edge(int from, int to, int cap)
{
	int f, t;
	EDGE *e;

	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = cap, e->rev = t; 
	e = &edge[to][t], e->to = from, e->cap = 0, e->rev = f;
}

void bfs(int s)
{
	int i, v;
	EDGE *e;
	
	memset(level, -1, V << 2);
	level[s] = 0;
	queue[0] = s, qtop =1;
	while (qtop) {
		v = queue[--qtop];
		for (i = 0; i < hi[v]; i++) {
			e = &edge[v][i];
			if (e->cap > 0 && level[e->to] < 0) {
				level[e->to] = level[v] + 1;
				queue[qtop++] = e->to;
			}
		}
	}
}
 
int dfs(int v, int t, int f)
{
	int *i, d;
	EDGE *e;
	
	if (v == t) return f;
	for (i = &iter[v]; *i < hi[v]; (*i)++) {
		e = &edge[v][*i];
		if (e->cap > 0 && level[v] < level[e->to]) {
			d = dfs(e->to, t, f <= e->cap? f: e->cap);
			if (d > 0) {
				e->cap -= d;
				edge[e->to][e->rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
 
int maxFlow(int s, int t)
{
	int f, flow = 0;
	while (1) {
		bfs(s);
		if (level[t] < 0) break;
		memset(iter, 0, V << 2);
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
	return flow;
}

/**********************************************/

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == EOF) return 0;
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int D[101][101];
int P[101];
int K[101];

int main()
{
	int N, M, L, i, j, k, a, b, d;
	int source, sink;

	while (N = in()) {
		M = in(), L = in();

		memset(D, INF, sizeof(D));
		for (i = 0; i < N; i++) D[i][i] = 0;
		for (i = 0; i < M; i++) {
			a = in()-1, b = in()-1, d = in();
			D[a][b] = D[b][a] = d;
		}
		for (k = 0; k < N; k++) {
			for (i = 0; i < N; i++) if (D[i][k] != INF) {
				for (j = 0; j < N; j++) if (D[k][j] != INF) {
					d = D[i][k] + D[k][j];
					if (D[i][j] > d) D[i][j] = d;
				}
			}
		}
		for (i = 0; i < N; i++) P[i] = in();
		for (i = 0; i < N; i++) K[i] = in();

		source = N << 1, sink = source+1, V = sink+1;
		memset(hi, 0, V << 2);

		for (i = 0; i < N; i++) {
			add_edge(source, i, P[i]);
			for (j = 0; j < N; j++) if (D[i][j] < L) add_edge(i, N+j, INF);
			add_edge(N+i, sink, K[i]);
		}
		
		printf("%d\n", maxFlow(source, sink));
	}
	return 0;
}


Measured memory_bytes: 2388
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T> 
void print(vector<T> &x) {
    int n = x.size();
    REP(i,n) {
        if (i != n-1) cout << x[i] << " ";
        else cout << x[i] << endl;
    }
}

int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n), accum_k(n+1), accum_p(n+1);
    REP(i,n) cin >> a[i];

    for (int i = 0; i < n; ++i) {
        accum_k[i+1] = accum_k[i]+a[i];
        accum_p[i+1] = accum_p[i]+max(a[i],0ll);
    }

    ll ans = 0ll;

    for (int i = k; i <= n; ++i) {
        ll tmp1 = 0;
        // printf("i = %d accum_k[i] = %lld accum_k[i-k] = %lld\n", i,accum_k[i],accum_k[i-k]);
        // printf("i = %d accum_p[i-1] = %lld accum_p[0] = %lld accum_p[n] = %lld accum_p[k] = %lld\n", i,accum_p[i-1],accum_p[0], accum_p[n], accum_p[k]);
        tmp1 += accum_k[i]-accum_k[i-k];
        tmp1 += accum_p[i-k]-accum_p[0];
        tmp1 += accum_p[n]-accum_p[i];
        ll tmp2 = 0;
        tmp2 += accum_p[i-k]-accum_p[0];
        tmp2 += accum_p[n]-accum_p[i];
        ans = max(ans, max(tmp1, tmp2));
    }

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

Measured memory_bytes: 2560
#include <iostream>

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

  int n = s.length();
  int res = 0;
  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[n - i - 1]) {
      res += 1;
    }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String S = in.nextLine();
      String str1 = new String(S);
          if(Character.isUpperCase(str1.charAt( 0 ))){
            String T = str1.toLowerCase();
            System.out.println("A");
          }
         else {String T = str1.toUpperCase();
           System.out.println("a");
                }
        }
    }

Measured memory_bytes: 35732
#include <iostream>

using namespace std;
int main(){
	long long int a,n,m,ans;
	cin >> n;
	cin >> m;

	if(m/2<n){
		ans=m/2;
	}
	if(m/2>=n){
		a=m-n*2;
		ans=a/4+n;
	}

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

Measured memory_bytes: 256
n = int(input())
list = []
for i in range(n):
    num = input().split()
    num.append(i+1)
    list.append(num)
    list[i][1] = int(list[i][1])

tmp = sorted(list, key=lambda x:x[1], reverse=True)
new_list = sorted(tmp, key=lambda x:x[0])

for i in range(n):
    print(new_list[i][2])


Measured memory_bytes: 3060
s = input()
a = list()
a.append('Q')

for i in range(len(s)):
    ch = s[i]
    if(ch == 'T' and a[len(a)-1]=='S'):
        a.pop()
    else:
        a.append(ch)
        
s = ""
s = s.join(a)

print(len(s)-1)

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

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

using namespace std;
using ll = long long;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> vec(n);
  rep(i, n) {
    cin >> vec[i].first >> vec[i].second;
  }
  sort(vec.begin(), vec.end());
  ll ans = 0;
  int i = 0;
  while (m > 0) {
    ans += vec[i].first * vec[i].second;
    m -= vec[i].second;
    i++;
  }
  while (m != 0) {
    ans -= vec[i - 1].first;
    m += 1;
  }
  cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1792