akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
typedef unsigned long long ull;
typedef long long ll;

ull modpow(ull a, ull n, ull mod) {
  ull res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    n >>= 1;
  }
  return res;
}

#define MAX 200001
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ull comb(ull n, ull r, ll finv[]) {
  ull ncr = 1;
  for (int i = 1; i <= r; i++) {
    ncr *= n - i + 1;
    ncr %= MOD;
  }
  ncr *= finv[r];
  ncr %= MOD;
  return ncr;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  if (n == 2) {
    cout << 0;
    return 0;
  }

  COMinit();

  ull max = modpow(2, n, MOD) - 1;  // 総パターン数

  ull nca = comb(n, a, finv);

  ull ncb = comb(n, b, finv);

  ll ans = max - nca - ncb;
  cout << (ans + MOD * 2) % MOD;
}


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

int main()
{
  int a,b;
  int count=0;
  int check=0;
  string ans="DENIED";
  cin>>a;
  for(int i=0;i<a;i++)
  {
    cin>>b;
    if(b%2==0)
    {
      count++;
      if(b%3==0||b%5==0)
      {
        check++;
      }
    }
  }
  if(count==check)ans = "APPROVED";
  cout<<ans<<endl;
  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 = sc.nextInt();
     
      String A = "AC";
      String B = "WA";
      String C = "TLE";
      String D = "RE";
     
      int C0 = 0;
      int C1 = 0;
      int C2 = 0;
      int C3 = 0;
     
     
      for(int i=0; i<=N; i++) {
       String H = sc.nextLine();
       if(H.equals(A)) {
				C0++;
			}else if(H.equals(B)) {
				C1++;
			}else if(H.equals(C)) {
				C2++;
			}else if(H.equals(D)) {
				C3++;
			}
      }
        System.out.println("AC x " + C0);
		System.out.println("WA x " + C1);
		System.out.println("TLE x " + C2);
		System.out.println("RE x " + C3);
   }
}


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

int main() {
  int n;

  cin >> n;

  vector<int> a;

  int mini = n + 1, ans = 0;

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    mini = min(mini, tmp);
    if (mini >= tmp) ans++;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
       int n,m,i,j,k,l,p,q,r,s1=0,s2=0,t;

   scanf("%d",&n);
    int a[n+1];
    for(i=0;i<n;i++)
    {
       scanf("%d",&a[i]);
    }
    scanf("%d",&m);
    int b[m+1];
    for(i=0;i<m;i++)
    {
        scanf("%d",&b[i]);
    }

    for(i=0;i<n&&i<m;i++)
    {


        if(b[i]>a[i])
        {
          printf("1\n");
            return 0;

        }
        else if(b[i]<a[i])
        {
            printf("0\n");
            return 0;
        }
        else if(a[i]==b[i])
        {
            s1++;
        }

    }
    if(s1==n||s1==m)
    {
        if(n>=m)
        {
            printf("0\n");
        }
        else if(m>n)
        {
            printf("1\n");
        }
    }




}


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

using namespace std;

int angka[2000005];
int main(){
   int a,i,d,e,sisa,tampung,b,c,awal,sama;
   scanf("%d", &a);
   sama=0;
   getchar();
   for(i=0;i<a;i++){
      scanf("%d", &angka[i]);
      if(angka[i]==1){
         sama=1;
      }
      getchar();
  }
 // cout<<sama;
  awal=1;
  tampung=0;
  for(i=0;i<a;i++){
     while(angka[i]!=awal && i<a){
        i=i+1;
        tampung=tampung+1;
     }
     awal=awal+1;
  }
  if(sama==0){
     tampung=-1;
  }
  printf("%d\n",tampung);
}

Measured memory_bytes: 1024
// 20:47 - 20:51
// debug: 20:51 - 21:03
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> pint;

const int N = (1 << 18) + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int a[N];
pint b[N][2];
int ans[N];

