akhauriyash/Code-Regression huggingface dataset:
import java.math.BigInteger

fun main() {
    val n = readLine()!!.toLong()
    if (n == 1L) {
        println(1L)
        return
    }
    var f = 1L
    var answer = BigInteger.valueOf(if (n % 2L == 1L) n else (2L * n))
    val factorSet = mutableSetOf<Long>()
    while (f * f <= n) {
        if (n % f == 0L) {
            factorSet.add(f)
            factorSet.add(n / f)
        }
        f++
    }
    val factors = factorSet.toList().sorted()
    fun totient(k: Long): Long {
        var k = k
        var res = 1L
        for (p in factors) {
            if (p != 1L && k % p == 0L) {
                res *= p - 1L
                k /= p
                while (k % p == 0L) {
                    res *= p
                    k /= p
                }
            }
        }
        return res
    }
    fun check(g: Long, h: Long) {
        //println("g = $g, h = $h")
        answer = minOf(answer, BigInteger.valueOf(g) * g.pow(totient(h) - 1L, h))
        //println(answer)
        answer = minOf(answer, BigInteger.valueOf(h) * h.pow(totient(g) - 1L, g))
        //println(answer)
    }
    for (f in factors) {
        if (f != 1L && f != n && f * f <= n && gcd(f, n / f) == 1L) {
            when {
                f % 2L == 0L -> check(2L * f, n / f)
                (n / f) % 2L == 0L -> check(f, 2L * (n / f))
                else -> check(f, n / f)
            }
        }
    }
    println(answer - BigInteger.ONE)
}

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

fun Long.pow(power: Long, mod: Long): BigInteger {
    val mod = BigInteger.valueOf(mod)
    var e = power
    var b = BigInteger.valueOf(this) % mod
    var res = BigInteger.ONE
    while (e > 0) {
        if (e and 1L != 0L) {
            res *= b
            res %= mod
        }
        b *= b
        b %= mod
        e = e shr 1
    }
    return res
}

Measured memory_bytes: 60264
program main
	implicit none
	integer(8):: A,B,H,M,i,j,k
	double precision::kai,pi=dacos(-1d0),t,s
	read *, A,B,H,M	
	s=dble(H)+dble(M)/60d0
	t=(30d0*s-6d0*dble(M))
	kai=sqrt(dble(A*A)+dble(B*B)&
		-2d0*dble(A*B)*dcos(t/180d0*pi))
	
	 print '(f0.14)', kai
end program main

Measured memory_bytes: 3316
N,M = map(int, input().split())
a = [-1]+[int(input()) for _ in range(M)]+[N+1]
mod = 10**9+7
fact = [1]+[0]*N
finv = [1]+[0]*N
for i in range(1,N+1):
    fact[i] = fact[i-1]*i % mod
    finv[i] = pow(fact[i], mod-2, mod)

def cmb(a,b):
    n = max(a,b)
    r = abs(a-b)
    if not n or min(a,b) < 0:
        return 0
    else:
        return fact[n]*finv[n-r]*finv[r] % mod
ans = 1
for i in range(1,M+2):
    if a[i] == 1:
        continue
    elif a[i] == N and a[i-1] == N-1:
        continue
    elif a[i]-a[i-1] == 2:
        continue
    b = a[i]-a[i-1]-2
    ansp = 0
    for j in range(b - (b+1) // 2 + 1):
        ansp = (ansp + cmb(b-j, j)) % mod
    ans = ans * ansp % mod

print(ans)

Measured memory_bytes: 15640
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int X = sc.nextInt();
	int[] x = new int[N+1];
	int[] y = new int[N];
	int min = Integer.MAX_VALUE;
	x[0] = X;
	for(int i = 1; i<N+1; i++) {
	    x[i] = sc.nextInt();
	}
	Arrays.sort(x);
	for(int i = 0; i<N; i++) {
	    y[i]=x[i+1]-x[i];
	    if(min>y[i]) min = y[i];
	}
	//min=4
	int m = min;
	int cnt = 2;
	for(int i = 0; i<N-1; i++) {
	    if(y[i]%m!=0) {
		m = min/cnt;
		if(m<1) break;
		i=0;
		cnt++;
	    }
	}
	System.out.println((m<1)?1:m);


    }
}

