akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const int inf = 1<<30;
const LL maxn = 1e5+10;
const int mod = 2019;

int main()
{
    LL l, r;
    cin >> l >> r;
    if((r/mod) != (l/mod))
        cout << "0" << endl;
    else{
        l %= mod, r %= mod;
        LL ans = inf, t1 = min(l, r), t = max(l, r);
        for(LL i = t1; i <= t; ++i)
            for(LL j = i+1; j <= t; ++j)
                ans = min(ans, i*j%mod);
        cout << ans << endl;
    }

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <string>
#include <set>

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

#define rep(i, N) for(ll i = 0; i < (N); ++i)

int main(){
    cin.tie(nullptr);

    ll N;
    cin >> N;

    map<ll, vector<ll>> edge[2];
    rep(i, N){
        ll x, y;
        cin >> x >> y;
        edge[0][x].push_back(y);
        edge[1][y].push_back(x);
    }

    set<ll> look[2]{};
    ll sum = 0;
    for(auto const &p : edge[0]){
        if(look[0].find(p.first) != look[0].end()) continue;
        queue<pair<int, ll>> q;
        q.emplace(0, p.first);
        ll c[2] = {};
        while(!q.empty()){
            auto &v = q.front();
            auto xory = v.first;
            auto index = v.second;
            q.pop();
            if(look[xory].find(index) != look[xory].end()) continue;
            look[xory].emplace(index);
            c[xory]++;
            for(auto const &v : edge[xory][index]){
                q.emplace(xory ^ 1, v);
            }
        }
        sum += c[0] * c[1];
    }

    cout << sum - N << endl;

    return 0;
}


Measured memory_bytes: 16384
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int p[100010], q[100010], r[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    
    rep(i, A) cin >> p[i];
    rep(i, B) cin >> q[i];
    rep(i, C) cin >> r[i];
    priority_queue<int> que;
    sort(p, p + A, greater<int>());
    sort(q, q + B, greater<int>());
    sort(r, r + C, greater<int>());
    rep(i, X) que.push(p[i]);
    rep(i, Y) que.push(q[i]);
    rep(i, C) que.push(r[i]);
    int ans = 0;
    rep(i, X + Y) {
        ans += que.top(); que.pop();
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 8816
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  vector<int> b(n);  //ソート用
  rep(i, n) b.push_back(a.at(i));
  sort(b.begin(), b.end(), greater<int>());
  int first = b.at(0);
  int second = b.at(1);

  rep(i, n) {
    if (a.at(i) == first)
      cout << second << " ";
    else {
      cout << first << " ";
    }
  }

  return 0;
}

/*
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n;cin>>n;
    int a[n],b[n];
    rep(i,n){
        cin>>a[i];b[i]=a[i];
    }
    sort(b,b+n, greater<int>());
    rep(i,n){
        co((a[i]==b[0])?b[1]:b[0]);
    }
}

*/

Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int H[N];
  for(int i = 0; i < N; i++){
  	cin >> H[i];
  }
  int count = 0;
  for(int i = 1; i <= N-1; i++){
  	for(int j = 0; j < i; j++){
    	if(H[j] > H[i]){
        	break;
        }
      	if(j+1 == i){
        	count++;
        }
    }
  }
  
  cout << count+1 << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> t, std::vector<long long> x, std::vector<long long> y) {
    ll prevt = 0;
    ll prevpos = 0;
    rep(i, N) {
        ll difft = t[i] - prevt;
        ll diffpos = abs(x[i] + y[i] - prevpos);

        if (difft >= diffpos && (difft % 2 == diffpos % 2)) {
            prevt = t[i];
            prevpos = x[i] + y[i];
            continue;
        } else {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> t(N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &t[i]);
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, std::move(t), std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 100000000

using namespace std;

int main() {
   int n,k,x,y;
   cin >> n >> k >> x >> y;
   if(k<n)
   cout << x*k+y*(n-k) << endl;
   else 
   cout << x*n << endl;
}

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

#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(a);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
const int mod=1e9+7;
const int mxN = 1e5+5;

ll n,nw;
vi v,w;
vector<vi> dp;

void solve(){
	cin>>n>>nw;
	v = vi(n+1);
	w = vi(n+1);
	dp = vector<vi>(n+1,vi(mxN));
	rep(j,1,mxN) dp[0][j] = mod;
	// dp[i][j] dentoes the min weight when using atmost i items and j value;
	trv(i,1,n+1) cin>>w[i]>>v[i];
	rep(i,1,n){
		rep(j,1,mxN){
			dp[i][j]=dp[i-1][j];
			if(j-v[i]>=0){
				dp[i][j] = min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
			}
		}
	}
	ll ans = mod;
	trv(j,mxN,0){
		if(dp[n][j] <= nw){
			ans = j;
			break;
		}
	}
	cout<<ans;
}

int main(){
	solve();
}
/*input
3 8
3 30
4 50
5 60

*/

Measured memory_bytes: 80256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

template<class T>
struct CumulativeSum2D{
  vector2d<T> cum;

  CumulativeSum2D(const vector2d<T>& data):cum(data.size(), vector<T>(data[0].size(),0)){
    cum[0][0]=data[0][0];
    for(int r=1;r<data.size();r++){
      cum[r][0]=cum[r-1][0]+data[r][0];
    }
    for(int c = 1; c < data[0].size(); ++c){
      cum[0][c]=cum[0][c-1]+data[0][c];
    }
    for(int r = 1; r < data.size(); ++r){
      for(int c = 1; c < data[0].size(); ++c){
        cum[r][c]=cum[r-1][c]+cum[r][c-1]-cum[r-1][c-1]+data[r][c];
      }
    }
  }


  /// \return 2頂点が(sr,sc)と(gr,gc)であるような矩形内の和(2頂点を含む)
  T Query(int sr, int sc, int gr, int gc){
    T result=cum[gr][gc];
    if(sr-1>=0){
      result-=cum[sr-1][gc];
    }
    if(sc-1>=0){
      result-=cum[gr][sc-1];
    }
    if(sr-1>=0&&sc-1>=0){
      result+=cum[sr-1][sc-1];
    }
    return result;
  }
};

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;
  auto *wpos=new vector2d<int>(2*k,vector<int>(2*k,0)),*bpos=new vector2d<int>(2*k,vector<int>(2*k,0));
  int mod=2*k;
  for(int i = 0; i < n; ++i){
    lint x,y;
    char c;
    cin>>x>>y>>c;
    if(c=='W'){
      (*wpos)[x%mod][y%mod]++;
    }else{
      (*bpos)[x%mod][y%mod]++;
    }
  }

  vector2d<int> wposl(4*k,vector<int>(4*k,0)),bposl(4*k,vector<int>(4*k,0));
  for(lint r=0;r<mod;r++){
    for(lint c=0;c<mod;c++){
      wposl[r][c]=(*wpos)[r][c];
      wposl[r+mod][c+mod]=(*wpos)[r][c];
      wposl[r][c+mod]=(*wpos)[r][c];
      wposl[r+mod][c]=(*wpos)[r][c];
    }
  }
  for(lint r=0;r<mod;r++){
    for(lint c=0;c<mod;c++){
      bposl[r][c]=(*bpos)[r][c];
      bposl[r+mod][c+mod]=(*bpos)[r][c];
      bposl[r+mod][c]=(*bpos)[r][c];
      bposl[r][c+mod]=(*bpos)[r][c];
    }
  }

  delete bpos;
  delete wpos;

  CumulativeSum2D<int> wcum(wposl),bcum(bposl);

  int result=0;

  for(lint r=0;r<mod;r++){
    for(lint c=0;c<mod;c++){
      int tmp=wcum.Query(r,c,r+k-1,c+k-1)+wcum.Query(r+k,c+k,r+2*k-1,c+2*k-1)+bcum.Query(r+k,c,r+2*k-1,c+k-1)+bcum.Query(r,c+k,r+k-1,c+2*k-1);
      UpdateMax(result,tmp);
    }
  }
  cout<<result<<endl;

  return 0;
}



Measured memory_bytes: 250880
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int cum_char_counts[3][4000];
int get_left_char(char c1, char c2){
  if(c1 > c2){
    char tmp = c1;
    c1 = c2;
    c2 = tmp;
  }
  if(c1 == 'B' && c2 == 'R'){
    return 1;
  } else if(c1 == 'B' && c2 == 'G'){
    return 0;
  }
  return 2;
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  if(S[0] == 'R'){
    cum_char_counts[0][0] = 1;
  } else if(S[0] == 'G'){
    cum_char_counts[1][0] = 1;
  } else {
    cum_char_counts[2][0] = 1;
  }

  for(int i = 1; i < N; i++){
    for(int j = 0; j < 3; j++){
      cum_char_counts[j][i] = cum_char_counts[j][i - 1];
    }
    if(S[i] == 'R'){
      cum_char_counts[0][i] ++;
    } else if(S[i] == 'G'){
      cum_char_counts[1][i] ++;
    } else {
      cum_char_counts[2][i] ++;
    }
  }

  long long ans = 0;
  for(int i = 0; i < N - 2; i++){
    for(int j = i + 1; j < N - 1; j++){
      if(S[i] != S[j]){
        int cum_ind = get_left_char(S[i], S[j]);
        int forbidden = 2 * j - i;
        if(forbidden < N){
          int tmp = cum_char_counts[cum_ind][forbidden] - cum_char_counts[cum_ind][forbidden - 1];
          ans += cum_char_counts[cum_ind][N - 1] - cum_char_counts[cum_ind][j] - tmp;
        } else {
          ans += cum_char_counts[cum_ind][N - 1] - cum_char_counts[cum_ind][j];
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3680
#include <stdio.h>

#define MIN(a, b) ((a > b)? b : a)

#define INFINITY (30000)

int main(void)
{
	int big, mini;
	int c_big, c_mini;
	int need;
	int min = INFINITY;
	
	scanf("%d %d %d", &big, &mini, &need);
	
	for (c_big = c_mini = 0; (c_mini * 500) < need; c_mini++);
	
	while (c_mini >= 0){
		min = MIN(min, (big * c_big) + (mini * c_mini));
		c_mini--;
		if ((c_big * 1000) + (c_mini * 500) < need) c_big++;
	}
	
	printf("%d\n", min);
	
	return (0);
}



Measured memory_bytes: 2052
#include<iostream>
#include<string>
using namespace std;
int main () {
  string S;
  cin >> S;
  string key = "keyence";
  int N = S.size();
  for (int i = 0; i <= 7; i ++) {
    bool ok = true;
    for (int j = 0; j < i; j ++) {
      if (S[j] != key[j]) ok = false;
    }
    for (int j = i; j < 7; j ++) {
      if (S[j + N - 7] != key[j])ok = false;
    }
    if (ok) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

ll fact(int n)
{
    ll ans = 1;
    for(int i = 2; i <= n; i++)
    {
        ans = (ans*i)%1000000007;
    }
    return ans;
}

int main()
{
    int n, m;
    cin >> n >> m;
    if(abs(n-m) > 1)
    {
        cout << 0 << endl;
        return 0;
    }

    if(abs(n-m) == 1)
    {
        ll ans = (fact(n)*fact(m))%1000000007;
        cout << ans << endl;
        return 0;
    }
    else
    {
        ll ans = (2*fact(n)*fact(m))%1000000007;
        cout << ans << endl;
        return 0;
    }
}


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

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

    vector<int> a(n+1),b(n);
    for(int i=0;i<n+1;i++) cin >> a[i];
    for(int i=0;i<n;i++) cin >> b[i];

    ll count = 0;
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            count += b[i];
            b[i] = 0;
        }else{
            count += a[i];
            b[i] = b[i] - a[i];
        }

        if(a[i+1]>b[i]){
            count += b[i];
            a[i+1] -= b[i];
        }else{
            count += a[i+1];
            a[i+1] = 0;
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 1024
N, M = map(int, input().split())
items = []
from collections import defaultdict
from heapq import *
di = defaultdict(list)
for i in range(N):
    a, b = map(int, input().split())
    di[a].append(b)



ans = 0
target = []
heapify(target)

for i in range(1, M+1):
    if i in di:
        tmp = di[i]
        for t in tmp:
            heappush(target, -t)


    if len(target) >0 :
        q = heappop(target)
        ans += -q
print(ans)




Measured memory_bytes: 27624
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

ll f(ll a, ll b) {
  ll cnt1 = 0, cnt2 = 0;
  while (0 < a) {
    a /= 10;
    cnt1++;
  }
  while (0 < b) {
    b /= 10;
    cnt2++;
  }
  return max(cnt1, cnt2);
}

int main() {
  ll n;
  cin >> n;
  ll ans = n;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i != 0) continue;
    ans = min(ans, f(i, n / i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int n,m;
    int a[10];
    cin >> n >> m;
    if(n==1&&!m)
    {
        cout << 0 << endl;
        return 0;
    }
    memset(a,-1,sizeof(a));
    bool f = 0;
    for(int i = 1;i <= m;i++){
        int s,c;
        cin >> s >> c;
        if(n!=1&&s==1&&c==0){
            f = 1;
        }else if(a[s]==-1){
            a[s] = c;
        }else{
            
            f = a[s] == c ? 0 : 1;
        }
    }
    if(f){
        cout << "-1\n";
        return 0;
    }
    string ans = "";
    for(int i = 1;i <= n;i++){
        if(a[i]==-1&&i==1)a[i] = 1;
        else if(a[i]==-1)a[i] = 0;
        ans += a[i] + '0';
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
n = int(input())
f = []
p = []
for i in range(n):
    f.append([int(_) for _ in input().split()])
for i in range(n):
    p.append([int(_) for _ in input().split()])

ans = 0
for i in range(1, 2**10):
    pat = format(i, "010b")
    score = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if pat[k]=="1" and f[j][k] == 1:
                cnt += 1
        score += p[j][cnt]
    if i == 1:
        ans = score
    ans = max(score, ans)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
 
#define MAX 4005
#define MAX_N 105
int n,x[MAX],y[MAX];
int t[MAX][MAX];
 
void init(){
  memset(t,0,sizeof(t));
}

void f(int x,int y,int z){
  // cout<<x-2001<<' '<<y-2001<<' '<<z<<endl;
  t[x][y]+=z;
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
 
    vector<P> V;
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
      V.push_back( P(x[i],y[i]));
      x[i]+=2001,y[i]+=2001;
    }
    double sum=0;
    for(int i=0;i<n;i++){
      sum+=arg( (V[(i+2)%n]-V[(i+1)%n])*conj(V[(i+1)%n]-V[i]) );
    }
 
    if(sum<0){
      reverse(x,x+n);
      reverse(y,y+n);
    }
 
    for(int i=0;i<n;i++){
      int sx=x[i],sy=y[i];
      int tx=x[(i+1)%n],ty=y[(i+1)%n];
      if(sx==tx){
        if(sy<ty) for(int i=sy;i<ty;i++)f(sx,i,-1);
        else for(int i=ty;i<sy;i++)f(sx,i,1);
        continue;
      }
      if(sy==ty){
        if(sx<tx)f(sx,sy,1),f(tx,sy,-1);
        else f(sx,sy-1,-1),f(tx,sy-1,1);
        continue;
      }
      
      int vx=tx-sx,vy=ty-sy;
 
      long long  A=0,B=abs(vy);
 
      if(vx>0&&vy>0){
        for(int y=sy;y<ty;y++){
          A+=abs(vx);
          if(A%B==0)f(sx+A/B,y,-1);
          else f(sx+A/B+1,y,-1);
        }
      }
 
      if(vx<0&&vy>0){
        for(int y=sy;y<ty;y++){
          if(A%B==0)f(sx-(A/B),y,-1);
          else f(sx-(A/B),y,-1);
          A+=abs(vx);
        }
      }
      
      if(vx<0&&vy<0){
        for(int y=sy-1;y>=ty;y--){
          A+=abs(vx);
          if(A%B==0)f(sx-(A/B),y,1);
          else f(sx-(A/B)-1,y,1);
        }
      }
       
      if(vx>0&&vy<0){
        for(int y=sy-1;y>=ty;y--){
          if(A%B==0)f(sx+A/B,y,1);
          else f(sx+A/B,y,1);
          A+=abs(vx);
        }
      }
    }
    int ans=0;
    for(int i=0;i<MAX;i++){
      for(int j=0;j<MAX;j++){
        if(i)t[i][j]+=t[i-1][j];
        if(t[i][j-1])ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 63964
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import java.util.PriorityQueue;
import java.util.Collection;
import java.util.Scanner;
import java.util.Queue;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author acesine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            List<Long> a = new ArrayList<>();
            for (int i = 0; i < 3 * N; i++) {
                a.add(in.nextLong());
            }
            Queue<Long> head = new PriorityQueue<>(Comparator.naturalOrder());
            Queue<Long> tail = new PriorityQueue<>(Comparator.reverseOrder());
            for (int i = 0; i < N; i++) {
                head.add(a.get(i));
                tail.add(a.get(a.size() - 1 - i));
            }
            assert head.size() == N;
            assert tail.size() == N;
            long[] l = new long[N + 1];
            long[] r = new long[N + 1];
            l[0] = head.parallelStream().mapToLong(Long::longValue).sum();
            r[N] = tail.parallelStream().mapToLong(Long::longValue).sum();
            for (int i = 1; i <= N; i++) {
                if (a.get(N + i - 1) > head.peek()) {
                    long t = head.poll();
                    head.add(a.get(N + i - 1));
                    l[i] = l[i - 1] + a.get(N + i - 1) - t;
                } else {
                    l[i] = l[i - 1];
                }
                if (a.get(2 * N - i) < tail.peek()) {
                    long t = tail.poll();
                    tail.add(a.get(2 * N - i));
                    r[N - i] = r[N - i + 1] + a.get(2 * N - i) - t;
                } else {
                    r[N - i] = r[N - i + 1];
                }
                assert tail.size() == head.size();
            }
            long max = l[0] - r[0];
            for (int i = 1; i <= N; i++) {
                if (l[i] - r[i] > max) max = l[i] - r[i];
            }
            out.println(max);
        }

    }
}



Measured memory_bytes: 104220
N, K = map(int, input().split())
h = [0]*(N+1)
for i in range(K):
    d = int(input())
    *A, = map(int, input().split())
    for a in A:
        h[a] = 1

ans = 0
for i in range(1, N+1):
    if h[i] == 0:
        ans += 1
print(ans)


Measured memory_bytes: 67628
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
int i, c;
printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

if( T[u].p == NIL) printf("root, ");
else if( T[u].l == NIL) printf("leaf, ");
else printf("internal node, ");

printf("[");
for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
  if(i) printf(", ");
  printf("%d", c);
}
printf("]\n");

}

void calcDepth(int u, int p){
D[u] = p;
if(T[u].l != NIL) calcDepth(T[u].l, p+1);
if(T[u].r != NIL) calcDepth(T[u].r, p);
}

int main(){
int i, j, k;
int n;
int id, sib, child;
int root = NIL;
scanf("%d", &n);
for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

for(i=0; i<n; i++){
  scanf("%d %d", &id, &k);
  for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
    scanf("%d", &child);
    T[child].p = id;
    if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
    else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
    sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
  }
}

//根を求める (find the root)
for(i=0; i<n; i++){
  if(T[i].p == -1) root = i;
}

//それぞれのノードの深さを求める (find depth of each node)
calcDepth(root, 0);

//出力 (output)
for(i=0; i<n; i++) print(i);

return 0;
}



Measured memory_bytes: 4260
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

int main() {
	string s;
	cin >> s;
	int ans = 1000;
	int cnt;

	if (s.size() == 1) {
		cout << 0 << endl;
		return 0;
	}
	
	rep(i, s.size() - 1) {
		if (s[i] != s[i + 1])break;
		if (i == s.size() - 2) {
			cout << 0 << endl;
			return 0;
		}
	}

	rep(i, 26) {
		string t = s, r;
		cnt = 0;
		while (1) {
			int tmp = 0;
			r = "";
			rep(j, t.size() - 1) {
				if (t[j] == (char)('a' + i) || t[j + 1] == (char)('a' + i)) {
					r.push_back((char)('a' + i));
				}
				else {
					r.push_back(t[j]);
					tmp = 1;
				}
			}
			if (tmp == 0) {
				ans = min(cnt, ans);
				break;
			}
			else {
				cnt++;
				t = r;
			}
		}
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 100;

int main(){
  int M[N][N];
  int n, u, k, v, i, j;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++) M[i][j] = 0;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j< k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}
    
	



Measured memory_bytes: 2048
//Problem: ABC 170B
//Progress:
#include <iostream>
typedef long long int ll;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x, y;
    bool ans = false;
    cin >> x >> y;
    for(ll i=0; i<=x; i++){
    	if((x-i)*4 + i*2 == y){
    		ans = true;
    		break;
    	}
    }
	cout << (ans ? "Yes" : "No");
    return 0;
}

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

using ll = long long;

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

  vector<ll> B(N - 1, 0);
  for (int i = 0; i < N - 1; i++) {
    scanf("%lld", &B.at(i));
  }

  vector<ll> A(N, 0);
  A.at(0) = B.at(0);
  for (int i = 1; i < N - 1; i ++) {
    A.at(i) = min(B.at(i - 1), B.at(i));
  }
  A.at(N - 1) = B.at(N - 2);

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A.at(i);
  }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());

		int[] line = new int[n];
		int count = 0;

		for (int i = 0; i < n; i++) {
			line[i] = Integer.parseInt(sc.next());
		}

		for (int i = 1; i < n - 1; i++) {
			if ((line[i] > line[i - 1] && line[i] < line[i + 1])
 			 || (line[i] < line[i - 1] && line[i] > line[i + 1])) {
				count++;
			}
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[n / 2] - a[n / 2 - 1] << endl;
	return 0;
}


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

typedef long long ll;

using namespace std;

ll dp[3]{};

int main() {
	string a;
	cin >> a;
	ll ans = 0;
	ll three = 1;
	for(int i = 0; i < a.size(); i++) {
		switch(a.at(i)) {
			case 'A':
				dp[0]+=three;
				break;
			case 'B':
				dp[1]+=dp[0];
				break;
			case 'C':
				dp[2] += dp[1];
				break;
			case '?':
				ll _dp[3];
				for(int i = 0; i < 3; i++) {
					_dp[i] = dp[i];
					dp[i] = _dp[i]*3LL;
				}
				dp[2] += _dp[1];
				dp[1] += _dp[0];
				dp[0] += three;
				three = (three*3LL)%1000000007LL;
				break;
		}
		for(int i = 0; i < 3; i++) {
			dp[i] %= 1000000007LL;
		}
		//cout << dp[0] << "," << dp[1] << "," << dp[2] << endl;
	}
	cout << dp[2] << endl;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
	unsigned long int a,b,c;
	int n;
	int i;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%ld%ld%ld",&a,&b,&c);
		if((a*a+b*b == c*c) || (c*c+b*b == a*a) || (a*a+c*c == b*b))printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
from itertools import accumulate


def gen_primes(n: int) -> set:
    if n < 2:
        return set()
    is_prime = [True] * n
    for i in range(3, n, 2):
        if is_prime[i]:
            is_prime[i * i:: 2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
    return {2} | {i for i in range(3, n, 2) if is_prime[i]}


if __name__ == "__main__":
    max_n = 10 ** 5 + 1
    primes = gen_primes(max_n)

    is_like_2017 = [True if i in primes and (i + 1) // 2 in primes else False for i in range(max_n)]
    sum_is_like_2017 = tuple(accumulate(is_like_2017))

    q = int(input())
    lr = [map(int, input().split()) for _ in range(q)]
    for l, r in lr:
        print(sum_is_like_2017[r] - sum_is_like_2017[l - 1])


Measured memory_bytes: 54184
H, W, N = map(int, input().split())
current_line = 0
ans = [0 for i in range(10)]
kuro = dict()

for i in range(N):
    a, b = map(int, input().split())
    for y in range(max(a-2, 1), min(a+1, H-1)):
        for x in range(max(b-2, 1), min(b+1, W-1)):
            p = (y, x)
            if p in kuro:
                kuro[p] += 1
            else:
                kuro[p] = 1

for n in kuro.values():
    ans[n] += 1
ans[0] = (H-2)*(W-2)-len(kuro)
print("\n".join([str(n) for n in ans]))
###

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

int main() {
	
	int N;
	cin >>N;
	
	vector<int> heights(N);
	for(int i=0; i<N; i++){
		
		cin >>heights.at(i);
		
	}
	
	int max=0;
	
	int count=0;
	
	for(int i=0; i<N; i++){
		
		if(heights.at(i)>=max){
			
			max=heights.at(i);
			count++;
			
		}
		
	}
	
	cout <<count <<endl;
	
}

Measured memory_bytes: 256
from collections import defaultdict
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
arr=[int(x) for x in arr_data[1]]

numbers = defaultdict(lambda: 0)
for v in arr:
    numbers[v] += 1
hash01=dict(numbers)

m = int(arr_data[2][0])
arr_problem=[int(x) for x in arr_data[3]]

numbers_problem = defaultdict(lambda: 0)
for v in arr_problem:
    numbers_problem[v] += 1
hash02=dict(numbers_problem)

chkflg=True

for k,v in hash02.items():
    
    if not k in hash01 or v>hash01[k]:
    
        chkflg=False
    
print("YES" if chkflg else "NO")

Measured memory_bytes: 109536
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    long long n;
    std::cin >> n;

    std::vector<long long> a(n);
    std::vector<std::pair<long long, long long>> num_and_pair(n + 1);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];

        num_and_pair[a[i]].first++;
    }

    for (int i = 0; i <= n; i++) {
        num_and_pair[i].second = num_and_pair[i].first * (num_and_pair[i].first - 1) / 2;
    }

    long long sum = 0;
    for (int i = 0; i < n + 1; i++) {
        sum += num_and_pair[i].second;
    }
    for (int i = 0; i < n; i++) {
        std::cout << sum - num_and_pair[a[i]].first + 1 << std::endl;
    }
}


Measured memory_bytes: 7296
def solve(n):
    if n % 2 == 1:
        return 0
    else:
        m = n // 2
        res = 0
        while m > 0:
            m = m // 5
            res += m
        return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(12) == 1
    assert solve(5) == 0
    assert solve(1000000000000000000) == 124999999999999995


if __name__ == "__main__":
    test()
    main()


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

int main(){
    int n;
    cin >> n;
    cout << ceil(n*0.5) << endl;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(n+1), res(2019);
    res[0] = 1;
    int ten = 1;
    for(int i = 0; i < n; i++){
        int x = s[n-1-i] - '0';
        a[i+1] = (a[i] + ten * x) % 2019;
        ten = ten * 10 % 2019;
        res[a[i+1]]++;
    }
    int ans = 0;
    for(int i = 0; i < 2019; i++){
        int cnt = res[i];
        ans += cnt * (cnt - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

int a[105], cnt[105];

int main(){
	int n, maxx, minx;
	scanf("%d",&n);
	memset(cnt, 0, sizeof(cnt));
	minx = 1000; maxx = 0;
	for (int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		cnt[a[i]]++;
		maxx = max(maxx, a[i]);
		minx = min(minx, a[i]);
	}
	if (maxx & 1){
		if (minx != maxx / 2 + 1 || cnt[minx] != 2){
			printf("Impossible\n");
			return 0;
		}
	}
	else{
		if (minx != maxx / 2 || cnt[minx] != 1){
			printf("Impossible\n");
			return 0;
		}
	}
	for (int i = minx + 1; i <= maxx; i++){
		if (cnt[i] < 2){
			printf("Impossible\n");
			return 0;
		}
	}
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(s: Vec<char>) -> u32 {

    let mut p = 700;

    for c in s {
        if c == 'o' {
            p += 100;
        }
    }

    p
}

fn main() {
    let s = read_line!();

    println!("{}", solve(s.chars().collect()));
}

#[test]
fn solve_test() {
    assert_eq!(solve("oxo".chars().collect()), 900);
    assert_eq!(solve("ooo".chars().collect()), 1000);
    assert_eq!(solve("xxx".chars().collect()), 700);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    String readStr;
    while ((readStr = reader.readLine()) != null) {
      String[] formattedStrs = readStr.split(" ");
      int left = Integer.parseInt(formattedStrs[0]);
      int right = Integer.parseInt(formattedStrs[1]);

      int weight = 1;
      int count = 1;
      while (true) {
        int surplus = (left + right) / weight;
        if (surplus < 10) {
          System.out.println(count);
          break;
        }
        weight *= 10;
        count++;
      }

    }
  }

}

Measured memory_bytes: 15160
from collections import deque


h, w = map(int,input().split())
ch, cw = map(lambda x: int(x) - 1, input().split())
dh, dw = map(lambda x: int(x) - 1, input().split())

G = []
for i in range(h):
    G.append(list(input()))

queue = deque([(ch, cw)])
S = [[float("inf")]*w for _ in range(h)]
S[ch][cw] = 0

while queue:
    y, x = queue.popleft()
    dx_dy = ((1,0),(0,1),(-1,0),(0,-1))
    ans = S[y][x]

    if (y, x) == (dh, dw):
            S[y][x] = ans
            break

    for j, i in dx_dy:
        if 0 <= x+i < w and 0 <= y+j < h and S[y+j][x+i] > ans and G[y+j][x+i] == ".":
            queue.appendleft((y+j, x+i))
            S[y+j][x+i] = ans
            

    ans += 1
    for i in range(-2, 3):
        for j in range(-2, 3):
            if 0 <= x+i < w and 0 <= y+j < h and S[y+j][x+i] > ans and G[y+j][x+i] == ".":
                S[y+j][x+i] = ans
                queue.append((y+j, x+i))


if S[dh][dw] == float("inf"):
    print(-1)
else:
    print(S[dh][dw])


Measured memory_bytes: 136852
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((a - b) % 2 == 0) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Borys" << endl;
	}
}



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

// THINK: INT vs LONG LONG?

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

	int n; cin >> n;
	int ans = 0, cur = 0;	
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		if (a == b) {
			cur++;
		}
		else cur = 0;
		ans = max(ans, cur);
	}
	cout << (ans >= 3 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 3648
require "bigdecimal"
require "bigdecimal/util"

def gi() gets.to_i end
def gs() gets.chomp end
def gmi() gets.split.map(&:to_i) end
def gms() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end


#####
n,k = gmi
nums = gmi
puts ((n-1)/(k-1).to_f).ceil

Measured memory_bytes: 8108
from collections import deque
N = int(input())
A = [[] for i in range(N)]
B = []
for i in range(N-1):
  a = list(map(int, input().split()))
  A[a[0]-1].append([a[1]-1, 0])
  A[a[1]-1].append([a[0]-1, 1])
  B.append(a)
K = 0
D = {}
C = [0 for i in range(N)]
de = deque([[0, -1]])
while len(de):
  n = de.pop()
  C[n[0]] = 1
  color = 1
  for a in A[n[0]]:
    if C[a[0]] == 1:
      continue
    if color == n[1]:
      color += 1
    if a[1] == 0:
      D[str(n[0])+","+str(a[0])] = color
    else:
      D[str(a[0])+","+str(n[0])] = color
    de.append([a[0], color])
    K = max(K, color)
    color += 1
print(K)
for b in B:
  print(D[str(b[0]-1)+","+str(b[1]-1)])

Measured memory_bytes: 141612
n,k = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(k)]
mod = 998244353

class Binary_Indexed_Tree():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get(self, i):
        return self.sum_range(i, i)

    def sum(self, i):
        i += 1
        ret = 0
        while i:
            ret += self.data[i]
            i &= i-1
        return ret

    def sum_range(self, l, r):
        return self.sum(r)-self.sum(l-1)

BIT = Binary_Indexed_Tree(n)
BIT.add(0, 1)
for i in range(1,n):
    tmp = 0
    for l,r in lr:
        l = i-l
        r = max(i-r, 0)
        if l < 0:
            continue
        tmp += BIT.sum_range(r, l)
    tmp %= mod
    BIT.add(i, tmp)

ans = BIT.get(n-1)
print(ans)



Measured memory_bytes: 75856
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    if(A+B >= C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
    fio;
    ll n,res=1,flag=1,v=0;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            v=1;
    }
    if(v==true)
    {
        cout<<0<<endl;
    }
    else
    {
         for(ll i=0;i<n-1;i++)
         {
         res*=a[i];
         if(res>(1000000000000000000)/a[i+1])
         {
             flag=0;
             break;
         }
    }
    if(flag==true)
    {
        ll dg=res*a[n-1];
        cout<<dg<<endl;
    }

    else
        cout<<-1<<endl;
    }
}

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

using namespace std;

int N, M, Q, sA[100009], sB[100009];
char A[100009], B[100009];

int val (char c)
{
    if (c == 'A') return 1;
    return 2;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", A + 1), N = strlen (A + 1);
scanf ("%s", B + 1), M = strlen (B + 1);
for (int i=1; i<=N; i++)
    sA[i] = sA[i - 1] + val (A[i]);
for (int i=1; i<=M; i++)
    sB[i] = sB[i - 1] + val (B[i]);
scanf ("%d", &Q);
while (Q --)
{
    int a1, a2, b1, b2;
    scanf ("%d %d %d %d", &a1, &a2, &b1, &b2);
    int x = sA[a2] - sA[a1 - 1], y = sB[b2] - sB[b1 - 1];
    if (x % 3 == y % 3) printf ("YES\n");
    else printf ("NO\n");
}

return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
#define LEN 100
#define INF 100000000

int  Q[LEN];
int G[LEN][LEN];
int head,tail;
int d[LEN];
int n;

void enqueue(int x){
  Q[tail] = x;
  tail = (tail+1) % LEN;
}
int dequeue(){
  int  x = Q[head];
  head = (head+1)%LEN;
  return x;
}

int enpty(){
  if(tail == head)return 1;
  else return 0;
}

void bfs(int s){
  int i;
  int u,v;
  enqueue(s);

  for(i=0;i<n;i++){
    d[i] = INF;
  }

  d[s] = 0;

  while(!enpty()){
    u = dequeue();
    for(v=0;v<n;v++){
      if(G[u][v] == 0)continue;
      if(d[v] != INF)continue;
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i+1,((d[i] == INF)? -1 : d[i]));
  }
}

int main(){
  int k,u,v;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}

Measured memory_bytes: 636
def getDist(a,b,c,d):
  return abs(a-c) + abs(b-d)
def findSmallest(student, checkPoints):
  [a,b] = student
  shortest = 99999999999
  index = 1
  for checkPoint in checkPoints:
    [c,d] = checkPoint
    dist = getDist(a,b,c,d)
    if dist < shortest:
      shortest = dist
      indexAns = index
    index += 1
  return indexAns

n,m=[int(x) for x in input().split()]
students = []
for x in range(n):
  students.append([int(x) for x in input().split()])
checkPoints = []
for x in range(m):
  checkPoints.append([int(x) for x in input().split()])

for student in students:
  print(findSmallest(student, checkPoints[:]))
  

Measured memory_bytes: 3064