akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#ifdef on_linux
	#include <sys/resource.h>
#endif

#ifdef dobby_is_a_free_elf
	#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
	#define trace(...) 0;
#endif

using namespace std;
using namespace __gnu_pbds;


#define all(x)                  (x).begin(), (x).end()
#define between(i,x,y)          ((i) >= (x) && (i) <= (y))
#define DECIMAL(n)              cout << fixed << setprecision(n)
#define fi                      first
#define lbd                     lower_bound
#define mem0(x)                 memset(x, 0, sizeof (x))
#define mem1(x)                 memset(x, -1, sizeof (x))
#define mp                      make_pair
#define pb                      push_back
#define pf                      push_front
#define ppb                     pop_back
#define ppf                     pop_front
#define sc                      second
#define sqr(a)                  ((a) * (a))
#define sz(x)                   (int)((x).size())
#define ubd                     upper_bound

#define int                     long long

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>,
      rb_tree_tag,
      tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0
// order_of_key(k) returns count of elements strictly smaller than k


const long double PI = 3.14159265358979323846264338;
const double eps = 1e-10;
#ifdef int
	const long long INF = 1e18;
#else
	const long long INF = 1e9;
#endif
const int32_t fftmod = 998244353;
const int32_t MOD = 1000000007;
const int32_t N = 1e5 + 10;
const int32_t NN = 1e6 + 10;



inline void elf_magic(int testcase)
{
	int n;
	cin >> n;
	int x[n], y[n];
	int mxx = -INF, mnx = INF;
	int mxy = -INF, mny = INF;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		x[i] = a - b;
		y[i] = a + b;
		mxx = max({mxx, x[i]});
		mnx = min({mnx, x[i]});
		mxy = max({mxy, y[i]});
		mny = min({mny, y[i]});
	}

	cout << max(mxx - mnx, mxy - mny);

	return;
}

int32_t main()
{
	#ifdef on_linux
	rlimit cpu_time {.rlim_cur = 2, .rlim_max = RLIM_INFINITY};
	setrlimit(RLIMIT_CPU, &cpu_time);
	#endif

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

	int TESTS = 1;
	//cin >> TESTS;
	for (int i = 1; i <= TESTS; ++i) {
		// cout << "Case #" << i << ": ";
		elf_magic(i);
		if (i != TESTS)	{ cout << '\n'; }
	}
	return 0;
}

Measured memory_bytes: 6712
#include<iostream>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <bits/stdc++.h> 
using namespace std;
 
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) 
\
 
int main()
{
  int n,k,c=1,p=0;
  cin>>n>>k;
  p=k;
  while(p<=n)
  {
    p=p*k;
    c++;
  }
  cout<<c;
  return 0;

}

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

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 100005, INF = 1e9;

/*******************************************************************************
 *
 *
 *
 ******************************************************************************/

int n, A[N], mi = INF;

int main() {
    n = read<int>();
    rep (i, 1, n) A[i] = read<int>();
    dep (i, n, 1) {
        if (A[i] - 1 > mi) {
            puts("No");
            return 0;
        }
        if (mi == A[i] - 1) --A[i];
        mi = min(A[i], mi);
    }
    puts("Yes");
    return 0;
}



Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 21:21:19 2019

