akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int a, b;
    cin >> a >> b;
    if (a + b >= 10) {
        cout << "error" << '\n';
    } else {
        cout << a + b << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = (int) 1e5 + 10;
const int MOD = (int) 1e9 + 7;

ll dp[Maxn][4];

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

    string s;
    cin >> s;
    int n = (int) s.size();
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            if (s[i] == '?') {
                (dp[i + 1][j] += 3 * dp[i][j]) %= MOD;
            } else {
                (dp[i + 1][j] += dp[i][j]) %= MOD;
            }
        }
        if (s[i] == 'A' || s[i] == '?') {
            (dp[i + 1][1] += dp[i][0]) %= MOD;
        }
        if (s[i] == 'B' || s[i] == '?') {
            (dp[i + 1][2] += dp[i][1]) %= MOD;
        }
        if (s[i] == 'C' || s[i] == '?') {
            (dp[i + 1][3] += dp[i][2]) %= MOD;
        }
    }

    cout << dp[n][3] << endl;
}


Measured memory_bytes: 3664
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
local f = true
for i = 1, n do
  if t[i] % 2 == 0 then
    if t[i] % 3 ~= 0 and t[i] % 5 ~= 0 then
      f = false
      break
    end
  end
end
print(f and "APPROVED" or "DENIED")


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    }

    private static long dp(int n, int[] h, int i, long[] memo) {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    }

}


Measured memory_bytes: 67424
n=int(input())
l=[1]
for i in [6,9]:
    x=i
    while x<=n:
        l.append(x)
        x*=i
dp=[10**9]*(n+1)
dp[0]=0
for x in l:
    for i in range(n):
        if i+x<=n:dp[i+x]=min(dp[i+x],dp[i]+1)
print(dp[n])



Measured memory_bytes: 6980
#include<stdio.h>

int linearSearch(int A[],int n, int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key) i++;
  return (n!=i);
}

int main(){
  int i,n,A[10001],q,key,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(linearSearch(A,n,key))sum++;
  }
  printf("%d\n",sum);
  
  return 0;
}



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

using namespace std;
typedef long long ll;

bool f[100001];
int c[100002];

int main() {
  for (int i=2; i<=100000; i++) {
    if (!f[i]) {
      for (int j=i+i; j<=100000; j+=i)
        f[j] = true;
    }
  }

  for (int i=3; i<=100000; i+=2) {
    if (!f[i] && !f[(i+1)/2])
      c[i]++;
  }
  for (int i=3; i<=100000; i++)
    c[i] += c[i-1];

  int q;
  scanf("%d", &q);
  for (int i=0; i<q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", c[r]-c[l-1]);
  }
}


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

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  double theta;
  if(x < a*b/2){
    theta = atan(b*b/2/x);
  }else{
    theta = asin(1) - atan(a*a/2/(a*b-x));
  }
  theta *= 180.0/acos(-1);
  printf("%.12f\n",theta);
}


Measured memory_bytes: 384
while 1:
  H , W = map( int , raw_input().split() )
  if H == W == 0:
    break
  print '#' * W
  for i in range(H-2):
    if W>=2:
      print '#' + '.' * (W-2) + '#'
    else :
      print '#'
  print '#' * W
  print''

