akhauriyash/Code-Regression huggingface dataset:
n = int(input())
k = int(input())

fact = [1]
for i in range(1, 101):
    fact += [fact[i-1] * i]


def nCk(N, K):
    if K > n or K < 0:
        return 0
    return fact[N] // fact[K] // fact[N-K]


def digits(N):
    N = abs(N)
    ret = 0
    x = 1
    while x <= N:
        ret += 1
        x *= 10
    return ret

def solve(N, K):
    if K == 0 and N == 0:
        return 1
    if K == 0 and N > 0:
        return 1
    if K > 0 and N == 0:
        return 0

    d = digits(N)
    if d < K:
        return 0

    top = N // (10**(d-1))
    return (top-1) * 9**(K-1) * nCk(d-1,K-1) + 9**(K) * nCk(d-1,K) + solve(N % (10**(d-1)), K-1)

print(solve(n,k))

Measured memory_bytes: 3064
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		System.out.println(Math.min(solve(H,W), solve(W,H)));
		
		sc.close();
	}
	
	static long solve(long a, long b) {
		if(a%3==0) {
			return 0;
		} else {
			ArrayList<Long> div = div2(a-a/3, b);
			div.add(a/3*b);
			Collections.sort(div);
			long ans = div.get(2)-div.get(0);
			
			div = div2(a-a/3-1, b);
			div.add((a/3+1)*b);
			Collections.sort(div);
			ans = Math.min(ans, div.get(2)-div.get(0));
			return ans;
		}
	}
	
	static ArrayList<Long> div2(long a, long b) {
		ArrayList<Long> ans = new ArrayList<>();
		if(a%2==0 || b%2==0) {
			ans.add(a*b/2);
			ans.add(a*b/2);
		} else {
			if(a<b) {
				long temp = a;
				a = b;
				b = temp;
			}
			ans.add(a/2*b);
			ans.add((a-a/2)*b);
		}
		
		return ans;
	}
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
using namespace std;
char a[10000000],b[10000000];
int main()
{
    int c,d;
    gets(a+1);
    c=strlen(a+1);
    for(int i=1;i<=c;i++)
    {
    	b[i]=a[c+1-i];
	}
	for(int i=1;i<=c;i++)
    {
    	if(b[i]=='b')
    	b[i]='d';
    	else
    	{
    		if(b[i]=='d')
    	    b[i]='b';
    	    else
    	    {
    	    	if(b[i]=='p')
    	        b[i]='q';
    	        else
    	        {
    	        	if(b[i]=='q')
    	            b[i]='p';
				}
			}
		}
	}
	for(int i=1;i<=c;i++)
    {
    	if(a[i]==b[i]&&i==c)
    	{
    		printf("Yes");
		}
	    else
		{
			if(a[i]!=b[i])
			{
				printf("No");
				break;
			}
		}
		
	}
	
    return 0;
} 

Measured memory_bytes: 2432
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)  for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define rep(i, n)	  for(int i = 0; i < (n); ++i)
#define all(c)		  begin(c), end(c)
#define rall(c)		  rbegin(c), rend(c)
#define SZ(a)		  ((ll) a.size())

typedef long long		   ll;
typedef unsigned long long ull;

int main() {
	ll N;
	ll K;
	scanf("%lld", &N);
	scanf("%lld", &K);
	ll a=1;
	rep(i, N) {
		if(2 * a < a + K) a = 2 * a;
		else a = a + K;
	}
	printf("%lld", a);
	return 0;
}


Measured memory_bytes: 256
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n, k = nm()
s = ns()
print(s[:k - 1] + s[k - 1].lower() + s[k:])


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;

const char *p;
string str;

int parse() {
  int num;
  char *e;
  p++;
  
  if(*p=='[') {
    vector<int> v;
    for(;;) { 
      if(*p == '[') {
	num = parse();
	v.push_back(num);
	p++;
      } else break;
    }
    sort(v.begin(), v.end());
    
    int sum = 0;
    for(int i=0; i<v.size()/2+1; i++) sum+=v[i];
    return sum;
  }
  
  if(isdigit(*p)) {
    num = strtol(p, &e, 10);
    p = e;
    return num/2+1;
  }
}