@author: Yamazaki Kenichi
"""

N,Q = map(int,input().split())
s = input()
A = [list(input().split()) for i in range(Q)]

def a(b,i):
    if i == -1 or i == N:
        return i        
    if b[0] == s[i]:
        return i - 1 if b[1] == 'L' else i + 1
    else:
        return i
def ar(i):
    for j in range(Q):
        if i == N:
            return False
        i = a(A[j],i)
    return False if i == N else True
def al(i):
    for j in range(Q):
        if i == -1:
            return False
        i = a(A[j],i)
    return False if i == -1 else True
def bir(i,j):
    if i + 1 == j:
        return i
    if ar((i+j)//2):
        return bir((i+j)//2,j)
    else:
        return bir(i,(i+j)//2)
def bil(i,j):
    if i + 1 == j:
        return i
    if al((i+j)//2):
        return bil(i,(i+j)//2)
    else:
        return bil((i+j)//2,j)
ans = bir(0,N) - bil(0,N)
print(ans)


Measured memory_bytes: 89036
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int main()
{
  char c[5];
  int n;
  map<int,string> B;
  int a,b,ab,o;
  a=b=ab=o=0;
  while(scanf("%d,%s",&n,c) !=EOF){
    if(c[0] =='A' &&c[1]=='B'){
      ab++;
    }else if(c[0] =='A'){
      a++;
    }else if(c[0] =='B'){
      b++;
    }else if(c[0]=='O'){
      o++;
    }
  }
  printf("%d\n%d\n%d\n%d\n", a,b,ab,o);
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	ll n, k;
	cin >> n >> k;
	V<ll> a(n);
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	
	V<ll> div(0);
	rep1(i, sqrt(sum)) {
		if (sum % i)continue;
		div.push_back(i);
		if (sum / i != i)div.push_back(sum / i);
	}

	sort(all(div), greater<ll>());

	ll ans = 1;

	for(auto t:div) {

		V<ll> d(n);
		ll ls = 0, rs = 0, cnt = LINF;

		rep(j, n) {
			d[j] = a[j] % t;
			rs += t - d[j];
		}

		sort(all(d));

		rep(j, n) {
			ls += d[j];
			rs -= t - d[j];
			cnt = min(cnt, max(ls, rs));
		}

		if (cnt <= k) {
			ans = t;
			break;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, N: int, A: "List[int]"):
    A.sort()
    print(YES if H<=sum(A[len(A)-N:]) else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(H, N, A)

if __name__ == '__main__':
    main()


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

int hand(char s){
	if(s=='y' || s=='u' || s=='i' || s=='o' || s=='p' || s=='h' || s=='j' || 
	s=='k' || s=='l' || s=='n' || s=='m') return 1;
	else return -1;
}

int chack(char tmp[40],int len){
	int i,set,count=0;
	set = hand(tmp[0]);
	for(i=1;i<len;i++){
		if(set!=hand(tmp[i])){
			count++;
			set=hand(tmp[i]);
		}
	}
	return count;
}

int main(){
	char tmp[40];
    int output[500];
    int i=0;
	int j;

    while(1){
        scanf("%s",tmp);
        if(tmp[0]=='#') break;
		output[i]=chack(tmp,strlen(tmp));
        i++;
    }
    for(j=0;j<i;j++){
    	printf("%d\n",output[j]);
    }
    
    return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int n, x;
  cin >> n >> x;

  int sum = 0;
  int cnt = 1;
  rep(i, n){
    int l;
    cin >> l;
    sum += l;
    if(sum > x) break;
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}


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

for i in s:
	i = ord(i)
	t = 0
	for j in range(ord('A'), ord('Z')+1):
		if i == j:
			t = j
	t+=N
	if t>ord('Z'):
		t -= 26
	print(chr(t),end='')
print()


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

using namespace std;


int main() {
#ifdef LOCAL
    freopen("atcoder/3/input.txt", "r", stdin);
#endif

    int n, k;
    cin >> n >> k;

    unordered_set<int> prohibited;
    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;

        prohibited.insert(d);
    }

    int ten_power = 1;
    int m = n;
    int change_power = 1;
    bool find = false;

    while (m > 0) {
        if (prohibited.count(m % 10)) {
            change_power = ten_power;
            find = true;
        }

        ten_power *= 10;
        m /= 10;
    }

    if (!find) {
        cout << n << "\n";
        return 0;
    }

    // 19 change_power = 1 {0, 9}
    // res = 19 - (19 % 1) = 19
    // 19 20

    int res = n - (n % change_power);

//    cout << "change_power = " << change_power << ", res = " << res << "\n";

    while (prohibited.count((res / change_power) % 10)) {
        res += change_power;

        if ((res / change_power) % 10 == 0) {
            change_power *= 10;
        }
    }

    if (prohibited.count(0)) {
        int min_d = 1;
        while (prohibited.count(min_d)) {
            ++min_d;
        }

        while (change_power >= 10) {
            change_power /= 10;
            res += min_d * change_power;
        }

    }

    cout << res << "\n";


    return 0;
}











Measured memory_bytes: 256
#include<stdio.h>
int main() { 
    int i,n,x,rem,cnt,flag=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        x=i;
        cnt=0;
        while(x!=0){
        rem=x%10;
        cnt++;
        x=x/10;
            
            }
        if(cnt%2==1){
            flag++;
        }
    }
    printf("%d",flag);
    return 0; 
    }

Measured memory_bytes: 1692
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {


     long long n,ans=0,sum=0,i;
      cin>>n;
        for(i=1;i<=n;i++){
                sum=sum+i;
            if(i%3==0 || i%5==0 || (i%3==0 && i%5==0))
           {

           ans=ans+i;}


            }
        cout<<sum-ans<<endl;

        }





Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
int main(){
  using namespace std;
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    vector<int> edge(3);
    for(int j = 0; j < 3; j++){
      cin >> edge[j];
    }
    sort(edge.begin(), edge.end());
    int l,m,s;
    s = edge[0];
    m = edge[1];
    l = edge[2];
    if(l*l == m*m + s*s){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 1204
// Last Change: 02/09/2019 21:40:20.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  ll maisu = 1;

  ll tmp = A - 1;
  ll diffAB = B - A;
  //交換する意味なし
  if (diffAB <= 1) {
    maisu += K;
  }
  //交換しよ
  else {
    //交換まで至れない
    if (K <= tmp) {
      maisu += K;
    }
    //交換のトライ
    else {
      maisu = A;
      K -= tmp;
      maisu += (K / 2) * diffAB;
      maisu += K % 2;
    }
  }
  //回答
  cout << maisu << endl;

  //LoopUntilZeroInpput();
}


Measured memory_bytes: 256
import numpy as np

s = input()
x_goal, y_goal = map(int, input().split())

directed_x = None
steps = 0
xs = [0]
ys = [0]
for c in (s+'T'):   #sentinel
    if c == 'F':
        steps += 1
    else:
        if directed_x is None:
            x_goal -= steps
            directed_x = True
        elif steps != 0:
            if directed_x:
                xs.append(steps)
            else:
                ys.append(steps)
        steps = 0
        directed_x = not directed_x

dx_2 = sum(xs) - x_goal
if dx_2 % 2 == 1 or dx_2 < 0:
    ans = False
else:
    dx = dx_2 // 2
    possible_x = np.full(dx + 1, False)
    possible_x[0] = True
    for x in xs:
        possible_x[x:] = np.logical_or(possible_x[:len(possible_x)-x], possible_x[x:])
        if possible_x[dx]:
            ans = True
            break
    else:
        ans = False

if ans:
    dy_2 = sum(ys) - y_goal
    if dy_2 % 2 == 1 or dy_2 < 0:
        ans = False
    else:
        dy = dy_2 // 2
        possible_y = np.full(dy + 1, False)
        possible_y[0] = True
        for y in ys:
            possible_y[y:] = np.logical_or(possible_y[:len(possible_y)-y], possible_y[y:])
            if possible_y[dy]:
                ans = True
                break
        else:
            ans = False

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14464
fun main(array: Array<String>){
    val n = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map { it.toInt() }
    var a = mutableListOf<Int>()
    a.add(b[0])
    for (i in 1 until n-1) {
        if(b[i] <= b[i-1]) {
            a.add(b[i])
        }
        else {
            a.add(b[i-1])
        }
    }
    a.add(b[n-2])
    print(a.sum())
}

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

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
  int64_t a,b;
  cin >> a >> b;
  cout << a*b / gcd(a,b) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 305
using namespace std;
int k,f[MN][MN][MN];char ch[MN];
int main(){
	scanf("%s",ch+1);int n=strlen(ch+1);scanf("%d",&k);
	for(int i=1;i<=n;i++)for(int j=0;j<=k;j++)f[i][i][j]=1;
	for(int len=2;len<=n;len++)
		for(int i=1,j=i+len-1;j<=n;i++,j++)
          	for(int kk=0;kk<=k;kk++){
            	f[i][j][kk]=max(f[i+1][j][kk],f[i][j-1][kk]);
            	if(kk>0)f[i][j][kk]=max(f[i][j][kk],f[i+1][j-1][kk-1]+2);
            	if(ch[i]==ch[j])f[i][j][kk]=max(f[i][j][kk],f[i+1][j-1][kk]+2);
          	}
	printf("%d\n",f[1][n][k]);
}

Measured memory_bytes: 110336
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <functional>
#include <string>
#include <stack>
#include <map>

using namespace std;
using ll = long long;
ll mod = 1e9 + 7;


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

	if (n % 2 == 1)
	{
		cout << (n - 1) * (n-1)/2 << endl;

		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				if (j + i != n)
					cout << i << " " << j << endl;
			}
		}
	}
	else
	{
		cout << n * (n - 2) / 2 << endl;

		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				if (j + i != n + 1)
					cout << i << " " << j << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
def build_stairs(n, hli):

    ans = "Yes"

    for i in range(1, n):
        if hli[i-1] < hli[i]:
            hli[i] -= 1
        elif hli[i-1] == hli[i]:
            pass
        else:
            return "No"

    return ans

def main():
    n = int(input())
    hli = list(map(int, input().split()))
    print(build_stairs(n, hli))

if __name__ == '__main__':
    main()

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

map <string,int> counting;

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

	int n;
	string s;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> s;
		sort(s.begin(),s.end());
		counting[s]++;
	}

	long long int res = 0;
	for(auto it : counting)
	{
		long long int x = it.second;
		res += (x*(x-1))/2;
	}

	cout << res << '\n';

	return 0;	
}

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

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

Measured memory_bytes: 4052
def main():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    P = [tuple(map(int, input().split())) for _ in range(M)]

    S = sum(T)

    for p in P:
        d = T[p[0] - 1] - p[1]
        print(S - d)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
N=int(input())
A=list(map(int,input().split()))
m,p=[],[]
for i in A:
    if i>=0:
        p.append(i)
    else:
        m.append(i)
if m and p:
    print(sum(p)-sum(m))
    t=m[0]
    for i in p[:-1]:
        print(t,i)
        t-=i
    print(p[-1],t)
    t=p[-1]-t
    for i in m[1:]:
        print(t,i)
        t-=i
elif p:
    p.sort()
    print(sum(p[1:])-p[0])
    t=p[0]
    for i in p[1:-1]:
        print(t,i)
        t-=i
    print(p[-1],t)
else:
    m.sort(reverse=1)
    print(m[0]-sum(m[1:]))
    t=m[0]
    for i in m[1:]:
        print(t,i)
        t-=i

Measured memory_bytes: 14324
num=[]
for i in range(3):
    array = list(map(int, input().strip().split()))
    num.append(array)
N = int(input())
a = [int(input()) for i in range(N)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if a[i] == num[j][k]:
                num[j][k] = False
bingo = 0
for m in range(3):
    if num[0][m] == num[1][m] == num[2][m] == False:bingo = 1

for n in range(3):
    if num[n][0] ==  num[n][1] ==  num[n][2] == 0:bingo = 1 
if num[0][0] == num[1][1] == num[2][2] == 0 :bingo = 1
if num[0][2] == num[1][1] == num[2][0] == 0 :bingo = 1

if bingo == 1:print("Yes")
elif bingo == 0:print("No")




Measured memory_bytes: 38384
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
#include <iostream>
// #include <iomanip>
// #include <sstream>
using namespace std;
// const int dx[] = {0, 1, 0, -1};
// const int dy[] = {1, 0, -1, 0};
// const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1};
// const int dy[] = {-1, 1, 1, -1, 2, -2, 2, -2};
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fr(_iii_, 0, 66)pf(">");puts("in")
#define deb(x) fr(_iii_, 0, 66)cerr<<'>';cerr<<#x"="<<x<<"\n"
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false)
#define boost2 cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
int on_bit(int x, int pos) {x |= (1 << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(int x, int pos) {return ((x & (1 << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
ll on_bit_all(ll x, int pos) {x = (1LL << pos)-1; return x;}
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int MOD = 1e9+7;
int add(ll a, ll b){return ((a%MOD)+(b%MOD))%MOD;}
int sub(ll a, ll b){return ((a%MOD)-(b%MOD))%MOD;}
int mult(ll a, ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}

bool ok(int x){
	bool ex[10];
	mems(ex);
	while(x){
		ex[x%10]=true;
		x/=10;
	}
	return ex[3]&&ex[5]&&ex[7];
}

int main(){
	boost;boost2;
	vector<string> v;
	v.reserve(3145738);
	v.pb("3");
	v.pb("5");
	v.pb("7");
	int curr_len = 1;
	while(curr_len < 10){
		int ss = sz(v);
		fr(i,0,ss){
			if(sz(v[i])!=curr_len)continue;
			string u = v[i];
			u.pb('3');
			v.pb(u);
			u[sz(u)-1]='5';
			v.pb(u);
			u[sz(u)-1]='7';
			v.pb(u);
		}
		curr_len++;
	}
	int n;
	cin>>n;
	int res=0;
	fr(i,0,sz(v)){
		if(atoi(v[i].c_str())<=n){
			if(ok(atoi(v[i].c_str()))){
				res++;
			}
		}
	}
	cout<<res<<'\n';
	return 0;
}

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

N, M, X = map(int, input().split())

N_list = list(range(N))

price_list = []
point_list = []

x = []

for i in range(N):
  my_list = list(map(int, input().split()))
  price_list.append(my_list[0])
  point_list.append(my_list[1:])
  x.append(list(combinations(N_list, i+1)))

my_np = np.array(point_list)

ans = None

for i in x:
  for j in i:
    check_price = 0
    check_np = np.zeros(M)
    for k in j:
      check_price += price_list[k]
      check_np += my_np[k]
    if min(check_np) >= X:
      if ans is None:
        ans = check_price
      else:
        ans = min(check_price,ans)

if ans is None:
  ans = -1

print(ans)

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

int main(){
  int N,Q;
  int ans;
  cin >> N >> Q;
  string s;
  cin >> s;
  int l[Q],r[Q];
  for (int i=0;i<Q;i++){
    cin >> l[i] >> r[i];
  }

  int t[N];
  t[0] = 0;
  for (int i=0;i<N-1;i++){
    if (s[i] == 'A' && s[i+1] == 'C') t[i+1] = t[i]+1;
    else t[i+1] = t[i];
  }
  
  for (int i=0;i<Q;i++){
    cout << t[r[i]-1] - t[l[i]-1]<< endl;
  }
  return 0;
}



Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;

ll xor_total(ll N) {
    ll ret = 0;
    if (N % 4 == 3)
        ret ^= 0;
    else if (N % 4 == 0)
        ret ^= N;
    else if (N % 4 == 1)
        ret ^= 1;
    else if (N % 4 == 2)
        ret ^= N+1;
    return ret;
}

int main(){
    // int N = 100;
    // int ret = 0;
    // for(size_t i = 1; i <= N; i++)
    // {
    //     ret ^= i;
    //     cout << ret << endl;
    // }

    ll A, B;
    cin >> A >> B;
    cout << (xor_total(B) ^ xor_total(A-1)) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException
    {
        Scanner input = new Scanner(System.in);
       
        String whole = input.nextLine();
        int Z = 0; 
        
        ArrayList<Integer> lens = new ArrayList<Integer>();
        if (whole.indexOf("A") >= 0 && whole.lastIndexOf("Z") >= whole.indexOf("A"))
        {
            int A = whole.indexOf("A"); // 1
            whole = whole.substring(A); // ABCZ
            Z = whole.lastIndexOf("Z"); // 3
            //lens.add((Z + 1)); // 4
            //whole = whole.substring(Z); // Z
        }
              
        System.out.println(Z+1);
    }
}


Measured memory_bytes: 27708
## 解説を見た
## まず9のべき乗の引き出しを行い、その後(最適に)6のべき乗の引き出しを行う
## 9のべき乗の引き出しは全通り行い、残金を全列挙する
## それぞれの残金を6進数で表し、各桁の総和が「6で引き出すコスト」となる

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def Base_n_to_10(X,n):
    out = 0
    for i in range(1,len(str(X))+1):
        out += int(str(X)[-i])*(n**(i-1))
    return out


N = int(input())

after_draw_9 = []
for i in range(N // 9 + 1):
  cost_9 = sum(map(int, Base_10_to_n(9*i,9)))
  after_draw_9.append((N-9*i, cost_9))
#print(after_draw_9)

solver = []
for i in range(len(after_draw_9)):
  cost_6 = sum(map(int, Base_10_to_n(after_draw_9[i][0], 6)))
  solver.append(after_draw_9[i][1] + cost_6)
  
#print(solver)
print(min(solver))

Measured memory_bytes: 4152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    double a,b,x;
    cin >> a >> b >> x;
    cout << fixed << setprecision(9);
    if(x <= a * b * a/2.0){
        cout << atan(a * b * b / (2.0 * x))/(2.0 * M_PI) * 360.0 << endl;
    }else{
        cout << atan((2.0 * b - 2.0 * x / (a * a))/a)/(2.0 * M_PI) * 360.0 << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int L,A,B,C,D;
int main(){

  cin>>L>>A>>B>>C>>D;
  cout<<L-max((A+C-1)/C,(D+B-1)/D)<<endl;
  
  return 0;
}

Measured memory_bytes: 1164
import sys


def sum_digits(n):
    r = 0
    while n > 0:
        r += n % 10
        n = int(n / 10)
    return r


def solve(inp):
    (N, A, B) = map(int, inp.readline().split(' '))

    r = 0
    for n in range(1, N + 1):
        s = sum_digits(n)
        if A <= s <= B:
            r += n

    return r


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


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

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

    if (s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7'){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int count = 0;
		
		for (int i = 0; i < N; i++) {
			count += 1 + i;
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'x') cnt++;
    }
    if (cnt <= 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pb push_back
using namespace std;

int main(void){
  int x,a,b;
  cin>>x>>a>>b;
  cout<<(abs(x-a)>abs(x-b)?"B":"A")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 5e3 + 17;

int n;
string s;

bool read()
{
	if (scanf("%s", buff) != 1)
		return false;

	return true;
}

void solve()
{
	s = buff;
	n = size(s);

	if ((size(s) & 1) ^ (s[0] == s.back()))
		printf("First\n");
	else
		printf("Second\n");
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		read(), solve();

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++) 
#define all(v) v.begin(),v.end()
#define F first
#define S second
ll fun(string s)
{
	ll res=0;
	for(int i=0;i<s.length();i++)
	{
		res+=(s[i]-'0');
	}
	return res;
}
void solve()
{
	ll n;
	cin>>n;
	ll arr[n];
	rep(i,n)
	{
		cin>>arr[i];
	}
	ll sum=0;
	for(int i=1;i<n;i++)
	{
		if(arr[i]<arr[i-1])
		{
			sum+=abs(arr[i-1]-arr[i]);
			arr[i]=arr[i-1];
		}
	}
	cout<<sum<<endl;
}
int main()
{
//	ios_base::sync_with_stdio(false); 
  //  cin.tie(NULL);  
	int t;
	t=1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
int main(){
  char b;
  cin >> b;
  if (b == 'A'){
    cout << 'T';
  }
  if (b == 'T'){
    cout << 'A';
  }
  if (b == 'C'){
    cout << 'G';
  }
  if (b == 'G'){
    cout << 'C';
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
                for(int i=0;i<H;i++){
                  for(int j=0;j<W;j++){
                    System.out.print("#");
                  }
                System.out.println();
                }
            System.out.println();
        }
        
    }
}



Measured memory_bytes: 35688
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;

int n;
pair<int,pair<int,int> > a[N];

bool cmp(pair<int,pair<int,int> >P1,pair<int,pair<int,int> > P2) {
	return P1.second.first<P2.second.first;
}

int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i].first);
	for (int i=1;i<=n;i++) a[i].second.first=i;
	sort(a+1,a+n+1);
	int t=n/2;
	for (int i=1;i<=n;i++) {
		int x=i-1,y=n-i;
//		a[i].second.second=a[i+(y-x)/2].first;
		if (i<=t) a[i].second.second=a[t+1].first;
		else a[i].second.second=a[t].first;
	}
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++) printf("%d\n",a[i].second.second);
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  ld R1, R2;
  cin >> R1 >> R2;
  ld R = R1 * R2 / (R1 + R2);
  cout << fixed << setprecision(10) << R << endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  if (s == "SAT") {
    ans = 1;
  } else if (s == "FRI") {
    ans = 2;
  } else if (s == "THU") {
    ans = 3;
  } else if (s == "WED") {
    ans = 4;
  } else if (s == "TUE") {
    ans = 5;
  } else if (s == "MON") {
    ans = 6;
  } else if (s == "SUN") {
    ans = 7;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String[] S = s.split(",");
    System.out.printf("%s",S[0]);
    System.out.printf(" ");
    System.out.printf("%s",S[1]);
    System.out.printf(" ");
    System.out.println(S[2]);
  }
}


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

void solve()
{
    long long t,n,m,i,j,k=0,kk=0,x,y,z=0,mn=0,mx,a[10],cnt=0;

    cin >> n >> m;

    n=n%m;

    x = abs(n-m);

    cout << min(n,x) << endl;

}

int main()
{
     long long t,n,m,i,j,k=0,kk=0,x,y,z=0,mn,mx;

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

     //cin >> t;

     //while(t--)
     solve();

}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.range, std.typecons, std.format;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.mutation;

void main()
{
    int[] input = readln.split.to!(int[]);
    int N = input[0];
    int M = input[1];
    Tuple!(int,int)[][] prefList;
    Tuple!(int, int)[] cityList;
    prefList.length = N;
    cityList.length = M;
    foreach(i; 0..M)
    {
        input = readln.split.to!(int[]);
        int cityIndex = input[0];
        int cityAge = input[1];
        cityList[i] = tuple!(int, int)(cityIndex-1, cityAge);
        prefList[cityIndex-1] ~= cityList[i];
    }

    int[Tuple!(int,int)] cityIDList;
    foreach(pref; prefList)
    {
        foreach(i,city; enumerate(pref.sort!((a,b)=>a[1]<b[1])()))
        {
            cityIDList[city] = cast(int)i;
        }
    }
    foreach(i; 0..cityList.length)
    {
        writeln("%06d%06d".format(cityList[i][0]+1, cityIDList[cityList[i]]+1));
    }
}


Measured memory_bytes: 27644
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    int d = 0;
    rep(i, 7)
    {
        if (n < pow(10, i))
        {
            d = i;
            break;
        }
    }

    int c = 0;
    for (int i = 1; i < d + 1; ++i)
    {
        if (i % 2 == 0)
            continue;
        if (i == d)
        {
            c += n - pow(10, i - 1) + 1;
            break;
        }
        c += pow(10, i) - pow(10, i - 1);
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
 
using namespace std;
 
const int64_t MAX_N = 500001;
 
char S[MAX_N];
 
void Main() {
  int64_t ans = 0;
  int64_t i = 0;
 
  bool desc = (S[0] == '>');
  int64_t up = 0;
  int64_t down = 0;
 
  while (S[i] != '\0') {
    if (S[i] == '>') {
      if (!desc) {
        ans += up * (up - 1) / 2;
//        printf("%d\n", ans);
 
        desc = true;
        down = 0;
      }
      down++;
    } else {
      if (desc) {
        ans += down * (down - 1) / 2;
        ans += max(down, up);
//        printf("%d\n", ans);
 
        desc = false;
        up = 0;
      }
      up++;
    }
//    printf("%c\n", S[i]);
    i++;
  }
  if (desc) {
    ans += down * (down - 1) / 2;
    ans += max(down, up);
  } else {
    ans += up * (up + 1) / 2;
  }
  cout << ans << endl;
}
 
int main() {
  std::cout << std::fixed << std::setprecision(15);
  cin >> S;
  Main();
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, k, a[100008], aa[100008], ra[100008], b[100008];
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> k;
	rep(i, 1, n){cin >> a[i];}
	aa[0] = 0;
	rep(i, 1, n){aa[i] = aa[i-1]+max(a[i], 0LL);}
	ra[n+1] = 0;
	rrep(i, n, 1){ra[i] = ra[i+1]+max(a[i], 0LL);}
	b[0] = 0;
	rep(i, 1, n){b[i] = b[i-1]+a[i];}
	
	ll ans = 0;
	rep(i, 0, n-k){
		ll tmp = aa[i]+max(b[i+k]-b[i], 0LL)+ra[i+k+1];
		ans = max(tmp, ans);
	}
	
	print(ans)
	return 0;
}

Measured memory_bytes: 3328
targetS = list(input())
targetS_r = list(reversed(targetS))
targetS_1 = []
targetS_2 = []
for target_list in range(int(len(targetS) / 2)):
    targetS_1.append(targetS[target_list])
    targetS_2.append(targetS_r[target_list])
count = 0
for target_list in range(int(len(targetS_1))):
    if targetS_1[target_list] != targetS_2[target_list]:
        count = count + 1
print(count)


Measured memory_bytes: 3060
#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int N,M;
string s;
int main(){
  while(1){
    cin >> N;
    if(!N) break;
    cin >> M;
    cin >> s;
    int co=0;
    int res=0;
    for(int i=0;i<(int)s.size();i++){
      if(s[i]=='I' && s[i+1]=='O' && s[i+2]=='I'){
	co++;
	i++;
      } else {
	res+=max(0,(co-N+1));
	co=0;
      }
    }
    res+=max(0,(co-N+1));
    cout << res << "\n";
  }
}

Measured memory_bytes: 2104
from collections import defaultdict
import sys
input = sys.stdin.readline

#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

def main():
    mod = 10**9+7
    n = int(input())
    a = tuple(map(int,input().split()))

    pr = primes(10**3+1)

    d = defaultdict(lambda : 0)

    for elt in a:
        for p in pr:
            if elt < p:
                break
            c = 0
            while not elt%p:
                c += 1
                elt //= p
            if c > d[p]:
                d[p] = c
        if elt > 1 and d[elt] == 0:
            d[elt] = 1

    lcm  = 1
    for elt in d:
        lcm = lcm*pow(elt,d[elt],mod)%mod

    res = 0
    for e in a:
        res = (res + pow(e,mod-2,mod))%mod
    print(res*lcm%mod)

if __name__ == '__main__':
    main()



Measured memory_bytes: 43376
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)




void solve(){
  int n,m;
  cin >> n >> m;
  int x[m+10];
  rep(i,m){
    cin >> x[i]; 
  }
  sort(x,x+m);
  int y[m+10];
  rep(i,m-1){
     y[i] = x[i+1] - x[i];
  }
  sort(y,y+m-1);
  int sum=0;
  if(m>n){
  rep(i,m-n){
    sum += y[i]; 
  }
  }
  cout << sum << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ii pair<int, int>
#define dd pair<double, double>
#define pb(i) push_back(i)


int dir1[4] = {0, 0, 1, -1};
int dir2[4] = {1, -1, 0, 0};
 
int n;
vector< set<ii> > p;
vector<vector<int> > adj;
vector<bool> visited;
vector<int> dist;
 
void bfs(int u){
    int ind = u;
    int i, j;
 
    fill(visited.begin(), visited.end(), false);
    visited[u] = true;
 
    fill(dist.begin(), dist.end(), -1);
    dist[u] = 0;
 
    queue<int> q;
    q.push(u);
    while(!q.empty()){
        u = q.front();
        q.pop();
 
        for(i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i];
            if(!visited[v])
            {
                visited[v] = true;
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
 
    for(int i = 1; i <= n; i++)
        if(dist[i] != -1)
        {
            int a = ind, b = i;
            if(a > b)
                swap(a, b);
            p[dist[i]].insert(ii(a, b));
        }
}
 
int main(){
    int i, j;
 
    int x, y;
    cin >> n >> x >> y;
 
    adj.resize(n+5);
    for(i = 1; i < n; i++){
        adj[i].pb(i+1); 
        adj[i+1].pb(i);
    }
 
    adj[x].pb(y);
    adj[y].pb(x);
 
    p.resize(n+5);
    dist.resize(n+5);
    visited.resize(n+5);
    for(i = 1; i <= n; i++)
        bfs(i);
    
 
    for(i = 1; i < n; i++)
        cout << p[i].size() << '\n';
    
 
}

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

int main() {
	
	int n;
	cin >> n;
	
	vector<long long> v(n);
	for(int i = 0; i < n; ++i){
		cin >> v[i];
	}
	
	
	set<long long> st;
	for(int i = 0; i < (1 << n); ++i){
		int tmp = i;
		int cnt = 0;
		long long sum = 0;
		while(tmp > 0){
			if(tmp % 2 == 1){
				sum += v[cnt];
			}
			tmp >>= 1;
			cnt++;
		}
		st.insert(sum);
	}
	
	int m;
	cin >> m;
	
	for(int i = 0; i < m; ++i){
		long long num;
		cin >> num;
		if(st.find(num) != st.end()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3108
H, W = map(int, input().split())
A = []
flags = []
for _ in range(H):
    A.append(list(input()))
    flags.append([False] * W)
x, y = 0, 0
flags[0][0] = True
while True:
    nx1, ny1 = x + 0, y + 1
    nx2, ny2 = x + 1, y + 0
    if x == W - 1 and y == H - 1:
        break
    if x == W - 1:
        if A[ny1][nx1] == '#':
            x, y = nx1, ny1
        else:
            print('Impossible')
            exit()
    elif y == H - 1:
        if A[ny2][nx2] == '#':
            x, y = nx2, ny2
        else:
            print('Impossible')
            exit()
    else:
        if A[ny1][nx1] == '#' and A[ny2][nx2] == '.':
            x, y = nx1, ny1
        elif A[ny1][nx1] == '.' and A[ny2][nx2] == '#':
            x, y = nx2, ny2
        else:
            print('Impossible')
            exit()
    flags[y][x] = True
# print(*flags, sep='\n')
for x in range(W):
    for y in range(H):
        if A[y][x] == '#' and not flags[y][x]:
            print('Impossible')
            exit()
print('Possible')

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

using namespace std;

const int MAX_N = 1e5 + 10;

int n, m;
vector <int> G[MAX_N];
bool vis[MAX_N];
vector <int> topo;

void dfs (int u) {
  vis[u] = true;
  for (int v: G[u]) if (not vis[v]) dfs(v);
  topo.push_back(u);
}

int main () {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
  }
  for (int u = 1; u <= n; u++) G[0].push_back(u);
  dfs(0);
  vector <int> dp(n + 1, 0);
  reverse(begin(topo), end(topo));
  for (int u: topo) {
    for (int v: G[u]) {
      dp[v] = max(dp[v], dp[u] + 1);
    }
  }
  cout << *max_element(begin(dp), end(dp)) - 1 << endl;
  return (0);
}


Measured memory_bytes: 9208
# -*- coding: utf-8 -*-
x,n = list(map(int,input().split()))
p = list(map(int,input().split()))

p.sort()
inf=float("inf")
min_dif =inf
ret=None

for i in range(102):
    if i in p:
        continue
    if abs(x-i)<min_dif:
        min_dif=abs(x-i)
        ret=i

print(ret)

Measured memory_bytes: 9188
n = int(input())
A = list(map(int, input().split()))
one = [0 for _ in range(60)]

for a in A:
    for i in range(60):
        if a & 1 << i:
            one[i] += 1
ans = 0
for a in A:
    n -= 1
    if n == 0:
        break
    for i in range(60):
        if a & 1 << i:
            one[i] -= 1

    for i in range(60):
        if a & 1 << i:
            ans += (1 << i) * (n - one[i])
        else:
            ans += (1 << i) * one[i]

print(ans % 1000000007)

Measured memory_bytes: 125624
'use strict'

function main (s) {
  let start = 0
  let end = s.length - 1
  let sArray = s.split('')
  while (sArray[start] !== 'A') {
    start++
  }
  while (sArray[end] !== 'Z') {
    end--
  }
  let len = end - start + 1
  console.log(len)
}

function doMain () {
  let input = ''
  process.stdin.resume()
  process.stdin.setEncoding('utf8')
  process.stdin.on('data', (chunk) => {
    input += chunk
  })
  process.stdin.on('end', () => {
    input = input.trim()
    main(input)
  })
}

doMain()


Measured memory_bytes: 9592
void main() {
	auto S = rs;
	if(S.uniq.array.length == 1) writeln("No");
	else writeln("Yes");
}

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

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256