akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <istream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    int d;
    vector<int> s(100001);

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

    int ans = 0;
    int cur = 0;
    for (int i=0; i<100001; ++i) {
        cur += s[i];
        if (cur*2 == n) ans++;
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1272
fivarray = [1,1,2,3,5,8,13,21,34,55]
 
h,w,k = gets.split.map(&:to_i)
 
arr = Array.new(h+1).map{Array.new(w,0)}
 
arr[0][0] = 1
 
i = 0
 
(h*w).times{
    
    
    syou = i/w+1
    amari = i%w
    
 
    
    arr[syou][amari]+=fivarray[amari]*fivarray[w-amari-1]*arr[syou-1][amari]
    
    if amari>0
    arr[syou][amari]+=fivarray[amari-1]*fivarray[w-amari-1]*arr[syou-1][amari-1]
    end
    
    if amari<w-1
    arr[syou][amari]+=fivarray[amari]*fivarray[w-amari-2]*arr[syou-1][amari+1]
    end
    
  i+=1  
 
}
 
p arr[-1][k-1]%1000000007
 
 
 
 

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

int main(void){
    int n = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        double x1, y1, x2, y2, x3, y3, x4, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        if(fabs((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)) < 0.0000000001){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 3072
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

#最後の状態からみれば最後に挿入した数字iはi-1番目に存在することがわかる。
n = int(input())
s = list(input().split(" "))
ans =deque()
while len(s)>0:
    bool = 1
    for i in range(len(s))[::-1]:
        if int(s[i]) == i+1:
            si = s.pop(i)
            ans.append(si)
            bool = 0
            break
    if bool:
        print(-1)
        exit()
while ans:
    print(ans.pop())

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

int main() {
  int X;
  cin >> X;

  int ans = 1;
  for (int b = 2; b <= X; b++) {
    int p = 1, exp = b;
    while (exp <= X) {
      exp *= b;
      p++;
    }
    exp /= b;
    if (p != 2 && exp > ans) ans = exp;
  }

  cout << ans << endl;

  return 0;
}

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

int a[1000];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  
  int sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += a[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
int dx[9] = {0, 1, -1, 0, 0, 1, 1, -1, -1};
int dy[9] = {0, 0, 0, 1, -1, 1, -1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M, 0));
    rep(i, N) rep(j, M){
        char c;
        cin >> c;
        if(i == 0) {
            A[i][j] = 1;
        }
        if(c == 'o'){
            rep(k, 3){
                if(i + dy[k] >= 0 && i + dy[k] < N && j + dx[k] >= 0 && j + dx[k] < M)
                    A[i + dy[k]][j + dx[k]] = 1;
            }
        }
        if(c == 'x'){
            rep(k, 9){
                if(i + dy[k] >= 0 && i + dy[k] < N && j + dx[k] >= 0 && j + dx[k] < M)
                    A[i + dy[k]][j + dx[k]] = 1;
            }
        }
    }
    int ret = 0;
    rep(i, N) rep(j, M){
        if(A[i][j] == 0) ret++;
    }
    
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3252
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

string S;

signed main() {
	cin >> S;
	if (S == "Sunny") cout << "Cloudy" << endl;
	if (S == "Cloudy") cout << "Rainy" << endl;
	if (S == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;

  vector<ll> a(n);
  vector<ll> b(n);
  ll sumA = 0;
  ll sumB = 0;

  for(ll i = 0;i < n;i++){
    cin >> a[i];
    sumA += a[i];
  }
  for(ll i = 0;i < n;i++){
    cin >> b[i];
    sumB += b[i];
  }

  ll cnt_a = 0;
  ll cnt_b = 0;
  
  for(ll i = 0;i < n;i++){
    if(b[i] - a[i] >= 0){
      if((b[i] - a[i]) % 2 == 0)cnt_a += (b[i]-a[i])/2;
      else{
        cnt_b++;
	b[i]++;
	cnt_a += (b[i]-a[i])/2;
      }
    }
    else{
      cnt_b += a[i]-b[i]; 
    }
  }

  if(cnt_a >= cnt_b && cnt_a+(cnt_a-cnt_b) == sumB - sumA)cout << "Yes" << endl;
  else cout << "No" << endl;
}  


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll X,K,D;
    cin>>X>>K>>D;
    if(X<0) X=-X;
    if(K>X/D){
        ll cnt = X/D;
        K-=cnt;
        ll ans = X - cnt*D;
        ans = llabs(ans - (K&1)*D);
        cout<<ans<<endl;
    }
    else{
        cout<<X-K*D<<endl;
    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int num = 0;
	string s1, s2;
	cin >> num;
	cin >> s1 >> s2;
	int temp = num * 2;
	int count1 = 0, count2 = 0;
	for (int i = 0; i < temp; i++)
	{
		if (i % 2 == 0)
		{
			cout << s1[count1++];
		}
		else
		{
			cout << s2[count2++];
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(100001);
  long a;
  for(int i = 0; i < N; i++){
    cin >> a;
    data.at(a)++;
  }
  long S = 0;
  for(long i = 0; i <= 100000; i++){
    S += data.at(i) * i;
  }
  long Q, B, C;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    cin >> B >> C;
    S -= data.at(B) * B;
    S += data.at(B) * C;
    data.at(C) += data.at(B);
    data.at(B) = 0;
    cout << S << endl;
  }
  return 0;
}

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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************

int main(void) {

	ll N, W;
	cin >> N >> W;

	vector<vector<ll>> dp(N + 1);
	fill(dp.begin(), dp.end(), vector<ll>(1e3 * N + 1, W * N * 1e5));
	dp[0][0] = 0;

	vector<pair<ll, ll>> wv(N);

	for (auto& p : wv) {
		cin >> p.first >> p.second;
	}
	
	REP(i, N) {
		ll w = wv[i].first;
		ll v = wv[i].second;
		REP(j, 1e3 * N + 1) {
			if (j - v >= 0) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v] + w);
			}
			dp[i + 1][j] = min(dp[i+1][j], dp[i][j]);
		}
	}

	ll ans = 0;
	for (ll i = 1e3 * N; i >= 0; i--) {
		if (dp[N][i] <= W) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[100001];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	int sum=0,s=0;
	for(int i=1;i<=k;i++)sum=a[k]-a[1];
	for(int i=2;i<=n-k+1;i++){
		s=a[i+k-1]-a[i];
		if(sum>s)sum=s;
	}
	cout<<sum;
	return 0;
}

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

signed main () {
	int n;
	cin >> n;
	vector < int > d(n); // dams
	for (int &x: d)
		cin >> x;
	vector < int > ac_diff(n, 0), bd_diff(n, 0); // picture
	for (int i = 0; i < n; i += 2) // also find a - b
		ac_diff[(i + 2) % n] = ac_diff[i] + d[(i + 1) % n] - d[i];
	for (int i = 1; i < n; i += 2) // also find a - b
		bd_diff[(i + 2) % n] = bd_diff[i] + d[(i + 1) % n] - d[i];
	for (int i = 1; i < n; i += 2) 
		ac_diff[i] = bd_diff[i] - bd_diff[0];
    int a = (d[0] - ac_diff[1]) / 2;
    for (int i = 0; i < n; ++i)
        ac_diff[i] = 2 * (ac_diff[i] + a);
	for (int x: ac_diff)
		cout << x << ' ';
	cout << '\n';
}

/*
 * 2 * a        2 * b       2 * c       2 * d       2 * e  
 *  /|\          /|\         /|\         /|\         /|\
 * / | \ 		/ | \ 		/ | \ 		/ | \		/ | \ 
 * 		 a + b 		  b + c 	  c + d 	  d + e 	  e + a
 */


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

int main(int argc, const char * argv[]) {
    int N;
    int p[10];
    int max = -1;
    int sum = 0;
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        if (max < p[i]) {
            max = p[i];
        }
    }
    
    for (int i = 0; i < N; i++) {
        if (p[i] == max) {
            max = -1;
            sum += p[i] / 2;
        } else {
            sum += p[i];
        }
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10



int main() {
	int a, b, c; cin >> a >> b >> c;
	cout << max(c - (a - b),0) << endl;

	return 0;
}


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

int dp[100005][3];

#undef int
int main()
{
#define int long long int
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	vector<int> a(n), b(n), c(n);
	for(int i = 0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];
	for(int i = 1;i<n;i++)
	{
		dp[i][0] = a[i]+max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i]+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i]+max(dp[i-1][0], dp[i-1][1]);
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;

	
	return 0;
}

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

typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }

void eprint() { cerr << endl; }
template <class First, class... Rest>
void eprint(First& f, Rest&... r) {
  cerr << f << ' ';
  eprint(r...);
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  size_t output_num = v.size();
  bool is_emitted = false;
#ifdef OUTPUT_VECTOR_MAX
  if (OUTPUT_VECTOR_MAX < output_num) {
    output_num = OUTPUT_VECTOR_MAX;
    is_emitted = true;
  }
#endif
  os << "[";
  for (size_t i = 0; i < output_num - 1; i++) os << v[i] << ", ";
  os << v[output_num - 1];
  if (is_emitted) os << ", ...";
  return os << "]";
}

void Main();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

void Main() {
  int n,m; cin >> n >> m;
  scc_graph g(n);
  Rep(m){
    int a,b; cin>>a>>b;
    g.add_edge(a,b);
  }
  auto ans = g.scc();
  cout << ans.size() << endl;
  for(auto v: ans){
    cout << v.size() << ' ';
    for(auto a: v){
      cout << a << ' ';
    }
    cout << endl;
  }
}


Measured memory_bytes: 40604
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int 
int main()
{
    ll h,w;cin>>h>>w;ll dp[h+1][w+1];
    
    memset(dp,0,sizeof(dp));dp[1][1]=1;
    for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){char c;cin>>c;if(c=='#')dp[i][j]=-1;}
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(i==1&&j==1)continue;
            if(dp[i][j]==-1)continue;
           if(dp[i-1][j]!=-1&&dp[i][j-1]!=-1)
           dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
           else if(dp[i-1][j]==-1&&dp[i][j-1]!=-1)
           {
               dp[i][j]=dp[i][j-1];
           }
           else if(dp[i][j-1]==-1&&dp[i-1][j]!=-1)
           {
               dp[i][j]=dp[i-1][j];
           }
           else if(dp[i][j-1]==-1&&dp[i-1][j]==-1)dp[i][j]=0;
        }
    }
   // for(int i=1;i<=h;i++){for(int j=1;j<=w;j++)cout<<dp[i][j]<<" ";cout<<endl;}
    cout<<dp[h][w];
    
    
    
}

