akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        Task task = new Task();
        task.solve(sc, out);
        out.flush();
        sc.close();
    }
    static class Task{
        public void solve(Scanner sc, PrintWriter out){
            long N = nlong(sc);
            long K = nlong(sc);

            if (K==0){
                out.println(N*N);
            }else{
                long count=0;
                for (long b = K+1; b <= N; b++){
                    long p = N / b;
                    long r = N - p * b;

                    count += p * Math.max(0, b - K);
                    count += Math.max(0, r - K + 1);
                }
                out.println(count);
            }

        }
    }

    static int nint(Scanner sc){
        return Integer.parseInt(sc.next());
    }
    static long nlong(Scanner sc){
        return Long.parseLong(sc.next());
    }
    static double ndouble(Scanner sc){
        return Double.parseDouble(sc.next());
    }
    static float nfloat(Scanner sc){
        return Float.parseFloat(sc.next());
    }
    static String nstr(Scanner sc){
        return  String.valueOf(sc.next());
    }
    static long[] longLine(Scanner sc, int size){
        long[] lLine = new long[size];
        for (int i = 0; i < size; i++) {
            lLine[i] = nlong(sc);
        }
        return lLine;
    }
    static int[] intLine(Scanner sc, int size){
        int[] iLine = new int[size];
        for (int i = 0; i < size; i++) {
            iLine[i] = nint(sc);
        }
        return iLine;
    }
    static String[] strLine(Scanner sc, int size){
        String[] strLine = new String[size];
        for (int i = 0; i < size; i++) {
            strLine[i] = nstr(sc);
        }
        return strLine;
    }
}

Measured memory_bytes: 23764
@n = gets.chomp
@l = @n.size
k = gets.to_i

def calc(i, k, b = false, c = false)
    return 0 if k < 0

    return (k == 0 ? 1 : 0) if i == @l
    m = @n[i].to_i

    if b && m == 0
        calc(i+1, k, b)
    elsif b
        calc(i+1, k) + (m-1) * calc(i+1, k-1) + calc(i+1, k-1, b)
    elsif c
        calc(i+1, k, b, c) + 9 * calc(i+1, k-1)
    else
        calc(i+1, k) + 9 * calc(i+1, k-1)
    end
end

p calc(1, k, false, true) + (@n[0].to_i - 1) * calc(1, k-1) + calc(1, k-1, true)

