akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
#include <chrono>
#include<unordered_map>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

int main()
{
	int H1, M1, H2, M2, K;
	scanf("%d%d%d%d%d", &H1, &M1, &H2, &M2, &K);

	int dm = (H2 - H1) * 60 + M2 - M1;
	printf("%d\n", max(0, dm - K));

	return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}

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

int GCD(int a, int b){
	int m = (a>b)?a:b;
	int n = (a>b)?b:a;
	int t;
	
	while(n!=0){
		t = m % n;
		m = n;
		n = t;
	}
	return m;
}
int LCM(int a, int b){
	return a*b/GCD(a,b);
}


int main() {
	int n;
	int a;
	int lcm=1;
	
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a;
		lcm = LCM(a,lcm);
	}
	cout << lcm << endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{int N,M; cin >> N >> M;
 vector<int> A(N),B(N);
 
 for(int i = 0; i < N; i++)
 {cin >> A[i] >> B[i];}
 
 vector<pair<int, int>> AB(N);
 
 for(int j = 0; j < N; j++)
 {AB[j] = make_pair(A[j],B[j]);}
 
 long long sum = 0;
 
 sort(AB.begin(),AB.end());
 //ABをAの小さい順にソート
 
 for(int k = 0 ; k < N; k++)
 {if(M > AB[k].second)
  {sum += (long long) AB[k].first * AB[k].second;
   M -=AB[k].second;
  continue;}
  else{ sum += (long long) AB[k].first * M;
       break;}}
 cout << sum << endl;
}


Measured memory_bytes: 1792
#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> pp;
const int INF = 1e9;
const int MOD = 1000000007;
int n = 200005;
vector<vector<int>> graph(n,vector<int>());
vector<char> color(n);
int r_cnt = 0,b_cnt = 0;
vector<int> ans(n);

void dfs(int i,int before,int dis){
  if(dis%2 == 0) {color.at(i) = 'r'; r_cnt ++;}
  else {color.at(i) = 'b'; b_cnt ++;}
  
  for(int p:graph.at(i)){
    if(p == before) continue;
    dfs(p,i,dis+1);
  }
}

 
int main() {
  cin >> n;  
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }
  
  dfs(0,-1,0);
  
  if(r_cnt <= n/3){
    int k = 1;
    rep(i,n){
      if(color.at(i) == 'r'){
        ans.at(i) = 3*k;
        k++;
      }
    }
    int l = 1;
    rep(i,n){
      if(color.at(i) == 'b'){
        if(l%3 == 0 && l < 3*k) l ++;
        ans.at(i) = l;
        l++;
      }
    }        
  }else if(b_cnt <= n/3){
    int k = 1;
    rep(i,n){
      if(color.at(i) == 'b'){
        ans.at(i) = 3*k;
        k++;
      }
    }
    int l = 1;
    rep(i,n){
      if(color.at(i) == 'r'){
        if(l%3 == 0 && l < 3*k) l++;
        ans.at(i) = l;
        l++;
      }
    }
  }else{
    int a = 1;
    rep(i,n){
      if(color.at(i) == 'r'){
        if(a > n) break;
        ans.at(i) = a;
        a += 3;
      }
    }
    int b = 2;
    rep(i,n){
      if(color.at(i) == 'b'){
        if(b > n) break;
        ans.at(i) = b;
        b += 3;
      }
    }
    int c = 3;
    rep(i,n){
      if(ans.at(i) == 0){
        ans.at(i) = c;
        c += 3;
      }
    }
  }
  rep(i,n) cout << ans.at(i) << " ";
  cout << endl;  
  
  
  return 0;
}



Measured memory_bytes: 18816
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(k);
    cii(n);
    VI vi;
    vcin(vi, n);
    LL mx = 0;
    rep(i, n-1){
        mx = max(mx, (LL)vi[i + 1] - vi[i]);
    }
    mx = max(mx, (LL)k - vi[n-1] + vi[0]);
    LL ans = k - mx;
    co(ans);
    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.15lf", sqrt(d));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#pragma GCC optimization ("O3")

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;
#define row vector<ll>
#define matrix vector<row>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
/// find_by_order(x) -> x-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x) -> inserts x into the set



