akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main(void){
  double output=0;
  int N;

  if(scanf("%d",&N) != 1){
    printf("*****SCANF ERROR*******\n");
    exit(1);
  }
  for(int i=1;i<=N;i++){
    if((i%3!=0) & (i%5!=0)) output+=(double)i;
  }
  printf("%.0f",output);
  
  return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string blue[n];
    for (int i=0;i<n;i++) 
	{
      cin>>blue[i];
    }
    int m;
    cin>>m;
    string red[m];
    for (int i=0;i<m;i++) 
	{
      cin >> red[i];
    }
    int ans=0;
    for (int i=0;i<n;i++)
	{
		string word=blue[i];   
		int count=0;
		for (int j=0;j<n;j++)
		{
			if (blue[j]==word) 
			count++;
		}
		for (int j=0; j<m; j++)
		{
			if (red[j]==word) 
			count--;
		}
		ans=max(ans, count);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import sys
import math as mt
input=sys.stdin.buffer.readline  
#t=int(input())
mod=10**9+7
t=1
for __ in range(t):
    
    x,n=map(int,input().split())
    l=[0]*103
    #n=int(input())
    #a=[[0 for j in range(m)] for i in range(n)]
    p=list(map(int,input().split()))

    for i in range(n):
        l[p[i]]=1
    mini=abs(x)
    ans=0
    #print(l)
    for i in range(102):
        if l[i]==0:
            if abs(x-i)<mini:
                mini=abs(x-i)
                
                ans=i
        
    print(ans)        

Measured memory_bytes: 61932
#include<iostream>
using namespace std;
int main()
{
  int n,k;cin>>n>>k;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
  }
  n--,k--;
  int res=n/k;
  if(n%k!=0)res++;
  cout<<res;
  return 0;
}

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

using namespace std;
using ll = long long;

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

	vector<int> d(N, 0);
	for (int i = 1; i < N; ++i) {
		if ((s[i] == 'C') && (s[i - 1] == 'A')) { ++d[i]; }
	}
	for (int i = 1; i < N; ++i) { d[i] += d[i - 1]; }

	for (int i = 0; i < Q; ++i) {
		cout << d[r[i] - 1] - d[l[i] - 1] << endl;
	}

	return 0;
}



Measured memory_bytes: 2176
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	ll A, B;
	cin >> A >> B;
	A--; B--;
	cout << A * B << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;

int factor(State &begin);

int number(State &begin)
{
	int ret = 0;

	while(isdigit(*begin))
	{
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}

	return  ret;
}

int term(State &begin)
{
	int ret = factor(begin);
	while(true)
	{
		if(*begin == '*')
		{
			begin++;
			ret *= factor(begin);
		}
		else if(*begin == '/')
		{
			begin++;
			ret /= factor(begin);
		}
		else
		{
			break;
		}
	}

	return ret;
}

int expression(State &begin)
{
	int ret = term(begin);

	while(true)
	{
		if(*begin == '+')
		{
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-')
		{
			begin++;
			ret -= term(begin);
		}
		else
		{
			break;
		}
	}
	
	return ret;
}


int factor(State &begin)
{
	int ret;

	if(*begin == '(')
	{
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	{
		ret = number(begin);
	}

	return ret;
}


int main()
{
	int n;
	cin >> n;
	cin.ignore();
	while(n--)
	{
		string s;
		getline(cin,s);

		State begin = s.begin();
		int ans = expression(begin);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());

            int output = 0;
            string value = "357";

            while (true)
            {
                if (n < long.Parse(value)) break;
                if (isSuitable(value))
                {
                    output++;
                }
                value = nextnumber(value);
            }
            Console.WriteLine(output);
            ;
        }

        static bool isSuitable(string shichigosan)
        {
            if (shichigosan.Contains("3") && shichigosan.Contains("5") && shichigosan.Contains("7"))
                return true;
            else return false;

        }

        static string nextnumber(string shichigosan)
        {
            string output = shichigosan;

            if (shichigosan.Length == 0)
            {
                return "3";
            }
            if (shichigosan[shichigosan.Length - 1] == '3')
            {
                return output.Substring(0, output.Length - 1) + '5';
            }
            if (shichigosan[shichigosan.Length - 1] == '5')
            {
                return output.Substring(0, output.Length - 1) + '7';
            }
            if (shichigosan[shichigosan.Length - 1] == '7')
            {
                return nextnumber(output.Substring(0, output.Length -1 )) + '3';
            }
            return "";
        }

    }
}


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

using namespace std;

typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
  	cin >> n;
  	ll ans = 1000*1ll*INT_MAX;
  	for(ll i=1;i<=sqrt(n);i++){
  		if(n%i) continue;
  		ll j = n/i;
  		ans = min(ans,i+j-2);
	}
	cout << ans << "\n";
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx=1e5+100;
const int INF=99999999;
const int MOD=1e9+7;
int main()
{
    int n;
    ll a,sum[maxx*2]={0};
    cin>>n;
    sum[0]=0;
    for(int i=1; i<=n; i++){
        cin>>a;
        sum[i]=sum[i-1]+a;
    }
    ll minn=abs(sum[1]*2-sum[n]);
    for(int i=2; i<n; i++){
        minn=min(minn,abs(sum[i]*2-sum[n]));
    }
    cout<<minn<<endl;
    return 0;
}

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define G           \
    if (++ip == ie) \
        if (fread(ip = buf, 1, SZ, stdin))
using namespace std;
const int SZ = 1 << 19, N = 1e5 + 9, M = 2 * N;
char buf[SZ], *ie = buf + SZ, *ip = ie - 1;
inline int in()
{
    G;
    while (*ip < '-')
        G;
    int x = *ip & 15;
    G;
    while (*ip > '-')
    {
        x *= 10;
        x += *ip & 15;
        G;
    }
    return x;
}
int h[N], w[M],o, q[M], f[N], c[N], v[N];
int get(int y)
{
    if(y==f[y]) return y ; 
    return f[y]=get(f[y]);
}
void dfs(int n, int m)
{
    c[n] = m;
    for (int i = h[n]; i; i = w[i])
        if (q[i]!= f[n])
        {
            f[q[i]] = n;
            dfs(q[i], -m);
            c[n] += c[q[i]];
        }
}
int a, b, qq = 1, ww = 1, ans = 0;
int qw , wq;
int main()
{
    for (int i = 1; i <= 100000; ++i)
    {
        f[i] = i;
    }
    cin>>a>>b;
    for (int i = 1; i <= b; ++i)
    {
        cin>>qw>>wq;
        if (get(qw) != get(wq))
        {
            f[f[qw]] = f[wq];
        }
        else
        {
            qq = qw;
             ww = wq;
            continue;
        }
        o++;
        w[o] = h[qw];
        q[o] = wq;
        h[qw]=o;
        o++;
        w[o] = h[wq];
        q[o] = qw;
        h[wq]=o;
    }
    f[qq] = 0;
    dfs(qq, 1);
    if (a == b)
    {
        long long u=0;
        for (int i = ww; i; i = f[i])
        {
            u++;
            v[u] = c[i];
        }
        if (u % 2)
        {
            if (c[qq] % 2)
            {
                cout<<"-1";
                return 0;
            }
            for (int i = ww; i; i = f[i])
            {
                c[i] -= c[qq] / 2;
            }
        }
        else
        {
            if (c[qq])
            {
                cout<<"-1";
                return 0;
            }
            sort(v + 1, v + u + 1);
            for (int i = ww; i; i = f[i])
            {
                c[i] -= v[u / 2];
            }
        }
    }
    else if (c[qq])
    {
        cout<<"-1";
        return 0;
    }
    for (int i = 1; i <= a; ++i)
        ans += abs(c[i]);
    return cout << ans, 0;
}

Measured memory_bytes: 14424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int a, b;
  cin >> a >> b;
  int tmp = a+b;
  if (tmp%2) {
    puts("IMPOSSIBLE");
  } else {
    cout << tmp/2 << endl;
  }
  
}


Measured memory_bytes: 256
// AOJ 1089: Strawberry Cake
// 2017.12.18 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

#define N 100
#define D 0.01
#define EPS 1e-8

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } LINE;

PP a[21]; int n;

int dcmp(double x)
{
	if (fabs(x) < EPS) return 0;
	return x < 0 ? -1 : 1;
}

double cross(double ax, double ay, double bx, double by) { return ax*by - ay*bx; }

void lineIntersection(PP *p, LINE *a, PP *vs, PP *ve)
{
    double a1, a2;

	a1 = cross(ve->x  - vs->x, ve->y  - vs->y,
			   a->s.x - vs->x, a->s.y - vs->y);
	a2 = cross(ve->x  - vs->x, ve->y  - vs->y,
			   a->e.x - vs->x, a->e.y - vs->y);
	p->x = (a->s.x*a2 - a->e.x*a1) / (a2-a1);
	p->y = (a->s.y*a2 - a->e.y*a1) / (a2-a1);
}

int convex_cut(LINE *u, int n, PP *p, PP *po)
{
	int i, d1, d2, top = 0;

    for (i = 0; i < n; i++) {
        d1 = dcmp(cross(u->e.x - u->s.x, u->e.y - u->s.y,
						p[i].x - u->s.x, p[i].y - u->s.y));
        d2 = dcmp(cross(u->e.x - u->s.x, u->e.y - u->s.y,
				      p[i+1].x - u->s.x, p[i+1].y - u->s.y));
        if (d1 >= 0) po[top++] = p[i];
        if (d1*d2 < 0) lineIntersection(po + top++, u, p+i, p+i+1);
    }
	po[top] = po[0];
#if 0
printf("convex_cut %d\n", top);
for (i = 0; i < top; i++) printf("[%d] (%lf,%lf)\n", i+1, po[i].x, po[i].y);
#endif
	return top;
}

