akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
inline int read(){
	int res=0,sign=1;char ch;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')sign=-1;res=res*10+ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;
	return res*sign;
}
const int maxn=2*1e5+10;
int n,k;
int f[maxn];
long long sum,ans;
bool flag;
priority_queue<int> q;
int main(){
    n=read(),k=read();
    for(int i=1;i<=n;i++){
    	f[i]=read();
    	q.push(f[i]);
		sum+=f[i];
	}
	if(k>=n){puts("0");return 0;}
	if(k==0){printf("%lld",sum);return 0;}//特判 
	int t=0;
	for(int i=1;i<=n;i++){
		int a=q.top();
		q.pop();
		k--;
		sum-=a;
		if(k>0)continue;
		break;
	}	 
    printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 1912
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////

void solve() {
	int A, B;
	cin >> A >> B;
	cout << (A - 1) * (B - 1) << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Collections;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        
        long[][] mat1 = new long[n][m];
        long[][] mat2 = new long[m][l];
        long[][] mat3 = new long[n][l];
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                mat1[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                mat2[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                for (int k = 0; k < m; k++) {
                    mat3[i][j] += mat1[i][k]*mat2[k][j];
                }
            }
        }
        
        for (int i = 0; i < n; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < l; j++) {
                sb.append(mat3[i][j]).append(" ");
            }
            sb.delete(sb.length()-1, sb.length());
            System.out.println(sb);
        }
    }
}

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

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

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
typedef long long ll;
typedef unsigned long long ull;


int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    vector<int> a(n+1,0);
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i)
            a[j]++;
    }
    ll total=0;
    for(ll i=1;i<=n;i++) {
        total+= (ll) i * a[i];
    }
    cout<< total << endl;
    return 0;
}


Measured memory_bytes: 42272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll n;
ll x, y;

int main() {
	scanf("%lld", &n);
	bool flg = 0;
	for(int i = sqrt(n); i >= 1; i--) {
		if(n % i == 0) {
			flg = 1;
			x = (ll)i;
			break;
		}
	}
	if(flg) y = n / x;
	else x = 1, y = n;
	printf("%lld\n", x + y - 2);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 10000
int hantei(int);
int main(){
  int n,A[N],i,total = 0;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  for(i = 0;i < n;i++){
    total += hantei(A[i]);
  }
  printf("%d\n",total);
}
//素数なら１を返す
int hantei(int x){
  int i;
  if(x == 2) return 1;
  if(x < 2 || x % 2 == 0)return 0;
  for(i = 3;i*i <= x;i+=2){
    if(x % i == 0){
       return 0; 
    }
  }
  return 1;
}


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


int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> AC(N,0);
    string str;
    cin >> str;
    for(int i = 0; i < N - 1; i++){
        if(str[i] == 'A' && str[i + 1] == 'C'){
            AC[i + 1] = AC[i] + 1;
        }
        else{
            AC[i + 1] = AC[i];
        }
    }

    for(int i = 0; i < M; i++){
        ll tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        tmp2--;
        tmp1--;
        cout << AC[tmp2] - AC[tmp1] << endl;
    }
}





Measured memory_bytes: 1792
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string s;
ll l, a[500001];
ll ans; 