Measured memory_bytes: 50264
#include<bits/stdc++.h> 
using namespace std;
int x[5];
int main()
{
    string k;
    int n;cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>k;
        if (k=="AC") x[1]++;
        else if (k=="WA") x[2]++;
        else if (k=="TLE") x[3]++;
        else if (k=="RE") x[4]++;
    }
    cout<<"AC x "<<x[1]<<endl;
    cout<<"WA x "<<x[2]<<endl;
    cout<<"TLE x "<<x[3]<<endl;
    cout<<"RE x "<<x[4]<<endl;
    return 0;
}



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

int main(int argc, const char * argv[]) {
    // insert code here...
    while(1)
    {
        int n;
        scanf("%d",&n);
        
        if(n==0){
            break;
        }
    
        int s[n];
        int sum =0;
        int i;
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum+=s[i];
        }
        
        double m = (double)sum / (double)n;
        
        double alpha = 0;
        for(i=0;i<n;i++){
            alpha+=(s[i]-m)*(s[i]-m);
        }
        
        printf("%f\n",sqrt(alpha/n));
    }
    
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		double[] l = new double[n];
		for (int i = 0; i < n; i++) {
			l[i] = in.nextInt();
		}
		Arrays.sort(l);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				long count = Arrays.binarySearch(l, l[j] + l[i] - 0.1);
				if (count < 0) {
					count = ~count;
				}
				ans += Math.max(count - (j + 1), 0);
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 28020
N = int(input())
count=0
total_count=0

list = list(map(int,input().split()))

for x in list:
    if int(x)%2==0:
        if int(x)%3==0 or int(x)%5==0:
            total_count +=1
    else:
        total_count+=1
    count+=1

if total_count==int(N):
    print('APPROVED')

else:
    print('DENIED')


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{	
    ios::sync_with_stdio(false);
    cin.tie(0);
 
	int n,a[112345],res[112345];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		res[a[i]-1]=i+1;
	}

	for(int i=0;i<n;i++)
		cout<<res[i]<<(i==n-1?"\n":" ");
}




Measured memory_bytes: 1664
def solve():
    N = int(input())
    B = list(map(int , input().split()))
    max_candidate = B[0]
    ret = B[0]
    for i in range(1, N-1):
        if max_candidate < B[i]:
            ret += max_candidate
        else:
            ret += B[i]
        max_candidate = B[i]
        
    ret += max_candidate
    print(ret)
    
solve()

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){

  map<std::string, int> mp{
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1},
    {"SUN", 7}
  };

  string S;
  cin >> S;
  cout << mp[S] << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#define NIL -1

struct node{
	int pa;
	int le;
	int ri;
};

const int maxn=1e7+10;
node nd[maxn];
int D[maxn],H[maxn];
int flag;

void Init(int n){
	for(int i=0;i<n;i++){
		nd[i].pa=nd[i].le=nd[i].ri=NIL;
	}
}

int getHeight(int u)
{
	int h1=0,h2=0;
	if(nd[u].ri!=NIL){
		h1=getHeight(nd[u].ri)+1;
	}	
	if(nd[u].le!=NIL){
		h2=getHeight(nd[u].le)+1;
	}
	return H[u]=(h1>h2?h1:h2);//这里不要用max(h1,h2)，编译错误，不知道为什么 
}

int getRoot(int n)
{
	for(int i=0;i<n;i++){
		if(nd[i].pa==NIL){
			return i;
		}
	}
	return NIL;
}

int getSibling(int u)
{
	if(nd[u].pa==NIL)return NIL;
	if(nd[nd[u].pa].le!=u&&nd[nd[u].pa].le!=NIL){
		return nd[nd[u].pa].le;//u不是左节点而且左节点存在的情况下，u的兄弟节点就是左节点 
	}
	if(nd[nd[u].pa].ri!=u&&nd[nd[u].pa].ri!=NIL){
		return nd[nd[u].pa].ri;
	}
	return NIL;
}

void setDepth(int u,int p)
{
	if(u==NIL)return;
	D[u]=p;
	setDepth(nd[u].le,p+1);
	setDepth(nd[u].ri,p+1);
}

void print_node(int n)
{
	for(int i=0;i<n;i++){
		int d=0;
		if(nd[i].le!=NIL)d++;//二叉树每个节点顶多只有两个子节点，因此只要检查左右子节点是否存在，然后d++就可以计算出节点度数 
		if(nd[i].ri!=NIL)d++;
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,nd[i].pa,getSibling(i),d,D[i],H[i]);
		if(nd[i].pa==NIL){
			printf("root");
		}else if(nd[i].le==NIL&&nd[i].ri==NIL){
			printf("leaf");
		}else{
			printf("internal node");
		}
		printf("\n");
	}
}