int main(){
	/// ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n; cin >> n;
	vector<ll> A(n), B(n), cnt(n + 2);
	for(int i = 0; i < n; i ++) cin >> A[i];
	for(int i = 0; i < n; i ++) cin >> B[i];
	for(int i = 0; i < n; i ++){
		++ cnt[A[i]];
		++ cnt[B[i]];
	}
	for(int i = 1; i <= n; i ++){
		if(cnt[i] > n){
			cout << "No\n";
			return 0;
		}
	}
	reverse(all(B));
	int L = 0, R = n - 1;
	for(int i = 0; i < n; i ++){
		if(A[i] == B[i]){
			if(B[L] != A[i] && A[L] != A[i]){
				swap(B[L], B[i]);
				++ L;
			}
			else{
				swap(B[R], B[i]);
				-- R;
			}
		}
	}
	cout << "Yes\n";
	for(auto x : B) cout << x << " "; cout << endl;
}
/**

*/

Measured memory_bytes: 8004
package main

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

func solve(N int, B []int) int {
	A := make([]int, N)

	for i := range B {
		if i == 0 {
			A[i], A[i+1] = B[i], B[i]
			continue
		}
		if A[i] > B[i] {
			A[i], A[i+1] = B[i], B[i]
		} else {
			A[i+1] = B[i]
		}
	}

	sum := 0
	for _, v := range A {
		sum += v
	}
	return sum
}

func newSplitScanner(r io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)
	return sc
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var sc = newSplitScanner(os.Stdin)
	n := nextInt(sc)
	a := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		a[i] = nextInt(sc)
	}

	fmt.Println(solve(n, a))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<long,long> P;
typedef pair<long,P> PP;

vector<PP> edge;
long long N,D;
vector<long long> A;
const long INF=(1L<<50);
class UF{
  vector<int> par,rank;
public:
  UF(int size){
    par.resize(size);rank.resize(size);
    for (int i = 0; i < size; i++) {
      par[i]=i;
      rank[i]=0;
    }
  }
  int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
};


void solve(long l,long r){
    if(l==r)return;
    long m=(l+r)/2;
    long mn=INF;
    int pl=-1;
    for(long i = l; i <= m; i++)
    {
        long vl=A[i]-D*i;
        if(mn>vl){
            mn=vl;
            pl=i;
        }
    }
    long pr=-1;
    mn=INF;
    for(long i=m+1;i<=r;i++){
        long vr=A[i]+D*i;
        if(mn>vr){
            mn=vr;
            pr=i;
        }
    }
    for(long i = l; i <= m; i++)
    {
        edge.push_back(PP(A[i]+A[pr]+D*(pr-i),P(i,pr)));
    }
    for(long i = m+1; i < r+1; i++)
    {
        edge.push_back(PP(A[i]+A[pl]+D*(i-pl),P(pl,i)));
    }
    solve(l,m);
    solve(m+1,r);
    return;
}


int main(){
    scanf("%lld",&N);
    scanf("%lld",&D);
    A.resize(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(0,N-1);
    sort(edge.begin(),edge.end());
    UF uf(N);
    long ret=0;
    for(auto tmp:edge){
        P p=tmp.second;
        if(!uf.same(p.first,p.second)){
            uf.unite(p.first,p.second);
            ret+=tmp.first;
        }
    }
    cout<<ret<<endl;
    return 0;
}


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

int main(void){
  int H,W;
  for(int c=0;;c++){
    cin >> H >> W;
    if(H+W==0)break;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(i==0 || i==H-1 || j==0 || j==W-1){
        cout << '#';
      }else{
        cout << '.';
      }
    }
    cout << endl;
  }
  cout << endl;
}

  return 0;
}