Measured memory_bytes: 8064
def main():
    k, n = list(map(int,input().strip().split()))
    a = list(map(int,input().strip().split()))

    point_start = 0
    point_end = 0
    max_dist = 0
    tmp_dist = 0

    for i in range(len(a)-1):
        tmp_dist = max(max_dist, a[i+1]-a[i])
        if(tmp_dist!=max_dist):
            point_start = i+1
            max_dist = tmp_dist

    tmp_dist = max(max_dist, (k-a[n-1])+a[0])
    if(tmp_dist!=max_dist):
        point_start = 0
        max_dist = tmp_dist


    dist = 0

    for i in range(len(a)-1):
        if(point_start!=(n-1)):
            dist = dist + (a[point_start+1]-a[point_start])
            point_start = point_start + 1
        else:
            dist = dist + ((k-a[point_start])+a[0])
            point_start = 0

    print(dist)

main()


Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll INF = ll(1e18)+1;

ll N, K;
ll A[1000000];

ll calcRank(ll x) {
  ll totalCount = 0;
  for (int i = 0; i < N; i++) {
    if(A[i] >= 0){
      int l = -1;
      int r = N;
      while (l+1<r) {
        int mid = (l+r)/2;

        if (A[mid]*A[i] < x) l=mid;
        else r=mid;
      }
      totalCount += r;
    } else {
      int l = -1;
      int r = N;
      while (l+1<r) {
        int mid = (l+r)/2;
        if (A[mid]*A[i] < x) r=mid;
        else l=mid;
      }
      totalCount += N-r;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i]*A[i] < x) totalCount--;
  }    
  totalCount /=2;
  return totalCount;
}