int main()
{
	int n;
	scanf("%d",&n);
	Init(n);
	memset(H,0,sizeof(H));
	memset(D,0,sizeof(D));
	int id,l,r;
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&id,&l,&r);
		nd[id].le=l;
		nd[id].ri=r;
		if(l!=NIL)nd[l].pa=id;
		if(r!=NIL)nd[r].pa=id;//不仅要把左右子节点给赋值好，还要设置好他们的父节点，否则没办法正确建立子节点与父节点的联系 
	}
	flag=getRoot(n);
	int root=flag;
	setDepth(root,0);
	getHeight(root); 
	print_node(n);
	return 0;
}


Measured memory_bytes: 81352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] tree = new int[n];
        for(int i = 0; i < n; i++){
            tree[i] = sc.nextInt();
        }
        Arrays.sort(tree);
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i <= n-k; i++){
            ans = Math.min(ans,tree[i+k-1] - tree[i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 49292
N,W = map(int, input().split())
dp = [0]*(W+1)
temp = [0]*(W+1)

for i in range(1,N+1):
    v,w = map(int,input().split())
    for j in range(w, W+1):
        if v + temp[j-w] > temp[j]:
            dp[j] = temp[j-w]+v
    temp[0:W+1] = dp[0:W+1]

print(dp[W])

Measured memory_bytes: 6660
while True:
    n = int(input())#n=0は終わり
    s = 0
    if n==0:
        break
    else:
        b=[]
        for i in range(n):
            a = int(input())#審判の点数
            b.append((a))
        b.sort()#全員分入力してからソート
        b.pop(n-1)#listが崩れるからz-1から抜いていく
        b.pop(0)
        s=sum(b) #bのリストのI番目をたす
        ave= s/(n-2)
        print(int(ave))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c;cin>>a>>b>>c;
    if(a%2*b%2*c%2==0)cout<<0<<endl;
    else{
        cout<<min(a*b,min(a,b)*c)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
	cin>>a>>b;
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	sort(a.begin(),a.end());
	if(b>a)puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;
using vi = vector<int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  string S;
  cin >> S;

  int before = 1,
      count = 0;
  vi v;
  for (const auto& c : S) {
    if ((c == '0' && before == 0) || (c == '1' && before == 1))
      ++count;
    else {
      v.push_back(count);
      before = c - '0';
      count = 1;
    }
  }
  v.push_back(count);

  int ans = 0;
  REP(i, v.size()) {
    if (i % 2 == 1)
      continue;
    int tmp = 0;
    REP(j, 2 * K + 1) {
      if (i + j >= v.size())
        break;
      tmp += v[i + j];
    }
    ans = max(ans, tmp);
  }
  OUT(ans);
  return 0;
}


Measured memory_bytes: 1020
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	string sj;
	int gs=0;
	cin>>sj;
	for(int i=0;i<sj.length();i++)
	{
		if(sj[i]=='1')gs++;
	}
	cout<<gs<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back


int main(void){
  string s;
  cin >> s;
  int x=0;
  int ans = 0;
  rep(i,s.sz){
    if(s[i] =='S') x++;
    else{
      if(x > 0){ans++;x--;}
    }
  }
  cout << s.size() - ans*2 << endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main()
{
    int i,count=0;
    char a[200009],b[200009];
    scanf("%s",&a);
    scanf("%s",&b);
    for (i=0;a[i]!='\0';i++)
    {
        if (a[i]!=b[i])
        {
            count++;
        }
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int q, r;
	int s, t;
	if (x >= y) {
		q = x;
		r = y;
		s = a;
		t = b;
	}
	else if (x < y) {
		q = y;
		r = x;
		s = b;
		t = a;
	}
	vector<int> v;
	v.push_back(s * q + t * r);
	v.push_back(s * (q - r) + c * 2 * r);
	v.push_back(2 * q * c);
	sort(v.begin(), v.end());
	cout << v[0];
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1 << 30
#define MAX 1000000000
#define SIZE 1000000000
char name[11];
ll num[5];
int main() {
	int n;
	char s[6] = "MARCH";
	scanf("%d", &n);
	rep(i, 0, n) {
		scanf("%s", name);
		rep(i2, 0, 5) {
			if (*name == s[i2]) {
				num[i2]++;
				break;
			}
		}
	}
	ll X = num[1] * (num[2] + num[3] + num[4]);
	ll Y = num[2] * (num[3] + num[4]);
	ll Z = num[3] * num[4];
	printf("%lld\n", num[0] * (X + Y + Z) + num[1] * (Y + Z) + num[2] * Z);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN

    ll n; cin>>n;
    while(1){
        string s = to_string(n);
        char id = s[0];
        ll ok = true;
        REP(j,s.size()){
            if (s[j]!=id) ok = false;
        }
        if (ok){
            cout<<n<<endl;
            return 0;
        }
        n++;
    }
    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define db double 
using namespace std;

int n,m,i,j,k,T,A,x,id;
db mi;

int main(){
	scanf("%d",&n);
	scanf("%d%d",&T,&A);
	id=0; mi=2147483647;
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		if (abs(T-1.0*x*0.006-A)<mi) id=i,mi=abs(T-1.0*x*0.006-A);
	}
	printf("%d",id);
}


Measured memory_bytes: 128
from itertools import accumulate
n=int(input())
a=list(map(int,input().split()))
c=list(accumulate(a))
b=[0]*(n+1)
#大きくしすぎてしまう場合がある
#いや上限を考えろや
def f():
    global n,a,b
    for i in range(n+1):
        if i==0:
            b[0]=min(c[n]-c[0],1)
        else:
            b[i]=min(2*(b[i-1]-a[i-1]),c[n]-c[i-1])

    if n==0:
        if a[0]!=1:
            print(-1)
        else:
            print(1)
    elif b[n]!=a[n]:
        print(-1)
    else:
        print(sum(b))
        #print(b)
f()

Measured memory_bytes: 650744
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
using ll = long long;

int cnt(int x){
   int a = 0;
   for(int i=1;i<=x;i++){
      if(x%i==0) a++;
    }
    return a;
  }

int main(){
 int n;
 cin >> n;
 int ans= 0;
 for(int i=1;i<=n;i=i+2){
    if(cnt(i)==8) ans++;
  }
  cout << ans << endl;
 return 0;
}
 

Measured memory_bytes: 256
import itertools

n, m = map(int, input().split())

path = [[False] * n for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True

ans = 0

# 頂点を並び替える順列を生成してループ
for i in itertools.permutations(range(n), n):
    # 頂点1が始点
    if i[0] == 0:
        # 生成した順列の中をさらにループ
        for j in range(n):
            # n - 1 まで続いたら条件を満たすパスが存在する
            if j == n - 1:
                ans += 1
                break
            # i[j] から i[j + 1] に行くパスがなければ終了
            if not path[i[j]][i[j + 1]]:
                break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int l[200000] = {0};

int main() {
    int N;
    map<int, int> d;

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

    for(int i=0;i<N;i++) {
        auto itr = d.find(l[i]);
        if(itr != d.end()) {
            d[l[i]]++;
        }
        else {
            d[l[i]] = 1;
        }
    }

    int ans = 0;
    for(auto i=d.rbegin();i!=d.rend();i++) {
        while(i->second > 0) {
            int bitLength = 0;
            int b = i->first;
            while (b) {
                b /= 2;
                bitLength++;
            }
            int v = pow(2, bitLength) - i->first ;
            if (d.find(v)!=d.end() && ((v!=i->first && d[v]>=1) || (v==i->first && d[v]>=2))) {
                i->second--;
                d[v]--;
                ans++;
            }
            else {
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 998244353;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

string c = "abc";
// 和を3で割った余りがSと等しい && 一回以上同じ文字が連続する文字列 + S 自身
// dp[i][j][k][0/1] := i 文字見て余り j, 最後の文字が k, 連続したことがあるか
ll dp[200010][3][3][2];

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

    string s;
    cin >> s;
    int n = s.length();
    bool f = true, cons = false;
    int sum = s[0] - 'a';
    for (int i = 1; i < n; i++)
    {
        sum += s[i] - 'a';
        sum %= 3;
        if (s[i] != s[i - 1])
        {
            f = false;
        }
        else
        {
            cons = true;
        }
    }
    if (f)
    {
        cout << 1 << endl;
        return 0;
    }
    if (n <= 3)
    {
        set<string> st;
        queue<string> que;
        que.push(s);
        st.insert(s);
        while (!que.empty())
        {
            string t = que.front();
            que.pop();
            for (int i = 0; i < n - 1; i++)
            {
                string tmp = t;
                if (tmp[i] == tmp[i + 1])
                    continue;
                for (int j = 0; j < 3; j++)
                {
                    if (tmp[i] == c[j] || tmp[i + 1] == c[j])
                        continue;
                    tmp[i] = tmp[i + 1] = c[j];
                    break;
                }
                if (st.find(tmp) != st.end())
                    continue;
                que.push(tmp);
                st.insert(tmp);
            }
        }
        cout << st.size() << endl;
        return 0;
    }
    dp[0][0][0][0] = 1;
    dp[0][1][1][0] = 1;
    dp[0][2][2][0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                for (int l = 0; l < 3; l++)
                {
                    dp[i + 1][(j + l) % 3][l][k == l] += dp[i][j][k][0];
                    dp[i + 1][(j + l) % 3][l][k == l] %= MOD;

                    dp[i + 1][(j + l) % 3][l][1] += dp[i][j][k][1];
                    dp[i + 1][(j + l) % 3][l][1] %= MOD;
                }
            }
        }
    }
    ll res = 0;
    if (!cons)
        res++;
    for (int i = 0; i < 3; i++)
    {
        res += dp[n - 1][sum][i][1];
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;

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

int n;
int a[101][101], sum[101][101];

int main() {
	cin >> n;
	
	FOR(i, 1, n + 1) FOR(j, 1, n + 1) {
		scanf("%d", &a[i][j]);
		sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
	}
	
	int ans = sum[1][1];
	FOR(i, 1, n + 1) FOR (j, 1, n + 1) {
		FOR(ny, i, n + 1) FOR(nx, j, n + 1) {
			ans = max(ans, sum[ny][nx] - sum[i - 1][nx] - sum[ny][j - 1] + sum[i - 1][j - 1]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1324
import java.util.*;

class Main {
    //
    static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int ans = 0;
        for(int i = 1;i <= n;i++){
            if(i < 10||(i >= 100&&i < 1000)||(i >= 10000&&i < 100000)){
                ans++;
            }
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
ll hell=998244353;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,a,b,i;
    cin>>n>>a>>b;
    ll p[n];
    for(i=0;i<n;i++)
        cin>>p[i];
    ll x1=0;
    ll x2=0;
    ll x3=0;
    for(i=0;i<n;i++)
    {
        if(p[i]<=a)
            x1++;
        else if(p[i]<=b)
            x2++;
        else
            x3++;
    }
    ll ans=x1;
    ans=min(ans,x2);
    ans=min(ans,x3);
    cout<<ans;
    return 0;
}






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

using namespace std;

int main()
{
  int n,x;

  cin >> n >> x;

  vector<int> l(n);
  for(int i=0;i<n;i++){
    int L;
    cin >> L;
    l.at(i)=L;
  }
  int jump=0;
  vector<int> ground(n+1);
  ground.at(0)=0;
  for(int i=1;i<n+1;i++){
    ground.at(i)=ground.at(i-1)+l.at(i-1);
  }
  for(int i=0;i<n+1;i++){
    if(ground.at(i)<=x){
      jump++;
    }
    else{
      break;
    }
  }
  cout << jump << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc162/abc162_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string N;
  cin >> N;

  bool ok = false;
  rep(i, N.size()) {
    if (N[i] == '7') {
      ok = true;
      break;
    }
  }

  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    ll n;
    cin >> n;
    if (n % 2) cout << 0 << endl;
    else {
        n /= 2;
        
        ll cnt = 0;
        ll now = 1;
        while (now <= n) {
            now *= 5;
            cnt += n / now;
        }
        cout << cnt << endl;
    }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<int> x;
    rep(i,n){
        auto it = upper_bound(x.begin(),x.end(),-a[i]);
        if(it!=x.end())x.erase(it);
        x.insert(it,-a[i]);
    }
    cout << x.size() << endl;
    return 0;
}

Measured memory_bytes: 1276
const lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    a,b=intLine()
    x=0
    for i in 1:2
        if a>b
            x+=a
            a-=1
        else
            x+=b
            b-=1
        end
    end
    println(x)
end
main()

Measured memory_bytes: 114636
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n=INT()
print(a[n-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--) 

const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

char s[maxn];
ll dp[maxn][14];
ll ppow10[maxn];

int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   cin >> s;
   int len = strlen(s);
   ppow10[0] = 1;
   rep(i,1,1e5) ppow10[i] = ppow10[i-1] * 10 % 13;
   reverse(s,s + len);
   dp[0][0] = 1;
   rep(i,0,len -1){
        rep(j,0,12){
            if(s[i] != '?') {
                int pos = (j + ppow10[i] * (s[i] - '0') % 13)%13;
                dp[i + 1][pos] = (dp[i + 1][pos] +  dp[i][j]) % MOD;
              }
            else {
                rep(k,0,9){
                    int pos = (j + ppow10[i] * k % 13) % 13;
                    dp[i + 1][pos] = (dp[i + 1][pos] + dp[i][j]) % MOD;
                }
            }
        }
   }
   cout << dp[len][5];
   return 0;
}

Measured memory_bytes: 12032
def resolve():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(60):
        p = 1 << i
        one = sum([1 for a in A if a & p])
        zero = N - one
        ans += p * one * zero
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 50912
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from math import gcd
def main():
    N,M = map(int,input().split())
    S = input()
    T = input()

    lcm = N*M//gcd(N,M)
    
    x = lcm//N
    y = lcm//M
    
    ans = lcm
    for i in range(N):
        j = x * i
        if j%y == 0:
            if S[i] != T[j//y]:
                ans = -1
                break
    
    for j in range(M):
        i = y * j
        if i%x == 0:
            if S[i//x] != T[j]:
                ans = -1
                break
    print(ans)  
if __name__ == '__main__':
    main()

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

#define int long long
#define double long double

const int INF=2147483647;
const int MOD=1000000007;
const int mod=998244353;
const double eps=1e-18;

using namespace std;

int power(int n,int p){

    int res=1;
    for(int i=0;i<p;i++){
        res*=n;
        res%=MOD;
    }
    return res;

}

signed main(){

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

    int n;
    int res;

    cin>>n;
    res=(power(10,n)-(2*power(9,n))+power(8,n)+(2*MOD))%MOD;
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3656
from collections import Counter
n = int(input())
d = list(map(int, input().split()))

if d[0] != 0:
    print(0)
    exit()

cnt = Counter(d)

if cnt[0] != 1:
    print(0)
    exit()

ans = 1
for i in d:
    if i != 0:
        ans = (ans * cnt[i-1]) % 998244353
print(ans)

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

int main(){
 int n;
  int p=0;
  cin>>n;
  vector<int>d(n);
  
  for(int i=0;i<n;i++){
  cin>>d.at(i);
  }
 for(int i=0;i<n;i++)
  {
   for(int j=0;j<n;j++)
  {
     if(i<j){
     p+=d.at(i)*d.at(j);
     }
     }
  }
  
  cout<<p<<endl;
 }
  


  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;

typedef long double ld;
using namespace std;


int main() {
    int N,D;
    cin>>N>>D;
    int count=0,hito=0;

    while(count<N){
        count+=2*D+1;
        hito++;
    }

    cout<<hito<<endl;

}
 

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define pr(x) cout<<#x<<" "<<x<<" "
#define prln(x) cout<<#x<<" "<<x<<endl;
const int maxn = 1e5 + 4;
const int inf = 0x3f3f3f3f;
int n, a[maxn];
int main(){
	while(scanf("%d", &n) != EOF){
		for(int i = 1, x; i <= n; i++){
			scanf("%d", &x);
			if(x == i) a[i] = 1;
			else a[i] = 0;
		}
		int res = 0;
		bool flag = false;
		for(int i = 1; i <= n; i++){
			if(a[i] == 1){
				if(flag) flag = false;
				else{
					res++;
					flag = true;
				}
			}
			else flag = false;
		}
		printf("%d\n", res);
	}
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define E 2.71828182845905
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define PI 3.14159265
#define mem(x) memset(x,0,sizeof(x));
using namespace std;

void sol() {
	int n;
	cin>>n;
	ll arr[n+1];
	rep(i,1,n+1)
	cin>>arr[i];
	ll psum[n+1];
	mem(psum);
	rep(i,1,n+1)
		psum[i]=psum[i-1]+arr[i];
	ll dp[n+1][n+1];
	mem(dp);
	rep(i,1,n+1){
		dp[i][i]=arr[i];
	}
	rep(l,2,n+1){
		rep(i,1,n+1){
			int j=i+l-1;
			if(j>n)
				break;
			if(dp[i+1][j]<dp[i][j-1]){
				dp[i][j]=psum[j]-psum[i-1]-dp[i+1][j];
			}
			else {
				dp[i][j]=psum[j]-psum[i-1]-dp[i][j-1];
			}
		}
	}
	cout<<2*dp[1][n]-psum[n];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
 	//cin>>t;
 	while(t--){	
	sol();
 	}
}

Measured memory_bytes: 70656
#include <stdio.h>

int main(void){
    char c[2];
    scanf("%s",c);
    if(c[0]=='a'||c[0]=='i'||c[0]=='u'||c[0]=='e'||c[0]=='o'){
        printf("vowel\n");
    }else{
        printf("consonant\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){
  ll N;
  cin >> N;
  vector<string> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
 
  cout << vec.size() << endl;
}


Measured memory_bytes: 9548
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main{
    static int[] memo;
    static int[] val;
    static int n;
    static int k;
    public static void main(String[] args) throws IOException {
        scanner sc = new scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        k = sc.nextInt();
        val = new int[n];

        for (int i = 0; i < n; i++)
            val[i] = sc.nextInt();

        memo = new int[n];
        Arrays.fill(memo,-1);


        out.println(dp(0));
        out.flush();
    }

    static int dp(int i){
        if (i == n-1)
            return 0;

        if (memo[i] != -1)
            return  memo[i];

        int one = Integer.MAX_VALUE-1;

        for (int j = 1; j <= k; j++) {
            if (i+j < n){
                one = Math.min(one,dp(i+j) + Math.abs(val[i]-val[i+j]));
            }
        }

        return memo[i] = one;
    }

}
class scanner{
    StringTokenizer st;
    BufferedReader br;
    public scanner(InputStream s){
        br = new BufferedReader(new InputStreamReader(s));
    }
    public scanner (String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s));}

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public boolean ready() throws IOException {
        return br.ready();
    }
}

Measured memory_bytes: 44568
#include <stdio.h>
int main() 
{
	int n,k,i,count=0;
	scanf("%d%d",&n,&k);
	int h[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&h[i]);
	}
	for(i=0;i<n;i++)
	{
		if(h[i]>=k)
		{
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

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

int main() {
	int n;
	int t[110];

	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> t[i];
		}

		int x;
		cin >> x;

		int l = 0;
		int r = n - 1;
		int cnt = 0;

		while (l <= r) {
			cnt++;
			int m = (l + r) / 2;

			if (t[m] == x)
				break;
			if (t[m] > x) {
				r = m - 1;
			} else {
				l = m + 1;
			}
		}

		cout << cnt << endl;
	}
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    int c[256] = {0};
    for (int i = 0; i < S.size(); i++)
        c[S[i]]++;
    int n = 0;
    for (int i = 0; i < 256; i++)
        if (c[i] == 2) n++;
    cout << (n == 2 ? YES : NO) << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
# m-solutions2020_b.py
# https://atcoder.jp/contests/m-solutions2020 : B

global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    A, B, C = list(map(int, lines[0].split()))
    # K = lines[1]
    K = int(lines[1])
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    for i in range(8):
        if A >= B:
            B *= 2
            K -= 1
    for i in range(8):
        if B >= C:
            C *= 2
            K -= 1
    log(f'K=[{K}]')
    if K < 0:
        ret = 'No'
    else:
        ret = 'Yes'

    return [ret]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['7 2 5', '3']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['7 4 2', '3']
        lines_export = ['No']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    if mode > 0:
        log(f'lines_input=[{lines_input}]')
        log(f'lines_export=[{lines_export}]')
        log(f'lines_result=[{lines_result}]')
        if lines_result == lines_export:
            log('OK')
        else:
            log('NG')
    finished = time.time()
    duration = finished - started
    log(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9316
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

std::string s;

int main() {
	std::cin>>s;
	if(s=="ABC") puts("ARC");
	else if(s=="ARC") puts("ABC");
	return 0;
}

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


int main () {
  int n, k;
  string s;

  cin >> n >> k >> s;

  vector<int> a;
  int i = 0, l = s.size();
  bool one = true;
  // 101010...01
  while(i < l) {
    int c = 0;
    while(s[i] == '0' + one) {
      c++;
      i++;
      if(i >= l) break;
    }
    one = !one;
    a.push_back(c);
  }
  if(s[l-1] == '0') a.push_back(0);

  int sum = a[0];
  l = a.size();
  int w = 1;
  int ans = sum;
  i = 1;
  while(i + 1 < l) {
    sum += a[i] + a[i+1];
    w += 2;
    if(w > 2*k + 1) {
      sum -= a[i-2*k-1] + a[i-2*k];
      w -= 2;
    }
    i += 2;
    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s;cin>>s;
  int ans=0;
  if(s[0]=='1') ans++;
  if(s[1]=='1') ans++;
  if(s[2]=='1') ans++;
  cout << ans << endl;
  return 0;
}


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

import static java.lang.Integer.parseInt;

/**
 * Unique number
 * JOI 12th, Pre 3
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int N = parseInt(br.readLine());
		String dst = br.readLine();
		char top = dst.charAt(0);

		int count = 0;
		for (int i = 0; i < N; i++) {
			String src = br.readLine();
			outer1:
			for (int j = 0; j < src.length(); j++) {
				outer2:
				if (src.charAt(j) == top) {
					for (int k = 0; ; k++) {
						for (int l = 0; l < dst.length(); l++) {
							if (j + l + (k * l) >= src.length()) {
								break outer2;
							}
							if (dst.charAt(l) != src.charAt(j + l + (k * l))) break;
							if (l == dst.length() - 1) {
								count++;
								break outer1;
							}
						}
					}
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24864
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};

fn main(){
    let n: usize = read();
    let mut a: Vec<isize> = (0..n + 1).map(|_| read()).collect();
    let mut b: Vec<isize> = (0..n).map(|_| read()).collect();
    let mut ans: isize = 0;
    for i in 0..n{
        ans += min(a[i], b[i]);
        b[i] = max(0, b[i] - a[i]);
        ans += min(a[i + 1], b[i]);
        a[i + 1] = max(0, a[i + 1] - b[i]);
    }
    println!("{}", ans);
}

fn upper_bound(a: &Vec<i32>, x: &i32) -> Option<usize>
{
    let mut ok: isize = a.len() as isize;
    let mut ng: isize = -1;
    if ok == 0 || a[ok as usize - 1] <= *x{
        None
    }else{
        while (ng - ok).abs() > 1{
            let mid = (ok + ng) / 2;
            if a[mid as usize] > *x{
                ok = mid;
            }else{
                ng = mid;
            }
        }
        Some(ok as usize)
    }
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 6396
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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;
}

const int INF = 1e9;
const long long LINF = 1e18;

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

    map<char, int> m;
    for (int i = 0; i < S.size(); i++) {
        m[S[i]]++;
    }

    if (m.size() != 2) {
        cout << "No" << endl;
        return 0;
    }

    for (map<char, int>::iterator itr = m.begin(); itr != m.end(); ++itr) {
        if (itr->second != 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 504
from bisect import bisect_left
s = input()
t = input()

l = len(s)
dic = {c: [0] * l for c in set(s)}

for i in range(l):
    dic[s[i]][i] = 1

for key in dic.keys():
    lst = dic[key]
    for i in range(l - 1):
        lst[i + 1] += lst[i]

idx = -1
ans = 0
for c in t:
    if not c in dic:
        print(-1)
        exit(0)
    lst = dic[c]
    cur = lst[idx] if idx >= 0 else 0
    i = bisect_left(lst, cur + 1)
    if i == l:
        ans += l
        idx = -1
        cur = 0
        i = bisect_left(lst, 1)

    idx = i
ans += idx
print(ans + 1)

Measured memory_bytes: 100724
# -*- coding: utf-8 -*-
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())

if D2 != 1:
    print(0)
elif D1 == 28:
    if M2 == 3 and M1 == 2:
        print(1)
    else:
        print(0)
        
elif D1 == 30:
    if M1 == 4:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 6:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 9:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 11:
        if M2 - M1 == 1:
            print(1)
    else:
        print(0)
    
elif D1 == 31:
    if M1 == 1:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 3:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 5:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 7:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 8:
        if M2 - M1 == 1:
            print(1)       
    elif M1 == 10:
        if M2 - M1 == 1:
            print(1)
    elif M1 == 12:
        if M2 == 1:
            print(1)
    else:
        print(0)

else:
    print(0)    

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

const int mod = 1e9 + 7;

int power(int x, int y)
{
    int ans = 1;
    while(y)
    {
        if(y & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int n;
        cin >> n;
        int a[n];
        map<int,int> mp;
        for(int i=0;i<n;i++)
        {
            cin >> a[i];
            int x = a[i];

            for(int i=2;i*i<=x;i++)
            {
                int cnt = 0;
                while(x % i == 0)
                {
                    cnt++;
                    x /= i;
                }

                mp[i] = max(mp[i], cnt); 
            }
            if(x > 1)
                mp[x] = max(mp[x], 1LL);
        }

        int l = 1;
        for(auto it = mp.begin() ; it != mp.end() ; it++)
        {
            //cout << "F : " << it->first << ' ' << it->second << '\n';
            int x = power(it->first, it->second);
            l = l * x % mod;
        }

        //cout << "LCM : " << l << '\n';
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            int x = l * power(a[i], mod - 2) % mod;
            ans = (ans + x) % mod;
        }

        cout << ans << '\n';

    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 1024