akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int h,w;
	cin >> h >> w;
	char a[101][101];
	rep(i,h)rep(j,w)cin >> a[i][j];

	rep(i,w+2)cout << '#';cout << endl;
	rep(i,h){
		cout << '#';
		rep(j,w)cout << a[i][j];
		cout << '#' << endl;;
	}
	rep(i,w+2)cout << '#';cout << endl;


	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc062.contest.atcoder.jp/tasks/abc062_b

Measured memory_bytes: 3684
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n,m;
	cin>>n>>m;
	ll arr[n+1];
	input(arr,n);arr[n]=0;
	sort(arr,arr+n);
	vector<pair<ll,ll> >v;
	for(ll i=0;i<m;i++)
	{
		ll b,c;
		cin>>b>>c;
		v.push_back({c,b});
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	ll ans=0;
	for(ll i=n-1;i>=0;i--)
	arr[i]+=arr[i+1];
	vector<ll>prf;
	for(ll i=0;i<v.size();i++)
	{
		ll val=v[i].f,freq=v[i].s;
		while(freq--)
		{
			prf.push_back(val);
			if(prf.size()==n)break;
		}
		if(prf.size()==n)break;
	}
	ll val=0;ans=arr[0];
	for(ll i=0;i<min(n,(ll)prf.size());i++)
	{
		val+=prf[i];
		ans=max(ans,val+arr[i+1]);
	}
	cout<<ans;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    vector<vector <int>> a(3,vector<int>(3));
    rep(i,3) rep(j,3)cin>>a[i][j];

    int n;cin>>n;
    rep(i,n){
        int tmp; cin>>tmp;
        rep(j,3)rep(k,3)if(a[j][k] == tmp) a[j][k] = -1;
    }
    bool ok = false;
    if(a[0][0]==-1&&a[0][1]==-1&&a[0][2]==-1) ok = true;
    if(a[1][0]==-1&&a[1][1]==-1&&a[1][2]==-1) ok = true;
    if(a[2][0]==-1&&a[2][1]==-1&&a[2][2]==-1) ok = true;
    if(a[0][0]==-1&&a[1][1]==-1&&a[2][2]==-1) ok = true;
    if(a[2][0]==-1&&a[1][1]==-1&&a[0][2]==-1) ok = true;
    if(a[0][0]==-1&&a[1][0]==-1&&a[2][0]==-1) ok = true;
    if(a[0][1]==-1&&a[1][1]==-1&&a[2][1]==-1) ok = true;
    if(a[0][2]==-1&&a[1][2]==-1&&a[2][2]==-1) ok = true;


    if(ok)cout <<"Yes"<<endl;
    else cout <<"No"<<endl;


}



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