int main(){
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A+N);
  
  ll l = -INF;
  ll r = INF;
  while (l+1 < r) {
    ll mid = (l+r)/2;   
    
    if (calcRank(mid)<K) l = mid;
    else r = mid;
  }
  
  cout << l << endl;
  return 0;
}

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

int main(){
	int n,c=0,f;
	string s,r;
	cin>>s;
	cin>>n;
	for(int i=0;i<n;i++){
		f=0;
		cin>>r;
		r+=r;
		for(int j=0;j<r.size()-s.size();j++){
			if(s==r.substr(j,s.size())) f=1;
		}
		if(f) c++;
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <bitset>
#define ll long long
using namespace std;


int main() {
	string s;
	int lose = 0;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'x')lose++;
	}
	if (lose < 8)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <random>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int l[30];
ll c[30],s[400][30],ans[11111];

int main(void){
	int d,i,j,n=26,k,m=10000;
	ll ansm = -INFLL;
	std::vector<int> v[m];
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			v[k].push_back(j);
		}
		std::random_device seed_gen;
		std::mt19937 engine(seed_gen());
		std::shuffle(v[k].begin(), v[k].end(), engine);
	}
	std::cin >> d;
	for(i=0; i<26; ++i){
		std::cin >> c[i];
	}
	for(i=0; i<d; ++i){
		for(j=0; j<n; ++j){
			std::cin >> s[i][j];
		}
	}
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			l[j] = -1;
		}
		for(i=0; i<d; ++i){
			ans[k] += s[i][v[k][i%26]];
			l[v[k][i%26]] = i;
			for(j=0; j<n; ++j){
				ans[k] -= c[j]*(i-l[j]);
			}
		}
		ansm = std::max(ansm,ans[k]);
	}
	for(k=0; k<m; ++k){
		if(ans[k] == ansm){
			for(i=0; i<d; ++i){
				std::cout << v[k][i%26]+1 << std::endl;
			}
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 5452
A,B,C = map(int,input().split())
K=int(input())

cnt = 0

while B<=A:
    cnt +=1
    B *=2
    
while C<=B:
    cnt +=1
    C *=2
    
#print(cnt)
if cnt <=K:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
string s,s1,s2;
int t,n,m,tmp;
long long cnt;
int a[200001];
int x[200001],y[200001];
void merge_sort(int l,int r){
	 int mid,n1,n2;
	 if (r-l==1) return;
	 mid=(l+r)/2; 
	 merge_sort(l,mid);
	 merge_sort(mid,r);
	 n1=mid-l; n2=r-mid;
	 for (int i=0; i<n1; i++)
	     x[i]=a[l+i];
	 for (int i=0; i<n2; i++)
	     y[i]=a[mid+i];
	 x[n1]=2000000001; y[n2]=2000000001;
	 int i=0,j=0;
	 for (int k=l; k<r; k++){
	 	 if (x[i]<y[j])
	 	 	a[k]=x[i++];
	 	 else{
	 	 	a[k]=y[j++];
	 	 	cnt+=n1-i;
		  }
	 }
   
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++)
        cin>>a[i];
    merge_sort(0,n);
    cout<<cnt<<endl;
	return 0;
} 


Measured memory_bytes: 4804
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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

const int MOD = 1000000007;

int main() {
    SS(ll,N);
    SV(ll,a,N*3);
    sort(all(a));
    ll ans = 0;
    for(ll i=N;i<3*N;i+=2)ans += a[i];
    cout << ans << endl;

}

Measured memory_bytes: 2560
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;
#define rep(i,n) for (int i = 0; i < (n); i++)

ll n, k, ans;
string s;
int main(void) {
    cin >> n >> k >> s;
    rep(i,n-1) {
        if (s[i] == s[i+1]) ans++;
    }
    ans = min(2*k+ans, n-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int f = 0;
  while(a>0 && c>0){
    if(f%2==0)
        c-=b;
    else
      a-=d;
    f++;
  }
  if(f%2)
    cout<<"Yes"<<endl;
   else
     cout<<"No"<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<std::string> s, std::vector<long long> t, std::string X){
  ll ans=0,sum=accumulate(t.begin(),t.end(),0LL);
  REP(N){
    ans+=t[i];
    if(X==s[i]){
      break;
    }
  }
  cout<<sum-ans<<endl;
}

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


Measured memory_bytes: 256
char s[100][101];h;r[100],R,c[100],C,i,j,x;
main(w){scanf("%d%d",&h,&w);for(i=h;i--;){scanf("%s",s[i]);
x=0;for(j=w;j--;x+='.'-s[i][j]);if(x)r[R++]=i;}
for(j=w;j--;){x=0;for(i=h;i--;x+='.'-s[i][j]);if(x)c[C++]=j;}
for(i=0;i<R;i++){for(j=C;j--;)putchar(s[r[i]][c[j]]);puts("");}
}


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

using namespace std;

const int MAX_N = 100005;
const int INF = (1 << 30);

int n;

int h[MAX_N], dp[MAX_N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &h[i]);
    dp[i] = INF;
  }
  dp[1] = 0;
  for (int i = 1; i <= n - 2; ++i) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  dp[n] = min(dp[n], dp[n - 1] + abs(h[n] - h[n - 1]));
  printf("%d", dp[n]);
  return 0;
}


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