Measured memory_bytes: 6428
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,a[N],num,od,ev,op;
int gcd(int x,int y){ return x ? gcd(y%x,x) : y;}
void GG(int t){ printf(t ? "Second" : "First"); exit(0);} 
int main()
{
	int i,p,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(n==1) GG(1);
	while(1){
		od=ev=0;
		for(i=1;i<=n;i++)
			if(a[i]&1) od++,p=i;
			else ev++;
		if(ev&1) GG(op);
		if(od>=2) GG(op^1);
		if(a[p]==1) GG(op^1);
		a[p]--,k=a[1],op^=1;
		for(i=2;i<=n;i++) k=gcd(k,a[i]);
		for(i=1;i<=n;i++) a[i]/=k;
	  }
	GG(op);
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineStringSplit();
            var result = "";

            //Atcoderくんが正直の場合
            if(n[0] == "H") {
                result = n[1];
            }
            //Atcoderくんが嘘つきの場合
            else if(n[0] == "D") {
                result = (n[1] == "H") ? "D": "H";
            }

            Console.WriteLine(result);
            ReadLine();
        }

        /// <summary>
        /// コンビネーション
        /// </summary>
        /// <param name="n"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }

        static string[] GetAplhaLowerArray() => new string[]{ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 11220
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#endif
using namespace std;

int a[500005];

struct Query {
  int l, r, id, ans;
};

// freqcnt
int freq[500005];
int distinct = 0;
void freqadd(int x) { 
//write("FA", x, freq[x], "->", freq[x]+1);
  if (!freq[x]) distinct++; freq[x]++; }
void freqrem(int x) { 
  
//write("FR", x, freq[x], "->", freq[x]-1);
  freq[x]--; if (!freq[x]) distinct--; }
Query query[500005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, q; read(n, q);
  rep(i, 1, n + 1) read(a[i]);
  rep(i, 0, q) read(query[i].l, query[i].r), query[i].id = i;
  
  const int BS = 3000;
  sort(query, query + q, [](const Query& a, const Query& b) {
    if (a.l / BS != b.l / BS) return a.l / BS < b.l / BS;
    else return a.r < b.r;
    });

  // inclusive [cl, cr]
  int cl = 1, cr = 0;
  rep(i, 0, q) {
    int nl = query[i].l, nr = query[i].r;
    while (cl > nl) freqadd(a[--cl]);
    while (cr < nr) freqadd(a[++cr]);
    while (cl < nl) freqrem(a[cl++]);
    while (cr > nr) freqrem(a[cr--]);
    query[i].ans = distinct;
  }

  sort(query, query + q, [](const Query& a, const Query& b) { return a.id < b.id; });
  rep(i, 0, q) write(query[i].ans);
}



Measured memory_bytes: 15488
def insert(dic,text):
  dic[text] = 1

def find(dic,text):
  if text in dic:
    print('yes')
  else:
    print('no')
    
num = int(input())
d = {}
while num > 0:
  ope , s = input().split()
  if ope == 'insert':
    insert(d,s)
  elif ope == 'find':
    find(d,s)  
  num -= 1


Measured memory_bytes: 33116
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    //入力値
    int x = sc.nextInt();
    //int count = 0;
    //買える個数
    int buy = x/100;
    //端数
    int rmd = x%100;
    
    //買い物してみる
    for(int i = 0 ; i<buy ; ++i){
      if(rmd>=5){
        rmd -=5;
      }else if(rmd>=4){
        rmd -=4;
      }else if(rmd>=3){
        rmd -=3;
      }else if(rmd>=2){
        rmd -=2;
      }else if(rmd>=1){
        rmd -=1;
      }
    }
    
    if(rmd==0){
      System.out.println(1);
    }else{
      System.out.println(0);
    }

  }
}

Measured memory_bytes: 35648
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

bool isPrime(int num){
  bool flag=true;
  for(int i = 2; i <= num / 2; i++) {
    if(num % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
int main() {
  int x;
  cin >> x;
  while(true) {
      if(isPrime(x)) { cout << x << endl; return 0; }
      x++;
  }
}

Measured memory_bytes: 256
N, K = [int(_) for _ in input().split()]
import math
MOD = 10**9+7

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
    try:
        print( (combinations_count(K-1,i-1)*combinations_count(N-K+1,i))%MOD )
    except:
        print(0)
        

Measured memory_bytes: 3316
import Data.List
main = do
  getLine
  as <- map read . words <$> getLine
  let bs = sort . map t $ as
  let c = length $ [b | b <- bs, b < 0]
  let d = length . nub $ [b | b <- bs, b >= 0]
  putStr . show $ o1 c d
  putStr " "
  putStr . show $ o2 c d
 
t :: Int -> Int
t  x
  | x >= 3200 = -1
  | otherwise = div x 400
 
o1 0 0 = 0
o1 _ 0 = 1
o1 _ d = d
 
o2 c d = c + d

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	string s;cin>>s;
	vector<int> t(1); t[0] = 1;
	rep(i,1,s.size()){
		if(s[i] == s[i-1]) t.back()++;
		else t.push_back(1);
	}cout<<t.size() - 1<<endl;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    string s;
    cin>>s;
    ll ans=0,p=0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='R')
            ans++;
        else
            ans=0;
        p=max(p,ans);
    }
    cout<<p;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll 1000000000000000000
using namespace std;
int main(void){
    
    int n;
    unsigned long long int ans = 1;
    cin >> n;
    unsigned long long int a[n];
    int b=0;
    
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]==0) b = 1;
    }
    
    if(b==1) {
        cout << 0 << endl;
        return 0;
    }
    
    for(int i=0;i<n;i++) {
        
        
        if(a[i] > ll/ans) {
            cout << -1 << endl;
            return 0;
        }
        
        ans *= a[i];
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4420
/**   Created by: Humberto Yusta
          Codeforces User: humbertoyusta
          Country: Cuba
          Copyright��                    */
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = (((1ll<<59ll)-1ll)*2ll)+1ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return pwur * pwur % mod;
}
/// My Code -------------------------------------------------

int arr[maxn], n, m, sum, ans;

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);

    cin >> n >> m;

    cout << min( n % m , m - n % m ) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    ll n,a; cin >> n >> a;
    cout << n*n-a << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    string s;
    cin >> s;
    rep(i,0,s.size()){
        if(s[i]!=',') cout << s[i];
        else cout << " " ;    
    }
    cout << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define itrep(type, it, t) for(type::iterator it=t.begin(); it!=t.end(); it++)
