akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n, ans = inf; cin >> n;
    string s,t;
    for(i32 a = 1, b = n-1; a < n && b >= 0; ++a, --b) {
        s = to_string(a);
        t = to_string(b);
        i32 tmp = 0;
        for(auto ch : s) tmp += (i32)(ch-'0');
        for(auto ch : t) tmp += (i32)(ch-'0');
        chmin(ans, tmp);
    }
    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 384
import math
a, b, h, m = map(int, input().split())
deg_long = (60 * h + m) * 6
deg_short = (60 * h + m) / 2
len_2 = a*a + b*b - 2 * a * b * math.cos(math.radians(deg_long - deg_short))
print(math.sqrt(len_2))

Measured memory_bytes: 62516
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int count = 0;
        for(int i = 1 ; i <= A / 2 ; i++) {
            if(i != (A - i))count++;
        }
        System.out.println(count);
    }
}


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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;


  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

//int s[10005];
set<int> s;
int t[502];

int main()
{
	s.clear();
	memset (t, 0, sizeof (t ) );

	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	int in;
	rep (i, n ) cin >> in, s.insert (in );
	int q; cin >> q;
	rep (j, q ) cin >> t[j];

	ll res = 0LL;
	rep (j, q ){
		set<int>::iterator it = s.begin();
		for (; it != s.end(); it++ ){
			int cand = (*it);
			if (cand == t[j] ){
				res++;
				break;
			} // end if	
		} // end rep
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;

int main() {
    ll n, k;
    int t = 1;
    cin >> n >> k;
    vector<int> a(n+1, 0);
    RE(i,n)
        cin >> a[i];
    // cout << n << " " << k << " " << to_string(a) << endl;
    map<int, int> tm;

    ll cur = 1, lambda, theta;
    bool flag = false;
    while(t < k){
        if (tm.count(cur)){
            lambda = cur;
            theta = t- tm[cur];
            flag = true;
            break;
        }

        // cout << to_string(tm) << endl;

        tm[cur] = t++;
        cur = a[cur];
    }

    if (!flag){
        cout << a[cur] << endl;
        return 0;
    }


    // cout << "t: " << t << endl;
    int steps = ((k-t+1) % theta);
    cur = lambda;
    for(int i = 0; i < steps; i++){
        // cout << cur << endl;
        cur = a[cur];
    }
    // cout << lambda << " " << theta << " " << steps << endl;
    cout << cur << endl;
    return 0;
}

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

int main() {
    int n, s;
    string ans;
    
    cin >> n;
    
    while (n != 0) {
        s = n % 2;
        
        if (s < 0) {
            s += 2;
        }
        
        ans += (char)(s + '0');
        n = (n - s) / (-2);
    }
    
    reverse(ans.begin(), ans.end());
    
    if (ans == "") {
        ans = "0";
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int main()
{
	int n;
	int a[110];
	scanf("%d", &n);
	
	int count = 0;
	for (int i = 1 ; i <= n ; i++) {
		scanf("%d", &(a[i]));
		if ((i % 2 == 1) && (a[i] % 2 == 1)) {
			count++;
		}
	}
	
	printf("%d\n", count);
	
	
	
	return 0;
}


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

namespace lean {
    class Program {
        static void Main() {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < S.Length; i++) {
            if(S[i]!=T[i]){
                    count++;
            }
            }
            Console.WriteLine(count);
        }
    }
}

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

int main() {
  int N, sum, F;
  cin >> N;
  sum = 0;
  F = N;

  // ここにプログラムを追記
  for (int i = 0; i < 9; i++){
    sum += F % 10;
    F = F / 10;
  } 
  
  if (N % sum == 0) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }  

}


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

int main()
{
  ll n,a[200005];
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  ll dp[200005];
   dp[0]=0;
   dp[1]=abs(a[1]-a[0]);
   ll ans=INT_MAX;
  for(int i=2;i<n;i++)
  {
     ll v1=dp[i-1]+abs(a[i]-a[i-1]);
     ll v2=dp[i-2]+abs(a[i]-a[i-2]);
    dp[i]=min(v1,v2);
  } 
  cout<<dp[n-1]<<"\n";
  return 0;
}

Measured memory_bytes: 5084
number = input()

ans_list = []
indexes = [1, 3, 5]
def make_seven(num, index):
    if index == 3:
        if eval(num) == 7:
            ans_list.append(num+"=7")
        return

    make_seven(num[:indexes[index]]+"+"+num[indexes[index]:], index+1)
    make_seven(num[:indexes[index]]+"-"+num[indexes[index]:], index+1)

make_seven(number, 0)
print(ans_list[0])

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

long long s[100010];
long long t[100010];
int n, q, b;

bool BinSI(int n, long long a[], long long x)
{
    int l=1,r=n;
    while (l <= r)
    {
        int m=(l+r)/2;
        if (x==a[m]) return true;
        if (x < a[m])
            r=m-1;
        else
            l=m+1;
    }
    return false;
}

int main()
{
    b=0;
    cin >> n;
    for (int i=1; i<=n; i++)
        cin >> s[i];
    cin >> q;
    for (int i=1; i<=q; i++)
        cin >> t[i];
    for (int i=1; i<=q; i++)
    {
        if (BinSI(n, s, t[i]))
            b=b+1;
    }
    cout << b << endl;
    
    return 0;
}



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


int main(){
    int N;
    cin >> N;
    int F[111][11]; // 月:0,1,火:2,3,..., 金:8,9
    int P[111][11];
    for(int i=0; i<N; i++)
        for(int j=0; j<10; j++)
            cin >> F[i][j];
    for(int i=0; i<N; i++)
        for(int j=0; j<=10; j++)
            cin >> P[i][j];
    
    int Ma=-1e9;
    for(int bit=1; bit < (1<<10); bit++){
        
        int cnt[111];
        fill(cnt, cnt+111, 0);
        for(int i=0; i<10; i++){
            if(bit & (1<<i)){
                for(int j=0; j<N; j++){
                    if(F[j][i]==1){
                        cnt[j]++;
                    }
                }
            }
        }
        int sum=0;
        for(int i=0; i<N; i++){
            sum += P[i][cnt[i]];
        }
        //cout << bitset<10>(bit) <<" "<< sum << endl;
        Ma = max(Ma, sum);
    }
    cout << Ma << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int A,B,N;
	cin>>N>>A>>B;
	int ans=min(N*A,B);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int sort(int *a,int *b){
  return *a-*b;
}
  
int main(void){
int A,B,M;
  scanf("%d%d%d",&A,&B,&M);
  int a[A+1],b[B+1],x[M+1],y[M+1],c[M+1],amin=100000,bmin=100000;
  for(int i=0;i<A;i++){
	scanf("%d",&a[i]);
    if(amin>a[i])amin=a[i];
  }
  for(int i=0;i<B;i++){
	scanf("%d",&b[i]);
    if(bmin>b[i])bmin=b[i];
  }
  for(int i=0;i<M;i++){
	scanf("%d%d%d",&x[i],&y[i],&c[i]);
  }
  int money[M+1];
  for(int i=0;i<M;i++){
	money[i]=a[x[i]-1]+b[y[i]-1]-c[i];
  }
  money[M]=amin+bmin;
  qsort(money,M+1,sizeof(int),sort);
  printf("%d",money[0]);
  return 0;
}

Measured memory_bytes: 2940
klst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(klst[K - 1])

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int a[1000000];
int zd,cd,zd1,cd1;
int main(){
	int n=read();
	for(register int i=1;i<=n;i++){
		a[i]=read();
		if(a[i]>zd){
			cd=zd;
			cd1=zd1;
			zd=a[i];
			zd1=i;
		}
		else if(a[i]>cd){
			cd=a[i];
			cd1=i;
		}
	}
	for(register int i=1;i<=n;i++){
		if(i==zd1)printf("%d\n",cd);
		else printf("%d\n",zd);
	}
	return 0;
}

Measured memory_bytes: 2432
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


N,M,X=acinput()

books=[]
for i in range(N):
    books.append(acinput())
    

res=10**9
for k in range(2**N):
    bk=list(map(int,list(bin(k)[2:].zfill(N))))
    
    sm=0
    usd=np.array([0]*M)
    for l,s in enumerate(bk):
        if s==1:
            sm+=books[l][0]
            usd+=books[l][1:]
    
    #print(bk)
    #print(usd)
    if np.all(usd>=X):
        res=min(res,sm)
        
    
if res==10**9:
    print(-1)
else:
    print(res)
    
    

Measured memory_bytes: 27368
using System;

namespace ASevenFiveThree
{
    class P
    {
        private string Read()
        {
            return Console.ReadLine();
        }
        private int ReadInt()
        {
            return int.Parse(Read());
        }

        private void C()
        {
            var X = ReadInt();

            var ans = X == 7 || X == 5 || X == 3 ? "YES" : "NO";
            Console.WriteLine(ans);
        }
        static void Main(string[] args)
        {
            new P().C();

        }
    }
}


Measured memory_bytes: 11092
#include <iostream>

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

    long long cnt = 0, subCnt = 0;
    for(int i = 0; i < n; ++i){
        int val;
        std::cin >> val;
        if(i + 1 == val){
            ++subCnt;
        }else{
            cnt += (subCnt + 1) / 2;
            subCnt = 0;
        }
    }

    cnt += (subCnt + 1) / 2;

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define read() Read<int>()
using namespace std;
typedef long long ll;
const int N=1e5+5;
namespace pb_ds{   
    namespace io{
        const int MaxBuff=1<<15;
        const int Output=1<<23;
        char B[MaxBuff],*S=B,*T=B;
		#define getc() ((S==T)&&(T=(S=B)+fread(B,1,MaxBuff,stdin),S==T)?0:*S++)
        char Out[Output],*iter=Out;
        inline void flush(){
            fwrite(Out,1,iter-Out,stdout);
            iter=Out;
        }
    }
    template<class Type> inline Type Read(){
        using namespace io;
        register char ch;
        register Type ans=0; 
        register bool neg=0;
        while(ch=getc(),(ch<'0' || ch>'9') && ch!='-');
        ch=='-'?neg=1:ans=ch-'0';
        while(ch=getc(),'0'<= ch && ch<='9') ans=ans*10+ch-'0';
        return neg?-ans:ans;
    }
    template<class Type> inline void Print(register Type x,register char ch='\n'){
        using namespace io;
        if(!x) *iter++='0';
        else{
            if(x<0) *iter++='-',x=-x;
            static int s[100]; 
            register int t=0;
            while(x) s[++t]=x%10,x/=10;
            while(t) *iter++='0'+s[t--];
        }
        *iter++=ch;
    }
}
using namespace pb_ds;
int n;
struct GRAPH{
	struct edge{
		int next,to;
	}a[N<<1];
	int head[N],cnt,rt;
	inline void init(){
		for (int i=1;i<=n;++i){
			int x=read();
			if (~x) add(x,i);
			else rt=i;
		}
	}
	inline void add(int u,int v){
		a[++cnt].to=v;
		a[cnt].next=head[u];
		head[u]=cnt;
	}	
	int vis[N],w[N];
	void dfs(int x){
		w[x]=1;
		for (int i=head[x];i;i=a[i].next)
			dfs(a[i].to),w[x]^=1;
	}
	void solve(int x,int now){
		w[x]=now;vis[x]=1;
		for (int i=head[x];i;i=a[i].next)
			if (!vis[a[i].to]) solve(a[i].to,now^1);
	}
}t[2],g;
void work(int opt,int x){
	if (t[opt].w[x]) t[opt].vis[x]=x;
	for (int i=t[opt].head[x];i;i=t[opt].a[i].next){
		int y=t[opt].a[i].to;
		work(opt,y);
		if (t[opt].vis[x]){
			g.add(t[opt].vis[x],t[opt].vis[y]);
			g.add(t[opt].vis[y],t[opt].vis[x]);
			t[opt].vis[x]=0;
		}else t[opt].vis[x]=t[opt].vis[y];
	}
}
int main(){
	n=read();
	t[0].init();t[1].init();
	t[0].dfs(t[0].rt);t[1].dfs(t[1].rt);
	for (int i=1;i<=n;++i)
		if (t[0].w[i]!=t[1].w[i]){
			printf("IMPOSSIBLE\n");
			return 0;
		}
	work(0,t[0].rt);work(1,t[1].rt);
	printf("POSSIBLE\n");
	for (int i=1;i<=n;++i)
		if (t[0].w[i] && !g.vis[i])
			g.solve(i,1);
	for (int i=1;i<=n;++i)
		if (!t[0].w[i]) printf("0 ");
		else printf("%d ",g.w[i]?1:-1);
	printf("\n");
	return 0;
}

Measured memory_bytes: 12672
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int M=15,N=600005;
int n,m,Q;
char s[N];
int Pw[M];
struct Trie
{
	struct Node
	{
		int ch[3];
		int val;
		int tag;
		Node()
		{
			ch[0]=ch[1]=ch[2]=0;
			val=-1;
			tag=0;
			return;
		}
	}trie[N*3];
	int tot=1;
	void insert(int x)
	{
		vector<int>v;
		int t=x;
		while(t)
			v.push_back(t%3),t/=3;
		while(v.size()<m)
			v.push_back(0);
		int u=1;
		for(int c:v)
		{
			if(!trie[u].ch[c]) trie[u].ch[c]=++tot;
			u=trie[u].ch[c];
		}
		trie[u].val=x;
		return;
	}
	void push_down(int u)
	{
		if(!trie[u].tag) return;
		swap(trie[u].ch[1],trie[u].ch[2]);
		for(int i=0;i<3;i++)
			trie[trie[u].ch[i]].tag^=1;
		trie[u].tag=0;
		return;
	}
	void reverse(int u)
	{
		trie[u].tag^=1;
		return;
	}
	void add(int u)
	{
		if(!u) return;
		push_down(u);
		int t=trie[u].ch[2];
		trie[u].ch[2]=trie[u].ch[1];
		trie[u].ch[1]=trie[u].ch[0];
		trie[u].ch[0]=t;
		add(trie[u].ch[0]);
		return;
	}
	void query(int u,int sum,int dep,vector<int>&res)
	{
		if(!u) return;
		push_down(u);
		if(trie[u].val!=-1) res[trie[u].val]=sum;
		for(int i=0;i<3;i++)
			query(trie[u].ch[i],sum+i*Pw[dep],dep+1,res);
		return;
	}
}T;
int main()
{
	scanf("%d",&m);
	Pw[0]=1;
	for(int i=1;i<=m;i++)
		Pw[i]=Pw[i-1]*3;
	n=Pw[m];
	scanf("%s",s+1);
	Q=strlen(s+1);
	for(int i=0;i<n;i++)
		T.insert(i);
	for(int i=1;i<=Q;i++)
		if(s[i]=='S') T.reverse(1);
		else if(s[i]=='R') T.add(1);
	vector<int>res;
	res.resize(n);
	T.query(1,0,0,res);
	for(int u:res)
		printf("%d ",u);
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  char C; cin >> C;
  printf("%c", (C + 1));
  cout << endl;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

func main() {
	inputs := scanIntNums()
	N := inputs[0]
	K := inputs[1]
	var min, max, ans int

	for i := K; i <= N+1; i++ {
		// 0~i-1までの和
		min = (0 + (i - 1)) * i / 2
		// N-i+1~Nまでの和
		max = (N - (i - 1) + N) * i / 2
		ans += max - min + 1
	}

	fmt.Println(ans % (1e9 + 7))
}

func scanIntNums() (nums []int) {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums = make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}
	return nums
}


Measured memory_bytes: 1760
$_=<>;($a,$b)=glob<>;s#F+#push@{$`=~y/T//&1},length$&#ge;$a-=/^1/&&shift@0;map{*s=$_?b:a;map$s+=$s>0?-$_:$_,sort{$b-$a}@$_}0,1;print$a|$b?No:Yes

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N, T;
    cin >> N >> T;
    int t;
    cin >> t;
    int res = 0;
    for(int i = 1; i < N; ++i) {
        int a;
        cin >> a;
        res += min(a - t, T);
        t = a;

    }
    cout << res + T << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define MAX 105

int main(void){
	int N, M, i, cnt=0, sum=0;
	int A[MAX];

	scanf("%d %d", &N, &M);
	for (i=0; i<N; i++){
		scanf("%d", &A[i]);
		sum += A[i];
	}

	for (i=0; i<N; i++){
		if (A[i]*4*M >= sum)
			cnt++;
	}
	if (cnt < M)
		printf("No");
	else
		printf("Yes");

	return 0;
}

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

int main(){

int a[100];
int d;
for(int i=0;;i++){
int m,f,r;
cin>>m>>f>>r;
if(m==-1 && f==-1 && r==-1){d=i; break;}
if(m==-1 || f==-1){a[i]=-1; continue;}
if(m+f>=80){a[i]=3; continue;}
if(m+f>=65){a[i]=2; continue;}
if(m+f>=50){a[i]=1; continue;}
if(m+f>=30 && r>=50){a[i]=1; continue;}
if(m+f>=30){a[i]=0; continue;}
a[i]=-1;
}

for(int i=0;i<d;i++){
if(a[i]==-1){cout<<"F"<<endl;}
if(a[i]==0){cout<<"D"<<endl;}
if(a[i]==1){cout<<"C"<<endl;}
if(a[i]==2){cout<<"B"<<endl;}
if(a[i]==3){cout<<"A"<<endl;}
}

return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
vector<int> adj[maxn];
int dis[maxn];

int dfs(int cur)
{
	if(dis[cur] != 1) return dis[cur];
	else{

		int temp = 0;
		for(auto i : adj[cur]){
			temp = max(temp, dfs(i));
		}
		dis[cur] += temp;
	}
	return dis[cur];
}
int main(int argc, char const *argv[])
{
	int n, m; scanf("%d %d", &n, &m);
	int x, y;
	fill(dis, dis + n + 1, 1);
	for(int i = 0; i < m; i++){
		scanf("%d %d", &x, &y);
		adj[x].push_back(y);
	}
	int ans = 1;
	for(int i = 1; i <= n; i++) ans = max(ans, dfs(i));
	/*	
	for(int i = 1; i <= n; i++){
		printf("%d ", dis[i]);
	}
	*/
	printf("%d\n", ans-1);

	return 0;
}

Measured memory_bytes: 11628
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
struct Node{
    vector<int> next;
    int value;
    Node() : next(0xff, -1), value(-1) {}
};
vector<Node> nodes;
void insert(string s, int v){
    int p = 0;
    for(char c : s){
        if(nodes[p].next[c] == -1){
            nodes.push_back(Node());
            nodes[p].next[c] = nodes.size() - 1;
        }
        p = nodes[p].next[c];
    }
    nodes[p].value = v;
}
int main(){
    int n;
    int CASENUM = 1;
    while(cin >> n && n){
        nodes.clear();
        nodes.push_back(Node());
        vector<string> str(n);
        vector<int> vals(n);
        REP(i, n){
            cin >> str[i] >> vals[i];
            insert(str[i], vals[i]);
        }
        string s;
        cin >> s;

        vector<int> cur( nodes.size(), -1 );
        cur[0] = 0;
        for(char c : s){
            vector<int> next( nodes.size(), -1);
            for(int i = 0; i < nodes.size(); i++){
                if(cur[i] < 0) continue;
                int k = nodes[i].next[c];
                if(k == -1) continue;
                next[k] = max(next[k], cur[i]);
                if(nodes[k].value >= 0){
                    next[0] = max(next[0], cur[i] + nodes[k].value);
                }
            }
            cur.swap(next);
        }

        int m = cur[0];
        vector<int> dp(m + 1, INT_MAX);
        dp[0] = 0;
        for(int i = 0; i < m; i++){
            if(dp[i] == INT_MAX) continue;
            for(int j = 0; j < n; j++){
                int ni = i + vals[j];
                if(ni <= m) dp[ni] = min<int>(dp[ni], dp[i] + str[j].size());
            }
        }

        int answer = dp[m];

        assert(answer < INT_MAX);
        cout << "Case " << CASENUM++ << ": ";
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 6508
#include <stdio.h>
#include <string.h>

int main(){
	int n,i,a,b;
	int score[2];

	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}

		memset(score,0,sizeof(score));

		for(i = 0;i < n;i++){
			scanf("%d %d",&a,&b);

			if(a > b){
				score[0] += a+b;
			}else if(a < b){
				score[1] += a+b;
			}else{
				score[0] += a;
				score[1] += b;
			}
		}

		printf("%d %d\n",score[0],score[1]);
	}

	return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextInt();
            var b = cin.nextInt();
            var c = cin.nextInt();
            var d = cin.nextInt();
                       
            Console.WriteLine((Math.Abs(a-c)<=d || (Math.Abs(a-b)<=d && Math.Abs(b-c)<=d))?"Yes":"No"  );
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
std::vector<int> alpa(26,INF);
int main(){
    CIN(N);
    V<string> vec;
    V<map<char,int>> counter;
    REP(a,N){
        SCIN(s);
        vec.push_back(s);
        map<char,int> co;
        REP(b,s.size()){
            if(co.find(s.at(b)) == co.end()){
                co[s.at(b)]=1;
            }else{
                co[s.at(b)]++;
            }
        }
        REP(b,26){
            if(co.find(b + 'a')==co.end()){
                co[b+'a']=0;
            }
        }
        counter.push_back(co);
    }
    REP(a,N){
        FOREACH(b,counter.at(a)){
            alpa[b.first-'a'] = min(alpa[b.first -'a'],b.second);
        }
    }
    string ans;
    REP(a,26){
        if(alpa[a]==INF)alpa[a]=0;
        REP(b,alpa[a]){
            ans +=  a+'a';
        }
    }
    COUT(ans);

    return 0;
}


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

int main(){
  int N;
  string S;
  cin>>N>>S;
  
  int x=0;
  int a=0;
  
  for(int i=0;i<N;i++){
    if(S.at(i)=='I'){
      x++;
      a=max(a,x);
    }else{
      x--;
    }
  }
  cout<<a<<endl;
}
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int input = scan.nextInt();
        int A, B, C, D;
        D = input % 10;
        input /= 10;
        C = input % 10;
        input /= 10;
        B = input % 10;
        input /= 10;
        A = input;//

        if(A+B+C+D==7){
            System.out.println(A+"+"+B+"+"+C+"+"+D+"=7");
        }
        else if(A-B+C+D==7){
            System.out.println(A+"-"+B+"+"+C+"+"+D+"=7");
        }
        else if(A+B-C+D==7){
            System.out.println(A+"+"+B+"-"+C+"+"+D+"=7");
        }
        else if(A+B+C-D==7){
            System.out.println(A+"+"+B+"+"+C+"-"+D+"=7");
        }
        else if(A-B-C+D==7){
            System.out.println(A+"-"+B+"-"+C+"+"+D+"=7");
        }
        else if(A-B+C-D==7){
            System.out.println(A+"-"+B+"+"+C+"-"+D+"=7");
        }
        else if(A+B-C-D==7){
            System.out.println(A+"+"+B+"-"+C+"-"+D+"=7");
        }
        else if(A-B-C-D==7){
            System.out.println(A+"-"+B+"-"+C+"-"+D+"=7");
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
using namespace std;
int n,k,w[100005]={0};
bool judge(int p){
    int i=0,K=0;
    long long load=0;
    while(i<n){
        if(p<w[i])return false;
        if(load+w[i]<=p){
            load+=w[i];
            i++;
        }else{
            K+=(int)ceil(1.0*load/p);
            load=w[i++];

        }
    }
    if(load>0)K+=(int)ceil(1.0*load/p);
    if(K>k)return false;
    return true;
}
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>w[i];
    long long left=0,right=10005*100005,mid,result=0;
    while(left<right){
        mid=left+(right-left)/2;
        if(judge(mid)){
            result=mid;
            right=mid;
        }else left=mid+1;
    }
    cout<<result<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int ans[40];

void solve(int now, int ai){
	if(now == n){
		for (int i = 1;i <= ai;i++){
			cout << ans[i] << (i==ai? "\n" : " ");
		}
		return;
	}
	ans[ai]++;
	if(ans[ai-1] >= ans[ai])solve(now+1, ai);
	ans[ai]--;

	ai++;


	ans[ai]++;
	if(ans[ai-1] >= ans[ai])solve(now+1, ai);
	ans[ai]--;

	return;

}

int main() {

	ans[1] = 1;
	ans[0] = 100;

	while(true){
		cin >> n;
		if(n == 0) break;

		solve(1,1);

	}

	return 0;

}



Measured memory_bytes: 3084
// In the name of God
 
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=9;i++) {
		for(int j=1;j<=9;j++) {
			if(i*j==n) {
				cout << "Yes";
				exit(0);
			}
		}
	}
	cout << "No";
	return 0;
}

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

int main() {
  // input
  int n, x, i;
  cin >> n >> x;
  int l[n+1], d[n+1];
  d[0] = 0; l[0] = 0;
  for (i=1; i<=n; i++) {
    cin >> l[i];
  }

  // calc
  for (i=1; i<=10000; i++) {
    d[i] = d[i-1] + l[i-1];
    if (d[i]>x) break;
  }

  // output
  cout << i-1 << endl;

  return 0;
}


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

int main() {
  int A, B;
  string s;
  bool flag = true;
  cin >> A >> B >> s;
  for (int i=0; i<A+B+1; i++) {
    if ((i!=A && s[i]=='-') || (i==A && s[i]!='-')) flag = false;
  }

  cout << (flag?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
int main()
{
	string a,b,c;
	cin>>a>>b>>c;
	int n1=a.length();
	int n2=b.length();
	if((a[n1-1]==b[0]) && (b[n2-1]==c[0]))
		cout<<"YES";
	else
		cout<<"NO";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int x[10000][5], m[5], maxn, sum;
int n;
int a, b, c;
int main() {
	while (true) {
		sum = 0;
		maxn = 0;
		memset(x, 0, sizeof(x));
		memset(m, 0, sizeof(m));
		cin >> n;
		if (n == 0) { break; }
		for (int h = 0; h < n; h++) {
			cin >> a >> b >> c;
			c--;
			if (a == 1) {
				maxn = 0;
				for (int j = c; j < c + b; j++) {
					maxn = max(maxn, m[j]);
				}
				for (int j = c; j < c + b; j++) {
					x[maxn][j] = 1;
					m[j] = maxn + 1;
				}
			}
			else {
				for (int j = 0; j < b; j++) {
					x[m[c] + j][c] = 1;
				}
				m[c] += b;
			}
			for (int i = 0; i < 10000; i++) {
				if (x[i][0] + x[i][1] + x[i][2] + x[i][3] + x[i][4] == 5) {
					x[i][0] = 0; x[i][1] = 0; x[i][2] = 0; x[i][3] = 0; x[i][4] = 0;
					for (int j = i; j < 9999; j++) {
						for (int k = 0; k < 5; k++) {
							x[j][k] = x[j + 1][k];
						}
					}
					x[9999][0] = 0; x[9999][1] = 0; x[9999][2] = 0; x[9999][3] = 0; x[9999][4] = 0;
					i--;
					for (int j = 0; j < 5; j++) {
						for (int k = m[j]; k >= 0; k--) {
							if (x[k][j] == 1) {
								m[j] = k + 1; goto E;
							}
						}
						m[j] = 0;
					E:;
					}
				}
			}
		}
		for (int i = 0; i < 10000; i++) {
			for (int j = 0; j < 5; j++) {
				sum += x[i][j];
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1364
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e4 + 5;

int D;
string s;
int dp[N][111][2];

int solve(int pos, int rem, bool less) {
    if (pos == s.size()) {
        return rem == 0;
    }

    if (dp[pos][rem][less] != -1) {
        return dp[pos][rem][less];
    }

    int ans = 0;
    if (less) {
        for (int d = 0; d <= 9; d++) {
            int nrem = (rem + d) % D;
            ans = (ans + solve(pos + 1, nrem, less)) % MOD; 
        }
    } else {
        for (int d = 0; d <= s[pos] - '0'; d++) {
            if (d == s[pos] - '0') {
                int nrem = (rem + d) % D;
                ans = (ans + solve(pos + 1, nrem, 0)) % MOD;
            } else {
                int nrem = (rem + d) % D;
                ans = (ans + solve(pos + 1, nrem, 1)) % MOD;
            }
        }
    }

    return dp[pos][rem][less] = ans;
}

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

    cin >> s >> D;

    for (int i = 0; i <= s.size(); i++) {
        for (int j = 0; j < 111; j++) {
            dp[i][j][0] = dp[i][j][1] = -1;
        }
    }

    cout << (solve(0, 0, 0) - 1 + MOD) % MOD << "\n";   
}


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

int n, D[2], col[360005], fa[360005];
bool d[360005];
vector<pair<int, int>> ans[4];

int Sqrt(int x) {
	int y = sqrt(x);
	while (y * y <= x) ++y;
	while (y * y > x) --y;
	return y;
}

int find(int x) {
	if (fa[x] == x) return x;
	int ff = find(fa[x]);
	d[x] ^= d[fa[x]];
	return fa[x] = ff;
}
void merge(int x, int y) {
	int s = find(x), t = find(y);
	if (s == t) return;
	fa[s] = t, d[s] = d[x] ^ d[y] ^ 1;
}

int main() {
	scanf("%d", &n);
	for (int c = 0; c < 2; ++c) {
		scanf("%d", D + c);
		for (int i = 0; i < 4 * n * n; ++i) fa[i] = i, d[i] = 0;
		for (int i = 0; i * i <= D[c]; ++i) {
			int j = Sqrt(D[c] - i * i);
			if (i * i + j * j != D[c]) continue;
			for (int a = 0; a + i < 2 * n; ++a)
				for (int b = 0; b + j < 2 * n; ++b) {
					merge(a * 2 * n + b, (a + i) * 2 * n + b + j);
					merge((a + i) * 2 * n + b, a * 2 * n + b + j);
				}
		}
		for (int i = 0; i < 4 * n * n; ++i)
			find(i), col[i] |= d[i] << c;
	}
	for (int i = 0; i < 2 * n; ++i)
		for (int j = 0; j < 2 * n; ++j)
			ans[col[i * 2 * n + j]].emplace_back(i, j);
	for (int c = 0; c < 4; ++c)
		if (ans[c].size() >= n * n) {
			for (int i = 0; i < n * n; ++i)
				printf("%d %d\n", ans[c][i].first, ans[c][i].second);
			return 0;
		}
}


Measured memory_bytes: 7392
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

summ = 0
ans = 0
for i in range(1, n):
    summ += a[-i]
    ans += a[-(i + 1)] * summ
    ans %= MOD

print(ans % MOD)


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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		char[] line = sc.next().toCharArray();
		boolean ans = false;
		for(int i = 0; i < line.length; i++) {
			if(line[i] == '7') {
				ans = true;
				break;
			}
		}
		if(ans) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

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

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

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

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

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

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

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

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

Measured memory_bytes: 32752
n = int(input())
bl = list(map(int, input().split()))
al = [0] * n

al[0] = bl[0]
al[1] = bl[0]

for i in range(1, n-1):
    al[i] = min(bl[i-1], bl[i])
    al[i+1] = bl[i]

print(sum(al))


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

using static System.Console;

namespace Atcoder01_10 {
    class Class1 {
        static void Main() {
            int n = int.Parse(ReadLine());
            string str = ReadLine();
            int sum = 0;

            for(int i = 0; i < n - 2; i++) {
                if(str[i] == 'A' && str[i + 1] == 'B' && str[i + 2] == 'C') {
                    sum++;
                }
            }

            WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13140
N, K = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

pogi = []
nega = []
zero = 0

h = A.group_by {|a| a <=> 0} # 返り値はハッシュ
nega = h[-1] || [] # ハッシュから配列を取り出す
pogi = h[1] || []
zero = h[0] || []

pogi.sort!
nega.sort!.reverse!

n_size = nega.size
p_size = pogi.size
z_size = zero.size

pair_zero = z_size * (z_size - 1) / 2 + z_size * (p_size + n_size)
pair_nega = p_size * n_size

if pair_nega < K && K <= (pair_nega + pair_zero)
    puts 0 
    exit
end

    # 2分木探査の返り値 b を res に入れる

res = if K <= pair_nega
    (-10**20..0).bsearch do |b|
        sum = 0
        r = p_size - 1
        nega.each do |n|
            while r >= 0 && n * pogi[r] <= b
                r -= 1
            end
            sum += p_size - r - 1
        end
        sum >= K
    end
else
    (0..10**20).bsearch do |b|
        sum = 0
        [nega, pogi].each do |a| # 負の数同士、正の数同士考える
            l = 0
            r = (a.size) - 1
            while l < r
                while l < r && a[l] * a[r] > b # 最小の値　×　最大の値
                    r -= 1
                end
                sum += r - l
                l += 1
            end
        end
        sum >= K - pair_nega - pair_zero
    end
end

puts res

Measured memory_bytes: 23916
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    string t;cin>>t;
    rep(i,t.size())if(t[i]=='?')t[i]='D';
    cout<<t<<endl;
}

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

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

    int cnt = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'p') cnt++;
    }

    int ans = (int)s.size()/2 - cnt;
    cout<<ans<<endl; 
}

Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll n;
  cin >> n;
  ll arr[n];
  ll x=0;
  ll count2=0;
  for(ll i=0;i<n;i++)
  {
    cin >> arr[i];
    if(arr[i]%4==0)
      x++;
    if(arr[i]%2==0 && arr[i]%4!=0)
      count2++;
  }
  if(count2==0){
    ll k;
    k=n/2;
    if(x>=k)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  else{
    if(count2>=2)
      n-=count2;
    ll k;
    k=n/2;
    if(n%2==0){
      if(x>=k)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
    else{
      if(x>k && count2>=2)
        cout << "Yes" << endl;
      else if(x>=k && count2<=1)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
//const int mod = 1e9+9;
//===========================================================//
int n, k;
const int nx = 1e5+5;
ll ac[nx][2];
ll dp[105][nx];
ll go(ll i, ll w){
	if(w>k) return -oo;
	if(i == n) return 0;
	if(dp[i][w] != -1) return dp[i][w];
	ll& ans = dp[i][w];
	ans = max(ans, go(i+1,w));
	if(w+ac[i][0]<=k) ans = max(ans, go(i+1,w+ac[i][0])+ac[i][1]);
	return ans;
}
int main(){
	
	cin>>n>>k;
	memset(dp, -1, sizeof dp);
	for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1];
	cout<<go(0,0)<<"\n";
}

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

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

using namespace std;

int main(){
  int n;cin>>n;
  int result=n;
  rep(i,n-1){
    int t = 0;
    int a=i+1,b=n-i-1;
    int ta,tb;
    rep(i,6){
      ta = a%10;
      t+=ta;
      a/=10;
      tb = b%10;
      t+=tb;
      b/=10;
    }
//if(t<result)cout<<t<<endl;
    result = min(result, t);
  }

  cout<<result;
  return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;

bool judge(string s,int n){
    if(n%2){
        return false;
    }else{
        int cnt=0;
        rp(i,n/2){
            if(s.at(i)==s.at(n/2+i)){
                cnt++;
            }
        }
        return (cnt==n/2?true:false);
    }
}

int main(){
    string s;
    cin >> s;
    int ans=0;
    rp(i,s.size()){
        if(judge(s,i)){
            ans = (ans>i?ans:i);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)	((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
#define int long long
#define double long double       
  
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
    cout.setf(ios::fixed); cout.precision(9);    
    solve();               	
    return 0;
} 

const int MOD = 998244353, MAXN = 100 + 10, INF = 1e9 + 10;
 
void solve() {
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; ++i) {
        int num;
        cin >> num;
        s.insert(num);
    }    

    if ($(s) == n) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;   
    }
}


Measured memory_bytes: 9600