#if 0
double area(int n, PP *p)
{
	int i;
    double s = 0;

    for (i = 1; i < n-1; i++) {
        s += cross(p[i].x-p[0].x, p[i].y-p[0].y, p[i+1].x-p[0].x, p[i+1].y-p[0].y);
    }
    return fabs(s) / 2;
}
#endif

double area(int n, PP *pp)
{
   int i;
   double s;

   for (s = 0, i = 0; i < n; i++) {
      s += (pp[i].x - pp[i+1].x) * (pp[i].y + pp[i+1].y);
   }
   return fabs(s)/2;
}

double calc(double x, double s)
{
	int k;
	PP b[30];

	LINE u;
	u.s.x = u.s.y = 0;
	u.e.x = 128*cos(x), u.e.y = 128*sin(x);
	k = convex_cut(&u, n, a, b);
	return area(k, b) / s;
}

int main()
{
	int i, x, y;
	double s, s1, s2, l, r, m;

	while(scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) {
			scanf("%d%d", &x, &y);
			a[i].x = x, a[i].y = y;
		}
		a[n] = a[0];
		s = area(n, a);

		l = 0, r = D, s1 = calc(0, s);
		for ( ; ; l+=D, r+=D, s1 = s2) {
			s2 = calc(r, s);
			if (s1 <= 0.5 && s2 >= 0.5) {
				i = N; while (i--) {
					m = (l+r)/2;
					if (calc(m, s) <= 0.5) l = m; else r = m;
				}
				break;
			}
		}
		printf("%.15lf %.15lf\n", 128*cos(m), 128*sin(m));
	}
	return 0;
}

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

int lcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  } else {
    return lcd(b, a % b);
  }
}


int main() {
  int N, K;
  cin >> N;
  int result = pow(N, 3);
  cout << result << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define FOR(i, a, b) for(int i=(int)a; i<(int)b; i++)
#define ndl "\n";
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define inrep int t; cin >> t; for(int tc=1; tc<=t; tc++)
#define debug cout << "THIS - PART - HAS - BEEN - REACHED" << ndl;
inline int lcm(int a, int b) {return a/__gcd(a, b)*b;}
inline void out() {cout <<  ndl;}
template <class T> inline void in(T &a) {cin >> a;}
template <class T> inline void in(T &a, T &b) {cin >> a >> b;}
template <class T> inline void out(T a) {cout << a << ndl;}
template <class T> inline void out(T a, T b) {cout << (a) << " " << (b) << ndl;}
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e6+7;
const int LOGN = log(N) + 2;
const int MOD = 1e9+7;

int main()
{
	ios;
	map <LL, LL> m;
	LL n; in(n);
	FOR(i, 0, n) {
		LL x; in(x);
		m[x]++;
	}
	LL maxi1 = INT_MIN, maxi2 = INT_MIN;
    for (auto &i : (m)) {
    	if (i.sc >= 2) {
    		maxi2 = maxi1;
    		maxi1 = i.fi;
    		if (i.sc >= 4) {
    			maxi2 = i.fi;
    		}
    	}
    }
    if (maxi1 == INT_MIN || maxi2 == INT_MIN) {
    	out(0);
    }
    else out(maxi1 * maxi2);
	return 0;
}

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



int main() {
  int N, D, X; cin >> N >> D >> X;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i];

  int cnt = 0;

  for(int i=0; i<N; i++){
    for(int j=0; j*A[i]+1<=D; j++){
      cnt++;
    }
  }

  cout << cnt + X << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

ll standardize(ll &t) {
    t *= 2;
    t--;
}


int main() {
    ll N, C;
    cin >> N >> C;
    vector<vector<ll>> ss(C, vector<ll>{}), ts(C, vector<ll>{});

    for (auto &&i: boost::irange(0LL, N)) {
        ll s, t, c;
        cin >> s >> t >> c;
        standardize(s);
        standardize(t);
        c--;
        ss.at(c).emplace_back(s);
        ts.at(c).emplace_back(t);
    }
    for (auto &&c: boost::irange(0LL, C)) {
        sort(ss.at(c).begin(), ss.at(c).end());
        sort(ts.at(c).begin(), ts.at(c).end());
    }
    vector<vector<ll>> ss_true(C, vector<ll>{});
    vector<vector<ll>> ts_true(C, vector<ll>{});
    for (auto &&c: boost::irange(0LL, C)) {
        for (auto &&i: boost::irange(0LL, (ll)ss.at(c).size())) {
            if (i == 0) {
                ss_true.at(c).emplace_back(ss.at(c).at(i)-1);
            } else{
                if (ss.at(c).at(i) != ts.at(c).at(i-1)){
                    ts_true.at(c).emplace_back(ts.at(c).at(i-1));
                    ss_true.at(c).emplace_back(ss.at(c).at(i)-1);
                }
            }
            if (i == ((ll)ss.at(c).size()-1)){
                ts_true.at(c).emplace_back(ts.at(c).at(i));
            }
        }
    }
//    for (auto &&c: boost::irange(0LL, C)){
//        cout << "channel: " << c << " ss_true: " << ss_true.at(c).size() << " ts_true: " << ts_true.at(c).size() << endl;
//    }
//
//    for (auto &&c: boost::irange(0LL, C)){
//        cout << "channel: " << c << endl;
//        for (auto &&i: boost::irange(0LL, (ll)ss_true.at(c).size())){
//            cout << "start: " << ss_true.at(c).at(i) << " end: " << ts_true.at(c).at(i) << endl;
//        }
//    }

    constexpr ll max_t = 200000;
    vector<ll> acc(max_t, 0);
    for (auto &&c: boost::irange(0LL, C)){
        for (auto &&i: ss_true.at(c)){
            acc.at(i)++;
        }
        for (auto &&i: ts_true.at(c)){
            acc.at(i)--;
        }
    }
    for (auto &&i: boost::irange(1LL, max_t)){
        acc.at(i)+=acc.at(i-1);
    }
    cout << *max_element(acc.begin(), acc.end()) << endl;
    return 0;
}

Measured memory_bytes: 5888
program main
  implicit none
  integer::N,Z,W
  integer,allocatable,dimension(:)::a
  read*,N,Z,W
  allocate(a(N))
  read*,a
  print"(i0)",merge(abs(a(N)-W),max( abs(a(N)-W), abs(a(N-1)-a(N)) ),N==1)
end program main

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a<b)
  {
    for(int i=0;i<b;i++)
      cout<<a;
  }  
  else
  {
    for(int i=0;i<a;i++)
      cout<<b;
  } 
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func countR(s string, n int) (ret int) {
  for i := n; i >= 0; i-- {
    if s[i] != 'R' {
      return
    }
    ret++
  }
  return
}