using namespace std;


int main(void) {

    int N;
    cin >> N;
    map<string, int> m;
    int mx = 0;
    rep(i, N) {
        string s;
        cin >> s;
        m[s]++;
        mx = max(mx, m[s]);
    }
    // sort(m.begin(), m.end());
    for(map<string, int>::iterator it=m.begin(); it!=m.end(); it++) {
        if(it->second == mx) {
            cout << it->first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
#include<stdio.h>
int main()
{
   char op;
   int a,b;
   scanf("%d %c %d",&a,&op,&b);
   if(op=='+')
     printf("%d\n",a+b);
   else if(op=='-')
    printf("%d\n",a-b);
   return 0;
}


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

int main()
{
    int x,y,t;
    while(1)
    {
        cin >> x >> y;
        if(x==0 && y==0)
        {
            break;
        }
        if(x>y)
        {
            t=y;
            y=x;
            x=t;
        }
        cout << x << " " << y << endl;
    }
}


Measured memory_bytes: 3084
#include <stdio.h>
#include <math.h>

int main(){
  double x1, y1, x2, y2;
  double distance;

  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  distance=sqrt(pow(x1-x2, 2.0)+pow(y1-y2, 2.0));

  printf("%8f\n", distance);

  return 0;
}

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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if((s[i]+n)<=90)
            cout<<(char)(s[i]+n);
        else
            cout<<(char)((s[i]+n)-26);
    }
}


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

#define _   int v, int tl, int tr, int l, int r
#define tm  (tl + tr >> 1)
#define sol v+v, tl, tm, l, r
#define sag v+v+1, tm+1, tr, l, r

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 1e5 + 5;    

int mx[N<<2],mn[N<<2],A[N],P[N],X,n;
pp nex[2][N][20];

int qry(_){
    if(tl > r || tr < l) return -mod;
    if(tl >= l && tr <= r) return mx[v];
    return max( qry(sol) , qry(sag) );
}
int qry2(_){
    if(tl > r || tr < l) return mod;
    if(tl >= l && tr <= r) return mn[v];
    return min( qry2(sol) , qry2(sag) );
}

int bld(_){
    if(tl == tr) return mn[v] = mx[v] = P[tl];
    mx[v] = max(bld(sol) , bld(sag));
    mn[v] = min(mn[v+v] , mn[v+v+1]);
    return mx[v];
}

pp f(int i, int l, int r, int a){
    for(; l < r ;){
        int m = l + r >> 1;
        if(a + qry(1,0,n+1,i+1,m) - P[i] >= X || a + qry2(1,0,n+1,i+1,m) - P[i] <= 0) r = m;
        else l = m+1;
    }
    if(a + P[l] - P[i] >= X) return mp(l,1);
    else return mp(l,0);
}

signed main(){  
    cin >> X >> n;
    for(int i=1; i<=n+1; i++){
        int x;
        if(i <= n) scanf("%d",&x);
        else x = mod+mod;
        A[i] = x;
        P[i] = P[i-1] + (i & 1 ? -1 : 1) * (x - A[i-1]);
    }

    bld(1,0,n+1,0,0);
    for(int i=0; i<=n; i++){
        nex[0][i][0] = f(i,i+1,n+1,0);
        nex[1][i][0] = f(i,i+1,n+1,X);
    }
    
    
    for(int j=0; j<20; j++){
        nex[0][n+1][j] = mp(n+1,0);
        nex[1][n+1][j] = mp(n+1,1);
    }
    
    for(int j=1; j<20; j++)
        for(int i=0; i<=n; i++)
            for(int h=0; h<=1; h++)
            	nex[h][i][j] = 	nex[ nex[h][i][j-1].nd ][ nex[h][i][j-1].st ][j-1];
            
    int q;
    cin >> q;
    for(; q-- ;){
        int t,a;
        scanf("%d%d",&t,&a);
		pp tt = f(0,1,n+1,a);
        int i = tt.st;
        int h = tt.nd;
		int end = lower_bound(A+1 , A+n+1 , t) - A;
        
        if(i >= end){
            int ans = a + P[end-1] + (end&1 ? -1 : 1) * (t-A[end-1]);
            printf("%d\n", max(0,min(ans,X)));
        	continue;
        }
        
        for(int j=19; j>=0; j--)
        	if(nex[h][i][j].st < end){
                tt = nex[h][i][j];
                i = tt.st;
                h = tt.nd;
            }
	
        int ans = (h ? X : 0) + P[end-1] - P[i] + (end&1 ? -1 : 1) * (t-A[end-1]);
        printf("%d\n", max(0,min(ans,X)));
    }
                                  
    return 0;
}

Measured memory_bytes: 35968
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
  int n,area[4];
  ll h;
  
  cin >> n;
  vector<ll> hs;
  ull ans = 0;
  area[0] = area[1] = area[2] = area[3] = 0;
  for(int i=0;i<n;i++){
    cin >> h;
    hs.push_back(h);
  }
  sort(hs.begin(),hs.end(),greater<ll>() );
  for(int i=0;i<n;i++){
    int pos = i%4;
    ans += hs[i]-area[pos]>=0?hs[i]-area[pos]:0;
    area[pos]++;
  }
  cout << ans+1 << endl;

return 0;
}