Measured memory_bytes: 1788
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, A, B := getInt(), getInt(), getInt()
	x := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = getInt()
	}
	ans := 0
	for i := 1; i < N; i++ {
		c0 := (x[i] - x[i-1]) * A
		if c0 > B {
			ans += B
		} else {
			ans += c0
		}
	}
	out(ans)
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

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

	vector<int> dp(n + 2, 1e9);

	dp[1] = 0;
	for(int i = 1; i < n; ++i){
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[n];

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
static const double EPS = 1e-5;
 
int main() {
    double d;
    cin >> d;
     
    double ans = 0;
     
    if (d < 1.0) ans = sqrt(2.0) * d;
     
    for (int r = 1; r <= 10; ++r) {
        double lb = (double)r, ub = sqrt(1.0 + (double)(r * r));
         
        if (lb < d + EPS && d < ub + EPS) {
            ans = max(sqrt(2.0) * d, (double)(r + 1));
            break;
        } else if (ub < d && d < (double)(r + 1) + EPS) {
            ans = sqrt(2.0) * d;
            break;
        }
    }
     
    printf("%.12f\n", ans);
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli n;
	cin>>n;

	REP(i,1,10){
		REP(j,1,10){
			if(i*j==n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}

	cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define MAX_N 1001
int EditDistance(std::string a,std::string b){
        int dp[MAX_N][MAX_N];
        int i,j,cost;
        int len_a=a.length()+1,len_b=b.length()+1;

        for(i=0;i<len_a;i++)
                dp[i][0]=i;
        for(i=0;i<len_b;i++)
                dp[0][i]=i;
        for(i=1;i<len_a;i++)
                for(j=1;j<len_b;j++){
                        cost=a[i-1]==b[j-1]?0:1;
                        dp[i][j]=std::min(dp[i-1][j-1]+cost,std::min(dp[i-1][j]+1,dp[i][j\
-1]+1));
                }

        return dp[len_a-1][len_b-1];
}

int main(){
        std::string a,b;
        std::cin>> a>>b;
        std::cout<<EditDistance(a,b)<<std::endl;
        return 0;
}

Measured memory_bytes: 7052
from collections import Counter

N = map(int, input().split())
A_list = list(map(int, input().split()))

L = []
R = []
for i, a in enumerate(A_list, start=1):
    L.append(i+a)
    R.append(i-a)

c_R = Counter(R)
c_L = Counter(L)

ans = 0
for r, cnt in c_R.items():
    ans += cnt * c_L.get(r, 0)

print(ans)


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

void solve(long long N, std::vector<long long> A){
    VPii a(N);
    REP(i,0,N){
        a[i]=mp(A[i],i+1);
    }
    sort(ALL(a));
    REP(i,0,N) cout<<a[i].second<<" ";
    cout<<endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

using namespace std;
using ll = long long;

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

    int x;

    for(int i = 1; i <= 5; ++i) {
        cin >> x;
        if(x == 0) {
            cout << i << "\n";
            return 0;
        }
    }

    return 0;
}

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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;

    vector<pair<int, int>> e;
    if (N % 2 == 1) {
        e.emplace_back(1, N);
        e.emplace_back(N, N - 1);
        for (int i = 2; i <= N / 2; ++i) {
            for (int j = 1; j < i; ++j) {
                e.emplace_back(i, j);
                e.emplace_back(N - i, j);
            }
            for (int j = N - i + 1; j <= N; ++j) {
                e.emplace_back(N - i, j);
                e.emplace_back(i, j);
            }
        }
    } else {
        e.emplace_back(1, 2);
        e.emplace_back(1, N - 1);
        e.emplace_back(2, N);
        e.emplace_back(N - 1, N);
        for (int i = 3; i <= N / 2; ++i) {
            for (int j = 1; j < i; ++j) {
                e.emplace_back(i, j);
                e.emplace_back(N - i + 1, j);
            }
            for (int j = N - i + 2; j <= N; ++j) {
                e.emplace_back(N - i + 1, j);
                e.emplace_back(i, j);
            }
        }
    }


    cout << e.size() << "\n";
    for (const auto &p : e) {
        cout << p.first << " " << p.second << "\n";
    }



    return 0;
}

Measured memory_bytes: 384
import pprint
H, W = list(map(int, input().split()))
S = []
for h in range(H):
    S.append([c for c in input()])
# pprint.pprint(S)
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            count = 0
            for pos_y in [-1, 0, 1]:
                for pos_x in [-1, 0, 1]:
                    y = h + pos_y
                    x = w + pos_x
                    if x < 0 or x >= W or y < 0 or y >= H:
                        continue
                    if S[y][x] == "#":
                        count += 1
            S[h][w] = str(count)
# pprint.pprint(S)
S = ["".join(s) for s in S]
S = "\n".join(S)
print(S)

Measured memory_bytes: 3700
package main

import (
  "bufio"
  "container/heap"
  "fmt"
  "os"
  "strconv"
  "strings"
)

const INF = 1<<30

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,10000)}
  n := input.NextInt()
  p := input.NextIntArray()
  odd := NewSegmentTree(n)
  evn := NewSegmentTree(n)
  pos := make([]int,n+1)
  for i:=0;i<n;i++ {
    if i%2 == 0 {
      evn.Update(i,p[i])
    } else {
      odd.Update(i,p[i])
    }
    pos[p[i]] = i
  }
  pq := PriorityQueue{}
  heap.Push(&pq,&Item{evn.Query(0,n),0,n})
  ans := make([]int,n)
  for i:=0;i<n; {
    i0 := heap.Pop(&pq).(*Item)
    p0 := i0.val
    p1 := evn.Query(pos[p0]+1,i0.r)
    if (pos[p0]+1)%2 == 1 { p1 = odd.Query(pos[p0]+1,i0.r) }
    ans[i] = p0
    ans[i+1] = p1
    i += 2
    i1 := Item{odd.Query(i0.l,pos[p0]),i0.l,pos[p0]}
    if i0.l%2 == 0 { i1 = Item{evn.Query(i0.l,pos[p0]),i0.l,pos[p0]} }
    i2 := Item{odd.Query(pos[p0]+1,pos[p1]),pos[p0]+1,pos[p1]}
    if (pos[p0]+1)%2 == 0 { i2 = Item{evn.Query(pos[p0]+1,pos[p1]),pos[p0]+1,pos[p1]} }
    i3 := Item{odd.Query(pos[p1]+1,i0.r),pos[p1]+1,i0.r}
    if (pos[p1]+1)%2 == 0 { i3 = Item{evn.Query(pos[p1]+1,i0.r),pos[p1]+1,i0.r} }
    heap.Push(&pq,&i1)
    heap.Push(&pq,&i2)
    heap.Push(&pq,&i3)
  }
  fmt.Print(ans[0])
  for i:=1;i<n;i++ { fmt.Print(" ");fmt.Print(ans[i]) }
  fmt.Println()
}

