akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int N, P;
string S;
LL answer;

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

    answer = 0;
    if (P == 2) {
        for (int i = 0; i < N; i++) {
            int digit = S[i] - '0';
            if (digit%2 == 0)
                answer += (i + 1);
        }
    } else if (P == 5) {
        for (int i = 0; i < N; i++) {
            int digit = S[i] - '0';
            if (digit%5 == 0)
                answer += (i + 1);
        }
    } else {
        map<int, int> cnt;

        cnt[0] = 1;
        int suffix = 0;
        int multiplier = 1;
        for (int i = N - 1; i >= 0; i--) {
            int digit = S[i] - '0';

            suffix = ((digit * multiplier) + suffix)%P;

            answer += cnt[suffix];

            cnt[suffix] = cnt[suffix] + 1;
            multiplier = (multiplier * 10)%P;
        }
    }

    cout << answer << endl;
}


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

int main()
{
  int n, m, a[1010], b;
  map<int, int> mii;
  cin >> n >> m;
  for (int i  = 0; i < n; i++){
    cin >> a[i];
    mii.insert(make_pair(i, 0));
  }
  for (int i = 0; i < m; i++){
    cin >> b;
    for (int j = 0; j < n; j++){
      if (a[j] <= b) {
        mii[j]++;
        break;
      }
    }
  }
  int res = -1, c;
  for (map<int, int>::iterator a = mii.begin(); a != mii.end(); ++a) {
    if (res < a->second){
      res = a->second;
      c = a->first;
    }
  }
  cout << c + 1 << "\n";
}

Measured memory_bytes: 3088
#include <stdio.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
const ll MOD = 1000000007;

ll scr[5050][5050];
int cnt[5050];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    int p[5050];
    ll c[5050];
    rep(i, n) scanf("%d", &p[i]);
    rep(i, n) p[i]--;
    rep(i, n) scanf("%lld", &c[i]);
    rep(i, n+1) rep(j, n+1) scr[i][j] = -(MOD*MOD);
    
    rep(i, n){
        int idx = i;
        cnt[i] = 0;
        scr[idx][cnt[i]] = c[p[idx]];
        while(p[idx] != i) {
            idx = p[idx];
            cnt[i]++;
            scr[i][cnt[i]] = c[p[idx]];
            scr[i][cnt[i]] += scr[i][cnt[i]-1];
        }
    }
    ll ans = -(MOD*MOD);
    rep(i, n){
        if(cnt[i]+1 >= k){
            rep(j, k)
                ans = max(ans, scr[i][j]);
        }else{
            if(scr[i][cnt[i]] <= 0){
                rep(j, cnt[i]+1)
                    ans = max(ans, scr[i][j]);
            }else{
                ll tmp = scr[i][cnt[i]] * (k/(cnt[i]+1));
                int tmpk = k % (cnt[i]+1);
                rep(j, cnt[i]+1)
                    ans = max(ans, tmp - scr[i][cnt[i]] + scr[i][j]);
                rep(j, tmpk)
                    ans = max(ans, tmp + scr[i][j]);
            }
        }
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 199120
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x,k,d;
    cin>>x>>k>>d;
    ll nt = min((abs(x)+d-1)/d,k);
    ll mini=INF;
    if(x>0)nt=-nt;
    rep(i,nt-10,nt+11){
        if(abs(i)>k)continue;
        mini = min(mini,abs(i*d+x + ((k-abs(i))%2)*d));
        mini = min(mini,abs(i*d+x - ((k-abs(i))%2)*d));
    }
    cout<<mini<<"\n";
    return 0;  
}   