Measured memory_bytes: 1228
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int parent[100001];
ll c[100001];

int fin(int node)
{
    vector<int> hist;
    int cur = node;
    while(parent[cur] != cur)
    {
        hist.push_back(cur);
        cur = parent[cur];
    }

    for(int x: hist)
    {
        parent[x] = cur;
    }

    return cur;
}

ll uni(int a, int b)
{
    int root_a = fin(a);
    int root_b = fin(b);
    
    if(root_a == root_b)
    {
        return 0;
    }

    ll count_a = c[root_a];
    ll count_b = c[root_b];

    parent[root_a] = root_b;
    c[root_b] = count_a + count_b;
    return count_a * count_b;
}

int main(){
    std::ios::sync_with_stdio(false);
    ll n, m, a, b;
    cin >> n >> m;
    vector<pair<int, int>> edges;
    fill(c, c + 100001, 1);
    for(int i=0;i<m;++i)
    {
        cin >> a >> b;
        edges.push_back(MP(a, b));
    }
    for(int i=0;i<n;++i)
    {
        parent[i] = i;
    }

    ll ret = n * (n - 1) / 2;
    vector<ll> ret_vec;
    ret_vec.push_back(ret);
    for(int i=m-1;i>=0;--i)
    {
        ll diff = uni(edges[i].first, edges[i].second);
        ret -= diff;
        ret_vec.push_back(ret);
    }

    assert(ret == 0);

    for(int i=0;i<m;++i)
    {
        cout << ret_vec[m-1-i] << endl;
    }
}

Measured memory_bytes: 4212
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	long long x,y,t,s=0;
	scanf("%lld %lld",&x,&y);
	t=x;s=1;
	//printf("**  %lld\n",t);
	while(t<=y)
	{
		t=t*2;//printf("**  %lld\n",t);
		if(t<=y)s++;
	}
	printf("%lld\n",s);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 3100
using namespace std;