A=[list(map(int,input().split())) for i in range(n)]
b=[list(map(int,input().split())) for i in range(m)]
c=[]


for ki in range(n):
    k=0
    for no in range(m):
        k+=A[ki][no]*b[no][0]
    c.append(k)

for i in range(len(c)):
    print(c[i])


Measured memory_bytes: 6036
from heapq import heappop, heappush


def main():
    N, M = map(int, input().split())
    lst_A = list(map(int, input().split()))

    pqueue = []
    for A in lst_A:
        heappush(pqueue, -A)

    for m in range(M):
        a = heappop(pqueue)
        a *= -1
        a //= 2
        a *= -1
        heappush(pqueue, a)
    ans = -sum(pqueue)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
n, d, a = map(int, input().split())
l = [[0, 0] for _ in range(n)]
for i in range(n):
  x, h = map(int, input().split())
  l[i][0] = x
  l[i][1] = h
  
l.sort()
from collections import deque
d = 2*d
q = deque([])
total = 0

ans = 0
for i in range(n):
  x = l[i][0]
  h = l[i][1]
  if q:
    while q[0][0] < x:
      total -= q[0][1]
      q.popleft()
      if not q:
        break
  h -= total
  if h > 0:
    num = (h+a-1)//a
    ans += num
    damage = num*a
    total += damage
    q.append([x+d, damage])