int main()
{
	cin>>s;
	s = " " + s;
	l = s.length() - 1;
	for(int i=1;i<=l;i++) (s[i] == '<') ? (a[i+1] = a[i] + 1) : (a[i+1]);
	for(int i=l;i>=1;i--) (s[i] == '>') ? (a[i] = max(a[i], a[i+1]+1)) : (a[i]);
	for(int i=1;i<=l+1;i++) ans += a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define double long double
using namespace std;
const double EPS = 1e-8;
const double INF = 1e9;

struct p3{
  double x,y,z,r;
  p3(){x=y=z=r=0;}
  p3(double x,double y,double z):x(x),y(y),z(z){};
  p3(double x,double y,double z,double r):x(x),y(y),z(z),r(r){};
  p3 operator + (const p3 a)const {return p3(x+a.x,y+a.y,z+a.z,r);}
  p3 operator - (const p3 a)const {return p3(x-a.x,y-a.y,z-a.z,r);}
  p3 operator * (const double a)const{return p3(x*a,y*a,z*a,r);}
  p3 operator / (const double a)const{return p3(x/a,y/a,z/a,r);}
  bool operator == (const p3 a)const {return abs(x-a.x)<EPS&&abs(y-a.y)<EPS&&abs(z-a.z)<EPS;}
  double Abs()const{return sqrt(x*x+y*y+z*z);}
  double dis(const p3 a)const{return sqrt((a.x-x)*(a.x-x)+(a.y-y)*(a.y-y)+(a.z-z)*(a.z-z));}
};

double dot(p3 a,p3 b){return a.x*b.x+a.y*b.y+a.z*b.z;}

struct L3{
  p3 s,t;
  L3(){s=t=p3();}
  L3(p3 s,p3 t):s(s),t(t){};
  bool operator == (const L3 a)const{return s==a.s&&t==a.t;}
};

L3 getRay(L3 a,p3 b){//???b??¨????????????a??????????°????????????????????????????
  a.t = a.t-a.s;
  b = b-a.s;
  p3 e = a.t / a.t.Abs();
  p3 s = e*dot(e,b);
  
  double d = s.dis(b);
  if(dot(e,b)<EPS||d>b.r+EPS)return L3();
  s = e * (s.Abs()-sqrt(b.r*b.r-d*d));
  
  
  p3 n = (b-s)/(b-s).Abs(); //??????????????????
  n = n*dot(a.t*(-1),n)*2;
  p3 t = a.t+n+s;
  return L3(s+a.s,t+a.s);
}


int n;
vector<p3> A;
p3 calc(L3 ray){
  while(1){
    double mn = INF;
    L3 nray;
    for(int i=0;i<n;i++){
      L3 res = getRay(ray,A[i]);
      if(res==L3())continue;
      if(mn>ray.s.dis(res.s)) mn=ray.s.dis(res.s),nray = res;
    }
    if(mn==INF) return ray.s;
    ray = nray;
    
  }
}

int main(){
  while(cin>>n,n){
    L3 start;
    cin>>start.t.x>>start.t.y>>start.t.z;
  
    A.resize(n);  
    for(int i=0;i<n;i++)cin>>A[i].x>>A[i].y>>A[i].z>>A[i].r;

    p3 ans = calc(start);
    printf("%Lf %Lf %Lf\n",ans.x,ans.y,ans.z);
  }
  return 0;
}

Measured memory_bytes: 3188
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il ll ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register ll x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}
const int N = 1e5 + 10, M = 2e5 + 30;
int n, m;
struct edge {
    int y, nxt, id;
}e[M << 1];
int lin[M], len;
int dis[N], pos[N];
bool vis[N];
set<int> c[N];

inline int read() {
    int s = 0, f = 1;
    char ch;
    for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-')   f = -1;
    for(; ch >= '0' && ch <= '9'; ch = getchar())   s = (s << 1) + (s << 3) + ch - '0';
    return s * f;
}

inline void add(int xx, int yy, int vv) {
    e[++len] = (edge){yy, lin[xx], vv};
    lin[xx] = len;
}

inline void Dijkstra() {
    priority_queue< pair < int, int > > q;
    memset(dis, 0x3f, sizeof(dis));
    memset(vis, 0, sizeof(vis));
    dis[1] = 0;
    q.push(make_pair(0, 1));
    while(!q.empty()) {
        int x = q.top().second; q.pop();
        if(vis[x])  continue;
        vis[x] = 1;
        for(int i = lin[x]; i; i = e[i].nxt) {
            int y = e[i].y, v = c[x].count(e[i].id) ? 0 : 1;
            if(dis[y] > dis[x] + v) {
                dis[y] = dis[x] + v;
                q.push(make_pair(-dis[y], y));
                c[y].clear();
                c[y].insert(e[i].id);
            } else if(dis[y] == dis[x] + v) c[y].insert(e[i].id);
        }
    }
}

int main() {
    n = read(), m = read(); 
    if(m == 0) { puts("-1"); return 0; }
    for(int i = 1; i <= m; ++i) {
        int xx = read(), yy = read(), vv = read();
        add(xx, yy, vv);
        add(yy, xx, vv);
    }
    Dijkstra();
    printf("%d\n", dis[n] == 0x3f3f3f3f ? -1 : dis[n]);
    return 0;
}


Measured memory_bytes: 20984
#include<bits/stdc++.h>
using namespace std;
#define maxn 10010
typedef long long ll;
typedef long double ld;
const ll inF=1e18;
string s;
int n,dem=0;
int main(){
    ios_base::sync_with_stdio(0);
    map<string,int> dd;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>s;
        dd[s]++;
        if (dd[s]==1) dem++;
    }
    cout << dem << endl;
}


Measured memory_bytes: 19236
from collections import deque
n, u, v = map(int, input().split())
u -= 1
v -= 1
edges = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
def bfs(u):
    visited = [-1] * n
    Q = deque()
    visited[u] = 0
    Q.append(u)
    while Q:
        p = Q.popleft()
        for v in edges[p]:
            if visited[v] == -1:
                visited[v] = visited[p] + 1
                Q.append(v)
    return visited
tak_dist = bfs(u)
aok_dist = bfs(v)
ans = []
for i in range(n):
    if tak_dist[i] < aok_dist[i]:
        ans.append(aok_dist[i])
print(max(ans) - 1)

Measured memory_bytes: 34424
N=int(input())
A=[int(i) for i in input().split()]
T=[]
for i in range(N):
  if i==0:
    T.append(A[i])
  else:
    T.append(T[i-1]+A[i])