int main(){
    int N,K;
    std::cin>>N>>K;
    std::vector<long long> A(N),S(N+1),black(N+1);
    for(int i=0;i<N;++i){
        std::cin>>A[i];
        S[i+1]=S[i]+A[i];
        black[i+1]=black[i]+((A[i]>0)?A[i]:0);
    }
    long long ans=-1e18,tmp;
    for(int i=0;i<=N-K;++i){
        tmp = (S[i+K]-S[i]>0)?(S[i+K]-S[i]):0;
        tmp += black[i]+black[N]-black[i+K];
        ans = std::max(ans,tmp);
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 2560
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

from collections import Counter

N = int(open(0).read())
l = prime_factorize(N)
c = Counter(l)
ans = 0
cl = [x for x in c.values()]
for i in range(1,41):
    for j in range(len(cl)):
        if cl[j] >= i:
            ans += 1
            cl[j] -= i
print(ans)

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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

int f(int x) {
    if (x < 400) return 0;
    else if (x < 800) return 1;
    else if (x < 1200) return 2;
    else if (x < 1600) return 3;
    else if (x < 2000) return 4;
    else if (x < 2400) return 5;
    else if (x < 2800) return 6;
    else if (x < 3200) return 7;
    return 8;
}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> cnt;
    set<int> S;
    bool flag = false;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] < 3200) flag = true;
        cnt[f(A[i])]++;
        S.insert(f(A[i]));
    }
    if (cnt[8] == 0) {
        cout << S.size() << " " << S.size() << endl;
        return;
    }
    if (flag) {
        cout << S.size()  - 1 << " " << S.size() + cnt[8] - 1 << endl;
    } else {
        cout << 1 << " " << cnt[8] << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
import sys

H, W = map(int, raw_input().split())
table = [(0 for _ in range(W)) for _ in range(H)]

for x in range(H):
	table[x] = raw_input().split()

def convert_num_to_alpha(x):
	return chr(65 + x)

for x in range(H):
	for y in range(W):
		if table[x][y] == "snuke":
			print convert_num_to_alpha(y) + str(x + 1)


Measured memory_bytes: 2568
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, A, B = map(int, input().split())
    X = list(map(int, input().split()))
    cost = 0
    for i in range(N - 1):
        d = X[i + 1] - X[i]
        cost += min(d * A, B)
    print(cost)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15016
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

k, s = map(int, input().split())

ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - (x+y)
        if (z>=0 and z <= k):
            #print(x,y,z)
            ans += 1
print(ans)




Measured memory_bytes: 9164
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
di = {}
for i in d:
    if i in di:
        di[i] += 1
    else:
        di[i] = 1
for i in t:
    if i not in di or di[i]==0:
        print('NO')
        break
    di[i] -= 1
else:
    print('YES')

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

int main() {
  ll N;
  cin>>N;
  //Nを素因数分解、因数を順番にsetに入れていく＞値が真ん中のものを選ぶ
  ll a=1;
  set<ll> st;
  
  while(N>=a*a){
    if(N%a==0){
      st.insert(a);
      st.insert(N/a);
    }
    a++;
  }
  
  int b=1;
  ll i=0,j;
  for(auto value:st){
    if(b==(st.size()+1)/2){
      i=(ll)value;
      j=N/(ll)value;
      break;
    }      
    else b++;
  }
  cout<<(ll)(i+j-2)<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, x;
cin >> n >> x;
if((n*2-1)>x&&x>1){
cout << "Yes" << endl;
for(int i=(x+n)%(2*n-1); i < n*2; i++){
  if(i==0){
    i = (2*n-1);
  }
    cout << i << endl;
  }
  for(int i=1; i <(x+n)%(2*n-1); i++){
      cout << i << endl;
    }
    if((x+n)%(2*n-1)==0){
      for(int i=1; i <(2*n-1); i++){
          cout << i << endl;
        }
    }

}
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1536
def solve():
    base = [] # 基底の初期化
    for a, s in zip(A[::-1], S[::-1]):
        # print(f'a: {a}, s: {s}')
        # for i, y in enumerate(base):
        #     print('base{:d} {:3d}: {:05b}'.format(i, y, y))

       # 従属関係を確認
        x = a
        for y in base:
            x = min(x, x ^ y)

        # A_iがA_{i+1:N}で表現可能ならx=0になっている
        if x:
            if s == "0":
                # print('=>add {:3d}: {:05b}'.format(x, x))
                base.append(x)
            else:
                return 1
    return 0


t = int(input())
for _ in range(t):
    n = int(input())
    *A, = map(int, input().split())
    S = input()
    # print(f'A: {A}, S: {S}')
    print(solve())
    # print('-'*32)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    out(360/gcd(n,360));
}

Measured memory_bytes: 3632
#include<cstdio>
using namespace std;
int n,m,sum1,sum2,a[111],p,x;
int main()
{
    scanf("%d",&n);
    for (register int i(1);i<=n;++i)
	{
        scanf("%d",&a[i]);
        sum1+=a[i];
    }
    scanf("%d",&m);
    sum2=sum1;
    while(m--)
    {
        
        scanf("%d%d",&p,&x);
        if (x>=a[p]) sum1+=x-a[p]; else sum1-=a[p]-x;
        printf("%d\n",sum1);
        sum1=sum2;
    }
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
char s[1000010],a,b,c;
bool cut[1000010];
int n,m,cnt[3],p[3];
bool cmp(int x,int y)
{
	return cnt[x]<cnt[y];
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	s[0]=4;
	for(int i=1;i<=n;++i)
	{
		s[i]-='A';
		if(s[i]!=s[i-1])s[++m]=s[i],++cnt[s[i]];
	}
	n=m;
	p[0]=0,p[1]=1,p[2]=2;
	sort(p,p+3,cmp);
	a=p[0],b=p[1],c=p[2];
//	printf("%d %d %d\n",a,b,c);
	int last=0,cnt1=0,cnt2=0;
	for(int i=1;i<=n;++i)
		if(s[i]==a)
		{
			if(last)
			{
				if(i==last+2&&s[i-1]==c)++cnt1;
				else ++cnt2;
			}
			else if(i>2||s[1]==b)++cnt2;
			last=i;
		}
	if(n-last>=2||s[n]==b)++cnt2;
//	for(int i=1;i<=n;++i)putchar(s[i]+'A');printf("\n");
//	printf("%d %d\n",cnt1,cnt2);
	if(cnt1>cnt2)
	{
		last=0;
		for(int i=1;i<=n;++i)
			if(s[i]==a)
			{
				if(last&&i==last+2&&s[i-1]==c)cut[i-1]=cut[last]=1,--cnt1;
				last=i;
				if(cnt1==cnt2)break;
			}
	}
	m=0;
	for(int i=1;i<=n;++i)if(!cut[i])s[++m]=s[i];
	n=m;memset(cut,0,sizeof(cut));
//	for(int i=1;i<=n;++i)putchar(s[i]+'A');printf("\n");
	int cnta=0,cntb=0,cntc=0;
	for(int i=1;i<=n;++i)
		if(s[i]==a)++cnta;
		else if(s[i]==b)++cntb;
		else ++cntc;
	if(cntc>cntb)
	{
		last=0;
		for(int i=1;i<=n;++i)
			if(s[i]==a)
			{
				if(!last)
				{
					if(i>=2)
					{
						if(s[i-1]==c)cut[i-1]=1,--cntc;
						if(cntb==cntc)break;
						if(s[1]==c&&i>2)cut[1]=1,--cntc;
						if(cntb==cntc)break;
					}
				}
				else
				{
					if(i!=last+2&&s[i-1]==c)cut[i-1]=1,--cntc;
					if(cntb==cntc)break;
					if(i!=last+2&&s[last+1]==c)cut[last+1]=1,--cntc;
					if(cntb==cntc)break;
				}
				last=i;
			}
		if(cntb!=cntc&&s[last+1]==c)cut[last+1]=1,--cntc;
		if(cntb!=cntc&&s[n]==c)cut[n]=1,--cntc;
	}
	m=0;
	for(int i=1;i<=n;++i)if(!cut[i])s[++m]=s[i];
	n=m;s[n+1]=a;memset(cut,0,sizeof(cut));
//	for(int i=1;i<=n;++i)putchar(s[i]+'A');printf("\n");
	last=0;
	for(int i=1;i<=n+1;++i)
		if(s[i]==a)
		{
			int p=last+1;
			while(cnta<cntb&&(p+2<i||i==n+1))cut[p]=cut[p+1]=1,p+=2,--cntb,--cntc;
			if(cnta==cntb)break;
			last=i;
		}
	for(int i=1;i<=n;++i)if(!cut[i])putchar(s[i]+'A');
	return 0;
}

Measured memory_bytes: 3072
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N = i2n()
    A = i2nn()
    a = A[0]
    b = A[0]
    n = 1
    j = 0
    #print(0, 0, a, b)
    for i in range(1, N):
        c = A[i]
        a ^= c
        b += c
        #print(j, i, a, b)
        while a != b:
            d = A[j]
            a ^= d
            b -= d
            j += 1
            #print(j, i, a, b)
        n += i - j + 1
    print(n)

main()


Measured memory_bytes: 69308
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, x, y;
	cin >> n;
	vector<pair<long long, long long> > a;
	for(int i = 0; i < n; i++) {
		cin >> x >> y;
		a.push_back({x, y});
	}
	sort(a.begin(), a.end());
	int ans = n;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			int dx = a[j].first - a[i].first;
			int dy = a[j].second - a[i].second;
			map<pair<long long, long long>, bool> mp;
			int cnt = 0;
			for(int k = 0; k < n; k++) {
				int px = a[k].first - dx;
				int py = a[k].second - dy;
				if(!mp[{px, py}])
					cnt++;
				mp[a[k]] = true;
			}
			ans = min(ans, cnt);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}



template< class T >
struct CumulativeSum {
  vector< T > data;

  CumulativeSum(int sz) : data(sz, 0) {};

  CumulativeSum(vector< T> v) : data(v.size()+1,0) {rep(i,v.size()) add(i+1,v[i]); build();};

  void add(int k, T x) {
    data[k] += x;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      data[i] += data[i - 1];
    }
  }

  T query(int l,int r) {  // [l,r)
    if(l < 0) return (0);
    return (data[min(r,(int)data.size()-1)]-data[min(l,(int)data.size()-1)]);
  }
};


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k;
  while(true){
    cin>>n>>k;
    if(n==0) break;
    vi a(n);
    rep(i,n){
      cin>>a[i];
    }
    CumulativeSum<int> v(a);
    int ans=-INF;
    rep(i,n-k){
      ans=max(ans,v.query(i,i+k));
    }
    cout<<ans<<endl;
  }


}