void pr(ll *x,ll y){
    *x=*x*y%MOD;
    return;
}
main(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    vector<int> v;
    rep(i,n){
        if(i+1==n){v.pb(0);break;}
        if(s[i]==s[i+1]){v.pb(1);i++;}
        else v.pb(0);
    }
    ll ans=(v[0]?6:3);
    rep2(i,1,v.size()-1){
        if(v[i]){
            if(v[i-1]) pr(&ans,3);
            else pr(&ans,2);
        }
        else{
            if(v[i-1]==0) pr(&ans,2);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#define maxn 100100
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
struct P{
    int x,y;
}a[maxn],b[maxn*2];
int cnt,res;
bool cmp(P a,P b)
{
    if(a.x!=b.x)  return a.x<b.x;
    return a.y<b.y;
}
bool operator < (P a,P b)
{
    if(a.x!=b.x)  return a.x<b.x;
    return a.y<b.y;
}
int id[maxn*4];
int head[maxn*4],nxt[maxn*40],to[maxn*40],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
void build(int k,int l,int r)
{
    if(l==r)
    {
        id[k]=b[l].y;
        return;
    }
    id[k]=++cnt;
    int mid=(l+r)/2;
    build(k*2,l,mid);
    build(k*2+1,mid+1,r);
    add(id[k],id[k*2]);
    add(id[k],id[k*2+1]);
}
void find(int k,int l,int r,int x,int y,int z)
{
    if(x>y)  return;
    if(l>=x&&r<=y)
    {
        add(z,id[k]);
        return;
    }
    int mid=(l+r)/2;
    if(mid>=x)  find(k*2,l,mid,x,y,z);
    if(mid<y)   find(k*2+1,mid+1,r,x,y,z);
}
void work(int x,int mid,int y,int z)
{
    int L=lower_bound(b+1,b+2*n+1,(P){x-mid+1,0})-b;
    int R=upper_bound(b+1,b+2*n+1,(P){x+mid-1,2*n+1})-b-1;
    int MID=lower_bound(b+1,b+2*n+1,(P){x,y})-b;
    find(1,1,2*n,L,MID-1,z);
    find(1,1,2*n,MID+1,R,z);
}
stack<int>s;
int dfn[maxn*4],low[maxn*4],vis[maxn*4],D;
int cnt_scc,scc[maxn*4];
void tarjan(int x)
{
    dfn[x]=low[x]=++D;
    vis[x]=1;s.push(x);
    for(int i=head[x];i;i=nxt[i])
    {
        if(!dfn[to[i]])
        {
            tarjan(to[i]);
            low[x]=min(low[x],low[to[i]]);
        }
        else if(vis[to[i]])
        {
            low[x]=min(low[x],dfn[to[i]]);
        }
    }
    if(dfn[x]==low[x])
    {
        cnt_scc++;
        int tmp=0;
        while(tmp!=x)
        {
            tmp=s.top();s.pop();
            scc[tmp]=cnt_scc;
            vis[tmp]=0;
        }
    }
}
bool check(int x)
{
    tot=0;cnt=2*n;D=0;cnt_scc=0;
    memset(scc,0,sizeof(scc));
    memset(head,0,sizeof(head));
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    build(1,1,2*n);
    for(int i=1;i<=n;i++)
    {
        work(a[i].x,x,i,i+n);
        work(a[i].y,x,i+n,i);
    }
    for(int i=1;i<=cnt;i++)
      if(!dfn[i])  tarjan(i);
    for(int i=1;i<=n;i++)
      if(scc[i]==scc[i+n])  return false;
    return true;
}
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i].x=read(),a[i].y=read();
    for(int i=1;i<=n;i++)  b[i*2-1].x=a[i].x,b[i*2].x=a[i].y;
    for(int i=1;i<=n;i++)  b[i*2-1].y=i,b[i*2].y=i+n;
    sort(b+1,b+2*n+1,cmp);
    int l=0,r=1000000000;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid))
        {
            res=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 23552
H, W, K = map(int, input().split())
c = []
for i in range(H):
	c.append(input())

Hrange = 2**H
Wrange = 2**W
ans = 0
for h in range(Hrange):
	for w in range(Wrange):
		cnt = 0
		for i in range(H):
			for j in range(W):
				if c[i][j]=='#' and (h>>i)&1 and (w>>j)&1:
					cnt+=1
		if(cnt==K):
			ans+=1

print(ans)

Measured memory_bytes: 9096
n = int(input())
p_list = list(map(int,input().split()))
p_list_s = sorted(p_list)
count = 0
for i in range(len(p_list)):
    if p_list[i] != p_list_s[i]:
        count += 1
if count <= 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 200000
#define int long long
int n, Q, tree[MAXN << 2], tree1[MAXN << 2], tree2[MAXN << 2], tag[MAXN << 2], A, B, a[MAXN];
inline int minx(int a, int b) {int t = b - a; return a + (t & t >> 63);}
inline int maxx(int a, int b) {int t = b - a; return b - (t & t >> 63);}
inline int absx(int x) {int t = x >> 63; return (x + t) ^ t;}
inline void getmin(int & a, int b) {if (a > b) a = b;}
void update (int u) {
	tree1[u] = minx(tree1[u << 1], tree1[u << 1 | 1]);
	tree2[u] = minx(tree2[u << 1], tree2[u << 1 | 1]);
	tree[u] = tree[u] + tree[u << 1 | 1];
}
void pushdown(int u, int sz) {
	if (tag[u]) {
		tag[u << 1] += tag[u];
		tag[u << 1 | 1] += tag[u];
		tree[u << 1] += tag[u] * (sz + 1 >> 1);
		tree[u << 1 | 1] += tag[u] * (sz >> 1);
		tree1[u << 1] += tag[u];
		tree1[u << 1 | 1] += tag[u];
		tree2[u << 1] += tag[u];
		tree2[u << 1 | 1] += tag[u];
		tag[u] = 0;
	}
}
void modify(int u, int l, int r, int tar, int v) { 
	if (l == r) {
		tree[u] = v;
		tree1[u] = v + l;
		tree2[u] = v - l;
		return ;
	}
	pushdown(u, r - l + 1);
	int mid = l + r >> 1;
	if (tar <= mid) modify(u << 1, l, mid, tar, v);
	else modify(u << 1 | 1, mid + 1, r, tar, v);
	update(u);
}
int query(int u, int l, int r, int L, int R, int * tree) {
	if (L > R) return *tree;
	if (L <= l && r <= R) return tree[u];
	int mid = l + r >> 1; int ans = 0x3f3f3f3f3f3f3f3fLL;
	pushdown(u, r - l + 1);
	if (L <= mid) getmin(ans, query(u << 1, l, mid, L, R, tree));
	if (mid < R) getmin(ans, query(u << 1 | 1, mid + 1, r, L, R, tree));
	return ans;
}
int f[1000][1000];
signed main() {
	scanf("%lld%lld%lld%lld", &n, &Q, &A, &B);
	memset(tree, 0x3f, sizeof tree);
	memset(tree1, 0x3f, sizeof tree1);
	memset(tree2, 0x3f, sizeof tree2);
	a[0] = B;
	modify(1, 1, n, A, 0);
	for (int i = 1; i <= Q; ++i) {
		scanf("%lld", &a[i]);
		int tx = minx(	query(1, 1, n, a[i], n, tree1) - a[i],
						query(1, 1, n, 1, a[i] - 1, tree2) + a[i]);
		modify(1, 1, n, a[i - 1], tx);
		tx = absx(a[i] - a[i - 1]);
		modify(1, 1, n, a[i - 1], query(1, 1, n, a[i - 1], a[i - 1], tree) - tx);
		tree[1] += n * tx; tree1[1] += tx; tree2[1] += tx; tag[1] += tx;
	}
	int ans = 0x3f3f3f3f3f3f3f3fLL;
	for (int i = 1; i <= n; ++i) getmin(ans, query(1, 1, n, i, i, tree));
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 28544
#include <iostream>
#include <cctype>
#include <algorithm>
using namespace std;

int main() {
  char x;
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> x;
    if (!isdigit(x)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cin >> x;
  if (x != '-') {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < b; i++) {
    cin >> x;
    if (!isdigit(x)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, m; cin >> n >> m;
	int attempts[n + 1] = {}; 
	int solved[n + 1] = {};
	while (m--) {
		int p;
		string s;
		cin >> p >> s;
		if (s == "AC") solved[p] = 1;
		else if (s == "WA" && !solved[p]){
			attempts[p]++;
		}
	}
	int c = 0, a = 0; 
	for (int i = 0; i < n + 1; i++) {
		c += solved[i];
		if (solved[i]) a += attempts[i];
	}
	cout << c << " " << a; 
}



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

using namespace std;

void printans(int x, int y) {
	for (int i = 1; i <= x; i++)cout << 3 * i << " ";
	for (int i = 1; i <= y; i++) {
		if(i % 2 == 1)cout << ((i - 1) / 2) * 6 + 2;
		else cout << ((i - 1) / 2) * 6 + 4;
		if (i != y)cout << " ";
	}
	cout << endl;
}

int main() {
	int N;
	cin >> N;
	if (N == 3)cout << "2 5 63" << endl;
	else if (N == 4)cout << "2 5 20 63" << endl;
	else {
		if (N % 2 == 1) {
			int a = min(9999, (N / 4 - 1) * 4 + 3);
			int b = N - a;
			printans(a, b);
		}
		else {
			int a = min(10000, ((N - 1) / 4) * 4);
			int b = N - a;
			printans(a, b);
		}
	}
	return 0;
}

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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==5 &&B==7 &&C==5){
    cout<<"YES"<<endl;
  }
  else if (A==5 &&B==5 &&C==7){
    cout<<"YES"<<endl;
  }
  else if (A==7 &&B==5 &&C==5){
    cout<<"YES"<<endl;
  }  
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<map>

using namespace std;

string in;
map<char,string> M;
map<string,char> M_2;

void solve(string in){
  string out = "";

  for(int i = 0; i < in.length(); i++)
    out += M[in[i]];

  while(out.length()%5) out+="0";

  string ans = "";
  for(int i = 0; i < out.length(); i+=5){
    string now = "";
    for(int j = 0; j < 5; j++)
      now += out[i+j];
    ans += M_2[now];
  }
  cout << ans << endl;
}

string to_b(int num){
  string out = "";
  for(int i = 4; i >= 0; i--){
    if(num >= (1<<i)){
      out += "1";
      num -= (1<<i);
    }else out += "0";
  }

  return out;
}

void make(){
  M[' '] = "101";
  M['\''] = "000000";
  M[','] = "000011";
  M['-'] = "10010001";
  M['.'] = "010001";
  M['?'] = "000001";
  M['A'] = "100101";
  M['B'] = "10011010";
  M['C'] = "0101";
  M['D'] = "0001";
  M['E'] = "110";
  M['F'] = "01001";
  M['G'] = "10011011";
  M['H'] = "010000";
  M['I'] = "0111";
  M['J'] = "10011000";
  M['K'] = "0110";
  M['L'] = "00100";
  M['M'] = "10011001";
  M['N'] = "10011110";
  M['O'] = "00101";
  M['P'] = "111";
  M['Q'] = "10011111";
  M['R'] = "1000";
  M['S'] = "00110";
  M['T'] = "00111";
  M['U'] = "10011100";
  M['V'] = "10011101";
  M['W'] = "000010";
  M['X'] = "10010010";
  M['Y'] = "10010011";
  M['Z'] = "10010000";

  for(char c = 'A'; c <= 'Z'; c++)
    M_2[to_b((int)(c-'A'))] = c;
 
  M_2["11010"] = ' ';
  M_2["11011"] = '.';
  M_2["11100"] = ',';
  M_2["11101"] = '-';
  M_2["11110"] = '\'';
  M_2["11111"] = '?';
  
}


int main(){
  make();
  while(getline(cin,in)) solve(in);
  return 0;
}

Measured memory_bytes: 0
//Unification

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    string s;cin>>s;
    int j=0,k=0;
    rep(i,0,s.size()){
        if(s[i]=='0'){
            j++;
        }else{
            k++;
        }
    }
    cout << min(j,k)*2 << nnn;
    return 0;
}

Measured memory_bytes: 3756
#include<cstdio> 
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	char a[1005];
	cin >> a;
	int l = strlen(a);
	if(a[l-1]=='s'){
		cout << a ;
		cout << "es";
	}
	else cout << a << 's';
}

Measured memory_bytes: 3620
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	long K;
	long[] A;

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		K = Long.parseLong(tokens[1]);
		A = new long[N];
		tokens = in.readLine().split(" ");
		for (int i = 0; i < N; ++i) {
			A[i] = Long.parseLong(tokens[i]);
		}
		Arrays.sort(A);
	}

	long getCutNum(long total, long len) {
		if (total % len == 0) {
			return total / len - 1L;
		} else {
			return total / len;
		}
	}

	boolean check(long len) {
		long count = 0L;
		for (int i = 0; i < N; ++i) {
			count += getCutNum(A[i], len);
		}
		if (count <= K) {
			return true;
		} else {
			return false;
		}
	}

	void calc() {
		long max = A[N - 1];
		long min = 1L;
		long result = -1L;

		while (true) {
			if (min == max) {
				result = min;
				break;
			} else if (min + 1L == max) {
				if (check(min)) {
					result = min;
					break;
				} else {
					result = max;
					break;
				}
			} else {
				long med = (max + min) / 2L;
				if (check(med)) {
					max = med;
				} else {
					min = med;
				}
			}
		}
		System.out.println(result);
	}

	void showResult() {
	}
}