ans=float("inf")
x=1
y=1
for i in range(2,N):
  while abs(T[i-1]-2*T[x-1])>abs(T[i-1]-2*T[x]):
    x+=1
  while abs(T[i-1]+T[N-1]-2*T[y-1])>abs(T[i-1]+T[N-1]-2*T[y]):
    y+=1
  P=T[x-1]
  Q=T[i-1]-T[x-1]
  R=T[y-1]-T[i-1]
  S=T[N-1]-T[y-1]
  A=max(P,Q,R,S)
  B=min(P,Q,R,S)
  ans=min(ans,A-B)
print(ans)  
  
  

  


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

typedef struct queue
{
    unsigned int *data;
    int head;
    int tail;
    int inputK;
} queue;

void initialization(queue *q, int inputK)
{
    q->head = 0;
    q->tail = 9;
    q->inputK = inputK;
    if (q->inputK < 10)
    {
        q->inputK = 100;
    }
    q->data = (unsigned int *)malloc(sizeof(unsigned int) * q->inputK);
    for (int index = 0; index < q->inputK; index++)
    {
        q->data[index] = 0;
    }
    for (int index = 0; index < 9; index++)
    {
        q->data[index] = index + 1;
    }
}

int enqueue(queue *q, unsigned int item)
{
    if (q->tail >= q->inputK)
    {
        return -1;
    }
    else
    {
        q->data[q->tail] = item;
        q->tail++;
        return 0;
    }
}

int dequeue(queue *q)
{
    unsigned int tmp;
    if (q->head > q->tail)
    {
        return -1;
    }
    else
    {
        tmp = q->data[q->head];
        q->head++;
        return tmp;
    }
}

