akhauriyash/Code-Regression huggingface dataset:
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *NOIP 2019 RP++                                      *
 ***********************************************************/
#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
    char *p = (char*)malloc(size) + size;  \
    __asm__("movl %0, %%esp\n" :: "r"(p))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) ((x>y)?x:y)
#define Min(x,y) ((x<y)?x:y)
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (int)(1<<30)
#define mod (int)(19260817)
#define FOR(a,b,c) for (register int a=b;a<=c;a++)
#define FORD(a,b,c) for (register int a=b;a>=c;a--)
using namespace std;
//char buf[1<<20],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline int read(){
    int x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}
template<typename T>
inline void write(T a){
    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
int n,k,tot;
ll a[120],ans,b[120],num;
signed main(){
    n=read(),k=read();
    FOR(i,1,n)a[i]=read();
    FOR(i,0,n)
    	FOR(j,i+1,n+1)if(i+n-j+1<=k){
    		tot=0;num=0;
    		FOR(l,1,i)b[++tot]=a[l],num+=a[l];//,writeln(l,a[l]);
    		FOR(l,j,n)b[++tot]=a[l],num+=a[l];//,writeln(l,a[l]);
    		sort(b+1,b+1+tot);
//    		write_(i,j);cout<<" : ";FOR(l,1,tot)write_(b[l]);puts("");
    		FOR(l,1,Min(k-(i+n-j+1),tot))if(b[l]<0)num-=b[l];else break;
    		ans=Max(ans,num);
    	}
    writeln(ans);
    return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        Console.WriteLine(getDiv(n));
    }
    static long getDiv(long n)
    {
        var ans = 0L;
        for (long i = 2; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                if ((n / (i - 1) == n % (i - 1))) ans += i - 1;
                if (n / i != i)
                    if ((n / (n / i - 1) == n % (n / i - 1))) ans += n / i - 1;
            }
        }
        if (n != 1)
            if ((n / (n - 1) == n % (n - 1))) ans += n - 1;
        return ans;
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

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

struct edge{int to,cost;};
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;

	ll t=0,a=0,tt,ta,m;
	cin >> t >> a;
	for(int i=1;i<n;i++){

//		cout << i << "--------\n";

		cin >> tt >> ta;

//		printf("t:%d a:%d\ttt:%d ta:%d\n",t,a,tt,ta);

		if(t>tt || a>ta){
			m =	max((t+(tt-1))/tt,(a+(ta-1))/ta);
			tt*=m; ta*=m;
		}
		t=tt; a=ta;
	}
	cout << t+a << "\n";
	
	return 0;
}

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