Measured memory_bytes: 55204
#include<bits/stdc++.h>
using namespace std;
const int N=100100;
typedef long long ll;
ll sum[N];int sz[N],n;
map<ll,int>mp;
vector<pair<int,int> >egs;
void gofail(){cout<<-1<<'\n';exit(0);}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){ll x;cin>>x;mp[x]=i;sz[i]=1;sum[i]=0;}
	for(;!mp.empty();){
		ll u=mp.rbegin()->first;int v=mp.rbegin()->second;mp.erase(u);
		if(sz[v]==n){
			if(sum[v]!=u)gofail();
			sort(egs.begin(),egs.end());
			for(auto&i:egs)cout<<i.first<<' '<<i.second<<'\n';
			return 0;
		}else{
			ll w=u+2*sz[v]-n;
			if(!mp.count(w))gofail();
			int x=mp[w];sz[x]+=sz[v];sum[x]+=sum[v]+sz[v];
			egs.emplace_back(min(v,x),max(v,x));
		}
	}
	return 0;
}


Measured memory_bytes: 9720
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   A : Integer;
   B : Integer;
begin
   Get (A);
   Get (B);
   if A = 2 then
      Put_Line ("No");
   elsif B = 2 then
      Put_Line ("No");
   else
      Put_Line ("Yes");
   end if;
