akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<iostream>
#include<functional>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

template <typename Monoid=ll> class SegmentTree {
    public:
    using Monoid_func = function<Monoid(Monoid, Monoid)>;
    ll size;
    std::vector<Monoid> segment;  // 1-indexed 葉ノードは size ~ 2*size-1
    Monoid Monoid_unit;
    Monoid_func Monoid_calc;

    SegmentTree(ll N, 
                Monoid Monoid_unit = 0,
                Monoid_func Monoid_calc = [](ll a, ll b){return a+b;}) 
            : size(1), Monoid_unit(Monoid_unit), Monoid_calc(Monoid_calc) {
        while(size < N) size <<= 1;
        segment.assign(size*2, Monoid_unit);
    }

    void set(ll k, Monoid a){
        segment[k+size] = a;
    }
    void build(){  // 全てのノードを再計算
        for(ll k=size-1; k>0; k--) segment[k] = Monoid_calc(segment[k*2], segment[k*2+1]);
    }
    void update_replace(ll k, Monoid a){
        k += size;
        segment[k] = a;
        while(k >>= 1) segment[k] = Monoid_calc(segment[k*2], segment[k*2+1]);
    }
    void update_add(ll k, Monoid a){
        k += size;
        segment[k] = Monoid_calc(segment[k], a);
        while(k >>= 1) segment[k] = Monoid_calc(segment[k*2], segment[k*2+1]);
    }
    Monoid query(ll a, ll b){ // [a, b)の演算結果
        Monoid l=Monoid_unit, r=Monoid_unit;
        for(a+=size, b+=size; a<b; a>>=1, b>>=1){
            if(a % 2 == 1) l = Monoid_calc(l, segment[a++]);
            if(b % 2 == 1) r = Monoid_calc(segment[--b], r);
        }
        return Monoid_calc(l,r);
    }

    Monoid operator[](const ll &k) const{
        return segment[k+size];
    }
};

