akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

vector<vector<int>> inp;
int n, m, q, ans;

void dfs(vector<int> a) {
  if (a.size() == n + 1) {
    int now = 0;
    rep(i, 0, q) {
      if (a[inp[i][1]] - a[inp[i][0]] == inp[i][2])
        now += inp[i][3];
      chmax(ans, now);
    }
    return;
  }
  a.push_back(a.back());
  while (a.back() <= m) {
    dfs(a);
    a.back()++;
  }
}

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

  cin >> n >> m >> q;
  inp.resize(q, vector<int>(4));
  rep(i, 0, q) { cin >> inp[i][0] >> inp[i][1] >> inp[i][2] >> inp[i][3]; }
  dfs(vector<int>(1, 1));
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void){
	double answer=1.0;
	int n,i;
	
	scanf("%d",&n);
	
	for(i=0;i < n-1;i++){
		answer *= 1.0*n-i;
	}
	
	printf("%-.0f\n",answer);
	
	return 0;
}

Measured memory_bytes: 628
#include<iostream>
using namespace std;
int gcd(int a, int b)
{
	int temp;

	if (a < b) { temp = a; a = b; b = temp; }
	if (b < 1) return -1;

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


int main() {
	int n;
	cin >> n;
	int a[100001];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int g;
	g = gcd(a[0], a[1]);
	for (int i = 2; i < n ; i++) {
		int u;
		u = gcd(a[i], g);
		g = u;
	}
	cout << g;
	return 0;



}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < W; i++) printf("#");
		printf("\n");

		for(int i = 1; i < H-1; i++){
			printf("#");
			for(int j = 1; j < W-1; j++) printf(".");
			printf("#\n");
		}

		if(H > 1){
			for(int i = 0; i < W; i++) printf("#");
			printf("\n");
		}
		printf("\n");
	}
}



Measured memory_bytes: 2588
#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;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

int main () {

    ll x;cin>>x;

    ll ans=0;

    ans+=(x/500)*1000;
    
    ll b = x%500;

    ans+=(b/5)*5;

    cout<<ans<<endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace A.Task_Scheduling_Problem
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var res = 0;

            Array.Sort(A);

            for (int i = 1; i < A.Length; i++)
                res += Math.Abs(A[i] - A[i - 1]);

            Console.WriteLine(res);
        }
    }
}

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

