akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main() {
	long long int a, b, n, m, c, d ,sa=0,sb=0;
	scanf("%lld %lld", &c, &d);
	for (n = 1; c >= n; n++) {
		scanf("%lld",&a );
		sa += a;
	}
	for (m = 1; d >= m; m++) {
		scanf("%lld", &b);
		sb += b;
	}
	printf("%lld\n", sa*sb);
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;cin>>N;
    vl A(N);
    rep(i, N) cin >> A[i];

    A.eb(A[N - 1]);

    ll ans = 1;
    ll ai = 0, st = 0, pre = A[0];
    while(ai<N){
        if(A[ai]>pre){
            if (st < 0) st = 0, ans++;
            else st = 1;
        }
        else if(A[ai]<pre){
            if (st > 0) st = 0, ans++;
            else st = -1;
        }

        pre = A[ai];
        ai++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	string S;
	cin >> S;
	int ans = 0;

	for (int i = 0; i < S.size(); ++i) {
		ans += S.at(i) - '0';
	}

	if (ans % 9 == 0) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

}

Measured memory_bytes: 3720
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
cnt=0
for i in range(N):
    A=list(map(int,input().split()))
    tmp=C
    for j in range(M):
        tmp+=A[j]*B[j]
    if tmp>0:
        cnt+=1
print(cnt)

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll modpow(ll a, ll n)
{
  ll ret = 1;
  while (n > 0) {
    if (n & 1) {
      ret = (ret * a) % MOD;
    }
    a = (a * a) % MOD;
    n >>= 1;
  }
  return ret;
}

ll combi(ll n, ll r, vector<ll>& fact, vector<ll>& inv_fact)
{
  if (r > n) { return 0; }
  ll ret = (fact[n] * inv_fact[r]) % MOD;
  ret = (ret * inv_fact[n - r]) % MOD;
  return ret;
}

int main()
{
  int H, W, A, B; scanf("%d %d %d %d", &H, &W, &A, &B);
  int N = H + W;
  vector<ll> fact(N + 5, 1), inv_fact(N + 5, 1);
  for (int i = 1; i <= N; ++i) {
    fact[i] = (i * fact[i - 1]) % MOD;
    inv_fact[i] = modpow(fact[i], MOD - 2);
  }

  // H - A - 1, [B, W - 1]
  ll ans = 0;
  for (int r = B; r <= W - 1; ++r) {
    int n = H - A - 1 + r;
    ll val = combi(n, r, fact, inv_fact) * combi(A - 1 + W - 1 - r, A - 1, fact, inv_fact);
    val %= MOD;
    ans = (ans + val) % MOD;
  }
  printf("%lld\n", ans);
  return 0;
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for (int i=0;i<n;i++){
		int f=0;
		for (int j=i;j<n;j++){
			if (s[j]!=t[j-i]){
				f=1;
				break;
			}
		}
		if (!f){
			cout<<n+i<<endl;
			return 0;
		}
	}
	cout<<n*2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;

int main(){
  int n;
  std::cin >> n;
  std::cout << (n-2)*180 << std::endl;
}

Measured memory_bytes: 256
# 写経しましたが、何もわかっていません。

def floor_sum(n, m, a, b):
    "Return sum( floor( (A * i + B) / M ) for i in range(N) )"
    ret = 0
    while True:
        if a >= m:
            ret += ((n - 1) * n) // 2 * (a // m)
            a %= m
        if b >= m:
            ret += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        x_max = y_max * m - b
        if y_max == 0:
            return ret
        ret += (n - (x_max + a - 1) // a) * y_max
        n, m, a, b = y_max, a, m, -x_max % a
    
    return ret

def main():
    import sys
    input = sys.stdin.buffer.readline

    ans = []
    T = int(input())
    for _ in range(T):
        N, M, A, B = map(int, input().split())
        ans.append(floor_sum(N, M, A, B))

    print('\n'.join(map(str, ans)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 79752
def delta(t,t1,t2):
	dt = [int(t2[i]) - int(t1[i]) for i in [0,1,3,4]]
	dt = 60*(10*dt[0] + dt[1]) + 10*dt[2] + dt[3]
	return dt if dt >= t else False
	
n,t = map(int,raw_input().split())
s = [raw_input().split() for i in range(n)]
a = []
for i in range(1,n):
	dt = delta(t,s[i-1][2],s[i][0])
	if dt:
		a.append([s[i][1], str(dt)])
print len(a)
for i in a:
	print " ".join(i)

Measured memory_bytes: 4248
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

void rec(vector<ll> &v, vector<vector<ll>> &c, vector<bool> &visited, const ll &k)
{
    for (ll i = 0; i < c[k].size(); i++)
    {
        ll childe = c[k][i];
        if (!visited[childe])
        {
            v[childe] += v[k];
            visited[childe] = true;
            rec(v, c, visited, childe);
        }
    }
}

int main()
{
    ll N = input<ll>(), Q = input<ll>();
    vector<vector<ll>> c(N + 1, vector<ll>());
    vector<ll> v(N + 1, 0);
    vector<bool> visited(N + 1, false);

    for (int i = 0; i < N - 1; i++)
    {
        ll a = input<ll>(), b = input<ll>();
        c[a].push_back(b);
        c[b].push_back(a);
    }

    for (int i = 0; i < Q; i++)
    {
        ll a = input<ll>(), b = input<ll>();
        v[a] += b;
    }

    visited[1] = true;
    rec(v, c, visited, 1);

    for (int i = 1; i < N + 1; i++)
    {
        cout << v[i] << (i == N ? "\n" : " ");
    }
    return 0;
}

Measured memory_bytes: 27392
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

void dfs(vector<vector<pii>> &G,vi &ans,int color,int v,int pv){
  int ng;
  ng = color;
  color = 0;
  
  for(pii nP: G.at(v)){
    int nv = nP.first;
    if(nv == pv) continue;
    int id = nP.second;
    color++;
    if(color == ng) color++;
    ans.at(id) = color;
    dfs(G,ans,color,nv,v);
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector<pii>> Graph(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;b--;
    Graph.at(a).push_back(pii(b,i));
    Graph.at(b).push_back(pii(a,i));
  }
  vector<int> ans(n-1,0);
  dfs(Graph,ans,0,0,-1);
  int k = 0;
  rep(i,n-1) k = max(k,ans.at(i));
  cout << k << endl;
  rep(i,n-1){
    cout << ans.at(i) << endl;
  }
}


Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int x,y,a[n+1]={};

  for(int i=0;i<m;i++){
    cin>>x>>y;
    if(x==1){
      a[y]++;
    }
    if(y==n){
      a[x]++;
    }
  }
  bool flag=0;
  for(int i=0;i<=n;i++){
    if(a[i]>=2){
      flag=1;
      break;
    }
  }
  if(flag){
    cout<<"POSSIBLE"<<endl;
  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
  return 0;
}


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

using namespace std;

int main() {
    int n;
    unsigned long int ans=0;
    bool break_loop;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i<n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    for (int i=0; i<n-2; i++) {
        for (int j=i+1; j<n-1; j++) {
            break_loop = false;
            for (int k=j+1; k<n; k++) {
                if (v[i] >= (v[j]+v[k])){
                    break_loop=true;
                    break;
                }
                else {
                    ans++;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = sorted(list(map(int, input().split())))

from bisect import bisect_left

ans = 0
for c in range(2, N):
  for a in range(c-1):
    b_index = bisect_left(L, L[c]-L[a]+1)

    if b_index <= a:
      b_index = a + 1
    if c - b_index > 0:
      ans += c - b_index

print(ans)

Measured memory_bytes: 3188
/* ex4_3
   YSK722 */

#include <stdio.h>

// プロトタイプ宣言
int calculation(int name1, int name2);


int main(void){
    int west, east, ans;
    scanf("%d %d", &west, &east);

    // 関数の呼び出し
    ans = calculation(west, east);

    printf("%d\n", ans);
    return 0;
}


// 関数の定義
int calculation(int name1, int name2){
    int i, height = 0;
    // 西側の塔の本当の高さを計算
    for (i = 1; i < name2 - name1; i++) {
        height += i;
    }
    // 積雪量を戻り値とする
    return height - name1;
}

Measured memory_bytes: 128
n=int(input())
a=[0]*n
xy=[]
for i in range(n):
    a[i]=int(input())
    hoge=[]*a[i]
    for j in range(a[i]):
        hoge.append(tuple(int(i) for i in input().split()))
    xy.append(hoge)

ans=0
def check(j,pattarn):
    if j in pattarn:
        for x,y in xy[j]:
            if not y and (x-1 in pattarn):
                return 0
            if y and (x-1 not in pattarn):
                return 0
        return 1

for bit in range(1<<n):
    pattarn = []
    for j in range(n):
        if (bit & (1<<j)):
            pattarn.append(j)

    for j in range(n):
        if check(j,pattarn)==0:
            break
    else:
        ans=max(ans,len(pattarn))
print(ans)

Measured memory_bytes: 3064
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, WM = map(int, input().split())
V = [0] * N
W = [0] * N

for i in range(N):
    V[i], W[i] = map(int, input().split())
dp = [0] * (WM + 1)

for i in range(N):
    for w in range(WM, -1, -1):
        if w - W[i] >= 0:
            dp[w] = max(dp[w - W[i]] + V[i], dp[w])
print(dp[-1])


Measured memory_bytes: 6432
#include<cstdio>

int main()
{
  long long s = 1ll;
  long long a;
  int n;
  scanf("%d",&n);
  while(n--){
    scanf("%lld",&a);
    if(a==0){
      printf("0");
      return 0;
    }
    if(s<0){
      continue;
    }
    if(2000000000000000000ll/a<s){
      s=-1ll;
      continue;
    }
    s*=a;
    if(s>1000000000000000000ll)
      s=-1;
  }
  printf("%lld",s<0?(-1ll):s);
  return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

struct Node {
    int a, b, c, d;
    bool operator<(const Node &aa) const {
        return d > aa.d;
    }
} a[55];

int n, m, q;
int ans[55];
int ansn = 0;

void dfs(int pos, int pre) {
    if(pos == n + 1) {
        int tmp = 0;
        for(int i = 1; i <= q; ++i) {
            if(ans[a[i].b] - ans[a[i].a] == a[i].c)
                tmp += a[i].d;
        }
        ansn = max(ansn, tmp);
//        for(int i = 1; i <= n; ++i)
//            cout << ans[i] << ' ';
//        cout << endl;
        return ;
    }
    for(int i = pre; i <= m; ++i) {
        ans[pos] = i;
        dfs(pos + 1, i);
    }
}

signed main() {
    cin >> n >> m >> q;
    for(int i = 1; i <= q; ++i)
        cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
    dfs(1, 1);
    cout << ansn;
    return 0;
}

Measured memory_bytes: 3636
#include <string>
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int count = 0;
	int la_count = 0;
	int fb_count = 0;
	int ba_count = 0;
	for (auto n = 0u; n < N; ++n)
	{
		string s;
		cin >> s;
		size_t pos = 0;
		while (true)
		{
			pos = s.find("AB", pos);
			if (pos == string::npos)
			{
				break;
			}
			else
			{
				++count;
				pos += 2;
			}
		}

		auto first_c = s[0];
		auto last_c = s[s.size() - 1];
		if (last_c == 'A')
		{
			if (first_c == 'B')
			{
				++ba_count;
			}
			else
			{
				++la_count;
			}
		}
		else if (first_c == 'B')
		{
			++fb_count;
		}
	}

	bool is_last_a = false;
	while (true)
	{
		if (!is_last_a)
		{
			if (la_count)
			{
				--la_count;
				is_last_a = true;
			}
			else if (ba_count)
			{
				--ba_count;
				is_last_a = true;
			}
			else
			{
				break;
			}
		}

		if (ba_count)
		{
			--ba_count;
			++count;
			is_last_a = true;
		}
		else if (fb_count)
		{
			--fb_count;
			++count;
			is_last_a = false;
		}
		else
		{
			break;
		}
	}

	cout << count;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ld w,h,x,y;
    cin >> w >> h >> x >> y;
    if( 2*x == w && 2*y == h) cout << w*h/2 << " " << "1"<<endl;
    else cout << w*h/2 << " " << "0"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.math.BigInteger
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.sqrt

val MOD = 1_000_000_007L

data class Entry(val a: Long, val b: Long)
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val E = Array(N) {Entry(nl(), nl())}
    val Ea = E.sortedBy { it.a }
    val Eb = E.sortedBy { -it.b }
    if (N % 2 == 1) {
      val l = Ea[N / 2].a
      val r = Eb[N / 2].b
      out.println(r - l + 1)
    } else {
      val l1 = Ea[N / 2 - 1].a
      val r1 = Eb[N / 2].b

      val l2 = Ea[N / 2].a
      val r2 = Eb[N / 2 - 1].b

      debug{"$l1:$r1 $l2:$r2"}

      out.println(r1 + r2 - (l1 + l2) + 1)
    }
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}

Measured memory_bytes: 70696
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();

    for(int i=0 ; i<s.length() ; i++){
      if(i<s.length()-1){
        if(s.charAt(i)==t.charAt(i)){
          continue;
        }else{
          System.out.println("No");
          break;
        }
      }else{
        if(s.charAt(i)==t.charAt(i)){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }
    }
  }
}


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

int main() {

  int n;

  cin >> n ;
  n = n % 100;
  n = n % 10;
  
  if(n==0 || n==1 || n==6 || n==8) cout << "pon" ;
  else if(n==3) cout << "bon" ;
  else cout << "hon" ;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>

using namespace std;

const int mod = 1'000'000'007;

int add(int a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
  return a;
}

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

const int N = 100'009;

int a[N];
int f[N];
int rf[N];
int s[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  f[0] = 1;
  for (int i = 1; i < n; ++i) {
    f[i] = mul(f[i - 1], i);
  }
  rf[n + 1] = 1;
  for (int i = n; i >= 2; --i) {
    rf[i] = mul(rf[i + 1], i);
  }
  s[0] = 0;
  for (int i = 1; i <= n; ++i) {
    s[i] = add(s[i - 1], mul(f[i - 1], rf[i + 1]));
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = add(ans, mul(a[i], add(add(s[i + 1], s[n - i]), mod - s[1])));
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 1792
main(){double a,b,c,d,e,f;for(;~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",(e*c-b*f)/(a*e-b*d)+0.0,(a*f-d*c)/(a*e-b*d)+0.0));exit(0);}

Measured memory_bytes: 648
import numpy as np


def getInput():
    """

    :return: list of list of str. 1st dim: row, 2nd dim: column.
    """
    separator = ' '
    ret_array = []
    while True:
        try:
            row = input().split(sep=separator)
            ret_array.append(row)
        except EOFError:
            break
    return ret_array


g = getInput()

# number
N = np.array(list(map(int, g[0])), dtype=np.int32)
# l,r
l = []
r = []
for row_idx in range(1, len(g)):
    l.append(int(g[row_idx][0]))
    r.append(int(g[row_idx][1]))

l = np.array(l, dtype=np.int32)
r = np.array(r, dtype=np.int32)

s = r-l+1

print(s.sum())


Measured memory_bytes: 12496
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,a,b,c,d=map(int,input().split())
    s=input()
    for i in range(a,max(c,d)):
        if i+2<=n:
            if s[i:i+2]=='##':
                print("No")
                break
    else:
        if c<d:
            print("Yes")
        else:
            flag=False
            for i in range(b-1,d):    
                if s[i-1:i+2]=="...":
                    flag=True
            if flag==True:
                print("Yes")
            else:
                print("No")

if __name__=='__main__':
    main()

Measured memory_bytes: 3572
#include <iostream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		int n;
		cin >> n;
		int arr[n + 1] = {0};
		long long ans = 0;
		for (int i = 1; i <= n; i++) 
		{
			for (int j = i; j < n + 1; j += i) 
			{
				arr[j]++;
			}
		}
		for (int i = 1; i <= n; i++) 
			ans += (long long)i * arr[i];

		cout << ans;
	}
	return 0;
}


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

typedef pair<int, int> P;

int main(){
    while(1){
        int a, l;
        cin >> a >> l;
        if (a == 0) break;

        priority_queue<int> que;
        priority_queue<int, vector<int>, greater<int>> que2;

        vector<int> tmp;
        bool flag = false;

        int ans_j, ans_a, ans_i_j;

        for (int k = 1; k <= 20; k++){
            tmp.push_back(a);
            for (int i = 0; i < l; i++){
                que.push(a % 10);
                que2.push(a % 10);
                a /= 10;
            }
            int a_max = 0;
            int a_min = 0;
            for (int i = 0; i < l; i++){
                a_max *= 10;
                a_min *= 10;
                a_max += que.top();
                a_min += que2.top();
                que.pop(); que2.pop();
            }
            a = a_max - a_min;
            for (int i = 0; i < tmp.size(); i++){
                if (a == tmp[i]) {
                    flag = true;
                    ans_a = a;
                    ans_j = i;
                    ans_i_j = k - i;
                    break;
                }
            }
            if (flag) break;
        }
        cout << ans_j << " " << ans_a << " " << ans_i_j << endl;
    }
}


Measured memory_bytes: 3160
#include<iostream>
#include<string>
#define int long long
signed main(){
  int N;
  std::string ans="No";
  std::cin>>N;
  for (int i=1;i<=9;i++){
      for (int j=1;j<=9;j++){
        if(i*j==N){
          ans="Yes";
        }
    }
  }
    std::cout<<ans<<std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i = i + 2){
    cout << s[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int x[4], y[4];

  for(int i = 0; i < 2; i++) cin >> x[i] >> y[i];

  x[2] = x[1]-(y[1] - y[0]);
  x[3] = x[2] - (x[1] - x[0]);
  y[2] = y[1] + (x[1] - x[0]);
  y[3] = y[0] + (x[1] - x[0]);

  cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int mInt;
#define int long
int cnt753(string s,int m){
  int a=0,b=0,c=0,res=0;
  if(s.length()){
    if(stol(s)>m)return 0;
    for(int i=0;i<s.length();++i){
      if(s[i]=='3')a++;
      if(s[i]=='5')b++;
      if(s[i]=='7')c++;
    }
  }
  if(a*b*c)res=1;
  return res+cnt753(s+"3",m)+cnt753(s+"5",m)+cnt753(s+"7",m);
}

mInt main(){
  int m;
  cin>>m;
  cout<<cnt753("",m);
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Main {

  public static void main(String[] args) throws Exception {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
      System.out.println(validate(reader.lines().iterator()) ? "Yes" : "No");
    }
  }

  private static boolean validate(Iterator<String> lines) {
    int count = Integer.parseInt(lines.next());
    // ほんとうはこんなコード書きたくない
    int lastChar = -1;
    Set<String> remember = new HashSet<>();
    for (; count != 0; --count) {
      final String line = lines.next();
      if (line == null) return false;
      if (remember.contains(line))
        return false;
      remember.add(line);
      final int length = line.length();
      if (lastChar != -1) {
        if (length == 0 || line.charAt(0) != lastChar) { return false; }
      }
      lastChar = line.charAt(length - 1);
    }
    return true;
  }

}


Measured memory_bytes: 22612
# -*- coding: utf-8 -*-
# abc141/abc141_d
import sys
import heapq

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    h = [-int(s) for s in sys.stdin.readline().rstrip().split()]
    heapq.heapify(h)
    for _ in range(M):
        top_h = -(-h[0] // 2)
        heapq.heapreplace(h, top_h)
    print(-sum(h))

main()


Measured memory_bytes: 14380
#include<stdio.h>

int main()
{
    long long int n,c=0,i,c2=0,j;
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        j=i;
        while(i!=0){
            c++;
            i=i/10;
        }
        if(c%2!=0){
            c2++;
        }
        c=0;
        i=j;

    }
    printf("%lld",c2);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <climits> 
//#include <iterator>

using namespace std;
using ll = long long;
using ull = unsigned long long;

struct Edge{
    int from;
    int to;
};

int findMax(int cur, int N, unordered_map<int, vector<int>>& edgeMap, vector<int>& maxLen) {
    if (maxLen[cur] >= 0) return maxLen[cur];
    int r = 0;
    for (auto e : edgeMap[cur]) {
        r = max(r, findMax(e, N, edgeMap, maxLen)+1);
    }
    maxLen[cur] = r;
    return maxLen[cur];
}

int longestPath(int N, int M, unordered_map<int, vector<int>>& edgeMap) {
    vector<int> maxLen(N+1,-1);
    int ans = 0;
    for (int i = 1; i <= N; ++ i) {
        ans = max(ans, findMax(i, N, edgeMap, maxLen));
    }
    return ans;
}

int main() {
    int M,N;
    cin>>N>>M;
    vector<Edge> edges(M);
    unordered_map<int, vector<int>> edgeMap; 
    for (auto& e : edges) {
        cin>>e.from>>e.to;
        edgeMap[e.from].push_back(e.to);
    }
    cout<<longestPath(N, M, edgeMap)<<endl;
    return 0;
}


Measured memory_bytes: 13604
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10);







ll checkman(vector<int> s, int i) {
	
	int mozila = 1;
	int n = s.size();
	int tmp = 0;
	ll ans=0;
	for (int k = i;k <n;k++) {
		tmp = tmp + s[k];
		if (tmp % 2019 == 0)ans++;

		


		tmp = (tmp * 10) % 2019;

	}
	return ans;


}








int main() {

	int a, b, c;
	cin >> a >> b >> c;
	if (b % a == 0 || c % a == 0)cout << "OK" << endl;
	else if (b / a == c / a)cout << "NG" << endl;
	else cout << "OK" << endl;
	return 0;
}



Measured memory_bytes: 3640
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
def f(i, e, dp):
    if dp[i] is not None:
        return dp[i]
    val = 0
    for nxt in e[i]:
        val = max(val, f(nxt, e, dp) + 1)
    dp[i] = val
    return dp[i]


def edu_dp_g_longest_path():
    n, m = map(int, input().split())
    e = [[] for _ in range(n)]
    for _ in range(m):
        x, y = map(int, input().split())
        e[x - 1].append(y - 1)
    dp = [None] * n
    result = 0
    for i in range(n):
        result = max(result, f(i, e, dp))
    print(result)

edu_dp_g_longest_path()

Measured memory_bytes: 115780
# coding: utf-8
import sys
# sys.exit()
a,b,c,k = map(int, input().split())
# sum = 0
if k <= a:
    sum = k
    print(sum)
    sys.exit()
else:
    sum = a
    k = k - a
if k <= b:
    print(sum)
    sys.exit()
else:
    k = k - b
    sum = sum - k
    print(sum)


Measured memory_bytes: 9088
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
typedef long long LL;
using namespace std;

const LL mod = 1e9 + 7;
const int MAXN = 1e5 + 10;
char str[MAXN];

int main() {
	int x1, y1, y, x;
	scanf("%d %d %d %d", &x1, &y1, &x, &y);
	x -= x1;
	y -= y1;
	if(x > 0 && y > 0) {
		for(int i = 0; i < y; ++i) 
			printf("U");
		for(int i = 0; i < x; ++i)
			printf("R");
		for(int i = 0; i < y; ++i) 
			printf("D");
		for(int i = 0; i < x; ++i)
			printf("L");
	}
	if(x < 0 && y > 0) {
		for(int i = 0; i < y; ++i) 
			printf("U");
		for(int i = 0; i < -x; ++i)
			printf("L");
		for(int i = 0; i < y; ++i) 
			printf("D");
		for(int i = 0; i < -x; ++i)
			printf("R");
	}
	if(x < 0 && y < 0) {
		for(int i = 0; i < -y; ++i) 
			printf("D");
		for(int i = 0; i < -x; ++i)
			printf("L");
		for(int i = 0; i < -y; ++i) 
			printf("U");
		for(int i = 0; i < -x; ++i)
			printf("R");
	}
	if(x > 0 && y < 0) {
		for(int i = 0; i < -y; ++i) 
			printf("D");
		for(int i = 0; i < x; ++i)
			printf("R");
		for(int i = 0; i < -y; ++i) 
			printf("U");
		for(int i = 0; i < x; ++i)
			printf("L");
	}
	//@@@@@@@@@@@@@@@@@@
	if(x > 0 && y > 0) {
		printf("L");
		for(int i = 0; i <= y; ++i) 
			printf("U");
		for(int i = 0; i <= x; ++i)
			printf("R");
		printf("D");
		printf("R");
		for(int i = 0; i <= y; ++i) 
			printf("D");
		for(int i = 0; i <= x; ++i)
			printf("L");
		printf("U");
	}
	if(x < 0 && y > 0) {
		printf("R");
		for(int i = 0; i <= y; ++i) 
			printf("U");
		for(int i = 0; i <= -x; ++i)
			printf("L");
		printf("D");
		printf("L");
		for(int i = 0; i <= y; ++i) 
			printf("D");
		for(int i = 0; i <= -x; ++i)
			printf("R");
		printf("U");
	}
	if(x < 0 && y < 0) {
		printf("R");
		for(int i = 0; i <= -y; ++i) 
			printf("D");
		for(int i = 0; i <= -x; ++i)
			printf("L");
		printf("U");
		printf("L");
		for(int i = 0; i <= -y; ++i) 
			printf("U");
		for(int i = 0; i <= -x; ++i)
			printf("R");
		printf("D");
	}
	if(x > 0 && y < 0) {
		printf("L");
		for(int i = 0; i <= -y; ++i) 
			printf("D");
		for(int i = 0; i <= x; ++i)
			printf("R");
		printf("U");
		printf("R");
		for(int i = 0; i <= -y; ++i) 
			printf("U");
		for(int i = 0; i <= x; ++i)
			printf("L");
		printf("D");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi(i,a,b) for(int i=a; i<=b; i-=-1)
#define fid(i,a,b) for(int i=a; i>=b; i--)
#define ll long long
#define F first
#define S second
#define VanLoi "a"
#define maxn 100005
#define pii pair<int, int>
#define MOD 1000000007
#define B 107
#define gb(i,j) ((i >> j) & 1)
#define pb push_back
#define reset(x) memset(x, 0, sizeof(x))
#define Block 400
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

int n, m;
ll l[105][maxn], res = 0;
pii a[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen(VanLoi".inp","r",stdin);
    freopen(VanLoi".out","w",stdout);
    #endif // ONLINE_JUDGE
    cin >> n >> m;
    fi(i, 1, n) cin >> a[i].F >> a[i].S;
    fi(i, 0, n)
        fi(j, 0, m) l[i][j] = -1;
    l[0][0] = 0;
    fi(i, 1, n)
        fi(j, 0, m) if (l[i - 1][j] != -1) {
            l[i][j] = max(l[i][j], l[i - 1][j]);
            if (j + a[i].F <= m) l[i][j + a[i].F] = max(l[i][j + a[i].F], l[i - 1][j] + a[i].S);
        }
    fi(i, 0, m) res = max(res, l[n][i]);
    cout << res;
}


Measured memory_bytes: 82576
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int w,a,b;
	scanf("%d %d %d",&w,&a,&b);
	if((a+w)<b)
		printf("%d\n",b-(a+w));
	else if(b>=a&&b<=(a+w))
		printf("0\n");
	else if(b<=a&&(b+w)>=a)
		printf("0\n");
	else if(a>(b+w))
		printf("%d\n",a-(b+w));
	return 0;
}

Measured memory_bytes: 128
K, N = map(int, input().split())
A = list(map(int, input().split()))

distA = []

for i in range(N-1):
  distA.append( A[i + 1] - A[i] )
distA.append(A[0] + (K - A[N-1]) )
print(sum(distA) - max(distA))






Measured memory_bytes: 26444
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
#define N 200005
int n, q, idx, ls[N], rs[N], a[N];
int edge, to[N << 1], pr[N << 1], hd[N];
void addedge(int u, int v){
	to[++edge] = v, pr[edge] = hd[u], hd[u] = edge;
}
void dfs(int u, int fa = 0){
	ls[u] = ++idx;
	for (register int i = hd[u]; i; i = pr[i])
		if (to[i] != fa) dfs(to[i], u);
	rs[u] = idx;
}
int main(){
	n = read(), q = read();
	for (register int i = 1, u, v; i < n; ++i)
		u = read(), v = read(), addedge(u, v), addedge(v, u);
	dfs(1);
	for (register int i = 1; i <= q; ++i){
		int u = read(), v = read();
		a[ls[u]] += v, a[rs[u] + 1] -= v;
	}
	for (register int i = 1; i <= n; ++i) a[i] += a[i - 1];
	for (register int i = 1; i <= n; ++i)
		printf("%d", a[ls[i]]), putchar(" \n"[i == n]);
}

Measured memory_bytes: 17920
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
 int n,k;
 int main(){
     cin >> n >> k;
     int res = 1;
     for(int i = 0 ; i < n ; i++){
         int temp1 = res * 2;
         int temp2 = res + k;
         res = min(temp1,temp2);
     }
     cout << res << endl;
     return 0;
 }

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	list <char> l;
	char b;
	cin >> a;
	for(int i=0;i<strlen(a);i++){
		l.push_back(a[i]);
	}
	int t,n,x,f=0;
	cin >> t;
	while(t--){
		cin >> n;
		if(n==1){
			f++;
		}
		else if(n==2){
			cin >> x;
			if(x==1){
				if(f&1){
					cin >> b;
					l.push_back(b);
				}
				else{
					cin >> b;
					l.push_front(b);
				}
			}
			else if(x==2){
				if(f&1){
					cin >> b;
					l.push_front(b);
				}
				else{
					cin >> b;
					l.push_back(b);
				}
			}
		}
	}
	if(f&1){
		reverse(l.begin(),l.end());
		for(list<char>::iterator it=l.begin();it!=l.end();++it)
			cout << *it;
	}
	else{
		for(list<char>::iterator it=l.begin();it!=l.end();++it)
			cout << *it;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 9984
s = input()
key = "keyence"
if s[:7] == key:
    print("YES")
    exit()
elif s[-6:] == key:
    print("YES")
    exit()
else:
    for i in range(7):
        if s[:i] == key[:i] and s[-7+i:] == key[-7+i:]:
            print("YES")
            exit()
print("NO")

Measured memory_bytes: 3060
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

# N - A - i
# M - B - j

A2i = {A: i for i, A in enumerate(As)}
B2j = {B: j for j, B in enumerate(Bs)}

allowed_A_count = 0
allowed_B_count = 0
ans = 1
for n in range(N * M, 0, -1):
    if n in A2i:
        allowed_A_count += 1
        if n in B2j:
            allowed_B_count += 1
        else:
            ans *= allowed_B_count
            ans %= MOD
    else:
        if n in B2j:
            allowed_B_count += 1
            ans *= allowed_A_count
            ans %= MOD
        else:
            ans *= (allowed_A_count * allowed_B_count - (N * M - n)) % MOD
            ans %= MOD

print(ans)

Measured memory_bytes: 68480
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  ll a[N][3];//R = 0 G = 1 B = 2
  if(s.at(0) == 'R'){
    a[0][0] = 1;
    a[0][1] = 0;
    a[0][2] = 0;
  }
  if(s.at(0) == 'G'){
    a[0][0] = 0;
    a[0][1] = 1;
    a[0][2] = 0;
  }
  if(s.at(0) == 'B'){
    a[0][0] = 0;
    a[0][1] = 0;
    a[0][2] = 1;
  }
  for(ll i = 1;i<N;i++){
    if(s.at(i) == 'R'){
      a[i][0] = a[i-1][0]+1;
      a[i][1] = a[i-1][1];
      a[i][2] = a[i-1][2];
    }
    if(s.at(i) == 'G'){
      a[i][0] = a[i-1][0];
      a[i][1] = a[i-1][1]+1;
      a[i][2] = a[i-1][2];
    }
    if(s.at(i) == 'B'){
      a[i][0] = a[i-1][0];
      a[i][1] = a[i-1][1];
      a[i][2] = a[i-1][2]+1;
    }
  }
  ll ans = 0;
  for(ll i = 0;i<N;i++){
    if(s.at(i) == 'R'){
      ans += a[i][1]*(a[N-1][2]-a[i][2]);
      ans += a[i][2]*(a[N-1][1]-a[i][1]);
      ll p = 1;
      while((i-p)>=0 && (i+p)<N){
        if(s.at(i-p) != s.at(i+p)){
          if(s.at(i-p) != 'R' && s.at(i+p) != 'R'){
            ans--;
          }
        }
        p++;
      }
    }
    if(s.at(i) == 'G'){
      ans += a[i][0]*(a[N-1][2]-a[i][2]);
      ans += a[i][2]*(a[N-1][0]-a[i][0]);
      ll p = 1;
      while((i-p)>=0 && (i+p)<N){
        if(s.at(i-p) != s.at(i+p)){
          if(s.at(i-p) != 'G' && s.at(i+p) != 'G'){
            ans--;
          }
        }
        p++;
      }
    }
    if(s.at(i) == 'B'){
      ans += a[i][0]*(a[N-1][1]-a[i][1]);
      ans += a[i][1]*(a[N-1][0]-a[i][0]);
      ll p = 1;
      while((i-p)>=0 && (i+p)<N){
        if(s.at(i-p) != s.at(i+p)){
          if(s.at(i-p) != 'B' && s.at(i+p) != 'B'){
            ans--;
          }
        }
        p++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3720
# -*- coding utf-8 -*-
import heapq
MOD = 10 ** 9 + 7

N = int(input())
vn = map(int, input().split())
# = list(map(int, input().split()))

hq = []
for v in vn:
    heapq.heappush(hq, v)

for i in range(N - 1):
    x = heapq.heappop(hq)
    y = heapq.heappop(hq)
    heapq.heappush(hq, (x + y) / 2)

ans = hq[0]

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath> //pow

using namespace std;


int main()
{
	int N, D;
	cin >> N >> D;


	//二次元配列の動的な生成
	int** X = new int*[N];
	for (int i = 0; i < N; i++)
	{
		X[i] = new int[D];
	}



	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < D; j++)
		{
			cin >> X[i][j];
		}

	}


	//整数の数
	int count = 0;

	//基準となる座標を決める
	for (int i = 0; i < N-1; i++)
	{
		//比較対象の座標を決める
		for (int j = i+1; j < N; j++)
		{
			//実際に距離を計算
			double tmp = 0;
			for (int k = 0; k < D; k++)
			{
				//           基準の座標  比較対象の座標
				tmp += fabs(pow(X[j][k] - X[i][k], 2));
			}
			double distance = sqrt(tmp);
			//cout << distance << "\n";

			//距離が整数かどうかをチェック
			if (distance == (int) distance) {
				count++;
			}
		}
	}


	cout << count;


	return 0;
}

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

const int INF = 1LL << 28;

struct state {
  int v, s, d;
};

bool check(state c, int dy, int dx, int N) {
  int vy = c.v / N, vx = c.v % N;
  int ny = vy + dy, nx = vx + dx;
  return 0 <= ny && ny < N && 0 <= nx && nx < N && !(c.s & (1 << (ny * N + nx)));
}

state move(state c, int dy, int dx, int N) {
  int vy = c.v / N, vx = c.v % N;
  int ny = vy + dy, nx = vx + dx;

  int ns = 0;
  REP(i, 0, N) REP(j, 0, N) {
    if (i == ny && j == nx) continue;

    int cnt = 0;
    REP(di, -1, 2) REP(dj, -1, 2) if (di != 0 || dj != 0) {
      int ni = i + di, nj = j + dj;
      if (0 <= ni && ni < N && 0 <= nj && nj < N) {
        if (c.s & (1 << (ni * N + nj))) cnt++;
        if (ni == ny && nj == nx) cnt++;
      }
    }

    if (c.s & (1 << (i * N + j))) {
      if (cnt == 2 || cnt == 3) ns |= 1 << (i * N + j);
    } else {
      if (cnt == 3) ns |= 1 << (i * N + j);
    }
  }

  return (state) { ny * N + nx, ns, c.d + 1 };
}

int solve(int N, const vector<string> &S) {
  int init_v, init_s = 0;
  REP(i, 0, N) REP(j, 0, N) {
    if (S[i][j] == '@') {
      init_v = i * N + j;
    }
    if (S[i][j] == '#') {
      init_s |= 1 << (i * N + j);
    }
  }

  set<pair<int, int>> st;

  queue<state> q;
  q.push((state) { init_v, init_s, 0 });

  while (q.size()) {
    state c = q.front();
    q.pop();

    if (st.count(make_pair(c.v, c.s))) continue;
    st.insert(make_pair(c.v, c.s));

    if (c.s == 0) return c.d;

    REP(dy, -1, 2) REP(dx, -1, 2) if (dy != 0 || dx != 0) {
      if (check(c, dy, dx, N)) {
        state n = move(c, dy, dx, N);
        if (!st.count(make_pair(n.v, n.s))) q.push(n);
      }
    }
  }

  return -1;
}

int main(void) {
  for (int N; cin >> N, N;) {
    vector<string> S(N);
    REP(i, 0, N) cin >> S[i];
    cout << solve(N, S) << endl;
  }
}


Measured memory_bytes: 3428
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0)cnt++;
	}
	cout << cnt << endl;
	ggr
}



Measured memory_bytes: 3120
N = int(input())
H = list(map(int, input().split()))
max_h = H[0]
flag = 0

for i in range(1, N):
    max_h = max(max_h, H[i])
    if max_h - H[i] > 1:
        flag += 1

if flag:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 85448