func countL(s string, n int) (ret int) {
  for i := n; i < len(s); i++ {
    if s[i] != 'L' {
      return
    }
    ret++
  }
  return
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := bufio.NewScanner(stdin)

	/* 入力バッファが大きくなるならこれ */
	buf := make([]byte, 1000000)
	sc.Buffer(buf, 1000000)

	sc.Scan()
  s := sc.Text()

  for i := 0; i < len(s); i++ {
    if s[i] == 'R' {
      if s[i + 1] == 'L' {
        fmt.Print((countR(s, i) + 1) / 2 + countL(s, i + 1) / 2)
      } else {
        fmt.Print(0)
      }
    } else {
      if s[i - 1] == 'R' {
        fmt.Print((countL(s, i) + 1) / 2 + countR(s, i - 1) / 2)
      } else {
        fmt.Print(0)
      }
    }
    fmt.Print(" ")
  }
  fmt.Println()

	/* 出力用 */
	_, _ = fmt.Fprintf(stdout, "")
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}


Measured memory_bytes: 3456
N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))

dp = [10 ** 10] * (N+1)
dp[1] = 0

for i in range(1, N+1):
    for j in range(1, K+1):
        if i + j > N:
            continue
        dp[i+j] = min(dp[i+j], dp[i] + abs(H[i+j] - H[i]))

print(dp[N])

Measured memory_bytes: 52960
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(i, name)in(i)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(i,v) for(auto &i:(v))
#define all(v) (v).begin(),(v).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, M);
  VEC(int, A, M);
  int ans = N;
  rep(i, 0, M) {
    ans -= A[i];
  }
  print(max(ans, -1));
}


Measured memory_bytes: 3700
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var N = cin.Nextint;
        var A = cin.Scanlong;

        var M = (long)N * (N + 1) / 2;
        if(A.Sum() % M != 0)
        {
            WriteLine("NO");
            return;
        }

        var k = A.Sum() / M;
        long cnt = 0;
        for (int i = 0; i < N; i++)
        {
            var d = A[(i + 1) % N] - A[i];
            d -= k;
            if (d % N != 0 || d > 0)
            {
                WriteLine("NO");
                return;
            }
            cnt += -d / N;
        }
        WriteLine((cnt == k) ? "YES" : "NO");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 12632
n,m=map(int,input().split())

info=[list(map(int,input().split())) for i in range(m)]

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

ans=0
for i in range(2**n):
  tmp=0
  f=1
  for mm in range(m):
    tmp=0
    for j in info[mm][1:]:
      tmp+=int(str(format(i,'b').zfill(n))[int(j)-1])
    if tmp%2!=p[mm]:
      f=0
  if f==1:
    ans+=1
print(ans)


Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MAXN = 5e5 + 100;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

