akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll a,b,c,d;cin>>a>>b>>c>>d;
  while(1){
    c-=b;
    if(c<=0){
      cout<<"Yes"<<ENDL;
      return 0;
    }
    a-=d;
    if(a<=0){
      cout<<"No"<<ENDL;
      return 0;
    }
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
// #include"prettyprint.hpp"
typedef long long ll;
typedef double db;

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, MOD = 1e9 + 7, N = 1e5 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

void test() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    // debug(arr(a, n));
    sort(a, a + n);
    ll c = a[n - 1];
    // debug(arr(a, n));
    // debug(c);
    int k = n - 2, div = k / 2, i = n - 2;
    // debug(div);
    for (i; div > 0; --div, --i) {
        c += 2 * a[i];
        // debug(c);
    }
    if (k % 2) c += a[i];
    cout << c << "\n";
}

int main() {
      fast_io();
      #ifdef HOME
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif
      cout << fixed << setprecision(15);
      int t = 1;
      // cin >> t;
      for (int i = 1; i <= t; ++i) {
          test();
      }
      #ifdef HOME
          cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
      #endif
      return 0;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> dp(H, vector<int> (W));
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
        {
            char c;
            cin >> c;
            if(c == '.')
                dp[i][j] = 1;
            else
                dp[i][j] = -1;
        }
    int mod = 1000000007;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            if(dp[i][j] == -1)
                continue;
            if(i == 0 && j == 0)
            {}
            else if(i == 0)
            {
                dp[i][j] = (dp[i][j-1] == -1 ? 0 : dp[i][j - 1]);
            }
            else if(j == 0)
            {
                dp[i][j] = (dp[i - 1][j] == -1 ? 0 : dp[i - 1][j]);
            }
            else
            {
                dp[i][j] = (dp[i - 1][j] == -1 ? 0 : dp[i - 1][j]) % mod;
                dp[i][j] = (dp[i][j] + (dp[i][j-1] == -1 ? 0 : dp[i][j - 1])) % mod;
            }
            dp[i][j] %= mod;
        }
    }
    cout << dp[H - 1][W - 1];
    return 0;
}

Measured memory_bytes: 6144
import math