int main() {
  int n;
  cin >> n;
  cin.ignore();
  
  for(int i=0; i<n; i++) {
    getline(cin, str);
    p = str.c_str();
    cout << parse() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	long long int N, D, X[10][10] = {}, ans = 0;
	cin >> N >> D;
	for (int i = 0; i < N; i++)for (int j = 0; j < D; j++)cin >> X[i][j];
	for (int i = 0; i < N; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			int sum = 0;
			for (int l = 0; l < D; l++) {
				sum += labs(X[i][l] - X[j][l])*labs(X[i][l] - X[j][l]);
			}
			int a = sqrt(sum);
				if ((a*a) == sum) {
				sqrt(sum);
				ans++;
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
<?php
    $N = intval(trim(fgets(STDIN)));
    
    $V = array_map('intval',explode(" ",trim(fgets(STDIN))));
    $C = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    $sum=0;
    
    for($i=0;$i<$N;$i++){
        if($V[$i]-$C[$i]>0){
            $sum += ($V[$i]-$C[$i]);
        }
    }
    
    echo $sum;
?>

Measured memory_bytes: 16152
def counter(list_1,list_2,length):
    count = 0
    m = 0
    for n in list_1:
        if m == length:
            count += 1
            m = 0
        m = list_2[n][m]
        if m == -1 :
            count += 1
            m = list_2[n][0]
    return count * length + m
s = input()
le_s = len(s)
t = input()
l_t = [ord(x)-97 for x in t]
s_t = set(l_t)
l_s = [[-1 for p in range(le_s)] for _ in range(26)]
s_s =set()
i = 1
l_c = [0 for _ in range(26)]
for y in s:
    z = ord(y)-97
    if z in s_t:
        l_s[z][l_c[z]:i] = [i for a in range(i - l_c[z])]
        l_c[z] = i
        s_s.add(z)
    i += 1
if s_t != s_s:
    print(-1)
    exit()
print(counter(l_t,l_s,le_s))


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

Node treeSearch(Node u, int k){
  while(u != NIL){
  if(u->key == k) return u;
  else if(u->key > k) u = u->left;
  else u = u->right;
   }
  return NIL;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
     } 
     else if ( com[0] == 'i' ){
       scanf("%d", &x);
       insert(x);
     } else if ( com[0] == 'p' ){
       inorder(root);
       printf("\n");
       preorder(root);
      printf("\n");
     } 
  }
  
  return 0;
}




Measured memory_bytes: 20448
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>k;
		// n=s.length();
		// ll a[n];
		map<ll,ll> mp;
		rep(i,k)
		{
			cin>>m;
			rep(j,m)
			{
				cin>>cs;
				mp[cs]++;
			}
		}
		rep(i,n)
		{
			c+=(mp[i+1]==0);
		}
		cout<<c;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;

int a[1100][1100];
int n;

int hoge(int y,int x,int n)
{
	return a[y+n-1][x+n-1]+a[y-1][x-1]-a[y-1][x+n-1]-a[y+n-1][x-1];
}

int main()
{
	while(cin>>n&&n)
	{
		memset(a,0,sizeof a);
		for(int y=1;y<=n;y++)
		{
			for(int x=1;x<=n;x++)
			{
				char j;
				cin>>j;
				a[y][x]=j=='*';
			}
		}
		for(int y=1;y<=n;y++)for(int x=1;x<=n;x++)
				a[y][x]+=a[y][x-1];
		for(int y=1;y<=n;y++)for(int x=1;x<=n;x++)
				a[y][x]+=a[y-1][x];
		
		bool flag=true;
		for(int i=n;i>=0&&flag;i--)
		{
			for(int y=1;y+i-1<=n&&flag;y++)
			{
				for(int x=1;x+i-1<=n&&flag;x++)
				{
					if(hoge(y,x,i)==0)
					{
						flag=false;
						cout<<i<<endl;
					}
					
				}
			}
		}
	}
	
}

Measured memory_bytes: 5892
# AOJ 1165: Pablo Squarson's Headache
# Python3 2018.7.14 bal4u

rr, cc = [0]*202, [0]*202
while True:
	n = int(input())
	if n == 0: break
	rr[0] = cc[0] = r1 = r2 = c1 = c2 = 200
	for i in range(1, n):
		m, d = map(int, input().split())
		r, c = rr[m], cc[m]
		if   d == 0: c -= 1
		elif d == 1: r += 1
		elif d == 2: c += 1
		else:        r -= 1
		rr[i], cc[i] = r, c
		if r < r1: r1 = r
		if r > r2: r2 = r
		if c < c1: c1 = c
		if c > c2: c2 = c
	print(c2-c1+1, r2-r1+1) 



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

int main() {
    int n, cnt=0, x, y;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i=0; i<n; i++) a[i]=i+1;
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n; i++) cin >> c[i];
    do{
        cnt++;
        for(int i=0; i<n; i++) {
            if(a[i]!=b[i]) {
                break;
            }
            if(i==(n-1)) {
                x=cnt;
            }
        }
        for(int i=0; i<n; i++) {
            if(a[i]!=c[i]) {
                break;
            }
            if(i==(n-1)) y=cnt;
        }
    } while(next_permutation(a.begin(), a.end()));

    cout << abs(x-y);
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
B = list(map(int, input().split()))
result = 0
for i in range(n):
    A = list(map(int, input().split()))
    sum = c
    for j in range(m):
        sum += A[j] * B[j]
    if sum > 0:
        result += 1
print(result)

Measured memory_bytes: 3064
N, x = map(int, input().split())
a = list(map(int, input().split()))
sumA = sum(a)
if sumA < x:
    print(N-1)
    exit()
a.sort()
ans = 0
for i in range(len(a)):
    if x < a[i]:
        break
    ans += 1
    x -= a[i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    int x,a,b;
    while(scanf("%d%d%d",&x,&a,&b)==3)
    {
        if(abs(x-a)<abs(x-b))
        {
            printf("A\n");
        }
        else
        {
            printf("B\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    string s;
    cin >> s;
    ll rem = s.len - 2 ;
    if(s[0] != s[s.len-1]){
        if(rem % 2 == 0 ) {
            cout << "Second\n" ;
            ro ;
        }
        else cout << "First\n" ;
        ro ;
    }
    else{
        if(rem % 2 == 0){
            cout << "First\n" ;
            ro;
        }
        else cout << "Second\n" ;
        ro ;
    }
    ro ;
}





Measured memory_bytes: 512
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n,a = LI()
x = LI()
s = sum(x)
dp = [[[0 for i in range(s+1)] for j in range(n+1)] for k in range(n+1)]
for i in range(n+1):
    dp[i][0][0] = 1
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(s+1):
            if k >= x[i-1]:
                dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
            else:
                dp[i][j][k] = dp[i-1][j][k]
ans = 0
for i in range(1,n+1):
    if a*i <= s:
        ans += dp[n][i][a*i]
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

_s = input()[:-1]

week = {
    'SUN': 7,
    'MON': 6,
    'TUE': 5,
    'WED': 4,
    'THU': 3,
    'FRI': 2,
    'SAT': 1
}

print(week[_s])


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef vector<int> vi;
const int mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) << ' ' << (a+b-n>0?a+b-n:0) << endl;
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int a[100][2];
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n,count=0;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
      cin>>a[i][0]>>a[i][1];
    }
    for (int i = 0; i < n; i++)
    {
      if(a[i][0]==a[i][1]){
          count++;
      }else
      {
          count=0;
      }
      if(count==3){
          cout<<"Yes"<<endl;
          return 0;
      }
    }
    cout<<"No"<<endl;
}

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

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

	long long k;
	cin >> k;
	vector<long long> arr(50, 49 + k / 50);

	for (int i = 0; i < k % 50; ++i) {
		arr[i] += 50;
		for (int j = 0; j < 50; ++j) {
			if (i != j) arr[j]--;
		}
	}

	cout << 50 << '\n';
	for (long long u: arr) cout << u << ' ';
}