Measured memory_bytes: 3084
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

// List with ListEntry
type List struct {
	head *ListEntry
	tail *ListEntry
}

func (l *List) print() {
	current := l.head
	elements := []string{}
	for current != nil {
		elements = append(elements, strconv.Itoa(current.key))
		current = current.next
	}
	fmt.Println(strings.Join(elements, " "))
}

// ListEntry with int key
type ListEntry struct {
	key  int
	next *ListEntry
}

func main() {
	scanner.Split(bufio.ScanWords)

	nLists := nextInt()
	nQueries := nextInt()
	lists := make([]List, nLists)

	for iQuery := 0; iQuery < nQueries; iQuery++ {
		queryType := nextInt()
		if queryType == 0 { // insert
			iList := nextInt()
			newEntry := ListEntry{
				key:  nextInt(),
				next: nil,
			}
			if lists[iList].head == nil {
				lists[iList].head = &newEntry
				lists[iList].tail = &newEntry
			} else {
				lists[iList].tail.next = &newEntry
				lists[iList].tail = lists[iList].tail.next
			}

			// lists[iList].print()
		} else if queryType == 1 { //dump
			iList := nextInt()
			lists[iList].print()
		} else if queryType == 2 { // splice
			s := nextInt()
			t := nextInt()

			if lists[t].tail == nil {
				lists[t].head = lists[s].head
			} else {
				lists[t].tail.next = lists[s].head
			}
			lists[t].tail = lists[s].tail

			lists[s].head = nil
			lists[s].tail = nil
		}
		// fmt.Println(lists)
	}
}



Measured memory_bytes: 41404
#include<stdio.h>

int main()
{
    int n,m,k;
    scanf("%d%d",&n,&m);
    if(2<=n && n<=100 && 2<=m && m<=100)
    {
        k = (n-1)*(m-1);
        printf("%d",k);
    }
return 0;
}

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


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

    int n;
    cin >> n;
    string s;
    map<string, int> ms;
    for (int i = 0; i < n; i++) {
        cin >> s;
        ms[s]++;
    }
    int maxc = 0;
    for (const auto &x : ms) maxc = max(maxc, x.second);
    for (const auto &x : ms) {
        if (x.second == maxc) cout << x.first << endl;
    }
    return 0;
}


Measured memory_bytes: 23808
N = int(input())
a = [int(i) for i in input().split()]

b = []
for i in range(N):
    b.append(max(a))
    a.remove(max(a))

Alice = 0
Bob = 0
for i in range(N):
    if i % 2 == 0:
        Alice += b[i]
    else:
        Bob += b[i]

result = Alice - Bob
print(result)

Measured memory_bytes: 3064
import sys
# from bisect import bisect_right
# gcd
# from fractions import gcd
# from math import ceil, floor
# from copy import deepcopy
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# fin = open('in_1.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template



if __name__ == '__main__':

    # write code
    Lis = li()
    if Lis[0] == Lis[1] or Lis[1] == Lis[2] or Lis[2] == Lis[3]:
        print("Bad")
    else:
        print("Good")
    

Measured memory_bytes: 3060
<?php

fscanf(STDIN, "%d", $n);

for ($i = $n; $i < 1000; ++$i) {
    $str_arr = str_split($i);

    if (
        $str_arr[0] === $str_arr[1]
        && $str_arr[0] === $str_arr[2]
        && $str_arr[1] === $str_arr[2]
    ) {
        echo $i;
        break;
    }
}


Measured memory_bytes: 4728
#include <iostream>

using namespace std;