def main():
    N = int(input())
    ans = 0
    for a in range(1, int(math.sqrt(N))+1):
        for b in range(a, (N // a) + 1):
            if a * b >= N:
                break
            if a != b:
                ans += 2
            else:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
	int n;
	cin>>n;
	int money[200001];
	money[0] = 2000000000;
	int maxProfit=1-1000000000;
	int min=money[0];
	
	for(int i=1;i<=n;i++){
		cin>>money[i];
		if(money[i]-min > maxProfit){
			maxProfit = money[i]-min;
		}
		if(min>money[i]){
			min = money[i];
		}
	}
	cout<<maxProfit<<endl;
	return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

ll power(ll n,ll p){
    if(p==0){return 1;}
    if(p%2==1){return n*power(n,(p-1)/2)*power(n,(p-1)/2);}
    else{return power(n,p/2)*power(n,p/2);}
}

int main() {
    int N;
    vector<int> A(3);
    cin>>N>>A.at(0)>>A.at(1)>>A.at(2);
    vector<int> L(N);
    rep(i,N)cin>>L.at(i);
    int ans=1e9;
    rep(kouho,power(4,N)){
        int MP=-30;
        int x=kouho;
        vector<int> go(N);
        rep(i,N){
            go.at(i)=x%4;
            x/=4;
        }
        int one=0,two=0,three=0;
        rep(i,N){
            if(go.at(i)==1){
                one+=L.at(i);
                MP+=10;
            }
            if(go.at(i)==2){
                two+=L.at(i);
                MP+=10;
            }
            if(go.at(i)==3){
                three+=L.at(i);
                MP+=10;
            }
        }
        if(!(one && two && three))continue;
        vector<int> sa={one,two,three};
        sort(sa.rbegin(),sa.rend());
        rep(i,3){
            MP+=abs(sa.at(i)-A.at(i));
        }
        chmin(ans,MP);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
main () {
    int H, W;
    scanf("%d %d", &H, &W);
    while ((H != 0) && (W != 0)) {
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if ((i+j) % 2 == 0) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &H, &W);
    }
}


Measured memory_bytes: 2112
#pragma GCC optimize("Ofast")
#include <cstdio>

const int cm = 1 << 8;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    343474715,
    0,
    0,
    0,
    0,
    499999999,
    0,
    0,
    0,
    495113154,
    675365680,
    0,
    0,
    0,
    0,
    0,
    0,
    2,
    19,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    833484826,
};

int main(void) {
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (a + b + c) % 29;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1572
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

  long long int a[100010];
  
  for(int i=0;i<N;i++)
  cin >> a[i];
    
    priority_queue<long long> que;
    for (int i = 0; i < N; ++i) {
         que.push(a[i]);
    }
  
    for (int i = 0; i < M; ++i) {
        long long t = que.top(); que.pop();
        que.push(t/2);
    }
  
    long long res = 0;
    while (!que.empty()) res += que.top(), que.pop();
    cout << res << endl;
}





Measured memory_bytes: 2168
N = int(input())
T,A = list(map(int,input().split()))
H = list(map(int,input().split()))

tmp = 10000000
for i in range(N):
  if tmp >= abs(A - (T - (H[i] * 0.006))):
    tmp = abs(A - (T - (H[i] * 0.006)))
    ans = i + 1
print(ans)

Measured memory_bytes: 3060
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

for l, r in LR:
    print(dp[r-1] - dp[l-1])


Measured memory_bytes: 30664
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iomanip>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000
#define mod 1000000000
#define N 100000
using namespace std;
long long a,b,c,s1,s2,s3;
int main()
{
	cin>>a>>b>>c;
	if (a%2==0||b%2==0||c%2==0) cout<<0<<endl; else
	{
		s1=a*b; s2=a*c; s3=b*c;
		if (s2<s1) s1=s2; if (s3<s1) s1=s3;
		cout<<s1<<endl;
	}
	return 0;
}

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

int main() {
    int n; cin >> n;
    int a = 4 , b = 7;
    
    bool ans = false;
    for (int i = 0;i < n; i++) {
        for (int j = 0;j < n; j++) {
            if (a*i + b*j == n) {
                ans = true;
                break;
            }
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout <<"No" << endl;
    return 0;
}

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

int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int ans = 0x7fffffff;
    int max_xy = max(x,y);
    for(int i=0;i<=2*max_xy;i++){
        int xx = x-i/2;
        int yy = y-i/2;
        xx = xx<0?0:xx;
        yy = yy<0?0:yy;
        ans = min(ans,xx*a+yy*b+i*c);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
K = int(input())

new_s = ""

# for i in range(len(s)):
#     c = s[i]
#     if i == len(s) - 1:
#         if cost_for_next_a(c) <= K:
#             new_s += chr(97 + (K - cost_for_next_a(c)) % 26)
#         else:
#             new_s += chr(ord(c) + K)
#     elif c == 'a':
#         new_s += 'a'
#     elif cost_for_next_a(c) <= K:
#         new_s += "a"
#         K -= cost_for_next_a(c)
#     else:
#         new_s += c

for i in range(len(s)):
    c = s[i]
    cost = 123 - ord(c)
    if i == len(s) - 1:
        if cost <= K:
            new_s += chr(97 + (K - cost) % 26)
        else:
            new_s += chr(ord(c) + K)
    elif c == 'a':
        new_s += 'a'
    elif cost <= K:
        new_s += "a"
        K -= cost
    else:
        new_s += c

print(new_s)

Measured memory_bytes: 3572
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	string a, b;
	cin >> a >> b;
	vector<vector<int> > dp(a.size() + 1, vector<int>(b.size() + 1));
	for (int i = a.size() - 1; i >= 0; --i)
		for (int j = b.size() - 1; j >= 0; --j)
			if (a[i] == b[j])
				dp[i][j] = 1 + dp[i + 1][j + 1];
			else
				dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
	for (int i = 0, j = 0; i < a.size(); ++i)
		if (a[i] == b[j])
			printf("%c", b[j++]);
		else if (dp[i + 1][j] < dp[i][j + 1]) {
			--i;
			++j;
		}
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll t;
  //assert(true);//ok
  //assert(false);//fails
  //  cin>>t;
  ll H,W,N;

  //cout<<x<<endl;
  cin>>H;
  cin>>W;
  cin>>N;
  ll s;
  s=max(H,W);
  s=(N+s-1)/s;
  cout<<s<<endl;

}


Measured memory_bytes: 256
n=int(input())
l=[50]*26
d=set(list("abcdefghijklnmopqrstuvwxyz"))
from collections import Counter as co
for i in range(n):
    x=input()
    f=d-set(list(x))
    for k,v in co(x).items():
        l[ord(k)-ord("a")]=min(l[ord(k)-ord("a")],v)
    for c in f:
        l[ord(c)-ord("a")]=0
ans=""
for i in range(26):
    ans+=chr(ord("a")+i)*l[i]
print(ans)

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    while (B <= A) {
        K--;
        B *= 2;
    }
    while (C <= B) {
        K--;
        C *= 2;
    }
    if (K < 0) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int> > A(H, vector<int>(W));
  vector<vector<int> > B(H, vector<int>(W));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> B[i][j];
    }
  }

  const int kMaxVal = 80 * (H + W - 1);
  vector<vector<vector<bool> > > dp(H, vector<vector<bool> >(W, vector<bool>(kMaxVal + 1)));

  int d = abs(A[0][0] - B[0][0]);
  dp[0][0][d] = true;

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      int d = abs(A[i][j] - B[i][j]);
      for (int x = 0; x <= kMaxVal; ++x) {
	if ((i - 1 >= 0 and dp[i - 1][j][x] == true)
	    or (j - 1 >= 0 and dp[i][j - 1][x] == true)) {
	  dp[i][j][x + d] = true;
	  dp[i][j][abs(x - d)] = true;
	}
      }
      
    }
  }

  for (int x = 0; x <= kMaxVal; ++x) {
    if (dp[H - 1][W - 1][x] == true) {
      cout << x << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 10624
S=list(input())
A=[]
B=[]
i=0
while i<len(S):
    if i%2==0:
        A += S[i]
    else:
        B += S[i]
    i+=1
if 'L' in A:
    print('No')
elif 'R' in B:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
# import numpy as np

import bisect

def main():
	N=II()
	A=LI()
	B=LI()
	C=LI()
	A.sort()
	B.sort()
	C.sort()
	BB=[0]*N
	ans=0
	for i,b in enumerate(B):
		BB[i]=N-bisect.bisect_right(C,b)
	BB.append(0)
	for i in range(N-2,-1,-1):
		BB[i]+=BB[i+1]
	for a in A:
		ans+=BB[bisect.bisect_right(B,a)]
	print(ans)



if __name__ == "__main__":
	main()


Measured memory_bytes: 71128
#include<iostream>
#include<string>
#include<vector>

using namespace std;

typedef long long ll;

int N, M;
ll h[100000 + 10];
vector<vector<int>> E;

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++)cin >> h[i];

	E.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].push_back(b), E[b].push_back(a);
	}

	int ans = 0;

	for (int i = 0; i < N; i++) {
		bool f = true;
		for (int j = 0; j < E[i].size(); j++) {
			int nxt = E[i][j];
			if (h[nxt] >= h[i])f = false;
		}
		if (f)ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10;
int n,a[maxn];
int main(){
	int n=read();
	REP(i,1,n) a[i]=read();
	sort(a+1,a+n+1);
	int Min=2e9,pos;
	REP(i,1,n) if(chkmin(Min,abs(a[n]-a[i]*2))) pos=a[i];
	printf("%d %d\n",a[n],pos);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

string s;
cin >> s;
rep(i,s.length())cout << "x";

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a[2][200],*c=a[0],*d=a[1],*e,i,j,k,l,m,n;

  scanf("%d%d",&n,&m);
  for(i=0;i<n*2;i++) c[i]=i+1;
  for(i=0;i<m;i++){
    scanf("%d",&k);
    if(k==0){
      for(j=0;j<n;j++){
        d[j*2]=c[j];
        d[j*2+1]=c[n+j];
      }
    } else {
      for(j=0;j<n*2-k;j++) d[j]=c[j+k];
      for(j=0;j<k;j++) d[n*2-k+j]=c[j];
    }
    e=c;c=d;d=e;
  }
  for(i=0;i<n*2;i++) printf("%d\n",c[i]);
  return 0;
}

Measured memory_bytes: 600
from heapq import heappush, heappop

n,m,s,t = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
    u,v,a,b = map(int,input().split())
    e[u].append((v,a,b))
    e[v].append((u,a,b))
    
def dik(s,v):
    S = [float("INF")]*(n+1)
    S[s] = 0
    h = []
    heappush(h,[0,s])
    while h:
        d,now = heappop(h)
        for nex in e[now]:
            a,b = nex[0],nex[v]
            if d+b < S[a]:
                S[a] = d+b
                heappush(h,[d+b,a])
    return S
S = dik(s,1)
T = dik(t,2)
ans = [0]*(n)
cost = 10**15
now = 0
for i in range(n-1,-1,-1):
    now = max(now,cost-S[i+1]-T[i+1])
    ans[i] = now
print(*ans,sep="\n")

Measured memory_bytes: 61024
import math
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n //= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
#a = factorization(n)
#b = []
#for i,j in a:
#  b.append(i)
def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    if n == 1:
      return([1])
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)
n = int(input())
a = 1
for i in range(1,n+1):
  a*=i