int main() {
  int i,j,min=1001;
  string S,T;
  cin>>S>>T;
  for (i=0;i<=S.size()-T.size();i++) {
    int count=0;
    for (j=0;j<T.size();j++) {
      if (S[i+j]!=T[j]) count++;
    }
    if (min > count) min = count;
  }
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
typedef vector<ll> vc;
typedef vector<string> vcs;
typedef vector<pair<ll, ll>> vcp;
typedef vector<tuple<ll, ll, ll>> vct;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator >(const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll a, b;
	cin >> a >> b;
	cout << max(0LL, a - b) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
from collections import *

class FordFulkerson:
    def __init__(self, N, edges):
        self.N = N
        self.G = defaultdict(lambda : defaultdict(int))
        
        for s, t, cap in edges:
            self.G[s][t] = cap
        
    def dfs(self, v, t, f):
        if v==t:
            return f
        
        self.used[v] = True
        
        for nv, cap in self.G[v].items():
            if not self.used[nv] and self.G[v][nv]>0:
                d = self.dfs(nv, t, min(f, self.G[v][nv]))
                
                if d>0:
                    self.G[v][nv] -= d
                    self.G[nv][v] += d
                    
                    return d
        
        return 0
    
    def max_flow(self, s, t):
        flow = 0
        
        while True:
            self.used = [False]*self.N
            f = self.dfs(s, t, 10**18)
        
            if f==0:
                return flow
        
            flow += f

N = int(input())
edges = []

for i in range(1, N+1):
    edges.append((0, i, 1))

for i in range(N+1, 2*N+1):
    edges.append((i, 2*N+1, 1))

ab = [tuple(map(int, input().split())) for _ in range(N)]
cd = [tuple(map(int, input().split())) for _ in range(N)]

for i in range(N):
    for j in range(N):
        if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
            edges.append((1+i, N+1+j, 1))

ff = FordFulkerson(2*N+2, edges)
print(ff.max_flow(0, 2*N+1))

Measured memory_bytes: 46300
import numpy as np
INF = 2**60 # 無限大を表す値
N, W = map(int, input().split())
wv = [tuple(map(int, input().split())) for i in range(N)]
dp = np.full((N+1, W+1), -INF, dtype = np.int64)
dp[0][0] = 0 # 初期条件
for i, (w, v) in enumerate(wv):
    dp[i+1] = np.maximum(dp[i+1], dp[i])
    dp[i+1][w:] = np.maximum(dp[i+1][w:], dp[i][:-w] + v)
print(np.max(dp[N][:W+1]))

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> M(N);
  for (int i = 0; i < N; i++) {
    cin >> M[i];
    X -= M[i];
  }
  sort(M.begin(),M.end());
  cout << N + X/M[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a==b){
cout<<"a"<<" "<<"=="<<" "<<"b"<<endl;
}else if(a<b){
	cout<<"a"<<" "<<"<"<<" "<<"b"<<endl;
}else if(a>b){
	cout<<"a"<<" "<<">"<<" "<<"b"<<endl;
}
return 0;

}


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

using namespace std;
typedef long long ll;

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

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

    vector<int> right(n);
    right[n-1] = 0;

    for(int i=n-2; i >= 0; i--) {
        right[i] = max(right[i+1], data[i+1]);
    }

    int left = 0;
    cout << max(right[0], left) << endl;

    for(int i=1; i < n; i++) {
        left = max(left, data[i-1]);
        if(i < n-1) {
            cout << max(right[i], left) << endl;
        }
        else {
            cout << max(left, 0) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define FI first
#define SE second
#define PB(a) push_back(a)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
#define SZ(x) ((int)(x).size())
#define SO(x) sizeof((x)) / sizeof((x)[0])
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void co(int a[], int n) {REP(i, n) cout << a[i] << " "; cout << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int n,t;
	cin >> n >> t;
	int a, b, ans = INF;
	REP(i,n){
		cin >> a >> b;
		if (b <= t){
			if (a < ans) ans = a;
		}
	}
	if (ans == INF){
		cout << "TLE" << endl;
	}else{
		cout << ans << endl;
	}
	
return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  string ans;
  rep(i, N) {
    ans += S[i];
    ans += T[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()

# N = 5*10**3
# S = "".join(["t" for n in range(N)])

dp = [[0 for j in range(N+1)] for i in range(N+1)]

mx = 0

for i in range(N):
#   print(dp)
  for k in range(N):
    if i<k and S[i] == S[k]:
      dp[i+1][k+1] = 1
    c_before = dp[i][k]
    if k<N and i+c_before<k and S[k]==S[i]:
      dp[i+1][k+1] = c_before+1
      mx = max(mx,c_before+1)

# print(dp)
print(mx)



Measured memory_bytes: 246536
a, b, c = map(int, input().split())
k = int(input())
ans= 0
 
for i in range(k):
  if a < b*(2**i) < c*(2**(k-i)):
    ans+=1
  else:
    ans+=0
  
if ans>=1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9180
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define MAX  1000005
#define SMAX 3000200

int binary_search(int a, int b[],int n);
void input(int a[]);

int main(void)
{
    int count=0;
    int n[1];
    int q[1];
    int S[MAX];
    int T[MAX];
    input(n);
    input(S);    
    input(q);
    input(T);
    for(int i=0;i<q[0];i++)
    {
        if(binary_search(T[i],S,n[0])){count++;}
    }
    printf("%d\n",count);


    return 0;
    
}

int binary_search(int a, int b[],int n)
{
    int left=0;
    int right=n;
    int mid;
    while(left<right)
    {
        mid = (left+right)/2;
        if(b[mid]==a)
        {
            return 1;
        }
        else if(a<b[mid])
        {
            right = mid;
        }
        else
        {
            left = mid+1;
        }
    }
    return 0;
}
void input(int a[])
{
    char str[SMAX];
    int x;
    int j=0;
    fgets(str,SMAX,stdin);
    int i=0;
    while(str[i]>=' ')
    {
        while(isspace(str[i])){i++;}
        if(isdigit(str[i]))
        {
            x=0;
            while(isdigit(str[i]))
            {
                x=10*x+(str[i]-'0');
                i++;
            }
            a[j]=x;
            j++;
        }
        else
        {
            i++;
        }
    }
}


Measured memory_bytes: 3232
import java.util.*;
import java.io.*;
import java.math.*;
	        public class Main {
	        	static int check(String s, String t) {
	        		int count = 0;
	        		for(int i = 0;i<s.length();i++) {
	        			if(s.charAt(i) != t.charAt(i)) {
	        				count++;
	        			}
	        		}
	        		return count;
	        	}
	        public static void main(String args[]) throws IOException {
	        	FastReader sc = new FastReader();
	        	
	        	String s = sc.next();
	        	String t = sc.next();
	        	int n = s.length();
	        	int min = Integer.MAX_VALUE;
	        	int nt = t.length();
	        	for(int i = 0;i<=n-nt;i++) {
	        		String res = s.substring(i, i + nt);
	        		min = Math.min(min, check(res, t));
	        	}
	        	pn(min);
	       }
	       static void p(Object p){System.out.print(p);}
	       static void pn(){System.out.println();}
	       static void pn(Object o){System.out.println(o);}
	       
	       static class FastReader {
	       static BufferedReader br;
	       StringTokenizer st;
	       public FastReader() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	       }
	            
	       String next(){
	       while (st == null || !st.hasMoreElements()) {
	            try{
	                st = new StringTokenizer(br.readLine());
	            }
	            catch (IOException  e) {
	                e.printStackTrace();
	            }}
	            return st.nextToken();
	            }
	            
	            int nextInt(){ 
	                return Integer.parseInt(next());
	            }
	            
	            long nextLong(){ 
	                return Long.parseLong(next());
	            }
	            
	            static int max(int[] a){
	            int max = Integer.MIN_VALUE;
	            for(int i : a) max = Math.max(max, i);
	            return max;
	            }
	            
	            public int[] readIntArray(int n) {
	            int[] arr = new int[n];
	            for(int i=0; i<n; ++i) arr[i]=nextInt();
	            return arr;
	            }
	            
	            public long[] readLongArray(int n){
	            long[] arr = new long[n];
	            for(int i=0; i<n; ++i) arr[i]=nextLong();
	            return arr;
	            }
	            
	            public int[][] readIntArray(int m, int n){
	            int[][] arr = new int[m][n];
	            for(int i = 0;i<m;i++) 
	            for(int j = 0;j<n;j++) arr[i][j] = nextInt();
	            return arr;
	            }
	            
	            public String[] readStringArray(int n) {
	            String[] arr = new String[n];
	            for(int i=0; i<n; ++i) arr[i]= nextLine();
	            return arr;
	            }
	            
	            double nextDouble() {return Double.parseDouble(next());}
	            
	            String nextLine() {
	            String str = "";
	            try{str = br.readLine();}
	            catch (IOException e) {e.printStackTrace();}
	            return str;}}
	        }

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

int main() {
  //定義一覧
  int A;
  int B;
  char op;
  
  cin >> A >> op >> B;
  if(op == '+'){
  	cout << A + B << endl;
  }else if(op == '-'){
  	cout << A - B << endl;
  }
}

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

int compare_int(const void *b,const void *a){
  return *(int*)a - *(int*)b;
}

int main(){
  int n,k,i,j;
  int h[200000];
  long long int ans=0;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
 
  qsort(h,n,sizeof(int),compare_int);
  
  for(i=0;i < k;i++){
    h[i] = 0;
  }
  for(i=0;i<n;i++){
    ans += h[i];
  }
  printf("%lld",ans);
}

Measured memory_bytes: 1788
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str;
	cin >> str;

	int result = 0;

	for (int i = 0; i < str.length() / 2; i++)
		if (str[i] != str[str.length() - 1 - i])
			result++;
	
	printf("%d", result);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
#define PI 3.1415926535
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;}
char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}
char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}
int GetDigit(int num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}
ll enum_divisors(ll N) {
    ll res = 0;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res++;
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res++;
        }
    }
    // 小さい順に並び替える
    return res;
}
//input