Measured memory_bytes: 5080
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif
    const int int_max = 1e9;
    int n, x;
    cin >> n;
    int a[n] = {};
    for (int i = 0; i < n; i++)
    {
        a[i] = int_max;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        auto y = lower_bound(a, a + n, x);
        *y = x;
    }
    int ans;
    for (int i = 0; i < n; i++)
    {
        if (a[i] != int_max)
            ans = i + 1;
    }
    cout << ans << endl;
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;

int main(void)
{
	ll n, k;
	cin >> n >> k;
	if (k > (n-2) * (n - 1) / 2) {
		cout << -1 << endl;
		return 0;
	}
	vector<vector<bool>> s(n,vector<bool>(n,false));
	for (int i = 1; i < n; i++) {
		s[0][i] = true;
	}
	auto count = (n - 2) * (n - 1) / 2;
	//cout << count << endl;
	int i = 1;
	int j = 2;
	while (count > k) {
		if (!s[i][j]) {
			s[i][j] = true;
			count--;
		}
		j++;
		if (j == n) {
			i++;
			j = i + 1;
		}
	}
	ll sum = 0;
	rep(i, n) rep(j, n) if (s[i][j]) sum++;
	cout << sum << endl;
	rep(i, n) rep(j, n) if (s[i][j]) cout << i+1 << " " << j+1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct UnionFind{
	vector<int> par,siz;
	UnionFind(int N): par(N), siz(N){
		rep(i, N){
			par[i] = i; siz[i] = 1;
		}
	}
	int root(int x){
		if(par[x]==x) return x;
		else return root(par[x]);
	}
	void unite(int x, int y){
		x=root(x); y=root(y);
		if(x==y) return;
		if(siz[x] < siz[y]) swap(x, y);
		par[y] = x;
		siz[x] += siz[y];
	}
	bool same(int x, int y){
		return root(x)==root(y);
	}
	int size(int x){
		return siz[root(x)];
	}
};


int main(){
  int N, M; cin >> N >> M;
  UnionFind uf(N);
  int a[M], b[M];
  rep(i, M){
    cin >> a[i] >> b[i]; a[i]--; b[i]--;
  }
  vector<ll> ans(M); ll cur = (ll) N*(N-1)/2;
  rep(i, M){
    ans.push_back(cur);
    int c, d; c = a[M-1-i]; d = b[M-1-i];
    if(!uf.same(c, d)) cur -= (ll) uf.size(c) * uf.size(d);
    uf.unite(c, d);
  }
  reverse(ans.begin(), ans.end());
  rep(i, M){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4464
#include<stdio.h>
int f(int x,int y)
{
	if(y%x==0)
	return x;
	else
	return f(y%x,x);
}
int main()
{
	long long int a,b,c,d,e,r,t,y,u,k;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if(c>d)
	{
		t=c;
		c=d;
		d=t;
	}
	e=b/c-(a-1)/c;
	r=b/d-(a-1)/d;
	u=c*d/f(c,d);
	k=b/u-(a-1)/u;
	printf("%lld\n",b-a+1-(e+r-k));
}

Measured memory_bytes: 128
#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>;
typedef struct {
    int x; int y;
    int c;
}D;
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

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

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};
struct Edge
{
  int a, b, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  int n;  // 頂点数
  vector<Edge> es;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  int kruskal() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;

    rep(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.a, e.b)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

// 標準入力からグラフを読み込む
Graph input_graph(int n, vector<D> cand) {
  Graph g;
  //int m;
  //cin >> g.n >> m;
  g.n = n;
  rep(i, cand.size()) {
    Edge e;
    //cin >> e.a >> e.b >> e.cost;
    e.a = cand[i].x; e.b = cand[i].y; e.cost = cand[i].c;
    g.es.push_back(e);
  }
  return g;
}
int main() {
    int N; cin >> N;
    vector<P> x(N), y(N);
    rep(i, N) {
        cin >> x[i].first >> y[i].first;
        x[i].second = y[i].second = i;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    vector<D> cand;
    rep(i, x.size()-1) {
        D d = {x[i].second, x[i+1].second, abs(x[i].first-x[i+1].first)};
        cand.push_back(d);
    }
    rep(i, y.size()-1) {
        D d = {y[i].second, y[i+1].second, abs(y[i].first-y[i+1].first)};
        cand.push_back(d);
    }
    //sort(cand.begin(), cand.end());
    Graph g = input_graph(N, cand);
    cout << g.kruskal();
}


Measured memory_bytes: 12656
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())
#ans = [0] * N
#math.ceilで切り上げ
import math
import string

def intinput():
    return int(input())

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

def splitintinput():
    return map(int,input().split())

S, T= input().split()
A, B = splitintinput()
U = input()

if U == S:
    print(A-1, B)
else:
    print(A, B-1)



Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<60
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17 -I .
//push_back -> emplace_back
int N,M,Q;
vector<VI> sum;
void buildSumTable(const VI &L,const VI& R){
   sum=vector<VI> (N+1,VI(N+1,0));
   rep(i,M){
      sum[L[i]][R[i]]++;
   }
   for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++){
         sum[i][j]+=sum[i-1][j];
         sum[i][j]+=sum[i][j-1];
         sum[i][j]-=sum[i-1][j-1];
      }
   }
}
int getSumRange(int l, int r){
   int ans=0;
   ans+=sum[r][r];
   ans-=sum[r][l-1];
   ans-=sum[l-1][r];
   ans+=sum[l-1][l-1];
   return ans;
}
int main(){
   cin>>N>>M>>Q;
   VI L(M),R(M);
   rep(i,M)cin>>L[i]>>R[i];
   VI p(Q),q(Q);
   buildSumTable(L,R);
   rep(i,Q){
      cin>>p[i]>>q[i];
      cout<<getSumRange(p[i],q[i])<<endl;
      }

}

Measured memory_bytes: 9844
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( true ) {
	    long n = stdin.nextLong();
	    if ( n == 0L ) {
		break;
	    }

	    long count = 0;
	    while ( n > 0 ) {
		count += n / 5L;
		n /= 5L;
	    }

	    System.out.println( count );
	    
	}
	
    }
    
}