type Item struct { val,l,r int }
type PriorityQueue []*Item
func(pq PriorityQueue) Len() int { return len(pq) }
func(pq PriorityQueue) Less(i,j int) bool { return pq[i].val < pq[j].val }
func(pq PriorityQueue) Swap(i,j int) { pq[i],pq[j] = pq[j],pq[i] }
func(pq *PriorityQueue) Push(x interface{}) {
  item := x.(*Item)
  *pq = append(*pq,item)
}
func(pq *PriorityQueue) Pop() interface{} {
  old := *pq
  n := len(old)
  item := old[n-1]
  *pq = old[0:n-1]
  return item
}

type SegmentTree struct { n,p int;c []int }
func NewSegmentTree(n int) SegmentTree {
  p := 1
  for p < n { p *= 2 }
  c := make([]int,2*p-1)
  for i:=0;i<2*p-1;i++ { c[i] = INF }
  return SegmentTree{n,p,c}
}
func op(a,b int) int {
  if a < b { return a }
  return b
}
func(st SegmentTree) Update(i int,c int) {
  i += st.p-1
  st.c[i] = c
  for i > 0 {
    i = (i-1)/2
    st.c[i] = op(st.c[2*i+1],st.c[2*i+2])
  }
}
func(st SegmentTree) Query(l,r int) int {
  l += st.p-1
  r += st.p-1
  ret := INF
  for l < r {
    if l%2 == 0 { ret = op(ret,st.c[l]) }
    if r%2 == 0 { ret = op(ret,st.c[r-1]) }
    l = l/2
    r = (r-1)/2
  }
  return ret
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextIntArray() []int {
  s := strings.Fields(i.NextLine())
  a := make([]int,len(s))
  for i:=0;i<len(s);i++ { a[i],_ = strconv.Atoi(s[i]) }
  return a
}

Measured memory_bytes: 31900
#include <stdio.h>

int get_month_days(int year, int month) {
  if (year % 3 == 0) {
    return 20;
  } else {
    return month % 2 == 0 ? 19 : 20;
  }
}

/* 1??´1???1??\???????????\??°??????????????? */
int get_days(int year, int month, int day) {
  int nday = 0, y, m, d;
  
  for (y = 1; y <= year; y++) {
    for (m = 1; m <= 10; m++) {
      d = get_month_days(y, m);
      if (year == y && month == m) {
        nday += day;
        break;
      } else {
        nday += d;
      }
    }
  }

  return nday;
}

int main(void) {
  int n, y, m, d, mdays, birth;

  mdays = get_days(1000, 1, 1);
  scanf("%d", &n);
  
  while (n > 0) {
    scanf("%d %d %d", &y, &m, &d);
    birth = get_days(y, m, d);
    printf("%d\n", mdays - birth);
    
    n--;
  }
  
  return 0;
}

Measured memory_bytes: 596
k = input()
k = int(k)

ll = []
for i in range(1, k + 1):
    l = []
    for j in range(1, i + 1):
        if i % j == 0:
            l.append(j)
            l.append(i // j)
        if (i // j) < j:
            break
    ll.append(set(l))


sum_k = 0

for i in range(k):
    i_s = ll[i]
    for j in range(k):
        j_s = ll[j]
        m = max(ll[i] & ll[j])
        if m == 1:
            sum_k += k
            continue
        for l in range(k):
            sum_k += max(ll[i] & ll[j] & ll[l])

print(sum_k)


Measured memory_bytes: 9236
//******* It's LEVI_17 ***************

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

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################


void solve()
{
    ll n;
    cin >> n ;
    if (n == 0)
        cout << 1 << "\n";
    else
        cout << 0 << "\n";
}

//###############################################################################################

int main()
{
    fast;
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    rr;
}


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 3548
s = list(input())
t = list(input())

S = sorted(s)
T = sorted(t, reverse = True)


U = min(len(s), len(t))

for i in range(U):
    if S[i] < T[i]:
        print("Yes")
        exit()
    elif S[i] == T[i]:
        continue
    else:
        print("No")
        exit()
    
if len(S) < len(T):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61884
#include<iostream>
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  int a[n],b[n],c[n-1];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
    ans+=b[i];
  }
  for(int i=0;i<n-1;i++){
    cin>>c[i];
  }
  for(int i=0;i<n-1;i++){
    if(a[i+1]-a[i]==1)ans+=c[a[i]-1];
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
k=2
a=list(map(int,input().split()))
res=[float('INF') for _ in range(n+1)]
res[0]=0
res[1]=0
res[2]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(k+1):
        if i+1-j<1:
            break
        res[i+1]=min(res[i+1],res[i+1-j]+abs(a[i]-a[i-j]))
print(res[n])

Measured memory_bytes: 53180
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  string s; cin >> s;
  int cnt = 15 - s.size();
  REP(i, s.size()){
    if(s[i] == 'o') cnt++;
  }
  if(cnt >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

main()
{
	IO;
	int n,w;
	cin>>n>>w;
	
	vector<pair<long long,long long>> v(n);
	
	for(int i=0;i<n;i++)
	{
		cin>>v[i].first>>v[i].second;
	}
	
	long long dp[w+1]={0};
	
	dp[v[0].first]=v[0].second;
	
	for(int i=1;i<n;i++)
	{
		for(int j=w;j>=v[i].first+1;j--)
		{
			if(dp[j-v[i].first])
			{
				dp[j]=max(dp[j],dp[j-v[i].first]+v[i].second);
			}
		}
		
		dp[v[i].first]=max(dp[v[i].first],v[i].second);
	}
	
	long long ans=0;
	
	for(int j=1;j<=w;j++)
	ans=max(ans,dp[j]);
	
	cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >>N;

	int sum=0;
	for(int i=0;i<N;i++){
		int x,y;
		cin>>x>>y;
		sum += (y-x+1);
	}
	cout <<sum<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,c; cin >> a >> b >> c;
    if(a+b<c)cout << "NA" << endl;
    else cout << max(0LL,c-a)<< endl;
}





Measured memory_bytes: 3088
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;
int main(){
  int n,k;cin>>n>>k;
  vector<int> ans(k,0);
  for(int i=0;i<n;i++){
    if(i<k){
      ans[i]++;
    }else{
      ans[0]++;
    }
  }
  cout<<ans[0]-ans[k-1]<<endl;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


ll dp[2010][2010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<P>vec(n);
  rep(i,n){
    ll x;
    cin >> x;
    vec[i]=P(x,i);
  }
  sort(vec.begin(),vec.end(),greater<P>());
  ll ans=0;
  rep(l,n){
    rep(r,n){
      if(l+r==n){
        chmax(ans,dp[l][r]);
        break;
      }
      else{
        chmax(dp[l+1][r],dp[l][r]+vec[l+r].first*(abs(l-vec[l+r].second)));
        chmax(dp[l][r+1],dp[l][r]+vec[l+r].first*(abs(n-1-r-vec[l+r].second)));
              
      }
    }
  }
  cout << ans << endl;
        
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll count(ll n){
    ll digits=0;
    while(n>0){
        n/=10;
        digits+=1;
    }
    return digits;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    ll ans=21;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
            int k=max(count(i),count(n/i));
            if(k<ans)
                ans=k;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// last edited at 25.8.2015 by charis 

#include<iostream>
using namespace std;


/*
void  insertionSort(A, N){ // N??????????´??????????0-?????????????????????A
	for (int i=1; i<N; i++){
		int v=A[i];
		int j=i-1;
		while(j>=0 && A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1] =v; 
		for(int k=0; k<N; k++){
			if(k==N-1) cout << A[N-1] <<endl;
			else cout << A[k] << " " ;

		}
	}
}
*/

int main(){
	int N;
	cin >> N;
	
	int A[N];
	for(int k=0; k<N; k++){
		cin  >> A[k] ;
	}

	for(int k=0; k<N; k++){
		if(k==N-1)cout << A[N-1]<< endl;
		else cout << A[k] << " ";
	}	
	//insertionSort(A, N);
	for (int i=1; i<N; i++){
		int v=A[i];
		int j=i-1;
		while(j>=0 && A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1] =v; 
		for(int k=0; k<N; k++){
			if(k==N-1) cout << A[N-1] << endl;	
			else cout << A[k] << " " ;
		}
	}
	
	return 0;
}

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

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

    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, k) ans += a[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
a,b,c,x,y = map(int,input().split())

ans = 0
if min(x,y)==x:
    ans += x*min(a+b,2*c)
    y -= x
    x = 0
else:
    ans += y*min(a+b,2*c)
    x -= y
    y = 0
    
if x == 0:
    ans += y*min(b, 2*c)
else:
    ans += x*min(a, 2*c)

print(ans)

Measured memory_bytes: 3064
/// Be Kind :)
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")

/*				I take you to the candy shop								*/

/*				Ooooh ooh, it's me, myself and I
				Solo ride until I die, cause I got me for life				*/

/*				So I ball So hard, muh'fuckas wanna find me					*/
 
/*				Bitch, where you when I was walkin'?
				Now I run the game, got the whole world talkin'				*/
 
/*				Niggas been counting me out
				I'm counting my bullets, I'm loading my clips
				I'm writing down names, I'm making a list					*/
 
/*				You never liked us anyway, fuck your friendship, I meant it */
 
/*				The Chanel or Balenciaga, Louis and Vuitton
				She know I got Fendi, Prada when I hit Milan				*/
 
/*				I ran away, I don't think I'm coming back home				*/
 
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn=5e3+10, maxm=1e5+10, lg=17, mod=1e9+7, inf=1e18;

ll n,a,b,p[maxn],we[maxn],dp[maxn][maxn],ps[maxn][maxn];

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++) cin>>p[i], we[p[i]]=i;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(j==we[i]) dp[i][j]=ps[i-1][j-1];
			else dp[i][j]=ps[i-1][j]+(j<we[i] ? b:a);
			ps[i][j]=dp[i][j];
			if(j) ps[i][j]=min(ps[i][j],ps[i][j-1]);
			//cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
		}
	}
	cout<<ps[n][n];

	return 0;
}






Measured memory_bytes: 392192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  string S;
  cin >> S;
  int mx = 0;
  int cnt = 0;
  rep(i, S.size())
  {
    if (S[i] == 'R')
      cnt++;
    else
    {
      mx = std::max(mx, cnt);
      cnt = 0;
    }
  }

  mx = std::max(mx, cnt);

  cout << mx << endl;

  return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<memory.h>
#include<stdlib.h>
int main(void)
{
	unsigned long long n, a, b, i, k, s1, s2;
	scanf("%llu", &n);
	scanf("%llu %llu", &s1, &s2);
	for (i = 1; i < n; i++)
	{
		scanf("%llu %llu", &a, &b);
		unsigned long long m = (s1 / a>s2 / b) ? (s1 / a) : (s2 / b);
		k = m;
		for (k = m;; k++)
		{
			if ((k*a >= s1) && (k*b >= s2))
			{
				s1 = k*a;
				s2 = k*b;
				break;
			}
		}
	}
	printf("%llu", s1 + s2);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n;
  cin >> n;
  vector<int> t(n);
  REP(i,n) cin >> t[i];
  
  int m;
  cin >> m;
  vector<int> p(m), x(m);
  REP(i, m){
    cin >> p[i] >> x[i];
    p[i]--;
  }
  
  vec ans(m, 0);
  REP(i, m) REP(j, n){
    if(j == p[i]) ans[i] += x[i];
    else ans[i] += t[j];
  }

  REP(i, m){
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 256
require "prime"

inputs = []
loop do 
  n = gets.to_i
  break if n == 0
  inputs << n
end 

primes = Prime.take_while {|x| x <= inputs.max }.to_a
inputs.each do |i|
  limit = i / 2
  cnt = 0
  primes.take_while {|x| x <= limit }.each {|p| cnt += 1 if primes.bsearch {|x| (i - p) <=> x } }
  puts cnt
end

Measured memory_bytes: 15828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll l,r;
	cin>>l>>r;
	map<ll,ll>ch;
	for(ll i=2;i<=1000000;i++){
		if(l%i==0){
			ch[i]++;
		}
		while(l%i==0){
			l/=i;
		}
	}
	if(l!=1){
	ch[l]++;
	}
	for(ll i=2;i<=1000000;i++){
		if(r%i==0){
			ch[i]++;
		}
		while(r%i==0){
			r/=i;
		}
	}
	if(r!=1){
	ch[r]++;
	}
	ll ans=1;
	for(auto itr=ch.begin();itr!=ch.end();itr++){
		ans+=(itr->second)/2;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)


int main(){
    int N;cin >> N;
    vector<LL> A(N,0);
    map<LL,bool> L;
    rep(i,N){
        cin >> A[i];
        L[A[i]] = false;
    }
    rep(i,N)L[A[i]] = !L[A[i]];
    LL ans = 0;
    for(auto itr = L.begin() ; itr != L.end() ;itr++)if(itr -> S)ans++;
    cout << ans << endl;


}


Measured memory_bytes: 7296
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = 0;
        int y = 0;
        int z = 0;
        if (n < m / 10000) {
            System.out.println("-1 -1 -1");
            return;
        }
        x = m / 10000;
        while (x >= 0) {
            y = n - x;
            while (y >= 0) {
                z = n - x - y;
                if (x * 10000 + y * 5000 + z * 1000 == m) {
                    System.out.println(x + " " + y + " " + z);
                    return;
                }
                y--;
            }
            x--;
        }
        System.out.println("-1 -1 -1");
    }

}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
const int N = 3005;
const int mod = 1e9 + 7;
using namespace std;

int n, m, a[N], dp[N][N], cnt[N], Max;
string s;

void add(int&a, int b){
    a += b; if (a >= mod) a -= mod;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> s; s = '.' + s;
    for (int i = 1; i <= n; i++) cnt[i] = cnt[i-1] + (s[i] == '0');
    while (m--){
        int l, r; cin >> l >> r;
        if (r > Max){
            a[l] = r;
            Max = r;
        }
    }
    Max = 0;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++){
        Max = max(Max, a[i]);
        for (int j = 0; j <= i; j++){
            if (Max < i) {
                if (j - (s[i] == '0') >= 0) dp[i][j] = dp[i-1][j - (s[i] == '0')];
            }
            else{
                if (j <= cnt[Max]) add(dp[i][j], dp[i-1][j-1]);
                if (i-j <= Max - cnt[Max]) add(dp[i][j], dp[i-1][j]);
            }
        }
    }
    cout << dp[n][cnt[n]];
}


Measured memory_bytes: 34304
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  if(n == 1)
  {
    cout << abs(a[0]-w) << endl;
  }
  else cout << max(abs(a[n-1]-w), abs(a[n-1]-a[n-2])) << endl;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
priority_queue<pll,vector<pll>,greater<pll> >pq,pq1;
priority_queue<ll,vector<ll>,greater<ll> >p1;



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin>>s>>t;
    cout<<t<<s;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define all(a) a.begin(),a.end()
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){x=x>y?y:x;}
template<class T> inline void gmax(T &x,const T &y){x=x<y?y:x;}
template<class T> inline bool Gmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T> inline bool Gmax(T &x,const T &y){return x<y?x=y,1:0;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int main(){
#ifdef rqgao2014
	assert(freopen("input.txt","r",stdin));
#endif
	int n,a,b;scanf("%d%d%d",&n,&a,&b);
	if(abs(a-b)%2) puts("Borys"); else puts("Alice");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>

int main(int argc, char *argv[]){
    long long N;
    std::cin >> N;
    long long tmp, min=std::numeric_limits<long long>::max();
    for(long long i=1; i*i<=N; ++i){
        if(N%i==0){
            tmp = i-1 + (N/i-1);
            if(tmp < min){
                min = tmp;
            }
        }
    }
    std::cout << min << std::endl;
    return 0;
}


Measured memory_bytes: 256
a=list(map(int,input().split()))
ans=min(a[0],a[3],a[4])
a[0]-=ans
a[3]-=ans
a[4]-=ans
ans*=3
if(ans>0 and (a[0]%2+a[3]%2+a[4]%2==2)):
  ans+=1
ans+=(a[0]//2*2)+(a[3]//2*2)+(a[4]//2*2)+a[1]
print(ans)


Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main() {// dream dreamer erase eraser 
	string T;
	cin >> T;
	ll size = T.size();
	vector<char> S(size);
	for (int i = size; i > 0; i--)S[size - i] = T[i - 1];//gyaku
	ll now = 0;
	bool ans = true;
	while (now < size) {//maerd remaerd esare resare
		if (S[now] == 'm' && S[now + 1] == 'a' && S[now + 2] == 'e' && S[now + 3] == 'r' && S[now + 4] == 'd')
			now += 5;
		else if (S[now] == 'r' && S[now + 1] == 'e' && S[now + 2] == 'm' && S[now + 3] == 'a' && S[now + 4] == 'e' &&
			S[now + 5] == 'r' && S[now + 6] == 'd')
			now += 7;
		else if (S[now] == 'e' && S[now + 1] == 's' && S[now + 2] == 'a' && S[now + 3] == 'r' && S[now + 4] == 'e')
			now += 5;
		else if (S[now] == 'r' && S[now + 1] == 'e' && S[now + 2] == 's' && S[now + 3] == 'a' && S[now + 4] == 'r' &&
			S[now + 5] == 'e')
			now += 6;
		else {
			ans = false;
			break;
		}
	}
	if (ans)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <iostream>

int gettime() {
    int h, m, s;
    std::cin >> h >> m >> s;
    return (h * 60 + m) * 60 + s;
}

void solve() {
    int t1 = gettime(), t2 = gettime();
    int t = t2 - t1;
    std::cout << (t / 60) / 60 << " " << (t / 60) % 60 << " " << t % 60 << "\n";
}

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

    for (int i = 0; i < 3; ++i) solve();

    return 0;
}



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

using namespace std;
typedef long long ll;

vector<vector<ll>> g(300010);
vector<ll> dis(300010);

int main(){
    ll n, m;
    cin >> n >> m;
    ll i, j, k;
    for(i = 0; i < m;i++){
        ll u, v;
        cin >> u >> v;
        g[u].push_back(n+v);
        g[u + n].push_back(2 * n + v);
        g[u + 2 * n].push_back(v);
    }

    ll s, t;
    cin >> s >> t;
    queue<ll> que;
    que.push(s);
    while(!que.empty()){
        ll x = que.front();
        que.pop();
        for(ll i:g[x]){
            if(dis[i]==0){
                dis[i] = dis[x] + 1;
                que.push(i);
            }
        }
    }
    cout << (dis[t] > 0 ? dis[t]/3 : -1) << endl;
    return 0;
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,k,ans,smin,smax;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(ll i=k;i<=n+1;i++)
    {
        smin=i*(i-1)/2LL;
        smax=(n+n-(i-1))*i/2LL;
        ans=(ans+(smax-smin+1))%mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3580
require 'prime'
loop do
  m, a, b = gets.split.map(&:to_i)
  break if m == 0
  ans = [0, 0]
  prod = 0
  Prime.each.lazy.take_while{ |p| p <= Math.sqrt(100000).to_i }.each do |p|
    break if p * p > m
    q = Prime.each.lazy.drop_while{ |q| q < p  }
                       .take_while{ |q| p * q <= m }
                       .take_while{ |q| a * q <= b * p }.to_a.last
    if q && prod < p * q
      ans = [p, q]
      prod = p * q
    end
  end
  puts ans * ' '
end

Measured memory_bytes: 9924
#include <iostream>
#include<bits/stdc++.h>
#include<string>
#include<string.h>
using namespace std;
/**
HIMA.HASSAN.SAIED
*/
int main()
{
string s;
cin>>s;
int v=s.length();
v--;

int z;
if(v%2==1){
    v--;
}


z=v/2;
for(int r=0;r<z;r++){


   if(s.at(r)!=s.at(r+z)||v%2==1){
        v--;
        z=v/2;

        r=-1;
    }

}
cout<<v;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {


    public static double prob(int N, double[] proba) {

        double[][] dp = new double[N + 1][N + 1];


        dp[0][0] = 1;

        for(int coin = 1; coin <= N; coin++) {
            dp[coin][0] = dp[coin - 1][0] * (1- proba[coin-1]);
        }

        for(int coin = 1; coin <= N; coin++) {
            dp[coin][coin] = dp[coin-1][coin-1] * (proba[coin-1]);
        }

        for(int coin=1; coin<=N; coin++) {
            for(int heads = 1; heads <= coin; heads++) {
                dp[coin][heads] = dp[coin - 1][heads - 1] * proba[coin - 1] + dp[coin - 1][heads] * (1 - proba[coin - 1]);
            }
        }

        double totalProba = 0.0;

        for(int heads=N/2+1; heads<=N; heads++) {
            totalProba = totalProba + dp[N][heads];
        }
        return totalProba;
    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        double[] p = new double[N];

        for(int i=0; i<N; i++)
            p[i] = scanner.nextDouble();

        System.out.println(prob(N, p));

    }
}


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

template <class T> T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
template <class T> T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

int main(void) {
  int N;
  cin >> N;
  unsigned long long ans = 1;
  for (int i = 0; i < N; i++) {
    unsigned long long T;
    cin >> T;
    ans = lcm(ans, T);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// kyopro.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<string>
using namespace std;
#define ll long long int
#define rep(N) for(ll i=0;i<N;i++)
#define For(i,N) for(ll i=0;i<N;i++)
ll MOD = 1e9 + 7;
int main()
{
	ll N;
	ll M;
	cin >> N >> M;
	vector<ll>a(M);
	rep(M)cin >> a[i];
	vector<ll>DP(N + 1);
	if (M == 0) {
		DP[0] = 1;
		DP[1] = 1;
		rep(N - 1) {
			DP[i + 2] = DP[i] + DP[i + 1];
			DP[i+2] %= MOD;
		}
	}
	else {
		DP[0] = 1;
		auto it = a.begin();
		if (*it != 1) {
			DP[1] = 1;
		}
		else if (it + 1 != a.end())
			it++;

		rep(N - 1) {
			DP[i + 2] = DP[i + 1] + DP[i];
			if (*it == i + 2) {
				DP[i + 2] = 0;
				if (it + 1 != a.end())
					it++;
			}
			DP[i + 2] %= MOD;

		}
	}
	cout << DP[N];
}


Measured memory_bytes: 1792