int main(){
    int n,q, com, x, y;

    cin >> n >> q;
    SegmentTree<ll> st(n, 0, [](ll a, ll b){return a+b;});
    REP(i,q){
        cin >> com >> x >> y;
        if(com==0){
            st.update_add(x,y);
        }
        else{
            cout << st.query(x,y+1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4944
MOD = int(1e9) + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        if a[j] >> i & 1 == 1:
            cnt += 1
    ans += (cnt * (n-cnt) * (2**i)) % MOD
ans %= MOD
print(ans)


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  cout<<a.at(n-1) - a.at(0)<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    lint ans=INF;
    for(int i=1;i<=100;i++){
        lint comp=0;
        rep(j,N) comp+=(A[j]-i)*(A[j]-i);
        ans=min(ans,comp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define dlwlrma ios::sync_with_stdio(0); cin.tie(0);
#define ll long long
const ll INF = 1e18;

int main(){
    dlwlrma
    int n;
    cin >> n;
    ll a = -INF, b = INF, c = -INF, d = INF;
    for(int i = 0; i < n; i++){
        ll x,y;
        cin >> x >> y;
        a = max(a,x+y);
        b = min(b,x+y);
        c = max(c,x-y);
        d = min(d,x-y);
    }
    cout << (max(a-b,c-d)) << "\n";
}


Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <utility>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

int snuke[104];

int main () {
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		for(int i=0;i<d;i++){
			int a;
			cin>>a;
			snuke[a]++;
		}
	}
	int s=0;
	for(int i=1;i<=n;i++){
		s+=!(snuke[i]);
	}
	cout<<s;


return 0;
}



Measured memory_bytes: 3676
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Fennec vs Monster
            var line = ReadLine();
            int N = (int)line[0];
            int K = (int)line[1];

            var H = ReadLine();

            var monsters = H.OrderByDescending(x => x).Skip(K);

            Console.WriteLine(monsters.Sum());
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => long.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 37120
N, K = map(int, input().split())
A = list(map(int, input().split()))
k = 0
for i in range(N-K+1):
	if i>0:
		K_sum = K_sum-A[i-1]+A[i+K-1]
		K_sum0 = max(0, K_sum)
		K_pos = K_pos-max(0, A[i-1])+max(0, A[i+K-1])
	else:
		K_sum = sum(A[i:i+K])
		K_sum0 = max(0, K_sum)
		K_pos = sum(map(lambda x:max(0, x), A[i:i+K]))
	loss = K_pos-K_sum0
	if i==0:
		loss_min = loss
	if loss<loss_min:
		k = i
		loss_min = loss
K_sum_result = max(0, sum(A[k:k+K]))
result = K_sum_result + sum(map(lambda x:max(0, x), A[:k]+A[k+K:]))
print(result)


Measured memory_bytes: 14760
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	string T, P; cin >> T >> P;
	int t = T.size(), p = P.size();
	for (int i = 0; i <= t - p; i++) {
		if (T[i] == P[0]) {
			if (T.substr(i, p) == P) {
				printf("%d\n", i);
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 110;

int c[N][N];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int pos = 0;
    for (int i = 0; i < h; ++i) {
        if (i % 2) {
            for (int j = w - 1; j >= 0; --j) {
                while (a[pos] == 0) {
                    ++pos;
                }
                c[i][j] = pos + 1;
                --a[pos];
            }
        } else {
            for (int j = 0; j < w; ++j) {
                while (a[pos] == 0) {
                    ++pos;
                }
                c[i][j] = pos + 1;
                --a[pos];
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << c[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
 
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}



Measured memory_bytes: 2136
#include <stdio.h>
int main()
{
 int a,b,c,d,n,count;
 while(scanf("%d",&n)!=EOF){
 count = 0;
 for(a=0; a<10; a++){
      for(b=0; b<10; b++){
          for(c=0; c<10; c++){
               for(d=0; d<10; d++){
               if((a+b+c+d)==n) count ++;
               }
          }
      }
  }
 printf("%d\n",count);                   
}
return 0;
}

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

#define debug(x) cerr << #x << " = " << x << endl

const int N_MAX = 200003;
int K, fa[N_MAX], ans;
vector<int> g[N_MAX];
int dfs(int x) {
  int lim = K - (x != 1), ret = 0;
  for (int y : g[x]) {
    int temp = dfs(y);
    if (temp >= lim)
      ++ans;
    else
      ret = std::max(temp + 1, ret);
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n >> K;
  for (int i = 1; i <= n; ++i)
    cin >> fa[i];
  for (int i = 2; i <= n; ++i)
    g[fa[i]].push_back(i);
  if (fa[1] != 1)
    ++ans;
  dfs(1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define int long long
ll n,q,a,b;
ll x[200005];
class segtree{
    public:
	ll seg[(1<<19)],lazy[(1<<19)];
	void init(){
		fill(seg,seg+(1<<19),10000000000000000LL);
		memset(lazy,0LL,sizeof(lazy));
	}
	ll update(int a,int b,int k,int l,int r,ll aa){
		if(r<a || b<l) return seg[k];
		if(a<=l && r<=b){
			seg[k] += aa;
			lazy[k] += aa;
			return seg[k];
		}
		if(lazy[k]){
			seg[k*2+1] += lazy[k]; seg[k*2+2] += lazy[k];
			lazy[k*2+1] += lazy[k]; lazy[k*2+2] += lazy[k];
			lazy[k] = 0;
		}
		return seg[k] = min(update(a,b,k*2+1,l,(l+r)/2,aa),update(a,b,k*2+2,(l+r)/2+1,r,aa));
	}
	ll query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return 20000000000000000LL;
		if(a<=l && r<=b) return seg[k];
		if(lazy[k]){
			seg[k*2+1] += lazy[k]; seg[k*2+2] += lazy[k];
			lazy[k*2+1] += lazy[k]; lazy[k*2+2] += lazy[k];
			lazy[k] = 0;
		}
		return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2+1,r));
	}
}kaede[2];

signed main(){
	scanf("%lld%lld%lld%lld",&n,&q,&a,&b);
	x[1] = a; x[2] = b;
	kaede[0].init();
	kaede[1].init();
	ll mx = kaede[0].query(a,a,0,0,(1<<18)-1);
	kaede[0].update(a,a,0,0,(1<<18)-1,-a-mx);
	ll mx2 = kaede[1].query(a,a,0,0,(1<<18)-1);
	kaede[1].update(a,a,0,0,(1<<18)-1,a-mx2);
	for(int i=3;i<=q+2;i++){
		scanf("%lld",&x[i]);
		mx = kaede[0].query(1,x[i],0,0,(1<<18)-1); mx += x[i];
		mx2 = kaede[1].query(x[i]+1,n,0,0,(1<<18)-1); mx2 -= x[i];
		ll cur = kaede[0].query(x[i-1],x[i-1],0,0,(1<<18)-1); 
		ll cur2 = kaede[1].query(x[i-1],x[i-1],0,0,(1<<18)-1);
		kaede[0].update(x[i-1],x[i-1],0,0,(1<<18)-1,min(0LL,min(mx,mx2)-x[i-1]-cur-abs(x[i-1]-x[i])));
		ll post = kaede[0].query(x[i-1],x[i-1],0,0,(1<<18)-1);
		kaede[1].update(x[i-1],x[i-1],0,0,(1<<18)-1,min(0LL,min(mx,mx2)+x[i-1]-cur2-abs(x[i-1]-x[i])));
		rep(k,2) kaede[k].update(1,n,0,0,(1<<18)-1,abs(x[i-1]-x[i]));
	}
	ll ans = 1e18;
	for(int i=1;i<=n;i++) ans = min(ans,kaede[0].query(i,i,0,0,(1<<18)-1)+i);
	cout << ans << endl;
}

Measured memory_bytes: 18176
import sys
import itertools
sys.setrecursionlimit(10000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    a,b,c,d = map(int,input().split())
    e = a*c
    f = a*d
    g = b*c
    h = b*d
    ans = max(e,f)
    ans = max(ans,g)
    ans = max(ans,h)
    print(ans)

Measured memory_bytes: 68080
# ABC144d


def main():
    import sys
    import math
    import numpy as np
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    a, b, x = map(int, input().split())
    if x > a*a*b/2:
        print(np.rad2deg(np.arctan(2*(a*a*b-x)/(a*a*a))))
        # print(math.degrees(math.atan(2*(a*a*b-x)/(a*a*a))))
        exit(0)
    # print(math.degrees(math.atan(a*b*b/2/x)))
    print(np.rad2deg(np.arctan(a*b*b/2/x)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12508
import sys, heapq
input = sys.stdin.readline
N, D, A = [int(_) for _ in input().split()]
XH = [[int(_) for _ in input().split()] for _ in range(N)]
He = [[2 * x, h, 0] for x, h in XH]
heapq.heapify(He)
now = 0
ans = 0
while He:
    x, h, t = heapq.heappop(He)
    if t:
        now -= h
    else:
        if h - A * now > 0:
            diff = (h - A * now - 1) // A + 1
            now += diff
            ans += diff
            heapq.heappush(He, [x + 4 * D + 1, diff, 1])
print(ans)


Measured memory_bytes: 70132
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <cmath>
using namespace std;
int X,N,M;
int sum=0;
int main()
{
	cin>>N>>X;
	int tmm=X;
	for(int i=1;i<=N;i++)
	{
		cin>>M;
		tmm=min(tmm,M);
		X=X-M;
		sum++;
	}
	sum=X/tmm+sum;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
A = np.array([int(x) for x in input().split()], dtype = np.int64)

abs_A = np.abs(A)
abs_sum = abs_A.sum()
abs_min = abs_A.min()
negatives = (A < 0).sum()

ans = abs_sum if negatives%2 == 0 else abs_sum - 2*abs_min
print(ans)


Measured memory_bytes: 25364
#include <stdio.h>
int main(){

	int num, cnt, tmp, i, j;
	int data[10];
	
	for(cnt=0; cnt<10; cnt++) {
		//printf("input number %d :", cnt+1);
		scanf("%d",&num);
	
		if(num>=0 && num<=10000) {
			data[cnt] = num;
		} else {
			return 0;
		}
	}
	
	for(i=0; i<11; i++) {
		for (j=i+1; j<10; ++j) {
      		if (data[i] < data[j]) {
        		tmp =  data[i];
        		data[i] = data[j];
        		data[j] = tmp;
      		}
		}
	}
	
	for(i=0; i<3; i++) {
		printf("%d\n", data[i]);
	}
	
    return 0;
}

Measured memory_bytes: 600
/*Made by Shivam Solanki*/
#include<bits/stdc++.h> 
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define repllr(i,k,n) for (ll i = n; i >= k; --i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
 
void solve(){
    int n,r;
    cin>>n>>r;
    cout<<((100*max(10-n,0))+r)<<'\n';
} 
  
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;

int main() {
  int K;
  string S;
  cin>>K>>S;
  int l = S.size();
  if(K>=l) cout<<S<<endl;
  if(K<l) {
    for(int i = 0; i < K; i++) cout<<S[i];
    cout<<"..."<<endl;
  }
}
  

Measured memory_bytes: 3624
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var d = ("0 " + Console.ReadLine()).Split().Select(int.Parse).GroupBy(x => x).OrderBy(g => g.Key).SelectMany((g, i) => g.Select((x, j) => (i + j) % 2 == 0 ? x : -x)).OrderBy(x => x).ToArray();
		Console.WriteLine(Enumerable.Range(0, n + 1).Min(i => (d[i == n ? 0 : (i + 1)] - d[i] + 24) % 24));
	}
}


Measured memory_bytes: 13660
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int p[3]={},a=0,b=0,c=0,d=0;
  while(cin >> p[0] >> p[1] >> p[2]) {
      sort(p,p+3);
      if(p[0]+p[1]<=p[2]) {
          cout << a << " " << b << " " << c << " " << d << endl;
          return 0;
      }
      a++;
      if(p[0]*p[0]+p[1]*p[1]==p[2]*p[2]) {
          b++;
      }
      else if(p[0]*p[0]+p[1]*p[1]>p[2]*p[2]) {
          c++;
      }
      else if(p[0]*p[0]+p[1]*p[1]<p[2]*p[2]) {
          d++;
      }
  }
}


Measured memory_bytes: 3168
/*    特徴    */

/*    教訓    */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){


  ll N = il();

  // buckets[i][j] := 先頭i 末尾j の数の数
  vector<vector<ll> > buckets(10, vector<ll>(10, 0));

  REP(i, 1, N+1){
    string si = to_string(i);
    buckets[si[0] - '0'][si[si.size()-1] - '0']++;
  }

  ll ans = 0;
  REP(i, 1, 10) REP(j, 1, 10){
    ans += buckets[i][j] * buckets[j][i];
  }

  cout << ans << endl;



  
}

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

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll left = -1, right = 1e12;
  while (left + 1 < right)
  {
    ll c = (left + right) / 2;
    bool ok = [&]{
      ll total = 0;
      rep(i, n)
          total += max(0ll, a[i] - c / f[i]);
      return total <= k;
    }();
    if (ok)
    {
      right = c;
    }
    else
    {
      left = c;
    }
  }
  cout << right << endl;
}


Measured memory_bytes: 1920
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    return N, A, B, C


def get_lb(l: list, key: int) -> int:
    """
    l[index] > keyとなる最小のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] > keyとなる最小のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess > key:
            high = mid
        else:
            low = mid
    return high


def get_ub(l: list, key: int) -> int:
    """
    l[index] < keyとなる最大のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] < keyとなる最大のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess < key:
            low = mid
        else:
            high = mid
    return low


def main(N: int, A: list, B: list, C: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): パーツの数
        A (list): 上部のパーツのサイズ
        B (list): 中部のパーツのサイズ
        C (list): 下部のパーツのサイズ
    """
    # 事前にリストをソートしておく
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    # 求解処理
    ans = 0
    for i in range(N):
        B_i = B[i]
        ans += (get_ub(A, B_i) + 1) * (N - get_lb(C, B_i))

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, A, B, C = get_input()

    # メイン処理
    main(N, A, B, C)


Measured memory_bytes: 28820
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll INF=1e18;

int main()
{
    string s;
    cin>>s;
    bool flag=false;
    rep(i,3)
    {
        if(s[i]-'0'==7)flag=true;
    }
    if(flag)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, m, l;

int main(){
	cin >> n>>m>>l;
	cout << min(n*m,l)<< endl;
	return 0;
}

Measured memory_bytes: 256
import math
from fractions import gcd

def count(n, A, B):
    n_upper = B // n
    n_lower = (A-1) // n
    n_count = n_upper - n_lower
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C * D) // gcd(C, D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    s = collections.Counter(s)
    t = 1
    for k, v in s.items():
        t = (t * (v + 1)) % mod
    print(t - 1)


if __name__ == '__main__':
    solve()


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 < i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

int main()
{
	string s;
	cin >> s;
	switch (s[0])
	{
		case 'A':
			cout << 'T' << endl;
			return 0;
		case 'T':
			cout << 'A' << endl;
			return 0;
		case 'C':
			cout << 'G' << endl;
			return 0;
		case 'G':
			cout << 'C' << endl;
			return 0;
		default:
			return 0;
	}
	//cout << s << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  vector<string> s(h,string(w,'0'));
  rep(i,b)rep(j,a)s[i][j] = '1';
  for(int i = b;i < h;i++)for(int j = w-1;j >= a;j--)s[i][j] = '1';
  rep(i,h)cout << s[i] << endl;

  



  return 0;
}

Measured memory_bytes: 2304
import numpy as np
import itertools

cc=0
h, w, k= map(int, input().split())
ans=np.zeros((h, w), dtype=int)
for ih in range(0,h):
  a = input()
  for iw in range (0,w):
    if (a[iw] == '.'): ans[ih,iw]=2
    if (a[iw] == '#'): ans[ih,iw]=1
      
hlist=list(itertools.product('01',repeat=h))
wlist=list(itertools.product('01',repeat=w))

for ih in hlist:
  for iw in wlist:
    ans1=ans.copy()
#    print (int(ih[0]))
#    print (int(iw[3]))
#    print (ans)
#    print (ans1)
    for iiih in range(0,h): 
      if (ih[iiih] == '0'): ans1[iiih,:]=0
    for iiiw in range(0,w):
      if (iw[iiiw] == '0'): ans1[:,iiiw]=0
#    print (ans1)
    
    kkk=np.count_nonzero(ans1 == 1)
    if (k == kkk): cc+=1
    
print (cc)

Measured memory_bytes: 27124
import sys
range = xrange
input = raw_input
 
big = int(2**63 - 1)
big2 = 2**64 - 1
def flipper(x):
    if x > big:
        return int(x - 2**64)
    else:
        return x
 
n = int(input())
S = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
 
Scount = [[0] for _ in range(2)]
for s in S:
    Scount[0].append((Scount[0][-1] + (s == 0)) & 1)
    Scount[1].append((Scount[1][-1] + (s == 1)) & 1)
 
Tcount = [[0] for _ in range(2)]
for t in T:
    Tcount[0].append((Tcount[0][-1] + (t == 0)) & 1)
    Tcount[1].append((Tcount[1][-1] + (t == 1)) & 1)
 
U = [flipper(int(x)) for x in input().split()]
V = [flipper(int(x)) for x in input().split()]
 
A = [[0] * n for _ in range(n)]

def solve(layer, par):
    ubit = [1 & (u >> layer) for u in U]
    vbit = [1 & (v >> layer) for v in V]
    mat = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if ubit[i] != S[i]:
                mat[i][j] = ubit[i]
            elif vbit[j] != T[j]:
                mat[i][j] = vbit[j]
            elif S[i] == T[j]:
                mat[i][j] = ubit[i]
            else:
                #assert(S[i] != T[j])
                mat[i][j] = par ^ Scount[S[i]][i] ^ Tcount[T[j]][j]
    
    for i in range(n):
        x = mat[i][0]
        if S[i] == 0:
            for j in range(n):
                x &= mat[i][j]
        else:
            for j in range(n):
                x |= mat[i][j]
        if x != ubit[i]:
            return False
    
    for j in range(n):
        x = mat[0][j]
        if T[j] == 0:
            for i in range(n):
                x &= mat[i][j]
        else:
            for i in range(n):
                x |= mat[i][j]
        if x != vbit[j]:
            return False
    for i in range(n):
        for j in range(n):
            A[i][j] += mat[i][j] << layer
    return True

for layer in range(64):
    if not solve(layer, 0):
        if not solve(layer, 1):
            print -1
            sys.exit()
 
print '\n'.join(' '.join(str(x) for x in row) for row in A)

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

int main()
{
	int i,j, k=0,n, a,flag=0;
	int arr[50][2] = { 0 };
	

	while (scanf("%d", &n) != EOF)
	{
		for (a = n - 1; ; a--)
		{
			if (a % 2 == 0&&a!=2)
			{
				continue;
			}
			for (i = 2; i <= sqrt(a); i++)
			{
				if (a%i == 0)
				{
					flag = 1;
					break;
				}
			}
			if (flag)
			{
				flag = 0;
			}
			else
			{
				arr[k][0] = a;
				break;
			}
		}
		
		for (a = n + 1; ; a++)
		{
			if (a % 2 == 0)
			{
				continue;
			}
			for (i = 2; i <= sqrt(a); i++)
			{
				if (a%i == 0)
				{
					flag = 1;
					break;
				}
			}
			if (flag)
			{
				flag = 0;
			}
			else
			{
				arr[k][1] = a;
				break;
			}
		}
		++k;
		n = 0;
	}

	
	for (i = 0; i < k; i++)
	{
		for (j = 0; j < 2; j++)
		{
			printf("%d",arr[i][j]);
			if (j != 1)
			{
				printf(" ");
			}
		}
		puts("");
	}
	

	return 0;
}


Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K=1000000007;
 
int main (){    
    int N, M;
    cin>>N>>M;
    int Min=min(N, M);
    int Max=max(N, M);
    for(int i=0; i<Max; i++){
        cout<<Min;
    }
 
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_e
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main()
{
    ll n,w;
    cin >> n >> w;
    vector<pair<ll,ll>> v;
    for(int i=0 ; i<n ; i++)
    {
        ll w,val;
        cin >> w >> val;
        v.push_back({val,w});
    }
    sort(v.begin(),v.end());
    ll dp[n][100005];
    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<=100001 ; j++)
            dp[i][j] = 1e18;
    }
    for(int i=0 ; i<n ; i++)
        dp[i][0] = 0;
    dp[0][v[0].first] = v[0].second;
    ll ans = 0;

    if(v[0].second <= w)
        ans = v[0].first;

    for(ll i=1 ; i<n ; i++)
    {
        for(ll j=1 ; j<=100001 ; j++)
        {
            ll ka=1e18,kh=1e18;

            ka = dp[i-1][j];
            if(j-v[i].first >= 0)
              kh = dp[i-1][j-v[i].first] + v[i].second;
            dp[i][j] = min(dp[i][j],min(ka,kh));
            if(dp[i][j]<=w)
                ans = max(ans,j);
        }
    }
   cout << ans;
    return 0;
}


Measured memory_bytes: 81728
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String line = br.readLine();
	    StringTokenizer st = new StringTokenizer(line);
	    int a = Integer.parseInt(st.nextToken());
	    int b = Integer.parseInt(st.nextToken());
	    if((a*b)%2==1){
	    	System.out.println("Odd");
	    }
	    else{
	    	System.out.println("Even");
	    }
	}

}


Measured memory_bytes: 21204
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <vector>
#include <iostream>
#include <cstring>
#include <set>
#include <map>
#include <string>

namespace fastinput
{
	/** Interface */

	inline int readChar();
	template <class T = int> inline T readInt();
	template <class T> inline void writeInt(T x, char end = 0);
	inline void writeChar(int x);
	inline void writeWord(const char *s);

	/** Read */

	static const int buf_size = 16384;

	inline int getChar() {
		static char buf[buf_size];
		static int len = 0, pos = 0;
		if (pos == len)
			pos = 0, len = fread(buf, 1, buf_size, stdin);
		if (pos == len)
			return -1;
		return buf[pos++];
	}

	inline int readChar() {
		int c = getChar();
		while (c <= 32)
			c = getChar();
		return c;
	}

	template <class T>
	inline T readInt() {
		int s = 1, c = readChar();
		T x = 0;
		if (c == '-')
			s = -1, c = getChar();
		while ('0' <= c && c <= '9')
			x = x * 10 + c - '0', c = getChar();
		return s == 1 ? x : -x;
	}

	/** Write */

	static int write_pos = 0;
	static char write_buf[buf_size];

	inline void writeChar(int x) {
		if (write_pos == buf_size)
			fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
		write_buf[write_pos++] = x;
	}

	template <class T>
	inline void writeInt(T x, char end) {
		if (x < 0)
			writeChar('-'), x = -x;

		char s[24];
		int n = 0;
		while (x || !n)
			s[n++] = '0' + x % 10, x /= 10;
		while (n--)
			writeChar(s[n]);
		if (end)
			writeChar(end);
	}

	inline void writeWord(const char *s) {
		while (*s)
			writeChar(*s++);
	}

	struct Flusher {
		~Flusher() {
			if (write_pos)
				fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
		}
	} flusher;
}

using namespace fastinput;
using namespace std;

int main()
{
	::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	cout << (n * (n + 1)) / 2;
	return 0;
}

Measured memory_bytes: 764
import sys

def pop(x):
    if(len(x) < 3):
        return str(int(0))
    a = x[len(x)-1]
    b = x[len(x)-2]
    c = x[len(x)-3]
    x[:] = list(x[:len(x)-3])
    if(b[0] == '+'):
        return str(int(float(a)) + int(float(c)))
    elif(b[0] == '-'):
        return str(int(float(c)) - int(float(a)))
    elif(b[0] == '*'):
        return str(int(float(a)) * int(float(c)))
    else:
        return str(int(float(c)) / int(float(a)))

l = []
for i in sys.stdin:
    l.append(i)
    if(len(l) == 3):
        l.append(pop(l))

print int(float(l[0]))


Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	return res;
}

vector<ll> fact, inv;
void fact_inv(int n, ll mod) {
	fact.resize(n + 1);
	inv.resize(n + 1);
	
	fact[0] = 1;
	FOR(i, 1, n + 1) fact[i] = fact[i - 1] * i % mod;
	inv[n] = mod_pow(fact[n], mod - 2, mod);
	for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

ll ncr(ll n, ll r, ll mod) {
	if (n < r || r < 0 || n < 0) return 0;
	return fact[n] * inv[r] % mod * inv[n - r] % mod;
}

int N, M;
string S;
int l[3000], r[3000];
ll dp[3001][3001]; // i:区間, j:前共通部分に含まれる0の数

int main() {
	fact_inv(3000, MOD);
	
	cin >> N >> M;
	cin >> S;
	REP(i, M) scanf("%d %d", l + i, r + i), l[i]--, r[i]--;
	
	vector<pii> q;
	q.push_back(pii(l[0], r[0]));
	
	FOR(i, 1, M) {
		pii &b = q.back();
		if (b.fi == l[i]) chmax(b.se, r[i]);
		else if (b.se < r[i]) q.push_back(pii(l[i], r[i]));
	}
	q.push_back(pii(N, N));
	
	dp[0][0] = 1;
	REP(i, q.size() - 1) {
		int lcc = max(q[i].se - q[i + 1].fi + 1, 0); // 後区間との共通の長さ
		
		int bcc = 0; // 前区間との共通の長さ
		if (i > 0) bcc = max(q[i - 1].se - q[i].fi + 1, 0);
		
		int bacnt = 0; // 前区間を除く区間に含まれる0の数
		FOR(j, q[i].fi + bcc, q[i].se + 1) if (S[j] == '0') bacnt++;
		
		int l = q[i].se - q[i].fi + 1; // 区間の長さ
		
		REP(j, bcc + 1) {
			if (dp[i][j] == 0) continue;;
			
			int cnt = bacnt + j; // 区間[l_i, r_i]の中に、cnt個の1が存在する。
			
			REP(k, lcc + 1) {
				(dp[i + 1][k] += dp[i][j] * ncr(l - lcc, cnt - k, MOD) % MOD) %= MOD;
			}
		}
	}
	
	cout << dp[q.size() - 1][0] << endl;
	
	return 0;
}


Measured memory_bytes: 29312
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    ll n = s.size();
    ll res = 1;
    char pres = s[n - 1];
    bool skip = false;
    for(ll i = n - 2; i >= 0; i--){
        if(skip){
            pres = s[i] + s[i + 1];
            res++;
            skip = false;
        }
        else if(s[i] == pres){
            skip = true; 
            continue;
        }
        else{
            pres = s[i];
            res++;
        }
    }
    cout << res;
    cout << endl;
    return 0;
}


Measured memory_bytes: 720
#pragma region header
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1) (__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1) (__VA_ARGS__)
#define each(i, a) for (auto &&i : (a))
using namespace std;

using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vp = vector<pii>;
using vvp = vector<vp>;

template <class T>
void COUT(T x) { cout << x << endl; }

#pragma endregion header

const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};

void solve() {
  int H, W;
  cin >> H >> W;
  int ch, cw;
  cin >> ch >> cw;
  ch--;
  cw--;
  int dh, dw;
  cin >> dh >> dw;
  dh--;
  dw--;
  vs s(H);
  rep(i, H)cin >> s[i];


  vp jumped;
  jumped.emplace_back(ch, cw);
  vvb used(H, vb(W));
  used[ch][cw] = true;
  function<bool(int, int)> check = [&](int x, int y) {
    if(x < 0 || y < 0 || x >= H || y >= W
      || s[x][y] == '#' || used[x][y])return false;
    used[x][y] = true;
    return true;
  };

  for(int i = 0; !jumped.empty(); i++) {
    queue<pii> q;
    each(p, jumped)q.push(p);
    vp moved;
    while(!q.empty()) {
      auto p = q.front();
      if(p.first == dh && p.second == dw) {
        COUT(i);
        return;
      }
      q.pop();
      moved.push_back(p);
      rep(i, 4) {
        int nx = p.first + vx[i], ny = p.second + vy[i];
        if(check(nx, ny))q.emplace(nx, ny);
      }
    }
    jumped.clear();
    each(p, moved) {
      for(int j = -2; j < 3; j++)for(int k = -2; k < 3; k++) {
        int nx = p.first + j, ny = p.second + k;
        if(check(nx, ny))jumped.emplace_back(nx, ny);
      }
    }
  }
  COUT(-1);
}


#pragma region main
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();
}
#pragma endregion main


Measured memory_bytes: 4892
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iterator>
#include<set>
#define rep(i,n) for(i=0;i<n;i++);
#define endl "\n"
#define ll long long
using namespace std;
int main()
{
    long long int d,i,n,m,p=0,q=0,r=0,s=0,l;

int j;
cin>>n;
for(i=1;i<=n;i++)
{
    cin>>d;
    if(i%2!=0 && d%2!=0 )
        p++;
}
cout<<p;



}

















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

int main() {
  long n;
  cin >> n;
  long v1[n/2], v2[n/2];
  unordered_map<long, long> m1, m2;
  long max1 = 0, max2 = 0, smax1 = 0, smax2 = 0,
  	mode1, mode2, smode1, smode2;
  for (long i = 0; i < n/2; i++) {
    cin >> v1[i] >> v2[i];
    m1[v1[i]] += 1;
    m2[v2[i]] += 1;
    if (max1 < m1[v1[i]]) {
      max1 = m1[v1[i]];
      mode1 = v1[i];
    } else if (smax1 < m1[v1[i]]) {
      smax1 = m1[v1[i]];
      smode1 = v1[i];
    }
    if (max2 < m2[v2[i]]) {
      max2 = m2[v2[i]];
      mode2 = v2[i];
    } else if (smax2 < m2[v2[i]]) {
      smax2 = m2[v2[i]];
      smode2 = v2[i];
    }
  }
  
  if (mode1 == mode2) {
    if (n - smax1 - max2 < n - max1 - smax2) cout << n - smax1 - max2;
    else cout << n - max1 - smax2;
  } else cout << n - max1 - max2;
  
  return 0;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N; cin >> N;
    string s; cin >> s;
    if (N%2==1) {
        cout << "No" << endl;
        return 0;
    }
    else {
        REP(i, N/2) {
            if (s[i] != s[N/2 + i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(void)
{
    int n, m;
    cin >> n >> m;

    int sum = 0;

    irep(i, m) {
        int tmp;
        cin >> tmp;
        sum += tmp;
    }

    if(sum > n) {
        cout << -1 << endl;
    } else {
        cout << n-sum << endl;
    }
    return 0;
}
/** atcoder **/


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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> ans(n,0);
  int w=0,e=0;
  for(int i=n-1;i>=0;i--){
    ans[i]+=e;
    if(s[i]=='E')e++;
  }
  for(int i=0;i<n;i++){
    ans[i]+=w;
    if(s[i]=='W') w++;
  }
  int fans=n;
  for(int i=0;i<n;i++){
    fans=min(fans,ans[i]);
  }
  cout << fans << endl;
}

Measured memory_bytes: 4812
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

bool IsPrime(ll n) {
	if (n <= 1)return false;
	for (ll i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0)return false;
	}
	return true;
}
ll dp[210000];


int main() {
	REPO(i, 201010) {
		if (IsPrime(i)) dp[i] = i;
	}
	REPR(i, 201010) {
		if (dp[i] == 0)dp[i] = dp[i + 1];
	}
	ll n;
	cin >> n;
	cout << dp[n] << endl;
}





Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
ll dp[3001][3001];
ll fun(int x,int y,int *a){
    if(x>y)return 0;
    if(x==y)return a[x];
    if(dp[x][y]>-1)return dp[x][y];
    ll X=a[x]+min(fun(x+2,y,a),fun(x+1,y-1,a));
    ll Y=a[y]+min(fun(x+1,y-1,a),fun(x,y-2,a));
    ll ans=max(X,Y);
    return dp[x][y]=ans;
}
void solve()
{
    int n;
    cin>>n;
    int a[n];
    ll sum=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    memset(dp,-1,sizeof dp);
    ll X=fun(0,n-1,a);
    cout<<X-(sum-X);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 74124
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <cmath>
#include <limits>

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

int main() {
    int n;
    cin >> n;
    vector<int> t(n), a(n);
    ll ans1 = 1;
    ll ans2 = 1;
    rep(i, n) {
        ll a,t;
        cin >> a >> t;
        ll a1 = ans1 % a == 0 ? ans1 / a : ans1 / a + 1;
        ll t1 = ans2 % t == 0 ? ans2 / t : ans2 / t + 1;
        ll rate = max(a1, t1);
        ans1 = rate * a;
        ans2 = rate * t;
    }

    cout << ans1 + ans2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll gcd(ll a, ll b) {
  ll v0=a, v1=b, v2=v0%v1;
  while(v2>0) {
    v0 = v1;
    v1 = v2;
    v2 = v0%v1;
  }
  return v1;
}

int main() {
  ll A, B, C, D;
  cin>>A>>B>>C>>D;
  ll tmp;
  ll ans = B-A+1;
  tmp = A+(C-A%C)%C;
  if(B>=tmp) ans -= (B-tmp)/C+1;
  tmp = A+(D-A%D)%D;
  if(B>=tmp) ans -= (B-tmp)/D+1;
  ll E = C*D/gcd(C, D);
  tmp = A+(E-A%E)%E;
  if(B>=tmp) ans += (B-tmp)/E+1;
  cout<<ans<<endl;
}



Measured memory_bytes: 3568
import numpy as np

v = []
for i in range(3):
    v.extend(input().split())

v = np.array([int(x) for x in v])



coeffs = np.array([
    [1, 0, 0, 1, 0, 0, v[0]],
    [1, 0, 0, 0, 1, 0, v[1]],
    [1, 0, 0, 0, 0, 1, v[2]],
    [0, 1, 0, 1, 0, 0, v[3]],
    [0, 1, 0, 0, 1, 0, v[4]],
    [0, 1, 0, 0, 0, 1, v[5]],
    [0, 0, 1, 1, 0, 0, v[6]],
    [0, 0, 1, 0, 1, 0, v[7]],
    [0, 0, 1, 0, 0, 1, v[8]],
])

rank = np.linalg.matrix_rank(coeffs)
if rank < 6:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14444
#include<bits/stdc++.h>
using namespace std;
const int M=51;
int n,A[M];
double ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	ans=A[1];
	for(int i=2;i<=n;i++)ans=(ans+A[i]*1.0)/2.0;
	printf("%.7lf\n",ans);
}

Measured memory_bytes: 256