x = factorization(a)
y = []
for i,j in x:
  y.append(j)
ans = 0
for i in y:
  if i >= 74:
    ans += 1
san = 0
go = 0
for i in y:
  if i >= 2:
    san += 1
  if i >= 4:
    go += 1
for i in y:
  if i>=24:
    ans += san-1
  if i >= 14:
    ans += go-1
ans += go*(go-1)//2*(san-2)
print(ans)

Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
from bisect import bisect_left
INF = 1 << 40

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    dp = [INF] * (N + 1)
    dp[0] = -1
    for a in A:
        idx = bisect_left(dp,a)
        dp[idx] = a
    ans = 1
    for i in range(N,-1,-1):
        if dp[i] < INF:
            ans = i
            break
    print(ans)
if __name__ == '__main__':
    main()



Measured memory_bytes: 10476
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine()
  val s = StdIn.readLine()

  println(impl(s))

  def impl(s: String): Int = {
    val reqSequence = Array('A', 'B', 'C')
    var count = 0
    var toBeSeen = 0
    for (c <- s) {
      if (c == reqSequence(toBeSeen)) {
        if (toBeSeen == 2) count += 1
        toBeSeen = (toBeSeen + 1) % 3
      } else {
        if (c == 'A') {
          toBeSeen = 1
        } else {
          toBeSeen = 0
        }
      }
    }
    count
  }
}