Measured memory_bytes: 15328
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define N 262144
ll dp[2][2*N+5];
int n,q,a,b;

#define INM 100000000000000000LL
//0-index
void update(int id,int k,ll a)
{
	k += N-1;
	dp[id][k] = a;
	while(k > 0)
	{
		k = (k-1)/2;
		dp[id][k] = min(dp[id][k*2+1],dp[id][k*2+2]);
	}
}


ll query(int id,int a,int b,int k=0,ll l=0,ll r=N)
{
	if(r <= a || b <= l)return INM;
	if(a <= l && r <= b)return dp[id][k];
	else
	{
		ll vr = query(id,a,b,k*2+1,l,(l+r)/2);
		ll vl = query(id,a,b,k*2+2,(l+r)/2,r);
		return min(vr,vl);
	}
}

int main()
{
	cin >> n >> q >> a >> b;
	REP(i,2)REP(j,N)update(i,j,INM);
	
	vector<int> que;que.PB(a);
	
	REP(i,q)
	{
		int tmp;cin >> tmp;que.PB(tmp);
	}
	
	update(0,b,b);
	update(1,b,n-b);
	
	//cout  << query(1,0,n+1) << endl;
	
	ll sum = 0;
	for(int i = 1;i <= q;i++)
	{
		ll tmp = abs(que[i-1]-que[i]);
		sum += tmp;
		
		ll mi = min(query(1,0,que[i]+1)-(n-que[i]),query(0,que[i],n+1)-que[i]);
		//cout << query(1,0,que[i]+1)-que[i]+1<< ' ' << query(0,que[i],n+1)-que[i] << endl;
		update(0,que[i-1],mi-tmp+que[i-1]);
		update(1,que[i-1],mi-tmp+n-que[i-1]);
	}
	

	
	ll ans = INM;
	
	REP(i,n+1)
	{
		ans = min(ans,dp[0][i+N-1]-i);
		ans = min(ans,dp[1][i+N-1]-(n-i));
	}
	
	cout << ans + sum << endl;

	return 0;
}