int main(){
	ios::sync_with_stdio(0);

	int n; cin >> n;
	int m = 1 << n;

	for(int i=0; i<m; i++){
		cin >> a[i];
		b[i][0] = make_pair(a[i], i);
		b[i][1] = make_pair(0, -1);
		
		for(int k=0; k<n; k++){
			if(((i >> k) & 1) == 0) continue;
			int j = i ^ (1 << k);

			auto Add = [&](pint x){
				if(x == b[i][0] || x == b[i][1]) return;
				if(x.fi >= b[i][0].fi){
					b[i][1] = b[i][0];
					b[i][0] = x;
				}else if(x.fi >= b[i][1].fi)
					b[i][1] = x;
			};

			Add(b[j][0]); Add(b[j][1]);
		}
	}
	
	for(int i=1; i<m; i++){
		ans[i] = ans[i-1];
		if(b[i][0].se != b[i][0].se)
			ans[i] = max(ans[i], b[i][0].fi + b[i][0].fi);
		if(b[i][0].se != b[i][1].se)
			ans[i] = max(ans[i], b[i][0].fi + b[i][1].fi);
		if(b[i][1].se != b[i][0].se)
			ans[i] = max(ans[i], b[i][1].fi + b[i][0].fi);
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 9216
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iostream>
using namespace std;
struct P{int x,y; P(int x,int y) : x(x) , y(y) {} };


vector<P> h;
long long sim(int x,int y){
	long long ans = 0 , mx = 0;
	for(int i = 0 ; i < h.size() ; i++){
		long long r =  abs(h[i].x - x) + abs(h[i].y - y);
		ans += r*2;
		mx = max( mx , r );
	}
	
	return ans - mx;
}
int main(){
	vector<int> X,Y;
	int N,W,H;
	scanf("%d%d%d",&W,&H,&N);
	for(int i = 0 ; i < N ; i++){
		int a,b;
		scanf("%d%d",&a,&b);
		h.push_back(P(a,b));
		X.push_back(a);
		Y.push_back(b);
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	if(N % 2){
		printf("%lld\n%d %d\n",sim(X[N/2],Y[N/2]),X[N/2],Y[N/2]);
	}else{
		long long answer = 1ll<<60 , rx , ry;
		for(int i = -1 ; i <= 0 ; i++){
			for(int j = -1 ; j <= 0 ; j++){
				long long g = sim(X[N/2+i],Y[N/2+j]);
				if(g < answer){
					rx = X[N/2+i] , ry = Y[N/2+j];
					answer = g;
				}
			}
		}
		printf("%lld\n%lld %lld\n",answer,rx,ry);
	}
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> t(n + 2, 0);
  VEC<int> v(n + 2, 0);
  int T = 0;
  REPC(i, 1, n) {
    cin >> t[i];
    T += t[i];
  }
  REPC(i, 1, n) cin >> v[i];
  //DUMP(t);
  //DUMP(v);
  auto velocity = [&](double time) -> double {
    double vel = 1e9;
    double tt = 0;
    REP(i, 0, n + 2) {
      double l = tt;
      double r = tt + t[i];
      if (0 <= time && time < l)
        vel = min(vel, v[i] + l - time);
      else if (l <= time && time < r)
        vel = min(vel, (double)v[i]);
      else
        vel = min(vel, v[i] + time - r);
      //DUMP("    ", time, l, r, v[i], vel);
      tt += t[i];
    }
    return vel;
  };
  double sum = 0;
  double pv = 0;
  for (double i = 0; i <= T; i += 0.5) {
    double cv = velocity(i);
    sum += 0.25 * (cv + pv);
    //DUMP(i, pv, cv, sum);
  }
  printf("%lf\n",2*sum);

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int mul(int n,int m);
int main(){
  int n,k;
  cin >> n >> k;
  cout << k*mul(n-1,k-1);
}

int mul(int n,int m){
  int ans=1;
  for (int i=0;i<n;i++){
    ans *= m;
  }
  return ans;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int a[11];
int main(void){
  for(int i = 0; i < 3; i++)
    cin >> a[i];
  sort(a,a+3);
  
  if(a[0] == 5 &&
     a[1] == 5 &&
     a[2] == 7)
    cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  vector<int> data(26);
  for (int i = 0; i < S.size(); i++) {
    data.at(S.at(i) - 'a')++;
  }
  string ans = "yes";
  for (int i = 0; i < 26; i++) {
    if(data.at(i) >= 2) ans = "no";
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0]){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	int ans = 0;
	for (int i = 0; i < K; i++)
	{
		if (0 < A)
		{
			ans += 1;
			A--;
		}
		else if (0 < B) {
			B--;
		}
		else if (0 < C) {
			ans -= 1;
			C--;
		}
	}
	cout << ans << endl;

}


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

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i,h) {
    vector<int> done(w);
    rep(j,w) {
      if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int l = 0;
      while (j+l < w) {
        if (s[i][j+l] == '#') break;
        l++;
      }
      rep(k,l) {
        cnt[i][j+k] += l;
        done[j+k] = 1;
      }
    }
  }
  rep(j,w) {
    vector<int> done(h);
    rep(i,h) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int l = 0;
      while (i+l < h) {
        if (s[i+l][j] == '#') break;
        l++;
      }
      rep(k,l) {
        cnt[i+k][j] += l;
        done[i+k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i,h)rep(j,w) ans = max(ans, cnt[i][j]-1);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    if(str.substr(0, n / 2) == str.substr(n / 2)){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		int b,c; cin >> b;
		if (b == 0) {
			cin >> c;
			a.push_back(c);
		}
		else if (b == 1) {
			cin >> c;
			cout << a[c] << endl;
		}
		else {
			a.pop_back();
		}
	}
}



Measured memory_bytes: 3916
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,m,a,sum=0;
  priority_queue<ll> que;
  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> a;
    que.push(a);
  }
  for(int i=0;i<m;i++){
    a = que.top();
    que.pop();
    a/=2;
    que.push(a);
  }
  while(!que.empty()){
    sum+=que.top();
    que.pop();
  }
  cout << sum<<endl;
}


Measured memory_bytes: 1400
import numpy as np
import scipy.sparse as sps
import sys,math

h,w = map(int,input().split())
c = np.array([list(map(int,input().split()))for i in range(10)])
wf = sps.csgraph.floyd_warshall(c,directed=1).astype(int)

a = np.array([list(map(int,input().split()))for i in range(h)])

ans = 0
for arr in a:
    for num in arr:
        if num == -1: continue
        else: ans += wf[num][1]
print(ans)



Measured memory_bytes: 38528
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i,n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(b,n) {
    int r = b+1;
    rep(a,b) {
      int ab = L[a]+L[b];
      while (r < n && L[r] < ab) ++r;
      int l = b+1;
      ans += r-l;
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> dp(n+1, vector<int>(n+1));
  int ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = n - 1; j >= 0; --j) {
      if (s[i] == s[j]) {
        dp[i][j] = dp[i+1][j+1] + 1;
      } else {
        dp[i][j] = 0;
      }
      if (j <= i) continue;
      ans = max(ans, min(dp[i][j], j - i));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 98176
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



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

    printf("%d\n", MAX(a+b,MAX(a-b,a*b)));


    return 0;
}


Measured memory_bytes: 128
MV = {}
MV['U'] = [-1, 0]; MV['D'] = [1, 0]; MV['L'] = [0, -1]; MV['R'] = [0, 1]
Tank = {}
Tank['^'] = 'U'; Tank['v'] = 'D'; Tank['<'] = 'L'; Tank['>'] = 'R'

gets.to_i.times do |i|
  puts if i > 0
  h, w = gets.split.map(&:to_i)
  fld = (h+2).times.map{''}
  fld[0] = fld[h+1] = ' '*(w+2)
  y, x = 0, 0 
  z = ''
  h.times do |i|
    f = gets.chomp
    Tank.keys.each do |t|
      if f.include?(t)
        y, x = i+1, f.index(t)+1
        z = Tank[t]
      end
    end
    fld[i+1] << ' ' + f + ' '
  end 

  n = gets.to_i
  tank = gets
  n.times do |j|
    if tank[j] == 'S'
      my, mx = y, x
      while fld[my][mx] != ' '
        my += MV[z][0]; mx += MV[z][1]
        if fld[my][mx] == '*'
          fld[my][mx] = '.'
          break
        elsif fld[my][mx] == '#'
          break
        end
      end
    else
      z = tank[j]
      if fld[y + MV[z][0]][x + MV[z][1]] == '.'
        fld[y][x] = '.'
        y += MV[z][0]; x += MV[z][1]
        fld[y][x] = Tank.key(z)
      else
        fld[y][x] = Tank.key(z)
      end
    end
  end
  (1..h).each{ |j| puts fld[j][1,w] }
end

Measured memory_bytes: 8748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[][] t = new int[n-1][3];
		
		for (int i = 0; i < n - 1; i++) {
			t[i][0] = sc.nextInt();
			t[i][1] = sc.nextInt();
			t[i][2] = sc.nextInt();
		}
		
		for (int i = 0; i < n - 1; i++) {
			int res = 0;
			int c = t[i][0];
			int s = t[i][1];
			long arrive = c + s;
			
			for (int j = i + 1; j < n - 1; j++) {
				int readyToGo = t[j][1];
				
				if (arrive < readyToGo) {
					arrive = readyToGo + t[j][0];
				} else {
					if ((arrive - t[j][1]) % t[j][2] == 0) {
						arrive += t[j][0]; 
					} else {
						arrive = arrive + (t[j][2]) - ((arrive - t[j][1]) % t[j][2]) + t[j][0];
					}
				}
			}
			
			System.out.println(arrive);
		}
		System.out.println(0);
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}

Measured memory_bytes: 22228
#include <iostream>

int main()
{
    int H, W;
    while (1) {
        std::cin >> H >> W;
        if (H == 0 || W == 0)
            break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                std::cout << '#';
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    for(int i=0; i<N; i++){
        cin >> X.at(i) >> Y.at(i);
    }
    vector<int> order(N);
    for(int i=0; i<N; i++){
        order.at(i) = i;
    }
    double dist=0;
    int cnt=0;
    do{
       for(int i=0; i<N-1;i++){
           int before=order.at(i);
           int after=order.at(i+1);
           int move_x = X.at(after) - X.at(before);
           int move_y = Y.at(after) - Y.at(before);
           dist += sqrt(move_x*move_x + move_y*move_y);
       } 
       cnt++;
    }while(next_permutation(order.begin(),order.end()));
    cout << fixed;
    cout << setprecision(7) << dist/cnt << endl;
}

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

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	cin >> s;
	int t = 0;
	for(char c: s) {
		t += c -'0';
	}
	cout << (t % 9 == 0 ? "Yes" : "No");
}

Measured memory_bytes: 3748
n = gets.chomp.split("").map(&:to_i)
flag = true
for i in 1...(n.length) do
  flag = false if n[i] != 9
end
ans = nil
if flag
  ans = n.inject(:+)
else
  ans = n[0] - 1 + 9 * (n.length - 1)
end
puts ans


Measured memory_bytes: 14316
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            int z = int.Parse(Console.ReadLine().Trim());
            var house = new int[12,10];
            for (int i = 0; i < z; i++)
            {
                string[] n = Console.ReadLine().Trim().Split(' ');
                int b = int.Parse(n[0]) - 1;
                var f = int.Parse(n[1]) - 1;
                var r = int.Parse(n[2]) - 1;
                var v = int.Parse(n[3]);

                house[f + b * 3, r] += v;
            }
            int count = 0;
            for (int i = 0; i < 12; i++)
            {
                if (count == 3)
                {
                    Console.WriteLine("####################");
                    count = 0;
                }

                for (int j = 0; j < 10; j++)
                {
                    if (j == 9)
                    {
                        Console.WriteLine(" {0}",house[i, j]);
                    }
                    else
                    {
                        Console.Write(" {0}",house[i, j]);
                    }
                    
                }
                count++;
            }
        }
    }
}


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


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