Measured memory_bytes: 25416
package main

import "fmt"

func main() {
	var x string
	var s int
	for {
		fmt.Scan(&x)
		if x == "0" {
			break
		}
		s = 0
		for _, v := range x {
			s += int(v - '0')
		}
		fmt.Println(s)
	}
	return
}



Measured memory_bytes: 1140
#include <bits/stdc++.h>
#define tam 300010

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vi> graph;

bool comp(ll a, ll b) {
	return a > b;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int a, b;
    cin >> a >> b;
    cout << (2 * b >= a ? 0 : a - 2 * b) << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] s = new int[n];
		int sum = 0;
		for(int i=0;i<n;i++){
			s[i] = scanner.nextInt();
			sum += s[i];
		}
		if(sum % 10 != 0){
			System.out.println(sum);
			return ;
		}
		Arrays.sort(s);
		for(int i=0;i<n;i++){
			int result = sum - s[i];
			if(result % 10 != 0){
				System.out.println(result);
				return;
			}
		}
		System.out.println(0);
	}

}


Measured memory_bytes: 21204
#include <stdio.h>
int main (void)
{
	int W,H,x,y,r;
	scanf("%d",&W);
	scanf("%d",&H);
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&r);
	if(W>=x+r&&0<=x-r)
	{
		if(H>=y+r&&0<=y-r)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define INF 1L << 50

signed main() {
  int n, x;
  cin >> n >> x;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int b[n][n];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    b[0][i] = a[i];
    ans += a[i];
  }
  for (int k = 1; k < n; k++) {
    int res = k * x;
    for (int i = 0; i < n; i++) {
      int p = i - k;
      if (p < 0) p += n;
      b[k][i] = min(b[k - 1][i], a[p]);
      res += b[k][i];
    }
    ans = min(ans, res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31488
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    vector<vector<char>>v(5,vc(5));
    while(cin>>v[0][0]){
        if(v[0][0]=='0')break;
        else for(int i=0; i<3;i++)
            for(int j=0; j<3;j++){
                if((i==0&&j==0))continue;
                    cin>>v[i][j];
            }
    bool flag=false; char ans = '\0';
    rep(i,3)if((v[i][0]==v[i][1])&&(v[i][1]==v[i][2])&&v[i][0]!='+'){
        flag=true;
        ans=v[i][0];
    }rep(i,3){
        if((v[0][i]==v[1][i])&&(v[1][i]==v[2][i])&&v[0][i]!='+'){
            flag=true;
            ans=v[0][i];
        }
    }if((v[0][0]==v[1][1])&&(v[1][1]==v[2][2])&&v[0][0]!='+'){flag=true; ans=v[0][0];}
    if((v[0][2]==v[1][1])&&(v[1][1]==v[2][0])&&v[1][1]!='+'){flag=true; ans=v[1][1];}
    if(flag)cout<<ans<<endl;
    else cout<<"NA"<<endl;
    }
}

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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

int main() {
	fastio();
	
	LL n, k;
	cin >> n >> k;

	vector<LL> a(n);

	for(auto &e : a) {
		cin >> e;
	}

	for (LL i = k; i < n; ++i) {
		if (a[i] > a[i-k]) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}

}

Measured memory_bytes: 4776
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int n, k, A[2000000], B[2000001], C[10001];

int main(void) {

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
        if (A[i] > k) {
            k = A[i];
        }
    }

    for (int i = 0; i < n; ++i) {
        ++C[A[i]];
    }

    for (int i = 1; i <= k; ++i) {
        C[i] += C[i - 1];
    }

    for (int i = n - 1; i >= 0; --i) {
        B[C[A[i]]] = A[i];
        --C[A[i]];
    }

    printf("%d", B[1]);
    for (int i = 2; i <= n; ++i) {
        printf(" %d", B[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 16856
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<int>t(n), x(n), y(n);
	rep(i, n)cin >> t[i] >> x[i] >> y[i];
	if (n == 1) {
		if (x[0] == 1 && y[0] == 0 || x[0] == 0 && y[0] == 1) {
			cout << "Yes" << endl;
            return 0;
		}
		else {
			cout << "No" << endl;
            return 0;
		}
	}
	rep(i, n-1) {
		int T = t[i + 1] - t[i];
		int D = abs(x[i] - x[i + 1]) + abs(y[i] - y[i + 1]);
		if (D <= T && T % 2 == D % 2) {
			continue;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin >> N;
  long long a[3*N];
  for(int i=0;i<3*N;i++) cin >> a[i];
  long long Z=0;
  sort(a,a+3*N);
  for(int j=1;j<=N;j++) Z+=a[3*N-(2*j)];
  cout << Z << endl;
}

Measured memory_bytes: 2560
//Volume0-0039
import java.util.*;

public class Main {
	
	public static void main(String[] args) {

		//declare
		char[] c;
		int    p,next,sum;
		
		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			c = sc.nextLine().toCharArray();
			
			//initialize
			p=0;next=0;sum=0;
			
			//calculate
			for(int i=0;i<c.length;i++){
				p = chg(c[i]);
				if(i+1<c.length){
					next = chg(c[i+1]);
					if(p < next){
						sum += (next - p);
						i++;
						continue;
					}
				}
				sum += p;
			}
			
			//output
			System.out.println(sum);
		}
	}

	//translate
	private static int chg(char c){
		int ret = 0;
		switch (c) {
			case 'I':{ret =    1; break;}
			case 'V':{ret =    5; break;}
			case 'X':{ret =   10; break;}
			case 'L':{ret =   50; break;}
			case 'C':{ret =  100; break;}
			case 'D':{ret =  500; break;}
			case 'M':{ret = 1000;      ;}
		}
		return ret;
	}
}

Measured memory_bytes: 17356
#include <iostream>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    for(int i=1; i <= n; i++) {
        int x = i;
        if(i%3 == 0 || i%10 == 3) {
            cout << " " << i;
        } else {
            rep(j, 3){
                x /= 10;
                if(x%10 == 3) {
                    cout << " " << i;
                    break;
                }
            }
        }
    }
    cout << endl;
    
    return 0;
}



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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll ara[n+1];
    memset(ara,0,sizeof(ara));
    for(ll i=1;i<n;i++)
    {
        ll a;
        cin>>a;
        ara[a]++;
    }
    for(ll i=1;i<=n;i++)
    {
        cout<<ara[i]<<endl;
    }
    return 0;
    
}


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

int n;
vector<int> childs[100005];
int p[100005];
int ntoid[100005], idton[100005], nid = 0;
int treesize[100005];
int seg[400005];

int query(int x, int l, int r, int k) {
  if (l == r)
    return seg[x];
  int m = l + r >> 1;
  if (k <= m)
    return seg[x] + query(x << 1, l, m, k);
  else
    return seg[x] + query(x << 1 | 1, m + 1, r, k);
}

void segadd(int x, int l, int r, int ul, int ur, int v) {
  if (l == ul && r == ur) {
    seg[x] += v;
    return;
  }

  int m = l + r >> 1;
  if (ur <= m)
    segadd(x << 1, l, m, ul, ur, v);
  else if (ul > m)
    segadd(x << 1 | 1, m + 1, r, ul, ur, v);
  else {
    segadd(x << 1, l, m, ul, m, v);
    segadd(x << 1 | 1, m + 1, r, m + 1, ur, v);
  }
}

int dfs(int n) {
  treesize[n] = 1;
  idton[nid] = n;
  ntoid[n] = nid++;
  for (int h : childs[n])
    treesize[n] += dfs(h);
  return treesize[n];
}

void update(int v, int w) {
  segadd(1, 0, n - 1, ntoid[v], ntoid[v] + treesize[v] - 1, w);
}

void getsum(int u) {
  cout << query(1, 0, n - 1, ntoid[u]) << endl;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    for (int j = 0; j < t; j++) {
      int x; cin >> x;
      p[x] = i;
      childs[i].push_back(x);
    }
  }
  dfs(0);
  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    if (t == 0) {
      int v, w; cin >> v >> w;
      update(v, w);
    }
    if (t == 1) {
      int u; cin >> u;
      getsum(u);
    }
  }
}