int main() {
  int P[200000];
  int N;
  int count=0;
  int min=2147483647;

  cin >> N;
  for(int i=0; i<N; i++) {
    cin >> P[i];
    if(P[i] < min) {
      min=P[i];
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

const int maxn = 1000005, P = 998244353;
int n, m, fac[maxn], ifac[maxn];

int power(int a, int x)
{
	int ans = 1;
	for (; x; x >>= 1, a = 1LL * a * a % P)
		if (x & 1)
			ans = 1LL * ans * a % P;
	return ans;
}
int binom(int n, int m)
{
	if (n < m || m < 0)
		return 0;
	return 1LL * fac[n] * ifac[m] % P * ifac[n - m] % P;
}

int main()
{
	scanf("%d%d", &n, &m);
	if (n < m)
		std::swap(n, m);
	fac[0] = 1;
	for (int i = 1; i <= n + m; ++i)
		fac[i] = 1LL * fac[i - 1] * i % P;
	ifac[n + m] = power(fac[n + m], P - 2);
	for (int i = n + m; i; --i)
		ifac[i - 1] = 1LL * ifac[i] * i % P;
	int ans = 0;
	for (int i = 1; i <= m; ++i)
		ans = (ans + 1LL * binom(2 * i, i) * binom(n + m - 2 * i, n - i)) % P;
	ans = 1LL * ans * power(2 * binom(n + m, n) % P, P - 2) % P;
	ans = (ans + n) % P;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    REP(i, n)
    {
        int a;
        cin >> a;
        v.push_back(make_pair(a, i + 1));
    }
    sort(v.begin(), v.end());
    REP(i, n)
    {
        pair<int, int> pr;
        pr = v[i];
        if (i == 0)
            cout << pr.second;
        else
        {
            cout << " " << pr.second;
        }
    }
    cout << endl;
}

Measured memory_bytes: 1780
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val a = sc.intList()
        var ans = Long.MAX_VALUE
        for (target in -100..100) {
            var s = 0L
            for (i in 0 until n) {
                s += (a[i] - target) * (a[i] - target)
            }
            ans = Math.min(ans, s)
        }

        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 38024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll INF = 1e18;

ll dp[10005];

int main(){
  int H, N;
  cin >> H >> N;
  vector<pair<int,int>> v;
  rep(i,N){
    int a, b;
    cin >> a >> b;
    v.emplace_back(a,b);
  }

  rep(i,H+1){
    dp[i] = INF;
  }
  dp[0] = 0;
  rep(i,H+1){
    rep(j,N){
      int nxt = i+v[j].first;
      if(nxt >= H) nxt = H;
      dp[nxt] = min(dp[nxt], dp[i] + v[j].second);
    }
  }

  cout << dp[H] << endl;
  
  return 0;
}



Measured memory_bytes: 384
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
from decimal import *
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.readline())
def FI(): return float(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
D = defaultdict(lambda:defaultdict(int))
for j in range(n):
    a = input()
    r = len(a) - a.find(".") - 1 if "." in a else 0
    a = a.replace(".", "")
    a = int(a) * 10 ** (9 - r)
    cnt1 = 0
    cnt2 = 0
    while a % 2 == 0:
        a //= 2
        cnt1 += 1
    while a % 5 == 0:
        a //= 5
        cnt2 += 1
    D[cnt1][cnt2] += 1

ans = 0
for i in range(50):
    for j in range(25):
        for k in range(50):
            for l in range(25):
                if min(i + k, j + l) >= 18:
                    if i == k and j == l:
                        ans += D[i][j] * (D[k][l] - 1)
                    else:
                        ans += D[i][j] * D[k][l]


print(ans // 2)


Measured memory_bytes: 86276
#include <stdio.h>

int n,A[1000000];

int search(int k){
    int left=0,right=n,mid;
    while(left<right){
        mid=(left+right)/2;
        if(A[mid]==k){
            return 1;
        }
        else if(k<A[mid]){
            right=mid;
        }
        else{
            left=mid+1;
        }
    }
    return 0;
}

int main(){
    int i,q,k,sum=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&k);
        if(search(k)){
            sum+=1;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int x,t;
cin >> x >> t;
if(t<=x) {
  cout << x-t << endl;
} else {
  cout <<"0" <<endl;
}
return 0;
}


Measured memory_bytes: 256
line = gets
line.chomp!
n = line.to_i

city=[]
for cnt in 1..5 do
  line = gets
  line.chomp!
  city.push(line.to_i)
end

cnt=[]

cnt.push(n/city[0])
if n%city[0] > 0
  cnt[0] += 1
end

min=city[0]
for i in 1..4 do
  if (city[i] < min)
    min = city[i]
  end
  if city[i-1] <= city[i]
    cnt.push(cnt[i-1]+1)
  else
    cnt.push(n/min)
    if (n%min > 0)
      cnt[i] += 1
    end
    cnt[i] += i
  end
end

print cnt[4]


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

int main(){
   int N;
  cin>>N;
  vector<int>vec(101);
  for(int i=0;i<N;i++){
     int d;
     cin>>d;
     vec.at(d)=1;
  }
  int step=0;
  for(int j=0;j<101;j++){
     step +=vec.at(j);
  }
  cout<<step;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	bool a[1000000]={false};
	for(int i=2;i<1000;i++){
		bool t=false;
		for(int j=2;j*j<=i;j++){
			if(i%j==0)
				t=true;
		}
		if(i==2)
			t=false;
		if(t==false){
			for(int j=i*2;j<1000000;j+=i)
			    a[j]=true;
			a[i]=false;
		}
	}
	while(cin>>n){
		int count=0;
		for(int i=0;i<=n;i++){
			if(a[i]==false)
				count++;
		}
		cout<<count-2<<endl;
	}
	return 0;
}

Measured memory_bytes: 2144
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum_B = sum(B)
sum_C = 0
for i in range(n-1):
  if A[i] + 1 == A[i+1]:
    sum_C += C[A[i]-1]
    
ans = sum_B + sum_C
print(ans)

  

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int a,b;
    cin >> a >> b;
    int ans=max(0,a-2*b);

    cout << ans <<"\n";

    return 0;
}

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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PRINTIA(a,n) REP(i,n){printf("%d ", *((a)+i));}putchar('\n');
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
void PI() {putchar('\n');}
template<typename... T>
void PI(const int head, T... tail ) {
    printf("%d ", head);
    PI(tail...);
}

#define MAX_N 100005

int main()
{
    LL N, A, B;
    scanf("%lld%lld%lld", &N, &A, &B);
    LL m = A*(N-1) + B;
    LL M = B*(N-1) + A;
    printf("%lld\n", max(0LL, M - m + 1));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll    long long int
#define ld    long double
#define pb    push_back
#define mp    make_pair
#define Maxn  1000007
#define ff    first
#define se    second
using namespace std;

int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	ll mi=min(n*a,b);
	cout<<mi;
}


Measured memory_bytes: 256
function main()
  local n = tonumber(io.read())
  local s = io.read()

  local animals = {{true, true}, {true, false}, {false, true}, {false, false}}
  for i = 1, #animals do
    for j = 3, n do
      if animals[i][j-1] == (string.sub(s, j-1, j-1) == "o") then
        animals[i][j] = animals[i][j-2]
      else
        animals[i][j] = not animals[i][j-2]
      end
    end
    if
      (animals[i][n] == (string.sub(s, n, n) == "o")) == (animals[i][n-1] == animals[i][1])
      and (animals[i][1] == (string.sub(s, 1, 1) == "o")) == (animals[i][n] == animals[i][2])
    then
      local str = ""
      for j = 1, n do
        if animals[i][j] then
          str = str .. "S"
        else
          str = str .. "W"
        end
      end
      print(str)
      return 0
    end
  end

  print(-1)
end

main()


Measured memory_bytes: 13352
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abs(x) ((x) < 0 ? (-(x)) : (x))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
#define PI 3.14159265

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
long double eps = 1.0E-14;
long long MOD = 1000000007;

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t,T;
	cin >> T;	
    string str;
    cin >> str;
	if (str.size() <= T) {
        cout << str << endl;
        return 0;
    } 
    cout << str.substr(0, T) + "..." << endl;
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

const int mod = 1e9+7;

vector<ll> Perm(200010);
vector<ll> ifac(200010);

ll mpow(ll x,ll n){
    ll ret = 1;
    while(n != 0){
        if(n&1) ret = ret * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ret;
}

int main(){
    ll n,a,b;
    cin >> n >> a >> b;

    Perm[0] = 1;
    ifac[0] = 1;
    rep(i,200001){
        Perm[i+1] = Perm[i] * (n-i) % mod;  
        ifac[i+1] = ifac[i] * mpow(i+1,mod-2) % mod;
    }

    ll ans = mpow(2,n);
    ans = (ans+mod-1) % mod;
    
    ll nCa,nCb;
    nCa = Perm[a] * ifac[a] % mod;
    nCb = Perm[b] * ifac[b] % mod;
    ans = (ans + mod - nCa) % mod;
    ans = (ans + mod - nCb) % mod;

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

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

using namespace std;

int main() {
    const int MAX = 123456 * 2 + 1;
    vector<bool> isPrime(MAX, true);
    isPrime[0] = isPrime[1] = false;

    for (int i = 2; i * i <= MAX; ++i) {
        if (isPrime[i]) {
            for (int j = i * 2; j < MAX; j += i)
                isPrime[j] = false;
        }
    }

    int n;
    for (;;) {
        cin >> n;
        if (n == 0) break;

        int ans = 0;
        for (int i = n + 1; i <= 2 * n; i++)
            if (isPrime[i]) ans++;

        cout << ans << endl;
    }
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int n,d;
const int INF=1000000000;
int main(){

	while(cin>>n>>d&&(n|d)){
		vector<stack<int> > vsi;
		vector<int> sums;
		int minSum=INF;
		int maxSum=-1;
		for(int i=0;i<n;i++){
			int m;
			cin>>m;
			stack<int> s;
			int sum=0;
			for(int j=0;j<m;j++){
				int a;
				cin>>a;
				sum+=a;
				s.push(a);
			}
			vsi.push_back(s);
			sums.push_back(sum);
			minSum=min(minSum,sum);
			maxSum=max(maxSum,sum);
		}
		while(1){
			// ðð½³È¢
			if(maxSum-(minSum)>d){
				cout<<"No"<<endl;
				break;
			}
			bool fin=true;
			for(int i=0;i<n;i++){
				if(vsi[i].empty())continue;
				else fin=false;
			}
			if(fin){
				cout<<"Yes"<<endl;
				break;
			}
			bool ok=false;
			for(int i=0;i<n;i++){
				if(vsi[i].empty())continue;
				int a=vsi[i].top();
				// Å¬lðÏ¦È¢ÈçAÌðµÄbreak
				if(sums[i]-a>=minSum){
					vsi[i].pop();
					sums[i]-=a;
					ok=true;
					break;
				}
			}
			// Å¬lðÏ»³¹È¢àÌðæè¢½
			if(ok){
				// ÅålðXV
				maxSum=-1;
				for(int i=0;i<n;i++)maxSum=max(sums[i],maxSum);
				minSum=INF;
				for(int i=0;i<n;i++)minSum=min(sums[i],minSum);
				continue;
			}
			int idx=-1;
			int num=-1;
			int band=INF;
			// æè¯éàÌÌ¤¿AÅ¬lÆÅålÌðÅà¬³­·éàÌðÌð
			for(int i=0;i<n;i++){
				if(vsi[i].empty())continue;
				int tmpMax=-1;
				int tmpMin=INF;
				int a=vsi[i].top();
				vsi[i].pop();
				sums[i]-=a;
				for(int j=0;j<n;j++){
					tmpMax=max(tmpMax,sums[j]);
					tmpMin=min(tmpMin,sums[j]);
				}
				sums[i]+=a;
				vsi[i].push(a);
				// àµÅålÆÅ¬lÌª¬³¯êÎ
				if(band>tmpMax-tmpMin){
					idx=i;
					band=tmpMax-tmpMin;
					num=vsi[i].top();
				}
			}
			sums[idx]-=num;
			vsi[idx].pop();
			maxSum=-1;
			for(int i=0;i<n;i++)maxSum=max(sums[i],maxSum);
			minSum=INF;
			for(int i=0;i<n;i++)minSum=min(sums[i],minSum);
		}
	}

	return 0;
}

Measured memory_bytes: 976
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new  BufferedReader(new InputStreamReader(System.in));
		String[] str = buf.readLine().split(" ");
		int r = Integer.parseInt(str[0]);
		int c = Integer.parseInt(str[1]);
		int[][] array = new int[r+1][c+1];
		
		for(int i=0; i<r; i++){
			str = buf.readLine().split(" ");
			for(int j=0; j<c; j++){
				array[i][j] = Integer.parseInt(str[j]);
			}
		}
		for(int i=0; i<r; i++){
			for(int j=0; j<c; j++){
				array[i][c] += array[i][j];
			}
		}
		for(int j=0; j<=c; j++){
			for(int i=0; i<r; i++){
				array[r][j] += array[i][j];
			}
		}
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c+1; j++){
				System.out.print(array[i][j]);
				if(j!=c)
					System.out.print(" ");
			}
			System.out.println();
		}		
	}
}

Measured memory_bytes: 30628
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
  long long x;
  long long y;

  cin >> x >> y;

  int counter = 1;
  long long tmp = x;

  while(1){
    tmp = tmp * 2;
    if(tmp > y) break;
    else counter ++;
  }

  cout << counter << endl;

  return 0;
}

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

number = int(input())
count = 0

if number < 10:
  count = number
elif 10 <= number < 100:
  count = 9
elif 100 <= number < 1000:
  count += 9
  count += number - 99
elif 1000 <= number < 10000:
  count += 909
elif 10000 <= number < 100000:
  count += 909
  count += number - 9999
elif 100000 <= number :
  count += 90909
  
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    }
    ll now = 0;
    ll cnt = 0;
    for (ll i = 0; i < n + 5; i++) {
        now = a[now];
        cnt++;
        if (now == 1) {
            cout << cnt << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i,n) for (int i=0; i< (n); ++i)
typedef pair<int, int> P;

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

int f(int x) {
  int res = 0;
  while (x%2 == 0) {
    x /= 2;
    res++;
  }
  return res;
}
      
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep (i, n) {
    cin >> a[i];
  }
  // a -> a'
  rep(i,n) {
    if (a[i] % 2 == 1) {
      cout << 0 << endl;
      return 0;
    }
    a[i] /= 2;
  }

  int t = f(a[0]);
  rep(i,n) {
    if (f(a[i]) != t) {
      cout << 0 << endl;
      return 0;
    }
    a[i] >>= t; // a[i] /= 2^t
  }
  m >>= t;

  ll l = 1;
  rep(i,n) {
    l = lcm(l, a[i]);
    if (l>m) {
      cout << 0 << endl;
      return 0;
    }
  }

  m /= l;
  int ans = (m+1)/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num=0, m=0, d=0;
		String[] day = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
		int[] n = {0,31,29,31,30,31,30,31,31,30,31,30};
		while(true){
		    m = s.nextInt();
		    if(m==0)break;
		    d = s.nextInt();
		    num = 0;
		    for(int i=0 ; i<m ; i++)
			num += n[i];
		    num += d;
		    System.out.println(day[num%7]);
		}
	}
}