int main(){
    // Your code here!
    while(true){
        int m,f,r;
        cin>>m>>f>>r;
        
        if(m==-1 || f==-1){
            if(m==-1 && f==-1 && r==-1){
                break;
            }
            else if(f!=-1){
                cout<<"F"<<endl;
            }
            else if(m!=-1){
                cout<<"F"<<endl;
            }
            else if(r!=-1){
                cout<<"F"<<endl;
            }
        }
        else if(m+f>=80){
            cout<<"A"<<endl;
        }
        else if(65<=m+f && m+f<80){
            cout<<"B"<<endl;
        }
        else if(50<=m+f && m+f<65){
            cout<<"C"<<endl;
        }
        else if(30<=m+f && m+f<50 && r>=50){
            cout<<"C"<<endl;
        }
        else if(30<=m+f && m+f<50 && r<50){
            cout<<"D"<<endl;
        }
        else if(0<=m+f && m+f<30){
            cout<<"F"<<endl;
        }
        
    }
    
    return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int lim,num,sum;
    vector<int>v1;
    while(cin>>num>>lim)
    {
        sum=0;
        for(int i=0;i<lim;i++)
        {
            int temp;
            cin>>temp;
            v1.push_back(temp);
            sum+=v1[i];
        }
        if(num>=sum)
        {
        cout<<(num-sum)<<endl;
        }
        else 
        {
        cout<<"-1"<<endl;
        }
        break;
    }
    
}


Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int n;
ll k;
ll a[100010],b[100010];
pair<ll,ll> pll[100010];
ll solve(){
  sort(pll,pll+n);
  ll cnt=0;
  int i=0;
  while(cnt<k){
    cnt+=pll[i].second;
    i++;
  }
  return pll[i-1].first;
}
int main(){
  cin>>n>>k;
  rep(i,n){
    cin>>a[i]>>b[i];
    pll[i]=make_pair(a[i],b[i]);
  }
  ll res=solve();
  prin(res);
  return 0;
}


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

int main() {

    int s;
    cin >> s;

    int first;
    first = s / 100;

    int second;
    second = s - first*100;

    if ((first >= 13 && second >= 13) || (first >=13 && second == 0) || (first == 0 && second >= 13) || (first == 0 && second == 0)) {
        cout << "NA";
        return 0;
    }

    if ((first >= 13 || first == 0) && (second <= 12 && second >= 1)) {
        cout << "YYMM";
        return 0;
    }

    if ((first >= 1 && first <= 12) && (second == 0 || second >= 13) ) {
        cout << "MMYY";
        return 0;
    }

    cout << "AMBIGUOUS";
    return 0;

}


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

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) {
        cin >> c[i];
    }
    
    vector<vector<int>> s(370, vector<int>(30));
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j]; 
        }
    }
    vector<int> t(d);
    rep(i, d) {
        cin >> t[i];
    }
    
    ll ans = 0;
    vector<int> cnt(26, 1);
    rep(i, d) {
        ans += s[i][t[i]-1];
        rep(j, 26) {
            if (t[i]-1 == j) continue; 
            ans-= cnt[j] * c[j];
        }
        rep(l, 26) cnt[l]++;
        cnt[t[i]-1] = 1;
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 3696
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]

x, y = map(int, raw_input().split())

if x in A:
    g_x = "A"
elif x in B:
    g_x = "B"
else:
    g_x = "C"

if y in A:
    g_y = "A"
elif y in B:
    g_y = "B"
else:
    g_y = "C"

if g_x == g_y:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 2568
a,b,k = gets.chomp.split.map(&:to_i)  # スペースで区切られた複数の整数

#馬鹿正直にもとめるなら当然TLE
=begin
num = 1
while num <= k do
  #ループ処理
  if a == 0 then
  	b -= 1
  else
    a -= 1
  end
  num += 1
end
puts ((a.to_s) + " " + (b.to_s)).to_s
=end

#答えを見て書き替えた
if a >= k  then
  #a食べ残し
  puts ((a-k).to_s + " " + (b.to_s)).to_s
elsif (a+b) >= k then
  #b食べ残し
  puts ("0" + " " + (b-(k-a)).to_s).to_s
else
  #全部食べた
  puts "0 0"