int main(void)
{
    int inputK, tmp;
    scanf("%d", &inputK);
    queue q;
    initialization(&q, inputK);
    for (int count = 0; count < inputK - 1; count++)
    {
        tmp = dequeue(&q);
        if (tmp % 10 != 0)
        {
            enqueue(&q, tmp * 10 + (tmp % 10) - 1);
        }
        enqueue(&q, tmp * 10 + (tmp % 10));
        if (tmp % 10 != 9)
        {
            enqueue(&q, tmp * 10 + (tmp % 10) + 1);
        }
    }
    tmp = dequeue(&q);
    printf("%u", tmp);
    queue *p_q = &q;
    free(p_q->data);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define debug(x) if(MODE==x)
#define MODE 0
using namespace std;

int A[100007]={};
int B[100007];

int main()
{
    int i,j;
    int N;

    scanf("%d",&N);
    for( i=1; i<=N-1; i++)
    {
        scanf("%d",&B[i]);
    }

    A[1] = B[1];
    for( i=2; i<=N-1; i++)
    {
        A[i] = min(B[i-1],B[i]);
    }
    A[N] = B[N-1];

    int total = 0;
    for( i=1; i<=N; i++)
        total += A[i];

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


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  string s; cin >> s;
  ll ans = 0;
  int i = 0, n = s.size();
  while (i < n) {
    int j = i;
    while (j < n && s[i] == s[j]) j++;
    ans++;
    i = j;
  }
  outl(ans-1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 512
n,x= map(int,input().split())
tp=0
for i in range(n):
    ct = (2**(n-i+2)-4)//2+1
    if x==0:break
    if i==n-1:tp+='bpppb'[:x].count('p')
    else:
        pn = 2**(n-i)-1
        if x<ct:x-=1
        elif x>=ct:
            tp+=pn+1
            if x==ct:break
            x-=ct
print(tp)

Measured memory_bytes: 9196
import sys
input = sys.stdin.readline
from itertools import product


def read():
    X, Y, Z, K = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    C = list(map(int, input().strip().split()))
    return X, Y, Z, K, A, B, C


def solve(X, Y, Z, K, A, B, C, INF=10000000001):
    # 美味しさの上位K=3000件を出力する
    AB = [a+b for a, b in product(A, B)]
    AB.sort(reverse=True)
    AB = AB[:K]
    C.sort(reverse=True)

    D = [AB[k] + C[0] for k in range(len(AB))]
    E = [0 for k in range(len(AB))]
    j = 0
    for k in range(K):
        hi = 0

        # find
        for i in range(len(D)):
            if D[hi] < D[i]:
                hi = i
        # print
        print(D[hi])

        # update
        E[hi] += 1
        if E[hi] >= len(C):
            D[hi] = -INF
        else:
            D[hi] = AB[hi] + C[E[hi]]


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)


Measured memory_bytes: 69092
import java.util.Scanner;

public class Main {

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

      int N = in.nextInt();
      int N1000 = N / 1000;
      N = N % 1000;
      int N100 = N / 100;
      N = N % 100;
      int N10 = N / 10;
      N = N % 10;
      int N1 = N;

      if(((N1000 == N100)&&(N100 == N10))||((N100 == N10)&&(N10 == N1))){
          System.out.println("Yes");
      }
      else {
          System.out.println("No");
      }

    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll  vo[100005] ; //両方かっこの中箱番号
ll seigo[100005] ;//入っている可能性があるかどうか
int main(){
 ll n,m ; 
 cin>> n>> m;
 vector<ll> A(m) ;
 vector<ll> B(m) ;
 rep(i,m){
   cin>>A[i] >>B[i] ;
   A[i] --;B[i] -- ;
 }
 rep(i,n) vo[i] =1 ;
 seigo[0] = 1 ;
 rep(i,m){
   vo[A[i]]-- ;
   vo[B[i]] ++ ;
   if(seigo[A[i]]==1)
   seigo[B[i]]=1 ;
   if(vo[A[i]]==0)
   seigo[A[i]] =0 ;
 }
 ll ans= 0;
 rep(i,n){
   if(seigo[i]==1) 
   ans++ ;
 }
   
   cout <<ans <<endl ;

   return 0;
}

Measured memory_bytes: 3328
package main

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

type Node struct {
	key                 int
	parent, left, right *Node
}

type BinarySearchTree struct {
	root *Node
	n    int
}

func (bst *BinarySearchTree) insert(x int) bool {
	p := bst.findLast(x)
	u := &Node{key: x}
	return bst.addChild(p, u)
}

func (bst *BinarySearchTree) findLast(x int) *Node {
	w := bst.root
	var prev *Node

	for w != nil {
		prev = w
		if x < w.key {
			w = w.left
		} else {
			w = w.right
		}
	}
	return prev
}

func (bst *BinarySearchTree) addChild(p, u *Node) bool {
	if p == nil {
		bst.root = u
	} else {
		if u.key < p.key {
			p.left = u
		} else {
			p.right = u
		}
		u.parent = p
	}
	bst.n++
	return true
}

func (bst *BinarySearchTree) find(x int) *Node {
	u := bst.root

	for u != nil && x != u.key {
		if x < u.key {
			u = u.left
		} else {
			u = u.right
		}
	}
	return u
}

func preorder(u *Node, keys []int) []int {
	if u != nil {
		keys = append(keys, u.key)
		keys = preorder(u.left, keys)
		keys = preorder(u.right, keys)
	}
	return keys
}

func inorder(u *Node, keys []int) []int {
	if u != nil {
		keys = inorder(u.left, keys)
		keys = append(keys, u.key)
		keys = inorder(u.right, keys)
	}
	return keys
}

func print(keys []int) {
	w := bufio.NewWriter(os.Stdout)
	for _, key := range keys {
		w.Write([]byte(fmt.Sprintf(" %d", key)))
	}
	w.Write([]byte("\n"))
	w.Flush()
}

func main() {
	var n int
	fmt.Scan(&n)

	bst := new(BinarySearchTree)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := 0; i < n; i++ {
		sc.Scan()
		command := sc.Text()

		if command == "insert" {
			sc.Scan()
			x, _ := strconv.Atoi(sc.Text())
			//insert
			bst.insert(x)
		} else if command == "print" {
			//print
			print(inorder(bst.root, []int{}))
			print(preorder(bst.root, []int{}))
		} else if command == "find" {
			sc.Scan()
			x, _ := strconv.Atoi(sc.Text())
			//find
			u := bst.find(x)
			if u != nil {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		}
	}

	return
}



Measured memory_bytes: 36372
n,k=map(int,input().split())
g=[[[0,0] for i in range(k)] for j in range(k)]

for i in range(n):
    x,y,c=input().split()
    x,y=int(x),int(y)
    if y%(2*k)<k and x%(2*k)<k:
        g[y%(2*k)][x%(2*k)][c=="W"]+=1
    elif y%(2*k)<k:
        g[y%(2*k)][x%(2*k)-k][c=="B"]+=1
    elif x%(2*k)<k:
        g[y%(2*k)-k][x%(2*k)][c=="B"]+=1
    else:
        g[y%(2*k)-k][x%(2*k)-k][c=="W"]+=1

ac=[[[0]*(k+1) for i in range(k+1)] for l in range(2)]
for l in range(2):
    for i in range(k):
        for j in range(k):
            ac[l][i+1][j+1]=ac[l][i][j+1]+ac[l][i+1][j]-ac[l][i][j]+g[i][j][l]

ans=0
for i in range(k):
    for j in range(k):
        ans=max(ac[0][k][k]-ac[0][i][k]-ac[0][k][j]+2*ac[0][i][j]+ac[1][i][k]+ac[1][k][j]-2*ac[1][i][j],ans)
        ans=max(ac[1][k][k]-ac[1][i][k]-ac[1][k][j]+2*ac[1][i][j]+ac[0][i][k]+ac[0][k][j]-2*ac[0][i][j],ans)
print(ans)

Measured memory_bytes: 179520
import collections
k=int(input())
if k<=9:
    print(k)
else:
    k-=9
    l =list(range(9,0,-1))
    #print(l)
    q = collections.deque(l)
    counter=0
    while counter<k:
        x=q.pop()
        xrem=x%10
        if xrem!=0:
            q.appendleft(10*x+xrem-1)
            counter+=1
            if counter>=k:
                break
        q.appendleft(10*x+xrem)
        counter+=1
        if counter>=k:
                break
        if xrem!=9:
            q.appendleft(10*x+xrem+1)
            counter+=1
    print(q[0])


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

int rlarge(int n)
{
 if(n < 0) return -n;
 else return n;
}

int dp[100010];//dp[N]を足場Nまでのコストの最小値とする

int main()
{
 int N;
 int h[100010];
 cin >> N;
 h[0] = 0;   
 for(int i = 1; i <= N; i++) cin >> h[i];
 dp[0] = dp[1] = 0;//dp初期条件
 dp[2] = rlarge(h[2] - h[1]);
 for(int i = 1; i < N - 1; i++){
  dp[i + 2] = min(dp[i] + rlarge(h[i] - h[i + 2]),dp[i + 1] + rlarge(h[i + 1] - h[i + 2]));
 }
 cout << dp[N];
 return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, T;
    cin >> n >> T;

    const int INF = 1 << 28;
    int res = INF;

    for (int i = 0; i < n; ++i) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            res = min(res, c);
        }
    }

    if (res < INF) {
        cout << res << '\n';
    } else {
        cout << "TLE" << '\n';
    }


    return 0;
}

Measured memory_bytes: 256
# Problem D - Teleporter

# input
N, K = map(int, input().split())
a_list = list(map(int, input().split()))

# initialization
visit_list = [0] * N
pos = a_list[0]
visit_list[pos-1] = 1
visit_count = 1
remain = K - 1
is_ok = True
ans = 0

# count
while remain>0 and is_ok:
    pos = a_list[pos-1]
    remain -= 1
    visit_count += 1
    if pos==1 or not visit_list[pos-1]==0:
        tmp_1 = visit_count - visit_list[pos-1]
        tmp_2 = remain % tmp_1
        for t in range(tmp_2):
            pos = a_list[pos-1]
        is_ok = False
        break
    else:
        if not pos==1 and visit_list[pos-1]==0:
            visit_list[pos-1] = visit_count

# output
print(pos)


Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(ALLR(b));
  int first = b.at(0);
  int second = b.at(1);
  rep(i,n){
    if(a.at(i)!=first){
      cout << first << endl;
    }else{
      cout << second << endl;
    }
  }
}

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

long long N, Q, K;

vector<pair<long long, long long> >tree[100005];
long long x[100005];
long long y[100005];
long long dist[100005];

int main(){
	cin >> N;
	for(long long i = 0; i < N-1; i++){
		long long a, b, c;
		cin >> a >> b >> c;
		a--;b--;
		tree[a].push_back(make_pair(b, c));
		tree[b].push_back(make_pair(a, c));
	}

	cin >> Q >> K;K--;
	for(long long i = 0; i < Q; i++){
		cin >> x[i] >> y[i];
		x[i]--;y[i]--;
	}

	for(long long i = 0; i < N; i++){
		dist[i] = INT_MAX;
	}

	priority_queue<pair<long long, long long>,
			vector<pair<long long, long long> >,
			greater<pair<long long, long long> > >Que;
	set<long long> visit;

	Que.push(make_pair(0, K));

	while(!Que.empty()){
		long long pos = Que.top().second;
		long long cost = Que.top().first;
		Que.pop();

		if(visit.count(pos) != 0)
			continue;

		visit.insert(pos);
		dist[pos] = cost;
		for(long long i = 0; i < tree[pos].size(); i++){
			long long to = tree[pos][i].first;
			long long newcost = cost + tree[pos][i].second;
			if(visit.count(to) != 0){
				continue;
			}
			Que.push(make_pair(newcost, to));
		}
	}

	for(long long i = 0; i < Q; i++){
		cout << dist[x[i]] + dist[y[i]] << endl;
	}
}


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

using namespace std;

int n ,m;

int main()
{
    int cas;
    cin >> cas;
    for(int i = 0 ;i < cas;i++) {
        scanf("%d%d",&m,&n);
        if(m *m + n * n <= 1) {
            puts("C");
            continue;
        }
        int div = 0;
        int sq = sqrt((double) m*m + n*n) + 0.1;
        for(int f = -sq; f <= sq;f ++)
            for(int g = -sq;g <= sq;g++) {
                int tt = f*f + g*g;
                if(0 == tt)
                    continue;
                int a = m*f + n*g;
                int b = m*g - n*f;
                if(0 == a%tt && 0 == b%tt) {
                    div ++;
                }
            }
        if(8 == div)
            puts("P");
        else
            puts("C");
    }
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;
// 変数初期化
vector<ll> bsv; // binary_search用のvector
ll a,b,c,n,m;
typedef pair<ll, ll> Pll;
vector<Pll> facts; // 素因数分解の結果格納用(基数:乗数)
vector<vector<ll> > bit_search_v; //nit全探索の結果格納用

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (bsv[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(int key) {
    int ng = -1;
    int ok = (ll)bsv.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    // OK(key以上となる)のindex番号を返す
    return ok;
}

// 最大公約数
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

// 最小公倍数
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

//　素因数分解
void prime_fact(ll target){
    ll base=2, exp=0;
    while (base*base<=target) {
        while (target%base==0) {
            target /= base; exp++;
        }
        if (exp>0) {
            facts.push_back(make_pair(base, exp));
        }
        base++; exp=0;
    }
    if (target>1) facts.push_back(make_pair(target,1));
}
// prime_factの結果の確認用
void print_facts(){
    for (int i=0; i<facts.size(); i++) {
        cout << facts[i].first << " " << facts[i].second << endl;
    }
}

// bit全探索
void bit_search(ll target){
    for (ll i=0; i<(1<<target); ++i) {
        if (i==0) continue;
        vector<ll> v;
        for (ll j=0; j<target; ++j) {
            if (i&(1<<j)) v.push_back(j);
            if (i&(1<<j)) cout << i << "  :  " << j << endl;
        }
        bit_search_v.push_back(v);
    }
}
// bit全探索の結果確認用
void print_bit_search(){
    for (ll i=0; i<bit_search_v.size(); ++i) {
        for (ll j=0; j<bit_search_v[i].size(); ++j) {
            cout << bit_search_v[i][j] << " ";
        }
        cout << endl;
    }
}





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

    cin >> n >> m;
    vector<int> good(n,1);
    vector<ll> h(n,0),A(m,0),B(m,0);
    for(ll i = 0; i < n;i++){
        cin >> h[i];
    }
    for(ll i = 0; i < m;i++){
        cin >> A[i] >>  B[i];
    }

    for(ll i = 0; i < m;i++){
        if(h[A[i]-1] > h[B[i]-1]){
            good[B[i]-1] = 0;
        }else if(h[A[i]-1] < h[B[i]-1]){
            good[A[i]-1] = 0;
        }else{
            good[B[i]-1] = 0;
            good[A[i]-1] = 0;
        }
    }

    ll ans =0 ;
    for(ll i = 0; i < n;i++){
        if(good[i] == 1) ans++;
    }

    cout << ans << endl;


    return 0;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, x, y;
    string s, t;


    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    auto tri = [&](bool t, string a, string b){
        cout << (t ? a : b) << endl;
    };

    cin >> a >> b;
    for(int i = 0; i < a; ++i){
        for(int j = 0; j < b; ++j){
            cin >> s;
            if(s == "snuke"){
                cout << char('A' + j) << i + 1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
 
using namespace std;
 
int main() {
 
    int a[5];
    int kari;
    char d;
     
    while (cin >> a[0] >> d >> a[1] >> d >> a[2] >> d >> a[3] >> d >> a[4]) {
        for (int i = 4; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[j+1]) {
                    kari = a[j];
                    a[j] = a[j+1];
                    a[j+1] = kari;
                }
            }
        }
        if (a[0] == a[1] || a[1] == a[2] || a[2] == a[3] || a[3] == a[4]) {
            if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3]) || (a[2] == a[3] && a[3] == a[4])) {
                if (((a[0] == a[1] && a[1] == a[2]) && (a[3] == a[4])) || ((a[0] == a[1]) && (a[2] == a[3] && a[3] == a[4]))) {
                    cout << "full house" << endl;
                } else if ((a[0] == a[1] && a[1] == a[2] && a[2]==a[3]) || (a[1] == a[2] && a[2] == a[3] && a[3] == a[4])){
                    cout << "four card" << endl;
                }else {
                    cout << "three card" << endl;
                }
            } else if ((a[0] == a[1] && a[2] == a[3]) || (a[0] == a[1] && a[3] == a[4]) || (a[1] == a[2] && a[3] == a[4])) {
                if ((a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) || (a[1] == a[2] && a[2] == a[3] && a[3] == a[4])) {
                    cout << "four card" << endl;
                } else {
                    cout << "two pair" << endl;
                }
            } else {
                cout << "one pair" << endl;
            }
        } else if ((a[1] == a[0] + 1 && a[2] == a[1] + 1 && a[3] == a[2] + 1 && a[4] == a[3] + 1) || (a[0]  == 1 && a[1] == 10 && a[2] == a[1] + 1 && a[3] == a[2] + 1 && a[4] == a[3] + 1)){
            cout << "straight" << endl;
        } else {
            cout << "null" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1156
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    string a;
    cin >> a;
    
    for (int i = 0; i < (int)a.size(); i++) {
        cout << "x";
    }
    cout << endl;

    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
import numpy as np
mod = 10**9 + 7

s = input()[::-1]
#s = "?"*(10**5)
n = len(s)
DP = [[0]*3 for i in range(n+1)]

power_three = 1

for i, c in enumerate(list(s)):
    for j in range(3):
        if c == "?":
            DP[i+1][j] = 3*DP[i][j] % mod
        else:
            DP[i+1][j] = DP[i][j] % mod
    if c == "C" or c == "?":
        DP[i+1][0] = (DP[i+1][0] + power_three) % mod
    if c == "B" or c == "?":
        DP[i+1][1] = (DP[i+1][1] + DP[i][0]) % mod
    if c == "A" or c == "?":
        DP[i+1][2] = (DP[i+1][2] + DP[i][1]) % mod
    if c == "?":
        power_three = 3*power_three % mod
print(DP[n][2] % mod)

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    int x, a;
    cin >> x >> a;
    if(x < a) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
//In the name of God
//SMani24
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, ma;
string s;
set<string> ans;
map<string, int> cnt;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		ma = max(ma, ++cnt[s]);
	}
	for (auto i : cnt)
		if (i.se == ma)
			ans.insert(i.fi);
	for (string i : ans)
		cout << i << endl;
	return 0;
}


Measured memory_bytes: 34560
unittest
{
	assert( [ "3", "1 1", "5 1", "5 5" ].parse.expand.solve == 1 );
	assert( [ "2", "10 10", "20 20" ].parse.expand.solve == 0 );
	assert( [ "9", "1 1", "2 1", "3 1", "4 1", "5 1", "1 2", "1 3", "1 4", "1 5" ].parse.expand.solve == 16 );
	
	assert( [ "4", "1 1", "5 1", "1 5", "5 5" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto xys = new long[ 2 ][ n ];
	foreach( ref xy; xys )
	{
		input.popFront;
		xy = input.front.split.to!( long[] );
	}
	return tuple( xys );
}

auto solve( long[ 2 ][] xys )
{
	const XM = 10 ^^ 5;
	const YM = 10 ^^ 5 * 2;
	
	// X座標とY座標で二部グラフを作る
	auto uft = UnionFindTree( YM + 1 );
	foreach( xy; xys )
	{
		uft.unite( xy[ 0 ], XM + xy[ 1 ] );		// X座標とかぶらないようにY座標は下駄を履かせる
	}
	
	// 連結成分ごとにX座標とY座標の種類数を数える
	long[ long ] rxs;
	long[ long ] rys;
	for( auto i = 1L; i <= XM; i++ )
	{
		if( uft.weight( i ) <= 1 ) continue;		// このX座標には頂点が無い
		rxs[ uft.root( i ) ]++;
	}
	for( auto i = XM + 1; i <= YM; i++ )
	{
		if( uft.weight( i ) <= 1 ) continue;		// このY座標には頂点が無い
		rys[ uft.root( i ) ]++;
	}
	
	// 連結成分ごとに完全グラフにしたときの頂点の数を計算
	auto ans = 0L;
	for( auto i = 1L; i <= YM; i++ )
	{
		if( i !in rxs || i !in rys ) continue;
		ans += rxs[ i ] * rys[ i ];
	}
	
	// 完全グラフの頂点数から元の頂点数を抜くと追加する頂点数になる
	return ans - xys.length;
}

// UnionFind木
struct UnionFindTree
{
	private long[] ps;
	private long[] rs;
	
	public this( long n )
	{
		ps.length = n;
		ps[] = -1;
		rs.length = n;
	}
	
	public long root( long i )
	{
		if( ps[ i ] < 0 ) return i;
		else              return ps[ i ] = root( ps[ i ] );
	}
	
	public bool same( long i, long j )
	{
		return root( i ) == root( j );
	}
	
	public void unite( long i, long j )
	{
		i = root( i );
		j = root( j );
		if( i == j ) return;
		if( rs[ i ] < rs[ j ] )
		{
			ps[ j ] += ps[ i ];
			ps[ i ] = j;
		}
		else
		{
			ps[ i ] += ps[ j ];
			ps[ j ] = i;
			if( rs[ i ] == rs[ j ] ) rs[ i ]++;
		}
	}
	
	public long weight( long i )
	{
		return -ps[ root( i ) ];
	}
}


Measured memory_bytes: 8444
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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


const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long double A,B,H,M;
  cin>>A>>B>>H>>M;
  long double m=60*H+M;
  long double t=2*acos(-1)*m/720-2*acos(-1)*m/60;

  cout<<setprecision(20)<<sqrtl(A*A+B*B-2*A*B*cosl(t))<<endl;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, l;
    cin >> n >> l;
    int m = INT32_MAX;
    int sum = 0;
    rep1(i, n) {
        if (abs(m) > abs(l+i-1)) m = l+i-1;
        sum += l+i-1;
    }
    cout << sum - m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

const ll inf = 1LL << 60;

int n;
ll dp[110000][3];
ll abc[110000][3];

int main(){
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    }

    int prev = 3;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i][k] = max(dp[i][k],dp[i-1][j] + abc[i-1][k]);
            }
        }
    }

    ll res = max(dp[n][0],dp[n][1]);
    res = max(res,dp[n][2]);

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 5120
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)