Measured memory_bytes: 9592
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    tmp_time = 0
    last_i = -1
    for i in range(N):
        if tmp_time + A[i] <= K:
            tmp_time += A[i]
            last_i = i
        else:
            break

    last_j = -1
    for j in range(M):
        if tmp_time + B[j] <= K:
            tmp_time += B[j]
            last_j = j
        else:
            break

    ans = last_i + last_j + 2
    now = ans
    while last_i >= 0:
        tmp_time -= A[last_i]
        now -= 1
        last_i -= 1

        while last_j + 1 < M and tmp_time + B[last_j + 1] <= K:
            tmp_time += B[last_j + 1]
            last_j += 1
            now += 1

        ans = max(ans, now)

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 41088
from itertools import combinations
import numpy as np

INF = 10**8
N,M,X=map(int, input().split())
C = []
A = [[0 for i in range(M)] for j in range(N)]

for i in range(N):
  temp = list(map(int, input().split()))
  c, a = temp[0], temp[1:]
  C.append(c)
  A[i] = a

C, A = map(np.array, [C,A]) 
min_ = INF
for i in range(1,N+1):
  for c in combinations(range(N),i):
    if (A[c,:].sum(0) >= X).sum() == M:
      if C[list(c)].sum() < min_:
        min_ = C[list(c)].sum()