Measured memory_bytes: 14280
#include <bits/stdc++.h>
using namespace std;
int num[100];
void change(int k,int n){
	for(int i=0;i<=n;i++)if(num[i]%k>num[i+1]%k)swap(num[i],num[i+1]);
}
int main() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    for(int i=1;i<=m;i++)change(i,n-2);
    for(int i=0;i<n;i++)cout<<num[i]<<endl;
}

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

while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == '?':
        break
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    else:
        print(a // b)


Measured memory_bytes: 5596
N, A, B = map(int, raw_input().split())
def f(x):
    res = 0
    while x > 0:
        res += x % 10
        x /= 10
    return res
ans = 0
for num in range(1, N+1):
    if A <= f(num) <= B:
        ans += num
print ans

Measured memory_bytes: 2948
#include <iostream>
#include <vector>

int main(){
    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());

    std::string key;
    int index = 0;
    bool flg = true;
    while(s.size() > index && flg){
        for(int i = 5; i <= 7; ++i){
            if(i > s.size()){
                flg = false;
                break;
            }
            key = s.substr(index, i);

            if("maerd" == key || "remaerd" == key || "esare" == key || "resare" == key){
                index = index + i;
                break;
            }else if(7 == i){
                flg = false;
                break;
            }
        }
    }

    if(flg){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
}



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

using namespace std;

const int N = 100001;
int a[N], b[N], c[N], dp[N][4];
int n;

int solve(int pos, int pre) {
    if (pos == 0) {
        return 0;
    }
    int& ans = dp[pos][pre];
    if (ans != -1) {
        return ans;
    }
    ans = 0;
    if (pre != 1) {
        ans = max(ans, solve(pos - 1, 1) + a[pos]);
    }
    if (pre != 2) {
        ans = max(ans, solve(pos - 1, 2) + b[pos]);
    }
    if (pre != 3) {
        ans = max(ans, solve(pos - 1, 3) + c[pos]);
    }
    return ans;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    memset(dp, -1, sizeof dp);
    cout << solve(n, 0);
    return 0;
}


Measured memory_bytes: 7680
#include<stdio.h>



unsigned long int gcd(unsigned long int one,unsigned long int two){		//Ååöñ
	
	unsigned long int temp,mod;
	
	if(one<two){
		temp=one;
		one=two;
		two=temp;
	}
	
	while(two!=0){
		
		mod=one%two;
		
		if(mod==0){
			
			return two;
		
		}else if(mod!=0){
			one=two;
			two=mod;
		}
	}
	return 0;
}


unsigned long int lcm(unsigned long int one, unsigned long int two){		//Å¬ö{
	return (one/gcd(one,two))*two;
}
	
int main(void){

	unsigned long int first,second;
	

	while(scanf("%d %d",&first,&second)!=EOF){
		
		if(first<=0||second<=0){
			break;
		}
		printf("%d %d\n",gcd(first,second),lcm(first,second));
	}
	
	return 0;
}

Measured memory_bytes: 0
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int k = 1;
		String prev = s.charAt(0)+"";
		int previd = 1;
		for(int i=1;i<s.length();i++){
		    String t = s.substring(previd, i+1);
		    if(!prev.equals(t)){
		        k++;
		        prev = t;
		        previd = i+1;
		    }
		}
		System.out.println(k);
	}
}