print(ans)

Measured memory_bytes: 53956
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;

constexpr int MAXN = 5+300000;
constexpr int MAXW = 5+100000;

int n, v[MAXN], w[MAXN];

ll dp[MAXW], ans[MAXN];

pair<ll,ll> ways[512];
vector<ii> queries[MAXN];

void solve(int u, int lvl) {
  if (u > n) return;

  vector<ll> oldp;
  if (lvl > 9) {
    int newlvl = lvl-9;
    int lb = 1 << (newlvl-1);

    foi (j,0,1<<newlvl) {
      if (j&lb) {
        ways[j].first = v[u] + ways[j-lb].first;
        ways[j].second = w[u] + ways[j-lb].second;
      }
    }

    for (auto x : queries[u]) {
      int L = x.first;
      int idx = x.second;
      foi (j,0,1<<newlvl) {
        if (ways[j].second > L) continue;
        ans[idx] = max(ans[idx], ways[j].first + dp[L-ways[j].second]);
      }
    }
  } else { // lvl <= 9. do dp.
    oldp.resize(MAXW);
    foi (i,0,MAXW) oldp[i] = dp[i];

    for (int j = 0; j < MAXW; ++j) {
      dp[j] = oldp[j];
      if (j-w[u] >= 0) dp[j] = max(dp[j], oldp[j-w[u]] + v[u]);
    }

    for (auto x : queries[u]) {
      ans[x.second] = dp[x.first];
    }
  }

  solve(2*u, 1+lvl);
  solve(1+2*u, 1+lvl);

  if (lvl <= 9) {
    foi (i,0,MAXW) dp[i] = oldp[i];
  }
}

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

  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> v[i] >> w[i];

  int q; cin >> q;
  foi (i,0,q) {
    int u,l; cin >> u >> l;
    queries[u].push_back({l,i});
  }
  solve(1,1);
  foi (i,0,q) cout << ans[i] << '\n';
  return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    set<char> one_digit;
    set<string> two_digit;
    set<string> three_digit;
    for(char c : s) {
        for(string d : two_digit) {
            string cur = d;
            cur += c;
            three_digit.insert(cur);
        }
        for(char d : one_digit) {
            string cur = "";
            cur += d;
            cur += c;
            two_digit.insert(cur);
        }
        one_digit.insert(c);
    }
    cout << (int)three_digit.size() << endl;
    return 0;
}


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

using namespace std;

int main() {

    int i, cnt = 0;
    string s;

    while(cin >> s) {

        for(i = 0; i < s.size(); ++i) {
            if(s[i] != s[s.size() - i - 1]) {
                break;
            }
        }

        if(i == s.size()) {
            ++cnt;
        }

    }

    cout << cnt << endl;

}

Measured memory_bytes: 1184
N, M, L = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
Y = [list(map(int, input().split())) for _ in range(Q)]

inf = 10 ** 9 + 7
graph = [[inf] * N for _ in range(N)]
count = [[inf] * N for _ in range(N)]

for i in range(N):
    graph[i][i] = 0
    count[i][i] = 0
    
for a, b, c in X:
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