end Solve;

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N, K;
  cin >> N >> K;
  vector <int> l(N);
  rep(i,N) cin >> l[i];

  sort(all(l));
  reverse(all(l));

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


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            const int M_MAX = 1000000;
            int S = int.Parse(Console.ReadLine());
            int[] an = Enumerable.Repeat(0, M_MAX).ToArray();

            an[0] = S;
            int next;
            for (int i = 1; i < M_MAX; i++)
            {
                next = Fn(an[i - 1]);
                if (an.Contains(next))
                {
                    Console.WriteLine(i + 1);
                    return;
                }
                an[i] = next;
            }
        }

        private static int Fn(int n)
        {
            return n % 2 == 0 ? n / 2 : 3 * n + 1;
        }
    }
}



Measured memory_bytes: 27076
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int N, kind = 0, cnt = 0, k = 0;
vi As;
map<int, int> mp;

void solve(){
    sort(As.begin(), As.end());

    for(auto itr = mp.begin(); itr!=mp.end(); ++itr){
        kind++;
        if(itr->second % 2 == 1){
            itr->second = 1;
        } else {
            itr->second = 2;
            k++;
        }
        cnt += itr->second;
        // cout << itr->first << " " << itr->second << endl;
    }
    cnt -= k;
    if(k % 2 == 1 && cnt >= 3){
        cout << cnt - 1 << endl;
    } else {
        cout << cnt << endl;
    }
}

int main(){
    cin >> N;
    As.resize(N);

    rep(i, N){
        cin >> As[i];
        mp[As[i]]++;
    }

    solve();
}


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

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

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

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

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

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

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

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