main :: IO ()
main = do
    n <- readLn
    as <- r n
    bs <- r n
    cs <- r (n-1)
    let ms = U.map ((bs U.!) . pred) as
    let ads = addit (U.head as) cs (U.tail as)
    --print ms
    --print ads
    print (U.sum ms + U.sum ads)


addit lst cs as
    | U.null as = U.empty
    | otherwise = let a = U.head as
            in U.cons (if lst+1 == a then cs U.! (a-2) else 0) (addit a cs (U.tail as))




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

int main() {
  ll n;
  cin >> n;
  ll ans = 1e12 + 10;
  for (ll i = 1; i < 1000100; i++) {
    if (n % i == 0) {
      ll j = n / i;
      ans = min(ans, i + j - 2);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define Max 500000
#define NIL NULL

struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *p; 

};

typedef struct node *Node;
 
Node  root;


void insert(int  z){

  Node data;
  Node x;
  Node y;

  y = NIL;
  x = root;

  data = malloc(sizeof(struct node));
  data->key = z;
  data->right = NIL;
  data->left = NIL;
  data->p = NIL;

  while( x != NIL ){
    y = x;
    if( data->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  
  data->p = y;
  
  if( y == NIL)
    root = data;
  else if( data->key < y->key)
    y->left = data;
  else 
    y->right = data;
}

void print1(Node u){
  if( u == NIL)
    return;
  print1(u->left);
  printf(" %d",u->key);
  print1(u->right);
}

void print2(Node u){
  if( u == NIL)
    return;
  printf(" %d",u->key);
  print2(u->left);
  print2(u->right);
}

Node treeSearch(Node x, int k){
  if( x == NIL || k == x->key)
    return x;
  if(k < x->key)
    return treeSearch(x->left, k);
  else
    return treeSearch(x->right, k);
}

int main(){

  int i, m, num;
  char order[10];
  char order1[] = "insert";
  char order2[] = "print"; 
  char order3[] = "find";

  scanf("%d",&m);

  for( i = 0 ; i < m ; i++){
    scanf("%s",order);

 
    if( (strcmp(order,order1)) == 0){
      scanf("%d",&num );
      insert(num);
    }
    if(( strcmp(order,order2)) == 0){
      print1(root);  
      printf("\n");
      print2(root);
      printf("\n");
    }
    if(( strcmp(order,order3)) == 0){
      scanf("%d",&num );
      if((treeSearch(root,num)) != NIL)
	printf("yes\n");
      else
	printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19372
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};

int main() {
    int a,b,k,ans=0;
    cin >> a>>b>>k;
    for (int i = min(a,b); i >= 1; i--) {
        if (a%i==0 && b%i==0){
            ans++;
            if (ans==k){
            cout << i << endl;
            break;
            }
        }
    }
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

class modint {
  private:
    ll m_val;
    ll m_mod;
  public:
    constexpr modint() : m_val(0), m_mod() { m_mod = MOD; }
    constexpr modint(const ll x) : m_val(0), m_mod(0) { m_mod = MOD; m_val = x % m_mod; }
    constexpr modint(const ll x, const ll mod) : m_val(0), m_mod(0) { m_mod = mod; m_val = x % m_mod; }
    constexpr ll val() const { return m_val; }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) {
      m_val += rhs.m_val;
      if (m_val >= m_mod) m_val -= m_mod;
      return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
      if (m_val < rhs.m_val) m_val += m_mod;
      m_val -= rhs.m_val;
      return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
      m_val = m_val * rhs.m_val % m_mod;
      return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
      *this *= rhs.inv();
      return *this;
    }
    constexpr modint pow(ll n) const {
      if (n == 0) return 1;
      modint o = pow(n >> 1);
      o *= o;
      if (n & 1) o *= *this;
      return o;
    }
    constexpr modint inv() const {
      return pow(m_mod - 2);
    }
    friend ostream& operator<<(ostream& os, const modint &a) { os << a.val(); return os; }
};

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

  if (abs(n-m) > 1) {
    cout << 0 << endl;
    return 0;
  }

  modint inu = 1;
  for (ll i = n; i > 0; --i) {
    inu *= i;
  }

  modint saru = 1;
  for (ll i = m; i > 0; --i) {
    saru *= i;
  }

  modint ans = inu * saru;
  if (n == m) ans *= 2;
  
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;
int f[100050];
int main()
{
    int n,k,cnt=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&f[i]);
        if(f[i]>=k)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG_ARR(x, a, b) for(int i=a; i<=b; i++) cerr<<x[i]<<" "; cerr<<endl;
#define DEBUG_STR(x, a, b) for(int i=a; i<=b; i++) cerr<<x[i]; cerr<<endl;


using namespace std;

typedef long long ll;
typedef unsigned long long llu;

int main() {
	FIO;
	string s;
	cin>>s;
	if(s[0] == '7' || s[1] == '7' || s[2] == '7' ) cout<<"Yes";
	else cout<<"No";	
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define BIG 1000000007
#define ll long long int

int main(){
  int y,m,d;
  bool b;
  string s;
  while(1){
    cin>>s;
    if(s=="#") break;
    cin>>y>>m>>d;
    b=true;
    if(y>31) b=false;
    else if(y==31){
      if(m>4) b=false;
    }
    if(b) cout<<"HEISEI"<<" ";
    else cout<<"?"<<" ";
    if(b) cout<<y<<" "<<m<<" "<<d<<endl;
    else cout<<y-30<<" "<<m<<" "<<d<<endl;
  }
  return 0;
}
	



Measured memory_bytes: 3152