if min_ == INF: print(-1)
else: print(min_)

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

int main() {
  int n, k, ans;
  cin >> n >> k;
  ans = 0;
  
  for (int i=0; i<n; i++) {
    int x;
    cin >> x;
    
    if (x < k-x)
      ans += x*2;
    else
      ans += (k-x)*2;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
	int a, b, c, d, e, f;
	double x, y;

	while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF) {
		if (b * d - a * e != 0) {
			y = (double)(d * c - a * f) / (b * d - a * e);
			if ( a != 0 ) {
				x = (c - b * y) / a;
			} else {
				x = (f - e * y) / d;
			}
			printf("%.3f %.3f\n", x, y);
		} else if (a * e - b * d == 0) {
			x = (double)(e * c - b * f) / ( a * e - b * d);
			if ( b != 0 ) {
				y = (c - a * x) / b;
			} else {
				y = (f - d * x) / e;
			}
		}
	}
	return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W, '.'));
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            cin >> A[i][j];
        }
    }
    
    vector<vector<ll>> dp(H, vector<ll>(W, 0));
    dp[0][0] = 1;
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {

            if ((i == 0) & (j == 0)) continue;
            if (A[i][j] == '#') continue;

            if (0 < i) dp[i][j] += dp[i-1][j];
            if (0 < j) dp[i][j] += dp[i][j-1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[H-1][W-1] << endl;

    return 0;
}

Measured memory_bytes: 9088
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
A,B,C,D= map(int, input().split())
AC = (A-1)//C
AD = (A-1)//D
ACD =(A-1)//(C*D//gcd(C,D))
ans1 = A -1-AC -AD + ACD
BC = B//C
BD = B//D
BCD = B//(C*D//gcd(C,D))
ans2 = B - BC - BD +BCD
print(ans2-ans1)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		sc.close();
		int p = b - a;
		int ans = 0;
		for(int i = 1; i <= p; ++i) 
			ans += i;
		ans -= b;
		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll x,y; cin>>x>>y;

  ll ans = inf;

  if (x <= y) ans = min(ans, y-x);
  if (x <= -y) ans = min(ans, -y-x+1);
  if (-x <= y) ans = min(ans, y+x+1);
  if (-x <= -y) ans = min(ans, -y+x+2);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#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>;

// 文字列に必要な区切り数を計算
ll getCount(const string &t) {
  vector<ll> continuousCountList;
  ll continuousCount = 1; // 連続している数
  char tmp = t[0];
  for (ll i = 1; i < t.size(); ++i) {
    if (t[i] == tmp) {
      continuousCount++;
    } else {
      if (continuousCount > 1) {
        continuousCountList.push_back(continuousCount);
      }
      tmp = t[i];
      continuousCount = 1;
    }
  }
  if (continuousCount > 0) {
    continuousCountList.push_back(continuousCount);
  }
  ll res = 0;
  for (int v : continuousCountList) {
    res += floor(v / 2);
  }
  return res;
}

int main() {
  string s;
  ll k;
  cin >> s >> k;
  // 通常
  ll one = getCount(s);
  ll two = getCount(s + s);
  ll diff = two - one * 2;
  // 文字が同じ
  bool same = true;
  for (int i = 0; i < s.size() - 1; ++i) {
    if (s[i] != s[i + 1]) {
      same = false;
      break;
    }
  }
  ll res;
  if (same) {
    // 全部同じ文字の時は特殊
    res = k * s.size() / 2;
  } else {
    res = one * k + (diff * (k - 1));
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <deque>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/

#define mod 1000000007

int main()
{
	int n;
	
	scanf("%d", &n);
	long long t = 1;
	for (int i = 1; i <= n; i++){
		t = t * i % mod;
	}
	printf("%I64d\n", t);
}


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

using namespace std;

vector<pair<long long, long long> > prime_factorize(long long N){
    vector<pair<long long, long long> > res;
    for(long long a = 2; a*a <= N; ++a){
        if(N % a != 0)continue;
        long long ex = 0; //指数

        // 割れる限り続ける
        while( N%a == 0){
            ++ex;
            N /= a;
        }

        res.push_back( {a, ex} );
    }

    // 最後に残った数について
    if(N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    long long N;
    cin >> N;
    const auto &res = prime_factorize(N);
    cout << N << ":";
    for(auto p: res){
        for(long long i=0; i<p.second; ++i){
            cout << " " << p.first;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;


int main(){
  int N;
  while(cin >> N){
    vector<int> A(N); cin >> A;

    bool no = false;
    LLI ans = 0;

    if(A[0] != 0){
      no = true;
    }else{
      FOR(i,1,N){
        if(A[i-1]+1 < A[i]){
          no = true;
          break;
        }else{
          if(A[i-1] >= A[i]){
            ans += A[i-1];
          }
        }
      }

      ans += A[N-1];
    }

    if(no){
      cout << -1 << endl;
    }else{
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
N, K = map(int, input().split())
print(len(Base_10_to_n(N, K)))

Measured memory_bytes: 2940
//TripleDots.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt();
        String s=sc.next();
        
        if(s.length()<=k){
            System.out.println(s);
        }
        else{
            String ans=s.substring(0,k);
            System.out.println(ans+"...");
        }		
        sc.close();
    }
}

Measured memory_bytes: 38604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    /*int a, b; cin >> a >> b;
    if (a < 10 && b < 10) cout << a * b << endl;
    else cout << -1 << endl;
    */

    int n; cin >> n;
    rep(i, 10) rep(j, 10) {
        if (n == i * j) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>

using namespace std;

int main (){
	int n,k;
	string s;
	cin >> n >> s >> k;
	
	char target = s[k-1];
	int i;
	
	for(i=0; i<s.length(); i++) {
		if(s[i] != target) s[i] = '*';
	}
	
	cout << s << endl;
	
	return 0; 
} 

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

int main() {
	int n,ans=0;
    vector <int>a(n),b(n),c(n-1);
	cin >> n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        ans+=b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]-a[i-1]==1){
            ans+=c[a[i-1]-1];
        }
    }
	
	cout << ans<< endl;

}

Measured memory_bytes: 640
# from math import gcd
from fractions import gcd
from functools import reduce

def lcm_list(numbers):
    return reduce(lambda x, y: (x * y) // gcd(x, y), numbers, 1)

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    lcm = lcm_list(a)
    aa = []
    for i in range(len(a)):
        aa.append(lcm // a[i])
    ans = sum(aa) % 1000000007
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

int main(void) {
    int n, k;
    int ans = 0;
    cin >> n >> k;
    vector<int> have(n + 1, 0);
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            have[a] = 1;
        }
    }

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

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static long rec(long N , long A , long B , long C , long D , Map<Long, Long> memo){
		if(memo.containsKey(N)){
			return memo.get(N);
		}
		if(N == 0){
			return 0;
		}
		if(N == 1){
			return D;
		}
		long r5 = N / 5;
		long diff = N - r5 * 5;
		long ret = rec(r5 , A , B , C , D , memo) + D * diff + C;
		if(diff != 0){
			diff = (r5 + 1) * 5 - N;
			ret = Math.min(rec(r5 + 1 , A , B , C , D , memo) + D * diff + C , ret);
		}
		long r3 = N / 3;
		diff = N - r3 * 3;
		ret = Math.min(ret, rec(r3 , A , B , C , D , memo) + D * diff + B);
		if(diff != 0){
			diff = (r3 + 1) * 3 - N;
			ret = Math.min(ret, rec(r3 + 1 , A , B , C , D , memo) + D * diff + B);
		}
		long r2 = N / 2;
		diff = N - r2 * 2;
		ret = Math.min(ret, rec(r2 , A , B , C , D , memo) + D * diff + A);
		if(diff != 0){
			diff = (r2 + 1) * 2 - N;
			ret = Math.min(ret, rec(r2 + 1 , A , B , C , D , memo) + D * diff + A);
		}
		if(N < ret / D){
			ret = Math.min(ret, N * D);			
		}
		memo.put(N, ret);
		return ret;
	}
	static long solve(long N , long A , long B , long C , long D){
		Map<Long, Long> memo = new HashMap<Long, Long>();		
		return rec(N , A , B , C , D , memo);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int cn = 1 ; cn <= T ; ++cn){
			long N = sc.nextLong();
			long A = sc.nextLong();
			long B = sc.nextLong();
			long C = sc.nextLong();
			long D = sc.nextLong();
			long ret = solve(N , A , B , C , D);
			System.out.println(ret);
		}
	}
}


Measured memory_bytes: 57260
# input V, E
v, e = map(int, input().split())


# input weighted edges into priority queue
import heapq
h = []
for i in range(e):
	s, t, w = map(int, input().split())
	heapq.heappush(h, (w, s, t))


# initialize union find tree for vertices
p = [i for i in range(v)]
rank = [0 for i in range(v)]

def union(x, y):
 link(findSet(x), findSet(y))

def link(x, y):
 if rank[x] > rank[y]:
  p[y] = x
 else:
  p[x] = y
  if rank[x] == rank[y]:
   rank[y] = rank[y] + 1

def findSet(x):
 if x != p[x]:
  p[x] = findSet(p[x])
 return p[x]


def unite(x, y):
 union(x, y)

def same(x, y):
 x = findSet(x)
 y = findSet(y)
 if x == y:
  return True
 else :
  return False


# search MST
s = 0
for i in range(e):
	edge = heapq.heappop(h)
	if same(edge[1], edge[2]) == False:
		s = s + edge[0]
		unite(edge[1], edge[2])

# print sum of weights
print(s)


Measured memory_bytes: 23340
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long int ll;
typedef unsigned long long int ull;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t="No";
  cin >>s;
  if(s[3]==s[2]&&s[5]==s[4]) t="Yes";
  cout <<t;
}

Measured memory_bytes: 3596
S = str(input())
s1,s2 = int(S[:2]),int(S[2:])
c1,c2 = 0,0

if 0 < s1 < 13:
  c1 = 1
if 0 < s2 < 13:
  c2 = 1

if c1 and c2:
  ans = "AMBIGUOUS"
elif c1:
  ans = "MMYY"
elif c2:
  ans = "YYMM"
else:
  ans = "NA"
print(ans)

Measured memory_bytes: 3064
from collections import deque
s = input()
t = input()
ans = 'UNRESTORABLE'

def match_str(s, t):
    for i, c in enumerate(s):
        if t[i] != c and c != '?':
            return False
    return True

t_len = len(t)
end = len(s) - len(t) +1

# コーナーケース大丈夫？
for i in reversed(range(end)):
#     print(i, s[i : i+t_len])
    if match_str(s[i : i+t_len], t):
        ans = s[:i].replace('?', 'a') + t +s[i+t_len:].replace('?', 'a')
        break
        
print(ans)

Measured memory_bytes: 3316