for i in range(N):
    for j in range(N):
        if i != j and graph[i][j] <= L:
            count[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            count[i][j] = min(count[i][j], count[i][k] + count[k][j])

for s, t in Y:
    if count[s - 1][t - 1] == inf:
        print(-1)
    else:
        print(count[s - 1][t - 1] - 1)


Measured memory_bytes: 99276
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Union_Find_Tree{
	public:
	vi p,r,s;
	Union_Find_Tree(int n){
		p=r=vi(n);
		s=vi(n,1);
		for(int i=0;i<n;i++) p[i]=i;
	}
	int Par(int x){
		if(p[x]==x) return x;
		return p[x]=Par(p[x]);
	}
	int Size(int x){return s[Par(x)];}
	bool Unite(int x,int y){
		x=Par(x);
		y=Par(y);
		if(x==y) return 0;
		if(r[x]<r[y]){
			p[x]=y;
			s[y]+=s[x];
		}
		else{
			p[y]=x;
			s[x]+=s[y];
			if(r[x]==r[y]) r[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){return Par(x)==Par(y);}
};

int n,m,k;

int main(){
	cin>>n>>m>>k;
	Union_Find_Tree uft(n);
	vi a(n,-1);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		a[u]--;a[v]--;
		uft.Unite(u,v);
	}
	for(int i=0;i<n;i++) a[i]+=uft.Size(i);
	for(int i=0;i<k;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		if(uft.Same(u,v)){
			a[u]--;
			a[v]--;
		}
	}
	for(int i=0;i<n;i++) cout<<a[i]<<" \n"[i==n-1];
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
using vi = vector<int>;

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

int main(){
    int h,w;
    cin >>h >>w;
    vector<string> s(h);
    rep(i,h) cin >>s[i];

    pi start,goal;
    rep(i,h)rep(j,w){
        if(s[i][j] == 'S') start = {i,j};
        if(s[i][j] == 'G') goal = {i,j};
    }

    auto IN = [&](int y, int x){
        return 0<=y && y<h && 0<=x && x<w;
    };

    vector<vi> d(h,vi(w,INF));
    queue<pi> que;
    d[start.fi][start.se] = 0;
    que.push(start);

    while(!que.empty()){
        pi c = que.front();
        que.pop();
        int D = d[c.fi][c.se];

        // 移動( o:1 .:2 )
        rep(i,4){
            int ny=c.fi+dy[i], nx=c.se+dx[i];
            if(IN(ny,nx)){
                if(s[ny][nx]=='o'){
                    if(d[ny][nx] > D+1){
                        d[ny][nx] = D+1;
                        que.push({ny,nx});
                    }
                }
                else if(s[ny][nx]=='.' || s[ny][nx]=='G'){
                    if(d[ny][nx] > D+2){
                        d[ny][nx] = D+2;
                        que.push({ny,nx});
                    }
                }
            }
        }

        // スミを吐いてから移動 (2+距離)
        rep(i,4){
            for(int v=1; v<=3; ++v){
                int ny=c.fi+v*dy[i], nx=c.se+v*dx[i];
                if(!IN(ny,nx)) break;
                if(s[ny][nx]=='#') break;

                if(d[ny][nx] > D+2+v){
                    d[ny][nx] = D+2+v;
                    que.push({ny,nx});
                }
            }
        }
    }

    cout << d[goal.fi][goal.se] << endl;
    return 0;
}



Measured memory_bytes: 3236
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M = map(int,readline().split())
A = np.array(read().split(),np.int64)

A.sort()

def test(n):
    if n >= N:
        return True
    # 左から 2n 個をペア、右から 2N - 2n 個をペア。
    # 右側がすべて M 以上ならTrue
    R = A[n+n:]
    return np.min(R + R[::-1]) >= M

right = N # True
left = -1
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        right = x
    else:
        left = x

n = right
L = A[:n+n]
R = A[n+n:]
x = np.concatenate([L + L[::-1], R + R[::-1]])

answer = np.max(x % M)
print(answer)

Measured memory_bytes: 25052
#include <iostream>

using namespace std;

int main()
{
    int k;
    int num=0;
    cin>>k;
    string s;
    cin>>s;
    int y=s.find("ABC",0);
    while(y!=-1)
    {
        num++;
        y=s.find("ABC",y+3);
    }
    cout<<num;
    return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector< vector<int> > G(n);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
	}
	
	vector<int> inDegree(n);
	for (int x = 0; x<G.size();x++) {
		for (int y = 0; y <G[x].size();y++)
		{
		    int t = G[x][y];
		    inDegree[t]++;
		    
		}
	}
	
	int num = 0;
	queue<int> q;
	for (int i = 0; i < n; i++)
		if (inDegree[i] == 0)
			q.push(i);
	
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			inDegree[v]--;
			if (inDegree[v] == 0)
				q.push(v);
		}
		G[u].clear();
		num ++;
	}
	if (num == n)				
		cout<<"0"<<endl;
	else
	    cout<<"1"<<endl;
 
	return 0;
}



Measured memory_bytes: 3172
#include <iostream>

using namespace std;

const int MAX = 10'000;

int P[MAX];
int R[MAX];

//
int parent(int x) {
    if (P[x] == x) {
        return x;
    } else {
        return P[x] = parent(P[x]);
    }
}

void unite(int x, int y) {
    int a, b;
    a = parent(x);
    b = parent(y);
    if (R[a] > R[b]) {
        P[b] = a;
    } else if (R[a] < R[b]) {
        P[a] = b;
    } else {
        P[b] = a;
        R[a]++;
    }
}

bool same(int x, int y) {
    return parent(x) == parent(y);
}

//
int main() {

    int n, q;
    cin >> n >> q;

    for (int i = 0; i < n; i++) {
        P[i] = i;
        R[i] = 0;
    }

    int com, x, y;
    for (int i = 0; i < q; i++) {
        scanf("%d%d%d", &com, &x, &y);
        if (com == 0) {
            unite(x, y);
        } else {
            cout << (same(x, y) ? 1 : 0) << endl;
        }
    }
}