fn main(){

    input!{
        a: i32,
        b: i32,
    }

    let ret = a - 2*b;
    if ret <= 0{
        println!("0");
    } else {
        println!("{}",ret);
    }

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define md 1000006
int p[md];
int main() {
  int n,x,gc=0;
  cin>>n;
  while(n--)
  {
	  cin>>x;
	  gc=__gcd(gc,x);
	  if(x%2==0) p[2]++;
	  while(x%2==0) x/=2;
	  for(int i=3;i*i<=x;i+=2)
	  {
		  if(x%i==0) p[i]++;
	  	  while(x%i==0) x/=i;
	  }
	  if(x>1) p[x]++;
  }
  bool f=0;
  for(int i=1;i<md;i++) if(p[i]>1) {
	  f=1;
	  break;
  }
  if(f==0) puts("pairwise coprime");
  else if(gc==1) puts("setwise coprime");
  else puts("not coprime");
}

Measured memory_bytes: 7484
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ans[] = new int[n];
        for(int i = 0; i < n; i++) {
            int a = scan.nextInt();
            ans[a - 1] = i + 1;
        }
        for(int i = 0; i < n; i++) {
            System.out.print(ans[i] + " ");
        }
    }
}


Measured memory_bytes: 62116
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
	int a,b,c,d,result;
	cin >> a >> b >> c >> d;
	result = max(a*b, c*d);
	puts(result)
}


Measured memory_bytes: 256
def Next(a):
    global n
    print(a)
    hajimari=[0]*n
    owari=[0]*n
    for i in range(n):
        hidari=i-a[i]-1
        migi=i+a[i]+1
        if(hidari>=0):
            hajimari[hidari]+=1
        if(migi<n):
            owari[migi]+=1
    print(hajimari)
    print(owari)
    for i in range(n-1):
        hajimari[n-i-2]+=hajimari[n-i-1]
    for i in range(n-1):
        owari[i+1]+=owari[i]
    print(hajimari)
    print(owari)

n,k=map(int,input().split())
a=list(map(int,input().split()))

k=min(300,k)

for i in range(k):
    #print(a)
    hajimari=[0]*n
    owari=[0]*n
    for i in range(n):
        hidari=i-a[i]-1
        migi=i+a[i]+1
        if(hidari>=0):
            hajimari[hidari]+=1
        if(migi<n):
            owari[migi]+=1
    #print(hajimari)
    #print(owari)
    for i in range(n-1):
        hajimari[n-i-2]+=hajimari[n-i-1]
    for i in range(n-1):
        owari[i+1]+=owari[i]
    #print(hajimari)
    #print(owari)
    for i in range(n):
        a[i]=n-hajimari[i]-owari[i]

s=[]
for i in range(n):
    s.append(str(a[i]))

print(" ".join(s))

Measured memory_bytes: 180728
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    //累積和
    vector<int> s(n+1); s[0] = 0;
    rep(i,n) s[i+1] = (s[i] + a[i]) %k;

    //分布
    map<int,int> mp;
    
    ll ans = 0;

    //ここで長さがk未満であること考慮する。
    queue<int> q;

    rep(i,n+1){
        ans += mp[s[i]];
        mp[s[i]]++;
        q.push(s[i]);
        if(q.size() == k){
            mp[q.front()]--;
            q.pop();
        }
    }

    dunk(ans);
}


Measured memory_bytes: 12032
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int max = 0;
        int min = 999;
        int bingo[][] = new int[5][5];
        boolean masu[][] = new boolean[5][5];
        boolean ans = false;

        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                bingo[i][j] = scan.nextInt();
                masu[i][j] = false;
                if(bingo[i][j] > max) max = bingo[i][j];
                if(bingo[i][j] < min) min = bingo[i][j];
            }
        }

        int n = scan.nextInt();
        for(int k = 0; k < n; k++){
            int s = scan.nextInt();
            if(min <= s && s <= max){
                for(int i = 0; i < 3; i++){
                    for(int j = 0; j < 3; j++){
                        if(bingo[i][j] == s) masu[i][j] = true;
                    }
                }
            }
            else continue;
        }

        scan.close();

        for(int p = 0; p < 3; p++){
            if(masu[p][0] && masu[p][1] && masu[p][2]) ans = true;
            if(masu[0][p] && masu[1][p] && masu[2][p]) ans = true;
        }
        if(masu[0][0] && masu[1][1] && masu[2][2]) ans = true;
        if(masu[0][2] && masu[2][0] && masu[1][1]) ans = true;

        if(ans) System.out.println("Yes");
        else System.out.println("No");

    }
}

Measured memory_bytes: 21844
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    A,B,C = map(int,input().split())

    s = set([A,B,C])

    if len(s) == 2:
        print('Yes')
    else:
        print('No')



main()


Measured memory_bytes: 2940