end

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

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

   // ポイントは単純にi,jを全探索するのではなく, jの終了条件j < iとして探索.
   // can_view = trueとして, 見えない山が出現した時点でfalseにしてbreakする.
   // あるiの条件に対するすべてのjに対してtrueだった場合のみans++とする.
   int ans = 0;
   for(int i = 0; i < h.size(); i++){
      bool can_view = true;
      for(int j = 0; j < i; j++){
         if(h[j] > h[i]){
            can_view = false;
            break;
         }
      }
      if(can_view){
         ans++;
      }
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1)
  {
    cout << 1 << endl;
  }
  else
  {
    cout << (h / 2) * w + (h % 2) * (w + 1) / 2 << endl;
  }
  return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int n;
string s;
vector < int > pos;

int main()
{
    _upgrade
    cin >> s;
    n = sz(s);
    int ans = 0;
    pos.push_back(-1);
    for(int i = 0; i < n; i++)
        if(s[i] != 'x') pos.push_back(i);
    pos.push_back(n);
    int m = sz(pos);
    for(int i = 1; i < (m + 1) / 2; i++)
    {
        int j = m - i - 1;
        if(s[pos[i]] != s[pos[j]])
        {
            cout << "-1\n";
            return 0;
        }
        ans += max(pos[i] - pos[i - 1], pos[j + 1] - pos[j]) - min(pos[i] - pos[i - 1], pos[j + 1] - pos[j]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 972
#include<stdio.h>
int main()
{
    int h,n,sum=0,i,c;
    scanf("%d%d",&h,&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&c);
        sum+=c;
    }
    if(sum>=h)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1628
package main

import (
	"fmt"
	"os"
)

var n, l int

func getFlavour(x int) int {
	result := 0
	for i := 0; i < n; i++ {
		result += i + l
	}
	return result - (x + l)
}

func main() {
	fmt.Scan(&n, &l)

	if l >= 0 {
		fmt.Println(getFlavour(0))
		os.Exit(0)
	}

	z := 1 - l
	if n >= z {
		fmt.Println(getFlavour(z - 1))
	} else {
		fmt.Println(getFlavour(n - 1))
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
#include<cctype>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

vector<int> bfs(vector<vector<int>> &graph, int start){
	queue<int> todo;
	vector<int> dist(graph.size(),-1);
	dist[start] = 1;
	todo.push(start);
	while(!todo.empty()){
		int now = todo.front();
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt] != -1) continue;
			dist[nxt] = dist[now] + 1;
			todo.push(nxt);
		}
	}
	return dist;
}

int main(){
    int h, w; cin >> h >> w;
    vector<string> map(h+2,string(w+2,'0'));
    for(int i = 1; i < h+1; i++){
        string s;
        cin >> s;
        for (int j = 0; j < s.size();j++){
            map[i][j+1] = s[j];
        }
    }
    int sc = 0;
    vector<vector<int>> graph;
    for (int i = 0; i < map.size(); i++){
        for (int j = 0; j < map[i].size(); j++){
            if (map[i][j] == '#') sc++;
            vector<int> a;
            if (map[i][j] == '.'){
                if (map[i][j-1] == '.') a.push_back(i*map[i].size()+j-1);
                if (map[i][j+1] == '.') a.push_back(i*map[i].size()+j+1);
                if (map[i-1][j] == '.') a.push_back((i-1)*map[i].size()+j);
                if (map[i+1][j] == '.') a.push_back((i+1)*map[i].size()+j);
            }
            graph.push_back(a);
        }
    }
    vector<int> dist = bfs(graph,map[1].size()+1);
    int goal = (map.size()-2)*map[0].size()+map[0].size()-2;
    if (dist[goal] == -1) cout << -1 << endl;
    else cout << w*h - dist[goal] - sc << endl;
    return 0;
}

Measured memory_bytes: 384
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=2019
    S=list(input())
    S=S[::-1]
    N=len(S)
    
    from collections import defaultdict
    dd = defaultdict(int)
    #2019で割ったあまりの個数
    p=[1]*N
    for i in range(N-1):
        p[i+1]=(p[i]*10)%mod
    
    now=0
    dd[0]=1
    for i in range(N):
        now=now+int(S[i])*p[i]
        now%=mod
        dd[now]+=1
        
    ans=0
    for k,v in dd.items():
        ans+=(v*(v-1))//2
    print(ans)
    

main()


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

int main()
{
    int N,K;
    int l[60];
    int ans;
    cin>>N>>K;
    for(int i=0;i<N;i++)cin>>l[i];

    sort(l,l+N,greater<int>());
    for(int i=0; i<K;i++){
        ans += l[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

arr_num, arr_times = [], []

for i in range(N) :
    a, b = map(int, input().split())
    
    arr_num.append(a)
    arr_times.append(b)
    
# do sort 
s_num, s_times = [], []
s_idx = sorted(range(N), key = lambda k : arr_num[k])

# propagate arr 
for i in s_idx :
    s_num.append(arr_num[i])
    s_times.append(arr_times[i])

cur_idx = 0

for i in range(N) :
    if cur_idx <= K :
        cur_idx += s_times[i]
        
    if cur_idx >= K :
        print(s_num[i])
        break
    

Measured memory_bytes: 17768
s = str(input())
n = len(s)

if n == 1:
    print(1)
    exit()

maxs = []
for i in range(n-1):
    if s[i] != s[i+1]:
        maxs.append(max(i+1, n-i-1))

if maxs != []:
    print(min(maxs))
else:
    print(n)

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    /* 先頭が正 */
    ll ruiseki, cnt;
    if(a[0] > 0) {
        cnt = 0;
        ruiseki = a[0];
    } else {
        cnt = (1 - a[0]);
        ruiseki = 1;
    }
    REPN(i, 1, n) {
        if(i % 2 == 0) {
            /* 正 */
            if(ruiseki + a[i] <= 0) {
                cnt += (1 - (ruiseki+a[i]));
                ruiseki = 1;
                //cout << "a " << ruiseki+a[i] << endl;
            } else {
                ruiseki += a[i];
                //cout << "b" << endl;
            }
        } else {
            /* 負 */
            if(ruiseki + a[i] >= 0) {
                cnt += (1 + (ruiseki+a[i]));
                ruiseki = -1;
            } else {
                ruiseki += a[i];
            }
        }
        //cout << i << " " << cnt << endl;
    }

    /* 先頭が負 */
    ll cnt2;
    if(a[0] < 0) {
        cnt2 = 0;
        ruiseki = a[0];
    } else {
        cnt2 = (1 + a[0]);
        ruiseki = -1;
    }
    REPN(i, 1, n) {
        if(i % 2 == 1) {
            /* 正 */
            if(ruiseki + a[i] <= 0) {
                cnt2 += (1 - (ruiseki+a[i]));
                ruiseki = 1;
            } else {
                ruiseki += a[i];
            }
        } else {
            /* 負 */
            if(ruiseki + a[i] >= 0) {
                cnt2 += (1 + (ruiseki+a[i]));
                ruiseki = -1;
            } else {
                ruiseki += a[i];
            }
        }
    }

    //cout << cnt << " " << cnt2 << endl;
    cout << min(cnt, cnt2) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using pint = pair<ll, ll>;

int main(){
  string S;
  cin >> S;
  if(S[S.size()-1]=='s'){
    cout << S << "es" << endl;
  }
  else{
      cout << S << "s" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

ll solve(ll h, ll w) {
  ll mn = 1e10;
  rep(i, 1, h) {
    vector<ll> a(3);
    a[0] = i * w;
    a[1] = (h - i) * (w / 2) ;
    a[2] = (h - i) * w - a[1];
    sort(a.begin(), a.end());
    ll tmp = a[2] - a[0];
    mn = min(mn, tmp);
  }
  rep(i, 1, h) {
    vector<ll> a(3);
    a[0] = i * w;
    a[1] = (h - i) / 2 * w;
    a[2] = (h - i) * w - a[1];
    sort(a.begin(), a.end());
    ll tmp = a[2] - a[0];
    mn = min(mn, tmp);
  }
  return mn;
}

int main() {
  ll H, W;
  cin >> H >> W;
  cout << min(solve(H, W), solve(W, H)) << endl;
  return 0;
}


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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];

  map<int, int> m;
  for (int i=0; i<n; i++) {
    if (m.find(a[i] - 1) != m.end()) {
      int v = m[a[i] - 1];
      m[a[i]] = v + 1;
      m.erase(a[i] - 1);
    } else {
      m[a[i]] = 1;
    }
  }
  int max_l = 0;
  for (auto i: m) {
    max_l = max(i.second, max_l);
  }
  cout<<n - max_l<<endl;
}

Measured memory_bytes: 10368
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void BPopularVote(std::istream& in, std::ostream& out) {
  int n, m;
  in >> n >> m;
  vector<int> a;
  llong count = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    in >> x;
    a.push_back(x);
    count += x;
  }
  sort(a.begin(), a.end(), greater<int>());
  for (int j = 0; j < m; ++j) {
    if (a[j] * 4 * m < count) {
      out << "No\n";
      return;
    }
  }
  out << "Yes\n";
}

int main(int argc, char** argv) { BPopularVote(cin, cout); return 0; }


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define  fo(i,n) for(ll i=0;i<n;i++)
#define rfo(i,n) for(ll i=n;i>=0;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
void solve()
{
	ll N;
	cin>>N;
	N = N%1000;
	if(N==0)
	{
		cout<<0;
	}
	else
	{
	cout<<1000-N;
}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	solve();
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    long int N;
    for(int i =0; i < 5; i++){
        int tmp;
        cin >> tmp;
        if(tmp == 0){
            cout << i+1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
k, n = map(int, input().split())

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

a.append(k + a[0])

section = []

for i in range(n):
    b = a[i + 1] - a[i]
    section.append(b)

b_max = max(section)
ans = k - b_max

print(ans)


Measured memory_bytes: 25840
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         ll n,k;
         cin>>n>>k;
         ll R,S,P;
         cin>>R>>S>>P;
         string s;
         cin>>s;
         string t="";
         ll ans =0;
         for(int i=0;i<s.size();i++)
         {
          if(s[i]=='r')
          {
            if(i<=k-1)
            {
               ans+=P;
               t+='p';
            }
            else
            {
                if(t[i-k]=='p')
                {
                   t+='?';
                }
                else
                {
                   ans+=P;
                   t+='p';
                }
            }
          }
          else if(s[i]=='s')
          {
            if(i<=k-1)
            {
                ans+=R;
                t+='r';
            }
            else
            {
               if(t[i-k]=='r')
                {
                   t+='?';
                }
                else
                {
                   ans+=R;
                   t+='r';
                }
            }
          }
          else
          {
             if(i<=k-1)
            {
                ans+=S;
                t+='s';
            }
            else
            {
               if(t[i-k]=='s')
               {
                  t+='?';
               }
               else
               {
                ans+=S;
                t+='s';
               }
            }
          }
         }
         cout<<ans<<endl;
         

      }
      






}



























Measured memory_bytes: 640
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];

void Solve() {
	string n;
	cin >> n;
	int res = 0;
	for (size_t i = 0; i < 4; i++)
	{
		res += n[i] == '2';
	}
	cout << res << endl;
}


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



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

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<int>> Map(H + 2, vector<int>(W + 2, 0));

	for (int i = 1; i < H + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			char c;
			cin >> c;
			if (c == '#') {
				Map[i - 1][j - 1]++;
				Map[i - 1][j]++;
				Map[i - 1][j + 1]++;

				Map[i][j - 1]++;
				Map[i][j] = -10;
				Map[i][j + 1]++;

				Map[i + 1][j - 1]++;
				Map[i + 1][j]++;
				Map[i + 1][j + 1]++;

			}
		}
	}
	for (int i = 1; i < H + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			if (Map[i][j] >= 0) cout << Map[i][j];
			else cout << '#';
		}
		cout << "\n";
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>a>>b>>c;
    rrep(i,1,ohara){
        ans=a*i;
        if(ans%b==c){
            Cout("YES");
            return 0;
        }
    }
    Cout("NO");
    return 0;
}


Measured memory_bytes: 384
while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break

    for h in range(H):
        for w in range(W):
            if (h + w) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')

        print()

    print()

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n;
	cin >> n;
	cout << n + n*n + n*n*n << endl;

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N, K;
string S;

void _main() {
    cin >> N >> S >> K;
    REP(i, N) {
        if (S[i] != S[K-1]) S[i] = '*';
    }
    cout << S << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    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 REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

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

int main()
{
	ll n;
	cin >> n;
	vll c(n-1),s(n-1),f(n-1);
	rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
	rep(i,n){
		ll cnt=0;
		for(ll j=i;j<n-1;j++){
			if(cnt<s[j]) cnt=s[j];
			else if(cnt%f[j]!=0) cnt+=f[j]-cnt%f[j];
			cnt+=c[j];
		}
		cout << cnt << endl;
	}
	return 0;
}

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

using namespace std;

typedef pair<int, int> PII;

int main() {
  int N;
  cin >> N;
  vector<PII> A(N), B(N);
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    A[i] = PII(k, i);
  }
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    B[i] = PII(k, i);
  }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  bool ans = true;
  bool last = false;
  for (int i = 0; i < N; i++) {
    if (A[i].first > B[i].first) ans = false;
    if (i < N - 1 && B[i].first >= A[i + 1].first) last = true;
  }

  vector<int> used(N, 0);
  int cur = 0;
  vector<int> inv(N);
  for (int i = 0; i < N; i++) inv[B[i].second] = i;
  for (int i = 0; i < N; i++) {
    used[cur] = true;
    cur = inv[A[cur].second];
  }
  for (int i = 0; i < N; i++) {
    if (!used[i]) last = true;
  }
  if (!last) ans = false;

  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}

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

void init() {

}

void solve() {
	int n, k, x, y; scanf("%d%d%d%d", &n, &k, &x, &y);
	printf("%lld", (long long)min(k, n)*x + max(n-k, 0)*y);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e16;

int main(){
    string s,t;
    cin >> s >> t;
    vector<vector<ll>>num(26);
    ll ls = s.size();
    ll lt = t.size();
    rep(i,ls){
        ll now = s[i]-'a';
        num[now].push_back(i);
        num[now].push_back(i+ls);
    }
    rep(i,26){
        sort(num[i].begin(),num[i].end());
    }
    ll ans = 0;
    ll pos = 0;
    rep(i,lt){
        ll now = t[i]-'a';
        if(num[now].size()==0){
            cout << -1 << endl;
            return 0;
        }
        ll nx = *lower_bound(num[now].begin(),num[now].end(),pos)+1;
        if(nx>=ls){
            ans+=nx-pos;
            pos=nx-ls;
        }
        else{
            ans+=nx-pos;
            pos = nx;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3768
#include<stdio.h>
#include<string.h>
int main(){
int i,j;
int n,l;
 scanf("%d",&n);
 scanf("%d",&l);
     
 char moji[110][110],tmp[110];
      
     
      
 for(i=0;i<n;i++){
   scanf("%s",moji[i]);
     
 }
     
     
 for(i=1;i<n;i++){
   for(j=1;j<n;j++){
     if(strcmp(moji[j-1], moji[j])>0){
       strcpy(tmp, moji[j-1]);
       strcpy(moji[j-1], moji[j]);
       strcpy(moji[j], tmp);
     }
   }
 }
 for(i = 0;i<n;i++)
   printf("%s",moji[i]);
     
 printf("\n");
    		       
      
 return 0;
}


Measured memory_bytes: 128