akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool next_state(vector<bool>& sw)
{
  for (int i = 1; i < (int)sw.size(); i++) {
    if (sw.at(i)) {
      sw.at(i) = false;
    } else {
      sw.at(i) = true;
      return true;
    }
  }
  return false;
}

bool all_bulb_on(const vector<bool>& sw, const vector<vector<int>>& bulb, const vector<int>& rest)
{
  for (int i = 0; i < (int)bulb.size(); i++) {
    int cnt = 0;
    for (int s : bulb.at(i)) {
      if (sw.at(s)) {
        cnt++;
      }
    }
    if (cnt % 2 != rest.at(i)) {
      return false;
    }
  }
  return true;
}

int main()
{
  int nswitches, nbulbs;
  cin >> nswitches >> nbulbs;
  vector<bool> sw(nswitches+1, false);
  vector<vector<int>> bulb(nbulbs);
  vector<int> rest(nbulbs);
  for (int i = 0; i < nbulbs; i++) {
    int k;
    cin >> k;
    for (int x = 0; x < k; x++) {
      int s;
      cin >> s;
      bulb.at(i).push_back(s);
    }
  }
  for (int i = 0; i < nbulbs; i++) {
    int p;
    cin >> p;
    rest.at(i) = p;
  }
  int cnt = 0;
  do {
    if (all_bulb_on(sw, bulb, rest)) {
      cnt++;
    }
  } while (next_state(sw));
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N, M = map(int, input().split())
    AB = [map(int, input().split()) for _ in range(M)]

    C = [[] for _ in range(N+1)]
    for a, b in AB:
        C[a].append(b)
        C[b].append(a)     

    #output
    #queue
    from collections import deque

    #iを出発して、ループが形成できるか確認。
    search_stack = deque([1])

    signpost = [-1] * (N+1)

    while search_stack:
        next_position = search_stack.popleft()
        for node in C[next_position]:
            if signpost[node] == -1:
                signpost[node] = next_position
                search_stack.append(node)

    print("Yes")
    for i in range(2, N+1):
        print(signpost[i])
    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()


Measured memory_bytes: 104484
H, W = map(int, input().split())

def judge(H, W):
    if H == 1 or W == 1:
        return 1
    elif (H * W) % 2 == 1:
        return int(H * W // 2) + 1
    else: 
        return int(H * W / 2)
    
print(judge(H, W))

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

int main(void){
    char str[4],c1,c2;
    int count1,count2;
    count1 = count2 = 0;
    cin >> str;
    sort(str,str+4);
    if(str[0] == str[1] && str[2] == str[3] && str[0] != str[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    string t;
    cin >> t;
    cout << "ABC" << t;    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;



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

  map<long long, int> n_frq_dict;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &n);
//    cout << "get " << n << endl;

    if(n_frq_dict.find(n) == n_frq_dict.end()){
      n_frq_dict[n] = 1;

    }else{
      n_frq_dict[n] += 1;

    }
  }

  int ans = 0;
  for(auto n_frq: n_frq_dict){
    if(n_frq.second % 2 == 1) {
//      cout << n_frq.first << " " << n_frq.second << endl;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 6528
h,w=map(int,input().split())
a=[[] for i in range(h)]
for i in range(h):
    a[i].append(input())
b=["#" for i in range(w+2)]
a.append(b)
a.insert(0,b)

for i in range(h):
    a[i+1].append("#")
    a[i+1].insert(0,"#")
    
for i in range(h+2):
    print("".join(a[i]))


Measured memory_bytes: 9144
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
	int N,M;
	for(;cin>>N>>M,N;){
		string file;
		set<string>files;
		set<string>directories;
		for(;N--;){
			cin>>file;
			files.insert(file);
			for(int i=file.size()-1;i>=0;i--){
				if(file[i]=='/'){
					file.resize(i);
					directories.insert(file);
				}
			}
		}
		for(;M--;){
			bool fail=false;
			vector<string>v(2);
			for(int _=0;_<2;_++){
				int prev=1;
				cin>>file;
				if(directories.find(file)!=directories.end())file+="/";
				for(int i=1;i<=file.size();i++){
					if(file[i]=='/'||!file[i])if(prev!=i){
						if(file.substr(prev,i-prev)=="."){
						}else if(file.substr(prev,i-prev)==".."){
							int j=v[_].size()-1;
							for(;j>=0;j--){
								if(v[_][j]=='/'){
									v[_].resize(j);
									break;
								}
							}
							if(j<0){
								fail=true;
								break;
							}
						}else{
							v[_]+="/";
							v[_]+=file.substr(prev,i-prev);
							if(file[i]){
								if(directories.find(v[_])==directories.end()){
									fail=true;
									break;
								}
							}
						}
						prev=i+1;
					}
				}
				if(directories.find(v[_])!=directories.end())v[_]+="/index.html";
				if(files.find(v[_])==files.end())fail=true;
			}
			if(fail)cout<<"not found"<<endl;
			else if(v[0]==v[1])cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
	}
}

Measured memory_bytes: 1228
f=lambda:map(int,input().split())
n,m,q=f()
lq=[tuple(f()) for _ in range(q)]
ans=0
from itertools import *
for t in combinations_with_replacement(range(m),n):
  s=0
  for a,b,c,d in lq:
    if t[b-1]-t[a-1]==c: s+=d
  ans=max(ans,s)
print(ans)

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main() {
	
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n), t(n);
	rep(i, n){
		ll tmp;
		cin >> tmp;
		a[i] = tmp / 2;
	}
	
	t = a;
	int precnt;
	rep(i, n){
		int cnt = 0;
		while(t[i]%2 == 0){
			t[i] /= 2;
			cnt++;
		}
		if(i>0){
			if(precnt != cnt){
				cout << "0" << endl;
				return 0;
			}
		}
		precnt = cnt;
	}
	
	ll lcm = a[0];
	for(int i = 1; i < n; i++){
		lcm = lcm / gcd(a[i], lcm) * a[i];
	}
	// cout << lcm << endl;
	cout << (m / lcm + 1LL) / 2 << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
  int N, i, l[1005], r[1005], S;
  scanf("%d", &N);
  S=0;
  for (i=1; i<=N; i++) {
    scanf("%d %d", &l[i], &r[i]);
    S+=r[i]-l[i]+1;
  }
  printf("%d", S);
  return 0;
}

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

int main(){
    int b, r, g, c, s, t;
    while(1){
        cin >> b >> r >> g >> c >> s >> t;
        if(b+r+g+c+s+t == 0)    break;
    
        int medal = 100;
        medal += 80*b;
        medal += 54*r;
        medal += 7*g;
        medal += 2*c;
        medal -= (t-s-5*b-3*r)*3;
        cout << medal << endl;
    }
    return 0;
}



Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
int n;
int mod(int a, int b)
{
    if(a < 0 && a%b != 0)
    {
        n = a / b + 1;
        return a - (a / b + 1) * b;
    }
    n = a / b;
    return a % b;
}
int main()
{
    int n2;
    char a[10] = {'0','1','2','3','4','5','6','7','8','9'};
    vector<int> array;
    cin >> n;
    if(n==0)
    {
        printf("0\n");
        return 0;
    }
    n2 = n;
    while(n != 0)
        array.push_back(mod(n,-2));
    for(int i=array.size()-1; i>=0; i--)
        cout << a[array[i]];
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int n = a + b + c;
    vector <ll> x(n), y(n), z(n);
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%lld%lld%lld", &x[i], &y[i], &z[i]);
        ans += z[i];
        x[i] -= z[i];
        y[i] -= z[i];
    }
    priority_queue <ll> q;
    vector <pair <ll, ll> > s_a, s_b;
    for (int i = 0; i < n; i++)
    {
        s_a.push_back({x[i], i});
        s_b.push_back({y[i], i});
    }
    sort(s_a.rbegin(), s_a.rend());
    sort(s_b.rbegin(), s_b.rend());
    int j = -1;
    int cnt = 0;
    multiset <ll> grab;
    multiset <ll> not_grab;
    ll sum_b = 0;
    ll sum_grab = 0;
    ll res = -1e18;
    multiset <pair <ll, int> > can_grab;
    for (int i = 0; i < a + b; i++)
    {
        int ind = s_a[i].second;
        not_grab.insert(x[ind] - y[ind]);
        sum_b += y[ind];
    }
    for (int ind = a + b; ind < n; ind++)
    {
        int i = s_a[ind].second;
        can_grab.insert({y[i], i});
    }
    ll sum = 0;
    for (int i = n - 1; i >= -1; i--)
    {
        if (i >= a + b)
        {
            continue;
        }
        while (i + 1 + cnt + 1 <= a + b)
        {
            auto get = *can_grab.rbegin();
            can_grab.erase(get);
            int ind = get.second;
            sum_b += y[ind];
            not_grab.insert(x[ind] - y[ind]);
            cnt++;
        }
        while (grab.size() < a)
        {
            sum += *not_grab.rbegin();
            grab.insert(*not_grab.rbegin());
            not_grab.erase(--not_grab.end());
        }
        while (grab.size() > 0 && not_grab.size() > 0 && *grab.begin() < *not_grab.rbegin())
        {
            sum += *not_grab.rbegin();
            grab.insert(*not_grab.rbegin());
            not_grab.erase(--not_grab.end());
            sum -= *grab.begin();
            not_grab.insert(*grab.begin());
            grab.erase(grab.begin());
        }
        res = max(res, ans + sum + sum_b);
        if (i != -1)
        {
            int ind = s_a[i].second;
            ll val = x[ind] - y[ind];
            sum_b -= y[ind];
            if (grab.find(val) != grab.end())
            {
                sum -= val;
                grab.erase(grab.find(val));
            }
            else
            {
                not_grab.erase(not_grab.find(val));
            }
            can_grab.insert({y[ind], ind});
        }
    }
    printf("%lld\n", res);
}


Measured memory_bytes: 11364
#include<cstdio>
using ll = long long;
using ull = unsigned long long;
const static ull MOD = 1000000007;

ll RepeatSquaring(ll N, ull P){
	if(P == 0 || N == 1) return 1;
	if(!(P & 1)){
		ll t = RepeatSquaring(N, P >> 1);
		return t*t % MOD;
	}
	//Pが偶数のときN^(P/2)を求めてからそれの2乗を返す

	return N*RepeatSquaring(N, P - 1) % MOD;
	//Pが奇数のときN^((P - 1)/2)を求めてからそれの2乗を返す
}
int main(){
	ll n, k;
	scanf("%lld %lld", &n, &k);
	ll answer = 1, c_1 = 1, c_2 = 1;
	for (ll i = 1; i < n && i <= k; ++i){
		c_1 = c_1*(n - i) % MOD;
		c_1 = c_1*RepeatSquaring(i, MOD - 2) % MOD;
		c_2 = c_2*(n - i + 1) % MOD;
		c_2 = c_2*RepeatSquaring(i, MOD - 2) % MOD;
		answer = (answer + c_1*c_2) % MOD;
	}
	printf("%lld\n", answer);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0,num=1;
    while(n>=num){
        num *= k;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int a = Integer.parseInt(in.readLine());
    String s = in.readLine();
    System.out.println(a>=3200?s:"red");
  }
}

Measured memory_bytes: 21460
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

int dayNum[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string day[7] = { "Monday",
				  "Tuesday",
				  "Wednesday",
				  "Thursday",	// <- 2004/1/1
				  "Friday",
				  "Saturday",
				  "Sunday" };

int main() {
	int m, d;
	
	cin >> m >> d;
	
	while (m != 0 && d != 0) {
		int daySum = 0;
		
		for (int i = 0; i < m - 1; i++) {
			daySum += dayNum[i];
		}
		
		daySum += d;
		
		cout << day[ (daySum + 2) % 7 ] << endl;
		
		cin >> m >> d;
	}
	
	return 0;
}

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

typedef long long int lli;

using namespace std;

int main()
{
    lli n, a, b;
    cin >> n >> a >> b;
    lli t = n/(a+b);
    lli s = n - t*(a+b);
    lli u = min(s, a);
    cout << t*a + u << endl;
    return 0;
}

Measured memory_bytes: 256
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n-1):
	for j in range(i+1,n):
		t=0
		for l in range(d):
			t+=(x[i][l]-x[j][l])**2
		if t**(1/2)%1==0:
			ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e3+10, mod=1e9+7;
vector<int> G[N];
ll cnt[N];
bool vis[N];

void BFS(int s){
    memset(vis,0,sizeof vis);
    queue<pair<int,int> > q;
    q.push({s,0});
    vis[s]=1;
    while(!q.empty()){
        auto p=q.front();
        q.pop();
        int u=p.F;
        int l=p.S;
        cnt[l]++;
        for(auto v:G[u]){
            if(!vis[v]){
                q.push({v,l+1});
                vis[v]=1;
            }
        }
    }
}
int main ()
{
    FASTIO
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    multiset<int> st;
    for(int i=0;i<a;i++){
        int t;
        cin >> t;
        if(x){
            st.insert(t);
            x--;
        }
        else{
            st.insert(t);
            st.erase(st.begin());
        }
    }
    multiset<int> st2;
    for(int i=0;i<b;i++){
        int t;
        cin >> t;
        if(y){
            st2.insert(t);
            y--;
        }
        else{
            st2.insert(t);
            st2.erase(st2.begin());
        }
    }
    for(auto x:st2)st.insert(x);
    int sum=x+y;
    for(int i=0;i<c;i++){
        int t;
        cin >> t;
        if(sum){
            st.insert(t);
            sum--;
        }
        else{
            st.insert(t);
            st.erase(st.begin());
        }
    }
    ll ans=0;
    for(auto x:st)ans += x;
    cout << ans << endl;
    return 0;
}
/**

*/


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MIN(a,b) ((a) < (b) ? (a) : (b))

//整数と、リストの次要素を指すポインタをまとめた構造体slobjを定義
typedef struct slobj_{
    char direction; //そのブロックの人が左向きLか右向きRか
    int sum; //ブロックの中に何個文字があるか
    struct slobj_ *next;
    struct slobj_ *prev;
}*slobj;

//slobj型の変数のポインタをslist型と定義→いずれリストの先頭要素を指す
typedef struct{
    slobj head;
    slobj tail;
}*slist;

//cirectionにc, sumにnを持つリスト要素を作る関数
slobj slobj_new(char c, int n){
    slobj p;
    NEW(p,1);
    p->direction=c;
    p->sum=n;
    p->next=NULL;
    p->prev=NULL;
    return p;
}

//slist型の空リスト1つを作る関数
slist slist_new(void){
    slist L;
    NEW(L,1);
    L->head=NULL;
    L->tail=NULL;
    return L;
}

//slobj要素のメモリを解放する
void free_slobj(slobj p){
    free(p);
    return;
}

//slobj型の要素pをリストLの最後に挿入する関数
void slist_insert_tail(slist L,slobj p){
    if(L->head==NULL){ //もし最初に挿入するなら
        //p->prev=NULL;
        //p->next=NULL;
        L->head=p;
        L->tail=p;
    }
    else{ //それ以外なら
        p->prev=L->tail;
        //p->next=NULL;
        L->tail->next=p;
        L->tail=p;
    }
    
    return;
}




int main(void){
    int N;
    scanf("%d",&N);

    int K;
    scanf("%d",&K);

    char S[N+1];
    scanf("%s",S); //S[0]~S[N-1]まで文字列、S[N]は0

    //ここから文字列ブロック化、関数にしても良い

    //文字列をブロックリストLに格納
    slist L=slist_new();
    int block_sum=0; //ブロック総数

    char c=S[0]; //ブロックの文字
    int charn=0; //ブロックの中にある文字の数

    for(int i=0;i<N;i++){
        if(S[i]==c){
            charn+=1;
        }
        else{
            block_sum+=1;
            slobj p=slobj_new(c, charn);
            slist_insert_tail(L,p);
            c=S[i];
            charn=1;
        }

        if(i==N-1){ //もし最後だったら、それをリストに足す
            block_sum+=1;
            slobj p=slobj_new(c, charn);
            slist_insert_tail(L,p);
        }
    }

    /* このprintを使えば、ブロックリストに何が入っているのか、ブロックが総数いくつあるのか確認可能
    slobj q=L->head;
    while(q!=NULL){
        printf("%c %d\n",q->direction, q->sum);
        q=q->next;
    }
    printf("%d\n",block_sum);
    */

    int unhappy;
    if((block_sum/2)>K){
        unhappy=block_sum-K*2;
    }
    else{
        unhappy=1;
    }

    int ans=N-unhappy;
    printf("%d\n",ans);

    return 0;
}

//400
//ブロックで考えること
//何も問題文に律儀に回転させる必要はない！！！LとRの変換だけでいい！！！
//文字列をブロック化することが一番大事！！！！
//手こずったねえ・・・

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

int main(void)
{
    char a[3];
  char b[3] = {"RRR"};
    int n = 0;

    scanf("%s",a);
    n = strspn(a,b);
  if(a[0]=='S'&&a[1]=='R'&&a[2]=='R')
  {
    n = 2;
  }
 else if(a[0]=='S'&&a[1]=='S'&&a[2]=='R')
 {
   n=1;
 }
 else if(a[0]=='S'&&a[1]=='R'&&a[2]=='S')
 {
   n = 1;
 }
    printf("%d",n);
    return 0;
    



}

Measured memory_bytes: 2080
package main

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

var scanner = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 0x100000)
var wtr = bufio.NewWriter(os.Stdout)

// SplitSpace 空白で分割設定
func SplitSpace() {
	scanner.Split(bufio.ScanWords)
}

// NextLine 標準入力から１行読み込む
func NextLine() string {
	scanner.Scan()
	return scanner.Text()
}

// NextInt 標準入力から数値を一つ読み込む
func NextInt() int {
	n, _ := strconv.Atoi(NextLine())
	return n
}

// ReadLine 標準入力から長めの1行を読み込む
func ReadLine() string {
	buf := make([]byte, 0, 0x100000)
	for {
		line, isPrefix, err := rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

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

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

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

func	ChMin( a *int, b int ) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func	ChMax( a *int, b int ) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}

//================

func main() {
	SplitSpace()
	n := NextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = NextInt()
	}
	dp := make( []int, n+1 )
	for i:=2; i < n; i++ {
		dp[i] = 1 << 29
	}
	dp[1] = Abs(h[1]-h[0])
	for i:=2; i < n; i++ {
		ChMin( &dp[i], Min(Abs(h[i]-h[i-1])+dp[i-1],Abs(h[i]-h[i-2])+dp[i-2]) )
	}
	fmt.Println(dp[n-1])
}


Measured memory_bytes: 2688
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()


def nck(n, k, mod):
    """
     O(n)でnCkを返す関数。
    """

    def continuous_inv(n, mod):
        """
        O(n)で1からnまでの範囲の逆元のリストを返す。
        """
        inv_list = [1]  # 0で割るというのは定義されないので無視。
        for i in range(n):
            inv_list.append(int(mod - inv_list[(mod % (i + 2)) - 1] * (mod // (i + 2)) % mod))
        return inv_list

    inv_list = continuous_inv(max(k, n - k), mod)
    return_value = 1
    for i in range(2, n + 1):
        return_value *= i
        return_value %= mod
    for i in range(k):
        return_value *= inv_list[i]
        return_value %= mod
    for i in range(n - k):
        return_value *= inv_list[i]
        return_value %= mod
    return return_value


X, Y = map(int, input().split())
if (X + Y) % 3 == 0 and Y - (X + Y) / 3 <= X <= Y + (X + Y) / 3:
    print(nck((X + Y) // 3, abs((X - Y + (X + Y) // 3) // 2), MOD))
else:
    print(0)


Measured memory_bytes: 21884
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()), ((v).end())
#define INF 1e9
#define EPS 1e-9
#define bitcount __builtin_popcount
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define LSOne(S) (S & (-S))
#define PI acos(-1.0)
#define P(x) cout << #x << " = { " << x << " }\n"
#define tests()  \
    int tttt;    \
    cin >> tttt; \
    while (tttt--)
#define fast_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define file_IO                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)
typedef long long ll;
int dcmp(long double x, long double y)
{
    return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}
const int MAX = 1e3 + 10;
const int MOD = 1e9 + 7;
int n, m;
int memo[MAX][MAX];
bool vis[MAX];
string grid[MAX];
void read();
void solve();
void clear();
int dp(int i, int j);
int main()
{
#ifndef ONLINE_JUDGE
    file_IO;
#else
    fast_IO;
#endif

    solve();
}
void read()
{
    cin >> n >> m;
    lp(i, n) { cin >> grid[i]; }
}
void clear()
{
    clr(memo, -1);
}
void solve()
{
    read();
    clear();
    cout << dp(0, 0) << '\n';
}
int dp(int i, int j)
{
    if (i == n - 1 && j == m - 1)
        return 1;
    int &ret = memo[i][j];
    if (ret != -1)
        return ret;
    int path = 0;
    int path2 = 0;
    if (i + 1 < n && grid[i + 1][j] != '#')
        path = dp(i + 1, j);
    if (j + 1 < m && grid[i][j + 1] != '#')
        path2 = dp(i, j + 1);

    return ret = (path2 % MOD + path % MOD) % MOD;
}

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

int main(){
	int num;cin>>num;
	int N=num;
	int sum=0;
	int dig;
	while(num){
    	dig = num % 10;
    	sum = sum + dig;
    	num = num / 10;
  }
  if(N%sum==0){
  	cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
}



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

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

const int INF = 1e9;
const int mod = 1e9+7;

vector<ll> z;

void zzz(int i,ll j)
{
    z.push_back(j);
    if(i < 10){
        zzz(i+1,j*10+3);
        zzz(i+1,j*10+5);
        zzz(i+1,j*10+7);    
    }
}

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

    zzz(0,0);
    sort(z.begin(),z.end());

    int ans = 0;
    for(int i = 0; z[i] <= s; i++){
        int flag[10] = {};
        while(z[i]){
            flag[z[i]%10]++;
            z[i] /= 10;
            if(flag[3] && flag[5] && flag[7]){
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = 1e9;

int dp[100010][3]; // 0 : A, 1 : B, 2 : C

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N),B(N),C(N);
    for(int i = 0; i < N; ++i) cin >> A[i] >> B[i] >> C[i];
    
    for(int i = 0; i < N; ++i){
        dp[i+1][0] = max(dp[i+1][0],max(dp[i][1] + A[i],dp[i][2] + A[i]));
        dp[i+1][1] = max(dp[i+1][1],max(dp[i][0] + B[i],dp[i][2] + B[i]));
        dp[i+1][2] = max(dp[i+1][2],max(dp[i][0] + C[i],dp[i][1] + C[i]));
    }
    cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
    return 0;
}

Measured memory_bytes: 2560
def main():

    N, K = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[0]*(K+1) for i in range(N+1)]
    import collections
    dp[0][K] = 1
    mod = 10**9 + 7
    # dp[i][j] i人目まで配って、残りがj個の方法の数
    s = [0]*(K+2)
    for i in range(1, N+1):
        tmp = 0
        for j in range(K, -1, -1):
            s[j] = (s[j+1] + dp[i-1][j]) % mod
        for j in range(K, -1, -1):
            tmp = s[j] - s[min(K, j+a[i-1]) + 1]
            tmp %= mod
            dp[i][j] = tmp

    print(dp[-1][0])


main()


Measured memory_bytes: 120176
#include <iostream>
#include <algorithm>
#include <numeric>
//#include <cmath>
#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    vector<int> a;
    int tmp;

    cin >> n;
    vector<size_t> indices(n);
    for(int i=0; i<n; i++){
        cin >> tmp;
        a.push_back(tmp);
    }

    iota(indices.begin(), indices.end(), 0);

    sort(indices.begin(), indices.end(), [&a](size_t i1, size_t i2) {
        return a[i1] < a[i2];
    });

    for(int i=0; i<n; i++){
        cout << indices[i]+1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2168
n,y = map(int, input().split())

exist = False

for i in reversed(range(y//10000+1)):
    for j in reversed(range(n-i+1)):
        k = n - i - j
        res = y - 10000*i - 5000*j
        if res == 1000*k:
            print("{} {} {}".format(i,j,n-i-j))
            print("\n")
            exist = True
        if exist:
            break
    if exist:
        break

if not exist:
    print("-1 -1 -1")
    print("\n")


Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;

struct dice{
  int num[6]={3,4,1,6,5,2};
  //int front=3,back=4,up=1,doun=6,right=5,left=2;
  int six=3,five=4,four=1;
};

dice d;

void roll1(int u){
    int n=d.num[2];
    d.num[2]=d.num[0];
    d.num[0]=d.num[3];
    d.num[3]=d.num[1];
    d.num[1]=n;
}

void roll2(int f){
    int n=d.num[0];
    d.num[0]=d.num[4];
    d.num[4]=d.num[1];
    d.num[1]=d.num[5];
    d.num[5]=n;
}

void roll3(int u){
    int n=d.num[2];
    d.num[2]=d.num[4];
    d.num[4]=d.num[3];
    d.num[3]=d.num[5];
    d.num[5]=n;
}

void search(){
  rep(i,6){
    if(d.num[i]==6) d.six=i;
    if(d.num[i]==5) d.five=i;
    if(d.num[i]==4) d.four=i;
  }
}

int main(){
  int n;
  int x[6]={1,-1,0,0,0,0};
  int y[6]={0,0,0,0,1,-1};
  int f,u;
  
  while(1){
    cin>>n;
    if(n==0) break;
    int mpn[101][101]={0};
    int mph[101][101]={0};
    int cnt[6]={0};
    rep(i,n){
      cin>>u>>f;
      rep(j,4){
	if(d.num[2]!=u){
	  roll1(u);
	}
	else break;
      }
      rep(j,4){
	if(d.num[2]!=u){
	  roll3(u);
	}
	else break;
      }
      rep(j,4){
	if(d.num[0]!=f){
	  roll2(f);
	}
	else break;
      }
      int a,b;
      a=b=50;
      while(1){
	search();
	/*	 rep(i,6){
	cout<<d.num[i]<<" ";
	}*/
	if(mph[a][b]==0){
	  mph[a][b]++;
	  cnt[mpn[a][b]-1]--;
	  mpn[a][b]=d.num[2];
	  cnt[mpn[a][b]-1]++;
	  break;
	}
	else{
	  if(mph[a+x[d.six]][b+y[d.six]]<mph[a][b]){
	    if(d.six==1) roll1(d.num[2]);
	    else if(d.six==0) rep(i,3) roll1(d.num[2]);
	    else if(d.six==5) roll3(d.num[2]);
	    else if(d.six==4) rep(i,3) roll3(d.num[2]);
	    a+=x[d.six];
	    b+=y[d.six];
	  }else if(mph[a+x[d.five]][b+y[d.five]]<mph[a][b]){
	    if(d.five==1) roll1(d.num[2]);
	    else if(d.five==0) rep(i,3) roll1(d.num[2]);
	    else if(d.five==5) roll3(d.num[2]);
	    else if(d.five==4) rep(i,3) roll3(d.num[2]);
	    a+=x[d.five];
	    b+=y[d.five];
	  }else if(mph[a+x[d.four]][b+y[d.four]]<mph[a][b]){
	  if(d.four==1) roll1(d.num[2]);
	  else if(d.four==0) rep(i,3) roll1(d.num[2]);
	  else if(d.four==5) roll3(d.num[2]);
	  else if(d.four==4) rep(i,3) roll3(d.num[2]);
	  a+=x[d.four];
	  b+=y[d.four]; 
	  }else{
	    mph[a][b]++;
	    cnt[mpn[a][b]-1]--;
	    mpn[a][b]=d.num[2];
	    cnt[mpn[a][b]-1]++;
	    break;
	  }
	}
	//	cout<<a<<" "<<b<<endl;
      }
      /*  repi(i,48,52){
      repi(j,48,52){
	cout<<mph[i][j]<<" ";
      }
      cout<<endl;
    }
        rep(i,6){
      cout<<cnt[i];
      if(i!=5) cout<<" ";
      }*/
    }
    /*repi(i,48,52){
      repi(j,48,52){
	cout<<mph[i][j]<<" ";
      }
      cout<<endl;
      }*/
    rep(i,6){
      cout<<cnt[i];
      if(i!=5) cout<<" ";
    }
    cout<<endl;
    
  }
      
	  
	  
	  
      
      
  return 0;
}















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


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

  set<int> hon = {2, 4, 5, 7, 9};
  set<int> pon = {0, 1, 6, 8};
  set<int> bon = {3};

  int d = N % 10;

  if (hon.find(d) != hon.end()) {
    cout << "hon" << endl;
  } else if (pon.find(d) != pon.end()) {
    cout << "pon" << endl;
  } else if (bon.find(d) != bon.end()) {
    cout << "bon" << endl;
  } else {
    cout << "I am stupid!" << endl;
  }

  return 0;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n,k;

    cin>>n>>k;

    li a[n];

    f(i,0,n-1)
    {
        cin>>a[i];
    }

    vector<bool> dp(k+1);

    f(stones,0,k)
    {
        for(li x:a)
        {
            if(stones>=x && !dp[stones-x])
            {
                dp[stones]=true;
            }
        }
    }

    cout<<(dp[k]?"First":"Second");
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
} 

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

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

  int N; cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;
const ll N=1e5 + 5;
ll cnt[N]={0};
ll dp[N]={0};

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

    if(n==3||n==5||n==7)
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 256
def solve():
  S = input()
  K = int(input())
  lis = set()
  for i in range(len(S)):
    for p in range(1,K+1):
      j = i+p
      if j>len(S):
        continue
      lis.add(S[i:j])
  ans = sorted(list(lis))[K-1]
  return ans
print(solve())

Measured memory_bytes: 69440
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


int main(){
  int N, Q;
  scanf("%d", &N);
  std::string s;
  std::cin >> s;
  scanf("%d", &Q);
  std::vector<int > type(Q), l(Q), r(Q), I(Q);
  std::vector<char > c(Q);
  for (int i=0; i<Q; i++){
    //printf("i=%d\n", i);
    std::cin >> type[i];
    if (type[i]==1){
      std::cin >>  I[i] >> c[i];
      I[i]--;
    } else {
      std::cin >> l[i] >> r[i];
      l[i]--;
      r[i]--;
    }
  }

  std::set<int > pos[28];
  for (int i=0; i<N; i++){
    int val = int(s[i])-int('a');
    pos[val].insert(i);
  }
  
  for (int i=0; i<Q; i++){
    if (type[i]==1){
      int val = int(s[I[i]])-int('a');
      //printf("i=%d, s[i]=%c\n", I[i], s[I[i]]);
      auto itr = pos[val].find(I[i]);
      if (itr==pos[val].end()){
	printf("Error\n");
      }
      pos[val].erase(itr);
      val = int(c[i])-int('a');
      //printf("val=%d\n", val);
      pos[val].insert(I[i]);
      s[I[i]]=c[i];
      //printf("end2\n");
      
    } else {
      //if (type[i]==2){
      int ans = 0;
      for (int j=0; j<26; j++){
	//auto itr = std::lower_bound(pos[j].begin(), pos[j].end(), l[i]);
	auto itr = pos[j].lower_bound(l[i]);
	//	printf("start1\n");
	if (itr!=pos[j].end() && *itr<=r[i]){
	  ans++;
	  //printf("%c find!\n", 'a'+j);
	}
	//printf("end1\n");
      }
      std::cout << ans << std::endl;
    }
  }
  return 0;
}

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

int main() {
  long long a=0,b=0,c=0,d=0,m=0,n=0,p=0,q=0;
  
  cin >> a;
  while(a>9)
  {
	  a -=10;
  }
  if(a==2||a==4||a==5||a==7||a==9)
  {
	  cout << "hon";
  }
  if(a==0||a==1||a==6||a==8)
  {
	  cout << "pon";
  }
  if(a==3)
  {
	  cout << "bon";
  }
}



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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;



const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
 
     

const LL MOD = 1000000007LL;
LL factorial[1000111];



int main() {
    //ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';
    cout.precision(16);
    
factorial[0] = 1LL;
iii (1, 1000111)
    factorial[i] = (factorial[i-1] * LL(i)) % MOD;

    int n, k;
    cin >> n >> k;
    vector<int> aa(n);
    ii (n)
        cin >> aa[i];

    vector<vector<LL> > mask_blen(257, vector<LL>(105, 0));
    mask_blen[0][0] = 1;
    ii (n) {
        vector<vector<LL> > next = mask_blen;
        xx (256) {
            int to = (x ^ aa[i]);
            yy (100) {
                next[to][y+1] += mask_blen[x][y];
                next[to][y+1] %= MOD;
            }
        }

        swap(mask_blen, next);
    }

    LL rr = 0;
    ii (101) {
        LL nseq = mask_blen[k][i];
        rr = (rr + nseq * factorial[i]) % MOD;
    }

    cout << rr << '\n';
    
    

    return 0;
}



Measured memory_bytes: 8668
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	string ans;
	ans += s[0];
	rep(i, 1, n-1){
		if(s[i] != s[i-1])
			ans += s[i];
	}
	cout << sz(ans);
}

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

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3732
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var power = 1UL;
            var mod = (UInt64)Pow(10, 9) + 7;
            for(int i = 1; i <= n; i++)
            {
                power = power * (UInt64)i;
                if(power > mod)
                {
                    power %= mod;
                }
            }
            WriteLine(power);
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
	int ans1=0,ans2=0,ans3=0;
	string s;
	cin>>s;
	for(int i=0; i<3; i++){
		if(s[i]=='a'){
			ans1=ans1+1;
		}
		if(s[i]=='b'){
			ans2=ans2+1;
		}
		if(s[i]=='c'){
			ans3=ans3+1;
		}
	}
	if(ans1==ans2 && ans2==ans3){
		cout<<"Yes"<<endl;
		return 0;
	}
	else{
		cout<<"No"<<endl;
		return 0;
	}
}


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

int main(){
	int loop;
	int N;
	int max;
	int sum;
	cin >> N;
	for (loop = 0;; loop++){
		sum += loop;
		if (sum >= N){
			max = loop;
			break;
		}
	}
	for (loop = 1; loop < sum - N; loop++)cout << loop << "\n";
	for (loop = sum - N + 1; loop <= max; loop++)cout << loop << "\n";

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    token = lines[0].split()
    s = token[0]

    return (s,)


def solve(s):

    result = "Good"
    for i in range(3):
        if s[i] == s[i+1]:
            result = "Bad"
        
    return result




def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
#include<iostream>
#include<string>

using namespace std;
int main(int argc, char *argv[])
{
	int n,k,i;
	string s;
	cin>>n>>k;
	cin>>s;
	s[k-1]=towlower(s[k-1]);
	cout<<s<<endl;
	
	

	return 0;
}

Measured memory_bytes: 3064
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,L=get_i
ans=0
min=10**9
L.upto(N+L-1) do|i|
  ans+=i
  min=i if min.abs>i.abs 
end
puts ans-min

Measured memory_bytes: 1916
#from matplotlib import pyplot as plt
def binary_search(mn,mx,a,x,y):
    #リストlからaの値のインデックスをサーチする。
    #二分探索を可能にするためにはリストlはソートされていなければならない。
    z = (mx+1)//2
    low = mn
    high = mx+1
    while low <= high:
        temp = rule2(x,y,z)
        if temp == a:
            if z <= 0:
                return None
            return z
        elif temp < a:
            low = z + 1
        elif temp > a:
            high = z - 1

        z = (low + high) // 2
    return None

def rule2(x,y,z):
    return x ** 2 + y ** 2 + z**2 + x * y + y * z + z*x
def main():
    n = int(input())
    x = []
    y = []
    for i in range(1,n+1):
        #x.append(i)
        #y.append(f(i))
        print(f(i))
    #plt.scatter(x,y)
    #plt.show()


def f(n):
    counter = 0
    for x in range(1,n):
        if x ** 2 > n:
            break
        for y in range(x,n-x**2):
            if y < x:
                continue
            if x ** 2 + y ** 2 > n:
                break
            z = binary_search(y,n-x**2-y**2-x*y,n,x,y)
            if z == None:
                continue
            else:
                if rule2(x,y,z) == n:
                    if x == y and y == z and z == x:
                        counter += 1
                    elif x != y and y != z and z != x:
                        counter += 6
                    else:
                        counter += 3

    return counter


if __name__ == '__main__':
    main()

#6 24 54 96
#1  4  9 16
#18

Measured memory_bytes: 73292
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
# N = gets_i

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
# N, M = gets_i_list
# list = gets_i_list

N, C, K = gets_i_list
t_list = []
N.times do
  t_list.push(gets_i)
end
t_list.sort!

t_end = t_list[0] + K
p_count = 0
count = 1
t_list.each do |t|
  if t <= t_end && p_count < C
    # 乗れた
    p_count += 1
  else
    # 乗れない
    t_end   = t + K
    count  += 1
    p_count = 1
  end
end

puts count

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  int ans = 0;
  for(int i = 1; i <= N; ++i){
    int n = i;
    int sum = 0;
    while(n!=0) {
      sum += n % 10;
      n /= 10;
    }
    if (A <= sum && sum <= B) ans += i;
  }
      
  cout << ans << endl;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<pair<int, int>> A(N);
    rep(i, N) cin >> A[i].first, A[i].second = i;

    vec<pair<int, int>> B(N);
    rep(i, N) cin >> B[i].first, B[i].second = i;

    sort(all(A));
    sort(all(B));

    rep(i, N) if (A[i].first > B[i].first) {
        cout << "No" << endl;
        return 0;
    }

    vec<int> c(N);
    rep(i,N){
        int a = A[i].second;
        c[a] = B[i].second;
    }

    vec<int> cycle;
    int now = 0;
    while (true) {
        cycle.push_back(now);
        now = c[now];
        if (now == 0) break;
    }
    if (cycle.size() != N) {
        cout << "Yes" << endl;
        return 0;
    }
    rep(i, N - 1) {
        if (A[i + 1].first <= B[i].first) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 5788
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

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

    int len = s.size();
    int count = 0;
    int ind = 0;
    while (count < K) {
        if (ind == len - 1) {
            int n = (K - count) % 26;
            s[ind] = (s[ind] - 'a' + n) % 26 + 'a';
            count = 1000000001;
        } else if (s[ind] == 'a') {
            ++ind;
        } else if (K - count >= 26 - (s[ind] - 'a')) {
            count += 26 - (s[ind] - 'a');
            s[ind] = 'a';
        } else {
            ++ind;
        }
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n[3], s;
	rep(i,3){
		cin >> s; 
		n[i] = s;
		}
	cout << n[2] << " " << n[0] << " " << n[1] << endl;
	return 0;

}

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

int main()
{
	int a, b , c;
	cin >> a;
	cin >> b;
	cin >> c;
	if (a < b && b < c){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define pb push_back
#define ff first
#define ss second
#define SIZE 100010
#define INF 2e9 + 9
#define acmpIN "input.txt"
#define acmpOUT "output.txt"

//#pragma GCC optimize("Ofast")

int n, m;
string s;

bool check(int l, int r)
{
    string nw;
    for(int i = l; i <= r; ++i)
        nw += s[i];
    m = nw.size();
    for(int i = 0; i < (m + 1)/ 2; i++)
    {
        if(nw[i] != nw[m - i - 1])
            return false;
    }
    return true;
}




void solve()
{
    cin >> s;
    n = s.size();
    bool ok = check(0, n - 1);
    int r = (n - 1) / 2;
    ok &=check(0, r - 1);
    int l = (n + 3) / 2;
    ok &=check(l - 1, n - 1);
    if(ok)
        cout << "Yes\n";
    else cout << "No\n";
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen(acmpIN, "r", stdin);
//    freopen(acmpOUT, "w", stdout);

    solve();

    return 0;
}


Measured memory_bytes: 256