Measured memory_bytes: 3640
N,M=map(int,input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        cnt=0
        for k in range(M):
            if A[i+k][j:j+M]==B[k]:
                cnt+=1
        if cnt==M:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9040
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = 0;
		String line1 = br.readLine();
		while(true){

			String line = br.readLine();
			if ("END_OF_TEXT".equals(line)) {break;}
			String[] str = line.split(" ");
			for (int i=0; i<str.length ; i++ ) {
				if (str[i].equalsIgnoreCase(line1)) {
					count++;	
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24488
import java.util.*;
import java.math.BigInteger;
class Main{

     public static void main(String []args){
      Scanner scan = new Scanner(System.in);
      String s = scan.next() ;
      int i = 0 ;
      while(s.length()!=0){
          s = s.substring(0,s.length()-1);
          //System.out.println(s);
          if(s.substring(0,(s.length()/2)).equals(s.substring(s.length()/2,s.length()))){
              System.out.println(s.length());
              break;
          }
          i++;
      }
    }
}

Measured memory_bytes: 22612
package main

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

var sc = bufio.NewScanner(os.Stdin)

type st struct {
	ind int
	min int64
}

func main() {
	var S int
	fmt.Scan(&S)
	sc.Split(bufio.ScanWords)
	lmap := map[int]int{}
	for i := 0; i < S; i++ {
		lmap[int(nextInt())]++
	}
	count := 0
	for li, lv := range lmap {
		for ji, jv := range lmap {
			for ki, kv := range lmap {
				if li > ji && ji > ki && li < ji+ki {
					count += lv * jv * kv
				}
			}
		}
	}
	fmt.Print(count)
}
func bc(s string, pos int) string {
	ch := "1"
	if string(s[pos]) == "1" {
		ch = "0"
	}
	pre := string(s[:pos])
	post := ""
	if pos != len(s)-1 {
		post = string(s[pos+1:])
	}
	tmp := pre + ch + post
	return tmp
}
func popCount(n string) int {
	count := 0
	for _, s := range n {
		if string(s) == "1" {
			count++
		}
	}
	return count
}
func chc(m [][]bool, p int) [][]bool {
	ret := make([][]bool, len(m))
	for i, l := range m {
		tmp := []bool{}
		for _, c := range l {
			if i == p {
				tmp = append(tmp, false)
			} else if c == true {
				tmp = append(tmp, true)
			} else {
				tmp = append(tmp, false)
			}
		}
		ret[i] = tmp
	}
	return ret
}
func chl(m [][]bool, p int) [][]bool {
	ret := make([][]bool, len(m))
	for j, l := range m {
		tmp := []bool{}
		for i, c := range l {
			if i == p {
				tmp = append(tmp, false)
			} else if c == true {
				tmp = append(tmp, true)
			} else {
				tmp = append(tmp, false)
			}
		}
		ret[j] = tmp
	}
	return ret
}
func helper(ma [][]bool) int {
	count := 0
	for _, l := range ma {
		for _, c := range l {
			if c == true {
				count++
			}
		}
	}
	return count
}
func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func arrSum(arr []int) int {
	sum := 0
	for _, a := range arr {
		sum += a
	}
	return sum
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}


Measured memory_bytes: 1880
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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() {
    ll n,m,k;
    cin >> n >> m >> k;
    for(ll i = 0; i <= n;i++){
        for(ll j = 0;j <= m;j++){
            if(i*(m - j) + (n - i)*j == k){
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &x : a) cin >> x;
	reverse(a.begin(), a.end());
	for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' ');
}


Measured memory_bytes: 3088
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i,k,h,w,idx,flag;
		h = sc.nextInt();
		w = sc.nextInt();
		int[][] answer = new int[h][w];
		for(i = 0; i < h; i ++ ){
			char weather[] = sc.next().toCharArray(); 
			flag = 0;
			idx = 0;
			for(k = 0; k < weather.length; k ++ ){
				if(weather[k] == 'c'){
					answer[i][k] = 0;
					idx = k;
					flag++;
				}
				if(flag == 0){
					if(weather[k] == '.')answer[i][k] = -1;
				}
				else{
					if(weather[k] == '.')answer[i][k] += k - idx;
				}
			}
		}
		for(i = 0; i < h; i ++ ){
			for(k = 0; k < w; k ++ ){
				if(k != w-1)System.out.print(answer[i][k]+" ");
				else System.out.println(answer[i][k]);
			}
		}
	}
}

Measured memory_bytes: 34420
h,w = map(int,input().split())
grid = []
for i in range(h):
  grid.append(input())
walk = [[1,0],[-1,0],[0,1],[0,-1]]
ans = 'Yes'
for i in range(h):
  for j in range(w):
    if grid[i][j]=='#':
      temp = 1
      for k,l in walk:
        ni = i+k
        nj = j+l
        if 0<=ni<h and 0<=nj<w:
          if grid[ni][nj]=='#':
            temp = 0
      if temp:
        ans = 'No'
print(ans)

Measured memory_bytes: 9076
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;



bool mp[401][401];
int main(){
	int N;
	int dx[]={-1,0,1,0};
	int dy[]={0,1,0,-1};
	
	while(cin>>N){
		if(N==0)break;
		CLR(mp);
		vector<PII>pi;
		mp[200][200]=true;
		pi.PB(MP(200,200));
		REP(i,N-1){
			int n,d;
			cin>>n>>d;
			int x=pi[n].first,y=pi[n].second;
			x+=dx[d];y+=dy[d];
			mp[x][y]=true;
			//cout<<x<<" "<<y<<endl;
			pi.PB(MP(x,y));
			
		}
		int maxi=-1,mini=INF,maxj=-1,minj=INF;
		REP(i,401){
			REP(j,401){
				if(mp[i][j]){
					maxi=max(maxi,i);
					mini=min(mini,i);
					maxj=max(maxj,j);
					minj=min(minj,j);
				}
			}
		}
		cout<<(maxi-mini+1)<<" "<<(maxj-minj+1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1368
#include <stdio.h>
#define N 500


main(){
  int i, j, ns, nt, S[10000], T[N], c;

  scanf("%d", &ns);
  for(i = 0;i < ns;i++)scanf("%d", &S[i]);

  scanf("%d", &nt);
  for(i = 0;i < nt;i++)scanf("%d", &T[i]);

  for(i = 0,c = 0;i < nt;i++){
    for(j = 0;j < ns;j++){
      if(S[j] == T[i]){
	c++;
	break;
      }
    }
  }
  printf("%d\n", c);
  return 0;
}

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

int N, K;

int solve(int i, int sum) {
    ll res = 1e8;
    if (i == N) {
        return sum;
    }
    res = min(solve(i+1, sum + K), solve(i+1, sum * 2));
    return res;
}

int main() {
    cin >> N >> K;
    cout << solve(0, 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define rFOR(i, a, b) for(int i=b-1; i>=a; i--)
#define MAX 50
typedef long long ll;
using namespace std;

int main(void){
  string s; cin >> s;
  int w; cin >> w;
  for(int i=0; i<s.size(); i+=w){
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long

signed main() {
	int n, k;
	string s;
	cin >> n >> k >> s;

	char s2;
	s2 = s[k - 1];
	s2 = s2 + 0x20;

	s[k - 1] = s2;

	cout << s << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
vector<int> v;
int main() {
  long long int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  cout << min(N, K) * X + max((long long int)0, N - K) * Y << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

const int INF=1e18;

signed main()
{
    int N,K; cin>>N>>K;
    vector<int> h(N);
    for(int i=0;i<N;i++){
        cin>>h[i];
    }

    vector<int> dp(N,INF);
    dp[0]=0;

    for(int i=0;i<N;i++){
        for(int j=1;j<=K;j++){
            if(i+j<N){
                chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
            }
        }
    }
    cout<<dp[N-1]<<endl;
}


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

int main() {
    int n; cin >> n;
    vector<long long> a(n), b(n);
    long long ans = 0;
    for (int i=0; i<n; ++i) cin >> a[i] >> b[i];
    for (int i = n-1; i>=0; --i) {
        long long now = a[i] + ans;
        if (now % b[i]) {
            ans += b[i] - (now % b[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
bool dp[82][82][82*82*2];
int differ[82][82],A[82][82],B[82][82];
int main()
{
	int H,W;
	cin>>H>>W;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin>>A[i][j];
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin>>B[i][j],
			differ[i][j]=abs(A[i][j]-B[i][j]);
	dp[0][0][differ[0][0]]=true;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			for(int k=0;k<=(i+j+1)*80;k++)
				if(dp[i][j][k])
				{
					if(i!=H-1)
					{
						dp[i+1][j][k+differ[i+1][j]]=dp[i+1][j][abs(k-differ[i+1][j])]=true;
					}
					if(j!=W-1)
					{
						dp[i][j+1][k+differ[i][j+1]]=dp[i][j+1][abs(k-differ[i][j+1])]=true;
					}
				}
	for(int i=0;i<82*82*2;i++)
		if(dp[H-1][W-1][i])
		{
			cout<<i<<endl;
			return 0;
		}
	return 0;
}


Measured memory_bytes: 87424
x=int(input())
a=1
while True:
    if a**5-x>0:
        for b in range(a):
            if x==a**5-b**5:
                print("{0} {1}".format(a,b))
                exit()
    elif a**5-x<0:
        b=-1
        while True:
            if b**5<a**5-x:
                break
            if x==a**5-b**5:
                print("{0} {1}".format(a,b))
                exit()
            b-=1
    else:
        b=0
        print("{0} {1}".format(a,b))
        exit()
    a+=1

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int x;cin>>x;
	int sum=0;
	int cnt=0;
	while(1){
		sum+=x;
		cnt++;
		if(sum%360==0){
			cout<<cnt<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    char a,b;cin>>a>>b;
    if(a=='H'){
        cout << b << endl;
    }else{
        if(b=='H') cout << 'D' << endl;
        else cout << 'H' << endl;
    }
    return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll x2 = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2) x2 -= a[i];
    else x2 += a[i];
  }
  vector<int> ans(n);
  ans[0] = x2 / 2;
  for (int i = 0; i < n - 1; i++) {
    ans[i + 1] = a[i] - ans[i];
  }
  for (int i = 0; i < n; i++) {
    ans[i] *= 2;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2048
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

string S, T;

void solve() {
    vector<int> ids;
    bool reached = false;
    int temp = 0;

    while (temp < S.length()) {
        int i_s = temp, i_t = 0, cnt = 0;
        while (i_t < T.length()) {
            if (S[i_s] == T[i_t] || S[i_s] == '?') {
                cnt++;
                if (cnt == T.length()) {
                    reached = true;
                    ids.emplace_back(temp);
                }
                i_s++, i_t++;
            } else {
                break;
            }
        }
        temp++;
    }
    if (reached) {
        vector<string> ans;
        EACH(t, ids) {
            string temp;
            REP(i, t) {
                if (S[i] == '?') temp += 'a';
                else temp += S[i];
            }
            REP(i, T.length()) {
                temp += T[i];
            }
            FOR(i, t + T.length(), S.length()) {
                if (S[i] == '?') temp += 'a';
                else temp += S[i];
            }
            ans.emplace_back(temp);
        }
        sort(ans.begin(), ans.end());
        cout << ans[0] << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
}

int main() {
    cin >> S >> T;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  priority_queue<int> que;
  int n,m;
  cin >> n >> m;
  rep(i,n){
    int a;
    cin >> a;
    que.push(a);
  }
  rep(i,m){
    int b = que.top();
    que.pop();
    b /= 2;
    que.push(b);
  }
  int ans = 0;
  rep(i,n){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

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

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

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vi cnt(9);
    rep(i, n) {
        int a; std::cin >> a;
        cnt[min(a/400, 8)]++;
    }
    int mi = 0;
    rep(i, 8) if (cnt[i] > 0) mi++;
    int ma = mi + cnt[8];
    chmax(mi, 1);
    std::cout << mi << " " << ma << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	ll n, k; scanf("%lld%lld", &n, &k);
	ll ans = 0;
	for(ll i = k; i <= n+1; i++){
		ans += (n-i+1 + n) * i / 2 - (0 + i-1) * i / 2 + 1;
		ans %= 1'000'000'007LL;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3868
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int A[200010];

int main() {
	int K, N;
	cin >> K >> N;
	for(int i=0; i<N; ++i) cin >> A[i];
	int mx=(K-A[N-1])+A[0];
	for(int i=1; i<N; ++i){
		mx=max(mx, A[i]-A[i-1]);
	}
	cout << K-mx << endl;
	return 0;
}

Measured memory_bytes: 1024
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N,M = imn()
ab = [iln() for _ in range(M)]
ab = sorted(ab, key=lambda x: x[1])

broken = ab[0][1]
cnt = 1
for i in range(1, M):
    if not ab[i][0] < broken <= ab[i][1]:
        broken = ab[i][1]
        cnt += 1
print(cnt)


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

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

const ll Inf = 1000000000000000000ll;
const int Maxn = 200005;
const int Maxm = 1048576;

struct node {
    ll add;
    lli mn;
};

int n, D;
int a[2][Maxn];
node st[2][Maxm];
map <int, ll> M[2];
ll res;

void downOn(int s, int v, ll fl)
{
    st[s][v].add += fl;
    st[s][v].mn.first += fl;
}

void Down(int s, int v)
{
    if (st[s][v].add) {
        downOn(s, 2 * v, st[s][v].add);
        downOn(s, 2 * v + 1, st[s][v].add);
        st[s][v].add = 0;
    }
}

void Union(int s, int v)
{
    st[s][v].mn = min(st[s][2 * v].mn, st[s][2 * v + 1].mn);
}

void Create(int s, int v, int l, int r)
{
    st[s][v].add = 0;
    if (l == r) {
        st[s][v].mn.first = a[s][l] - ll(l) * D;
        st[s][v].mn.second = l;
    } else {
        int m = l + r >> 1;
        Create(s, 2 * v, l, m);
        Create(s, 2 * v + 1, m + 1, r);
        Union(s, v);
    }
}

void Update(int s, int v, int l, int r, int a, int b, ll add)
{
    if (l == a && r == b) downOn(s, v, add);
    else {
        Down(s, v);
        int m = l + r >> 1;
        if (a <= m) Update(s, 2 * v, l, m, a, min(m, b), add);
        if (m + 1 <= b) Update(s, 2 * v + 1, m + 1, r, max(m + 1, a), b, add);
        Union(s, v);
    }
}

void Insert(int s, int x, ll val)
{
    map <int, ll>::iterator it = M[s].upper_bound(x);
    if (it->second <= val) return;
    ll oldval = it->second;
    int cur = x;
    it--;
    Update(s, 1, 0, n - 1, it->first + 1, cur, val - oldval);
    while (val <= it->second) {
        cur = it->first;
        oldval = it->second;
        M[s].erase(it--);
        Update(s, 1, 0, n - 1, it->first + 1, cur, val - oldval);
    }
    M[s][x] = val;
}

void Init()
{
    for (int s = 0; s < 2; s++) {
        Create(s, 1, 0, n - 1);
        M[s][-1] = -Inf; M[s][n] = Inf;
        Update(s, 1, 0, n - 1, 0, n - 1, Inf);
    }
}

int main()
{
    scanf("%d %d", &n, &D);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[0][i]);
        a[1][n - 1 - i] = a[0][i];
    }
    Init();
    int v = 0;
    for (int i = 0; i < n - 1; i++) {
        int ov = n - 1 - v;
        Update(0, 1, 0, n - 1, v, v, Inf);
        Update(1, 1, 0, n - 1, ov, ov, Inf);
        ll myval = a[0][v] + ll(v) * D;
        Insert(0, v, myval);
        ll omyval = a[1][ov] + ll(ov) * D;
        Insert(1, ov, omyval);
        lli A = st[0][1].mn;
        lli B = st[1][1].mn;
        if (A <= B) { res += A.first; v = A.second; }
        else { res += B.first; v = n - 1 - B.second; }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 75776
#include <cstdio>
#include <cstring>
using namespace std;
char s[10];
int i;
int main()
{
	scanf("%s",s);int n=strlen(s);
	for (i=0;i<n-1;i++) if (s[i]=='A' && s[i+1]=='C'){
		puts("Yes");return 0;
	}puts("No");
	return 0;
}

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

int main() {
  //宣言
  int N;
  vector<int> D;
  int ans =0;
  
  //入力
  cin >> N;
  D = vector<int>(N);
  for(int i=0;i<N;i++){
  cin >> D.at(i);
  }
  
  //処理
  sort(D.begin(),D.end());
  ans++;
  for(int i=0;i<N-1;i++){
    if(D.at(i) != D.at(i+1))ans++;
  }
  
  //出力
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll N;
  cin >> N;
  Vl A(N);
  ll ans = 1;
  REP(i, N) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  REP(i, N) {
    if (ans > (1000000000000000000 / A.at(i))) {
      cout << -1 << endl;
      return 0;
    }
    ans = ans * A.at(i);
  }
  if (ans > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3992
#include<stdio.h>

int main(){

     int S, h, m, s;

     scanf("%d", &S);

     h=S/3600;
     S=S-h*3600;
     m=S/60;
     s=S-m*60;

     printf("%d:%d:%d\n", h, m, s);

     return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
int main(void){
  int n,i,j,k,l,count=0;
  while(scanf("%d",&n)!=EOF){
    count=0;
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
	for(k=0;k<10;k++){
	  for(l=0;l<10;l++){
	    if(i+j+k+l==n){
	      count++;
	    }
	  }
	}
      }
    }
    printf("%d\n",count);
  }
  return(0);
}

Measured memory_bytes: 1724
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
//#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const long long linf = 4523372036854775807;
const int inf = 1500000000;
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	int from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
int fact(int i) {
	ll sum = 1;
	for (int j = 2; j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
 //---------------------------------------------------
 //+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int a, b;
	cin >> a >> b;
	cout << ceil((a + b) / 2.0) << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main(){
	int n;
	cin >> n;
	set<string> st;
	while(n--){
		string s;
		cin >> s;
		st.insert(s);
	}
	int m;
	cin >> m;
	bool flag = false;
	while(m--){
		string s;
		cin >> s;
		if(st.find(s) == st.end()){
			cout << "Unknown " << s << endl;
		}else{
			flag = !flag;
			cout << (flag ? "Opened by " : "Closed by ") << s << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define FLOOR '.'
#define BOMB '#'

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

	vector<string> stage(H+2, string(W+2, FLOOR));
	for(int i=0; i<H; i++)
	{
		string line;
		cin >> line;

		stage[i+1].replace(1, W, line);
	}

	const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
	const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
	for(int i=1; i<H+1; i++)
	{
		for(int j=1; j<W+1; j++)
		{
			if(stage[i][j] != FLOOR)
				continue;

			int cnt = 0;
			for(int k=0; k<8; k++)
			{
				int y = i + dy[k];
				int x = j + dx[k];

				if(stage[y][x] == BOMB)
					cnt++;
			}
			stage[i][j] = to_string(cnt)[0];
		}
	}

	for(int i=1; i<H+1; i++)
		cout << stage[i].substr(1, W) << endl;

	return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
ans = [0] * len(s)
# [RL]の位置と区切れを記録
index = []

for i in range(n-1):
  if s[i] == "L" and s[i+1] == "R":
    index.append([i])
index.append([n-1])

j=0
for i in range(n-1):
  if s[i] == "R" and s[i+1] == "L":
    index[j].append(i)
    index[j].append(i+1)
    j+=1

#index = [最後の位置、Lの位置、Rの位置、最初の位置]
for i in range(1,len(index)):
  index[i].append(index[i-1][0]+1)
index[0].append(0)

#print(index)

for i in range(len(index)):
  kosu = index[i][0] - index[i][3] + 1
  #print(kosu)
  #rの位置が偶数
  if (index[i][1] - index[i][3] + 1)%2 == 0:
    r = kosu // 2
    l = kosu - r
  else:
    l = kosu // 2
    r = kosu - l
  
  ans[index[i][1]] = r
  ans[index[i][2]] = l
  






print(*ans)


Measured memory_bytes: 18544
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    int arr[n];
    forn(i, n) cin >> arr[i];
    sort(arr, arr + n);
    int alice = 0, bob = 0;
    for (int i = 0; i < n; i += 2) {
        alice += arr[i];
    }
    for (int i = 1; i < n; i += 2) {
        bob += arr[i];
    }
    cout << abs(alice - bob) << endl;
    return 0;
}

Measured memory_bytes: 256
/*
.   Bismillahir Rahmanir Rahim
.   Author - Marajul islam
.   created- Sat Mar 28 17:56:19 2020

*/ 
#include<bits/stdc++.h>
using namespace std;


 
int sc1() {int x; scanf("%d", &x); return x;}
long long sc2() {long long x; scanf("%lld", &x); return x;}

const int mod= 1e9 + 7;
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (long long)a * b % mod;}
 
#define F               first
#define S               second 
#define mp              make_pair
#define pb              push_back
#define pf              push_front
#define speed_up        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x)           (int)x.size()
#define all(x)          x.begin(), x.end()
#define debug           cerr << "OK\n";
#define ub              upper_bound
#define lb              lower_bound
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define Int             sc1()
#define LL              sc2()
#define For(n)          for(int i=0;i<n;i++)
#define Forj(n)         for(int j=0;j<n;j++)
#define Fork(n)         for(int k=0;k<n;k++)
#define For1(n)         for(int i=1;i<=n;i++)

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef set <int>       si;
typedef set <ll>        sll;
typedef multiset <int>  msi;
typedef multiset <ll>   msll;
typedef map <int, int>  mi;
typedef map <ll, ll>    mll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
  
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
 
 
int solve() {
 
	ll k=LL;
	ll n=LL;
	std::vector<ll> v;
	ll arr[n+1];
	For(n) arr[i]=LL;
	sort(arr,arr+n);
	For(n) v.pb(arr[i]);
	v.pb(v[0]+k);
	std::vector<ll> v2;
	for(int i=0;i<sz(v)-1;i++){
		v2.pb(v[i+1]-v[i]);
	}
	sort(v2.begin(), v2.end());
	ll ans = 0;
	For(v2.size()-1) ans+=v2[i];

	cout<<ans<<endl;

 
	return 0;
}
 
 
 
 
int main()
{
	//speed_up;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 6384
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  int n,k;
  cin >> n;
  cin >> k;
  
  int res = n - k + 1;
  
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/keyence2020_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K , S;
  cin >> N >> K >> S;

  rep(i, K) { cout << S << " "; }
  rep(i, N - K) {
    if (S == 1e9) {
      cout << 1 << " ";
    } else {
      cout << S + 1 << " ";
    }
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)

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

    vector<i64> a(n);
    vector<pair<i64,int>> cb(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> cb[i].second >> cb[i].first;

    sort(a.begin(),a.end(),greater<i64>());
    sort(cb.begin(),cb.end(),greater<pair<i64,int>>());

    i64 sum = 0;

    for(int i=0,j=0,k=0;k<n;)
    {        
        if(j<m && a[i]<cb[j].first)
        {
            int dk = min(n-k,cb[j].second);
            sum += cb[j].first * dk;
            j++;
            k += dk;
        }
        else
        {
            sum += a[i];
            i++;
            k++;
        }        
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<math.h>
int prime(int);
int main() 
{
  int all=0,ans=0;
  int a,n;
  int i;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&a);
    
   ans =  prime(a);

   if(ans == 0) all++;
  }

  printf("%d\n",all);

  return 0;
  
}

int prime(int a)
{
  int x;

  if(a == 2) return 0;

  else if(a<2 || a%2==0) return 1;

  x = 3;

  while(x<=sqrt(a)){
    if(a % x == 0) return 1;
    x = x + 2;
  }
  
  return 0;
  
}
  

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

int main(){
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=n-1;i>=0;i--){
        if(h[i-1]>h[i]){
            h[i-1]--;
        }
        if(h[i-1]>h[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 640
def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    d = {0: 0}
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    cnt = 0
    for i in d.keys():
        if d[i] >= i:
            cnt += d[i] - i
        else:
            cnt += d[i]
    print(cnt)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 67172
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n;
  cin >> n;
  bool found = false;
  for (int i = 1; i <= 9; ++i) {
    if (n % i == 0) {
      int j = n / i;
      if (j >= 1 && j <= 9) found = true;
    }
  }
  cout << (found ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
main()
{
	int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a<=b) 
{
	printf("%d\n",a*c);
}
else 
{
	printf("%d\n",b*c+(a-b)*d);
}
return 0;
}

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

using namespace std;
int main() {
    int a, b;
    int num;
    int scale = 10;

    cin >> a >> b;
    while (b/scale) {
        scale *= 10;
    }
    num = a*scale + b;

    for (int i = 1; i <= 1000; i++) {
        int pow = i*i;

        if (num == pow) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N;
int W[101];

int main(void){
    // Your code here!
    cin >> N;
    int total = 0;
    
    for(int i = 0; i < N; i++) {
        cin >> W[i];
        total += W[i];
    }
    
    
    int ans = 100000;
    
    for(int t = 1; t < N; t++){
        int s1 = 0;
        int s2 = 0;
        for(int j = 0; j < t; j++) {
            s1 += W[j];
        }
        
        s2 = total - s1;
        ans  = min(ans, abs(s2-s1));
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
n,x = list(map(int,input().split()))
A = list(map(int,input().split()))

cnt = 0
for i in range(1,n):
    if A[i-1]+A[i] > x:
        cnt += A[i]-(x-A[i-1])
        A[i] = x-A[i-1]
        if A[i] < 0:
            A[i] = 0
            A[i-1] = A[i-1]+A[i]
              

print(cnt)


Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=3e3+1;
ll dp[N][N][2];
vector<int> a(N);
ll n;

ll go(int l, int r, int mov){
    if(l>r) return 0;
    if(dp[l][r][mov]!=-1)
        return dp[l][r][mov];
    ll ans;
    if(mov==0)
        ans=max(a[l]+go(l+1,r,1^mov),a[r]+go(l,r-1,1^mov));
    else
        ans=min(go(l+1,r,1^mov)-a[l],go(l,r-1,1^mov)-a[r]);
    return dp[l][r][mov]=ans;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<n;i++)
        cin>>a[i];
    cout<<go(0,n-1,0);

    

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    string ans = "Yes";
    if ((a * b) % 2 == 0) ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
li = input()
n = int(li.split()[0])
d = int(li.split()[1])
max_distance = math.sqrt(d**2)
ans = 0
for _ in range(n):
    a = input()
    x = int(a.split()[0])
    y = int(a.split()[1])
    distance = math.sqrt(x**2 + y**2)
    if distance <= max_distance:
        ans += 1
print(ans)

Measured memory_bytes: 9188
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
if n%2==0:
  m=n//2
  ans=0
  for i in range(m):
    ans+=2*a[i]
  ans-=a[0]
else:
  m=n//2
  ans=0
  for i in range(m):
    ans+=2*a[i]
  ans+=a[m]
  ans-=a[0]
print(ans)

Measured memory_bytes: 31536
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int n;
	cin >> n;
	cout << 800 * n - 200 * (n/15) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int w[]=new int[N];
        int v[]=new int[N];

        long dp[][] = new long[N][W+1];

        for(int i=0;i<N;i++){
            w[i]=sc.nextInt();
            v[i]=sc.nextInt();
        }

        for(int i=0;i<w[0];i++)dp[0][i]=0;
        for(int i=w[0];i<W+1;i++)dp[0][i]=v[0];

        for(int i=1;i<N;i++){
            for(int j=0;j<w[i];j++){
                dp[i][j]=dp[i-1][j];
            }
            for(int j=w[i];j<W+1;j++){
                dp[i][j]=Math.max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
        }
        /*

        for(int i=0;i<N;i++){
            for(int j=0;j<W+1;j++) System.out.print(dp[i][j]+" ");
            System.out.println();
        }

         */
        System.out.println(dp[N-1][W]);

    }
}


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

using namespace std;
const int mod = 1e9 + 7;
int n;
long long k;
void add(int &a, int b){
    a = (a + b) % mod;
}
int mul(int a, int b){
    return (a * 1ll * b) % mod;
}
struct M{
    vector < vector < int > > v;
    M(){
        v.resize(n, vector < int > (n, 0));
    }
    M operator*(const M& b) {
        M c;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                for(int t = 0; t < n; t++){
                    add(c.v[i][t], mul(v[i][j], b.v[j][t]));
                }
            }
        }
        return c;
    }
};
int main(){
    cin >> n >> k;
    vector < vector < int > > v(n, vector < int > (n, 0));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> v[i][j];
        }
    }
    M answer;
    for(int i = 0; i < n; i++){
        answer.v[i][i] = 1;
    }
    M m;
    m.v = v;
    while(k > 0){
        if(k % 2 == 1){
            answer = answer * m;
        }
        m = m * m;
        k /= 2;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            add(ans, answer.v[i][j]);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256