akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {

	s := nextString()
	t := nextString()

	n := len(s)
	m := len(t)

	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, m+1)
		for j := 0; j < m+1; j++ {
			dp[i][j] = 0
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if s[i] == t[j] {
				dp[i+1][j+1] = Max([]int{dp[i+1][j+1], dp[i][j] + 1})
			}
			dp[i+1][j+1] = Max([]int{dp[i+1][j+1], dp[i+1][j], dp[i][j+1]})
		}
	}

	ans := ""
	i := n
	j := m
	for i > 0 && j > 0 {
		if dp[i][j] == dp[i-1][j] {
			i--
		} else if dp[i][j] == dp[i][j-1] {
			j--
		} else {
			ans = string(s[i-1]) + ans
			i--
			j--
		}
	}

	fmt.Println(ans)
}

/* templates */

func Max(a []int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func Min(a []int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextStrings(n int) []string {
	r := make([]string, n)
	for i := 0; i < n; i++ {
		r[i] = nextString()
	}
	return r
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 80512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int ct[60];
int main(){
    int n;
    scanf("%d",&n);
    ll a[n];
    ll ans = 0;
    ll sum = 0;
    ll mis = 0 ;
    for (int i = 0; i < n; i++){
        scanf("%lld",&a[i]);
        sum += a[i];
        sum %= mod;
        for (int k = 0; k < 60; k++){
            if (a[i] & (1ll<<k)){
                mis += 2*ct[k]*((1ll<<k)%mod);
                mis %= mod;
                ct[k]++;
            }
        }
    }
    ans += sum*(n-1);
    ans %= mod;
    ans -= mis;
    ans %= mod;
    printf("%lld",(ans+mod)%mod);


}


Measured memory_bytes: 2560
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def yn(f) return (f)? "Yes": "No" end
def ynb(f) return (f)? "YES": "NO" end
def ap(a) a.each{|u| p u} end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
t = inp[0]
ans = 0
t.times do
  a = inps
  ans += a[0].to_f * ((a[1] == "JPY")? 1 : 380000.0)
end
p ans

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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl


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

    int N; cin >>N;
    vector<int> H(N); cin >> H;
    
    int ans = 1;

    for (int i = 1; i < N; i++) {
        bool ok=true;
        for (int j = 0; j < i; j++) {
            if (H[j] > H[i]) {
                ok = false;
                break;
            }   
        }
        if (ok) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=[[0]*N]*N
B=[[0]*M]*M
for _ in range(N):
    A[_]=list(input())
for _ in range(M):
    B[_]=list(input())
clear=False
flag=False

for i in range(N-M+1):
    for j in range(N-M+1):
        cnt=0
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]==B[k][l]:
                    cnt+=1
                    if cnt==M**2:
                        clear=True
                        flag=True
                        break
                else:
                    flag=True
                    break
            if flag:
                break
        if clear:
            break
        else:
            flag=False
            cnt=0
    if clear:
        break

if clear:
    print("Yes")
else:
    print("No")

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

bool comp(pair<long long,long long > x,pair<long long,long long> x1){
  return x.second+x.first<x1.second+x1.first;
}
void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
      vector<pair<long long,long long>> tmp;
    for(int i = 0;i<N;i++){tmp.push_back(make_pair(A[i],B[i]));}
      sort(tmp.begin(),tmp.end(),comp);
    reverse(tmp.begin(),tmp.end());
    long long  tmp1 = 0;
    long long  tmp2 = 0;
    for(int i =0;i<N;i++){
      if((i+1)%2 == 1)tmp1+=tmp[i].first;
      else tmp2+=tmp[i].second;
    }
    cout<<tmp1-tmp2;
}


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

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    V<ll> A(N);
    for(ll &e : A) cin >> e;

	ll ans = 1;
    for(ll i = 0; i <= 1; i++) {
        ll e = A[i];
        for(ll j = 1; j * j <= e; j++) {
            if(e % j) continue;
            for(ll d : { j, e / j }) {
                ll cnt = 0;
                for(ll k = 0; k < N; k++) cnt += !!(A[k] % d);
                if(cnt <= 1) chmax(ans, d);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N, X = map(int, input().split())
x = list(map(int, input().split()))

y = list(map(lambda a: abs(a - X), x))
g = y[0]
for yy in y[1:]:
    g = gcd(g, yy)
print(g)


Measured memory_bytes: 14252
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   A.cpp                                              :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: kotaro666 <kotaro0726@gmail.com>           +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/03/04 14:55:36 by kotaro666         #+#    #+#             */
/*   Updated: 2020/03/04 15:10:15 by kotaro666        ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

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

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;

    vector<string> week(7);
    week = {
        "SUN",
        "MON",
        "TUE",
        "WED",
        "THU",
        "FRI",
        "SAT",
    };

    int ans;
    for (int i = 0; i < 7; i++)
    {
        if (S == week.at(i))
        {
            ans = 7 - i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char a[200][200];
    int row,col,i,j;
    scanf("%d %d",&row,&col);
    for(i=0; i<row; i++)
    {
        for(j=0; j<=col; j++)
        {
            scanf("%c",&a[i][j]);
        }
    }

    for(i=0; i<col+2; i++)
    {
        printf("#");
    }
    printf("\n");
    for(i=0; i<row; i++)
    {
        printf("#");
        for(j=1; j<=col; j++)
        {
            printf("%c",a[i][j]);
        }
        printf("#\n");
    }
    for(i=0; i<col+2; i++)
    {
        printf("#");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
sa = list(input())
sb = list(input())
sc = list(input())
turn = sa[0]
sa = sa[1:]
while 1:
    if turn == "a":
        if len(sa) == 0:
            print("A")
            break
        turn = sa[0]
        sa = sa[1:]

    elif turn == "b":
        if len(sb) == 0:
            print("B")
            break
        turn = sb[0]
        sb = sb[1:]

    elif turn == "c":
        if len(sc) == 0:
            print("C")
            break
        turn = sc[0]
        sc = sc[1:]

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
using namespace std;
typedef long long ll;

int main(){
  ll x;
  IN1(x);
  ll money = 100, count = 0;
  while (money < x){
    count++;
    money += money/100;
  }
  OUT(count);
}

Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct node {
	int key;
	node *pre, *nex;
};
node *nil;
void init() {
	nil = (node *)malloc(sizeof(node));
	nil->nex = nil;
	nil->pre = nil;
}
void insert(int key) {
	node *a = (node*)malloc(sizeof(node));
	a ->key = key;
	a->nex = nil->nex;
	nil->nex->pre = a;
	nil->nex = a;
	a->pre = nil;
}
node* search(int key) {
	node *cur;
	cur = nil->nex;
	while (cur != nil && cur->key != key) {
		cur = cur->nex;
	}
	return cur;
}
void deletenode(node *pt) {
	if (pt != nil) {
		pt->nex->pre = pt->pre;
		pt->pre->nex = pt->nex;
		free(pt);
	}
	else return;
	
}
void deleteFirst() {
	deletenode(nil->nex);
}
void deleteLast() {
	deletenode(nil->pre);
}
void deletekey(int key) {
	deletenode(search(key));
}
void printNode() {
	node *cur = nil->nex;
	while (cur != nil) {
		printf("%d", cur->key);
		if(cur != nil -> pre)printf(" ");
		cur = cur->nex;
	}
	printf("\n");
	
}
int main() {
	
	int n, key;
	char com[20];
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') {
			insert(key);
		}
		else if (com[6] == 'F') {
			deleteFirst();
		}
		else if (com[6] == 'L') {
			deleteLast();
		}
		else {
			deletekey(key);
		}
		
				

			}
		
	
		printNode();
		return 0;
}

Measured memory_bytes: 33900
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    cout<<(char)(a[0]-('a'-'A'))<<(char)(b[0]-('a'-'A'))<<(char)(c[0]-('a'-'A'))<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a,b,i;
  cin>>n>>a>>b;
  for(i=a;i<=b;i++)
    if(i%n==0)
      break;
  if(i<=b)
    cout<<"OK";
  else
    cout<<"NG";
  return 0;
}

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

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


Measured memory_bytes: 256
function main()
  
  S = split(readline(),"")
  
  check = false
  
  for i in 0:25
    
    if !in(string('a'+i),S)
      check = true
      println('a'+i)
      break
    end
    
  end
  
  if !check
    
    println("None")
    
  end
  
end

main()

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

using namespace std;

const int MaxN = 100005;

int n;
int a[MaxN], b[MaxN], c[MaxN];
int dp[MaxN][3];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int N,M; cin >> N >> M;
    vector<vector<double>> a(N,vector<double>(3));
    for (int i=0;i<N;++i)
        for (int j=0;j<3;++j)
            cin >> a[i][j];
    double ans=0;
    for (int mask=0;mask<(1<<N);++mask){
        if (__builtin_popcount(mask)!=M) continue;
        vector<int> v;
        for (int i=0;i<N;++i) if (mask&1<<i){
            v.emplace_back(i);
        }
        double cnt=0;
        for (int i=0;i<M;++i)
            for (int j=i+1;j<M;++j)
                for (int k=0;k<3;++k)
                    cnt+=(a[v[i]][k]-a[v[j]][k])*(a[v[i]][k]-a[v[j]][k]);
        ans=max(ans,cnt);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3320
<?php

$input = explode(" ",trim(fgets(STDIN)));
$count = $input[0];//3
$g = $input[1]; //1000
$sum = 0;
$c = 0;
$n = 0;

for($i=0; $i<=$count-1; $i++){//ドーナツの種類分ループさせる
    $total = trim(fgets(STDIN));//標準入力
    $c += $total;//3つの合計を出す
    $min[] = $total;//最小値を求めるため配列に入れる
}
$nokori = $g - $c;//あと何グラム残るか計算する
// var_dump($min);
$min = min($min);//最小値を出す
$v = floor($nokori / $min);//切り捨てで何個作れるか求める
echo $v + $count;//出力

Measured memory_bytes: 3956
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,m;
    std::cin >> n>>m;
    if(n==1 && m==1){
        std::cout << 1 << std::endl;
        return 0;
    }
    if(n==1 || m==1){
        std::cout << n*m-2 << std::endl;
        return 0;
    }
    std::cout << n*m-n*2-m*2+4 << std::endl;
}


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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    string a;

    cin >> a;

    if(a.back()=='s') {

        a+=("es");

    } else {

        a+=("s");

    }

    cout << a << '\n';

    return 0;

}



Measured memory_bytes: 3612
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, t, sum int
	fmt.Scan(&n)
	for _, v := range strconv.Itoa(n) {
		t, _ = strconv.Atoi(string(v))
		sum += t
	}
	if n%sum == 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>
#include<stack>
#define eps 1e-50
using namespace std;
int  inf=1000000002;
long long int  a[200005],b[200005],z[200004];
int main()
{
    long n;
    cin>>n;
    for(long i=1;i<=n;i++)cin>>a[i];
    stack<int >s;
    for(long i=1;i<=n;i++)
    {
        while(!s.empty()&&a[s.top()]>a[i])s.pop();
        if(s.empty()){b[i]=1;}
        else {b[i]=s.top()+1;}
        s.push(i);
    }
    while(!s.empty())s.pop();
    for(long i=n;i>=1;i--)
    {
        while(!s.empty()&&a[s.top()]>a[i])s.pop();
        if(s.empty()){z[i]=n;}
        else {z[i]=s.top()-1;}
        s.push(i);
    }
    long long int ans=0;
    for(long i=1;i<=n;i++)
    {
        long long p=i-b[i]+1;
        long long h=z[i]-i+1;
        ans=ans+p*h*a[i];
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 5760
# Aizu Problem 0238: Time to Study

import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    T = int(input())
    if T == 0:
        break
    n = int(input())
    for _ in range(n):
        start, end = [int(_) for _ in input().split()]
        T -= (end - start)
    print("OK" if T <= 0 else T)

Measured memory_bytes: 7776
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
typedef pair<int,ll> ill;
ll fac[200005];
ll inv[200005];
ll invfac[200005];
int p[200005];
int n;
ll SZ[200005];
ll ANS[200005];
ll ans[200005];
ll total[200005];
vector<int> adjlist[200005];
ll exp(int a, int x){
    if (x == 0) return 1;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x & 1){
        p *= a;
        p %= mod;
    }
    return p;
}
void dp(int u){
    int sz = 1;
    ll ans = 1;
    for (auto v: adjlist[u]){
        if (v==p[u])continue;
        p[v] = u;
        dp(v);
        sz += SZ[v];
        ans *= invfac[SZ[v]]; ans %= mod;
        ans *= ANS[v]; ans %= mod;
    }
    ans *= fac[sz-1]; ans %= mod;
    SZ[u] = sz;
    ANS[u] = ans;
}
void dp2(int u){
    ll finalans = fac[n-1];
    for (auto v : adjlist[u]){
        if (v == p[u]){
            ll newans = ans[v];
            newans *= invfac[n-1]; newans %= mod;
            newans *= fac[SZ[u]]; newans %= mod;
            newans *= exp(ANS[u],mod-2); newans %= mod;
            int newsz = n-SZ[u];
            newans *= fac[newsz-1]; newans %= mod;
            finalans *= newans; finalans %= mod;
            finalans *= invfac[newsz]; finalans %= mod;
        }
        else{
            finalans *= ANS[v]; finalans %= mod;
            finalans *= invfac[SZ[v]]; finalans %= mod;
        }
    }
    ans[u] = finalans;
    for (auto v : adjlist[u]){
        if (v == p[u]) continue;
        dp2(v);
    }
}
int main(){
    //freopen("160f.txt","r",stdin);
    //freopen("testdebug.txt","w",stdout);
    scanf("%d",&n);
    fac[0] = inv[0] = invfac[0] =1;
    for (int i = 1; i <= n; i++){
        fac[i] = (fac[i-1]*i)%mod;
        inv[i] = exp(i,mod-2);
        invfac[i] = (invfac[i-1]*inv[i])%mod;
    }
    for (int i = 1; i < n; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    p[1] = 0;
    dp(1);
    dp2(1);
    for (int i = 1; i <= n; i++){
        printf("%lld\n",ans[i]);
    }

}


Measured memory_bytes: 25588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dig(ll x) {
  ll ans = 0;
  while(x > 0) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll sum = 0;
  for(ll i = 1; i <= N; i++) {
    ll C = dig(i);
    if(A <= C && C <= B) {
      sum += i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,c=0;
  cin>>n>>k;
  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;
    if(x>=k)
      c++;
  }
  cout<<c;
  return 0;
}
    

Measured memory_bytes: 256
let i_inp : unit -> int = fun () ->
  int_of_string (input_line stdin)

let inp_loop_array : 'a array -> int -> unit = fun a n ->
  let rec loop i = 
    if i = n then ()
    else
      (a.(i) <- (Scanf.scanf " %d" (fun x -> x));
       loop (i + 1))
  in loop 0 
   
let () =
  let n = i_inp () in
  let a = Array.make n 0 in
  let () = inp_loop_array a n in
  if n mod 2 <> 0 then (print_int 0; print_newline ())
  else
    let () = Array.sort (fun a b -> if a > b then 1 else if a = b then 0 else -1) a in 
    print_int (a.(n / 2) - a.(n / 2 -1));
    print_newline ()
      
        


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int a,b;
	cin >> a >> b;
	if(a<=5)
	{
		cout<<0<<endl;
	}
	else if(a<=12)
	{
		cout<<b/2<<endl;
	}
	else
	{
		cout<<b<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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


	int n, k, i, j, ans;
	cin >> n >> k;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	ans = 0;
	for (i = 0; i < k; i++) ans += a[i];
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(void){
    int a=0;
    int b=0;
    int c=0;
    int sum1=0;
    int sum2=0;
    int sum3=0;

    cin >> a >> b >> c;

    sum1=a+b;
    sum2=b+c;
    sum3=c+a;

    if(sum1<=sum2&&sum1<=sum3)cout << sum1 << endl;
    else if(sum2<=sum1&&sum2<=sum3)cout << sum2 << endl;
    else if(sum3<=sum1&&sum3<=sum2)cout << sum3 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector<pair<int, int> > v;

vector<int> f(int n){
	vector<int> vv(v.size());
	for(int i=0; i< n; i++){
		int m;
		cin >> m;
		for(int k=0; k < m; k++){
			int a, b, c, d;
			scanf("%d:%d-%d:%d", &a, &b, &c, &d);
			a = a*100+b; c = c*100+d;
			for(int j=0; j< v.size(); j++){
				if(a <= v[j].first && v[j].second <= c) vv[j]++;
			}
		}
	}
	return vv;
}

int main(){
	int p;
	cin >> p;
	for(int i=0; i < p; i++){
		int a, b, c, d;
		scanf("%d:%d-%d:%d", &a, &b, &c, &d);
		a = a*100+b; c = c*100+d;
		v.push_back(make_pair(a, c));
	}
	int n, m;
	cin >> n;
	vector<int> a = f(n);
	cin >> m;
	vector<int> b = f(m);

	int ret = 0;
	for(int i=0; i< a.size(); i++){
		ret += min(a[i], b[i]);
	}
	cout << ret << endl;
}

Measured memory_bytes: 1244
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String ans = (n + 1 >= 2 * k)? "YES" : "NO";
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include<stdio.h>

int main(){
  int a[1000];
  int i,j,n,key;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  for(i=1;i<n;i++){
    key=a[i];
    j=i-1;
    while(j>=0&&a[j]>key){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=key;
    for(j=0;j<n;j++){
      printf("%d",a[j]);
      if(j!=n-1) printf(" ");
    }
      printf("\n");
    }
    return 0;
  }



Measured memory_bytes: 2128
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var L = ReadInt();
            var c = Reads();

            var list = new List<int>();
            //最後尾は list[list.Length()-1]

            for (int i = 0; i < L; i++)
            {
                var input = c[i];
                if (input[0] == '-')
                {
                    //出
                    if (list.Count == 0)
                    {
                        WriteLine(i+1);
                        return;
                    }
                    else if (list.Last() != Abs(int.Parse(input)))
                    {
                        WriteLine(i+1);
                        return;
                    }
                    else
                    {
                        list.RemoveAt(list.Count - 1);
                    }
                }
                else
                {
                    //入
                    if (list.Contains(int.Parse(input)))
                    {
                        WriteLine(i+1);
                        return;
                    }
                    else
                    {
                        list.Add(int.Parse(input));
                    }
                }
            }
            WriteLine("OK");
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 20216
ABC=list(map(int,input().split()))

ABC.sort()

max = ABC[2]
mid = ABC[1]
min = ABC[0]

if (max-mid) % 2 == 0:
    if (max-min) % 2 == 0:
        print((max-mid)+(mid-min)//2)
    else:
        print((max-mid)+1+(mid-min)//2 + 1)
else:
    if (max-min) % 2 == 0:
        print((max-mid)+1 + (mid-min)//2 + 1)
    else:
        print((max-mid) + (mid-min)//2)

Measured memory_bytes: 3064
N = int(input())
H = list(map(int,input().split()))
ans = True
for i in range(N-2,-1,-1):
    if H[i] > H[i+1]:
        H[i] -= 1
for i in range(N-1):
    if H[i] > H[i+1]:
        ans = False
        break
print(["No","Yes"][ans])

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

using namespace std;

using ll = long long;
using ld = double;

using T = __int128_t;

T my_gcd(T a, T b)
{
    return b ? my_gcd(b, a % b) : a;
}

T my_lcm(T a, T b)
{
    T g = my_gcd(a, b);
    //cerr << a << " " << b << endl;
    assert(g != 0);
    __int128_t tmp = a / g * b;
    if (tmp > (1LL << 60))
        return (1LL << 60);
    return tmp;
}

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

    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ld> p(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> p[i];
    ld ret = 0;
    for (int i = 1; i < (1 << n); i++)
    {
        ld pp = 1;
        ll l = 1;
        int cnt = 0;
        for (int j = 0; j < n; j++)
        {
            if (((i >> j) & 1) == 0)
                continue;
            cnt++;
            pp *= p[j] / 100;
            l = my_lcm(l, a[j]);
        }
        assert(l != 0);
        pp *= m / l;
        if (cnt % 2)
            ret += pp;
        else
            ret -= pp;
    }
    cout << fixed << setprecision(10) << ret << endl;
}



Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define NMAX 405
using namespace std;

const long long INF=(1LL<<60);

int n;
long long sum[NMAX];
long long a[NMAX],dp[NMAX][NMAX];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];

    for(int i=1;i<=n;i++){
        dp[i][i]=0;
    }

    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
    }

    for(int i=n;i>=1;i--)
    {
        for(int j=i+1;j<=n;j++){
            long long val=INF;
            for(int k=i;k<j;k++){
                val=min(val,dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]);
            }
            dp[i][j]=val;
        }
    }
    cout<<dp[1][n];
    return 0;
}

Measured memory_bytes: 1536
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

def divisors(n):
  ret=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      ret.append(i)
      if i!=n//i:
        ret.append(n//i)
  return ret
    
def is_prime(n):
  if n==1 or n==2 or n==3:
    return True
  else:
    for i in range(2,int(n**0.5)+1):
      if n%i==0:
        return False
    return True

a,b=map(int,input().split())
g=gcd(a,b)
divs=divisors(g)
ans=0
for val in divs:
  if is_prime(val)==True:
    ans+=1
print(ans)

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

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> vec(h);

    rep(i, h) {
        cin >> vec.at(i);
    }

    rep(i, w + 2) {
        cout << "#";
    }
    cout << endl;

    rep(i, h) {
        cout << "#" << vec.at(i) << "#" << endl;
    }

    rep(i, w + 2) {
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<int,int>
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second

int main()
{   fastio ;
    int n,i,j ;
    cin>>n ;
    int a[n],b[n],c[n] ;
    for (i = 0; i < n; ++i)
    {
    	cin>>a[i]>>b[i]>>c[i] ;
    }
    int maxa[n],maxb[n],maxc[n] ;
   
    maxa[0]=a[0] ;   
    maxb[0]=b[0] ;
    maxc[0]=c[0] ;
    for (i = 1; i < n; ++i)
    {   maxa[i]=a[i]+max(maxb[i-1],maxc[i-1]) ;
        maxb[i]=b[i]+max(maxa[i-1],maxc[i-1]) ;
        maxc[i]=c[i]+max(maxb[i-1],maxa[i-1]) ;
    }
    cout<<max(max(maxa[n-1],maxb[n-1]),maxc[n-1])<<"\n" ;
    return 0 ;
}    

Measured memory_bytes: 2560
x=int(input())

s=0
a=-1
z5=[]
ans=[]
aans=0
bans=0
while(s==0):
    a+=1
    z5.append(a**5)
    if (x+a**5) in z5:
        bans=a
        break
    elif  (x-a**5) in z5:
        bans=-a
        break

    elif (a**5-x) in z5:
        aans=a
        break
        

if aans==0:
    aans=int((x+bans**5)**(1.0/5.0))
if bans==0:
    bans=int((aans**5-x)**(1.0/5.0))

print(aans,bans)

Measured memory_bytes: 9404
import math

num = 50000
L = [True] * (num+1)
L[0] = L[1] = False
sqrt = int(num**0.5) +1
for i in range(2, sqrt):
    if L[i] == False:
        continue
    for j in range(i*2,num+1,i):
        L[j] = False

p = [x for x in range(num+1) if L[x] ]

#pset = set(p)

while True:
    num = int(input())
    if num == 0:
        break

    half = num // 2
    c = 0
    for i in p:
        if i > half:
            break
        j = num - i
        if L[j]:
            c += 1
    print(c)



Measured memory_bytes: 6268
#include<bits/stdc++.h>
using  namespace std;
 
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << endl;
 
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define scl1(a)             scanf("%lld", &a)
#define scl2(a, b)          scanf("%lld %lld", &a, &b)
 
#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
 
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
const int mod = 1e9+7;
const db pi = acos(-1);
const long long infl = LLONG_MAX;
const int inf = 0x3f3f3f3f;
 
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision
 
#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase   
int32_t main(){
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 
ll t,i,x,j,y,z,k,n;

cin>>n>>x;
ll w[n],v[n];
rep(i,0,n,1)cin>>w[i]>>v[i];

ll dp[x+1];
memset(dp,0,sizeof(dp));
rep(i,0,n,1){
	repr(j,x,w[i]-1,-1){
			dp[j]=max(dp[j],v[i]+dp[j-w[i]]);
	}
}
ll mx=0;
	rep(j,1,x+1,1)mx=max(mx,dp[j]);
cout<<mx;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define N 100050
int a[N],n,k,pos;
int main() {
	scanf("%d%d",&n,&k);
	int i;
	for(i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if(a[i]==1) pos=i;
	}
	int ans=1<<30;
	for(i=max(1,pos-k+1);i<=pos;i++) {
		int j=i+k-1;
		ans=min(ans,(i-1+k-2)/(k-1)+(n-j+k-2)/(k-1));
	}
	printf("%d\n",ans+1);
}

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


namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			int m, f, r;
			
			while (true)
			{
				var data = Console.ReadLine().Split(' ');
				m = int.Parse(data[0]);
				f = int.Parse(data[1]);
				r = int.Parse(data[2]);

				if (m == -1 && f == -1 && r == -1)
					break;
			
				if(m == -1 || f == -1 || m + f < 30)
				{
					Console.WriteLine("F");
				}
				else if(80 <= m + f)
				{
					Console.WriteLine("A");
				}
				else if(65 <= m + f && m + f < 80)
				{
					Console.WriteLine("B");
				}
				else if (50 <= m + f && m + f < 65)
				{
					Console.WriteLine("C");
				}
				else if (30 <= m + f && m + f < 50)
				{
					if(r < 50)
					{
						Console.WriteLine("D");
					}
					else
					{
						Console.WriteLine("C");
					}
				}
			}
		}
	}
}



Measured memory_bytes: 15948
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
using namespace std;

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

    bool res = true;
    for(int i = n-1; i > 0; i--){
        if(h[i-1] > h[i]){
            if(h[i-1]-1 == h[i]) h[i-1] -= 1;
            else {
                res = false;
                break;
            }
        }
    }
    cout << (res?"Yes":"No") << endl;
}

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

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define INF 900000000

using namespace std;

int main()
{
for (int i=1;i<100000;i+=1){
	int x;
	cin>>x;
	if (x==0) break;
	else {
		cout<<"Case "<<i<<": "<<x<<endl;
   }
   }
    return 0;
}




Measured memory_bytes: 3044
#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 n,m; cin >> n >> m;
    vector<pii>v(n);
    for(auto& e : v) cin >> e.first >> e.second;
    sort(all(v));
    int cst = 0;
    for(auto e : v){
        if(e.second < m){
            m -= e.second;
            cst += e.second * e.first;
        } else {
            cout << cst + m * e.first << endl;
            return 0;
        }
    }
}




Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

ll gcd(ll x, ll y){
	ll r = x%y;
	while(r){
		x = y;
		y = r;
		r = x%y;
	}
	return y;
}

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

int main(){
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = b-(b/c+b/d-b/lcm(c,d));
	a--;
	ll tmp = a/c+a/d-a/lcm(c,d);
	ans = ans+tmp-a;
	cout << ans << endl;
	return 0;
}

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

const long long inf = 100009;

long long arr[inf][3];
long long dp [inf][3];

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

    for(long long i=1;i<=n;i++)
    {
        for(long long j=0;j<3;j++)
        {
            cin>>arr[i][j];
        }
    }

    dp[1][0]=arr[1][0];dp[1][1]=arr[1][1];dp[1][2]=arr[1][2];

    for(long long i=2;i<=n;i++)
    {
        dp[i][0] = max(dp[i-1][1]+arr[i][0],dp[i-1][2]+arr[i][0]);
        dp[i][1] = max(dp[i-1][0]+arr[i][1],dp[i-1][2]+arr[i][1]);
        dp[i][2] = max(dp[i-1][1]+arr[i][2],dp[i-1][0]+arr[i][2]);
    }

    long long mx = max(dp[n][0],dp[n][1]);
    mx = max(mx,dp[n][2]);

    cout<<mx<<endl;
}


Measured memory_bytes: 4992
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = 0
    mod = 10 ** 9 + 7
    for d in range(61):
        # d桁目ごとに考える
        x = 0
        for a in A:
            if (a >> d) & 1:
                x += 1
        ans += x * (n-x) * 2**d
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 50888
#include <cstdio>
#include <vector>

int main()
{
  int n, m;
  char s[100002];
  scanf("%d%d%s", &n, &m, s);
  int cur = n;
  std::vector<int> ans;
  while (true)
  {
    bool ng = true;
    for (int i = m; i >= 1; --i)
    {
      if (cur - i < 0) continue;
      if (s[cur - i] == '1') continue;
      ng = false;
      cur -= i;
      ans.emplace_back(i);
      break;
    }
    if (ng)
    {
      puts("-1");
      return 0;
    }
    if (cur == 0) break;
  }
  for (int i = ans.size() - 1; i >= 0; --i)
  {
    printf("%d%c", ans[i], i == 0 ? '\n' : ' ');
  }
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 2.70 + c[j] * 20;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3680
#include <iostream>
using namespace std;
int main(){
    int count[4][3][10]={{{}}},n,b,f,r,v;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        count[b-1][f-1][r-1]+=v;
    }
    for(int j=0;j<4;j++){
        if(j>0) cout<<"####################"<<endl;
        for(int k=0;k<3;k++){
            for(int l=0;l<10;l++){
                cout<<" "<<count[j][k][l];
            }cout<<endl;
        }
    }return 0;
}


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

int main(){
	int n,l;cin>>n>>l;
	int sum=0;
	for(int i=0;i<n;i++){
		sum+=l+i;
	}
	int a=100000;
	for(int i=0;i<n;i++){
		if(abs(l+i)<abs(a)){
			a=l+i;
		}
	}
	cout<<sum-a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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 = 1000000007;
const ll HIGHINF = (ll)1e18;

struct UnionFind {
  vector<long long> p, size, height;

  UnionFind(){}
  UnionFind(long long n) {
    size.resize(n, 1);
    height.resize(n, 1);
    p.resize(n);
    for (long long i=0; i<n; i++) p[i] = i;
  }

  long long root(long long i) {
    // iの親を求める
    if (p[i] != i) p[i] = root(p[i]);
    return p[i];
  }

  bool same(long long i, long long j) {
    // iとjが同じグループかどうかを判別する
    return root(i) == root(j);
  }

  void unite(long long i, long long j) {
    // iとjを併合する
    long long pi=root(i), pj=root(j);
    if (pi == pj) return;
    if (height[pi] < height[pj]) {
      p[pi] = pj;
      size[pj] += size[pi];
    } else {
      p[pj] = pi;
      size[pi] += size[pj];
      if (height[pi] == height[pj]) height[pi]++;
    }
  }
};

int main() {
  ll n, k, l; cin >> n >> k >> l;
  UnionFind rail(n), road(n);
  REP(i, k) {
    ll p, q; cin >> p >> q;
    road.unite(p-1, q-1);
  }
  REP(i, l) {
    ll r, s; cin >> r >> s;
    rail.unite(r-1, s-1);
  }
  map<P<ll, ll>, ll> con;
  REP(i, n) con[make_pair(rail.root(i), road.root(i))]++;
  REP(i, n) {
    cout << con[make_pair(rail.root(i), road.root(i))];
    if (i != n-1) cout << ' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 21120
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define Aint(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
const int mINF = -1001001001;
const int mod = 1000000007;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());


int main() {
  int n,m;
  cin >> n >> m;
  Graph x(m);
  int s,k;
  REP(i,m) {
    cin >> k;
    x[i].resize(k);
    REP(j,k) {
      cin >> s;
      x[i][j]=s;
      x[i][j]--;
    }
  }
  v p(m);
  REP(i,m) cin >> p[i];
  int ans=0;
  REP(swt,(1<<n)) {
    bool ok = true;
    REP(lmp,m) {
      int c=0;
      for(int id:x[lmp]) {
        if((swt >> id) & 1) c++;
      }
      if(c%2!=p[lmp]) ok=false;
    }
    if(ok) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int count=0;
    int count2=0;
    for(int c=1;c<=N;c++){
        for(int i=1;i*i<=(N-c);i++){
            if((N-c)%i==0){
                count++;
            }
            if(i*i==(N-c)){
                count2++;
            }
        }
    }
    int ans=2*count-count2;
    cout << ans << endl;
    }

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;

	while (cin >> n, n) {

		vector<map<int,int>> v(n);
		REP(i, n) {
			int k;
			cin >> k;
			REP(j, k) {
				int a;
				cin >> a;
				v[i][a] = 1;
			}
		
		}
		vector<vvi> dp(31, vvi(n, vi(n, 0)));
		REP(i, n)dp[0][i][i] = 1;
		REP(d, 30) {
			vi tmp;
			REP(i, n) {
				if (v[i][d + 1])tmp.push_back(i);
			}
			REP(i, n) {
				dp[d + 1] = dp[d];
			}
			REP(i, tmp.size()) {
				REP(j, tmp.size()) {
					REP(k, n) {
						dp[d+1][tmp[i]][k] |= dp[d][tmp[j]][k];
					}
				}
			}
		}
		REP(d,31){
			REP(i, n) {
				int cnt = 0;
				REP(j, n)cnt += dp[d][i][j];
				if (cnt == n) {
					cout << d << endl;
					goto a;
				}
			}
		}
		cout << -1 << endl;
	a:;
	}
}

Measured memory_bytes: 3500
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>

int main() {
	
	string s;
	cin >> s;
	int n;
	cin >> n;
	int x = s.size();
	vector<string>z;
	map<string, bool>v;
	for (int i = 0; i < x; i++) {
		string p;
		for (int j = i; j < min(x,i+6); j++) {

			p += s[j];
			if (!v[p])z.push_back(p);
			v[p] = 1;
		}
	}
	sort(z.begin(), z.end());
	cout << z[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 2556