template<class T> struct BIT{
	vector<T> bit;
	BIT(){
		bit.assign(MAXN, 0);
	}
	void update(int ind, T delta){
		for(; ind < MAXN; ind += (ind & (-ind))){
			bit[ind] += delta;
			if(!ind) break;
		}
	}
	T query(int ind){
		T sum = 0;
		for(; ; ind -= (ind & (-ind))){
			sum += bit[ind];
			if(ind <= 0) break;
		}
		return sum;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	string s;
	cin >> s;
	BIT<int> bit1[26];
	rep(i, s.size()) bit1[s[i] - 'a'].update(i, 1);
	int q;
	cin >> q;
	rep(j, q){
		int t;
		cin >> t;
		if(t == 1){
			int pos;
			char c;
			cin >> pos >> c;
			pos--;
			bit1[s[pos] - 'a'].update(pos, -1);
			s[pos] = c;
			bit1[s[pos] - 'a'].update(pos, 1);
		}
		else{
			int l, r;
			cin >> l >> r;
			int ans = 0;
			l -= 2, r--;
			rep(i, 26){
				ans += (((bit1[i].query(r) - (l >= 0 ? bit1[i].query(l) : 0))) > 0);
			}
			cout << ans << endl;
		}
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 51868
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define coc g[node][i]
#define N 1000005
using namespace std;

int n, m, u, v, vis[N];
vector < int > g[N], ans;
deque < int > q;

void git(int node, int par){
	vis[node] = 1;
	ans.pb(node);
	for(int i = 0; i < g[node].size(); i++)
		if(coc != par and !vis[coc]){
			git(coc, node);
			break;
		}
}

// bool bastir(int node, int par){}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&m);
	for(int i = 1; i <= m; i++){
		scanf("%d %d",&u ,&v);
		g[u].pb(v);
		g[v].pb(u);
	}
	u = 1;
	v = 0;
	q.push_front(1);
	bool f = 1;
	vis[1] = 1;
	while(f){
		f = 0;
		for(int i = 0; i < g[u].size(); i++)
			if(!vis[g[u][i]]){
				f = 1;
				vis[g[u][i]] = 1;
				if(v == 0)
					v = u;
				// cout << u << " dan " << g[u][i] << endl;
				u = g[u][i];
				q.push_front(u);
				break;
			}
		for(int i = 0; i < g[v].size(); i++)
			if(!vis[g[v][i]]){
				f = 1;
				vis[g[v][i]] = 1;
				// cout << v << " dan " << g[v][i] << endl;
				v = g[v][i];
				q.push_back(v);
				break;
			}
		// cout << u << " " << v << endl;
	}
	printf("%d\n", (int)q.size());
	while(!q.empty()){
		printf("%d ", q.front());
		q.pop_front();
	}
	return 0;
}

Measured memory_bytes: 28884
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int n, place_sa, x, y;
  int flag = 1;

  scanf("%d", &n);
  
  int zahyou[3*(n + 1)];
  
  for(int i = 0; i < 3; i++){
    zahyou[i] = 0;
  }

  for(int i = 1; i <= n; i++){
    scanf("%d %d %d", &zahyou[3*i+0], &zahyou[3*i+1], &zahyou[3*i+2]);
  }
  
  for(int i = n; i > 0; i--){
    place_sa = zahyou[3*i+0] - zahyou[3*(i - 1)+0];
    x = zahyou[3*i+1] - zahyou[3*(i - 1)+1];
    if(x < 0) {
        x = -x;
        }
    y = zahyou[3*i+2] - zahyou[3*(i - 1)+2];

    if(y < 0){ 
        y = -y;
        }
    if((place_sa % 2) != ((x + y) % 2) || (x + y) > place_sa){
      flag = 0;
      break;
    }
  }
  if(flag == 1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <array>
#include <cmath>
#include <random>
#include <functional>
#include <climits>
#include <iomanip>
using namespace std;
using lint=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  bool f1=false,f2=false;
  cin>>s;
  if(stoi(s.substr(2,3))>0&&stoi(s.substr(2,3))<13) {
    //cout<<stoi(s.substr(2,3))<<"\n";
    f1=true;
  }
  if(stoi(s.substr(0,2))>0&&stoi(s.substr(0,2))<13) {
    //cout<<stoi(s.substr(0,2))<<"\n";
    f2=true;
  }
  cout<<(f1&&f2 ? "AMBIGUOUS" : f1 ? "YYMM" : f2 ? "MMYY" : "NA")<<endl;
  return 0;
}


Measured memory_bytes: 256
def solve(string):
    n, *x = map(int, string.split())
    mid = n // 2
    l, r = sorted(x)[mid - 1:mid + 1]
    return "\n".join([str(r) if _x < r else str(l) for _x in x])


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 30528
#include <bits/stdc++.h>
using ll = long long;

bool ba[4003];

int main() {
    using std::cin;
    using std::cout;
    using std::endl;
    using std::min;
    using std::max;
    using std::vector;
    using std::string;
    using std::fill;
    int n;
    cin >> n;
    string s;
    cin >> s;


    fill(ba,ba+4003,false);
    for(int i=0; i<n; i++){
        ba[i]=(s[i]=='B');
    }

    vector<int> r,g,b;
    for(int i=0; i<n; i++){
        if(s[i]=='R') r.push_back(i);
        if(s[i]=='G') g.push_back(i);
        if(s[i]=='B') b.push_back(i);
    }

    int rs = r.size();
    int gs = g.size();
    int bs = b.size();

    ll sum = rs * (long long)gs * bs;
    for(int i=0; i<rs; i++){
        for(int j=0; j<gs; j++){
            int ri = r.at(i);
            int gj = g.at(j);
            int mx = max(ri,gj);
            int mn = min(ri,gj);
            int df = mx-mn;
            if(mx+df<n && ba[mx+df])sum--;
            if(df%2==0 && ba[(ri+gj)/2])sum--;
            if(mn-df>=0 && ba[mn-df])sum--;
        }
    }

    cout << sum << endl;
    return 0;
}



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

const int len = 1005, mod = 1e9+7;
int per[len], inv[len], dp[len][len];

int add(int a, int b){
    return (a+b)%mod;
}

int mul(int a, int b){
    return (a*1LL*b)%mod;
}

int po(int a, int b){
    if (b == 0)
        return 1;
    if (b%2 == 0)
        return po(mul(a, a), b/2);
    return mul(a, po(mul(a, a), b/2));
}

int main(){
    int n, a, b, c, d;
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);

    per[0] = inv[0] = 1;
    for (int i = 1; i <= n; i++){
        per[i] = mul(per[i-1], i);
        inv[i] = po(per[i], mod-2);
    }

    dp[a-1][0] = 1;
    for (int x = a; x <= b; x++){
        for (int i = 0; i <= n; i++){
            int cur = 1;
            for (int j = 1; j < c && j*x <= i; j++){
                cur = mul(cur, per[i-(j-1)*x]);
                cur = mul(cur, inv[i-j*x]);
                cur = mul(cur, inv[x]);
            }

            dp[x][i] = dp[x-1][i];
            for (int j = c; j <= d && j*x <= i; j++){
                cur = mul(cur, per[i-(j-1)*x]);
                cur = mul(cur, inv[i-j*x]);
                cur = mul(cur, inv[x]);

                //printf("x = %d, i = %d, j = %d, cur = %d\n", x, i, j, cur);

                dp[x][i] = add(dp[x][i], mul(mul(cur, inv[j]), dp[x-1][i-j*x]));
            }

            //printf("dp(%d, %d) = %d\n", x, i, dp[x][i]);
        }
    }

    printf("%d\n", dp[b][n]);
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    cins(all(a));
    ll ans = 0;
    rep(i,n) ans = gcd(ans,a[i]);
    bool ok = 0;
    rep(i,n){
        if (a[i] < k) continue;
        if ((a[i]-k)%ans == 0) ok = 1;
    }
    if (ok) PRINT("POSSIBLE");
    else PRINT("IMPOSSIBLE");
}


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

int main(void){
    int x,a;
    cin >> x >> a;
    if(x<a){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    int N;
    string s;
    bool Four=false;
    string out;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> s;
        if (s=="Y") Four =true;
    }
    out = (Four)? "Four" : "Three";
    cout << out << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == x:
                ans += 1
print(ans)

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

typedef long long ll;
ll N,A;

ll mul(ll a,ll b){
	if(a>=((ll)1e18-1)/b+1)return (ll)1e18;
	return min((ll)1e18,a*b);
}

ll power(ll a,ll x){
	ll ans=1;
	for(;x;x>>=1,a=mul(a,a))if(x&1)ans=mul(ans,a);
	return ans;
}

int main(){
	cin>>N>>A;
	ll ans=N;
	for(int k=1;k<=40;++k)
		for(int i=0;i<=k;++i){
			ll l=1,r=N;
			while(l<r){
				ll mid=l+r>>1;
				if(mul(power(mid,i),power(mid+1,k-i))>=N)r=mid;
				else l=mid+1;
			}
			ans=min(ans,A*(k-1)+l*k+k-i);
		}
	cout<<ans;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    long k =sc.nextLong()-1;
    int st=0;
    while(s.length()>st&&s.charAt(st)=='1'){
      st++;
    }
    if(k<st || s.length()==st){
      System.out.println(1);
    }else{
      System.out.println(s.charAt(st));
    }
  }
}

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

#define N_MAX   (100000)

typedef long long ll;

int main()
{
    // 整数の入力
    int N , Y;
    cin >> N >> Y ;
    int x, y, z;
    bool isans = false;
    for (x = 0; x <= N; x++) {
        int result = 0;
        for (y = N - x; y >= 0; y--) {
            z = N - x - y;
            result = 10000 * x + 5000 * y + 1000 * z;
            if (result == Y) {
                isans = true;
                break;
            }
            result = 0;
        }
        if (isans) {
            break;
        }
    }

    if (!isans) {
        cout << -1 << " " << -1 << " "<< -1 << endl;
    } else {
        cout << x << " " << y << " "<< z << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<VB> VVB;

int main(void){
	short N;
	char flag;
	cin >> N;
	VVI A(N,VI(N));
	VVB E(N,VB(N,true));

	REP(i,N) REP(j,N) cin >> A[i][j];

	REP(i,N){
		FOR(j,i+1,N){
			flag = 0;
			REP(k,N){
				if (i == k || j == k) continue;
				if (A[i][j] > A[i][k] + A[k][j]){
					cout << "-1" << endl;
					exit(0);
				}
				else {
					if (A[i][j] == A[i][k] + A[k][j]){
						flag = 1;
						E[i][j] = E[j][i] = false;
					}
				}
			}
		}
	}
	LL ans = 0;

	REP(i,N){
		REP(j,N){
			if (E[i][j]) ans += A[i][j];			
		}
	}

	cout << ans/2 << endl;

	return 0;
}

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

using namespace std;

using Weight=int;
struct Edge{
    int src,dst;
    Weight weight;
    Edge(int src,int dst,Weight weight):
    src(src),dst(dst),weight(weight){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else if(e.src!=f.src)return e.src<f.src;
    else return e.dst<f.dst;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;

using Array=vector<Weight>;
using Matrix=vector<Array>;

pair<Weight,Edges>prim(const Graph &g,int s){
    int n=g.size();
    Edges tree;
    Weight total=0;
    vector<int>visited(n,0);
    priority_queue<Edge>q;
    q.emplace(-1,s,0);
    while(!q.empty()){
        Edge e=q.top();q.pop();
        if(visited[e.dst])continue;
        tree.push_back(e);
        total+=e.weight;
        visited[e.dst]=true;
        for(auto f:g[e.dst]){
            if(!visited[f.dst])q.push(f);
        }
    }
    return pair<Weight,Edges>(total,tree);
}

int main(){
    int v,e;cin>>v>>e;
    Graph g(v);
    for(int i=0;i<e;++i){
        int s,t,w;cin>>s>>t>>w;
        g[s].emplace_back(s,t,w);
        g[t].emplace_back(t,s,w);
    }
    cout<<prim(g,0).first<<endl;
    return 0;
}

Measured memory_bytes: 8704
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  2 20:06:44 2018

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

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

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
"""

S = input()

len_S = len(S)
s_list = []

for n in range(len_S):
    s_list.append(int(S[n]))

min753 = 10000

for n in range(len_S-2):
    temp_diff = abs(100*s_list[n] + 10*s_list[n+1] + s_list[n+2] - 753)
    if temp_diff < min753:
        min753 = temp_diff
        if min753 == 0:
            break
        

print(min753)
  


Measured memory_bytes: 24476
n, m = map(int, raw_input().split())

mp = [[0]*n for _ in xrange(n)]

for idx in xrange(m):
    a, b = map(int, raw_input().split())
    mp[a-1][b-1] += 1
    mp[b-1][a-1] += 1

for idx in range(n):
    print sum(mp[idx])


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mx 200005
#define fr first
#define se second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
struct hello
{
    int first,second,third;
}coin[100005];
ll dp[100005][3];
ll DP2[105][100005];
ll n,k;
ll func(ll i, ll who)
{
    if(i>n) return 0;
    if(dp[i][who]!=-1) return dp[i][who];
    int ans1=0,ans2=0,ans3=0;
    if(who == 0){
        ans1+=coin[i].first+func(i+1,1);
        ans2+=coin[i].second+func(i+1,2);
        ans3+=coin[i].third+func(i+1,3);
    }
    else if(who == 1){
        ans1+=coin[i].second+func(i+1,2);
        ans2+=coin[i].third+func(i+1,3);
    }
    else if(who == 2){
        ans1+=coin[i].first+func(i+1,1);
        ans3+=coin[i].third+func(i+1,3);
    }
    else if(who == 3){
        ans1+=coin[i].first+func(i+1,1);
        ans2+=coin[i].second+func(i+1,2);
    }
    return dp[i][who] = max({ans1,ans2,ans3});
}

int main()
{
   fast;
   cin >> n;
   memset(dp,-1,sizeof dp);
   for(ll i=1; i<=n; i++) cin >> coin[i].first >> coin[i].second >> coin[i].third;
   cout << func(1,0) << "\n";
   return 0;
}


Measured memory_bytes: 11776
# include <iostream>
# include <cmath>
# include <vector>
# include <algorithm>
# include <string>
# include <set>
# include <map>
# include <bitset>
# include <queue>

# define FILE
using namespace std;

int main()
{
    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif // FILE
    ios_base::sync_with_stdio( false );

    int n, k, m; cin >> n >> k >> m;
    int cnt[101111] = {};
    for( int i = 1; i <= m; i ++ ){
        int a; cin >> a;
        cnt[a] ++;
    }
    for( int i = 1; i <= n; i ++ ){
        if( m - cnt[i] >= k )cout << "No";
        else cout << "Yes";
        cout << endl;
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second

const int maxn = 212345;

int n;
ll a[maxn], ans[2][maxn];
int to[maxn];

set<int> s;

inline int upd(int idx, int now) {
    if (to[idx] >= now) {
        to[idx] -= now;
        return -1;
    }
    return now - to[idx];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 2, n) if (a[i] >= 4 * a[i - 1]) {
            s.insert(i);
            ll tmp = a[i - 1];
            while (tmp * 4 <= a[i]) tmp *= 4, to[i]++;
        }
    ROF(i, n - 1, 1) {
        if (a[i] > a[i + 1]) {
            int now = 0;
            ll tmp = a[i + 1];
            while (tmp < a[i]) tmp *= 4, now++;
            vector<int> buff;
            int pre = i + 1;
            for (auto it = s.lower_bound(i + 1); it != s.end(); ++it){
                int idx = *it;
                assert(idx > i);
                ans[0][i] += now * ll(idx - pre);
                now = upd(idx, now);
                pre = idx;
                if (now == -1) break;
                buff.pb(idx);
            }
            if (now != -1) ans[0][i] += ll(n - pre + 1) * now;
            for (int it : buff) s.erase(it);
        }
        ans[0][i] = ans[0][i] * 2 + ans[0][i + 1];
    }
    s.clear();
    reset(to, 0);
    FOR(i, 1, n - 1) if (a[i] >= 4 * a[i + 1]) {
            s.insert(-i);
            ll tmp = a[i + 1];
            while (a[i] >= tmp * 4) to[i]++, tmp *= 4;
        }
    ans[1][1] = 1;
    FOR(i, 2, n) {
        if (a[i] > a[i - 1]) {
            int now = 0;
            ll tmp = a[i - 1];
            while (tmp < a[i]) tmp *= 4, now++;
            vector<int> buff;
            int pre = i - 1;
            for (auto it = s.lower_bound(-pre); it != s.end(); ++it){
                int idx = -(*it);
                assert(idx < i);
                ans[1][i] += now * ll(pre - idx);
                now = upd(idx, now);
                pre = idx;
                if (now == -1) break;
                buff.pb(idx);
            }
            if (now != -1) ans[1][i] += ll(pre) * now;
            for (int it : buff) s.erase(-it);
        }
        ans[1][i] = ans[1][i] * 2 + ans[1][i - 1] + 1;
    }
    ll res = 1e18;
    FOR(i, 1, n + 1) res = min(res, ans[0][i] + ans[1][i - 1]);
    cout << res;
}

Measured memory_bytes: 7168
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return ((a*b)/gcd(a,b));}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{






int n,d;
cin>>n>>d;
double a[n][d];

for(int i=0;i<n;i++)
{
	for(int j=0;j<d;j++)
	cin>>a[i][j];
}

int c=0;

for(int i=0;i<n;i++)
{
	for(int j=i+1;j<n;j++)
	{
		double dis=0;
		for(int k=0;k<d;k++)
		{
			dis+=pow((a[i][k]-a[j][k]),2);
			
		}
		double p=sqrt(dis);
		//cout<<d<<" "<<p<<"\n";
		if(p==(int)p)
		c++;
	}
}

cout<<c;



}return 0;}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    vector<string> T;
    REP(i,0,SZ(S)) {
        REP(j,i,SZ(S)) {
            if(j - i + 1 <= K) T.pb(S.substr(i,j-i+1));
        }
    }

    ASC(T);
    vector<string> U;
    U.pb(T[0]);
    REP(i,0,SZ(T)-1) {
        if(T[i] != T[i+1]) U.pb(T[i+1]);
    }
    PR(U[K-1]);

    return 0;
}

/*



*/

Measured memory_bytes: 5120
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>

#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[]){

  int N, Z, W;
  cin >> N >> Z >> W;
  int *a = new int [N];
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  /*
   a[N-2] is X
   a[N-1] is Y
  */
  int pattern1 = abs(a[N-2] - a[N-1]);
  if(N == 1) pattern1 = 0;

  /*
   a[N-1] is X
  */
  int pattern2 = abs(a[N-1] - W);
  int ans = pattern1>pattern2?pattern1:pattern2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
 
 
public class Main {
    public static void main(String[] args) {
    	
        Scanner scanner=new Scanner(System.in);
        
        int N = scanner.nextInt();
        String s = scanner.next();
        
        boolean right[] = new boolean[26];
        boolean left[] = new boolean[26];
        int count = 0;
        int ans=0;
        
        
        for(int i=0;i<N;i++){
        	count = 0;
        	
        	if(!right[s.charAt(i)-'a']){
        		
        		right[s.charAt(i)-'a'] = true;
        		
        	
        		for(int j=i+1;j<N;j++){
        			left[s.charAt(j)-'a'] = true;	
        		}
        		
        		for(int j=0;j<26;j++){
        			if(right[j]&&left[j])
        				count++;
        			left[j] = false;
        		}
        	}
        	
        	if(ans<count)
        		ans = count;
        	
        }
        
        System.out.println(ans);
 
 
    }
 
}


Measured memory_bytes: 23380