/* vector<int> A(N); 
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
*/
 
int main() {
  
  int N, count=0, ans=0;
  vector<int> A(9); 
  vector<int> Ans(9); 
  string D, E;
  rep(i,9){
  	cin >> A.at(i);
    Ans.at(i)==0;
  }
  cin >> N;
  vector<int> B(N); 
  rep(i,N){
  	cin >> B.at(i);
  }
  
  rep(i,N){
    rep(l,9){
    	if(B.at(i)==A.at(l)) Ans.at(l)++;
    }
  }
  
  if(Ans[0]+Ans[1]+Ans[2]==3||
     Ans[3]+Ans[4]+Ans[5]==3||
     Ans[6]+Ans[7]+Ans[8]==3||
     Ans[0]+Ans[3]+Ans[6]==3||
     Ans[1]+Ans[4]+Ans[7]==3||
     Ans[2]+Ans[5]+Ans[8]==3||
     Ans[0]+Ans[4]+Ans[8]==3||
     Ans[2]+Ans[4]+Ans[6]==3){
  	cout << "Yes" << endl;
  }
  else {cout << "No" << endl;}
}

Measured memory_bytes: 256
s = list(input())
K = int(input())
N = len(s)

for i in range(N - 1):
	if s[i] != "a":
		if K >= 123 - ord(s[i]):
			K -= 123 - ord(s[i])
			s[i] = "a"
			