Measured memory_bytes: 3228
n = gets.chomp.to_i
a = []
n.times do
  a.push(gets.chomp.to_i)
end

max_gap = -Float::INFINITY
low = a[0]

for i in 1..a.size-1
  max_gap = a[i] - low if a[i] - low > max_gap
  low = a[i] if a[i] < low
end

puts max_gap

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
 
//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans = (n / (a + b)) * a;
	ans += min(n % (a + b),a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a[10];
	scanf("%s",a);
	if(a[0]>='a' and a[0]<='z'){
		printf("a");
		
		}else if(a[0]>='A' and a[0]<='Z'){
		printf("A");
		
	}
	
	

}




Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned char uchar;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

int h, w;
char field[16][16];
int label[16][16];

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

int labeling(int y, int x, int l)
{
    int ret = 1;
    label[y][x] = l;
    
    rep(i, 4){
        int py = y + dy[i];
        int px = x + dx[i];
        if(py<0 || h<=py || px<0 || w<=px) continue;
        if(field[py][px] == 'X' && label[py][px] == 0){
            ret += labeling(py, px, l);
        }
    }
    
    return ret;
}

struct Data
{
    int y, x, cost;
    vector<uchar> broken;
    
    bool operator== (const Data& d) const
    {
        return y == d.y && x == d.x && broken == d.broken;
    }
};

struct myhash
{
    size_t operator()(const Data& d) const
    {
        size_t h = d.y ^ d.x;
        rep(i, d.broken.size()) h ^= d.broken[i] << i;
        return h;
    }
};

int func()
{
    rep(i, h) rep(j, w) label[i][j] = 0;
    
    rep(i, h){
        cin >> field[i];
    }
    
    vector<uchar> area;
    rep(y, h) rep(x, w){
        if(field[y][x] == 'X' && label[y][x] == 0){
            area.push_back(labeling(y, x, area.size() + 1));
        }
    }
    
    for(uchar& a : area){
        a /= 2;
    }
    
    queue<Data> Q;
    unordered_set<Data, myhash> visited;
    
    rep(y, h) rep(x, w){
        if(field[y][x] == 'S'){
            Q.push({y, x, 0, area});
            visited.insert(Q.front());
        }
    }
    
    while(!Q.empty()){
        Data d = Q.front();
        Q.pop();
        
        rep(i, 4){
            int py = d.y + dy[i];
            int px = d.x + dx[i];
            if(py<0 || h<=py || px<0 || w<=px || field[py][px] == '#') continue;
            
            Data next;
            if(field[py][px] == 'G'){
                return d.cost + 1;
            }
            else if(field[py][px] == 'X'){
                uchar& b = d.broken[label[py][px]-1];
                if(b == 0) continue;
                --b;
                next = {py, px, d.cost + 1, d.broken};
                ++b;
            }
            else{
                next = {py, px, d.cost + 1, d.broken};
            }
            
            if(visited.count(next)) continue;
            
            Q.push(next);
            visited.insert(next);
        }
    }
    
    return 0;
}
    
int main()
{
    while(cin >> w >> h, w){
        printf("%d\n", func());
    }
}

Measured memory_bytes: 64080
import numpy as np
tmps = []
for i in range(3):
    tmp = list(map(int, input().split(' ')))
    tmps.append(tmp)
bingo = np.array(tmps)
N = int(input())
for i in range(N):
    bingo = np.where(bingo==int(input()), -1, bingo)
c = 2
x1 = 0
x2 = 0
ret = []
for i in range(3):
    row = np.sum(bingo[i, :])
    col = np.sum(bingo[:, i])
    x1 += np.sum(bingo[i, i])
    x2 += np.sum(bingo[i, c-i])
    ret.append(row)
    ret.append(col)
ret.append(x1)
ret.append(x2)
if -3 in ret:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 12504
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD =1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1LL;}return res%p;}
const int N=1e6+2,M=1e6+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	// freopen("out10.txt","w",stdout);
	#endif
	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y;
}
//
// Don't be afraid to fail. Be afraid not to try.
// "Become grindian instead of greendian" - aryanc403
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

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

long long int gcd(long long int a,long long int b){
  if(a%b==0) return(b);
  else return(gcd(b,a%b));
}