Measured memory_bytes: 12000
n = int(input())
s = input()

ans = [0]*n
ans[0] = s[1:].count("E")

for i in range(1,n):
    ans[i]=ans[i-1]
    if s[i-1]=="W":
        ans[i] += 1
    if s[i]=="E":
        ans[i] -= 1

print(min(ans))

Measured memory_bytes: 15436
//https://atcoder.jp/contests/keyence2019/tasks/keyence2019_b
//B - KEYENCE String
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main(){
    string S; cin>>S;
    bool ans=false;
    string bs="keyence";
    auto difs=S.size()-bs.size();
    FOR(i,0,S.size()){
        if(difs<0)break;
        if(i+difs>S.size())break;
        string tmp=S;
        tmp.erase(i,difs);
        if(tmp==bs) {
            ans=true;
            break;
        }
    }
    cout<<(ans?"YES":"NO")<<endl;
    return 0;
}
int main_() {
#if LOCAL&01
    std::ifstream in("./test/sample-4.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    string S; cin>>S;
    auto check_func=[&](const string& h,const string& f){
        auto r1=S.find(h,0);
        if (r1==string::npos) return false;
        auto r2=S.find(f,r1+h.size());
        if (r2==string::npos) return false;
        return true;
    };
    bool ans=false;
    string bs="keyence";
    FOR(i,1,bs.size()){
        string h,f;
        h.append(bs,0,i);
        f.append(bs,i,bs.size()-i);
        dump(i,h,f);
        ans|=check_func(h,f);
        if(ans)break;
    }

    cout<<(ans?"YES":"NO")<<endl;    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
#define MOD 1000000007

void Main(){
  string s;
  cin>>s;
  rep(i,s.length()){
    cout<<'x';
  }

} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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


using namespace std;

int main(void){
    int r, d, x2000;

    cin >> r >> d >> x2000;

    int x = r * x2000 - d;
    for(int i = 0; i < 10; i++){
        cout << x << endl;
        x = r * x - d;
    }
    
    return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;

	if(p==5||p==2) {

		long long ans = 0;
		for(int i = 0; i < n; i++) {
			if((s[i]-'0')%p==0) ans+=(i+1);
		}
		cout << ans;
		exit(0);
	}

	int pw = 1;

	vector<long long> hs(n);

	for(int i = n-1; i >= 0; i--) {
		hs[i] = ((s[i] - '0') * pw) % p;
		if(i != n - 1) hs[i] = (hs[i] + hs[i+1]) % p;
		pw = (pw * 10) % p;
	}

	map<int,int> mp;

	long long ans = 0;

	for(int i = n - 1; i >= 0; i--) {
		if(hs[i] == 0) ans++;
		ans += mp[hs[i]];
		mp[hs[i]]++;
	}

	cout << ans;
	

	return 0;
}


Measured memory_bytes: 2452
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define cyes cout<<"Yes"<<endl;
#define cno cout<<"No"<<endl;
#define gcd __gcd
using namespace std;

signed main() {
  int a,b,c;
  cin>>a>>b>>c;
  cout<<a*b/2<<endl;
}

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

long long solve(long long a,long long b)
{
    if(a==0)
        return 0;
    long long res=a*(b/a)*2;
    if(b%a==0)
    {
        res-=a;
        return res;
    }
    return res+solve(b%a,a);
}

int main()
{
    long long N,X;
    scanf("%lld%lld",&N,&X);
    long long ans=N+solve(min(X,N-X),max(X,N-X));
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int MAX_N = 200000;

int par[MAX_N];
int rank_uf[MAX_N];

//init(要素数)でUnion-Find木を初期化
void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank_uf[i] = 0;
    }
}

//Union-Find木運用に使うので、自分では使わない
int find(int x) {
    if(par[x] == x) {
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

//グループの合成
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank_uf[x] < rank_uf[y]) {
        par[x] = y;
    }else{
        par[y] = x;
        if(rank_uf[x] == rank_uf[y]) rank_uf[x]++;
    }
}

//同一グループか判定
bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    cin>>N;
    init(N);
    cin>>M;
    int x,y,z;
    int ans = N;
    rep(i,M){
        cin>>x>>y>>z;
        if(!same(x-1,y-1)) ans--;
        unite(x-1,y-1);
    }
    /*vector<bool> know(N,false);
    rep(i,N){
        if(know.at(i)) continue;
        ans++;
        know.at(i) = true;
        reps(j,i,N){
            if(same(i,j)) know.at(j) = true;
        }
    }*/
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;


int main()
{
	LL K;
	scanf("%lld", &K);

	if (!K)
	{
		printf("2\n1 1\n");
		return 0;
	}

	if (K == 1)
	{
		printf("2\n2 0\n");
		return 0;
	}

	int N;

	if (K > 50)
		N = 50;
	else
		N = max(K, 2LL);
	
	LL mx = max(N - 1 + K / N, (LL)N);
	
	printf("%d\n", N);
	// dodaj na poczatku pewna wartosc
	int md = K%N;
	REP(i, N)
	{
		int add = md > 0 ? 1 : 0;
		printf("%lld ", mx+add);
		md--;
		mx--;
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.141592653589793238462643387
#define mo 924844033ll
#define ll long long
#define N 600010
#define int long long
using namespace std;
ll n,vv=1,rev[N],len,x,y;
ll f[N],g[N],h[N],ec,v[N],nxt[N],sz[N],c[N],jc[N],ij[N];
void add(int x,int y){v[++ec]=y;nxt[ec]=h[x];h[x]=ec;}
ll qp(ll x,ll y){
    if(!y)return 1;
    if(y==1)return x%mo;
    ll r=qp(x,y/2);
    if(y&1)return r*r%mo*x%mo;
    return r*r%mo;
}
void fft(ll *a,ll t){
    for(ll i=0;i<vv;i++)
		if(i<rev[i])
			swap(a[i],a[rev[i]]);
    for(ll i=1;i<vv;i*=2){
        ll w;
        if(t==1)w=qp(5,(mo-1)/(i*2));
        else w=qp(554906420,(mo-1)/(i*2));
        for(ll r=i*2,j=0;j<vv;j+=r){
            ll tp=1;
            for(ll k=0;k<i;k++,tp=(tp*w)%mo){
                ll tx=a[j+k],ty=(a[j+i+k]*tp)%mo;
                a[j+k]=(tx+ty)%mo;
				a[j+i+k]=(tx-ty+mo)%mo;
            }
        }
    }
    if(t==1)return;
    ll iv=qp(vv,mo-2);
    for(int i=0;i<vv;i++)
    	a[i]=a[i]*iv%mo;
}
void dfs(int x,int fa){
	sz[x]=1;
	for(int i=h[x];i;i=nxt[i])
		if(v[i]!=fa){
			dfs(v[i],x);
			sz[x]+=sz[v[i]];
			c[sz[v[i]]]++;
		}
	c[n-sz[x]]++;
}
void init(){
	jc[0]=1;
	for(int i=1;i<N;i++)
		jc[i]=jc[i-1]*i%mo;
	ij[N-1]=qp(jc[N-1],mo-2);
	for(int i=N-1;i;i--)
		ij[i-1]=ij[i]*i%mo;
}
int cc(int x,int y){
	return jc[x]*ij[y]%mo*ij[x-y]%mo;
}
signed main(){
    cin>>n;
    for(int i=1;i<n;i++){
    	int a,b;
    	cin>>a>>b;
    	add(a,b);
    	add(b,a);
	}
	dfs(1,0);
	init();
	for(int i=1;i<=n;i++)
		f[i]=c[i]*jc[i]%mo;
	reverse(f,f+n+1);
	for(int i=0;i<=n;i++)
		g[i]=ij[i];
	vv=1;
	int len=0;
	while(vv<=2*n)vv*=2,len++;
    for(ll i=0;i<vv;i++)
        rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
   	fft(f,1);
    fft(g,1);
	for(int i=0;i<vv;i++)
		f[i]=f[i]*g[i]%mo;
	fft(f,-1);
	reverse(f,f+n+1);
	for(int i=1;i<=n;i++)
		cout<<(n*cc(n,i)%mo-ij[i]*f[i]%mo+mo)%mo<<'\n';
}

Measured memory_bytes: 49664
#include <stdio.h>

/*#define d*/

int main()
{
        unsigned long long S=0;
        unsigned long long c=0;
        unsigned long long numOfScc=0;

        scanf("%llu %llu", &S, &c);

        while(1)
        {
#ifdef d
                printf("%llu %llu %llu\n", S, c, numOfScc);
#endif

                if(S*2>c)
                {
                        numOfScc=numOfScc+(c/2);
                        c=0;
                        break;
                }
                else if(S*2==c)
                {
                        numOfScc=numOfScc+S;
                        S=0;
                        break;
                }
                else
                {
                        numOfScc=numOfScc+S;
                        c=c-2*S;
                        S=c/2/2;
                        c=c/2;
                }
        }

        printf("%llu\n", numOfScc);

        return 0;
}

Measured memory_bytes: 128
using System;

class AtCoder
{
    static void Main()
    {
        string[] s;       
        s = NextS();
        int n = int.Parse(s[0]);
        int m = int.Parse(s[1]);

        int[] a = new int[n];
        s = NextS();
        for(int i=0; i<n; i++) a[i] = int.Parse(s[i]);
        Array.Sort(a);

        int[] b = new int[m];
        s = NextS();
        for (int i = 0; i < m; i++) b[i] = int.Parse(s[i]);
        Array.Sort(b);

        int p = 1000000000 + 7;
        long ans = 1; long t;
        int x = n - 1; int y = m - 1;
        int c = n * m; int d = 0;
        int u = 0; int v = 0; bool f, g;
        for (int i = n * m; i > 0; i--)
        {
            f = false; g = false;
            if (x > -1 && a[x] == c)
            {
                x--; u++; f = true;
            }
            if (y > -1 && b[y] == c)
            {
                y--; v++; g = true;
            }
            if (f)
            {
                if (!g)
                {
                    ans *= v;
                    if (v == 0) break;
                    else ans %= p;
                }
            }
            else
            {
                if (g)
                {
                    ans *= u;
                    if (u == 0) break;
                    else ans %= p;
                }
                else
                {
                    t = u * v - d;
                    if (t < 1)
                    {
                        ans = 0; break;
                    }
                    else
                    {
                        ans = ans * t % p;
                    }
                }
            }
            c--;  d++;
        }
        Console.WriteLine(ans);

    }

    static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
    static string[] NextS() { return Console.ReadLine().Trim().Split(' '); }
}

Measured memory_bytes: 13268
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
import sys
sys.setrecursionlimit(10**9)

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

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    A, B = l_inpl()
    ans = 0
    cnt = 1
    while True:
        if cnt >= B:
            break
        cnt -= 1
        cnt += A
        ans += 1
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

char s[99];
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	int flag=1;
	if(s[0]!='A')flag=0;
	int cnt=0;
	rep(i,2,n-1)if(s[i]=='C')cnt++;
	if(cnt!=1)flag=0;
	rep(i,1,n)if(s[i]!='C'&&'A'<=s[i]&&s[i]<='Z')flag=0;
	puts(flag?"AC":"WA");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
using namespace std;
const int N = 5e5+5;
ll n, m, k, x, y, a, b, t, q, ans, sum;
ll mod=1e9+7;
char c;
string s;

vector< ll >v;
ll A[N],B[N];

bool ok;

main()
{
    ios::sync_with_stdio(0);
    cin>>n;
 	cin>>s;
 	
 	ans++;A[s[0]-'a']++;
 	
    for(int i=1;i<n;i++){
       
        A[s[i]-'a']++;
        t=1;
        
       
        for(int j=0;j<26;j++)
        if(j!=s[i]-'a' && A[j]>0)
        t*=(A[j]+1),t%=mod;
        
        //cout<<t<<endl;
        
        ans+=t;
        ans%=mod;
    }
    
    cout<<ans<<endl;
}







Measured memory_bytes: 2512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int S,W;
    cin>>S>>W;
    if(W>=S) p("unsafe");
    else p("safe");
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;

int main(){


	std::string S; std::cin >> S;
	std::reverse(S.begin(), S.end());

	std::array<std::string, 4> arr{"maerd", "remaerd", "esare", "resare"};

	while(S.size() > 0){
		bool flag = false;
		rep(i, 4){
			if(S.substr(0, arr[i].size()) == arr[i]){
				flag = true;
				S.erase(0, arr[i].size());
			}
		}
		if(!flag){
			std::cout << "NO";
			return 0;
		}
	}

	std::cout << "YES";

	
	return 0;
}

Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    r = 0
    for i in range(1,n-1):
        t = sorted(a[i-1:i+2])[1]
        if t == a[i]:
            r += 1

    return r


print(main())



Measured memory_bytes: 5332
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    S = ' ' + S;

    vector<int> index;

    for(int i = 1; i < S.size(); i++){
        if(S[i] != S[i - 1]) index.push_back(i);
    }

    int ans = 0;
    for(int i = 1; i <= index.size(); i++){
        int tmp1 = index[i - 1];
        
        int j = i + 2 * K;
        if(S[tmp1] == '1') j += 1;

        int tmp2;
        if(j > index.size()) tmp2 = N + 1;
        else tmp2 = index[j - 1];
        ans = max(ans, tmp2 - tmp1);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1016
#include<iostream>
#include<cstring>
#include<vector>
#define MOD 1000000007
using namespace std;

int candies(vector<int> &v, int n, int k) {
    long long int dp[n + 2][k + 2]; // Memory
    for(int j = 0; j <= k; j++) dp[1][j] = (j > v[1]) ? 0 : 1; // Base Case
    for(int i = 2; i <= n; i++) {
        for(int j = 0; j <= k; j++) {
            if(j == 0) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = (MOD + dp[i][j - 1] + dp[i - 1][j] - ((j - v[i] - 1 >= 0) ? dp[i - 1][j - v[i] - 1] : 0)) % MOD;
        }
    }
    return dp[n][k];
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n + 1);
    for(int i = 1; i <= n; i++) cin >> v[i];
    cout << candies(v, n, k) << endl;
    return 0;
}

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

int main(){
    int n, i = 0;
    long long r = 1;
    int c[26] = {};
    string s;
    cin >> n >> s;
    for(i=0; i<n; i++){
        c[(int)s[i]-'a']++;
    }
    for(i=0; i<26; i++){
        r *= (long long)c[i] + 1;
        r %= 1000000007;
    }
    cout << r - 1;
    return 0;
}

Measured memory_bytes: 512
n = gets.to_i
s = gets.chomp

n.odd? ? condition = false : condition = true
if n >= 2 && n.even?
  str = s.split("")
  (n / 2).times do |i|
    if str[i] != str[i + (n / 2)]
      condition = false
    end
  end
end

puts condition ? "Yes" : "No"

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
long long dp[210][210];
int n,m,r,R[10];
bool vis[10];
long long ans;
void DFS(long long cnt,int len,int now){
	if(len==r-1){
		ans=min(ans,cnt);
		return;
	}
	for(int i=0;i<r;i++){
		if(vis[i]==false){
			vis[i]=true;
			cnt+=dp[now-1][R[i]-1];
			DFS(cnt,len+1,R[i]);
			cnt-=dp[now-1][R[i]-1];
			vis[i]=false;
		}
	}
	return;
}
int main(){
	cin>>n>>m>>r;
	for(int i=0;i<r;i++)cin>>R[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)dp[i][j]=0;
			else dp[i][j]=1145141919;
		}
	}
	for(int i=0;i<m;i++){
		int a,b,c;cin>>a>>b>>c;a--,b--;
		dp[a][b]=c;
		dp[b][a]=c;
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			if(dp[i][k]==1145141919)continue;
			for(int j=0;j<n;j++){
				if(dp[k][j]==1145141919)continue;
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	ans=114514114514114514;
	for(int i=0;i<r;i++){
		for(int j=0;j<r;j++)vis[j]=false;
		vis[i]=true;
		DFS(0,0,R[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

ll dfs(ll val) {
    if (val == 1) {
        return 1;
    }

    ll cnt = 1;

    cnt += (2 * dfs(val / 2));

    return cnt;
}

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

    cout << dfs(H) << endl;
}


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

int main() {
  char str[1000];
  int len, i;
  int count = 0;
  scanf("%s", str);
  len = strlen(str);
  for (i = 0; i < len / 2; i++) {
    if (str[i] != str[len - i - 1]) { count++; }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
from sys import stdin
n,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
def knapsack(n,w,li):
    #li[i][0]が重さ,li[i][1]が価値
    dp = [[0 for i in range(w+1)]for j in range(n+1)]
    #dp[i][total_w]はi-1回目までの商品を加えた時に重さがtotal_wを超えないような値の最大値
    for i in range(n):
        for total_w in range(w+1):
            if total_w - li[i][0] >= 0:
                dp[i+1][total_w] = max(dp[i][total_w],dp[i][total_w-li[i][0]]+li[i][1])
            else:
                dp[i+1][total_w] = dp[i][total_w]
    return max(dp[-1])
print(knapsack(n,w,li))

Measured memory_bytes: 171528
n = int(input())
a = list(map(int,input().split()))

ans = []
x  = 0
for  i in range(n):
    if i%2 == 0:
        x += a[i]
    else:
        x -= a[i]

ans.append(x)
for i in range(n-1):
    ans.append(2*a[i]-ans[-1])

print(*ans)

Measured memory_bytes: 14092
#include <stdio.h>

int main(void){
    // 宣言
    int n, k;
    int counter = 0;
    int num;

    // 入力
    scanf( "%d %d" ,&n ,&k );
    num = n ;

    // 演算
    while( num >= k ){
        num = num / k ;
        counter++;
    }

    if( num != 0){
        counter++;
    }

    // 出力
    printf( "%d", counter );

    return 0;
}

Measured memory_bytes: 128