akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    long long n; cin >> n;
    long long minx = 100000000;
    long long k = 1;
    while (k * k <= n){
        if (n%k == 0){
            long long x = max(to_string(n/k).size(), to_string(k).size());
            minx = min(x, minx);
        }
        k ++;
    }
    cout << minx << endl;
}

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

using namespace std;

int G[4][4];
int main(void){
	for(int i = 1;i <= 3;++i) for(int j = 1;j <= 3;++j) scanf("%d", G[i]+j);

	int flag = 0;

	for(int a1 = 0;a1 <= G[1][1];++a1){
		int b1 = G[1][1] - a1;
		for(int a2 = 0;a2 <= G[2][2];++a2){
			int b2 = G[2][2] - a2;
			for(int a3 = 0;a3 <= G[3][3];++a3){
				int b3 = G[3][3] - a3;
				if(a1 + b1 == G[1][1] && a1 + b2 == G[1][2] && a1 + b3 == G[1][3] && a2 + b1 == G[2][1] && a2 + b2 == G[2][2] && a2 + b3 == G[2][3] && a3 + b1 == G[3][
					1] && a3 + b2 == G[3][2] && a3 + b3 == G[3][3]) flag = 1;
			}
		}
	}

	if(flag == 1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}

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

int main(){
    
    int W,H,x,y,r;
    string result = "Yes";
    
    cin >> W >> H >> x >> y >> r;
    
    if (x-r < 0 || y-r < 0 || x+r > W || y+r > H) {
        
        result = "No";
    }
    
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#include<math.h>
#define ll long long
#define ld long double
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  for( ll i = 0 ; i<n ; i++ ) cin>>a[i];
  vector<ll> ans;
  if( k <= 50 )
  {
      for( ll i = 0 ; i<k ; i++ )
      {
          vector<ll> b(n,0);
          for( ll i = 0 ; i<n ; i++ )
          {
              ll x = max( 0ll , i - a[i] );
              ll y = min( n-1 , i + a[i] );
              b[x]++;
              if( y+1<n ) b[y+1]--;
          }
          for( ll i = 1 ; i<n ; i++ ) b[i]+=b[i-1];
          a = b;
      }
      for( ll i = 0 ; i<n ; i++ )
        cout<<a[i]<<" ";
  }
  else
  {
      for( ll i = 0 ; i<n ; i++ )
        cout<<n<<" ";
  }

  return 0;

}


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

int main() {
	string s,res="yes";
	cin >> s;
	int n = s.size();
	for (int i = 0;i < n - 1;i++) {
		for (int j = i + 1;j < n;j++) {
			if (s[i] == s[j]) {
				res = "no";
				break;
			}
		}
	}
	cout << res << endl;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    vll count(3,0);
    char c[3];
    rep(i,3){
        cin >> c[i];
        if(c[i] == 'a')count[0]++;
        else if(c[i] == 'b')count[1]++;
        else if(c[i] == 'c')count[2]++;
    }
    if(count[0]==1 && count[1]==1 && count[2]==1)
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
A = input()
B = input()
a,b = len(A),len(B)
F = [[0 for i in range(b+1)] for i in range(a+1)]
for i in range(a+1):
    for j in range(b+1):
        if i==0:F[i][j] = j
        elif j==0:F[i][j] = i
        else: 
            k = 0 if A[i-1]==B[j-1] else 1
            F[i][j] = min(F[i-1][j]+1,F[i][j-1]+1,F[i-1][j-1]+k)
print(F[a][b])


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

int main() {
 string x;
  cin>>x;
  if(x=="000"){
    cout<<"0"<<endl;
  }
  else if(x=="001"||x=="010"||x=="100"){
    cout<<"1"<<endl;
  }
  else if(x=="011"||x=="101"||x=="110"){
    cout<<2<<endl;
  }
     else if(x=="111"){
            cout<<"3"<<endl;
          }
}




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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n;
    cin >> n;
    
    vector<pair<pair<string,ll>,ll>> p(n);
    rep(i,n){
        string s;
        ll m;
        cin >> s >> m;
        p[i] = make_pair(make_pair(s,100-m),i+1);
    }

    sort(all(p));

    cout << endl;
    rep(i,n){
        /*cout << p[i].first.first << " ";
        cout << p[i].first.second << " ";
        */cout << p[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int jc(int x)
{
	int num=1;
	for(int i=2;i<=x;i++)
	    num*=i;
	return num;    
}
struct node{int x,y;
}k[10];
double d(node a,node b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
	int n,i,j;
	double l,num,s=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	    scanf("%d%d",&k[i].x,&k[i].y);
	for(i=1;i<=n-1;i++)
	for(j=i+1;j<=n;j++)   
	    s+=d(k[i],k[j]);
	num=jc(n)*(n-1)/(n*(n-1)/2);
	l=s*num/jc(n);
	printf("%.10lf\n",l);	 
}

Measured memory_bytes: 128
# N: 宝石の数　K: 操作できる回数
N, K = map(int, input().split())
# 宝石たちの価値
V = list(map(int, input().split()))


# 解：宝石の価値の合計
ans = 0

# 宝石の数と操作できる数で小さい方を選び、その数だけ繰り返し
for n in range(1, min(K, N)+1):
    # (操作できる回数 - 操作回数), 操作回数 で小さい方を記録
    m = min(K-n, n)
    for l in range(n+1):
        # 操作回数
        r = n-l
        # 左からl番目までの宝石と右から r番目までの宝石を格納
        S = V[:l] + (V[-r:] if r != 0 else [])
        # ソートする
        S.sort()

        an = 0
        for i, a in enumerate(S):
            if i < m and a < 0:
                continue
            else:
                an += a
        ans = max(ans, an)

print(ans)


Measured memory_bytes: 3316
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long height;
long long width;
char randomVal;


int main()
{
	
	scanf("%lld %lld", &height, &width);
	char mineSweep[height][width];
	int finalAns[height + 1][width +1];
	memset(finalAns, 0, sizeof(finalAns));

	for(int i = 0; i < height; i++)
	{
		for(int j = 0; j < width; j++)
		{
			cin >> mineSweep[i][j];
		}
	}
	for(int i = 0; i < height; i++)
	{
		for(int j = 0; j < width; j++)
		{
			if(mineSweep[i][j] == '#')
			{
				finalAns[i - 1][j]++;
				finalAns[i - 1][j - 1]++;
				finalAns[i - 1][j + 1]++;
				finalAns[i][j - 1]++;
				finalAns[i][j + 1]++;
				finalAns[i + 1][j - 1]++;
				finalAns[i + 1][j]++;
				finalAns[i + 1][j + 1]++;
			}
		}
	}
	// for(int i = 0; i < height; i++)
	// {
	// 	for(int j = 0; j < width; j++)
	// 	{
	// 		if(mineSweep[i][j] == '#')
	// 		{
	// 			finalAns[i][j] = '#';
	// 		}
	// 	}
	// }
	for(int i = 0; i < height; i++)
	{
		for(int j = 0; j < width; j++)
		{
			if(mineSweep[i][j] == '#')
			{
				cout << '#';
			}
			else
			{
				cout << finalAns[i][j];
			}

		}
		cout << "\n";
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int H,W;
char buf[105][105];

int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){

		scanf("%s",buf[row]);
	}

	for(int row = 0; row < H; row++){
		for(int i = 0; i < 2; i++){
			for(int col = 0; col < W; col++){

				printf("%c",buf[row][col]);
			}
			printf("\n");
		}
	}

	return 0;
}


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int L=A+B,R=C+D;
  if(L>R){
  cout<<"Left"<<endl;
  }
  else if(L==R){
  cout<<"Balanced"<<endl;
  }
  else {
  cout<<"Right"<<endl;
  }
  }

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

int n, A, B, C;
vector<int> l;
int dfs(int depth, int a, int b, int c, int cost) {
    if (depth == n) {
        if (min({a,b,c}) == 0) return 1e9;
        else return abs(a-A)+abs(b-B)+abs(c-C)+cost;
    }
    int ret0 = dfs(depth+1,a,b,c,cost);
    int ret1 = dfs(depth+1,a+l[depth],b,c,cost+((a==0)?0:10));
    int ret2 = dfs(depth+1,a,b+l[depth],c,cost+((b==0)?0:10));
    int ret3 = dfs(depth+1,a,b,c+l[depth],cost+((c==0)?0:10));
    return min({ret0,ret1,ret2,ret3});
}

int main() {
    cin >> n >> A >> B >> C;
    l.resize(n);
    rep(i,n) cin >> l[i];
    cout << dfs(0,0,0,0,0) << endl;
}

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

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  int ans = 0;
  for(int i = 0; i < 3; i++){
    if(s[i] == t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
n, x, mod = map(int, input().split())
lst = [0, x]
num_set = set([x])
num_lst = [0, x]
flag = False

for i in range(mod - 1):
  x = (x * x) % mod
  s = x + lst[-1]
  if x == 0:
    lst.append(s)
    break
  if x in num_set:
    flag = True
    break
  lst.append(s)
  num_set.add(x)
  num_lst.append(x)
  if i + 2 == n:
    break

#print(lst)
if flag:
  for i, ele in enumerate(num_lst):
    if x == ele:
      loop_s = i
      break

l = len(lst)
if lst[l - 1] == lst[l - 2]:
  print(lst[l - 1])
else:
  if not flag:
    print(lst[-1])
  else:
    loop = len(lst) - loop_s
    n -= loop_s - 1
    c = n // loop
    r = n % loop
    ans = lst[l - 1] + (c - 1) * (lst[l - 1] - lst[loop_s - 1]) + lst[loop_s + r - 1] - lst[loop_s - 1]
    print(ans)


Measured memory_bytes: 15588
#include <stdint.h>

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

template <int64_t Mod>
struct ModInt {
  int64_t x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % Mod : (Mod - (-y) % Mod) % Mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= Mod) x -= Mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += Mod - p.x) >= Mod) x -= Mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = int64_t(1LL * x * p.x % Mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.Inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt Inverse() const {
    int64_t a = x, b = Mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt Pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<Mod>(t);
    return (is);
  }

  static int64_t GetMod() { return Mod; }
};

template <typename T>
struct Combination {
  vector<T> _fact, _rfact, _inv;

  Combination(int64_t sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for (int64_t i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for (int64_t i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for (int64_t i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T Fact(int64_t k) const { return _fact[k]; }

  inline T Rfact(int64_t k) const { return _rfact[k]; }

  inline T Inv(int64_t k) const { return _inv[k]; }

  T P(int64_t n, int64_t r) const {
    if (r < 0 || n < r) return 0;
    return Fact(n) * Rfact(n - r);
  }

  T C(int64_t p, int64_t q) const {
    if (q < 0 || p < q) return 0;
    return Fact(p) * Rfact(q) * Rfact(p - q);
  }

  T H(int64_t n, int64_t r) const {
    if (n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

using Mi = ModInt<1000000007>;

int main(void) {
  Combination<Mi> combi(1000000);

  int64_t X, Y;
  cin >> X >> Y;

  if (X < Y) {
    swap(X, Y);
  }

  int64_t Z = X - Y;

  for (int64_t k = 0; k <= 500000; ++k) {
    int64_t x = 2 * (Z + k) + k;
    int64_t y = 2 * k + (Z + k);

    if (x == X && y == Y) {
      int64_t n = Z + k + k;
      cout << combi.C(n, k) << endl;
      return 0;
    }
  }
  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 26572
N = int(input())
S = []
for _ in range(N):
    S.append(int(input()))


max1=-1
max2=-10

max1_ind=-100
max2_ind=-100

for i in range(len(S)):
        if S[i] > max1:
                max2=max1
                max2_ind = max1_ind

                max1=S[i]
                max1_ind=i
        elif S[i] > max2:
                max2=S[i]
                max2_ind=i

for i in range(len(S)):
        if i != max1_ind:
                print(max1)
        else:
                print(max2)

Measured memory_bytes: 12532
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 2000000
#define MOD 1000000007

int main(){
  int N,W;
  cin>>N>>W;
  vector<ll> w(N),v(N);
  for(int i=0;i<N;i++){
    cin>>w.at(i)>>v.at(i);
  }

  vector<ll> dp(W+1,0);
  for(int i=0;i<N;i++){
    for(int j=W;j>=w.at(i);j--){
      dp.at(j)=max<ll>(dp.at(j),dp.at(j-w.at(i))+v.at(i));
    }
  }
  ll ans=0;
  for(int i=0;i<=W;i++){
    ans=max<ll>(ans,dp.at(i));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
input=sys.stdin.readline
h,w=map(int,input().split())
a=[list(map(str,input())) for _ in range(h)]
b=deque()
n=[-1]*(h*w)
p=((1,0),(-1,0),(0,1),(0,-1))
for x in range(h):
  for y in range(w):
    if a[x][y]=="#":
      b.append((x,y))
      n[x*w+y]=0
while b:
  x,y=b.popleft()
  for idx in p:
    s,t=idx
    if 0<=x+s<h and 0<=y+t<w:
      if n[(x+s)*w+(y+t)]==-1:
        n[(x+s)*w+(y+t)]=n[x*w+y]+1
        b.append((x+s,y+t))
print(max(n))


Measured memory_bytes: 122076
#include<iostream>
using namespace std;
int main(void){
  long h;
  int n, temp;
  cin >> h;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> temp; 
    h = h-temp;
  }
  if(h<=0){
  	cout << "Yes";
  }else{
  	cout << "No";
  }
}

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

using namespace std;

#define DIM 200009
#define INF ((long long)1e18+9ll)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double
#define endl '\n'
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define amen exit(0)

long long i,j,k,l,n,m,sz;

struct line{
    long long k,b;
};

line ls[DIM];

long long dp[DIM],a[DIM],b[DIM];

bool check(line a1,line a2,line a3){
    return (ld)(a1.b-a2.b)/(ld)(a1.k-a2.k)>=(ld)(a1.b-a3.b)/(ld)(a1.k-a3.k);
}

void add(long long k,long long b){
    line a={k,b};
    while(sz>1 && check(ls[sz-1],a,ls[sz]))sz--;
    ls[++sz]=a;
}

long long get(line a,long long x){
    return a.k*x+a.b;
}

long long bs(long long x){
    long long l=0,r=sz;
    while(r-l>1){
        long long mid=(l+r)/2;
        if(get(ls[mid],x)<get(ls[mid+1],x))r=mid;
        else l=mid;
    }
    return get(ls[r],x);
}

long long C;

int main()
{
    fast;

    cin>>n>>C;
    for(i=1;i<=n;i++)cin>>a[i];

    dp[1]=0;
    add(-2*a[1],a[1]*a[1]);
    for(i=2;i<=n;i++){
        dp[i]=bs(a[i])+a[i]*a[i]+C;
        add(-2*a[i],dp[i]+a[i]*a[i]);
    }

    cout<<dp[n]<<endl;

    amen;
}
/**
dp[i]=dp[j]+(h[i]-h[j])*(h[i]-h[j])+C
dp[i]=dp[j]+h[i]*h[i]-2*h[i]*h[j]+h[j]*h[j]+C

b=dp[j]+h[i]*h[i]+h[j]*h[j]+C
k=-2*h[i]
*/


Measured memory_bytes: 6528
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

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

    for(int i = n - 1; i >= 0; i--){
      System.out.print(a[i]);
      
      if(i != 0){
        System.out.print(" ");
      } else {
        System.out.println();
      }
    }
  }
}



Measured memory_bytes: 26316
N = input()


def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if int(N[0]) > 3:
            ret += f(len(N) - 1, used, "3")
        if int(N[0]) > 5:
            ret += f(len(N) - 1, used, "5")
        if int(N[0]) > 7:
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret

    if N[0] in ["3", "5", "7"]:
        ret = high(N[1:], used | set(N[0]), ret)

    return ret


def low():
    d = 0
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)
        d += 1
    return ret


def main():
    print(high(N, set(), low()))
    return


main()


Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    p,q,r = LI()
    print(p+q+r-max(p,q,r))
    return

#B
def B():
    n = I()
    w = LI()
    ans = float("inf")
    for i in range(n):
        m = sum(w[:i])
        l = sum(w[i:])
        ans = min(ans,abs(m-l))
    print(ans)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 39280
import collections
def main():
  N,K = map(int, input().split())
  lists=[0]*N
  num_list = [list(map(int, input().split())) for _ in range(2*K)]
  num_list2=[list(num_list[i]) for i in range(1,2*K,2)]
  for i in range(K):
    tgtlist=num_list2[i]
    for j in range(len(tgtlist)):
      lists[tgtlist[j]-1]=lists[tgtlist[j]-1]+1
  print(len([i for i, x in enumerate(lists) if x == 0]))
  
    
if __name__=='__main__':
  main()

Measured memory_bytes: 67932
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

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

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

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    int n,k;
    cin >> n >> k;
    vector<bool> ans(n,false);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d) {
            int a;
            cin >> a;
            ans.at(a-1)=true;
        }
    }
    int cnt=0;
    rep(i,n) {
        if(!ans.at(i)) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3860
/* ABC116 */
/* A */
#include <iostream>
#include <algorithm>
using namespace std;

int main(void){

    int arr[3];
    for (int i=0; i<3; ++i)
        cin >> arr[i];

    sort(arr, arr+3);

    int S;
    S = (arr[0] * arr[1]) /2;

    cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
//#define DEBUG
using namespace std;

int main(){
    long long N, A, B, C, D, E;
    cin >> N;
    cin >> A >> B >> C >> D >> E;
    long long MinMove = min( {A, B, C, D, E} );
    long long ans = ((N + MinMove - 1) / MinMove) + 4;

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
vint node[SIZE];
int num[SIZE]={};
bool done[SIZE]={};
bool eone[SIZE]={};
vpint seg;
void DFS(int now){
	done[now]=1;
	if(!node[now].size())
		return;
	//可能な区間を求める
	int left=seg[now].first, right=seg[now].second;
	for(int next:node[now]){
		if(done[next])
			continue;
		DFS(next);
		left=max(left, seg[next].first-1);
		right=min(right, seg[next].second+1);
	}
	seg[now]=mp(left, right);
}
int con(int now, int prev){
	eone[now]=1;
	int left=seg[now].first, right=seg[now].second;
	bool isNG=0;
	if(right<left)
		isNG=1;
	else if(num[now]!=-1){
		if(left<=num[now] && num[now]<=right)
			isNG=0;
		else
			isNG=1;
	}
	else if(now==0)
		num[now]=left;
	else if(left<=prev+1 && prev+1<=right)
		num[now]=prev+1;
	else if(left<=prev-1 && prev-1<=right)
		num[now]=prev-1;
	else
		isNG=1;
	if(isNG)
		return 1;
	else{
		for(int next:node[now]){
			if(!eone[next] && con(next, num[now]))
				return 1;
		}
		return 0;
	}
}
signed main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
		seg.eb(-INF, INF);
	for(int i=0;i<SIZE;i++)
		num[i]=-1;
	for(int i=0;i<N-1;i++){
		int a, b;
		cin>>a>>b;
		a--, b--;
		node[a].pb(b);
		node[b].pb(a);
	}
	int K;
	cin>>K;
	for(int i=0;i<K;i++){
		int a, b;
		cin>>a>>b;
		a--;
		seg[a]=mp(b, b);
	}
	DFS(0);
	if(con(0, 0)){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<N;i++)
		cout<<num[i]<<endl;

	return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;

#define MAX 1145141

vector<bool>isPrime(MAX,true);

void sieve(){
        for(ll i=2;i<MAX;i++){
                if(isPrime[i]){
                        for(ll j=i+i;j<1145141;j+=i)isPrime[j]=false;
                }
        }
        isPrime[0]=false;
        isPrime[1]=false;
}

int main(){
        int a,d,n;
        sieve();
        while(cin>>a>>d>>n&&a,d,n){
                int tmp=0;
                for(ll i=a;;i+=d){
                        if(isPrime[i])tmp++;
                        if(tmp==n){
                                cout<<i<<endl;
                                break;
                        }
                }
        }
        return 0;
}


Measured memory_bytes: 3024
#include <iostream>

int main(int argc, char *argv[])
{
    char s[6];
    int ans;

    std::cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        std::cout << "Bad" << std::endl;
    } else {
        std::cout << "Good" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int A[100],N,i,j,temp,tempcount=0,flag;  
  scanf("%d",&N);

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

  flag = 1;
  while(flag){
    flag = 0;
    for(j=N-1 ; j>=1 ; j--){
      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	flag = 1;
        tempcount++ ;
      }
    }
  }

  for(i=0 ; i<N ; i++){
    if(i > 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",tempcount);
  return 0;
}




Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;

#define ll long long

int H,W;
char s[51][51];
char ans[51][51];
int dx[8] = {-1,-1,-1,0,1,1,1,0};
int dy[8] = {-1,0,1,1,1,0,-1,-1};

int main(){
    int H, W;
    int tmp;
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#'){
                ans[i][j] = '#';
                cout << ans[i][j];
            }else{
                int tmp = 0;
                for(int k = 0; k < 8; k++){
                    int ni, nj;
                    ni = i + dx[k];
                    nj = j + dy[k];
                    if(ni >= 0 && ni < H && nj >= 0 && nj < W){
                        if(s[ni][nj] == '#') tmp++;
                    }
                }
                cout << tmp; 
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        readonly args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc001 {
    export class TaskA implements AtCoder.Task, AtCoder.Paramable {
        public constructor(public readonly args: string[][]) {
        }

        public main(this: TaskA): void {

            const r :number = +this.args[0][0];
            const g :number = +this.args[1][0];

            // (2032 + 2002) /2 = 2017
            // (x + 2002) /2 = 2017
            // (2017*2) - 2002 = 2032

            console.log(g*2-r);



        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
    const task: AtCoder.Task = new TaskA(args);
    task.main();
}



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

using namespace std;

typedef long long ll;

const int maxn = 1e5+500;
ll T,n,m;
int s[1005][1005];
int ct[1005];
int vis[maxn];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=0;j<n-1;j++){
			scanf("%d",&s[i][j]);
		}
		ct[i] = 0;
	}
	int cnt = 0,sum=0;
	while(1){
		int flag=0;
		for(int i=1;i<=n;i++)
			vis[i] = 0;
		for(int i=1;i<=n;i++){
			int now = s[i][ct[i]];
			if(ct[i]>=n-1)
				continue;
			if(vis[now]){
				vis[i] = 1;
				continue;
			}
			if(vis[i])
				continue;
			if(i==s[now][ct[now]]&&!vis[i]&&!vis[now]){
				vis[i] = 1;
				vis[now]=1;
				ct[i]++;
				ct[now]++;
				flag = 1;
				sum++;
			}
		}
		if(!flag){
			printf("-1\n");
			return 0;
		}
		cnt++;
		if(sum==(n*(n-1)/2)){
			break;
		}
	}
	printf("%d\n",cnt);
	
}

Measured memory_bytes: 4224
n = int(input())
xl = [list(map(int,input().split())) for _ in range(n)]
xl_two = sorted([[xl[i][0]+xl[i][1],xl[i][0]-xl[i][1]] for i in range(n)])
ans = 0
flag = -float("inf")
for i in range(n):
  if flag <= xl_two[i][1]:
    flag = xl_two[i][0]
    ans += 1
print(ans)

Measured memory_bytes: 77400
use std::io;
use std::str::FromStr;

fn main() {
    let reader = io::stdin();
    let mut line = String::new();
    reader.read_line(&mut line).unwrap();
    let words:Vec<&str> = line.trim().split(" ").collect();
    let x = i32::from_str(words[0]).unwrap();
    let a = i32::from_str(words[1]).unwrap();

    if x < a {
        println!("0");
    } else {
        println!("10");
    }
}

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

int main(void){
    char s,t;
    cin >> s;
    t = s + 1;
    cout << t << endl;
    
    return 0;
    
}




















































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/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);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll getsize(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;
    int x[M], y[M], z[M];
    rep(i, M) {
        cin >> x[i] >> y[i] >> z[i];
        x[i]--; y[i]--;
    }

    UnionFind ut(N);
    rep(i, M) {
        ut.unite(x[i], y[i]);
    }
    set<int> st;
    rep(i, N) {
        st.insert(ut.root(i));
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[255]={0};
	for(int i=0;i<3;i++)
	{
		char c;
		cin>>c;
		a[c]++;
	}
	if(a['a']==1&&a['b']==1&&a['c']==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
	
}

Measured memory_bytes: 256
# coding: utf-8

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if i == A[A[i] - 1] - 1:
            ans += 1
    print(ans // 2)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20480
#include<iostream>
#include<string>
using namespace std;
string S; int sum;
int main() {
	while (cin >> S) {
		for (int i = 0; i < S.size() / 2; i++) {
			if (S[i] != S[S.size() - 1 - i]) { goto E; }
		}
		sum++;
	E:;
	}
	cout << sum << endl;
}

Measured memory_bytes: 1184
d=input().split(" ")
a0=input().split(" ")
a1=input().split(" ")
a2=input().split(" ")
a3=input().split(" ")
a4=input().split(" ")
a5=input().split(" ")
a6=input().split(" ")
a7=input().split(" ")
a8=input().split(" ")
a9=input().split(" ")
AA=[a0,a1,a2,a3,a4,a5,a6,a7,a8,a9]
stop=0
for k in range(10):
    for i in range(10):
        for j in range(10):
            AA[i][j]=min(int(AA[i][j]),int(AA[i][k])+int(AA[k][j]))
for i in range(int(d[0])):
    gear=input().split()
    for j in range(int(d[1])):
        if int(gear[j])!=-1:
            stop+=int(AA[int(gear[j])][1])
print(stop)

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

using namespace std;

void solve() {
	int N;
	cin >> N;

	/* calculate */
	int ans = 0;
	const int P_MAX = 15;
	int prime[P_MAX] =
			{ 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
	int i, j, k;
	for (i = 0; i < P_MAX; ++i) {
		if (prime[i] * prime[i + 1] * prime[i + 2] > N) {
			break;
		}
		for (j = i + 1; j < P_MAX; ++j) {
			if (prime[i] * prime[j] * prime[j + 1] > N) {
				break;
			}
			for (k = j + 1; k < P_MAX; ++k) {
				if (prime[i] * prime[j] * prime[k] > N) {
					break;
				} else {
					ans++;
				}
			}
		}
	}

	for (i = 0; i < P_MAX; ++i) {
		if (prime[i] * prime[i] * prime[i] * prime[i + 1] > N) {
			break;
		}
		for (j = i + 1; j < P_MAX; ++j) {
			if (prime[i] * prime[i] * prime[i] * prime[j] > N) {
				break;
			} else {
				ans++;
			}
		}
	}

	/* print */
	cout << ans << endl;
}

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


Measured memory_bytes: 256
#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 pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

set<int> st;
int main(){
    int n,ai;
    cin>>n;
    rep(i,n){
        cin>>ai;
        st.insert(ai);
    }
    int m;
    cin>>m;
    int ans=0;
    rep(i,m){
        cin>>ai;
        if(st.count(ai)>0) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int h,w;
	cin >> h >> w;
	char field[h][w];
	FOR(i,0,h)cin >> field[i];
	bool checked[h][w];
	FOR(i,0,h)FOR(j,0,w)checked[i][j] = false;
	ll ans = 0;
	FOR(i,0,h)FOR(j,0,w){
		if(!checked[i][j]){
			queue<pii> bfs;
			bfs.push(mp(i,j));
			checked[i][j] = true;
			ll countB,countW;
			countB = countW = 0;
			while(!bfs.empty()){
				int y = bfs.front().first;
				int x = bfs.front().second;
				//cout << y << " " << x << endl;
				bfs.pop();
				if(field[y][x] == '#'){
					countB++;
				}else{
					countW++;
				}
				int dy[4] = {0,1,0,-1};
				int dx[4] = {1,0,-1,0};
				FOR(k,0,4){
					int ny = y + dy[k];
					int nx = x + dx[k];
					if(ny < 0 || h <= ny)continue;
					if(nx < 0 || w <= nx)continue;
					if(checked[ny][nx])continue;
					if(field[y][x] == field[ny][nx])continue;
					checked[ny][nx] = true;
					bfs.push(mp(ny,nx));
				}
			}
			ans += countB * countW;
			//cout << "----------------------\n";
		}
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	long long x,a;
	while(~scanf("%lld%lld",&x,&a)&&x>=0&&x<=9&&a>=0&&a<=9)
	{
		if(x<a)
		printf("%d\n",0);
		else
		printf("%d\n",10);
	}
}

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

int main(void){
    long long A, B, K;
    cin >> A >> B >> K;
    if(A > K){
        cout << A-K << " " << B << endl;
    }else if (A+B > K){
        cout << 0 << " " << A+B-K << endl;
    }else cout << "0 0" << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))

good = [True for _ in range(n)]

for _ in range(m):
	a, b = map(int, input().split())
	a -= 1
	b -= 1
	if (h[a] >= h[b]):
		good[b] = False
	if (h[b] >= h[a]):
		good[a] = False

print(len([i for i in good if i]))

Measured memory_bytes: 20120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int N;
	scanf("%d", &N);

	long long A[N];
	long long B[N];
	long long C[N];
	long long sumb[N];
	long long sumc[N];

	for(int i=0;i<N;i++){
		scanf("%lld",&A[i]);
	}
	sort(A,A+N);
	for(int i=0;i<N;i++){
		scanf("%lld",&B[i]);
	}
	sort(B,B+N);

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

	long long ans = 0;
	for(int i=0;i<N;i++){
		int b,c;
		b = lower_bound(A, A+N, B[i]) - A;
		c = N - (upper_bound(C, C+N, B[i]) - C);
		ans += (long long)b * c;
		//printf("%d: %lld\n",i,b*c);
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 2560
a, b = map(int,input().split())
def d(a, b):
    D = a // b
    return D
def r(a, b):
    R = a % b
    return R
def f(a, b):
    F = a / b
    return F
print('{0} {1} {2:.5f}'.format(d(a, b), r(a, b), f(a, b)))
    
        


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int W,H;
char field[60][60];
int dx[8]{-1,0,1,-1,1,-1,0,1};
int dy[8]{1,1,1,0,0,-1,-1,-1};

void dfs(int x,int y){
    field[x][y] = '0';
    for(int i = 0;i < 8;i++){
        int nx = x + dy[i];
        int ny = y + dx[i];
        if(0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] == '1'){
            dfs(nx,ny);
        }
    }
    return;
}
int main(){
    for(int k = 0;1;k++){
    cin >> W >> H;
    if(H == 0 && W == 0){
        return 0;
    }
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            cin >> field[i][j];
        }
    }
    int ans = 0;
    bool frag = 0;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(field[i][j] == '1'){
                ans++;
                dfs(i,j);
            }
        }
    }
    cout << ans  << endl;
    }
}



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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  rep(i,n){
    if(n == i*108/100){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
x = sorted(set(a))
if (max(a) - 1) // 2 + 1 == min(a):
  if max(a) & 1:
    m = m = a.count(x[0]) != 2
    for i in range(x[0],x[-1]+1):
      if a.count(i) < 2: m = 1
    if m:
      print("Impossible")
    else:
      print("Possible")
  else:
    m = a.count(x[0]) != 1
    for i in range(x[0]+1,x[-1]+1):
      if a.count(i) < 2: m = 1
    if m:
      print("Impossible")
    else:
      print("Possible")
else:
  print("Impossible")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define     mkp(a,b)    make_pair(a,b)
#define     PI          3.14159265359
#define     ll              long long
#define     ul              unsigned long long
#define     ld              long double
#define     mset(arr,val)   memset(arr,val,sizeof arr)
#define     MAXN            (long long)2e5+5
#define     eb              emplace_back
#define     mod             (long long)(1e9+7)
#define     FILE_READ       freopen("input.txt","r",stdin)
#define     FILE_WRITE      freopen("output.txt","w",stdout)
using namespace std;
using namespace __gnu_pbds;;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void dfs(int root,int par,vector<int> nbs[],ll val[]) {
    for(auto i:nbs[root]) {
        if(i==par) {
            continue;
        }
        val[i]+=val[root];
        dfs(i,root,nbs,val);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
//    FILE_READ;
//    FILE_WRITE;

    int n,q;
    cin>>n>>q;
    vector<int> nbs[n+1];
    ll val[n+1]={0};
    for(int i=0;i<n-1;++i) {
        int u,v;
        cin>>u>>v;
        nbs[u].eb(v);
        nbs[v].eb(u);
    }
    while(q--) {
        ll u,v;
        cin>>u>>v;
        val[u]+=v;
    }
    dfs(1,0,nbs,val);
    for(int i=1;i<=n;++i) {
        cout<<val[i]<<" ";
    }

    return 0;
}

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

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

    int k,t;
    cin >> k >> t;
    
    vector<int> a(t);
    for(int i = 0; i < t; i++){
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    
    int sum = 0;
    for(int i = 0; i < t - 1; i++){
        sum += a[i];
    }
    if(a[t-1] - sum <= 1) cout << 0 << endl;
    else cout << a[t-1] - sum - 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;

int main()
{
    int n;
    while(cin>>n){
        
        if(n==0){
            break;
        }
        priority_queue<int> maxpq;
        int a, b=0;
        
        for(int i=0; i<n; i++){
            cin >> a;
            maxpq.push(a);
        }
        
        maxpq.pop();
        
        for(int i=0; i<n-2; i++){
            b +=maxpq.top();
            maxpq.pop();
        }
        
        cout << b/(n-2) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n ; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> C(N), S(N), F(N);
    rep(i, N-1) {
        cin >> C[i] >> S[i] >> F[i];
    }
    rep(i, N) {
        ll t = 0; // i回目の値
        for (ll j = i; j < N - 1;++j) {
            if (t < S[j]) {
                t = S[j];
            } else if (t % F[j] == 0) {
                ;
            } else {
                t += F[j] - t % F[j];
            }
            t += C[j];
        }
        cout << t << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  for (int i = 0; i < (a + b + 1); ++i) {
    if (i == a) continue;
    if (s[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }
  
  if (s[a] == '-') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
      


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n ;
ll ans ,x , a;
int main()
{
	IO;
    cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        ans=__gcd(ans,abs(x-a));
    }
    cout<<ans;
}


Measured memory_bytes: 256
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout<<endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x ; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll x, y;
		cin >> x >> y;



		double b = y / 2.0 - x;
		double a = x - b;

		if (y > x && a >= 0 && b >= 0 && floor(a) == ceil(a) && floor(b) == ceil(b))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;

	}
	CLOCK
	return 0;
}



Measured memory_bytes: 3852
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc081/tasks/abc081_a

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    s = input().strip()
    print(s.count('1'))


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 2940
from itertools import combinations

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

border = (n - 1) * (n - 2) // 2

if k > border:
  print(-1)
else:
  print(n - 1 + border - k)
  comb = list(combinations([i for i in range(1, n + 1)], 2))
  for i, j in comb[:n - 1 + border - k]:
    print(i, j)

Measured memory_bytes: 9480
import heapq
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a)) 
heapq.heapify(a)
for i in range(m):
    tmp = math.ceil(heapq.heappop(a)/2)
    heapq.heappush(a, tmp)
a = list(map(lambda x: x*(-1), a)) 
print(sum(a))

Measured memory_bytes: 110616