//processing
int cnt;


//dpTable
//int dp[100050];
int main(){
    double N,D;
    cin >> N >> D;
    vector<double> X(N);
    vector<double> Y(N);
    rep (i,N){
        cin >> X.at(i) >> Y.at(i);
        if (sqrt(pow(X.at(i),2) + pow(Y.at(i),2)) <= D){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 6544
package main

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

func main() {
	n := readInt()
	k := readInt()
	p := readIntSlice(n)

	sort.Slice(p, func(i, j int) bool { return p[i] < p[j] })

	answer := 0
	for i := 0; i < k; i++ {
		answer += p[i]
	}

	fmt.Println(answer)

}

var (
	scanner *bufio.Scanner
)

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.Atoi(t)
	if err != nil {
		log.Fatal(err)
	}

	return n

}

func readIntSlice(n int) []int {
	s := make([]int, n)
	var t string

	for i := 0; i < int(n); i++ {
		if scanner.Scan() {
			t = scanner.Text()
		}

		num, err := strconv.Atoi(t)
		if err != nil {
			log.Fatal(err)
		}
		s[i] = num
	}

	return s
}


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

using namespace std;

void Main() {
    int N;
    cin >> N;
    vector<long long> A(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    vector<long long> sums(N, 0);
    sums[0] = A[0];
    for (int i = 1; i < N; ++i) {
        sums[i] = A[i] + sums[i - 1];
    }
    long long ans = 100000000000001;
    for (int i = 0; i < N - 1; ++i) {
        long long x = sums[i];
        long long y = sums[N - 1] - sums[i];
        ans = min(ans, abs(x - y));
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 6376
n,m=[int(i) for i in input().split()]
pp=[[0 for i in range(2)] for j in range(m)]
not_bridge=0

#深さ優先探索---------------------------------
#参照元：Python3でグラフの実装＆深さ優先探索・幅優先探索の実装
#http://muromura.hatenablog.com/entry/2017/07/16/025414
def dfs(Graph, Start, Vn, Visited=None):
  
##追加（空から読んでも動くように修正）-----------------------
  if Graph[Start]==[] and Visited==None: 
        Next=Start+1
        dfs(Graph, Next, Vn, Visited)  #再帰
  else:
##--------------------------------------------------------

    if (Visited==None): 
        Visited = [] #開始点のときに探索済みリストをつくる
        Visited.append(Start)  #現在の頂点を探索済みリストに加える

    
    if len(Visited)==Vn: #全点訪問済みの場合、橋ではない
        #print(Visited)
        global not_bridge
        if len(set(Visited)) == n:
            not_bridge=not_bridge+1
#        print(Visited)
        return 0
        
    for Next in Graph[Start]:  #次に探索する頂点の候補
        Visited.append(Next)
        #if ( Next in Visited ):  continue  #訪問済みリストにある頂点は飛ばす
        dfs(Graph, Next, Vn, Visited)  #再帰
        Visited.pop()
    return 0
  
#--------------------------------------------------------        

for i in range(m) :
    pp[i] =[int(i) for i in input().split()]
    
#隣接リスト
l = [[] for i in range(n+1)] #頂点の数+1
for pi in pp:  #0-originedに注意、l[0]は空
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])

#print(l)
dfs(l, 0, n)
print(not_bridge)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;

int main(){
  int n;
  cin >> n;
  int c=0;

  for(int i=1; i<n+1; i++){
    if(std::to_string(i).length() % 2 == 1) c++;
  }
  cout << c << endl;



}


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

long long n, m, a, s;
priority_queue<int> pq;
int main() {
	cin >> n >> m;
	while(n--) scanf("%lld", &a), pq.push(a);
	while(m--) {
		a = pq.top(); pq.pop();
		pq.push(a/2);
	}
	while(!pq.empty()) s += pq.top(), pq.pop();
	cout << s;
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int a[1000010],b[1000010];
int main(){
	a[0]=0;b[0]=0;
	for(int i=1;i<=1000010;i++){
		a[i]=i;b[i]=i;
		int j=1;
		while(j++){
			int p=j*(j+1)*(j+2)/6;
			if(i<p)break;
			a[i]=min(a[i],a[i-p]+1);
			if(p%2)b[i]=min(b[i],b[i-p]+1);
		}
	}
	int n;
	while(cin>>n,n){
		cout<<a[n]<<" "<<b[n]<<endl;
	}
	return 0;
}



Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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() {
  string s;
  cin >> s;
  int N = s.size();
  int K;
  cin >> K;

  vector<string> st;
  rep(start, N) {
    repp(end, start, min(N - 1, start + 4)) {
      st.pb(s.substr(start, end - start + 1));
    }
  }
  sort(all(st));
  st.erase(unique(all(st)), st.end());
  cout << st[K - 1] << endl;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin >>a >>b >>k;
  vector<int> s(128);
  int f=0;
 for(int i=1;i<=100;i++){
  if(a%i==0&&b%i==0){
    s.at(f)=i;
    f++;
  } 
     }
  sort(s.begin(),s.end(),greater<int>());
cout << s.at(k-1) <<endl;
  }
    
   
  

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let s1: String = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().chars().collect();
        buf.clear();
        tmp
    };
    let s2: String = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().chars().collect();
        buf.clear();
        tmp
    };
    let mut memo: Vec<Vec<Option<usize>>> = vec![vec![None; s2.len() + 1]; s1.len() + 1];
    for i in 0..s1.len() + 1 {
        for j in 0..s2.len() + 1 {
            memo[i][j] = None;
        }
    }
    let mut length = dp(&s1, &s2, &mut memo);
    let mut i = s1.len();
    let mut j = s2.len();
    let mut ans = vec![0; length];
    while i != 0 && j != 0 {
        if memo[i-1][j].is_none() || memo[i][j-1].is_none() {
            ans[length - 1] = s1.as_bytes()[i - 1];
            length -= 1;
            i -= 1;
            j -= 1;
        } else if memo[i][j-1] == memo[i][j] {
            j -= 1;
        } else if memo[i-1][j] == memo[i][j] {
            i -= 1;
        } else if memo[i-1][j] == memo[i][j-1] && memo[i-1][j] == memo[i-1][j-1] {
            ans[length - 1] = s1.as_bytes()[i - 1];
            length -= 1;
            i -= 1;
            j -= 1;
        } else {
            panic!("wtf");
        }
    }
    let ans: String = String::from_utf8_lossy(&ans).to_string();
    println!("{}", ans);
}

fn dp(s1: &str, s2: &str, memo: &mut Vec<Vec<Option<usize>>>) -> usize {
    let i = s1.len();
    let j = s2.len();
    if s1.len() == 0 || s2.len() == 0 {
        memo[i][j] = Some(0);
        return 0;
    } else if memo[i][j] != None {
        // do nothing
    } else {
        if s1.chars().last() == s2.chars().last() {
            let tmp = dp(&s1[0..i - 1], &s2[0..j - 1], memo);
            memo[i][j] = Some(tmp + 1);
        } else {
            let tmp1 = dp(&s1[0..i - 1], &s2[0..j], memo);
            let tmp2 = dp(&s1[0..i], &s2[0..j - 1], memo);
            if tmp1 > tmp2 {
                memo[i][j] = Some(tmp1);
            } else {
                memo[i][j] = Some(tmp2);
            }
        }
    }
    return memo[i][j].unwrap();
}


Measured memory_bytes: 166524
n,m=map(int,input().split())
S,C=[], []
for i in range(m):
  a,b=map(int,input().split())
  S.append(a)
  C.append(b)
for j in range(10**n):
  if len(str(j))==n and all(str(j)[x-1]==str(y) for x,y in zip(S,C)):
    print(j)
    break;
else:
  print(-1)

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

int main(){
	int n, k;
	cin>>n>>k;
	vector<int>a(n),dp(k+1,0);
	for (int i=0;i<n;i++)
	cin>>a[i];
	
	for(int j=1;j<=k;j++)
	for(int i=0;i<n;i++)
	{
		if(j>=a[i]&&dp[j-a[i]]==0)
		dp[j]=1;
		
	}
	if(dp[k])
	cout<<"First";
	else
	cout<<"Second";
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()

int main(){
    int a;int b;int c;int d;
    cin >> a >> b >> c >> d;
    while(a>0 && c>0){
        c -= b;
        if(c<=0){
            cout << "Yes" << endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout<<"No" << endl;
            break;
        }

    }
}

Measured memory_bytes: 3108
""" B
    https://atcoder.jp/contests/abc175/tasks/abc175_b
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return [readIntegerSet(m) for _ in range(0, n)]

def main(T, S):
    best = sys.maxsize
    for i in range(len(T)-len(S)+1):
        s = T[i:i+len(S)]
        count = 0
        for j in range(len(S)):
            if s[j] != S[j]:
                count += 1
        if best > count:
            best = count
    return best


if __name__ == "__main__":
    _T = readString().rstrip()
    _S = readString().rstrip()

    print(main(_T, _S))


Measured memory_bytes: 9440
#include<stdio.h>

int main(void) {
	int a, b, x;

	scanf("%d %d %d", &x, &a, &b);

	if (0 >= b - a) {
		printf("delicious\n");
	}
	else if (x >= b - a) {
		printf("safe\n");
	}
	else {
		printf("dangerous\n");
	}
}


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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

string s[8];

int main(void){
  int h, w;
  cin >> h >> w;
  int c = 0;
  REP(i, 0, h) {
    cin >> s[i];
    REP(j, 0, w) {
      c += s[i][j] == '#';
    }
  }
  cout << (c == h + w - 1 ? "Possible" : "Impossible") << endl;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

std::vector<bool> sieve;
std::vector<int> primes;

void eratosthenes(int maximum){
	sieve = std::vector<bool>(maximum+1);
	sieve[0]=sieve[1]=false;
	for(int i=2; i<sieve.size(); i++) sieve[i]=true;
	for(int j=4; j<sieve.size(); j+=2) sieve[j]=false;
	for(int i=3; 2*i<sieve.size(); i++){
		if(!sieve[i]) continue;
		for(int j=2*i; j<sieve.size(); j+=i) sieve[j] = false;
	}
}

void get_primes(int maximum){
	if(sieve.size() < maximum) eratosthenes(maximum);
	for(int i=2; i<sieve.size(); i++){
		if(sieve[i]) primes.push_back(i);
	}
}

std::map<long long, int> get_factors(long long x){
	std::map<long long, int> factors;
	for(int p: primes){
		if(p*p>x) break;
		while(x%p==0){
			factors[p]++;
			x /= p;
		}
	}
	if(x>1) factors[x]++;
	return factors;
}

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;
	get_primes(10000000);

	ll n; cin >> n;

	int ans = 0;
	for(int p: primes){
		if(n==1) break;
		if(n%p) continue;

		int e = 0;
		while(n%p==0){
			n/=p;
			e++;
		}

		int i=1;
		while(e-i>=0){
			e-=i;
			i++;
			ans++;
		}
	}

	if(n>1) ans++;

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 8588
# ABC088C - Takahashi's Information
def main():
    arr = [list(map(int, input().rstrip().split())) for _ in range(3)]
    memo = []
    for i, j, k in arr:
        memo += [(i - j, j - k)]
    flg = True if memo[0] == memo[1] and memo[1] == memo[2] else False

    memo = []
    for i in range(3):
        i, j, k = arr[0][i], arr[1][i], arr[2][i]
        memo += [(i - j, j - k)]
    flg = True if memo[0] == memo[1] and memo[1] == memo[2] else False
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 100; int n;
const lli inf = 1e18;
int x[maxN];

int main()
{
  while (scanf("%d", &n) != EOF)
  {
    for (int i = 0; i < n; i ++)
      scanf("%d", &x[i]);

    lli ans = inf;
    for (int p = 1; p <= 100; p ++)
    {
      lli c = 0;
      for (int i = 0; i < n; i ++)
        c += (x[i] - p)*(x[i] - p);
      ans = min(ans, c);
    }
    printf("%lld\n", ans);
  }
  return 0;
}

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

int main() {
	long S;
  	cin >> S;
  
  	vector<int> vec(0);
  
  	while(S >= 111) {
    	vec.push_back(abs(S % 1000 - 753));
      	S /=  10;
    }
  
  	sort(vec.begin(),vec.end());
  
  	cout << vec.at(0) << endl;
}


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

int main(){
    int n;
    int x[100]={};
    int y[100]={};
    double a,b,D;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        cin>>y[i];
    }
    for(double j=1;j<=3;j++){
        a=0;
        D=0;
        for(int i=0;i<n;i++){
            a+=pow(fabs(x[i]-y[i]),j);
        }
        D=pow(a,(1/j));
        printf("%lf\n",D);
    }
    for(int i=0;i<n;i++){
        if(fabs(x[i]-y[i])>b){
            b=fabs(x[i]-y[i]);
        }
    }
    printf("%lf\n",b);

    return 0;
}


Measured memory_bytes: 3356
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll a=0;
    for(int i=0;i<s.length();i++){
        a+= (ll)(s[i]-'0');
    }
    if(a%9==0){
        Yes;
    }
    else{
        No;
    }
    

    


	return 0;
}


Measured memory_bytes: 3744
import math

x=int(input())
s=math.floor(x/3)
f=math.floor(x/5)
sf=math.floor(x/15)
sum=math.floor(x*(x+1)/2)

s_sum=math.floor(3*s*(s+1)/2)
f_sum=math.floor(5*f*(f+1)/2)
sf_sum=math.floor(15*sf*(sf+1)/2)

fl=sum-(s_sum+f_sum-sf_sum)
print(math.floor(fl))


Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a == 7) {
			if(b == 5 && c == 5) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
		else if (b == 7) {
			if(a == 5 && c == 5) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
		else if(c  == 7) {
			if(a == 5 && b == 5) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 35740
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if B < A:
    A, B = B, A

related_speed = W - V
if W > V:
    print("NO")
elif B - A <= (V - W) * T:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3568
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
#define ll 5000000000000000
using namespace std;
int a[101];
string s;
int main(){
	ios::sync_with_stdio(false);
	int i,l;
	cin>>s;
	l=s.size() ;
	for(i=0;i<l;i++){
		a[i]=s[i]-'0';
	}
	int k;
	cin>>k;
	int m=k,q;
	for(i=0;i<l;i++){
		if(a[i]==1){
			m-=1;
		}else{
			m-=pow(a[i],ll);
		}
		if(m<=0){
			q=a[i];
			break;
		}
	}
	cout<<q<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include <ctype.h>
#include <sstream>
using namespace std;
using Graph = vector<vector<int>>;
#define  itn int
using ll=int64_t;
#define rep(i,n) for (int i = 0; i < (int) (n); i++)
using vi = vector<int>;
using vll = vector<ll>;
//GCD
long long gcd(long long a, long long b)
{if(a<b) swap(a,b);
   if (a%b == 0){return(b);}
   else{return(gcd(b, a%b));}
}
//lcm
long long lcm(long long a, long long b)
{return a * b / gcd(a, b);}

long long bikkuri(long long k){
    long long sum = 1;
    for (long long i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
int main() {
char a;
cin>>a;
if(a >= 'a' && a <= 'z')
cout<<'a';
if(a >= 'A' && a <= 'Z')
cout<<'A';

}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int main() {
	int N;
	cin >> N;
	vector<int> v;
	rep(i, N) {
		int p;
		cin >> p;
		if (p == i + 1) v.push_back(i);
	}
	int ans = 0;
	rep(i, v.size()) {
		ans++;
		if (i + 1 < v.size() && v[i] + 1 == v[i + 1]) i++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0},w,h,t,d[101][101];
string s[101];
typedef pair<int,int> P;
queue<P>q;
void dfs(int a,int b,char p){
  d[a][b]=t;
  r(i,4){
    int y=a+dy[i],x=b+dx[i];
    if(y>=0&&x>=0&&y<h&&x<w){
      if(d[y][x]==1e9){
        if(s[a][b]==s[y][x])dfs(y,x,p);
        else q.push(P(y,x));
      }
    }
  }
}
int main(){
  while(cin>>w>>h,w){
    while(!q.empty())q.pop();
    r(i,h)r(j,w)d[i][j]=1e9;
    r(i,h)cin>>s[i];
    r(i,h)r(j,w)if(s[i][j]=='&'){
      s[i][j]='.';t=0;
      dfs(i,j,s[i][j]);
    }
    r(i,1e9){
      if(i%2==0)t++;
      if(q.empty())break;
      queue<P>pp;
      while(!q.empty())pp.push(q.front()),q.pop();
      while(!pp.empty()){
        P pt=pp.front();pp.pop();
        int y=pt.first,x=pt.second;
        if(d[y][x]==1e9)dfs(y,x,s[y][x]);
      }
    }
    int ans=1e9;
    r(i,h)ans=min(ans,min(d[i][0],d[i][w-1]));
    r(i,w)ans=min(ans,min(d[0][i],d[h-1][i]));
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3760
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

def hurui(n):
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data
pp = hurui(1500)

N = int(input())

tmp = 0
ans = []
for p in pp:
	if p%5 == 1:
		ans.append(p)
		tmp += 1
	if tmp == N:
		break

print(' '.join(map(str,ans)))


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

using namespace std;

int arr_x[100],arr_y[100],arr_h[100];

bool is_ok(int cx, int cy, int ch, int x, int y, int h) {
	int calced_h = max(ch-abs(cx-x)-abs(cy-y),0);
	return h == calced_h;
}

int get_h(int cx, int cy, int x, int y, int h) {
	int dist = abs(cx-x)+abs(cy-y);
	return h+dist;
}

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> arr_x[i] >> arr_y[i] >> arr_h[i];
	}
	for(int cx = 0; cx <= 100; cx++) {
		for(int cy = 0; cy <= 100; cy++) {
			int ch = -1;
			for(int i = 0; i < n; i++) {
				if(arr_h[i]>0) {
					ch = get_h(cx,cy,arr_x[i],arr_y[i],arr_h[i]);
					break;
				}
			}
			//cout << "ch = " << ch << endl;
			bool flag = true;
			for(int i = 0; i < n; i++) {
				flag &= is_ok(cx,cy,ch,arr_x[i],arr_y[i],arr_h[i]);
			}
			if(flag) {
				cout << cx << " " << cy << " " << ch << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    if(N % 2 == 1) {
        int cnt = 1;
        ll ret = 0;
        for(int i = 0;i < N / 2;i++) {
            ret += vec.at(cnt);
            cnt += 2;
        }
        cnt = 1;
        vector<ll> left(N / 2 + 1);
        vector<ll> right(N / 2 + 1);
        for(int i = 0;i < N / 2;i++) {
            left.at(i + 1) = left.at(i) + (vec.at(cnt - 1) - vec.at(cnt));
            cnt += 2;
        }
        cnt = N - 2;
        for(int i = 0;i < N / 2;i++) {
            right.at(i + 1) = right.at(i) + (vec.at(cnt + 1) - vec.at(cnt));
            cnt -= 2;
        }
        ll cnt2 = 0;
        ll Max = 0;
        for(int i = N / 2;i >= 0;i--) {
            Max = max(Max,right.at(N / 2 - i));
            cnt2 = max(cnt2,Max + left.at(i));
        }
        cout << ret + cnt2 << endl;
    }
    else {
        int cnt = 1;
        ll ret = 0;
        for(int i = 0;i < N / 2;i++) {
            ret += vec.at(cnt);
            cnt += 2;
        }
        cnt = 1;
        vector<ll> left(N / 2 + 1);
        for(int i = 0;i < N / 2;i++) {
            left.at(i + 1) = left.at(i) + (vec.at(cnt - 1) - vec.at(cnt));
            cnt += 2;
        }
        ll cnt2 = 0;
        for(int i = N / 2;i >= 0;i--) {
            cnt2 = max(cnt2,left.at(i));
        }
        cout << ret + cnt2 << endl;
    }
}

Measured memory_bytes: 6428
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, A, B = rdi()

if A > B:
        print 0
elif N == 1:
        if A == B:
                print 1
        else:
                print 0
else:
        print (B-A)*(N-2)+1


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

int main() {

	int N,K,R,S,P,score=0;
  string T;
  cin>>N>>K>>R>>S>>P>>T;
  map<char,int> es;
  es['r']=P;
  es['s']=R;
  es['p']=S;
  for(int i=0; i<N;i++)
  {
    if(i>=K)
    {
      char a,b,c;   
      a=T.at(i-K); b=T.at(i);
      //if(i+K<N){c=T.at(i+K);}
      if(a==b){T.at(i)='l';}
      else{score += es.at(b);}     
    }
    else{score+=es.at(T.at(i));}
   }
cout<<score<<endl;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] a = sc.nextIntArray(n);
    StringBuilder sb = new StringBuilder();
    while (k-- > 0) {
      sb.delete(0, sb.length());
      int[] b = new int[n];
      for (int i = 0; i < n; i++) {
        b[Math.max(0, i - a[i])]++;
        if (i + a[i] < n - 1) b[i + a[i] + 1]--;
      }
      int min = n;
      a[0] = b[0];
      for (int i = 1; i < n; i++) {
        a[i] = a[i - 1] + b[i];
        min = Math.min(min, a[i]);
      }
      if (min == n) break;
      if (min < 0) {
        for (int i = 0; i < n; i++) a[i] -= min;
      }
    }
    for (int i = 0; i < n; i++) {
      if (sb.length() > 0) sb.append(" ");
      sb.append(a[i]);
    }
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 56080
H, W = map(int, input().split())
S = [['.']*(W + 2)] + [list('.' + input() + '.') for _ in range(H)] + [['.']*(W + 2)]
# print(S)
# 上下左右に隣り合う黒がいない黒を探す
for i in range(1, H):
    for k in range(1, W):
        if S[i][k] == '#' and S[i][k - 1] != '#' and S[i - 1][k] != '#' and S[i][k + 1] != '#' and S[i + 1][k] != '#':
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
if __name__ == "__main__":
    N, K = map(int, input().split())
    ab = list()
    for i in range(N):
        ab.append(list(map(int, input().split())))
    
    ab = sorted(ab)

    res = K
    for i in range(N):
        res -= ab[i][1]
        if res <= 0:
            print(ab[i][0])
            exit()


Measured memory_bytes: 28640
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

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;
}

/*-----Library-----*/
int n,a,b;
int h[114514];
P max_h(){
    P re=P(h[0],0);
    for(int i=1;i<n;i++){
        if(re.first<h[i]){
            re=P(h[i],i);
        }
    }
    return re;
}
int dp[3100][6100];
signed main(){
    int n,t;
    cin>>n>>t;
    P f[114514];
    for(int i=0;i<n;i++){
        cin>>f[i].first>>f[i].second;
    }
    sort(f,f+n);
    int p=f[n-1].first;
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=0;i<=t+p;i++){
        dp[0][i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=t+p;j++){
            if(j>=f[i].first){
                if(j-f[i].first<t)dp[i+1][j]=max(dp[i][j],dp[i][j-f[i].first]+f[i].second);
                else dp[i+1][j]=max(dp[i][j],dp[i+1][j-1]);
            }
            else dp[i+1][j]=max(dp[i][j],dp[i+1][j-1]);
        }
    }
    
    cout<<dp[n][t+p]<<endl;
}



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

int main()
{
    int N,K,X,Y;
    cin>>N>>K>>X>>Y;
    if(N<=K){
        cout<<N*X<<endl;
    }else{
        cout<<(N-K)*Y+K*X<<endl;
    }
    return 0;
}


Measured memory_bytes: 256