int main(){
  long long int N,K;
  cin>>N>>K;
  cout<<((N/gcd(N,K))*3-3)*gcd(N,K)<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func solve() {
	var n, m int
	fmt.Scan(&n, &m)

	fmt.Println((n - 1) * (m - 1))
}

func main() {
	solve()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
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);
        YProcon_2 solver = new YProcon_2();
        solver.solve(1, in, out);
        out.close();
    }

    static class YProcon_2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] city = new int[4 + 1];
            boolean first = true;

            for (int i = 0; i < 3; i++) {
                int a = in.nextInt(); //a1
                int b = in.nextInt();
                city[a] += 1;
                city[b] += 1;
            }

            int come2count = 0;
            for (int val : city) {
                if (val == 2) {
                    come2count++;
                }
            }
            if (come2count == 2) {
                out.println("YES");
            } else {
                out.println("NO");
            }

        }

    }
}



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

int main() {
  // 入力
  int N;
  cin >> N;
  vector<int> v(N); 
  vector<int> c(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> c.at(i);
  }
  
  // 判定と計算
  int ad, ans = 0;
  for (int i = 0; i < N; i++) {
    ad = v.at(i) - c.at(i);
    if (ad > 0) {
      ans += ad;
    }
  }
  
  // 出力
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
#define re register
#define il inline
#define pi pair<int,int>
#define mk make_pair
#define fp(i,a,b) for(re int i=a;i<=b;++i)
#define fq(i,a,b) for(re int i=a;i>=b;--i)
using namespace std;
const int N=2e5+100,M=2005,mod=1e9+7;
int n,a[N],b[N],jc[N],inv[N];
ll mp[4100][4100],ans;
il int gi()
{
  re int x=0,t=1;
  re char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
  if(ch=='-') t=-1,ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
  return x*t;
}
il ll ksm(re ll S,re ll n)
{
  re ll T=S;S=1;
  while(n)
    {
      if(n&1) S=S*T%mod;
      T=T*T%mod;
      n>>=1;
    }
  return S;
}
il ll C(re int x,re int y)
{
  if(x<0||y<0||x<y) return 0;
  return 1ll*jc[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
  jc[0]=inv[0]=1;
  fp(i,1,M<<2) jc[i]=1ll*jc[i-1]*i%mod;
  inv[M<<2]=ksm(jc[M<<2],mod-2);
  fq(i,(M<<2)-1,1) inv[i]=1ll*inv[i+1]*(i+1)%mod;
  n=gi();
  fp(i,1,n) a[i]=gi(),b[i]=gi();
  fp(i,1,n) ++mp[M-a[i]][M-b[i]];
  fp(i,1,4005)
    fp(j,1,4005)
    (mp[i][j]+=mp[i-1][j]+mp[i][j-1])%=mod;
  fp(i,1,n) (ans+=mp[M+a[i]][M+b[i]])%=mod;
  fp(i,1,n) (ans+=mod-C(2*a[i]+2*b[i],2*a[i]))%=mod;
  printf("%lld\n",ans*ksm(2,mod-2)%mod);
  return 0;
}

Measured memory_bytes: 132608
r,g,b,n=map(int,input().split())
maxr=n//r
maxg=n//g
maxb=n//b
bag=0
cnt=0
for i in range(0,maxr+1):
    bag+=i*r
    for j in range(0,((n-bag)//g)+1):
        bag+=j*g
        if (n-bag)%b==0:
            cnt+=1
        bag=i*r
    bag=0
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

  int n; cin >> n;
  vector< pair<int, ll> > g[n];
  for(int i=1; i<n; i++) {
    int u, v, w; cin >> u >> v >> w;
    u--, v--;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }

  int ans[n];
  function<void(int,int,ll)> f =
    [&] (int u, int par, ll depth) {
      ans[u] = (depth & 1);
      for(auto e: g[u]) {
        if( e.ff == par ) continue;
        f(e.ff, u, depth + e.ss);
      }
    };

  f(0, 0, 0ll);
  for(int i=0; i<n; i++) cout << ans[i] << nl;

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 11264
#include<iostream>
#include<vector>

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> zorome(n,0);
  int d0,d1;
  for(int i=0;i<n;i++){
    cin >> d0 >> d1;
    if(d0==d1){
      zorome.at(i)=1;
    }
  }
  for(int i=0;i<n-2;i++){
    if(zorome.at(i)*zorome.at(i+1)*zorome.at(i+2)==1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3116
#include <iostream>

int main()
{
  unsigned N, num;
  std::cin >> N;
  for (int ii=0; ii<N; ++ii) {
    unsigned l,r;
    std::cin >> l >> r;
    num += (r-l+1);
  }
  std::cout << num << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,n;
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
    scanf("%d%d%d",&a,&b,&c);
    if(a*a==b*b+c*c | b*b==a*a+c*c | c*c==a*a+b*b){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    }
    return 0;
}



Measured memory_bytes: 2044