Measured memory_bytes: 256
package main

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

func main() {
	scan_init()
	d := scanInt()
	t := scanInt()
	s := scanInt()
	if d - s*t <= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}

Measured memory_bytes: 1784
//Littleboy123 Template 1.7
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")t
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(int (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(int (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("walk.in", "r", stdin);
}

void outfile(){
    freopen("output.txt", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2LL, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1LL)
        tmp = (tmp * a) % mod;
    return tmp;
}

ll ex(ll a, ll b){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = ex(a, b/2LL);
    tmp = (tmp * tmp);
    if(b & 1LL)
        tmp = (tmp * a);
    return tmp;
}

//End of template

set<pair<ll, ll>> t, l;

template <class T>
auto lower_bound_first(const set<std::pair<T, T>>& s, T first)
{
   static constexpr T min = numeric_limits<T>::min();

   return s.lower_bound({first, min});
}

int main(){
    init();

    ll n, q;
    cin >> n >> q;
    t.insert(mp(n, n-1));
    l.insert(mp(n, n-1));
    ll ans = (n-2LL)*(n-2LL);
    ll u, v;
    pair<ll, ll> tmp;
    FOR(i, 0, q){
        cin >> u >> v;
        if(u == 1){
            auto pos = lower_bound_first(l, v);
            tmp = *pos;
            //cout << tmp.se << endl;
            ans -= tmp.se-1;
            t.insert(mp(tmp.se+1, v-1));
        }
        else{
            auto pos = lower_bound_first(t, v);
            tmp = *pos;
            //cout << tmp.se << endl;
            ans -= tmp.se-1;
            l.insert(mp(tmp.se+1, v-1));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16104
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
vector<int>a[100005];
queue<int>b;
int n, m;
int cnt = 0;
int len = 1;
int sd = 1;
int deep[100005];
int pos[1000005];
void solve() {
	int i, t, j;
	while (!b.empty()) {
		for (j = 0; j < len; j++) {
			t = b.front();
			for (i = 0; i < a[t].size(); i++) {
				if (deep[a[t][i]] == 0) {
					deep[a[t][i]] = sd;
					b.push(a[t][i]);
					cnt++;
				}
			}
			b.pop();
		}
		sd++;
		len = cnt;
		cnt = 0;
	}
}
int main() {
	cin >> n >> m;
	int i, j, t, x, y;
	for (i = 0; i < m; i++) {
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	/*for (i = 1; i <= n; i++) {
		cout << i << ": ";
		for (j = 0; j < a[i].size(); j++)cout << a[i][j] << " ";
		cout << endl;
	}*/
	b.push(1);
	solve();
	deep[1] = 0;
	int temp = 1;
	for (i = 2; i <= n; i++) {
		if (deep[i] == 0)temp = 0;
	}
	if (temp == 0)cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for (i = 2; i <= n; i++) {
			for (j = 0; j < a[i].size(); j++) {
				if (deep[a[i][j]] == deep[i] - 1) {
					pos[i] = a[i][j];
					break;
				}
			}
		}
		for (i = 2; i <= n; i++)cout << pos[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 10812
// abc130_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

ll dp[2001][2001];

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    REP(i, N) cin >> S[i];
    REP(j, M) cin >> T[j];

    dp[0][0] = 1;
    REP(i, N+1) dp[i][0] = 1;
    REP(j, M+1) dp[0][j] = 1;

    REPN(i, 1, N+1) REPN(j, 1, M+1){

        if (S[i-1] == T[j-1]) {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        } else {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + MOD) % MOD;
        }

    }

    print(dp[N][M]);



    return 0;
}


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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define endl "\n"

const int N = 105;
string s[N];

int32_t main()
{
	IOS;
	int n, l;
	cin >> n >> l;
	for (int i = 1; i <= n; i++)
		cin >> s[i];
	sort(s + 1, s + n + 1);
	for (int i = 1; i <= n; i++)
		cout << s[i];
	cout << endl;


	return 0;
}

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


using namespace std;

int main()
{
  int n;
  cin>>n;
  string s;
  map<string,int> mp;
  for(int i = 0; i <n ;i++){
    cin>>s;
    mp[s]++;
  }
  cout<<mp.size();
}


Measured memory_bytes: 19016
n = int(input())
a = list(map(int,input().split()))

c4 = 0
c2 = 0
for ai in a:
  if ai%4 == 0:
    c4 += 1
  elif ai%2 == 0:
    c2 += 1
if (c2 > 0 and c4 >= n-c4-c2) or (c2 == 0 and c4 >= n-c4-c2-1):
  print('Yes')
else:
  print('No')


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

string S, T;
void input() {
cin >> S >> T;
}

void solve() {
T.pop_back();
if(S == T) cout << "Yes" << endl;
else cout << "No" << endl;
}

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool ans = false;
  for(int i=1;i<10;i++){
    for(int j=i;j<10;j++){
      if(i*j==N){
        ans = true;
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std ;
typedef long long int ll ;


int main(){
	int n,a[105],b[105];
	cin>>n;
	for(int i=0; i<n-1; i++){
		cin>>b[i];
		a[i]=a[i+1]=1e9;
	}
	for(int i=0;i<n-1;i++){
	
		a[i]=min(a[i],b[i]);
		a[i+1]=min(b[i],a[i+1]);
		//cout<<a[i]<<" ";
	}
	a[n-1]=b[n-2];
	ll sum=0;
	for(int i=0;i<n;i++)sum+=a[i];
	
	cout<<sum<<'\n';
	return 0;
}



Measured memory_bytes: 256
import numpy as np
from itertools import permutations
import math

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]): 
        x = x1-x2
        y = y1-y2
        dis += math.sqrt(x * x + y * y)
    re.append(dis)

print(np.average(re))


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

int main() {
	int h, w;
	while (cin >> h >> w && h != 0 || w != 0) {
		for (int i = 0; i < h; ++i) {
			int mode = 0;
			if (i % 2 == 0) {
				mode = 0;
			}
			else {
				mode = 1;
			}
			for (int i2 = 0; i2 < w; ++i2) {
				if(mode == 0){
					cout << "#";
					mode = 1;
				}
				else {
					cout << ".";
					mode = 0;
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  const int NN = 100001;
  vector<bool> flag(NN, true);
  flag[0] = false;
  flag[1] = false;
  for (int i = 2; i < sqrt(NN); i++) {
    if (flag[i]) {
      for (int j = 0; i * (j + 2) < NN; j++) {
        flag[i * (j + 2)] = 0;
      }
    }
  }
  int Q;
  cin >> Q;
  vector<int> cnt(NN, 0);
  for (int i = 2; i < NN; i++) {
    if (flag[i] && flag[(i + 1) / 2])
      cnt[i]++;
    cnt[i] += cnt[i - 1];
    // cout << cnt[i] << endl;
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << cnt[r] - cnt[l - 1] << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll x,ans=0,x1;
  cin>>x;
  ans=ans+(x/500)*1000;
  x1=x%500;
  ans=ans+(x1/5)*5;
  cout<<ans;
  
  
   
   
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	while (1)
	{
		c -= b;
		if (c <= 0)
		{
			println("Yes");
			return 0;
		}

		a -= d;
		if (a <= 0)
		{
			println("No");
			return 0;
		}
	}
}

Measured memory_bytes: 3500
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


void solve(){
  string S, T;
  cin >> S >> T;
  cout << T << S << endl;
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 200007;
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    unsigned long long res = 0;
    //k/2 * floor(n/k) * floor(1 + n/k)
    for (int i = 1; i <= n; i++) {
        res += (i/(long double)2.0) * (n/i) * floor(1 + n/i);
    }
    cout << res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

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

struct Team{
  int tid, cntWrong[11], penalty, AC;
  Team(int i){
    tid = i;
    for(int i = 1; i <= 10; i++) cntWrong[i] = 0;
    penalty = 0;
    AC = 0;
  }
};

vector<Team> teams;

void init(int T){
  for(int i = 1; i <= T; i++){
    teams.push_back(Team(i));
  }
}

bool compare(const Team &t1, const Team &t2){
  if(t1.AC != t2.AC) return t1.AC > t2.AC;
  else if(t1.penalty != t2.penalty) return t1.penalty < t2.penalty;
  else return t1.tid < t2.tid;
}

int main(void){
  int T, P, R;
  while(cin >> T >> P >> R && T != 0 && P != 0 && R != 0){
    int tid, pid, time;
    string message;
    teams.clear();
    init(T);
    for(int i = 0; i < R; i++){
      cin >> tid >> pid >> time >> message;
      if(message == "WRONG"){
        teams[tid-1].cntWrong[pid]++;
      }else if(message == "CORRECT"){
        teams[tid-1].penalty += teams[tid-1].cntWrong[pid] * 1200 + time;
        teams[tid-1].AC++;
      }
    }
    sort(teams.begin(), teams.end(), compare);
    for(int i = 0; i < T; i++){
      cout << teams[i].tid << " " << teams[i].AC << " " << teams[i].penalty << endl;
    }
  }
  return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

    int cnt0=0, cnt1=0;
    for(int in=0;in<s.size();in++) {
        if(s.at(in)=='0') cnt0++;
        else cnt1++;
    }

    cout << 2*min(cnt0, cnt1) << endl;

    return 0;
}





Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

string s1[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", 
				 "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", 
				 "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", 
				 "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"};
char c1[32] = {'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', ' ', '.',',','-','\'','?'};

char c2[32] = {' ','\'',',','-','.','?','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'};
string s2[32] = {"101", "000000","000011","10010001","010001","000001","100101","10011010",
				 "0101","0001","110","01001","10011011","010000","0111","10011000",
				 "0110","00100","10011001","10011110","00101","111","10011111","1000",
				 "00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};



void solve()
{
	string s;
	while(getline(cin, s))
	{
		string binary;
		for(int i = 0; i < s.size(); ++i)
		{
			for(int j = 0; j < 32; ++j)
			{
				if(s[i] == c1[j])
				{
					binary += s1[j];
				}
			}
		}
		string ans;
		string temp;
		for(int i = 0; i < binary.size(); ++i)
		{
			temp += binary[i];
			if(temp.size() < 3)
			{
				continue;
			}
			for(int j = 0; j < 32; ++j)
			{
				if(temp == s2[j])
				{
					ans += c2[j];
					temp.clear();
				}
			}
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1196
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(){
    long H, W;
    cin >> H >> W;

    long ans = 0;


    ans = ans + H * (W / 2);
    if (W % 2 != 0){
        ans = ans + H / 2 + H % 2;
    }

    if (H == 1 | W == 1){
        ans = 1;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX 300005
int m,n,A,B;
int a,b,C=~(1<<31),M=(1<<16)-1;

int r() {
  a = 36969 * (a&M) + (a>>16);
  b = 18000 * (b&M) + (b>>16);
  return (C&((a<<16)+b))%1000000;
}

int x[MAX],y[MAX],z[MAX];
set< P > t[MAX];


void insert(set<P> &s,P p){
  set<P> :: iterator it;
  while(1){
    it=s.upper_bound(p);
    if(it==s.end())break;

    if( p.first <= it->first &&
        p.second <= it->second ){
      s.erase(it);
    }else{
      break;
    }
  }
  s.insert(p);
}

bool check(set<P> &s,P p){
  set<P> :: iterator it;
  it=s.upper_bound(p);
  int cc=0;
  while(it!=s.begin()){
    cc++;
    if(cc>3)break;

    it--;
    if(it->first < p.first)
      if(it->second < p.second)
        return true;
  }
  return false;
}

int calc(P p){
  int left=0,right=m+n,mid;
  while(left<right){
    mid=(left+right)/2;
    if(check(t[mid],p))left=mid+1;
    else right=mid;
  }
  return left;
}


vector<P> G[1000005];

int solve(){
  int ans=1;

  for(int i=0;i<=m+n;i++){
    t[i].clear();
  }
  t[0].insert(P(-1,-1));
  set<int> st;

  for(int i=0;i<m+n;i++){
    st.insert( z[i] );
    G[ z[i] ].push_back( P(x[i],y[i]) );
  }

  for( int i : st ){
    vector<int> v( G[i].size() );
    for(int j=0;j<(int)G[i].size();j++){
      v[j]=calc(G[i][j]);
      ans=max(ans,v[j]);
    }
    for(int j=0;j<(int)G[i].size();j++){
      if(check( t[ v[j] ] , G[i][j])==false)
        insert(t[ v[j] ],G[i][j]);
    }
    G[i].clear();    
  }
  /*
  for(int i=0;i<=ans;i++){
    cout<<i<<" :"<<endl;
    for(P p:t[i]){
      cout<<p.first<<' '<<p.second<<endl;
    }
    cout<<endl;
    cout<<endl;
  }
  cout<<endl;
  */
  return ans;
}

int main(){
  while(1){
    scanf("%d %d %d %d",&m,&n,&A,&B);
    if(m==0&&n==0&&A==0&&B==0)break;

    a=A,b=B;
    
    for(int i=0;i<m;i++){
      scanf("%d %d %d",&x[i],&y[i],&z[i]);
    }

    for(int i=m;i<m+n;i++){
      x[i]=r();
      y[i]=r();
      z[i]=r();
    }
    printf("%d\n",solve());


  }
}

Measured memory_bytes: 83344
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
key = c.keys()
comb = 0
for i in key:
    comb += (c[i]) * (c[i]-1) // 2

for i in A:
    ans = comb - (c[i]-1)
    print(ans)

Measured memory_bytes: 34036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,k;cin>>n>>k;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  sort(all(l),greater<int>());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=l[i];
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  int d = 0, ans = 1;
  for (int i = 0; i < n; i++) {
    d += l[i];
    if (d <= x) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
if n%2==1:
    print(0)
    exit()
# 5で割れる数は変わらないが、
# 階乗の計算にするため、2で悪
n //= 2
ans=n

def kosu(n,p):
    if n == 0:
        return 0
    return n //p + kosu(n//p,p)

print(kosu(n,5))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int imos[201][201];
int sum(int si, int sj, int li, int lj) {
    return imos[li][lj] - imos[li][sj] - imos[si][lj] + imos[si][sj];
}
int sol2(int si, int sj, int li, int lj, int need) {
    if (sum(si, sj, li, lj) / 2 <= need) return 0;
    
    int ret = 0;
    for (int i = si; i < li; ++i) {
        ret = max(ret, min(sum(si, sj, i, lj), sum(i, sj, li, lj)));
    }
    for (int i = sj; i < lj; ++i) {
        ret = max(ret, min(sum(si, sj, li, i), sum(si, i, li, lj)));
    }
    return ret;
}
int sol3(int si, int sj, int li, int lj, int need) {
    if (sum(si, sj, li, lj) / 3 <= need) return 0;
 
    int ret = 0;
    for (int i = si; i < li; ++i) {
        ret = max(ret, min(sum(si, sj, i, lj), sol2(i, sj, li, lj, ret)));
        ret = max(ret, min(sum(i, sj, li, lj), sol2(si, sj, i, lj, ret)));
    }
    for (int i = sj; i < lj; ++i) {
        ret = max(ret, min(sum(si, sj, li, i), sol2(si, i, li, lj, ret)));
        ret = max(ret, min(sum(si, i, li, lj), sol2(si, sj, li, i, ret)));
    }
    return ret;
}
int sol4(int si, int sj, int li, int lj) {
    int ret = 0, s1, s2, s, ini, lim;
    for (int i = si; i < li; ++i) {
        ret = max(ret, min(sum(si, sj, i, lj), sol3(i, sj, li, lj, ret)));
        ret = max(ret, min(sum(i, sj, li, lj), sol3(si, sj, i, lj, ret)));
    }
    for (int i = sj; i < lj; ++i) {
        ret = max(ret, min(sum(si, sj, li, i), sol3(si, i, li, lj, ret)));
        ret = max(ret, min(sum(si, i, li, lj), sol3(si, sj, li, i, ret)));
    }
    for (int i = si; i < li; ++i) {
        for (int j = sj; j < lj; ++j) {
            if (ret >= (s1 = sum(si, sj, i, j))) continue;
            
            for (int k = si; k < li; ++k) {
                if (ret >= (s2 = sum(si, j, k, lj))) continue;
                
                s = min(s1, s2);
                ini = k < i ? j : sj;
                lim = k > i ? j : lj;
                for (int l = ini; l < lim; ++l) {
                    ret = max(ret, min(s, min(sum(i, sj, li, l), sum(k, l, li, lj))));
                }
            }
        }
    }
    return ret;
}
int main(){
    int h, w, n, a[200][200], s;
    cin >> h >> w >> n;
    for (int i = 0; i < h; ++i) {
        s = 0;
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
            s += a[i][j];
            imos[i + 1][j + 1] = imos[i][j + 1] + s;
        }
    }
    switch (n) {
        case 2:
            cout << sol2(0, 0, h, w, 0) << "\n";
            break;
        case 3:
            cout << sol3(0, 0, h, w, 0) << "\n";
            break;
        case 4:
            cout << sol4(0, 0, h, w) << "\n";
            break;
    }
    
    return 0;
}

Measured memory_bytes: 3384
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=1e5+5;
int n,m,tax[maxn],fl[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	n=rd(); m=rd(); fl[1]=1; int a,b;
	go(i,n+1,1) tax[i]=1;
	go(i,m+1,1){
		a=rd(); b=rd(); fl[b]|=fl[a]; tax[b]++;
		if(--tax[a] == 0) fl[a]=0;
	}
	int ans=0;
	go(i,n+1,1)	ans+=fl[i];
	printf("%d",ans);
	return 0;
}//Faze


Measured memory_bytes: 1024
A = int(input()) # 500
B = int(input()) # 100
C = int(input()) # 50
X = int(input()) # target
 
ans = 0
 
for i in range(A+1):
  for j in range(B+1):
    for h in range(C+1):
      amount = 500*i + 100 * j + 50 * h
      if amount == X:
        ans += 1

print(ans)

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

using static Input;
using static Util;
class Program
{
    static int N;
    static int M;
    static UnionFind uf;
    static void INPUT()
    {
        N = NextInt();
        M = NextInt();
        uf = new UnionFind(N);
        for (int i = 0; i < M; i++)
        {
            uf.Unite(NextInt(), NextInt());
        }
    }

    static void OUT()
    {
        Console.WriteLine(uf.GetSize().Max());
    }

    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
    /// <summary>
    /// UnionFind木
    /// </summary>
    public class UnionFind
    {
        private int[] data;

        public UnionFind(int size)
        {
            size++;
            data = new int[size];
            for (int i = 1; i < size; i++) data[i] = -1;
        }

        public bool Unite(int x, int y)
        {

            x = Root(x);
            y = Root(y);

            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }

        public bool IsSameGroup(int x, int y)
        {
            return Root(x) == Root(y);
        }

        public IEnumerable<int> GetSize()
        {
            foreach (var item in data.Where(_ => _ < 0).ToArray())
            {
                yield return -item;
            }

            yield break;
        }

        private int Root(int x)
        {
            return data[x] < 0 ? x : data[x] = Root(data[x]);
        }
    }
}


Measured memory_bytes: 23992
N = int(input())
D, X = [int(x) for x in input().split()]
A = [int(input()) for _ in range(N)]
ans = X
for i in range(N):
  a = 1
  l = 1
  while a <= D:
    ans += 1
    a = l*A[i] + 1
    l += 1
print(ans)

Measured memory_bytes: 9124
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        int a = int.Parse(cin[0]);
        int b = int.Parse(cin[1]);

        if (b % a == 0) Console.WriteLine(a + b);
        else Console.WriteLine(b - a);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> X(100010, 0);
  rep(i, N) {
    int a; cin >> a;
    ++X[a];
  }
  int ans = 0;
  rep(i, 100000) {
    chmax(ans, X[i]+X[i+1]+X[i+2]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
"use strict";//const 使用のため宣言
// inputに入力データ全体が入る
function Main(input) {

    const arg = input.split('\n');
    const A = parseInt(arg[0]);
    const B = parseInt(arg[1]);
    const C = parseInt(arg[2]);
    const X = parseInt(arg[3]);

    let count = 0;

    for (let a = 0; a <= A; a++) {
        for (let b = 0; b <= B; b++) {
            for (let c = 0; c <= C; c++) {

                let sum = (500 * a) + (100 * b) + (50 * c);
                if (sum === X) count += 1;
                //console.log(sum);
                //console.log(count);



            }

        }

    }
    console.log(count);

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//Main(require("fs").readFileSync("./a.txt", "utf8"));

Measured memory_bytes: 7372