Measured memory_bytes: 35912
#include <stdio.h>

int main(void){
	int sp=0,sq=0;
	int n,count=0;
	int p[30],q[30];
	while(scanf("%d",&n)!=EOF){
		if(n!=0){
			p[++sp]=n;
			count=count+1;
		}else if(n==0){
			q[++sq]=p[sp--];
		}
	}
	for(sq=1;sq<=count;sq++){
		printf("%d\n",q[sq]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main(void){
    // Your code here!
    int length, index;
    scanf("%d%d", &length, &index);
    
    char s[length];
    scanf("%s", s);
    
    // 小文字にする
    s[index - 1] += 32;
    
    printf("%s\n", s);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;

ll comb(ll cb_l, ll cb_r) {
    ll comb = 1;
    if (cb_l < cb_r || cb_l < 0 || cb_r < 0) comb = 0;
    else {
        cb_r = min(cb_r, cb_l - cb_r);
        for (int i = 1; i <= cb_r; i++) {
            comb *= (cb_l - i + 1);
            comb /= i;
        }
    }
    return comb;
}

int main(void){
    ll n, a, b;
    ll v[55];
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> v[i];
    
    sort(v, v + n, greater<ll>());
    
    ll mx = v[0], mn = 1e16, mn_all = 0, mn_in = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        if (mn == v[i]) {
            mn_all++;  mn_in++;
        }
        else {
            mn_all = mn_in = 1;
        }
        mn = v[i];
        
        if (i == b) {
            cout << v[0] << endl;
            cout << ans << endl;
            return 0;
        }
        
        if (i >= a - 1) {
            if (v[i + 1] != mx) {
                ll v_sum = 0;
                for (int j = 0; j <= i; j++) {
                    v_sum += v[j];
                }
                cout << setprecision(20) << double(v_sum) / double(i + 1) << endl;
                
                for (int j = i + 1; j < n; j++) {
                    if (v[i] == v[j]) mn_all++;
                }
                
                //cout << mn_all << " "  << mn_in << endl;
                
                cout << ans + comb(mn_all, mn_in) << endl;
                return 0;
            }
            else {
                int tmp = 0;
                for (int j = 0; j < n; j++) {
                    if (mx == v[j]) tmp++;
                }
                ans += comb(tmp, i + 1);
                //cout << tmp << " " << i + 1 << endl;
            }
        }
        
    }
    
    cout << v[0] << endl;
    cout << ans + 1 << endl;
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N, L;
        static string[] S;
        
        

        public static void Input()
        {
            var cin = new Scanner();
            var input = cin.SplitReader();
            N = input[0];
            L = input[1];
            S = new string[N];
            for(var i = 0; i < N; i++)
            {
                S[i] = Console.ReadLine();
            }
        }

        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);


            var ans = new StringBuilder();
            Sort(S);
            for(var i = 0; i < N; i++)
            {
                ans.Append(S[i]);
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 11616
# 次に試合したい相手をdequeで管理
# お互いの試合したい相手(dequeの先頭)が一致すれば試合できる
# 次の日のチェック対象は「前日に試合した人」だけ。これをキュー管理

import sys
readline = sys.stdin.readline

N = int(readline())
ALL = (N * (N - 1)) // 2 # 試合数

from collections import deque
player = [None] * N
for i in range(N):
  player[i] = deque(list(map(lambda x:int(x) - 1,readline().split())))
  
# 明日試合する候補の人
q = set(range(N))

day = 0
while q:
  day += 1
  nextday = set()
  checked = set()
  for p in q:
    if p in checked:
      continue
    if len(player[p]) == 0:
      continue
    op = player[p][0] # 次の対戦相手
    if op in checked:
      continue
    if player[op][0] == p:
      # 試合成立
      player[p].popleft()
      player[op].popleft()
      checked.add(op)
      checked.add(p)
      if player[p]:
        nextday.add(p)
      if player[op]:
        nextday.add(op)
  q = nextday 

for p in player:
  if len(p) > 0:
    print(-1)
    break
else:
  print(day)

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

using namespace std;

int main(){
    
    int ac = 0, wa = 0, tle = 0, re = 0;
    int n = 0;
    cin >> n;
    while(n){
        string tmp;
        cin >> tmp;
        if(tmp == "AC")
            ac++;
        else if(tmp == "WA")
            wa++;
        else if(tmp == "TLE")
            tle++;
        else
            re++;
        n--;
    }
    cout <<"AC x " << ac << '\n' << "WA x " << wa << '\n' << "TLE x " << tle << '\n' << "RE x " << re << '\n';
    return 0;
}

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

int main(){
  long long s;
  cin >> s;
  long long shou = s / 1000000000;
  long long amari = s % 1000000000;
  if(shou == 0){
    cout << 0 << " " << 0 << " " << 1 << " " << 0 << " " << 0 << " " << amari << endl;
  }else if(amari == 0){
    cout << 1 << " " << 0 << " " << 0 << " " << 1000000000 << " " << shou << " " << 1000000000 << endl;
  }else{
    cout << 1 << " " << 0 << " " << 0 << " " << 1000000000 << " " << shou+1 << " " << amari << endl;
  }
  return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, K; cin >> N >> K;
	string S; cin >> S;

	S[K - 1] = tolower(S[K - 1]);
	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    int a,b;
    cin >> a >> b;
    int ans = max(a,b);
    if(a>=b){
        a--;
    }
    else{
        b--;
    }
    ans += max(a,b);
    cout << ans;

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 100000000
using namespace std;

struct state {
  int n, d;
  bool operator<(const state &s) const { return d > s.d; }
};

int N, P[100000];
int dp[100000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> P[i];

  REP(i, 0, N) dp[i] = INF;

  int ans = -1;
  priority_queue<state> q;
  q.push((state) { 0, 0 });
  while(q.size()) {
    state c = q.top();
    q.pop();

    // cout << c.n << " " << c.d << endl;

    if(c.n >= N - 1) {
      ans = c.d;
      break;
    }

    if(dp[c.n] <= c.d) continue;
    dp[c.n] = c.d;

    if(P[c.n] != 0) {
      q.push((state) { c.n + P[c.n], c.d });
      continue;
    }

    REP(i, 1, 7) {
      int nn = c.n + i, nd = c.d + 1;
      if(dp[nn] > nd) q.push((state) { nn, nd });
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3948
def main():
    n = int(input())
    A = [0] + [int(input()) for _ in [0] * n]
    visited = [0] * (n+1)
    now = 1
    visited[now] = 1
    cnt = 0
    while True:
        next = A[now]
        cnt += 1
        if visited[next]:
            print(-1)
            break

        if next == 2:
            print(cnt)
            break

        visited[next] = 1
        now = next


if __name__ == "__main__":
    main()


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

const ll MOD = 1'000'000'007;

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

ll f(ll l, ll r) {
  ll res = (l + r) * (r - l + 1) / 2;
  return res;
}

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

  ll res = 0;
  for (ll i = k; i <= n + 1; ++i) {
    ll maxV = f(n - i + 1, n);
    ll minV = f(0, i - 1);
    res = (res + ((maxV - minV + 1) % MOD)) % MOD;
  }
  cout << res << endl;

  return 0;
}


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

using namespace std;

const array<string, 4> uses = {"esare", "resare", "maerd", "remaerd"};
string s;
int n;

bool Solve(int idx) {
    if (idx == n) return true;
    for (const auto &x : uses) {
        if (s.substr(idx, x.size()) == x)
            return Solve(idx + x.size());
    }
    return false;
}

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

    cin >> s;
    reverse(s.begin(), s.end());
    n = s.size();

    if (Solve(0)) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int L = nextInt();
  int s = 0;
  REP(i, N) s += L+i;

  int ans = 999999999;
  int ans_i = 0;
  for (int i = 0; i < N; i++) {
    int si = 0;
    for (int j = 0; j < N; j++) if (i != j) {
      si += L+j;
    }
    if (ans > abs(s-si)) {
      ans = abs(s-si);
      ans_i = si;
    }
  }
  cout << ans_i << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int n;

	cin >> n;

	int ct[26][50] = {};
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++) {
			ct[s[j] - 'a'][i]++;
		}
	}

	string ans;
	
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < *min_element(ct[i], ct[i] + n); j++)
			ans += ('a' + i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256