s[-1] = chr((ord(s[-1]) - 97 + K) % 26 + 97)

print("".join(s))

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

int main() {
  string s;
  cin >> s;
  int answer = 0;
  int N = s.size();
  for(int i = 1; i < N - 1; i++){
    answer++;
  }
  cout << s.at(0) << answer << s.at(N - 1) << endl;
}


Measured memory_bytes: 256
s = list(input())
count = 0
if len(s) % 2 ==0:
  s1 = s[:len(s)//2]
  s2 = s[len(s)//2:]
else:
  s1 = s[:len(s)//2]
  s2 = s[len(s)//2+1:]
  
s2.reverse()

for (i,j) in zip(s1,s2):
  if i != j:
    count += 1
print(count)

Measured memory_bytes: 3064
import heapq
from itertools import starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = [[x, 1] for x in R()]
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if i < y:
            a[0][1] -= i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    if i < b:
        heapq.heappush(a, [c, b - i])
print(sum(starmap(mul, a)))


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

bool is_harshad(int x, int fx) {
    if (x % fx == 0) return true;
    else return false;
}

int main() {
    int n; cin >> n;
    int x = n;
    int fx = 0;

    while(x) {
        fx += x % 10;
        x /= 10;
    }
    
    if (is_harshad(n, fx)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

func readIntPair() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

let (N, K) = readIntPair()
let p = readIntArray().sorted()
var ans = 0
for i in 0..<K {
    ans += p[i]
}
print(ans)


Measured memory_bytes: 8400
import sys
input=sys.stdin.readline

s = input().strip()
if s[0] == "A":
    if s[2:-1].count("C") == 1:
        tmp = s[2:-1].replace("C","",1)
        s = s[1:2] + tmp + s[-1]
        if s.islower():
            print("AC")
            exit()
print("WA")


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

int main (){
    int i = 0;
    int height[10];
    for(i = 0; i < 10; i++){
        cin >> height[i];
    }
    //??????????????????
    sort(height, height + 10, greater<int>());
    //???3?????¨???
    for(i = 0; i < 3; i++){
        cout << height[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3136
# from sys import stdin #入力の高速化にはあまりつながらなかった
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

# S = [-INF] + list(map(int, (stdin.readline() for _ in [0] * A))) + [INF]
# T = [-INF] + list(map(int, [stdin.readline() for _ in [0] * B])) + [INF]
S = [-INF] + [int(input()) for _ in [0]*A]+[INF]
T = [-INF] + [int(input()) for _ in [0]*B]+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(input())  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


Measured memory_bytes: 12808
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (a < b) {
        ll buf = a;
        a = b;
        b = buf;
    }
    while (a%b > 0) {
        ll buf = b;
        b = a%b;
        a = buf;
    }
    return b;
}

int main() {
    ll n = 0, m = 0;
    cin >> n >> m;
    string s = "", t = "";
    cin >> s >> t;
    ll fire = gcd(n, m);
    ll ans = n*m/fire;
    ll s_ski = m/fire, t_ski = n/fire;
    for (int i=0; i<s.size(); i++) {
        if (i*s_ski%t_ski == 0) {
            if (s.at(i) != t.at(i*s_ski/t_ski)) {
                ans = -1;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

	deque<int> dq;
	while(q--){
		int query;cin>>query;
		if(query==0){
			// push
			int d,x;cin>>d>>x;
			if(d==0) {
				dq.push_front(x);
			}else{
				dq.push_back(x);
			}
		}else if(query==1){
			// randomaccess
			int p;cin>>p;
			cout<<dq[p]<<endl;
		}else{
			int d;cin>>d;
			if(d==0)dq.pop_front();
			else dq.pop_back();
		}
	}
  return 0;
}



Measured memory_bytes: 4612
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

int D,N;

struct Info{
	Info(){
		attack = exp = r_exp = -1;
		unuse = false;
	}
	Info(int arg_attack,int arg_exp,int arg_r_exp){
		attack = arg_attack;
		exp = arg_exp;
		r_exp = arg_r_exp;
		unuse = false;
	}
	bool operator<(const struct Info &arg) const{
			return r_exp > arg.r_exp;
	};

	int attack,exp,r_exp;
	bool unuse;
};

struct Data{
	int current_exp,rest_D,count;
};


void func(){

	int a,e,r;
	priority_queue<Info> S;

	for(int i = 0; i < N; i++){
		scanf("%d %d %d",&a,&e,&r);
		S.push(Info(a,e,r));
	}

	Info info[N];

	int index = 0;

	while(!S.empty()){
		info[index].attack = S.top().attack;
		info[index].exp = S.top().exp;
		info[index].r_exp = S.top().r_exp;
		index++;
		S.pop();
	}

	//??¨????????????????????¨????????????????????????
	int a_num = 0,e_num = 0;
	for(int i = 0; info[i].r_exp == 0 && i < N; i++){
		if(info[i].attack > 0){
			a_num++;
		}
		if(info[i].exp > 0){
			e_num++;
		}
	}

	if(a_num == 0 && e_num == 0){
		printf("NA\n");
		return;
	}else{

		if(a_num == 0 && e_num > 0){ //????¨??????????????????????????????¨??????????????????????????????
			for(int i = 0; i < N; i++){
				if(info[i].attack > 0)a_num++;
			}

			if(a_num == 0){
				printf("NA\n");
				return;
			}
		}
	}

	int dp[101][101];

	for(int i = 0; i < 101; i++){
		for(int k = 0; k < 101; k++)dp[i][k] = BIG_NUM;
	}

	dp[D][0] = 0;

	for(int a = 0; a <= 100; a++){
		for(int b = D;b >= 0;b--){
			if(dp[b][a] == BIG_NUM)continue;
			for(int c = 0;info[c].r_exp <= a && c < N; c++){
				dp[max(0,b-info[c].attack)][min(100,a+info[c].exp)] = min(dp[max(0,b-info[c].attack)][min(100,a+info[c].exp)],dp[b][a]+1);
			}
		}
	}

	int minimum = BIG_NUM;

	for(int i = 0; i < 101;i++){
		minimum = min(minimum,dp[0][i]);
	}

	if(minimum == BIG_NUM){
		printf("NA\n");
	}else{
		printf("%d\n",minimum);
	}

}

int main(){

	while(true){
		scanf("%d %d",&D,&N);
		if(D == 0 && N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    long long n,m,k;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        k=n*m;
        if (k%2==0) printf("Even\n");
        else printf("Odd\n");
    }
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int n;
	cin >> n;
	int a[n];
	double sum = 0;
	REP(i, n){
		cin >> a[i];
		sum += a[i];
	}

	sum /= n;

	if (sum > (int)sum + 0.5) sum++;

	int ans = 0;

	REP(i, n){
		int r;
		r = a[i] - (int)sum;
		ans += r * r;
	}

	cout << ans << endl;


}


Measured memory_bytes: 256
class Dice():
    def __init__(self, ls = [0 for i in range(6)]):
        self.ls = ls
        
    def now(self):
        return ls
    
    def S(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[4]
        n_ls[1] = ls[0]
        n_ls[2] = ls[2]
        n_ls[3] = ls[3]
        n_ls[4] = ls[5]
        n_ls[5] = ls[1]
        
        return Dice(n_ls)
    
    def N(self):
        ls = self.S().S().S().ls
        return Dice(ls)
        
    def E(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[3]
        n_ls[1] = ls[1]
        n_ls[2] = ls[0]
        n_ls[3] = ls[5]
        n_ls[4] = ls[4]
        n_ls[5] = ls[2]
        return Dice(n_ls)
    
    
    def W(self):
        ls = self.E().E().E().ls
        return Dice(ls)
        
        
        
    def R_rot(self):
        return self.E().S().W()
        
    def rot(self, num):
        for _ in range(num):
            self = self.R_rot()
        return self
    
        
ls = list(map(int, input().split()))
LS = list(map(int, input().split()))

a = Dice(ls)
b = Dice(LS)
#print(a.ls)
#print(b.ls)

me = [a, a.N(), a.W(), a.E(), a.S(), a.S().S()]

judge = False
for i in me:
    for j in range(4):
        #print(i.rot(j).ls)
        if i.rot(j).ls == b.ls:
            judge = True

if judge == True:
    print('Yes')
else:
    print('No')
            






Measured memory_bytes: 5612
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 9223372036854775807;

int main(){

    ll N;
    cin >> N;

    ll ans = 0;
    ll AB = 0;
    ll A = 0;
    ll B = 0;

    for(ll i = 0; i < N; i++){
        string s; cin >> s;
        if(s.front() == 'B' && s.back() == 'A') AB++;
        else if(s.front() == 'B') B++;
        else if(s.back() == 'A') A++;
        
        for(ll j = 1; j < s.length(); j++){
            if(s[j-1] == 'A' && s[j] == 'B') ans++;
        } 
    }

    if(AB >= 1){
        AB--;
        if(A >= 1) AB++, A--;
        if(B >= 1) AB++, B--;
        ans += min(A, B);
    }else{
        if(A >= 1 && B >= 1) ans += min(A, B);    
    }
    
    cout << AB + ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  set<ll> mySet;
  for (char c : s) {
    mySet.insert(c);
  }

  cout << ((mySet.size() == 1) ? "No" : "Yes") << en;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
#define MAX 50000000

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


int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> s(H+2, vector<char>(W+2));
    vector<vector<int>> check(H+2, vector<int>(W+2, MAX));
    queue<pair<int, int>> q;
    rep(i, W+2) {
        s[0][i] = '#';
        s[H][i] = '#';
    }
    rep(i, H+2) {
        s[i][0] = '#';
        s[i][W+1] = '#';
    }
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> s[i][j];
            if (s[i][j] == '#') {
                check[i][j] = 0;
                q.push(make_pair(i, j));
            }
        }
    }
    int ans = 0;
    while(!q.empty()) {
        pair<int, int> tmp = q.front(); q.pop();
        for (int k = 0; k < 4; k++) {
            if (check[tmp.first+dy[k]][tmp.second+dx[k]] > check[tmp.first][tmp.second] + 1 && s[tmp.first+dy[k]][tmp.second+dx[k]] == '.') {
                q.push(make_pair(tmp.first+dy[k], tmp.second+dx[k]));
                check[tmp.first+dy[k]][tmp.second+dx[k]] = check[tmp.first][tmp.second] + 1;
                ans = max(ans, check[tmp.first+dy[k]][tmp.second+dx[k]]);
            }
        }
    }
    cout << ans << endl;
}


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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(c>=a){
        if(c>b){
            cout<<0<<endl;
        }
        else if(b<d){
            cout<<b-c<<endl;
        }
        else if(b>=d){
            cout<<d-c<<endl;
        }
    }
    else{
        if(d<a){
            cout<<0<<endl;
        }
        else if(b>=d){
            cout<<d-a<<endl;
        }
        else if(b<d){
            cout<<b-a<<endl;
        }
    }

}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class DXXOR {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long k = in.nextLong();
            long[] a = new long[n];
            long maxAK = k;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                maxAK = Math.max(maxAK, a[i]);
            }

            long answer = 0;
            long x = 0;
            for (long bit = Long.highestOneBit(maxAK) * 2; bit >= 1; bit /= 2) {
                long on = 0, off = 0;
                for (long A : a) {
                    if ((A & bit) > 0) {
                        on += bit;
                    } else {
                        off += bit;
                    }
                }

                if (x + bit <= k && off > on) {
                    answer += off;
                    x += bit;
                } else {
                    answer += on;
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 45620
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct Node{
	int key;
	struct Node *right, *left , *parent;
};

struct Node *root , *NIL;

void insert(int k){
	struct Node *y = NIL;
	struct Node *x = root;
	struct Node *z;
	
	z = (struct Node *)malloc(sizeof(struct Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while( x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}
	z->parent = y;
	if(y == NIL){
		root = z;
	}else{
		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void inorder(struct Node *u){
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(struct Node *u){
	if( u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(void){
	int n,i,x;
	char  com[100];
	char A[] = "insert";
	char B[] = "print";
	scanf("%d",&n);
	
	for( i = 0; i < n; i++){
		while(scanf("%s",com) != EOF)
		if(strcmp(com,A)==0){
			scanf("%d",&x);
			insert(x);
		}else if( strcmp(com,B)==0){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}




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

using namespace std;

bool cmp(pair<int, int> &a, pair<int, int> &b) {
  if(a.second == b.second) return a.first > b.first;
  return a.second < b.second;
}

int main() {
  int n;
  vector<pair<int, int>> a;
  cin >> n;
  for(int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a.push_back({x, y});
  }
  sort(a.begin(), a.end(), cmp);
  int sum = 0;
  //bool ok = true;
  for(auto i : a) {
    sum += i.first;
    if(sum > i.second) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


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

using namespace std;

namespace {
    int N, M;
    void input() {
        cin >> N >> M;
    }

    void solve() {
        int x = 1900 * M + 100 * (N - M);
        int alpha = x * (1 << M);
        cout << alpha << endl;
    }
}

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



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

// 二項係数計算
long long com(ll n){
    int k = 2;
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return n*(n-1)/2;
}

int main()
{

    int N;
    cin >> N;
    vector<int> A;
    int same[200005] = {};
    int done[200005] = {};

    for(ll i=0; i<N; ++i)
    {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
        ++same[tmp];
    }

    ll all = 0;
    for(ll i=0; i<N; ++i)
    {
        if(done[A[i]]==1) continue;
        else
        {
            done[A[i]] = 1;
            all += com(same[A[i]]);
        }
    }

    for(ll i=0; i<N; ++i)
    {
        cout << all - com(same[A[i]]) + com(same[A[i]]-1) << endl;
    }

    return 0;
}


Measured memory_bytes: 5108
def count(s, idx):
	ac = 0
	step = 0
	bc = 0
	cc = 0
	c = 0
	while(idx < len(s) and step < 3):
		if s[idx] == 'A' and bc == 0 and cc == 0:
			ac = 1
		elif s[idx] == 'B' and cc == 0 and ac == 1:
			bc = 1
		elif s[idx] == 'C' and bc == 1 and ac == 1:
			cc = 1
		idx += 1
		step += 1
	c = ac + bc + cc
	if c == 3:
		return 1
	return 0

n = int(input())
s = input()
summ = 0
for i in range(n):
	if s[i] == 'A':
		if count(s, i) == 1:
			summ += 1
print(summ)

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

using namespace std;

const int MAXN = 1e5 + 10;

int n, o, e;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++){
		int x;	cin >> x;
		if (x & 1)
			o++;
		else
			e++;
	}
	e += o/2;
	int x = o&1;
	x += bool(e > 0);
	if (x < 2)
		cout << "YES\n";
	else
		cout << "NO\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();

		list.add(sc.nextInt());
		for(int i = 1; i < n; i++) {
			int num = sc.nextInt();
			int index = meguruSearch(num, list);
			//更新できる木がない
			if (index == 0) {
				list.add(0, num);
			} else {
				list.set(index - 1, num);
			}
		}
		out.println(list.size());

		out.close();
	}
	static int meguruSearch(int n, List<Integer> list) {
		int left = -1;
		int right = list.size();
		
		while (right - left > 1) {
			int mid = left + (right - left) / 2;
			if(lower_bound(mid, n,list)) right = mid; //upper_boundで探索したい場合は要修正
			else left = mid;
		}		
		return right;		
	}
	//ロウワ―バウンド
	static boolean lower_bound(int index, int n, List<Integer> list) {
		if( list.get(index) >= n ) return true;
		else return false;
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 25864
N, x = map(int, input().split())
A = list(map(int, input().split()))
K = []
for i in range(N-1):
    K.append(A[i]+A[i+1])
ans = 0
for i in range(N-1):
    if K[i] > x:
        if K[i] - A[i+1] <= x:
            ans += K[i] - x
            if i != N-2:
                K[i+1] -= K[i] - x
        else:
            ans += K[i] - x
            if i != N-2:
                K[i+1] -= A[i+1]
print(ans)

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> p(n+1,0);
	for (int i=1; i<=n; i++) cin>>p[i];
	int cur=1;
	for (int i=1; i<=2*n; i++) {
		cur=p[cur];
		if(cur==2) { cout << i << endl; return 0; }
	}
	cout << -1 << endl;
	return 0;
}


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

using namespace std;

const long long inf = 1e18 + 5;

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#ifdef LOCAL
    freopen("input.in" , "r" , stdin);
#endif
    int n;
    long long k;
    cin >> n >> k;

    vector<int> neg , pos;
    for (int i = 0 ;i < n ;i++) {
        int x;
        cin >> x;
        if (x >= 0)
            pos.push_back(x);
        else
            neg.push_back(x);
    }

//    vector<long long> test;
//    for (int i = 0 ;i < n ;i++)
//        for (int j = i + 1 ;j < n ;j++)
//            test.push_back(a[i] * 1ll * a[j]);
//
//    sort(test.begin() , test.end());
//    for (int i = 0 ;i < test.size() ;i++) {
//        cout << i + 1 << ' ' << test[i] << endl;
//    }
//
//    cout << endl;

    sort(pos.begin() , pos.end());
    sort(neg.rbegin() , neg.rend());

    auto get = [&] (long long product) {
        long long ret = 0;
        int r = pos.size() - 1;
        for (int i = 0 ;i < pos.size() ;i++) {
            while (r >= 0 && pos[r] * 1ll * pos[i] > product)
                r--;
            ret += max(0 , r - i);
        }

        r = neg.size() - 1;
        for (int i = 0 ;i < neg.size() ;i++) {
            while (r >= 0 && neg[r] * 1ll * neg[i] > product)
                r--;
            ret += max(0 , r - i);
        }

        r = neg.size() - 1;
        for (int i = 0 ;i < pos.size() ;i++) {
            while (r >= 0 && neg[r] * 1ll * pos[i] <= product)
                r--;
            ret += neg.size() - r - 1;
        }

        return ret;
    };

    long long l = -inf , r = inf , ans = -1;
    while (l <= r) {
        long long mid = l + (r - l) / 2;
        long long cnt = get(mid);
        if (cnt >= k) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    cout << ans;
}


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

using namespace std;

int main()
{
    int n,v,l,i,j,m,p,f,k;
    cin>>n>>k;
    int a[n],dp[n];
    cin>>a[0]>>a[1];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        cin>>a[i];
        p=dp[i-1]+abs(a[i]-a[i-1]);
        j=i-1;
          //cout<<dp[j]<<" "<<abs(a[i]-a[j])<<" "<<p<<"*";
        j=i-2;
        while((j>=0)&&((i-k)<=j))
        {
            if((dp[j]+abs(a[i]-a[j]))<p)
               {
                   p=(dp[j]+abs(a[i]-a[j]));
                 //   cout<<dp[j]<<" "<<abs(a[i]-a[j])<<" "<<p<<"*";
               }
            j--;
        }
        dp[i]=p;
        //cout<<p<<"\n";
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1024